Hallo zusammen,
letzte Woche bin ich über das Linux-Kommando [font="Courier New"]stat[/font] gestolpert. Irgendwie hatte ich mich vertippt - und bin dann da hängengeblieben.
Dann dachte ich mir, dass es ganz sinnvoll sein könnte, gezielt bestimmte von [font="Courier New"]stat[/font] gelieferte Daten abzufragen - dieses Mal aber nicht über die Frickler-Pipes .
Entstanden ist dann folgendes Programm:
record fstats_(filename,size,block,eab,typ,device,inodes, links, rights, uid, gid, access, modified, changed, birth)
$define f "/home/andreas/icon9_51/bin/coexp_fileattr"
procedure stat(s)
static zeile, liste
initial
{ liste := []
zeile := 0
write("Image: ", image(liste))
if pipe := open("stat " || s, "p") then
{ while z := read(pipe) do
{ write("Input: ", z)
zeile +:= 1
case zeile of
{ 1: { # Datei: »/home/andreas/icon9_51/bin/coexp_fileattr“
put(liste, z[find(":", z)+4:-1]) # fil Dateiname (1)
}
2: { # Größe: 7224 Blöcke: 16 EA Block: 4096 Normale Datei
z ? {while tab(upto(&letters ++ ' ')) do typ := (tab(many(&letters ++ ' ')))}
z ? {while tab(upto(&digits)) do put(liste, tab(many(&digits)))}
while(match(" ", typ)) do typ := typ[2:0]
put(liste, typ) # siz Dateigröße
# blo Blockanzahl
# eab EA Block
# typ Dateityp
}
3: { # Gerät: 816h/2070d Inode: 22589277 Verknüpfungen: 1
z ? {if tab(find("h/") + 2) then
tab(0) ? {while tab(upto(&digits)) do
put(liste, tab(many(&digits))) # dev Gerät
# ino Inode
# lin Verknüpfungen
}
}
}
4: { # Zugriff: (0775/-rwxrwxr-x) Uid: ( 1000/ andreas) Gid: ( 1000/ andreas)
z ? {while tab(upto('(')) do
put(liste, tab(upto(')') + 1))
} # rig Zugriffsrechte
# uid
# gid
}
5 | 6 | 7 | 8: # Zugriff : 2017-09-03 18:25:28.526677002 +0200
# Modifiziert: 2017-09-03 18:25:28.522677002 +0200
# Geändert : 2017-09-03 18:25:28.522677002 +0200
# Geburt : -
{ put(liste, z[find(":", z)+2:0]) # acc Dateityp (5)
# mod Modifizierungsdatum (6)
# cha Änderungsdatum (7)
# bir Erstellungsdatum (8)
}
}
}
close(\pipe)
}
}
suspend !liste
end
procedure main()
stat(f)
write("\nAusgabe über Variablen:")
filestat := create stat(f)
every write((fil | siz | blo | eab | typ | dev | ino | lin | rig | uid | gid | acc | mod | cha | bir) := @filestat)
# Setzen eines Arrays
write("\nSetzen eines Arrays")
fs := []
filestat := ^filestat
while put(fs, @filestat)
write(*fs, " Elemente")
every i := 1 to *fs do write(name(fs[i]), ": ", fs[i])
# weitere Nutzung der Variablen zum Setzen in einem Record...
write("\nSetzen über einen Record")
filestat := ^filestat
fs := fstats_()
every !fs := @filestat
every write(!fs)
every i := 1 to *fs do write(name(fs[i]), ": ", repl(" ",20 - *name(fs[i])), fs[i])
write("\nSetzen über eine Tabelle")
filestat := ^filestat
fs := table()
every fs[("filename"|"size"|"block"|"eab"|"typ"|"device"|"inodes"|"links"|"rights"|"uid"|"gid"|"access"|"modification"|"change"|"birth")] := @filestat
every x := key(fs) do write(name(fs), "[\"", x, "\"] = " , repl(" ",20 - *x), fs[x])
end
Alles anzeigen
Ausgabe (die Formatierung der Ausgabe kommt hier jetzt nicht so rüber :
Spoiler anzeigen
Icon Version 9.5.1, June 5, 2013 (linux 32/64, Sep 5 2014)
Image: list_1(0)
Input: Datei: »/home/andreas/icon9_51/bin/coexp_fileattr“
Input: Größe: 12364 Blöcke: 32 EA Block: 4096 Normale Datei
Input: Gerät: 816h/2070d Inode: 22589277 Verknüpfungen: 1
Input: Zugriff: (0775/-rwxrwxr-x) Uid: ( 1000/ andreas) Gid: ( 1000/ andreas)
Input: Zugriff : 2017-09-03 22:21:16.479085893 +0200
Input: Modifiziert: 2017-09-03 22:21:16.475085893 +0200
Input: Geändert : 2017-09-03 22:21:16.475085893 +0200
Input: Geburt : -
Ausgabe über Variablen:
/home/andreas/icon9_51/bin/coexp_fileattr
12364
32
4096
Normale Datei
2070
22589277
1
(0775/-rwxrwxr-x)
( 1000/ andreas)
( 1000/ andreas)
2017-09-03 22:21:16.479085893 +0200
2017-09-03 22:21:16.475085893 +0200
2017-09-03 22:21:16.475085893 +0200
-
Setzen eines Arrays
15 Elemente
L[1]: /home/andreas/icon9_51/bin/coexp_fileattr
L[2]: 12364
L[3]: 32
L[4]: 4096
L[5]: Normale Datei
L[6]: 2070
L[7]: 22589277
L[8]: 1
L[9]: (0775/-rwxrwxr-x)
L[10]: ( 1000/ andreas)
L[11]: ( 1000/ andreas)
L[12]: 2017-09-03 22:21:16.479085893 +0200
L[13]: 2017-09-03 22:21:16.475085893 +0200
L[14]: 2017-09-03 22:21:16.475085893 +0200
L[15]: -
Setzen über einen Record
/home/andreas/icon9_51/bin/coexp_fileattr
12364
32
4096
Normale Datei
2070
22589277
1
(0775/-rwxrwxr-x)
( 1000/ andreas)
( 1000/ andreas)
2017-09-03 22:21:16.479085893 +0200
2017-09-03 22:21:16.475085893 +0200
2017-09-03 22:21:16.475085893 +0200
-
fstats_.filename: /home/andreas/icon9_51/bin/coexp_fileattr
fstats_.size: 12364
fstats_.block: 32
fstats_.eab: 4096
fstats_.typ: Normale Datei
fstats_.device: 2070
fstats_.inodes: 22589277
fstats_.links: 1
fstats_.rights: (0775/-rwxrwxr-x)
fstats_.uid: ( 1000/ andreas)
fstats_.gid: ( 1000/ andreas)
fstats_.access: 2017-09-03 22:21:16.479085893 +0200
fstats_.modified: 2017-09-03 22:21:16.475085893 +0200
fstats_.changed: 2017-09-03 22:21:16.475085893 +0200
fstats_.birth: -
Setzen über eine Tabelle
fs["block"] = 32
fs["filename"] = /home/andreas/icon9_51/bin/coexp_fileattr
fs["links"] = 1
fs["device"] = 2070
fs["gid"] = ( 1000/ andreas)
fs["eab"] = 4096
fs["rights"] = (0775/-rwxrwxr-x)
fs["typ"] = Normale Datei
fs["change"] = 2017-09-03 22:21:16.475085893 +0200
fs["uid"] = ( 1000/ andreas)
fs["modification"] = 2017-09-03 22:21:16.475085893 +0200
fs["access"] = 2017-09-03 22:21:16.479085893 +0200
fs["inodes"] = 22589277
fs["birth"] = -
fs["size"] = 12364
Verwendete Techniken:
- Alternative Variablenzuweisungen,
- die üblichen Zeichenkettenaufrufe (dieses Mal nur von Variablen - nicht von Funktionen),
- die Datentypen Listen, und Tabellen
- Co-Expressions (bis zum Erbrechen)
- und mal wieder String-Scanning (auch reichlich eingesetzt)
Code-Deutung:
folgt ein anderes Mal...
Beste Grüße
Andreas