2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
24 * COMPONENT_NAME: austext
26 * FUNCTIONS: delete_whitespace
31 * (C) COPYRIGHT International Business Machines Corp. 1990,1995
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.
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.
51 * Revision 2.3 1995/12/01 16:05:37 miker
52 * No longer overlays tabs with a space char.
54 * Revision 2.2 1995/10/25 22:06:36 miker
57 * Revision 2.1 1995/09/22 19:46:16 miker
58 * Freeze DtSearch 0.1, AusText 2.1.8
60 * Revision 1.2 1995/08/31 22:27:03 miker
61 * Minor changes for DtSearch.
66 void delete_whitespace (char *linebuf)
68 static char *ptr, *endptr;
69 static int has_linefeed;
71 /* do nothing if empty or ff string */
72 if (*linebuf == '\0' || *linebuf == '\f')
75 ptr = linebuf + strlen (linebuf) - 1;
76 has_linefeed = (*ptr == '\n');
77 while (!isgraph (*ptr) && ptr >= linebuf)
80 endptr = ptr + 1; /* endptr = just past last char */
81 for (ptr = linebuf; ptr < endptr; ptr++)
82 if (!isprint(*ptr) && *ptr != '\t')
91 /***************************** DELSPACE.C *****************************/