CVS update: /ccvs/src/

[email protected] 3 Jun 2005 15:36:38 -0000
Newsgroups gmane.comp.version-control.cvs.cvs
Message-ID <[email protected]>
User: dprice  
Date: 05/06/03 08:36:38

Modified:
 /ccvs/src/
  ChangeLog, cvs.h, expand_path.c, parseinfo.c

Log:
 * cvs.h (expand_path): Rearrange args and use bool for formatsafe flag.
 * expand_path.c: Globally: Remove init of globals to NULL by C89,
 reformat to CVS conventions, remove unnecessary comparisons to NULL and
 0, & remove unnecessary typecasts.
 (expand_variable): Remove proto and move function above first use.
 Make return value const.
 (expand_path): Don't refer to var when contents are known.  Rearrange
 args per cvs.h changes.  Improve header comment block.
 * parseinfo.c (Parse_Info): Use new expand_path API.

File Changes:

Directory: /ccvs/src/
=====================

File [changed]: ChangeLog
Url: https://ccvs.cvshome.org/source/browse/ccvs/src/ChangeLog?r1=1.3206&r2=1.3207
Delta lines:  +12 -0
--------------------
--- ChangeLog	3 Jun 2005 13:14:41 -0000	1.3206
+++ ChangeLog	3 Jun 2005 15:36:35 -0000	1.3207
@@ -1,3 +1,15 @@
+2005-06-03  Derek Price  <[email protected]>
+
+	* cvs.h (expand_path): Rearrange args and use bool for formatsafe flag.
+	* expand_path.c: Globally: Remove init of globals to NULL by C89,
+	reformat to CVS conventions, remove unnecessary comparisons to NULL and
+	0, & remove unnecessary typecasts.
+	(expand_variable): Remove proto and move function above first use.
+	Make return value const.
+	(expand_path): Don't refer to var when contents are known.  Rearrange
+	args per cvs.h changes.  Improve header comment block.
+	* parseinfo.c (Parse_Info): Use new expand_path API.
+
 2005-06-02  Derek Price  <[email protected]>
 
 	* client.c: Don't set NULL for globals by C89.  Globally remove

File [changed]: cvs.h
Url: https://ccvs.cvshome.org/source/browse/ccvs/src/cvs.h?r1=1.337&r2=1.338
Delta lines:  +2 -2
-------------------
--- cvs.h	27 May 2005 18:07:48 -0000	1.337
+++ cvs.h	3 Jun 2005 15:36:35 -0000	1.338
@@ -839,8 +839,8 @@
 #endif /* SERVER_SUPPORT || CLIENT_SUPPORT */
 
 /* Pathname expansion */
-char *expand_path (const char *name, const char *file, int line,
-                   int formatsafe);
+char *expand_path (const char *name, bool formatsafe,
+		   const char *file, int line);
 
 /* User variables.  */
 extern List *variable_list;

File [changed]: expand_path.c
Url: https://ccvs.cvshome.org/source/browse/ccvs/src/expand_path.c?r1=1.33&r2=1.34
Delta lines:  +99 -103
----------------------
--- expand_path.c	22 Apr 2005 11:59:00 -0000	1.33
+++ expand_path.c	3 Jun 2005 15:36:35 -0000	1.34
@@ -15,11 +15,9 @@
 #include "cvs.h"
 #include <sys/types.h>
 
-static char *expand_variable (const char *env, const char *file, int line);
-
 /* User variables.  */
 
-List *variable_list = NULL;
+List *variable_list;
 
 static void variable_delproc (Node *);
 
@@ -43,8 +41,7 @@
     while (isalnum ((unsigned char) *p) || *p == '_')
 	++p;
     if (*p != '=')
-	error ( 1, 0, "invalid character in user variable name in %s",
-		nameval );
+	error (1, 0, "invalid character in user variable name in %s", nameval);
     if (p == nameval)
 	error (1, 0, "empty user variable name in %s", nameval);
     name = xmalloc (p - nameval + 1);
@@ -52,14 +49,14 @@
     name[p - nameval] = '\0';
     /* Make p point to the value.  */
     ++p;
-    if (strchr (p, '\012') != NULL)
+    if (strchr (p, '\012'))
 	error (1, 0, "linefeed in user variable value in %s", nameval);
 
-    if (variable_list == NULL)
+    if (!variable_list)
 	variable_list = getlist ();
 
     node = findnode (variable_list, name);
-    if (node == NULL)
+    if (!node)
     {
 	node = getnode ();
 	node->type = VARIABLE;
@@ -80,18 +77,93 @@
 
 
 
+static const char *
+expand_variable (const char *name, const char *file, int line)
+{
+    if (!strcmp (name, CVSROOT_ENV))
+	return current_parsed_root->directory;
+    else if (!strcmp (name, "RCSBIN"))
+    {
+	error (0, 0, "RCSBIN internal variable is no longer supported");
+	return NULL;
+    }
+    else if (!strcmp (name, EDITOR1_ENV))
+	return Editor;
+    else if (!strcmp (name, EDITOR2_ENV))
+	return Editor;
+    else if (!strcmp (name, EDITOR3_ENV))
+	return Editor;
+    else if (!strcmp (name, "USER"))
+	return getcaller ();
+    else if (!strcmp (name, "SESSIONID")
+	     || !strcmp (name, "COMMITID"))
+	return global_session_id;
+    else if (isalpha (name[0]))
+    {
+	/* These names are reserved for future versions of CVS,
+	   so that is why it is an error.  */
+	if (line)
+	    error (0, 0, "%s:%d: no such internal variable $%s",
+		   file, line, name);
+	else
+	    error (0, 0, "%s: no such internal variable $%s",
+		   file, name);
+	return NULL;
+    }
+    else if (name[0] == '=')
+    {
+	Node *node;
+	/* Crazy syntax for a user variable.  But we want
+	   *something* that lets the user name a user variable
+	   anything he wants, without interference from
+	   (existing or future) internal variables.  */
+	node = findnode (variable_list, name + 1);
+	if (!node)
+	{
+	    if (line)
+		error (0, 0, "%s:%d: no such user variable ${%s}",
+		       file, line, name);
+	    else
+		error (0, 0, "%s: no such user variable ${%s}",
+		       file, name);
+	    return NULL;
+	}
+	return node->data;
+    }
+    else
+    {
+	/* It is an unrecognized character.  We return an error to
+	   reserve these for future versions of CVS; it is plausible
+	   that various crazy syntaxes might be invented for inserting
+	   information about revisions, branches, etc.  */
+	if (line)
+	    error (0, 0, "%s:%d: unrecognized variable syntax %s",
+		   file, line, name);
+	else
+	    error (0, 0, "%s: unrecognized variable syntax %s",
+		   file, name);
+	return NULL;
+    }
+}
+
+
+
 /* This routine will expand the pathname to account for ~ and $
-   characters as described above.  Returns a pointer to a newly
-   malloc'd string.  If an error occurs, an error message is printed
-   via error() and NULL is returned.  FILE and LINE are the filename
-   and linenumber to include in the error message.  FILE must point
-   to something; LINE can be zero to indicate the line number is not
-   known.  */
+ * characters as described above.  Returns a pointer to a newly
+ * malloc'd string.  If an error occurs, an error message is printed
+ * via error() and NULL is returned.  FILE and LINE are the filename
+ * and linenumber to include in the error message.  FILE must point
+ * to something; LINE can be zero to indicate the line number is not
+ * known.
+ *
+ * When FORMATSAFE is set, percent signs (`%') in variable contents are doubled
+ * to prevent later expansion by format_cmdline.
+ */
 char *
-expand_path (const char *name, const char *file, int line, int formatsafe)
+expand_path (const char *name, bool formatsafe, const char *file, int line)
 {
     size_t s, d, p;
-    char *e;
+    const char *e;
 
     char *mybuf = NULL;
     size_t mybuf_size = 0;
@@ -159,7 +231,7 @@
 	    {
 		if (flag
 		    ? name[s] =='}'
-		    : isalnum ((unsigned char) name[s]) == 0 && name[s] != '_')
+		    : !isalnum (name[s]) && name[s] != '_')
 		    break;
 		expand_string (&mybuf, &mybuf_size, d + 1);
 	    }
@@ -192,7 +264,7 @@
 			 * later (in make_cmdline).
 			 */
 			expand_string (&mybuf, &mybuf_size, d + 1);
-			mybuf[d] = mybuf[d-1];
+			mybuf[d] = '%';
 			d++;
 		    }
 		}
@@ -230,7 +302,7 @@
 	else
 	{
 #ifdef GETPWNAM_MISSING
-	    if (line != 0)
+	    if (line)
 		error (0, 0,
 		       "%s:%d:tilde expansion not supported on this system",
 		       file, line);
@@ -243,7 +315,7 @@
 	    ps = getpwnam (buf + d);
 	    if (ps == 0)
 	    {
-		if (line != 0)
+		if (line)
 		    error (0, 0, "%s:%d: no such user %s",
 			   file, line, buf + d);
 		else
@@ -253,18 +325,18 @@
 	    e = ps->pw_dir;
 #endif
 	}
-	if (e == NULL)
+	if (!e)
 	    error (1, 0, "cannot find home directory");
 
-	p = strlen(e);
+	p = strlen (e);
 	expand_string (&buf, &buf_size, d + p);
-	memcpy(buf + d, e, p);
+	memcpy (buf + d, e, p);
 	d += p;
     }
     /* Kill up to here */
-    p = strlen(mybuf + s) + 1;
+    p = strlen (mybuf + s) + 1;
     expand_string (&buf, &buf_size, d + p);
-    memcpy(buf + d, mybuf + s, p);
+    memcpy (buf + d, mybuf + s, p);
 
     /* OK, buf contains the value we want to return.  Clean up and return
        it.  */
@@ -276,83 +348,7 @@
     return result;
 
  error_exit:
-    if (mybuf != NULL)
-	free (mybuf);
-    if (buf != NULL)
-	free (buf);
-    return NULL;
-}
-
-
-
-static char *
-expand_variable (const char *name, const char *file, int line)
-{
-    if (strcmp (name, CVSROOT_ENV) == 0)
-	return current_parsed_root->directory;
-    else if (strcmp (name, "RCSBIN") == 0)
-    {
-	error (0, 0, "RCSBIN internal variable is no longer supported");
-	return NULL;
-    }
-    else if (strcmp (name, EDITOR1_ENV) == 0)
-	return Editor;
-    else if (strcmp (name, EDITOR2_ENV) == 0)
-	return Editor;
-    else if (strcmp (name, EDITOR3_ENV) == 0)
-	return Editor;
-    else if (strcmp (name, "USER") == 0)
-	return getcaller ();
-    else if (strcmp (name, "SESSIONID") == 0
-	     || strcmp (name, "COMMITID") == 0)
-	/* It's okay to cast out the const below since we know
-	 * it is only ever used read-only in expand_path().
-	 */
-	return (char *)global_session_id;
-    else if (isalpha ((unsigned char) name[0]))
-    {
-	/* These names are reserved for future versions of CVS,
-	   so that is why it is an error.  */
-	if (line != 0)
-	    error (0, 0, "%s:%d: no such internal variable $%s",
-		   file, line, name);
-	else
-	    error (0, 0, "%s: no such internal variable $%s",
-		   file, name);
-	return NULL;
-    }
-    else if (name[0] == '=')
-    {
-	Node *node;
-	/* Crazy syntax for a user variable.  But we want
-	   *something* that lets the user name a user variable
-	   anything he wants, without interference from
-	   (existing or future) internal variables.  */
-	node = findnode (variable_list, name + 1);
-	if (node == NULL)
-	{
-	    if (line != 0)
-		error (0, 0, "%s:%d: no such user variable ${%s}",
-		       file, line, name);
-	    else
-		error (0, 0, "%s: no such user variable ${%s}",
-		       file, name);
+    if (mybuf) free (mybuf);
+    if (buf) free (buf);
 	    return NULL;
-	}
-	return node->data;
-    }
-    else
-    {
-	/* It is an unrecognized character.  We return an error to
-	   reserve these for future versions of CVS; it is plausible
-	   that various crazy syntaxes might be invented for inserting
-	   information about revisions, branches, etc.  */
-	if (line != 0)
-	    error (0, 0, "%s:%d: unrecognized variable syntax %s",
-		   file, line, name);
-	else
-	    error (0, 0, "%s: unrecognized variable syntax %s",
-		   file, name);
-	return NULL;
-    }
 }

File [changed]: parseinfo.c
Url: https://ccvs.cvshome.org/source/browse/ccvs/src/parseinfo.c?r1=1.76&r2=1.77
Delta lines:  +7 -10
--------------------
--- parseinfo.c	26 May 2005 17:48:06 -0000	1.76
+++ parseinfo.c	3 Jun 2005 15:36:35 -0000	1.77
@@ -142,9 +142,8 @@
 	    if (!(opt & PIOPT_ALL))
 		error (0, 0, "Keyword `ALL' is ignored at line %d in %s file",
 		       line_number, infofile);
-	    else if ((expanded_value = expand_path (value, infofile,
-	                                            line_number, 1))
-	             != NULL )
+	    else if ((expanded_value = expand_path (value, true, infofile,
+	                                            line_number)))
 	    {
 		err += callproc (repository, expanded_value, closure);
 		free (expanded_value);
@@ -169,8 +168,7 @@
 	    continue;				/* no match */
 
 	/* it did, so do the callback and note that we did one */
-	if ((expanded_value = expand_path( value, infofile, line_number, 1)
-	    ) != NULL)
+	if ((expanded_value = expand_path (value, true, infofile, line_number)))
 	{
 	    err += callproc (repository, expanded_value, closure);
 	    free (expanded_value);
@@ -187,9 +185,8 @@
     /* if we fell through and didn't callback at all, do the default */
     if (callback_done == 0 && default_value != NULL)
     {
-	if ((expanded_value = expand_path (default_value, infofile,
-	                                   line_number, 1)
-	    ) != NULL)
+	if ((expanded_value = expand_path (default_value, true, infofile,
+	                                   line_number)))
 	{
 	    err += callproc (repository, expanded_value, closure);
 	    free (expanded_value);
@@ -496,7 +493,7 @@
 	    if (retval->HistoryLogPath) free (retval->HistoryLogPath);
 
 	    /* Expand ~ & $VARs.  */
-	    retval->HistoryLogPath = expand_path (p, infopath, ln, false);
+	    retval->HistoryLogPath = expand_path (p, false, infopath, ln);
 
 	    if (retval->HistoryLogPath && !ISABSOLUTE (retval->HistoryLogPath))
 	    {
@@ -509,7 +506,7 @@
 	else if (strcmp (line, "HistorySearchPath") == 0)
 	{
 	    if (retval->HistorySearchPath) free (retval->HistorySearchPath);
-	    retval->HistorySearchPath = expand_path (p, infopath, ln, false);
+	    retval->HistorySearchPath = expand_path (p, false, infopath, ln);
 
 	    if (retval->HistorySearchPath
 		&& !ISABSOLUTE (retval->HistorySearchPath))