int main(int argc, char** argv) { Css_t* css; Cssfd_t* fp; Connection_t* con; char* e; State_t state; NoP(argc); error_info.id = "css"; memset(&state, 0, sizeof(state)); state.disc.version = CSS_VERSION; state.disc.flags = CSS_DAEMON|CSS_ERROR|CSS_INTERRUPT; state.disc.acceptf = acceptf; state.disc.actionf = actionf; state.disc.errorf = errorf; state.disc.exceptf = exceptf; for (;;) { switch (optget(argv, usage)) { case 't': state.disc.timeout = strelapsed(opt_info.arg, &e, 1); if (*e) error(3, "%s: invalid timeout value", opt_info.arg); state.disc.flags |= CSS_DORMANT; continue; case '?': error(ERROR_USAGE|4, "%s", opt_info.arg); continue; case ':': error(2, "%s", opt_info.arg); continue; } break; } argv += opt_info.index; if (!argv[0] || !argv[1]) error(ERROR_USAGE|4, "%s", optusage(NiL)); if (!(state.tmp = sfstropen())) error(ERROR_SYSTEM|3, "out of space [tmp stream]"); if (!(state.proc = procopen(argv[1], argv + 1, NiL, NiL, PROC_READ|PROC_WRITE))) error(ERROR_SYSTEM|3, "%s: cannot execute", argv[1]); if (!(css = cssopen(argv[0], &state.disc))) return 1; if (!(fp = cssfd(css, state.proc->rfd, CS_POLL_READ))) error(ERROR_SYSTEM|3, "%s: cannot poll output", argv[1]); if (!(con = newof(0, Connection_t, 1, 0))) error(ERROR_SYSTEM|3, "out of space"); fp->data = con; con->service = 1; csspoll(CS_NEVER, 0); return 1; }
int main(int argc, char** argv) { char* e; State_t state; NoP(argc); error_info.id = "mbb"; memset(&state, 0, sizeof(state)); state.disc.version = CSS_VERSION; state.disc.flags = CSS_DAEMON|CSS_ERROR|CSS_INTERRUPT|CSS_LOG; state.disc.acceptf = acceptf; state.disc.actionf = actionf; state.disc.errorf = errorf; state.disc.exceptf = exceptf; for (;;) { switch (optget(argv, usage)) { case 'b': state.backlog = opt_info.num; continue; case 'd': error_info.trace = -opt_info.num; continue; case 't': state.disc.timeout = strelapsed(opt_info.arg, &e, 1); if (*e) error(3, "%s: invalid timeout value", opt_info.arg); state.disc.flags |= CSS_DORMANT; continue; case '?': error(ERROR_USAGE|4, "%s", opt_info.arg); continue; case ':': error(2, "%s", opt_info.arg); continue; } break; } argv += opt_info.index; if (!argv[0] || argv[1]) error(ERROR_USAGE|4, "%s", optusage(NiL)); if (!(state.tmp = sfstropen())) error(ERROR_SYSTEM|3, "out of space [tmp stream]"); if (!cssopen(argv[0], &state.disc)) return 1; umask(S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); csspoll(CS_NEVER, 0); return 1; }
int b_date(int argc, register char** argv, void* context) { register int n; register char* s; register Fmt_t* f; char* t; unsigned long u; Time_t now; Time_t ts; Time_t te; Time_t e; char buf[1024]; Fmt_t* fmts; Fmt_t fmt; struct stat st; char* cmd = argv[0]; /* original command path */ char* format = 0; /* tmxfmt() format */ char* string = 0; /* date string */ int elapsed = 0; /* args are start/stop pairs */ int filetime = 0; /* use this st_ time field */ int increment = 0; /* incrementally adjust time */ int last = 0; /* display the last time arg */ Tm_zone_t* listzones = 0; /* known time zone table */ int network = 0; /* don't set network time */ int show = 0; /* show date and don't set */ int unelapsed = 0; /* fmtelapsed() => strelapsed */ cmdinit(argc, argv, context, ERROR_CATALOG, 0); tm_info.flags = TM_DATESTYLE; fmts = &fmt; fmt.format = ""; fmt.next = 0; for (;;) { switch (optget(argv, usage)) { case 'a': case 'c': case 'm': filetime = opt_info.option[1]; continue; case 'd': string = opt_info.arg; show = 1; continue; case 'e': format = "%#"; continue; case 'E': elapsed = 1; continue; case 'f': format = opt_info.arg; continue; case 'i': increment = 1; continue; case 'l': tm_info.flags |= TM_LEAP; continue; case 'L': last = 1; continue; case 'n': network = 1; continue; case 'p': if (!(f = newof(0, Fmt_t, 1, 0))) error(ERROR_SYSTEM|3, "out of space [format]"); f->next = fmts; f->format = opt_info.arg; fmts = f; continue; case 's': show = 1; continue; case 'u': tm_info.flags |= TM_UTC; continue; case 'U': unelapsed = (int)opt_info.num; continue; case 'z': listzones = tm_data.zone; continue; case '?': error(ERROR_USAGE|4, "%s", opt_info.arg); continue; case ':': error(2, "%s", opt_info.arg); continue; } break; } argv += opt_info.index; if (error_info.errors) error(ERROR_USAGE|4, "%s", optusage(NiL)); now = tmxgettime(); if (listzones) { s = "-"; while (listzones->standard) { if (listzones->type) s = listzones->type; sfprintf(sfstdout, "%3s %4s %4s %4d %4d\n", s, *listzones->standard ? listzones->standard : "-", listzones->daylight ? listzones->daylight : "-", listzones->west, listzones->dst); listzones++; show = 1; } } else if (elapsed) { e = 0; while (s = *argv++) { if (!(t = *argv++)) { argv--; t = "now"; } ts = convert(fmts, s, now); te = convert(fmts, t, now); if (te > ts) e += te - ts; else e += ts - te; } sfputr(sfstdout, fmtelapsed((unsigned long)tmxsec(e), 1), '\n'); show = 1; } else if (unelapsed) { while (s = *argv++) { u = strelapsed(s, &t, unelapsed); if (*t) error(3, "%s: invalid elapsed time", s); sfprintf(sfstdout, "%lu\n", u); } show = 1; } else if (filetime) { if (!*argv) error(ERROR_USAGE|4, "%s", optusage(NiL)); n = argv[1] != 0; while (s = *argv++) { if (stat(s, &st)) error(2, "%s: not found", s); else { switch (filetime) { case 'a': now = tmxgetatime(&st); break; case 'c': now = tmxgetctime(&st); break; default: now = tmxgetmtime(&st); break; } tmxfmt(buf, sizeof(buf), format, now); if (n) sfprintf(sfstdout, "%s: %s\n", s, buf); else sfprintf(sfstdout, "%s\n", buf); show = 1; } } } else { if ((s = *argv) && !format && *s == '+') { format = s + 1; argv++; s = *argv; } if (s || (s = string)) { if (*argv && string) error(ERROR_USAGE|4, "%s", optusage(NiL)); now = convert(fmts, s, now); if (*argv && (s = *++argv)) { show = 1; do { if (!last) { tmxfmt(buf, sizeof(buf), format, now); sfprintf(sfstdout, "%s\n", buf); } now = convert(fmts, s, now); } while (s = *++argv); } } else show = 1; if (format || show) { tmxfmt(buf, sizeof(buf), format, now); sfprintf(sfstdout, "%s\n", buf); } else if (settime(context, cmd, now, increment, network)) error(ERROR_SYSTEM|3, "cannot set system time"); } while (fmts != &fmt) { f = fmts; fmts = fmts->next; free(f); } tm_info.flags = 0; if (show && sfsync(sfstdout)) error(ERROR_system(0), "write error"); return error_info.errors != 0; }