jed@mb2c.UUCP (John E. Duncan III) (03/28/84)
/* date.c * * Simulate the UNIX 'date' command (sort of) using the * AZTEC 'C' system on an Apple-II with a * Mountain Computer CPS Multi-Function card clock in slot 5. * * Author: John E. Duncan */ static char datestr[30]; /* D mm/dd/yy hh;mm;ss */ static char *month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; static char *day[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; static char output[] = "www MMM dd, 19yy hh:mm:ss xm\n"; char ch; /* this is where the characters come in */ main() { register int i; static int MM, dd, hh, mm, ss; static char *ampm; for(i=0; i<30; i++) { /* The following assembler code retrieves an input character from * the clock and turns off the high bit should it have been on. * The card must be in slot 5, however, by changing the 5 in the * 'jsr' to the a different slot number, any slot can be handled. */ #asm jsr $c503 and #$7f sta ch_ #endasm if( ch == '\r' ) break; datestr[i] = ch; } /* Get the day */ strncpy( output, day[ datestr[0] - '0'], 3 ); /* Get the month */ MM = (datestr[2] - '0')*10 + (datestr[3] - '0'); strncpy( output+4, month[MM-1], 3 ); /* Get the day */ output[8] = datestr[5]; if( datestr[5] == '0' ) output[8] = ' '; output[9] = datestr[6]; /* Put out the year */ output[14] = datestr[8]; output[15] = datestr[9]; /* Put out the time */ hh = (datestr[11] - '0')*10 + (datestr[12] -'0'); if( hh > 11 ) { ampm = "pm"; } else ampm = "am"; if( hh > 12 ) { hh -= 12; } if( hh > 9 ) { output[17] = '1'; hh -= 10; } else output[17] = ' '; output[18] = hh + '0'; output[20] = datestr[14]; output[21] = datestr[15]; output[23] = datestr[17]; output[24] = datestr[18]; output[26] = *ampm; output[27] = *++ampm; write( 1, output, 29 ); }