* ------------------------------------------------------------------ PROGRAM SEARCH * ------------------------------------------------------------------ * * Name: SEARCH - SEARCH for a file * * Computer: LSI-11/23 & LSI-11/73 * Operating System: RSX-11M V4.2 BL38C * Language: FORTRAN-77 * Original Programmer: R. E. K. Neitzel * Rockwell International * Rocky Flats Plant * Process Control Applications * Golden, CO 80401 * (303) 966-7171 * * Date Written: 3/31/87 * * * Revisions: Programmer Date Description * ---------- -------- --------------------- * * * Quality Assurance * Software Control no.: * * * Description: * This program acts in two modes: print all matching files and query * the user, or search for a specified pattern and only query if it is * found. The program is installed as a task under the form ...SSS. It is * invoked as follows: * >SSS filespec/nn[\Q] * The file spec can be of any legal form, with wildcards of the * forms *.*;* , *.xxx;* , xxx.*;* , *.*;x , etc. The '/nn' portion * MUST consist of two characters that determine the number of lines of * the file displayed on the CRT. Values of less then 10 must be entered as * 0n. Default is 21 lines. The \Q switch causes the user to be prompted * for a search string of up to 80 characters in length. If the string is * not found no query will be made and the next file is opened. * In the query section the user may elect to go to the next file, * stop searching or print the current file. Printing a file ends the * search. * The reader of this is strongly urged to examine the documentation * found in MACLIB.DOC for the routines PCAINI, PCAOPN and PCANAM. The * documentation can also be found in the library module FILES in * MACLIB.ULB. * * ---Local variables--- * type name usage * ---- ---- ----- CHARACTER*80 BUFF ! Invoking command buffer CHARACTER*1 CHOICE ! Action choice CHARACTER*2 CLINES ! # of lines to print in ASCII form INTEGER*2 COUNT ! Number of actual bytes in command line CHARACTER*5 DEV ! Device to work on INTEGER*2 DEVLEN ! Length of device name INTEGER*2 DSW ! Directive status word CHARACTER*16 FILE ! Name of file(s) to work on INTEGER*2 FLEN ! Length of file name INTEGER*2 FOUND ! Flag with various uses INTEGER*2 LINES ! Number of lines to print INTEGER*2 LOOP ! Counter for characters in search string CHARACTER*80 STRING ! Search string INTEGER*2 STRLEN ! Length of string INTEGER*2 TOP ! Pointer to end of filespec CHARACTER*9 UIC ! UIC INTEGER*2 UICLEN ! UIC length * * * ---Executable statements begin here--- * CALL GETMCR (BUFF, DSW) IF (DSW .LT. 1) THEN WRITE(5,5)DSW 5 FORMAT(' Error in GETMCR, DSW = ',I4) CALL EXIT ENDIF * * ---For no such file (29) & EOF (24) do our own error * recovery--- * CALL ERRSET (29,.TRUE.,.FALSE.,.TRUE.,.FALSE.) CALL ERRSET (24,.TRUE.,.FALSE.,.TRUE.,.FALSE.) BUFF(1:76) = BUFF(5:80) ! Strip out command name BUFF(77:80) = ' ' COUNT = DSW - 4 TOP = INDEX(BUFF(1:5),':') ! Look for device name IF (TOP .NE. 0) THEN DEV(1:TOP) = BUFF(1:TOP) ! Get name DEVLEN = TOP BUFF(1:80-TOP) = BUFF(TOP+1:80) COUNT = COUNT - TOP ELSE DEV(1:1) = '*' ! If no device set a marker for subroutine ENDIF TOP = INDEX(BUFF(1:9),']') ! Look for UIC IF (TOP .NE. 0) THEN UIC(1:TOP) = BUFF(1:TOP) ! Get it UICLEN = TOP BUFF(1:80-TOP) = BUFF(TOP+1:80) COUNT = COUNT - TOP ELSE UIC(1:1) = '*' ! Else set marker ENDIF TOP = INDEX(BUFF(1:COUNT),'/') ! Find start of line # IF (TOP .NE. 0) THEN FLEN = TOP - 1 ! This is end of filespec FILE(1:FLEN) = BUFF(1:FLEN) ! Get filespec CLINES(1:2) = BUFF(TOP+1:TOP+2) ! Get # of lines DECODE (2,10,CLINES) LINES ! Convert to numeric form 10 FORMAT(I2) ELSE LINES = 21 ! Default # of lines ENDIF FOUND = INDEX(BUFF(1:80),'\Q') ! Look for search switch IF (FOUND .EQ. 0) GOTO 19 ! Not there TYPE *, ' Enter the string to locate:' READ(5,15)STRING 15 FORMAT(A) 17 LOOP = LOOP + 1 IF (STRING(LOOP:LOOP) .GT. ' ') GOTO 17 ! Any nonprinting code is ! ignored STRLEN = LOOP - 1 19 CALL OPNFIL (DEV, DEVLEN, UIC, UICLEN, FILE, FLEN) ! Set up 20 CALL GETFIL (LINES, STRING, STRLEN, FOUND) ! Read a file IF (FOUND .GT. -1) THEN ! Search success or no search requested CALL QUERY (CHOICE) ELSE CLOSE (UNIT=1) ! Search failed GOTO 20 ENDIF IF (CHOICE .EQ. 'S') THEN CALL EXIT ELSEIF (CHOICE .EQ. 'P') THEN C CALL PRINT TYPE *, ' PRETEND PRINTING' CALL EXIT ELSE CLOSE (UNIT=1) GOTO 20 ENDIF END * ------------------------------------------------------------------ SUBROUTINE OPNFIL (DEV, DEVLEN, UIC, UICLEN, FILE, FLEN) * ------------------------------------------------------------------ * * Name: OPNFIL - OPeN the 1st FILe * * Computer: LSI-11/23 & LSI-11/73 * Operating System: RSX-11M V4.2 BL38C * Language: FORTRAN-77 * Original Programmer: R. E. K. Neitzel * Rockwell International * Rocky Flats Plant * Process Control Applications * Golden, CO 80401 * (303) 966-7171 * * Date Written: 3/31/87 * * * Revisions: Programmer Date Description * ---------- -------- --------------------- * * * Description: * This routine initializes the data structures used to open a series * of files. * * Subroutine and function calling outline: * PCAINI ! in MACLIB.ULB (OLB) * * * Passed variables * type name usage * ---- ---- ----- CHARACTER*5 DEV ! Device name INTEGER*2 DEVLEN ! Its length CHARACTER*16 FILE ! File name INTEGER*2 FLEN ! Its length CHARACTER*9 UIC ! UIC INTEGER*2 UICLEN ! Its length * * * ---Executable statements begin here--- * * ---'*' means that that field is blank, so default is used--- * IF ((DEV(1:1) .EQ. '*').AND.(UIC(1:1) .EQ. '*')) GOTO 10 IF ((DEV(1:1) .EQ. '*').AND.(UIC(1:1) .NE. '*')) GOTO 20 IF ((DEV(1:1) .NE. '*').AND.(UIC(1:1) .EQ. '*')) GOTO 30 IF ((DEV(1:1) .NE. '*').AND.(UIC(1:1) .NE. '*')) GOTO 40 10 CALL PCAINI(,,,,FILE,FLEN) RETURN 20 CALL PCAINI(,,UIC,UICLEN,FILE,FLEN) RETURN 30 CALL PCAINI(DEV,DEVLEN,,,FILE,FLEN) RETURN 40 CALL PCAINI(DEV,DEVLEN,UIC,UICLEN,FILE,FLEN) RETURN END * ------------------------------------------------------------------ SUBROUTINE GETFIL (LINES, STRING, STRLEN, FOUND) * ------------------------------------------------------------------ * * Name: GETFIL - GET the next FIle * * Computer: LSI-11/23 & LSI-11/73 * Operating System: RSX-11M V4.2 BL38C * Language: FORTRAN-77 * Original Programmer: R. E. K. Neitzel * Rockwell International * Rocky Flats Plant * Process Control Applications * Golden, CO 80401 * (303) 966-7171 * * Date Written: 3/31/87 * * * Revisions: Programmer Date Description * ---------- -------- --------------------- * * * Description: * * * Subroutine and function calling outline: * xxxxxx ! source in xxxxxx.FTN * EXTERNAL PCAOPN * * Passed variables * type name usage * ---- ---- ----- INTEGER*2 FOUND ! Flag INTEGER*2 LINES ! # of lines to print CHARACTER*80 STRING ! Search string INTEGER*2 STRLEN ! Its length * * Constants: * type name usage * ---- ---- ----- BYTE CLR(80) ! A blank line CHARACTER*80 CLEAR ! Ditto BYTE ESC ! ASCII escape code DATA CLR /80*0/ PARAMETER (ESC = "33) EQUIVALENCE (CLR(1),CLEAR(1:1)) * ---Local variables--- * type name usage * ---- ---- ----- LOGICAL*1 FLAG ! Flag INTEGER*2 LOOP ! Loop counter CHARACTER*80 RECORD ! Input record * * ---Executable statements begin here--- * * ---Open the next file in list--- * OPEN (UNIT=1,FILE='X.X',ACCESS='SEQUENTIAL',FORM='FORMATTED', * STATUS='OLD',USEROPEN=PCAOPN,ERR=1000,RECL=80) WRITE(5,1)ESC,ESC ! Clear crt and home cursor 1 FORMAT(' ',A1,'[1;1H',A1,'[2J') * * ---If flag is zero, no search--- * IF (FOUND .EQ. 0) THEN FLAG = .FALSE. ELSE FOUND = 0 ! Zero to prevent false return value FLAG = .TRUE. ENDIF DO 20 LOOP = 1, LINES READ(1,5,ERR=2000)RECORD 5 FORMAT(A) IF (FLAG) THEN FOUND = INDEX(RECORD(1:80),STRING(1:STRLEN)) ! Find it? IF (FOUND .GT. 0) FLAG = .FALSE. ! Yes, so don't look ! again ENDIF WRITE(5,10)RECORD ! Echo to CRT 10 FORMAT(' ',A) 20 RECORD(1:80) = CLEAR(1:80) ! Blank out record for next input * * ---If search failed (found=0) and we were searching, -1 means do not * query user.--- * IF ((FOUND .EQ. 0).AND.(FLAG)) FOUND = -1 RETURN 1000 TYPE *, ' No more files exist to be tested, exiting program.' CALL EXIT 2000 TYPE *, ' End of file reached.' IF ((FOUND .EQ. 0).AND.(FLAG)) FOUND = -1 ! As above RETURN END * ------------------------------------------------------------------ SUBROUTINE QUERY (CHOICE) * ------------------------------------------------------------------ * * Name: QUERY * * Computer: LSI-11/23 & LSI-11/73 * Operating System: RSX-11M V4.2 BL38C * Language: FORTRAN-77 * Original Programmer: R. E. K. Neitzel * Rockwell International * Rocky Flats Plant * Process Control Applications * Golden, CO 80401 * (303) 966-7171 * * Date Written: 3/31/87 * * * Revisions: Programmer Date Description * ---------- -------- --------------------- * * * Description: * This routine querys the user for the next action to take. The * choices are: Stop further processing, Print the current file or Go to * the next file. There is a one minute limit on the answer or the * program exits to avoid tying up the terminal. * * Passed variables * type name usage * ---- ---- ----- CHARACTER*1 CHOICE ! Decision made * * Constants: * type name usage * ---- ---- ----- INCLUDE 'QIO.PAR' * * ---Local variables--- * type name usage * ---- ---- ----- INTEGER*2 DSW ! Directive status word INTEGER*2 PARMS(6) ! QIO parameters DATA PARMS(2) /1/ * * * ---Executable statements begin here--- * CALL GETADR (PARMS(1),CHOICE) TYPE *, ' Enter one of the following actions - [P]rint ', * 'this file, [S]top the search,' TYPE 10 10 FORMAT(' [G]o to next file, [R]epeat this file: ',$) CALL MARK (1,60,2) ! Get user 1 minute to answer CALL QIO(IORVB,5,2,,,PARMS) ! Post qio CALL WFLOR(1,2) ! Wait for qio or time out CALL READEF (1, DSW) ! Check for time out IF (DSW .EQ. 2) THEN ! Oops TYPE *, ' Program timed out exiting.' CALL EXIT ENDIF RETURN END * ------------------------------------------------------------------ SUBROUTINE PRINT * ------------------------------------------------------------------ * * Name: PRINT * * Computer: LSI-11/23 & LSI-11/73 * Operating System: RSX-11M V4.2 BL38C * Language: FORTRAN-77 * Original Programmer: R. E. K. Neitzel * Rockwell International * Rocky Flats Plant * Process Control Applications * Golden, CO 80401 * (303) 966-7171 * * Date Written: 3/31/87 * * * Revisions: Programmer Date Description * ---------- -------- --------------------- * * * Description: * This module prints out the current file. The file name is * determined via PCANAM and then the file is closed. The print command * is then spawned to perform printing and the program exits. * * Subroutine and function calling outline: * xxxxxx ! source in xxxxxx.FTN * * ---Local variables--- * type name usage * ---- ---- ----- CHARACTER*29 COMAND ! Command spawned CHARACTER*2 DEV ! Device file is on CHARACTER*3 DEVNUM ! Its number CHARACTER*9 FNAME ! Its name CHARACTER*3 FTYPE ! Its type CHARACTER*3 VER ! and version # DATA COMAND(1:4) /'LGP '/ DATA COMAND(10:10) /':'/ DATA COMAND(20:20) /'.'/ DATA COMAND(24:24) /';'/ * * * ---Executable statements begin here--- * CALL PCANAM (DEV, DEVNUM, FNAME, FTYPE, VER) CLOSE(UNIT=1) COMAND(5:6) = DEV(1:2) COMAND(7:9) = DEVNUM(1:3) COMAND(11:19) = FNAME(1:9) COMAND(21:23) = FTYPE(1:3) COMAND(25:27) = VER(1:3) TYPE *, ' Print [L]ong, [S]hort or [B]oth: ' ! Print what READ(5,5)COMAND(29:29) 5 FORMAT(A1) CALL SPNMC1(COMAND, 29) C CALL SPNMCR(COMAND, 29) RETURN END