📄 msg_parser.awk
字号:
if ((getline dummy < TEMPLATE2) < 0) { print( TEMPLATE2 ": " ERRNO ); failed=1; exit(1); } getline dummy < TEMPLATE2; getline template2 < TEMPLATE2; getline dummy < TEMPLATE2; } if (TEMPLATE3) { if ((getline dummy < TEMPLATE3) < 0) { print( TEMPLATE3 ": " ERRNO ); failed=1; exit(1); } getline dummy < TEMPLATE3; getline template3 < TEMPLATE3; getline dummy < TEMPLATE3; } sub(/.*[\/]/, "", TEMPLATE); gsub(/#AUTO#/, auto, header); gsub(/#DATE#/, "@date Generated: " date, header); if (PACKAGE_NAME) gsub(/#PACKAGE_NAME#/, PACKAGE_NAME, header); if (PACKAGE_VERSION) gsub(/#PACKAGE_VERSION#/, PACKAGE_VERSION, header); print header > PR; RS=RS0; } if (!NO_FIRST) { protos("request", "/**< Request line */", -1); protos("status", "/**< Status line */", -2); } }}/^#### EXTRA HEADER LIST STARTS HERE ####$/ { HLIST=1; templates(); }HLIST && /^#### DEFAULT HEADER LIST ENDS HERE ####$/ { basic=total; }HLIST && /^#### EXPERIMENTAL HEADER LIST STARTS HERE ####$/ { without_experimental = total; }HLIST && /^[a-z]/ { protos($1, $0, 0, $2); headers[total++] = $1; Extra[$1] = extra++;}/^#### EXTRA HEADER LIST ENDS HERE ####$/ { HLIST=0; }/^ *\/\* === Headers start here \*\// { in_header_list=1; templates(); }/^ *\/\* === Headers end here \*\// { in_header_list=0; }PT && /^ *\/\* === Hash headers end here \*\// { in_header_list=0;}in_header_list && /^ (sip|rtsp|http|msg|mp)_[a-z_0-9]+_t/ { n=$0 sub(/;.*$/, "", n); sub(/^ *(sip|rtsp|http|msg|mp)_[a-z0-9_]*_t[ ]*/, "", n); sub(/^[*](sip|rtsp|http|msg|mp)_/, "", n); if ($0 !~ /[\/][*][*][<]/) { getline; } if ($0 !~ /[\/][*][*][<]/) { printf "msg_protos.awk: header %s is malformed\n", n; failed=1; exit 1; } if (!NO_MIDDLE) protos(n, $0, 0); headers[total] = n; total++; ordinary++;}function print_parser_table(struct, scope, name, N, N_EXPERIMENTAL){ if (PT) { if (N > ordinary) { printf("/* Ordinary %u, extra %u, experimental %u */\n", ordinary, N - ordinary, N_EXPERIMENTAL - N) > PT; printf("struct %s {\n", struct) > PT; printf(" %s_t base;\n", module) > PT; printf(" msg_header_t *extra[%u];\n", N - ordinary) > PT; if (N != N_EXPERIMENTAL) { print "#if SU_HAVE_EXPERIMENTAL" > PT; printf(" msg_header_t *extra[%u];\n", N_EXPERIMENTAL - N) > PT; print "#endif" > PT; } printf("};\n\n") > PT; } printf("%s\n", scope) > PT; printf("msg_mclass_t const %s[1] = \n{{\n", name) > PT; printf("# if defined (%s_HCLASS)\n", toupper(module)) > PT; printf(" %s_HCLASS,\n", toupper(module)) > PT; printf("#else\n") > PT; printf(" {{ 0 }},\n") > PT; printf("#endif\n") > PT; printf(" %s_VERSION_CURRENT,\n", toupper(module)) > PT; printf(" %s_PROTOCOL_TAG,\n", toupper(module)) > PT; printf("#if defined (%s_PARSER_FLAGS)\n", toupper(module)) > PT; printf(" %s_PARSER_FLAGS,\n", toupper(module)) > PT; printf("#else\n") > PT; printf(" 0,\n") > PT; printf("#endif\n") > PT; if (N > ordinary) { printf(" sizeof (struct %s),\n", struct) > PT; } else { printf(" sizeof (%s_t),\n", module) > PT; } printf(" %s_extract_body,\n", module) > PT; len = split("request status separator payload unknown error", unnamed, " "); for (i = 1; i <= len; i++) { printf(" {{ %s_%s_class, msg_offsetof(%s_t, %s_%s) }},\n", tprefix, unnamed[i], module, prefix, unnamed[i]) > PT; } if (multipart) { printf(" {{ %s_class, msg_offsetof(%s_t, %s_multipart) }},\n", multipart, module, prefix) > PT; } else { printf(" {{ NULL, 0 }},\n") > PT; } if (MC_SHORT_SIZE) { printf(" %s_short_forms, \n", module) > PT; } else { printf(" NULL, \n") > PT; } printf(" %d, \n", MC_HASH_SIZE) > PT; if (N != N_EXPERIMENTAL) { print "#if SU_HAVE_EXPERIMENTAL" > PT; printf(" %d,\n", N_EXPERIMENTAL) > PT; print "#else" > PT; } printf(" %d,\n", N) > PT; if (N != N_EXPERIMENTAL) { print "#endif" > PT; } printf(" {\n") > PT; for (j = 0; j < MC_HASH_SIZE; j++) { c = (j + 1 == MC_HASH_SIZE) ? "" : ","; if (j in header_hash) { n = header_hash[j]; i = index_hash[j]; flags = header_flags[n]; if (flags) flags = ",\n " flags; if (i >= N) { print "#if SU_HAVE_EXPERIMENTAL" > PT; } if (i >= ordinary) { printf(" { %s_%s_class,\n" \ " msg_offsetof(struct %s, extra[%u])%s }%s\n", tprefix, n, struct, Extra[n], flags, c) > PT; } else { printf(" { %s_%s_class, msg_offsetof(%s_t, %s_%s)%s }%s\n", tprefix, n, module, prefix, n, flags, c) > PT; } if (i >= N) { printf("#else\n { NULL, 0 }%s\n#endif\n", c) > PT; } } else { printf(" { NULL, 0 }%s\n", c) > PT; } } printf(" }\n}};\n\n") > PT; }}END { if (failed) { exit }; if (!NO_LAST) { protos("unknown", "/**< Unknown headers */", -3); protos("error", "/**< Erroneous headers */", -4); protos("separator", "/**< Separator line between headers and body */", -5); protos("payload", "/**< Message payload */", -6); if (multipart) protos("multipart", "/**< Multipart payload */", -7); } if (PR) { process_footer(footer); } else if (PT) { if (FLAGFILE) read_header_flags(FLAGFILE); if (TEMPLATE == "") { TEMPLATE = PT ".in"; } RS0=RS; RS="\n"; getline theader < TEMPLATE; getline header < TEMPLATE; getline template < TEMPLATE; getline footer < TEMPLATE; RS=RS0; sub(/.*[\/]/, "", TEMPLATE); gsub(/#AUTO#/, auto, header); gsub(/#DATE#/, "@date Generated: " date, header); print header > PT; print "" > PT; print "#define msg_offsetof(s, f) ((unsigned short)offsetof(s ,f))" > PT; print "" > PT; if (MC_SHORT_SIZE) { printf("static msg_href_t const " \ "%s_short_forms[MC_SHORT_SIZE] = \n{\n", module) > PT; for (i = 1; i <= MC_SHORT_SIZE; i = i + 1) { c = (i == MC_SHORT_SIZE) ? "" : ","; if (i in shorts) { n = shorts[i]; flags = header_flags[n]; if (flags) flags = ",\n " flags; printf(" { /* %s */ %s_%s_class, msg_offsetof(%s_t, %s_%s)%s }%s\n", substr(lower_case, i, 1), tprefix, n, module, prefix, n, flags, c) \ > PT; } else { printf(" { NULL }%s\n", c) \ > PT; } } printf("};\n\n") > PT; } # printf("extern msg_hclass_t msg_multipart_class[];\n\n") > PT; if (basic == 0) basic = total; if (without_experimental == 0) without_experimental = total; split("", header_hash); split("", index_hash); for (i = 0; i < basic; i++) { n = headers[i]; h = hashed[n]; if (h < 0) continue; j = h % MC_HASH_SIZE; if (j == -0) j = 0; for (; j in header_hash;) { if (++j == MC_HASH_SIZE) { j = 0; } } header_hash[j] = n; index_hash[j] = i; } m = module "_mclass"; s = "_d_" module "_t"; # Add basic headers if (ordinary == basic) { print_parser_table(s, "", m, basic, basic); } else if (basic < without_experimental) { print_parser_table(s, "", m, basic, basic); } else { print_parser_table(s, "", m, without_experimental, basic); } if (0) { # Hash extra headers for (i = basic; i < total; i++) { n = headers[i]; h = hashed[n]; if (h < 0) continue; j = h % MC_HASH_SIZE; if (j == -0) j = 0; for (; j in header_hash;) { if (++j == MC_HASH_SIZE) { j = 0; } } header_hash[j] = n; index_hash[j] = i; } if (basic < total) { m = module "_ext_mclass"; s = "_e_" module "_s"; print_parser_table(s, "static", m, without_experimental, total); } printf("msg_mclass_t const * %s_extended_mclass = %s;\n\n", module, m) > PT; } if (basic < total) { printf("msg_hclass_t * const %s_extensions[] = {\n", module) > PT; for (i = basic; i < total; i++) { if (i == without_experimental) { print "#if SU_HAVE_EXPERIMENTAL" > PT; } printf(" %s_%s_class,\n", module, headers[i]) > PT; } if (total != without_experimental) print "#endif" > PT; print " NULL\n};\n\n" > PT; } } exit success;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -