Re-use AWK components
[khatus.git] / bin / khatus_gen_bar_make_status
diff --git a/bin/khatus_gen_bar_make_status b/bin/khatus_gen_bar_make_status
new file mode 100755 (executable)
index 0000000..00e5506
--- /dev/null
@@ -0,0 +1,39 @@
+#! /usr/bin/awk -f
+
+BEGIN {
+    aliases["@energy"]    = "bar_make_status_energy()"
+    aliases["@memory"]    = "bar_make_status_mem()"
+    aliases["@processes"] = "bar_make_status_procs()"
+    aliases["@cpu"]       = "bar_make_status_cpu()"
+    aliases["@disk"]      = "bar_make_status_disk()"
+    aliases["@net"]       = "bar_make_status_net()"
+    aliases["@bluetooth"] = "bar_make_status_bluetooth()"
+    aliases["@backlight"] = "bar_make_status_screen_brightness()"
+    aliases["@volume"]    = "bar_make_status_volume()"
+    aliases["@mpd"]       = "bar_make_status_mpd()"
+    aliases["@weather"]   = "bar_make_status_weather()"
+    aliases["@datetime"]  = "bar_make_status_datetime()"
+    out = "function bar_make_status(    position, bar, sep, i, j) {\n"
+    n = split(Status_Bar, s, ",")
+    for (i=1; i<=n; i++) {
+        alias = s[i]
+        function_call = aliases[alias]
+        if (function_call) {
+            out = out "        position[++i] = " function_call ";\n"
+        } else {
+            printf("Unexpected status bar component alias: \"%s\"\n", alias) \
+                > "/dev/stderr"
+            exit(1)
+        }
+    }
+    out = out "\
+        bar = \"\";\
+        sep = \"\";\
+        for (j = 1; j <= i; j++) {\
+           bar = bar sep position[j];\
+           sep = \" \";\
+        }\
+        return bar;\
+    }";
+    print out
+}
This page took 0.019877 seconds and 4 git commands to generate.