Annotation of gnutrition/log.h, revision 1.1
1.1 ! asm 1: // SPDX-License-Identifier: GPL-3.0-or-later
! 2: /*
! 3: * $Id$
! 4: *
! 5: * log.h - Food log for GNUtrition
! 6: *
! 7: * Copyright (C) 2026 Free Software Foundation, Inc.
! 8: *
! 9: * Author: Jason Self <jself@gnu.org>
! 10: * Anton McClure <asm@gnu.org>
! 11: */
! 12:
! 13: #ifndef LOG_H
! 14: #define LOG_H
! 15:
! 16: #include <sqlite3.h>
! 17: #include <stddef.h>
! 18:
! 19: /* A single log entry. */
! 20: struct log_entry
! 21: {
! 22: int id;
! 23: int food_code;
! 24: char *description;
! 25: char *date; /* ISO 8601 date string YYYY-MM-DD */
! 26: double servings;
! 27: };
! 28:
! 29: /* A dynamically-sized list of log entries. */
! 30: struct log_list
! 31: {
! 32: struct log_entry *items;
! 33: size_t count;
! 34: size_t capacity;
! 35: };
! 36:
! 37: /* User profile for calorie estimation. Stored in the log database
! 38: so it persists across sessions. The calorie_target is computed
! 39: from the other fields via budget_estimate_calories() and cached
! 40: here so the program can use it without re-prompting. */
! 41: struct user_profile
! 42: {
! 43: int age_years;
! 44: double height_cm;
! 45: double weight_kg;
! 46: int activity_level; /* enum activity_level from budget.h */
! 47: int gender;
! 48: int calorie_target; /* computed and rounded to pattern level */
! 49: };
! 50:
! 51: /* Open (or create) the user's food log database at PATH.
! 52: Returns NULL on failure. */
! 53: sqlite3 *log_open (const char *path);
! 54:
! 55: /* Close the log database. */
! 56: void log_close (sqlite3 *db);
! 57:
! 58: /* Add a food to the log. DATE should be in YYYY-MM-DD format.
! 59: Returns 0 on success, -1 on error. */
! 60: int log_add (sqlite3 *db, int food_code, const char *description,
! 61: const char *date, double servings);
! 62:
! 63: /* Delete a log entry by its ID. Returns 0 on success, -1 on error. */
! 64: int log_delete (sqlite3 *db, int id);
! 65:
! 66: /* Update the servings and date of a log entry identified by ID.
! 67: DATE should be in YYYY-MM-DD format. Returns 0 on success, -1 on
! 68: error. */
! 69: int log_update (sqlite3 *db, int id, const char *date, double servings);
! 70:
! 71: /* Retrieve all log entries for DATE. Returns 0 on success, -1 on
! 72: error. The caller must free the result with log_list_free. */
! 73: int log_get_day (sqlite3 *db, const char *date, struct log_list *results);
! 74:
! 75: /* Free resources held by a log_list. */
! 76: void log_list_free (struct log_list *list);
! 77:
! 78: /* A dynamically-sized list of date strings (YYYY-MM-DD). */
! 79: struct date_list
! 80: {
! 81: char **dates;
! 82: size_t count;
! 83: size_t capacity;
! 84: };
! 85:
! 86: /* Retrieve all distinct dates that have log entries, sorted in
! 87: ascending order. Returns 0 on success, -1 on error. The caller
! 88: must free the result with date_list_free. */
! 89: int log_get_dates (sqlite3 *db, struct date_list *results);
! 90:
! 91: /* Free resources held by a date_list. */
! 92: void date_list_free (struct date_list *list);
! 93:
! 94: /* Save the user's profile to the log database. Only one profile
! 95: row is stored; subsequent calls overwrite the previous one.
! 96: Returns 0 on success, -1 on error. */
! 97: int log_save_profile (sqlite3 *db, const struct user_profile *profile);
! 98:
! 99: /* Load the user's profile from the log database. Returns 0 on
! 100: success, 1 if no profile exists yet, -1 on error. */
! 101: int log_get_profile (sqlite3 *db, struct user_profile *profile);
! 102:
! 103: #endif /* LOG_H */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>