summaryrefslogtreecommitdiffstats
path: root/c/src/librdbg/src/awk.svc
blob: b9a88bdacacb8cacc1d33ef6c659999cf4a6391b (plain) (blame)
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
#########################################################################
#
#  Component:	RDBG
#  Module:	awk.svc
#
#  Synopsis:	AWK script which transforms the server skeleton produced
#		by rpcgen(1) into something suitable for RDB servers.
#
#########################################################################
#
# $Id$
#
BEGIN {
    headerstarted = 0
    withinproc = 0
    brack = 0
}

$1 ~ /^\/\*HEADER_START\*\/$/ {
    headerstarted = 1
    printf("#include <rpc/types.h>\n");
    printf("#include <rpc/rpc.h>\n");
    printf("#include <stdio.h>\n");
    printf("#include <stdlib.h>\n");
    printf("#include <string.h>\n");
    printf("#include <bsp.h>\n");
    printf("#include <rdbg/servrpc.h>\n");
    printf("#include <rdbg/%s>\n", THEPROG);
    printf("#define fprintf(a,b) printf(b)\n");
    printf("#define msgout(a) printf(a)\n")
    printf("#define _msgout(a) fprintf(stderr,a)\n");
}

$1 ~ /^\/\*HEADER_END\*\/$/ {
    headerstarted = 0
}

{
    if (headerstarted == 1) {
	print $0
    } else if ($1 ~ /.*_2.*/) {
	withinproc = 1
	printf("void\n");
	print $0
    } else if (withinproc == 1) {
	if ($1 == "switch") {
	    print "\tDPRINTF ((\"remotedeb_2: %s (%d)\\n\", "
	    print "\t\t(unsigned) rqstp->rq_proc < "
	    print "\t\t(unsigned) (sizeof names / sizeof names[0]) ?"
	    print "\t\tnames [rqstp->rq_proc] : \"???\", "
	    print "\t\t(int) rqstp->rq_proc));\n"
	}
	for (i = 1; i <= NF; i++) {
	    if ($i == "{") {
		brack++;
	    } else if ($i == "}") {
		brack--;
		if (brack == 0) {
		    withinproc = 0;
		}
	    }
        }
	if ($1 != "_rpcsvcdirty" ) {
	    print $0
        }
    }
}