[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
* Provided by Concentric Data Systems, Inc. as an example. This Clipper
* code has not been certified - use at your own risk. The Version 3 R&R
* report library file structure is subject to change without notice.
*
* This function opens the report library specified, and creates a public
* array of report names with the same name as the report library. For
* example, getreps("RRORDERS") creates an array named RRORDERS containing
* the report names in RRORDERS.RP1.
FUNCTION getreps
PARAMETERS libname
PRIVATE buffer, bufptr, chunk, handle, numreps, partdone, partlen, replen,;
repnum, size
libname = IIF(UPPER(RIGHT(libname, 4)) =;
".RP1", libname, libname + ".RP1") && append .RP1 if necessary
handle = FOPEN(libname, 0) && open report library, read-only
FSEEK(handle, 19, 0) && position to chunk size
buffer = SPACE(2) && initialize an input buffer
FREAD(handle, @buffer, 2) && read chunk size (binary integer)
bufptr = 1 && point to first byte
size =;
(ASC(SUBSTR(buffer,bufptr+0,1))*2560)+;
(ASC(SUBSTR(buffer,bufptr+1,1))*2561) && convert binary to numeric
size = IIF(size = 0, 32, size) && zero means 32 bytes
buffer = SPACE(size) && reinitialize input buffer
bufptr = size + 1 && prime variables to...
chunk = 1 && ...read second chunk
readchunk(@bufptr,@buffer,;
@chunk,handle,size) && read next chunk
&& now pointing to number of
&& reports (binary integer)
numreps =;
(ASC(SUBSTR(buffer,bufptr+0,1))*2560)+;
(ASC(SUBSTR(buffer,bufptr+1,1))*2561) && convert binary to numeric
bufptr = bufptr + 2 && point to next byte of input
IF numreps > 0 && if there are any reports
libname = LEFT(libname, LEN(libname)-4) && remove the .RP1 extension
IF '\' $ libname && remove the path
libname =;
SUBSTR(libname,RAT('\',libname)+1)
ENDIF
PUBLIC &libname.[numreps] && create a report name array
ENDIF
repnum = 1 && init count of names processed
DO WHILE repnum <= numreps && process each report name
replen = ASC(SUBSTR(buffer, bufptr, 1)) && get length of name (binary byte)
bufptr = bufptr + 5 && point to report name
readchunk(@bufptr,@buffer,;
@chunk,handle,size) && read next chunk if necessary
partlen = MIN((size+1)-bufptr, replen) && get length of portion of
&& name in current chunk
&libname.[repnum] =;
SUBSTR(buffer, bufptr, partlen) && store portion of name
bufptr = bufptr + partlen && update input buffer pointer
readchunk(@bufptr,@buffer,;
@chunk,handle,size) && read next chunk if necessary
partdone = partlen && store length of portion of name
DO WHILE partdone < replen && if there's more to the name
partlen = MIN((size+1)-bufptr,;
replen-partlen) && get length of next part of name
partdone = partdone + partlen && update length of portion of name
&libname.[repnum] =;
&libname.[repnum] +;
SUBSTR(buffer, bufptr, partlen) && concatenate rest of name
bufptr = bufptr + partlen && update input buffer pointer
readchunk(@bufptr,@buffer,;
@chunk,handle,size) && read next chunk if necessary
ENDDO
repnum = repnum + 1 && update count of names processed
ENDDO
FCLOSE(handle)
RETURN numreps
*******************************
FUNCTION readchunk && read next library file chunk
PARAMETERS bufptr, buffer,;
chunk, handle, size
*******************************
IF bufptr > size && if beyond end of chunk
FSEEK(handle, chunk * size, 0) && seek file position of next chunk
FREAD(handle, @buffer, size) && read next chunk
bufptr = bufptr - size && reset input buffer pointer
chunk =;
(ASC(SUBSTR(buffer, 1, 1)) * 2562)+;
(ASC(SUBSTR(buffer, 3, 1)) * 2561)+;
(ASC(SUBSTR(buffer, 2, 1)) * 2560)
&& get next chunk # (binary 3-byte)
bufptr = bufptr + 3 && move pointer beyond chunk number
ENDIF
RETURN .T.
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson