Annotation of sbbs/src/xpdev/xptime.c, revision 1.1.1.1

1.1       root        1: /* $Id: xptime.c,v 1.2 2008/02/23 22:18:37 rswindell Exp $ */
                      2: 
                      3: #include <stdio.h>
                      4: #include <stdlib.h>
                      5: #include <time.h>
                      6: #include <string.h>
                      7: #ifndef __unix__
                      8: #include <dos.h>
                      9: #endif
                     10: #include <ctype.h>
                     11: #define USE_SNPRINTF   /* we don't need safe_snprintf for this project */
                     12: #include "genwrap.h"
                     13: #include "datewrap.h"
                     14: #include "xpdatetime.h"
                     15: 
                     16: int main(int argc, char **argv)
                     17: {
                     18:        char                    str[256];
                     19:        char                    revision[16];
                     20:        time_t                  t;
                     21:        struct tm*              tp;
                     22:        struct tm               tm;
                     23:        int                             argn=1;
                     24:        xpDateTime_t    xpDateTime;
                     25: 
                     26:        printf("\n");
                     27:        DESCRIBE_COMPILER(str);
                     28:        sscanf("$Revision: 1.2 $", "%*s %s", revision);
                     29: 
                     30:        printf("Rev %s Built " __DATE__ " " __TIME__ " with %s\n\n", revision, str);
                     31: 
                     32:        if(argc<2)
                     33:                printf("usage: xptime [-z] <date_str || time_t>\n\n");
                     34: 
                     35:        if(argc>1 && stricmp(argv[1],"-z")==0)  { /* zulu/GMT/UTC timezone */
                     36:                printf("Setting timezone to Zulu/GMT/UTC\n\n");
                     37:                putenv("TZ=UTC0");
                     38:                argn++;
                     39:        }
                     40:        tzset();
                     41: 
                     42:        if((t=checktime())!=0L)
                     43:                printf("!time() result diverges from standard by: %ld seconds\n\n",t);
                     44: 
                     45:        printf("Current timezone: %d\n", xpTimeZone_local());
                     46:        printf("\n");
                     47: 
                     48:        if(argc>argn && strlen(argv[argn]) > 10) {
                     49:                xpDateTime=isoDateTimeStr_parse(argv[argn]);
                     50:                t=xpDateTime_to_time(xpDateTime);
                     51:                printf("Using specified date and time:\n");
                     52:        } else if(argc>argn) {
                     53:                printf("Using specified time_t value:\n");
                     54:                t=strtoul(argv[argn],NULL,0);
                     55:                xpDateTime=time_to_xpDateTime(t,xpTimeZone_LOCAL);
                     56:        } else {
                     57:                printf("Using current time:\n");
                     58:                xpDateTime=xpDateTime_now();
                     59:                t=time(NULL);
                     60:        }
                     61:        printf("%-8s %-10ld  (0x%08lX)    ISO %s\n"
                     62:                ,"time_t"
                     63:                ,t, t
                     64:                ,xpDateTime_to_isoDateTimeStr(xpDateTime
                     65:                        ,NULL, " ", NULL
                     66:                        ,/* precision: */3
                     67:                        , str, sizeof(str)));
                     68:        {
                     69:                const char* fmt="%-8s %.24s    ISO %s\n";
                     70: 
                     71:                if((tp=localtime_r(&t, &tm))==NULL)
                     72:                        printf("localtime() failure\n");
                     73:                else
                     74:                        printf(fmt
                     75:                                ,"local"
                     76:                                ,asctime(tp)
                     77:                                ,xpDateTime_to_isoDateTimeStr(
                     78:                                        time_to_xpDateTime(t, xpTimeZone_LOCAL)
                     79:                                        ,NULL, " ", NULL
                     80:                                        ,/*precision: */0
                     81:                                        ,str, sizeof(str))
                     82:                                );
                     83:                if((tp=gmtime_r(&t, &tm))==NULL)
                     84:                        printf("gmtime() failure\n");
                     85:                else
                     86:                        printf(fmt
                     87:                                ,"GMT"
                     88:                                ,asctime(tp)
                     89:                                ,xpDateTime_to_isoDateTimeStr(
                     90:                                        gmtime_to_xpDateTime(t)
                     91:                                        ,NULL, " ", NULL
                     92:                                        ,/*precision: */0
                     93:                                        ,str, sizeof(str))
                     94:                                );
                     95:        }
                     96: 
                     97:        return(0);
                     98: }

unix.superglobalmegacorp.com

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