1 /*********************************************************************
2 * Copyright 2007, UCAR/Unidata
3 * See netcdf/COPYRIGHT file for copying and redistribution conditions.
4 * $Header: /upc/share/CVS/netcdf-3/ncdump/indent.c,v 1.6 2009/09/28 18:27:04 russ Exp $
5 *********************************************************************/
6
7 #include <stdio.h>
8
9 #include "indent.h"
10 static int indent = 0;
11 static int indent_increment = 2; /* blanks for each nesting level */
12
13 void
indent_init()14 indent_init() { /* initialize output line indent */
15 indent = 0;
16 }
17
18 void
indent_out()19 indent_out(){ /* output current indent */
20 /* Just does this, but we avoid looping for small indents:
21
22 int i;
23 for (i=0; i < indent; i++)
24 printf(" ");
25
26 */
27
28 int indent_small = 8;
29 char* indents[] =
30 {"",
31 " ",
32 " ",
33 " ",
34 " ",
35 " ",
36 " ",
37 " ",
38 " "
39 };
40
41 int ind = indent;
42 while (ind > indent_small) {
43 (void) printf("%s", indents[indent_small]);
44 ind -= indent_small;
45 }
46 (void) printf("%s", indents[ind]);
47 }
48
49 void
indent_more()50 indent_more(){ /* increment current indent */
51 indent += indent_increment;
52 }
53
54 void
indent_less()55 indent_less(){ /* decrement current indent */
56 indent -= indent_increment;
57 if(indent < 0)
58 indent = 0;
59 }
60
61 int
indent_get()62 indent_get() { /* return current indent */
63 return indent;
64 }
65
66