home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume39 / rperf / part03 < prev    next >
Encoding:
Text File  |  1993-08-30  |  19.5 KB  |  767 lines

  1. Newsgroups: comp.sources.misc
  2. From: fitz@rpi.edu (Brian P. Fitzgerald)
  3. Subject: v39i071:  rperf - performance monitoring of network hosts, v2.1, Part03/03
  4. Message-ID: <1993Aug30.212026.21063@sparky.sterling.com>
  5. X-Md4-Signature: eec20065afd8ea04b7b001820f8d7c25
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Rensselaer Polytechnic Institute, Troy NY
  8. Date: Mon, 30 Aug 1993 21:20:26 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: fitz@rpi.edu (Brian P. Fitzgerald)
  12. Posting-number: Volume 39, Issue 71
  13. Archive-name: rperf/part03
  14. Environment: UNIX
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then unpack
  18. # it by saving it into a file and typing "sh file".  To overwrite existing
  19. # files, type "sh file -c".  You can also feed this as standard input via
  20. # unshar, or by typing "sh <file", e.g..  The tool that generated this
  21. # shell archive is called "shar", and is available by anonymous ftp
  22. # from ftp.uu.net in subdirectory /usenet/comp.sources.unix, and from many
  23. # other places. Check 'archie' for the latest locations.  If this archive
  24. # is complete, you will see the following message at the end:
  25. #        "End of archive 3 (of 3)."
  26. # Contents:  strftime.c
  27. # Wrapped by fitzgb@mml0.meche.rpi.edu on Mon Aug 30 15:01:25 1993
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f 'strftime.c' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'strftime.c'\"
  31. else
  32. echo shar: Extracting \"'strftime.c'\" \(17080 characters\)
  33. sed "s/^X//" >'strftime.c' <<'END_OF_FILE'
  34. X/*
  35. X * strftime.c
  36. X *
  37. X * Public-domain relatively quick-and-dirty implementation of
  38. X * ANSI library routine for System V Unix systems.
  39. X *
  40. X * It's written in old-style C for maximal portability.
  41. X * However, since I'm used to prototypes, I've included them too.
  42. X *
  43. X * If you want stuff in the System V ascftime routine, add the SYSV_EXT define.
  44. X * For extensions from SunOS, add SUNOS_EXT.
  45. X * For stuff needed to implement the P1003.2 date command, add POSIX2_DATE.
  46. X * For complete POSIX semantics, add POSIX_SEMANTICS.
  47. X *
  48. X * The code for %c, %x, and %X is my best guess as to what's "appropriate".
  49. X * This version ignores LOCALE information.
  50. X * It also doesn't worry about multi-byte characters.
  51. X * So there.
  52. X *
  53. X * This file is also shipped with GAWK (GNU Awk), gawk specific bits of
  54. X * code are included if GAWK is defined.
  55. X *
  56. X * Arnold Robbins
  57. X * January, February, March, 1991
  58. X * Updated March, April 1992
  59. X * Updated May, 1993
  60. X *
  61. X * Fixes from ado@elsie.nci.nih.gov
  62. X * February 1991, May 1992
  63. X * Fixes from Tor Lillqvist tor@tik.vtt.fi
  64. X * May, 1993
  65. X */
  66. X
  67. X#ifndef GAWK
  68. X#include <stdio.h>
  69. X#include <ctype.h>
  70. X#include <string.h>
  71. X#include <time.h>
  72. X#include <sys/types.h>
  73. X#endif
  74. X
  75. X/* defaults: season to taste */
  76. X#define SYSV_EXT    1    /* stuff in System V ascftime routine */
  77. X#define SUNOS_EXT    1    /* stuff in SunOS strftime routine */
  78. X#define POSIX2_DATE    1    /* stuff in Posix 1003.2 date command */
  79. X#define VMS_EXT        1    /* include %v for VMS date format */
  80. X#ifndef GAWK
  81. X#define POSIX_SEMANTICS    1    /* call tzset() if TZ changes */
  82. X#endif
  83. X
  84. X#if defined(POSIX2_DATE)
  85. X#if ! defined(SYSV_EXT)
  86. X#define SYSV_EXT    1
  87. X#endif
  88. X#if ! defined(SUNOS_EXT)
  89. X#define SUNOS_EXT    1
  90. X#endif
  91. X#endif
  92. X
  93. X#if defined(POSIX2_DATE)
  94. X#define adddecl(stuff)    stuff
  95. X#else
  96. X#define adddecl(stuff)
  97. X#endif
  98. X
  99. X#undef strchr    /* avoid AIX weirdness */
  100. X
  101. X#ifndef __STDC__
  102. X#define const    /**/
  103. Xextern void *malloc();
  104. Xextern void *realloc();
  105. Xextern void tzset();
  106. Xextern char *strchr();
  107. Xextern char *getenv();
  108. Xstatic int weeknumber();
  109. Xadddecl(static int iso8601wknum();)
  110. X#else
  111. Xextern void *malloc(unsigned count);
  112. Xextern void *realloc(void *ptr, unsigned count);
  113. Xextern void tzset(void);
  114. Xextern char *strchr(const char *str, int ch);
  115. Xextern char *getenv(const char *v);
  116. Xstatic int weeknumber(const struct tm *timeptr, int firstweekday);
  117. Xadddecl(static int iso8601wknum(const struct tm *timeptr);)
  118. X#endif
  119. X
  120. X#ifdef __GNUC__
  121. X#define inline    __inline__
  122. X#else
  123. X#define inline    /**/
  124. X#endif
  125. X
  126. X#define range(low, item, hi)    max(low, min(item, hi))
  127. X
  128. X#if !defined(MSDOS) && !defined(TZNAME_MISSING)
  129. Xextern char *tzname[2];
  130. Xextern int daylight;
  131. X#endif
  132. X
  133. X/* min --- return minimum of two numbers */
  134. X
  135. X#ifndef __STDC__
  136. Xstatic inline int
  137. Xmin(a, b)
  138. Xint a, b;
  139. X#else
  140. Xstatic inline int
  141. Xmin(int a, int b)
  142. X#endif
  143. X{
  144. X    return (a < b ? a : b);
  145. X}
  146. X
  147. X/* max --- return maximum of two numbers */
  148. X
  149. X#ifndef __STDC__
  150. Xstatic inline int
  151. Xmax(a, b)
  152. Xint a, b;
  153. X#else
  154. Xstatic inline int
  155. Xmax(int a, int b)
  156. X#endif
  157. X{
  158. X    return (a > b ? a : b);
  159. X}
  160. X
  161. X/* strftime --- produce formatted time */
  162. X
  163. X#ifndef __STDC__
  164. Xsize_t
  165. Xstrftime(s, maxsize, format, timeptr)
  166. Xchar *s;
  167. Xsize_t maxsize;
  168. Xconst char *format;
  169. Xconst struct tm *timeptr;
  170. X#else
  171. Xsize_t
  172. Xstrftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
  173. X#endif
  174. X{
  175. X    char *endp = s + maxsize;
  176. X    char *start = s;
  177. X    char tbuf[100];
  178. X    int i;
  179. X    static short first = 1;
  180. X#ifdef POSIX_SEMANTICS
  181. X    static char *savetz = NULL;
  182. X    static int savetzlen = 0;
  183. X    char *tz;
  184. X#endif /* POSIX_SEMANTICS */
  185. X
  186. X    /* various tables, useful in North America */
  187. X    static char *days_a[] = {
  188. X        "Sun", "Mon", "Tue", "Wed",
  189. X        "Thu", "Fri", "Sat",
  190. X    };
  191. X    static char *days_l[] = {
  192. X        "Sunday", "Monday", "Tuesday", "Wednesday",
  193. X        "Thursday", "Friday", "Saturday",
  194. X    };
  195. X    static char *months_a[] = {
  196. X        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  197. X        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
  198. X    };
  199. X    static char *months_l[] = {
  200. X        "January", "February", "March", "April",
  201. X        "May", "June", "July", "August", "September",
  202. X        "October", "November", "December",
  203. X    };
  204. X    static char *ampm[] = { "AM", "PM", };
  205. X
  206. X    if (s == NULL || format == NULL || timeptr == NULL || maxsize == 0)
  207. X        return 0;
  208. X
  209. X    if (strchr(format, '%') == NULL && strlen(format) + 1 >= maxsize)
  210. X        return 0;
  211. X
  212. X#ifndef POSIX_SEMANTICS
  213. X    if (first) {
  214. X        tzset();
  215. X        first = 0;
  216. X    }
  217. X#else    /* POSIX_SEMANTICS */
  218. X    tz = getenv("TZ");
  219. X    if (first) {
  220. X        if (tz != NULL) {
  221. X            int tzlen = strlen(tz);
  222. X
  223. X            savetz = (char *) malloc(tzlen + 1);
  224. X            if (savetz != NULL) {
  225. X                savetzlen = tzlen + 1;
  226. X                strcpy(savetz, tz);
  227. X            }
  228. X        }
  229. X        tzset();
  230. X        first = 0;
  231. X    }
  232. X    /* if we have a saved TZ, and it is different, recapture and reset */
  233. X    if (tz && savetz && (tz[0] != savetz[0] || strcmp(tz, savetz) != 0)) {
  234. X        i = strlen(tz) + 1;
  235. X        if (i > savetzlen) {
  236. X            savetz = (char *) realloc(savetz, i);
  237. X            if (savetz) {
  238. X                savetzlen = i;
  239. X                strcpy(savetz, tz);
  240. X            }
  241. X        } else
  242. X            strcpy(savetz, tz);
  243. X        tzset();
  244. X    }
  245. X#endif    /* POSIX_SEMANTICS */
  246. X
  247. X    for (; *format && s < endp - 1; format++) {
  248. X        tbuf[0] = '\0';
  249. X        if (*format != '%') {
  250. X            *s++ = *format;
  251. X            continue;
  252. X        }
  253. X    again:
  254. X        switch (*++format) {
  255. X        case '\0':
  256. X            *s++ = '%';
  257. X            goto out;
  258. X
  259. X        case '%':
  260. X            *s++ = '%';
  261. X            continue;
  262. X
  263. X        case 'a':    /* abbreviated weekday name */
  264. X            if (timeptr->tm_wday < 0 || timeptr->tm_wday > 6)
  265. X                strcpy(tbuf, "?");
  266. X            else
  267. X                strcpy(tbuf, days_a[timeptr->tm_wday]);
  268. X            break;
  269. X
  270. X        case 'A':    /* full weekday name */
  271. X            if (timeptr->tm_wday < 0 || timeptr->tm_wday > 6)
  272. X                strcpy(tbuf, "?");
  273. X            else
  274. X                strcpy(tbuf, days_l[timeptr->tm_wday]);
  275. X            break;
  276. X
  277. X#ifdef SYSV_EXT
  278. X        case 'h':    /* abbreviated month name */
  279. X#endif
  280. X        case 'b':    /* abbreviated month name */
  281. X            if (timeptr->tm_mon < 0 || timeptr->tm_mon > 11)
  282. X                strcpy(tbuf, "?");
  283. X            else
  284. X                strcpy(tbuf, months_a[timeptr->tm_mon]);
  285. X            break;
  286. X
  287. X        case 'B':    /* full month name */
  288. X            if (timeptr->tm_mon < 0 || timeptr->tm_mon > 11)
  289. X                strcpy(tbuf, "?");
  290. X            else
  291. X                strcpy(tbuf, months_l[timeptr->tm_mon]);
  292. X            break;
  293. X
  294. X        case 'c':    /* appropriate date and time representation */
  295. X            sprintf(tbuf, "%s %s %2d %02d:%02d:%02d %d",
  296. X                days_a[range(0, timeptr->tm_wday, 6)],
  297. X                months_a[range(0, timeptr->tm_mon, 11)],
  298. X                range(1, timeptr->tm_mday, 31),
  299. X                range(0, timeptr->tm_hour, 23),
  300. X                range(0, timeptr->tm_min, 59),
  301. X                range(0, timeptr->tm_sec, 61),
  302. X                timeptr->tm_year + 1900);
  303. X            break;
  304. X
  305. X        case 'd':    /* day of the month, 01 - 31 */
  306. X            i = range(1, timeptr->tm_mday, 31);
  307. X            sprintf(tbuf, "%02d", i);
  308. X            break;
  309. X
  310. X        case 'H':    /* hour, 24-hour clock, 00 - 23 */
  311. X            i = range(0, timeptr->tm_hour, 23);
  312. X            sprintf(tbuf, "%02d", i);
  313. X            break;
  314. X
  315. X        case 'I':    /* hour, 12-hour clock, 01 - 12 */
  316. X            i = range(0, timeptr->tm_hour, 23);
  317. X            if (i == 0)
  318. X                i = 12;
  319. X            else if (i > 12)
  320. X                i -= 12;
  321. X            sprintf(tbuf, "%02d", i);
  322. X            break;
  323. X
  324. X        case 'j':    /* day of the year, 001 - 366 */
  325. X            sprintf(tbuf, "%03d", timeptr->tm_yday + 1);
  326. X            break;
  327. X
  328. X        case 'm':    /* month, 01 - 12 */
  329. X            i = range(0, timeptr->tm_mon, 11);
  330. X            sprintf(tbuf, "%02d", i + 1);
  331. X            break;
  332. X
  333. X        case 'M':    /* minute, 00 - 59 */
  334. X            i = range(0, timeptr->tm_min, 59);
  335. X            sprintf(tbuf, "%02d", i);
  336. X            break;
  337. X
  338. X        case 'p':    /* am or pm based on 12-hour clock */
  339. X            i = range(0, timeptr->tm_hour, 23);
  340. X            if (i < 12)
  341. X                strcpy(tbuf, ampm[0]);
  342. X            else
  343. X                strcpy(tbuf, ampm[1]);
  344. X            break;
  345. X
  346. X        case 'S':    /* second, 00 - 61 */
  347. X            i = range(0, timeptr->tm_sec, 61);
  348. X            sprintf(tbuf, "%02d", i);
  349. X            break;
  350. X
  351. X        case 'U':    /* week of year, Sunday is first day of week */
  352. X            sprintf(tbuf, "%d", weeknumber(timeptr, 0));
  353. X            break;
  354. X
  355. X        case 'w':    /* weekday, Sunday == 0, 0 - 6 */
  356. X            i = range(0, timeptr->tm_wday, 6);
  357. X            sprintf(tbuf, "%d", i);
  358. X            break;
  359. X
  360. X        case 'W':    /* week of year, Monday is first day of week */
  361. X            sprintf(tbuf, "%d", weeknumber(timeptr, 1));
  362. X            break;
  363. X
  364. X        case 'x':    /* appropriate date representation */
  365. X            sprintf(tbuf, "%s %s %2d %d",
  366. X                days_a[range(0, timeptr->tm_wday, 6)],
  367. X                months_a[range(0, timeptr->tm_mon, 11)],
  368. X                range(1, timeptr->tm_mday, 31),
  369. X                timeptr->tm_year + 1900);
  370. X            break;
  371. X
  372. X        case 'X':    /* appropriate time representation */
  373. X            sprintf(tbuf, "%02d:%02d:%02d",
  374. X                range(0, timeptr->tm_hour, 23),
  375. X                range(0, timeptr->tm_min, 59),
  376. X                range(0, timeptr->tm_sec, 61));
  377. X            break;
  378. X
  379. X        case 'y':    /* year without a century, 00 - 99 */
  380. X            i = timeptr->tm_year % 100;
  381. X            sprintf(tbuf, "%d", i);
  382. X            break;
  383. X
  384. X        case 'Y':    /* year with century */
  385. X            sprintf(tbuf, "%d", 1900 + timeptr->tm_year);
  386. X            break;
  387. X
  388. X        case 'Z':    /* time zone name or abbrevation */
  389. X            i = 0;
  390. X            if (
  391. X#ifndef TZNAME_MISSING
  392. X                daylight &&
  393. X#endif
  394. X                timeptr->tm_isdst)
  395. X                i = 1;
  396. X#ifdef TZNAME_MISSING
  397. X            strcpy(tbuf, timeptr->tm_zone);
  398. X#else
  399. X            strcpy(tbuf, tzname[i]);
  400. X#endif
  401. X            break;
  402. X
  403. X#ifdef SYSV_EXT
  404. X        case 'n':    /* same as \n */
  405. X            tbuf[0] = '\n';
  406. X            tbuf[1] = '\0';
  407. X            break;
  408. X
  409. X        case 't':    /* same as \t */
  410. X            tbuf[0] = '\t';
  411. X            tbuf[1] = '\0';
  412. X            break;
  413. X
  414. X        case 'D':    /* date as %m/%d/%y */
  415. X            strftime(tbuf, sizeof tbuf, "%m/%d/%y", timeptr);
  416. X            break;
  417. X
  418. X        case 'e':    /* day of month, blank padded */
  419. X            sprintf(tbuf, "%2d", range(1, timeptr->tm_mday, 31));
  420. X            break;
  421. X
  422. X        case 'r':    /* time as %I:%M:%S %p */
  423. X            strftime(tbuf, sizeof tbuf, "%I:%M:%S %p", timeptr);
  424. X            break;
  425. X
  426. X        case 'R':    /* time as %H:%M */
  427. X            strftime(tbuf, sizeof tbuf, "%H:%M", timeptr);
  428. X            break;
  429. X
  430. X        case 'T':    /* time as %H:%M:%S */
  431. X            strftime(tbuf, sizeof tbuf, "%H:%M:%S", timeptr);
  432. X            break;
  433. X#endif
  434. X
  435. X#ifdef SUNOS_EXT
  436. X        case 'k':    /* hour, 24-hour clock, blank pad */
  437. X            sprintf(tbuf, "%2d", range(0, timeptr->tm_hour, 23));
  438. X            break;
  439. X
  440. X        case 'l':    /* hour, 12-hour clock, 1 - 12, blank pad */
  441. X            i = range(0, timeptr->tm_hour, 23);
  442. X            if (i == 0)
  443. X                i = 12;
  444. X            else if (i > 12)
  445. X                i -= 12;
  446. X            sprintf(tbuf, "%2d", i);
  447. X            break;
  448. X#endif
  449. X
  450. X
  451. X#ifdef VMS_EXT
  452. X        case 'v':    /* date as dd-bbb-YYYY */
  453. X            sprintf(tbuf, "%2d-%3.3s-%4d",
  454. X                range(1, timeptr->tm_mday, 31),
  455. X                months_a[range(0, timeptr->tm_mon, 11)],
  456. X                timeptr->tm_year + 1900);
  457. X            for (i = 3; i < 6; i++)
  458. X                if (islower(tbuf[i]))
  459. X                    tbuf[i] = toupper(tbuf[i]);
  460. X            break;
  461. X#endif
  462. X
  463. X
  464. X#ifdef POSIX2_DATE
  465. X        case 'C':
  466. X            sprintf(tbuf, "%02d", (timeptr->tm_year + 1900) / 100);
  467. X            break;
  468. X
  469. X
  470. X        case 'E':
  471. X        case 'O':
  472. X            /* POSIX locale extensions, ignored for now */
  473. X            goto again;
  474. X
  475. X        case 'V':    /* week of year according ISO 8601 */
  476. X#if defined(GAWK) && defined(VMS_EXT)
  477. X        {
  478. X            extern int do_lint;
  479. X            extern void warning();
  480. X            static int warned = 0;
  481. X
  482. X            if (! warned && do_lint) {
  483. X                warned = 1;
  484. X                warning(
  485. X    "conversion %%V added in P1003.2/11.3; for VMS style date, use %%v");
  486. X            }
  487. X        }
  488. X#endif
  489. X            sprintf(tbuf, "%d", iso8601wknum(timeptr));
  490. X            break;
  491. X
  492. X        case 'u':
  493. X        /* ISO 8601: Weekday as a decimal number [1 (Monday) - 7] */
  494. X            sprintf(tbuf, "%d", timeptr->tm_wday == 0 ? 7 :
  495. X                    timeptr->tm_wday);
  496. X            break;
  497. X#endif    /* POSIX2_DATE */
  498. X        default:
  499. X            tbuf[0] = '%';
  500. X            tbuf[1] = *format;
  501. X            tbuf[2] = '\0';
  502. X            break;
  503. X        }
  504. X        i = strlen(tbuf);
  505. X        if (i)
  506. X            if (s + i < endp - 1) {
  507. X                strcpy(s, tbuf);
  508. X                s += i;
  509. X            } else
  510. X                return 0;
  511. X    }
  512. Xout:
  513. X    if (s < endp && *format == '\0') {
  514. X        *s = '\0';
  515. X        return (s - start);
  516. X    } else
  517. X        return 0;
  518. X}
  519. X
  520. X#ifdef POSIX2_DATE
  521. X/* iso8601wknum --- compute week number according to ISO 8601 */
  522. X
  523. X#ifndef __STDC__
  524. Xstatic int
  525. Xiso8601wknum(timeptr)
  526. Xconst struct tm *timeptr;
  527. X#else
  528. Xstatic int
  529. Xiso8601wknum(const struct tm *timeptr)
  530. X#endif
  531. X{
  532. X    /*
  533. X     * From 1003.2 D11.3:
  534. X     *    If the week (Monday to Sunday) containing January 1
  535. X     *    has four or more days in the new year, then it is week 1;
  536. X     *    otherwise it is week 53 of the previous year, and the
  537. X     *    next week is week 1.
  538. X     *
  539. X     * ADR: This means if Jan 1 was Monday through Thursday,
  540. X     *    it was week 1, otherwise week 53.
  541. X     */
  542. X
  543. X    int simple_wknum, jan1day, diff, ret;
  544. X
  545. X    /* get week number, Monday as first day of the week */
  546. X    simple_wknum = weeknumber(timeptr, 1) + 1;
  547. X
  548. X    /*
  549. X     * With thanks and tip of the hatlo to tml@tik.vtt.fi
  550. X     *
  551. X     * What day of the week does January 1 fall on?
  552. X     * We know that
  553. X     *    (timeptr->tm_yday - jan1.tm_yday) MOD 7 ==
  554. X     *        (timeptr->tm_wday - jan1.tm_wday) MOD 7
  555. X     * and that
  556. X     *     jan1.tm_yday == 0
  557. X     * and that
  558. X     *     timeptr->tm_wday MOD 7 == timeptr->tm_wday
  559. X     * from which it follows that. . .
  560. X      */
  561. X    jan1day = timeptr->tm_wday - (timeptr->tm_yday % 7);
  562. X    if (jan1day < 0)
  563. X        jan1day += 7;
  564. X
  565. X    /*
  566. X     * If Jan 1 was a Monday through Thursday, it was in
  567. X     * week 1.  Otherwise it was last year's week 53, which is
  568. X     * this year's week 0.
  569. X     */
  570. X    if (jan1day >= 1 && jan1day <= 4)
  571. X        diff = 0;
  572. X    else
  573. X        diff = 1;
  574. X    ret = simple_wknum - diff;
  575. X    if (ret == 0)    /* we're in the first week of the year */
  576. X        ret = 53;
  577. X    return ret;
  578. X}
  579. X#endif
  580. X
  581. X/* weeknumber --- figure how many weeks into the year */
  582. X
  583. X/* With thanks and tip of the hatlo to ado@elsie.nci.nih.gov */
  584. X
  585. X#ifndef __STDC__
  586. Xstatic int
  587. Xweeknumber(timeptr, firstweekday)
  588. Xconst struct tm *timeptr;
  589. Xint firstweekday;
  590. X#else
  591. Xstatic int
  592. Xweeknumber(const struct tm *timeptr, int firstweekday)
  593. X#endif
  594. X{
  595. X    if (firstweekday == 0)
  596. X        return (timeptr->tm_yday + 7 - timeptr->tm_wday) / 7;
  597. X    else
  598. X        return (timeptr->tm_yday + 7 -
  599. X            (timeptr->tm_wday ? (timeptr->tm_wday - 1) : 6)) / 7;
  600. X}
  601. X
  602. X#if 0
  603. X/* ADR --- I'm loathe to mess with ado's code ... */
  604. X
  605. XDate:         Wed, 24 Apr 91 20:54:08 MDT
  606. XFrom: Michal Jaegermann <audfax!emory!vm.ucs.UAlberta.CA!NTOMCZAK>
  607. XTo: arnold@audiofax.com
  608. X
  609. XHi Arnold,
  610. Xin a process of fixing of strftime() in libraries on Atari ST I grabbed
  611. Xsome pieces of code from your own strftime.  When doing that it came
  612. Xto mind that your weeknumber() function compiles a little bit nicer
  613. Xin the following form:
  614. X/*
  615. X * firstweekday is 0 if starting in Sunday, non-zero if in Monday
  616. X */
  617. X{
  618. X    return (timeptr->tm_yday - timeptr->tm_wday +
  619. X        (firstweekday ? (timeptr->tm_wday ? 8 : 1) : 7)) / 7;
  620. X}
  621. XHow nicer it depends on a compiler, of course, but always a tiny bit.
  622. X
  623. X   Cheers,
  624. X   Michal
  625. X   ntomczak@vm.ucs.ualberta.ca
  626. X#endif
  627. X
  628. X#ifdef    TEST_STRFTIME
  629. X
  630. X/*
  631. X * NAME:
  632. X *    tst
  633. X *
  634. X * SYNOPSIS:
  635. X *    tst
  636. X *
  637. X * DESCRIPTION:
  638. X *    "tst" is a test driver for the function "strftime".
  639. X *
  640. X * OPTIONS:
  641. X *    None.
  642. X *
  643. X * AUTHOR:
  644. X *    Karl Vogel
  645. X *    Control Data Systems, Inc.
  646. X *    vogelke@c-17igp.wpafb.af.mil
  647. X *
  648. X * BUGS:
  649. X *    None noticed yet.
  650. X *
  651. X * COMPILE:
  652. X *    cc -o tst -DTEST_STRFTIME strftime.c
  653. X */
  654. X
  655. X/* ADR: I reformatted this to my liking, and deleted some unneeded code. */
  656. X
  657. X#ifndef NULL
  658. X#include    <stdio.h>
  659. X#endif
  660. X#include    <sys/time.h>
  661. X#include    <string.h>
  662. X
  663. X#define        MAXTIME        132
  664. X
  665. X/*
  666. X * Array of time formats.
  667. X */
  668. X
  669. Xstatic char *array[] =
  670. X{
  671. X    "(%%A)      full weekday name, var length (Sunday..Saturday)  %A",
  672. X    "(%%B)       full month name, var length (January..December)  %B",
  673. X    "(%%C)                                               Century  %C",
  674. X    "(%%D)                                       date (%%m/%%d/%%y)  %D",
  675. X    "(%%E)                           Locale extensions (ignored)  %E",
  676. X    "(%%H)                          hour (24-hour clock, 00..23)  %H",
  677. X    "(%%I)                          hour (12-hour clock, 01..12)  %I",
  678. X    "(%%M)                                       minute (00..59)  %M",
  679. X    "(%%O)                           Locale extensions (ignored)  %O",
  680. X    "(%%R)                                 time, 24-hour (%%H:%%M)  %R",
  681. X    "(%%S)                                       second (00..61)  %S",
  682. X    "(%%T)                              time, 24-hour (%%H:%%M:%%S)  %T",
  683. X    "(%%U)    week of year, Sunday as first day of week (00..53)  %U",
  684. X    "(%%V)                    week of year according to ISO 8601  %V",
  685. X    "(%%W)    week of year, Monday as first day of week (00..53)  %W",
  686. X    "(%%X)     appropriate locale time representation (%H:%M:%S)  %X",
  687. X    "(%%Y)                           year with century (1970...)  %Y",
  688. X    "(%%Z) timezone (EDT), or blank if timezone not determinable  %Z",
  689. X    "(%%a)          locale's abbreviated weekday name (Sun..Sat)  %a",
  690. X    "(%%b)            locale's abbreviated month name (Jan..Dec)  %b",
  691. X    "(%%c)           full date (Sat Nov  4 12:02:33 1989)%n%t%t%t  %c",
  692. X    "(%%d)                             day of the month (01..31)  %d",
  693. X    "(%%e)               day of the month, blank-padded ( 1..31)  %e",
  694. X    "(%%h)                                should be same as (%%b)  %h",
  695. X    "(%%j)                            day of the year (001..366)  %j",
  696. X    "(%%k)               hour, 24-hour clock, blank pad ( 0..23)  %k",
  697. X    "(%%l)               hour, 12-hour clock, blank pad ( 0..12)  %l",
  698. X    "(%%m)                                        month (01..12)  %m",
  699. X    "(%%p)              locale's AM or PM based on 12-hour clock  %p",
  700. X    "(%%r)                   time, 12-hour (same as %%I:%%M:%%S %%p)  %r",
  701. X    "(%%u) ISO 8601: Weekday as decimal number [1 (Monday) - 7]   %u",
  702. X    "(%%v)                                VAX date (dd-bbb-YYYY)  %v",
  703. X    "(%%w)                       day of week (0..6, Sunday == 0)  %w",
  704. X    "(%%x)                appropriate locale date representation  %x",
  705. X    "(%%y)                      last two digits of year (00..99)  %y",
  706. X    (char *) NULL
  707. X};
  708. X
  709. X/* Main routine. */
  710. X
  711. Xint
  712. Xmain(argc, argv)
  713. Xint argc;
  714. Xchar **argv;
  715. X{
  716. X    long time();
  717. X
  718. X    char *next;
  719. X    char string[MAXTIME];
  720. X
  721. X    int k;
  722. X    int length;
  723. X
  724. X    struct tm *tm;
  725. X
  726. X    long clock;
  727. X
  728. X    /* Call the function. */
  729. X
  730. X    clock = time((long *) 0);
  731. X    tm = localtime(&clock);
  732. X
  733. X    for (k = 0; next = array[k]; k++) {
  734. X        length = strftime(string, MAXTIME, next, tm);
  735. X        printf("%s\n", string);
  736. X    }
  737. X
  738. X    exit(0);
  739. X}
  740. X#endif    /* TEST_STRFTIME */
  741. END_OF_FILE
  742. if test 17080 -ne `wc -c <'strftime.c'`; then
  743.     echo shar: \"'strftime.c'\" unpacked with wrong size!
  744. fi
  745. # end of 'strftime.c'
  746. fi
  747. echo shar: End of archive 3 \(of 3\).
  748. cp /dev/null ark3isdone
  749. MISSING=""
  750. for I in 1 2 3 ; do
  751.     if test ! -f ark${I}isdone ; then
  752.     MISSING="${MISSING} ${I}"
  753.     fi
  754. done
  755. if test "${MISSING}" = "" ; then
  756.     echo You have unpacked all 3 archives.
  757.     echo "Now do 'sh ./configure'"
  758.     rm -f ark[1-9]isdone
  759. else
  760.     echo You still need to unpack the following archives:
  761.     echo "        " ${MISSING}
  762. fi
  763. ##  End of shell archive.
  764. exit 0
  765.  
  766. exit 0 # Just in case...
  767.