Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The Guide To Clipper - <b>get_expr() reads exp from expr_buff via offset_buff rlback.prg</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Get_expr()     Reads exp from expr_buff via offset_buff     Rlback.prg


Syntax:        Get_expr(<expN>)

Argument:      <expN> is a pointer to offset contained in
               OFFSETS_BUFF string that in turn points to an expression
               located in the EXPR_BUFF string.

Returns:       A character string representing the retrieved expression,
               null ("") if it is empty.

Calls:         Word_2_num()

Notes:         . The expression is empty if:

                 1. Passed pointer is equal to 65535.
                 2. Character following character pointed to by pointer
                    is CHR(0) (NULL).

               . Called by the FRM_LOAD(), GET_FIELD()
               . File error number placed in file_error


--------------------------------- Source Code ------------------------------

   FUNCTION GET_EXPR

   PARAMETERS pointer

   PRIVATE expr_offset, expr_length, offset_offset, string

   expr_offset   = 0
   expr_length   = 0
   offset_offset = 0

   string = ""

   ** Stuff for dBASE compatibility. **
   IF pointer != 65535

      ** Convert DOS FILE offset to CLIPPER string offset **
      pointer = pointer + 1

      ** Calculate offset into OFFSETS_BUFF **
      IF pointer > 1
         offset_offset = (pointer * 2) - 1
      ENDIF

      expr_offset = WORD_2_NUM(substr(offsets_buff, offset_offset, 2))
      expr_length = WORD_2_NUM(substr(lengths_buff, offset_offset, 2))

      ** EXPR_OFFSET points to a NULL, so add one (+1) to get the string **
      ** and subtract one (-1) from EXPR_LENGTH for correct length **

      expr_offset = expr_offset + 1
      expr_length = expr_length - 1

      ** Extract string **
      string = substr(expr_buff, expr_offset, expr_length)

      ** dBASE does this so we must do it too **
      ** Character following character pointed to by pointer is NULL **
      IF CHR(0) = SUBSTR(string, 1, 1) .AND. LEN(SUBSTR(string,1,1)) = 1
         string = ""
      ENDIF
   ENDIF

   RETURN (string)

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson