dot

packages and services management
Log | Files | Refs | README

commit 0cca57653528ccd5f64d1e5e8adab98a5ea709e7
parent b8931e22bb82470bf7eae0a31104ef3618001f34
Author: Josuah Demangeon <mail@josuah.net>
Date:   Tue,  2 Oct 2018 20:50:50 +0200

make-a and make-h are now part of the general "code" repository

Diffstat:
Dbin/make-a | 10----------
Dbin/make-h | 94-------------------------------------------------------------------------------
Mbin/ptree | 78+++++++++++++++++++++++++++++++++++++++---------------------------------------
3 files changed, 39 insertions(+), 143 deletions(-)

diff --git a/bin/make-a b/bin/make-a @@ -1,10 +0,0 @@ -#!/bin/sh -e - -echo makelib "${1}_"*.c | - fold -s -w 78 | - sed 's,\.c,\.o,g; $ s,$, ,; s,$,\\,' -echo "$1.h:" - -echo ./makelib "lib$1.a" "${1}_"*.c | - fold -s -w 70 | - sed 's,^, ,; s,\.c,\.o,g; s,$,\\,; $s,\\$,,' diff --git a/bin/make-h b/bin/make-h @@ -1,94 +0,0 @@ -#!/usr/bin/awk -f -# generate .h prototypes out of a .c file with space for alignment - -# target must be a multiple of 8 -function space(pos, target) -{ - if (pos > target) - return pos; - printf("\t"); - pos += 8 - (pos - 1) % 8; - for (; pos < target; pos += 8) - printf("\t"); - return pos; -} - -function print_args(pos, args) -{ - while (pos + length(args) + 1 > COL_MAX) { - head = substr(args, 1, COL_MAX - pos); - sub(",[^,]*$", "", head); - - printf("%s,\n", head); pos = 0; - pos = space(pos, COL_ARGS); - printf(" "); pos++; - - args = substr(args, length(head) + 1); - sub(", *", "", args); - } - printf("%s;\n", args); -} - -BEGIN { - COL_SYMBOL = 16; - COL_ARGS = 32; - COL_MAX = 80; -} - -FILENAME == "main.c" { - next; -} - -#ARGC > 1 && FNR == 1 { -# sub(".*/", "", FILENAME); -# printf("\n/* %s */\n", FILENAME); -#} - -/^[a-zA-Z0-9_]*\(/ { - if (match(type, "static") || match($0, ";$")) - next; - - ptr = type; - if (sub(" *[*]+", "", type)) - gsub("[^*]", "", ptr); - else - ptr = " "; - - symbol = $0; - sub("\\(.*", "", symbol); - sub("[a-zA-Z0-9_]*\\(", "("); - - if (symbol == "main") - next; - - pos = 0; - printf("%s", type); pos += length(type); - pos = space(pos, COL_SYMBOL); - printf("%s", ptr); pos += length(ptr); - printf("%s", symbol); pos += length(symbol); - pos = space(pos, COL_ARGS); - - IN = 1; -} - -IN { - args = args " " $0; -} - -IN && /\)$/ { - gsub("[ \t]+", " ", args); - sub("^ ", "", args); - gsub("[*][a-zA-Z0-9_]+,", "*,", args); - gsub("[*][a-zA-Z0-9_]+\\)", "*)", args); - gsub("[ ][a-zA-Z0-9_]+,", ",", args); - gsub("[ ][a-zA-Z0-9_]+\\)", ")", args); - - print_args(pos, args); - - args = "" - IN = 0; -} - -{ - type = $0; -} diff --git a/bin/ptree b/bin/ptree @@ -2,42 +2,6 @@ # pstree implementation in awk -# Use ps(1) to generate a list of pid, ppid and other properties with -# the command name, displayed as a tree built from the pid-ppid pairs: -# -# USER TT NI PID STAT COMMAND -# root ? 0 1 Ss runit -# josuah ? 0 22437 S ├─ startx -# josuah ? 0 22451 S │ └─ xinit -# root tty7 0 22452 Rsl+ │ ├─ Xorg -# josuah ? 0 22457 S │ └─ dwm -# josuah ? 0 24882 S └─ runsvdir -# josuah ? 0 24884 S ├─ runsv -# josuah ? 0 24887 S │ ├─ svlogd -# josuah ? 0 24890 S │ └─ ratox -# josuah ? 0 24885 S └─ runsv -# josuah ? 0 24405 S ├─ tor -# josuah ? 0 24889 S └─ svlogd - -BEGIN { - LINE = "│ "; - NODE = "├─ "; - TAIL = "└─ "; - VOID = " "; - - list(entries); - NUM = 1; fill(entries, 1, 0); - tree(entries, NUM); - - for (i = 1; i < NUM; i++) { - printf("%s", entries[i":info"]); - for (j = 1; entries[i":"j] != ""; j++) - printf("%s", entries[i":"j]); - printf("%-" 30 - j * 3 "s", entries[i":comm"]); - print(" "entries[i":args"]); - } -} - # Build a relational database in <entries> from the output of ps: The # parent pid (ppid) -> pid pairs are used to accumulate a list of child # pid (serialized into a csv: ",234,532,454") later used for building @@ -47,7 +11,7 @@ BEGIN { function list(entries) { - opt = "-o ppid,user,vsz,pid,stat,comm,args" + opt = "-o ppid,user,pid,stat,comm,args" cmd = "exec ps -ax " opt " 2>/dev/null"; if (!(cmd | getline)) { cmd = "exec ps " opt @@ -57,10 +21,10 @@ function list(entries) print $0; for (num = 0; cmd | getline; num++) { - ppid = $1; pid = $4; + ppid = $1; pid = $3; entries[ppid"cpid"] = entries[ppid"cpid"] "," pid; sub(" *[^ ]+", ""); - sub(" *[^ ]+ + *[^ ]+ + *[^ ]+ + *[^ ]+ +", "&\t"); + sub(" *[^ ]+ + *[^ ]+ + *[^ ]+ +", "&\t"); sub("[^\t]+ [^ ]+ +", "&\t"); split($0, info, "\t"); sub(" *$" , "", info[2]); @@ -125,3 +89,39 @@ function tree(entries, num) } } } + +# Use ps(1) to generate a list of pid, ppid and other properties with +# the command name, displayed as a tree built from the pid-ppid pairs: +# +# USER TT NI PID STAT COMMAND +# root ? 0 1 Ss runit +# josuah ? 0 22437 S ├─ startx +# josuah ? 0 22451 S │ └─ xinit +# root tty7 0 22452 Rsl+ │ ├─ Xorg +# josuah ? 0 22457 S │ └─ dwm +# josuah ? 0 24882 S └─ runsvdir +# josuah ? 0 24884 S ├─ runsv +# josuah ? 0 24887 S │ ├─ svlogd +# josuah ? 0 24890 S │ └─ ratox +# josuah ? 0 24885 S └─ runsv +# josuah ? 0 24405 S ├─ tor +# josuah ? 0 24889 S └─ svlogd + +BEGIN { + LINE = "│ "; + NODE = "├─ "; + TAIL = "└─ "; + VOID = " "; + + list(entries); + NUM = 1; fill(entries, 1, 0); + tree(entries, NUM); + + for (i = 1; i < NUM; i++) { + printf("%s", entries[i":info"]); + for (j = 1; entries[i":"j] != ""; j++) + printf("%s", entries[i":"j]); + printf("%-" 30 - j * 3 "s", entries[i":comm"]); + print(" "entries[i":args"]); + } +}