home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / hard / misc / clocktool / clocktool.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-04  |  30.3 KB  |  1,737 lines

  1. #define VERSION "1.1 "
  2.  
  3. #define EARLIEST_LIB    37    /* 2.04 and above */
  4.  
  5. /**
  6.  
  7.  * ClockTool.c
  8.  *
  9.  *  Displays/adjusts/sets times of battery clock and/or system clock
  10.  *  from one or the other.
  11.  *
  12.  * Options:
  13.  *
  14.  *      -b       ; battery clock
  15.  *      -s       ; system  clock
  16.  *      -d<str>    : set selected clock to str (dd-MMM-yy)
  17.  *      -t<str>    : set selected clock to str (hh:mm[:ss])
  18.  *                    (use either or both d/t options)
  19.  *      -annnn   ; adjust selected clock time by -nnnn millisecs",
  20.  *      +annnn   ; adjust selected clock time by +nnnn millisecs",
  21.  *      -l<file> ; log system time to <file> , reset clock from other
  22.  *                                    (default LOG_CLOCKTOOL:)
  23.  *      -L<file> ; log system time to <file> , Dont reset clock from other
  24.  *                                    (default LOG_CLOCKTOOL:)
  25.  *      -n<str>  ; append the <str> to log file entry, e.g. "reboot"
  26.  *
  27.  *  (see Usage () )
  28.  *
  29.  * Runs under AmigaDOS 2.04+, and only machines containing
  30.  * a battery clock.
  31.  *
  32.  *
  33.  *
  34.  *****  Written by Gary Duncan
  35.  *
  36.  *      Bug reports etc via e-mail to gduncan@philips.oz.au) , or mail to
  37.  *
  38.  *Work: Gary Duncan
  39.  *      Philips PTS
  40.  *      23 Lakeside Dr
  41.  *      Tally-Ho Technology Park
  42.  *      Burwood East Vic 3151
  43.  *      Australia
  44.  *
  45.  *Home: Gary Duncan
  46.  *      57 Melbourne Hill Rd
  47.  *      Warrandyte
  48.  *      Vic 3113
  49.  *      Australia
  50.  *
  51.  *
  52.  *
  53.  *****  Freely distributable for non-commercial purposes.
  54.  *      Please keep this header intact.
  55.  *
  56.  *
  57.  *      Compiles under SAS 6.2
  58.  *
  59.  *      Formatted with 'indent -gnu' ; a big time-saving program.
  60.  *
  61.  * Functions:-
  62.  
  63.  main
  64.  tv2dss
  65.  tv2str
  66.  dss2tv
  67.  dss2str
  68.  str2dss
  69.  Init_Timer
  70.  hexit
  71.  DeleteTimer
  72.  usage
  73.  scan_args
  74.  tv_diff
  75.  tv_diff_str
  76.  format_diff_str
  77.  set_system_time
  78.  get_system_time
  79.  get_battclock_time
  80.  set_battclock_time
  81.  tv_update
  82.  check4battclock
  83.  get_syncd_battclock_time
  84.  get_syncd_system_time
  85.  print_clock
  86.  display_clocks
  87.  adjust_clock
  88.  set_system_time_to_syncd_battclock
  89.  set_battclock_time_to_syncd_system_time
  90.  wait_for_timer
  91.  pause
  92.  
  93.  
  94.  
  95.  Version        Date    Changes
  96.  ~~~~~~~        ~~~~    ~~~~~~~
  97.  
  98.  1.0            27Oct93 Original release
  99.  1.1            04Apr94 Changes :-
  100.                 1) use __AMIGADATE__
  101.                 2) added L option, reorganised logic.
  102.                 3) added d,t options (set date/time).
  103.                 4) corrected clocktool -b output for big difference  
  104.  
  105.  
  106.  **/
  107.  
  108. #include "ClockTool.h"
  109.  
  110.  
  111. /*
  112.  * string for AmigaDOS Version Command
  113.  */
  114. char A_vers[] = "\0$VER: clocktool\t" VERSION __AMIGADATE__;
  115.  
  116.  
  117. LIBRARY *UtilityBase = NULL;
  118. LIBRARY *BattClockBase;
  119.  
  120. TIMEVAL tv_sysclock;
  121. TIMEVAL tv_battclock;
  122. TIMEVAL tv_tmp;
  123.  
  124. DATESTAMP dss_sysclock;
  125. DATESTAMP dss_battclock;
  126.  
  127. DATETIME datetime;
  128. char *date_ptr;
  129. char *time_ptr;
  130.  
  131. LONG adjust;
  132. LONG temp;
  133.  
  134. MSGPORT *TimeP = NULL;
  135. TIMERREQUEST *Timermsg;
  136. IOREQUEST *Timer = NULL;
  137.  
  138. BOOL a_flag = FALSE;
  139. BOOL b_flag = FALSE;
  140. BOOL d_flag = FALSE;
  141. BOOL l_flag = FALSE;
  142. BOOL L_flag = FALSE;
  143. BOOL n_flag = FALSE;
  144. BOOL s_flag = FALSE;
  145. BOOL t_flag = FALSE;
  146.  
  147. char buf[80];
  148. char *xstr = "";
  149.  
  150. int opt_count = 0;
  151.  
  152. char *logfile;
  153. FILE *fp = NULL;
  154. char log_buf[80];
  155.  
  156. /*
  157.  * used by date conversion functions
  158.  */
  159.  
  160. DM days_month[] =
  161. {
  162.   31, "Jan",
  163.   28, "Feb",
  164.   31, "Mar",
  165.   30, "Apr",
  166.   31, "May",
  167.   30, "Jun",
  168.   31, "Jul",
  169.   31, "Aug",
  170.   30, "Sep",
  171.   31, "Oct",
  172.   30, "Nov",
  173.   31, "Dec",
  174. };
  175.  
  176. /*
  177.  *********************************************************************
  178.  */
  179.  
  180. VOID
  181. main (int argc, char **argv)
  182. {
  183.  
  184.   /*
  185.    * abort if no battclock and not AmigaDos 2.xx
  186.    */
  187.   if (check4battclock () == FALSE)
  188.     {
  189.       hexit (1);
  190.     }
  191.  
  192.   scan_args (argc, argv);
  193.  
  194.   Init_Timer ();
  195.  
  196.   /*
  197.    ***** Mode (1) ? - just display both clocks ?
  198.    */
  199.   if (opt_count == 0)
  200.     {
  201.       get_syncd_battclock_time (&tv_battclock);
  202.       get_system_time (&tv_sysclock);
  203.  
  204.       display_clocks (&tv_battclock, &tv_sysclock);
  205.       hexit (1);
  206.     }
  207.  
  208.   /*
  209.    ***** Mode (2) -  just a s or b option ?
  210.    */
  211.  
  212.   if (opt_count == 1)
  213.     {
  214.       /*
  215.        * just set one clock from the other
  216.        */
  217.       if (s_flag == TRUE)
  218.     {
  219.       (void) set_system_time_to_syncd_battclock ();
  220.  
  221.       print_old_new ("system", &tv_sysclock, &tv_battclock);
  222.     }
  223.       else
  224.     /* set battclock from system time */
  225.     {
  226.       (void) set_battclock_time_to_syncd_system_time ();
  227.  
  228.       print_old_new ("battery", &tv_battclock, &tv_sysclock);
  229.     }
  230.  
  231.       hexit (1);
  232.     }
  233.  
  234.  
  235.   if ((d_flag == TRUE) || (t_flag == TRUE))
  236.     {
  237.       TIMEVAL t_val;
  238.  
  239.       DateStamp (&datetime.dat_Stamp);
  240.  
  241.       datetime.dat_Format = FORMAT_DOS;
  242.       datetime.dat_Flags = 0;
  243.  
  244.       if (d_flag)
  245.     {
  246.       datetime.dat_StrDate = date_ptr;
  247.       datetime.dat_StrTime = NULL;
  248.       if (StrToDate (&datetime) == FALSE)
  249.         {
  250.           fprintf (stderr, "invalid date string\n");
  251.           hexit (1);
  252.         }
  253.     }
  254.       if (t_flag)
  255.     {
  256.       datetime.dat_StrTime = time_ptr;
  257.       datetime.dat_StrDate = NULL;
  258.       if (StrToDate (&datetime) == FALSE)
  259.         {
  260.           fprintf (stderr, "invalid time string\n");
  261.           hexit (1);
  262.         }
  263.     }
  264.  
  265.       /*
  266.        * now change date/time of selected clock
  267.        */
  268.       dss2tv (&datetime.dat_Stamp, &t_val);
  269.  
  270.       b_flag ? set_battclock_time (&t_val) : set_system_time (&t_val);
  271.  
  272.       /*
  273.        * now display both clocks 
  274.        */
  275.       get_syncd_battclock_time (&tv_battclock);
  276.       get_system_time (&tv_sysclock);
  277.  
  278.       display_clocks (&tv_battclock, &tv_sysclock);
  279.       hexit (1);
  280.  
  281.     }
  282.  
  283.   /*
  284.    ***** Mode (4) - adjust a clock (no logging) ?
  285.    */
  286.  
  287.   if ((a_flag == TRUE) && (opt_count == 2))
  288.     {
  289.       adjust_clock (adjust, &tv_tmp);
  290.  
  291.       if (s_flag == TRUE)
  292.     {
  293.       print_old_new ("system", &tv_sysclock, &tv_tmp);
  294.     }
  295.       else
  296.     {
  297.       print_old_new ("battery", &tv_battclock, &tv_tmp);
  298.     }
  299.       hexit (1);
  300.     }
  301.  
  302.   /*
  303.    ***** Mode (5) - log selected clock time with reset  ?
  304.    */
  305.  
  306.   if (l_flag == TRUE)
  307.     {
  308.       if (s_flag == TRUE)
  309.     {
  310.       temp = set_system_time_to_syncd_battclock ();
  311.  
  312.       sprintf (log_buf, "\nS: %s %s",
  313.            tv2str (&tv_sysclock),
  314.            format_diff_str (temp, "(%s secs)  "));
  315.     }
  316.       else if (b_flag == TRUE)
  317.     {
  318.       temp = set_battclock_time_to_syncd_system_time ();
  319.  
  320.       sprintf (log_buf, "\nB: %s %s",
  321.            tv2str (&tv_battclock),
  322.            format_diff_str (temp, "(%s secs)  "));
  323.     }
  324.  
  325.       if (n_flag == TRUE)
  326.     {
  327.       strcat (log_buf, xstr);
  328.     }
  329.  
  330.       printf ("%s\n", log_buf);
  331.     }
  332.  
  333.   /*
  334.    ***** Mode (6) - log selected clock time with NO reset  ?
  335.    */
  336.  
  337.   if (L_flag == TRUE)
  338.     {
  339.  
  340.       get_syncd_battclock_time (&tv_battclock);
  341.       get_system_time (&tv_sysclock);
  342.  
  343.       temp = tv_diff (&tv_sysclock, &tv_battclock);
  344.  
  345.       if (s_flag == TRUE)
  346.     {
  347.       sprintf (log_buf, "\nS: %s %s", tv2str (&tv_sysclock),
  348.            format_diff_str (temp, "(%s secs)  "));
  349.     }
  350.       else if (b_flag == TRUE)
  351.     {
  352.       sprintf (log_buf, "\nB: %s %s", tv2str (&tv_battclock),
  353.            format_diff_str (temp, "(%s secs)  "));
  354.  
  355.     }
  356.  
  357.       if (n_flag == TRUE)
  358.     {
  359.       strcat (log_buf, xstr);
  360.     }
  361. #if 1
  362.       printf ("%s\n", log_buf);
  363. #endif
  364.     }
  365.  
  366.   /*
  367.    * now log message , maybe
  368.    */
  369.   if (fp)
  370.     {
  371.       int rote;
  372.       int len = strlen (log_buf);
  373.  
  374.       if ((rote = fwrite (log_buf, 1, len, fp)) != len)
  375.     {
  376.       fprintf (stderr, "fwrite error (wanted=%d),(actual=%d)\n",
  377.            len, rote);
  378.     }
  379.     }
  380.  
  381.   hexit (1);
  382. }
  383.  
  384.  
  385. /***************************************************************************
  386.  
  387.  
  388.  Function :     tv2dss
  389.  
  390.  Purpose:       given a Timeval structure , returns Datestamp
  391.  
  392.  Entry    :     ptr to Timeval
  393.  ptr to Datestamp
  394.  
  395.  Returns  :
  396.  
  397.  
  398.  ****************************************************************************/
  399.  
  400.  
  401. void
  402. tv2dss (TIMEVAL * tv, DATESTAMP * dss)
  403.  
  404. {
  405.   long rem;
  406.  
  407.   dss->ds_Days = tv->tv_secs / (24 * 60 * 60);
  408.   rem = tv->tv_secs % (24 * 60 * 60);    /* secs in last day */
  409.  
  410.   dss->ds_Minute = rem / 60;
  411.   rem = rem % 60;        /* secs in last minute */
  412.  
  413.   rem = (rem * 1000) + (tv->tv_micro / 1000);    /* msecs in last minute */
  414.  
  415.   dss->ds_Tick = rem / (1000 / TICKS_PER_SECOND);    /* ticks in last minute */
  416. }
  417.  
  418. /***************************************************************************
  419.  
  420.  
  421.  Function :     tv2str
  422.  
  423.  Purpose:       given a Timeval structure , returns date string
  424.  
  425.  Entry    :     ptr to Timeval
  426.  
  427.  Returns  :
  428.  
  429.  
  430.  ****************************************************************************/
  431.  
  432.  
  433. char *
  434. tv2str (TIMEVAL * tv)
  435.  
  436. {
  437.   static char tbuf[40];
  438.   DATESTAMP dss;
  439.  
  440.   tv2dss (tv, &dss);
  441.   dss2str (&dss, tbuf);
  442.   return tbuf;
  443. }
  444.  
  445. /***************************************************************************
  446.  
  447.  
  448.  Function :     dss2tv
  449.  
  450.  Purpose:       given a DateStamp structure , returns an updated TIMEVAL
  451.  
  452.  Entry    :    ptr to DateStamp structure
  453.  
  454.  Returns  :
  455.  
  456.  
  457.  ****************************************************************************/
  458.  
  459.  
  460. void
  461. dss2tv (DATESTAMP * t1, TIMEVAL * tv)
  462.  
  463. {
  464.   ULONG secs;
  465.  
  466.   secs = t1->ds_Days * 24 * 60 * 60;
  467.   secs += t1->ds_Minute * 60;
  468.   secs += t1->ds_Tick / TICKS_PER_SECOND;
  469.  
  470.   tv->tv_secs = secs;
  471.   tv->tv_micro = (t1->ds_Tick % TICKS_PER_SECOND) * (1000000 / TICKS_PER_SECOND);
  472.  
  473. }
  474.  
  475. /***************************************************************************
  476.  
  477.  
  478.  Function :     dss2str
  479.  
  480.  Purpose:       generates a date string given a DateStamp
  481.  
  482.  Entry    :     ptr to Datestamp
  483.  
  484.  
  485.  Returns  :    ptr to date string
  486.  
  487.  
  488.  
  489.  ****************************************************************************/
  490.  
  491.  
  492. void
  493. dss2str (DATESTAMP * dss, char *str)
  494.  
  495. {
  496.   static TIMEVAL tv;
  497.   struct tm Time;
  498.   int j;
  499.   long time, ago;
  500.  
  501.  
  502.   dss2tv (dss, &tv);        /* date to secs/usecs since 01 Jan 78 */
  503.   time = tv.tv_secs;
  504.  
  505.   Time.tm_sec = time % 60;
  506.   time /= 60;
  507.   Time.tm_min = time % 60;
  508.   time /= 60;
  509.   Time.tm_hour = time % 24;
  510.   time /= 24;
  511.   Time.tm_wday = time % 7;
  512.   Time.tm_year = 78 + (time / (4 * 365 + 1)) * 4;
  513.   time %= 4 * 365 + 1;
  514.  
  515.  
  516.   while (time)
  517.     {
  518.       ago = 365;
  519.       if ((Time.tm_year & 3) == 0)    /* leap year */
  520.     ago++;
  521.       if (time < ago)
  522.     break;
  523.       time -= ago;
  524.       Time.tm_year++;
  525.     }
  526.   Time.tm_yday = ++time;
  527.  
  528.   for (j = 0; j < 12; j++)
  529.     {
  530.       ago = days_month[j].days;
  531.       if (j == 1 && (Time.tm_year & 3) == 0)    /* Feb , and leap year ? */
  532.     ago++;
  533.       if (time <= ago)
  534.     break;
  535.       time -= ago;
  536.     }
  537.   Time.tm_mon = j;
  538.   Time.tm_mday = time;
  539.  
  540.   /* date format : 23-dec-88 22:33:01  */
  541.  
  542.   sprintf (str, "%02d-%s-%2d %02d:%02d:%02d.%03d",
  543.        Time.tm_mday,
  544.        days_month[Time.tm_mon].months,
  545.        Time.tm_year,
  546.        Time.tm_hour,
  547.        Time.tm_min,
  548.        Time.tm_sec,
  549.        tv.tv_micro / 1000
  550.     );
  551.  
  552. }
  553.  
  554.  
  555.  
  556. /***************************************************************************
  557.  
  558.  
  559.  Function :   str2dss
  560.  
  561.  
  562.  Purpose  :   converts a truncated Amiga date string to a Datestamp
  563.  
  564.  e.g.   "22-Dec-92 08:10:26" , no leading day
  565.  
  566.  Entry    :
  567.  
  568.  
  569.  Returns  :   TRUE if successful, FALSE otherwise
  570.  
  571.  
  572.  
  573.  ****************************************************************************/
  574.  
  575. BOOLEAN
  576. str2dss (char *str, DATESTAMP * ds)
  577.  
  578. {
  579. /* 012345678901234567 */
  580. /* 22-Dec-92 08:10:26 */
  581.  
  582.   char *p = str;
  583.   ULONG dss_days;
  584.  
  585.   int day, month, year, hour, min, sec, diy, j, k, rem;
  586.  
  587.   p[2] = '\0';
  588.   p[6] = '\0';
  589.   p[9] = '\0';
  590.   p[12] = '\0';
  591.   p[15] = '\0';
  592.  
  593.   day = atoi (&p[0]);
  594.   year = atoi (&p[7]) + 1900;
  595.   hour = atoi (&p[10]);
  596.   min = atoi (&p[13]);
  597.   sec = atoi (&p[16]);
  598.  
  599.   /*
  600.    * compute days-in-year from month
  601.    * - may be incremented later if a leap year
  602.    */
  603.   for (p = str + 3, j = 0, diy = 0;; ++j)
  604.     {
  605.       if (j == 12)
  606.     return FALSE;
  607.       if (strcmp (p, days_month[j].months) == 0)
  608.     {
  609.       month = j + 1;
  610.       break;
  611.     }
  612.       diy += days_month[j].days;
  613.     }
  614.  
  615.   /*
  616.    * tricky bit ; adjust for leap years
  617.    */
  618.   dss_days = diy + day - 1;
  619.   dss_days += 2 * 365;        /* 1978, 1979 */
  620.   for (j = 1980, k = 0;;)
  621.     {
  622.       dss_days += 365;
  623.       if ((rem = (k++ % 4)) == 0)
  624.     dss_days += 1;        /* leap year */
  625.  
  626.       if (++j == year)
  627.     {
  628.       if (((rem = (k++ % 4)) == 0) && (month > 2))
  629.         {
  630.           dss_days += 1;
  631.         }
  632.       break;
  633.     }
  634.     }
  635.  
  636.   ds->ds_Days = dss_days;
  637.   /*
  638.    * now fill in mins, ticks in min
  639.    */
  640.   ds->ds_Minute = (60 * hour) + min;
  641.   ds->ds_Tick = sec * TICKS_PER_SECOND;
  642.  
  643.   return TRUE;
  644. }
  645.  
  646. /***************************************************************************
  647.  
  648.  
  649.  Function :     Init_Timer
  650.  
  651.  Purpose:       Inits timer
  652.  
  653.  Entry    :
  654.  
  655.  
  656.  Returns  :
  657.  
  658.  
  659.  
  660.  ****************************************************************************/
  661.  
  662.  
  663. void
  664. Init_Timer (void)
  665. {
  666.  
  667.   int error;
  668.  
  669.   TimeP = CreatePort (0, 0);
  670.   if (TimeP == NULL)
  671.     hexit (1);
  672.  
  673.   Timermsg = (TIMERREQUEST *) CreateExtIO (TimeP, sizeof (TIMERREQUEST));
  674.   if (Timermsg == NULL)
  675.     {
  676.       hexit (1);
  677.     }
  678.  
  679.   error = OpenDevice (TIMERNAME, UNIT_MICROHZ, (IOREQUEST *) Timermsg, 0);
  680.   if (error != 0)
  681.     {
  682.       DeleteExtIO ((IOREQUEST *) Timermsg);
  683.       hexit (1);
  684.     }
  685. }
  686.  
  687.  
  688. /***************************************************************************
  689.  
  690.  
  691.  Function :      hexit
  692.  
  693.  
  694.  Purpose  :      cleans up and exits
  695.  
  696.  
  697.  Entry    :
  698.  
  699.  
  700.  Returns  :
  701.  
  702.  
  703.  
  704.  ****************************************************************************/
  705.  
  706.  
  707. void
  708. hexit (int fred)
  709. {
  710.  
  711.   if (UtilityBase)
  712.     {
  713.       CloseLibrary (UtilityBase);
  714.     }
  715.  
  716.   if (Timermsg != NULL)
  717.     {
  718.       DeleteTimer (Timermsg);
  719.     }
  720.   /*
  721.    * close log file if open
  722.    */
  723.   if (fp)
  724.     fclose (fp);
  725.  
  726.   exit (0);
  727. }
  728.  
  729. /***************************************************************************
  730.  
  731.  
  732.  Function :     DeleteTimer
  733.  
  734.  Purpose:       Deletes Timer
  735.  
  736.  Entry    :
  737.  
  738.  
  739.  Returns  :
  740.  
  741.  
  742.  
  743.  ****************************************************************************/
  744.  
  745.  
  746. void
  747. DeleteTimer (TIMERREQUEST * tr)
  748. {
  749.   MSGPORT *tp;
  750.  
  751.   tp = tr->tr_node.io_Message.mn_ReplyPort;
  752.   if (tr != 0)
  753.     {
  754.       CloseDevice ((IOREQUEST *) tr);
  755.       DeleteExtIO ((IOREQUEST *) tr);
  756.     }
  757.   if (tp != 0)
  758.     DeletePort (tp);
  759. }
  760.  
  761. /***************************************************************************
  762.  
  763.  
  764.  Function :     tv_diff
  765.  
  766.  
  767.  Purpose  :     returns difference in msecs between two TIMEVALS,
  768.  or -1 if overflow 
  769.  Entry    :
  770.  
  771.  
  772.  Returns  :
  773.  
  774.  
  775.  
  776.  ****************************************************************************/
  777.  
  778. LONG
  779. tv_diff (TIMEVAL * tv1, TIMEVAL * tv2)
  780. {
  781.   LONG val;
  782.  
  783.   val = (LONG) tv2->tv_secs - (LONG) tv1->tv_secs;
  784.   /*
  785.    * quick and nasty range check
  786.    */
  787.   if (labs (val) > 4294966L)
  788.     return -1;
  789.  
  790.   val *= 1000;
  791.  
  792.   val += (((LONG) tv2->tv_micro) - ((LONG) tv1->tv_micro)) / 1000;
  793.  
  794.   return val;
  795. }
  796.  
  797.    /***************************************************************************
  798.  
  799.  
  800.     Function :     tv_diff_str
  801.  
  802.  
  803.     Purpose  :     returns difference in msecs between two TIMEVALS
  804.     expressed as secs.msecs string
  805.  
  806.     Entry    :
  807.  
  808.  
  809.     Returns  :
  810.  
  811.  
  812.  
  813.     ****************************************************************************/
  814.  
  815. char *
  816. tv_diff_str (TIMEVAL * tv1, TIMEVAL * tv2)
  817. {
  818.   LONG val;
  819.  
  820.   val = tv_diff (tv1, tv2);
  821.  
  822.   return (format_diff_str (val, " (%s)"));
  823. }
  824.  
  825. /***************************************************************************
  826.  
  827.  
  828.  Function :     format_diff_str
  829.  
  830.  
  831.  Purpose  :     formats diff string
  832.  
  833.  Entry    :
  834.  
  835.  
  836.  Returns  :
  837.  
  838.  
  839.  
  840.  ****************************************************************************/
  841.  
  842. char *
  843. format_diff_str (LONG val, char *form)
  844. {
  845.   static char mbuf[80];
  846.   char tmp[80];
  847.  
  848.   tmp[0] = ' ';
  849.  
  850.   if (val == -1)
  851.     {
  852.       return " ( >999.999 ) ";
  853.     }
  854.  
  855.   if (val < 0)
  856.     {
  857.       tmp[0] = '-';
  858.       val = -val;
  859.     }
  860.   else if (val > 0)
  861.     {
  862.       tmp[0] = '+';
  863.     }
  864.   if (val > 999999)
  865.     {
  866.       return " ( >999.999 ) ";
  867.     }
  868.  
  869.   sprintf (&tmp[1], " %3d.%03d", val / 1000, val % 1000);
  870.  
  871.   sprintf (mbuf, form, tmp);
  872.   return mbuf;
  873. }
  874.  
  875. /***************************************************************************
  876.  
  877.  
  878.  Function :     set_system_time
  879.  
  880.  Purpose:       sets system date/time
  881.  
  882.  Entry    :     TIMEVAL
  883.  
  884.  
  885.  Returns  :     void
  886.  
  887.  
  888.  ****************************************************************************/
  889.  
  890. void
  891. set_system_time (TIMEVAL * tv)
  892. {
  893.  
  894.   Timermsg->tr_node.io_Command = TR_SETSYSTIME;
  895.   Timermsg->tr_time.tv_secs = tv->tv_secs;
  896.   Timermsg->tr_time.tv_micro = tv->tv_micro;
  897.  
  898.   if (DoIO ((IOREQUEST *) Timermsg))
  899.     {
  900.       fprintf (stderr, "set_system_time() - DoIO fail\n");
  901.       hexit (1);
  902.     }
  903. }
  904.  
  905. /***************************************************************************
  906.  
  907.  
  908.  Function :     get_system_time
  909.  
  910.  Purpose:       gets system date/time
  911.  
  912.  Entry    :     ptr to TIMEVAL
  913.  
  914.  
  915.  Returns  :     void
  916.  
  917.  
  918.  ****************************************************************************/
  919.  
  920. void
  921. get_system_time (TIMEVAL * tv)
  922. {
  923.  
  924.   Timermsg->tr_node.io_Command = TR_GETSYSTIME;
  925.  
  926.   if (DoIO ((IOREQUEST *) Timermsg))
  927.     {
  928.       fprintf (stderr, "get_time() - DoIO fail\n");
  929.       hexit (1);
  930.     }
  931.   tv->tv_secs = Timermsg->tr_time.tv_secs;
  932.   tv->tv_micro = Timermsg->tr_time.tv_micro;
  933. }
  934.  
  935. /***************************************************************************
  936.  
  937.  
  938.  Function :     get_battclock_time
  939.  
  940.  Purpose:       Get Battery Backed-up Clock time
  941.  
  942.  Entry    :    ptr to TIMEVAL structure
  943.  
  944.  Returns  :
  945.  
  946.  
  947.  ****************************************************************************/
  948.  
  949.  
  950. void
  951. get_battclock_time (TIMEVAL * tv)
  952.  
  953. {
  954.  
  955.   tv->tv_secs = ReadBattClock ();
  956.   tv->tv_micro = 0;
  957. }
  958.  
  959. /***************************************************************************
  960.  
  961.  
  962.  Function :     set_battclock_time
  963.  
  964.  Purpose:       Set Battery Backed-up Clock time
  965.  
  966.  Entry    :    ptr to TIMEVAL structure
  967.  
  968.  Returns  :
  969.  
  970.  
  971.  ****************************************************************************/
  972.  
  973.  
  974. void
  975. set_battclock_time (TIMEVAL * tv)
  976.  
  977. {
  978.   WriteBattClock (tv->tv_secs);
  979. }
  980.  
  981. /***************************************************************************
  982.  
  983.  
  984.  Function :     tv_update
  985.  
  986.  
  987.  Purpose  :     updates a TIMEVAL with nnn msecs
  988.  
  989.  Entry    :
  990.  
  991.  
  992.  Returns  :
  993.  
  994.  
  995.  
  996.  ****************************************************************************/
  997.  
  998. void
  999. tv_update (TIMEVAL * tv, LONG msecs)
  1000. {
  1001.   LONG t_secs, t_msecs;
  1002.   TIMEVAL tv_tmp = *tv;
  1003.   BOOL flag = TRUE;
  1004.  
  1005.   if (msecs < 0)
  1006.     {
  1007.       flag = FALSE;
  1008.       msecs = -msecs;
  1009.     }
  1010.   t_secs = msecs / 1000;
  1011.   t_msecs = msecs % 1000;
  1012.  
  1013.   /*
  1014.      * conv microsecs field to msecs
  1015.    */
  1016.   tv_tmp.tv_micro %= 1000;
  1017.  
  1018.   if (flag == TRUE)
  1019.     {
  1020.       /* add */
  1021.  
  1022.       tv_tmp.tv_micro += t_msecs;
  1023.       if (tv_tmp.tv_micro >= 1000)
  1024.     {
  1025.       tv_tmp.tv_micro %= 1000;
  1026.       tv_tmp.tv_secs += 1;
  1027.     }
  1028.       tv_tmp.tv_secs += t_secs;
  1029.     }
  1030.   else
  1031.     {
  1032.       /* subtract */
  1033.  
  1034.       if (tv_tmp.tv_micro < t_msecs)
  1035.     {
  1036.       tv_tmp.tv_micro += 1000 - t_msecs;
  1037.       tv_tmp.tv_secs -= 1;
  1038.     }
  1039.       tv_tmp.tv_secs -= t_secs;
  1040.     }
  1041.   /*
  1042.      * conv  msecs back to microsecs
  1043.    */
  1044.   tv_tmp.tv_micro *= 1000;
  1045.   /*
  1046.      * update given TIMEVAL
  1047.    */
  1048.  
  1049.   *tv = tv_tmp;
  1050. }
  1051.  
  1052. /***************************************************************************
  1053.  
  1054.  
  1055.  Function :     check4battclock
  1056.  
  1057.  Purpose:       Inits other stuff
  1058.  
  1059.  Entry    :
  1060.  
  1061.  
  1062.  Returns  :
  1063.  
  1064.  
  1065.  
  1066.  ****************************************************************************/
  1067.  
  1068.  
  1069. BOOL
  1070. check4battclock (void)
  1071. {
  1072.  
  1073.   UtilityBase = (LIBRARY *) OpenLibrary ("diskfont.library", 0L);
  1074.  
  1075.  
  1076.   if (UtilityBase == NULL)
  1077.     {
  1078.       fprintf (stderr, "Can't open diskfont.library\n");
  1079.       return FALSE;
  1080.     }
  1081.  
  1082.   UtilityBase = (LIBRARY *) OpenLibrary ("utility.library", EARLIEST_LIB);
  1083.  
  1084.   if (UtilityBase == NULL)
  1085.     {
  1086.       fprintf (stderr, "Abort: only runs under AmigaDOS 2.04 and above\n");
  1087.       return FALSE;
  1088.     }
  1089.   /*
  1090.      * see if Battery Clock there
  1091.    */
  1092.  
  1093.   BattClockBase = OpenResource (BATTCLOCKNAME);
  1094.   if (BattClockBase == NULL)
  1095.     {
  1096.       fprintf (stderr, "Abort: can't find a Battery Clock\n");
  1097.       return FALSE;
  1098.     }
  1099.   return TRUE;
  1100. }
  1101.  
  1102. /***************************************************************************
  1103.  
  1104.  
  1105.  Function :     get_syncd_battclock_time
  1106.  
  1107.  Purpose:       reads battclock and returns when sec just ticked over
  1108.  
  1109.  Entry    :
  1110.  
  1111.  
  1112.  Returns  :
  1113.  
  1114.  
  1115.  
  1116.  ****************************************************************************/
  1117.  
  1118. void
  1119. get_syncd_battclock_time (TIMEVAL * tv)
  1120. {
  1121.   TIMEVAL tv_tmp;
  1122.  
  1123.   get_battclock_time (&tv_tmp);
  1124.   do
  1125.     {
  1126.       get_battclock_time (tv);
  1127.     }
  1128.   while (tv_tmp.tv_secs == tv->tv_secs);
  1129. }
  1130.  
  1131. /***************************************************************************
  1132.  
  1133.  
  1134.  Function :     get_syncd_system_time
  1135.  
  1136.  Purpose:       reads sysclock and returns when sec just ticked over
  1137.  
  1138.  Entry    :
  1139.  
  1140.  
  1141.  Returns  :
  1142.  
  1143.  
  1144.  
  1145.  ****************************************************************************/
  1146.  
  1147. void
  1148. get_syncd_system_time (TIMEVAL * tv)
  1149. {
  1150.   TIMEVAL tv_tmp;
  1151.  
  1152.   get_system_time (&tv_tmp);
  1153.   do
  1154.     {
  1155.       get_system_time (tv);
  1156.     }
  1157.   while (tv_tmp.tv_secs == tv->tv_secs);
  1158. }
  1159.  
  1160. /***************************************************************************
  1161.  
  1162.  
  1163.  Function :     print_clock
  1164.  
  1165.  Purpose:       prints clock time surrounded by given strings
  1166.  
  1167.  Entry    :
  1168.  
  1169.  
  1170.  Returns  :
  1171.  
  1172.  
  1173.  
  1174.  ****************************************************************************/
  1175.  
  1176. void
  1177. print_clock (char *pre, TIMEVAL * tv, char *post)
  1178. {
  1179.  
  1180.   /*
  1181.      * print results
  1182.    */
  1183.   printf ("%s%s%s", pre, tv2str (tv), post);
  1184.   fflush (stdout);
  1185. }
  1186.  
  1187. /***************************************************************************
  1188.  
  1189.  
  1190.  Function :     display both clocks
  1191.  
  1192.  Purpose:       as the name suggests
  1193.  
  1194.  Entry    :
  1195.  
  1196.  
  1197.  Returns  :
  1198.  
  1199.  
  1200.  
  1201.  ****************************************************************************/
  1202.  
  1203. void
  1204. display_clocks (TIMEVAL * tv_b, TIMEVAL * tv_s)
  1205. {
  1206.  
  1207.   print_clock ("Battery clock time = ", tv_b, "\n");
  1208.   print_clock ("System  clock time = ", tv_s, tv_diff_str (tv_b, tv_s));
  1209.   printf ("\n");
  1210.  
  1211. }
  1212.  
  1213. /***************************************************************************
  1214.  
  1215.  
  1216.  Function :     adjust a clock
  1217.  
  1218.  Purpose:       adjusts either system clock or  battclock by given
  1219.  number of millisecs
  1220.  
  1221.  Entry    :
  1222.  
  1223.  
  1224.  Returns  :
  1225.  
  1226.  
  1227.  
  1228.  ****************************************************************************/
  1229.  
  1230. void
  1231. adjust_clock (LONG msecs, TIMEVAL * tv)
  1232. {
  1233.   static TIMEVAL tv_tmpx;
  1234.  
  1235.   /*
  1236.      * wait until given clock wraps over a second
  1237.    */
  1238.   if (s_flag == TRUE)
  1239.     {
  1240.       get_syncd_system_time (&tv_sysclock);
  1241.       tv_tmpx = tv_sysclock;
  1242.       tv_update (&tv_tmpx, msecs);
  1243.  
  1244.       set_system_time (&tv_tmpx);
  1245.     }
  1246.   else
  1247.     {
  1248.       LONG res;
  1249.       /*
  1250.          * battclock here
  1251.        */
  1252.       get_syncd_battclock_time (&tv_battclock);
  1253.       tv_tmpx = tv_battclock;
  1254.       tv_update (&tv_tmpx, msecs);
  1255.  
  1256.       res = 1000 - (tv_tmpx.tv_micro / 1000);
  1257.       tv_update (&tv_battclock, 1000);
  1258.       ++tv_tmpx.tv_secs;
  1259.  
  1260.       /*
  1261.          * - wait a bit to account for fraction of a sec
  1262.        */
  1263.       pause (res);
  1264.  
  1265.       set_battclock_time (&tv_tmpx);
  1266.     }
  1267.   *tv = tv_tmpx;
  1268.  
  1269. }
  1270.  
  1271. /***************************************************************************
  1272.  
  1273.  
  1274.  Function :     print_old_new
  1275.  
  1276.  Purpose:       as the name suggests
  1277.  
  1278.  Entry    :
  1279.  
  1280.  
  1281.  Returns  :
  1282.  
  1283.  
  1284.  
  1285.  ***************************************************************************/
  1286.  
  1287. void
  1288. print_old_new (char *ptr, TIMEVAL * tv_old, TIMEVAL * tv_new)
  1289. {
  1290.   printf ("Old %s clock time = ", ptr);
  1291.   print_clock ("", tv_old, "\n");
  1292.  
  1293.   printf ("New %s clock time = ", ptr);
  1294.   print_clock ("", tv_new, tv_diff_str (tv_old, tv_new));
  1295.   printf ("\n");
  1296.  
  1297. }
  1298.  
  1299. /***************************************************************************
  1300.  
  1301.  
  1302.  Function :     set_system_time_to_syncd_battclock
  1303.  
  1304.  Purpose:       sets system clock to battclock time when it ticks
  1305.  over a second.
  1306.  
  1307.  Entry    :
  1308.  
  1309.  
  1310.  Returns  :
  1311.  
  1312.  
  1313.  
  1314.  ***************************************************************************/
  1315.  
  1316. LONG
  1317. set_system_time_to_syncd_battclock ()
  1318. {
  1319.   get_syncd_battclock_time (&tv_battclock);
  1320.   get_system_time (&tv_sysclock);
  1321.   set_system_time (&tv_battclock);
  1322.  
  1323.   return (tv_diff (&tv_battclock, &tv_sysclock));
  1324. }
  1325.  
  1326. /***************************************************************************
  1327.  
  1328.  
  1329.  Function :     set_battclock_time_to_syncd_system_time
  1330.  
  1331.  Purpose:       sets battery clock to system time when it ticks
  1332.  over a second.
  1333.  
  1334.  Entry    :
  1335.  
  1336.  
  1337.  Returns  :
  1338.  
  1339.  
  1340.  ****************************************************************************/
  1341.  
  1342. LONG
  1343. set_battclock_time_to_syncd_system_time ()
  1344. {
  1345.   TIMEVAL tv_tmp;
  1346.   LONG diff;
  1347.  
  1348.   /*
  1349.      * we need to mess around a bit to get diff
  1350.      * between batt and system clock because batt clock
  1351.      * is only accurate to 1 sec
  1352.    */
  1353.   get_syncd_battclock_time (&tv_battclock);
  1354.   get_system_time (&tv_tmp);
  1355.   diff = tv_diff (&tv_battclock, &tv_tmp);
  1356.  
  1357.   get_syncd_system_time (&tv_sysclock);
  1358.   set_battclock_time (&tv_sysclock);
  1359.  
  1360.   /*
  1361.      * now correct battclock time to give msecs precision
  1362.      * PROVIDED that diff was in range (<999 secs) else ignore
  1363.      * trying to be precise.
  1364.    */
  1365.   if (diff != -1)
  1366.     {
  1367.       tv_battclock = tv_sysclock;
  1368.       tv_update (&tv_battclock, diff);
  1369.     }
  1370.  
  1371.   return (-diff);
  1372. }
  1373.  
  1374. /***************************************************************************
  1375.  
  1376.  
  1377.  Function :      wait_for_timer
  1378.  
  1379.  Purpose:       Waits until given time expires
  1380.  
  1381.  Entry    :
  1382.  
  1383.  
  1384.  Returns  :
  1385.  
  1386.  
  1387.  
  1388.  ****************************************************************************/
  1389.  
  1390.  
  1391. void
  1392. wait_for_timer (TIMERREQUEST * tr, TIMEVAL * tv)
  1393.  
  1394. {
  1395.   MSGPORT *tp;
  1396.   ULONG flags;
  1397.  
  1398.   tp = tr->tr_node.io_Message.mn_ReplyPort;
  1399.  
  1400.   tr->tr_node.io_Command = TR_ADDREQUEST;
  1401.   tr->tr_time.tv_secs = tv->tv_secs;
  1402.   tr->tr_time.tv_micro = tv->tv_micro;
  1403.   SendIO ((IOREQUEST *) tr);
  1404.  
  1405.  
  1406.   flags = Wait ((1L << tp->mp_SigBit) | SIGBREAKF_CTRL_C);
  1407.   if (flags & SIGBREAKF_CTRL_C)
  1408.     {
  1409.       AbortIO ((IOREQUEST *) tr);
  1410.       WaitIO ((IOREQUEST *) tr);
  1411.       hexit (1);
  1412.     }
  1413. }
  1414.  
  1415. /***************************************************************************
  1416.  
  1417.  
  1418.  Function :      pause
  1419.  
  1420.  
  1421.  Purpose  :      waits for given millisecs
  1422.  ( or until ^C hit )
  1423.  
  1424.  Entry    :
  1425.  
  1426.  
  1427.  Returns  :
  1428.  
  1429.  
  1430.  
  1431.  ****************************************************************************/
  1432.  
  1433.  
  1434. void
  1435. pause (int millisecs)
  1436. {
  1437.   static TIMEVAL tv;
  1438.  
  1439.   tv.tv_secs = millisecs / 1000;
  1440.   tv.tv_micro = (millisecs % 1000) * 1000;
  1441.  
  1442.   wait_for_timer (Timermsg, &tv);
  1443. }
  1444.  
  1445.  
  1446. /***************************************************************************
  1447.  
  1448.  
  1449.  Function :     scan_args
  1450.  
  1451.  Purpose:       scans and validates command line
  1452.  
  1453.  Entry    :
  1454.  
  1455.  
  1456.  Returns  :
  1457.  
  1458.  
  1459.  
  1460.  ****************************************************************************/
  1461.  
  1462.  
  1463.  
  1464. void
  1465. scan_args (int argc, char **argv)
  1466.  
  1467. {
  1468.   char *ptr;
  1469.   char arch;
  1470.   char plusminus;
  1471.   int a = 0;
  1472.   int n = 0;
  1473.   int b = 0;
  1474.   int d = 0;
  1475.   int s = 0;
  1476.   int t = 0;
  1477.   int l = 0;
  1478.   int L = 0;
  1479.  
  1480.  
  1481.   while (--argc)
  1482.     {
  1483.       ptr = *++argv;
  1484.       plusminus = *ptr++;
  1485.       /*
  1486.          * now look for options
  1487.        */
  1488.       if ((plusminus == '-') || (plusminus == '+'))
  1489.     {
  1490.       ++opt_count;
  1491.       arch = *ptr++;
  1492.  
  1493.       switch (arch)
  1494.         {
  1495.  
  1496.         case 'a':        /* adjust clock time */
  1497.           if (a++)
  1498.         {
  1499.           fprintf (stderr, "too many -a options\n");
  1500.           hexit (1);
  1501.         }
  1502.           a_flag = TRUE;
  1503.           if (sscanf (ptr, "%d", &adjust) != 1)
  1504.         {
  1505.           fprintf (stderr, "bad -a option value\n");
  1506.           hexit (1);
  1507.         }
  1508.           if (plusminus == '-')
  1509.         adjust = -adjust;
  1510.  
  1511.           break;
  1512.  
  1513.         case 'b':
  1514.           if (b++)
  1515.         {
  1516.           fprintf (stderr, "too many -b options\n");
  1517.           hexit (1);
  1518.         }
  1519.           b_flag = TRUE;
  1520.           break;
  1521.  
  1522.         case 'd':
  1523.           if (d++)
  1524.         {
  1525.           fprintf (stderr, "too many -d options\n");
  1526.           hexit (1);
  1527.         }
  1528.           d_flag = TRUE;
  1529.           date_ptr = ptr;
  1530.           break;
  1531.  
  1532.         case 't':
  1533.           if (t++)
  1534.         {
  1535.           fprintf (stderr, "too many -t options\n");
  1536.           hexit (1);
  1537.         }
  1538.           t_flag = TRUE;
  1539.           time_ptr = ptr;
  1540.           break;
  1541.  
  1542.         case 's':
  1543.           if (s++)
  1544.         {
  1545.           fprintf (stderr, "too many -s options\n");
  1546.           hexit (1);
  1547.         }
  1548.           s_flag = TRUE;
  1549.           break;
  1550.  
  1551.  
  1552.         case 'h':
  1553.           usage ("");    /* help */
  1554.           hexit (1);
  1555.  
  1556.         case 'l':
  1557.           if (l++)
  1558.         {
  1559.           fprintf (stderr, "too many -l options\n");
  1560.           hexit (1);
  1561.         }
  1562.           l_flag = TRUE;
  1563.           logfile = (*ptr) ? ptr : "LOG_CLOCKTOOL:";
  1564.           if ((fp = fopen (logfile, "a")) == NULL)
  1565.         {
  1566.           fprintf (stderr, "Can't open %s\n", logfile);
  1567.           hexit (1);
  1568.         }
  1569.           break;
  1570.  
  1571.         case 'L':
  1572.           if (L++)
  1573.         {
  1574.           fprintf (stderr, "too many -L options\n");
  1575.           hexit (1);
  1576.         }
  1577.           L_flag = TRUE;
  1578.           logfile = (*ptr) ? ptr : "LOG_CLOCKTOOL:";
  1579.           if ((fp = fopen (logfile, "a")) == NULL)
  1580.         {
  1581.           fprintf (stderr, "Can't open %s\n", logfile);
  1582.           hexit (1);
  1583.         }
  1584.           break;
  1585.  
  1586.         case 'n':        /* put str in log file entry    */
  1587.           if (n++)
  1588.         {
  1589.           fprintf (stderr, "too many -n options\n");
  1590.           hexit (1);
  1591.         }
  1592.           n_flag = TRUE;
  1593.           xstr = ptr;
  1594.           break;
  1595.  
  1596.         default:
  1597.           usage ("unknown option");        /* bad option   */
  1598.           hexit (1);
  1599.  
  1600.         }
  1601.     }
  1602.       else
  1603.     {
  1604.       usage ("not an option");
  1605.       hexit (1);
  1606.     }
  1607.     }
  1608.  
  1609.   if (opt_count == 0)
  1610.     return;
  1611.  
  1612.   /*
  1613.      * now validate options
  1614.    */
  1615.  
  1616.   if (b_flag && s_flag)
  1617.     {
  1618.       usage ("only one -b or -s option");    /* bad option   */
  1619.       hexit (1);
  1620.     }
  1621.  
  1622.   if ((b_flag == FALSE) && (s_flag == FALSE))
  1623.     {
  1624.       usage ("need -b or -s option");    /* bad option   */
  1625.       hexit (1);
  1626.     }
  1627.  
  1628.   if (d_flag || t_flag)
  1629.     {
  1630.       if (d_flag)
  1631.     {
  1632.       if (*date_ptr == '\0')
  1633.         {
  1634.           fprintf (stderr, "need a date string\n");
  1635.           hexit (1);
  1636.         }
  1637.     }
  1638.  
  1639.       if (t_flag)
  1640.     {
  1641.       if (*time_ptr == '\0')
  1642.         {
  1643.           fprintf (stderr, "need a time string\n");
  1644.           hexit (1);
  1645.         }
  1646.     }
  1647.       return;
  1648.     }
  1649.  
  1650.   if (l_flag && L_flag)
  1651.     {
  1652.       usage ("only one -l or -L option");    /* bad option   */
  1653.       hexit (1);
  1654.     }
  1655.  
  1656.   if ((opt_count > 2) && (a_flag == TRUE))
  1657.     {
  1658.       usage ("invalid options with -a option");        /* bad option   */
  1659.       hexit (1);
  1660.     }
  1661.  
  1662.   if ((opt_count > 2) && (n_flag == FALSE))
  1663.     {
  1664.       usage ("need a -n option");    /* bad option   */
  1665.       hexit (1);
  1666.     }
  1667. }
  1668.  
  1669. /***************************************************************************
  1670.  
  1671.  
  1672.  Function :     usage
  1673.  
  1674.  Purpose:       prints invocation parameters
  1675.  
  1676.  Entry    :
  1677.  
  1678.  
  1679.  Returns  :
  1680.  
  1681.  
  1682.  
  1683.  ****************************************************************************/
  1684.  
  1685. void
  1686. usage (char *p)
  1687.  
  1688.  
  1689. {
  1690.   static char *rats[] =
  1691.   {
  1692.     "Usage modes :-",
  1693.     " 1) display both   : clocktool",
  1694.     " 2) set selected",
  1695.     "    from other     : clocktool -[b | s]",
  1696.     " 3) set date/time  : clocktool -[b | s] -d<date> -t<time> ",
  1697.     " 4) adjust         : clocktool -[b | s] +|-a<n>",
  1698.     " 5) log then reset : clocktool -[b | s] -l<file> [-n<str>]",
  1699.     " 6) log  only      : clocktool -[b | s] -L<file> [-n<str>]",
  1700.     "\nOptions:",
  1701.     "    -b         : battery clock",
  1702.     "    -s         : system  clock",
  1703.     "    -d<str>    : set selected clock's date to str (dd-MMM-yy)",
  1704.     "    -t<str>    : set selected clock's time to str (hh:mm[:ss])",
  1705.     "                   (can use either or both d/t options)",
  1706.     "",
  1707.  
  1708.     "    +|-a<n>    : change selected clock by + or - <n> millisecs",
  1709.     "",
  1710.     "    -l<file>   : log time of clock to <file> ; reset from other",
  1711.     "                     (default file =  LOG_CLOCKTOOL:)",
  1712.     "    -L<file>   : log time of clock to <file> ; don't reset from other",
  1713.     "                     (default file =  LOG_CLOCKTOOL:)",
  1714.     "    -n<str>    : append the <str> to log file entry, e.g. \"reboot\"",
  1715.     NULL
  1716.   };
  1717.   int j = 0;
  1718.   char *ptr;
  1719.  
  1720.  
  1721.  
  1722.   if (*p)
  1723.     printf ("Error: %s\n\n", p);
  1724.  
  1725.   printf (
  1726.   "%s: Displays/adjusts/sets times of battery clock and/or system clock\n\n",
  1727.        "ClockTool");
  1728.   printf (
  1729.        "Version %s [%s : %s] written by gduncan\n\n",
  1730.        VERSION, __DATE__, __TIME__);
  1731.  
  1732.   while (ptr = rats[j++])
  1733.     printf ("%s\n", ptr);
  1734. }
  1735.  
  1736. /**/
  1737.