Mercurial > hg > toybox
annotate toys/other/w.c @ 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.
The actual code should be the same afterward, this is just cosmetic refactoring.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 13 Nov 2012 17:14:08 -0600 |
parents | 6df4ccc0acbe |
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 /* w.c - shows logged in users |
630
03f18afb4b44
Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 * |
03f18afb4b44
Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 * Copyright 2012 Gaurang Shastri <gmshastri@gmail.com> |
03f18afb4b44
Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 |
03f18afb4b44
Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 USE_W(NEWTOY(w, NULL, TOYFLAG_USR|TOYFLAG_BIN)) |
03f18afb4b44
Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 |
03f18afb4b44
Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 config W |
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
|
8 bool "w" |
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
|
9 default y |
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
|
10 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
|
11 usage: w |
630
03f18afb4b44
Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 |
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
|
13 Show who is logged on and since how long they logged in. |
630
03f18afb4b44
Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 */ |
03f18afb4b44
Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 |
03f18afb4b44
Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 #include "toys.h" |
03f18afb4b44
Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 |
03f18afb4b44
Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
18 void w_main(void) |
03f18afb4b44
Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
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 struct utmpx *x; |
631 | 21 |
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
|
22 xprintf("USER TTY LOGIN@ FROM"); |
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
|
23 setutxent(); |
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
|
24 while ((x=getutxent()) != NULL) { |
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
|
25 if (x->ut_type==7) { |
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
|
26 time_t tt = x->ut_tv.tv_sec; |
630
03f18afb4b44
Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
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 xprintf("\n%-9.8s%-9.8s %-4.24s (%-1.12s)", x->ut_user, x->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
|
29 ctime(&tt), x->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
|
30 } |
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
|
31 } |
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 xputc('\n'); |
630
03f18afb4b44
Add w command by Gaurang Shastri.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
33 } |