#!/usr/bin/awk -f # # Copyright (c) 1995, 1996 Gunther Schadow. All rights reserved. # # This program 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 2 of the License, or # (at your option) any later version. # # This program 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 this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. BEGIN{ DEBUG=0; OUTPUT=/dev/stdout; FS="( +)| "; for(i=1; i "/dev/stderr" ; ERROR=1 ; exit 3 ; } function warning(msg, obj) { printf("%s:%d:warning at `%s': %s\n", FILENAME, FNR, obj, msg) > "/dev/stderr" ; } function trace_rule(x) { if(DEBUG) printf("Rule %s\n", x); } function finish_message() { if(MESSAGE) { MESSAGE=0; empty_lines=0; printf("]).\n"); } } DEBUG==2 { printf("\n% 4d %s\n", FNR, $0); printf("MESSAGE=%d, empty_lines=%d, $1=`%s', \n", MESSAGE, empty_lines, $1); } FNR==1 { # descriptive header printf("\n%% exmsg.awk output from `%s', %s\n%%\n", \ FILENAME, \ strftime("%D %T",systime())); } $0~"\\(event code " EVCID "\\)" { trace_rule(1); event=$0 gsub("^.*event code ","",event); gsub("\\).*$","",event); event=tolower(event); } $0~"\\(Trigger Event " EVCID "\\)" { trace_rule(2); event=$0 gsub("^.*Trigger Event ","",event); gsub("\\).*$","",event); event=tolower(event); } $0~"XE \"Trigger Event: " EVCID "\"" { trace_rule(99); event=$0 gsub("^.*XE \"Trigger Event: ","",event); gsub("\".*$","",event); event=tolower(event); } $1~"^" MSGID && ($0~"Chapter[ ]*$" || $0~"Appendix[ ]*$") { trace_rule(3); if(MESSAGE==1) finish_message(); MESSAGE=1; empty_lines=0; name=$0; descr=$0; gsub("^[A-Z][A-Z][A-Z][ ]+","",descr); gsub("^\\([^)]*\\)[ ]+","",descr); gsub("[ ][ ]*"," ",descr); split(name,naml," "); name=tolower(naml[1]); descr=tolower(descr); gsub("[ ]+appendix[ ]*$","",descr); gsub("[ ]+chapter[ ]*$","",descr); # Chapter if(CHAPTER=="") CHAPTER=FILENAME; sub("^.*app","",CHAPTER); sub("^.*chp","",CHAPTER); sub("[.][^.]*$","",CHAPTER); if(CHAPTER=="1") chapter=1; else if(CHAPTER=="2") chapter=2; else if(CHAPTER=="3") chapter=3; else if(CHAPTER=="4") chapter=4; else if(CHAPTER=="5") chapter=5; else if(CHAPTER=="6") chapter=6; else if(CHAPTER=="7") chapter=7; else if(CHAPTER=="8") chapter=8; else if(CHAPTER=="a") chapter=-1; else if(CHAPTER=="b") chapter=-2; else if(CHAPTER=="c") chapter=-3; else if(CHAPTER=="d") chapter=-4; else if(CHAPTER=="e") chapter=-5; else chapter=0; printf("message(%s,%s,%s,\"%s\",\n [", name, event, chapter, descr); WAS_OPEN=1; event=NIL; next; } MESSAGE && $0~"^[ \\{\\[]*" MSGID "[ \\}\\]]* *.*$" { trace_rule(4); empty_lines=0; theline=$0; gsub("Z\.\.","ANY",theline); gsub("Order Detail Segment","ANY",theline); gsub("[ ]*","",theline); sub("[\\{\\[]*[A-Z][A-Z][A-Z0-9][\\]\\}]*","&<",theline); sub("<.*$","",theline); gsub("\\[","opt(",theline); gsub("\\]",")",theline); gsub("\\{","rep(",theline); gsub("\\}",")",theline); theline=tolower(theline); if(!WAS_OPEN && (theline!~"^\\)") && (theline!="")) COMMA=", " else COMMA=""; WAS_OPEN=(theline~"\\($"); printf("%s%s", COMMA, theline); next; } MESSAGE && $0~"^[ ]*$" { trace_rule(5); if(empty_lines == 0) { trace_rule(5); empty_lines++; } else finish_message(); next; } MESSAGE && $0~"^[ \\{\\[\\]\\}]*$" { trace_rule(6); empty_lines=0; theline=$0; gsub("[ ]*","",theline); gsub("\\[","opt(",theline); gsub("\\]",")",theline); gsub("\\{","rep(",theline); gsub("\\}",")",theline); if(!WAS_OPEN && (theline~"^...\\(")) COMMA=", " else COMMA=""; WAS_OPEN=(theline~"\\($"); printf("%s%s", COMMA, theline); next; } MESSAGE { trace_rule(7); finish_message(); next; } 1 { trace_rule("D"); next; }