prot-a-parse-arg-c.awk 6.76 KB
Newer Older
Linus Tolke Y's avatar
Linus Tolke Y committed
1
#
2
# $Id: prot-a-parse-arg-c.awk,v 0.28 2003/07/12 22:26:34 ceder Exp $
3
# Copyright (C) 1991-1994, 1996-1999, 2002  Lysator Academic Computer Association.
Linus Tolke Y's avatar
Linus Tolke Y committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#
# This file is part of the LysKOM server.
# 
# LysKOM is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by 
# the Free Software Foundation; either version 1, or (at your option) 
# any later version.
# 
# LysKOM is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
# 
# You should have received a copy of the GNU General Public License
# along with LysKOM; see the file COPYING.  If not, write to
# Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
# or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
# MA 02139, USA.
#
# Please mail bug reports to bug-lyskom@lysator.liu.se. 
#
25
# $Id: prot-a-parse-arg-c.awk,v 0.28 2003/07/12 22:26:34 ceder Exp $
Per Cederqvist's avatar
Per Cederqvist committed
26
27
28
BEGIN {
    printf("/* Don't edit this file - it is generated automatically");
    printf(" from\n   prot-a-parse-arg-c.awk and fncdef.txt */\n\n");
David Byers's avatar
David Byers committed
29
30
31
    printf("#ifdef HAVE_CONFIG_H\n");
    printf("#  include <config.h>\n");
    printf("#endif\n");
32
33
34
    printf("#include <sys/types.h>\n");
    printf("#include <sys/socket.h>\n");
    printf("#include <stdarg.h>\n");
Per Cederqvist's avatar
Per Cederqvist committed
35
    printf("#include <setjmp.h>\n");
36
    printf("#include \"timewrap.h\"\n");
37
    printf("\n");
Per Cederqvist's avatar
Per Cederqvist committed
38
39
    printf("#include \"oop.h\"\n");
    printf("\n");
40
    printf("#include \"s-string.h\"\n");
Per Cederqvist's avatar
Per Cederqvist committed
41
    printf("#include \"kom-types.h\"\n");
Per Cederqvist's avatar
Per Cederqvist committed
42
    printf("#include \"com.h\"\n");
43
    printf("#include \"isc-interface.h\"\n");
44
    printf("#include \"async.h\"\n");
Per Cederqvist's avatar
Per Cederqvist committed
45
46
    printf("#include \"connections.h\"\n");
    printf("#include \"isc-parse.h\"\n");
Per Cederqvist's avatar
Per Cederqvist committed
47
    printf("#include \"server/smalloc.h\"\n");
Per Cederqvist's avatar
Per Cederqvist committed
48
49
50
    printf("#include \"prot-a.h\"\n");
    printf("#include \"prot-a-parse.h\"\n");
    printf("#include \"prot-a-parse-arg.h\"\n");
David Byers's avatar
David Byers committed
51
    printf("#include \"kom-config.h\"\n");
52
    printf("#include \"param.h\"\n\n");
Per Cederqvist's avatar
Per Cederqvist committed
53
}
54
55
56
57
58
59
60
61
62
63
$1 == "#ifdef" {
    printf("#ifdef %s\n", $2);
    next;
}
$1 == "#endif" {
    printf("#endif\n");
    next;
}
$1 != "#" && $1 != "" {
    printf("void\nprot_a_parse_arg_%s(Connection *client)\n{\n", $3);
Per Cederqvist's avatar
Per Cederqvist committed
64
65
66
    printf("    switch( client->fnc_parse_pos )\n");
    printf("    {\n");
    num=0;
67
    pos=0;
Per Cederqvist's avatar
Per Cederqvist committed
68
69
    string=0;
    c_string=0;
70
    for ( i = 4; i <= NF; i++)
Per Cederqvist's avatar
Per Cederqvist committed
71
72
73
74
    {
	if ( $i == ":" )
	    break;

75
	printf("    case %d:\n", pos);
Per Cederqvist's avatar
Per Cederqvist committed
76
77
78
	if ( $i == "num" )
	    printf("\tclient->num%d = prot_a_parse_long(client);\n", num++);
	else if ( $i == "c_string" )
Per Cederqvist's avatar
Per Cederqvist committed
79
	   printf("\tprot_a_parse_string(client, &client->c_string%d, %s);\n",\
Per Cederqvist's avatar
Per Cederqvist committed
80
81
		   c_string++, $(++i));
	else if ( $i == "string" )
Per Cederqvist's avatar
Per Cederqvist committed
82
	    printf("\tprot_a_parse_string(client, &client->string%d, %s);\n",\
Per Cederqvist's avatar
Per Cederqvist committed
83
84
85
86
87
		   string++, $(++i));
	else if ( $i == "priv_bits" )
	    printf("\tprot_a_parse_priv_bits(client, &client->priv_bits);\n");
	else if ( $i == "conf_type" )
	    printf("\tprot_a_parse_conf_type(client, &client->conf_type);\n");
88
89
	else if ( $i == "membership_type" )
	    printf("\tprot_a_parse_membership_type(client, &client->membership_type);\n");
Per Cederqvist's avatar
Per Cederqvist committed
90
91
92
	else if ( $i == "c_local_text_no_p" )
	{
	    printf("\tif ( parse_nonwhite_char(client) != '{' )\n");
Per Cederqvist's avatar
Per Cederqvist committed
93
	    printf("\t    longjmp(parse_env, KOM_PROTOCOL_ERR);\n");
94
95
	    printf("\tif ( client->num%d > %s )\n",\
                   num-1, $(++i));
Per Cederqvist's avatar
Per Cederqvist committed
96
	    printf("\t    longjmp(parse_env, KOM_PROTOCOL_ERR);\n");
Per Cederqvist's avatar
Per Cederqvist committed
97
98
99
100
	    printf("\n");
	    printf("\tclient->c_local_text_no_p = ");
	    printf("smalloc(client->num%d\n", num-1);
	    printf("\t\t\t\t\t    * sizeof(Local_text_no));\n\n");
101
	    printf("\tclient->array_parse_index = 0;\n");
102
103
	    printf("\tclient->fnc_parse_pos = %d;\n", ++pos);
	    printf("    case %d:\n", pos);
104
	    printf("\twhile( client->array_parse_index < ");
Per Cederqvist's avatar
Per Cederqvist committed
105
106
107
	    printf("client->num%d )\n", num-1);
	    printf("\t{\n");
	    printf("\t    client->c_local_text_no_p[ client->");
108
	    printf("array_parse_index ]\n");
Per Cederqvist's avatar
Per Cederqvist committed
109
	    printf("\t\t= prot_a_parse_long(client);\n");
110
	    printf("\t    ++client->array_parse_index;\n");
Per Cederqvist's avatar
Per Cederqvist committed
111
	    printf("\t}\n");
112
113
	    printf("\tclient->fnc_parse_pos = %d;\n", ++pos);
	    printf("    case %d:\n", pos);
Per Cederqvist's avatar
Per Cederqvist committed
114
	    printf("\tif ( parse_nonwhite_char(client) != '}' )\n");
Per Cederqvist's avatar
Per Cederqvist committed
115
	    printf("\t    longjmp(parse_env, KOM_PROTOCOL_ERR);\n");
Per Cederqvist's avatar
Per Cederqvist committed
116
117
118
119
	}
	else if ( $i == "c_misc_info_p" )
	{
	    printf("\tif ( parse_nonwhite_char(client) != '{' )\n");
Per Cederqvist's avatar
Per Cederqvist committed
120
	    printf("\t    longjmp(parse_env, KOM_PROTOCOL_ERR);\n");
121
	    printf("\tif ( client->num%d > %s )\n", num-1, $(++i));
Per Cederqvist's avatar
Per Cederqvist committed
122
	    printf("\t    longjmp(parse_env, KOM_PROTOCOL_ERR);\n");
Per Cederqvist's avatar
Per Cederqvist committed
123
124
125
126
	    printf("\n");
	    printf("\tclient->c_misc_info_p = ");
	    printf("smalloc(client->num%d\n", num-1);
	    printf("\t\t\t\t\t* sizeof(Misc_info));\n");
127
	    printf("\tclient->array_parse_index = 0;\n");
128
129
	    printf("\tclient->fnc_parse_pos = %d;\n", ++pos);
	    printf("    case %d:\n", pos);
130
	    printf("\twhile( client->array_parse_index < ");
Per Cederqvist's avatar
Per Cederqvist committed
131
132
133
134
	    printf("client->num%d )\n", num-1);
	    printf("\t{\n");
	    printf("\t    prot_a_parse_misc_info(client,");
	    printf(" &client->c_misc_info_p");
135
136
	    printf("[ client->array_parse_index ]);\n");
	    printf("\t    ++client->array_parse_index;\n");
Per Cederqvist's avatar
Per Cederqvist committed
137
	    printf("\t}\n");
138
139
	    printf("\tclient->fnc_parse_pos = %d;\n", ++pos);
	    printf("    case %d:\n", pos);
Per Cederqvist's avatar
Per Cederqvist committed
140
	    printf("\tif ( parse_nonwhite_char(client) != '}' )\n");
Per Cederqvist's avatar
Per Cederqvist committed
141
	    printf("\t    longjmp(parse_env, KOM_PROTOCOL_ERR);\n");
Per Cederqvist's avatar
Per Cederqvist committed
142
	}
143
        else if ( $i == "aux_item" )
David Byers's avatar
David Byers committed
144
          printf("\tprot_a_parse_aux_item(client, &client->aux_item);\n");
145
146
	else if ( $i == "aux_item_list" )
          printf("\tprot_a_parse_aux_item_list(client, &client->aux_item_list, %s);\n", $(++i));
David Byers's avatar
David Byers committed
147
148
        else if ( $i == "misc_info_list" )
          printf("\tprot_a_parse_misc_info_list(client, &client->misc_info_list, %s);\n", $(++i));
149
	else if ( $i == "time_date" )
Per Cederqvist's avatar
Per Cederqvist committed
150
	    printf("\tprot_a_parse_time_date(client, &client->time);\n");
David Byers's avatar
David Byers committed
151
152
        else if ( $i == "info" )
            printf("\tprot_a_parse_info(client, &client->info);\n");
David Byers's avatar
David Byers committed
153
        else if ( $i == "num_list" )
154
155
            printf("\tprot_a_parse_num_list(client, &client->num_list, %s);\n",
		   $(++i));
David Byers's avatar
David Byers committed
156
157
        else if ( $i == "pers_flags" )
            printf("\tprot_a_parse_pers_flags(client, &client->pers_flags);\n");
Per Cederqvist's avatar
Per Cederqvist committed
158
159
160
        else if ( $i == "read_range_list" )
	    printf("\tprot_a_parse_read_range_list(client, " \
		   "&client->read_range_list, %s);\n", $(++i));
Per Cederqvist's avatar
Per Cederqvist committed
161
162
163
164
	else
	    printf("#error in prot-a-parse-arg-c.awk: not ready yet.\n");

	if ( i != NF && $(i+1) != ":")
165
	    printf("\tclient->fnc_parse_pos = %d;\n", ++pos);
Per Cederqvist's avatar
Per Cederqvist committed
166
167
168
169
170
171
172
173
174
175
    }

    printf("    default:\n");
    printf("\tclient->fnc_parse_pos = 0;\n");
    printf("    }\n");
    printf("}\n\n");
}
END {
    printf("/* end of this auto generated file. */\n");
}