/*************************************************************************\ * Copyright (c) 2002 The University of Chicago, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. * This file is distributed subject to a Software License Agreement found * in the file LICENSE that is included with this distribution. \*************************************************************************/ /* * $Log: replaceText.c,v $ * Revision 1.4 2006/06/27 15:18:39 shang * added include/sinclude file feature * * Revision 1.3 2003/09/02 18:08:32 soliday * Cleaned up code for Linux. * * Revision 1.2 2002/08/14 16:49:36 soliday * Added Open License * * Revision 1.1 2000/04/11 19:57:59 soliday * Moved from elegant * * Revision 1.1 2000/04/11 15:10:23 borland * First version of utility for text replacements. * * * program: replaceText * purpose: replace strings in a file. * a simplified variant of the replace program. * * Michael Borland, 2000 */ #include "mdb.h" #include "scan.h" #define SET_ORIGINAL 0 #define SET_REPLACEMENT 1 #define SET_VERBOSE 2 #define SET_STRINGS 3 #define SET_STDIO 4 #define SET_FILTER 5 #define N_OPTIONS 6 char *option[N_OPTIONS] = { "original", "replacement", "verbose", "strings", "stdio", "filter", } ; #define USAGE "replaceText {input [output] | -stdio | -strings=string[,string...]}\n\ -original=string[,string...] -replacement=string[,string...]\n\ [-verbose] [-filter=string[,string...]]\n\n\ -stdio Take input from standard input and deliver output to standard output.\n\ -strings Perform replacement on the listed strings.\n\ -original List of strings to replace.\n\ -replacement Parallel list of replacements for original strings.\n\ -verbose Report the number of replacements made.\n\ -filter Perform replacement only on lines containing one or more of the\n\ strings in the filter list.\n\n\ Program by Michael Borland. (This is version 1, April 2000)." int replace_string1(char *t, char *s, char *orig, char *repl); long passesFilters(char *s, char **filter, long filters); char *strextract(char *s, char start, char end, long include); void process_include_file(char *str, FILE *out, char **oirg, char **repl, int n_pairs, char **filter, int filters, int *count); int main( int argc, char **argv ) { char **orig, **repl, *input, *output, *ptr, **filter; char **string_list; int n_pairs, i_pair, filters; char s[1024], t[1024]; FILE *fpi=NULL, *fpo=NULL; SCANNED_ARG *s_arg; int i_arg, *count, n_strings=0, use_stdio; char *input_fn, *output_fn; int tmp_file, verbose; argc = scanargs(&s_arg, argc, argv); if (argc<2 || argc>(3+N_OPTIONS)) bomb("too few or too many arguments", USAGE); input = output = NULL; orig = repl = filter = NULL; n_pairs = verbose = filters = 0; string_list = NULL; use_stdio = tmp_file = 0; for (i_arg=1; i_arg