1 /* $MirOS: src/gnu/usr.bin/cvs/src/cvs.h,v 1.6 2011/06/11 02:56:58 tg Exp $ */
2 
3 /*
4  * Copyright (C) 1986-2005 The Free Software Foundation, Inc.
5  *
6  * Portions Copyright (C) 1998-2005 Derek Price, Ximbiot <http://ximbiot.com>,
7  *                                  and others.
8  *
9  * Portions Copyright (C) 1992, Brian Berliner and Jeff Polk
10  * Portions Copyright (C) 1989-1992, Brian Berliner
11  *
12  * You may distribute under the terms of the GNU General Public License as
13  * specified in the README file that comes with the CVS kit.
14  */
15 
16 /*
17  * basic information used in all source files
18  *
19  */
20 
21 
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>		/* this is stuff found via autoconf */
24 #endif /* CONFIG_H */
25 
26 /* Add GNU attribute suppport.  */
27 #ifndef __attribute__
28 /* This feature is available in gcc versions 2.5 and later.  */
29 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
30 #  define __attribute__(Spec) /* empty */
31 # else
32 #   if __GNUC__ == 2 && __GNUC_MINOR__ < 96
33 #    define __pure__	/* empty */
34 #   endif
35 #   if __GNUC__ < 3
36 #    define __malloc__	/* empty */
37 #   endif
38 # endif
39 /* The __-protected variants of `format' and `printf' attributes
40    are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
41 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
42 #  define __const__	const
43 #  define __format__	format
44 #  define __noreturn__	noreturn
45 #  define __printf__	printf
46 # endif
47 #endif /* __attribute__ */
48 
49 /* Some GNULIB headers require that we include system headers first.  */
50 #include "system.h"
51 
52 /* begin GNULIB headers */
53 #include "dirname.h"
54 #include "exit.h"
55 #include "getdate.h"
56 #include "minmax.h"
57 #include "regex.h"
58 #include "strcase.h"
59 #include "stat-macros.h"
60 #include "timespec.h"
61 #include "unlocked-io.h"
62 #include "xalloc.h"
63 #include "xgetcwd.h"
64 #include "xreadlink.h"
65 #include "xsize.h"
66 /* end GNULIB headers */
67 
68 #if ! STDC_HEADERS
69 char *getenv();
70 #endif /* ! STDC_HEADERS */
71 
72 /* Under OS/2, <stdio.h> doesn't define popen()/pclose(). */
73 #ifdef USE_OWN_POPEN
74 #include "popen.h"
75 #endif
76 
77 #ifdef SERVER_SUPPORT
78 /* If the system doesn't provide strerror, it won't be declared in
79    string.h.  */
80 char *strerror (int);
81 #endif
82 
83 #include "hash.h"
84 #include "stack.h"
85 
86 #include "root.h"
87 
88 #if defined(SERVER_SUPPORT) || defined(CLIENT_SUPPORT)
89 # include "client.h"
90 #endif
91 
92 #ifdef MY_NDBM
93 #include "myndbm.h"
94 #else
95 #include <ndbm.h>
96 #endif /* MY_NDBM */
97 
98 #include "wait.h"
99 
100 #include "rcs.h"
101 
102 
103 
104 /* Note that the _ONLY_ reason for PATH_MAX is if various system calls (getwd,
105  * getcwd, readlink) require/want us to use it.  All other parts of CVS
106  * allocate pathname buffers dynamically, and we want to keep it that way.
107  */
108 #include "pathmax.h"
109 
110 
111 
112 /* Definitions for the CVS Administrative directory and the files it contains.
113    Here as #define's to make changing the names a simple task.  */
114 
115 #ifdef USE_VMS_FILENAMES
116 #define CVSADM          "CVS"
117 #define CVSADM_ENT      "CVS/Entries."
118 #define CVSADM_ENTBAK   "CVS/Entries.Backup"
119 #define CVSADM_ENTLOG   "CVS/Entries.Log"
120 #define CVSADM_ENTSTAT  "CVS/Entries.Static"
121 #define CVSADM_REP      "CVS/Repository."
122 #define CVSADM_ROOT     "CVS/Root."
123 #define CVSADM_TAG      "CVS/Tag."
124 #define CVSADM_NOTIFY   "CVS/Notify."
125 #define CVSADM_NOTIFYTMP "CVS/Notify.tmp"
126 #define CVSADM_BASE      "CVS/Base"
127 #define CVSADM_BASEREV   "CVS/Baserev."
128 #define CVSADM_BASEREVTMP "CVS/Baserev.tmp"
129 #define CVSADM_TEMPLATE "CVS/Template."
130 #else /* USE_VMS_FILENAMES */
131 #define	CVSADM		"CVS"
132 #define	CVSADM_ENT	"CVS/Entries"
133 #define	CVSADM_ENTBAK	"CVS/Entries.Backup"
134 #define CVSADM_ENTLOG	"CVS/Entries.Log"
135 #define	CVSADM_ENTSTAT	"CVS/Entries.Static"
136 #define	CVSADM_REP	"CVS/Repository"
137 #define	CVSADM_ROOT	"CVS/Root"
138 #define	CVSADM_TAG	"CVS/Tag"
139 #define CVSADM_NOTIFY	"CVS/Notify"
140 #define CVSADM_NOTIFYTMP "CVS/Notify.tmp"
141 /* A directory in which we store base versions of files we currently are
142    editing with "cvs edit".  */
143 #define CVSADM_BASE     "CVS/Base"
144 #define CVSADM_BASEREV  "CVS/Baserev"
145 #define CVSADM_BASEREVTMP "CVS/Baserev.tmp"
146 /* File which contains the template for use in log messages.  */
147 #define CVSADM_TEMPLATE "CVS/Template"
148 #endif /* USE_VMS_FILENAMES */
149 
150 /* This is the special directory which we use to store various extra
151    per-directory information in the repository.  It must be the same as
152    CVSADM to avoid creating a new reserved directory name which users cannot
153    use, but is a separate #define because if anyone changes it (which I don't
154    recommend), one needs to deal with old, unconverted, repositories.
155 
156    See fileattr.h for details about file attributes, the only thing stored
157    in CVSREP currently.  */
158 #define CVSREP "CVS"
159 
160 /*
161  * Definitions for the CVSROOT Administrative directory and the files it
162  * contains.  This directory is created as a sub-directory of the $CVSROOT
163  * environment variable, and holds global administration information for the
164  * entire source repository beginning at $CVSROOT.
165  */
166 #define	CVSROOTADM		"CVSROOT"
167 #define	CVSROOTADM_CHECKOUTLIST "checkoutlist"
168 #define CVSROOTADM_COMMITINFO	"commitinfo"
169 #define CVSROOTADM_CONFIG	"config"
170 #define	CVSROOTADM_HISTORY	"history"
171 #define	CVSROOTADM_IGNORE	"cvsignore"
172 #define	CVSROOTADM_LOGINFO	"loginfo"
173 #define	CVSROOTADM_MODULES	"modules"
174 #define CVSROOTADM_NOTIFY	"notify"
175 #define CVSROOTADM_PASSWD	"passwd"
176 #define CVSROOTADM_POSTADMIN	"postadmin"
177 #define CVSROOTADM_POSTPROXY	"postproxy"
178 #define CVSROOTADM_POSTTAG	"posttag"
179 #define CVSROOTADM_POSTWATCH	"postwatch"
180 #define CVSROOTADM_PREPROXY	"preproxy"
181 #define	CVSROOTADM_RCSINFO	"rcsinfo"
182 #define CVSROOTADM_READERS	"readers"
183 #define CVSROOTADM_TAGINFO      "taginfo"
184 #define CVSROOTADM_USERS	"users"
185 #define CVSROOTADM_VALTAGS	"val-tags"
186 #define CVSROOTADM_VERIFYMSG    "verifymsg"
187 #define CVSROOTADM_WRAPPER	"cvswrappers"
188 #define CVSROOTADM_WRITERS	"writers"
189 
190 #define CVSNULLREPOS		"Emptydir"	/* an empty directory */
191 
192 /* Other CVS file names */
193 
194 /* Files go in the attic if the head main branch revision is dead,
195    otherwise they go in the regular repository directories.  The whole
196    concept of having an attic is sort of a relic from before death
197    support but on the other hand, it probably does help the speed of
198    some operations (such as main branch checkouts and updates).  */
199 #define	CVSATTIC	"Attic"
200 
201 #define	CVSLCK		"#cvs.lock"
202 #define	CVSHISTORYLCK	"#cvs.history.lock"
203 #define	CVSVALTAGSLCK	"#cvs.val-tags.lock"
204 #define	CVSRFL		"#cvs.rfl"
205 #define	CVSPFL		"#cvs.pfl"
206 #define	CVSWFL		"#cvs.wfl"
207 #define CVSPFLPAT	"#cvs.pfl.*"	/* wildcard expr to match plocks */
208 #define CVSRFLPAT	"#cvs.rfl.*"	/* wildcard expr to match read locks */
209 #define	CVSEXT_LOG	",t"
210 #define	CVSPREFIX	",,"
211 #define CVSDOTIGNORE	".cvsignore"
212 #define CVSDOTWRAPPER   ".cvswrappers"
213 
214 /* Command attributes -- see function lookup_command_attribute(). */
215 #define CVS_CMD_IGNORE_ADMROOT        1
216 
217 /* Set if CVS needs to create a CVS/Root file upon completion of this
218    command.  The name may be slightly confusing, because the flag
219    isn't really as general purpose as it seems (it is not set for cvs
220    release).  */
221 
222 #define CVS_CMD_USES_WORK_DIR         2
223 
224 #define CVS_CMD_MODIFIES_REPOSITORY   4
225 
226 /* miscellaneous CVS defines */
227 
228 /* This is the string which is at the start of the non-log-message lines
229    that we put up for the user when they edit the log message.  */
230 #define	CVSEDITPREFIX	"CVS: "
231 /* Number of characters in CVSEDITPREFIX to compare when deciding to strip
232    off those lines.  We don't check for the space, to accomodate users who
233    have editors which strip trailing spaces.  */
234 #define CVSEDITPREFIXLEN 4
235 
236 #define	CVSLCKAGE	(60*60)		/* 1-hour old lock files cleaned up */
237 #define	CVSLCKSLEEP	30		/* wait 30 seconds before retrying */
238 #define	CVSBRANCH	"1.1.1"		/* RCS branch used for vendor srcs */
239 
240 #ifdef USE_VMS_FILENAMES
241 # define BAKPREFIX	"_$"
242 #else /* USE_VMS_FILENAMES */
243 # define BAKPREFIX	".#"		/* when rcsmerge'ing */
244 #endif /* USE_VMS_FILENAMES */
245 
246 /*
247  * Special tags. -rHEAD	refers to the head of an RCS file, regardless of any
248  * sticky tags. -rBASE	refers to the current revision the user has checked
249  * out This mimics the behaviour of RCS.
250  */
251 #define	TAG_HEAD	"HEAD"
252 #define	TAG_BASE	"BASE"
253 
254 /* Environment variable used by CVS */
255 #define	CVSREAD_ENV	"CVSREAD"	/* make files read-only */
256 #define	CVSREAD_DFLT	0		/* writable files by default */
257 
258 #define	CVSREADONLYFS_ENV "CVSREADONLYFS" /* repository is read-only */
259 
260 #define	TMPDIR_ENV	"TMPDIR"	/* Temporary directory */
261 #define	CVS_PID_ENV	"CVS_PID"	/* pid of running cvs */
262 
263 #define	EDITOR1_ENV	"CVSEDITOR"	/* which editor to use */
264 #define	EDITOR2_ENV	"VISUAL"	/* which editor to use */
265 #define	EDITOR3_ENV	"EDITOR"	/* which editor to use */
266 
267 #define	CVSROOT_ENV	"CVSROOT"	/* source directory root */
268 /* Define CVSROOT_DFLT to a fallback value for CVSROOT.
269  *
270 #undef	CVSROOT_DFL
271  */
272 
273 #define	IGNORE_ENV	"CVSIGNORE"	/* More files to ignore */
274 #define WRAPPER_ENV     "CVSWRAPPERS"   /* name of the wrapper file */
275 
276 #define	CVSUMASK_ENV	"CVSUMASK"	/* Effective umask for repository */
277 
278 /*
279  * If the beginning of the Repository matches the following string, strip it
280  * so that the output to the logfile does not contain a full pathname.
281  *
282  * If the CVSROOT environment variable is set, it overrides this define.
283  */
284 #define	REPOS_STRIP	"/master/"
285 
286 /* Large enough to hold DATEFORM.  Not an arbitrary limit as long as
287    it is used for that purpose, and not to hold a string from the
288    command line, the client, etc.  */
289 #define MAXDATELEN	50
290 
291 /* The type of an entnode.  */
292 enum ent_type
293 {
294     ENT_FILE, ENT_SUBDIR
295 };
296 
297 /* structure of a entry record */
298 struct entnode
299 {
300     enum ent_type type;
301     char *user;
302     char *version;
303 
304     /* Timestamp, or "" if none (never NULL).  */
305     char *timestamp;
306 
307     /* Keyword expansion options, or "" if none (never NULL).  */
308     char *options;
309 
310     char *tag;
311     char *date;
312     char *conflict;
313 };
314 typedef struct entnode Entnode;
315 
316 /* The type of request that is being done in do_module() */
317 enum mtype
318 {
319     CHECKOUT, TAG, PATCH, EXPORT, MISC
320 };
321 
322 /*
323  * structure used for list-private storage by Entries_Open() and
324  * Version_TS() and Find_Directories().
325  */
326 struct stickydirtag
327 {
328     /* These fields pass sticky tag information from Entries_Open() to
329        Version_TS().  */
330     int aflag;
331     char *tag;
332     char *date;
333     int nonbranch;
334 
335     /* This field is set by Entries_Open() if there was subdirectory
336        information; Find_Directories() uses it to see whether it needs
337        to scan the directory itself.  */
338     int subdirs;
339 };
340 
341 /* Flags for find_{names,dirs} routines */
342 #define W_LOCAL			0x01	/* look for files locally */
343 #define W_REPOS			0x02	/* look for files in the repository */
344 #define W_ATTIC			0x04	/* look for files in the attic */
345 
346 /* Flags for return values of direnter procs for the recursion processor */
347 enum direnter_type
348 {
349     R_PROCESS = 1,			/* process files and maybe dirs */
350     R_SKIP_FILES,			/* don't process files in this dir */
351     R_SKIP_DIRS,			/* don't process sub-dirs */
352     R_SKIP_ALL				/* don't process files or dirs */
353 };
354 #ifdef ENUMS_CAN_BE_TROUBLE
355 typedef int Dtype;
356 #else
357 typedef enum direnter_type Dtype;
358 #endif
359 
360 /* Recursion processor lock types */
361 #define CVS_LOCK_NONE	0
362 #define CVS_LOCK_READ	1
363 #define CVS_LOCK_WRITE	2
364 
365 /* Option flags for Parse_Info() */
366 #define PIOPT_ALL 1	/* accept "all" keyword */
367 
368 extern const char *program_name, *program_path, *cvs_cmd_name;
369 extern char *Editor;
370 extern char *LogMsgFile;
371 extern int cvsadmin_root;
372 extern char *CurDir;
373 extern int really_quiet, quiet;
374 extern int use_editor;
375 extern int cvswrite;
376 extern mode_t cvsumask;
377 
378 /* Temp dir abstraction.  */
379 /* From main.c.  */
380 const char *get_cvs_tmp_dir (void);
381 /* From filesubr.c.  */
382 const char *get_system_temp_dir (void);
383 void push_env_temp_dir (void);
384 
385 
386 /* This global variable holds the global -d option.  It is NULL if -d
387    was not used, which means that we must get the CVSroot information
388    from the CVSROOT environment variable or from a CVS/Root file.  */
389 extern char *CVSroot_cmdline;
390 
391 /* This variable keeps track of all of the CVSROOT directories that
392  * have been seen by the client.
393  */
394 extern List *root_directories;
395 
396 char *emptydir_name (void);
397 int safe_location (char *);
398 
399 extern int trace;		/* Show all commands */
400 extern int noexec;		/* Don't modify disk anywhere */
401 extern int readonlyfs;		/* fail on all write locks; succeed all read locks */
402 extern int logoff;		/* Don't write history entry */
403 
404 
405 
406 #define LOGMSG_REREAD_NEVER 0	/* do_verify - never  reread message */
407 #define LOGMSG_REREAD_ALWAYS 1	/* do_verify - always reread message */
408 #define LOGMSG_REREAD_STAT 2	/* do_verify - reread message if changed */
409 
410 /* This header needs the LOGMSG_* defns above.  */
411 #include "parseinfo.h"
412 
413 /* This structure holds the global configuration data.  */
414 extern struct config *config;
415 
416 #ifdef CLIENT_SUPPORT
417 extern List *dirs_sent_to_server; /* used to decide which "Argument
418 				     xxx" commands to send to each
419 				     server in multiroot mode. */
420 #endif
421 
422 extern char *hostname;
423 
424 /* Externs that are included directly in the CVS sources */
425 
426 int RCS_merge (RCSNode *, const char *, const char *, const char *,
427                const char *, const char *);
428 /* Flags used by RCS_* functions.  See the description of the individual
429    functions for which flags mean what for each function.  */
430 #define RCS_FLAGS_FORCE 1
431 #define RCS_FLAGS_DEAD 2
432 #define RCS_FLAGS_QUIET 4
433 #define RCS_FLAGS_MODTIME 8
434 #define RCS_FLAGS_KEEPFILE 16
435 #define RCS_FLAGS_USETIME 32
436 
437 int RCS_exec_rcsdiff (RCSNode *rcsfile, int diff_argc,
438                       char * const *diff_argv, const char *options,
439                       const char *rev1, const char *rev1_cache,
440                       const char *rev2,
441                       const char *label1, const char *label2,
442                       const char *workfile);
443 int diff_exec (const char *file1, const char *file2,
444                const char *label1, const char *label2,
445                int iargc, char * const *iargv, const char *out);
446 
447 
448 #include "error.h"
449 
450 /* If non-zero, error will use the CVS protocol to report error
451  * messages.  This will only be set in the CVS server parent process;
452  * most other code is run via do_cvs_command, which forks off a child
453  * process and packages up its stderr in the protocol.
454  *
455  * This needs to be here rather than in error.h in order to use an unforked
456  * error.h from GNULIB.
457  */
458 extern int error_use_protocol;
459 
460 
461 DBM *open_module (void);
462 List *Find_Directories (char *repository, int which, List *entries);
463 void Entries_Close (List *entries);
464 List *Entries_Open (int aflag, char *update_dir);
465 void Subdirs_Known (List *entries);
466 void Subdir_Register (List *, const char *, const char *);
467 void Subdir_Deregister (List *, const char *, const char *);
468 
469 void parse_tagdate (char **tag, char **date, const char *input);
470 char *Make_Date (const char *rawdate);
471 char *date_from_time_t (time_t);
472 void date_to_internet (char *, const char *);
473 void date_to_tm (struct tm *, const char *);
474 void tm_to_internet (char *, const struct tm *);
475 char *gmformat_time_t (time_t unixtime);
476 char *format_date_alloc (char *text);
477 
478 char *Name_Repository (const char *dir, const char *update_dir);
479 const char *Short_Repository (const char *repository);
480 void Sanitize_Repository_Name (char *repository);
481 
482 char *entries_time (time_t unixtime);
483 time_t unix_time_stamp (const char *file);
484 char *time_stamp (const char *file);
485 
486 typedef	int (*CALLPROC)	(const char *repository, const char *value,
487                          void *closure);
488 int Parse_Info (const char *infofile, const char *repository,
489                 CALLPROC callproc, int opt, void *closure);
490 
491 typedef	RETSIGTYPE (*SIGCLEANUPPROC)	(int);
492 int SIG_register (int sig, SIGCLEANUPPROC sigcleanup);
493 bool isdir (const char *file);
494 bool isfile (const char *file);
495 ssize_t islink (const char *file);
496 bool isdevice (const char *file);
497 bool isreadable (const char *file);
498 bool iswritable (const char *file);
499 bool isaccessible (const char *file, const int mode);
500 const char *last_component (const char *path);
501 char *get_homedir (void);
502 char *strcat_filename_onto_homedir (const char *, const char *);
503 char *cvs_temp_name (void);
504 FILE *cvs_temp_file (char **filename);
505 
506 int ls (int argc, char *argv[]);
507 int unlink_file (const char *f);
508 int unlink_file_dir (const char *f);
509 
510 int suck (int argc, char *argv[]);
511 
512 /* This is the structure that the recursion processor passes to the
513    fileproc to tell it about a particular file.  */
514 struct file_info
515 {
516     /* Name of the file, without any directory component.  */
517     const char *file;
518 
519     /* Name of the directory we are in, relative to the directory in
520        which this command was issued.  We have cd'd to this directory
521        (either in the working directory or in the repository, depending
522        on which sort of recursion we are doing).  If we are in the directory
523        in which the command was issued, this is "".  */
524     const char *update_dir;
525 
526     /* update_dir and file put together, with a slash between them as
527        necessary.  This is the proper way to refer to the file in user
528        messages.  */
529     const char *fullname;
530 
531     /* Name of the directory corresponding to the repository which contains
532        this file.  */
533     const char *repository;
534 
535     /* The pre-parsed entries for this directory.  */
536     List *entries;
537 
538     RCSNode *rcs;
539 };
540 
541 /* This needs to be included after the struct file_info definition since some
542  * of the functions subr.h defines refer to struct file_info.
543  */
544 #include "subr.h"
545 
546 int update (int argc, char *argv[]);
547 /* The only place this is currently used outside of update.c is add.c.
548  * Restricting its use to update.c seems to be in the best interest of
549  * modularity, but I can't think of a good way to get an update of a
550  * resurrected file done and print the fact otherwise.
551  */
552 void write_letter (struct file_info *finfo, int letter);
553 int xcmp (const char *file1, const char *file2);
554 void *valloc (size_t bytes);
555 
556 int Create_Admin (const char *dir, const char *update_dir,
557                   const char *repository, const char *tag, const char *date,
558                   int nonbranch, int warn, int dotemplate);
559 int expand_at_signs (const char *, size_t, FILE *);
560 
561 /* Locking subsystem (implemented in lock.c).  */
562 
563 int Reader_Lock (char *xrepository);
564 void Simple_Lock_Cleanup (void);
565 void Lock_Cleanup (void);
566 
567 /* Writelock an entire subtree, well the part specified by ARGC, ARGV, LOCAL,
568    and AFLAG, anyway.  */
569 void lock_tree_promotably (int argc, char **argv, int local, int which,
570 			   int aflag);
571 
572 /* See lock.c for description.  */
573 void lock_dir_for_write (const char *);
574 
575 /* Get a write lock for the history file.  */
576 int history_lock (const char *);
577 void clear_history_lock (void);
578 
579 /* Get a write lock for the val-tags file.  */
580 int val_tags_lock (const char *);
581 void clear_val_tags_lock (void);
582 
583 void Scratch_Entry (List * list, const char *fname);
584 void ParseTag (char **tagp, char **datep, int *nonbranchp);
585 void WriteTag (const char *dir, const char *tag, const char *date,
586                int nonbranch, const char *update_dir, const char *repository);
587 void WriteTemplate (const char *update_dir, int dotemplate,
588                     const char *repository);
589 void cat_module (int status);
590 void check_entries (char *dir);
591 void close_module (DBM * db);
592 void copy_file (const char *from, const char *to);
593 void fperrmsg (FILE * fp, int status, int errnum, char *message,...);
594 
595 int ign_name (char *name);
596 void ign_add (char *ign, int hold);
597 void ign_add_file (char *file, int hold);
598 void ign_setup (void);
599 void ign_dir_add (char *name);
600 int ignore_directory (const char *name);
601 typedef void (*Ignore_proc) (const char *, const char *);
602 void ignore_files (List *, List *, const char *, Ignore_proc);
603 extern int ign_inhibit_server;
604 
605 #include "update.h"
606 
607 void make_directories (const char *name);
608 void make_directory (const char *name);
609 int mkdir_if_needed (const char *name);
610 void rename_file (const char *from, const char *to);
611 /* Expand wildcards in each element of (ARGC,ARGV).  This is according to the
612    files which exist in the current directory, and accordingly to OS-specific
613    conventions regarding wildcard syntax.  It might be desirable to change the
614    former in the future (e.g. "cvs status *.h" including files which don't exist
615    in the working directory).  The result is placed in *PARGC and *PARGV;
616    the *PARGV array itself and all the strings it contains are newly
617    malloc'd.  It is OK to call it with PARGC == &ARGC or PARGV == &ARGV.  */
618 void expand_wild (int argc, char **argv,
619                   int *pargc, char ***pargv);
620 
621 /* exithandle.c */
622 void signals_register (RETSIGTYPE (*handler)(int));
623 void cleanup_register (void (*handler) (void));
624 
625 void update_delproc (Node * p);
626 void usage (const char *const *cpp);
627 void xchmod (const char *fname, int writable);
628 List *Find_Names (char *repository, int which, int aflag,
629 		  List ** optentries);
630 void Register (List * list, const char *fname, const char *vn, const char *ts,
631                const char *options, const char *tag, const char *date,
632                const char *ts_conflict);
633 void Update_Logfile (const char *repository, const char *xmessage,
634                      FILE *xlogfp, List *xchanges);
635 void do_editor (const char *dir, char **messagep,
636                 const char *repository, List *changes);
637 void logmsg_cleanup (int err);
638 
639 void do_verify (char **messagep, const char *repository, List *changes);
640 
641 typedef	int (*CALLBACKPROC)	(int argc, char *argv[], char *where,
642 	char *mwhere, char *mfile, int shorten, int local_specified,
643 	char *omodule, char *msg);
644 
645 
646 typedef	int (*FILEPROC) (void *callerdat, struct file_info *finfo);
647 typedef	int (*FILESDONEPROC) (void *callerdat, int err,
648                               const char *repository, const char *update_dir,
649                               List *entries);
650 typedef	Dtype (*DIRENTPROC) (void *callerdat, const char *dir,
651                              const char *repos, const char *update_dir,
652                              List *entries);
653 typedef	int (*DIRLEAVEPROC) (void *callerdat, const char *dir, int err,
654                              const char *update_dir, List *entries);
655 
656 int mkmodules (char *dir);
657 int init (int argc, char **argv);
658 
659 int do_module (DBM * db, char *mname, enum mtype m_type, char *msg,
660 		CALLBACKPROC callback_proc, char *where, int shorten,
661 		int local_specified, int run_module_prog, int build_dirs,
662 		char *extra_arg);
663 void history_write (int type, const char *update_dir, const char *revs,
664                     const char *name, const char *repository);
665 int start_recursion (FILEPROC fileproc, FILESDONEPROC filesdoneproc,
666 		     DIRENTPROC direntproc, DIRLEAVEPROC dirleaveproc,
667 		     void *callerdat,
668 		     int argc, char *argv[], int local, int which,
669 		     int aflag, int locktype, char *update_preload,
670 		     int dosrcs, char *repository);
671 void SIG_beginCrSect (void);
672 void SIG_endCrSect (void);
673 int SIG_inCrSect (void);
674 void read_cvsrc (int *argc, char ***argv, const char *cmdname);
675 
676 /* flags for run_exec(), the fast system() for CVS */
677 #define	RUN_NORMAL            0x0000    /* no special behaviour */
678 #define	RUN_COMBINED          0x0001    /* stdout is duped to stderr */
679 #define	RUN_REALLY            0x0002    /* do the exec, even if noexec is on */
680 #define	RUN_STDOUT_APPEND     0x0004    /* append to stdout, don't truncate */
681 #define	RUN_STDERR_APPEND     0x0008    /* append to stderr, don't truncate */
682 #define	RUN_SIGIGNORE         0x0010    /* ignore interrupts for command */
683 #define	RUN_TTY               (char *)0 /* for the benefit of lint */
684 
685 void run_add_arg_p (int *, size_t *, char ***, const char *s);
686 void run_arg_free_p (int, char **);
687 void run_add_arg (const char *s);
688 void run_print (FILE * fp);
689 void run_setup (const char *prog);
690 int run_exec (const char *stin, const char *stout, const char *sterr,
691               int flags);
692 int run_piped (int *, int *);
693 
694 /* other similar-minded stuff from run.c.  */
695 FILE *run_popen (const char *, const char *);
696 int piped_child (char *const *, int *, int *, bool);
697 void close_on_exec (int);
698 
699 pid_t waitpid (pid_t, int *, int);
700 
701 /*
702  * a struct vers_ts contains all the information about a file including the
703  * user and rcs file names, and the version checked out and the head.
704  *
705  * this is usually obtained from a call to Version_TS which takes a
706  * tag argument for the RCS file if desired
707  */
708 struct vers_ts
709 {
710     /* rcs version user file derives from, from CVS/Entries.
711        It can have the following special values:
712 
713        NULL = file is not mentioned in Entries (this is also used for a
714 	      directory).
715        "" = INVALID!  The comment used to say that it meant "no user file"
716 	    but as far as I know CVS didn't actually use it that way.
717 	    Note that according to cvs.texinfo, "" is not valid in the
718 	    Entries file.
719        0 = user file is new
720        -vers = user file to be removed.  */
721     char *vn_user;
722 
723     /* Numeric revision number corresponding to ->vn_tag (->vn_tag
724        will often be symbolic).  */
725     char *vn_rcs;
726     /* If ->tag is a simple tag in the RCS file--a tag which really
727        exists which is not a magic revision--and if ->date is NULL,
728        then this is a copy of ->tag.  Otherwise, it is a copy of
729        ->vn_rcs.  */
730     char *vn_tag;
731 
732     /* This is the timestamp from stating the file in the working directory.
733        It is NULL if there is no file in the working directory.  It is
734        "Is-modified" if we know the file is modified but don't have its
735        contents.  */
736     char *ts_user;
737     /* Timestamp from CVS/Entries.  For the server, ts_user and ts_rcs
738        are computed in a slightly different way, but the fact remains that
739        if they are equal the file in the working directory is unmodified
740        and if they differ it is modified.  */
741     char *ts_rcs;
742 
743     /* Options from CVS/Entries (keyword expansion), malloc'd.  If none,
744        then it is an empty string (never NULL).  */
745     char *options;
746 
747     /* If non-NULL, there was a conflict (or merely a merge?  See merge_file)
748        and the time stamp in this field is the time stamp of the working
749        directory file which was created with the conflict markers in it.
750        This is from CVS/Entries.  */
751     char *ts_conflict;
752 
753     /* Tag specified on the command line, or if none, tag stored in
754        CVS/Entries.  */
755     char *tag;
756     /* Date specified on the command line, or if none, date stored in
757        CVS/Entries.  */
758     char *date;
759     /* If this is 1, then tag is not a branch tag.  If this is 0, then
760        tag may or may not be a branch tag.  */
761     int nonbranch;
762 
763     /* Pointer to entries file node  */
764     Entnode *entdata;
765 
766     /* Pointer to parsed src file info */
767     RCSNode *srcfile;
768 };
769 typedef struct vers_ts Vers_TS;
770 
771 Vers_TS *Version_TS (struct file_info *finfo, char *options, char *tag,
772 			    char *date, int force_tag_match,
773 			    int set_time);
774 void freevers_ts (Vers_TS ** versp);
775 
776 /* Miscellaneous CVS infrastructure which layers on top of the recursion
777    processor (for example, needs struct file_info).  */
778 
779 int Checkin (int type, struct file_info *finfo, char *rev,
780 	     char *tag, char *options, char *message);
781 int No_Difference (struct file_info *finfo, Vers_TS *vers);
782 /* TODO: can the finfo argument to special_file_mismatch be changed? -twp */
783 int special_file_mismatch (struct file_info *finfo,
784 				  char *rev1, char *rev2);
785 
786 /* CVSADM_BASEREV stuff, from entries.c.  */
787 char *base_get (struct file_info *);
788 void base_register (struct file_info *, char *);
789 void base_deregister (struct file_info *);
790 
791 /*
792  * defines for Classify_File() to determine the current state of a file.
793  * These are also used as types in the data field for the list we make for
794  * Update_Logfile in commit, import, and add.
795  */
796 enum classify_type
797 {
798     T_UNKNOWN = 1,			/* no old-style analog existed	 */
799     T_CONFLICT,				/* C (conflict) list		 */
800     T_NEEDS_MERGE,			/* G (needs merging) list	 */
801     T_MODIFIED,				/* M (needs checked in) list 	 */
802     T_CHECKOUT,				/* O (needs checkout) list	 */
803     T_ADDED,				/* A (added file) list		 */
804     T_REMOVED,				/* R (removed file) list	 */
805     T_REMOVE_ENTRY,			/* W (removed entry) list	 */
806     T_UPTODATE,				/* File is up-to-date		 */
807     T_PATCH,				/* P Like C, but can patch	 */
808     T_TITLE				/* title for node type 		 */
809 };
810 typedef enum classify_type Ctype;
811 
812 Ctype Classify_File (struct file_info *finfo, char *tag, char *date, char *options,
813       int force_tag_match, int aflag, Vers_TS **versp, int pipeout);
814 
815 /*
816  * structure used for list nodes passed to Update_Logfile() and
817  * do_editor().
818  */
819 struct logfile_info
820 {
821   enum classify_type type;
822   char *tag;
823   char *rev_old;		/* rev number before a commit/modify,
824 				   NULL for add or import */
825   char *rev_new;		/* rev number after a commit/modify,
826 				   add, or import, NULL for remove */
827 };
828 
829 /* Wrappers.  */
830 
831 typedef enum { WRAP_MERGE, WRAP_COPY } WrapMergeMethod;
832 typedef enum {
833     /* -t and -f wrapper options.  Treating directories as single files.  */
834     WRAP_TOCVS,
835     WRAP_FROMCVS,
836     /* -k wrapper option.  Default keyword expansion options.  */
837     WRAP_RCSOPTION
838 } WrapMergeHas;
839 
840 void  wrap_setup (void);
841 int   wrap_name_has (const char *name,WrapMergeHas has);
842 char *wrap_rcsoption (const char *fileName, int asFlag);
843 char *wrap_tocvs_process_file (const char *fileName);
844 int   wrap_merge_is_copy (const char *fileName);
845 void wrap_fromcvs_process_file (const char *fileName);
846 void wrap_add_file (const char *file,int temp);
847 void wrap_add (char *line,int temp);
848 void wrap_send (void);
849 #if defined(SERVER_SUPPORT) || defined(CLIENT_SUPPORT)
850 void wrap_unparse_rcs_options (char **, int);
851 #endif /* SERVER_SUPPORT || CLIENT_SUPPORT */
852 
853 /* Pathname expansion */
854 char *expand_path (const char *name, const char *cvsroot, bool formatsafe,
855 		   const char *file, int line);
856 
857 /* User variables.  */
858 extern List *variable_list;
859 
860 void variable_set (char *nameval);
861 
862 int watch (int argc, char **argv);
863 int edit (int argc, char **argv);
864 int unedit (int argc, char **argv);
865 int editors (int argc, char **argv);
866 int watchers (int argc, char **argv);
867 int annotate (int argc, char **argv);
868 int add (int argc, char **argv);
869 int admin (int argc, char **argv);
870 int checkout (int argc, char **argv);
871 int commit (int argc, char **argv);
872 int diff (int argc, char **argv);
873 int history (int argc, char **argv);
874 int import (int argc, char **argv);
875 int cvslog (int argc, char **argv);
876 #ifdef AUTH_CLIENT_SUPPORT
877 /* Some systems (namely Mac OS X) have conflicting definitions for these
878  * functions.  Avoid them.
879  */
880 #ifdef HAVE_LOGIN
881 # define login		cvs_login
882 #endif /* HAVE_LOGIN */
883 #ifdef HAVE_LOGOUT
884 # define logout		cvs_logout
885 #endif /* HAVE_LOGOUT */
886 int login (int argc, char **argv);
887 int logout (int argc, char **argv);
888 #endif /* AUTH_CLIENT_SUPPORT */
889 int patch (int argc, char **argv);
890 int release (int argc, char **argv);
891 int cvsremove (int argc, char **argv);
892 int rtag (int argc, char **argv);
893 int cvsstatus (int argc, char **argv);
894 int cvstag (int argc, char **argv);
895 int version (int argc, char **argv);
896 
897 unsigned long int lookup_command_attribute (const char *);
898 
899 #if defined(AUTH_CLIENT_SUPPORT) || defined(AUTH_SERVER_SUPPORT)
900 char *scramble (char *str);
901 char *descramble (char *str);
902 #endif /* AUTH_CLIENT_SUPPORT || AUTH_SERVER_SUPPORT */
903 
904 #ifdef AUTH_CLIENT_SUPPORT
905 char *get_cvs_password (void);
906 /* get_cvs_port_number() is not pure since the /etc/services file could change
907  * between calls.  */
908 int get_cvs_port_number (const cvsroot_t *root);
909 /* normalize_cvsroot() is not pure since it calls get_cvs_port_number.  */
910 char *normalize_cvsroot (const cvsroot_t *root)
911 	__attribute__ ((__malloc__));
912 #endif /* AUTH_CLIENT_SUPPORT */
913 
914 void tag_check_valid (const char *, int, char **, int, int, char *, bool);
915 
916 #include "server.h"
917 
918 /* From server.c and documented there.  */
919 void cvs_output (const char *, size_t);
920 void cvs_output_binary (char *, size_t);
921 void cvs_outerr (const char *, size_t);
922 void cvs_flusherr (void);
923 void cvs_flushout (void);
924 void cvs_output_tagged (const char *, const char *);
925 
926 extern const char *global_session_id;
927 
928 /* From find_names.c.  */
929 List *find_files (const char *dir, const char *pat);
930