"Fossies" - the Fresh Open Source Software Archive

Member "leafnode-1.12.0/getfoldedline.c" (28 Dec 2021, 1372 Bytes) of package /linux/misc/leafnode-1.12.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "getfoldedline.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.11.12_vs_1.12.0.

    1 /* (C) 2002 - 2005 Matthias Andree. See COPYING for license conditions */
    2 
    3 #include "leafnode.h"
    4 #include "critmem.h"
    5 
    6 #ifdef WITH_DMALLOC
    7 #include <dmalloc.h>
    8 #endif
    9 
   10 #include <string.h>
   11 
   12 /*@null@*/ /*@only@*/ char *
   13 getfoldedline(FILE * f, char *(*reader)(FILE *))
   14 {
   15     /* what characters are considered whitespace that marks the beginning of
   16        continuation lines.
   17        WARNING: NEVER EVER list \n here! */
   18     static const char white[] = " \t";
   19     char *l1, *l2;
   20     int c;
   21     size_t len, oldlen;
   22 
   23     l1 = reader(f);
   24     if (!l1)
   25     return NULL;
   26     l2 = (char *)critmalloc((len = strlen(l1)) + 1, "getfoldedline");
   27     strcpy(l2, l1); /* RATS: ignore */
   28 
   29     /* only try to read continuation if the line is not empty 
   30      * and not a lone dot */
   31     if (*l2 && strcmp(l2, ".")) {
   32     for (;;) {
   33         c = fgetc(f);
   34         if (c != EOF) {
   35         ungetc(c, f);
   36         if (strchr(white, c)) {
   37             /* join */
   38             l1 = reader(f);
   39             if (l1) {
   40             oldlen = len;
   41             len += strlen(l1) + 1;
   42             l2 = (char *)critrealloc(l2, len + 2,
   43                            "getfoldedline");
   44             l2[oldlen++] = '\n';
   45             strcpy(l2 + oldlen, l1); /* RATS: ignore */
   46             }
   47         } else {
   48             break;
   49         }
   50         } else {
   51         break;
   52         }
   53     }
   54     }
   55     return l2;
   56 }
   57 
   58 #ifdef TEST
   59 int debug = 0;
   60 
   61 int
   62 main()
   63 {
   64     char *f;
   65     while ((f = getfoldedline(stdin, getaline))) {
   66     puts(f);
   67     free(f);
   68     }
   69     return 0;
   70 }
   71 #endif