drop adt746x objects
[monky] / src / core.c
index 00b740b..ce75e90 100644 (file)
@@ -36,7 +36,9 @@
 #include "colours.h"
 #include "combine.h"
 #include "diskio.h"
+#include "entropy.h"
 #include "exec.h"
+#include "proc.h"
 #ifdef X11
 #include "fonts.h"
 #endif
@@ -74,9 +76,6 @@
 #include "openbsd.h"
 #endif
 
-/* OS specific prototypes to be implemented by linux.c & Co. */
-void update_entropy(void);
-
 #include <string.h>
 #include <ctype.h>
 
@@ -170,7 +169,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                } else {
                        obj->data.i = atoi(&arg[0]);
                }
-               obj->a = 1;
        END OBJ(freq_g, 0)
                get_cpu_count();
                if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
@@ -181,7 +179,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                } else {
                        obj->data.i = atoi(&arg[0]);
                }
-               obj->a = 1;
        END OBJ_ARG(read_tcp, 0, "read_tcp: Needs \"(host) port\" as argument(s)")
                parse_read_tcp_arg(obj, arg, free_at_crash);
 #if defined(__linux__)
@@ -195,7 +192,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                } else {
                        obj->data.i = atoi(&arg[0]);
                }
-               obj->a = 1;
        END OBJ(voltage_v, 0)
                get_cpu_count();
                if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
@@ -206,7 +202,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                } else {
                        obj->data.i = atoi(&arg[0]);
                }
-               obj->a = 1;
 
 #ifdef HAVE_IWLIB
        END OBJ(wireless_essid, &update_net_stats)
@@ -345,9 +340,8 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                DBGP2("Adding $cpu for CPU %d", obj->data.i);
 #ifdef X11
        END OBJ(cpugauge, &update_cpu_usage)
-               SIZE_DEFAULTS(gauge);
                SCAN_CPU(arg, obj->data.i);
-               scan_gauge(arg, &obj->a, &obj->b);
+               scan_gauge(obj, arg);
                DBGP2("Adding $cpugauge for CPU %d", obj->data.i);
 #endif /* X11 */
        END OBJ(cpubar, &update_cpu_usage)
@@ -358,7 +352,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        END OBJ(cpugraph, &update_cpu_usage)
                char *buf = 0;
                SCAN_CPU(arg, obj->data.i);
-               buf = scan_graph(obj, arg);
+               buf = scan_graph(obj, arg, 100);
                DBGP2("Adding $cpugraph for CPU %d", obj->data.i);
                if (buf) free(buf);
        END OBJ(loadgraph, &update_load_average)
@@ -472,7 +466,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                scan_exec_arg(obj, arg);
 #ifdef X11
        END OBJ(execgauge, 0)
-               SIZE_DEFAULTS(gauge);
                scan_exec_arg(obj, arg);
        END OBJ(execgraph, 0)
                scan_execgraph_arg(obj, arg);
@@ -483,7 +476,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        END OBJ_ARG(execigraph, 0, "execigraph needs arguments")
                scan_execgraph_arg(obj, arg);
        END OBJ_ARG(execigauge, 0, "execigauge needs arguments")
-               SIZE_DEFAULTS(gauge);
                scan_execi_arg(obj, arg);
 #endif /* X11 */
        END OBJ_ARG(execi, 0, "execi needs arguments")
@@ -520,20 +512,10 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                obj->data.i = arg ? atoi(arg) : 1;
        END OBJ_ARG(goto, 0, "goto needs arguments")
                obj->data.i = atoi(arg);
+#ifdef X11
        END OBJ(tab, 0)
-               int a = 10, b = 0;
-
-               if (arg) {
-                       if (sscanf(arg, "%d %d", &a, &b) != 2) {
-                               sscanf(arg, "%d", &b);
-                       }
-               }
-               if (a <= 0) {
-                       a = 1;
-               }
-               obj->data.pair.a = a;
-               obj->data.pair.b = b;
-
+               scan_tab(obj, arg);
+#endif /* X11 */
 #ifdef __linux__
        END OBJ_ARG(i2c, 0, "i2c needs arguments")
                parse_i2c_sensor(obj, arg);
@@ -570,37 +552,25 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        END OBJ(loadavg, &update_load_average)
                scan_loadavg_arg(obj, arg);
        END OBJ_IF_ARG(if_empty, 0, "if_empty needs an argument")
-               obj->data.ifblock.s = strndup(arg, text_buffer_size);
                obj->sub = malloc(sizeof(struct text_object));
-               extract_variable_text_internal(obj->sub, obj->data.ifblock.s);
+               extract_variable_text_internal(obj->sub, arg);
        END OBJ_IF_ARG(if_match, 0, "if_match needs arguments")
-               obj->data.ifblock.s = strndup(arg, text_buffer_size);
                obj->sub = malloc(sizeof(struct text_object));
-               extract_variable_text_internal(obj->sub, obj->data.ifblock.s);
+               extract_variable_text_internal(obj->sub, arg);
        END OBJ_IF_ARG(if_existing, 0, "if_existing needs an argument or two")
-               char buf1[256], buf2[256];
-               int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
-
-               if (r == 1) {
-                       obj->data.ifblock.s = strndup(buf1, text_buffer_size);
-                       obj->data.ifblock.str = NULL;
-               } else {
-                       obj->data.ifblock.s = strndup(buf1, text_buffer_size);
-                       obj->data.ifblock.str = strndup(buf2, text_buffer_size);
-               }
-               DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str);
+               obj->data.s = strndup(arg, text_buffer_size);
        END OBJ_IF_ARG(if_mounted, 0, "if_mounted needs an argument")
-               obj->data.ifblock.s = strndup(arg, text_buffer_size);
+               obj->data.s = strndup(arg, text_buffer_size);
 #ifdef __linux__
        END OBJ_IF_ARG(if_running, &update_top, "if_running needs an argument")
                top_running = 1;
-               obj->data.ifblock.s = strndup(arg, text_buffer_size);
+               obj->data.s = strndup(arg, text_buffer_size);
 #else
        END OBJ_IF_ARG(if_running, 0, "if_running needs an argument")
                char buf[256];
 
                snprintf(buf, 256, "pidof %s >/dev/null", arg);
-               obj->data.ifblock.s = strndup(buf, text_buffer_size);
+               obj->data.s = strndup(buf, text_buffer_size);
 #endif
        END OBJ(kernel, 0)
        END OBJ(machine, 0)
@@ -637,15 +607,14 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        END OBJ(memperc, &update_meminfo)
 #ifdef X11
        END OBJ(memgauge, &update_meminfo)
-               SIZE_DEFAULTS(gauge);
-               scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b);
+               scan_gauge(obj, arg);
 #endif /* X11*/
        END OBJ(membar, &update_meminfo)
                scan_bar(obj, arg);
 #ifdef X11
        END OBJ(memgraph, &update_meminfo)
                char *buf = 0;
-               buf = scan_graph(obj, arg);
+               buf = scan_graph(obj, arg, 100);
 
                if (buf) free(buf);
 #endif /* X11*/
@@ -673,8 +642,27 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        END OBJ(desktop_name, &update_x11info)
 #endif
        END OBJ(nodename, 0)
+       END OBJ_ARG(pid_cmdline, 0, "pid_cmdline needs a pid as argument")
+               scan_pid_cmdline_arg(obj, arg, free_at_crash);
+       END OBJ_ARG(pid_cwd, 0, "pid_cwd needs a pid as argument")
+               scan_pid_cwd_arg(obj, arg, free_at_crash);
+       END OBJ_ARG(pid_environ, 0, "pid_environ needs arguments")
+               scan_pid_environ_arg(obj, arg, free_at_crash);
+       END OBJ_ARG(pid_environ_list, 0, "pid_environ_list needs a pid as argument")
+               scan_pid_environ_list_arg(obj, arg, free_at_crash);
+       END OBJ_ARG(pid_exe, 0, "pid_exe needs a pid as argument")
+               scan_pid_exe_arg(obj, arg, free_at_crash);
+       END OBJ_ARG(pid_openfiles, 0, "pid_openfiles needs a pid as argument")
+               scan_pid_openfiles_arg(obj, arg, free_at_crash);
+       END OBJ_ARG(pid_stderr, 0, "pid_stderr needs a pid as argument")
+               scan_pid_stderr_arg(obj, arg, free_at_crash);
+       END OBJ_ARG(pid_stdin, 0, "pid_stdin needs a pid as argument")
+               scan_pid_stdin_arg(obj, arg, free_at_crash);
+       END OBJ_ARG(pid_stdout, 0, "pid_stdout needs a pid as argument")
+               scan_pid_stdout_arg(obj, arg, free_at_crash);
        END OBJ(processes, &update_total_processes)
        END OBJ(running_processes, &update_running_processes)
+       END OBJ(threads, &update_threads)
        END OBJ(shadecolor, 0)
 #ifdef X11
                obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
@@ -685,18 +673,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
 #endif /* X11 */
        END OBJ(stippled_hr, 0)
 #ifdef X11
-               int a = get_stippled_borders(), b = 1;
-
-               if (arg) {
-                       if (sscanf(arg, "%d %d", &a, &b) != 2) {
-                               sscanf(arg, "%d", &b);
-                       }
-               }
-               if (a <= 0) {
-                       a = 1;
-               }
-               obj->data.pair.a = a;
-               obj->data.pair.b = b;
+               scan_stippled_hr(obj, arg);
 #endif /* X11 */
        END OBJ(swap, &update_meminfo)
        END OBJ(swapfree, &update_meminfo)
@@ -723,9 +700,9 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                parse_net_stat_arg(obj, arg, free_at_crash);
        END OBJ(updates, 0)
        END OBJ_IF(if_updatenr, 0)
-               obj->data.ifblock.i = arg ? atoi(arg) : 0;
-               if(obj->data.ifblock.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument");
-               set_updatereset(obj->data.ifblock.i > get_updatereset() ? obj->data.ifblock.i : get_updatereset());
+               obj->data.i = arg ? atoi(arg) : 0;
+               if(obj->data.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument");
+               set_updatereset(obj->data.i > get_updatereset() ? obj->data.i : get_updatereset());
        END OBJ(alignr, 0)
                obj->data.i = arg ? atoi(arg) : 0;
        END OBJ(alignc, 0)
@@ -748,10 +725,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        END OBJ(gw_iface, &update_gateway_info)
        END OBJ(gw_ip, &update_gateway_info)
 #endif /* !__linux__ */
-#ifndef __OpenBSD__
-       END OBJ(adt746xcpu, 0)
-       END OBJ(adt746xfan, 0)
-#endif /* !__OpenBSD__ */
 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
                || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
        END OBJ(apm_adapter, 0)
@@ -770,7 +743,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        END OBJ_ARG(smapi, 0, "smapi needs an argument")
                obj->data.s = strndup(arg, text_buffer_size);
        END OBJ_IF_ARG(if_smapi_bat_installed, 0, "if_smapi_bat_installed needs an argument")
-               obj->data.ifblock.s = strndup(arg, text_buffer_size);
+               obj->data.s = strndup(arg, text_buffer_size);
        END OBJ_ARG(smapi_bat_perc, 0, "smapi_bat_perc needs an argument")
                obj->data.s = strndup(arg, text_buffer_size);
        END OBJ_ARG(smapi_bat_temp, 0, "smapi_bat_temp needs an argument")
@@ -945,15 +918,14 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
 #ifdef X11
        END OBJ_ARG(lua_graph, 0, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]")
                char *buf = 0;
-               buf = scan_graph(obj, arg);
+               buf = scan_graph(obj, arg, 0);
                if (buf) {
                        obj->data.s = buf;
                } else {
                        CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
                }
        END OBJ_ARG(lua_gauge, 0, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]")
-               SIZE_DEFAULTS(gauge);
-               arg = scan_gauge(arg, &obj->a, &obj->b);
+               arg = scan_gauge(obj, arg);
                if (arg) {
                        obj->data.s = strndup(arg, text_buffer_size);
                } else {
@@ -1028,11 +1000,10 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
 #ifdef X11
        END OBJ(apcupsd_loadgraph, &update_apcupsd)
                char* buf = 0;
-               buf = scan_graph(obj, arg);
+               buf = scan_graph(obj, arg, 0);
                if (buf) free(buf);
        END OBJ(apcupsd_loadgauge, &update_apcupsd)
-               SIZE_DEFAULTS(gauge);
-               scan_gauge(arg, &obj->a, &obj->b);
+               scan_gauge(obj, arg);
 #endif /* X11 */
        END OBJ(apcupsd_charge, &update_apcupsd)
        END OBJ(apcupsd_timeleft, &update_apcupsd)
@@ -1055,7 +1026,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
 #undef __OBJ_IF
 #undef __OBJ_ARG
 #undef END
-#undef SIZE_DEFAULTS
 
        return obj;
 }
@@ -1278,6 +1248,33 @@ void free_text_objects(struct text_object *root, int internal)
                                free_sysfs_sensor(obj);
                                break;
 #endif /* __linux__ */
+                       case OBJ_pid_cmdline:
+                               free(data.s);
+                               break;
+                       case OBJ_pid_cwd:
+                               free(data.s);
+                               break;
+                       case OBJ_pid_environ:
+                               free_pid_environ(obj);
+                               break;
+                       case OBJ_pid_environ_list:
+                               free(data.s);
+                               break;
+                       case OBJ_pid_exe:
+                               free(data.s);
+                               break;
+                       case OBJ_pid_openfiles:
+                               free(data.s);
+                               break;
+                       case OBJ_pid_stderr:
+                               free(data.s);
+                               break;
+                       case OBJ_pid_stdin:
+                               free(data.s);
+                               break;
+                       case OBJ_pid_stdout:
+                               free(data.s);
+                               break;
                        case OBJ_read_tcp:
                                free_read_tcp(obj);
                                break;
@@ -1315,12 +1312,11 @@ void free_text_objects(struct text_object *root, int internal)
                        case OBJ_if_match:
                                free_text_objects(obj->sub, 1);
                                free(obj->sub);
-                               /* fall through */
+                               break;
                        case OBJ_if_existing:
                        case OBJ_if_mounted:
                        case OBJ_if_running:
-                               free(data.ifblock.s);
-                               free(data.ifblock.str);
+                               free(data.s);
                                break;
                        case OBJ_head:
                        case OBJ_tail:
@@ -1330,6 +1326,8 @@ void free_text_objects(struct text_object *root, int internal)
                        case OBJ_font:
                        case OBJ_image:
                        case OBJ_eval:
+                               free(data.s);
+                               break;
                        case OBJ_exec:
                        case OBJ_execbar:
 #ifdef X11
@@ -1349,8 +1347,6 @@ void free_text_objects(struct text_object *root, int internal)
                                free(data.s);
                                break;
                        case OBJ_if_gw:
-                               free(data.ifblock.s);
-                               free(data.ifblock.str);
                        case OBJ_gw_iface:
                        case OBJ_gw_ip:
                                free_gateway_info();
@@ -1554,8 +1550,7 @@ void free_text_objects(struct text_object *root, int internal)
                                free(data.s);
                                break;
                        case OBJ_if_smapi_bat_installed:
-                               free(data.ifblock.s);
-                               free(data.ifblock.str);
+                               free(data.s);
                                break;
 #endif /* IBM */
 #ifdef NVIDIA
@@ -1653,6 +1648,7 @@ void free_text_objects(struct text_object *root, int internal)
                                break;
 #endif /* X11 */
                }
+               if(obj->special_data) free(obj->special_data);
                free(obj);
        }
 #undef data