#!/usr/local/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{ printf("SEGMENT\nSEGMENT:DESCRIPTION\nsym:str\n"); printf("-FIELD:LEN:DATA TYPE:R/O:REP#:TABLE#:DATEL#"); printf(":DESCRIPTION:DEUTSCHE BEZEICHNUNG\n"); printf("-num:num:sym:sym:sym:num:num:str:str\n"); } # finish the last table # function finish() { if (seg_name != was) { seg_name=("?" seg_name "/" was "?"); warning("was and willbe differ", seg_name); } # print it printf("%s:%s\n", seg_name, seg_desc); for(i=0;i "/dev/stderr" ; ERROR=1 ; exit 3 ; } function warning(msg, obj) { printf("w:%s,%d at `%s': %s\n", FILENAME, FNR, obj, msg) > "/dev/stderr" ; } $1~"^[ \t]*SEQ" { if (!USED) USED=1; else finish(); #initialize for reading of the new table SEGTABLE=1 ; row_cnt=0; seg_name=will_be; next; } # Skip garbage lines # $0 ~ "^[ \t]*Ä+[ Ä\t]*[ \t]*$" { if (!SEGTABLE && WARNALL) warning("ÄÄÄs outside of a table", $0); next; } # An empty line is the end of the table # SEGTABLE && $0~"^ *$" { SEGTABLE=0 ; next; } # if there is a "field notes" line, it tells us the name of the # segment, which we just scanned. # $0~"^FIELD NOTES: ... " { if (SEGTABLE) { warning("unusual end of table",$0); SEGTABLE=0; } was=$3; seg_desc=""; for(i=4;i<=NF;i++) seg_desc=(seg_desc " " $i); gsub("(^ *)|(* $)","",seg_desc); gsub(" *Ä *"," ",seg_desc); next ; } # each line is stored into the buffer # SEGTABLE { the_row=$0 if(gsub("\t",":",the_row)) gsub(" *"," ",the_row); gsub("^[^0-9]*","",the_row); gsub(" *Ä *"," ",the_row); row[row_cnt++]=the_row; next; } # We always remember the latest segment name, which is mentioned in # the text. # ! SEGTABLE { if (pos=match($0,"^The [A-Z][A-Z0-9][A-Z0-9] segment")) will_be=substr($0, pos+4, 3); } END { if (ERROR) exit 3 ; finish(); }