home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / database / informix / 1597 < prev    next >
Encoding:
Internet Message Format  |  1992-07-23  |  13.2 KB

  1. Path: sparky!uunet!caen!sol.ctr.columbia.edu!emory!walt
  2. From: walt@mathcs.emory.edu (Walt Hultgren {rmy})
  3. Newsgroups: comp.databases.informix
  4. Subject: sh/awk script to scan .err files
  5. Message-ID: <9223@emory.mathcs.emory.edu>
  6. Date: 23 Jul 92 20:26:33 GMT
  7. Organization: Emory University
  8. Lines: 441
  9.  
  10. Back in May, Brad Kuhn posted a handy perl script that scanned .err files
  11. for error messages.  That is, it *looked* handy.  Not having perl here, I
  12. couldn't tell first-hand.  So, I implemented the idea in an sh/awk script.
  13.  
  14. Enclosed is a shar of the script fglerr and its man page.  I confess it
  15. has suffered from a little "creeping featurism," but not too much.  I'd
  16. appreciate any comments you might have in a couple of areas:
  17.  
  18.   o We work mostly in compiled I4GL and ISQL here.  Would this script
  19.     work in other environments, and what changes would be required to
  20.     make it handle RDS, ESQL/C, etc.
  21.  
  22.   o I chose "fglerr" as the best command name among the possible ones that
  23.     came to mind.  However, several files in $INFORMIXDIR start with "fgl".
  24.     Does "fglerr" collide with any known or planned ISI or third-party names.
  25.  
  26.   o I'd like to hear about any bugs you find or ideas you have for improvement.
  27.  
  28. I've also placed a copy of this shar in the ftp archive on mathcs.emory.edu
  29. in /pub/informix/pub/fglerr.shar.  If anyone else has tools they'd like to
  30. add to the archive, send me a copy.
  31.  
  32. Have fun,
  33.  
  34. Walt.
  35.  
  36. -- 
  37. Walt Hultgren              Internet: walt@rmy.emory.edu       (IP 128.140.8.1)
  38. Emory University               UUCP: {...,gatech,rutgers,uunet}!emory!rmy!walt
  39. 954 Gatewood Road, NE        BITNET: walt@EMORY
  40. Atlanta, GA  30329  USA       Voice: +1 404 727 0648
  41.  
  42. ------------------------------------------------------------------------------
  43.  
  44. #!/bin/sh
  45. #
  46. # This is a shell archive.  To extract its contents,
  47. # execute this file with /bin/sh to create the file(s):
  48. #
  49. # fglerr            fglerr.1
  50. #
  51. # This shell archive created: Thu Jul 23 14:53:21 EDT 1992
  52. #
  53. echo "Extracting file fglerr"
  54. sed -e 's/^X//' <<\SHAR_EOF > fglerr
  55. X#!/bin/sh
  56. X#
  57. X#   fglerr   List Informix errors in *.err files
  58. X#
  59. X#
  60. X#   SCCS ID:  @(#) fglerr 1.2 7/23/92 14:51:34
  61. X#
  62. X#
  63. X#   Usage:  fglerr [-fc] [-snum] [-enum] [-nv] [files]
  64. X#
  65. X#   where:
  66. X#
  67. X#      -fc     use character "c" as the error line flag
  68. X#      -snum   list a maximum of <num> source lines before each error message
  69. X#      -enum   list a maximum of <num> lines from each error message
  70. X#      -n      list only source line numbers of errors
  71. X#      -v      list file names (may be done automatically based on arguments)
  72. X#
  73. X#
  74. X#   This script scans error files generated by various Informix program, form
  75. X#   and report compilers.  It will list the source line number, error message
  76. X#   and preceding source lines for each error.
  77. X#
  78. X#   Code is provided near line 160 of the script that will set the default
  79. X#   error flag based on the command name ("$0") used to invoke this script if
  80. X#   the flag is not otherwise set.  This allows you to link this file to names
  81. X#   like "rpterr", "formerr", etc.  That code is disabled in this release.
  82. X#
  83. X#   A number of Informix-4GL utilities in $INFORMIXDIR have names beginning
  84. X#   with "fgl".  Although there is no known Informix file "fglerr" as of
  85. X#   release 4.10.UC1, there may be such a file in a future release.  Check
  86. X#   subsequent Informix releases and/or $PATH to insure that this script does
  87. X#   not interfere with DBMS operations.  Or, install this script under a
  88. X#   different name.
  89. X#
  90. X#
  91. X#   Notice:  Copyright 1992 by Yerkes Research Center of Emory University,
  92. X#                   Atlanta, Georgia, U.S.A.  All Rights Reserved.
  93. X#
  94. X#
  95. X#   Author:  Walt Hultgren <walt@rmy.emory.edu>
  96. X#
  97. X#
  98. X
  99. X
  100. XCMD_NAME=`basename $0`
  101. X
  102. XUSAGE="usage:  $CMD_NAME [-fc] [-snum] [-enum] [-nv] [files]"
  103. X
  104. X
  105. X#
  106. X#   Set defaults
  107. X#
  108. X
  109. XMAX_SRC='5'     # number of source lines to list before error message
  110. XMAX_ERR='100'   # number of lines to list from each error message
  111. XNUM_ONLY='0'    # default to not list only line numbers of errors
  112. X
  113. X
  114. X#
  115. X#   Parse command line
  116. X#
  117. X
  118. Xset -- `getopt 'e:f:ns:v' $* 2>/dev/null`
  119. X
  120. Xif [ $? -ne 0 ]
  121. Xthen
  122. X    echo "$USAGE" 1>&2
  123. X    exit 1
  124. Xfi
  125. X
  126. XERR_FLAG=''
  127. XLIST_NAMES=''
  128. X
  129. Xfor ARG in $*
  130. Xdo
  131. X    case "$ARG" in
  132. X        -e )  MAX_ERR="$2" ; shift 2 ;;
  133. X        -f )  ERR_FLAG="$2" ; shift 2 ;;
  134. X        -n )  NUM_ONLY='1' ; MAX_ERR='0' ; MAX_SRC='0' ; BEG_SRC='0' ; shift ;;
  135. X        -s )  MAX_SRC="$2" ; shift 2 ;;
  136. X        -v )  LIST_NAMES='Y' ; shift ;;
  137. X        -- )  shift ; break ;;
  138. X    esac
  139. Xdone
  140. X
  141. X
  142. X#
  143. X#   Set default verbose mode based on number of files specified
  144. X#
  145. X
  146. Xif [ "$#" -gt 1 ]
  147. Xthen
  148. X    LIST_NAMES='Y'
  149. Xfi
  150. X
  151. X
  152. X#
  153. X#   Generate list of error files from files on command line.  Set error
  154. X#   message line flag based on first file name if not already set.
  155. X#
  156. X
  157. XERR_FILES=''
  158. X
  159. Xfor FILE in $*
  160. Xdo
  161. X    case "$FILE" in
  162. X
  163. X        *.4g[el] | *.ace | *.arc | *.frm | *.per | *.sql | *.[ox] )
  164. X
  165. X            ERR_FILE=`echo $FILE | sed 's/...$/err/'`
  166. X
  167. X            if [ -f "$ERR_FILE" ]
  168. X            then
  169. X                ERR_FILES="$ERR_FILES $ERR_FILE"
  170. X                LIST_NAMES='Y'
  171. X            else
  172. X                echo "$CMD_NAME:  no error file '$ERR_FILE' for '$FILE'" 1>&2
  173. X                exit 2
  174. X            fi
  175. X
  176. X            if [ -z "$ERR_FLAG" ]
  177. X            then
  178. X                case "$FILE" in
  179. X                    *.4g[el] | *.[ox] )                      ERR_FLAG='|' ;;
  180. X                    *.ace | *.arc | *.frm | *.per | *.sql )  ERR_FLAG='#' ;;
  181. X                esac
  182. X            fi
  183. X            ;;
  184. X
  185. X        - )
  186. X            ERR_FILES="$ERR_FILES -"
  187. X            ;;
  188. X
  189. X        * )
  190. X            if [ -f "$FILE" ]
  191. X            then
  192. X                ERR_FILES="$ERR_FILES $FILE"
  193. X            else
  194. X                echo "$CMD_NAME:  no such file '$FILE'" 1>&2
  195. X                exit 2
  196. X            fi
  197. X            ;;
  198. X    esac
  199. X
  200. Xdone
  201. X
  202. X
  203. X#
  204. X#   If no files specified, use standard input
  205. X#
  206. X
  207. Xif [ -z "$ERR_FILES" ]
  208. Xthen
  209. X    ERR_FILES='-'
  210. Xfi
  211. X
  212. X
  213. X##
  214. X##   Set error line flag based on command name if not already set
  215. X##
  216. X#
  217. X#if [ -z "$ERR_FLAG" ]
  218. X#then
  219. X#    case "$CMD_NAME" in
  220. X#        ace* | form* | frm* | per* | sql* )  ERR_FLAG='#' ;;
  221. X#        * )                                  ERR_FLAG='|' ;;
  222. X#    esac
  223. X#fi
  224. X
  225. X
  226. X#
  227. X#   Scan error file(s) with awk to extract error messages
  228. X#
  229. X
  230. Xfor FILE in $ERR_FILES
  231. Xdo
  232. X    #
  233. X    #   Print file name if required
  234. X    #
  235. X
  236. X    if [ -n "$LIST_NAMES" ]
  237. X    then
  238. X        echo
  239. X
  240. X        if [ "$FILE" = "-" ]
  241. X        then
  242. X            echo "Error file:  standard input"
  243. X            FILE=''
  244. X        else
  245. X            echo "Error File:  $FILE"
  246. X        fi
  247. X    fi
  248. X
  249. X
  250. X    #
  251. X    #   Run file through awk sript
  252. X    #
  253. X
  254. X    nawk '
  255. X        BEGIN {
  256. X            err_expr = "^\\" errflag   # build RE for error message line flag
  257. X
  258. X            max_src  = maxsrc    # work around nawk bug
  259. X            max_err  = maxerr
  260. X            num_only = numonly
  261. X
  262. X            num_src  = 0   # number of source lines saved for next error msg
  263. X            err_msg  = 0   # ==> currently listing error message
  264. X            src_line = 0   # current line number from source file
  265. X            }
  266. X
  267. X
  268. X        $0 ~ err_expr {   # error message line
  269. X
  270. X            if ( err_msg == 0 )
  271. X              {
  272. X                if ( num_only == 1 )
  273. X                  {
  274. X                    printf ( "%d\n", src_line )
  275. X                  }
  276. X                else
  277. X                  {
  278. X                    printf ( "\nSource line" )
  279. X
  280. X                    if ( num_src > 1 )
  281. X                        printf ( "s %d-%d:\n",
  282. X                                 ( src_line - num_src + 1 ), src_line )
  283. X                    else
  284. X                        printf ( " %d:\n", src_line )
  285. X
  286. X                    for ( i = 1; i <= num_src; ++i ) print line_buf[i]
  287. X
  288. X                    num_err = 0   # initialize error message line count
  289. X                    num_src = 0   # reset count of saved source lines
  290. X                  }
  291. X
  292. X                err_msg = 1   # indicate currently listing error message
  293. X              }
  294. X
  295. X            if ( ++num_err <= max_err ) print
  296. X
  297. X            }
  298. X
  299. X
  300. X        $0 !~ err_expr {   # source line
  301. X
  302. X            err_msg = 0   # turn off error message indicator
  303. X            ++src_line    # increment source line count
  304. X
  305. X            if ( max_src > 0 )
  306. X              {
  307. X                if ( num_src >= max_src )   # shift source lines if buffer full
  308. X                  {
  309. X                    for ( i = 2; i <= num_src; ++i )
  310. X                        line_buf[i-1] = line_buf[i]
  311. X
  312. X                    --num_src
  313. X                  }
  314. X
  315. X                line_buf[++num_src] = $0
  316. X              }
  317. X            }
  318. X
  319. X        ' errflag="$ERR_FLAG" maxsrc="$MAX_SRC" maxerr="$MAX_ERR" \
  320. X          numonly="$NUM_ONLY" $FILE
  321. Xdone
  322. SHAR_EOF
  323. if [ `wc -c < fglerr` -ne     6558 ]
  324. then
  325.     echo "Lengths do not match -- Bad Copy of fglerr"
  326. fi
  327. echo "Extracting file fglerr.1"
  328. sed -e 's/^X//' <<\SHAR_EOF > fglerr.1
  329. X.\"   fglerr.1   Source for man page(s) for fglerr command
  330. X.\"
  331. X.\"
  332. X.\"   Copyright 1992 by Yerkes Research Center of Emory University,
  333. X.\"          Atlanta, Georgia, U.S.A.  All Rights Reserved.
  334. X.\"
  335. X.\"
  336. X.\"   SCCS ID:  @(#) fglerr.1 1.1 7/23/92 14:48:18
  337. X.\"
  338. X.\"
  339. X.TH FGLERR 1 "July, 1992"
  340. X.UC 4.2
  341. X.SH NAME
  342. Xfglerr \- List errors in Informix .err files
  343. X.SH SYNOPSIS
  344. X.B fglerr
  345. X[-fc] [-snum] [-enum] [-nv] [files]
  346. X.SH DESCRIPTION
  347. X.I fglerr
  348. Xscans
  349. X.I .err
  350. Xerror files generated by various Informix compilers.  It lists the error
  351. Xmessage and preceding source lines for each error.
  352. X.LP
  353. XThe error files to be scanned may be specified by listing their names
  354. Xor the names of their corresponding source or object files on the command
  355. Xline.  If a file name ends in one of the standard Informix source
  356. Xor object suffixes,
  357. X.I fglerr
  358. Xwill attempt to read its
  359. X.I .err
  360. Xfile.
  361. X.LP
  362. XIf no files are specified, or if a file name of "-" is used,
  363. Xstandard input will be read.
  364. X.SH OPTIONS
  365. X.IP "-fc" 8
  366. Xuse character
  367. X.I c
  368. Xas the error message line flag.
  369. X.IP "-snum" 8
  370. Xlist a maximum of
  371. X.I num
  372. Xsource lines preceding each error message.
  373. X.IP "-enum" 8
  374. Xlist a maximum of the first
  375. X.I num
  376. Xlines of each error message.
  377. X.IP -n 8
  378. Xlist only the source file line numbers where errors occur.
  379. X.IP -v 8
  380. Xlist the name of each error file before displaying the error messages
  381. Xin it ("verbose" mode).  This may occur automatically.
  382. X.SH DETECTING ERROR MESSAGES
  383. XAn Informix
  384. X.I .err
  385. Xerror file contains a copy of the source file with error messages interspersed
  386. Xthroughout the file.  The message for each error immediately follows the
  387. Xsource line at which the compiler recognized the error.
  388. X.LP
  389. XError message lines are distinguished from source lines by a one-character
  390. Xflag at the beginning of each error line.  The character used depends on
  391. Xwhich compiler generated the file.
  392. X.LP
  393. XIf a file name is given that ends in one of the standard Informix source
  394. Xor object suffixes,
  395. X.I fglerr
  396. Xwill automatically use the appropriate flag character.  If more than one
  397. Xfile is given, the first file on the command line will determine the flag.
  398. XThe default flag is the "|" character used by Informix-4GL.
  399. X.LP
  400. XThe error message line flag may be set explicitly using the (-f) option.
  401. X.SH REPORTING ERRORS
  402. XUnder normal operation,
  403. X.I fglerr
  404. Xlists each error message and the source lines immediately preceding it.
  405. X.LP
  406. XThe (-s) and (-e) options may be used to specify the maximum number of source
  407. Xlines and error message lines respectively to be listed for each error.  The
  408. Xdefault (-s) value is 5, and the default (-e) value is 100.  Either
  409. Xof these counts may be set to zero (0).
  410. X.LP
  411. XThe (-n) option causes only the line numbers of source lines containing
  412. Xerrors to be listed.  The line number reported for each error is the
  413. Xline number of the last source line before the error message.  That is, it
  414. Xis the number of the offending source line as reported by the
  415. Xcompiler, even though the actual error may occur earlier in the file.
  416. X.LP
  417. XThe (-v) option causes the name of each error file to be displayed before
  418. Xits errors are listed.  This occurs automatically if more than
  419. Xone file is scanned, or if a source or object file name is given.
  420. X.SH RESTRICTIONS
  421. XAce report source files present a potential problem to
  422. X.I fglerr.
  423. XAce error message lines begin with "#", yet such lines are also valid
  424. Xcomment lines.  If you use lines with "#" in character position (1) for
  425. Xcomments in Ace source files, such lines will be interpreted as error
  426. Xmessages by
  427. X.I fglerr.
  428. XAce comment lines that begin with a "#" not in position (1)
  429. Xwill be correctly processed as source lines.
  430. X.LP
  431. XA number of Informix-4GL utilities in $INFORMIXDIR have names
  432. Xbeginning with "fgl".  Although there is no known Informix file "fglerr"
  433. Xas of release 4.10.UC1, there may be such a file in a future release.
  434. XCheck subsequent Informix releases and/or $PATH to insure that there is
  435. Xno conflict with DBMS operations.  Or, install
  436. X.I fglerr
  437. Xunder a different name.
  438. X.SH NOTICES
  439. XCopyright 1992 by Yerkes Research Center of Emory University,
  440. XAtlanta, Georgia, U.S.A.  All Rights Reserved.
  441. X.LP
  442. X"Informix" is a registered trademark of Informix Software, Inc.
  443. X.SH AUTHOR
  444. XWalt Hultgren  walt@rmy.emory.edu
  445. SHAR_EOF
  446. if [ `wc -c < fglerr.1` -ne     4195 ]
  447. then
  448.     echo "Lengths do not match -- Bad Copy of fglerr.1"
  449. fi
  450. echo "Done."
  451.