#!/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: Wed Oct 20 14:20:55 EDT 1999 # 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# 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 source lines before each error message X# -enum list a maximum of 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# SCCS ID: @(#) inferr 1.1 10/20/99 14:15:09 X# X# @(#) (c) Copyright 1999 by Walt Hultgren. All rights reserved. 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 "$CMD_NAME: cannot read file '$ERR_FILE'" 1>&2 X continue X fi X else X ERR_FILE='' X fi X X X # X # Set up arguments to initialize nawk variables on the command line X # based on whether the OS is SunOS 4.x or 5.x. X # X X case `uname -r` in X X 5* ) PREVARS="-v errflag=$ERR_FLAG -v maxsrc=$MAX_SRC" X PREVARS="$PREVARS -v maxerr=$MAX_ERR -v numonly=$NUM_ONLY" X POSTVARS="" X ;; X X * ) PREVARS="" X POSTVARS="errflag=$ERR_FLAG maxsrc=$MAX_SRC maxerr=$MAX_ERR" X POSTVARS="$POSTVARS numonly=$NUM_ONLY" X ;; X esac X X X # X # Run file through awk sript X # X X nawk $PREVARS ' X 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 err_msg = 0 # ==> currently listing error message X src_line = 0 # current line number from source file X X num_src = 0 # number of source lines saved for next error msg X X fst_src = 1 # pointers to saved source line buffer X lst_src = 0 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 if ( lst_src > 0 ) X { X if ( fst_src <= lst_src ) X { X for ( i = fst_src ; i <= lst_src; ++i ) X print src_buf[i] X } X else X { X for ( i = fst_src ; i <= max_src; ++i ) X print src_buf[i] X X for ( i = 1 ; i <= lst_src; ++i ) X print src_buf[i] X } X } X X num_err = 0 # initialize error message line count X num_src = 0 # reset count of saved source lines X lst_src = 0 # reset pointer for 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 ( lst_src == 0 ) X { X fst_src = 1 X lst_src = 1 X } X else X { X lst_src = ( lst_src == max_src ? 1 : lst_src + 1 ) X X if ( fst_src == lst_src ) X { X fst_src = ( fst_src == max_src ? 1 : fst_src + 1 ) X } X } X X src_buf[lst_src] = $0 X X if ( num_src < max_src ) ++num_src X X } X } X X ' $POSTVARS $ERR_FILE Xdone SHAR_EOF if [ `wc -c < inferr` -ne 8030 ] then echo "Lengths do not match -- Bad Copy of inferr" fi echo "Extracting file inferr.1" sed -e 's/^X//' <<\SHAR_EOF > inferr.1 X.\" inferr.1 Source for man page(s) for inferr command X.\" X.\" X.\" SCCS ID: @(#) inferr.1 1.1 10/20/99 14:15:09 X.\" X.\" @(#) (c) Copyright 1999 by Walt Hultgren. All rights reserved. X.\" X.\" X.\" X.TH INFERR 1 "October, 1999" X.UC 4.2 X.SH NAME Xinferr \- List errors in Informix .err files X.SH SYNOPSIS X.B inferr X[-fc] [-snum] [-enum] [-nv] [files] X.SH DESCRIPTION X.I inferr 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 inferr 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 file names are given that end in one of the standard Informix source Xor object suffixes, X.I inferr Xwill automatically use the appropriate flag character for each file. XThe default error flag is "|", the character used by the Informix-4GL compiler. X.LP XThe error message line flag may be set explicitly using the (-f) option. X.SH REPORTING ERRORS XUnder normal operation, X.I inferr 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 inferr. 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 inferr. XAce comment lines that begin with a "#" not in position (1) Xwill be correctly processed as source lines. X.SH NOTICES XCopyright 1999 by Walt Hultgren. All rights reserved. X.LP X"Informix" is a registered trademark of Informix Software, Inc. SHAR_EOF if [ `wc -c < inferr.1` -ne 3620 ] then echo "Lengths do not match -- Bad Copy of inferr.1" fi echo "Done." exit 0