From decwrl!ucbvax!ucsd!swrinde!cs.utexas.edu!uunet!allbery Sun Oct 1 15:39:51 PDT 1989 Article 1126 of comp.sources.misc: Path: decwrl!ucbvax!ucsd!swrinde!cs.utexas.edu!uunet!allbery From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) Newsgroups: comp.sources.misc Subject: v08i082: libhoward portability library, part 4 of 9 Message-ID: <68940@uunet.UU.NET> Date: 1 Oct 89 14:43:27 GMT Sender: allbery@uunet.UU.NET Reply-To: howard@dahlbeck.ericsson.se (Howard Gayle) Lines: 1516 Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) Posting-number: Volume 8, Issue 82 Submitted-by: howard@dahlbeck.ericsson.se (Howard Gayle) Archive-name: libhoward/part04 #! /bin/sh # This is a shell archive. Remove anything before this line, then feed it # into a shell via "sh file" or similar. To overwrite existing files, # type "sh file -c". # The tool that generated this appeared in the comp.sources.unix newsgroup; # send mail to comp-sources-unix@uunet.uu.net if you want that tool. # If this archive is complete, you will see the following message at the end: # "End of archive 4 (of 9)." # Contents: a2i.c a2u.c a2ul.c freezePch.b getlin.c mopenp.c new.1 # port.h qrndu.c yrwk.c # Wrapped by howard@hasse on Mon Sep 25 07:08:08 1989 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'a2i.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'a2i.c'\" else echo shar: Extracting \"'a2i.c'\" \(4221 characters\) sed "s/^X//" >'a2i.c' <<'END_OF_FILE' X/* X * a2i - convert Ada-syntax integer literal to int X */ X X#ifndef lint Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle"; X#endif lint X X/* X * This program is free software; you can redistribute it and/or modify X * it under the terms of the GNU General Public License version 1, X * as published by the Free Software Foundation. X * X * This program is distributed in the hope that it will be useful, X * but WITHOUT ANY WARRANTY; without even the implied warranty of X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X * GNU General Public License for more details. X * X * You should have received a copy of the GNU General Public License X * along with this program; if not, write to the Free Software X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X */ X X#include X#include X#include X XMODVER ("@(#)$Header: a2i.c,v 1.7 89/08/10 13:02:15 howard Exp $"); X X#include X#include X#include X#include X#include X#include X XPUBLIC int a2i (str, lim, synok, res, end) XbStrT str; /* Input string.*/ XbStrT lim; /* Don't pass this.*/ XboolT synok; /* Accept non-fatal syntax errors.*/ Xint *res; /* Points to where to store result.*/ XbStrT *end; /* End pointer stored here.*/ X X/* Function: X * X * Algorithm: X * Call a2l(), then range check the result. X * Returns: X * X * Notes: X * X */ X{ XR1 int s; /* Return code.*/ X long l; /* a2l() stores its result here.*/ X Xs = a2l (str, lim, synok, &l, end); Xif (SUCCESS == s) X { X if ((l < ((long) INT_MIN)) || (l > ((long) INT_MAX))) X s = ERANGE; X else X *res = l; X } Xreturn (s); X} X X#ifdef TEST X#include X XMAINVER ("@(#)$Header: a2i.c,v 1.7 89/08/10 13:02:15 howard Exp $"); XUSAGE ("integer_numeric_literal"); X X#include X#include X XPRIVATE void t (num, str, limoff, synok, xrc, xres, xendoff) Xint num; /* Test number.*/ XbStrT str; /* str argument.*/ Xint limoff; /* Limit offset, -1 for none.*/ XboolT synok; /* synok argument.*/ Xint xrc; /* Expected return code.*/ Xint xres; /* Expected result.*/ Xint xendoff; /* Expected end offset.*/ X{ Xint rc; /* Return code.*/ Xint res; /* Result stored here.*/ XbStrT end; /* End string stored here.*/ X Xrc = a2i (str, (limoff < 0) ? NULBSTR : str + limoff, synok, &res, &end); Xif (rc != xrc) PRINTF ("%d: rc %d expected %d\n", num, rc, xrc); Xif ((0 == rc) && (0 == xrc) && (res != xres)) X PRINTF ("%d: res %d expected %d\n", num, res, xres); Xif (xendoff < 0) xendoff = strlen (str); Xif ((end - str) != xendoff) X PRINTF ("%d: end %s expected %s\n", num, end, str + xendoff); X} X XPUBLIC int main (argc, argv) Xint argc; /* Number of arguments.*/ XbStrT *argv; /* Points to array of argument strings.*/ X{ XbStrT end; /* End of string.*/ Xint res; /* a2i() stores its result here.*/ X X/*num str limoff syn rc res end */ Xt(__LINE__,"12", -1, 0, 0, 12, -1); Xt(__LINE__,"0", -1, 0, 0, 0, -1); Xt(__LINE__,"1E6", -1, 0, 0, 1000000, -1); Xt(__LINE__,"2#1111_1111#", -1, 0, 0, 255, -1); Xt(__LINE__,"16#FF#", -1, 0, 0, 255, -1); Xt(__LINE__,"016#0FF#", -1, 0, 0, 255, -1); Xt(__LINE__,"16#E#E1", -1, 0, 0, 224, -1); Xt(__LINE__,"2#1110_0000#", -1, 0, 0, 224, -1); Xt(__LINE__,"012", 1, 0, 0, 0, 1); Xt(__LINE__,"-2_147_483_648", -1, 0, 0, INT_MIN, -1); Xt(__LINE__," \t2_147_483_647",-1, 1, 0, INT_MAX, -1); Xt(__LINE__,"12B", -1, 1, 0, 12, 2); Xt(__LINE__,"16#abcdef#.", -1, 1, 0, 0xABCDEF, 10); X Xif (2 != argc) usage(); Xswitch (a2i (argv[1], NULBSTR, FALSE, &res, &end)) X { X case SUCCESS: X PRINTF ("8#%o#\t10#%d#\t16#%X#\n", res, res, res); X break; X case EINVAL: X PRINTF ("EINVAL %s\n", end); X break; X case EDOM: X PRINTF ("EDOM %s\n", end); X break; X case ERANGE: X PRINTF ("ERANGE %s\n", end); X break; X default: X PUTS ("Unexpected return"); X break; X } Xmfflush (stdout, "Standard Output"); Xexit (SUCCESS); X X#ifdef lint Xreturn (SUCCESS); X#endif X} X#endif END_OF_FILE if test 4221 -ne `wc -c <'a2i.c'`; then echo shar: \"'a2i.c'\" unpacked with wrong size! fi # end of 'a2i.c' fi if test -f 'a2u.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'a2u.c'\" else echo shar: Extracting \"'a2u.c'\" \(4270 characters\) sed "s/^X//" >'a2u.c' <<'END_OF_FILE' X/* X * a2u - convert Ada-syntax integer literal to unsigned X */ X X#ifndef lint Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle"; X#endif lint X X/* X * This program is free software; you can redistribute it and/or modify X * it under the terms of the GNU General Public License version 1, X * as published by the Free Software Foundation. X * X * This program is distributed in the hope that it will be useful, X * but WITHOUT ANY WARRANTY; without even the implied warranty of X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X * GNU General Public License for more details. X * X * You should have received a copy of the GNU General Public License X * along with this program; if not, write to the Free Software X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X */ X X#include X#include X#include X XMODVER ("@(#)$Header: a2u.c,v 1.6 89/08/11 14:08:33 howard Exp $"); X X#include X#include X#include X#include X#include X#include X XPUBLIC int a2u (str, lim, synok, res, end) XbStrT str; /* Input string.*/ XbStrT lim; /* Don't pass this.*/ XboolT synok; /* Accept non-fatal syntax errors.*/ Xunsigned *res; /* Points to where to store result.*/ XbStrT *end; /* End pointer stored here.*/ X X/* Function: X * X * Algorithm: X * Call a2smp() then smp2u(). X * Returns: X * X * Notes: X * X */ X{ XR1 int s; /* Return code.*/ X smpT smp; /* a2smp() stores its result here.*/ X Xs = a2smp (str, lim, synok, &smp, end); Xif (SUCCESS == s) s = smp2u (&smp, res); Xreturn (s); X} X X#ifdef TEST X#include X XMAINVER ("@(#)$Header: a2u.c,v 1.6 89/08/11 14:08:33 howard Exp $"); XUSAGE ("integer-numeric-literal"); X X#include X#include X XPRIVATE void t (num, str, limoff, synok, xrc, xres, xendoff) Xint num; /* Test number.*/ XbStrT str; /* str argument.*/ Xint limoff; /* Limit offset, -1 for none.*/ XboolT synok; /* synok argument.*/ Xint xrc; /* Expected return code.*/ Xunsigned xres; /* Expected result.*/ Xint xendoff; /* Expected end offset.*/ X{ Xint rc; /* Return code.*/ Xunsigned res; /* Result stored here.*/ XbStrT end; /* End string stored here.*/ X Xrc = a2u (str, (limoff < 0) ? NULBSTR : str + limoff, synok, &res, &end); Xif (rc != xrc) PRINTF ("%d: rc %d expected %d\n", num, rc, xrc); Xif ((0 == rc) && (0 == xrc) && (res != xres)) X PRINTF ("%d: res %u expected %u\n", num, res, xres); Xif (xendoff < 0) xendoff = strlen (str); Xif ((end - str) != xendoff) X PRINTF ("%d: end %s expected %s\n", num, end, str + xendoff); X} X XPUBLIC int main (argc, argv) Xint argc; /* Number of arguments.*/ XbStrT *argv; /* Points to array of argument strings.*/ X{ XbStrT end; /* End of string.*/ Xunsigned res; /* a2u() stores its result here.*/ X X/*num str limoff syn rc res end */ Xt(__LINE__,"12", -1, 0, 0, (unsigned) 12, -1); Xt(__LINE__,"0", -1, 0, 0, (unsigned) 0, -1); Xt(__LINE__,"1E6", -1, 0, 0, (unsigned) 1000000, -1); Xt(__LINE__,"2#1111_1111#", -1, 0, 0, (unsigned) 255, -1); Xt(__LINE__,"16#FF#", -1, 0, 0, (unsigned) 255, -1); Xt(__LINE__,"016#0FF#", -1, 0, 0, (unsigned) 255, -1); Xt(__LINE__,"16#E#E1", -1, 0, 0, (unsigned) 224, -1); Xt(__LINE__,"2#1110_0000#", -1, 0, 0, (unsigned) 224, -1); Xt(__LINE__,"012", 1, 0, 0, (unsigned) 0, 1); Xt(__LINE__," \t2_147_483_647",-1, 1, 0, (unsigned) INT_MAX, -1); Xt(__LINE__," \t4_294_967_295",-1, 1, 0, (unsigned) UINT_MAX, -1); Xt(__LINE__,"12B", -1, 1, 0, (unsigned) 12, 2); Xt(__LINE__,"16#abcdef#.", -1, 1, 0, (unsigned) 0xABCDEF, 10); X Xif (2 != argc) usage(); Xswitch (a2u (argv[1], NULBSTR, FALSE, &res, &end)) X { X case SUCCESS: X PRINTF ("8#%o#\t10#%u#\t16#%X#\n", res, res, res); X break; X case EINVAL: X PRINTF ("EINVAL %s\n", end); X break; X case EDOM: X PRINTF ("EDOM %s\n", end); X break; X case ERANGE: X PRINTF ("ERANGE %s\n", end); X break; X default: X PUTS ("Unexpected return"); X break; X } Xmfflush (stdout, "Standard Output"); Xexit (SUCCESS); X X#ifdef lint Xreturn (SUCCESS); X#endif X} X#endif END_OF_FILE if test 4270 -ne `wc -c <'a2u.c'`; then echo shar: \"'a2u.c'\" unpacked with wrong size! fi # end of 'a2u.c' fi if test -f 'a2ul.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'a2ul.c'\" else echo shar: Extracting \"'a2ul.c'\" \(4528 characters\) sed "s/^X//" >'a2ul.c' <<'END_OF_FILE' X/* X * a2ul - convert Ada-syntax integer literal to unsigned long X */ X X#ifndef lint Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle"; X#endif lint X X/* X * This program is free software; you can redistribute it and/or modify X * it under the terms of the GNU General Public License version 1, X * as published by the Free Software Foundation. X * X * This program is distributed in the hope that it will be useful, X * but WITHOUT ANY WARRANTY; without even the implied warranty of X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X * GNU General Public License for more details. X * X * You should have received a copy of the GNU General Public License X * along with this program; if not, write to the Free Software X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X */ X X#include X#include X#include X XMODVER ("@(#)$Header: a2ul.c,v 1.7 89/08/11 14:17:25 howard Exp $"); X X#include X#include X#include X XPUBLIC int a2ul (str, lim, synok, res, end) XbStrT str; /* Input string.*/ XbStrT lim; /* Don't pass this.*/ XboolT synok; /* Accept non-fatal syntax errors.*/ XulongT *res; /* Points to where to store result.*/ XbStrT *end; /* End pointer stored here.*/ X X/* Function: X * X * Algorithm: X * Call a2smp() and then smp2ul(). X * Returns: X * X * Notes: X * X */ X{ XR1 int s; /* Return code.*/ X smpT smp; /* a2smp() stores its result here.*/ X Xs = a2smp (str, lim, synok, &smp, end); Xif (SUCCESS == s) s = smp2ul (&smp, res); Xreturn (s); X} X X#ifdef TEST X#include X XMAINVER ("@(#)$Header: a2ul.c,v 1.7 89/08/11 14:17:25 howard Exp $"); XUSAGE ("integer-numeric-literal"); X X#include X#include X#include X#include X XPRIVATE void t (num, str, limoff, synok, xrc, xres, xendoff) Xint num; /* Test number.*/ XbStrT str; /* str argument.*/ Xint limoff; /* Limit offset, -1 for none.*/ XboolT synok; /* synok argument.*/ Xint xrc; /* Expected return code.*/ XulongT xres; /* Expected result.*/ Xint xendoff; /* Expected end offset.*/ X{ Xint rc; /* Return code.*/ XulongT res; /* Result stored here.*/ XbStrT end; /* End string stored here.*/ X Xrc = a2ul (str, (limoff < 0) ? NULBSTR : str + limoff, synok, &res, &end); Xif (rc != xrc) PRINTF ("%d: rc %d expected %d\n", num, rc, xrc); Xif ((0 == rc) && (0 == xrc) && (res != xres)) X PRINTF ("%d: res %lu expected %lu\n", num, res, xres); Xif (xendoff < 0) xendoff = strlen (str); Xif ((end - str) != xendoff) X PRINTF ("%d: end %s expected %s\n", num, end, str + xendoff); X} X XPUBLIC int main (argc, argv) Xint argc; /* Number of arguments.*/ XbStrT *argv; /* Points to array of argument strings.*/ X{ XbStrT end; /* End of string.*/ XulongT res; /* a2ul() stores its result here.*/ X X/* num str limoff syn rc res end */ Xt(__LINE__,"12", -1, 0, 0, (ulongT) 12, -1); Xt(__LINE__,"0", -1, 0, 0, (ulongT) 0, -1); Xt(__LINE__,"1E6", -1, 0, 0, (ulongT) 1000000, -1); Xt(__LINE__,"2#1111_1111#", -1, 0, 0, (ulongT) 255, -1); Xt(__LINE__,"16#FF#", -1, 0, 0, (ulongT) 255, -1); Xt(__LINE__,"016#0FF#", -1, 0, 0, (ulongT) 255, -1); Xt(__LINE__,"16#E#E1", -1, 0, 0, (ulongT) 224, -1); Xt(__LINE__,"2#1110_0000#", -1, 0, 0, (ulongT) 224, -1); Xt(__LINE__,"012", 1, 0, 0, (ulongT) 0, 1); Xt(__LINE__,"-2_147_483_648", -1, 0, ERANGE, (ulongT) 0, -1); Xt(__LINE__," \t2_147_483_647",-1, 1, 0, (ulongT) LONG_MAX, -1); Xt(__LINE__," \t4_294_967_295",-1, 1, 0, (ulongT) ULONG_MAX, -1); Xt(__LINE__,"4_294_967_296", -1, 0, ERANGE, (ulongT) 0, 12); Xt(__LINE__,"12B", -1, 1, 0, (ulongT) 12, 2); Xt(__LINE__,"16#abcdef#.", -1, 1, 0, (ulongT) 0xABCDEF, 10); Xt(__LINE__,"-2_147_483_649", -1, 0, ERANGE, (ulongT) 0, -1); X Xif (2 != argc) usage(); Xswitch (a2ul (argv[1], NULBSTR, FALSE, &res, &end)) X { X case SUCCESS: X PRINTF ("8#%lo#\t10#%lu#\t16#%lX#\n", res, res, res); X break; X case EINVAL: X PRINTF ("EINVAL %s\n", end); X break; X case EDOM: X PRINTF ("EDOM %s\n", end); X break; X case ERANGE: X PRINTF ("ERANGE %s\n", end); X break; X default: X PUTS ("Unexpected return"); X break; X } Xmfflush (stdout, "Standard Output"); Xexit (SUCCESS); X X#ifdef lint Xreturn (SUCCESS); X#endif X} X#endif END_OF_FILE if test 4528 -ne `wc -c <'a2ul.c'`; then echo shar: \"'a2ul.c'\" unpacked with wrong size! fi # end of 'a2ul.c' fi if test -f 'freezePch.b' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'freezePch.b'\" else echo shar: Extracting \"'freezePch.b'\" \(2604 characters\) sed "s/^X//" >'freezePch.b' <<'END_OF_FILE' X X# freezePch.b - make a patch file from one revision to another X# X# $Header: freezePch.b,v 1.2 89/09/25 07:01:13 howard Exp $ X# X# Copyright 1989 Howard Lee Gayle X# This file is written in the ISO 8859/1 character set. X# X# This program is free software; you can redistribute it and/or modify X# it under the terms of the GNU General Public License version 1, X# as published by the Free Software Foundation. X# X# This program is distributed in the hope that it will be useful, X# but WITHOUT ANY WARRANTY; without even the implied warranty of X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X# GNU General Public License for more details. X# X# You should have received a copy of the GNU General Public License X# along with this program; if not, write to the Free Software X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X# X# Shell variables: X# a - files in old FREEZE file X# b - files in new FREEZE file X# n - new FREEZE file, without header X# o - old FREEZE file, without header X# r - files to remove X# s - all new files X# u - usage string X XCMDNAME=freezePch Xexport CMDNAME Xu="Usage: $CMDNAME old-revision new-revision" Xif [ $# -ne 2 ] Xthen X echo "$u" 1>&2 X exit 1 Xfi Xa=/tmp/frzpch$$a Xb=/tmp/frzpch$$b Xn=/tmp/frzpch$$n Xo=/tmp/frzpch$$o Xr=/tmp/frzpch$$r Xs=/tmp/frzpch$$s Xco -p -r"$1" FREEZE | \ X sed -e '1,/^========================================$/d' > $o Xco -r"$2" FREEZE Xsed -e '1,/^========================================$/d' FREEZE > $n Xawk '{print $1}' $o > $a Xawk '{print $1}' $n > $b X Xecho FREEZE > $r Xcomm -23 $a $b >> $r Xcat << EOF X#! /bin/sh X# This is a shell patch script from revision $1 to revision $2. XEOF Xcat << 'EOF' X# Remove anything before this line, then feed it into a shell. for X# example by typing "sh file". This script was created by: X# $Header: freezePch.b,v 1.2 89/09/25 07:01:13 howard Exp $ X# X# The following files are to be removed. If you have a command X# available to delete files so that they may later be undeleted, X# you may wish to substitute that command for rm below. An X# example of such a command is Jonathan I. Kamens's delete X# command, posted to comp.sources.unix on 29 March 1989 as volume X# 18, issues 73-78, archive name undel. XEOF Xsed -e 's;^;rm -f ;' $r X Xcat << 'EOF' X# X# Here is the updated FREEZE file: XEOF Xshar FREEZE | grep -v '^exit 0$' X Xcomm -13 $a $b > $s Xif [ -s $s ] Xthen X cat << 'EOF' X# X# The following files are all new: XEOF X xargs shar < $s | grep -v '^exit 0$' Xfi X Xjoin -o 1.1 1.2 2.2 $o $n | awk '$2 != $3{print "freezePch0", $0}' | sh Xecho "echo 'End of shell patch script.'" Xrm -f $a $b $n $o $r $s END_OF_FILE if test 2604 -ne `wc -c <'freezePch.b'`; then echo shar: \"'freezePch.b'\" unpacked with wrong size! fi # end of 'freezePch.b' fi if test -f 'getlin.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'getlin.c'\" else echo shar: Extracting \"'getlin.c'\" \(3962 characters\) sed "s/^X//" >'getlin.c' <<'END_OF_FILE' X/* X * getlin - read next line from a file X */ X X#ifndef lint Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle"; X#endif lint X X/* X * This program is free software; you can redistribute it and/or modify X * it under the terms of the GNU General Public License version 1, X * as published by the Free Software Foundation. X * X * This program is distributed in the hope that it will be useful, X * but WITHOUT ANY WARRANTY; without even the implied warranty of X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X * GNU General Public License for more details. X * X * You should have received a copy of the GNU General Public License X * along with this program; if not, write to the Free Software X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X */ X X#include X#include X#include X XMODVER ("@(#)$Header: getlin.c,v 1.7 89/08/09 09:46:03 howard Exp $"); X X#include X#include X XPUBLIC bStrT getlin (l, ls, f, fn, ln, tw) XbStrT l; /* Points to buffer provided by caller where line X * will be stored.*/ Xunsigned ls; /* Number of bytes in buffer, including terminal X * NUL. (No space needs to be provided for the X * newline since getlin removes it.)*/ XstreamT f; /* Input stream.*/ XbStrT fn; /* Input file name, for possible error messages.*/ Xunsigned *ln; /* Points to where current line number is stored. X * getlin increments it after a successful read, and X * uses it for error messages.*/ XR3 unsigned tw; /* Expand tabs into this many spaces. 0 = no expand.*/ X X/* Function: X * Read one line. Handle errors. X * Algorithm: X * Read one character at a time until X * 1) a newline is received, X * 2) an EOF is received, or X * 3) the buffer becomes full. X * Returns: X * On success, a pointer to the NUL terminator in l[]. X * On normal EOF, NULBSTR. X * No return on error. X */ X X{ XR1 rcharT c; /* Current input character.*/ XbStrT bp = l; /* Current position in line buffer.*/ Xunsigned col = 0; /* Current column number (leftmost 0).*/ XR2 boolT more = TRUE; /* Set when more to do.*/ X Xif ((NULBSTR == fn) || (EOS == B(*fn))) malf1 ("getlin: No file name"); Xif (NULBSTR == l) malf1 ("getlin %s: No line buffer", fn); Xif (ls < 2) malf1 ("getlin %s: Line buffer too small", fn); Xif (NULSTRM == f) malf1 ("getlin %s: No FILE", fn); Xif (((unsigned *) NULL) == ln) malf1 ("getlin %s: No line number pointer", fn); Xdo X { X c = getc (f); X switch (c) X { X case '\t': X if (0 == tw) X { X *bp++ = c; X ++col; X } X else X { X c = tw - (col % tw); X col += c; X if (col < ls) X while (c--) X *bp++ = ' '; X } X break; X case '\n': X *bp = EOS; X more = FALSE; X ++(*ln); X break; X case EOF: X if (ferror (f)) malf1 ("%s: %u: Read error", fn, 1 + *ln); X if (bp != l) X malf1 ("%s: %u: End of file in middle of line", fn, 1 + *ln); X *bp = EOS; X bp = NULBSTR; X more = FALSE; X break; X case EOS: /* NUL.*/ X malf1 ("%s: %u: NUL in line", fn, 1 + *ln); X break; X default: X *bp++ = c; X ++col; X break; X } X if (col == ls) malf1 ("%s: %u: Line too long, %u max", fn, 1 + *ln, ls - 1); X } Xwhile (more); Xreturn (bp); X} X X X#ifdef TEST X#include X XMAINVER ("@(#)$Header: getlin.c,v 1.7 89/08/09 09:46:03 howard Exp $"); X X/* This test driver copies stdin to stdout, converting tabs to X * spaces like expand(1).*/ X XUSAGE (""); X X#include X Xmain() X{ Xunsigned ln = 0; Xstatic byteT l[1024]; X Xwhile (NULBSTR != getlin (l, 1024, stdin, "Standard Input", &ln, 8)) X (void) puts (l); X Xmfflush (stdout, "Standard Output"); Xexit (SUCCESS); X X#ifdef lint Xreturn (SUCCESS); X#endif X} X#endif END_OF_FILE if test 3962 -ne `wc -c <'getlin.c'`; then echo shar: \"'getlin.c'\" unpacked with wrong size! fi # end of 'getlin.c' fi if test -f 'mopenp.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'mopenp.c'\" else echo shar: Extracting \"'mopenp.c'\" \(3589 characters\) sed "s/^X//" >'mopenp.c' <<'END_OF_FILE' X/* X * mopenp - try to open a file by searching a path X */ X X#ifndef lint Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle"; X#endif lint X X/* X * This program is free software; you can redistribute it and/or modify X * it under the terms of the GNU General Public License version 1, X * as published by the Free Software Foundation. X * X * This program is distributed in the hope that it will be useful, X * but WITHOUT ANY WARRANTY; without even the implied warranty of X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X * GNU General Public License for more details. X * X * You should have received a copy of the GNU General Public License X * along with this program; if not, write to the Free Software X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X */ X X#include X#include X#include X XMODVER ("@(#)$Header: mopenp.c,v 1.6 89/09/21 07:43:04 howard Exp $"); X X#include X#include X#include X XPUBLIC streamT mopenp (pth, sep, sim, suf, mod, fnb, len) X bStrT pth; /* Path to search.*/ XR10 rcharT sep; /* Path separator.*/ XR7 bStrT sim; /* Simple part of file name.*/ XR8 bStrT suf; /* Suffix.*/ XR9 bStrT mod; /* Mode string.*/ XR6 bStrT fnb; /* Store full file name here.*/ X unsigned len; /* Length of fnb[].*/ X X/* Function: X * Search pth for a file named sim+suf. Open it. Handle errors. X * Algorithm: X * Step through each element of pth. Assemble the full file name X * in fnb[]. Try to open it. Return on success. X * Returns: X * X * Notes: X * X */ X{ XR1 bStrT p1; /* Points to beginning of current path.*/ XR2 bStrT p2; /* Points to separator at end of current path.*/ XR3 int i; /* Path length.*/ XR4 int m; /* Max path length.*/ XR5 streamT s; /* Returned by fopen(3).*/ X Xif (NULBSTR == pth) malf1 ("mopenp: NULL path"); Xif (EOS == sep) malf1 ("mopenp: NULL separator character"); Xif (NULBSTR == sim) malf1 ("mopenp: NULL file name"); Xif (NULBSTR == suf) malf1 ("mopenp: NULL suffix"); Xif (NULBSTR == mod) malf1 ("mopenp: NULL mode"); Xif (NULBSTR == fnb) malf1 ("mopenp: NULL file name buffer"); Xm = ((int) len) - 2 - strlen ((cStrT) sim) - strlen ((cStrT) suf); Xp1 = pth; Xdo X { X p2 = (bStrT) strchr ((cStrT) p1, sep); X i = ((NULBSTR == p2) ? strlen ((cStrT) p1) : p2 - p1); X if ((0 == i) || (i > m)) X malf1 ("mopenp: path length out of range [1, %d]: %s", m, p1); X STRNCPY ((cStrT) fnb, (cStrT) p1, i); X p1 = &fnb[i]; X if ('/' != B(p1[-1])) *p1++ = '/'; X SPRINTF (p1, "%s%s", sim, suf); X s = fopen ((cStrT) fnb, (cStrT) mod); X if (NULSTRM != s) return (s); X if (NULBSTR != p2) p1 = p2 + 1; X } Xwhile (NULBSTR != p2); Xmalf1 ("mopenp: no %s%s in %s", sim, suf, pth); X/*NOTREACHED*/ X} X X#ifdef TEST X#include X XMAINVER ("@(#)$Header: mopenp.c,v 1.6 89/09/21 07:43:04 howard Exp $"); XUSAGE ("filename"); X X#define MLINE 1024 /* Max line length.*/ X XPUBLIC int main (argc, argv) Xint argc; /* Number of arguments.*/ XbStrT *argv; /* Points to array of argument strings.*/ X{ XstreamT is; /* Input stream.*/ Xunsigned ln = 0; /* Line number.*/ XbyteT fnb[MFILE]; /* Store full paths here.*/ XbyteT lb[MLINE]; /* Line buffer.*/ Xextern cStrT getenv(); /* (3).*/ X Xif (2 != argc) usage(); Xis = mopenp ((bStrT) getenv ("EMACSLOADPATH"), ':', argv[1], S(".el"), S("r"), X fnb, MFILE); Xwhile ((NULBSTR != getlin (lb, MLINE, is, fnb, &ln, 0)) && (5 != ln)) X PUTS (lb); Xmfflush (stdout, S("Standard Output")); Xexit (SUCCESS); X X#ifdef lint Xreturn (SUCCESS); X#endif X} X#endif END_OF_FILE if test 3589 -ne `wc -c <'mopenp.c'`; then echo shar: \"'mopenp.c'\" unpacked with wrong size! fi # end of 'mopenp.c' fi if test -f 'new.1' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'new.1'\" else echo shar: Extracting \"'new.1'\" \(4757 characters\) sed "s/^X//" >'new.1' <<'END_OF_FILE' X.\" $Header: new.1,v 1.2 89/09/22 07:24:33 howard Exp $ X.TH NEW 1 "$Revision: 1.2 $" X.SH NAME Xnew, new-Make, new-MakeC, new-1, new-3, new-b, new-bib, new-c, new-el, new-h, new-uMake \- create source files from prototypes X.SH SYNOPSIS X.B new X.I filename \&.\|.\|. X.LP X.B new-* X.I filename \&.\|.\|. X.SH COPYRIGHT XCopyright \(co 1989 Howard Lee Gayle X.SH DESCRIPTION X.I new Xcreates each of its arguments, and initializes it with a Xskeleton for the given type of source file. XIt determines the file type from the suffix, and executes the Xcorresponding new-* command. XThis makes it easy to write private versions of new-* commands. X.SH EXAMPLE XCreate a C program, a C include file, and the makefiles: X.nf X % new foo.c foo.h MakeCommon uMakefile Makefile X.fi X.SH ENVIRONMENT XIf the environment variable NEWTEXTPATH is set, it is searched Xfor various files to be included in the prototype. XThe default is new.txt, which would typically contain a Xcopyright notice and license information. XAppropriate comment characters are prepended to each line. X.PP XFor manual entries, the files are X.RI new- section .cprt Xfor the copyright notice, and X.RI new- section .txt Xfor additional text to be included at the end, X.I e.g. Xlicense and author sections. XHere, X.I section Xis the manual section number. X.PP XFor C programs, the file is new-c.txt. X.SH FILES XHere is my new.txt file: X.nf X Copyright 1989 Howard Lee Gayle X This file is written in the ISO 8859/1 character set. X X This program is free software; you can redistribute it and/or modify X it under the terms of the GNU General Public License version 1, X as published by the Free Software Foundation. X X This program is distributed in the hope that it will be useful, X but WITHOUT ANY WARRANTY; without even the implied warranty of X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X GNU General Public License for more details. X X You should have received a copy of the GNU General Public License X along with this program; if not, write to the Free Software X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X X.fi X.PP XHere is my new-[1-8].cprt file: X.nf X .SH COPYRIGHT X Copyright \e(co 1989 Howard Lee Gayle X.fi X.PP XHere is my new-[1-8].txt file: X.nf X .SH LICENSE X This program is free software; you can redistribute it and/or modify X it under the terms of the GNU General Public License version 1, X as published by the Free Software Foundation. X .PP X This program is distributed in the hope that it will be useful, X but WITHOUT ANY WARRANTY; without even the implied warranty of X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X GNU General Public License for more details. X .PP X You should have received a copy of the GNU General Public License X along with this program; if not, write to the Free Software X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X .SH AUTHOR X Howard Gayle, X TN/ETX/T/BG, X Ericsson Telecom AB, X S-126 25 Stockholm, X Sweden, X howard@ericsson.se, X uunet!ericsson.se!howard, X Phone: +46 8 719 5565, X FAX: +46 8 719 9598, X Telex: 14910 ERIC S X.fi X.PP XHere is my new-c.txt file: X.nf X #ifndef lint X static char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle"; X #endif lint X X /* X * This program is free software; you can redistribute it and/or modify X * it under the terms of the GNU General Public License version 1, X * as published by the Free Software Foundation. X * X * This program is distributed in the hope that it will be useful, X * but WITHOUT ANY WARRANTY; without even the implied warranty of X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X * GNU General Public License for more details. X * X * You should have received a copy of the GNU General Public License X * along with this program; if not, write to the Free Software X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X */ X X.fi X.SH LICENSE XThis program is free software; you can redistribute it and/or modify Xit under the terms of the GNU General Public License version 1, Xas published by the Free Software Foundation. X.PP XThis program is distributed in the hope that it will be useful, Xbut WITHOUT ANY WARRANTY; without even the implied warranty of XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the XGNU General Public License for more details. X.PP XYou should have received a copy of the GNU General Public License Xalong with this program; if not, write to the Free Software XFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X.SH AUTHOR XHoward Gayle, XTN/ETX/T/BG, XEricsson Telecom AB, XS-126 25 Stockholm, XSweden, Xhoward@ericsson.se, Xuunet!ericsson.se!howard, XPhone: +46 8 719 5565, XFAX: +46 8 719 9598, XTelex: 14910 ERIC S END_OF_FILE if test 4757 -ne `wc -c <'new.1'`; then echo shar: \"'new.1'\" unpacked with wrong size! fi # end of 'new.1' fi if test -f 'port.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'port.h'\" else echo shar: Extracting \"'port.h'\" \(4389 characters\) sed "s/^X//" >'port.h' <<'END_OF_FILE' X/* port.h - Common definitions for portability. X * X * Copyright 1989 Howard Lee Gayle X * X * $Header: port.h,v 1.30 89/08/29 08:52:40 howard Exp $ X * X * This program is free software; you can redistribute it and/or modify X * it under the terms of the GNU General Public License version 1, X * as published by the Free Software Foundation. X * X * This program is distributed in the hope that it will be useful, X * but WITHOUT ANY WARRANTY; without even the implied warranty of X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X * GNU General Public License for more details. X * X * You should have received a copy of the GNU General Public License X * along with this program; if not, write to the Free Software X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X * X * Prerequisites: stdio.h. X * X * Some of the ideas in this file come from the following book, X * which I highly recommend: X * Title Portable C and UNIX system programming X * FullAuthor J. E. Lapin X * Publisher Prentice-Hall X * Address Englewood Cliffs, New Jersey X * Year 1987 X * ISBN 0-13-686494-5 X * Pages 249 X * However, all code is original. X */ X X#include X#include X X#ifdef NOUCHAR Xtypedef char byteT; X#define B(x) ((x) & 0377) /* Access byteT.*/ X#else /* NOUCHAR*/ X/* This kludge is to keep lint from generating spurious X * messages for every string literal cast to bStrT, e.g. by the X * S() macro defined below.*/ X#ifdef lint Xtypedef char byteT; X#else /* lint*/ Xtypedef unsigned char byteT; X#endif /* lint*/ X#define B(x) (x) /* Access byteT.*/ X#endif /* NOUCHAR*/ X X#ifdef NOULONG Xtypedef long ulongT; X#else Xtypedef unsigned long ulongT; X#endif X X#ifdef NOUSHRT Xtypedef unsigned ushrtT; X#else Xtypedef unsigned short ushrtT; X#endif X X#ifdef NOVOID Xtypedef int void; X#endif X X#ifdef NOVOIDP Xtypedef char *voidPT; X#else Xtypedef void *voidPT; X#endif X Xtypedef int boolT; /* Boolean type.*/ Xtypedef byteT *bStrT; /* Byte string type.*/ Xtypedef char *cStrT; /* Character string type.*/ Xtypedef char flagT; /* Compact Boolean.*/ Xtypedef int rcharT; /* Character from e.g. getc().*/ Xtypedef FILE *streamT; /* Stdio stream.*/ X X#define EOS '\0' /* End of string.*/ X#define FALSE 0 /* Boolean.*/ X#define MFILE 1024 /* Maximum file name length.*/ X#define PRIVATE static /* Scope one file.*/ X#define PUBLIC /* Exported from this file.*/ X#define SUCCESS 0 /* Returned by a function on success.*/ X#define TRUE 1 /* Boolean.*/ X X/* Equality comparison for byte and character strings. X * Checking the first byte is before calling strcmp() is for extra X * speed. */ X#define bStrEQ(x,y) ((*(x) == *(y)) && (0 == strcmp ((cStrT)(x),(cStrT)(y)))) X#define cStrEQ(x,y) ((*(x) == *(y)) && (0 == strcmp ((x),(y)))) X X#define DIG2INT(d) ((int) ((d) - '0')) /* Character of digit to int.*/ X X/* Macros to make lint quieter:*/ X#define FFLUSH(s) (void) fflush (s) X#define FPRINTF (void) fprintf X#define FPUTS(s,f) (void) fputs(s,f) X#define PRINTF (void) printf X#define PUTC(x,p) if(--(p)->_cnt>=0)*(p)->_ptr++=(unsigned char)(x);else(void)_flsbuf((unsigned char)(x),p) X#define PUTCHAR(c) (void) putchar(c) X#define PUTS(s) (void) puts(s) X#define SPRINTF (void) sprintf X#define STRCPY(t,f) (void) strcpy (t, f) X#define STRCAT(t,f) (void) strcat (t, f) X#define STRNCAT(t,f,n) (void) strncat (t, f, n) X#define STRNCPY(t,f,n) (void) strncpy (t, f, n) X X/* Macros for absolute value, minimum, and maximum:*/ X#define ABS(a) (((a) < 0) ? (-(a)) : (a)) X#define DABS(a) (((a) < 0.0) ? (-(a)) : (a)) X#define MIN(a,b) (((a) < (b)) ? (a) : (b)) X#define MAX(a,b) (((a) > (b)) ? (a) : (b)) X X/* NULLs of various types:*/ X#define NULBSTR ((bStrT) NULL) /* NULL byte string.*/ X#define NULCSTR ((cStrT) NULL) /* NULL character string.*/ X#define NULSTRM ((streamT)NULL) /* NULL stdio stream.*/ X X/* Cast a "" string literal to a byte string:*/ X#define S(x) ((bStrT)(x)) X X/* Number of elements in an array:*/ X#define ELEMNTS(a) (sizeof(a)/sizeof(*(a))) X X/* Substitute for missing functions.*/ X#ifdef NOSTRCHR X#define strchr(s,c) index (s, c) X#define strrchr(s,c) rindex (s, c) X#endif X X/* bStrT version of strchr and strrchr: */ X#define bStrChr(s,c) ((bStrT) strchr ((cStrT) (s), (c))) X#define bStrRChr(s,c) ((bStrT) strrchr ((cStrT) (s), (c))) X X#define SPCTAB(c) ((' ' == (c)) || ('\t' == (c))) /* Space or tab.*/ END_OF_FILE if test 4389 -ne `wc -c <'port.h'`; then echo shar: \"'port.h'\" unpacked with wrong size! fi # end of 'port.h' fi if test -f 'qrndu.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'qrndu.c'\" else echo shar: Extracting \"'qrndu.c'\" \(4277 characters\) sed "s/^X//" >'qrndu.c' <<'END_OF_FILE' X/* X * qrndu - uniformly distributed quasi-random long in given range X */ X X#ifndef lint Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle"; X#endif lint X X/* X * This program is free software; you can redistribute it and/or modify X * it under the terms of the GNU General Public License version 1, X * as published by the Free Software Foundation. X * X * This program is distributed in the hope that it will be useful, X * but WITHOUT ANY WARRANTY; without even the implied warranty of X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X * GNU General Public License for more details. X * X * You should have received a copy of the GNU General Public License X * along with this program; if not, write to the Free Software X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X */ X X#include X#include X#include X XMODVER ("@(#)$Header: qrndu.c,v 1.7 89/08/14 10:41:31 howard Exp $"); X X#include X#include X#include X X#ifdef NORANDOM X#ifdef NODRAND48 X/* Desperation time: neither random(3) nor drand48(3).*/ X#define MDIFF 32767L /* Max value of h - l.*/ X#define RAND rand /* Function to call for next number.*/ Xextern int rand(); /* (3).*/ Xextern int srand(); /* rand(3).*/ X X#else NODRAND48 X/* No random(3), but there is drand48(3).*/ X#define MDIFF LONG_MAX /* Max value of h - l.*/ X#define RAND lrand48 /* Function to call for next number.*/ Xextern long lrand48(); /* drand48(3).*/ Xextern void srand48(); /* drand48(3).*/ X#endif NODRAND48 X X#else NORANDOM X/* random(3) is available.*/ X#define MDIFF LONG_MAX /* Max value of h - l.*/ X#define RAND random /* Function to call for next number.*/ XPRIVATE char qrndSt[256]; /* For random()'s state information. */ Xextern cStrT initstate(); /* random(3).*/ Xextern long random(); /* (3).*/ X#endif NORANDOM X X/* qrnds - initialize quasi-random number generator with given seed */ X XPUBLIC void qrnds (s) Xunsigned s; /* Seed.*/ X X/* Function: X * X * Algorithm: X * Call the right function. X * Returns: X * X * Notes: X * X */ X{ X#ifdef NORANDOM X#ifdef NODRAND48 X(void) srand ((int) s); X#else NODRAND48 Xsrand48 ((long) s); X#endif NODRAND48 X#else NORANDOM X(void) initstate (s, qrndSt, sizeof (qrndSt)); X#endif NORANDOM X} X X/* qrndr - initialize quasi-random number generator with random seed */ X XPUBLIC void qrndr () X X/* Function: X * X * Algorithm: X * Call qrnds() with the process ID number as seed. X * Returns: X * X * Notes: X * X */ X{ Xextern int getpid(); /* (2).*/ X Xqrnds ((unsigned) getpid()); X} X XPUBLIC long qrndu (l, h) XR4 long l; /* Lower bound.*/ XR5 long h; /* Upper bound.*/ X X/* Function: X * X * Algorithm: X * Check args. Compute d = h - l. Compute m = (2 ^ n) - 1, X * where n is ceiling (log2 (d)), where log2 is log to base 2. X * In other words, m is a mask of the form 00000111111... with just X * enough one bits to make m >= d. Then get a quasi-random number, X * and mask it with m. If it's too big, loop. Otherwise scale it X * with l and return it. X * Returns: X * X * Notes: X * X */ X{ XR3 ulongT d; /* h - l.*/ XR1 ulongT m; /* Mask.*/ XR2 ulongT r; /* Random number.*/ X Xif (l > h) malf1 ("qrndu: empty range [%ld, %ld]", l, h); Xif (l == h) return (l); Xd = h - l; Xif (d > MDIFF) malf1 ("qrndu: range > %ld", MDIFF); Xfor (m = 1; m < d; m = (m << 1) | 1) X ; Xfor (;;) X { X r = m & RAND(); X if (r <= d) return (r + l); X } X} X X#ifdef TEST X#include X XMAINVER ("@(#)$Header: qrndu.c,v 1.7 89/08/14 10:41:31 howard Exp $"); XUSAGE ("low high [count]"); X X#include X XPUBLIC int main (argc, argv) Xint argc; /* Number of arguments.*/ XbStrT *argv; /* Points to array of argument strings.*/ X{ Xlong l; /* Lower bound.*/ Xlong h; /* Upper bound.*/ XulongT n = 1; /* Number of numbers to generate.*/ X Xif ((3 != argc) && (4 != argc)) usage(); Xl = ma2l (argv[1], NULBSTR, FALSE, S("Lower bound"), (bStrT *) NULL); Xh = ma2l (argv[2], NULBSTR, FALSE, S("Upper bound"), (bStrT *) NULL); Xif (4 == argc) X n = ma2ul (argv[3], NULBSTR, FALSE, S("Count"), (bStrT *) NULL); Xqrndr(); Xfor (; 0 != n; --n) X PRINTF ("%ld\n", qrndu (l, h)); Xmfflush (stdout, "Standard Output"); Xexit (SUCCESS); X X#ifdef lint Xreturn (SUCCESS); X#endif X} X#endif END_OF_FILE if test 4277 -ne `wc -c <'qrndu.c'`; then echo shar: \"'qrndu.c'\" unpacked with wrong size! fi # end of 'qrndu.c' fi if test -f 'yrwk.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'yrwk.c'\" else echo shar: Extracting \"'yrwk.c'\" \(4174 characters\) sed "s/^X//" >'yrwk.c' <<'END_OF_FILE' X/* X * yrwk - compute year and ISO week from struct tm X */ X X#ifndef lint Xstatic char _cpyrgt[] = "Copyright 1989 Howard Lee Gayle"; X#endif lint X X/* X * This program is free software; you can redistribute it and/or modify X * it under the terms of the GNU General Public License version 1, X * as published by the Free Software Foundation. X * X * This program is distributed in the hope that it will be useful, X * but WITHOUT ANY WARRANTY; without even the implied warranty of X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X * GNU General Public License for more details. X * X * You should have received a copy of the GNU General Public License X * along with this program; if not, write to the Free Software X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X */ X X#include X#include X#include X XMODVER ("@(#)$Header: yrwk.c,v 1.5 89/08/14 10:01:11 howard Exp $"); X X#include X#include X#include X#include X#include X XPUBLIC unsigned yrwk (tmp, yrp) XR4 struct tm *tmp; /* Points to struct tm with input data.*/ XR5 unsigned *yrp; /* If non-NULL, year corresponding to week stored here.*/ X X/* Function: X * Return the ISO week number of the date encoded in the struct tm, X * and, if yrp is not NULL, store the year of the ISO week in the X * location to which yrp points. ISO weeks start on Monday and end X * on Sunday. ISO week 1 is the first week of a year with four or more X * days in that year. X * Algorithm: X * Week is the same for every day in the week, so the week for any day of X * the year is the same as for the day of the year of the Monday of X * that week, assuming negative values are handled correctly. X * Let idw be the ISO day of the week, where 0 = Monday, etc. X * Let i = 10 + tm_yday - idw. i has the range [4, 375], and has the same X * value for every day in a week. Here is how i behaves near the X * start of a year: X * X * Year Starts On i For Week Containing Start Of Year i For Next Week X * Mon = 0 10 17 X * Tue = 1 9 16 X * Wed = 2 8 15 X * Thu = 3 7 14 X * Fri = 4 6 13 X * Sat = 5 5 12 X * Sun = 6 4 11 X * X * If i>=7, then i/7 gives the week number near the start of a year. X * X * Here is how i behaves near the end of a non-yeap year: X * X * Year Ends On i For Week Containing End Of Year X * Mon = 0 374 X * Tue = 1 373 X * Wed = 2 372 X * Thu = 3 371 X * Fri = 4 370 X * Sat = 5 369 X * Sun = 6 368 X * X * If i<=371 then i/7 gives the week number, but if i>371 then the X * week counts as part of the next year. Leap years require a one-day X * adjustment. X * Returns: X * Week number. X * Notes: X * X */ X{ XR1 unsigned i; /* See above.*/ XR2 unsigned yr; /* Year.*/ XR3 unsigned wk; /* Week number.*/ X Xif (((struct tm *) NULL) == tmp) malf1 ("yrwk: NULL struct tm *"); Xi = 10 + tmp->tm_yday - ((tmp->tm_wday + 6) % 7); Xyr = TM_YEAR_BASE + tmp->tm_year; Xif (i > (LEAPYEAR (yr) ? 372 : 371)) X { X ++yr; X wk = 1; X } Xelse if (i < 7) X { X --yr; X wk = (i + YEARSIZE (yr)) / 7; X } Xelse X wk = i / 7; Xif (((unsigned *) NULL) != yrp) *yrp = yr; Xreturn (wk); X} X X#ifdef TEST X#include X XMAINVER ("@(#)$Header: yrwk.c,v 1.5 89/08/14 10:01:11 howard Exp $"); XUSAGE (""); X X#include X XPUBLIC int main (argc, argv) Xint argc; /* Number of arguments.*/ XbStrT *argv; /* Points to array of argument strings.*/ X{ Xtime_t ut; /* Current system time.*/ Xunsigned w; /* Week.*/ Xunsigned y; /* Year.*/ Xextern time_t time(); /* (3).*/ X Xif (1 != argc) usage(); Xut = time ((time_t *) NULL); Xw = yrwk (localtime (&ut), &y); XPRINTF ("%u-%02u\n", y, w); Xmfflush (stdout, "Standard Output"); Xexit (SUCCESS); X X#ifdef lint Xreturn (SUCCESS); X#endif X} X#endif END_OF_FILE if test 4174 -ne `wc -c <'yrwk.c'`; then echo shar: \"'yrwk.c'\" unpacked with wrong size! fi # end of 'yrwk.c' fi echo shar: End of archive 4 \(of 9\). cp /dev/null ark4isdone MISSING="" for I in 1 2 3 4 5 6 7 8 9 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 9 archives. rm -f ark[1-9]isdone ark[1-9][0-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0