update
This commit is contained in:
47
app.cpp
47
app.cpp
@@ -62,7 +62,7 @@ GymLogDbParsed *parseDb(Arena *arena, string database) {
|
||||
|
||||
list<GymLogEntry> loadEntryLog(Arena *arena, string fileLocation) {
|
||||
list<GymLogEntry> result = {0};
|
||||
string logfile = readEntireFile(arena, LOG_FILE_LOCATION);
|
||||
string logfile = os_readEntireFile(arena, LOG_FILE_LOCATION);
|
||||
|
||||
if (logfile.length % sizeof(GymLogEntry) != 0) {
|
||||
log("Log file corrupted.\n");
|
||||
@@ -96,7 +96,7 @@ WorkSummary workSummaryForExercise(list<GymLogEntry> entries) {
|
||||
|
||||
int gymTrackerWorkToday(Arena *arena, uint32 exerciseId, string exerciseName) {
|
||||
int statusCode = 0;
|
||||
string logfile = readEntireFile(arena, LOG_FILE_LOCATION);
|
||||
string logfile = os_readEntireFile(arena, LOG_FILE_LOCATION);
|
||||
|
||||
if (logfile.length % sizeof(GymLogEntry) != 0) {
|
||||
log("Log file corrupted.\n");
|
||||
@@ -114,7 +114,7 @@ int gymTrackerWorkToday(Arena *arena, uint32 exerciseId, string exerciseName) {
|
||||
Timestamp logTs = timestampFromUnixTime(&logEntry.timestamp);
|
||||
if (logTs.tm_yday == todayTs.tm_yday && todayTs.tm_year == logTs.tm_year) {
|
||||
todaysEntries.head += 1;
|
||||
todaysEntries.data = &logEntries.data[i + 1];
|
||||
todaysEntries.data = &logEntries.data[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,9 +131,9 @@ int gymTrackerWorkToday(Arena *arena, uint32 exerciseId, string exerciseName) {
|
||||
|
||||
int gymTrackerStatus(Arena *arena, list<string> args) {
|
||||
int statusCode = 0;
|
||||
string file = readEntireFile(arena, LOG_FILE_LOCATION);
|
||||
string file = os_readEntireFile(arena, LOG_FILE_LOCATION);
|
||||
|
||||
GymLogDbParsed *db = parseDb(arena, readEntireFile(arena, DB_FILE_LOCATION));
|
||||
GymLogDbParsed *db = parseDb(arena, os_readEntireFile(arena, DB_FILE_LOCATION));
|
||||
|
||||
if (file.length % sizeof(GymLogEntry) != 0) {
|
||||
puts("Log file corrupted.");
|
||||
@@ -271,7 +271,7 @@ int gymTrackerDeleteEntries(Arena *arena, list<string> args) {
|
||||
log("%i is more than the current number of log entries (%i). Aborting.", numToDelete, logEntries.length);
|
||||
statusCode = 1;
|
||||
} else {
|
||||
writeEntireFile(arena, LOG_FILE_LOCATION, (byte *)logEntries.data, (logEntries.length - numToDelete) * sizeof(GymLogEntry));
|
||||
os_writeEntireFile(arena, LOG_FILE_LOCATION, (byte *)logEntries.data, (logEntries.length - numToDelete) * sizeof(GymLogEntry));
|
||||
}
|
||||
} else {
|
||||
log("Invalid number to delete.\n");
|
||||
@@ -296,7 +296,7 @@ int gymTrackerDo(Arena *arena, list<string> args) {
|
||||
GymLogDbParsedEntry *existingEntry = 0;
|
||||
|
||||
if (statusCode == 0) {
|
||||
GymLogDbParsed *db = parseDb(arena, readEntireFile(arena, DB_FILE_LOCATION));
|
||||
GymLogDbParsed *db = parseDb(arena, os_readEntireFile(arena, DB_FILE_LOCATION));
|
||||
for (EachIn(db->entries, i)) {
|
||||
GymLogDbParsedEntry entry = db->entries.data[i];
|
||||
if (strStartsWith(entry.name, newExerciseName)) {
|
||||
@@ -327,7 +327,7 @@ int gymTrackerDo(Arena *arena, list<string> args) {
|
||||
kg,
|
||||
};
|
||||
|
||||
fileAppend(arena, LOG_FILE_LOCATION, (byte *)&entry, sizeof(entry));
|
||||
os_fileAppend(arena, LOG_FILE_LOCATION, (byte *)&entry, sizeof(entry));
|
||||
statusCode = gymTrackerWorkToday(arena, exerciseId, newExerciseName);
|
||||
}
|
||||
}
|
||||
@@ -337,7 +337,7 @@ int gymTrackerDo(Arena *arena, list<string> args) {
|
||||
|
||||
int gymTrackerListExercises(Arena *arena, list<string> args) {
|
||||
int statusCode = 0;
|
||||
GymLogDbParsed *db = parseDb(arena, readEntireFile(arena, DB_FILE_LOCATION));
|
||||
GymLogDbParsed *db = parseDb(arena, os_readEntireFile(arena, DB_FILE_LOCATION));
|
||||
|
||||
if (db->entries.length == 0) {
|
||||
log("No entries currently registered in the exercise database.");
|
||||
@@ -353,7 +353,7 @@ int gymTrackerListExercises(Arena *arena, list<string> args) {
|
||||
|
||||
int gymTrackerAddExercise(Arena *arena, list<string> args) {
|
||||
int statusCode = 0;
|
||||
GymLogDbParsed *db = parseDb(arena, readEntireFile(arena, DB_FILE_LOCATION));
|
||||
GymLogDbParsed *db = parseDb(arena, os_readEntireFile(arena, DB_FILE_LOCATION));
|
||||
|
||||
string newExerciseName = args.data[0];
|
||||
if (newExerciseName.length == 0) {
|
||||
@@ -363,7 +363,7 @@ int gymTrackerAddExercise(Arena *arena, list<string> args) {
|
||||
|
||||
if (statusCode != 1) {
|
||||
string databaseLocation = DB_FILE_LOCATION;
|
||||
string database = readEntireFile(arena, databaseLocation);
|
||||
string database = os_readEntireFile(arena, databaseLocation);
|
||||
|
||||
byte *buf = 0;
|
||||
size_t newEntryStartIndex = 0;
|
||||
@@ -411,7 +411,7 @@ int gymTrackerAddExercise(Arena *arena, list<string> args) {
|
||||
byte *newExerciseNameDb = buf + newEntryStartIndex + sizeof(GymLogDbEntry);
|
||||
memcpy(newExerciseNameDb, newExerciseName.str, newExerciseName.length);
|
||||
size_t bufSize = newEntryStartIndex + sizeof(GymLogDbEntry) + newExerciseName.length;
|
||||
writeEntireFile(arena, databaseLocation, buf, bufSize);
|
||||
os_writeEntireFile(arena, databaseLocation, buf, bufSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -430,16 +430,19 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
if (statusCode == 0) {
|
||||
if (strEql(args.data[0], "status"_s)) {
|
||||
statusCode = gymTrackerStatus(arena, listSlice(args, 1));
|
||||
} else if (strEql(args.data[0], "do"_s)) {
|
||||
statusCode = gymTrackerDo(arena, listSlice(args, 1));
|
||||
} else if (strEql(args.data[0], "delete"_s)) {
|
||||
statusCode = gymTrackerDeleteEntries(arena, listSlice(args, 1));
|
||||
} else if (strEql(args.data[0], "list"_s)) {
|
||||
statusCode = gymTrackerListExercises(arena, listSlice(args, 1));
|
||||
} else if (strEql(args.data[0], "add"_s)) {
|
||||
statusCode = gymTrackerAddExercise(arena, listSlice(args, 1));
|
||||
string cmd = args.data[0];
|
||||
list<string> argsRest = listSlice(args, 1);
|
||||
|
||||
if (strEql("status"_s, cmd)) {
|
||||
statusCode = gymTrackerStatus(arena, argsRest);
|
||||
} else if (strEql("do"_s, cmd)) {
|
||||
statusCode = gymTrackerDo(arena, argsRest);
|
||||
} else if (strEql("delete"_s, cmd)) {
|
||||
statusCode = gymTrackerDeleteEntries(arena, argsRest);
|
||||
} else if (strEql("list"_s, cmd)) {
|
||||
statusCode = gymTrackerListExercises(arena, argsRest);
|
||||
} else if (strEql("add"_s, cmd)) {
|
||||
statusCode = gymTrackerAddExercise(arena, argsRest);
|
||||
} else {
|
||||
log("Unknown command \"%S\"\n", args.data[0]);
|
||||
statusCode = 1;
|
||||
|
||||
Reference in New Issue
Block a user