-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.awk
153 lines (126 loc) · 2.85 KB
/
module.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
function _dirname_(file){
sub(/\/[^/]+$/,"",file)
return file
}
function _basename_(_name_,_suffix_) {
gsub(/^\/|[^/]+\//,"",_name_)
if (_suffix_) {
_suffix_ = index(_name_,_suffix_)-1
_name_ = substr(_name_,1,_suffix_)
}
return _name_
}
function makesizes(bytes,array){
# For quick access, this creates size variables
split("0 0 0 0",array," ")
for (i=1;i<=length(array);i++) {
bytes /= 1024
if (bytes<1) break
array[i] = bytes
}
sizekb =array[1]
sizemb =array[2]
sizegb =array[3]
sizetb =array[4]
# SIZE should be an array!
# size["bytes"] can then be used
}
function hbytes(i, x,z){ # returns i in kb,mb,etc
x=i
while( (x/=1024) > 1){ i=x; z++ }
return sprintf("%.4g%sb",i,OrderedStringBytes[z])
}
function hBytes(i, x,z){ # returns i in KB,MB,GB,etc
x=i
while( (x/=1000) > 1){ i=x; z++ }
return sprintf( "%.4g%sB", i, toupper(OrderedStringBytes[z]) )
}
function mkdate(string,array,epoch, a){
array[""]=string
array["epoch"]=epoch
split(string,a,/[-:. ]/)
for(i in dates) array[dates[i]]=a[i]
}
BEGIN {
split("k m g t p",OrderedStringBytes)
split("year month day hour minute seconds nanoseconds",dates)
split("jan feb mar apr may jun jul aug sep oct nov dec",months)
split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec",Months)
FS="\r"
# FS="\x30"
# RS="\x00"
}
{ # Formats translater
operms = $1 #0755
huperms = $2 #-rwxrwxrwx
humanperms = $2 # synonym
permission = $2
permissions = $2
blocks = $3
ByteBlocks = $4
DeviceNum = $5
DeviceHex = $6
rawhex = $7
filetype = $8 # regular file|directory|character special file
type = $8 # block special file|symbolic link|regular empty file
# Group ID
gid = $9
groupid = $9 # (Numeric)
# Group name
group = $10
groupname = $10
gname = $10
hardlinks = $11
inode = $12
mount = $13
file = $14
FileName = $15 # outputs realpath for symbolic links
optimalIO = $16
sizeb = $17
majordevicetype = $18
minordevicetype = $19
# User ID
uid = $20 # numeric
uname = $21 # name
username = $21 # name
owner = $21 # name
# Dates!
hbirth = $22
obirth = $23
mkdate(hbirth,birth,obirth)
haccess = $24
oaccess = $25
mkdate(haccess,access,oaccess)
hmod = $26
omod = $27
mkdate(hmod,mod,omod)
hchange = $28
ochange = $29
mkdate(hchange,change,ochange)
inodetotal = $30
maxfilelength = $31
fublocksize = $32
for(i=1;i<=NF;i++) all[i]=$i
$0=file # for quick searching with // or $0 ~ ""
# file be filename?
# path is fullpath?
# dir is the directory? as in ../
# dirname is the directory name?
makesizes(sizeb)
filename = _basename_(file)
ext = ""
if (filetype == "directory") {
dirname = file # get ../ not current file!
} else {
dirname = _dirname_(file)
}
if (filetype == "regular file") {
ext=filename
# can't use match
if ( sub(/(\.[^.]+)$/,"\1",ext) ) {
ext = substr(filename,length(ext)+1)
} else {
ext=""
}
}
}