Blob Blame History Raw
From f1bf2a86a69f93a03844a5fdf3ff97187556fdf7 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Thu, 9 Mar 2017 14:55:33 +0000
Subject: [PATCH 21/26] wrestool: Const-correctness in command line argument
 handling.

Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
---
 wrestool/extract.c  |  2 +-
 wrestool/main.c     | 30 +++++++++++++++---------------
 wrestool/restable.c | 18 +++++++++---------
 wrestool/wrestool.h |  6 +++---
 4 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/wrestool/extract.c b/wrestool/extract.c
index e1140a3..0044ce0 100644
--- a/wrestool/extract.c
+++ b/wrestool/extract.c
@@ -39,7 +39,7 @@ extract_resources_callback (WinLibrary *fi, WinResource *wr,
 	size_t size;
 	bool free_it;
 	void *memory;
-	char *outname;
+	const char *outname;
 	FILE *out;
 
 	memory = extract_resource(fi, wr, &size, &free_it, type_wr->id, (lang_wr == NULL ? NULL : lang_wr->id), arg_raw);
diff --git a/wrestool/main.c b/wrestool/main.c
index 218bbbd..4c33ba9 100644
--- a/wrestool/main.c
+++ b/wrestool/main.c
@@ -47,12 +47,12 @@ const char version_etc_copyright[] = "Copyright (C) 1998 Oskar Liljeblad";
 bool arg_raw;
 static FILE *verbose_file;
 static int arg_verbosity;
-static char *arg_output;
-static char *arg_type;
-static char *arg_name;
-static char *arg_language;
+static const char *arg_output;
+static const char *arg_type;
+static const char *arg_name;
+static const char *arg_language;
 static int arg_action;
-static char *res_types[] = {
+static const char *res_types[] = {
     /* 0x01: */
     "cursor", "bitmap", "icon", "menu", "dialog", "string",
     "fontdir", "font", "accelerator", "rcdata", "messagelist",
@@ -64,14 +64,14 @@ static char *res_types[] = {
 };
 #define RES_TYPE_COUNT ((int)(sizeof(res_types)/sizeof(char *)))
 
-static char *res_type_string_to_id (char *);
-static char *get_extract_extension (char *);
+static const char *res_type_string_to_id (const char *);
+static const char *get_extract_extension (const char *);
 
 /* res_type_id_to_string:
  *   Translate a numeric resource type to it's corresponding string type.
  *   (For informative-ness.)
  */
-char *
+const char *
 res_type_id_to_string (int id)
 {
     if (id == 241)
@@ -85,10 +85,10 @@ res_type_id_to_string (int id)
  *   Translate a resource type string to integer.
  *   (Used to convert the --type option.)
  */
-static char *
-res_type_string_to_id (char *type)
+static const char *
+res_type_string_to_id (const char *type)
 {
-    static char *res_type_ids[] = {
+    static const char *res_type_ids[] = {
 	"-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9", "-10",
 	"-11", "-12", NULL, "-14", NULL, "-16", "-17", NULL, "-19",
 	"-20", "-21", "-22"
@@ -110,8 +110,8 @@ res_type_string_to_id (char *type)
  *   Return extension for files of a certain resource type
  *
  */
-static char *
-get_extract_extension (char *type)
+static const char *
+get_extract_extension (const char *type)
 {
     uint16_t value;
 
@@ -134,8 +134,8 @@ get_extract_extension (char *type)
 /* get_destination_name:
  *   Make a filename for a resource that is to be extracted.
  */
-char *
-get_destination_name (WinLibrary *fi, char *type, char *name, char *lang)
+const char *
+get_destination_name (WinLibrary *fi, const char *type, const char *name, const char *lang)
 {
     static char filename[1024];
 
diff --git a/wrestool/restable.c b/wrestool/restable.c
index 1547979..df0ffd5 100644
--- a/wrestool/restable.c
+++ b/wrestool/restable.c
@@ -35,11 +35,11 @@ static WinResource *list_ne_type_resources (WinLibrary *, int *);
 static WinResource *list_ne_name_resources (WinLibrary *, WinResource *, int *);
 static WinResource *list_pe_resources (WinLibrary *, Win32ImageResourceDirectory *, int, int *);
 static int calc_vma_size (WinLibrary *);
-static void do_resources_recurs (WinLibrary *, WinResource *, WinResource *, WinResource *, WinResource *, char *, char *, char *, DoResourceCallback);
+static void do_resources_recurs (WinLibrary *, WinResource *, WinResource *, WinResource *, WinResource *, const char *, const char *, const char *, DoResourceCallback);
 static char *get_resource_id_quoted (WinResource *);
-static WinResource *find_with_resource_array(WinLibrary *, WinResource *, char *);
+static WinResource *find_with_resource_array(WinLibrary *, WinResource *, const char *);
 static WinResource *list_resources (WinLibrary *fi, WinResource *res, int *count);
-static bool compare_resource_id (WinResource *wr, char *id);
+static bool compare_resource_id (WinResource *wr, const char *id);
 
 /* Check whether access to a PE_SECTIONS is allowed */
 #define RETURN_IF_BAD_PE_SECTIONS(ret, module)                                              \
@@ -53,7 +53,7 @@ static bool compare_resource_id (WinResource *wr, char *id);
  */
 
 void
-do_resources (WinLibrary *fi, char *type, char *name, char *lang, DoResourceCallback cb)
+do_resources (WinLibrary *fi, const char *type, const char *name, const char *lang, DoResourceCallback cb)
 {
 	WinResource *type_wr;
 	WinResource *name_wr;
@@ -77,8 +77,8 @@ do_resources (WinLibrary *fi, char *type, char *name, char *lang, DoResourceCall
 
 static void
 do_resources_recurs (WinLibrary *fi, WinResource *base, WinResource *type_wr,
-                          WinResource *name_wr, WinResource *lang_wr,
-						  char *type, char *name, char *lang, DoResourceCallback cb)
+                     WinResource *name_wr, WinResource *lang_wr,
+                     const char *type, const char *name, const char *lang, DoResourceCallback cb)
 {
 	int c, rescnt;
 	WinResource *wr;
@@ -116,7 +116,7 @@ print_resources_callback (WinLibrary *fi, WinResource *wr,
                           WinResource *type_wr, WinResource *name_wr,
 						  WinResource *lang_wr)
 {
-	char *type, *offset;
+	const char *type, *offset;
 	int32_t id;
 	size_t size;
 
@@ -155,7 +155,7 @@ get_resource_id_quoted (WinResource *wr)
 }
 
 static bool
-compare_resource_id (WinResource *wr, char *id)
+compare_resource_id (WinResource *wr, const char *id)
 {
 	if (wr->numeric_id) {
 		int32_t cmp1, cmp2;
@@ -518,7 +518,7 @@ calc_vma_size (WinLibrary *fi)
 }
 
 static WinResource *
-find_with_resource_array(WinLibrary *fi, WinResource *wr, char *id)
+find_with_resource_array(WinLibrary *fi, WinResource *wr, const char *id)
 {
 	int c, rescnt;
 	WinResource *return_wr;
diff --git a/wrestool/wrestool.h b/wrestool/wrestool.h
index e4bae73..a3543a3 100644
--- a/wrestool/wrestool.h
+++ b/wrestool/wrestool.h
@@ -93,13 +93,13 @@ typedef void (*DoResourceCallback) (WinLibrary *, WinResource *, WinResource *,
 bool read_library (WinLibrary *);
 WinResource *find_resource (WinLibrary *, const char *, const char *, const char *, int *);
 void *get_resource_entry (WinLibrary *, WinResource *, size_t *);
-void do_resources (WinLibrary *, char *, char *, char *, DoResourceCallback);
+void do_resources (WinLibrary *, const char *, const char *, const char *, DoResourceCallback);
 void print_resources_callback (WinLibrary *, WinResource *, WinResource *, WinResource *, WinResource *);
 /* bool compare_resource_id (WinResource *, char *); */
 
 /* main.c */
-char *res_type_id_to_string (int);
-char *get_destination_name (WinLibrary *, char *, char *, char *);
+const char *res_type_id_to_string (int);
+const char *get_destination_name (WinLibrary *, const char *, const char *, const char *);
 
 /* extract.c */
 void *extract_resource (WinLibrary *, WinResource *, size_t *, bool *, char *, char *, bool);
-- 
2.10.2