regedit: Move PerformRegAction() and get_file_name() around to
eliminate forward references. Make them static.
Francois Gouget
fgouget at codeweavers.com
Wed Jun 13 06:18:50 CDT 2007
---
This is a nop. It just simplifies the code and makes it clearer.
programs/regedit/regedit.c | 215 ++++++++++++++++++++++++++++----------------
programs/regedit/regproc.c | 59 ------------
programs/regedit/regproc.h | 1 -
3 files changed, 136 insertions(+), 139 deletions(-)
diff --git a/programs/regedit/regedit.c b/programs/regedit/regedit.c
index 68b11df..0c587d6 100644
--- a/programs/regedit/regedit.c
+++ b/programs/regedit/regedit.c
@@ -58,101 +58,66 @@ typedef enum {
ACTION_UNDEF, ACTION_ADD, ACTION_EXPORT, ACTION_DELETE
} REGEDIT_ACTION;
-BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s);
-/**
- * Process unknown switch.
+/******************************************************************************
+ * Copies file name from command line string to the buffer.
+ * Rewinds the command line string pointer to the next non-space character
+ * after the file name.
+ * Buffer contains an empty string if no filename was found;
*
- * Params:
- * chu - the switch character in upper-case.
- * s - the command line string where s points to the switch character.
+ * params:
+ * command_line - command line current position pointer
+ * where *s[0] is the first symbol of the file name.
+ * file_name - buffer to write the file name to.
*/
-static void error_unknown_switch(char chu, char *s)
+static void get_file_name(CHAR **command_line, CHAR *file_name)
{
- if (isalpha(chu)) {
- fprintf(stderr,"%s: Undefined switch /%c!\n", getAppName(), chu);
- } else {
- fprintf(stderr,"%s: Alphabetic character is expected after '%c' "
- "in switch specification\n", getAppName(), *(s - 1));
- }
- exit(1);
-}
+ CHAR *s = *command_line;
+ int pos = 0; /* position of pointer "s" in *command_line */
+ file_name[0] = 0;
-BOOL ProcessCmdLine(LPSTR lpCmdLine)
-{
- REGEDIT_ACTION action = ACTION_UNDEF;
- LPSTR s = lpCmdLine; /* command line pointer */
- CHAR ch = *s; /* current character */
-
- setAppName("regedit");
- while (ch && ((ch == '-') || (ch == '/'))) {
- char chu;
- char ch2;
+ if (!s[0]) {
+ return;
+ }
+ if (s[0] == '"') {
s++;
- ch = *s;
- ch2 = *(s+1);
- chu = toupper(ch);
- if (!ch2 || isspace(ch2)) {
- if (chu == 'S' || chu == 'V') {
- /* ignore these switches */
- } else {
- switch (chu) {
- case 'D':
- action = ACTION_DELETE;
- break;
- case 'E':
- action = ACTION_EXPORT;
- break;
- case '?':
- fprintf(stderr,usage);
- exit(0);
- break;
- default:
- error_unknown_switch(chu, s);
- break;
- }
+ (*command_line)++;
+ while(s[0] != '"') {
+ if (!s[0]) {
+ fprintf(stderr,"%s: Unexpected end of file name!\n",
+ getAppName());
+ exit(1);
}
s++;
- } else {
- if (ch2 == ':') {
- switch (chu) {
- case 'L':
- /* fall through */
- case 'R':
- s += 2;
- while (*s && !isspace(*s)) {
- s++;
- }
- break;
- default:
- error_unknown_switch(chu, s);
- break;
- }
- } else {
- /* this is a file name, starting from '/' */
- s--;
- break;
- }
+ pos++;
}
- /* skip spaces to the next parameter */
- ch = *s;
- while (ch && isspace(ch)) {
+ } else {
+ while(s[0] && !isspace(s[0])) {
s++;
- ch = *s;
+ pos++;
}
}
+ memcpy(file_name, *command_line, pos * sizeof((*command_line)[0]));
+ /* remove the last backslash */
+ if (file_name[pos - 1] == '\\') {
+ file_name[pos - 1] = '\0';
+ } else {
+ file_name[pos] = '\0';
+ }
- if (*s && action == ACTION_UNDEF)
- action = ACTION_ADD;
-
- if (action == ACTION_UNDEF)
- return FALSE;
-
- return PerformRegAction(action, s);
+ if (s[0]) {
+ s++;
+ pos++;
+ }
+ while(s[0] && isspace(s[0])) {
+ s++;
+ pos++;
+ }
+ (*command_line) += pos;
}
-BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
+static BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
{
switch (action) {
case ACTION_ADD: {
@@ -239,3 +204,95 @@ BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
}
return TRUE;
}
+
+/**
+ * Process unknown switch.
+ *
+ * Params:
+ * chu - the switch character in upper-case.
+ * s - the command line string where s points to the switch character.
+ */
+static void error_unknown_switch(char chu, char *s)
+{
+ if (isalpha(chu)) {
+ fprintf(stderr,"%s: Undefined switch /%c!\n", getAppName(), chu);
+ } else {
+ fprintf(stderr,"%s: Alphabetic character is expected after '%c' "
+ "in switch specification\n", getAppName(), *(s - 1));
+ }
+ exit(1);
+}
+
+BOOL ProcessCmdLine(LPSTR lpCmdLine)
+{
+ REGEDIT_ACTION action = ACTION_UNDEF;
+ LPSTR s = lpCmdLine; /* command line pointer */
+ CHAR ch = *s; /* current character */
+
+ setAppName("regedit");
+ while (ch && ((ch == '-') || (ch == '/'))) {
+ char chu;
+ char ch2;
+
+ s++;
+ ch = *s;
+ ch2 = *(s+1);
+ chu = toupper(ch);
+ if (!ch2 || isspace(ch2)) {
+ if (chu == 'S' || chu == 'V') {
+ /* ignore these switches */
+ } else {
+ switch (chu) {
+ case 'D':
+ action = ACTION_DELETE;
+ break;
+ case 'E':
+ action = ACTION_EXPORT;
+ break;
+ case '?':
+ fprintf(stderr,usage);
+ exit(0);
+ break;
+ default:
+ error_unknown_switch(chu, s);
+ break;
+ }
+ }
+ s++;
+ } else {
+ if (ch2 == ':') {
+ switch (chu) {
+ case 'L':
+ /* fall through */
+ case 'R':
+ s += 2;
+ while (*s && !isspace(*s)) {
+ s++;
+ }
+ break;
+ default:
+ error_unknown_switch(chu, s);
+ break;
+ }
+ } else {
+ /* this is a file name, starting from '/' */
+ s--;
+ break;
+ }
+ }
+ /* skip spaces to the next parameter */
+ ch = *s;
+ while (ch && isspace(ch)) {
+ s++;
+ ch = *s;
+ }
+ }
+
+ if (*s && action == ACTION_UNDEF)
+ action = ACTION_ADD;
+
+ if (action == ACTION_UNDEF)
+ return FALSE;
+
+ return PerformRegAction(action, s);
+}
diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c
index 16a2b8c..2718194 100644
--- a/programs/regedit/regproc.c
+++ b/programs/regedit/regproc.c
@@ -99,65 +99,6 @@ char* getToken(char** str, const char* delims)
#endif
/******************************************************************************
- * Copies file name from command line string to the buffer.
- * Rewinds the command line string pointer to the next non-space character
- * after the file name.
- * Buffer contains an empty string if no filename was found;
- *
- * params:
- * command_line - command line current position pointer
- * where *s[0] is the first symbol of the file name.
- * file_name - buffer to write the file name to.
- */
-void get_file_name(CHAR **command_line, CHAR *file_name)
-{
- CHAR *s = *command_line;
- int pos = 0; /* position of pointer "s" in *command_line */
- file_name[0] = 0;
-
- if (!s[0]) {
- return;
- }
-
- if (s[0] == '"') {
- s++;
- (*command_line)++;
- while(s[0] != '"') {
- if (!s[0]) {
- fprintf(stderr,"%s: Unexpected end of file name!\n",
- getAppName());
- exit(1);
- }
- s++;
- pos++;
- }
- } else {
- while(s[0] && !isspace(s[0])) {
- s++;
- pos++;
- }
- }
- memcpy(file_name, *command_line, pos * sizeof((*command_line)[0]));
- /* remove the last backslash */
- if (file_name[pos - 1] == '\\') {
- file_name[pos - 1] = '\0';
- } else {
- file_name[pos] = '\0';
- }
-
- if (s[0]) {
- s++;
- pos++;
- }
- while(s[0] && isspace(s[0])) {
- s++;
- pos++;
- }
- (*command_line) += pos;
-}
-
-
-/******************************************************************************
* Converts a hex representation of a DWORD into a DWORD.
*/
DWORD convertHexToDWord(char *str, BYTE *buf)
diff --git a/programs/regedit/regproc.h b/programs/regedit/regproc.h
index 9a39951..0b23c6a 100644
--- a/programs/regedit/regproc.h
+++ b/programs/regedit/regproc.h
@@ -48,7 +48,6 @@ void processRegLines(FILE *in, CommandAPI command);
* Generic prototypes
*/
char* getToken(char** str, const char* delims);
-void get_file_name(CHAR **command_line, CHAR *filename);
DWORD convertHexToDWord(char *str, BYTE *buf);
DWORD convertHexCSVToHex(char *str, BYTE *buf, ULONG bufLen);
LPSTR convertHexToHexCSV( BYTE *buf, ULONG len);
--
1.4.4.4
More information about the wine-patches
mailing list