home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / busi / nojcb.zip / CBMAIN.INC < prev   
Text File  |  1989-09-09  |  29KB  |  620 lines

  1. /*----------------------------------------------------------------------------
  2.  *  File:     CBMAIN.INC  (in Turbo C 1.5)
  3.  *
  4.  *  Purpose:  Provides functions and structures for CB.
  5.  *
  6.  *  Author:   Steven "Noji" Ratzlaff
  7.  *
  8.  *  Date:     09 Sep 1989
  9.  *--------------------------------------------------------------------------*/
  10.   struct      EntryPrompt
  11.               {
  12.                 char    msg[MSG_LEN];
  13.                 char    var[LINE_LIM];
  14.               } input[] =
  15.               {
  16.                 { "Check or Item:",              0 },
  17.                 { "Date:",                       0 },
  18.                 { "Amount:",                     0 },
  19.                 { "Purpose:",                    0 },
  20.                 0
  21.               };
  22.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  23.   struct      Record                   /* record of each transaction        */
  24.               {
  25.                 int     ind;                /* index number of the record   */
  26.                 char    check[INPUT_SP];    /* check number / xaction type  */
  27.                 char    date[INPUT_SP];     /* date of transaction          */
  28.                 char    amt[INPUT_SP];      /* amount                       */
  29.                 char    pur[MSG_LEN];       /* purpose of transaction       */
  30.                 char    bal[INPUT_SP];      /* balance after transaction    */
  31.                 struct Record
  32.                         *next;              /* pointer to the next record   */
  33.               } *head,
  34.                 *tail,
  35.                 *cur;
  36.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37.   char        *func_key[] =
  38.               {
  39.                 "WordPerfect",         /*  F1  */
  40.                 "DEP",                 /*  F2  */
  41.                 "VIS",                 /*  F3  */
  42.                 "UCC",                 /*  F4  */
  43.                 "Loan Payment",        /*  F5  */
  44.                 "Food-4-Less",         /*  F6  */
  45.                 "Albertsons",          /*  F7  */
  46.                 "Dr. Myers",           /*  F8  */
  47.                 "Visa Credit Payment", /*  F9  */
  48.                 "Tithing",             /*  F10 */
  49.                 0
  50.               };
  51.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  52.   int         nmonth[] =
  53.                 { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  54.   char        *month[] =
  55.                 {
  56.                   "XXX", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  57.                   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  58.                 };
  59. /*--------------------------------------------------------------------------*/
  60. main(argc, argv)                       /* CB                                */
  61.   int         argc;
  62.   char        **argv;
  63. {
  64.   struct ffblk
  65.               block;                   /* structure of file attributes      */
  66.   int         yn = 0;                  /* yes or no?                        */
  67.   char        *acct = *++argv,         /* account file name                 */
  68.               filepath[MAX_PATH];      /*    "      "  pathname             */
  69.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  70.   strcpy(filepath, CB_DIR);            /* specify the directory of the path */
  71.   if (argc == 2)
  72.   {
  73.     beg_bal[0] = last_check[0] = '\0'; /* initialize all global variables   */
  74.     for (yn = 0; yn < ELEMENTS; yn++)
  75.       input[yn].var[0] = '\0';
  76.     yn = 0;
  77.     head = tail = cur = NULL;
  78.     prompt = getenv("PROMPT");
  79.     strcat(filepath, strupr(acct));
  80.     strcat(filepath, ".CB");
  81.     if (findfirst(filepath, &block, 0) == 0)     /* if the file exists      */
  82.       transact(filepath, yn);                    /*   transact business     */
  83.     else
  84.     {
  85.       printf("  *** Account '%s' not found\n%s", acct,
  86.              "      Create a new account?  ");
  87.       while (yn != 'y' && yn != 'n')
  88.         yn = tolower(getch());
  89.       if (yn == 'y')
  90.       {
  91.         printf("\n      Enter the beginning balance:  ");
  92.         gets(beg_bal);
  93.         transact(filepath, yn);
  94.       }
  95.     }
  96.   }                                    /* end of if (argc == 2) ...         */
  97.   else
  98.   {
  99.     printf("%s\n\n", Version);
  100.     directory(FALSE);                  /* display the account directory     */
  101.   }
  102.   return 0;                            /* successful completion             */
  103. }                                      /* end of main()                     */
  104. /*----------------------------------------------------------------------------
  105.  *  before_date():  Determines whether date1 is chronologically before date2.
  106.  *            Both dates must be properly formatted beforehand.
  107.  *--------------------------------------------------------------------------*/
  108.   int
  109. before_date(date1, date2)
  110.   char        *date1,                  /* the date to test                  */
  111.               *date2;                  /* the date in question              */
  112. {
  113.   char        c_day1[INPUT_SP],        /* the day string                    */
  114.               c_day2[INPUT_SP],        /*  "   "     "                      */
  115.               c_month1[INPUT_SP],      /*  "  month  "                      */
  116.               c_month2[INPUT_SP],      /*  "    "    "                      */
  117.               c_year1[INPUT_SP],       /*  "  year   "                      */
  118.               c_year2[INPUT_SP];       /*  "    "    "                      */
  119.   long        total1,                  /* the composite of date1            */
  120.               total2;                  /*  "      "      " date2            */
  121.   int         i_day1,                  /* the day number                    */
  122.               i_day2,                  /*  "   "     "                      */
  123.               i_month1,                /*  "  month  "                      */
  124.               i_month2,                /*  "    "    "                      */
  125.               i_year1,                 /*  "  year   "                      */
  126.               i_year2,                 /*  "    "    "                      */
  127.               i;                       /* arbitrary counter                 */
  128.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  129.   strncpy(c_day1, date1, 2);           /* get the days                      */
  130.   strncpy(c_day2, date2, 2);
  131.   c_day1[2] = c_day2[2] = '\0';
  132.   i_day1 = atoi(c_day1);
  133.   i_day2 = atoi(c_day2);
  134.  
  135.   strcpy(c_month1, date1);             /* get the months                    */
  136.   strcpy(c_month2, date2);
  137.   for (i = 0; i < 3; i++)
  138.   {
  139.     c_month1[i] = c_month1[i + 3];
  140.     c_month2[i] = c_month2[i + 3];
  141.   }
  142.   c_month1[3] = c_month2[3] = '\0';
  143.   for (i = 1; i < 13; i++)
  144.   {
  145.     if (stricmp(c_month1, month[i]) == 0)
  146.       i_month1 = i;
  147.     if (stricmp(c_month2, month[i]) == 0)
  148.       i_month2 = i;
  149.   }
  150.  
  151.   strcpy(c_year1, date1);              /* get the years                     */
  152.   strcpy(c_year2, date2);
  153.   for (i = 0; i < 2; i++)
  154.   {
  155.     c_year1[i] = c_year1[i + 7];
  156.     c_year2[i] = c_year2[i + 7];
  157.   }
  158.   c_year1[2] = c_year2[2] = '\0';
  159.   i_year1 = atoi(c_year1);
  160.   i_year2 = atoi(c_year2);
  161.  
  162.   total1 = (long) i_day1 + (long) i_month1 * 100L + (long) i_year1 * 10000L;
  163.   total2 = (long) i_day2 + (long) i_month2 * 100L + (long) i_year2 * 10000L;
  164.  
  165.   return (total1 < total2);
  166. }                                      /* end of before_date()              */
  167. /*----------------------------------------------------------------------------
  168.  *  clear_line():  Clears the line from the current cursor pos to the end.
  169.  *--------------------------------------------------------------------------*/
  170.   void
  171. clear_line(xpos)
  172.   int         xpos;
  173. {
  174.   while (++xpos < 70)
  175.     printf(" ");
  176. }                                      /* end of clear_line()               */
  177. /*----------------------------------------------------------------------------
  178.  *  directory():  Displays a directory listing by account names.
  179.  *--------------------------------------------------------------------------*/
  180.   void
  181. directory(menucall)
  182.   int         menucall;                /* called from the main menu ?       */
  183. {
  184.   struct ffblk
  185.               block;                   /* structure of file sttributes      */
  186.   int         done,                    /* is the directory search done?     */
  187.               cols = 0;                /* columns of display shown          */
  188.   char        drive[MAXDRIVE],         /* space for the drive name          */
  189.               dir[MAXDIR],             /*   "    "   "  directory name      */
  190.               fname[MAXFILE],          /*   "    "   "  file name           */
  191.               ext[MAXEXT];             /*   "    "   "  extension name      */
  192.   char        filepath[MAX_PATH];      /*    "      "  pathname             */
  193.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  194.   strcpy(filepath, CB_DIR);            /* specify the directory of the path */
  195.   printf("      Accounts available:\n\n");
  196.   strcat(filepath, "*.CB");
  197.   done = findfirst(filepath, &block, 0);         /* grab the 1st file       */
  198.   if (!done)
  199.   {
  200.     while (!done)                      /* as long as there are files here   */
  201.     {
  202.       fnsplit(block.ff_name, drive, dir, fname, ext);
  203.       printf("              %-8s", fname);
  204.       if (++cols == 3)
  205.         cols = printf("\n") - 1;
  206.       done = findnext(&block);         /* grab the next filename            */
  207.       if (done && cols)
  208.         printf("\n");
  209.     }                                  /* end of while (!done)              */
  210.   }                                    /* end of if (!done)                 */
  211.   else
  212.     printf("      <None available>\n");
  213.   if (menucall)
  214.     pause();
  215. }                                      /* end of directory()                */
  216. /*----------------------------------------------------------------------------
  217.  *  get_char():  Grabs a keyboard character.  This function was made to catch
  218.  *            function keys on MS-DOS machines.
  219.  *--------------------------------------------------------------------------*/
  220.   int
  221. get_char()
  222. {
  223.   int         c;                       /* the character to return           */
  224.   static union REGS
  225.               rg;
  226.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  227.   while (TRUE)                         /* infinite loop                     */
  228.   {
  229.     rg.h.ah = 1;
  230.     int86(0x16, &rg, &rg);             /* ah = 1, int 16H : keyboard status */
  231.     if (rg.x.flags & 0x40)             /* if zero flag (key stroke) is set  */
  232.     {
  233.       int86(0x28, &rg, &rg);           /*   DOSOK interrupt                 */
  234.       continue;                        /*   jump to beginning of loop       */
  235.     }
  236.     rg.h.ah = 0;
  237.     int86(0x16, &rg, &rg);             /* ah = 0, int 16H : read character  */
  238.     if (rg.h.al == 0)                  /* if a function key is detected     */
  239.       c = rg.h.ah | 128;               /*   give it an ASCII value          */
  240.     else
  241.       c = rg.h.al;
  242.     break;
  243.   }
  244.   return c;                            /* return the character              */
  245. }                                      /* end of get_char()                 */
  246. /*----------------------------------------------------------------------------
  247.  *  get_cursor():  Retrieves the current cursor position.
  248.  *--------------------------------------------------------------------------*/
  249.   void
  250. get_cursor(x, y)
  251.   int         *x,
  252.               *y;
  253. {
  254.   static union REGS
  255.               rg;
  256.  
  257.   rg.x.ax = 0x0300;
  258.   rg.x.bx = 0;
  259.   int86(0x10, &rg, &rg);               /* ah = 3, int 10H : get cursor pos  */
  260.   *x = rg.h.dl;                        /* x points to the x position        */
  261.   *y = rg.h.dh;                        /* y   "     "  "  y    "            */
  262. }                                      /* end of get_cursor()               */
  263. /*----------------------------------------------------------------------------
  264.  *  get_todays_date():  Retrieves today's date from DOS and formats it into a
  265.  *            string for use in data entry.
  266.  *--------------------------------------------------------------------------*/
  267.   void
  268. get_todays_date(str)
  269.   char        *str;
  270. {
  271.   struct date today;                   /* current DOS date structure        */
  272.   char        daynum[INPUT_SP],        /* today's date in a string          */
  273.               year[INPUT_SP];          /* this year in string form          */
  274.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  275.   getdate(&today);                     /* grab the current date             */
  276.   itoa(today.da_day, daynum, DEC);               /* convert days to string  */
  277.   itoa(today.da_year, year, DEC);                /*    "    years "    "    */
  278.   if (today.da_day < DEC)                        /* leading zeroes in day   */
  279.   {
  280.     daynum[1] = daynum[0];
  281.     daynum[0] = '0';
  282.     daynum[2] = '\0';
  283.   }
  284.   year[0] = year[2];
  285.   year[1] = year[3];
  286.   year[2] = '\0';
  287.   strcpy(str, daynum);                           /* concat the day string   */
  288.   strcat(str, "-");                              /*   tack on a dash        */
  289.   strcat(str, month[today.da_mon]);              /* attach the month name   */
  290.   strcat(str, "-");                              /*   put on another dash   */
  291.   strcat(str, year);                             /* finally stick the year  */
  292. }                                      /* end of get_todays_date()          */
  293. /*----------------------------------------------------------------------------
  294.  *  increment_date():  Increments the month or day.  The day string must have
  295.  *            been properly formatted.
  296.  *--------------------------------------------------------------------------*/
  297.   void
  298. increment_date(date, inc)
  299.   char        *date;                   /* date string to increment          */
  300.   int         inc;                     /* increment type                    */
  301. {
  302.   int         i,                       /* arbitrary counter                 */
  303.               n_day,                   /* day number                        */
  304.               n_month,                 /* month number                      */
  305.               n_year;                  /* year number                       */
  306.   char        date_copy1[INPUT_SP],    /* a copy of the date string         */
  307.               date_copy2[INPUT_SP],    /* another one                       */
  308.               date_copy3[INPUT_SP];    /* and yet another                   */
  309.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  310.   strcpy(date_copy1, date);
  311.   strcpy(date_copy2, date);
  312.   strcpy(date_copy3, date);
  313.   date_copy1[2] = '\0';
  314.   n_day = atoi(date_copy1);
  315.   for (i = 0; i < 3; i++)
  316.     date_copy2[i] = date_copy2[i + 3];
  317.   date_copy2[3] = '\0';
  318.   for (i = 1; i < 13; i++)
  319.     if (stricmp(date_copy2, month[i]) == 0)
  320.       n_month = i;
  321.   for (i = 0; i < 2; i++)
  322.     date_copy3[i] = date_copy3[i + 7];
  323.   date_copy3[2] = '\0';
  324.   n_year = atoi(date_copy3);
  325.   switch (inc)
  326.   {
  327.     case  UP   :   if (++n_day > nmonth[n_month])
  328.                    {
  329.                      n_day = 1;
  330.                      if (++n_month > 12)
  331.                      {
  332.                        n_month = 1;
  333.                        n_year++;
  334.                      }
  335.                    }
  336.                    break;
  337.     case  DN   :   if (--n_day == 0)
  338.                    {
  339.                      if (n_month > 1)
  340.                        n_month--;
  341.                      else
  342.                      {
  343.                        n_month = 12;
  344.                        n_year--;
  345.                      }
  346.                      n_day = nmonth[n_month];
  347.                    }
  348.                    break;
  349.     case  PGUP :   if (++n_month > 12)
  350.                    {
  351.                      n_month = 1;
  352.                      n_year++;
  353.                    }
  354.                    break;
  355.     case  PGDN :   if (--n_month < 1)
  356.                    {
  357.                      n_month = 12;
  358.                      n_year--;
  359.                    }
  360.     default    :   break;
  361.   }                                    /* end of switch (inc)               */
  362.   itoa(n_day, date_copy1, DEC);
  363.   if (n_day < DEC)                               /* leading zeroes in day   */
  364.   {
  365.     date_copy1[1] = date_copy1[0];
  366.     date_copy1[0] = '0';
  367.     date_copy1[2] = '\0';
  368.   }
  369.   strcat(date_copy1, "-");
  370.   strcat(date_copy1, month[n_month]);
  371.   strcat(date_copy1, "-");
  372.   itoa(n_year, date_copy3, 10);
  373.   strcat(date_copy1, date_copy3);
  374.   strcpy(date, date_copy1);
  375. }                                      /* end of increment_date()           */
  376. /*----------------------------------------------------------------------------
  377.  *  instructions():  Displays the set of instructions required to run this
  378.  *            program.
  379.  *--------------------------------------------------------------------------*/
  380.   void
  381. instructions()
  382. {
  383.   clrscr();
  384.   printf("                      CB: The Ratzlaff Checkbook Program\n\n"
  385.   "     Access to all functions in     For the 'Date' prompt:\n"
  386.   "CB is through the main menu.  The     Up Arrow / Down Arrow: Increments\n"
  387.   "functions are self-explanatory          and decrements the day number.\n"
  388.   "except for the E>nter option.         PgUp / PgDn: Increments and\n"
  389.   "     After calling the E>nter           decrements the month.\n"
  390.   "function, the most recent trans-      End: Toggles between the most\n"
  391.   "action will be displayed.  Then         recent date and today's date.\n"
  392.   "CB will prompt the user for each    For all prompts:\n"
  393.   "of the four information elements,     Home: Clears the line and restarts\n"
  394.   "displaying the next expected check      from beginning.\n"
  395.   "number and the most recently          Backspace / Left Arrow: Moves\n"
  396.   "entered date.                           cursor to the left, erasing.\n"
  397.   "     While being prompted, the        Space / Right Arrow: Spaces.\n"
  398.   "user may enter and edit characters    Delete: Cancels the line and moves\n"
  399.   "and numbers as needed.  A few           to the next prompt.\n"
  400.   "special features are included to      Function Keys: Places predefined\n"
  401.   "aid the user in editing and they        strings at the prompt.\n"
  402.   "are explained here.                   Enter: Accepts the input line.\n\n"
  403.   "     The keyword 'DEP' in the 'Check' section indicates a credit to the\n"
  404.   "account; any other string is assumed to be a debit.\n");
  405.   pause();
  406. }                                      /* end of instructions()             */
  407. /*----------------------------------------------------------------------------
  408.  *  num_format():  Formats a string that has been converted from a floating
  409.  *            point value into one compatible with this program.
  410.  *--------------------------------------------------------------------------*/
  411.   void
  412. num_format(str)
  413.   char        *str;
  414. {
  415.   int         ind,                     /* index into the array              */
  416.               point = 0;               /* index to the decimal point        */
  417.   char        new[INPUT_SP];           /* new array for floating pt number  */
  418.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  419.   for (ind = 0; str[ind]; ind++)       /* ind == string length              */
  420.     if (str[ind] == '.')
  421.       point = ind;
  422.   if (point == 0)
  423.     if (str[0] == '.')                 /* decimal point is at the beginning */
  424.     {
  425.       strcpy(new, "0");
  426.       strcat(new, str);
  427.       if (ind == 2)
  428.         strcat(new , "0");
  429.       strcpy(str, new);
  430.     }
  431.     else                               /* no decimal point present          */
  432.       strcat(str, ".00");
  433.   else                                 /* decimal point next to last        */
  434.     if (point == ind - 2)
  435.       strcat(str, "0");
  436. }                                      /* end of num_format()               */
  437. /*----------------------------------------------------------------------------
  438.  *  pause():  Pauses until <Space> is pressed.
  439.  *--------------------------------------------------------------------------*/
  440.   void
  441. pause()
  442. {
  443.   printf("\nPress <Space> to continue ");
  444.   while (getch() != SP)
  445.     ;
  446. }                                      /* end of pause()                    */
  447. /*----------------------------------------------------------------------------
  448.  *  read_string():  Reads a string from the keyboard into a buffer.  This
  449.  *            replaces scanf() and gets() for this specific application.
  450.  *--------------------------------------------------------------------------*/
  451.   int
  452. read_string(buff)
  453.   char        *buff;                   /* the input buffer                  */
  454. {
  455.   int         c = 0,                   /* the retrieved character           */
  456.               ind;                     /* array indexd                      */
  457.   int         xcur,                    /* original x position               */
  458.               ycur,                    /*     "    y    "                   */
  459.               xpos,                    /* current x position                */
  460.               ypos;                    /*    "    y     "                   */
  461.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  462.   ind = strlen(buff);                  /* use old string length as offset   */
  463.   get_cursor(&xcur, &ycur);            /* get original cursor position      */
  464.   xcur -= ind;
  465.   xpos = xcur + ind;
  466.   ypos = ycur;
  467.   while (c != ESC && c != RET && c != DEL && c != END &&
  468.          c != UP && c != DN && c != PGUP && c != PGDN)
  469.   {
  470.     set_cursor(xpos, ypos);            /* place the cursor at the curr pos  */
  471.     c = get_char();                    /* grab a character from the kbd     */
  472.     switch (c)
  473.     {
  474.       case  BS   :
  475.       case  LEFT : if (ind > 0)
  476.                    {
  477.                      buff[--ind] = '\0';         /*   erase one char        */
  478.                      set_cursor(--xpos, ycur);   /*   reset cursor one back */
  479.                      printf(" ");                /*   display the space     */
  480.                    }
  481.                    else
  482.                      ind = 0;
  483.                    break;
  484.       case  HOME : buff[ind=0] = '\0';            /*   clear the string     */
  485.       case  END  :
  486.       case  UP   :
  487.       case  DN   :
  488.       case  PGUP :
  489.       case  PGDN : set_cursor(xpos=xcur, ycur);   /*   reset cursor         */
  490.                    clear_line(xcur);              /*   clear to end of line */
  491.                    break;
  492.       case  RGT  : c = SP;                        /* right arrow == space   */
  493.                    break;
  494.       case  F1   : case  F2   :                   /* function keys          */
  495.       case  F3   : case  F4   :
  496.       case  F5   : case  F6   :
  497.       case  F7   : case  F8   :
  498.       case  F9   : case  F10  :   if (ind == 0)
  499.                                     strcpy(buff, func_key[c - F1]);
  500.                                   else
  501.                                     strcat(buff, func_key[c - F1]);
  502.                                   clear_line(xpos);
  503.                                   xpos += strlen(func_key[c - F1]);
  504.                                   ind += strlen(func_key[c - F1]);
  505.                                   break;
  506.       default    : break;
  507.     }                                  /* end of switch (c)                 */
  508.     if (isprint(c) && c != DELIM)      /* if c is a printable character     */
  509.     {
  510.       if (ind == LINE_LIM)             /*   prevent strings being too long  */
  511.         printf("\a");
  512.       else
  513.       {
  514.         buff[ind++] = c;               /*   add the character here          */
  515.         buff[ind] = '\0';              /*   and terminate the string        */
  516.         xpos++;                        /*   update the cursor               */
  517.         if (ind == 1)
  518.           clear_line(xpos);            /*   clear other characters          */
  519.       }
  520.     }
  521.     set_cursor(xcur, ycur);            /* move the cursor back to the start */
  522.     printf(buff);                      /* print the string out              */
  523.   }                                    /* end of while (c != )...           */
  524.   if (c == RET && strlen(buff) == 0)
  525.     c = DEL;
  526.   if (c == DEL)
  527.   {
  528.     strcpy(buff, "***");
  529.     clear_line(xcur);
  530.   }
  531.   set_cursor(xcur, ycur);              /* move the cursor back to the start */
  532.   return c;                            /* return the delimiter              */
  533. }                                      /* end of read_string()              */
  534. /*----------------------------------------------------------------------------
  535.  *  repeat_entry():  Prompts the user for input until only a carriage return
  536.  *            is entered, after which the string is converted to a double.
  537.  *--------------------------------------------------------------------------*/
  538.   void
  539. repeat_entry(str, val)
  540.   char        *str;                    /* buffer for string input           */
  541.   double      *val;                    /* total of the double values        */
  542. {
  543.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  544.   *val = 0.0;                          /* initialize the double total       */
  545.   do {
  546.     printf("  -->  ");                 /* prompt                            */
  547.     gets(str);                         /* entry                             */
  548.     if (str[0])                        /* if an entry was made              */
  549.       *val += atof(str);               /*   add it to the total             */
  550.   } while (str[0]);
  551. }                                      /* end of repeat_entry()             */
  552. /*----------------------------------------------------------------------------
  553.  *  save():  Writes the entire list to the account file.
  554.  *--------------------------------------------------------------------------*/
  555.   void
  556. save(fname)
  557.   char        *fname;                  /* file to save the list to          */
  558. {
  559.   FILE        *fp;                     /* pointer to the file               */
  560.   int         wrong = TRUE;            /* error condition present           */
  561.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  562.   gotoxy(1, CURSOR);
  563.   if (head != NULL)
  564.     if (fp = fopen(fname, "w"))
  565.     {
  566.       printf("  Saving the account to the disk\n");
  567.       wrong = FALSE;
  568.       for (cur = head; cur != NULL; cur = cur->next)
  569.         fprintf(fp, "%s:%s:%s:%s:%s:\n",
  570.                 cur->check, cur->date, cur->amt, cur->pur, cur->bal);
  571.       fclose(fp);
  572.     }
  573.     else
  574.       printf("  *** File '%s' could not be written to\n", fname);
  575.   else
  576.     printf("  *** No data present to save\n");
  577.   if (wrong)
  578.     pause();
  579. }                                      /* end of save()                     */
  580. /*----------------------------------------------------------------------------
  581.  *  set_cursor():  Sets the current cursor position.
  582.  *--------------------------------------------------------------------------*/
  583.   void
  584. set_cursor(x, y)
  585.   int         x,
  586.               y;
  587. {
  588.   static union REGS
  589.               rg;
  590.  
  591.   rg.x.ax = 0x0200;
  592.   rg.x.bx = 0;
  593.   rg.x.dx = ((y << 8) & 0xff00) + x;   /* calculate the position by dx      */
  594.   int86(0x10, &rg, &rg);               /* ah = 2, int 10H : set cursor pos  */
  595. }                                      /* end of set_cursor()               */
  596. /*----------------------------------------------------------------------------
  597.  *  shell_out():  Creates a temporary shell out to DOS.
  598.  *--------------------------------------------------------------------------*/
  599.   void
  600. shell_out()
  601. {
  602.   char        prompt_add[MAX_PATH],    /* addition to the prompt            */
  603.               path[MAX_PATH];          /* path of the current working dir   */
  604.   /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  605.   getcwd(path, MAX_PATH);
  606.   strcpy(prompt_add, "PROMPT=");
  607.   strcat(prompt_add, "(CB Shell)  ");
  608.   strcat(prompt_add, prompt);
  609.   putenv(prompt_add);
  610.   printf("Enter 'Exit' to return to CB");
  611.   spawnl(P_WAIT, "c:\\command.com", "c:\\command.com", NULL);
  612.   strcpy(prompt_add, "PROMPT=");
  613.   strcat(prompt_add, prompt);
  614.   putenv(prompt_add);
  615.   chdir(path);
  616. }                                      /* end of shell_out()                */
  617. /*----------------------------------------------------------------------------
  618.  *  End of CBMAIN.INC
  619.  *--------------------------------------------------------------------------*/
  620.