"Fossies" - the Fresh Open Source Software Archive 
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /* replace.h - All the boring definitions for replace.c
2 (C) Richard K. Lloyd 2001-2004 */
3
4 /* Just reminding you what version we're up to... */
5 #define REPLACE_VERSION "2.24"
6 #define REPLACE_YEAR "2004"
7
8 /* Standard system header files */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <ctype.h>
12 #include <unistd.h>
13 #include <string.h>
14 #include <malloc.h>
15 #include <sys/stat.h>
16 #include <ftw.h>
17 #include <utime.h>
18 #include <signal.h>
19
20 /* Linux prefers to define getopt() in getopt.h */
21 #ifdef __linux__
22 #include <getopt.h>
23 #endif
24
25 /* Macros to allow prototypes to be declared when using
26 ANSI C. Does nothing for K&R compilers */
27 #ifdef __STDC__
28 #define P(a) a
29 #define P2(a,b) a,b
30 #define P3(a,b,c) a,b,c
31 #else
32 #define P(a)
33 #define P2(a,b)
34 #define P3(a,b,c)
35 #endif
36
37 /* If compiled with -DHAVE_LONG_LONG, set up needed long long definitions */
38 #ifdef HAVE_LONG_LONG
39 #define LONG_LONG signed long long
40 #define LONG_LONG_FORMAT "%lld"
41 #else
42 #define LONG_LONG signed long
43 #define LONG_LONG_FORMAT "%ld"
44 #endif
45
46 /* No agreement as to malloc() types...grrr... */
47 #define MALLOCPTR void *
48 #define MALLOCPAR size_t
49
50 extern char *optarg;
51 extern int optind;
52
53 #define BIN_CHUNK 16384 /* 16K chunks of binary data */
54
55 #define MAXSTRS 255 /* Maximum number of replacement pairs */
56
57 #define MAX_DIR_LEVELS 32 /* Maximum dir recursion */
58
59 #define MAX_SOFT_LINKS 16 /* Maximum number of soft-links before
60 assume a soft-link loop */
61
62 #define MAX_BIN_BYTES 256 /* Examine these number of bytes for binary chars */
63
64 /* Just in case someone fools around with the values... */
65 #if MAX_BIN_BYTES > BIN_CHUNK
66 #error MAX_BIN_BYTES must be <= BIN_CHUNK
67 #endif
68
69 #define DEF_BACKUP_SUFFIX ".cln" /* Default backup suffix */
70
71 #define DEF_TMP_DIR "/tmp" /* Default temporary directory */
72
73 #define TERMINAL_DEV "/dev/tty" /* Terminal device (keyboard) */
74
75 #define RENAME_COMMAND "/bin/mv -f" /* System command to rename files */
76
77 /* Global variables (define "Extern" as either nothing or extern) */
78
79 Extern char *oldstr[MAXSTRS+1]; /* Set of original strings */
80 Extern char *newstr[MAXSTRS+1]; /* Set of new strings */
81 Extern char *sufflist[MAXSTRS+1]; /* List of suffixes (-x option) */
82
83 /* Dynamically allocated buffer variables */
84 Extern char *binchunkptr; /* Binary replacement buffer */
85 Extern size_t binchunksize; /* Binary replacement buffer size */
86 Extern char *thestring; /* Text replacement buffer */
87 Extern size_t thestringsize; /* Text replacement buffer size */
88 Extern char *newline; /* New line output buffer */
89 Extern size_t newlinesize; /* New line output buffer size */
90
91 Extern char intitle[BUFSIZ]; /* Current file being string-replaced */
92 Extern char progname[BUFSIZ]; /* Basename of this executable */
93 Extern char backupsuff[BUFSIZ]; /* Backup suffix (usually .cln) */
94 Extern char filetype[16]; /* Holds "binary file" or "text file" depending on -b flag */
95 Extern char tmpdir[BUFSIZ]; /* Temporary direcotry to hold replaced file */
96 Extern char tempfile_cleanup[BUFSIZ]; /* Current temporary file */
97
98 Extern size_t oldstrlen[MAXSTRS],newstrlen[MAXSTRS]; /* Set of org/new strlens */
99
100 /* Misc. global int/size_t variables (see init.c) */
101 Extern int sensitive,word,force,prepadit,padit,verbose,startline,
102 recursive,prompt,fake,numfilereps,numfiles,
103 numreps,updated,linenum,repcount,binary,hex,maxreplines,
104 maxtimes,zeroterm,linecount,retainstamp,followsoftlinks,ascii,
105 autodetect;
106 Extern size_t autobinread,autobinsize,minsuff,numstrs,startcol,suffixes,
107 sufflen;
108
109 /* Initialisation routines */
110 Extern void leave(P(char *)),
111 tidy_up(P(void));
112
113 /* Other cross-source routines */
114 Extern void plural(P2(char *,LONG_LONG));
115 Extern int ask_user(P2(int,char *));
116 Extern char *alloc_mem(P3(char *,size_t *,size_t));
117 Extern char *basename_path(P(char *));
118 Extern void set_temp_file(P(char *));