home *** CD-ROM | disk | FTP | other *** search
/ The CIA World Factbook 1992 / k3bimage.iso / sel / 12 / 0090 / bbtotxt.pas next >
Encoding:
Pascal/Delphi Source File  |  1991-12-02  |  3.9 KB  |  117 lines

  1. program bbtotext; {convert to text file}
  2.  
  3.   (****************************************************************)
  4.   (*                                                              *)
  5.   (*                     LITTLE BLACK BOOK                        *)
  6.   (*                                                              *)
  7.   (*               Black book to Text file conversion             *)
  8.   (*                                                              *)
  9.   (*                  Copyright (C) 1986 by                       *)
  10.   (*                     MARTIN C. BEATTIE                        *)
  11.   (*                                                              *)
  12.   (****************************************************************)
  13.  
  14.   {$v-}
  15.  
  16.   TYPE
  17.     Str80 = STRING [80];
  18.     Buffer = STRING [255];
  19.     Rectype = (S, P);
  20.     Bbrectype =
  21.       RECORD
  22.         CASE Rectype OF
  23.            P: (
  24.               RecStatus  : integer;       (*  Record Status *)
  25.               LastName   : string[20];    (*  last name *)
  26.               FirstName  : string[15];    (*  first name *)
  27.               address1   : string[30];    (*  Address 1 *)
  28.               address2   : string[30];    (*  Address 2 *)
  29.               Phone      : string[14];    (*  Phone number *)
  30.               Note       : string[25]     (*  remarks 1 *)
  31.               );
  32.            S: ( Int1, Int2, Int3, NumRecs: integer);
  33.             end;
  34.  
  35.   VAR
  36.     Infile: FILE OF Bbrectype;
  37.     Outfile: Text;
  38.     Returnfile: FILE;
  39.     Infilename, Outfilename: STRING [20];
  40.     Bbrec: Bbrectype;
  41.     Lastrec, I, X, Y: Integer;
  42.     Ch: Char;
  43.     Ok: Boolean;
  44.  
  45.     (* Convert does the job *)
  46.  
  47.  
  48.   PROCEDURE Convert;
  49.     BEGIN
  50.       Writeln('Creating ', Outfilename, ' file from BLKBOOK.DAT');
  51.       Write('Working....');
  52.       Read(Infile, Bbrec); {get turbo access status record}
  53.       Lastrec := Bbrec.Numrecs;
  54.       FOR I := 1 TO Lastrec - 1 DO
  55.         BEGIN
  56.         Read(Infile, Bbrec);
  57.         WITH Bbrec DO
  58.           IF Recstatus = 0 THEN
  59.             Writeln(Outfile, Lastname, '': 20 - Length(Lastname), Firstname, '':
  60.                     15 - Length(Firstname), Address1, '': 30 - Length(Address1),
  61.                     Address2, '': 30 - Length(Address2), Phone, '': 14 - Length(Phone),
  62.                     Note, '': 25 - Length(Note));
  63.  
  64.         END;
  65.       Writeln('Done.');
  66.       Write(Outfile, Chr($1A)); {mark end of file}
  67.     END;
  68.  
  69.   BEGIN
  70.     Writeln('Type in name of text file to be created (<filename>.TXT): ');
  71.     Writeln('Maximum of 8 characters, the filetype TXT will be added.');
  72.     Write('> ');
  73.     X := Wherex;
  74.     Y := Wherey;
  75.     REPEAT
  76.       Gotoxy(X, Y);
  77.       Clreol;
  78.       Readln(Outfilename);
  79.     UNTIL Length(Outfilename) <= 8;
  80.     Outfilename := Outfilename + '.TXT';
  81.     Infilename := 'blkbook.dat';
  82.     Assign(Infile, Infilename);
  83.     Assign(Outfile, Outfilename);
  84.     {$i-}
  85.     Reset(Infile);
  86.     Ok := (Ioresult = 0);
  87.     IF Ok THEN
  88.       BEGIN
  89.       Rewrite(Outfile);
  90.       Ok := (Ioresult = 0);
  91.       IF Ok THEN
  92.         BEGIN
  93.         Convert;
  94.         Close(Infile);
  95.         END
  96.       ELSE Writeln(' Bad output file name');
  97.       Close(Outfile);
  98.       END
  99.     ELSE Writeln('BlkBook.DAT file not found');
  100.     IF Ok THEN
  101.       BEGIN
  102.       Writeln;
  103.       Writeln('You now have a Text file named ', Outfilename, '.  Each Record');
  104.       Writeln('is on a separate line 160 characters wide.  You may examine it');
  105.       Writeln('with a text editor such as WordStar (in the NonDocument mode),');
  106.       Writeln('TurboPascals editor, SideKick, or EDLIN.  The individual fields');
  107.       Writeln('are separated only by their field length and must be maintained');
  108.       Writeln('in order for it to load back into Blaque Book properly.');
  109.       END;
  110.     Writeln;
  111.     Writeln('Type "Q" to quit, any other key will return to utility menu.');
  112.     Read(Kbd, Ch);
  113.     Assign(Returnfile, 'BBUTIL.COM');
  114.     IF Upcase(Ch) <> 'Q' THEN Execute(Returnfile);
  115.   END.
  116.  
  117.