summaryrefslogtreecommitdiffstats
path: root/contrib/cvs/src/modules.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/cvs/src/modules.c')
-rw-r--r--contrib/cvs/src/modules.c202
1 files changed, 99 insertions, 103 deletions
diff --git a/contrib/cvs/src/modules.c b/contrib/cvs/src/modules.c
index 9907cc8..0381ec9 100644
--- a/contrib/cvs/src/modules.c
+++ b/contrib/cvs/src/modules.c
@@ -120,10 +120,9 @@ do_module (db, mname, m_type, msg, callback_proc, where,
int modargc;
int xmodargc;
char **modargv;
- char **xmodargv;
+ char **xmodargv = NULL;
/* Found entry from modules file, including options and such. */
char *value = NULL;
- char *zvalue = NULL;
char *mwhere = NULL;
char *mfile = NULL;
char *spec_opt = NULL;
@@ -186,25 +185,21 @@ do_module (db, mname, m_type, msg, callback_proc, where,
val.dptr = NULL;
if (val.dptr != NULL)
{
- /* null terminate the value XXX - is this space ours? */
- val.dptr[val.dsize] = '\0';
+ /* copy and null terminate the value */
+ value = xmalloc (val.dsize + 1);
+ memcpy (value, val.dptr, val.dsize);
+ value[val.dsize] = '\0';
/* If the line ends in a comment, strip it off */
- if ((cp = strchr (val.dptr, '#')) != NULL)
- {
- do
- *cp-- = '\0';
- while (isspace ((unsigned char) *cp));
- }
+ if ((cp = strchr (value, '#')) != NULL)
+ *cp = '\0';
else
- {
- /* Always strip trailing spaces */
- cp = strchr (val.dptr, '\0');
- while (cp > val.dptr && isspace ((unsigned char) *--cp))
- *cp = '\0';
- }
+ cp = value + val.dsize;
+
+ /* Always strip trailing spaces */
+ while (cp > value && isspace ((unsigned char) *--cp))
+ *cp = '\0';
- value = val.dptr;
mwhere = xstrdup (mname);
goto found;
}
@@ -297,7 +292,7 @@ do_module (db, mname, m_type, msg, callback_proc, where,
error_exit ();
cwd_saved = 1;
- err += callback_proc (&modargc, modargv, where, mwhere, mfile,
+ err += callback_proc (modargc, modargv, where, mwhere, mfile,
shorten,
local_specified, mname, msg);
@@ -332,17 +327,20 @@ do_module (db, mname, m_type, msg, callback_proc, where,
{
char *cp2;
- /* null terminate the value XXX - is this space ours? */
- val.dptr[val.dsize] = '\0';
+ /* copy and null terminate the value */
+ value = xmalloc (val.dsize + 1);
+ memcpy (value, val.dptr, val.dsize);
+ value[val.dsize] = '\0';
/* If the line ends in a comment, strip it off */
- if ((cp2 = strchr (val.dptr, '#')) != NULL)
- {
- do
- *cp2-- = '\0';
- while (isspace ((unsigned char) *cp2));
- }
- value = val.dptr;
+ if ((cp2 = strchr (value, '#')) != NULL)
+ *cp2 = '\0';
+ else
+ cp2 = value + val.dsize;
+
+ /* Always strip trailing spaces */
+ while (cp2 > value && isspace ((unsigned char) *--cp2))
+ *cp2 = '\0';
/* mwhere gets just the module name */
mwhere = xstrdup (mname);
@@ -375,11 +373,7 @@ do_module (db, mname, m_type, msg, callback_proc, where,
error_exit ();
cwd_saved = 1;
- /* copy value to our own string since if we go recursive we'll be
- really screwed if we do another dbm lookup */
assert (value != NULL);
- zvalue = xstrdup (value);
- value = zvalue;
/* search the value for the special delimiter and save for later */
if ((cp = strchr (value, CVSMODULE_SPEC)) != NULL)
@@ -387,62 +381,9 @@ do_module (db, mname, m_type, msg, callback_proc, where,
*cp = '\0'; /* null out the special char */
spec_opt = cp + 1; /* save the options for later */
- if (cp != value) /* strip whitespace if necessary */
- while (isspace ((unsigned char) *--cp))
- *cp = '\0';
-
- if (cp == value)
- {
- /*
- * we had nothing but special options, so skip arg
- * parsing and regular stuff entirely
- *
- * If there were only special ones though, we must
- * make the appropriate directory and cd to it
- */
- char *dir;
-
- /* XXX - XXX - MAJOR HACK - DO NOT SHIP - this needs to
- be !pipeout, but we don't know that here yet */
- if (!run_module_prog)
- goto out;
-
- dir = where ? where : mname;
- /* XXX - think about making null repositories at each dir here
- instead of just at the bottom */
- make_directories (dir);
- if ( CVS_CHDIR (dir) < 0)
- {
- error (0, errno, "cannot chdir to %s", dir);
- spec_opt = NULL;
- err++;
- goto out;
- }
- if (!isfile (CVSADM))
- {
- char *nullrepos;
-
- nullrepos = emptydir_name ();
-
- Create_Admin (".", dir,
- nullrepos, (char *) NULL, (char *) NULL, 0, 0);
- if (!noexec)
- {
- FILE *fp;
-
- fp = open_file (CVSADM_ENTSTAT, "w+");
- if (fclose (fp) == EOF)
- error (1, errno, "cannot close %s", CVSADM_ENTSTAT);
-#ifdef SERVER_SUPPORT
- if (server_active)
- server_set_entstat (dir, nullrepos);
-#endif
- }
- free (nullrepos);
- }
- out:
- goto do_special;
- }
+ /* strip whitespace if necessary */
+ while (cp > value && isspace ((unsigned char) *--cp))
+ *cp = '\0';
}
/* don't do special options only part of a module was specified */
@@ -460,7 +401,8 @@ do_module (db, mname, m_type, msg, callback_proc, where,
/* Put the value on a line with XXX prepended for getopt to eat */
line = xmalloc (strlen (value) + 10);
- (void) sprintf (line, "%s %s", "XXX", value);
+ strcpy(line, "XXX ");
+ strcpy(line + 4, value);
/* turn the line into an argv[] array */
line2argv (&xmodargc, &xmodargv, line, " \t");
@@ -478,56 +420,56 @@ do_module (db, mname, m_type, msg, callback_proc, where,
alias = 1;
break;
case 'd':
- nonalias_opt = 1;
if (mwhere)
free (mwhere);
mwhere = xstrdup (optarg);
+ nonalias_opt = 1;
break;
case 'i':
- nonalias_opt = 1;
if (checkin_prog)
free (checkin_prog);
checkin_prog = xstrdup (optarg);
+ nonalias_opt = 1;
break;
case 'l':
- nonalias_opt = 1;
local_specified = 1;
+ nonalias_opt = 1;
break;
case 'o':
- nonalias_opt = 1;
if (checkout_prog)
free (checkout_prog);
checkout_prog = xstrdup (optarg);
+ nonalias_opt = 1;
break;
case 'e':
- nonalias_opt = 1;
if (export_prog)
free (export_prog);
export_prog = xstrdup (optarg);
+ nonalias_opt = 1;
break;
case 't':
- nonalias_opt = 1;
if (tag_prog)
free (tag_prog);
tag_prog = xstrdup (optarg);
+ nonalias_opt = 1;
break;
case 'u':
- nonalias_opt = 1;
if (update_prog)
free (update_prog);
update_prog = xstrdup (optarg);
+ nonalias_opt = 1;
break;
case '?':
error (0, 0,
"modules file has invalid option for key %s value %s",
- key.dptr, val.dptr);
+ key.dptr, value);
err++;
goto do_module_return;
}
}
modargc -= optind;
modargv += optind;
- if (modargc == 0)
+ if (modargc == 0 && spec_opt == NULL)
{
error (0, 0, "modules file missing directory for module %s", mname);
++err;
@@ -575,15 +517,66 @@ module `%s' is a request for a file in a module which is not a directory",
}
/* otherwise, process this module */
- err += callback_proc (&modargc, modargv, where, mwhere, mfile, shorten,
- local_specified, mname, msg);
+ if (modargc > 0)
+ {
+ err += callback_proc (modargc, modargv, where, mwhere, mfile, shorten,
+ local_specified, mname, msg);
+ }
+ else
+ {
+ /*
+ * we had nothing but special options, so we must
+ * make the appropriate directory and cd to it
+ */
+ char *dir;
+
+ /* XXX - XXX - MAJOR HACK - DO NOT SHIP - this needs to
+ be !pipeout, but we don't know that here yet */
+ if (!run_module_prog)
+ goto do_special;
- free_names (&xmodargc, xmodargv);
+ dir = where ? where : (mwhere ? mwhere : mname);
+ /* XXX - think about making null repositories at each dir here
+ instead of just at the bottom */
+ make_directories (dir);
+ if ( CVS_CHDIR (dir) < 0)
+ {
+ error (0, errno, "cannot chdir to %s", dir);
+ spec_opt = NULL;
+ err++;
+ goto do_special;
+ }
+ if (!isfile (CVSADM))
+ {
+ char *nullrepos;
+
+ nullrepos = emptydir_name ();
+
+ Create_Admin (".", dir,
+ nullrepos, (char *) NULL, (char *) NULL, 0, 0, 1);
+ if (!noexec)
+ {
+ FILE *fp;
+
+ fp = open_file (CVSADM_ENTSTAT, "w+");
+ if (fclose (fp) == EOF)
+ error (1, errno, "cannot close %s", CVSADM_ENTSTAT);
+#ifdef SERVER_SUPPORT
+ if (server_active)
+ server_set_entstat (dir, nullrepos);
+#endif
+ }
+ free (nullrepos);
+ }
+ }
/* if there were special include args, process them now */
do_special:
+ free_names (&xmodargc, xmodargv);
+ xmodargv = NULL;
+
/* blow off special options if -l was specified */
if (local_specified)
spec_opt = NULL;
@@ -635,7 +628,7 @@ module `%s' is a request for a file in a module which is not a directory",
/* strip whitespace off the end */
do
*cp = '\0';
- while (isspace ((unsigned char) *--cp));
+ while (cp > spec_opt && isspace ((unsigned char) *--cp));
}
else
next_opt = NULL;
@@ -745,6 +738,7 @@ module `%s' is a request for a file in a module which is not a directory",
cvs_output (": Executing '", 0);
run_print (stdout);
cvs_output ("'\n", 0);
+ cvs_flushout ();
}
err += run_exec (RUN_TTY, RUN_TTY, RUN_TTY, RUN_NORMAL);
free (expanded_path);
@@ -755,6 +749,8 @@ module `%s' is a request for a file in a module which is not a directory",
do_module_return:
/* clean up */
+ if (xmodargv != NULL)
+ free_names (&xmodargc, xmodargv);
if (mwhere)
free (mwhere);
if (checkin_prog)
@@ -769,8 +765,8 @@ module `%s' is a request for a file in a module which is not a directory",
free (update_prog);
if (cwd_saved)
free_cwd (&cwd);
- if (zvalue != NULL)
- free (zvalue);
+ if (value != NULL)
+ free (value);
if (xvalue != NULL)
free (xvalue);
OpenPOWER on IntegriCloud