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