home *** CD-ROM | disk | FTP | other *** search
/ Current Shareware 1994 January / SHAR194.ISO / modem / ter110.zip / TER110.EXE / PASCAL._XE / MAKEBBS.PAS < prev    next >
Pascal/Delphi Source File  |  1993-06-07  |  6KB  |  213 lines

  1. Program FilesBBSmaker;
  2.  
  3. { This utility will search all the filelists specified in MAKEBBS.CFG    }
  4. { for decriptions and create a FILES.BBS, usefull if you have a large    }
  5. { download directory and you don't know the descriptions for the files   }
  6. { Then this program will do all the work for you. 1993 by Bo Bendtsen    }
  7. { Totally freeware, make any modifications you like, just remember to    }
  8. { give some thanx or credits to me.                                      }
  9.  
  10. Uses Crt,Dos;
  11.  
  12. Var
  13.   I,Out      : Text;
  14.   Buf        : Array[1..40960] of byte;       { For reading textfiles faster }
  15.   Info       : SearchRec;
  16.   Name       : Array[1..1000] of String[12];  { Max 1000 filenames }
  17.   L,X,Y,left : Word;
  18.   Stop       : Boolean;
  19.   C          : Longint;
  20.   S,UPS      : String;
  21.   StartPos,p : Byte;
  22.   Filelist   : Array[1..20] of Record
  23.                                F        : String[60];
  24.                                StartPos : Byte;
  25.                              End;
  26.   Lister     : Byte;  { how many filelists }
  27.  
  28. Function GrabWord(S: String; B: Byte) : String;
  29. Var st,e:Byte;
  30.     return : String[80];
  31. Begin
  32.   Return:='';
  33.   st:=1;e:=1;
  34.   While B>0 Do
  35.   Begin
  36.     While (S[st]=' ') or (S[st]=#9) Do Inc(st);  { #9 er TAB }
  37.     e:=st;
  38.     While (S[e]<>' ') And (e<=Length(s)) Do Inc(e);
  39.     Return:=Copy(S,st,e-st);
  40.     st:=e;
  41.     Dec(B);
  42.   End;
  43.   GrabWord:=Return;
  44. End;
  45.  
  46. Function StrToInt(S: String) : LongInt;
  47. Var
  48.   Kode : Integer;
  49.   i    : LongInt;
  50.   b    : Byte;
  51. Begin
  52.   b:=Length(s);
  53.   While b>0 Do
  54.   Begin
  55.     If s[b] in [#0..#255]-['0'..'9'] Then Delete(s,b,1);
  56.     Dec(b);
  57.   End;
  58.   If Length(S) = 0 Then StrToInt := 0 Else Begin
  59.     Val(S,i,Kode);
  60.     If Kode = 0 Then StrToInt := i Else StrToInt := 0;
  61.   End;
  62. End;
  63.  
  64. Function StUpcase(s:string):string;
  65. Var i :byte;
  66. Begin
  67.   for i := 1 to Length(s) do s[i] := UpCase(s[i]);
  68.   StUpcase:=s;
  69. End;
  70.  
  71. Function BlankAfter(S : String; Len : Byte): String;
  72. var
  73.   o : string;
  74.   SLen : Byte absolute S;
  75. Begin
  76.   If Length(S) >= Len then BlankAfter := S
  77.   Else begin
  78.     o[0] := Chr(Len);
  79.     Move(S[1], o[1], SLen);
  80.     if SLen < 255 then FillChar(o[Succ(SLen)], Len-SLen, ' ');
  81.     BlankAfter := o;
  82.   End;
  83. End;
  84.  
  85. Begin
  86.   TextAttr:=7; ClrScr; TextAttr:=16*7;
  87.   WriteLn('╒═════════════════════════════════════════════════════════════════════════════╕');
  88.   WriteLn('│     Filelist description searcher 1.00, made by Bo Bendtsen +45-42643827    │');
  89.   WriteLn('╘═════════════════════════════════════════════════════════════════════════════╛'#10);
  90.   TextAttr:=7;
  91.  
  92.   If paramcount=0 Then
  93.   Begin
  94.     WriteLn('This program will read all files specified in a directory and search the');
  95.     WriteLn('for descriptions in the filelists specified in MAKEBBS.CFG');
  96.     WriteLn(#10'Syntax: MAKEBBS path+wildcard');
  97.     WriteLn(   '        MAKEBBS C:\TERMINAT\DOWNLOAD\*.*');
  98.     WriteLn(   '        MAKEBBS C:\TERMINAT\DOWNLOAD\*.GIF');
  99.     Halt;
  100.   End;
  101.  
  102.   Assign(I,Copy(ParamStr(0),1,Length(ParamStr(0))-3)+'CFG');
  103.   {$I-} Reset(I); {$I+}
  104.  
  105.   If IOResult<>0 Then
  106.   Begin
  107.     WriteLn('Unable to open config file');
  108.     Halt;
  109.   End;
  110.   Lister:=0; Fillchar(Filelist,sizeof(filelist),0);
  111.  
  112.   While Not Eof(i) And (Lister<20) Do
  113.   Begin
  114.     ReadLn(I,S);
  115.     If (S<>'') And Not (S[1] in [';','%']) Then
  116.     Begin
  117.       Inc(Lister);
  118.       Filelist[Lister].F:=GrabWord(S,1);
  119.       Filelist[Lister].StartPos:=StrToInt(GrabWord(S,2));
  120.       If Filelist[Lister].StartPos=0 Then Filelist[Lister].StartPos:=1;
  121.     End;
  122.   End;
  123.  
  124.   L:=0; Fillchar(Name,sizeof(name),0);
  125.   WriteLn('Reading files '+Paramstr(1));
  126.   FindFirst(Paramstr(1),Archive,Info);
  127.   While (DosError=0) And (L<1000) Do
  128.   Begin
  129.     If l mod 25=0 Then Write(#13,l);
  130.     Inc(L);
  131.     Name[L]:=Info.Name;
  132.     If Pos('.',Name[L])=0 Then Name[L]:=Name[L]+'.';
  133.     FindNext(Info);
  134.   End;
  135.   Left:=L;
  136.  
  137.   If L=0 Then
  138.   Begin
  139.     WriteLn('No files to find');
  140.     Halt;
  141.   End;
  142.  
  143.   Assign(Out,'FILES.BBS');
  144.   {$I-} Append(Out); {$I+}
  145.   If IOResult<>0 Then
  146.   Begin
  147.     {$I-} Rewrite(Out); {$I+}
  148.     If IOResult<>0 Then
  149.     Begin
  150.       WriteLn('Unable to write to FILES.BBS');
  151.       Halt;
  152.     End;
  153.     WriteLn(#13#10'Creating FILES.BBS');
  154.   End
  155.   Else WriteLn(#13#10'Appending to FILES.BBS');
  156.  
  157.   For y:=1 to Lister Do
  158.   Begin
  159.  
  160.     WriteLn(FileList[y].F);
  161.     Assign(I,FileList[y].F);
  162.     SetTextBuf(I,Buf);
  163.     {$I-} Reset(I); {$I+}
  164.     If IOResult<>0 Then WriteLn('Unable to open input file')
  165.     Else Begin
  166.       WriteLn(Out);
  167.       WriteLn(Out,' - MakeBBS : '+FileList[y].F);
  168.       WriteLn(Out);
  169.  
  170.       StartPos:=Filelist[y].StartPos;
  171.  
  172.       Stop:=False; C:=0;
  173.       While Not Eof(I) And Not Stop And (Left>0) Do
  174.       Begin
  175.         Inc(C);
  176.         If C Mod 100=0 Then
  177.         Begin
  178.           Stop:=KeyPressed;
  179.           Write(#13,'Lines: ',C,', missing ',Left,'      ');
  180.         End;
  181.         ReadLn(I,S);
  182.         UPS:=StUpcase(S);
  183.         For x:=1 To L Do
  184.         Begin
  185.           If Pos(Name[x],UPS)=StartPos Then
  186.           Begin
  187.             Dec(Left);
  188.             WriteLn(Out,S);
  189.             Name[x]:='';
  190.           End
  191.           Else Begin
  192.             p:=Pos('.',Name[x]);
  193.             If Pos(Copy(Name[x],1,p-1),UPS)=StartPos Then
  194.             Begin
  195.               Dec(Left);
  196.               If Name[x][Length(Name[x])]='.' Then Name[x][0]:=Chr(Ord(Name[x][0])-1);
  197.               WriteLn(Out,BlankAfter(Name[x],12)+Copy(S,13,255));
  198.               Name[x]:='';
  199.             End
  200.           End;
  201.         End;
  202.       End;
  203.  
  204.       WriteLn(#13#10'Lines processed: ',C);
  205.  
  206.       Close(I);
  207.     End;
  208.  
  209.   End;
  210.  
  211.   Close(Out);
  212. End.
  213.