Extend commit 25680305095bfcedaa46cb017182544183ab743b to the whole cpu object.
[monky] / src / text_object.c
index e473e67..7bc625b 100644 (file)
@@ -1,4 +1,7 @@
-/* Conky, a system monitor, based on torsmo
+/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
+ * vim: ts=4 sw=4 noet ai cindent syntax=c
+ *
+ * Conky, a system monitor, based on torsmo
  *
  * Any original torsmo code is licensed under the BSD license
  *
@@ -6,8 +9,7 @@
  *
  * Please see COPYING for details
  *
- * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2008 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
  *     (see AUTHORS)
  * All rights reserved.
  *
@@ -25,7 +27,9 @@
  *
  */
 #include "text_object.h"
-#include "conky.h"     /* not as worse: only for the printing macros */
+#include "logging.h"
+#include <stdlib.h>
+#include <stdio.h>
 
 /* text_object_list
  *
@@ -51,7 +55,7 @@ int append_object(struct text_object *root, struct text_object *obj)
 
        if (end) {
                if (end->next)
-                       CRIT_ERR("huston, we have a lift-off");
+                       CRIT_ERR(NULL, NULL, "huston, we have a lift-off");
                end->next = obj;
        } else {
                root->next = obj;
@@ -85,12 +89,6 @@ struct ifblock_stack_obj {
        struct ifblock_stack_obj *next;
 };
 
-/* top of the internal ifblock stack
- * initially contains only one "object", i.e. a NULL pointer
- * indicating the end of the stack.
- */
-static struct ifblock_stack_obj *ifblock_stack_top = NULL;
-
 /* push an ifblock object onto the stack
  * in fact, this does a lot more:
  * - IFBLOCK_IF is just pushed onto the stack
@@ -100,63 +98,64 @@ static struct ifblock_stack_obj *ifblock_stack_top = NULL;
  *   object in the stack and then triggers stack popping of
  *   any optional IFBLOCK_ELSE along with it's IFBLOCK_IF
  */
-static int push_ifblock(struct text_object *obj, enum ifblock_type type)
+static int push_ifblock(struct ifblock_stack_obj **ifblock_stack_top,
+                        struct text_object *obj, enum ifblock_type type)
 {
        struct ifblock_stack_obj *stackobj;
 
        switch (type) {
                case IFBLOCK_ENDIF:
-                       if (!ifblock_stack_top)
-                               CRIT_ERR("got an endif without matching if");
-                       ifblock_stack_top->obj->data.ifblock.next = obj;
+                       if (!(*ifblock_stack_top))
+                               CRIT_ERR(NULL, NULL, "got an endif without matching if");
+                       (*ifblock_stack_top)->obj->ifblock_next = obj;
                        /* if there's some else in between, remove and free it */
-                       if (ifblock_stack_top->type == IFBLOCK_ELSE) {
-                               stackobj = ifblock_stack_top;
-                               ifblock_stack_top = stackobj->next;
+                       if ((*ifblock_stack_top)->type == IFBLOCK_ELSE) {
+                               stackobj = *ifblock_stack_top;
+                               *ifblock_stack_top = stackobj->next;
                                free(stackobj);
                        }
                        /* finally remove and free the if object */
-                       stackobj = ifblock_stack_top;
-                       ifblock_stack_top = stackobj->next;
+                       stackobj = *ifblock_stack_top;
+                       *ifblock_stack_top = stackobj->next;
                        free(stackobj);
                        break;
                case IFBLOCK_ELSE:
-                       if (!ifblock_stack_top)
-                               CRIT_ERR("got an else without matching if");
-                       ifblock_stack_top->obj->data.ifblock.next = obj;
+                       if (!(*ifblock_stack_top))
+                               CRIT_ERR(NULL, NULL, "got an else without matching if");
+                       (*ifblock_stack_top)->obj->ifblock_next = obj;
                        /* fall through */
                case IFBLOCK_IF:
                        stackobj = malloc(sizeof(struct ifblock_stack_obj));
                        stackobj->type = type;
                        stackobj->obj = obj;
-                       stackobj->next = ifblock_stack_top;
-                       ifblock_stack_top = stackobj;
+                       stackobj->next = *ifblock_stack_top;
+                       *ifblock_stack_top = stackobj;
                        break;
                default:
-                       CRIT_ERR("push_ifblock() missuse detected!");
+                       CRIT_ERR(NULL, NULL, "push_ifblock() missuse detected!");
        }
        return 0;
 }
 
 /* public functions for client use */
 
-int obj_be_ifblock_if(struct text_object *obj)
+int obj_be_ifblock_if(void **opaque, struct text_object *obj)
 {
-       return push_ifblock(obj, IFBLOCK_IF);
+       return push_ifblock((struct ifblock_stack_obj **)opaque, obj, IFBLOCK_IF);
 }
-int obj_be_ifblock_else(struct text_object *obj)
+int obj_be_ifblock_else(void **opaque, struct text_object *obj)
 {
-       return push_ifblock(obj, IFBLOCK_ELSE);
+       return push_ifblock((struct ifblock_stack_obj **)opaque, obj, IFBLOCK_ELSE);
 }
-int obj_be_ifblock_endif(struct text_object *obj)
+int obj_be_ifblock_endif(void **opaque, struct text_object *obj)
 {
-       return push_ifblock(obj, IFBLOCK_ENDIF);
+       return push_ifblock((struct ifblock_stack_obj **)opaque, obj, IFBLOCK_ENDIF);
 }
 
 /* check if ifblock stack is empty
  * if so, return true (!= 0)
  */
-int ifblock_stack_empty(void)
+int ifblock_stack_empty(void **opaque)
 {
-       return ifblock_stack_top == NULL;
+       return *opaque == NULL;
 }