home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / OPUS / ARKALOG.ZIP / ARKALOG.C next >
Encoding:
C/C++ Source or Header  |  1991-05-11  |  4.0 KB  |  141 lines

  1. /*******************************************************************/
  2. /* ARKALOG - Create a weekly name/dated archive of your log file   */
  3. /* based upon the last two digits of the year and week number of   */
  4. /* that year.  It does not delete the log file.  You may do that   */
  5. /* in your in a batch file based upon the exit ERRORLEVEL.         */
  6. /*                                                                 */
  7. /* Created 01-MAY-91 by Keith Ford.                                */
  8. /*                                                                 */
  9. /*   Micro Magic BBS       Phone:  +1 205 830 2362                 */
  10. /*   203 Creek Trail       Fido:   1:373/12                        */
  11. /*   Madison, AL 35758     Usenet: sysop@umagic.fidonet.org        */
  12. /*                                                                 */
  13. /* This file is being placed into the public domain.  If you make  */
  14. /* interesting or useful enhancements, the author would like to    */
  15. /* know about them.                                                */
  16. /*******************************************************************/
  17.  
  18.  
  19. #include <stdio.h>
  20. #ifdef __clipper__
  21. #include <conio.h>
  22. #endif
  23. #include <time.h>
  24.  
  25.  
  26.  
  27. show_help()
  28. {
  29.   puts("");
  30.   puts("Usage: ARKALOG DAY \"COMMAND\"");
  31.   puts("");
  32.   puts("  DAY is the day of week to execute \"COMMAND\"");
  33.   puts("  [SUN, MON, TUE, WED, THU, FRI, SAT]");
  34.   puts("");
  35.   puts("  \"COMMAND\" is a quoted archive command string.");
  36.   puts("  A 4 digit date code of YYWW will replace #### as it appears");
  37.   puts("  in the command string.  YY = last two digits of the year,");
  38.   puts("  WW = week number where 01 = week of January 1st.");
  39.   puts("");
  40.   puts("Examples: arkalog mon \"lharc a olog#### opus.log\"");
  41.   puts("          ARKALOG Tue \"Pkzip -a C:\\Save\\LOG_#### D:\\Bbs\\Bbs.Log\"");
  42.   puts("");
  43.   puts("Exit ERRORLEVELs:");
  44.   puts("   0 - completed successfully");
  45.   puts("   1 - not the specified day of the week");
  46.   puts("   2 - command not done due to error");
  47.   puts("");
  48. }
  49.  
  50.  
  51. main(argc,argv)
  52. int argc;
  53. char **argv;
  54. {
  55.   struct tm *timeptr;
  56.   time_t elapsed_seconds;
  57.   int day_number;
  58.   char *cptr, *dsptr, *acptr, archive_command[80], date_string[5];
  59.   int status=0;
  60.  
  61.   if (argc!=3)
  62.   {
  63.     puts("** incorrect number of arguments specified");
  64.     show_help();
  65.     exit(2);
  66.   }
  67.   
  68.   if (strlen(argv[1]) != 3)
  69.   {
  70.     printf("** unrecognized day: %s\n", argv[1]);
  71.     puts("valid choices are SUN, MON, TUE, WED, THU, FRI, SAT\n");
  72.     exit(2);
  73.   }
  74.   else
  75.   {
  76.     cptr = argv[1];
  77.     for(;*cptr;++cptr) *cptr=toupper(*cptr);
  78.     switch (argv[1][0])
  79.     {
  80.       case 'M': day_number = 1; break;
  81.       case 'W': day_number = 3; break;
  82.       case 'F': day_number = 5; break;
  83.       case 'S':
  84.       {
  85.         if (argv[1][1] == 'U') day_number = 0;
  86.         else day_number = 6;
  87.         break;
  88.       }
  89.       case 'T':
  90.       {
  91.         if (argv[1][1] == 'U') day_number = 2;
  92.         else day_number = 4;
  93.         break;
  94.       }
  95.       default:
  96.       {
  97.         printf("** unrecognized day: %s\n", argv[1]);
  98.         puts("valid choices are SUN, MON, TUE, WED, THU, FRI, SAT\n");
  99.         exit(2);
  100.         break;
  101.       }
  102.     }
  103.   }
  104.  
  105.   tzset();
  106.   time(&elapsed_seconds);
  107.   timeptr = localtime(&elapsed_seconds);
  108.   if (day_number != timeptr->tm_wday)
  109.   {
  110.     puts("** wrong day\n");
  111.     exit(1);
  112.   }
  113.  
  114.   sprintf(date_string, "%02d%02d", timeptr->tm_year, (int)(timeptr->tm_yday/7)+1);
  115.   dsptr = date_string;
  116.   cptr = argv[2];
  117.   acptr = archive_command;
  118.   while(*cptr && strncmp(cptr,"####",4)) *acptr++ = *cptr++;
  119.   if (*cptr)
  120.   {
  121.     while(*dsptr) *acptr++ = *dsptr++;
  122.     cptr+=4;
  123.     while(*cptr) *acptr++ = *cptr++;
  124.   }
  125.   else
  126.   {
  127.     puts("** warning: #### not used in command string\n");
  128.   }
  129.   *acptr = 0;
  130.   printf("executing: %s\n",archive_command);
  131.  
  132.   status = system(archive_command);
  133.   if (status)
  134.   {
  135.     printf("** ERROR: command status returned was: %d\n\n",status);
  136.     exit(2);
  137.   }
  138.  
  139.   exit(0);
  140. }
  141.