File: squeeze.c

package info (click to toggle)
grass 6.0.2-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 40,044 kB
  • ctags: 31,303
  • sloc: ansic: 321,125; tcl: 25,676; sh: 11,176; cpp: 10,098; makefile: 5,025; fortran: 1,846; yacc: 493; lex: 462; perl: 133; sed: 1
file content (58 lines) | stat: -rw-r--r-- 1,403 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <string.h>
#include "gis.h"
/*
 * squeeze - edit superfluous white space out of strings
 *
 *  char *G_squeeze (s)
 *     char *s;
 *
 * scan a string of text, converting tabs to spaces and
 * compressing out leading spaces, redundant internal spaces,
 * and trailing spaces.
 * returns the address of the resulting compressed string.
 *
 * last modification: 12 aug 81, j w hamilton
 *
 * 1998-04-04  WBH
 *     Also squeezes out newlines -- easier to use with fgets()
 *
 * 1999-19-12 Werner Droege 
 *     changed line 37, line 48ff. -- return (strip_NL(line))
 */

#include <ctype.h>


/*!
 * \brief remove unnecessary white space
 *
 * Leading and trailing white space is removed from the string <b>s</b> and internal
 * white space which is more than one character is reduced to a single space
 * character. White space here means spaces, tabs, linefeeds, newlines, and
 * formfeeds. Returns <b>s.</b>
 *
 *  \param s
 *  \return char * 
 */

char *G_squeeze (char *line)
{
    register char *f = line, *t = line;
    int l;

    /* skip over space at the beginning of the line. */
    while (isspace (*f))
        f++;

    while (*f)
        if (! isspace (*f))
            *t++ = *f++;
        else
            if (*++f)
                if (! isspace (*f))
                    *t++ = ' ';
    *t = '\0';
    l=strlen(line)-1;
    if(*(line+l)=='\n') *(line+l)='\0';
    return line;
}