home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / ME22-OS2.ZIP / MACROS.ZIP / EXIT.M < prev    next >
Text File  |  1988-09-12  |  1KB  |  50 lines

  1. /* 
  2.     Backs up the current file to the directory specified by the BAKDIR
  3.     environment variable when ME is exiting.
  4.     This allows you to avoid messing up your root directory with .BAK
  5.     files. Remember to alter the CONFIG.ME file so that it no longer creates 
  6.    .BAK files upon exit
  7.    
  8.     Written by Jim Mochel of The Oakland Group
  9. */
  10.  
  11. init()
  12. {
  13.   add_hook(1, "backup");        /* hook called when ME exits */
  14. }
  15.  
  16. backup()
  17. {
  18.   string dir;
  19.   string file;
  20.   int posn;
  21.  
  22.   dir = getenv("BAKDIR");    /* Get the directory for .BAK files */
  23.  
  24.   /*
  25.    * If the directory does not end with a \ , add it on to the directory 
  26.    */
  27.   if ((posn = search_string(dir, "\\$")) <= 0)
  28.     dir = strcat(dir, "\\");
  29.  
  30.   /*
  31.    * If the filename has an extension, alter it to .BAK 
  32.    */
  33.   posn = index(filename(), ".");
  34.  
  35.   if (posn > 0)
  36.     file = strcat(substr(filename(), 1, posn - 1), ".BAK");
  37.   else
  38.     file = strcat(filename(), ".BAK");
  39.  
  40.   /*
  41.    * Create the full filename including path 
  42.    */
  43.   file = strcat(dir, file);
  44.  
  45.   /*
  46.    * Save the backup file 
  47.    */
  48.   writefile(file);
  49. }
  50.