summaryrefslogtreecommitdiff
path: root/util_theme.c
diff options
context:
space:
mode:
Diffstat (limited to 'util_theme.c')
-rw-r--r--util_theme.c79
1 files changed, 38 insertions, 41 deletions
diff --git a/util_theme.c b/util_theme.c
index e003e2c3d05f..caf62852e9f3 100644
--- a/util_theme.c
+++ b/util_theme.c
@@ -100,7 +100,7 @@ static struct property p[NPROPERTY] = {
{ "theme.button.f_shortcutcolor", COLOR, &t.button.f_shortcutcolor}
};
-static char *color[8] = {
+static const char *color[8] = {
"black",
"red",
"green",
@@ -111,7 +111,15 @@ static char *color[8] = {
"white"
};
-int savetheme(const char *file, char *errbuf, const char *version)
+#define EXIT_FMTERROR(fmt, ...) do { \
+ bsddialog_end(); \
+ printf("Error: "); \
+ printf(fmt, __VA_ARGS__); \
+ printf(".\n"); \
+ exit (255); \
+} while (0)
+
+void savetheme(const char *file, const char *version)
{
int i;
unsigned int flags;
@@ -119,20 +127,14 @@ int savetheme(const char *file, char *errbuf, const char *version)
time_t clock;
FILE *fp;
- if (bsddialog_get_theme(&t) != BSDDIALOG_OK) {
- sprintf(errbuf, "Cannot save theme: %s", bsddialog_geterror());
- return (BSDDIALOG_ERROR);
- }
+ if (bsddialog_get_theme(&t) != BSDDIALOG_OK)
+ EXIT_FMTERROR("cannot save theme: %s", bsddialog_geterror());
- if(time(&clock) < 0) {
- sprintf(errbuf, "Cannot save profile (getting current time)");
- return (BSDDIALOG_ERROR);
- }
+ if(time(&clock) < 0)
+ EXIT_FMTERROR("%s", "cannot save profile getting current time");
- if ((fp = fopen(file, "w")) == NULL) {
- sprintf(errbuf, "Cannot open %s to save profile", file);
- return (BSDDIALOG_ERROR);
- }
+ if ((fp = fopen(file, "w")) == NULL)
+ EXIT_FMTERROR("cannot open %s to save profile", file);
fprintf(fp, "### bsddialog theme - %s", ctime(&clock));
fputs("# Refer to bsddialog(3) manual for theme.* properties\n", fp);
@@ -167,11 +169,15 @@ int savetheme(const char *file, char *errbuf, const char *version)
}
fclose(fp);
+}
- return (BSDDIALOG_OK);
+void setdeftheme(enum bsddialog_default_theme theme)
+{
+ if (bsddialog_set_default_theme(theme) != BSDDIALOG_OK)
+ EXIT_FMTERROR("%s", bsddialog_geterror());
}
-int loadtheme(const char *file, char *errbuf)
+void loadtheme(const char *file)
{
bool boolvalue;
char charvalue, *value;
@@ -181,21 +187,16 @@ int loadtheme(const char *file, char *errbuf)
enum bsddialog_color bg, fg;
FILE *fp;
- if (bsddialog_get_theme(&t) != BSDDIALOG_OK) {
- sprintf(errbuf, "Cannot get current theme: %s",
+ if (bsddialog_get_theme(&t) != BSDDIALOG_OK)
+ EXIT_FMTERROR("Cannot get current theme: %s",
bsddialog_geterror());
- return (BSDDIALOG_ERROR);
- }
- if((fp = fopen(file, "r")) == NULL) {
- sprintf(errbuf, "Cannot open theme \"%s\"", file);
- return (BSDDIALOG_ERROR);
- }
+ if((fp = fopen(file, "r")) == NULL)
+ EXIT_FMTERROR("Cannot open theme \"%s\"", file);
-#define RETURN_ERROR(name, error) do { \
- sprintf(errbuf, "%s for \"%s\"", error, name); \
+#define EXIT_ERROR(name, error) do { \
fclose(fp); \
- return (BSDDIALOG_ERROR); \
+ EXIT_FMTERROR("%s for \"%s\"", error, name); \
} while (0)
while(fgets(line, BUFSIZ, fp) != NULL) {
@@ -211,7 +212,7 @@ int loadtheme(const char *file, char *errbuf)
if (i >= NPROPERTY) {
if (strcmp(name, "version") == 0)
continue;
- RETURN_ERROR(name, "Unknown theme property name");
+ EXIT_ERROR(name, "Unknown theme property name");
}
switch (p[i].type) {
case CHAR:
@@ -219,17 +220,17 @@ int loadtheme(const char *file, char *errbuf)
value[0] == '\0')
value++;
if (sscanf(value, "%c", &charvalue) != 1)
- RETURN_ERROR(p[i].name, "Cannot get a char");
+ EXIT_ERROR(p[i].name, "Cannot get a char");
*((int*)p[i].value) = charvalue;
break;
case INT:
if (sscanf(value, "%d", &intvalue) != 1)
- RETURN_ERROR(p[i].name, "Cannot get a int");
+ EXIT_ERROR(p[i].name, "Cannot get a int");
*((int*)p[i].value) = intvalue;
break;
case UINT:
if (sscanf(value, "%u", &uintvalue) != 1)
- RETURN_ERROR(p[i].name, "Cannot get a uint");
+ EXIT_ERROR(p[i].name, "Cannot get a uint");
*((unsigned int*)p[i].value) = uintvalue;
break;
case BOOL:
@@ -239,19 +240,19 @@ int loadtheme(const char *file, char *errbuf)
break;
case COLOR:
if (sscanf(value, "%s %s", c1, c2) != 2)
- RETURN_ERROR(p[i].name, "Cannot get 2 colors");
+ EXIT_ERROR(p[i].name, "Cannot get 2 colors");
/* Foreground */
for (j = 0; j < 8 ; j++)
if ((strstr(c1, color[j])) != NULL)
break;
if ((fg = j) > 7)
- RETURN_ERROR(p[i].name, "Bad foreground");
+ EXIT_ERROR(p[i].name, "Bad foreground");
/* Background */
for (j = 0; j < 8 ; j++)
if ((value = strstr(c2, color[j])) != NULL)
break;
if ((bg = j) > 7)
- RETURN_ERROR(p[i].name, "Bad background");
+ EXIT_ERROR(p[i].name, "Bad background");
/* Flags */
flags = 0;
if (strstr(value, "bold") != NULL)
@@ -268,11 +269,9 @@ int loadtheme(const char *file, char *errbuf)
fclose(fp);
bsddialog_set_theme(&t);
-
- return (BSDDIALOG_OK);
}
-int bikeshed(struct bsddialog_conf *conf, char *errbuf)
+void bikeshed(struct bsddialog_conf *conf)
{
int margin, i;
int colors[8] = {0, 0, 0, 0 ,0 ,0 , 0, 0};
@@ -284,7 +283,7 @@ int bikeshed(struct bsddialog_conf *conf, char *errbuf)
/* theme */
if (bsddialog_get_theme(&t) != BSDDIALOG_OK)
- return (BSDDIALOG_ERROR);
+ EXIT_FMTERROR("%s", bsddialog_geterror());
for (i = 0; i < 6; i++) {
do {
@@ -339,7 +338,7 @@ int bikeshed(struct bsddialog_conf *conf, char *errbuf)
t.button.shortcutcolor = bsddialog_color(col[1], col[5], 0);
if (bsddialog_set_theme(&t))
- return (BSDDIALOG_ERROR);
+ EXIT_FMTERROR("%s", bsddialog_geterror());
/* conf */
conf->button.always_active = (rand() % 2 == 0) ? true : false;
@@ -351,6 +350,4 @@ int bikeshed(struct bsddialog_conf *conf, char *errbuf)
memset(title + strlen(title), ' ', margin);
conf->title = title;
}
-
- return (BSDDIALOG_OK);
}