home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / aix-rs6000 / elm2.3.11.AIX3.1.5.Z / elm2.3.11.AIX3.1.5 / src / calendar.c < prev    next >
C/C++ Source or Header  |  1991-11-26  |  4KB  |  162 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: calendar.c,v 4.1.1.1 90/06/21 22:16:50 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 4.1.1.1 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1986, 1987 Dave Taylor
  8.  *             Copyright (c) 1988, 1989, 1990 USENET Community Trust
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log:    calendar.c,v $
  17.  * Revision 4.1.1.1  90/06/21  22:16:50  syd
  18.  * Add skip leading whitespace
  19.  * From Jerry Pendergrafyt
  20.  * 
  21.  * Revision 4.1  90/04/28  22:42:36  syd
  22.  * checkin of Elm 2.3 as of Release PL0
  23.  * 
  24.  *
  25.  ******************************************************************************/
  26.  
  27. /** This routine implements a rather snazzy idea suggested by Warren
  28.     Carithers of the Rochester Institute of Technology that allows
  29.     mail to contain entries formatted in a manner that will allow direct
  30.     copying into a users calendar program.
  31.  
  32.     All lines in the current message beginning with "->", e.g.
  33.  
  34.     -> Mon 04/21 1:00p meet with chairman candidate
  35.  
  36.     get copied into the user's calendar file.
  37.  
  38. **/
  39.  
  40. #include "headers.h"
  41.  
  42. #ifdef ENABLE_CALENDAR        /* if not defined, this will be an empty file */
  43.  
  44. #include <errno.h>
  45.  
  46. extern int errno;
  47.  
  48. char *error_name(), *error_description(); /* *strcpy(); */
  49.  
  50. scan_calendar()
  51. {
  52.     FILE *calendar;
  53.     int  count;
  54.  
  55.     /* First step is to open the calendar file for appending... **/
  56.  
  57.     if (can_open(calendar_file, "a") != 0) {
  58.       dprint(2, (debugfile,
  59.           "Error: wrong permissions to append to calendar %s\n",
  60.           calendar_file));
  61.       dprint(2, (debugfile, "** %s - %s **\n",
  62.           error_name(errno), error_description(errno)));
  63.       error1("Not able to append to file %s!", calendar_file);
  64.       return; 
  65.     }
  66.  
  67.     save_file_stats(calendar_file);
  68.  
  69.     if ((calendar = fopen(calendar_file,"a")) == NULL) {
  70.       dprint(2, (debugfile, 
  71.         "Error: couldn't append to calendar file %s (scan)\n", 
  72.         calendar_file));
  73.       dprint(2, (debugfile, "** %s - %s **\n",
  74.           error_name(errno), error_description(errno)));
  75.       error1("Couldn't append to file %s!", calendar_file);
  76.       return; 
  77.     }
  78.     
  79.     count = extract_info(calendar);
  80.  
  81.     fclose(calendar);
  82.  
  83.     restore_file_stats(calendar_file);
  84.  
  85.     if (count > 0)
  86.       error2("%d entr%s saved in calendar file.", 
  87.          count, count > 1 ? "ies" : "y");
  88.     else 
  89.       error("No calendar entries found in that message.");
  90.  
  91.     return;
  92. }
  93.  
  94. int
  95. extract_info(save_to_fd)
  96. FILE *save_to_fd;
  97. {
  98.     /** Save the relevant parts of the current message to the given
  99.         calendar file.  The only parameter is an opened file
  100.         descriptor, positioned at the end of the existing file **/
  101.         
  102.     register int entries = 0, lines;
  103.     char buffer[SLEN], *cp, *is_cal_entry();
  104.  
  105.         /** get to the first line of the message desired **/
  106.  
  107.         if (fseek(mailfile, headers[current-1]->offset, 0) == -1) {
  108.              dprint(1,(debugfile, 
  109.         "ERROR: Attempt to seek %d bytes into file failed (%s)",
  110.         headers[current-1]->offset, "extract_info"));
  111.              error1("ELM [seek] failed trying to read %d bytes into file.",
  112.              headers[current-1]->offset);
  113.              return(0);
  114.         }
  115.  
  116.         /* how many lines in message? */
  117.  
  118.         lines = headers[current-1]->lines;
  119.  
  120.         /* now while not EOF & still in message... scan it! */
  121.  
  122.     while (lines) {
  123.  
  124.           if(fgets(buffer, SLEN, mailfile) == NULL)
  125.         break;
  126.  
  127.       if(buffer[strlen(buffer)-1] == '\n')
  128.         lines--;                    /* got a full line */
  129.  
  130.       if((cp = is_cal_entry(buffer)) != NULL) {
  131.         entries++;
  132.         fprintf(save_to_fd,"%s", cp);
  133.       }
  134.  
  135.     }
  136.     dprint(4,(debugfile,
  137.         "Got %d calender entr%s.\n", entries, entries > 1? "ies":"y"));
  138.  
  139.     return(entries);
  140. }
  141.  
  142. char *
  143. is_cal_entry(string)
  144. register char *string;
  145. {
  146.     /* If string is of the form
  147.          * {optional white space} ->{optional white space} {stuff}
  148.      * return a pointer to stuff, otherwise return NULL.
  149.      */
  150.     while( whitespace(*string) )
  151.       string++;      /* strip leading W/S */
  152.     
  153.     if(strncmp(string, "->", 2) == 0) {
  154.       for(string +=2 ; whitespace(*string); string++)
  155.           ;
  156.       return(string);
  157.     }
  158.     return(NULL);
  159. }
  160.  
  161. #endif
  162.