home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: OtherApp / OtherApp.zip / nut-os2.zip / src / options.c < prev    next >
C/C++ Source or Header  |  1998-09-10  |  4KB  |  136 lines

  1. /* options.c */
  2.  
  3. /*
  4.     Nut nutrition software 
  5.     Copyright (C) 1998 Jim Jozwiak.
  6.  
  7.     This program is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. #include "options.h"
  23. #include "food.h"
  24. #include "util.h"
  25. #include "db.h"
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <time.h>
  30.  
  31. struct opt options = {2000,-1};
  32.  
  33. void personal_cal()
  34. {
  35. float buf = 0;
  36. int junk;
  37. header("NUT:  Set Personal Calorie Level");
  38. spacer(0);
  39. printf("\nCalorie level is set to %0.0f.  Type new level (just <enter> for default):  ",Rdi[0]);
  40. get_cals(&buf);
  41. if (buf <= 0)
  42.  {
  43.  buf = 2000;
  44.  Rdi[0] = RdiBase[0];
  45.  Rdi[2] = RdiBase[2];
  46.  Rdi[3] = RdiBase[3];
  47.  Rdi[4] = RdiBase[4];
  48.  Rdi[25] = RdiBase[25];
  49.  Rdi[26] = RdiBase[26];
  50.  Rdi[27] = RdiBase[27];
  51.  Rdi[29] = RdiBase[29];
  52.  Rdi[30] = RdiBase[30];
  53.  options.calopt = RdiBase[0];
  54.  }
  55. else if (buf > 0 && buf <= 100) buf = 100;
  56. else if (buf > 9999) buf = 9999;
  57. buf /= RdiBase[0];
  58. Rdi[0] = buf * RdiBase[0];
  59. Rdi[2] = buf * RdiBase[2];
  60. Rdi[3] = buf * RdiBase[3];
  61. Rdi[4] = buf * RdiBase[4];
  62. Rdi[25] = buf * RdiBase[25];
  63. Rdi[26] = buf * RdiBase[26];
  64. Rdi[27] = buf * RdiBase[27];
  65. Rdi[29] = buf * RdiBase[29];
  66. Rdi[30] = buf * RdiBase[30];
  67. options.calopt = Rdi[0];
  68. write_options_db();
  69. header("NUT:  Set Personal Calorie Level");
  70. printf("\n      New Nutrient Levels:    %-13s %6.1f %-s\n",Nutrient[0],Rdi[0],RdiUnit[0]);
  71. printf("                              %-13s %6.1f %-s\n",Nutrient[3],Rdi[3],RdiUnit[3]);
  72. printf("                              %-13s %6.1f %-s\n",Nutrient[4],Rdi[4],RdiUnit[4]);
  73. printf("                              %-13s %6.1f %-s\n",Nutrient[2],Rdi[2],RdiUnit[2]);
  74. printf("                              %-13s %6.1f %-s\n",Nutrient[25],Rdi[25],RdiUnit[25]);
  75. printf("                              %-13s %6.1f %-s\n",Nutrient[26],Rdi[26],RdiUnit[26]);
  76. printf("                              %-13s %6.1f %-s\n",Nutrient[27],Rdi[27],RdiUnit[27]);
  77. printf("                              %-13s %6.1f %-s\n",Nutrient[29],Rdi[29],RdiUnit[29]);
  78. printf("                              %-13s %6.1f %-s\n",Nutrient[30],Rdi[30],RdiUnit[30]);
  79. spacer(10);
  80. printf("\nPress <enter> to continue...");
  81. junk = get_int();
  82. }
  83.  
  84. void get_cals(float *cals)
  85. {
  86. char buff[128];
  87. gets(buff);
  88. *cals = (float) atof(buff);
  89. }
  90.  
  91. void auto_del()
  92. {
  93. char buf[128];
  94. int junk;
  95. header("NUT:  Automatic Deletion of Meals");
  96. spacer(0);
  97. printf("\nDo you want to have meals deleted automatically from database?  (y/n):  ");
  98. junk = get_char();
  99. if (junk != 'Y' && junk != 'y' && junk != 'N' && junk != 'n') return;
  100. if (junk != 'Y' && junk != 'y')
  101.  {
  102.  header("NUT:  Automatic Deletion of Meals");
  103.  spacer(0);
  104.  options.delopt = -1;
  105.  write_options_db();
  106.  printf("\nMeals will not be deleted automatically.  Press <enter> to continue...");
  107.  junk = get_int();
  108.  return;
  109.  }
  110. junk = 0;
  111. header("NUT:  Automatic Deletion of Meals");
  112. spacer(0);
  113. printf("\nHow many meals should be kept in database?  "); 
  114. while (junk < 1)
  115.  {
  116.  get_string(buf,127);
  117.  junk = atoi(buf);
  118.  if (junk > 0)
  119.   {
  120.   options.delopt = junk;
  121.   write_options_db();
  122.   delete_meals(options.delopt);
  123.   write_meal_db();
  124.   header("NUT:  Automatic Deletion of Meals");
  125.   spacer(0);
  126.   if (junk == 1) printf("\n%d meal will be kept in database.  Press <enter> to continue...",junk); 
  127.   else printf("\n%d meals will be kept in database.  Press <enter> to continue...",junk); 
  128.   junk = get_int();
  129.   return;
  130.   }
  131.  header("NUT:  Automatic Deletion of Meals");
  132.  spacer(0);
  133.  printf("\nMust keep at least one meal in database.  How many?  ");
  134.  }
  135. }
  136.