Updated sh/awk script to scan .err files
Posted in 1993
This is an updated copy of the sh/awk script I posted in July of last year that scans Informix .err files for error messages. There are several differences between this version (1.4) and the one previously posted (1.2): o The command has been renamed from "fglerr" to "inferr" since I was worried about a possible name collision with future Informix utilities, and since the script *does* handle error files from Informix compilers other than I4GL. o The method of saving source lines as the script moves through the error file has been changed to a circular list (a.k.a ring buffer, etc.) which makes it much faster on long flies. o The script now sets the default error flag character separately for each file on the command line, rather than use the same flag for all files. o This version fixes a couple of minor bugs. I have placed a copy of this shar in the ftp archive on mathcs.emory.edu in "/pub/informix/pub/inferr.shar". This replaces "fglerr.shar". If you notice any bugs or have any suggestions for improvement, I like to hear them. Happy compiling, Walt. ------------------------------------------------------------------------------ #!/bin/sh # # This is a shell archive. To extract its contents, # execute this file with /bin/sh to create the file(s): # # inferr inferr.1 # # This shell archive created: Thu Jan 7 09:08:28 EST 1993 # echo "Extracting file inferr" sed -e 's/^X//' <<\\SHAR_EOF > inferr X#!/bin/sh X# X# inferr List Informix errors in *.err files X# X# X# SCCS ID: @(#) inferr 1.4 1/7/93 09:04:24 X# X# X# Usage: inferr [-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# X# Notice: Copyright 1992, 1993 by Yerkes Research Center of Emory X# University, 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# Set default error line flag based on command name X# X Xcase "$CMD_NAME" in X ace* | form* | frm* | per* | sql* ) DFLT_FLAG='#' ;; X * ) DFLT_FLAG='|' ;; Xesac 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 XARG_FLAG='' XLIST_NAMES='' X Xfor ARG in $* Xdo X case "$ARG" in X -e ) MAX_ERR="$2" ; shift 2 ;; X -f ) ARG_FLAG="$2" ; shift 2 ;; X -n ) NUM_ONLY='1' ; MAX_ERR='0' ; MAX_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# If no files specified, use standard input X# X Xif [ $# -eq 0 ] Xthen X set - - Xfi X X X# X# Scan error file(s) with awk to extract error messages X# X Xfor ARG_FILE in $* Xdo X X # X # Get source and error file names from command-line file name X # X X SRC_FILE='' X ERR_FILE='' X ERR_FLAG='' X X case "$ARG_FILE" in X X *.4gl | *.ace | *.per | *.sql ) X SRC_FILE="$ARG_FILE" X ERR_FILE=`echo $SRC_FILE | sed 's/...$/err/'` X LIST_NAMES='Y' X ;; X X *.err ) X ERR_FILE="$ARG_FILE" X SRC_BASE=`echo $ERR_FILE | sed 's/\\.err$//'` X X FILES=`ls $SRC_BASE.* 2>/dev/null | grep -v '\\.err$'` X X if [ -n "$FILES" ] X then X set $FILES X X if [ $# = 1 ] X then X SRC_FILE="$1" X else X ERR_SUM=`head -2 $ERR_FILE | sum` X X for FILE in $* X do X case "$FILE" in X *.4gl | *.ace | *.per | *.sql ) X SRC_SUM=`head -2 $FILE | sum` ;; X * ) X continue ;; X esac X X if [ "$SRC_SUM" = "$ERR_SUM" ] X then X SRC_FILE="$FILE" X break X fi X done X X LIST_NAMES='Y' X fi X fi X ;; X X * ) X ERR_FILE="$ARG_FILE" X ;; X esac X X X # X # Set error flag based on source file name if not given on command line X # X X if [ -n "$ARG_FLAG" ] X then X ERR_FLAG="$ARG_FLAG" X else X case "$SRC_FILE" in X *.4gl ) ERR_FLAG='|' ;; X *.ace | *.per | *.sql ) ERR_FLAG='#' ;; X * ) ERR_FLAG="$DFLT_FLAG" ;; X esac X fi X X X # X # Print file names if required X # X X if [ -n "$LIST_NAMES" ] X then X echo X echo "Source file: $SRC_FILE" X X if [ "$ERR_FILE" = "-" ] X then X echo "Error file: standard input" X else X echo "Error file: $ERR_FILE" X fi X X echo "Error flag: '$ERR_FLAG'" X fi X X X # X # Make sure error file exists if not standard input X # X X if [ "$ERR_FILE" != "-" ] X then X if [ ! -r "$ERR_FILE" ] X then X echo @