Annotation of researchv10no/cmd/numdate/numdate.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *     numdate -- command interface to getdate()
        !             3:  */
        !             4: 
        !             5: #include <stdio.h>
        !             6: #include <sys/types.h>
        !             7: 
        !             8: char *malloc();
        !             9: 
        !            10: main (argc, argv)
        !            11:        int argc;
        !            12:        char **argv;
        !            13: {
        !            14:        register char *buf, *p, *arg;
        !            15:        register int i, n;
        !            16:        time_t t, getdate();
        !            17: 
        !            18:        /* calculate the length of the date string */
        !            19:        n = 1;
        !            20:        for (i = 1; i < argc; i++)
        !            21:                n += strlen (argv[i]) + 1;
        !            22: 
        !            23:        /* allocate memory for the string */
        !            24:        buf = malloc (n);
        !            25:        if (buf == NULL) {
        !            26:                fprintf (stderr, "numdate: out of memory\n");
        !            27:                exit (1);
        !            28:        }
        !            29: 
        !            30:        /* build the string */
        !            31:        p = buf;
        !            32:        for (i = 1; i < argc; i++) {
        !            33:                arg = argv[i];
        !            34:                while (*arg)
        !            35:                        *p++ = *arg++;
        !            36:                if (i < argc - 1)
        !            37:                        *p++ = ' ';
        !            38:        }
        !            39:        *p++ = '\0';
        !            40: 
        !            41:        /* attempt to parse it */
        !            42:        t = getdate (buf, (time_t) 0);
        !            43:        free (buf);
        !            44: 
        !            45:        /* failed? */
        !            46:        if (t == -1) {
        !            47:                fprintf (stderr, "numdate: bad argument\n");
        !            48:                exit (1);
        !            49:        }
        !            50: 
        !            51:        /* success! */
        !            52:        printf ("%ld\n", t);
        !            53: 
        !            54:        return 0;
        !            55: }

unix.superglobalmegacorp.com

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