Debian Codegraph @

test/nsprof2.awk

raw
1 # passwd.awk --- access password file information
2 #
3 # Arnold Robbins, [email protected], Public Domain
4 # May 1993
5 # Revised October 2000
6 # Revised December 2010
7 # Revised July 2017
8
9 @namespace "foo" # this is foo
10
11 @namespace "bar" # this is bar
12
13 @namespace "passwd" # move to passwd namespace
14
15 BEGIN {
16 # tailor this to suit your system
17 Awklib = "/usr/local/libexec/awk/"
18 }
19
20 function Init( oldfs, oldrs, olddol0, pwcat, using_fw, using_fpat)
21 {
22 if (Inited)
23 return
24
25 oldfs = FS
26 oldrs = RS
27 olddol0 = $0
28 using_fw = (PROCINFO["FS"] == "FIELDWIDTHS")
29 using_fpat = (PROCINFO["FS"] == "FPAT")
30 FS = ":"
31 RS = "\n"
32
33 pwcat = Awklib "pwcat"
34 while ((pwcat | getline) > 0) {
35 Byname[$1] = $0
36 Byuid[$3] = $0
37 Bycount[++Total] = $0
38 }
39 close(pwcat)
40 Count = 0
41 Inited = 1
42 FS = oldfs
43 if (using_fw)
44 FIELDWIDTHS = FIELDWIDTHS
45 else if (using_fpat)
46 FPAT = FPAT
47 RS = oldrs
48 $0 = olddol0
49 }
50
51 function awk::getpwnam(name)
52 {
53 Init()
54 return Byname[name]
55 }
56
57 function awk::getpwuid(uid)
58 {
59 Init()
60 return Byuid[uid]
61 }
62
63 function awk::getpwent()
64 {
65 Init()
66 if (Count < Total)
67 return Bycount[++Count]
68 return ""
69 }
70
71 function awk::endpwent()
72 {
73 Count = 0
74 }