2 * Copyright (C) 1986-2005 The Free Software Foundation, Inc.
4 * Portions Copyright (C) 1998-2005 Derek Price, Ximbiot <http://ximbiot.com>,
7 * Portions Copyright (C) 1993 david d zuhn
9 * Written by david d `zoo' zuhn while at Cygnus Support
11 * You may distribute under the terms of the GNU General Public License as
12 * specified in the README file that comes with the CVS source distribution.
20 /* this file is to be found in the user's home directory */
22 #ifndef CVSRC_FILENAME
23 #define CVSRC_FILENAME ".cvsrc"
25 char cvsrc[] = CVSRC_FILENAME;
29 extern char *strtok ();
31 /* Read cvsrc, processing options matching CMDNAME ("cvs" for global
32 options, and update *ARGC and *ARGV accordingly. */
35 read_cvsrc (argc, argv, cmdname)
46 size_t line_chars_allocated;
59 /* old_argc and old_argv hold the values returned from the
60 previous invocation of read_cvsrc and are used to free the
61 allocated memory. The first invocation of read_cvsrc gets argv
62 from the system, this memory must not be free'd. */
63 static int old_argc = 0;
64 static char **old_argv = NULL;
66 /* don't do anything if argc is -1, since that implies "help" mode */
70 /* determine filename for ~/.cvsrc */
72 homedir = get_homedir ();
73 /* If we can't find a home directory, ignore ~/.cvsrc. This may
74 make tracking down problems a bit of a pain, but on the other
75 hand it might be obnoxious to complain when CVS will function
76 just fine without .cvsrc (and many users won't even know what
81 homeinit = strcat_filename_onto_homedir (homedir, cvsrc);
83 /* if it can't be read, there's no point to continuing */
85 if (!isreadable (homeinit))
91 /* now scan the file until we find the line for the command in question */
94 line_chars_allocated = 0;
95 command_len = strlen (cmdname);
96 cvsrcfile = open_file (homeinit, "r");
97 while ((line_length = getline (&line, &line_chars_allocated, cvsrcfile))
100 /* skip over comment lines */
104 /* stop if we match the current command */
105 if (!strncmp (line, cmdname, command_len)
106 && isspace ((unsigned char) *(line + command_len)))
113 if (line_length < 0 && !feof (cvsrcfile))
114 error (0, errno, "cannot read %s", homeinit);
118 /* setup the new options list */
121 max_new_argv = (*argc) + GROW;
122 new_argv = (char **) xmalloc (max_new_argv * sizeof (char*));
123 new_argv[0] = xstrdup ((*argv)[0]);
127 /* skip over command in the options line */
128 for (optstart = strtok (line + command_len, "\t \n\r");
130 optstart = strtok (NULL, "\t \n\r"))
132 new_argv [new_argc++] = xstrdup (optstart);
134 if (new_argc >= max_new_argv)
136 max_new_argv += GROW;
137 new_argv = (char **) xrealloc (new_argv, max_new_argv * sizeof (char*));
145 /* now copy the remaining arguments */
147 if (new_argc + *argc > max_new_argv)
149 max_new_argv = new_argc + *argc;
150 new_argv = (char **) xrealloc (new_argv, max_new_argv * sizeof (char*));
152 for (i=1; i < *argc; i++)
154 new_argv [new_argc++] = xstrdup ((*argv)[i]);
157 if (old_argv != NULL)
159 /* Free the memory which was allocated in the previous
161 free_names (&old_argc, old_argv);
164 old_argc = *argc = new_argc;
165 old_argv = *argv = new_argv;