File: indent.c

package info (click to toggle)
netcdf-parallel 1%3A4.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 105,352 kB
  • sloc: ansic: 229,114; sh: 11,180; yacc: 2,561; makefile: 1,390; lex: 1,173; xml: 173; awk: 2
file content (65 lines) | stat: -rw-r--r-- 1,448 bytes parent folder | download | duplicates (6)
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
59
60
61
62
63
64
65
/*********************************************************************
 *   Copyright 2018, UCAR/Unidata
 *   See netcdf/COPYRIGHT file for copying and redistribution conditions.
 *   $Header: /upc/share/CVS/netcdf-3/ncdump/indent.c,v 1.6 2009/09/28 18:27:04 russ Exp $
 *********************************************************************/

#include <stdio.h>

#include "indent.h"
static int indent = 0;
static int indent_increment = 2; /* blanks for each nesting level */

void 
indent_init() {		/*  initialize output line indent */
    indent = 0;
}

void 
indent_out(){		/*  output current indent */
    /* Just does this, but we avoid looping for small indents:

       int i;
       for (i=0; i < indent; i++)
	 printf(" ");

    */

    int indent_small = 8;
    char* indents[] = 
                     {"", 
		      " ", 
		      "  ", 
		      "   ", 
		      "    ", 
		      "     ", 
		      "      ", 
		      "       ", 
                      "        "
                     };

    int ind = indent;
    while (ind > indent_small) {
	(void) printf("%s", indents[indent_small]);
	ind -= indent_small;
    }
    (void) printf("%s", indents[ind]);
}

void 
indent_more(){		/*  increment current indent */
    indent += indent_increment;
}

void 
indent_less(){		/*  decrement current indent */
    indent -= indent_increment;
    if(indent < 0)
    	indent = 0;
}

int
indent_get() {		/* return current indent */
    return indent;
}