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

  1. /* util.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 "util.h"
  23. #include <string.h>
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26.             
  27. char KeyArray[366];
  28. char *Key[] = {KeyArray, KeyArray + 61, KeyArray + 122, KeyArray + 183, KeyArray + 244, KeyArray + 305};
  29.  
  30. int get_char()
  31. {
  32. int ch;
  33. int junk;
  34. ch = getchar();
  35. if ( ch == '\n' ) return (ch);
  36. while ( (junk = getchar() ) != '\n' );
  37. return ch;    
  38. }
  39.  
  40. void get_qty(float *result, float *grams)
  41. {
  42. char buff[128];
  43. gets(buff);
  44. if (strchr(buff,'g') != NULL) *result = ((float) (atof(buff) / *grams));
  45. else if (strchr(buff,'o') != NULL) *result = ((float) (atof(buff) * 28.35 / *grams));
  46. else if (strchr(buff,'b') != NULL || strchr(buff,'B') != NULL) *result = -38;
  47. else *result = ((float) atof(buff));
  48. }
  49.  
  50. int get_int()
  51. {
  52. char buff[128];
  53. gets(buff);
  54. return (atoi(buff));
  55. }
  56.  
  57. void get_string(char *dest, int length)
  58. {
  59. char temp[128];
  60. gets(temp);
  61. strncpy(dest,temp,length);
  62. dest[length-1] = '\0';
  63. }
  64.  
  65. void header(char *string)
  66. {
  67. char buffer[81];
  68. int count;
  69. size_t size = 80;
  70. size -= strlen(string);
  71. size /= 2;
  72. for (count = 0 ; count < size ; count++) buffer[count] = ' '; 
  73. buffer[count] = '\0';
  74. printf("\033[2J%s%s\n\n",buffer,string);
  75. }
  76.  
  77. void spacer(int lines)
  78. {
  79. lines = 20 - lines;
  80. for ( ; lines > 0 ; lines--) printf("\n");
  81. }
  82.  
  83. void key_clean()
  84. {
  85. int i;
  86. for (i = 0 ; i < 6 ; i++) strcpy(Key[i],"");
  87. }
  88.  
  89. void key_put(char *key)
  90. {
  91. int i;
  92. for (i = 4 ; i >= 0 ; i--) strcpy(Key[i+1],Key[i]);
  93. strcpy(Key[0],key);
  94. }
  95.  
  96. char *key_take()
  97. {
  98. static char key[61];
  99. int i;
  100. strcpy(key,Key[0]);
  101. for (i = 0 ; i < 5 ; i++) strcpy(Key[i],Key[i+1]); 
  102. strcpy(Key[5],"");
  103. return key;
  104. }
  105.