home *** CD-ROM | disk | FTP | other *** search
- From: vac@CS.CMU.EDU (Vincent.Cate)
- Newsgroups: comp.sources.misc
- Subject: v42i048: alex - NFS/FTP global filesystem, Part10/13
- Date: 30 Mar 1994 20:57:40 -0600
- Organization: Sterling Software
- Sender: kent@sparky.sterling.com
- Approved: kent@sparky.sterling.com
- Message-ID: <2nde74$jj4@sparky.sterling.com>
- X-Md4-Signature: 2da3bc68446579b01012dbc2598a6db0
-
- Submitted-by: vac@CS.CMU.EDU (Vincent.Cate)
- Posting-number: Volume 42, Issue 48
- Archive-name: alex/part10
- Environment: Most Unix machines - with 100 MB to 10 GB of free disk
-
- #! /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".
- # Contents: alexsrvr/src/alex.h alexsrvr/src/cmucs.c
- # alexsrvr/src/defs.c alexsrvr/src/init.c
- # alexsrvr/src/stringtotime.c alexsrvr/src/stringtotime.y
- # Wrapped by kent@sparky on Tue Mar 29 21:56:23 1994
- PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 10 (of 13)."'
- if test -f 'alexsrvr/src/alex.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'alexsrvr/src/alex.h'\"
- else
- echo shar: Extracting \"'alexsrvr/src/alex.h'\" \(17110 characters\)
- sed "s/^X//" >'alexsrvr/src/alex.h' <<'END_OF_FILE'
- X
- X#include "config.h"
- X
- X
- X#ifndef DEBUGLEVEL
- X#define DEBUGLEVEL 1
- X#endif
- X
- X/* The following can be renumbered. Any that are <= DEBUGLEVEL
- X* end up getting sent to the log. For example, make DBDOTALEX 0 if you always
- X* want to see the .alex.dir and .alex.info files
- X*
- X* 0 nothing to log - should not do this */
- X#define DBERROR 1 /* errors only - minimal logging */
- X#define DBMAJOR 2 /* only major calls - like to CheckAlexCache */
- X#define DBRPC 3 /* a line or two per RPC */
- X#define DBPERF 4 /* performance monitoring */
- X#define DBPERF2 5 /* more performance monitoring */
- X#define DBFTP 6 /* all actual FTP details from parent side */
- X#define DBFTPCHILD 7 /* all FTP details in childs own log */
- X#define DBOPEN 9 /* opens and closes of files */
- X#define DBALL 10 /* log every random thing - lots of stuff */
- X#define DBALLT 11 /* log everything and timestamp it */
- X
- X#define DBDOTALEX 1000000 /* show .alex.dir and .alex.info files */
- X
- X#define DEFAULTTIMEZONE 300 /* Eastern time if can not get remote timezone info back */
- X#define MAXWAITFORTIME 30 /* 30 seconds */
- X
- Xextern FILE *debugLog;
- X
- Xextern ToLog_c();
- Xextern Logcall_c();
- X
- X#if (DEBUGLEVEL != 0)
- X#define ToLog ToLog_c
- X#define Logcall Logcall_c
- X#else
- X#define ToLog (void)
- X#define Logcall (void)
- X#endif
- X
- X
- X#define Log2(x, y) ToLog(10, "%s : %s\n", x, y)
- X#define Log3(x, y, z) ToLog(10, "%s : %s : %s \n", x, y, z)
- X#define LogN(x, y) ToLog(10, "%s : %d \n", x, y)
- X#define LogD(x, y) ToLog(10, "%s : %f \n", x, y)
- X#define LogT(x, t) ToLog(10, "%s : %s \n", x, ATypeToString(t))
- X#define LogC(x, c) ToLog(10, "%s : %c \n", x, c)
- X#define Log(x) ToLog(10, "%s \n", x)
- X#define AlexAssert(x) if (!(x)) AlexAssertFailed(__FILE__, __LINE__, 1); /* phone home */
- X#define AlexAssertSetup(x) if (!(x)) AlexAssertFailed(__FILE__, __LINE__, 0); /* just a setup thing */
- X
- Xextern error1();
- Xextern error2();
- Xextern double TimeStampLog();
- Xextern char *DateStr();
- Xextern char *CurrentDateStr();
- X
- X#define DONOTWAIT 0
- X#define DOWAIT 1
- X
- X#define AMINUTE 60
- X#define AHOUR (60 * AMINUTE)
- X#define ADAY (24 * AHOUR)
- X#define AWEEK ( 7 * ADAY)
- X#define AMONTH (30 * ADAY)
- X#define TRUSTTIMEZONE (6*AMONTH) /* we catch daylight savings, so no hurry really to recheck timezone */
- X#define TRUSTHOSTTYPE AMONTH /* if NOANONFTP don't go back for one month */
- X#define SECSTILLRETRY (10 * AMINUTE) /* till we retry after major FTP error */
- X
- X#define MINCONSSLOP (5 * AMINUTE) /* minimum consistency promise */
- X /* if file changes every minute, you loose */
- X
- X/* Will force an update off all .alex.info files older than this. */
- X#define MINTIMEOKALEXINFO 690460771
- X
- X#define AFOPEN(x, t) afopen(x, t, __FILE__, __LINE__)
- X#define ALEXINFOINOPEN(m, n, o, p) AlexInfoInOpen(m, n, o, p, __FILE__, __LINE__)
- X
- X#define AFCLOSE(f) afclose(f, __FILE__, __LINE__)
- X
- X#define STARTDATA 20
- X
- X#define ROOTINODE 3 /* also in RootAlexInfo */
- Xextern char ROOTALEXINFOSTR[]; /* something like /usr2/.alex.info */
- Xextern int CACHEDIRLEN; /* strlen(CACHEDIR) */
- Xextern char CACHEDIRVAR[]; /* alot like CACHEDIR */
- Xextern int CACHEDIRPARTS; /* number of directories */
- Xextern int ALEXUIDVAR;
- Xextern int ALEXGIDVAR;
- X
- Xextern int NumFinishedFtps;
- X
- X#define FTPWRAPPATH "/usr/vac/alex/bin/ftpwrap"
- X#define FTPWRAP "ftpwrap"
- X
- X#define ALEXDIR ".alex.dir"
- X#define SLASHALEXDIR "/.alex.dir"
- X
- X#define ALEXINFO ".alex.info"
- X#define SLASHALEXINFO "/.alex.info"
- X
- X#define ALEXERROR ".alex.error"
- X#define SLASHALEXERROR "/.alex.error"
- X
- X#define ALEXUPDATE ".alex.update" /* accessing this file causes server to update dir */
- X#define SLASHALEXUPDATE "/.alex.update"
- X
- X#define ALEXADDHOST ".addhost" /* if NOAUTOADDHOST only check if host if this is */
- X /* at end of a path */
- X
- X#define MAXPARTSINHOSTNAME 6 /* only a very few this long and never seen longer */
- X/* I only know of 2 hosts with 6 part names. One is:
- X * USUHS.UCC.USUHS.NNMC.NAVY.MIL:131.158.4.3 CPU=VAX-8350 OS=VMS 5.0
- X */
- X
- X
- X#define MAXFTPSOPEN 10 /* note they also are closed after MAXIDLEFTP */
- X#define STRANGEOPENCOUNT 10 /* does not count FTPs - should not be this many files open */
- X
- X#define RemTimeZoneFAIL 24*60 /* unreasonable number of minutes */
- X
- X#define FILLCHAR '_' /* what strange chars and spaces are replaced with in error messages */
- X
- X#define MAXPATH 500
- X
- X#define MAXTOKENS 11
- X#define MAXTOKENLEN 200
- X
- X#define RECURSIONOK 1
- X#define NORECURSION 0
- X
- X#define NoKillFtps 0
- X#define YesKillFtps 1
- X
- X#define BOGUSINODE 123456
- X
- X/* C's enumerated types are not really portable and don't mix well with real ints
- X * so I don't use them.
- X *
- X * .alex.info needs AFILE, ADIR, ALINK to not change (can remove all .alex.info if need to)
- X */
- X#define AOK 0 /* function did what was asked - we use fact that is zero */
- X#define AFAIL 1 /* function failed */
- X#define AFILE 2 /* type info (no failure implied) */
- X#define ADIR 3 /* type info " " " */
- X#define AERRORMESSAGE 4 /* not a real file just an error message */
- X /* 5 no longer used */
- X#define ALINK 6 /* a link on a remote host type info */
- X#define NOSUCHFILE 7 /* */
- X#define AOLD 8 /* failed because we have old directory data */
- X#define NOPWD 9 /* failed because it does not do PWD but don't know type */
- X#define SOFTERROR 10 /* seems to be the type of error where a retry might work */
- X#define AEOF 11 /* were reading a file and got to the end */
- X#define AHOST 12 /* a directory for a host */
- X#define AUPDATE 13 /* we found that directory information is out of date */
- X#define AWORKING 14 /* Alex is working on that job but is not yet done */
- X#define ANFSSTALE 15 /* Stale NFS Handle */
- X#define NOSUCHHOST 16 /* even if there used to be such a host, there is not now */
- X /* 17 no longer used */
- X#define MAKELINKSTOPARENT 18 /* only in dirtoinfo.c */
- X#define MAKELINKSTOALEX 19 /* only in dirtoinfo.c */
- X#define REMOVEALWAYS 20 /* always remove (unless just seconds old) */
- X#define REMOVEMAYBE 21 /* if old then remove */
- X#define REMOVENEVER 22 /* do not remove */
- X#define ADOMAIN 23 /* we have something that is part of a hostname */
- X /* XXXXXX UG. ADOMAIN is in .alex.info as 23 so can not change but is a hosttype */
- X /* so mst be between MinHostType and MaxHostType. Ug. */
- X /* we use strings for the types below in HostsList so they can change */
- X#define MinHostType ADOMAIN
- X#define NOANONFTP ADOMAIN+1 /* this host does not alow anonymous ftp */
- X#define NEVERDOFTP ADOMAIN+2 /* this host hates ftp attempts - dmscanb.cbr.dms.csiro.au */
- X#define UNIX ADOMAIN+3 /* Unix */
- X#define ABSUNIX ADOMAIN+4 /* Unix with absolute paths like /usr0/anon/pub/README */
- X#define CDMODE ADOMAIN+5 /* unix but must use CDs to get around */
- X#define RELMODE ADOMAIN+6 /* unix but use . as top */
- X#define DECVMS ADOMAIN+7 /* VMS */
- X#define IBM ADOMAIN+8 /* IBM */
- X#define TOPS20 ADOMAIN+9 /* TOPS20 */
- X#define DECTEN ADOMAIN+10 /* DECTEN */
- X#define HOSTALIAS ADOMAIN+11 /* need to keep track of these too - very similar to ALINK */
- X#define HPUX ADOMAIN+12 /* only used in dirtoinfo */
- X#define DECVMS2 ADOMAIN+13 /* only used in dirtoinfo */
- X#define HENSA ADOMAIN+14 /* uk.ac.hensa.micros */
- X#define NOVEL ADOMAIN+15 /* Novel */
- X#define MaxHostType NOVEL
- X#define UNKNOWN MaxHostType+1 /* can not tell type - always largest type number */
- X
- X#define ALEXINFOVERSION 4 /* changes .alex.info's format changes */
- X#define OLDVERSIONTOKEN "()" /* compatibility with older shit */
- X#define METACHAR '!' /* non directory info in .alex.info */
- X#define VERSCHAR 'V' /* version number (ALEXINFOVERSION) */
- X#define DATECHAR 'D' /* date last fetched */
- X#define NEWCHAR 'N' /* date of newest item in directory */
- X#define SIZECHAR 'S' /* 1 if we could parse the sizes of files */
- X#define HOSTPARTSCHAR 'H' /* number of parts in hostname "cs.cmu.edu" is 3 */
- X#define ERRORCHAR 'E' /* if there then there if a .alex.error type message */
- X#define UPDATECHAR 'U' /* force and update on next use of this file */
- X
- Xstruct HostEntry {
- X char *Path; /* like /edu/berkeley */
- X int Type; /* ADOMAIN, UNIX... */
- X int TimeZone; /* in minutes from greenwich */
- X int TimeLastCheck; /* time we last checked with host about this info */
- X char *TopDir; /* for places we keep a topdir for */
- X char *SymLink; /* if HOSTALIAS */
- X /* above is stuff that is saved in file below is dynamic */
- X int Status; /* AFAIL / AOK / AWORKING */
- X int NumErrorsSinceOk; /* 0 add 1 for error clear when worked */
- X unsigned int LastUsed; /* Time last used */
- X int PartsInHostName; /* /edu/berkeley is 2 */
- X int PathLen; /* strlen(Path) = strlen("/edu/berkeley") = 13 */
- X float RespTime;
- X float KBPSec;
- X};
- X
- Xextern char SERVERHOSTNAME[]; /* name of host running alex - myhostname */
- X
- Xextern struct HostEntry *HostsTable[]; /* mostly just in alex but dirtoinfo uses too */
- Xextern int HostsInTable;
- X
- Xstruct ParsedDir {
- X int Type; /* AFILE, ADIR, ALINK, AHOST */
- X#ifdef EXECUTABLE
- X int Executable; /* if the file is trusted as executable */
- X#endif
- X unsigned int Date; /* same as NFS */
- X unsigned int Size; /* same as NFS */
- X unsigned int Inode; /* same as NFS */
- X int CacheStatus; /* 0=NotThere 1=There */
- X char Name[MAXPATH]; /* like foo */
- X char SymLink[MAXPATH]; /* except for /afs and /alex the link should be relative */
- X int Stale; /* 0 if consistent enough 1 if stale */
- X int SizeTrusted; /* 1 if sizes come from trusted .alex.dir like UNIX ones */
- X int PartsInHostName; /* cs.cmu.edu is 3 */
- X};
- X
- Xstruct ActiveAlexInfo {
- X int Version;
- X char OpenAlexInfoPath[MAXPATH]; /* path used for open of .alex.info */
- X int PartsInDirPath; /* /usr2/alex-cache/edu/berkeley/.alex.info is 2 i.e. after CACHEDIR */
- X unsigned int UpdateDate; /* date of last fetch of .alex.dir */
- X unsigned int NewestDate; /* date of newest item in directory */
- X int SizeOk; /* 1=parsed good sizes, 0=don't know sizes */
- X FILE *File;
- X int PartsInHostName; /* cs.cmu.edu is 3 */
- X int HasAlexError; /* an .alex.error was included in this */
- X int NeedAnUpdate; /* an old .alex.error was included in this - need an update */
- X};
- X
- X
- Xextern unsigned int InodeNext;
- X
- X/* UidToUidStr module */
- Xextern char LastUidStr[];
- Xextern char *UidToUidStr();
- Xextern void ClearKnownUsers();
- Xextern int NumKnownUsers;
- Xextern int NumDiffKnownUids();
- X
- X
- Xextern SetUidGid();
- X
- X/* Friendly string operations */
- X#define streql(x, y) (!(strcmp(x, y)))
- Xextern int WhereString();
- Xextern int HasStringNoCase();
- Xextern int HasString();
- Xextern int HasChar();
- Xextern int CountOccurances();
- Xextern int StrLastNCmp();
- Xextern char *strsave();
- X
- X/* Destructive string operations */
- Xextern int ChopAtCR();
- Xextern int RemoveTrailingSlash();
- Xextern int RemoveDot();
- Xextern int RemoveDotDot();
- Xextern int SimplifyPath();
- Xextern int NoTrailingSpaces();
- Xextern int RemoveThroughSlash();
- Xextern int RemoveTrailingC();
- X
- Xextern int afclose();
- Xextern FILE *afopen();
- X
- Xextern char *GetNthToken();
- Xextern char *GetNextToken();
- Xextern GetLastToken();
- X
- Xextern int DirToInfo();
- Xextern int EmptyToInfo();
- Xextern int OneLineIn();
- Xextern int OneLineOut();
- Xextern CopyParsedDir();
- X
- Xextern char *ATypeToString();
- Xextern int StringToAType();
- Xextern int IsAHostType();
- X
- Xextern int AlexStat();
- Xextern int LiteStat();
- X
- Xextern double TimeInSeconds();
- Xextern double RecentTime;
- Xextern double GreenTimeInSeconds();
- Xextern int StringToTimeb();
- Xextern int StringToTimeInt();
- Xextern double LastTimeChange;
- X
- Xextern double MTimeOfFile();
- Xextern double SecsSinceWrite();
- X
- Xextern int AlarmIgnore();
- X
- Xextern int CheckFileCache();
- Xextern int CloseAndDie();
- Xextern int HisClockIsOK();
- Xextern int RemTimeZone();
- Xextern int AlexInit();
- Xextern int TouchFile();
- X
- Xextern int PathToFileName(); /* /foo/bar/baz to baz */
- Xextern int PathToDir(); /* /foo/bar/baz to /foo/bar */
- X
- X/* converstion between /* /edu/berkeley and berkeley.edu */
- Xextern int HostNameToPath();
- Xextern void PathToHostName();
- X
- X
- Xextern int AlexInfoCompatStat(); /* returns a regular stat buf */
- Xextern int AlexInfoLStat();
- Xextern int SimpleType();
- X
- X
- Xextern int LocateHostEntry();
- Xextern void ToLower();
- X
- Xextern int InvalidateStatCache; /* readinfo should not trust its cache after alex changes world */
- X
- Xextern int AlexInfoInNext();
- Xextern int AlexInfoInClose();
- Xextern int AlexInfoInOpen();
- Xextern int AlexOpenDir();
- Xextern unsigned int AlexInfoMTime();
- X
- X
- Xextern int LineToTokens(); /* string to array of token strings */
- X
- Xextern SetUsrX();
- Xextern int CopyAFile();
- X
- X
- X
- X#define Return return
- X
- Xextern char * strerror();
- X
- Xextern int StringIntoFile();
- Xextern int StringFromFile();
- Xextern int StringToUnsigned();
- X
- Xextern int RecursiveRm();
- X
- Xextern int SpecialFileName();
- X
- X/* doanftp.c */
- Xextern int IgnoreSIGPIPE();
- Xextern int CloseAllFtpCaches();
- Xextern int ClearFtpCacheEntry();
- Xextern int DoAnFtp();
- Xextern int CheckFileStatus();
- Xextern int HaveResultFile();
- Xextern int InTransit();
- Xextern void KillOldFtps();
- X
- X/* known stale stuff */
- Xextern void SaveKnownStaleFilePath();
- Xextern void ClearKnownStaleFilePath();
- Xextern int IsKnownStale();
- X
- X
- Xextern int FilesAreEqual();
- X
- X
- X/* Performance results */
- Xextern double InitTime;
- X
- Xextern double TotalBytesNFSed;
- Xextern double TotalBytesFTPed;
- Xextern double TotalFTPTime;
- Xextern int NumFinishedFTPs;
- X
- Xextern int TotalFilesNFSed;
- Xextern int TotalFilesFTPed;
- Xextern double TotalFileBytesNFSed;
- Xextern double TotalFileBytesFTPed;
- X
- Xextern int TotalFtpsForked;
- X
- Xextern int TotalDirsNFSed;
- Xextern int TotalDirsFTPed;
- Xextern double TotalDirBytesNFSed;
- Xextern double TotalDirBytesFTPed;
- X
- Xextern int LookupHits;
- Xextern int LookupMisses;
- Xextern int LookupDrops;
- X
- Xextern int ReadHits;
- Xextern int ReadMisses;
- Xextern int ReadDrops;
- X
- Xextern int ReadDirHits;
- Xextern int ReadDirMisses;
- Xextern int ReadDirDrops;
- X
- Xextern int TotalStaleFiles;
- Xextern int TotalStaleSecs;
- X
- Xextern double TotalNFSLS;
- Xextern double TotalFTPLS;
- X
- Xextern void AlexAssertFailed();
- Xextern void PhoneHome();
- X
- Xextern int TotalGHBNCalls;
- Xextern double TotalGHBNTime;
- Xextern double TotalGHBNTimeSQ;
- Xextern int TotalRTZCalls;
- Xextern double TotalRTZTime;
- Xextern double TotalRTZTimeSQ;
- X
- Xextern int NumAlexUpdates;
- X
- Xextern int TotalErrorMsg;
- Xextern int TotalUnchangedDirs;
- X
- X
- X
- X#ifndef FALSE
- X#define FALSE 0 /* probably only used for AlexAssert(FALSE) */
- X#endif
- X
- Xextern int h_errno;
- X
- Xextern int SortFile();
- Xextern int PrependLineToFile();
- X
- X#define ALEXVERSION "Tue Mar 29 05:35:43 EST 1994"
- END_OF_FILE
- if test 17110 -ne `wc -c <'alexsrvr/src/alex.h'`; then
- echo shar: \"'alexsrvr/src/alex.h'\" unpacked with wrong size!
- fi
- # end of 'alexsrvr/src/alex.h'
- fi
- if test -f 'alexsrvr/src/cmucs.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'alexsrvr/src/cmucs.c'\"
- else
- echo shar: Extracting \"'alexsrvr/src/cmucs.c'\" \(15544 characters\)
- sed "s/^X//" >'alexsrvr/src/cmucs.c' <<'END_OF_FILE'
- X/*
- X * Copyright (c) 1990 Carnegie Mellon University
- X * All Rights Reserved.
- X *
- X * Permission to use, copy, modify and distribute this software and its
- X * documentation is hereby granted, provided that both the copyright
- X * notice and this permission notice appear in all copies of the
- X * software, derivative works or modified versions, and any portions
- X * thereof, and that both notices appear in supporting documentation.
- X *
- X * THE SOFTWARE IS PROVIDED "AS IS" AND CARNEGIE MELLON UNIVERSITY
- X * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
- X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT
- X * SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR ANY SPECIAL, DIRECT,
- X * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
- X * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
- X * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- X * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- X *
- X * Users of this software agree to return to Carnegie Mellon any
- X * improvements or extensions that they make and grant Carnegie the
- X * rights to redistribute these changes.
- X *
- X * Export of this software is permitted only after complying with the
- X * regulations of the U.S. Deptartment of Commerce relating to the
- X * Export of Technical Data.
- X */
- X
- X
- X#include "alexincs.h"
- X
- X
- X
- X/*
- X * HISTORY
- X * $Log: fdate.c,v $
- X * Revision 1.3 92/03/24 14:09:25 mja
- X * For gcc: forward declarations:
- X * static int dofield(), percent(), formfld(), copyword(), casefix();
- X * static char foldc();
- X * [91/11/26 rvb]
- X *
- X * Revision 1.2 90/12/11 17:52:25 mja
- X * Add copyright/disclaimer for distribution.
- X *
- X * 30-Apr-85 Steven Shafer (sas) at Carnegie-Mellon University
- X * Adapted for 4.2 BSD UNIX: macro file name changed.
- X *
- X *
- X * March 1984 - Leonard Hamey (lgh) at Carnegie-Mellon University
- X * Created.
- X */
- X
- X# define TEXT 1
- X# define FAIL 2
- X# define OPTIONAL 3
- X# define SUCCEED 4
- X
- X# define YES 1
- X# define NO 0
- X# define MAYBE 2
- X
- X# define SMONTHS 0
- X# define SWDAYS 12
- X# define SNOON 19
- X# define SMIDNIGHT 20
- X# define SAM 21
- X# define SPM 22
- X# define STH 23
- X# define SST 24
- X# define SND 25
- X# define SRD 26
- X
- X# define NOON 0
- X# define HOUR 1
- X# define AM 2
- X# define MINX 3
- X# define SEC 4
- X# define WDAY 5
- X# define DAY 6
- X# define TH 7
- X# define NMONTH 8
- X# define MONTH 9
- X# define YEAR 10
- X# define YDAY 11
- X# define MIDNIGHT 12
- X# define TIME 13
- X
- Xstatic char *strings[] =
- X{ "jan*uary", "feb*ruary", "mar*ch", "apr*il", "may", "jun*e",
- X "jul*y", "aug*ust", "sep*tember", "oct*ober", "nov*ember", "dec*ember",
- X "sun*day", "mon*day", "tue*s*day", "wed*nesday", "thu*r*s*day",
- X "fri*day", "sat*urday",
- X "noon", "00:00", "am", "pm", "th", "st", "nd", "rd"
- X};
- X
- Xstatic char *keys[] =
- X{ "noon", "hour", "am", "min", "sec",
- X "wday", "day", "th", "nmonth", "month", "year", "yday",
- X "midnight", "time",
- X 0
- X};
- X
- X/* The following is a macro definition of %time. */
- X
- Xstatic char *mactime =
- X "[%midnight|%noon|%0hour:%min:%?sec|{%hour{:%?min}%am}]";
- X
- Xstatic char *p;
- Xstatic int resp;
- Xstatic char *result;
- Xstatic int dofield(), percent(), formfld(), copyword(), casefix();
- Xstatic char foldc();
- X
- Xchar *fdate (resb, patt, tm)
- Xchar *resb, *patt;
- Xstruct tm *tm;
- X{ result = resb;
- X resp = 0;
- X p = patt;
- X dofield (' ', tm);
- X result[resp] = '\0';
- X return (result);
- X}
- X
- Xstatic dofield (doing, tm)
- Xchar doing;
- Xstruct tm *tm;
- X{ int ndep, s, sresp, sresp2;
- X int fail;
- X char ch;
- X fail = MAYBE;
- X sresp = resp;
- X while (*p)
- X { if (*p == '{' || *p == '[')
- X { ch = *p++;
- X s = dofield (ch, tm);
- X if (s == FAIL && doing == '[')
- X fail = YES;
- X else if (s == SUCCEED && doing == '{')
- X fail = NO;
- X }
- X else if (*p == '}' || *p == ']' || *p == '|')
- X { if (doing == '{' && fail == MAYBE)
- X fail = YES;
- X if (fail == YES)
- X { resp = sresp;
- X if (*p == '|')
- X { p++;
- X fail = MAYBE; /* try next */
- X continue;
- X }
- X p++;
- X }
- X else if (*p == '|')
- X { /* Scan to matching bracket/brace */
- X ndep = 1;
- X while (ndep > 0)
- X { if (*p == '{' || *p == '[')
- X ndep++;
- X else if (*p == '}' || *p == ']')
- X ndep--;
- X p++;
- X }
- X }
- X else
- X p++;
- X return (fail == YES ? FAIL : SUCCEED);
- X }
- X else if (*p == '%')
- X { sresp2 = resp;
- X s = percent (tm);
- X if (doing == '{')
- X { if (s == FAIL) /* Discard failure results */
- X resp = sresp2;
- X else if (s == SUCCEED)
- X fail = NO;
- X }
- X else if (doing == '[')
- X { if (s == FAIL)
- X fail = YES;
- X }
- X }
- X else
- X { result[resp++] = *p;
- X p++;
- X }
- X if (fail == YES)
- X { /* Failure: scan for barline or closing bracket/brace; leave ptr there */
- X resp = sresp;
- X ndep = 1;
- X while (ndep > 0)
- X { if (*p == '|' && ndep == 1)
- X break;
- X if (*p == '[' | *p == '{')
- X ndep++;
- X else if (*p == ']' || *p == '}')
- X { ndep--;
- X if (ndep == 0)
- X return (FAIL);
- X }
- X p++;
- X }
- X }
- X }
- X return (SUCCEED);
- X}
- X
- Xstatic percent (tm)
- Xstruct tm *tm;
- X{ register char *pp;
- X char *spp;
- X int query, lead0, prec, upcase, sresp, s;
- X char *savep;
- X register int ks;
- X register char *k;
- X char foldc ();
- X int formfld ();
- X char *fldp;
- X pp = p + 1;
- X if (*pp == '%' || *pp == '{' || *pp == '}' || *pp == '|' ||
- X *pp == '[' || *pp == ']')
- X { p += 2;
- X result[resp++] = *pp;
- X return (TEXT); /* Was just text */
- X }
- X query = *pp == '?'; /* Query? */
- X if (query)
- X pp++;
- X lead0 = *pp == '0'; /* Leading zero? */
- X if (lead0)
- X pp++;
- X if (*pp >= '1' && *pp <= '9') /* Precision? */
- X { prec = *pp - '0';
- X pp++;
- X }
- X else
- X prec = 0;
- X upcase = 0; /* Case? */
- X if (*pp >= 'A' && *pp <= 'Z')
- X upcase = 1;
- X if (pp[1] >= 'A' && pp[1] <= 'Z')
- X upcase = 2;
- X
- X spp = pp;
- X for (ks = 0; keys[ks]; ks++) /* Check for keyword */
- X { for (k = keys[ks], pp = spp; *k; k++, pp++)
- X if (foldc (*k) != foldc (*pp))
- X break;
- X if (! *k) /* Match found */
- X break;
- X }
- X if (! keys[ks]) /* No match */
- X { result[resp++] = '%'; /* Treat as text */
- X p++;
- X return (TEXT);
- X }
- X p = pp;
- X if (ks == TIME) /* Macro */
- X { savep = p;
- X sresp = resp;
- X p = mactime + 1; /* Skip leading bracket */
- X s = dofield (mactime[0], tm);
- X p = savep;
- X return (s);
- X }
- X /* Match found */
- X s = formfld (tm, ks, lead0, prec, &fldp);
- X sresp = resp;
- X if (s == OPTIONAL)
- X { if (query)
- X s = FAIL;
- X else
- X s = SUCCEED;
- X }
- X if (s == SUCCEED)
- X { for (; *fldp; fldp++)
- X result[resp++] = *fldp;
- X casefix (&result[sresp], upcase);
- X }
- X return (s);
- X}
- X
- Xstatic char foldc (c)
- Xchar c;
- X{
- X return (c < 'a' || c > 'z' ? c : c - 'a' + 'A');
- X}
- X
- Xstatic char nstr[30];
- Xstatic char sfield[30];
- Xstatic int thmem;
- X
- Xstatic formfld (tm, field, lead0, prec, result)
- Xstruct tm *tm;
- Xint field, lead0, prec;
- Xchar **result;
- X{ int fld, ddiff, s;
- X struct tm ctm;
- X long ctime;
- X sfield[0] = '\0';
- X *result = sfield;
- X if (field != TH)
- X thmem = -1;
- X switch (field)
- X { case NOON:
- X if (tm->tm_hour == 12 && tm->tm_min == 0 && tm->tm_sec == 0)
- X { *result = strings[SNOON];
- X return (SUCCEED);
- X }
- X return (FAIL);
- X
- X case HOUR:
- X for (; prec > 2; prec--)
- X strcat (sfield, " ");
- X if (lead0)
- X sprintf (nstr, "%02d", tm->tm_hour);
- X else if (prec < 2)
- X sprintf (nstr, "%d", (tm->tm_hour + 11) % 12 + 1);
- X else
- X sprintf (nstr, "%2d", (tm->tm_hour + 11) % 12 + 1);
- X strcat (sfield, nstr);
- X thmem = tm->tm_hour;
- X return (tm->tm_hour >= 0 ? SUCCEED : FAIL);
- X
- X case MINX:
- X fld = tm->tm_min;
- X case SEC:
- X if (field == SEC)
- X fld = tm->tm_sec;
- X if (prec == 0)
- X prec = 2;
- X for (; prec > 2; prec--)
- X strcat (sfield, " ");
- X if (prec < 2)
- X sprintf (nstr, "%d", fld);
- X else
- X sprintf (nstr, "%02d", fld);
- X strcat (sfield, nstr);
- X thmem = fld;
- X return (fld > 0 ? SUCCEED : (fld == 0 ? OPTIONAL : FAIL));
- X
- X case AM:
- X if (tm->tm_hour >= 12)
- X *result = strings[SPM];
- X else if (tm->tm_hour >= 0)
- X *result = strings[SAM];
- X return (tm->tm_hour >= 0 ? SUCCEED : FAIL);
- X
- X case WDAY:
- X if (tm->tm_wday >= 0 && tm->tm_wday < 7)
- X { copyword (sfield, strings[SWDAYS + tm->tm_wday], prec);
- X return (SUCCEED);
- X }
- X return (FAIL);
- X
- X case MONTH:
- X if (tm->tm_mon >= 0 && tm->tm_mon < 12)
- X { copyword (sfield, strings[SMONTHS + tm->tm_mon], prec);
- X return (SUCCEED);
- X }
- X return (FAIL);
- X
- X case DAY:
- X fld = tm->tm_mday;
- X case NMONTH:
- X case YDAY:
- X if (field == NMONTH)
- X fld = tm->tm_mon + 1;
- X else if (field == YDAY)
- X fld = tm->tm_yday;
- X if (prec == 0)
- X prec = 1;
- X if (lead0)
- X { strcpy (nstr, "%09d");
- X nstr[2] = prec + '0';
- X }
- X else
- X { strcpy (nstr, "%9d");
- X nstr[1] = prec + '0';
- X }
- X sprintf (sfield, nstr, fld);
- X thmem = fld;
- X return (fld >= 0 ? SUCCEED : FAIL);
- X
- X case TH:
- X if (thmem >= 0)
- X { if ((thmem / 10) % 10 == 1)
- X *result = strings[STH];
- X else if (thmem % 10 == 1)
- X *result = strings[SST];
- X else if (thmem % 10 == 2)
- X *result = strings[SND];
- X else if (thmem % 10 == 3)
- X *result = strings[SRD];
- X else
- X *result = strings[STH];
- X return (SUCCEED);
- X }
- X return (FAIL);
- X
- X case YEAR:
- X ctime = time (0);
- X ctm = *localtime (&ctime);
- X ddiff = (tm->tm_year - ctm.tm_year) * 366 + tm->tm_yday - ctm.tm_yday;
- X if (tm->tm_year >= -1900)
- X { if (prec == 0 || prec > 3)
- X sprintf (nstr, "%04d", tm->tm_year + 1900);
- X else
- X sprintf (nstr, "%02d", (tm->tm_year + 1900) % 100);
- X *result = nstr;
- X return (ddiff < 0 || ddiff > 300 ? SUCCEED : OPTIONAL);
- X }
- X return (FAIL);
- X
- X case MIDNIGHT:
- X if (tm->tm_hour == 0 && tm->tm_min == 0 && tm->tm_sec == 0)
- X { *result = strings[SMIDNIGHT];
- X return (SUCCEED);
- X }
- X return (FAIL);
- X }
- X}
- X
- X/* copyword: Copy <from> to <to> subject to precision <prec>. Asterisks in
- X * <from> mark valid truncation points. The longest string no longer than
- X * <prec> and broken at a valid truncation point is returned in <to>. Note
- X * that the result may exceed <prec> in length only if there are no valid
- X * truncation points short enough. The shortest is then taken.
- X *
- X * e.g. Tue*s*day. Precision 1-3 -> Tue, Precision 4-6 -> Tues,
- X * Precision 0 and 7... -> Tuesday.
- X */
- X
- Xstatic copyword (to, from, prec)
- Xchar *to, *from;
- Xint prec;
- X{ int ast = 0, top = 0;
- X if (prec == 0)
- X prec = 999;
- X for (; *from; from++)
- X { if (*from == '*')
- X ast = top;
- X else
- X { to[top] = *from;
- X top++;
- X }
- X if (top > prec && ast > 0)
- X { /* Required precision exceeded and asterisk found */
- X to[ast] = '\0'; /* Truncate at asterisk */
- X return;
- X }
- X }
- X to[top] = '\0';
- X return;
- X}
- X
- X
- Xvac_foldup(s)
- Xchar *s;
- X{
- X while (*s != 0) {
- X if (islower(*s)) {
- X *s = toupper(*s);
- X }
- X s++;
- X }
- X}
- X
- X/* casefix: select case of word. 1: first letter raised. 2: all raised. */
- X
- Xstatic casefix (text, upcase)
- Xchar *text;
- Xint upcase;
- X{
- X if (upcase == 1)
- X *text = foldc (*text);
- X else if (upcase > 0)
- X vac_foldup (text);
- X}
- X
- X
- X
- X
- X/* filecopy -- copy a file from here to there
- X *
- X * Usage: i = filecopy (here,there);
- X * int i, here, there;
- X *
- X * Filecopy performs a fast copy of the file "here" to the
- X * file "there". Here and there are both file descriptors of
- X * open files; here is open for input, and there for output.
- X * Filecopy returns 0 if all is OK; -1 on error.
- X *
- X * I have performed some tests for possible improvements to filecopy.
- X * Using a buffer size of 10240 provides about a 1.5 times speedup
- X * over 512 for a file of about 200,000 bytes. Of course, other
- X * buffer sized should also work; this is a rather arbitrary choice.
- X * I have also tried inserting special startup code to attempt
- X * to align either the input or the output file to lie on a
- X * physical (512-byte) block boundary prior to the big loop,
- X * but this presents only a small (about 5% speedup, so I've
- X * canned that code. The simple thing seems to be good enough.
- X *
- X * HISTORY
- X * $Log: filecopy.c,v $
- X * Revision 1.2 90/12/11 17:52:57 mja
- X * Add copyright/disclaimer for distribution.
- X *
- X * 20-Nov-79 Steven Shafer (sas) at Carnegie-Mellon University
- X * Rewritten for VAX; same as "filcopy" on PDP-11. Bigger buffer
- X * size (20 physical blocks) seems to be a big win; aligning things
- X * on block boundaries seems to be a negligible improvement at
- X * considerable cost in complexity.
- X *
- X */
- X
- X#define BUFFERSIZE 10240
- X
- Xint filecopy (here,there)
- Xint here,there;
- X{
- X register int kount;
- X char buffer[BUFFERSIZE];
- X kount = 0;
- X while (kount == 0 && (kount=read(here,buffer,BUFFERSIZE)) > 0)
- X kount -= write (there,buffer,kount);
- X return (kount ? -1 : 0);
- X}
- X
- X
- X
- X/* ffilecopy -- very fast buffered file copy
- X *
- X * Usage: i = ffilecopy (here,there)
- X * int i;
- X * FILE *here, *there;
- X *
- X * Ffilecopy is a very fast routine to copy the rest of a buffered
- X * input file to a buffered output file. Here and there are open
- X * buffers for reading and writing (respectively); ffilecopy
- X * performs a file-copy faster than you should expect to do it
- X * yourself. Ffilecopy returns 0 if everything was OK; EOF if
- X * there was any error. Normally, the input file will be left in
- X * EOF state (feof(here) will return TRUE), and the output file will be
- X * flushed (i.e. all data on the file rather in the core buffer).
- X * It is not necessary to flush the output file before ffilecopy.
- X *
- X * HISTORY
- X * $Log: ffilecopy.c,v $
- X * Revision 1.2 90/12/11 17:52:41 mja
- X * Add copyright/disclaimer for distribution.
- X *
- X * 20-Nov-79 Steven Shafer (sas) at Carnegie-Mellon University
- X * Created for VAX.
- X *
- X */
- X
- Xint ffilecopy (here,there)
- XFILE *here, *there;
- X{
- X register int i, herefile, therefile;
- X
- X herefile = fileno(here);
- X therefile = fileno(there);
- X
- X if (fflush (there) == EOF) /* flush pending output */
- X return (EOF);
- X
- X#if defined(__386BSD__) || defined(__NetBSD__)
- X if ((here->_r) > 0) { /* flush buffered input */
- X i = write (therefile, here->_p, here->_r);
- X if (i != here->_r) return (EOF);
- X here->_p = here->_bf._base;
- X here->_r = 0;
- X }
- X
- X i = filecopy (herefile, therefile); /* fast file copy */
- X if (i < 0) return (EOF);
- X
- X (here->_flags) |= __SEOF; /* indicate EOF */
- X#else
- X#if defined(__linux__)
- X
- X/*
- X * This is to deal with the new IO stream functions in Linux libc version
- X * 4.5.8 and onwards. It will most definetly not work with libraries before
- X * this. Please report bugs herein to me - Mitch <m.dsouza@mrc-apu.cam.ac.uk>
- X *
- X */
- X if ((here->_IO_read_end - here->_IO_read_ptr) > 0) { /* flush buffered input */
- X i = write (therefile, here->_IO_read_ptr,here->_IO_read_end - here->_IO_read_ptr);
- X if (i != here->_IO_read_end - here->_IO_read_ptr) return (EOF);
- X here->_IO_read_ptr = here->_IO_read_end;
- X }
- X
- X i = filecopy (herefile, therefile); /* fast file copy */
- X if (i < 0) return (EOF);
- X
- X (here->_IO_file_flags) |= _IO_EOF_SEEN; /* indicate EOF */
- X#else
- X if ((here->_cnt) > 0) { /* flush buffered input */
- X i = write (therefile, here->_ptr, here->_cnt);
- X if (i != here->_cnt) return (EOF);
- X here->_ptr = here->_base;
- X here->_cnt = 0;
- X }
- X
- X i = filecopy (herefile, therefile); /* fast file copy */
- X if (i < 0) return (EOF);
- X
- X (here->_flag) |= _IOEOF; /* indicate EOF */
- X#endif
- X#endif
- X
- X return (0);
- X}
- X
- X
- X
- END_OF_FILE
- if test 15544 -ne `wc -c <'alexsrvr/src/cmucs.c'`; then
- echo shar: \"'alexsrvr/src/cmucs.c'\" unpacked with wrong size!
- fi
- # end of 'alexsrvr/src/cmucs.c'
- fi
- if test -f 'alexsrvr/src/defs.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'alexsrvr/src/defs.c'\"
- else
- echo shar: Extracting \"'alexsrvr/src/defs.c'\" \(1678 characters\)
- sed "s/^X//" >'alexsrvr/src/defs.c' <<'END_OF_FILE'
- X
- X#include "alexincs.h"
- X#include "alex.h"
- X
- XFILE *debugLog;
- X
- Xfh_fdclose()
- X{
- X printf("ERROR fh_fdclose should not be called\n");
- X exit(-1);
- X}
- X
- Xmain(argc, argv)
- Xint argc;
- Xchar *argv[];
- X{
- X FILE *devnull;
- X char myname[MAXPATH];
- X
- X PathToFileName(argv[0], myname);
- X if ((argc > 2) || ((argc==1) && (!streql(myname, "cachedir")))) {
- X fprintf(stderr, "%s: usage is %s [alexsrvr/home/install/resolver]\n", argv[0], argv[0]);
- X exit(-1);
- X }
- X
- X
- X devnull=fopen("/dev/null", "w");
- X if (devnull == NULL) {
- X fprintf(stderr, "ERROR: Can not open /dev/null \n ");
- X exit(-1);
- X }
- X
- X debugLog=devnull;
- X
- X if (streql(myname, "cachedir") || streql(argv[1], "cachedir")) {
- X InitReadOnlyVariables();
- X printf("%s\n", CACHEDIRVAR); /* only one that needs Init */
- X
- X } else if (streql(argv[1], "alexsrvr")) {
- X printf("%s\n", ALEXSRVR);
- X
- X } else if (streql(argv[1], "tmpdir")) {
- X printf("%s\n", TMPDIR);
- X
- X } else if (streql(argv[1], "logdir")) {
- X printf("%s\n", LOGDIR);
- X
- X } else if (streql(argv[1], "home")) {
- X printf("%s\n", ALEXSRVRHOME);
- X
- X } else if (streql(argv[1], "debuglevel")) {
- X printf("%d\n", DEBUGLEVEL);
- X
- X } else if (streql(argv[1], "install")) {
- X printf("%s\n", INSTALLDIR);
- X
- X } else if (streql(argv[1], "cacheinfohead")) {
- X printf("%s\n", CACHEINFOHEAD);
- X
- X } else if (streql(argv[1], "at_dir")) {
- X#ifdef AT_DIR
- X printf("/@");
- X#else
- X printf("");
- X#endif
- X } else if (streql(argv[1], "resolver")) {
- X#ifdef USINGRESOLVER
- X printf("-lresolv\n");
- X#else
- X printf("");
- X#endif
- X }
- X}
- X
- END_OF_FILE
- if test 1678 -ne `wc -c <'alexsrvr/src/defs.c'`; then
- echo shar: \"'alexsrvr/src/defs.c'\" unpacked with wrong size!
- fi
- # end of 'alexsrvr/src/defs.c'
- fi
- if test -f 'alexsrvr/src/init.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'alexsrvr/src/init.c'\"
- else
- echo shar: Extracting \"'alexsrvr/src/init.c'\" \(15476 characters\)
- sed "s/^X//" >'alexsrvr/src/init.c' <<'END_OF_FILE'
- X/* Copyright (c) 1992 Vincent Cate
- X * All Rights Reserved.
- X *
- X * Permission to use and modify this software and its documentation
- X * is hereby granted, provided that both the copyright notice and this
- X * permission notice appear in all copies of the software, derivative works
- X * or modified versions, and any portions thereof, and that both notices
- X * appear in supporting documentation. This software or any derivate works
- X * may not be sold or distributed without prior written approval from
- X * Vincent Cate.
- X *
- X * THE SOFTWARE IS PROVIDED "AS IS" AND VINCENT CATE DISCLAIMS ALL
- X * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
- X * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
- X * VINCENT CATE BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
- X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- X * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- X * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
- X * OR PERFORMANCE OF THIS SOFTWARE.
- X *
- X * Users of this software agree to return to Vincent Cate any improvements
- X * or extensions that they make and grant Vincent Cate the rights to
- X * redistribute these changes.
- X *
- X */
- X
- X
- X
- X
- X/* UNFSD - copyright Mark A Shand, May 1988.
- X * This software maybe be used for any purpose provided
- X * the above copyright notice is retained. It is supplied
- X * as is, with no warranty expressed or implied.
- X */
- X
- X/*
- X** Udp socket establishment routine
- X*/
- X
- X
- X#ifndef lint
- Xstatic char sccsid[] = "@(#)init.c 1.2atd Wed, Jun 07, 1989";
- X#endif lint
- X
- X#include "alexincs.h"
- X#include "unfsd.h"
- X#include "alex.h"
- X
- X
- X#ifdef EXPORTSFILE
- X#define DEFAULT_EXPORTSFILE EXPORTSFILE
- X#else
- X#define DEFAULT_EXPORTSFILE ALEXEXPORTSFILE
- X#endif
- X
- X#ifndef SYSERROR
- X#define SYSERROR (-1)
- X#endif
- X
- X
- Xint init_Log()
- X{
- X char logbuf[100];
- X
- X sprintf(logbuf,"%s/alex.log",LOGDIR);
- X SetLogBaseName(logbuf);
- X InitReadOnlyVariables(); /* needs to be first before any Logs() */
- X Log("init_Log just warming up unfsd Log");
- X}
- X
- Xint makesock(port,socksz)
- Xint port;
- Xint socksz;
- X{
- X struct sockaddr_in my_sock;
- X int s;
- X extern int errno;
- X
- X bzero((char *)&my_sock, sizeof(my_sock));
- X my_sock.sin_addr.s_addr = INADDR_ANY;
- X my_sock.sin_family = AF_INET;
- X my_sock.sin_port = htons(port);
- X
- X if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
- X {
- X error1("makesock could not make a socket");
- X return(SYSERROR);
- X }
- X#ifdef SO_SNDBUF
- X {
- X int sblen, rblen;
- X
- X sblen = rblen = socksz + 1024;
- X /* 1024 for rpc & transport overheads */
- X if (
- X setsockopt(s, SOL_SOCKET, SO_SNDBUF, &sblen, sizeof sblen) < 0
- X ||
- X setsockopt(s, SOL_SOCKET, SO_RCVBUF, &rblen, sizeof sblen) < 0
- X )
- X error1("makesock setsockopt failed");
- X }
- X#endif
- X
- X if (bind(s, (struct sockaddr *) &my_sock, sizeof(my_sock)) == -1) {
- X error1("makesock could not bind name to socket");
- X return(SYSERROR);
- X }
- X
- X return s;
- X}
- X
- Xftype ft_map[16];
- Xint svc_euid;
- Xint svc_egid;
- Xint cur_gid;
- Xint svc_ngids;
- Xint svc_gids[NGROUPS+2];
- X
- Xstatic clnt_param *clients = NULL;
- Xstatic clnt_param *unknown_clients = NULL;
- Xstatic clnt_param *default_client = NULL;
- X
- X#define LINE_SIZE 1024
- X
- Xstatic char *
- Xparse_opts(s, terminator, o, client_name)
- Xchar *s;
- Xchar terminator;
- Xoptions *o;
- Xchar *client_name;
- X{
- X /* parse option string pointed to by s and set o accordingly */
- X char kwdbuf[LINE_SIZE];
- X char *k;
- X
- X /* skip white */
- X while (isspace(*s))
- X s++;
- X while (*s != terminator)
- X {
- X k = kwdbuf;
- X while (isalnum(*s) || *s == '_')
- X *k++ = *s++;
- X *k = '\0';
- X /* process keyword */
- X if (strcmp(kwdbuf, "secure") == 0)
- X o->secure_port = 1;
- X else if (strcmp(kwdbuf, "insecure") == 0)
- X o->secure_port = 0;
- X else if (strcmp(kwdbuf, "root_squash") == 0)
- X o->root_squash = 1;
- X else if (strcmp(kwdbuf, "no_root_squash") == 0)
- X o->root_squash = 0;
- X else if (strcmp(kwdbuf, "ro") == 0)
- X o->read_only = 1;
- X else if (strcmp(kwdbuf, "rw") == 0)
- X o->read_only = 0;
- X else if (strcmp(kwdbuf, "link_relative") == 0)
- X o->link_relative = 1;
- X else if (strcmp(kwdbuf, "link_absolute") == 0)
- X o->link_relative = 0;
- X else if (strcmp(kwdbuf, "map_daemon") == 0)
- X o->uidmap = map_daemon;
- X else if (strcmp(kwdbuf, "map_identity") == 0)
- X o->uidmap = identity;
- X else
- X Log2("parse_opts Unknown keyword ", kwdbuf);
- X while (isspace(*s))
- X s++;
- X if (*s == terminator)
- X break;
- X if (*s == ',') {
- X s++;
- X } else if (!isalnum(*s) && *s != '_' && *s != '\0') {
- X if (client_name == NULL) {
- X LogN("parse_opts Comma expected in option list for default client but got ", (int) *s);
- X } else {
- X ToLog(DBERROR, "parse_opts Comma expected in option list for client %s but got %c",
- X client_name, *s);
- X }
- X }
- X while (isspace(*s)) {
- X s++;
- X }
- X if (*s == '\0' && *s != terminator) {
- X LogN("parse_opts missing terminator on option list", (int) terminator);
- X return(s);
- X }
- X }
- X if (*s != terminator)
- X LogC("Internal inconsistency in parse, character '%c'.", *s);
- X s++; /* Skip past terminator */
- X while (isspace(*s))
- X s++;
- X return s;
- X}
- X
- Xstatic int
- Xfilt_getc(f)
- XFILE *f;
- X{
- X int c;
- X
- X c = getc(f);
- X if (c == '\\')
- X {
- X c = getc(f);
- X if (c == '\n')
- X return ' ';
- X if (c != EOF)
- X ungetc(c, f);
- X return '\\';
- X }
- X else if (c == '#')
- X {
- X int lastc = c;
- X while ((c = getc(f)) != '\n' && c != EOF)
- X lastc = c;
- X if (c == '\n' && lastc == '\\')
- X c = getc(f);
- X }
- X return c;
- X}
- X
- X#define CHUNK_SIZE 132 /* The 'typical' maximum length line */
- X
- Xstatic int getline(lbuf, f)
- Xchar **lbuf;
- XFILE *f;
- X{
- X int c;
- X char *p;
- X char *buf;
- X int sz;
- X
- X sz = CHUNK_SIZE;
- X buf = malloc(sz);
- X if (buf == NULL) {
- X MallocDeath("getline");
- X }
- X p = buf;
- X while ((c = filt_getc(f)) != '\n' && c != EOF) {
- X if (((int) p - (int) buf) == (sz - 2)) {
- X buf = realloc(buf, sz * 2);
- X if (buf == NULL) {
- X MallocDeath("getline 2");
- X }
- X p = buf + sz-2;
- X sz *= 2;
- X }
- X *p++ = c;
- X }
- X if (c == EOF && p == buf) {
- X free(buf);
- X *lbuf = NULL;
- X return 0;
- X }
- X *p++ = '\0';
- X *lbuf = buf;
- X return 1;
- X}
- X
- Xunfsd_init(argc, argv, envp)
- Xint argc;
- Xchar **argv, **envp;
- X{
- X int i, n;
- X FILE *f;
- X char *lbuf;
- X char *p, *q, *r;
- X char *exportsfile = DEFAULT_EXPORTSFILE;
- X struct hostent *hent;
- X clnt_param *tmp;
- X char *mount_point;
- X
- X /* options */
- X int promiscuous = 0;
- X char *o_string = NULL;
- X options def_opts;
- X
- X
- X /* setup defaults */
- X def_opts.uidmap = identity;
- X def_opts.root_squash = 0;
- X def_opts.secure_port = 1;
- X def_opts.read_only = 1;
- X def_opts.link_relative = 0; /* vac changed default for Alex world */
- X
- X (void) AlexInit();
- X
- X#ifdef NAMECHANGE
- X InitNameChangeVars(argc, argv, envp);
- X#endif
- X
- X argc--; argv++;
- X while (argc > 0)
- X {
- X if ((*argv)[0] == '-')
- X {
- X switch ((*argv)[1])
- X {
- X case 'o':
- X if ((*argv)[2] == '\0' && argc > 1)
- X {
- X argc--; argv++;
- X o_string = *argv;
- X }
- X else
- X o_string = *argv + 2;
- X break;
- X case 'p':
- X promiscuous = 1;
- X break;
- X case 'f':
- X if ((*argv)[2] == '\0' && argc > 1)
- X {
- X argc--; argv++;
- X exportsfile = *argv;
- X }
- X else
- X exportsfile = *argv + 2;
- X break;
- X default:
- X LogC("unfsd_init Unknown option ", (*argv)[1]);
- X }
- X }
- X else
- X Log2("unfsd_init Bad argument ", *argv);
- X argc--; argv++;
- X }
- X
- X fh_init();
- X
- X ft_map[0] = NFNON;
- X for (i = 1; i < 16; i++)
- X ft_map[i] = NFBAD;
- X#ifdef S_IFIFO
- X ft_map[ft_extr(S_IFIFO)] = NFFIFO;
- X#endif
- X ft_map[ft_extr(S_IFCHR)] = NFCHR;
- X ft_map[ft_extr(S_IFDIR)] = NFDIR;
- X ft_map[ft_extr(S_IFBLK)] = NFBLK;
- X ft_map[ft_extr(S_IFREG)] = NFREG;
- X ft_map[ft_extr(S_IFLNK)] = NFLNK;
- X ft_map[ft_extr(S_IFSOCK)] = NFSOCK;
- X
- X /* umask(0); */
- X
- X svc_euid = geteuid();
- X svc_ngids = getgroups(NGROUPS, svc_gids);
- X /* Does this always include gid and egid? I don't know. Play it safe */
- X if (svc_ngids < 0)
- X svc_ngids = 0;
- X n = getgid();
- X for (i = 0; i < svc_ngids; i++)
- X if (svc_gids[i] == n)
- X break;
- X if (i == svc_ngids)
- X svc_gids[svc_ngids++] = n;
- X n = svc_egid = getegid();
- X for (i = 0; i < svc_ngids; i++)
- X if (svc_gids[i] == n)
- X break;
- X if (i == svc_ngids)
- X svc_gids[svc_ngids++] = n;
- X cur_gid = svc_gids[0];
- X if (o_string != NULL)
- X parse_opts(o_string, '\0', &def_opts, NULL);
- X
- X if (!promiscuous && (exportsfile != NULL)) {
- X if ((f = fopen(exportsfile, "r")) == NULL) {
- X Log2("unfsd_init Could not open ", exportsfile);
- X exit(1);
- X }
- X /* process exports file */
- X while (getline(&lbuf, f)) {
- X p = lbuf;
- X while (isspace(*p))
- X p++;
- X q = p;
- X /* file-system name */
- X while (*q != '\0' && !isspace(*q)) {
- X q++;
- X }
- X if ((mount_point = malloc(q-p+1)) == NULL) {
- X MallocDeath("unfsd_init");
- X }
- X for (r = mount_point; p < q;) {
- X *r++ = *p++;
- X }
- X *r = '\0';
- X p = q;
- X while (isspace(*p)) {
- X p++;
- X }
- X while (*p != '\0') {
- X q = p;
- X /* host name */
- X while (*q != '\0' && !isspace(*q) && *q != '(')
- X q++;
- X if ((tmp = (clnt_param *) malloc(sizeof *tmp)) == NULL
- X || (tmp->clnt_name = malloc(q-p+1)) == NULL)
- X MallocDeath("unfsd_init");
- X for (r = tmp->clnt_name; p < q;)
- X *r++ = *p++;
- X *r = '\0';
- X
- X /* Finish parsing options */
- X tmp->o = def_opts;
- X while (isspace(*p))
- X p++;
- X if (*p == '(')
- X p = parse_opts(p+1, ')', &(tmp->o), tmp->clnt_name);
- X
- X tmp->mount_point = mount_point;
- X
- X if ((hent = gethostbyname(tmp->clnt_name)) == NULL)
- X {
- X char *reason;
- X switch (h_errno) {
- X#ifdef HOST_NOT_FOUND /* Only on 4.3 systems */
- X case HOST_NOT_FOUND:
- X reason = "Authoritive -- the host exists only in your imagination.";
- X break;
- X case TRY_AGAIN:
- X reason = "Non-Authoritive -- the host might exist."; break;
- X case NO_RECOVERY:
- X reason = "Non-recoverable error."; break;
- X case NO_ADDRESS:
- X reason = "Valid host name, but no address."; break;
- X#endif
- X default:
- X reason = "Unknown reason.";
- X }
- X Log3("Unknown host in file ", tmp->clnt_name, exportsfile);
- X tmp->next = unknown_clients;
- X unknown_clients = tmp;
- X } else {
- X /* This should be changed to handle the address list under 4.3 */
- X tmp->clnt_addr = *((struct in_addr *)hent->h_addr);
- X tmp->next = clients; /* Add to client list */
- X clients = tmp;
- X }
- X }
- X free(lbuf);
- X }
- X fclose(f);
- X }
- X if (promiscuous) {
- X if ((tmp = (clnt_param *) malloc(sizeof *tmp)) == NULL)
- X MallocDeath("unfsd_init");
- X tmp->clnt_name = NULL;
- X tmp->mount_point = CACHEDIRVAR; /* vac */
- X default_client = tmp;
- X tmp->o = def_opts;
- X }
- X}
- X
- Xint
- X_in_gid_set(gid)
- Xint gid;
- X{
- X int i;
- X
- X for (i = 0; i < svc_ngids; i++)
- X if (svc_gids[i] == gid)
- X {
- X cur_gid = gid;
- X return 1;
- X }
- X return 0;
- X}
- X
- Xclnt_param *knownclient(rqstp)
- Xstruct svc_req *rqstp;
- X{
- X clnt_param **cpp, *cp;
- X int IncomingPort;
- X
- X /* find host parameter struct */
- X for (cpp = &clients; *cpp != NULL; cpp = &((*cpp)->next))
- X {
- X if ((*cpp)->clnt_addr.s_addr == svc_getcaller(rqstp->rq_xprt)->sin_addr.s_addr)
- X {
- X cp = *cpp;
- X if (cp != clients)
- X {
- X /* Move to front */
- X *cpp = cp->next;
- X cp->next = clients;
- X clients = cp;
- X }
- X goto found_it;
- X }
- X }
- X
- X /* Check the list of clients we didn't know at start-up. */
- X {
- X struct hostent *hent;
- X/* clnt_param *tmp; */
- X for (cpp = &unknown_clients; (cp = *cpp) != NULL;
- X cpp = &((*cpp)->next)) {
- X if ((hent = gethostbyname(cp->clnt_name)) != NULL) {
- X ToLog(DBFTP, "clnt_param Found previously unknown host %s\n", cp->clnt_name);
- X /* First remove from the unknown_clients list. */
- X *cpp = cp->next;
- X
- X cp->clnt_addr = *((struct in_addr *)hent->h_addr);
- X cp->next = clients; /* Add to front of client list. */
- X clients = cp;
- X
- X if (cp->clnt_addr.s_addr == svc_getcaller(rqstp->rq_xprt)->sin_addr.s_addr)
- X goto found_it;
- X }
- X }
- X }
- X
- X if (default_client != NULL)
- X cp = default_client;
- X else
- X {
- X LogN("clnt_param Access attempt by unknown client ", /* XXX better as %08X */
- X ntohl(svc_getcaller(rqstp->rq_xprt)->sin_addr.s_addr));
- X return NULL;
- X }
- X found_it:
- X /* check request originated on a privileged port */
- X IncomingPort = ntohs(svc_getcaller(rqstp->rq_xprt)->sin_port);
- X if (IncomingPort >= IPPORT_RESERVED && cp->o.secure_port) {
- X ToLog(DBERROR, "clnt_param ERROR NFS request originated on insecure port %d %d \n",
- X IncomingPort, ntohl(svc_getcaller(rqstp->rq_xprt)->sin_addr.s_addr));
- X
- X return NULL;
- X }
- X return cp;
- X}
- X
- X/*
- X * Local variables:
- X * compile-command: "make"
- X * tab-width: 4
- X * comment-column: 48
- X * c-indent-level: 4
- X * c-continued-statement-offset: 4
- X * c-continued-brace-offset: -4
- X * c-brace-offset: 0
- X * c-brace-imaginary-offset: 0
- X * c-argdecl-indent: 0
- X * c-label-offset: -4
- X * End:
- X */
- END_OF_FILE
- if test 15476 -ne `wc -c <'alexsrvr/src/init.c'`; then
- echo shar: \"'alexsrvr/src/init.c'\" unpacked with wrong size!
- fi
- # end of 'alexsrvr/src/init.c'
- fi
- if test -f 'alexsrvr/src/stringtotime.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'alexsrvr/src/stringtotime.c'\"
- else
- echo shar: Extracting \"'alexsrvr/src/stringtotime.c'\" \(19965 characters\)
- sed "s/^X//" >'alexsrvr/src/stringtotime.c' <<'END_OF_FILE'
- X# define ID 257
- X# define MONTH 258
- X# define DAYOFWEEK 259
- X# define MERIDIAN 260
- X# define NUMBER 261
- X# define ZONE 262
- X# define DAYZONE 263
- X
- X# line 3 "stringtotime.y"
- X
- X/* Vince Cate 11/9/91
- X *
- X * Simplified a bit - no more shift/reduce conflicts.
- X */
- X
- X/* Steven M. Bellovin (unc!smb) */
- X/* Dept. of Computer Science */
- X/* University of North Carolina at Chapel Hill */
- X/* @(#)getdate.y 2.13 9/16/86 */
- X
- X/* defining malloc in one of the following can cause problems if you do
- X * a "make noyacc" because you do not have yacc */
- X#include "alexincs.h"
- X#include "alex.h"
- X
- X#define daysec (24L*60L*60L)
- X
- Xstatic int timeflag, zoneflag, dateflag, yearflag;
- Xstatic int hh, mm, ss, merid, daylightsvs;
- Xstatic int month, day, year;
- Xstatic int ourzone;
- X
- X#define AM 1
- X#define PM 2
- X#define DAYLIGHT 1
- X#define STANDARD 2
- X#define MAYBE 3
- X#define yyclearin yychar = -1
- X#define yyerrok yyerrflag = 0
- Xextern int yychar;
- Xextern short yyerrflag;
- X#ifndef YYMAXDEPTH
- X#define YYMAXDEPTH 150
- X#endif
- X#ifndef YYSTYPE
- X#define YYSTYPE int
- X#endif
- XYYSTYPE yylval, yyval;
- X# define YYERRCODE 256
- X
- X# line 86 "stringtotime.y"
- X
- X
- Xstatic int mdays[12] =
- X {31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- X
- X#define epoch 1970
- X
- Xextern struct tm *localtime();
- Xtime_t dateconv(mm, dd, yy, h, m, s, mer, zone, daylightsvs)
- Xint mm, dd, yy, h, m, s, mer, zone, daylightsvs;
- X{
- X time_t tod, jdate;
- X register int i;
- X time_t timeconv();
- X
- X if (yy < 0) yy = -yy;
- X if (yy < 100) yy += 1900;
- X mdays[1] = 28 + (yy%4 == 0 && (yy%100 != 0 || yy%400 == 0));
- X if (yy < epoch || yy > 1999 || mm < 1 || mm > 12 ||
- X dd < 1 || dd > mdays[--mm]) return (-1);
- X jdate = dd-1;
- X for (i=0; i<mm; i++) jdate += mdays[i];
- X for (i = epoch; i < yy; i++) jdate += 365 + (i%4 == 0);
- X jdate *= daysec;
- X jdate += zone * 60L;
- X if ((tod = timeconv(h, m, s, mer)) < 0) return (-1);
- X jdate += tod;
- X if (daylightsvs==DAYLIGHT ||(daylightsvs==MAYBE&&localtime(&jdate)->tm_isdst))
- X jdate += -1*60*60;
- X return (jdate);
- X}
- X
- X
- Xtime_t timeconv(hh, mm, ss, mer) register int hh, mm, ss, mer;
- X{
- X if (mm < 0 || mm > 59 || ss < 0 || ss > 59) return (-1);
- X switch (mer) {
- X case AM: if (hh < 1 || hh > 12) return(-1);
- X return (60L * ((hh%12)*60L + mm)+ss);
- X case PM: if (hh < 1 || hh > 12) return(-1);
- X return (60L * ((hh%12 +12)*60L + mm)+ss);
- X case 24: if (hh < 0 || hh > 23) return (-1);
- X return (60L * (hh*60L + mm)+ss);
- X default: return (-1);
- X }
- X}
- X
- X
- Xstatic char *lptr;
- X
- Xyylex()
- X{
- X extern int yylval;
- X register char c;
- X register char *p;
- X char idbuf[20];
- X int pcnt;
- X
- X for (;;) {
- X while (isspace(*lptr)) lptr++;
- X
- X if (isdigit(c = *lptr)) {
- X yylval = 0;
- X while (isdigit(c = *lptr++)) yylval = 10*yylval + c - '0';
- X lptr--;
- X return (NUMBER);
- X
- X } else if (isalpha(c)) {
- X p = idbuf;
- X while (isalnum(c = *lptr++) || c=='.' || c=='+' || c=='-') {
- X if (p < &idbuf[sizeof(idbuf)-1]) {
- X *p++ = c;
- X }
- X }
- X *p = '\0';
- X lptr--;
- X return (lookup(idbuf));
- X
- X } else if (c == '(') { /* ignore anything in parens */
- X pcnt = 0;
- X do {
- X c = *lptr++;
- X if (c == '\0') return(c);
- X else if (c == '(') pcnt++;
- X else if (c == ')') pcnt--;
- X } while (pcnt > 0);
- X
- X } else {
- X return (*lptr++);
- X }
- X }
- X}
- X
- Xstruct table {
- X char *name;
- X int type, value;
- X};
- X
- Xstruct table mdtab[] = { /* user can abreviate with just first 3 chars */
- X {"January", MONTH, 1},
- X {"February", MONTH, 2},
- X {"March", MONTH, 3},
- X {"April", MONTH, 4},
- X {"May", MONTH, 5},
- X {"June", MONTH, 6},
- X {"July", MONTH, 7},
- X {"August", MONTH, 8},
- X {"September", MONTH, 9},
- X {"October", MONTH, 10},
- X {"November", MONTH, 11},
- X {"December", MONTH, 12},
- X
- X {"Sunday", DAYOFWEEK, 0},
- X {"Monday", DAYOFWEEK, 1},
- X {"Tuesday", DAYOFWEEK, 2},
- X {"Wednesday", DAYOFWEEK, 3},
- X {"Thursday", DAYOFWEEK, 4},
- X {"Friday", DAYOFWEEK, 5},
- X {"Saturday", DAYOFWEEK, 6},
- X {0, 0, 0}};
- X
- X#define HRS *60
- X#define HALFHR 30
- Xstruct table mztab[] = { /* meridian and zones - always full length */
- X {"a.m.", MERIDIAN, AM},
- X {"am", MERIDIAN, AM},
- X {"p.m.", MERIDIAN, PM},
- X {"pm", MERIDIAN, PM},
- X {"nst", ZONE, 3 HRS + HALFHR}, /* Newfoundland */
- X {"n.s.t.", ZONE, 3 HRS + HALFHR},
- X {"ast", ZONE, 4 HRS}, /* Atlantic */
- X {"a.s.t.", ZONE, 4 HRS},
- X {"adt", DAYZONE, 4 HRS},
- X {"a.d.t.", DAYZONE, 4 HRS},
- X {"est", ZONE, 5 HRS}, /* Eastern */
- X {"e.s.t.", ZONE, 5 HRS},
- X {"edt", DAYZONE, 5 HRS},
- X {"e.d.t.", DAYZONE, 5 HRS},
- X {"cst", ZONE, 6 HRS}, /* Central */
- X {"c.s.t.", ZONE, 6 HRS},
- X {"cdt", DAYZONE, 6 HRS},
- X {"c.d.t.", DAYZONE, 6 HRS},
- X {"mst", ZONE, 7 HRS}, /* Mountain */
- X {"m.s.t.", ZONE, 7 HRS},
- X {"mdt", DAYZONE, 7 HRS},
- X {"m.d.t.", DAYZONE, 7 HRS},
- X {"pst", ZONE, 8 HRS}, /* Pacific */
- X {"p.s.t.", ZONE, 8 HRS},
- X {"pdt", DAYZONE, 8 HRS},
- X {"p.d.t.", DAYZONE, 8 HRS},
- X {"yst", ZONE, 9 HRS}, /* Yukon */
- X {"y.s.t.", ZONE, 9 HRS},
- X {"ydt", DAYZONE, 9 HRS},
- X {"y.d.t.", DAYZONE, 9 HRS},
- X {"hst", ZONE, 10 HRS}, /* Hawaii */
- X {"h.s.t.", ZONE, 10 HRS},
- X {"hdt", DAYZONE, 10 HRS},
- X {"h.d.t.", DAYZONE, 10 HRS},
- X
- X {"gmt", ZONE, 0 HRS},
- X {"gmt+000", ZONE, 0 HRS},
- X {"gmt+100", ZONE, 1 HRS},
- X {"gmt+200", ZONE, 2 HRS},
- X {"gmt+300", ZONE, 3 HRS},
- X {"gmt+400", ZONE, 4 HRS},
- X {"gmt+500", ZONE, 5 HRS},
- X {"gmt+600", ZONE, 6 HRS},
- X {"gmt+700", ZONE, 7 HRS},
- X {"gmt+800", ZONE, 8 HRS},
- X {"gmt+900", ZONE, 9 HRS},
- X {"gmt+1000", ZONE, 10 HRS},
- X {"gmt+1100", ZONE, 11 HRS},
- X {"gmt+1200", ZONE, 12 HRS},
- X {"gmt-100", ZONE, -1 HRS},
- X {"gmt-200", ZONE, -2 HRS},
- X {"gmt-300", ZONE, -3 HRS},
- X {"gmt-400", ZONE, -4 HRS},
- X {"gmt-500", ZONE, -5 HRS},
- X {"gmt-600", ZONE, -6 HRS},
- X {"gmt-700", ZONE, -7 HRS},
- X {"gmt-800", ZONE, -8 HRS},
- X {"gmt-900", ZONE, -9 HRS},
- X {"gmt-1000", ZONE, -10 HRS},
- X {"gmt-1100", ZONE, -11 HRS},
- X {"g.m.t.", ZONE, 0 HRS},
- X {"bst", DAYZONE, 0 HRS}, /* British Summer Time */
- X {"b.s.t.", DAYZONE, 0 HRS},
- X {"eet", ZONE, 0 HRS}, /* European Eastern Time */
- X {"e.e.t.", ZONE, 0 HRS},
- X {"eest", DAYZONE, 0 HRS}, /* European Eastern Summer Time */
- X {"e.e.s.t.", DAYZONE, 0 HRS},
- X {"met", ZONE, -1 HRS}, /* Middle European Time */
- X {"m.e.t.", ZONE, -1 HRS},
- X {"mest", DAYZONE, -1 HRS}, /* Middle European Summer Time */
- X {"m.e.s.t.", DAYZONE, -1 HRS},
- X {"wet", ZONE, -2 HRS }, /* Western European Time */
- X {"w.e.t.", ZONE, -2 HRS },
- X {"west", DAYZONE, -2 HRS}, /* Western European Summer Time */
- X {"w.e.s.t.", DAYZONE, -2 HRS},
- X
- X {"jst", ZONE, -9 HRS}, /* Japan Standard Time */
- X {"j.s.t.", ZONE, -9 HRS}, /* Japan Standard Time */
- X /* No daylight savings time */
- X
- X {"aest", ZONE, -10 HRS}, /* Australian Eastern Time */
- X {"a.e.s.t.", ZONE, -10 HRS},
- X {"aesst", DAYZONE, -10 HRS}, /* Australian Eastern Summer Time */
- X {"a.e.s.s.t.", DAYZONE, -10 HRS},
- X {"acst", ZONE, -(9 HRS + HALFHR)}, /* Australian Central Time */
- X {"a.c.s.t.", ZONE, -(9 HRS + HALFHR)},
- X {"acsst", DAYZONE, -(9 HRS + HALFHR)}, /* Australian Central Summer */
- X {"a.c.s.s.t.", DAYZONE, -(9 HRS + HALFHR)},
- X {"awst", ZONE, -8 HRS}, /* Australian Western Time */
- X {"a.w.s.t.", ZONE, -8 HRS}, /* (no daylight time there, I'm told */
- X {0, 0, 0}};
- X
- Xstruct table milzone[] = {
- X {"a", ZONE, 1 HRS},
- X {"b", ZONE, 2 HRS},
- X {"c", ZONE, 3 HRS},
- X {"d", ZONE, 4 HRS},
- X {"e", ZONE, 5 HRS},
- X {"f", ZONE, 6 HRS},
- X {"g", ZONE, 7 HRS},
- X {"h", ZONE, 8 HRS},
- X {"i", ZONE, 9 HRS},
- X {"k", ZONE, 10 HRS},
- X {"l", ZONE, 11 HRS},
- X {"m", ZONE, 12 HRS},
- X {"n", ZONE, -1 HRS},
- X {"o", ZONE, -2 HRS},
- X {"p", ZONE, -3 HRS},
- X {"q", ZONE, -4 HRS},
- X {"r", ZONE, -5 HRS},
- X {"s", ZONE, -6 HRS},
- X {"t", ZONE, -7 HRS},
- X {"u", ZONE, -8 HRS},
- X {"v", ZONE, -9 HRS},
- X {"w", ZONE, -10 HRS},
- X {"x", ZONE, -11 HRS},
- X {"y", ZONE, -12 HRS},
- X {"z", ZONE, 0 HRS},
- X {0, 0, 0}};
- X
- Xlookup(id)
- Xchar *id;
- X{
- X#define gotit (yylval=i->value, i->type)
- X#define getid for(j=idvar, k=id; *j++ = *k++; ) /* fresh copy */
- X
- X char idvar[20];
- X register char *j, *k;
- X register struct table *i;
- X
- X getid;
- X for (i = mdtab; i->name; i++) {
- X if (strncasecmp(idvar, i->name, 3) == 0) {
- X return gotit;
- X }
- X }
- X
- X getid;
- X for (i = mztab; i->name; i++)
- X if (strcmp(i->name, idvar) == 0) return gotit;
- X
- X for (j = idvar; *j; j++)
- X if (isupper(*j)) *j = tolower(*j);
- X for (i=mztab; i->name; i++)
- X if (strcmp(i->name, idvar) == 0) return gotit;
- X
- X getid;
- X if (strlen(idvar) == 1 && isalpha(*idvar)) {
- X if (isupper(*idvar)) *idvar = tolower(*idvar);
- X for (i = milzone; i->name; i++) {
- X if (strcmp(i->name, idvar) == 0) return gotit;
- X }
- X }
- X
- X return(ID);
- X}
- X
- X#define mcheck(f) if (f>1) err++
- X
- Xint StringToTimeb(p, Now, Result)
- Xchar *p;
- Xstruct timeb *Now, *Result;
- X{
- X int err;
- X struct tm *lt;
- X struct timeb ftz;
- X time_t sdate;
- X
- X lptr = p;
- X if (Now == ((struct timeb *) NULL)) {
- X Now = &ftz;
- X ftime(&ftz);
- X }
- X lt = localtime(&Now->time);
- X year = lt->tm_year;
- X month = lt->tm_mon+1;
- X day = lt->tm_mday;
- X timeflag=zoneflag=dateflag=yearflag=0;
- X ourzone = Now->timezone;
- X daylightsvs = MAYBE;
- X hh = mm = ss = 0;
- X merid = 24;
- X
- X err=yyparse();
- X if (err) {
- X Log2("StringToTimeb could not parse date ", p);
- X return(AFAIL);
- X }
- X
- X mcheck(timeflag); /* each of these should be at most 1 */
- X mcheck(zoneflag);
- X mcheck(dateflag);
- X mcheck(yearflag);
- X
- X if (err) {
- X Log2("StringToTimeb ERROR parsed some type of field twice", p);
- X return(AFAIL);
- X }
- X if (!dateflag && !timeflag) {
- X Log2("StringToTimeb ERROR did not find a major item in string ", p);
- X return(AFAIL);
- X }
- X
- X sdate = dateconv(month,day,year,hh,mm,ss,merid,ourzone,daylightsvs);
- X if (sdate < 0) {
- X Log2("StringToTimeb ERROR from dateconv", p);
- X return(AFAIL);
- X }
- X
- X/* This is for times of files, so if there is no year we assume it could
- X * be up to a day ahead but otherwise in the past if no year specified.
- X */
- X if (!yearflag && (sdate > (Now->time + ADAY))) {
- X Log2("StringToTimeb backing up a year since file dates must be in past", p);
- X year--;
- X sdate = dateconv(month,day,year,hh,mm,ss,merid,ourzone,daylightsvs);
- X if (sdate < 0) {
- X Log2("StringToTimeb ERROR from dateconv after backing up a year", p);
- X return(AFAIL);
- X }
- X }
- X
- X
- X Result->time=sdate;
- X Result->millitm=0;
- X Result->timezone=ourzone;
- X Result->dstflag=daylightsvs;
- X
- X Log("StringToTimeb returning AOK");
- X return(AOK);
- X}
- X
- Xyyerror(s)
- Xchar *s;
- X{
- X Log2("yyerror", s);
- X}
- X
- Xshort yyexca[] ={
- X-1, 1,
- X 0, -1,
- X -2, 0,
- X };
- X# define YYNPROD 22
- X# define YYLAST 212
- Xshort yyact[]={
- X
- X 12, 8, 34, 11, 9, 10, 33, 32, 31, 28,
- X 24, 23, 22, 35, 25, 21, 29, 20, 30, 26,
- X 7, 6, 5, 4, 3, 2, 1, 0, 19, 13,
- X 14, 15, 16, 17, 18, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- X 0, 27 };
- Xshort yypact[]={
- X
- X-258,-1000,-258,-258,-258,-258,-258,-258,-1000,-1000,
- X-1000, -30,-249,-1000,-1000,-1000,-1000,-1000,-1000,-250,
- X-251,-244, -25, -49, -31, -27,-253,-1000,-254,-255,
- X-259,-1000,-247,-1000,-1000,-1000 };
- Xshort yypgo[]={
- X
- X 0, 26, 25, 24, 23, 22, 21, 20 };
- Xshort yyr1[]={
- X
- X 0, 1, 1, 1, 1, 1, 1, 1, 2, 7,
- X 4, 4, 4, 4, 3, 3, 5, 5, 5, 6,
- X 6, 6 };
- Xshort yyr2[]={
- X
- X 0, 0, 2, 2, 2, 2, 2, 2, 1, 1,
- X 3, 4, 5, 6, 1, 1, 3, 2, 3, 5,
- X 4, 5 };
- Xshort yychk[]={
- X
- X-1000, -1, -2, -3, -4, -5, -6, -7, 259, 262,
- X 263, 261, 258, -1, -1, -1, -1, -1, -1, 58,
- X 47, 45, 261, 261, 261, 258, 44, 260, 58, 47,
- X 45, 261, 261, 261, 261, 260 };
- Xshort yydef[]={
- X
- X 1, -2, 1, 1, 1, 1, 1, 1, 8, 14,
- X 15, 9, 0, 2, 3, 4, 5, 6, 7, 0,
- X 0, 0, 17, 10, 16, 18, 0, 11, 0, 0,
- X 0, 20, 12, 19, 21, 13 };
- X/*
- X **********************************************************************
- X * HISTORY
- X * $Log: yaccpar,v $
- X * Revision 2.2 89/05/30 11:38:04 gm0w
- X * Removed unknown preprocessor directive "#".
- X * [89/05/30 gm0w]
- X *
- X **********************************************************************
- X */
- X#ifndef lint
- Xstatic char yaccpar_sccsid[] = "@(#)yaccpar 4.1 (Berkeley) 2/11/83";
- X#endif not lint
- X
- X# define YYFLAG -1000
- X# define YYERROR goto yyerrlab
- X# define YYACCEPT return(0)
- X# define YYABORT return(1)
- X
- X/* parser for yacc output */
- X
- X#ifdef YYDEBUG
- Xint yydebug = 0; /* 1 for debugging */
- X#endif
- XYYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
- Xint yychar = -1; /* current input token number */
- Xint yynerrs = 0; /* number of errors */
- Xshort yyerrflag = 0; /* error recovery flag */
- X
- Xyyparse() {
- X
- X short yys[YYMAXDEPTH];
- X short yyj, yym;
- X register YYSTYPE *yypvt;
- X register short yystate, *yyps, yyn;
- X register YYSTYPE *yypv;
- X register short *yyxi;
- X
- X yystate = 0;
- X yychar = -1;
- X yynerrs = 0;
- X yyerrflag = 0;
- X yyps= &yys[-1];
- X yypv= &yyv[-1];
- X
- X yystack: /* put a state and value onto the stack */
- X
- X#ifdef YYDEBUG
- X if( yydebug ) printf( "state %d, char 0%o\n", yystate, yychar );
- X#endif
- X if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
- X *yyps = yystate;
- X ++yypv;
- X *yypv = yyval;
- X
- X yynewstate:
- X
- X yyn = yypact[yystate];
- X
- X if( yyn<= YYFLAG ) goto yydefault; /* simple state */
- X
- X if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
- X if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
- X
- X if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
- X yychar = -1;
- X yyval = yylval;
- X yystate = yyn;
- X if( yyerrflag > 0 ) --yyerrflag;
- X goto yystack;
- X }
- X
- X yydefault:
- X /* default state action */
- X
- X if( (yyn=yydef[yystate]) == -2 ) {
- X if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
- X /* look through exception table */
- X
- X for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
- X
- X while( *(yyxi+=2) >= 0 ){
- X if( *yyxi == yychar ) break;
- X }
- X if( (yyn = yyxi[1]) < 0 ) return(0); /* accept */
- X }
- X
- X if( yyn == 0 ){ /* error */
- X /* error ... attempt to resume parsing */
- X
- X switch( yyerrflag ){
- X
- X case 0: /* brand new error */
- X
- X yyerror( "syntax error" );
- X yyerrlab:
- X ++yynerrs;
- X
- X case 1:
- X case 2: /* incompletely recovered error ... try again */
- X
- X yyerrflag = 3;
- X
- X /* find a state where "error" is a legal shift action */
- X
- X while ( yyps >= yys ) {
- X yyn = yypact[*yyps] + YYERRCODE;
- X if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
- X yystate = yyact[yyn]; /* simulate a shift of "error" */
- X goto yystack;
- X }
- X yyn = yypact[*yyps];
- X
- X /* the current yyps has no shift onn "error", pop stack */
- X
- X#ifdef YYDEBUG
- X if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
- X#endif
- X --yyps;
- X --yypv;
- X }
- X
- X /* there is no state on the stack with an error shift ... abort */
- X
- X yyabort:
- X return(1);
- X
- X
- X case 3: /* no shift yet; clobber input char */
- X
- X#ifdef YYDEBUG
- X if( yydebug ) printf( "error recovery discards char %d\n", yychar );
- X#endif
- X
- X if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
- X yychar = -1;
- X goto yynewstate; /* try again in the same state */
- X
- X }
- X
- X }
- X
- X /* reduction by production yyn */
- X
- X#ifdef YYDEBUG
- X if( yydebug ) printf("reduce %d\n",yyn);
- X#endif
- X yyps -= yyr2[yyn];
- X yypvt = yypv;
- X yypv -= yyr2[yyn];
- X yyval = yypv[1];
- X yym=yyn;
- X /* consult goto table to find next state */
- X yyn = yyr1[yyn];
- X yyj = yypgo[yyn] + *yyps + 1;
- X if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
- X switch(yym){
- X
- Xcase 2:
- X# line 36 "stringtotime.y"
- X
- X {;} break;
- Xcase 3:
- X# line 38 "stringtotime.y"
- X
- X {zoneflag++;} break;
- Xcase 4:
- X# line 40 "stringtotime.y"
- X
- X {timeflag++;} break;
- Xcase 5:
- X# line 42 "stringtotime.y"
- X
- X {dateflag++;} break;
- Xcase 6:
- X# line 44 "stringtotime.y"
- X
- X {dateflag++; yearflag++;} break;
- Xcase 7:
- X# line 46 "stringtotime.y"
- X
- X {yearflag++;} break;
- Xcase 8:
- X# line 49 "stringtotime.y"
- X
- X {;} break;
- Xcase 9:
- X# line 53 "stringtotime.y"
- X
- X {year = yypvt[-0]; } break;
- Xcase 10:
- X# line 56 "stringtotime.y"
- X
- X {hh = yypvt[-2]; mm = yypvt[-0]; ss=0; merid = 24;} break;
- Xcase 11:
- X# line 58 "stringtotime.y"
- X
- X {hh = yypvt[-3]; mm = yypvt[-1]; ss=0; merid = yypvt[-0];} break;
- Xcase 12:
- X# line 60 "stringtotime.y"
- X
- X {hh = yypvt[-4]; mm = yypvt[-2]; ss = yypvt[-0]; merid = 24;} break;
- Xcase 13:
- X# line 62 "stringtotime.y"
- X
- X {hh = yypvt[-5]; mm = yypvt[-3]; ss = yypvt[-1]; merid = yypvt[-0];} break;
- Xcase 14:
- X# line 66 "stringtotime.y"
- X
- X {ourzone = yypvt[-0]; daylightsvs = STANDARD;} break;
- Xcase 15:
- X# line 68 "stringtotime.y"
- X
- X {ourzone = yypvt[-0]; daylightsvs = DAYLIGHT;} break;
- Xcase 16:
- X# line 71 "stringtotime.y"
- X
- X {month = yypvt[-2]; day = yypvt[-0];} break;
- Xcase 17:
- X# line 73 "stringtotime.y"
- X
- X {month = yypvt[-1]; day = yypvt[-0];} break;
- Xcase 18:
- X# line 75 "stringtotime.y"
- X
- X {month = yypvt[-0]; day = yypvt[-2];} break;
- Xcase 19:
- X# line 78 "stringtotime.y"
- X
- X {month = yypvt[-4]; day = yypvt[-2]; year = yypvt[-0]; } break;
- Xcase 20:
- X# line 80 "stringtotime.y"
- X
- X {month = yypvt[-3]; day = yypvt[-2]; year = yypvt[-0]; } break;
- Xcase 21:
- X# line 82 "stringtotime.y"
- X
- X {month = yypvt[-2]; day = yypvt[-4]; year = yypvt[-0]; } break;
- X }
- X goto yystack; /* stack new state and value */
- X
- X }
- END_OF_FILE
- if test 19965 -ne `wc -c <'alexsrvr/src/stringtotime.c'`; then
- echo shar: \"'alexsrvr/src/stringtotime.c'\" unpacked with wrong size!
- fi
- # end of 'alexsrvr/src/stringtotime.c'
- fi
- if test -f 'alexsrvr/src/stringtotime.y' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'alexsrvr/src/stringtotime.y'\"
- else
- echo shar: Extracting \"'alexsrvr/src/stringtotime.y'\" \(13406 characters\)
- sed "s/^X//" >'alexsrvr/src/stringtotime.y' <<'END_OF_FILE'
- X%token ID MONTH DAYOFWEEK MERIDIAN NUMBER ZONE DAYZONE
- X%{
- X
- X/* Vince Cate 11/9/91
- X *
- X * Simplified a bit - no more shift/reduce conflicts.
- X */
- X
- X/* Steven M. Bellovin (unc!smb) */
- X/* Dept. of Computer Science */
- X/* University of North Carolina at Chapel Hill */
- X/* @(#)getdate.y 2.13 9/16/86 */
- X
- X/* defining malloc in one of the following can cause problems if you do
- X * a "make noyacc" because you do not have yacc */
- X#include "alexincs.h"
- X#include "alex.h"
- X
- X#define daysec (24L*60L*60L)
- X
- Xstatic int timeflag, zoneflag, dateflag, yearflag;
- Xstatic int hh, mm, ss, merid, daylightsvs;
- Xstatic int month, day, year;
- Xstatic int ourzone;
- X
- X#define AM 1
- X#define PM 2
- X#define DAYLIGHT 1
- X#define STANDARD 2
- X#define MAYBE 3
- X%}
- X
- X%%
- X
- Xvalidstring: /* empty */
- X | dayofweek validstring =
- X {;}
- X | zonespec validstring =
- X {zoneflag++;}
- X | timespec validstring =
- X {timeflag++;}
- X | datespec validstring =
- X {dateflag++;}
- X | dateyearspec validstring =
- X {dateflag++; yearflag++;}
- X | yearspec validstring =
- X {yearflag++;};
- X
- Xdayofweek: DAYOFWEEK =
- X {;};
- X
- X
- Xyearspec: NUMBER =
- X {year = $1; };
- X
- Xtimespec: NUMBER ':' NUMBER =
- X {hh = $1; mm = $3; ss=0; merid = 24;}
- X | NUMBER ':' NUMBER MERIDIAN =
- X {hh = $1; mm = $3; ss=0; merid = $4;}
- X | NUMBER ':' NUMBER ':' NUMBER =
- X {hh = $1; mm = $3; ss = $5; merid = 24;}
- X | NUMBER ':' NUMBER ':' NUMBER MERIDIAN =
- X {hh = $1; mm = $3; ss = $5; merid = $6;};
- X
- X/* note that zone flag means that both ourzone and daylightsvs are set */
- Xzonespec: ZONE =
- X {ourzone = $1; daylightsvs = STANDARD;}
- X | DAYZONE =
- X {ourzone = $1; daylightsvs = DAYLIGHT;};
- X
- Xdatespec: NUMBER '/' NUMBER =
- X {month = $1; day = $3;}
- X | MONTH NUMBER =
- X {month = $1; day = $2;}
- X | NUMBER '-' MONTH =
- X {month = $3; day = $1;};
- X
- Xdateyearspec: NUMBER '/' NUMBER '/' NUMBER =
- X {month = $1; day = $3; year = $5; }
- X | MONTH NUMBER ',' NUMBER =
- X {month = $1; day = $2; year = $4; }
- X | NUMBER '-' MONTH '-' NUMBER =
- X {month = $3; day = $1; year = $5; };
- X
- X
- X%%
- X
- Xstatic int mdays[12] =
- X {31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- X
- X#define epoch 1970
- X
- Xextern struct tm *localtime();
- Xtime_t dateconv(mm, dd, yy, h, m, s, mer, zone, daylightsvs)
- Xint mm, dd, yy, h, m, s, mer, zone, daylightsvs;
- X{
- X time_t tod, jdate;
- X register int i;
- X time_t timeconv();
- X
- X if (yy < 0) yy = -yy;
- X if (yy < 100) yy += 1900;
- X mdays[1] = 28 + (yy%4 == 0 && (yy%100 != 0 || yy%400 == 0));
- X if (yy < epoch || yy > 1999 || mm < 1 || mm > 12 ||
- X dd < 1 || dd > mdays[--mm]) return (-1);
- X jdate = dd-1;
- X for (i=0; i<mm; i++) jdate += mdays[i];
- X for (i = epoch; i < yy; i++) jdate += 365 + (i%4 == 0);
- X jdate *= daysec;
- X jdate += zone * 60L;
- X if ((tod = timeconv(h, m, s, mer)) < 0) return (-1);
- X jdate += tod;
- X if (daylightsvs==DAYLIGHT ||(daylightsvs==MAYBE&&localtime(&jdate)->tm_isdst))
- X jdate += -1*60*60;
- X return (jdate);
- X}
- X
- X
- Xtime_t timeconv(hh, mm, ss, mer) register int hh, mm, ss, mer;
- X{
- X if (mm < 0 || mm > 59 || ss < 0 || ss > 59) return (-1);
- X switch (mer) {
- X case AM: if (hh < 1 || hh > 12) return(-1);
- X return (60L * ((hh%12)*60L + mm)+ss);
- X case PM: if (hh < 1 || hh > 12) return(-1);
- X return (60L * ((hh%12 +12)*60L + mm)+ss);
- X case 24: if (hh < 0 || hh > 23) return (-1);
- X return (60L * (hh*60L + mm)+ss);
- X default: return (-1);
- X }
- X}
- X
- X
- Xstatic char *lptr;
- X
- Xyylex()
- X{
- X extern int yylval;
- X register char c;
- X register char *p;
- X char idbuf[20];
- X int pcnt;
- X
- X for (;;) {
- X while (isspace(*lptr)) lptr++;
- X
- X if (isdigit(c = *lptr)) {
- X yylval = 0;
- X while (isdigit(c = *lptr++)) yylval = 10*yylval + c - '0';
- X lptr--;
- X return (NUMBER);
- X
- X } else if (isalpha(c)) {
- X p = idbuf;
- X while (isalnum(c = *lptr++) || c=='.' || c=='+' || c=='-') {
- X if (p < &idbuf[sizeof(idbuf)-1]) {
- X *p++ = c;
- X }
- X }
- X *p = '\0';
- X lptr--;
- X return (lookup(idbuf));
- X
- X } else if (c == '(') { /* ignore anything in parens */
- X pcnt = 0;
- X do {
- X c = *lptr++;
- X if (c == '\0') return(c);
- X else if (c == '(') pcnt++;
- X else if (c == ')') pcnt--;
- X } while (pcnt > 0);
- X
- X } else {
- X return (*lptr++);
- X }
- X }
- X}
- X
- Xstruct table {
- X char *name;
- X int type, value;
- X};
- X
- Xstruct table mdtab[] = { /* user can abreviate with just first 3 chars */
- X {"January", MONTH, 1},
- X {"February", MONTH, 2},
- X {"March", MONTH, 3},
- X {"April", MONTH, 4},
- X {"May", MONTH, 5},
- X {"June", MONTH, 6},
- X {"July", MONTH, 7},
- X {"August", MONTH, 8},
- X {"September", MONTH, 9},
- X {"October", MONTH, 10},
- X {"November", MONTH, 11},
- X {"December", MONTH, 12},
- X
- X {"Sunday", DAYOFWEEK, 0},
- X {"Monday", DAYOFWEEK, 1},
- X {"Tuesday", DAYOFWEEK, 2},
- X {"Wednesday", DAYOFWEEK, 3},
- X {"Thursday", DAYOFWEEK, 4},
- X {"Friday", DAYOFWEEK, 5},
- X {"Saturday", DAYOFWEEK, 6},
- X {0, 0, 0}};
- X
- X#define HRS *60
- X#define HALFHR 30
- Xstruct table mztab[] = { /* meridian and zones - always full length */
- X {"a.m.", MERIDIAN, AM},
- X {"am", MERIDIAN, AM},
- X {"p.m.", MERIDIAN, PM},
- X {"pm", MERIDIAN, PM},
- X {"nst", ZONE, 3 HRS + HALFHR}, /* Newfoundland */
- X {"n.s.t.", ZONE, 3 HRS + HALFHR},
- X {"ast", ZONE, 4 HRS}, /* Atlantic */
- X {"a.s.t.", ZONE, 4 HRS},
- X {"adt", DAYZONE, 4 HRS},
- X {"a.d.t.", DAYZONE, 4 HRS},
- X {"est", ZONE, 5 HRS}, /* Eastern */
- X {"e.s.t.", ZONE, 5 HRS},
- X {"edt", DAYZONE, 5 HRS},
- X {"e.d.t.", DAYZONE, 5 HRS},
- X {"cst", ZONE, 6 HRS}, /* Central */
- X {"c.s.t.", ZONE, 6 HRS},
- X {"cdt", DAYZONE, 6 HRS},
- X {"c.d.t.", DAYZONE, 6 HRS},
- X {"mst", ZONE, 7 HRS}, /* Mountain */
- X {"m.s.t.", ZONE, 7 HRS},
- X {"mdt", DAYZONE, 7 HRS},
- X {"m.d.t.", DAYZONE, 7 HRS},
- X {"pst", ZONE, 8 HRS}, /* Pacific */
- X {"p.s.t.", ZONE, 8 HRS},
- X {"pdt", DAYZONE, 8 HRS},
- X {"p.d.t.", DAYZONE, 8 HRS},
- X {"yst", ZONE, 9 HRS}, /* Yukon */
- X {"y.s.t.", ZONE, 9 HRS},
- X {"ydt", DAYZONE, 9 HRS},
- X {"y.d.t.", DAYZONE, 9 HRS},
- X {"hst", ZONE, 10 HRS}, /* Hawaii */
- X {"h.s.t.", ZONE, 10 HRS},
- X {"hdt", DAYZONE, 10 HRS},
- X {"h.d.t.", DAYZONE, 10 HRS},
- X
- X {"gmt", ZONE, 0 HRS},
- X {"gmt+000", ZONE, 0 HRS},
- X {"gmt+100", ZONE, 1 HRS},
- X {"gmt+200", ZONE, 2 HRS},
- X {"gmt+300", ZONE, 3 HRS},
- X {"gmt+400", ZONE, 4 HRS},
- X {"gmt+500", ZONE, 5 HRS},
- X {"gmt+600", ZONE, 6 HRS},
- X {"gmt+700", ZONE, 7 HRS},
- X {"gmt+800", ZONE, 8 HRS},
- X {"gmt+900", ZONE, 9 HRS},
- X {"gmt+1000", ZONE, 10 HRS},
- X {"gmt+1100", ZONE, 11 HRS},
- X {"gmt+1200", ZONE, 12 HRS},
- X {"gmt-100", ZONE, -1 HRS},
- X {"gmt-200", ZONE, -2 HRS},
- X {"gmt-300", ZONE, -3 HRS},
- X {"gmt-400", ZONE, -4 HRS},
- X {"gmt-500", ZONE, -5 HRS},
- X {"gmt-600", ZONE, -6 HRS},
- X {"gmt-700", ZONE, -7 HRS},
- X {"gmt-800", ZONE, -8 HRS},
- X {"gmt-900", ZONE, -9 HRS},
- X {"gmt-1000", ZONE, -10 HRS},
- X {"gmt-1100", ZONE, -11 HRS},
- X {"g.m.t.", ZONE, 0 HRS},
- X {"bst", DAYZONE, 0 HRS}, /* British Summer Time */
- X {"b.s.t.", DAYZONE, 0 HRS},
- X {"eet", ZONE, 0 HRS}, /* European Eastern Time */
- X {"e.e.t.", ZONE, 0 HRS},
- X {"eest", DAYZONE, 0 HRS}, /* European Eastern Summer Time */
- X {"e.e.s.t.", DAYZONE, 0 HRS},
- X {"met", ZONE, -1 HRS}, /* Middle European Time */
- X {"m.e.t.", ZONE, -1 HRS},
- X {"mest", DAYZONE, -1 HRS}, /* Middle European Summer Time */
- X {"m.e.s.t.", DAYZONE, -1 HRS},
- X {"wet", ZONE, -2 HRS }, /* Western European Time */
- X {"w.e.t.", ZONE, -2 HRS },
- X {"west", DAYZONE, -2 HRS}, /* Western European Summer Time */
- X {"w.e.s.t.", DAYZONE, -2 HRS},
- X
- X {"jst", ZONE, -9 HRS}, /* Japan Standard Time */
- X {"j.s.t.", ZONE, -9 HRS}, /* Japan Standard Time */
- X /* No daylight savings time */
- X
- X {"aest", ZONE, -10 HRS}, /* Australian Eastern Time */
- X {"a.e.s.t.", ZONE, -10 HRS},
- X {"aesst", DAYZONE, -10 HRS}, /* Australian Eastern Summer Time */
- X {"a.e.s.s.t.", DAYZONE, -10 HRS},
- X {"acst", ZONE, -(9 HRS + HALFHR)}, /* Australian Central Time */
- X {"a.c.s.t.", ZONE, -(9 HRS + HALFHR)},
- X {"acsst", DAYZONE, -(9 HRS + HALFHR)}, /* Australian Central Summer */
- X {"a.c.s.s.t.", DAYZONE, -(9 HRS + HALFHR)},
- X {"awst", ZONE, -8 HRS}, /* Australian Western Time */
- X {"a.w.s.t.", ZONE, -8 HRS}, /* (no daylight time there, I'm told */
- X {0, 0, 0}};
- X
- Xstruct table milzone[] = {
- X {"a", ZONE, 1 HRS},
- X {"b", ZONE, 2 HRS},
- X {"c", ZONE, 3 HRS},
- X {"d", ZONE, 4 HRS},
- X {"e", ZONE, 5 HRS},
- X {"f", ZONE, 6 HRS},
- X {"g", ZONE, 7 HRS},
- X {"h", ZONE, 8 HRS},
- X {"i", ZONE, 9 HRS},
- X {"k", ZONE, 10 HRS},
- X {"l", ZONE, 11 HRS},
- X {"m", ZONE, 12 HRS},
- X {"n", ZONE, -1 HRS},
- X {"o", ZONE, -2 HRS},
- X {"p", ZONE, -3 HRS},
- X {"q", ZONE, -4 HRS},
- X {"r", ZONE, -5 HRS},
- X {"s", ZONE, -6 HRS},
- X {"t", ZONE, -7 HRS},
- X {"u", ZONE, -8 HRS},
- X {"v", ZONE, -9 HRS},
- X {"w", ZONE, -10 HRS},
- X {"x", ZONE, -11 HRS},
- X {"y", ZONE, -12 HRS},
- X {"z", ZONE, 0 HRS},
- X {0, 0, 0}};
- X
- Xlookup(id)
- Xchar *id;
- X{
- X#define gotit (yylval=i->value, i->type)
- X#define getid for(j=idvar, k=id; *j++ = *k++; ) /* fresh copy */
- X
- X char idvar[20];
- X register char *j, *k;
- X register struct table *i;
- X
- X getid;
- X for (i = mdtab; i->name; i++) {
- X if (strncasecmp(idvar, i->name, 3) == 0) {
- X return gotit;
- X }
- X }
- X
- X getid;
- X for (i = mztab; i->name; i++)
- X if (strcmp(i->name, idvar) == 0) return gotit;
- X
- X for (j = idvar; *j; j++)
- X if (isupper(*j)) *j = tolower(*j);
- X for (i=mztab; i->name; i++)
- X if (strcmp(i->name, idvar) == 0) return gotit;
- X
- X getid;
- X if (strlen(idvar) == 1 && isalpha(*idvar)) {
- X if (isupper(*idvar)) *idvar = tolower(*idvar);
- X for (i = milzone; i->name; i++) {
- X if (strcmp(i->name, idvar) == 0) return gotit;
- X }
- X }
- X
- X return(ID);
- X}
- X
- X#define mcheck(f) if (f>1) err++
- X
- Xint StringToTimeb(p, Now, Result)
- Xchar *p;
- Xstruct timeb *Now, *Result;
- X{
- X int err;
- X struct tm *lt;
- X struct timeb ftz;
- X time_t sdate;
- X
- X lptr = p;
- X if (Now == ((struct timeb *) NULL)) {
- X Now = &ftz;
- X ftime(&ftz);
- X }
- X lt = localtime(&Now->time);
- X year = lt->tm_year;
- X month = lt->tm_mon+1;
- X day = lt->tm_mday;
- X timeflag=zoneflag=dateflag=yearflag=0;
- X ourzone = Now->timezone;
- X daylightsvs = MAYBE;
- X hh = mm = ss = 0;
- X merid = 24;
- X
- X err=yyparse();
- X if (err) {
- X Log2("StringToTimeb could not parse date ", p);
- X return(AFAIL);
- X }
- X
- X mcheck(timeflag); /* each of these should be at most 1 */
- X mcheck(zoneflag);
- X mcheck(dateflag);
- X mcheck(yearflag);
- X
- X if (err) {
- X Log2("StringToTimeb ERROR parsed some type of field twice", p);
- X return(AFAIL);
- X }
- X if (!dateflag && !timeflag) {
- X Log2("StringToTimeb ERROR did not find a major item in string ", p);
- X return(AFAIL);
- X }
- X
- X sdate = dateconv(month,day,year,hh,mm,ss,merid,ourzone,daylightsvs);
- X if (sdate < 0) {
- X Log2("StringToTimeb ERROR from dateconv", p);
- X return(AFAIL);
- X }
- X
- X/* This is for times of files, so if there is no year we assume it could
- X * be up to a day ahead but otherwise in the past if no year specified.
- X */
- X if (!yearflag && (sdate > (Now->time + ADAY))) {
- X Log2("StringToTimeb backing up a year since file dates must be in past", p);
- X year--;
- X sdate = dateconv(month,day,year,hh,mm,ss,merid,ourzone,daylightsvs);
- X if (sdate < 0) {
- X Log2("StringToTimeb ERROR from dateconv after backing up a year", p);
- X return(AFAIL);
- X }
- X }
- X
- X
- X Result->time=sdate;
- X Result->millitm=0;
- X Result->timezone=ourzone;
- X Result->dstflag=daylightsvs;
- X
- X Log("StringToTimeb returning AOK");
- X return(AOK);
- X}
- X
- Xyyerror(s)
- Xchar *s;
- X{
- X Log2("yyerror", s);
- X}
- X
- END_OF_FILE
- if test 13406 -ne `wc -c <'alexsrvr/src/stringtotime.y'`; then
- echo shar: \"'alexsrvr/src/stringtotime.y'\" unpacked with wrong size!
- fi
- # end of 'alexsrvr/src/stringtotime.y'
- fi
- echo shar: End of archive 10 \(of 13\).
- cp /dev/null ark10isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 13 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
-