/*------------------------------------------------------------------------ * xsh_date - obtain and print the current month, day, year, and time *------------------------------------------------------------------------ */ shellcmd xsh_date(int nargs, char *args[]) { int32 retval; /* return value */ uint32 now; /* current local time */ char datestr[64]; /* printable date in ascii */ /* Output info for '--help' argument */ if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) { printf("Usage: %s\n\n", args[0]); printf("Description:\n"); printf("\tDisplays the current date and time\n"); printf("Options (one per invocation):\n"); printf("\t-f\tforce a time server request to be sent\n"); printf("\t-d\tset daylight savings time on\n"); printf("\t-s\tset standard time (not daylight savings)\n"); printf("\t-a\tset daylight savings to automatic\n"); printf("\t--help\tdisplay this help and exit\n"); return 0; } /* Check argument count */ if (nargs > 2) { fprintf(stderr, "%s: too many arguments\n", args[0]); fprintf(stderr, "Try '%s --help' for more information\n", args[0]); return 1; } if (nargs == 2) { if (strncmp(args[1], "-f", 3) == 0) { Date.dt_bootvalid = FALSE; } else if (strncmp(args[1], "-d", 3) == 0) { Date.dt_daylight = DATE_DST_ON; } else if (strncmp(args[1], "-s", 3) == 0) { Date.dt_daylight = DATE_DST_OFF; } else if (strncmp(args[1], "-a", 3) == 0) { Date.dt_daylight = DATE_DST_AUTO; } else { fprintf(stderr, "%s: invalid argument\n", args[0]); fprintf(stderr, "Try '%s --help' for more information\n", args[0]); return 1; } } retval = gettime(&now); if (retval == SYSERR) { fprintf(stderr, "%s: could not obtain the current date\n", args[0]); return 1; } ascdate(now, datestr); printf("%s\n", datestr); return 0; }
/*------------------------------------------------------------------------ * lfing - print local FINGER info on the given descriptor *------------------------------------------------------------------------ */ int lfing(char *nam, int output) { struct user *pue; int tt, uc; u_long now; char *p, buf[128]; gettime(&now); sprintf(buf, "%-9s%-21s%3s%6s %-12s\n", "Login", "Name", "TTY", "Idle", "Login Time"); if (nam == NULL || *nam == '\0' || *nam == '\r') { uc = 0; for (tt=0; tt<Ntty; ++tt) { struct tty *ptty = &ttytab[tt]; if (ptty->tty_state == TTYS_FREE) continue; if (ptty->tty_uid < 0) continue; pue = getuser(ptty->tty_uid); if (pue == 0) continue; if (uc++ == 0) write(output, buf, strlen(buf)); sprintf(buf, "%-9s%-21s%2s%c%6s ", pue->ue_login, pue->ue_name, tt ? "tt" : " c", tt ? tt + '0' : 'o', pidle(now - ptty->tty_ctime)); p = buf + strlen(buf); ascdate(ptty->tty_ltime, p); strcat(p, "\n"); write(output, buf, strlen(buf)); } if (uc == 0) write(output, "no one logged in\n", 17); return OK; } write(output, "Not implemented\n", 16); /* not implemented (yet) */ return SYSERR; }