home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 294.lha / TurboFile / dbase.def next >
Text File  |  1989-10-09  |  4KB  |  133 lines

  1. DEFINITION MODULE dBASE;
  2.  
  3.  
  4. (*
  5.  
  6.  
  7.      Written by Dexter (Chip) Orange  July, 1987.
  8.  
  9.  
  10.      Copyright by Dexter (Chip) Orange 1987, 1989.
  11. All rights reserved.
  12.  
  13.  
  14.  
  15.      This module is designed to work in conjunction with the RandomIO module
  16. of the TurboFile system to give you easy access to dBASE formatted
  17. databases.
  18.      Note that since the dBASE format came from an 8088 environment, it
  19. stores its binary  numbers in a reversed way from the 68000, and thus the
  20. need for the "Backward" conversion procedures below.
  21.  
  22.                    Version 1.0  October, 1989.
  23. Converted from TDI to M2Sprint.
  24.  
  25.  
  26. *)
  27.  
  28. FROM SYSTEM IMPORT
  29.   BYTE;
  30. FROM RandomIO IMPORT
  31.   RandomFile, RandomFileMode;
  32.  
  33.  
  34. CONST
  35.  
  36. (* the MemoFileIndicator field should be equal to one of these values *)
  37.   NoMemoFile = 3;
  38.   YesMemoFile = 131;
  39.  
  40.  
  41.   MaxFields = 128;
  42.  
  43. TYPE
  44.   BackwardCard = ARRAY [1..2] OF BYTE;
  45.   BackwardLongCard = ARRAY [1..4] OF BYTE;
  46.  
  47.  
  48.   DataBaseInfoRec = RECORD
  49.     MemoFileIndicator: BYTE;
  50.  
  51. (* the last modified date  *)
  52.     Y: BYTE;
  53.     M: BYTE;
  54.     D: BYTE;
  55.     RecordCount: BackwardLongCard;
  56.     FileHeaderSize: BackwardCard;
  57.     RecordLength: BackwardCard;
  58. (* includes an extra byte for a "deleted" indicator *)
  59.     Reserved: ARRAY [1..20] OF BYTE;
  60.   END;
  61.  
  62.   FieldDescriptorRec = RECORD
  63.     FieldName: ARRAY [1..10] OF CHAR;
  64.     Pad: BYTE;                          (* SHOULD ALWAYS BE SET TO ZERO *)
  65.     FieldType: CHAR;
  66. (* Valid values are "L" for logical, "N" for numeric, "C" for character, "D"
  67. for date, or "M" for memo. *)
  68.     Reserved: ARRAY [1..4] OF BYTE;
  69.     FieldLength: BYTE;
  70.     FieldDecimals: BYTE;
  71.     Reserved2: ARRAY [1..14] OF BYTE;
  72.   END;
  73.  
  74. (* THE FOLLOWING DESCRIPTION OF A DBASE HEADER IS NOT COMPLETELY ACCURATE
  75. SINCE THE NUMBER OF FIELDESCRIPTOR RECORDS IS VARIABLE *)
  76.   dBASEHeaderRec = RECORD
  77.     Info: DataBaseInfoRec;
  78.     FieldList: ARRAY [1..MaxFields] OF FieldDescriptorRec;
  79.     EndOfHeader: BYTE;                  (* SHOULD ALWAYS BE SET TO 13 *)
  80.   END;
  81.  
  82. (* format of dBASE "date" fields *)
  83.   YYYYMMDD = RECORD
  84.     YYYY: ARRAY [1..4] OF CHAR;
  85.     MM: ARRAY [1..2] OF CHAR;
  86.     DD: ARRAY [1..2] OF CHAR;
  87.   END;
  88.  
  89.  
  90. PROCEDURE Card(BC: BackwardCard): CARDINAL;
  91. (* TRanSLATE A BACKWARD (LEAST SIGNIFICANT BYTE FIRST) CARDINAL INTO A CARDINAL
  92.  *)
  93.  
  94. PROCEDURE LCard(BLC: BackwardLongCard): LONGCARD;
  95. (* TRanSLATE A BACKWARD LONGCARD INTO A LONGCARD *)
  96.  
  97.  
  98. TYPE
  99.   DataRecordPtr = POINTER TO ARRAY [0..32766] OF CHAR;
  100.  
  101.  
  102. VAR
  103.   dBASEErrorMessage : ARRAY [0..80] OF CHAR;
  104. (* contains the text of an error message if an error occurs *)
  105.  
  106.  
  107.  
  108.  
  109. PROCEDURE Use(FileName: ARRAY OF CHAR; VAR Hdr: dBASEHeaderRec; VAR F:
  110. RandomFile; Mode: RandomFileMode; VAR NumFields: CARDINAL; VAR RecLength:
  111. CARDINAL; BufferSize: LONGCARD; VAR DRPtr: DataRecordPtr) : BOOLEAN;
  112. (*
  113.      Attempt to open the file specified by FileName with the RandomIO
  114. module, and then read in a dBASE header record into dBASEHeaderRec.  If the
  115. header is read successfully, the parameters of the Random file are reset to
  116. reflect the complete header size, and to set the record length properly.
  117. You may then use RandomIO routines to read/write records in the database.
  118. IF DRPtr is NIL, a record buffer of the appropriate size will automatically
  119. be allocated for  you and DRPtr will point to it.  Remember that element 0
  120. of this buffer will always be the byte which indicates whether the record is
  121. deleted ("*") or not (" ").
  122.      If a random file mode of NewFile or NewFileWriteOnly is specified,
  123. instead of reading the header information, this routine will create the
  124. specified file and write out the information contained in dBASEHeaderRec as
  125. an empty dBASE file.
  126.      This routine will automatically use a file extension of '.dbf' if one
  127. is not specified in the file name.
  128.  
  129. *)
  130.  
  131.  
  132. END dBASE.
  133.