Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / lib / DtSearch / delspace.c
1 /*
2  *   COMPONENT_NAME: austext
3  *
4  *   FUNCTIONS: delete_whitespace
5  *
6  *   ORIGINS: 27
7  *
8  *
9  *   (C) COPYRIGHT International Business Machines Corp. 1990,1995
10  *   All Rights Reserved
11  *   Licensed Materials - Property of IBM
12  *   US Government Users Restricted Rights - Use, duplication or
13  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
14  */
15 /***************************** DELSPACE.C *****************************
16  * $XConsortium: delspace.c /main/5 1996/05/07 13:28:17 drk $
17  * Removes trailing whitespace from a character buffer 
18  * (such as a line read in with fgets).
19  * If the last char in the original buffer was \n, 
20  * then the last char in the resulting string will be \n.
21  * Replaces all internal control and extended graphics
22  * characters (except the last \n) with a blank.
23  * Does nothing to empty strings ("\0") and strings
24  * beginning with a form feed ("\f....").
25  * All Conversions are done inplace, i.e. within 
26  * the same buffer passed to the function.
27  *
28  * $Log$
29  * Revision 2.3  1995/12/01  16:05:37  miker
30  * No longer overlays tabs with a space char.
31  *
32  * Revision 2.2  1995/10/25  22:06:36  miker
33  * Added prolog.
34  *
35  * Revision 2.1  1995/09/22  19:46:16  miker
36  * Freeze DtSearch 0.1, AusText 2.1.8
37  *
38  * Revision 1.2  1995/08/31  22:27:03  miker
39  * Minor changes for DtSearch.
40  */
41 #include "SearchP.h"
42 #include <ctype.h>
43
44 void            delete_whitespace (char *linebuf)
45 {
46     static char    *ptr, *endptr;
47     static int      has_linefeed;
48
49     /* do nothing if empty or ff string */
50     if (*linebuf == '\0' || *linebuf == '\f')
51         return;
52
53     ptr = linebuf + strlen (linebuf) - 1;
54     has_linefeed = (*ptr == '\n');
55     while (!isgraph (*ptr) && ptr >= linebuf)
56         ptr--;
57
58     endptr = ptr + 1;   /* endptr = just past last char */
59     for (ptr = linebuf; ptr < endptr; ptr++)
60         if (!isprint(*ptr) && *ptr != '\t')
61             *ptr = ' ';
62
63     if (has_linefeed)
64         *endptr++ = '\n';
65     *endptr = 0;
66     return;
67 }
68
69 /***************************** DELSPACE.C *****************************/