home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / database / informix / 2884 < prev    next >
Encoding:
Internet Message Format  |  1993-01-07  |  14.1 KB

  1. Path: sparky!uunet!usc!wupost!emory!emory!not-for-mail
  2. From: walt@mathcs.emory.edu (Walt Hultgren {rmy})
  3. Newsgroups: comp.databases.informix
  4. Subject: Updated sh/awk script to scan .err files
  5. Date: 7 Jan 1993 09:41:13 -0500
  6. Organization: Emory University
  7. Lines: 497
  8. Distribution: world
  9. Message-ID: <1ihfe9INN53f@emory.mathcs.emory.edu>
  10. NNTP-Posting-Host: emory.mathcs.emory.edu
  11.  
  12. This is an updated copy of the sh/awk script I posted in July of last year
  13. that scans Informix .err files for error messages.
  14.  
  15. There are several differences between this version (1.4) and the one
  16. previously posted (1.2):
  17.  
  18.   o The command has been renamed from "fglerr" to "inferr" since I was
  19.     worried about a possible name collision with future Informix utilities,
  20.     and since the script *does* handle error files from Informix compilers
  21.     other than I4GL.
  22.  
  23.   o The method of saving source lines as the script moves through the
  24.     error file has been changed to a circular list (a.k.a ring buffer,
  25.     etc.) which makes it much faster on long flies.
  26.  
  27.   o The script now sets the default error flag character separately for
  28.     each file on the command line, rather than use the same flag for all
  29.     files.
  30.  
  31.   o This version fixes a couple of minor bugs.
  32.  
  33. I have placed a copy of this shar in the ftp archive on mathcs.emory.edu
  34. in "/pub/informix/pub/inferr.shar".  This replaces "fglerr.shar".
  35.  
  36. If you notice any bugs or have any suggestions for improvement, I like to
  37. hear them.
  38.  
  39. Happy compiling,
  40.  
  41. Walt.
  42.  
  43. ------------------------------------------------------------------------------
  44.  
  45. #!/bin/sh
  46. #
  47. # This is a shell archive.  To extract its contents,
  48. # execute this file with /bin/sh to create the file(s):
  49. #
  50. # inferr            inferr.1
  51. #
  52. # This shell archive created: Thu Jan  7 09:08:28 EST 1993
  53. #
  54. echo "Extracting file inferr"
  55. sed -e 's/^X//' <<\SHAR_EOF > inferr
  56. X#!/bin/sh
  57. X#
  58. X#   inferr   List Informix errors in *.err files
  59. X#
  60. X#
  61. X#   SCCS ID:  @(#) inferr 1.4 1/7/93 09:04:24
  62. X#
  63. X#
  64. X#   Usage:  inferr [-fc] [-snum] [-enum] [-nv] [files]
  65. X#
  66. X#   where:
  67. X#
  68. X#      -fc     use character "c" as the error line flag
  69. X#      -snum   list a maximum of <num> source lines before each error message
  70. X#      -enum   list a maximum of <num> lines from each error message
  71. X#      -n      list only source line numbers of errors
  72. X#      -v      list file names (may be done automatically based on arguments)
  73. X#
  74. X#
  75. X#   This script scans error files generated by various Informix program, form
  76. X#   and report compilers.  It will list the source line number, error message
  77. X#   and preceding source lines for each error.
  78. X#
  79. X#
  80. X#   Notice:  Copyright 1992, 1993 by Yerkes Research Center of Emory
  81. X#            University, Atlanta, Georgia, U.S.A.  All Rights Reserved.
  82. X#
  83. X#
  84. X#   Author:  Walt Hultgren <walt@rmy.emory.edu>
  85. X#
  86. X#
  87. X
  88. X
  89. XCMD_NAME=`basename $0`
  90. X
  91. XUSAGE="usage:  $CMD_NAME [-fc] [-snum] [-enum] [-nv] [files]"
  92. X
  93. X
  94. X#
  95. X#   Set defaults
  96. X#
  97. X
  98. XMAX_SRC='5'     # number of source lines to list before error message
  99. XMAX_ERR='100'   # number of lines to list from each error message
  100. XNUM_ONLY='0'    # default to not list only line numbers of errors
  101. X
  102. X
  103. X#
  104. X#   Set default error line flag based on command name
  105. X#
  106. X
  107. Xcase "$CMD_NAME" in
  108. X    ace* | form* | frm* | per* | sql* )  DFLT_FLAG='#' ;;
  109. X    * )                                  DFLT_FLAG='|' ;;
  110. Xesac
  111. X
  112. X
  113. X#
  114. X#   Parse command line
  115. X#
  116. X
  117. Xset -- `getopt 'e:f:ns:v' $* 2>/dev/null`
  118. X
  119. Xif [ $? -ne 0 ]
  120. Xthen
  121. X    echo "$USAGE" 1>&2
  122. X    exit 1
  123. Xfi
  124. X
  125. XARG_FLAG=''
  126. XLIST_NAMES=''
  127. X
  128. Xfor ARG in $*
  129. Xdo
  130. X    case "$ARG" in
  131. X        -e )  MAX_ERR="$2" ; shift 2 ;;
  132. X        -f )  ARG_FLAG="$2" ; shift 2 ;;
  133. X        -n )  NUM_ONLY='1' ; MAX_ERR='0' ; MAX_SRC='0' ; shift ;;
  134. X        -s )  MAX_SRC="$2" ; shift 2 ;;
  135. X        -v )  LIST_NAMES='Y' ; shift ;;
  136. X        -- )  shift ; break ;;
  137. X    esac
  138. Xdone
  139. X
  140. X
  141. X#
  142. X#   Set default verbose mode based on number of files specified
  143. X#
  144. X
  145. Xif [ $# -gt 1 ]
  146. Xthen
  147. X    LIST_NAMES='Y'
  148. Xfi
  149. X
  150. X
  151. X#
  152. X#   If no files specified, use standard input
  153. X#
  154. X
  155. Xif [ $# -eq 0 ]
  156. Xthen
  157. X    set - -
  158. Xfi
  159. X
  160. X
  161. X#
  162. X#   Scan error file(s) with awk to extract error messages
  163. X#
  164. X
  165. Xfor ARG_FILE in $*
  166. Xdo
  167. X
  168. X    #
  169. X    #   Get source and error file names from command-line file name
  170. X    #
  171. X
  172. X    SRC_FILE=''
  173. X    ERR_FILE=''
  174. X    ERR_FLAG=''
  175. X
  176. X    case "$ARG_FILE" in
  177. X
  178. X        *.4gl | *.ace | *.per | *.sql )
  179. X            SRC_FILE="$ARG_FILE"
  180. X            ERR_FILE=`echo $SRC_FILE | sed 's/...$/err/'`
  181. X            LIST_NAMES='Y'
  182. X            ;;
  183. X
  184. X        *.err )
  185. X            ERR_FILE="$ARG_FILE"
  186. X            SRC_BASE=`echo $ERR_FILE | sed 's/\.err$//'`
  187. X
  188. X            FILES=`ls $SRC_BASE.* 2>/dev/null | grep -v '\.err$'`
  189. X
  190. X            if [ -n "$FILES" ]
  191. X            then
  192. X                set $FILES
  193. X
  194. X                if [ $# = 1 ]
  195. X                then
  196. X                    SRC_FILE="$1"
  197. X                else
  198. X                    ERR_SUM=`head -2 $ERR_FILE | sum`
  199. X
  200. X                    for FILE in $*
  201. X                    do
  202. X                        case "$FILE" in
  203. X                            *.4gl | *.ace | *.per | *.sql )
  204. X                                SRC_SUM=`head -2 $FILE | sum` ;;
  205. X                            * )
  206. X                                continue ;;
  207. X                        esac
  208. X
  209. X                        if [ "$SRC_SUM" = "$ERR_SUM" ]
  210. X                        then
  211. X                            SRC_FILE="$FILE"
  212. X                            break
  213. X                        fi
  214. X                    done
  215. X
  216. X                    LIST_NAMES='Y'
  217. X                fi
  218. X            fi
  219. X            ;;
  220. X
  221. X        * )
  222. X            ERR_FILE="$ARG_FILE"
  223. X            ;;
  224. X    esac
  225. X
  226. X
  227. X    #
  228. X    #   Set error flag based on source file name if not given on command line
  229. X    #
  230. X
  231. X    if [ -n "$ARG_FLAG" ]
  232. X    then
  233. X        ERR_FLAG="$ARG_FLAG"
  234. X    else
  235. X        case "$SRC_FILE" in
  236. X            *.4gl )                  ERR_FLAG='|' ;;
  237. X            *.ace | *.per | *.sql )  ERR_FLAG='#' ;;
  238. X            * )                      ERR_FLAG="$DFLT_FLAG" ;;
  239. X        esac
  240. X    fi
  241. X
  242. X
  243. X    #
  244. X    #   Print file names if required
  245. X    #
  246. X
  247. X    if [ -n "$LIST_NAMES" ]
  248. X    then
  249. X        echo
  250. X        echo "Source file: $SRC_FILE"
  251. X
  252. X        if [ "$ERR_FILE" = "-" ]
  253. X        then
  254. X            echo "Error file:  standard input"
  255. X        else
  256. X            echo "Error file:  $ERR_FILE"
  257. X        fi
  258. X
  259. X        echo "Error flag:  '$ERR_FLAG'"
  260. X    fi
  261. X
  262. X
  263. X    #
  264. X    #   Make sure error file exists if not standard input
  265. X    #
  266. X
  267. X    if [ "$ERR_FILE" != "-" ]
  268. X    then
  269. X        if [ ! -r "$ERR_FILE" ]
  270. X        then
  271. X            echo "$CMD_NAME:  cannot read file '$ERR_FILE'" 1>&2
  272. X            continue
  273. X        fi
  274. X    else
  275. X        ERR_FILE=''
  276. X    fi
  277. X
  278. X
  279. X    #
  280. X    #   Run file through awk sript
  281. X    #
  282. X
  283. X    nawk '
  284. X        BEGIN {
  285. X            err_expr = "^\\" errflag   # build RE for error message line flag
  286. X
  287. X            max_src  = maxsrc    # work around nawk bug
  288. X            max_err  = maxerr
  289. X            num_only = numonly
  290. X
  291. X            err_msg  = 0   # ==> currently listing error message
  292. X            src_line = 0   # current line number from source file
  293. X
  294. X            num_src  = 0   # number of source lines saved for next error msg
  295. X
  296. X            fst_src  = 1   # pointers to saved source line buffer
  297. X            lst_src  = 0
  298. X            }
  299. X
  300. X
  301. X        $0 ~ err_expr {   # error message line
  302. X
  303. X            if ( err_msg == 0 )
  304. X              {
  305. X                if ( num_only == 1 )
  306. X                  {
  307. X                    printf ( "%d\n", src_line )
  308. X                  }
  309. X                else
  310. X                  {
  311. X                    printf ( "\nSource line" )
  312. X
  313. X                    if ( num_src > 1 )
  314. X                        printf ( "s %d-%d:\n",
  315. X                                 ( src_line - num_src + 1 ), src_line )
  316. X                    else
  317. X                        printf ( " %d:\n", src_line )
  318. X
  319. X                    if ( lst_src > 0 )
  320. X                      {
  321. X                        if ( fst_src <= lst_src )
  322. X                          {
  323. X                            for ( i = fst_src ; i <= lst_src; ++i )
  324. X                                print src_buf[i]
  325. X                          }
  326. X                        else
  327. X                          {
  328. X                            for ( i = fst_src ; i <= max_src; ++i )
  329. X                                print src_buf[i]
  330. X
  331. X                            for ( i = 1 ; i <= lst_src; ++i )
  332. X                                print src_buf[i]
  333. X                          }
  334. X                      }
  335. X
  336. X                    num_err = 0   # initialize error message line count
  337. X                    num_src = 0   # reset count of saved source lines
  338. X                    lst_src = 0   # reset pointer for saved source lines
  339. X                  }
  340. X
  341. X                err_msg = 1   # indicate currently listing error message
  342. X              }
  343. X
  344. X            if ( ++num_err <= max_err ) print
  345. X
  346. X            }
  347. X
  348. X
  349. X        $0 !~ err_expr {   # source line
  350. X
  351. X            err_msg = 0   # turn off error message indicator
  352. X            ++src_line    # increment source line count
  353. X
  354. X            if ( max_src > 0 )
  355. X              {
  356. X                if ( lst_src == 0 )
  357. X                  {
  358. X                    fst_src = 1
  359. X                    lst_src = 1
  360. X                  }
  361. X                else
  362. X                  {
  363. X                    lst_src = ( lst_src == max_src ? 1 : lst_src + 1 )
  364. X
  365. X                    if ( fst_src == lst_src )
  366. X                      {
  367. X                        fst_src = ( fst_src == max_src ? 1 : fst_src + 1 )
  368. X                      }
  369. X                  }
  370. X
  371. X                src_buf[lst_src] = $0
  372. X
  373. X                if ( num_src < max_src ) ++num_src
  374. X
  375. X              }
  376. X            }
  377. X
  378. X        ' errflag="$ERR_FLAG" maxsrc="$MAX_SRC" maxerr="$MAX_ERR" \
  379. X          numonly="$NUM_ONLY" $ERR_FILE
  380. Xdone
  381. SHAR_EOF
  382. if [ `wc -c < inferr` -ne     7700 ]
  383. then
  384.     echo "Lengths do not match -- Bad Copy of inferr"
  385. fi
  386. echo "Extracting file inferr.1"
  387. sed -e 's/^X//' <<\SHAR_EOF > inferr.1
  388. X.\"   inferr.1   Source for man page(s) for inferr command
  389. X.\"
  390. X.\"
  391. X.\"   Copyright 1992, 1993 by Yerkes Research Center of Emory University,
  392. X.\"          Atlanta, Georgia, U.S.A.  All Rights Reserved.
  393. X.\"
  394. X.\"
  395. X.\"   SCCS ID:  @(#) inferr.1 1.2 1/7/93 09:04:27
  396. X.\"
  397. X.\"
  398. X.TH INFERR 1 "January, 1993"
  399. X.UC 4.2
  400. X.SH NAME
  401. Xinferr \- List errors in Informix .err files
  402. X.SH SYNOPSIS
  403. X.B inferr
  404. X[-fc] [-snum] [-enum] [-nv] [files]
  405. X.SH DESCRIPTION
  406. X.I inferr
  407. Xscans
  408. X.I .err
  409. Xerror files generated by various Informix compilers.  It lists the error
  410. Xmessage and preceding source lines for each error.
  411. X.LP
  412. XThe error files to be scanned may be specified by listing their names
  413. Xor the names of their corresponding source or object files on the command
  414. Xline.  If a file name ends in one of the standard Informix source
  415. Xor object suffixes,
  416. X.I inferr
  417. Xwill attempt to read its
  418. X.I .err
  419. Xfile.
  420. X.LP
  421. XIf no files are specified, or if a file name of "-" is used,
  422. Xstandard input will be read.
  423. X.SH OPTIONS
  424. X.IP "-fc" 8
  425. Xuse character
  426. X.I c
  427. Xas the error message line flag.
  428. X.IP "-snum" 8
  429. Xlist a maximum of
  430. X.I num
  431. Xsource lines preceding each error message.
  432. X.IP "-enum" 8
  433. Xlist a maximum of the first
  434. X.I num
  435. Xlines of each error message.
  436. X.IP -n 8
  437. Xlist only the source file line numbers where errors occur.
  438. X.IP -v 8
  439. Xlist the name of each error file before displaying the error messages
  440. Xin it ("verbose" mode).  This may occur automatically.
  441. X.SH DETECTING ERROR MESSAGES
  442. XAn Informix
  443. X.I .err
  444. Xerror file contains a copy of the source file with error messages interspersed
  445. Xthroughout the file.  The message for each error immediately follows the
  446. Xsource line at which the compiler recognized the error.
  447. X.LP
  448. XError message lines are distinguished from source lines by a one-character
  449. Xflag at the beginning of each error line.  The character used depends on
  450. Xwhich compiler generated the file.
  451. X.LP
  452. XIf file names are given that end in one of the standard Informix source
  453. Xor object suffixes,
  454. X.I inferr
  455. Xwill automatically use the appropriate flag character for each file.
  456. XThe default error flag is "|", the character used by the Informix-4GL compiler.
  457. X.LP
  458. XThe error message line flag may be set explicitly using the (-f) option.
  459. X.SH REPORTING ERRORS
  460. XUnder normal operation,
  461. X.I inferr
  462. Xlists each error message and the source lines immediately preceding it.
  463. X.LP
  464. XThe (-s) and (-e) options may be used to specify the maximum number of source
  465. Xlines and error message lines respectively to be listed for each error.  The
  466. Xdefault (-s) value is 5, and the default (-e) value is 100.  Either
  467. Xof these counts may be set to zero (0).
  468. X.LP
  469. XThe (-n) option causes only the line numbers of source lines containing
  470. Xerrors to be listed.  The line number reported for each error is the
  471. Xline number of the last source line before the error message.  That is, it
  472. Xis the number of the offending source line as reported by the
  473. Xcompiler, even though the actual error may occur earlier in the file.
  474. X.LP
  475. XThe (-v) option causes the name of each error file to be displayed before
  476. Xits errors are listed.  This occurs automatically if more than
  477. Xone file is scanned, or if a source or object file name is given.
  478. X.SH RESTRICTIONS
  479. XAce report source files present a potential problem to
  480. X.I inferr.
  481. XAce error message lines begin with "#", yet such lines are also valid
  482. Xcomment lines.  If you use lines with "#" in character position (1) for
  483. Xcomments in Ace source files, such lines will be interpreted as error
  484. Xmessages by
  485. X.I inferr.
  486. XAce comment lines that begin with a "#" not in position (1)
  487. Xwill be correctly processed as source lines.
  488. X.SH NOTICES
  489. XCopyright 1992, 1993 by Yerkes Research Center of Emory University,
  490. XAtlanta, Georgia, U.S.A.  All Rights Reserved.
  491. X.LP
  492. X"Informix" is a registered trademark of Informix Software, Inc.
  493. X.SH AUTHOR
  494. XWalt Hultgren  walt@rmy.emory.edu
  495. SHAR_EOF
  496. if [ `wc -c < inferr.1` -ne     3787 ]
  497. then
  498.     echo "Lengths do not match -- Bad Copy of inferr.1"
  499. fi
  500. echo "Done."
  501.  
  502. ------------------------------------------------------------------------------
  503.  
  504. -- 
  505. Walt Hultgren              Internet: walt@rmy.emory.edu       (IP 128.140.8.1)
  506. Emory University               UUCP: {...,gatech,rutgers,uunet}!emory!rmy!walt
  507. 954 Gatewood Road, NE        BITNET: walt@EMORY
  508. Atlanta, GA  30329  USA       Voice: +1 404 727 0648
  509.