home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume41 / rperf / part04 < prev    next >
Encoding:
Text File  |  1993-12-19  |  23.2 KB  |  883 lines

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