home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!caen!sol.ctr.columbia.edu!emory!walt
- From: walt@mathcs.emory.edu (Walt Hultgren {rmy})
- Newsgroups: comp.databases.informix
- Subject: sh/awk script to scan .err files
- Message-ID: <9223@emory.mathcs.emory.edu>
- Date: 23 Jul 92 20:26:33 GMT
- Organization: Emory University
- Lines: 441
-
- Back in May, Brad Kuhn posted a handy perl script that scanned .err files
- for error messages. That is, it *looked* handy. Not having perl here, I
- couldn't tell first-hand. So, I implemented the idea in an sh/awk script.
-
- Enclosed is a shar of the script fglerr and its man page. I confess it
- has suffered from a little "creeping featurism," but not too much. I'd
- appreciate any comments you might have in a couple of areas:
-
- o We work mostly in compiled I4GL and ISQL here. Would this script
- work in other environments, and what changes would be required to
- make it handle RDS, ESQL/C, etc.
-
- o I chose "fglerr" as the best command name among the possible ones that
- came to mind. However, several files in $INFORMIXDIR start with "fgl".
- Does "fglerr" collide with any known or planned ISI or third-party names.
-
- o I'd like to hear about any bugs you find or ideas you have for improvement.
-
- I've also placed a copy of this shar in the ftp archive on mathcs.emory.edu
- in /pub/informix/pub/fglerr.shar. If anyone else has tools they'd like to
- add to the archive, send me a copy.
-
- Have fun,
-
- Walt.
-
- --
- Walt Hultgren Internet: walt@rmy.emory.edu (IP 128.140.8.1)
- Emory University UUCP: {...,gatech,rutgers,uunet}!emory!rmy!walt
- 954 Gatewood Road, NE BITNET: walt@EMORY
- Atlanta, GA 30329 USA Voice: +1 404 727 0648
-
- ------------------------------------------------------------------------------
-
- #!/bin/sh
- #
- # This is a shell archive. To extract its contents,
- # execute this file with /bin/sh to create the file(s):
- #
- # fglerr fglerr.1
- #
- # This shell archive created: Thu Jul 23 14:53:21 EDT 1992
- #
- echo "Extracting file fglerr"
- sed -e 's/^X//' <<\SHAR_EOF > fglerr
- X#!/bin/sh
- X#
- X# fglerr List Informix errors in *.err files
- X#
- X#
- X# SCCS ID: @(#) fglerr 1.2 7/23/92 14:51:34
- X#
- X#
- X# Usage: fglerr [-fc] [-snum] [-enum] [-nv] [files]
- X#
- X# where:
- X#
- X# -fc use character "c" as the error line flag
- X# -snum list a maximum of <num> source lines before each error message
- X# -enum list a maximum of <num> lines from each error message
- X# -n list only source line numbers of errors
- X# -v list file names (may be done automatically based on arguments)
- X#
- X#
- X# This script scans error files generated by various Informix program, form
- X# and report compilers. It will list the source line number, error message
- X# and preceding source lines for each error.
- X#
- X# Code is provided near line 160 of the script that will set the default
- X# error flag based on the command name ("$0") used to invoke this script if
- X# the flag is not otherwise set. This allows you to link this file to names
- X# like "rpterr", "formerr", etc. That code is disabled in this release.
- X#
- X# A number of Informix-4GL utilities in $INFORMIXDIR have names beginning
- X# with "fgl". Although there is no known Informix file "fglerr" as of
- X# release 4.10.UC1, there may be such a file in a future release. Check
- X# subsequent Informix releases and/or $PATH to insure that this script does
- X# not interfere with DBMS operations. Or, install this script under a
- X# different name.
- X#
- X#
- X# Notice: Copyright 1992 by Yerkes Research Center of Emory University,
- X# Atlanta, Georgia, U.S.A. All Rights Reserved.
- X#
- X#
- X# Author: Walt Hultgren <walt@rmy.emory.edu>
- X#
- X#
- X
- X
- XCMD_NAME=`basename $0`
- X
- XUSAGE="usage: $CMD_NAME [-fc] [-snum] [-enum] [-nv] [files]"
- X
- X
- X#
- X# Set defaults
- X#
- X
- XMAX_SRC='5' # number of source lines to list before error message
- XMAX_ERR='100' # number of lines to list from each error message
- XNUM_ONLY='0' # default to not list only line numbers of errors
- X
- X
- X#
- X# Parse command line
- X#
- X
- Xset -- `getopt 'e:f:ns:v' $* 2>/dev/null`
- X
- Xif [ $? -ne 0 ]
- Xthen
- X echo "$USAGE" 1>&2
- X exit 1
- Xfi
- X
- XERR_FLAG=''
- XLIST_NAMES=''
- X
- Xfor ARG in $*
- Xdo
- X case "$ARG" in
- X -e ) MAX_ERR="$2" ; shift 2 ;;
- X -f ) ERR_FLAG="$2" ; shift 2 ;;
- X -n ) NUM_ONLY='1' ; MAX_ERR='0' ; MAX_SRC='0' ; BEG_SRC='0' ; shift ;;
- X -s ) MAX_SRC="$2" ; shift 2 ;;
- X -v ) LIST_NAMES='Y' ; shift ;;
- X -- ) shift ; break ;;
- X esac
- Xdone
- X
- X
- X#
- X# Set default verbose mode based on number of files specified
- X#
- X
- Xif [ "$#" -gt 1 ]
- Xthen
- X LIST_NAMES='Y'
- Xfi
- X
- X
- X#
- X# Generate list of error files from files on command line. Set error
- X# message line flag based on first file name if not already set.
- X#
- X
- XERR_FILES=''
- X
- Xfor FILE in $*
- Xdo
- X case "$FILE" in
- X
- X *.4g[el] | *.ace | *.arc | *.frm | *.per | *.sql | *.[ox] )
- X
- X ERR_FILE=`echo $FILE | sed 's/...$/err/'`
- X
- X if [ -f "$ERR_FILE" ]
- X then
- X ERR_FILES="$ERR_FILES $ERR_FILE"
- X LIST_NAMES='Y'
- X else
- X echo "$CMD_NAME: no error file '$ERR_FILE' for '$FILE'" 1>&2
- X exit 2
- X fi
- X
- X if [ -z "$ERR_FLAG" ]
- X then
- X case "$FILE" in
- X *.4g[el] | *.[ox] ) ERR_FLAG='|' ;;
- X *.ace | *.arc | *.frm | *.per | *.sql ) ERR_FLAG='#' ;;
- X esac
- X fi
- X ;;
- X
- X - )
- X ERR_FILES="$ERR_FILES -"
- X ;;
- X
- X * )
- X if [ -f "$FILE" ]
- X then
- X ERR_FILES="$ERR_FILES $FILE"
- X else
- X echo "$CMD_NAME: no such file '$FILE'" 1>&2
- X exit 2
- X fi
- X ;;
- X esac
- X
- Xdone
- X
- X
- X#
- X# If no files specified, use standard input
- X#
- X
- Xif [ -z "$ERR_FILES" ]
- Xthen
- X ERR_FILES='-'
- Xfi
- X
- X
- X##
- X## Set error line flag based on command name if not already set
- X##
- X#
- X#if [ -z "$ERR_FLAG" ]
- X#then
- X# case "$CMD_NAME" in
- X# ace* | form* | frm* | per* | sql* ) ERR_FLAG='#' ;;
- X# * ) ERR_FLAG='|' ;;
- X# esac
- X#fi
- X
- X
- X#
- X# Scan error file(s) with awk to extract error messages
- X#
- X
- Xfor FILE in $ERR_FILES
- Xdo
- X #
- X # Print file name if required
- X #
- X
- X if [ -n "$LIST_NAMES" ]
- X then
- X echo
- X
- X if [ "$FILE" = "-" ]
- X then
- X echo "Error file: standard input"
- X FILE=''
- X else
- X echo "Error File: $FILE"
- X fi
- X fi
- X
- X
- X #
- X # Run file through awk sript
- X #
- X
- X nawk '
- X BEGIN {
- X err_expr = "^\\" errflag # build RE for error message line flag
- X
- X max_src = maxsrc # work around nawk bug
- X max_err = maxerr
- X num_only = numonly
- X
- X num_src = 0 # number of source lines saved for next error msg
- X err_msg = 0 # ==> currently listing error message
- X src_line = 0 # current line number from source file
- X }
- X
- X
- X $0 ~ err_expr { # error message line
- X
- X if ( err_msg == 0 )
- X {
- X if ( num_only == 1 )
- X {
- X printf ( "%d\n", src_line )
- X }
- X else
- X {
- X printf ( "\nSource line" )
- X
- X if ( num_src > 1 )
- X printf ( "s %d-%d:\n",
- X ( src_line - num_src + 1 ), src_line )
- X else
- X printf ( " %d:\n", src_line )
- X
- X for ( i = 1; i <= num_src; ++i ) print line_buf[i]
- X
- X num_err = 0 # initialize error message line count
- X num_src = 0 # reset count of saved source lines
- X }
- X
- X err_msg = 1 # indicate currently listing error message
- X }
- X
- X if ( ++num_err <= max_err ) print
- X
- X }
- X
- X
- X $0 !~ err_expr { # source line
- X
- X err_msg = 0 # turn off error message indicator
- X ++src_line # increment source line count
- X
- X if ( max_src > 0 )
- X {
- X if ( num_src >= max_src ) # shift source lines if buffer full
- X {
- X for ( i = 2; i <= num_src; ++i )
- X line_buf[i-1] = line_buf[i]
- X
- X --num_src
- X }
- X
- X line_buf[++num_src] = $0
- X }
- X }
- X
- X ' errflag="$ERR_FLAG" maxsrc="$MAX_SRC" maxerr="$MAX_ERR" \
- X numonly="$NUM_ONLY" $FILE
- Xdone
- SHAR_EOF
- if [ `wc -c < fglerr` -ne 6558 ]
- then
- echo "Lengths do not match -- Bad Copy of fglerr"
- fi
- echo "Extracting file fglerr.1"
- sed -e 's/^X//' <<\SHAR_EOF > fglerr.1
- X.\" fglerr.1 Source for man page(s) for fglerr command
- X.\"
- X.\"
- X.\" Copyright 1992 by Yerkes Research Center of Emory University,
- X.\" Atlanta, Georgia, U.S.A. All Rights Reserved.
- X.\"
- X.\"
- X.\" SCCS ID: @(#) fglerr.1 1.1 7/23/92 14:48:18
- X.\"
- X.\"
- X.TH FGLERR 1 "July, 1992"
- X.UC 4.2
- X.SH NAME
- Xfglerr \- List errors in Informix .err files
- X.SH SYNOPSIS
- X.B fglerr
- X[-fc] [-snum] [-enum] [-nv] [files]
- X.SH DESCRIPTION
- X.I fglerr
- Xscans
- X.I .err
- Xerror files generated by various Informix compilers. It lists the error
- Xmessage and preceding source lines for each error.
- X.LP
- XThe error files to be scanned may be specified by listing their names
- Xor the names of their corresponding source or object files on the command
- Xline. If a file name ends in one of the standard Informix source
- Xor object suffixes,
- X.I fglerr
- Xwill attempt to read its
- X.I .err
- Xfile.
- X.LP
- XIf no files are specified, or if a file name of "-" is used,
- Xstandard input will be read.
- X.SH OPTIONS
- X.IP "-fc" 8
- Xuse character
- X.I c
- Xas the error message line flag.
- X.IP "-snum" 8
- Xlist a maximum of
- X.I num
- Xsource lines preceding each error message.
- X.IP "-enum" 8
- Xlist a maximum of the first
- X.I num
- Xlines of each error message.
- X.IP -n 8
- Xlist only the source file line numbers where errors occur.
- X.IP -v 8
- Xlist the name of each error file before displaying the error messages
- Xin it ("verbose" mode). This may occur automatically.
- X.SH DETECTING ERROR MESSAGES
- XAn Informix
- X.I .err
- Xerror file contains a copy of the source file with error messages interspersed
- Xthroughout the file. The message for each error immediately follows the
- Xsource line at which the compiler recognized the error.
- X.LP
- XError message lines are distinguished from source lines by a one-character
- Xflag at the beginning of each error line. The character used depends on
- Xwhich compiler generated the file.
- X.LP
- XIf a file name is given that ends in one of the standard Informix source
- Xor object suffixes,
- X.I fglerr
- Xwill automatically use the appropriate flag character. If more than one
- Xfile is given, the first file on the command line will determine the flag.
- XThe default flag is the "|" character used by Informix-4GL.
- X.LP
- XThe error message line flag may be set explicitly using the (-f) option.
- X.SH REPORTING ERRORS
- XUnder normal operation,
- X.I fglerr
- Xlists each error message and the source lines immediately preceding it.
- X.LP
- XThe (-s) and (-e) options may be used to specify the maximum number of source
- Xlines and error message lines respectively to be listed for each error. The
- Xdefault (-s) value is 5, and the default (-e) value is 100. Either
- Xof these counts may be set to zero (0).
- X.LP
- XThe (-n) option causes only the line numbers of source lines containing
- Xerrors to be listed. The line number reported for each error is the
- Xline number of the last source line before the error message. That is, it
- Xis the number of the offending source line as reported by the
- Xcompiler, even though the actual error may occur earlier in the file.
- X.LP
- XThe (-v) option causes the name of each error file to be displayed before
- Xits errors are listed. This occurs automatically if more than
- Xone file is scanned, or if a source or object file name is given.
- X.SH RESTRICTIONS
- XAce report source files present a potential problem to
- X.I fglerr.
- XAce error message lines begin with "#", yet such lines are also valid
- Xcomment lines. If you use lines with "#" in character position (1) for
- Xcomments in Ace source files, such lines will be interpreted as error
- Xmessages by
- X.I fglerr.
- XAce comment lines that begin with a "#" not in position (1)
- Xwill be correctly processed as source lines.
- X.LP
- XA number of Informix-4GL utilities in $INFORMIXDIR have names
- Xbeginning with "fgl". Although there is no known Informix file "fglerr"
- Xas of release 4.10.UC1, there may be such a file in a future release.
- XCheck subsequent Informix releases and/or $PATH to insure that there is
- Xno conflict with DBMS operations. Or, install
- X.I fglerr
- Xunder a different name.
- X.SH NOTICES
- XCopyright 1992 by Yerkes Research Center of Emory University,
- XAtlanta, Georgia, U.S.A. All Rights Reserved.
- X.LP
- X"Informix" is a registered trademark of Informix Software, Inc.
- X.SH AUTHOR
- XWalt Hultgren walt@rmy.emory.edu
- SHAR_EOF
- if [ `wc -c < fglerr.1` -ne 4195 ]
- then
- echo "Lengths do not match -- Bad Copy of fglerr.1"
- fi
- echo "Done."
-