Skip to content

Commit

Permalink
Use const char* in xml parameters, avoid C style casts.
Browse files Browse the repository at this point in the history
  • Loading branch information
redtide committed Apr 26, 2024
1 parent f8eddb9 commit 80d391f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
20 changes: 10 additions & 10 deletions src/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ static struct ctx {
char *filename;
xmlDoc *doc;
xmlXPathContextPtr xpath_ctx_ptr;
char *nodename;
char *value;
const char *nodename;
const char *value;
xmlNode *node;
enum {
XML_MODE_SETTING = 0,
Expand Down Expand Up @@ -196,7 +196,7 @@ xml_finish(void)
}

void
xml_set(char *nodename, char *value)
xml_set(const char *nodename, const char *value)
{
ctx.nodename = nodename;
ctx.value = value;
Expand All @@ -205,7 +205,7 @@ xml_set(char *nodename, char *value)
}

void
xml_set_num(char *nodename, double value)
xml_set_num(const char *nodename, double value)
{
char buf[64];
snprintf(buf, sizeof(buf), "%.0f", value);
Expand All @@ -215,8 +215,8 @@ xml_set_num(char *nodename, double value)
xml_tree_walk(xmlDocGetRootElement(ctx.doc));
}

char *
xml_get(char *nodename)
const char *
xml_get(const char *nodename)
{
ctx.nodename = nodename;
ctx.mode = XML_MODE_GETTING;
Expand All @@ -225,7 +225,7 @@ xml_get(char *nodename)
}

int
xml_get_int(char *nodename)
xml_get_int(const char *nodename)
{
ctx.nodename = nodename;
ctx.mode = XML_MODE_GETTING;
Expand All @@ -234,9 +234,9 @@ xml_get_int(char *nodename)
}

int
xml_get_bool_text(char *nodename)
xml_get_bool_text(const char *nodename)
{
char *value = xml_get(nodename);
const char *value = xml_get(nodename);

/* handle <foo></foo> and <foo /> where no value has been specified */
if (!value || !*value) {
Expand All @@ -263,7 +263,7 @@ xml_get_node(char *nodename)
}

char *
xpath_get_content(char *xpath_expr)
xpath_get_content(const char *xpath_expr)
{
xmlChar *ret = NULL;
xmlXPathObjectPtr object = xmlXPathEvalExpression((xmlChar *)xpath_expr, ctx.xpath_ctx_ptr);
Expand Down
12 changes: 6 additions & 6 deletions src/xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ void xml_init(const char *filename);
void xml_save(void);
void xml_save_as(const char *filename);
void xml_finish(void);
void xml_set(char *nodename, char *value);
void xml_set_num(char *nodename, double value);
char *xml_get(char *nodename);
int xml_get_int(char *nodename);
int xml_get_bool_text(char *nodename);
void xml_set(const char *nodename, const char *value);
void xml_set_num(const char *nodename, double value);
const char *xml_get(const char *nodename);
int xml_get_int(const char *nodename);
int xml_get_bool_text(const char *nodename);

/**
* xpath_get_content() - Get content of node specified by xpath
* @xpath_expr: xpath expression for node
*/
char *xpath_get_content(char *xpath_expr);
char *xpath_get_content(const char *xpath_expr);

/**
* xpath_add_node - add xml nodes from xpath
Expand Down
14 changes: 7 additions & 7 deletions tweaks-qt/maindialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void MainDialog::activate()
struct themes openbox_themes = { 0 };
theme_find(&openbox_themes, "themes", "openbox-3/themerc");
int active = -1;
char *active_id = xml_get((char *)"/labwc_config/theme/name");
const char *active_id = xml_get("/labwc_config/theme/name");
for (int i = 0; i < openbox_themes.nr; ++i) {
struct theme *theme = openbox_themes.data + i;
if (active_id && !strcmp(theme->name, active_id)) {
Expand All @@ -67,7 +67,7 @@ void MainDialog::activate()
theme_free_vector(&openbox_themes);

/* Corner Radius */
ui->cornerRadius->setValue(xml_get_int((char *)"/labwc_config/theme/cornerradius"));
ui->cornerRadius->setValue(xml_get_int("/labwc_config/theme/cornerradius"));

/* # MOUSE & TOUCHPAD */

Expand Down Expand Up @@ -96,13 +96,13 @@ void MainDialog::activate()
ui->naturalScroll->addItem("no");
ui->naturalScroll->addItem("yes");
ui->naturalScroll->setCurrentIndex(
xml_get_bool_text((char *)"/labwc_config/libinput/device/naturalscroll"));
xml_get_bool_text("/labwc_config/libinput/device/naturalscroll"));

/* # LANGUAGE */

/* Keyboard Layout */
GList *keyboard_layouts = NULL;
keyboard_layouts_init(&keyboard_layouts, (char *)"/usr/share/X11/xkb/rules/evdev.lst");
keyboard_layouts_init(&keyboard_layouts, "/usr/share/X11/xkb/rules/evdev.lst");
char xkb_default_layout[1024];
environment_get(xkb_default_layout, sizeof(xkb_default_layout), "XKB_DEFAULT_LAYOUT");
active = -1;
Expand All @@ -128,9 +128,9 @@ void MainDialog::activate()
void MainDialog::onApply()
{
/* ~/.config/labwc/rc.xml */
xml_set_num((char *)"/labwc_config/theme/cornerradius", ui->cornerRadius->value());
xml_set((char *)"/labwc_config/theme/name", ui->openboxTheme->currentText().toLatin1().data());
xml_set((char *)"/labwc_config/libinput/device/naturalscroll",
xml_set_num("/labwc_config/theme/cornerradius", ui->cornerRadius->value());
xml_set("/labwc_config/theme/name", ui->openboxTheme->currentText().toLatin1().data());
xml_set("/labwc_config/libinput/device/naturalscroll",
ui->naturalScroll->currentText().toLatin1().data());
xml_save();

Expand Down

0 comments on commit 80d391f

Please sign in to comment.