[3f615e]: gendefs.awk Maximize Restore History

Download this file

gendefs.awk    110 lines (108 with data), 4.0 kB

  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
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
#!/bin/awk -f
# $Id$
#
# A simple script for generating a message catalogue definitions file
# suitable for input to `gencat', from a `C' header file which contains
# message definition records of the form:--
#
# #define MSG_ID_TOKEN <setnum>, <msgnum>, "<message text>"
#
# where:--
#
# MSG_ID_TOKEN is any valid `C' token, used to represent the
# manifest declaration of the message. A unique
# token must be used for each individual message
# definition, and each must match a specified
# regular expression.
#
# <setnum> is a numeric token, specifying the identification
# number of the message set, to which the specified
# message is to be assigned; all messages in a given
# set must be grouped together within the `C' header
# file, and all message sets must be presented in
# strictly ascending order of set number.
#
# <msgnum> is a numeric token, specifying the identification
# number of the message, within its designated set;
# message definitions must be presented in strictly
# ascending order of message number, within each
# message set.
#
# <message text> is the fallback text defined for the message; it
# must all on the same line as the `#define' token.
#
#
# Written by Keith Marshall <keithmarshall@users.sourceforge.net>
# Last modification: 05-Mar-2007
#
#
# This is free software. It is provided AS IS, in the hope that it may
# be useful, but WITHOUT WARRANTY OF ANY KIND, not even an IMPLIED WARRANTY
# of MERCHANTABILITY, nor of FITNESS FOR ANY PARTICULAR PURPOSE.
#
# Permission is granted to redistribute this software, either "as is" or
# in modified form, under the terms of the GNU General Public License, as
# published by the Free Software Foundation; either version 2, or (at your
# option) any later version.
#
# You should have received a copy of the GNU General Public License
# along with this software; see the file COPYING. If not, write to the
# Free Software Foundation, 51 Franklin St - Fifth Floor, Boston,
# MA 02110-1301, USA.
#
# Establish the default convention for identifying message definitions.
#
BEGIN { MSGTAG = "MSG_[A-Z_a-z0-9]+" }
#
# Allow the user to substitute an alternative identification convention,
# by assigning a new MSGTAG value in the input stream.
#
( $1 == "/*" || $1 == "*" ) && match( $2$3, "MSGTAG=" ) == 1 {
sub( "^[^=]*=[ ]*", "" ); MSGTAG = $0
next
}
#
# Identify `boilerplate' text in the header file comments,
# which is to be replicated into the message catalogue source file.
#
( $1 == "/*" || $1 == "*" ) && match( $2, "!" ) == 1 {
sub( "^[^!]*!", "" ); print
next
}
#
# Normalise whitespace, between an initial `#' and a following `define' keyword,
# then select those records which define messages.
#
{ sub( "^#[ ]*define[ ]+", "# define " ) }
$1$2 == "#define" && match( $3, MSGTAG ) == 1 && RLENGTH == length( $3 ){
#
# Extract the set number from the message definition;
# if it differs from that of the set identified by CURSET,
# then start a new set.
#
SETNUM = $4
sub( ",.*", "", SETNUM )
if( SETNUM != CURSET ){
CURSET = SETNUM
print "$set", SETNUM
}
#
# Capture the message identification comment string,
# and write it out to the generated message catalogue source file,
# immediately preceding the message definition.
#
print "$", $2, $3
#
# Extract the message number for the current message definition.
#
sub( "[^,]*,[ ]*", "" )
MSGNUM = $1; sub( ",.*", "", MSGNUM )
sub( "[^,]*,[ ]*", "" )
#
# And finally, append the message number, and its associated definition,
# to the generated message catalogue source file.
#
print MSGNUM, $0
}
#
# $RCSfile$Revision: end of file