lcdexec: parameter support using widgets enabled (currently only marginally
documented in lcdexec.conf)
This commit is contained in:
@@ -33,7 +33,7 @@ v.0.5dev (ongoing development)
|
|||||||
* picolcd driver: overhaul USB init for more portability (M. Dolze)
|
* picolcd driver: overhaul USB init for more portability (M. Dolze)
|
||||||
+ curses driver: new option DrawBorder (Bruno Schwander)
|
+ curses driver: new option DrawBorder (Bruno Schwander)
|
||||||
* avoid sending duplicate "success" messages in response to menu_add_item
|
* avoid sending duplicate "success" messages in response to menu_add_item
|
||||||
+ lcdexec: parameter support using widgets; hidden behind compile time option
|
+ lcdexec: parameter support using widgets
|
||||||
* server core: display values in menu for all input MenuEntry types
|
* server core: display values in menu for all input MenuEntry types
|
||||||
|
|
||||||
v.0.5.2
|
v.0.5.2
|
||||||
|
|||||||
+26
-23
@@ -1,12 +1,14 @@
|
|||||||
/*
|
/* \file clients/lcdexec/lcdexec.c
|
||||||
* lcdexec.c
|
* Main file for \lcdexec, the program starter in the LCDproc suite.
|
||||||
* This file is part of lcdexec, an LCDproc client.
|
*/
|
||||||
|
|
||||||
|
/* This file is part of lcdexec, an LCDproc client.
|
||||||
*
|
*
|
||||||
* This file is released under the GNU General Public License. Refer to the
|
* This file is released under the GNU General Public License. Refer to the
|
||||||
* COPYING file distributed with this package.
|
* COPYING file distributed with this package.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2002, Joris Robijn
|
* Copyright (c) 2002, Joris Robijn
|
||||||
* Copyright (c) 2006, Peter Marschall
|
* Copyright (c) 2006-7, Peter Marschall
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -26,12 +28,14 @@
|
|||||||
|
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
|
|
||||||
|
|
||||||
#if !defined(SYSCONFDIR)
|
#if !defined(SYSCONFDIR)
|
||||||
# define SYSCONFDIR "/etc"
|
# define SYSCONFDIR "/etc"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEFAULT_CONFIGFILE SYSCONFDIR "/lcdexec.conf"
|
#define DEFAULT_CONFIGFILE SYSCONFDIR "/lcdexec.conf"
|
||||||
|
|
||||||
|
|
||||||
/** information about a process started by lcdexec */
|
/** information about a process started by lcdexec */
|
||||||
typedef struct ProcInfo {
|
typedef struct ProcInfo {
|
||||||
struct ProcInfo *next; /**< pointer to the next ProcInfo entry */
|
struct ProcInfo *next; /**< pointer to the next ProcInfo entry */
|
||||||
@@ -95,6 +99,7 @@ static int exec_command(MenuEntry *cmd);
|
|||||||
static int show_procinfo_msg(ProcInfo *p);
|
static int show_procinfo_msg(ProcInfo *p);
|
||||||
static int main_loop(void);
|
static int main_loop(void);
|
||||||
|
|
||||||
|
|
||||||
#define CHAIN(e,f) { if (e>=0) { e=(f); }}
|
#define CHAIN(e,f) { if (e>=0) { e=(f); }}
|
||||||
#define CHAIN_END(e) { if (e<0) { report(RPT_CRIT,"Critical error, abort"); exit(e); }}
|
#define CHAIN_END(e) { if (e<0) { report(RPT_CRIT,"Critical error, abort"); exit(e); }}
|
||||||
|
|
||||||
@@ -376,7 +381,6 @@ static int process_response(char *str)
|
|||||||
exec_command(entry);
|
exec_command(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if defined(LCDEXEC_PARAMS)
|
|
||||||
else if ((strcmp(argv[1], "plus") == 0) ||
|
else if ((strcmp(argv[1], "plus") == 0) ||
|
||||||
(strcmp(argv[1], "minus") == 0) ||
|
(strcmp(argv[1], "minus") == 0) ||
|
||||||
(strcmp(argv[1], "update") == 0)) {
|
(strcmp(argv[1], "update") == 0)) {
|
||||||
@@ -431,7 +435,6 @@ static int process_response(char *str)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
else {
|
else {
|
||||||
; /* Ignore other menuevents */
|
; /* Ignore other menuevents */
|
||||||
}
|
}
|
||||||
@@ -472,11 +475,9 @@ static int exec_command(MenuEntry *cmd)
|
|||||||
const char *argv[4];
|
const char *argv[4];
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
ProcInfo *p;
|
ProcInfo *p;
|
||||||
#if defined(LCDEXEC_PARAMS)
|
|
||||||
char *envp[cmd->numChildren+1];
|
char *envp[cmd->numChildren+1];
|
||||||
MenuEntry *arg;
|
MenuEntry *arg;
|
||||||
int i;
|
int i;
|
||||||
#endif
|
|
||||||
|
|
||||||
/* set argument vector */
|
/* set argument vector */
|
||||||
argv[0] = default_shell;
|
argv[0] = default_shell;
|
||||||
@@ -484,52 +485,56 @@ static int exec_command(MenuEntry *cmd)
|
|||||||
argv[2] = command;
|
argv[2] = command;
|
||||||
argv[3] = NULL;
|
argv[3] = NULL;
|
||||||
|
|
||||||
#if defined(LCDEXEC_PARAMS)
|
|
||||||
/* set environment vector: allocate & fill contents */
|
/* set environment vector: allocate & fill contents */
|
||||||
for (arg = cmd->children, i = 0; arg != NULL; arg = arg->next, i++) {
|
for (arg = cmd->children, i = 0; arg != NULL; arg = arg->next, i++) {
|
||||||
char buf[1025];
|
char buf[1025];
|
||||||
|
|
||||||
switch (arg->type) {
|
switch (arg->type) {
|
||||||
case MT_ARG_SLIDER:
|
case MT_ARG_SLIDER:
|
||||||
snprintf(buf, 1024, "%s=%d", arg->name, arg->data.slider.value);
|
snprintf(buf, sizeof(buf)-1, "%s=%d",
|
||||||
|
arg->name, arg->data.slider.value);
|
||||||
break;
|
break;
|
||||||
case MT_ARG_RING:
|
case MT_ARG_RING:
|
||||||
snprintf(buf, 1024, "%s=%s", arg->name, arg->data.ring.strings[arg->data.ring.value]);
|
snprintf(buf, sizeof(buf)-1, "%s=%s", arg->name,
|
||||||
|
arg->data.ring.strings[arg->data.ring.value]);
|
||||||
break;
|
break;
|
||||||
case MT_ARG_NUMERIC:
|
case MT_ARG_NUMERIC:
|
||||||
snprintf(buf, 1024, "%s=%d", arg->name, arg->data.numeric.value);
|
snprintf(buf, sizeof(buf)-1, "%s=%d",
|
||||||
|
arg->name, arg->data.numeric.value);
|
||||||
break;
|
break;
|
||||||
case MT_ARG_ALPHA:
|
case MT_ARG_ALPHA:
|
||||||
snprintf(buf, 1024, "%s=%s", arg->name, arg->data.alpha.value);
|
snprintf(buf, sizeof(buf)-1, "%s=%s",
|
||||||
|
arg->name, arg->data.alpha.value);
|
||||||
break;
|
break;
|
||||||
case MT_ARG_IP:
|
case MT_ARG_IP:
|
||||||
snprintf(buf, 1024, "%s=%s", arg->name, arg->data.ip.value);
|
snprintf(buf, sizeof(buf)-1, "%s=%s",
|
||||||
|
arg->name, arg->data.ip.value);
|
||||||
break;
|
break;
|
||||||
case MT_ARG_CHECKBOX:
|
case MT_ARG_CHECKBOX:
|
||||||
snprintf(buf, 1024, "%s=%d", arg->name, arg->data.checkbox.value);
|
if (arg->data.checkbox.map[arg->data.checkbox.value] != NULL)
|
||||||
|
strncpy(buf, arg->data.checkbox.map[arg->data.checkbox.value],
|
||||||
|
sizeof(buf)-1);
|
||||||
|
else
|
||||||
|
snprintf(buf, sizeof(buf)-1, "%s=%d",
|
||||||
|
arg->name, arg->data.checkbox.value);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* error ? */
|
/* error ? */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buf[1024] ='\0';
|
buf[sizeof(buf)-1] ='\0';
|
||||||
envp[i] = strdup(buf);
|
envp[i] = strdup(buf);
|
||||||
|
|
||||||
debug(RPT_DEBUG, "Environment: %s", envp[i]);
|
debug(RPT_DEBUG, "Environment: %s", envp[i]);
|
||||||
}
|
}
|
||||||
envp[cmd->numChildren] = NULL;
|
envp[cmd->numChildren] = NULL;
|
||||||
#endif
|
|
||||||
|
|
||||||
debug(RPT_DEBUG, "Executing '%s' via Shell %s", command, default_shell);
|
debug(RPT_DEBUG, "Executing '%s' via Shell %s", command, default_shell);
|
||||||
|
|
||||||
switch (pid = fork()) {
|
switch (pid = fork()) {
|
||||||
case 0:
|
case 0:
|
||||||
/* We're the child: execute the command */
|
/* We're the child: execute the command */
|
||||||
#if defined(LCDEXEC_PARAMS)
|
|
||||||
execve(argv[0], (char **) argv, envp);
|
execve(argv[0], (char **) argv, envp);
|
||||||
#else
|
|
||||||
execv(argv[0], (char **) argv);
|
|
||||||
#endif
|
|
||||||
exit(0);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -550,11 +555,9 @@ static int exec_command(MenuEntry *cmd)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(LCDEXEC_PARAMS)
|
|
||||||
/* free envp's contents */
|
/* free envp's contents */
|
||||||
for (i = 0; envp[i] != NULL; i++)
|
for (i = 0; envp[i] != NULL; i++)
|
||||||
free(envp[i]);
|
free(envp[i]);
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,76 +59,77 @@ Exec="echo P"
|
|||||||
[CmdQ]
|
[CmdQ]
|
||||||
DisplayName="Show environment"
|
DisplayName="Show environment"
|
||||||
Exec="env"
|
Exec="env"
|
||||||
# When lcdexec is compiled with compiler option -DLCDEXEC_PARAMS
|
# Now you can change parameters for commands within lcdexec.
|
||||||
# you can change parameters for commands within lcdexec.
|
|
||||||
# Parameters are handed to the program as environment variables;
|
# Parameters are handed to the program as environment variables;
|
||||||
# so they can be easily used in the Exec=... line as $XXX
|
# so they can be easily used in the Exec=... line as $XXX
|
||||||
# (e.g. "echo $SLIDER_ARG").
|
# (e.g. "echo $SLIDER_ARG").
|
||||||
# Please note: command with parameters get an action entry
|
# Please note: commands with parameters get an action entry
|
||||||
# added to the parameter menu automatically.
|
# added to end of the parameter menu automatically.
|
||||||
# Activating this entry will execute the program.
|
# Activating this action named "Apply!" will execute the program.
|
||||||
# This is IMHO not ideal, but the best idea I could come up with
|
# This is IMHO not ideal, but the best idea I could come up with.
|
||||||
# I'm open for ideas to improve it.
|
# I'm open for ideas to improve it.
|
||||||
# Here's how they are defined:
|
# Here's how paramters get defined:
|
||||||
#Parameter=SLIDER_ARG
|
Parameter=SLIDER_ARG
|
||||||
#Parameter=RING_ARG
|
Parameter=RING_ARG
|
||||||
#Parameter=NUMERIC_ARG
|
Parameter=NUMERIC_ARG
|
||||||
#Parameter=ALPHA_ARG
|
Parameter=ALPHA_ARG
|
||||||
#Parameter=CHECKBOX_ARG
|
Parameter=CHECKBOX_ARG
|
||||||
#Parameter=IP_ARG
|
Parameter=IP_ARG
|
||||||
#
|
|
||||||
#[SLIDER_ARG]
|
[SLIDER_ARG]
|
||||||
#DisplayName="Slider"
|
DisplayName="Slider"
|
||||||
## Type of argument widget [legal: Slider, Checkbox, Ring, Numeric, Alpha, IP]
|
# Type of argument widget [legal: Slider, Checkbox, Ring, Numeric, Alpha, IP]
|
||||||
#Type=Slider
|
Type=Slider
|
||||||
## inital value of the argument
|
# inital value of the argument
|
||||||
#Value=5
|
Value=5
|
||||||
## options depending on the widget type
|
# options depending on the widget type
|
||||||
#MinValue=0
|
MinValue=0
|
||||||
#MaxValue=10
|
MaxValue=10
|
||||||
#
|
|
||||||
#[CHECKBOX_ARG]
|
[CHECKBOX_ARG]
|
||||||
#DisplayName="Checkbox"
|
DisplayName="Checkbox"
|
||||||
#Type=Checkbox
|
Type=Checkbox
|
||||||
#Value=on
|
Value=on
|
||||||
#AllowGray=no
|
AllowGray=yes
|
||||||
#
|
# replacement texts for the possible values
|
||||||
#[RING_ARG]
|
OffText="off"
|
||||||
#DisplayName="Ring"
|
OnText="on"
|
||||||
#Type=Ring
|
GrayText="gray"
|
||||||
#Value=0
|
|
||||||
## list of alternative strings
|
[RING_ARG]
|
||||||
#String=Eins
|
DisplayName="Ring"
|
||||||
#String=Zwei
|
Type=Ring
|
||||||
#String=Drei
|
Value=0
|
||||||
#
|
# list of alternative strings to choose from
|
||||||
#[NUMERIC_ARG]
|
String=Eins
|
||||||
#DisplayName="Numeric"
|
String=Zwei
|
||||||
#Type=Numeric
|
String=Drei
|
||||||
#Value=5
|
|
||||||
#MinValue=0
|
[NUMERIC_ARG]
|
||||||
#MaxValue=10
|
DisplayName="Numeric"
|
||||||
#
|
Type=Numeric
|
||||||
#[ALPHA_ARG]
|
Value=5
|
||||||
#DisplayName="Alpha"
|
MinValue=0
|
||||||
#Type=Alpha
|
MaxValue=10
|
||||||
## range of characters allowed [default: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
|
|
||||||
#AllowedChars = "+-0123456789ABCDEF"
|
[ALPHA_ARG]
|
||||||
#Value=5
|
DisplayName="Alpha"
|
||||||
#MinLength=0
|
Type=Alpha
|
||||||
#MaxLength=10
|
# range of characters allowed [default: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
|
||||||
#
|
AllowedChars = "+-0123456789ABCDEF"
|
||||||
#[IP_ARG]
|
Value=5
|
||||||
#DisplayName="IP"
|
MinLength=0
|
||||||
#Type=IP
|
MaxLength=10
|
||||||
#Value=10.230.2.2
|
|
||||||
#v6=no
|
[IP_ARG]
|
||||||
|
DisplayName="IP"
|
||||||
|
Type=IP
|
||||||
|
Value=10.230.2.2
|
||||||
|
v6=no
|
||||||
|
|
||||||
|
|
||||||
# Ideas for further extensions:
|
# Ideas for further extensions (patches welcome):
|
||||||
# - shell selectable in command sections
|
# - shell selectable in command sections
|
||||||
# - type definitions instead implicit depending on Exec/Entry
|
|
||||||
# (the latter only as fallback)
|
|
||||||
# - display configurable result of a command on the display
|
# - display configurable result of a command on the display
|
||||||
# - jump to other menus depending on the output/result of a command
|
# - jump to other menus depending on the output/result of a command
|
||||||
|
|
||||||
|
|||||||
+41
-41
@@ -1,12 +1,14 @@
|
|||||||
/*
|
/** \file clients/lcdexec/menu.c
|
||||||
* menu.c
|
* Menu parsing and building functions for the \c lcdexec client
|
||||||
* This file is part of lcdexec, an LCDproc client.
|
*/
|
||||||
|
|
||||||
|
/* This file is part of lcdexec, an LCDproc client.
|
||||||
*
|
*
|
||||||
* This file is released under the GNU General Public License. Refer to the
|
* This file is released under the GNU General Public License. Refer to the
|
||||||
* COPYING file distributed with this package.
|
* COPYING file distributed with this package.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2002, Joris Robijn
|
* Copyright (c) 2002, Joris Robijn
|
||||||
* Copyright (c) 2006, Peter Marschall
|
* Copyright (c) 2006-7, Peter Marschall
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -20,11 +22,10 @@
|
|||||||
|
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
|
|
||||||
|
|
||||||
/* names for boolean and tristate values */
|
/* names for boolean and tristate values */
|
||||||
static char *boolValueName[] = { "false", "true" };
|
static char *boolValueName[] = { "false", "true" };
|
||||||
#if defined(LCDEXEC_PARAMS)
|
|
||||||
static char *triGrayValueName[] = { "off", "on", "gray" };
|
static char *triGrayValueName[] = { "off", "on", "gray" };
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* recursively read the menu hierarchy */
|
/* recursively read the menu hierarchy */
|
||||||
@@ -79,10 +80,9 @@ MenuEntry *menu_read(MenuEntry *parent, const char *name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (config_get_string(name, "Exec", 0, NULL) != NULL) {
|
else if (config_get_string(name, "Exec", 0, NULL) != NULL) {
|
||||||
#if defined(LCDEXEC_PARAMS)
|
|
||||||
MenuEntry **addr = &me->children;
|
MenuEntry **addr = &me->children;
|
||||||
const char *entryname;
|
const char *entryname;
|
||||||
#endif
|
|
||||||
// it's a command to execute
|
// it's a command to execute
|
||||||
me->type = MT_EXEC;
|
me->type = MT_EXEC;
|
||||||
|
|
||||||
@@ -93,7 +93,6 @@ MenuEntry *menu_read(MenuEntry *parent, const char *name)
|
|||||||
}
|
}
|
||||||
me->data.exec.feedback = config_get_bool(name, "Feedback", 0, 0);
|
me->data.exec.feedback = config_get_bool(name, "Feedback", 0, 0);
|
||||||
|
|
||||||
#if defined(LCDEXEC_PARAMS)
|
|
||||||
// try to read parameters
|
// try to read parameters
|
||||||
while ((entryname = config_get_string(name, "Parameter", me->numChildren, NULL)) != NULL) {
|
while ((entryname = config_get_string(name, "Parameter", me->numChildren, NULL)) != NULL) {
|
||||||
MenuEntry *entry = menu_read(me, entryname);
|
MenuEntry *entry = menu_read(me, entryname);
|
||||||
@@ -112,9 +111,7 @@ MenuEntry *menu_read(MenuEntry *parent, const char *name)
|
|||||||
// automagically add an "Apply ?" action
|
// automagically add an "Apply ?" action
|
||||||
if ((me->numChildren > 0) && (addr != NULL))
|
if ((me->numChildren > 0) && (addr != NULL))
|
||||||
*addr = menu_read(me, NULL);
|
*addr = menu_read(me, NULL);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#if defined(LCDEXEC_PARAMS)
|
|
||||||
else if (config_get_string(name, "Type", 0, NULL) != NULL) {
|
else if (config_get_string(name, "Type", 0, NULL) != NULL) {
|
||||||
// it's a command parameter
|
// it's a command parameter
|
||||||
const char *type;
|
const char *type;
|
||||||
@@ -168,7 +165,8 @@ MenuEntry *menu_read(MenuEntry *parent, const char *name)
|
|||||||
me->data.alpha.value = strdup(config_get_string(name, "Value", 0, ""));
|
me->data.alpha.value = strdup(config_get_string(name, "Value", 0, ""));
|
||||||
me->data.alpha.minlen = config_get_int(name, "MinLength", 0, 0);
|
me->data.alpha.minlen = config_get_int(name, "MinLength", 0, 0);
|
||||||
me->data.alpha.maxlen = config_get_int(name, "MaxLength", 0, 100);
|
me->data.alpha.maxlen = config_get_int(name, "MaxLength", 0, 100);
|
||||||
me->data.alpha.allowed_chars = strdup(config_get_string(name, "AllowedChars", 0, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
me->data.alpha.allowed = strdup(config_get_string(name, "AllowedChars", 0,
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
||||||
}
|
}
|
||||||
else if (strcasecmp(type, "ip") == 0) {
|
else if (strcasecmp(type, "ip") == 0) {
|
||||||
me->type = MT_ARG_IP;
|
me->type = MT_ARG_IP;
|
||||||
@@ -177,12 +175,21 @@ MenuEntry *menu_read(MenuEntry *parent, const char *name)
|
|||||||
me->data.ip.v6 = config_get_bool(name, "Value", 0, 0);
|
me->data.ip.v6 = config_get_bool(name, "Value", 0, 0);
|
||||||
}
|
}
|
||||||
else if (strcasecmp(type, "checkbox") == 0) {
|
else if (strcasecmp(type, "checkbox") == 0) {
|
||||||
|
const char *tmp;
|
||||||
|
|
||||||
me->type = MT_ARG_CHECKBOX;
|
me->type = MT_ARG_CHECKBOX;
|
||||||
|
|
||||||
me->data.checkbox.allow_gray = config_get_bool(name, "AllowGray", 0, 0);
|
me->data.checkbox.allow_gray = config_get_bool(name, "AllowGray", 0, 0);
|
||||||
me->data.checkbox.value = (me->data.checkbox.allow_gray)
|
me->data.checkbox.value = (me->data.checkbox.allow_gray)
|
||||||
? config_get_tristate(name, "Value", 0, "gray", 0)
|
? config_get_tristate(name, "Value", 0, "gray", 0)
|
||||||
: config_get_bool(name, "Value", 0, 0);
|
: config_get_bool(name, "Value", 0, 0);
|
||||||
|
// get replacement strings for different values
|
||||||
|
tmp = config_get_string(name, "OffText", 0, NULL);
|
||||||
|
me->data.checkbox.map[0] = (tmp != NULL) ? strdup(tmp) : NULL;
|
||||||
|
tmp = config_get_string(name, "OnText", 0, NULL);
|
||||||
|
me->data.checkbox.map[1] = (tmp != NULL) ? strdup(tmp) : NULL;
|
||||||
|
tmp = config_get_string(name, "GrayText", 0, NULL);
|
||||||
|
me->data.checkbox.map[2] = (tmp != NULL) ? strdup(tmp) : NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
report(RPT_DEBUG, "illegal parameter type");
|
report(RPT_DEBUG, "illegal parameter type");
|
||||||
@@ -190,7 +197,6 @@ MenuEntry *menu_read(MenuEntry *parent, const char *name)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
else {
|
else {
|
||||||
report(RPT_DEBUG, "unknown menu entry type");
|
report(RPT_DEBUG, "unknown menu entry type");
|
||||||
//menu_free(me);
|
//menu_free(me);
|
||||||
@@ -267,7 +273,6 @@ int menu_sock_send(MenuEntry *me, MenuEntry *parent, int sock)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MT_EXEC:
|
case MT_EXEC:
|
||||||
#if defined(LCDEXEC_PARAMS)
|
|
||||||
if (me->children == NULL) {
|
if (me->children == NULL) {
|
||||||
if (sock_printf(sock, "menu_add_item \"%s\" \"%d\" action \"%s\"\n",
|
if (sock_printf(sock, "menu_add_item \"%s\" \"%d\" action \"%s\"\n",
|
||||||
parent_id, me->id, me->displayname) < 0)
|
parent_id, me->id, me->displayname) < 0)
|
||||||
@@ -290,17 +295,7 @@ int menu_sock_send(MenuEntry *me, MenuEntry *parent, int sock)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
if (sock_printf(sock, "menu_add_item \"%s\" \"%d\" action \"%s\"\n",
|
|
||||||
parent_id, me->id, me->displayname) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (sock_printf(sock, "menu_set_item \"%s\" \"%d\" -menu_result quit\n",
|
|
||||||
parent_id, me->id) < 0)
|
|
||||||
return -1;
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
#if defined(LCDEXEC_PARAMS)
|
|
||||||
case MT_ARG_SLIDER:
|
case MT_ARG_SLIDER:
|
||||||
if (sock_printf(sock, "menu_add_item \"%s\" \"%d\" slider -text \"%s\""
|
if (sock_printf(sock, "menu_add_item \"%s\" \"%d\" slider -text \"%s\""
|
||||||
" -value %d -minvalue %d -maxvalue %d"
|
" -value %d -minvalue %d -maxvalue %d"
|
||||||
@@ -372,7 +367,7 @@ int menu_sock_send(MenuEntry *me, MenuEntry *parent, int sock)
|
|||||||
me->data.alpha.value,
|
me->data.alpha.value,
|
||||||
me->data.alpha.minlen,
|
me->data.alpha.minlen,
|
||||||
me->data.alpha.maxlen,
|
me->data.alpha.maxlen,
|
||||||
me->data.alpha.allowed_chars) <0)
|
me->data.alpha.allowed) <0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (me->next == NULL) {
|
if (me->next == NULL) {
|
||||||
@@ -418,7 +413,6 @@ int menu_sock_send(MenuEntry *me, MenuEntry *parent, int sock)
|
|||||||
parent_id, me->id) < 0)
|
parent_id, me->id) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -464,9 +458,10 @@ const char *menu_command(MenuEntry *me)
|
|||||||
void menu_free(MenuEntry *me)
|
void menu_free(MenuEntry *me)
|
||||||
{
|
{
|
||||||
if (me != NULL) {
|
if (me != NULL) {
|
||||||
switch (me->type) {
|
MenuEntry *entry;
|
||||||
MenuEntry *entry;
|
int i;
|
||||||
|
|
||||||
|
switch (me->type) {
|
||||||
case MT_EXEC:
|
case MT_EXEC:
|
||||||
if (me->data.exec.command != NULL)
|
if (me->data.exec.command != NULL)
|
||||||
free(me->data.exec.command);
|
free(me->data.exec.command);
|
||||||
@@ -482,7 +477,6 @@ void menu_free(MenuEntry *me)
|
|||||||
}
|
}
|
||||||
me->children = NULL;
|
me->children = NULL;
|
||||||
break;
|
break;
|
||||||
#if defined(LCDEXEC_PARAMS)
|
|
||||||
case MT_ARG_SLIDER:
|
case MT_ARG_SLIDER:
|
||||||
if (me->data.slider.mintext != NULL)
|
if (me->data.slider.mintext != NULL)
|
||||||
free(me->data.slider.mintext);
|
free(me->data.slider.mintext);
|
||||||
@@ -506,16 +500,22 @@ void menu_free(MenuEntry *me)
|
|||||||
if (me->data.alpha.value != NULL)
|
if (me->data.alpha.value != NULL)
|
||||||
free(me->data.alpha.value);
|
free(me->data.alpha.value);
|
||||||
me->data.alpha.value = NULL;
|
me->data.alpha.value = NULL;
|
||||||
if (me->data.alpha.allowed_chars != NULL)
|
if (me->data.alpha.allowed != NULL)
|
||||||
free(me->data.alpha.allowed_chars);
|
free(me->data.alpha.allowed);
|
||||||
me->data.alpha.allowed_chars = NULL;
|
me->data.alpha.allowed = NULL;
|
||||||
break;
|
break;
|
||||||
case MT_ARG_IP:
|
case MT_ARG_IP:
|
||||||
if (me->data.ip.value != NULL)
|
if (me->data.ip.value != NULL)
|
||||||
free(me->data.ip.value);
|
free(me->data.ip.value);
|
||||||
me->data.ip.value = NULL;
|
me->data.ip.value = NULL;
|
||||||
break;
|
break;
|
||||||
#endif
|
case MT_ARG_CHECKBOX:
|
||||||
|
for (i = 0; i < sizeof(me->data.checkbox.map)/sizeof(me->data.checkbox.map[0]); i++) {
|
||||||
|
if (me->data.checkbox.map[i] != NULL) {
|
||||||
|
free(me->data.checkbox.map[i]);
|
||||||
|
me->data.checkbox.map[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -562,11 +562,10 @@ void menu_dump(MenuEntry *me)
|
|||||||
for (entry = me->children; entry != NULL; entry = entry->next)
|
for (entry = me->children; entry != NULL; entry = entry->next)
|
||||||
menu_dump(entry);
|
menu_dump(entry);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MT_EXEC:
|
case MT_EXEC:
|
||||||
report(RPT_DEBUG, "Exec=\"%s\"", me->data.exec.command);
|
report(RPT_DEBUG, "Exec=\"%s\"", me->data.exec.command);
|
||||||
report(RPT_DEBUG, "Feedback=%s", boolValueName[me->data.exec.feedback]);
|
report(RPT_DEBUG, "Feedback=%s", boolValueName[me->data.exec.feedback]);
|
||||||
#if defined(LCDEXEC_PARAMS)
|
|
||||||
// dump entry's parameter referencess
|
// dump entry's parameter referencess
|
||||||
for (entry = me->children; entry != NULL; entry = entry->next)
|
for (entry = me->children; entry != NULL; entry = entry->next)
|
||||||
report(RPT_DEBUG, "Parameter=%s", entry->name);
|
report(RPT_DEBUG, "Parameter=%s", entry->name);
|
||||||
@@ -575,11 +574,7 @@ void menu_dump(MenuEntry *me)
|
|||||||
// dump entry's parameters
|
// dump entry's parameters
|
||||||
for (entry = me->children; entry != NULL; entry = entry->next)
|
for (entry = me->children; entry != NULL; entry = entry->next)
|
||||||
menu_dump(entry);
|
menu_dump(entry);
|
||||||
#else
|
|
||||||
report(RPT_DEBUG, "");
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
#if defined(LCDEXEC_PARAMS)
|
|
||||||
case MT_ARG_SLIDER:
|
case MT_ARG_SLIDER:
|
||||||
report(RPT_DEBUG, "Type=slider");
|
report(RPT_DEBUG, "Type=slider");
|
||||||
report(RPT_DEBUG, "Value=%d", me->data.slider.value);
|
report(RPT_DEBUG, "Value=%d", me->data.slider.value);
|
||||||
@@ -611,7 +606,7 @@ void menu_dump(MenuEntry *me)
|
|||||||
case MT_ARG_ALPHA:
|
case MT_ARG_ALPHA:
|
||||||
report(RPT_DEBUG, "Type:=lpha");
|
report(RPT_DEBUG, "Type:=lpha");
|
||||||
report(RPT_DEBUG, "Value=\"%s\"", me->data.alpha.value);
|
report(RPT_DEBUG, "Value=\"%s\"", me->data.alpha.value);
|
||||||
report(RPT_DEBUG, "AllowedChars=\"%s\"", me->data.alpha.allowed_chars);
|
report(RPT_DEBUG, "AllowedChars=\"%s\"", me->data.alpha.allowed);
|
||||||
report(RPT_DEBUG, "");
|
report(RPT_DEBUG, "");
|
||||||
break;
|
break;
|
||||||
case MT_ARG_IP:
|
case MT_ARG_IP:
|
||||||
@@ -624,9 +619,14 @@ void menu_dump(MenuEntry *me)
|
|||||||
report(RPT_DEBUG, "Type=ip");
|
report(RPT_DEBUG, "Type=ip");
|
||||||
report(RPT_DEBUG, "Value=%s", triGrayValueName[me->data.checkbox.value]);
|
report(RPT_DEBUG, "Value=%s", triGrayValueName[me->data.checkbox.value]);
|
||||||
report(RPT_DEBUG, "AllowGray=%s", boolValueName[me->data.checkbox.allow_gray]);
|
report(RPT_DEBUG, "AllowGray=%s", boolValueName[me->data.checkbox.allow_gray]);
|
||||||
|
if (me->data.checkbox.map[0] != NULL)
|
||||||
|
report(RPT_DEBUG, "OffText=%s", me->data.checkbox.map[0]);
|
||||||
|
if (me->data.checkbox.map[1] != NULL)
|
||||||
|
report(RPT_DEBUG, "OnText=%s", me->data.checkbox.map[1]);
|
||||||
|
if (me->data.checkbox.map[2] != NULL)
|
||||||
|
report(RPT_DEBUG, "GrayText=%s", me->data.checkbox.map[2]);
|
||||||
report(RPT_DEBUG, "");
|
report(RPT_DEBUG, "");
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
default:
|
default:
|
||||||
report(RPT_DEBUG, "ERROR: unknown menu entry type");
|
report(RPT_DEBUG, "ERROR: unknown menu entry type");
|
||||||
break;
|
break;
|
||||||
|
|||||||
+42
-42
@@ -8,13 +8,13 @@
|
|||||||
* COPYING file distributed with this package.
|
* COPYING file distributed with this package.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2002, Joris Robijn
|
* Copyright (c) 2002, Joris Robijn
|
||||||
* Copyright (c) 2006, Peter Marschall
|
* Copyright (c) 2006-7, Peter Marschall
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LCDEXEC_MENU_H
|
#ifndef LCDEXEC_MENU_H
|
||||||
#define LCDEXEC_MENU_H
|
#define LCDEXEC_MENU_H
|
||||||
|
|
||||||
|
/* boolean values */
|
||||||
#ifndef TRUE
|
#ifndef TRUE
|
||||||
# define TRUE 1
|
# define TRUE 1
|
||||||
#endif
|
#endif
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
# define FALSE 0
|
# define FALSE 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/** Symbolic names for the types of a MenuEntry */
|
/** Symbolic names for the types of a MenuEntry */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MT_UNKNOWN = 0x00, /**< Unknown MenuEntry type. */
|
MT_UNKNOWN = 0x00, /**< Unknown MenuEntry type. */
|
||||||
@@ -29,7 +30,7 @@ typedef enum {
|
|||||||
MT_EXEC = 0x20, /**< MenuEntry representing an executable command. */
|
MT_EXEC = 0x20, /**< MenuEntry representing an executable command. */
|
||||||
MT_ARGUMENT = 0x40, /**< Mask denoting a parameter of any type */
|
MT_ARGUMENT = 0x40, /**< Mask denoting a parameter of any type */
|
||||||
MT_AUTOMATIC = 0x80, /**< BitFlag denoting automatically generated entries */
|
MT_AUTOMATIC = 0x80, /**< BitFlag denoting automatically generated entries */
|
||||||
#if defined(LCDEXEC_PARAMS)
|
|
||||||
MT_ARG_SLIDER = 0x41, /**< MenuEntry representing a slider parameter. */
|
MT_ARG_SLIDER = 0x41, /**< MenuEntry representing a slider parameter. */
|
||||||
MT_ARG_RING = 0x42, /**< MenuEntry representing a ring parameter. */
|
MT_ARG_RING = 0x42, /**< MenuEntry representing a ring parameter. */
|
||||||
MT_ARG_NUMERIC = 0x43, /**< MenuEntry representing a numeric input parameter. */
|
MT_ARG_NUMERIC = 0x43, /**< MenuEntry representing a numeric input parameter. */
|
||||||
@@ -37,60 +38,59 @@ typedef enum {
|
|||||||
MT_ARG_IP = 0x45, /**< MenuEntry representing a IP input parameter. */
|
MT_ARG_IP = 0x45, /**< MenuEntry representing a IP input parameter. */
|
||||||
MT_ARG_CHECKBOX = 0x46, /**< MenuEntry representing a checkbox input parameter. */
|
MT_ARG_CHECKBOX = 0x46, /**< MenuEntry representing a checkbox input parameter. */
|
||||||
MT_ARG_ACTION = 0x47, /**< MenuEntry representing a checkbox input parameter. */
|
MT_ARG_ACTION = 0x47, /**< MenuEntry representing a checkbox input parameter. */
|
||||||
#endif
|
|
||||||
} MenuType;
|
} MenuType;
|
||||||
|
|
||||||
|
|
||||||
|
/** Data structure to hold a menu entry in \c lcdexec */
|
||||||
typedef struct menu_entry {
|
typedef struct menu_entry {
|
||||||
|
// Variables necessary for multiple/all types
|
||||||
char *name; /**< Name of the menu entry (from section name). */
|
char *name; /**< Name of the menu entry (from section name). */
|
||||||
char *displayname; /**< isible name of the entry. */
|
char *displayname; /**< Visible name of the entry. */
|
||||||
int id; /**< Internal ID of the entry. */
|
int id; /**< Internal ID of the entry. */
|
||||||
MenuType type; /**< Type of the entry. */
|
MenuType type; /**< Type of the entry. */
|
||||||
struct menu_entry *parent; /**< Parent menu entry */
|
struct menu_entry *parent; /**< Parent menu entry. */
|
||||||
int numChildren; /**< # of child entries */
|
int numChildren; /**< # of child entries. */
|
||||||
|
struct menu_entry *children; /**< Subordinate menu entries (for type \c MT_MENU & \c MT_EXEC). */
|
||||||
|
struct menu_entry *next; /**< Next sibling menu entry (for type \c MT_MENU). */
|
||||||
|
|
||||||
// variables necessary for multiple types
|
// Variables specific to one special type
|
||||||
struct menu_entry *children; /**< Subordinate menu entries (for MenuType \c MT_MENU & \c MT_EXEC). */
|
union data {
|
||||||
struct menu_entry *next; /**< Next sibling menu entry (for MenuType \c MT_MENU). */
|
struct exec{ // elements necessary for type MT_EXEC
|
||||||
|
char *command; /**< Command to execute. */
|
||||||
union {
|
int feedback; /**< Feedback flag. */
|
||||||
struct { // elements necessary for type MT_EXEC
|
|
||||||
char *command; /**< Command to execute (for MenuType \c exec). */
|
|
||||||
int feedback; /**< Feedback option (for MenuType \c exec). */
|
|
||||||
} exec;
|
} exec;
|
||||||
#if defined(LCDEXEC_PARAMS)
|
struct slider { // elements necessary for type MT_ARG_SLIDER
|
||||||
struct { // elements necessary for type MT_ARG_SLIDER
|
int value; /**< Numeric value of slider. */
|
||||||
int value;
|
int minval; /**< Minimal allowed value. */
|
||||||
int minval;
|
int maxval; /**< Maximal allowed value. */
|
||||||
int maxval;
|
int stepsize; /**< Increments/decrement for value. */
|
||||||
int stepsize;
|
char *mintext; /**< Label for the min. value. */
|
||||||
char *mintext;
|
char *maxtext; /**< Label for the max. value. */
|
||||||
char *maxtext;
|
|
||||||
} slider;
|
} slider;
|
||||||
struct { // elements necessary for type MT_ARG_RING
|
struct ring { // elements necessary for type MT_ARG_RING
|
||||||
int value;
|
int value; /**< Index into list of alternatives. */
|
||||||
char **strings;
|
char **strings; /**< List of alternatives. */
|
||||||
} ring;
|
} ring;
|
||||||
struct { // elements necessary for type MT_ARG_NUMERIC
|
struct numeric { // elements necessary for type MT_ARG_NUMERIC
|
||||||
int value;
|
int value; /**< Numeric input value. */
|
||||||
int minval;
|
int minval; /**< Minimal allowed value. */
|
||||||
int maxval;
|
int maxval; /**< Maximal allowed value. */
|
||||||
} numeric;
|
} numeric;
|
||||||
struct { // elements necessary for type MT_ARG_ALPHA
|
struct alpha { // elements necessary for type MT_ARG_ALPHA
|
||||||
char *value;
|
char *value; /**< Text value. */
|
||||||
int minlen;
|
int minlen; /**< Maximal allowed length. */
|
||||||
int maxlen;
|
int maxlen; /**< Minimal required length. */
|
||||||
char *allowed_chars;
|
char *allowed; /**< Characters allowed in input. */
|
||||||
} alpha;
|
} alpha;
|
||||||
struct { // elements necessary for type MT_ARG_IP
|
struct ip { // elements necessary for type MT_ARG_IP
|
||||||
char *value;
|
char *value; /**< IP address value. */
|
||||||
int v6;
|
int v6; /**< Flag: use IPv6 editing logic. */
|
||||||
} ip;
|
} ip;
|
||||||
struct { // elements necessary for type MT_ARG_CHECKBOX
|
struct checkbox { // elements necessary for type MT_ARG_CHECKBOX
|
||||||
int value;
|
int value; /**< Checkbox value. */
|
||||||
int allow_gray;
|
int allow_gray; /**< Flag for tristate chechboxes. */
|
||||||
|
char *map[3]; /**< Replacement strings for each value. */
|
||||||
} checkbox;
|
} checkbox;
|
||||||
#endif
|
|
||||||
} data;
|
} data;
|
||||||
} MenuEntry;
|
} MenuEntry;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user