home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 December / simtel1292_SIMTEL_1292_Walnut_Creek.iso / msdos / deskaces / reminder.arc / REMIND.ORI < prev    next >
Text File  |  1987-10-06  |  3KB  |  116 lines

  1. /* remind.c: Make an entry in the dates file for reminder.
  2.  *   Programmed by Ken Van Camp, ARDEC, October 1987.
  3.  */
  4. #include <stdio.h>
  5.  
  6. #define DATEFILE "\\DATES"
  7.  
  8. #ifdef CHECKCZ
  9. #include <fcntl.h>
  10. int fd;
  11. #else
  12. FILE *fd, *fopen();
  13. #endif
  14.  
  15. void getdata();
  16.  
  17. main(argc,argv)
  18. int argc;
  19. char *argv[];
  20. {
  21.         char    line[256],
  22.                 event[128],
  23.                 person[128],
  24.                 tim[20],
  25.                 dat[30],
  26.                 ndays[10];
  27. #ifdef CHECKCZ
  28.         int     i;
  29.         char    c;
  30.  
  31.         if (argc > 1){
  32.                 if ((fd = open (argv[1], O_RDWR|O_CREAT)) < 0){
  33.                         fprintf(stderr,"Error: Can't open file '%s'\n",
  34.                                 argv[1]);
  35.                         exit(1);
  36.                 }
  37.         }else{
  38.                 if ((fd = open (DATEFILE, O_RDWR|O_CREAT)) < 0){
  39.                         fprintf(stderr,"Error: Can't open file '%s'\n",
  40.                                 DATEFILE);
  41.                         exit(1);
  42.                 }
  43.         }
  44. #else
  45.         if (argc > 1){
  46.                 if ((fd = fopen (argv[1], "a")) == NULL){
  47.                         fprintf(stderr,"Error: Can't open file '%s'\n",
  48.                                 argv[1]);
  49.                         exit(1);
  50.                 }
  51.         }else{
  52.                 if ((fd = fopen (DATEFILE, "a")) == NULL){
  53.                         fprintf(stderr,"Error: Can't open file '%s'\n",
  54.                                 DATEFILE);
  55.                         exit(1);
  56.                 }
  57.         }
  58. #endif
  59.  
  60. #ifdef CHECKCZ
  61.         /* Read forward in file til EOF (either CTRL-Z or no more data) */
  62.         i = 1;
  63.         while (i > 0){
  64.                 i = read (fd, &c, 1);
  65. #ifdef DEBUG
  66.                 putchar(c);
  67. #endif
  68.                 if (c == '\032'){       /* CTRL-Z is End of file marker */
  69.                         /* Stop the read here and backup one byte for
  70.                            subsequent writes */
  71. #ifdef DEBUG
  72.                         printf("Read EOF\n");
  73. #endif
  74.                         i = 0;
  75.                         lseek (fd, -1, 1);
  76.                 }
  77.         }
  78. #ifdef DEBUG
  79.         printf("No more chars to read\n");
  80. #endif
  81. #endif
  82.         getdata ("Event for reminder file", event);
  83.         getdata ("Person", person);
  84.         getdata ("Time (e.g. 1300)", tim);
  85.         getdata ("Date (e.g. 10/01/87 or 10/01 or 01 or Thu)", dat);
  86.         getdata ("Number of days notice", ndays);
  87.  
  88. #ifdef CHECKCZ
  89.         sprintf(line,"%s:%s:%s %s:%s:N\n", dat, ndays, tim, event, person);
  90.         write (fd, line, strlen(line));
  91.         close(fd);
  92. #else
  93.         fprintf(fd,"%s:%s:%s %s:%s:N\n", dat, ndays, tim, event, person);
  94.         fclose(fd);
  95. #endif
  96. }
  97.  
  98. /* getdata: Get another data item for the reminder file */
  99. void getdata (prompt, vbl)
  100. char    *prompt, *vbl;
  101. {
  102.         int ok=0;
  103.         char *c, *strchr();
  104.  
  105.         while (!ok){
  106.                 printf ("%s: ", prompt);
  107.                 gets(vbl);
  108.                 c = strchr(vbl,':');
  109.                 /* This should modified to check for a preceding backslash */
  110.                 if (*c != NULL)
  111.                         printf ("Error: Can't use a colon; please retype.\n");
  112.                 else
  113.                         ok = 1;
  114.         }
  115. }
  116.