home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 December / simtel1292_SIMTEL_1292_Walnut_Creek.iso / msdos / deskaces / reminder.arc / EVENT.C next >
C/C++ Source or Header  |  1989-12-03  |  5KB  |  186 lines

  1. /* event.c: Make an entry in the dates file for reminder, using
  2.  * full-screen input editing.
  3.  *
  4.  * This version is for MS-DOS only, using the CXL library (v5.0).
  5.  *
  6.  * By Richard J. Reiner, rreiner@vm1.yorku.ca (BITNET),
  7.  * grad3077@writer.yorku.ca (Internet).  2 Dec 89.
  8.  *
  9.  * Derived from remind.c by Ken Van Camp, ARDEC, October 1987.
  10.  *
  11.  *
  12.  * exit codes:    0 -- normal completion
  13.  *                1 -- error opening reminders file
  14.  *                2 -- user abort
  15.  *
  16.  *
  17.  * event leaves the screen undisturbed: it pops up, and restores
  18.  * the obscured area on exit.  this is intended for applications
  19.  * like the following batch file:
  20.  *
  21.  *        echo off
  22.  *        cls
  23.  *        cal
  24.  *        event
  25.  *
  26.  * where cal is like the *nix utility of the same name (which shows
  27.  * the current month's calendar when called w/o parms).  This batch
  28.  * file leaves the calendar visible while the user is in event.
  29.  *
  30.  */
  31.  
  32. /*
  33.  *    11-18-89    RjR        Port of remind.c to MS C.  Uses ".\dates".
  34.  *  12-02-89    RjR        Renamed to event.c; calls to getdata() and
  35.  *                        getdata() itself replaced with CXL code;
  36.  *                        output fixed to not leave a space after the
  37.  *                        time if the time is blank.
  38.  */
  39.  
  40. #define DATEFILE ".\\dates"
  41.  
  42. #include <fcntl.h>
  43. #include <stdio.h>
  44. #include <string.h>
  45.  
  46. #include <cxl\cxldef.h>
  47. #include <cxl\cxlvid.h>
  48. #include <cxl\cxlwin.h>
  49. #include <cxl\cxlstr.h>
  50.  
  51. int fsread(void);
  52. void initcxl(void);
  53. int validnocolon(char *);
  54. char *strrtrim(char *);
  55.  
  56. FILE    *fd;
  57. char    line[256],
  58.         event[128],
  59.         person[128],
  60.         tim[20],
  61.         dat[30],
  62.         ndays[10];
  63.  
  64.  
  65. main(int argc,char **argv)
  66. {
  67.     if (argc > 1)
  68.     {
  69.         if ((fd = fopen (argv[1], "a")) == NULL)
  70.         {
  71.             fprintf(stderr,"event: error: can't open file '%s'\n",argv[1]);
  72.             exit(1);
  73.         }
  74.     }
  75.     else
  76.     {
  77.         if ((fd = fopen (DATEFILE, "a")) == NULL)
  78.         {
  79.             fprintf(stderr,"event: error: can't open file '%s'\n",DATEFILE);
  80.             exit(1);
  81.         }
  82.     }
  83.  
  84.     initcxl();
  85.  
  86.     if (fsread() != W_ESCPRESS)
  87.         if (*tim != '\0')
  88.             fprintf(fd,"%s:%s:%s %s:%s:N\n", dat, ndays, tim, event, person);
  89.         else
  90.             fprintf(fd,"%s:%s:%s:%s:N\n", dat, ndays, event, person);
  91.     else
  92.     {
  93.         fprintf(stderr,"\nevent: error: user abort\n");
  94.         fclose(fd);
  95.         exit(2);
  96.     }
  97.  
  98.     fclose(fd);
  99.     fprintf(stderr,"\nevent: done\n");
  100.     exit(0);
  101. }
  102.  
  103.  
  104. /*---------------------------------------------------------------------------*/
  105. /* fsread -- input a record in full-screen mode */
  106. int fsread(void)
  107. {
  108.     WINDOW editwin;
  109.     int editstat;
  110.  
  111.     editwin=wopen( 9, 1,18,78,1,LGREY|_BLACK,LGREY|_BLACK);
  112.     wcenters(0,LMAGENTA|_BLACK,"Enter event for reminder");
  113.  
  114.     /* set up defaults */
  115.     *event=*person=*tim=*dat=*ndays='\0';
  116.     strcpy(dat,sysdate(3));
  117.     strcpy(ndays,"3");
  118.  
  119.     winpbeg(LGREY|_BLACK,BLACK|_LGREY);
  120.         wprints( 2, 1,LGREY|_BLACK,"Event:");
  121.         winpdef( 2,14,event ,"*************************************************************",0,1,validnocolon,0);
  122.         wprints( 3, 1,LGREY|_BLACK,"Person:");
  123.         winpdef( 3,14,person,"*************************************************************",0,1,validnocolon,0);
  124.         wprints( 4, 1,LGREY|_BLACK,"Time (hhmm):");
  125.         winpdef( 4,14,tim,   "<012>#<012345>#",                                              0,1,validnocolon,0);
  126.         wprints( 5, 1,LGREY|_BLACK,"Date:");
  127.         winpdef( 5,14,dat,   "********",                                                     0,1,validnocolon,0);
  128.         wprints( 6, 1,LGREY|_BLACK,"Days notice:");
  129.         winpdef( 6,14,ndays, "%%%",                                                          0,1,validnocolon,0);
  130.     editstat=winpread();
  131.  
  132.     wclose();
  133.  
  134.     /* kill all the trailing whitespace */
  135.     strrtrim(event);
  136.     strrtrim(person);
  137.     strrtrim(tim);
  138.     strrtrim(dat);
  139.     strrtrim(ndays);
  140.  
  141.     return (editstat);
  142. }
  143.  
  144.  
  145. /*---------------------------------------------------------------------------*/
  146. /* initialize CXL video and keyboard handling */
  147. void initcxl(void)
  148. {
  149.     _vinfo.dvcheck=0;                // don't check for DESQview
  150.     videoinit();
  151.     _vinfo.usebios=0;
  152.     wfillch('░');                    // background char for windows
  153.     wsetesc(1);                        // set ESC checking on
  154. }
  155.  
  156.  
  157. /*---------------------------------------------------------------------------*/
  158. /* make sure input contains no colons */
  159. int validnocolon(char *s)
  160. {
  161.     char *colptr;
  162.  
  163.     if ((colptr=strchr(s,':')) == NULL)
  164.         return 0;
  165.     else
  166.     {
  167.         beep();
  168.         return (colptr - s + 1);
  169.     }
  170. }
  171.  
  172.  
  173. /*---------------------------------------------------------------------------*/
  174. /* strrtrim -- kill trailing whitespace in a string */
  175. char *strrtrim(char *s)
  176. {
  177.     char *p;
  178.     p=s + strlen(s) - 1;    /* point at the last data char */
  179.  
  180.     while (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r')
  181.         p--;
  182.  
  183.     *(++p)='\0';
  184.  
  185.     return(s);
  186. }