home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / sendmail-5.65c+IDA-1.4.4.1 / src / RCS / convtime.c,v < prev    next >
Encoding:
Text File  |  1991-06-25  |  5.1 KB  |  306 lines

  1. head    5.4;
  2. branch    5.4.0;
  3. access;
  4. symbols
  5.     RELEASE:5.4.0.5
  6.     BETA:5.4.0.4
  7.     UICSO:5.4.0
  8.     VANILLA:5.4;
  9. locks; strict;
  10. comment    @ * @;
  11.  
  12.  
  13. 5.4
  14. date    90.06.20.08.35.34;    author paul;    state Exp;
  15. branches
  16.     5.4.0.1;
  17. next    ;
  18.  
  19. 5.4.0.1
  20. date    90.10.05.14.32.02;    author paul;    state Exp;
  21. branches;
  22. next    5.4.0.2;
  23.  
  24. 5.4.0.2
  25. date    90.11.26.20.13.19;    author paul;    state Exp;
  26. branches;
  27. next    5.4.0.3;
  28.  
  29. 5.4.0.3
  30. date    91.04.05.14.55.15;    author paul;    state Exp;
  31. branches;
  32. next    5.4.0.4;
  33.  
  34. 5.4.0.4
  35. date    91.05.18.17.22.24;    author paul;    state Exp;
  36. branches;
  37. next    5.4.0.5;
  38.  
  39. 5.4.0.5
  40. date    91.06.21.12.40.29;    author paul;    state Exp;
  41. branches;
  42. next    ;
  43.  
  44.  
  45. desc
  46. @@
  47.  
  48.  
  49. 5.4
  50. log
  51. @5.64 Berkeley release
  52. @
  53. text
  54. @/*
  55.  * Copyright (c) 1983 Eric P. Allman
  56.  * Copyright (c) 1988 Regents of the University of California.
  57.  * All rights reserved.
  58.  *
  59.  * Redistribution and use in source and binary forms are permitted provided
  60.  * that: (1) source distributions retain this entire copyright notice and
  61.  * comment, and (2) distributions including binaries display the following
  62.  * acknowledgement:  ``This product includes software developed by the
  63.  * University of California, Berkeley and its contributors'' in the
  64.  * documentation or other materials provided with the distribution and in
  65.  * all advertising materials mentioning features or use of this software.
  66.  * Neither the name of the University nor the names of its contributors may
  67.  * be used to endorse or promote products derived from this software without
  68.  * specific prior written permission.
  69.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  70.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  71.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  72.  */
  73.  
  74. #ifndef lint
  75. static char sccsid[] = "@@(#)convtime.c    5.4 (Berkeley) 6/1/90";
  76. #endif /* not lint */
  77.  
  78. # include <ctype.h>
  79. # include "useful.h"
  80.  
  81. /*
  82. **  CONVTIME -- convert time
  83. **
  84. **    Takes a time as an ascii string with a trailing character
  85. **    giving units:
  86. **      s -- seconds
  87. **      m -- minutes
  88. **      h -- hours
  89. **      d -- days (default)
  90. **      w -- weeks
  91. **    For example, "3d12h" is three and a half days.
  92. **
  93. **    Parameters:
  94. **        p -- pointer to ascii time.
  95. **
  96. **    Returns:
  97. **        time in seconds.
  98. **
  99. **    Side Effects:
  100. **        none.
  101. */
  102.  
  103. time_t
  104. convtime(p)
  105.     char *p;
  106. {
  107.     register time_t t, r;
  108.     register char c;
  109.  
  110.     r = 0;
  111.     while (*p != '\0')
  112.     {
  113.         t = 0;
  114.         while (isdigit(c = *p++))
  115.             t = t * 10 + (c - '0');
  116.         if (c == '\0')
  117.             p--;
  118.         switch (c)
  119.         {
  120.           case 'w':        /* weeks */
  121.             t *= 7;
  122.  
  123.           case 'd':        /* days */
  124.           default:
  125.             t *= 24;
  126.  
  127.           case 'h':        /* hours */
  128.             t *= 60;
  129.  
  130.           case 'm':        /* minutes */
  131.             t *= 60;
  132.  
  133.           case 's':        /* seconds */
  134.             break;
  135.         }
  136.         r += t;
  137.     }
  138.  
  139.     return (r);
  140. }
  141. /*
  142. **  PINTVL -- produce printable version of a time interval
  143. **
  144. **    Parameters:
  145. **        intvl -- the interval to be converted
  146. **        brief -- if TRUE, print this in an extremely compact form
  147. **            (basically used for logging).
  148. **
  149. **    Returns:
  150. **        A pointer to a string version of intvl suitable for
  151. **            printing or framing.
  152. **
  153. **    Side Effects:
  154. **        none.
  155. **
  156. **    Warning:
  157. **        The string returned is in a static buffer.
  158. */
  159.  
  160. # define PLURAL(n)    ((n) == 1 ? "" : "s")
  161.  
  162. char *
  163. pintvl(intvl, brief)
  164.     time_t intvl;
  165.     bool brief;
  166. {
  167.     static char buf[256];
  168.     register char *p;
  169.     int wk, dy, hr, mi, se;
  170.  
  171.     if (intvl == 0 && !brief)
  172.         return ("zero seconds");
  173.  
  174.     /* decode the interval into weeks, days, hours, minutes, seconds */
  175.     se = intvl % 60;
  176.     intvl /= 60;
  177.     mi = intvl % 60;
  178.     intvl /= 60;
  179.     hr = intvl % 24;
  180.     intvl /= 24;
  181.     if (brief)
  182.         dy = intvl;
  183.     else
  184.     {
  185.         dy = intvl % 7;
  186.         intvl /= 7;
  187.         wk = intvl;
  188.     }
  189.  
  190.     /* now turn it into a sexy form */
  191.     p = buf;
  192.     if (brief)
  193.     {
  194.         if (dy > 0)
  195.         {
  196.             (void) sprintf(p, "%d+", dy);
  197.             p += strlen(p);
  198.         }
  199.         (void) sprintf(p, "%02d:%02d:%02d", hr, mi, se);
  200.         return (buf);
  201.     }
  202.  
  203.     /* use the verbose form */
  204.     if (wk > 0)
  205.     {
  206.         (void) sprintf(p, ", %d week%s", wk, PLURAL(wk));
  207.         p += strlen(p);
  208.     }
  209.     if (dy > 0)
  210.     {
  211.         (void) sprintf(p, ", %d day%s", dy, PLURAL(dy));
  212.         p += strlen(p);
  213.     }
  214.     if (hr > 0)
  215.     {
  216.         (void) sprintf(p, ", %d hour%s", hr, PLURAL(hr));
  217.         p += strlen(p);
  218.     }
  219.     if (mi > 0)
  220.     {
  221.         (void) sprintf(p, ", %d minute%s", mi, PLURAL(mi));
  222.         p += strlen(p);
  223.     }
  224.     if (se > 0)
  225.     {
  226.         (void) sprintf(p, ", %d second%s", se, PLURAL(se));
  227.         p += strlen(p);
  228.     }
  229.  
  230.     return (buf + 2);
  231. }
  232. @
  233.  
  234.  
  235. 5.4.0.1
  236. log
  237. @Initialize wk = 0.
  238. @
  239. text
  240. @d116 1
  241. a116 2
  242.     int wk = 0;
  243.     int dy, hr, mi, se;
  244. @
  245.  
  246.  
  247. 5.4.0.2
  248. log
  249. @Commented out un-used assignment at end of procedure.
  250. @
  251. text
  252. @d175 1
  253. a175 1
  254.         /* p += strlen(p);    unused -pbp */
  255. @
  256.  
  257.  
  258. 5.4.0.3
  259. log
  260. @Added RCS ID string
  261. @
  262. text
  263. @a22 1
  264. static char rcsid[] = "@@(#)$Id$";
  265. @
  266.  
  267.  
  268. 5.4.0.4
  269. log
  270. @System 5 and general improvement patches contributed by Bruce Lilly
  271. (bruce%balilly@@broadcast.sony.com).
  272. @
  273. text
  274. @d22 2
  275. a23 2
  276. static char sccsid[] = "@@(#)convtime.c    5.4 (Berkeley) 6/1/90    %I% local";
  277. static char rcsid[] = "@@(#)$Id: convtime.c,v 5.4.0.3 1991/04/05 14:55:15 paul Exp paul $";
  278. d27 1
  279. a27 1
  280. # include "sendmail.h"
  281. d53 1
  282. a53 1
  283.     const char *p;
  284. @
  285.  
  286.  
  287. 5.4.0.5
  288. log
  289. @Use TIME_TYPE instead of time_t.
  290. @
  291. text
  292. @d22 2
  293. a23 2
  294. static char sccsid[] = "@@(#)convtime.c    5.4 (Berkeley) 6/1/90";
  295. static char rcsid[] = "@@(#)$Id: convtime.c,v 5.4.0.4 1991/05/18 17:22:24 paul Exp paul $";
  296. d51 1
  297. a51 1
  298. TIME_TYPE
  299. d55 1
  300. a55 1
  301.     register TIME_TYPE t, r;
  302. d112 1
  303. a112 1
  304.     TIME_TYPE intvl;
  305. @
  306.