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