BOOTSTRAP (kutils) functions


LIBRARY ROUTINE

ksedfile - khoros string edit a file

LIBRARY CALL

int ksedfile(
   const char *ifilename,
   const char *ofilename,
   int  mode,
   int  *status,
   kvalist)

INPUT

OUTPUT

RETURN VALUE

TRUE (1) on success, FALSE (0) otherwise

DESCRIPTION

This routine takes two filenames, and copies the data from the source file to the destination file. It also uses a variable argument list consisting of pairs of strings and a logical value. The strings are used as a search pattern and a replacement pattern, respectively. The logical value is used to tell ksedfile whether or not to use kstring_replace or kregex_replace. A value of TRUE tells it to use kregex_replace, FALSE tells it to use kstring_replace. kregex_replace allows sed like substitutions, but is much slower than a straight string replace. This offers the user speed when patterns are simple, and versatility when necessary. Note, the variable argument list MUST be terminated with a NULL in one of the search pattern slots

For example, the following is a correct termination:

ksedfile(ifilename, ofilename, FALSE, KFILE_UPDATE, NULL, "t1", "t2", FALSE, NULL);

And this is an incorrect termination:

ksedfile(ifilename, ofilename, FALSE, KFILE_UPDATE, NULL, "t1", NULL);

The reason the NULL must be on the search pattern, is so that NULL can be sent in as the replacement string.

The mode parameter dictates how ksedfile should perform the string editing. The first mode is to query what would happen if string edition would take place. Whether any difference exists in which to update the destination. The second is to update the destination, only if a difference exists. The final mode is to overwrite the destination irregardless if a difference exists or not. The mode parameter can be one of:

KFILE_QUERY - returns whether an update would take place KFILE_UPDATE - updates the destination only if different KFILE_OVERWRITE - updates the destination irregardless if different

if KFILE_QUERY is specified then the "status" parameter will retain whether or not the output file would be updated. If KFILE_UPDATE is used then the "status" parameter is will retain whether to output file was actually changed or not. If KFILE_OVERWRITE is specified then the "status" parameter will always be TRUE, unless an error is encountered and ksedfile() returns FALSE.

ADDITIONAL INFORMATION

none

EXAMPLES

none

SIDE EFFECTS

none

RESTRICTIONS

none

MODIFICATION

none

FILES

$BOOTSTRAP/objects/library/kutils/src/file.c

SEE ALSO

kutils(3)

COPYRIGHT

Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.