--- gnutrition/main.c 2026/05/08 03:23:59 1.1 +++ gnutrition/main.c 2026/05/12 21:50:01 1.5 @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later /* - * $Id: main.c,v 1.1 2026/05/08 03:23:59 asm Exp $ + * $Id: main.c,v 1.5 2026/05/12 21:50:01 asm Exp $ * * main.c - Entry point for GNUtrition * @@ -46,8 +46,8 @@ static const struct option long_options[ {"age", required_argument, NULL, 'a'}, {"height", required_argument, NULL, 'H'}, {"weight", required_argument, NULL, 'w'}, - {"activity", required_argument, NULL, 'A'}, {"gender", required_argument, NULL, 'G'}, + {"activity", required_argument, NULL, 'A'}, {"date", required_argument, NULL, 'd'}, {"db", required_argument, NULL, 'D'}, {"profile-db", required_argument, NULL, 'P'}, @@ -89,21 +89,19 @@ print_help (void) "(for calorie estimation)\n")); printf (_(" -H, --height=CM your height in centimeters\n")); printf (_(" -w, --weight=KG your weight in kilograms\n")); + printf (_(" -G, --gender=NAME neutral, female, or male\n")); printf (_(" -A, --activity=LEVEL activity level: sedentary, light,\n")); - printf (_(" moderate, very-active, " - "or extra-active\n")); + printf (_(" moderate, very-active, or extra-active\n")); printf (_(" -d, --date=DATE date for log/budget " "(default: today)\n")); - printf (_(" -D, --db=PATH path to food database " - "(default: food.db)\n")); + printf (_(" -D, --db=PATH path to food database (default: food.db)\n")); printf (_(" -P, --profile-db=PATH\n")); printf (_(" path to profile/log database\n")); - printf (_(" (default: " - "$XDG_DATA_HOME/gnutrition/log.db)\n")); + printf (_(" (default: $XDG_DATA_HOME/gnutrition/log.db)\n")); printf (_(" -h, --help display this help and exit\n")); printf (_(" -V, --version output version information and exit\n")); - printf (_("\nWhen --age, --height, --weight, and --activity are all given,\n")); - printf (_("the calorie target is estimated using the Mifflin-St Jeor\n")); + printf (_("\nWhen --age, --height, --weight, --gender and --activity are all\n")); + printf (_("given, the calorie target is estimated using the Mifflin-St Jeor\n")); printf (_("equation and saved to your profile for future sessions.\n")); printf (_("Use --calories to override the computed estimate.\n")); printf (_("\nThe calorie level determines your daily food-group budget\n")); @@ -462,8 +460,8 @@ main (int argc, char **argv) int profile_age; double profile_height; double profile_weight; + int profile_gender; /* neutral, female, male */ int profile_activity; - int profile_gender; int profile_given; /* bitmask: 1=age, 2=height, 4=weight, 8=activity */ int mode; /* 0 = interactive, 1 = search, 2 = info, 3 = log, 4 = budget, 5 = delete, 6 = edit */ @@ -496,8 +494,8 @@ main (int argc, char **argv) profile_age = 0; profile_height = 0.0; profile_weight = 0.0; - profile_activity = ACTIVITY_SEDENTARY; profile_gender = GENDER_NEUTRAL; + profile_activity = ACTIVITY_SEDENTARY; profile_given = 0; mode = 0; delete_id = 0; @@ -508,7 +506,7 @@ main (int argc, char **argv) log_db = NULL; exit_status = 0; - while ((c = getopt_long (argc, argv, "hVs:i:l:n:x:e:bc:a:H:w:A:d:D:P:", + while ((c = getopt_long (argc, argv, "hVs:i:l:n:x:e:bc:a:H:w:A:G:d:D:P:", long_options, NULL)) != -1) { switch (c) @@ -612,6 +610,18 @@ main (int argc, char **argv) profile_given |= 4; break; + case 'G': + profile_gender = parse_gender (optarg); + if (profile_gender < 0) + { + fprintf (stderr, _("%s: unknown gender '%s'\n"), + PROGRAM_NAME, optarg); + fprintf (stderr, _("Valid options: neutral, female, male\n")); + return 1; + } + profile_given |= 7; + break; + case 'A': profile_activity = parse_activity (optarg); if (profile_activity < 0) @@ -625,17 +635,6 @@ main (int argc, char **argv) profile_given |= 8; break; - case 'G': - profile_gender = parse_gender (optarg); - if (profile_gender < 0) - { - fprintf (stderr, _("%s: unknown gender '%s'\n"), - PROGRAM_NAME, optarg); - fprintf (stderr, _("Valid options: neutral, female, male\n")); - return 1; - } - break; - case 'd': date = optarg; edit_date_given = 1; @@ -735,13 +734,13 @@ main (int argc, char **argv) prof.age_years = profile_age; prof.height_cm = profile_height; prof.weight_kg = profile_weight; - prof.activity_level = profile_activity; prof.gender = profile_gender; + prof.activity_level = profile_activity; prof.calorie_target = budget_estimate_calories (profile_age, profile_height, profile_weight, - profile_activity, - profile_gender); + profile_gender, + profile_activity); if (log_save_profile (log_db, &prof) < 0) fprintf (stderr, _("%s: warning: could not save profile\n"), PROGRAM_NAME); @@ -754,7 +753,7 @@ main (int argc, char **argv) } else if (profile_given != 0) { - fprintf (stderr, _("%s: --age, --height, --weight, and --activity " + fprintf (stderr, _("%s: --age, --height, --weight, --gender, and --activity " "must all be given together\n"), PROGRAM_NAME); log_close (log_db); db_close (food_db);