home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 592b.lha / XTime_v1.0 / source / XTime.c < prev    next >
C/C++ Source or Header  |  1991-11-23  |  4KB  |  135 lines

  1. /* XTime v. 1.10
  2.    Copyright November 1991 by Kurt R. Krueger
  3.  
  4.    This program is freely distributable in an unmodified form with the
  5.    proviso that I retain all rights to it and how it is used.  I could
  6.    put a disclaimer in here, but since this is free, your rights to sue
  7.    me for any major screw up in the program are nil.  For this reason, I
  8.    ask for no money and do not release rights to anyone who sells it for
  9.    more than or equal to $0.01 above the cost of distribution.  Actually,
  10.    the real reason why I ask for no money is that I know that I wouldn't
  11.    see $0.01 in shareware fees anyway, but if there is one person out there
  12.    who actually would send money, send it to the charity of your choice,
  13.    and I will be happy.  Finally, I will specifically allow Fred Fish to
  14.    put this in his archive if he really thinks it is worth it. */
  15.  
  16.  
  17. /* I don't claim it's efficient.  I just claim it usually works. */
  18.  
  19. #define XFER_RATE 232
  20. #include <time.h>
  21.  
  22. extern long atol();
  23. extern int atoi();
  24. extern long FindFiles();
  25. struct tm *tmp;
  26. struct tm *localtime();
  27. char *param, k[] = "-k", r[] = "-r", f[] = "-f", r_string[4];
  28. int n = 1, i = 0, r_len = 0, hours = 0, mins, h, m, s, min_xfer = 5L;
  29. int filemode = 0, x_rate = XFER_RATE;
  30. long secs, byte = 0, time(), tp;
  31.  
  32. main (argc, argv)
  33.  
  34. int argc;
  35. char *argv[];
  36.  
  37. {
  38.   if (argc == 1)
  39.     {
  40.     help();
  41.     exit(0);
  42.     }
  43. /* Check to see if a number or text was entered.  If text, go to file mode. */
  44.   byte = atol(argv[argc-1]);
  45.   if (!byte)
  46.     filemode = 1;
  47.  
  48. /* Parse the command line */
  49.   param = argv[n];
  50.   while (param[0] == '-')
  51.     {
  52. /* Set kilo mode if -k and not in filemode */
  53.     if (strcmp(argv[n], k) == 0 && filemode == 0)
  54.       byte *= 1000;
  55.  
  56. /* Separate the value after -r */
  57.     if (strncmp(argv[n], r, 2) == 0)
  58.       {
  59.       r_len = strlen(argv[n]) - 2;
  60.       for (i = 0; i < r_len; i++)
  61.         r_string[i] = argv[n][i+2];
  62.       x_rate = atoi(r_string);
  63.       if (x_rate == 0)
  64.         x_rate = XFER_RATE;
  65.       }
  66.  
  67. /* Parse out -f */
  68.     if (!strcmp(argv[n], f))
  69.       filemode = 1;
  70.  
  71. /* Complete loop and go on to parse out next parameter. */
  72.     param = argv[n++];
  73.     }
  74.  
  75. /* if true, go into file mode to get file size(s) */
  76.   if (filemode)
  77.     {
  78.     byte = FindFiles(argv[argc-1]);
  79.     if (!byte)
  80.       {
  81.       printf ("\nNo files matched.\n\n");
  82.       exit(0);
  83.       }
  84.     /* PTH printf ("\nTotal size: %ld bytes\n", byte); */
  85.     printf ("--------------------------------------\n");
  86.     printf ("Total size:                   %8ld bytes\n", byte);
  87.     }
  88.  
  89.   secs = byte / x_rate;
  90.   mins = secs / 60;
  91.   hours = mins / 60;
  92.   secs -= (long)mins * 60;
  93.   mins -= hours * 60;
  94.   if (secs <= min_xfer)
  95.     secs = min_xfer;
  96.   printf ("\nAssumed transfer rate: %d CPS\n", x_rate);
  97.   printf ("Transfer should take:  %dh %dm %lds\n", hours, mins, secs);
  98.  
  99.   /* Get clock time and estimate completion time. */
  100.   
  101.   time(&tp);
  102.   tmp = localtime(&tp);
  103.   h = tmp->tm_hour;
  104.   m = tmp->tm_min;
  105.   s = tmp->tm_sec;
  106.   printf ("The current time is:   %02d:%02d:%02d\n", h, m, s);
  107.   s += secs;
  108.   if (s >= 60)
  109.     {
  110.     mins++;
  111.     s -= 60;
  112.     }
  113.   m += mins;
  114.   if (m >= 60)
  115.     {
  116.     hours++;
  117.     m -= 60;
  118.     }
  119.   h += hours;
  120.   while (h > 23)
  121.     h -= 24;
  122.  
  123.   printf ("Est. completion time:  %02d:%02d:%02d\n\n", h, m, s);
  124. }
  125.  
  126. help()
  127.   {
  128.   printf("\nXTime v. 1.10\n");
  129.   printf("Copyright 1991 by Kurt R. Krueger\n\n");
  130.   printf("XTime [-k] [-r<cps>] <[file size in bytes] or [filename]>\n\n");
  131.   printf("-f: Force file mode\n");
  132.   printf("-k: File size is in K.  Turned off in file mode.\n");
  133.   printf("-r: Assumed transfer rate is r characters/sec\n\n");
  134.   }
  135.