Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / DtSearch / delspace.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*
24  *   COMPONENT_NAME: austext
25  *
26  *   FUNCTIONS: delete_whitespace
27  *
28  *   ORIGINS: 27
29  *
30  *
31  *   (C) COPYRIGHT International Business Machines Corp. 1990,1995
32  *   All Rights Reserved
33  *   Licensed Materials - Property of IBM
34  *   US Government Users Restricted Rights - Use, duplication or
35  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
36  */
37 /***************************** DELSPACE.C *****************************
38  * $XConsortium: delspace.c /main/5 1996/05/07 13:28:17 drk $
39  * Removes trailing whitespace from a character buffer 
40  * (such as a line read in with fgets).
41  * If the last char in the original buffer was \n, 
42  * then the last char in the resulting string will be \n.
43  * Replaces all internal control and extended graphics
44  * characters (except the last \n) with a blank.
45  * Does nothing to empty strings ("\0") and strings
46  * beginning with a form feed ("\f....").
47  * All Conversions are done inplace, i.e. within 
48  * the same buffer passed to the function.
49  *
50  * $Log$
51  * Revision 2.3  1995/12/01  16:05:37  miker
52  * No longer overlays tabs with a space char.
53  *
54  * Revision 2.2  1995/10/25  22:06:36  miker
55  * Added prolog.
56  *
57  * Revision 2.1  1995/09/22  19:46:16  miker
58  * Freeze DtSearch 0.1, AusText 2.1.8
59  *
60  * Revision 1.2  1995/08/31  22:27:03  miker
61  * Minor changes for DtSearch.
62  */
63 #include "SearchP.h"
64 #include <ctype.h>
65
66 void            delete_whitespace (char *linebuf)
67 {
68     static char    *ptr, *endptr;
69     static int      has_linefeed;
70
71     /* do nothing if empty or ff string */
72     if (*linebuf == '\0' || *linebuf == '\f')
73         return;
74
75     ptr = linebuf + strlen (linebuf) - 1;
76     has_linefeed = (*ptr == '\n');
77     while (!isgraph (*ptr) && ptr >= linebuf)
78         ptr--;
79
80     endptr = ptr + 1;   /* endptr = just past last char */
81     for (ptr = linebuf; ptr < endptr; ptr++)
82         if (!isprint(*ptr) && *ptr != '\t')
83             *ptr = ' ';
84
85     if (has_linefeed)
86         *endptr++ = '\n';
87     *endptr = 0;
88     return;
89 }
90
91 /***************************** DELSPACE.C *****************************/