Annotation of 43BSDReno/contrib/isode-beta/dsap/common/time.c, revision 1.1.1.1

1.1       root        1: /* time.c - */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/dsap/common/RCS/time.c,v 7.0 89/11/23 21:44:38 mrose Rel $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/dsap/common/RCS/time.c,v 7.0 89/11/23 21:44:38 mrose Rel $
                      9:  *
                     10:  *
                     11:  * $Log:       time.c,v $
                     12:  * Revision 7.0  89/11/23  21:44:38  mrose
                     13:  * Release 6.0
                     14:  * 
                     15:  */
                     16: 
                     17: /*
                     18:  *                               NOTICE
                     19:  *
                     20:  *    Acquisition, use, and distribution of this module and related
                     21:  *    materials are subject to the restrictions of a license agreement.
                     22:  *    Consult the Preface in the User's Manual for the full terms of
                     23:  *    this agreement.
                     24:  *
                     25:  */
                     26: 
                     27: 
                     28: /* SYNTAX
                     29: 
                     30:        time ::= 'yymmddhhmmssz'
                     31: 
                     32:        where yy   = year
                     33:              mm   = month
                     34:              dd   = day
                     35:              hh   = hours
                     36:              mm   = minutes
                     37:              ss   = seconds
                     38:               z    = timezone
                     39: 
                     40:     EXAMPLE
                     41:        890602093221Z -> 09:32:21 GMT, on June 2nd 1989.
                     42: 
                     43: */
                     44: 
                     45: #include "quipu/util.h"
                     46: #include "quipu/attr.h"
                     47: #include "psap.h"
                     48: 
                     49: strprint ();
                     50: sfree ();
                     51: pstrcmp();
                     52: 
                     53: static UTC     qstr2utct (s, len)
                     54: char   *s;
                     55: int    len;
                     56: {
                     57:     UTC            ut;
                     58:     
                     59:     if (len > 14
                     60:            && strncmp (s, "1989", 4) == 0
                     61:            && (ut = str2utct (s + 2, len - 2)))
                     62:        return ut;
                     63: 
                     64:     return str2utct (s, len);
                     65: }
                     66: 
                     67: #define        str2utct        qstr2utct
                     68: 
                     69: 
                     70: static PE timeenc (x)
                     71: char *x;
                     72: {
                     73: PE ret_pe = NULLPE;
                     74: 
                     75:        (void) build_UNIV_UTCTime (&ret_pe,0,0,x,NULL);
                     76:        return (ret_pe);
                     77: }
                     78: 
                     79: static char * timedec (pe)
                     80: PE pe;
                     81: {
                     82: char * x;
                     83:        if (parse_UNIV_UTCTime (pe,0,0,&x,NULL) == NOTOK)
                     84:                return (NULLCP);
                     85:        return (x);
                     86: }
                     87: 
                     88: utcprint (ps,time,format)
                     89: PS ps;
                     90: char *time;
                     91: int format;
                     92: {
                     93:     UTC            ut;
                     94: 
                     95:     if (format == READOUT && (ut = str2utct (time, strlen (time)))) {
                     96:        long    mtime;
                     97: 
                     98:        mtime = gtime (ut2tm (ut));
                     99: 
                    100:        ps_printf (ps, "%-24.24s", ctime (&mtime));
                    101:     }
                    102:     else
                    103:        ps_printf (ps, "%s", time);
                    104: }
                    105: 
                    106: 
                    107: static utccmp (a, b)
                    108: char   *a, *b;
                    109: {
                    110:     long    a_time,
                    111:            mdiff;
                    112:     UTC            ut;
                    113: 
                    114:     if ((ut = str2utct (a, strlen (a))) == NULL)
                    115:        return pstrcmp (a, b);
                    116:     a_time = gtime (ut2tm (ut));
                    117: 
                    118:     if ((ut = str2utct (b, strlen (b))) == NULL)
                    119:        return pstrcmp (a, b);
                    120: 
                    121:     return ((mdiff = a_time - gtime (ut2tm (ut))) == 0L ? 0
                    122:                                                        : mdiff > 0L ? 1 : -1);
                    123: }
                    124: 
                    125: 
                    126: time_syntax ()
                    127: {
                    128:        (void) add_attribute_syntax ("UTCTime",
                    129:                (IFP) timeenc,  (IFP) timedec,
                    130:                (IFP) strdup,   utcprint,
                    131:                (IFP) strdup,   utccmp,
                    132:                sfree,          NULLCP,
                    133:                NULLIFP,        FALSE);
                    134: }
                    135: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.