home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / eel / save_mod.zip / SAVE_MOD.E < prev    next >
Text File  |  1990-11-04  |  5KB  |  173 lines

  1. /*
  2.  EPSHeader
  3.  
  4.    File: save_mod.e
  5.    Author: J. Kercheval
  6. */
  7.  
  8. /*
  9.  EPSRevision History
  10.  
  11.    J. Kercheval  Sat, 10/24/1990  21:58:03  comment and explain
  12.    J. Kercheval  Sat, 10/25/1990  00:01:45  set mark before updating headers
  13.    J. Kercheval  Sat, 11/04/1990  22:38:35  add break to date switch (bug fix)
  14. */
  15.  
  16. /* 
  17.  
  18.     This command implements a simple and convenient tracking function
  19.     for internal to file creation and revision tracking messages which
  20.     allow input in addition to the standard revision control system
  21.     comments allowed by products such as TLib or PVCS.
  22.         
  23.     This is designed as a replacement for save_file() which behaves
  24.     slightly differently for certian file suffixes.
  25.         
  26.     On first save with this routine a header is created using the file
  27.     name, the newly defined buffer variable author which is up to 80
  28.     characters of name, and the time of creation.  In addition, a hook
  29.     is called when the header block is created to allow specification
  30.     of copyright notices or company headers or ... or ... etc.
  31.         
  32.     On second invocation this routine asks for a comment to insert in 
  33.     a revision history block and inserts the author, the date, and the
  34.     comment in the revision block.
  35.         
  36.     The routine asks before doing the above.  The non-special suffixed
  37.     files are passed normally to save_file() and nothing occurs if the
  38.     file was not modified.
  39.         
  40.         John Kercheval
  41.         127 NW Bowdoin Pl #105
  42.         Seattle, WA  98107-4960
  43.         October 24, 1990
  44.             
  45. */
  46.     
  47. #include "eel.h"
  48.  
  49. #define boolean int
  50. #define TRUE 1
  51. #define FALSE 0
  52.  
  53. /* buffer dependent author globally defined */
  54.  
  55. buffer char author_name[80] = "";
  56.  
  57. /* helper routine to obtain current day, date, time */
  58.  
  59. char *datestr(timestr)
  60.   char *timestr;
  61. {
  62.   struct time_info time;
  63.   char dow[4];
  64.   
  65.   time_and_day(&time);
  66.   switch (time.day_of_week) {
  67.     case 0: 
  68.         strcpy(dow,"Sun");
  69.         break;
  70.     case 1: 
  71.         strcpy(dow,"Mon");
  72.         break;
  73.     case 2: 
  74.         strcpy(dow,"Tue");
  75.         break;
  76.     case 3: 
  77.         strcpy(dow,"Wed");
  78.         break;
  79.     case 4: 
  80.         strcpy(dow,"Thu");
  81.         break;
  82.     case 5: 
  83.         strcpy(dow,"Fri");
  84.         break;
  85.     case 6:
  86.         strcpy(dow,"Sat");
  87.         break;
  88.   }
  89.   sprintf(timestr,"%s, %02d/%02d/%4d  %02d:%02d:%02d",
  90.     dow,time.month,time.day,time.year,
  91.     time.hour,time.minute,time.second);
  92.   
  93.   return(timestr);
  94. }
  95.  
  96. /* user routine to save a file only if modified and to both place an initial 
  97.    time stamp and/or to place a revision date and comment */
  98.  
  99. command save_modified_file()
  100. {
  101.   char comment_open[4];
  102.   char comment_close[4];
  103.   char response[80];
  104.   char tmpfile[20];
  105.   char time[30];
  106.   int tmpint;
  107.   boolean check;
  108.   
  109.   /* save only if file is modified */
  110.   
  111.   if (modified) {
  112.  
  113.     /* establish qualifications for revision update */
  114.  
  115.     check = FALSE;
  116.     if (!strcmp(get_extension(filename),".c") ||
  117.       !strcmp(get_extension(filename),".h") ||
  118.       !strcmp(get_extension(filename),".e") ||
  119.       !strcmp(get_extension(filename),".y")) {
  120.         strcpy(comment_open,"/*");
  121.         strcpy(comment_close,"*/");
  122.         check = TRUE;
  123.     }
  124.     if (!strcmp(get_extension(filename),".pas")) {
  125.       strcpy(comment_open,"{");
  126.       strcpy(comment_close,"}");
  127.       check = TRUE;
  128.     }
  129.  
  130.     /* if qualified then prompt for verification */
  131.  
  132.     if (check) {
  133.       strcpy(tmpfile,get_tail(filename,0));
  134.       get_strdef(response,"Update revision information?","y");
  135.       
  136.       /* if user wants revision update then check for stamp, call hook,
  137.         and prompt for revision message */
  138.       
  139.       if (!strnfcmp(response,"Y",1)) {
  140.         mark = point;
  141.         point = 0;
  142.         if (!search(1,"EPSHeader")) {
  143.           point = 0;
  144.           bprintf("%s\n EPSHeader\n\n   File: %s\n   Author: %s\n",
  145.                   comment_open,tmpfile,author_name);
  146.           bprintf("   Created: %s\n%s\n\n",
  147.                   datestr(time),comment_close);
  148.           try_calling("revision-update-header-hook");
  149.         }
  150.         else {
  151.           point = 0;
  152.           search(1,"EPSHeader");
  153.           search(1,comment_close);
  154.           tmpint = point;
  155.           if (!search(1,"EPSRevision")) {
  156.             point = tmpint;
  157.             bprintf("\n%s\n EPSRevision History\n\n%s",
  158.               comment_open,comment_close);
  159.           }
  160.           point = 0;
  161.           get_string(response,"Revision comment: ");
  162.           search(1,"EPSRevision History");
  163.           search(1,comment_close);
  164.           to_begin_line();
  165.           bprintf("   %s  %s  %s\n",author_name,datestr(time),response);
  166.         }
  167.       }
  168.     }
  169.     save_file();
  170.   }
  171.   else say("File was not modified.");
  172. }
  173.