Mercurial > hg > toybox
annotate toys/posix/who.c @ 1525:95cb37adb024 draft
Factor out printf-style escape parsing logic from echo.c.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 18 Oct 2014 17:14:12 -0500 |
parents | 53f165466f3b |
children | 685a0da6ca59 |
rev | line source |
---|---|
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
1 /* who.c - display who is on the system |
436
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
2 * |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
3 * Copyright 2012 ProFUSION Embedded Systems |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
4 * |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
5 * by Luis Felipe Strano Moraes <lfelipe@profusion.mobi> |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
6 * |
656
6df4ccc0acbe
Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
7 * See http://opengroup.org/onlinepubs/9699919799/utilities/who.html |
825
53f165466f3b
Add -a to who and switch to default y in defconfig.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
8 * |
53f165466f3b
Add -a to who and switch to default y in defconfig.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
9 * Posix says to support many options (-abdHlmpqrstTu) but this |
53f165466f3b
Add -a to who and switch to default y in defconfig.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
10 * isn't aimed at minicomputers with modem pools. |
436
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
11 |
825
53f165466f3b
Add -a to who and switch to default y in defconfig.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
12 USE_WHO(NEWTOY(who, "a", TOYFLAG_BIN)) |
436
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
13 |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
14 config WHO |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
15 bool "who" |
825
53f165466f3b
Add -a to who and switch to default y in defconfig.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
16 default y |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
17 help |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
18 usage: who |
436
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
19 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
20 Print logged user information on system |
436
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
21 */ |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
22 |
825
53f165466f3b
Add -a to who and switch to default y in defconfig.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
23 #define FOR_who |
436
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
24 #include "toys.h" |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
25 |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
26 void who_main(void) |
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
27 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
28 struct utmpx *entry; |
436
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
29 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
30 setutxent(); |
436
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
31 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
32 while ((entry = getutxent())) { |
825
53f165466f3b
Add -a to who and switch to default y in defconfig.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
33 if ((toys.optflags & FLAG_a) || entry->ut_type == USER_PROCESS) { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
34 time_t time; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
35 int time_size; |
825
53f165466f3b
Add -a to who and switch to default y in defconfig.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
36 char *times; |
437
2d19539c3aeb
Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
436
diff
changeset
|
37 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
38 time = entry->ut_tv.tv_sec; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
39 times = ctime(&time); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
40 time_size = strlen(times) - 2; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
41 printf("%s\t%s\t%*.*s\t(%s)\n", entry->ut_user, entry->ut_line, |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
42 time_size, time_size, ctime(&time), entry->ut_host); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
43 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
44 } |
437
2d19539c3aeb
Added time to the output of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
436
diff
changeset
|
45 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
46 endutxent(); |
436
bc347fc87b00
Initial version of who command.
Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
parents:
diff
changeset
|
47 } |