xref: /dragonfly/contrib/cvs-1.12/src/subr.h (revision 86d7f5d3)
1*86d7f5d3SJohn Marino /*
2*86d7f5d3SJohn Marino  * Copyright (c) 1992, Brian Berliner and Jeff Polk
3*86d7f5d3SJohn Marino  * Copyright (c) 1989-1992, Brian Berliner
4*86d7f5d3SJohn Marino  * Copyright (c) 2004, Derek R. Price and Ximbiot <http://ximbiot.com>
5*86d7f5d3SJohn Marino  * Copyright (c) 1989-2004 The Free Software Foundation <http://gnu.org>
6*86d7f5d3SJohn Marino  *
7*86d7f5d3SJohn Marino  * This program is free software; you can redistribute it and/or modify
8*86d7f5d3SJohn Marino  * it under the terms of the GNU General Public License as published by
9*86d7f5d3SJohn Marino  * the Free Software Foundation; either version 2, or (at your option)
10*86d7f5d3SJohn Marino  * any later version.
11*86d7f5d3SJohn Marino  *
12*86d7f5d3SJohn Marino  * This program is distributed in the hope that it will be useful,
13*86d7f5d3SJohn Marino  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14*86d7f5d3SJohn Marino  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*86d7f5d3SJohn Marino  * GNU General Public License for more details.
16*86d7f5d3SJohn Marino  */
17*86d7f5d3SJohn Marino 
18*86d7f5d3SJohn Marino #ifndef SUBR_H
19*86d7f5d3SJohn Marino # define SUBR_H
20*86d7f5d3SJohn Marino 
21*86d7f5d3SJohn Marino void expand_string (char **, size_t *, size_t);
22*86d7f5d3SJohn Marino char *Xreadlink (const char *link, size_t size);
23*86d7f5d3SJohn Marino void xrealloc_and_strcat (char **, size_t *, const char *);
24*86d7f5d3SJohn Marino int strip_trailing_newlines (char *str);
25*86d7f5d3SJohn Marino int pathname_levels (const char *path);
26*86d7f5d3SJohn Marino void free_names (int *pargc, char *argv[]);
27*86d7f5d3SJohn Marino void line2argv (int *pargc, char ***argv, char *line, char *sepchars);
28*86d7f5d3SJohn Marino int numdots (const char *s);
29*86d7f5d3SJohn Marino int compare_revnums (const char *, const char *);
30*86d7f5d3SJohn Marino char *increment_revnum (const char *);
31*86d7f5d3SJohn Marino char *getcaller (void);
32*86d7f5d3SJohn Marino char *previous_rev (RCSNode *rcs, const char *rev);
33*86d7f5d3SJohn Marino char *gca (const char *rev1, const char *rev2);
34*86d7f5d3SJohn Marino void check_numeric (const char *, int, char **);
35*86d7f5d3SJohn Marino char *make_message_rcsvalid (const char *message);
36*86d7f5d3SJohn Marino int file_has_markers (const struct file_info *);
37*86d7f5d3SJohn Marino void get_file (const char *, const char *, const char *,
38*86d7f5d3SJohn Marino                char **, size_t *, size_t *);
39*86d7f5d3SJohn Marino void resolve_symlink (char **filename);
40*86d7f5d3SJohn Marino char *backup_file (const char *file, const char *suffix);
41*86d7f5d3SJohn Marino char *shell_escape (char *buf, const char *str);
42*86d7f5d3SJohn Marino void sleep_past (time_t desttime);
43*86d7f5d3SJohn Marino 
44*86d7f5d3SJohn Marino /* for format_cmdline function - when a list variable is bound to a user string,
45*86d7f5d3SJohn Marino  * we need to pass some data through walklist into the callback function.
46*86d7f5d3SJohn Marino  * We use this struct.
47*86d7f5d3SJohn Marino  */
48*86d7f5d3SJohn Marino struct format_cmdline_walklist_closure
49*86d7f5d3SJohn Marino {
50*86d7f5d3SJohn Marino     const char *format;	/* the format string the user passed us */
51*86d7f5d3SJohn Marino     char **buf;		/* *dest = our NUL terminated and possibly too short
52*86d7f5d3SJohn Marino 			 * destination string
53*86d7f5d3SJohn Marino 			 */
54*86d7f5d3SJohn Marino     size_t *length;	/* *dlen = how many bytes have already been allocated to
55*86d7f5d3SJohn Marino 			 * *dest.
56*86d7f5d3SJohn Marino 			 */
57*86d7f5d3SJohn Marino     char **d;		/* our pointer into buf where the next char should go */
58*86d7f5d3SJohn Marino     char quotes;	/* quotes we are currently between, if any */
59*86d7f5d3SJohn Marino #ifdef SUPPORT_OLD_INFO_FMT_STRINGS
60*86d7f5d3SJohn Marino     int onearg;
61*86d7f5d3SJohn Marino     int firstpass;
62*86d7f5d3SJohn Marino     const char *srepos;
63*86d7f5d3SJohn Marino #endif /* SUPPORT_OLD_INFO_FMT_STRINGS */
64*86d7f5d3SJohn Marino     void *closure;	/* our user defined closure */
65*86d7f5d3SJohn Marino };
66*86d7f5d3SJohn Marino char *cmdlinequote (char quotes, char *s);
67*86d7f5d3SJohn Marino char *cmdlineescape (char quotes, char *s);
68*86d7f5d3SJohn Marino #ifdef SUPPORT_OLD_INFO_FMT_STRINGS
69*86d7f5d3SJohn Marino char *format_cmdline (bool oldway, const char *srepos, const char *format, ...);
70*86d7f5d3SJohn Marino #else /* SUPPORT_OLD_INFO_FMT_STRINGS */
71*86d7f5d3SJohn Marino char *format_cmdline (const char *format, ...);
72*86d7f5d3SJohn Marino #endif /* SUPPORT_OLD_INFO_FMT_STRINGS */
73*86d7f5d3SJohn Marino 
74*86d7f5d3SJohn Marino /* Many, many CVS calls to xstrdup depend on it to return NULL when its
75*86d7f5d3SJohn Marino  * argument is NULL.
76*86d7f5d3SJohn Marino  */
77*86d7f5d3SJohn Marino #define xstrdup Xstrdup
78*86d7f5d3SJohn Marino char *Xstrdup (const char *str)
79*86d7f5d3SJohn Marino 	__attribute__ ((__malloc__));
80*86d7f5d3SJohn Marino 
81*86d7f5d3SJohn Marino char *Xasprintf (const char *format, ...)
82*86d7f5d3SJohn Marino 	__attribute__ ((__malloc__, __format__ (__printf__, 1, 2)));
83*86d7f5d3SJohn Marino char *Xasnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
84*86d7f5d3SJohn Marino         __attribute__ ((__malloc__, __format__ (__printf__, 3, 4)));
85*86d7f5d3SJohn Marino bool readBool (const char *infopath, const char *option,
86*86d7f5d3SJohn Marino 	       const char *p, bool *val);
87*86d7f5d3SJohn Marino 
88*86d7f5d3SJohn Marino FILE *xfopen (const char *, const char *);
89*86d7f5d3SJohn Marino char *xcanonicalize_file_name (const char *path);
90*86d7f5d3SJohn Marino bool isThisHost (const char *otherhost);
91*86d7f5d3SJohn Marino bool isSamePath (const char *path1_in, const char *path2_in);
92*86d7f5d3SJohn Marino #endif /* !SUBR_H */
93