home *** CD-ROM | disk | FTP | other *** search
- /***
- *
- * Lblrun.prg
- * Clipper 5.0 LABEL FORM runtime system
- * Copyright (c) 1990 Nantucket Corp. All rights reserved
- *
- * Compile: /m/n/w
- */
-
- #include "lbldef.ch" // Label array definitions
- #include "error.ch"
-
-
- // File-wide static declarations
- STATIC aLabelData // Label definition array
- STATIC aBandToPrint := {}
- STATIC cBlank
- STATIC lOneMoreBand := .T.
- STATIC nCurrentCol := 1 // The current column in the band
-
-
- /***
- * __LabelForm( ... ) --> NIL
- *
- * Print the specified (.lbl) definition for specified records
- * meeting specified scope and condition
- *
- */
-
- FUNCTION __LabelForm( cLBLName, lPrinter, cAltFile, lNoConsole, bFor, ;
- bWhile, nNext, nRecord, lRest, lSample )
- LOCAL lPrintOn := .F.
- LOCAL lConsoleOn := .T.
- LOCAL cExtraFile, lExtraState
- LOCAL xBreakVal, lBroke := .F.
- LOCAL err
- Local OldMargin
-
-
- // Resolve parameters
- IF cLBLName == NIL
- err := ErrorNew()
- err:severity := 2
- err:genCode := EG_ARG
- err:subSystem := "FRMLBL"
- Eval(ErrorBlock(), err)
-
- ELSE
- IF AT( ".", cLBLName ) == 0
- cLBLName := TRIM( cLBLName ) + ".LBL"
- ENDIF
-
- ENDIF
-
- IF lPrinter == NIL
- lPrinter := .F.
- ENDIF
-
- IF lNoConsole == NIL
- lNoConsole := .F.
- ENDIF
-
- IF lSample == NIL
- lSample := .F.
- ENDIF
-
- // Set output devices
- IF lPrinter // To the printer
- lPrintOn := SET( _SET_PRINTER, lPrinter )
- ENDIF
-
- IF lNoConsole // To the screen
- lConsoleOn := SET( _SET_CONSOLE, .F. )
- ENDIF
-
- IF (!Empty(cAltFile)) // To file
- cExtraFile := SET( _SET_EXTRAFILE, cAltFile )
- lExtraState := SET( _SET_EXTRA, .T. )
- ENDIF
-
- OldMargin := SET( _SET_MARGIN, 0)
-
- BEGIN SEQUENCE
-
- aLabelData := __LblLoad( cLBLName ) // Load the (.lbl) into an array
-
- // Add to the left margin if a SET MARGIN has been defined
- aLabelData[ LB_LMARGIN ] += OldMargin
-
- // Size the aBandToPrint array to the number of fields
- ASIZE( aBandToPrint, LEN( aLabelData[ LB_FIELDS ] ) )
- AFILL( aBandToPrint, SPACE( aLabelData[ LB_LMARGIN ] ) )
-
- // Create enough space for a blank record
- cBlank := SPACE( aLabelData[ LB_WIDTH ] + aLabelData[ LB_SPACES ] )
-
- // Handle sample labels
- IF lSample
- SampleLabels()
- ENDIF
-
- // Execute the actual label run based on matching records
- DBEval( { || ExecuteLabel() }, bFor, bWhile, nNext, nRecord, lRest )
-
- // Print the last band if there is one
- IF lOneMoreBand
- // Print the band
- AEVAL( aBandToPrint, ;
- { | BandLine | ; // PrintIt( SPACE(aLabelData[LB_LMARGIN])+ BandLine ) ;
- PrintIt( BandLine ) ;
- } ;
- )
- ENDIF
-
-
- RECOVER USING xBreakVal
-
- lBroke := .T.
-
- END
-
- // Clean up and leave
- aLabelData := {} // Recover the space
- aBandToPrint := {}
- nCurrentCol := 1
- cBlank := ""
- lOneMoreBand :=.T.
-
- // clean up
- SET( _SET_PRINTER, lPrintOn ) // Set the printer back to prior state
- SET( _SET_CONSOLE, lConsoleOn ) // Set the console back to prior state
-
- IF (!Empty(cAltFile)) // Set extrafile back
- SET( _SET_EXTRAFILE, cExtraFile )
- SET( _SET_EXTRA, lExtraState )
- ENDIF
-
- IF lBroke
- BREAK xBreakVal // continue breaking
- ENDIF
-
- SET( _SET_MARGIN, OldMargin)
-
- RETURN NIL
-
-
- /***
- * ExecuteLabel() --> NIL
- * Process the label array using the current record
- */
- STATIC FUNCTION ExecuteLabel
- LOCAL nField, nMoreLines, aBuffer := {}, cBuffer
- LOCAL v
-
- // Load the current record into aBuffer
- FOR nField := 1 TO LEN( aLabelData[ LB_FIELDS ] )
-
- if ( aLabelData[ LB_FIELDS, nField ] <> NIL )
-
- v := Eval( aLabelData[ LB_FIELDS, nField, LF_EXP ] )
-
- cBuffer := PadR( v, aLabelData[ LB_WIDTH ] )
- cBuffer += Space( aLabelData[ LB_SPACES ] )
-
-
- if ( aLabelData[ LB_FIELDS, nField, LF_BLANK ] )
- if ( !Empty( cBuffer ) )
- AAdd( aBuffer, cBuffer )
- end
- else
- AAdd( aBuffer, cBuffer )
- endif
-
- else
-
- AAdd( aBuffer, NIL )
-
- end
-
- NEXT
-
- ASIZE( aBuffer, LEN( aLabelData[ LB_FIELDS ] ) )
-
- // Add aBuffer to aBandToPrint
- FOR nField := 1 TO LEN( aLabelData[ LB_FIELDS ] )
- IF aBuffer[ nField ] == NIL
- aBandToPrint[ nField ] += cBlank
- ELSE
- aBandToPrint[ nField ] += aBuffer[ nField ]
- ENDIF
- NEXT
-
- IF nCurrentCol == aLabelData[ LB_ACROSS ]
-
-
- // trim
- FOR nField := 1 TO LEN( aBandToPrint )
- aBandToPrint[ nField ] := Trim( aBandToPrint[ nField ] )
- NEXT
-
-
- lOneMoreBand := .F.
- nCurrentCol := 1
-
- // Print the band
- AEVAL( aBandToPrint, ;
- { | BandLine | ; //----PU---PrintIt( SPACE(aLabelData[LB_LMARGIN])+ BandLine ) ;
- PrintIt( BandLine ) ;
- } ;
- )
- nMoreLines := aLabelData[ LB_HEIGHT ] - LEN( aBandToPrint )
- IF nMoreLines > 0
- FOR nField := 1 TO nMoreLines
- PrintIt()
- NEXT
- ENDIF
- IF aLabelData[ LB_LINES ] > 0
-
- // Add the spaces between the label lines
- FOR nField := 1 TO aLabelData[ LB_LINES ]
- PrintIt()
- NEXT
-
- ENDIF
-
- // Clear out the band
- AFILL( aBandToPrint, SPACE( aLabelData[ LB_LMARGIN ] ) )
- ELSE
- lOneMoreBand := .T.
- nCurrentCol++
- ENDIF
-
- RETURN NIL
-
-
- /***
- * SampleLabels() --> NIL
- * Print sample labels
- */
- STATIC FUNCTION SampleLabels
- LOCAL nGetKey, lMoreSamples := .T., nField
- LOCAL aBand := {}
-
- // Create the sample label row
- ASIZE( aBand, aLabelData[ LB_HEIGHT ] )
- AFILL( aBand, SPACE( aLabelData[ LB_LMARGIN ] ) +;
- REPLICATE( REPLICATE( "*", ;
- aLabelData[ LB_WIDTH ] ) + ;
- SPACE( aLabelData[ LB_SPACES ] ), ;
- aLabelData[ LB_ACROSS ] ) )
-
- // Prints sample labels
- DO WHILE lMoreSamples
-
- // Print the samples
- AEVAL( aBand, ;
- { | BandLine | ;
- PrintIt( BandLine ) ;
- } ;
- )
- IF aLabelData[ LB_LINES ] > 0
- // Add the spaces between the label lines
- FOR nField := 1 TO aLabelData[ LB_LINES ]
- PrintIt()
- NEXT
- ENDIF
-
- // Prompt for more
- @ ROW(), 0 SAY "Do you want more samples? (Y/N)"
- nGetKey := INKEY(0)
- @ ROW(), COL() SAY CHR(nGetKey)
- IF ROW() == MAXROW()
- SCROLL( 0, 0, MAXROW(), MAXCOL(), 1 )
- @ MAXROW(), 0 SAY ""
- ELSE
- @ ROW()+1, 0 SAY ""
- ENDIF
- IF UPPER(CHR(nGetKey)) == "N"
- lMoreSamples := .F.
- ENDIF
- ENDDO
- RETURN NIL
-
-
- /***
- * PrintIt( <cString> ) --> NIL
- * Print a string, then send a CRLF
- */
- STATIC FUNCTION PrintIt( cString )
-
- IF cString == NIL
- cString := ""
- ENDIF
- QQOUT( cString )
- QOUT()
-
- RETURN NIL
-