#!/usr/local/bin/rxx /* qall EXEC - Displays all the lines of in the selected file with the selected text*/ /* qall EXEC displays all lines in the file with the selected text string ..................................................................... Command Format: qall Where: Parms, if provided, gives the filename and search criteria if not provided then the filename & search criteria come from GETENV('QUERY_STRING') (where they are placed by WWW). The format of the Parms or the QUERY_STRING input is: FILENAME=filename&SELECT=select_value&CASE=case_value The filename is case sensitive and must be a valid Unix filename. The select_value is the string of text to be use. Any lines with the select_value in them will be displayed. The case_value if set to IGNORE will be used to ignore the case of the string of text being sought. The script is expected to be called by a CGI Wrapper which will ensure that only appropriate characters are included in the values. Method: Qall uses egrep to perform the search (unless no SELECT is provided in which case it simply uses cat) and the output is sent to standard output. The output format is designed to be displayed by a WWW browser and so is in html format. Examples: qall "file=/u/sf/cottrell/ssc/mers.txt&SELECT=HP&CASE=ignore" http://www/cgi-wrap?qall+file=/u/sf/cottrell/mers&SELECT=IBM Please send comments and/or suggestions to Les Cottrell. */ /* **************************************************************** */ /* Owner(s): Les Cottrell Sep 10, 1994 */ /* Revision History: */ /* **************************************************************** */ ADDRESS 'COMMAND'; SIGNAL ON NOVALUE; SIGNAL ON HALT; SIGNAL ON SYNTAX PARSE ARG Parms /*****************************************************************/ /* HELP */ /*****************************************************************/ IF Parms = '?' | Parms='help' THEN DO Saying = 0 DO I = 2 BY 1 WHILE "SOURCELINE"(I)/='*/' IF Saying ^= 0 THEN SAY "SOURCELINE"(I) IF SOURCELINE(I) = '/*' THEN Saying = I END I EXIT 100 END Debug=1 /* ******************************************** */ /* The Wrapper puts out the Content-type info */ /* SAY "Content-type: text/html"; SAY */ /* ******************************************** */ SAY 'Find ALL lines in file with selected text' QueryString=GETENV('QUERY_STRING') IF Debug>0 THEN SAY 'QueryString="'GETENV('QUERY_STRING')'"
' IF Parms='' THEN DO /* Input from QUERY_STRING*/ QueryString=GETENV('QUERY_STRING'); From='QUERY_STRING' END ELSE DO /* Input direct from Parms */ QueryString=Parms; From='PARMS' END IF Debug>0 THEN SAY 'Raw input(from='From')="'QueryString'".
' Select=''; Case='' DO I=1 BY 1 UNTIL QueryString='' IF POS('=',QueryString)=0 THEN CALL Exit 24, 'Equal sign (=) missing in substring' String 'of the input' QueryString'.' PARSE VAR QueryString Name'='Value QueryString IF Debug>0 THEN SAY Name'='Value'.
' IF Value='' THEN ITERATE I IF TRANSLATE(Name)='FILE' THEN DO FileName=Value IF Exist(FileName)=0 THEN CALL Exit 28, "Can't find file" Filename"!
" END ELSE IF TRANSLATE(Name)='CASE' THEN DO IF TRANSLATE(Value)/='IGNORE' THEN Case='-i' END ELSE IF TRANSLATE(Name)='SELECT' THEN Select=Value ELSE CALL Exit 24, 'Name=' Name 'not recognized, command not executed!
' END I IF Select='' THEN DO SAY '

No selection string given, displaying complete file' FileName'

'
      ADDRESS UNIX 'cat' filename
   END
   ELSE DO
      SAY '

Display of all lines with' Select 'in' FileName'

'
      ADDRESS UNIX "egrep" Case "'"Select"'" Filename
      IF RC/=0 THEN SAY 'Failed to find any lines matching selection=' Select'.'
   END

EXIT 0

Exist: PROCEDURE
/* ********************************************************************
| The Exist function returns 1 (true) if the Filename specified
| exists, and 0 (false) otherwise.
| i=Exist(filename)
| ******************************************************************** */
   PARSE ARG Filename
      IF LINES(Filename)=0 THEN RETURN 0
      ELSE                      RETURN 1
 
/* ERROR MESSAGES */
/* Rex will jump to this error exit if a variable is encountered */
/* that has not been initialized. It will show which line it found */
/* the variable and begin a trace, so that you can see what value */
/* each variable has at that time. */
NoValue:
   PARSE SOURCE . . $Fn .
   CALL Exit 99, 'Undefined variable referenced on line' SIGL 'of' $Fn SOURCELINE(SIGL)'!
' /* Rex will jump to this exit if during the execution of the exec, */ /* the user types HE. (That's Halt Execution). */ Halt: PARSE SOURCE . . $Fn $Ft $Fm . SAY 'Signaled on line' SIGL 'of' $Fn $Ft $Fm SAY SOURCELINE(SIGL) EXIT 99 /* Rex will jump to this error exit if a syntax error occurs. */ /* It returns the user to the line in the exec with the error. */ Syntax: PARSE SOURCE . . $Fn . CALL Exit 98, 'Syntax error signaled on line' SIGL 'of' $Fn SOURCELINE(SIGL)'!
' Exit: PROCEDURE EXPOSE Debug Parms /* ******************************************************************** | Exit from Script - Assumes Content-type: text/html | ********************************************************************* */ PARSE ARG Code, Msg SAY ''GETENV('SCRIPT_NAME')' error' Code'' SAY '

Error Code' Code 'reported by'GETENV('SCRIPT_NAME')'.

' SAY 'The WWW utility on' SAY ''GETENV('SERVER_NAME')':'GETENV('SERVER_PORT')'' SAY 'that you are using' SAY 'from your WWW browser ('GETENV('HTTP_USER_AGENT')')' SAY 'on 'GETENV('REMOTE_HOST')' called' SAY '(using the 'GETENV('REQUEST_METHOD')' method) a' SAY 'Common Gateway Interface' SAY '(revision 'GETENV('GATEWAY_INTERFACE')') script' SAY 'which reports the following error:' IF Msg/='' THEN SAY '

'Msg'

' IF Debug>0 THEN DO SAY '
The complete environment (for debugging purposes) follows:

'
     ADDRESS Unix "tcsh -c printenv"
     SAY '
Arguments="'Parms'".
' SAY '
' END SAY '
[' SAY 'SLAC Home Page |' SAY 'Suggestion Box ]' SAY '
Les Cottrell
' IF Code=0 THEN RETURN EXIT /*Code*/