home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a009 / 5.ddi / SYS.LIF / LBLBACK.PRG < prev    next >
Encoding:
Text File  |  1991-04-14  |  4.1 KB  |  134 lines

  1. /***
  2. *
  3. *   Lblback.prg
  4. *   Clipper 5.0 LABEL FORM runtime system
  5. *   Copyright (c) 1990 Nantucket Corp.  All rights reserved
  6. *
  7. *   Compile:  /m/n/w
  8. */
  9.  
  10. #include "lbldef.ch"
  11. #include "error.ch"
  12.  
  13. #define BUFFSIZE        1034          // Size of label file
  14. #define FILEOFFSET      74            // Start of label content descriptions
  15. #define FIELDSIZE       60
  16. #define REMARKOFFSET    2
  17. #define REMARKSIZE      60
  18. #define HEIGHTOFFSET    62
  19. #define HEIGHTSIZE      2
  20. #define WIDTHOFFSET     64
  21. #define WIDTHSIZE       2
  22. #define LMARGINOFFSET   66
  23. #define LMARGINSIZE     2
  24. #define LINESOFFSET     68
  25. #define LINESSIZE       2
  26. #define SPACESOFFSET    70
  27. #define SPACESSIZE      2
  28. #define ACROSSOFFSET    72
  29. #define ACROSSSIZE      2
  30.  
  31. // File error definitions
  32. #define  F_OK              0          // No error
  33. #define  F_EMPTY          -3          // File is empty
  34. #define  F_ERROR          -1          // Some kind of error
  35. #define  F_NOEXIST         2          // File does not exist
  36.  
  37.  
  38. /***
  39. *  __LblLoad( cLblFile ) --> aLabel
  40. *  Load a (.lbl) file into a label array as specified in lbldef.ch
  41. *
  42. */
  43. FUNCTION __LblLoad( cLblFile )
  44.    LOCAL i, j       := 0                  // Counters
  45.    LOCAL cBuff      := SPACE(BUFFSIZE)    // File buffer
  46.    LOCAL nHandle    := 0                  // File handle
  47.    LOCAL nReadCount := 0                  // Bytes read from file
  48.    LOCAL lStatus    := .F.                // Status
  49.    LOCAL nOffset    := FILEOFFSET         // Offset into file
  50.    LOCAL nFileError := F_OK               // File error
  51.    LOCAL cFieldText := ""                 // Text expression container
  52.    LOCAL err
  53.  
  54.    // Create and initialize default label array
  55.    LOCAL aLabel[ LB_COUNT ]
  56.    aLabel[ LB_REMARK ]  := SPACE(60)      // Label remark
  57.    aLabel[ LB_HEIGHT ]  := 5              // Label height
  58.    aLabel[ LB_WIDTH ]   := 35             // Label width
  59.    aLabel[ LB_LMARGIN ] := 0              // Left margin
  60.    aLabel[ LB_LINES ]   := 1              // Lines between labels
  61.    aLabel[ LB_SPACES ]  := 0              // Spaces between labels
  62.    aLabel[ LB_ACROSS ]  := 1              // Number of labels across
  63.    aLabel[ LB_FIELDS ]  := {}             // Array of label fields
  64.  
  65.    // Open the label file
  66.    nHandle := FOPEN( cLblFile )
  67.  
  68.    nFileError := FERROR()
  69.  
  70.    // File error
  71.    IF nFileError != F_OK
  72.       err := ErrorNew()
  73.       err:severity := 2
  74.       err:genCode := EG_OPEN
  75.       err:subSystem := "FRMLBL"
  76.       Eval(ErrorBlock(), err)
  77.    ENDIF
  78.  
  79.    // If we got this far, assume the label file is open and ready to go
  80.    // and so go ahead and read it
  81.    nReadCount := FREAD( nHandle, @cBuff, BUFFSIZE )
  82.  
  83.    // READ ok?
  84.    IF nReadCount == 0
  85.       nFileError := F_EMPTY             // File is empty
  86.    ELSE
  87.       nFileError := FERROR()            // Check for DOS errors
  88.    ENDIF
  89.  
  90.    IF nFileError == 0
  91.  
  92.       // Load label dimension into aLabel
  93.       aLabel[ LB_REMARK ] := SUBSTR(cBuff, REMARKOFFSET, REMARKSIZE)
  94.       aLabel[ LB_HEIGHT ] := BIN2W(SUBSTR(cBuff, HEIGHTOFFSET, HEIGHTSIZE))
  95.       aLabel[ LB_WIDTH  ] := BIN2W(SUBSTR(cBuff, WIDTHOFFSET, WIDTHSIZE))
  96.       aLabel[ LB_LMARGIN] := BIN2W(SUBSTR(cBuff, LMARGINOFFSET, LMARGINSIZE))
  97.       aLabel[ LB_LINES  ] := BIN2W(SUBSTR(cBuff, LINESOFFSET, LINESSIZE))
  98.       aLabel[ LB_SPACES ] := BIN2W(SUBSTR(cBuff, SPACESOFFSET, SPACESSIZE))
  99.       aLabel[ LB_ACROSS ] := BIN2W(SUBSTR(cBuff, ACROSSOFFSET, ACROSSSIZE))
  100.  
  101.       FOR i := 1 TO aLabel[ LB_HEIGHT ]
  102.  
  103.          // Get the text of the expression
  104.          cFieldText := TRIM( SUBSTR( cBuff, nOffset, FIELDSIZE ) )
  105.          nOffset += 60
  106.  
  107.          IF !EMPTY( cFieldText )
  108.  
  109.             AADD( aLabel[ LB_FIELDS ], {} )
  110.  
  111.             // Field expression
  112.             AADD( aLabel[ LB_FIELDS, i ], &( "{ || " + cFieldText + "}" ) )
  113.  
  114.             // Text of field
  115.             AADD( aLabel[ LB_FIELDS, i ], cFieldText )
  116.  
  117.             // Compression option
  118.             AADD( aLabel[ LB_FIELDS, i ], .T. )
  119.  
  120.          ELSE
  121.  
  122.             AADD( aLabel[ LB_FIELDS ], NIL )
  123.  
  124.          ENDIF
  125.  
  126.       NEXT
  127.  
  128.       // Close file
  129.       FCLOSE( nHandle )
  130.       nFileError = FERROR()
  131.  
  132.    ENDIF
  133.    RETURN( aLabel )
  134.