-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprinter.c
More file actions
92 lines (80 loc) · 1.6 KB
/
printer.c
File metadata and controls
92 lines (80 loc) · 1.6 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* cdoc
* Copyright (c) 2019 Matthew Veety.
* See LICENSE for details
*/
#include "impl.h"
int tabtype = TabNative;
int tabstop = 4;
void
_indentone(int ofd)
{
int i;
switch(tabtype){
case TabNative:
dprintf(ofd, "\t");
break;
case TabSpaces:
for(i = 0; i < tabstop; i++)
dprintf(ofd, " ");
break;
}
}
void
indent(int ofd, int depth)
{
int i;
if(depth == 0)
return;
for(i = 0; i < depth; i++)
_indentone(ofd);
}
void
doclineprinter(int ofd, Docline *dl, int tab)
{
indent(ofd, tab);
dprintf(ofd, "%s\n", dl->dat);
}
void
functionprinter(int ofd, Function *fn, int tab, int lastfn)
{
int i;
Docline *cur;
indent(ofd, tab);
dprintf(ofd, "%s:%d", fn->fname, fn->linenum);
indent(ofd, 1);
dprintf(ofd, "%s %s(", fn->type, fn->name);
if(fn->argn == 0){
dprintf(ofd, "void");
} else {
for(i = 0; i < fn->argn; i++){
if(i != 0)
dprintf(ofd, ", ");
dprintf(ofd, "%s %s", fn->argtypes[i], fn->argnames[i]);
}
}
dprintf(ofd, ")\n");
if(fn->doclines != nil)
for(cur = fn->doclines; cur != nil; cur = cur->next)
doclineprinter(ofd, cur, tab+1);
if(!lastfn)
dprintf(ofd, "\n");
}
void
docfileprinter(int ofd, Docfile *df, int tab, int printfname)
{
Docline *dlcur;
Function *fncur;
if(printfname){
indent(ofd, tab);
dprintf(ofd, "%s\n\n", df->fname);
}
if(df->globaldocs != nil)
for(dlcur = df->globaldocs; dlcur != nil; dlcur = dlcur->next)
doclineprinter(ofd, dlcur, tab);
dprintf(ofd, "\n");
if(df->funs != nil)
for(fncur = df->funs; fncur != nil; fncur = fncur->next)
functionprinter(ofd, fncur, tab, fncur->next == nil ? 1 : 0);
dprintf(ofd, "\n");
}