2 * COMPONENT_NAME: austext
4 * FUNCTIONS: append_ext
10 * (C) COPYRIGHT International Business Machines Corp. 1990,1995
12 * Licensed Materials - Property of IBM
13 * US Government Users Restricted Rights - Use, duplication or
14 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
16 /*************************** APNDEXT.C *************************
17 * $XConsortium: apndext.c /main/5 1996/05/07 13:24:29 drk $
19 * 1. Concatenates a file extension to a passed filename,
20 * unless an extension is already provided in the name.
21 * Moves the concatenated string to the passed buffer.
22 * 2. Checks for filename buffer overflow.
25 * Same thing, except that if a dotted extension is already
26 * provided, it REPLACES the last extension with the passed one.
29 * Revision 2.2 1995/10/25 22:25:29 miker
32 * Revision 2.1 1995/09/22 18:08:26 miker
33 * Freeze DtSearch 0.1, AusText 2.1.8
38 /********************************************************/
42 /********************************************************/
43 void append_ext(char *buffer, /* output assy area */
44 int buflen, /* length of buffer */
45 char *fname, /* input prefix (file name) */
46 char *fext) /* input suffix (file ext .XXX) */
48 char *endptr, *slashptr, *dotptr;
50 strncpy (buffer, fname, buflen);
51 *(buffer + buflen - 5) = '\0'; /* room for ".xxx" at end */
53 /* Look for FINAL dot and FINAL slash (directory delim) */
54 dotptr = slashptr = NULL;
55 for (endptr = buffer; *endptr != 0; endptr++) {
56 if (*endptr == LOCAL_SLASH)
58 else if (*endptr == '.')
62 /* If extension already exists (ie there's a dot in the name),
63 * and its past any dir delim, if any,
64 * return immediately: the dot is a valid extension marker.
66 if (dotptr) { /* extension already exists */
69 else if (slashptr < dotptr)
73 /* Extension does not exist or its in earlier dir name */
74 strcpy (endptr, fext);
79 /********************************************************/
83 /********************************************************/
84 void replace_ext (char *buffer, /* output assy area */
85 int buflen, /* length of buffer */
86 char *fname, /* input prefix (file name) */
87 char *fext) /* input suffix (file ext .XXX) */
92 strncpy(buffer, fname, buflen - 1);
93 *(buffer + buflen - 1) = '\0'; /* just in case */
94 fnamelen = strlen(buffer);
95 if ((targ = strrchr(buffer, '.')) == NULL) {
96 strncpy (buffer + fnamelen, fext, buflen - fnamelen - 1);
97 *(buffer + buflen - 1) = '\0'; /* again just in case */
100 while (*targ != 0 && *fext != 0) *targ++ = *fext++;
101 if (*fext == 0) *targ = 0;
104 } /* replace_ext() */
106 /*************************** APNDEXT.C ****************************/