[PATCH 12/12] libusbg: Replace directory names with defines.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Replace strings, functions, configs strings placed
everywhere in code with macro defintions STRINGS_DIR,
FUNCTIONS_DIR and CONFIGS_DIR.

Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx>
---
 src/gadget.c |   37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/src/gadget.c b/src/gadget.c
index 005d9b0..9447bde 100644
--- a/src/gadget.c
+++ b/src/gadget.c
@@ -26,6 +26,10 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#define STRINGS_DIR "strings"
+#define CONFIGS_DIR "configs"
+#define FUNCTIONS_DIR "functions"
+
 /**
  * @file gadget.c
  * @todo Handle buffer overflows
@@ -218,7 +222,7 @@ static int gadget_parse_functions(char *path, struct gadget *g)
 	struct dirent **dent;
 	char fpath[MAX_PATH_LENGTH];
 
-	sprintf(fpath, "%s/%s/functions", path, g->name);
+	sprintf(fpath, "%s/%s/%s", path, g->name, FUNCTIONS_DIR);
 
 	TAILQ_INIT(&g->functions);
 
@@ -292,7 +296,7 @@ static int gadget_parse_configs(char *path, struct gadget *g)
 	struct dirent **dent;
 	char cpath[MAX_PATH_LENGTH];
 
-	sprintf(cpath, "%s/%s/configs", path, g->name);
+	sprintf(cpath, "%s/%s/%s", path, g->name, CONFIGS_DIR);
 
 	TAILQ_INIT(&g->configs);
 
@@ -328,9 +332,14 @@ static void gadget_parse_attrs(char *path, struct gadget *g)
 static void gadget_parse_strings(char *path, struct gadget *g)
 {
 	/* Strings - hardcoded to U.S. English only for now */
-	gadget_read_string(path, g->name, "strings/0x409/serialnumber", g->str_ser);
-	gadget_read_string(path, g->name, "strings/0x409/manufacturer", g->str_mnf);
-	gadget_read_string(path, g->name, "strings/0x409/product", g->str_prd);
+	int lang = LANG_US_ENG;
+	char spath[MAX_PATH_LENGTH];
+
+	sprintf(spath, "%s/%s/%s/0x%x", path, g->name, STRINGS_DIR, lang);
+
+	gadget_read_string(spath, "", "serialnumber", g->str_ser);
+	gadget_read_string(spath, "", "manufacturer", g->str_mnf);
+	gadget_read_string(spath, "", "product", g->str_prd);
 }
 
 static int gadget_parse_gadgets(char *path, struct state *s)
@@ -591,7 +600,7 @@ void gadget_set_gadget_serial_number(struct gadget *g, int lang, char *serno)
 {
 	char path[MAX_PATH_LENGTH];
 
-	sprintf(path, "%s/%s/%s/0x%x", g->path, g->name, "strings", lang);
+	sprintf(path, "%s/%s/%s/0x%x", g->path, g->name, STRINGS_DIR, lang);
 
 	mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO);
 
@@ -604,7 +613,7 @@ void gadget_set_gadget_manufacturer(struct gadget *g, int lang, char *mnf)
 {
 	char path[MAX_PATH_LENGTH];
 
-	sprintf(path, "%s/%s/%s/0x%x", g->path, g->name, "strings", lang);
+	sprintf(path, "%s/%s/%s/0x%x", g->path, g->name, STRINGS_DIR, lang);
 
 	mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO);
 
@@ -617,7 +626,7 @@ void gadget_set_gadget_product(struct gadget *g, int lang, char *prd)
 {
 	char path[MAX_PATH_LENGTH];
 
-	sprintf(path, "%s/%s/%s/0x%x", g->path, g->name, "strings", lang);
+	sprintf(path, "%s/%s/%s/0x%x", g->path, g->name, STRINGS_DIR, lang);
 
 	mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO);
 
@@ -646,7 +655,7 @@ struct function *gadget_create_function(struct gadget *g, enum function_type typ
 		return NULL;
 	}
 
-	sprintf(fpath, "%s/%s/functions/%s", g->path, g->name, name);
+	sprintf(fpath, "%s/%s/%s/%s", g->path, g->name, FUNCTIONS_DIR, name);
 
 	f = malloc(sizeof(struct function));
 	if (!f) {
@@ -655,7 +664,7 @@ struct function *gadget_create_function(struct gadget *g, enum function_type typ
 	}
 
 	strcpy(f->name, name);
-	sprintf(f->path, "%s/%s/%s", g->path, g->name, "functions");
+	sprintf(f->path, "%s/%s/%s", g->path, g->name, FUNCTIONS_DIR);
 	f->type = type;
 
 	ret = mkdir(fpath, S_IRWXU|S_IRWXG|S_IRWXO);
@@ -701,7 +710,7 @@ struct config *gadget_create_config(struct gadget *g, char *name)
 		return NULL;
 	}
 
-	sprintf(cpath, "%s/%s/configs/%s", g->path, g->name, name);
+	sprintf(cpath, "%s/%s/%s/%s", g->path, g->name, CONFIGS_DIR, name);
 
 	c = malloc(sizeof(struct config));
 	if (!c) {
@@ -711,7 +720,7 @@ struct config *gadget_create_config(struct gadget *g, char *name)
 
 	TAILQ_INIT(&c->bindings);
 	strcpy(c->name, name);
-	sprintf(c->path, "%s/%s/%s/%s", g->path, g->name, "configs", name);
+	sprintf(c->path, "%s/%s/%s", g->path, g->name, CONFIGS_DIR);
 
 	ret = mkdir(cpath, S_IRWXU|S_IRWXG|S_IRWXO);
 	if (ret < 0) {
@@ -754,7 +763,7 @@ void gadget_set_config_string(struct config *c, int lang, char *str)
 {
 	char path[MAX_PATH_LENGTH];
 
-	sprintf(path, "%s/%s/0x%x", c->path, "strings", lang);
+	sprintf(path, "%s/%s/%s/0x%x", c->path, c->name, STRINGS_DIR, lang);
 
 	mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO);
 
@@ -786,7 +795,7 @@ int gadget_add_config_function(struct config *c, char *name, struct function *f)
 		return ret;
 	}
 
-	sprintf(bpath, "%s/%s", c->path, name);
+	sprintf(bpath, "%s/%s/%s", c->path, c->name, name);
 	sprintf(fpath, "%s/%s", f->path, f->name);
 
 	b = malloc(sizeof(struct binding));
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux