Add optional argument to $acpiacadapter
[monky] / src / core.c
index e1083fe..68997ad 100644 (file)
@@ -10,7 +10,7 @@
  * Please see COPYING for details
  *
  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
- * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
  *     (see AUTHORS)
  * All rights reserved.
  *
@@ -157,6 +157,22 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        OBJ(acpitemp, 0)
                obj->data.i = open_acpi_temperature(arg);
        END OBJ(acpiacadapter, 0)
+               if(arg) {
+#ifdef __linux__
+                       if(strpbrk(arg, "/.") != NULL) {
+                               /* 
+                                * a bit of paranoia. screen out funky paths
+                                * i hope no device will have a '.' in its name
+                                */
+                               NORM_ERR("acpiacadapter: arg must not contain '/' or '.'");
+                       } else 
+                               obj->data.opaque = strdup(arg);
+#else
+                       NORM_ERR("acpiacadapter: arg is only used on linux");
+#endif
+               }
+               if(! obj->data.opaque)
+                       obj->data.opaque = strdup("AC");
 #endif /* !__OpenBSD__ */
        END OBJ(freq, 0)
                get_cpu_count();
@@ -1196,9 +1212,9 @@ int extract_variable_text_internal(struct text_object *retval, const char *const
        s = orig_p = p;
 
        if (strcmp(p, const_p)) {
-               DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
+               DBGP2("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p);
        } else {
-               DBGP("no templates to replace");
+               DBGP2("no templates to replace");
        }
 
        memset(retval, 0, sizeof(struct text_object));
@@ -1250,7 +1266,7 @@ int extract_variable_text_internal(struct text_object *retval, const char *const
                                }
 
                                /* copy variable to buffer */
-                               len = (p - s > text_buffer_size-1) ? text_buffer_size-1 : (p - s);
+                               len = ((unsigned int) (p - s) > text_buffer_size - 1) ? text_buffer_size - 1 : (unsigned int) (p - s);
                                strncpy(buf, s, len);
                                buf[len] = '\0';
 
@@ -1351,6 +1367,9 @@ void free_text_objects(struct text_object *root, int internal)
                        case OBJ_acpitemp:
                                close(data.i);
                                break;
+                       case OBJ_acpiacadapter:
+                               free(data.opaque);
+                               break;
 #endif /* !__OpenBSD__ */
 #ifdef __linux__
                        case OBJ_i2c: