File: ostreaminsert.c

package info (click to toggle)
yodl 4.05.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,724 kB
  • sloc: ansic: 7,803; perl: 683; cpp: 570; sh: 411; xml: 190; makefile: 163
file content (58 lines) | stat: -rw-r--r-- 1,863 bytes parent folder | download | duplicates (5)
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 "ostream.ih"

static size_t s_last_line;
static bool   s_errors;

void ostream_insert(register Ostream *ostream, char const *str)
{
    if (s_errors)                           /* return on errors             */
        return;

    if (message_errors())                   /* repeatedly done on errors    */
    {                                       /* but that's ok                */
        s_errors = true;
        return;
    }

    if (!*str)                              /* no string, nogo */
    {
        if (message_show(MSG_DEBUG))
            message("INSERT: <nothing>");
        return;
    }

    if (message_show(MSG_DEBUG))
        message("INSERT \"%s\"", str);

    if (ostream->d_trace)
        fprintf(stderr, "%s", str);

    if (ostream->d_ws_only)
    {
        String out;
        bool non_ws;

        string_construct(&out, str);

                                    /* Ugly semantics, but it means:        */
                                    /* true if there are any non-white      */
                                    /* white-space in `out'                 */
                                /* we did not fail to find the first non-ws */
        non_ws = string_find_first_not_of(&out, isspace) != UFAILED;

        if (non_ws)                 /* If we did find NON-ws chars here */
        {
            if (s_last_line != message_lineno())
            {
                s_last_line = message_lineno();
                warning("IGNORED unexpected non-whitespace text `%s'",
                                                string_str(&out));
            }
            string_destruct(&out);
            return;                 /* ignore the cargo if it contains  */
                                    /* non-ws                           */
        }
        string_destruct(&out);
    }
    o_output(ostream, str);
}