home *** CD-ROM | disk | FTP | other *** search
- program DB_Make;
-
- { DB_Make Copyright (c) Richard F. Griffin
-
- 8 January 1990
-
- 102 Molded Stone Pl
- Warner Robins, GA 31088
-
- -------------------------------------------------------------
-
- This program creates the .PAS unit for a dBase III file.
- The resulting unit creates objects for each data field and
- the entire database. The units HLTH_UNT.PAS and HLTHDATA.PAS
- demonstrate the resulting units.
-
- The program expects two parameters: The dBase file, without
- the .DBF extension, and the name you want the resulting unit
- to have.
-
- For example, the HLTH_UNT.PAS unit was created by executing:
-
- DM_MAKE HEALTH Hlth_Unt
-
- If the second parameter is left out, the unit will take the
- the first parameter.
-
- }
-
- uses
- Crt, dos, GS_Dbase;
-
- var
- FileN : GS_dBase_DB;
- display_Name : string[12];
- In_Name : string[12];
- Outfile : text;
- i, k, os, fs : integer;
-
- function Fld_Num(inum, slen : integer) : string;
- var
- data : string[10];
- k : integer;
- begin
- str(inum:slen, data);
- for k := 1 to slen do if data[k] = ' ' then data[k] := '0';
- Fld_Num := data;
- end;
-
-
- PROCEDURE DisplayStructure;
-
- VAR
- i, k, v : Integer;
-
- BEGIN
- ClrScr;
-
- writeln(outfile,'type');
- FOR i := 1 TO FileN.NumFields DO
- BEGIN
- WITH FileN.Fields^[i] DO
- BEGIN
- write(outfile,' ',display_Name,'_FL',Fld_Num(i,3));
- write(outfile,'':10-length(display_Name),'= Object(GS_dBase_FL');
- case FieldType of
- 'C' : write(outfile,'_C)');
- 'D' : write(outfile,'_D)');
- 'N' : begin
- if FieldDec = 0 then write(outfile,'_I)')
- else write(outfile,'_R)');
- end;
- 'M' : write(outfile,'_M)');
- 'L' : write(outfile,'_L)');
- end;
- write(outfile,' {');
- for k := 1 to 11 do
- if FieldName[k] = #0 then write(outfile,' ')
- else write(outfile,FieldName[k]);
- writeln(outfile,'}');
- writeln(outfile,'':25,'constructor Init(LF, LR : pointer);');
- writeln(outfile,'':22,'end;');
- writeln(outfile);
- end;
- end;
- write(outfile,' ',display_Name,'_Objct');
- writeln(outfile,'':10-length(display_Name),'= Object(GS_dBase_DB)');
- FOR i := 1 TO FileN.NumFields DO
- BEGIN
- WITH FileN.Fields^[i] DO
- BEGIN
- write(outfile,'':25);
- for k := 1 to 11 do
- if FieldName[k] = #0 then write(outfile,' ')
- else write(outfile,FieldName[k]);
- write(outfile,' : ');
- writeln(outfile,display_Name,'_FL',Fld_Num(i,3),';');
- end;
- END; {FOR}
- writeln(outfile,'':22,'end;');
- END; { DisplayStructure }
-
- begin
- clrscr;
- if paramcount < 1 then exit;
- In_Name := ParamStr(1);
- if paramcount = 2 then Display_Name := ParamStr(2)
- else Display_Name := In_Name;
- FileN.Init(In_Name);
- FileN.Open;
- IF NOT FileN.dbfOK THEN exit;
- assign(Outfile,display_Name+'.PAS');
- rewrite(Outfile);
- writeln(outfile,'unit ',display_Name,';');
- writeln(outfile);
- writeln(outfile,'interface');
- writeln(outfile,'uses');
- writeln(outfile,' GS_dBase, GS_DB_FL;');
- writeln(outfile);
- DisplayStructure;
- writeln(outfile);
- writeln(outfile,'var');
- writeln(outfile,' ',display_Name,'_R : ',Display_Name,'_Objct;');
- writeln(outfile,' ',display_Name,'_Exit : pointer;');
- writeln(outfile);
- writeln(outfile,'implementation');
- writeln(outfile);
- writeln(outfile,'type');
- writeln(outfile,' PtrRec = record');
- writeln(outfile,' ofs, seg : word;');
- writeln(outfile,' end;');
- writeln(outfile);
- os := 1;
- fs := 1;
- FOR i := 1 TO FileN.NumFields DO
- BEGIN
- WITH FileN.Fields^[i] DO
- BEGIN
- writeln(outfile,'constructor ',display_Name,'_FL',Fld_Num(i,3),
- '.Init(LF, LR : pointer);');
- writeln(outfile,'begin');
- writeln(outfile,' OffSet := ',os,';');
- writeln(outfile,' Inc(PtrRec(LF).ofs,',(fs-1)*32,');');
- writeln(outfile,' Inc(PtrRec(LR).ofs,',os,');');
- write(outfile,' GS_dBase_FL');
- case FieldType of
- 'C' : write(outfile,'_C');
- 'D' : write(outfile,'_D');
- 'N' : begin
- if FieldDec = 0 then write(outfile,'_I')
- else write(outfile,'_R');
- end;
- 'M' : write(outfile,'_M');
- 'L' : write(outfile,'_L');
- end;
- writeln(outfile,'.Init(LF, LR);');
- if FieldType = 'M' then
- writeln(outfile,' File_ptr := @',display_Name,'_R.mFile;');
- writeln(outfile,'end;');
- writeln(outfile);
- inc(fs);
- os := os + FieldLen;
- end;
- end;
-
-
-
-
- writeln(outfile,'{$F+}');
- writeln(outfile,'procedure Exit_Proc;');
- writeln(outfile,'begin');
- writeln(outfile,' ',display_Name,'_R.Close;');
- writeln(outfile,' exitProc := ',display_Name,'_Exit;');
- writeln(outfile,'end;');
- writeln(outfile);
- writeln(outfile,'begin');
- writeln(outfile,' ',display_Name,'_Exit := exitProc;');
- writeln(outfile,' exitProc := @Exit_Proc;');
- writeln(outfile,' ',display_Name,'_R.Init(',#39,In_Name,#39,');');
- writeln(outfile,' with ',display_Name,'_R do');
- writeln(outfile,' begin');
-
- FOR i := 1 TO FileN.NumFields DO
- BEGIN
- WITH FileN.Fields^[i] DO
- BEGIN
- write(outfile,'':6);
- for k := 1 to 11 do
- if FieldName[k] <> #0 then write(outfile,FieldName[k]);
- writeln(outfile,'.Init(Fields, CurRecord);');
- end;
- END; {FOR}
- writeln(outfile,' end;');
- writeln(outfile,' ',display_Name,'_R.Close;');
- writeln(outfile,'end.');
- FileN.Close;
- close(outfile);
- end.