   ****************  REVIEW.CMD FILE  ***********************
* this is used to list entries in any .DBF file.  The database muse be named in
* the command file calling the procedure.  Records may be listed conditionally.
* with or without the record numbers.
*      Records are listed in groups of 10 with a line space between each group.
* Processing can be continuous, or can stop after every group of 10.
*      The listing can start on a specified record number.
*      The files can be re-listed as many times as desired.
*      Printing is optional.  The "CHR(X)" commands are for a Diablo 1650
* printer.
**************************************************************************

STORE 'Y' TO Reviewing
DO WHILE !(Reviewing)='Y'
   COPY STRUCTURE EXTENDED TO Temp
   GO BOTTOM
   STORE STR(#,5) TO Last
   ERASE
   ?
   ? 'The '+!(Database)+' database has '-Last+' entries.  They will be shown'
   ? 'in groups of 10 records, 50 records to a page if printed.'
   ? 'Enter new values for defaults or press <Return>:'
   ?
   ? '***  DISPLAY  [Field list] [FOR <expression> [OFF]   ***'
   ?
   STORE   1 TO First
   STORE   1 TO PageCnt
   STORE VAL(Last) TO RecoCnt
   STORE 'N' TO Pause
   STORE 'N' TO Partial
   STORE 'N' TO Conditions
   STORE 'N' TO Tally
   STORE 'C' TO Changing
   DO WHILE !(Changing) = 'C'
      @  8,10 SAY 'START ON RECORD NUMBER ' GET First
      @  9,10 SAY ' STOP ON RECORD NUMBER ' GET RecoCnt
      @ 10,10 SAY ' START PAGE NUMBERS ON ' GET PageCnt
      @ 11,10 SAY 'PAUSE EVERY 10 RECORDS ' GET Pause
      @ 12,10 SAY '  SHOW SELECTED FIELDS ' GET Partial
      @ 13,10 SAY 'DISPLAY FOR EXPRESSION ' GET Conditions
      @ 14,10 SAY '   SHOW RECORD NUMBERS ' GET Tally

      ?
      ? '      C to CHANGE the defaults,'
      ? '     <Return> to continue.'
      WAIT TO Changing

      IF !(Changing) = 'C'
         * Clear to end of screen on IBM 3101-CHR(27)&(74)
         @ 15,0 SAY CHR(27)+CHR(74)
         READ
      ELSE
         IF First > VAL(Last) .OR. First <= 0 .OR. RecoCnt > VAL(Last);
                           .OR. RecoCnt <= 0
            @ 15,0 SAY CHR(27)+CHR(74)
            @ 16,0 SAY 'Sorry, wrong number:  '-!(Database)+' contains '+;
                       'records 1 through'+Last+'.'
            ? '<Return> to correct your entry.'
            WAIT
            @ 15,0 SAY CHR(27)+CHR(74)
            STORE 'C' TO Changing
            STORE 1 TO First
            STORE VAL(Last) TO RecoCnt
         ENDIF
      ENDIF
      * Clear to end of screen on IBM 3101-CHR(27)&(74)
      @ 15,0 SAY CHR(27)+CHR(74)
   ENDDO
   ?
   ?   
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   ?
   IF !(Partial) = 'Y'
      @ 11,0 SAY CHR(27)+CHR(74)
      @ 11,0 SAY 'The '+!(Database)+' database consists of these FIELDS:'
      USE Temp
      ?
      STORE ' ' TO Choices
      DO WHILE .NOT. EOF
         STORE Choices+Trim(Field:Name)+', ' TO Choices
         SKIP
      ENDDO
      STORE $(Choices,2,LEN(Choices)-3) TO Choices
      STORE 'Y' TO Unfinished
      DO WHILE !(Unfinished) = 'Y'
         @ 13, 0 SAY Choices

         USE B:&Database
         ?
         ? 'List FIELDS to display (<return> to show all).'
         ?
         ACCEPT '        DISPLAY ' TO Partial
         STORE !(Partial) TO Partial
         STORE Partial TO String
         STORE LEN(String) TO Size

         IF Size = 0 .OR. (Size = 1 .AND. Partial = ' ')
            STORE CHR(0) TO Partial
            STORE 'N' TO Unfinished
         ELSE
            ?
            ? 'Want to change it (Y or N)?'
            WAIT TO Unfinished
            IF !(Unfinished) = 'Y'
               @ 12, 0 SAY CHR(27) + CHR(74)
            ELSE
               @ 10, 0 SAY CHR(27) + CHR(74)
               ? '*** Checking fields ['+Partial+'] : '
               ?
               STORE 0 TO F
               STORE 0 TO Counter
               DO WHILE Size >0
                  STORE Counter + 1 TO Counter
                  ?? ' *'+STR(Counter,2)
                  STORE @(',', String) TO Mark
                  IF Mark = 1 .OR. Mark = Size
                     ? 'Uh, oh--trouble: comma cannot be at the ';
                              +'start or end of a list of values.'
                     ? '<Return> and try again.'
                     STORE 0 TO Size
                     STORE 'Y' TO Unfinished
                     WAIT
                  ELSE
                     IF Mark > 0
                        STORE (Mark - 1) TO Size
                     ENDIF

                     STORE T TO Blank
                     STORE 1 TO Start
                     DO WHILE Blank .AND. (.NOT. Start > Size)
                        IF $(String,Start, 1)=  ' '
                           STORE (Start + 1) TO Start
                        ELSE 
                           STORE (.NOT. Blank) TO Blank
                        ENDIF
                     ENDDO

                     IF Start > Size
                        ? 'How on earth can I find a blank field?'
                        ? '<Return> and try again.'
                        STORE 0 TO Size
                        STORE 'Y' TO Unfinished
                        WAIT
                     ELSE
                        STORE (F + 1) TO F
                        IF F < 10
                           STORE STR(F,1) TO Suffix
                        ELSE
                           STORE SRT(F,2) TO Suffix
                        ENDIF
                        STORE 'FIELD'+Suffix TO Field
                        STORE 'TRIM($(String,Start,(Size,-Start+1)))' TO &Field

                        IF Mark > 0
                           STORE TRIM($(String, (Size + 2))) TO String
                           STORE LEN(String) TO Size
                        ELSE
                           STORE 'N' TO Unfinished
                           STORE 0 TO Size
                        ENDIF
                     ENDIF
                  ENDIF
               ENDDO
            ENDIF
         ENDIF
      ENDDO
      IF LEN(Partial) > 0
         * DO Headings
         ? "WE'D DO THE HEADINGS HERE (need to write this .cmd file)."
         WAIT
      ENDIF
   
   ELSE
      STORE CHR(0) TO Partial
   ENDIF
   
   IF !(Conditions) = 'Y'
      STORE 'Y' TO Unfinished
      DO WHILE !(Unfinished) = 'Y'
         @ 11, 0 SAY CHR(27)+CHR(74)
         @ 11, 0 SAY 'Specify the EXPRESSION or <Return> to skip.'
         ?
         ? 'DISPLAY &Partial FOR '
         ACCEPT TO Expression
         ?
         ? 'Do you want to change the expression (Y or N)?'
         WAIT TO Unfinished
      ENDDO

      IF Expression > '                                            '
         STORE 'FOR '+ Expression TO Conditions
      ELSE
         STORE CHR(0) TO Conditions
      ENDIF
   ELSE
      STORE CHR(0) TO Conditions
   ENDIF

   IF !(Tally) <> 'Y'
      STORE  'OFF' TO Tally
   ELSE
      STORE CHR(0) TO Tally
   ENDIF

   STORE [DISPLAY Next 1 &Partial &Conditions &Tally] TO Command
   @ 11, 0 SAY CHR(27)+CHR(74)
   @ 11, 0 SAY '***  '+[DISPLAY &Partial &Conditions &Tally]+'  ***'
   ?
   ? 'is the command that will be performed on the '+!(Database)+' database.'
   ? '      C to CHANGE it,'
   ? '      Q to QUIT with no action,'
   ? '   <Return> to review the database.'
   WAIT TO Abort

   IF !(Abort) = 'Q'
      STORE CHR(0) TO Reviewing
   ELSE
      IF !(Abort) <> 'C'
         ERASE
         ? 'Enter a one-line heading or press <Return> to skip.'
         ACCEPT TO Message
         STORE !(Message) TO Message
         ?
         STORE 0 TO Count
         STORE 0 TO PageMark
         STORE STR(First,5) TO Number
         GO &Number

         ERASE
         ? 'Do you want to print the listing now (Y or N)?'
         ACCEPT TO Hardcopy

         IF !(Hardcopy) = 'Y'
            SET PRINT ON
            DO RevMrgn
         ENDIF

         ERASE
         ? Message
         ? 'Page '+ STR(PageCnt,3)
    
         IF Tally = 'OFF'
            ?? 'starts on Record #'-STR(#,5)
            ?
            IF .NOT. (Partial > ' ' .OR. Conditions > ' ')
               DO RevHdr
            ENDIF
         ENDIF
         ?
         DO WHILE .NOT. EOF .AND. # <= RecoCnt
            &Command

            IF !(Conditions) > CHR(0)
               IF &Expression
                  STORE (Count + 1) TO Count
               ENDIF
            ELSE
               STORE (Count + 1) TO Count
            ENDIF
            SKIP

            IF Count=10
               STORE 0 TO Count
               * Inserts a space every ten records, then waits.  The printer
               * is turned off so that "WAIT" does not print out on the hardcopy.
               ?
               SET PRINT OFF
               IF !(Pause) = 'Y'
                  WAIT
               ENDIF

               IF !(Hardcopy) = 'Y'
                  SET PRINT ON
               ENDIF

               * The following routine prints 50 entries to a page,
               * then moves to the next page and prints a heading

               STORE (PageMark + 1) TO PageMark
               IF PageMark = 5
                  ? CHR(12)
                  STORE (PageCnt + 1) TO PageCnt

                  IF INT(PageCnt/7) = PageCnt/7
                     ?
                  ENDIF

                  ? Message
                  ? 'Page '+STR(PageCnt,3)

                  IF Tally = 'OFF'
                     ?? 'starts on Record #'-STR(#,5)
                     ?
                     IF .NOT.( Partial > ' ' .OR. Conditions > ' ')
                        DO RevHdr
                     ENDIF
                  ENDIF
                  ?
                  STORE 0 TO PageMark
               ENDIF
            ENDIF
         ENDDO

         * Formfeed on Diablo 1650 printer = CHR(12)
         ? CHR(12)
         SET PRINT OFF
         SET RAW ON
         * SET MARGIN TO 38
         SET MARGIN TO 10

         ? 'Do you want to see the '+!(Database)+' again (Y or N)?'
         WAIT TO Reviewing
      ELSE
         STORE 'Y' TO Reviewing
      ENDIF
   ENDIF
   ?
ENDDO Reviewing

USE
DELETE FILE Temp
RELEASE All
RETURN
