|
DataMuseum.dkPresents historical artifacts from the history of: Commodore CBM-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Commodore CBM-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 2028 (0x7ec) Types: TextFile Notes: UNIX file Names: »time.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code └─⟦f4b8d8c84⟧ UNIX Filesystem └─⟦this⟧ »cmd/time.c«
/* * Time command */ #include <stdio.h> #include <timeb.h> #include <times.h> #include <signal.h> #include <machine.h> #define MILLI 1000 /* Parts of a second */ extern char *signame[]; main(argc, argv) char *argv[]; { if (argc <= 1) { execl("/bin/date", "date", NULL); eprint("date: not found\n"); exit(1); } dotime(argc-1, argv+1); } dotime(argc, argv) char *argv[]; { int pid, status; register n; struct timeb before, after; struct tbuffer tb; long tdiff; int tpart; char *command = argv[0]; ftime(&before); if ((pid = fork()) < 0) { eprint("Try again.\n"); exit(1); } if (pid) { signal(SIGHUP, SIG_IGN); signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGTERM, SIG_IGN); while (wait(&status) >= 0) if (n = status&0177) { if (n <= NSIG) eprint("%s", signame[n]); else eprint("sig. %d", n); if (status & 0200) eprint(" -- core dumped"); fprintf(stderr ,"\n"); } ftime(&after); times(&tb); tdiff = after.time-before.time; tpart = after.millitm - before.millitm; if (tpart < 0) { tpart += MILLI; tdiff--; } output("Real:", tdiff, (tpart+MILLI/20)/(MILLI/10)); tpart = tb.tb_cutime%HZ; output("User:", tb.tb_cutime/HZ, (tpart+HZ/20)/(HZ/10)); tpart = tb.tb_cstime%HZ; output("Sys: ", tb.tb_cstime/HZ, (tpart+HZ/20)/(HZ/10)); } else { execvp(command, argv); eprint("%s: not found\n", command); exit(1); } exit(n); } /* * Format the output for a time entry. */ output(name, tsec, tenths) char *name; long tsec; { long hours; int mins; int secs; /* * Fudge for sloppy rounding above */ if (tenths > 9) { tenths = 0; tsec++; } hours = tsec/(60*60); tsec %= (60*60); mins = tsec/60; secs = tsec%60; eprint("%s", name); if (hours != 0) eprint("%5d:%02d:%02d", (int)hours, mins, secs); else { eprint(" "); if (mins) eprint("%2d:%02d", mins, secs); else eprint(" %2d", secs); } eprint(".%d\n", tenths); } /* VARARGS */ eprint(x) { fprintf(stderr, "%r", &x); }