From: Alan Cox Date: Sun, 12 Nov 2017 18:58:28 +0000 (+0000) Subject: who: reformat and add the ability to run it as 'users' as well X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=5107689d76747841153a56cf370add5124e768a4;p=FUZIX.git who: reformat and add the ability to run it as 'users' as well --- diff --git a/Applications/util/who.c b/Applications/util/who.c index e97a75af..b50edc9a 100644 --- a/Applications/util/who.c +++ b/Applications/util/who.c @@ -16,27 +16,36 @@ */ -#include #include +#include #include #include #include void main(int argc, char *argv[]) { - register struct utmp * entry; - char * timestr; + register struct utmp *entry; + char *timestr; + uint8_t fmt = 0; - setutent(); - while ((entry = getutent()) != NULL) - if (entry->ut_type == USER_PROCESS) { - timestr = ctime(&entry->ut_time); - timestr[strlen(timestr) - 1] = '\0'; - printf("%s tty%c%c %s %s\n", entry->ut_user, - entry->ut_id[0], - entry->ut_id[1] ? entry->ut_id[1] : 0, - timestr, - entry->ut_host); + if (strcmp(argv[0], "users") == 0) + fmt = 1; + setutent(); + while ((entry = getutent()) != NULL) { + if (entry->ut_type == USER_PROCESS) { + if (fmt == 0) { + timestr = ctime(&entry->ut_time); + timestr[strlen(timestr) - 1] = '\0'; + printf("%s tty%c%c %s %s\n", entry->ut_user, entry->ut_id[0], entry->ut_id[1] ? entry->ut_id[1] : 0, timestr, entry->ut_host); + } else { + if (fmt == 2) + putchar(' '); + printf("%s", entry->ut_user); + fmt = 2; + } + } } - exit(0); + if (fmt == 2) + putchar('\n'); + exit(0); }