dumb fixes
This commit is contained in:
31
app.cpp
31
app.cpp
@@ -41,11 +41,10 @@ struct GymLogEntry {
|
||||
GymLogDbParsed *parseDb(Arena *arena, string database) {
|
||||
GymLogDbParsed *dbParsed = PushStruct(arena, GymLogDbParsed);
|
||||
|
||||
GymLogDbHeader *header = (GymLogDbHeader *)database.str;
|
||||
dbParsed->header = *header;
|
||||
dbParsed->header = *((GymLogDbHeader *)database.str);
|
||||
|
||||
size_t head = sizeof(GymLogDbHeader);
|
||||
uint32 entriesLeft = header->nextId - 1;
|
||||
uint32 entriesLeft = dbParsed->header.nextId - 1;
|
||||
dbParsed->entries = PushList(arena, GymLogDbParsedEntry, entriesLeft);
|
||||
|
||||
while (entriesLeft > 0 && head < database.length) {
|
||||
@@ -133,12 +132,12 @@ int gymTrackerStatus(Arena *arena, list<string> args) {
|
||||
int statusCode = 0;
|
||||
string file = os_readEntireFile(arena, LOG_FILE_LOCATION);
|
||||
|
||||
GymLogDbParsed *db = parseDb(arena, os_readEntireFile(arena, DB_FILE_LOCATION));
|
||||
|
||||
if (file.length % sizeof(GymLogEntry) != 0) {
|
||||
puts("Log file corrupted.");
|
||||
statusCode = 1;
|
||||
} else {
|
||||
GymLogDbParsed *db = parseDb(arena, os_readEntireFile(arena, DB_FILE_LOCATION));
|
||||
|
||||
Timestamp startTs = {0};
|
||||
int numDays = 1;
|
||||
bool showAll = args.length == 1 && strEql(args.data[0], "--all"_s);
|
||||
@@ -285,12 +284,12 @@ int gymTrackerDeleteEntries(Arena *arena, list<string> args) {
|
||||
// Syntax: do <exercise-name> weightKg reps
|
||||
int gymTrackerDo(Arena *arena, list<string> args) {
|
||||
int statusCode = 0;
|
||||
string newExerciseName = {0};
|
||||
string exerciseName = {0};
|
||||
if (args.length < 3 || args.data[0].length == 0) {
|
||||
log("Invalid exercise name and/or number of arguments.\n");
|
||||
statusCode = 1;
|
||||
} else {
|
||||
newExerciseName = args.data[0];
|
||||
exerciseName = args.data[0];
|
||||
}
|
||||
|
||||
GymLogDbParsedEntry *existingEntry = 0;
|
||||
@@ -299,14 +298,17 @@ int gymTrackerDo(Arena *arena, list<string> args) {
|
||||
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)) {
|
||||
if (strStartsWith(entry.name, exerciseName)) {
|
||||
existingEntry = &entry;
|
||||
log("Assuming exercise \"%S\".\n\n", entry.name);
|
||||
if (entry.name.length != exerciseName.length) {
|
||||
exerciseName = entry.name;
|
||||
log("Assuming exercise \"%S\".\n\n", entry.name);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!existingEntry) {
|
||||
log("The exercise \"%S\" hasn't been registered.", newExerciseName);
|
||||
log("The exercise \"%S\" hasn't been registered.", exerciseName);
|
||||
statusCode = 1;
|
||||
}
|
||||
}
|
||||
@@ -328,7 +330,7 @@ int gymTrackerDo(Arena *arena, list<string> args) {
|
||||
};
|
||||
|
||||
os_fileAppend(arena, LOG_FILE_LOCATION, (byte *)&entry, sizeof(entry));
|
||||
statusCode = gymTrackerWorkToday(arena, exerciseId, newExerciseName);
|
||||
statusCode = gymTrackerWorkToday(arena, exerciseId, exerciseName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,7 +355,6 @@ int gymTrackerListExercises(Arena *arena, list<string> args) {
|
||||
|
||||
int gymTrackerAddExercise(Arena *arena, list<string> args) {
|
||||
int statusCode = 0;
|
||||
GymLogDbParsed *db = parseDb(arena, os_readEntireFile(arena, DB_FILE_LOCATION));
|
||||
|
||||
string newExerciseName = args.data[0];
|
||||
if (newExerciseName.length == 0) {
|
||||
@@ -362,8 +363,7 @@ int gymTrackerAddExercise(Arena *arena, list<string> args) {
|
||||
}
|
||||
|
||||
if (statusCode != 1) {
|
||||
string databaseLocation = DB_FILE_LOCATION;
|
||||
string database = os_readEntireFile(arena, databaseLocation);
|
||||
string database = os_readEntireFile(arena, DB_FILE_LOCATION);
|
||||
|
||||
byte *buf = 0;
|
||||
size_t newEntryStartIndex = 0;
|
||||
@@ -411,7 +411,8 @@ 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;
|
||||
os_writeEntireFile(arena, databaseLocation, buf, bufSize);
|
||||
log("%i\n", bufSize);
|
||||
os_writeEntireFile(arena, DB_FILE_LOCATION, buf, bufSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user