|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T r
Length: 3810 (0xee2) Types: TextFile Names: »rfc2UTC.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0 └─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z« └─⟦e5a54fb17⟧ └─⟦this⟧ »pp-5.0/Lib/format/rfc2UTC.c«
/* rfc2UTC.c - Converts an RFC string into UTC structure */ # ifndef lint static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Lib/format/RCS/rfc2UTC.c,v 5.0 90/09/20 16:05:16 pp Exp Locker: pp $"; # endif /* * $Header: /cs/research/pp/hubris/pp-beta/Lib/format/RCS/rfc2UTC.c,v 5.0 90/09/20 16:05:16 pp Exp Locker: pp $ * * $Log: rfc2UTC.c,v $ * Revision 5.0 90/09/20 16:05:16 pp * rcsforce : 5.0 public release * */ #include "util.h" #include <isode/cmd_srch.h> #include "mta.h" extern CMD_TABLE tbl_month[]; /* --------------------- Begin Routines -------------------------------- */ /* This routine converts a RFC 822 standard time string like: "Tue, 16 Aug 88 10:23:21 BST" into a UTC structure. Where "Tue," is optional. */ extern char *index (); static void getzone (); int rfc2UTC (str, utc) char *str; UTC *utc; { UTC ut; char *cp, *cp2; char tbuf[LINESIZE]; int n; PP_DBG (("Lib/rfc2UTC (%s)", str)); ut = (UTC) smalloc (sizeof *ut); bzero ((char *)ut, sizeof *ut); *utc = NULL; cp = str; #define skips(c) while (isspace (*c)) c++ #define skipsp(c) while (isspace (*c) || ispunct(*c)) c++; skips (cp); if (isalpha (*cp)) { while(isalpha (*cp)) cp ++; skipsp (cp); } /* month day */ if (isdigit (*cp)) { n = 0; while (isdigit (*cp)) n = n * 10 + (*cp++ - '0'); ut -> ut_mday = n; skips (cp); } else { PP_LOG (LLOG_EXCEPTIONS, ("Bad month day '%s'", str)); free(ut); return NOTOK; } /* Month */ if (isalpha (*cp)) { for (cp2 = tbuf; isalpha(*cp); *cp2 ++ = *cp++) continue; *cp2 = NULL; ut -> ut_mon = cmd_srch (tbuf, tbl_month) + 1; skips (cp); } else { free(ut); return NOTOK; } /* -- Year -- */ if (isdigit (*cp)) { n = 0; while (isdigit (*cp)) n = n * 10 + (*cp ++ - '0'); if (n < 100) ut -> ut_year = 1900 + n; else ut -> ut_year = n; skips (cp); } else { free (ut); return NOTOK; } if (isdigit (*cp)) { n = 0; while (isdigit(*cp)) n = n * 10 + (*cp++ - '0'); ut -> ut_hour = n; skips (cp); } /* -- Minute & Secs -- */ if (*cp == ':') { cp ++; n = 0; while (isdigit (*cp)) n = n * 10 + (*cp++ - '0'); ut -> ut_min = n; skips (cp); } if (*cp == ':') { cp ++; n = 0; while (isdigit (*cp)) n = n * 10 + (*cp ++ - '0'); ut -> ut_sec = n; ut -> ut_flags |= UT_SEC; skips (cp); } getzone (cp, ut); *utc = ut; PP_DBG (("Lib/rfc2UTC returns (%.22s)", utct2str (ut))); return OK; } static CMD_TABLE zone_tbl[] = { /* some of the more popular zones... */ "GMT", 0, "UT", 0, "WET", 0, "WDT", 1, "BST", 1, "EST", -5, "EDT", -4, "CST", -6, "CDT", -5, "MST", -7, "MDT", -6, "PST", -8, "PDT", -7, "Z", 0, "A", -1, "B", -2, "C", -3, "D", -4, "E", -5, "F", -6, "G", -7, "H", -8, "I", -9, "K", -10, "L", -11, "M", -12, "N", 1, "O", 2, "P", 3, "Q", 4, "R", 5, "S", 6, "T", 7, "U", 8, "V", 9, "W", 10, "X", 11, "Y", 12, 0, -99 }; static void getzone (bp, ut) char *bp; UTC ut; { int hours, mins; char *cp, zbuf[64]; while (isspace (*bp)) bp ++; if (*bp == '+' || *bp == '-') { /* offset TZ */ if (sscanf (bp, "%*c%02d%02d", &hours, &mins) != 2) return; ut -> ut_zone = 60 * hours + mins; if (*bp == '-') ut -> ut_zone = - ut -> ut_zone; ut -> ut_flags |= UT_ZONE; return; } if (isupper(*bp)) { /* 'real' TZ (e.g. BST) */ for (cp = zbuf; isupper(*bp); ) *cp++ = *bp ++; *cp = 0; if ((hours = cmd_srch (zbuf, zone_tbl)) != -99) { ut -> ut_flags |= UT_ZONE; ut -> ut_zone = hours * 60; return; } } PP_LOG (LLOG_EXCEPTIONS, ("Unknown timezone syntax %s", bp)); }