| 1 | #include "cll1.h" |
| 2 | |
| 3 | struct Passwd |
| 4 | { |
| 5 | char *username, *home, *shell; |
| 6 | int uid, gid; |
| 7 | list(Passwd); |
| 8 | } *etcpasswd,*passwd; |
| 9 | |
| 10 | program |
| 11 | { |
| 12 | char *ptr; |
| 13 | FILE *f; |
| 14 | int col; |
| 15 | |
| 16 | parse("/etc/passwd") |
| 17 | { |
| 18 | col=1; |
| 19 | suffix(ptr,_,'\n'); |
| 20 | split(ptr,_,':') switch(col++) |
| 21 | { |
| 22 | case 1: create(passwd,Passwd);passwd->username=ptr;break; |
| 23 | case 3: passwd->uid=atoi(ptr);break; |
| 24 | case 4: passwd->gid=atoi(ptr);break; |
| 25 | case 6: passwd->home=ptr;break; |
| 26 | case 7: passwd->shell=ptr;insert(passwd,etcpasswd,sort_by,username);break; |
| 27 | } |
| 28 | } |
| 29 | done; |
| 30 | |
| 31 | puts("--------- /etc/passwd sorted by username ---------------"); |
| 32 | every(passwd,etcpasswd) printf("#%03d: %s\n",passwd->uid,passwd->username); |
| 33 | |
| 34 | puts("--------- /etc/passwd sorted by uid --------------------"); |
| 35 | sort(passwd,etcpasswd,order_by,uid); |
| 36 | every(passwd,etcpasswd) printf("#%03d: %s\n",passwd->uid,passwd->username); |
| 37 | } |