[comp.binaries.ibm.pc.d] UNIX Like Split Utility

shehzad@babel.SanDiego.NCR.COM (Mevawalla Shezad) (08/04/88)

Recently I posted the binaries for a UNIX like split utility. Since I wrote 
this program for my own use, I did not take the trouble to make it usable
with binary files. If there is interest, I can post the source (Turbo Pascal
4.0) or make the necessary modifications (shouldn't be too much of a problem)
and post the binaries again, depending on what people want. I will only do
this if there is sufficient interest.

irv@happym.UUCP (Irving Wolfe) (08/09/88)

Please post the source.  A few people don't have Turbo Pascal, but EVERYONE
has a friend who has it.  The same is true for programs written in C.

Some people might like binaries posted too for their convenience, but others
cannot (due to company policy) or will not (due to their own) allow binaries
into their systems, except commercial products from major vendors.

The reason binaries became popular is not that the world prefers them, but 
that some programmers are either too ashamed of their code to let anyone else 
see it, or have the silly idea that it will be commercially valuable someday.  

-- 
   Irving Wolfe      irv@happym.UUCP              Happy Man Corp, 119 Aloha St
   206/282-9598      tikal!camco!happym!irv            Seattle, WA  98109-3799
   SOLID VALUE, the only newsletter for Benjamin Graham's intelligent investor
			(sample on request)

shehzad@babel.SanDiego.NCR.COM (Mevawalla Shezad) (08/10/88)

In article <486@happym.UUCP> irv@happym.UUCP (Irving Wolfe) writes:
>Please post the source.  A few people don't have Turbo Pascal, but EVERYONE


OK. Here is the source for the Split utility. Sorry for the lack of comments,
but I wrote this program for my own use and therefore didn't bother to put them
in. However the code is pretty straight forward and people should have no
problems customizing it to their liking.

Even though this program is written for TP 4.0 I don't think it will be too
difficult to port to another compiler.

Right now the program doesn't work with binary files and doesn't accept 
command line parameters. Something you might want to add (pretty trivial).

------  Cut Here  -----

Program Split (input,output);

uses crt;

Type

   Instring=Packed Array [1..30] of char;
   TempType=Packed Array [1..3] of char;
Var
   Num_Of_Lines:Integer;
   Filename:Instring;
   File1:Text;
   File2:Text;

  Procedure Get_File_Name(var error:Boolean;var TempFile:TempType;
                          var Loop:Integer; var Done:Integer);
  Var
  	I:Integer;
  Begin
       If (Loop=1) and (Done=1) then
       Begin
            TempFile[1]:='X';
            TempFile[2]:='A';
            TempFile[3]:='A';
       End
       else if (Loop=27) and (Done=676) then
       Begin
       		Error:=true;
                For i:=1 to 25 do write(' ');
       		Writeln('ERROR TOO MANY FILES');
       	End
       else if Loop=27 then
       Begin
       		I:=ord(TempFile[2]);
       		I:=I+1;
       		TempFile[2]:=chr(I);
       		TempFile[3]:='A';
                Loop:=1;
                Done:=Done+1;
  	End
  	else Begin
  		I:=ord(TempFile[3]);
  		I:=I+1;
  		TempFile[3]:=Chr(I);
                Done:=Done+1;
  	     end;
  end;
  Procedure Readin(var Filename:Instring;Var Num_Of_lines:Integer);
  Var
  	I,J:Integer;
  	Temp:Integer;
  	X,Y,Loop:Integer;
  	TempFile:TempType;
  	Ch:Char;
        Done:Integer;
  	Finish,Bad,Error:Boolean;
  Begin
        TextBackGround(4);
        ClrScr;
        Writeln;Writeln;
        Writeln;Writeln;
        Finish:=False;
  	I:=1;
  	Loop:=0;
        Done:=1;
  	Error:=False;
  	Bad:=True;
        X:=WhereX;
        Y:=Wherey;
        {$I-}
        While Bad do
        Begin
        	Write('Enter Number of Lines : ');
  		Read(Num_Of_Lines);
                If IOResult<>0 then
		Begin
		     GotoXY(X,Y);
		     Write('                                         ');
                     Write('                                         ');
		     GotoXY(X,Y);
		End
		Else Bad:=False;
	End;
        {$I+}
  	Temp:=Num_Of_Lines;
        Bad:=True;
        X:=WhereX;
        Y:=WhereY;
        {$I-}
        While Bad do
        Begin
              Readln;
              Write('Enter Filename or <CR> to exit : ');
  	      While not(Eoln) and (not(I>30)) do
  	      Begin
  		   Read(Filename[I]);
                   I:=I+1;
  	      End;
              Writeln;
  	      For J:=30 Downto I do Filename[J]:=' ';
  	      If I=1 then Error:=True
  	      Else Begin
  	      		Assign(File1,Filename);
  	      		Reset(File1);
  	      	   End;
              If IOResult <> 0 then
              Begin
                    GotoXY(X,Y);
                    Write('File not found !!                       ');
                    Write('                                        ');
                    Delay(1000);
                    GotoXY(X,Y);
                    I:=1;
              End
              Else Bad:=False;
        End;
        {$I+}
      If not(Error) then
      Begin
        Repeat
        Loop:=Loop+1;
        Get_File_Name(Error,TempFile,Loop,Done);
        If not(Error) then
        Begin
        Assign(File2,TempFile);
        Rewrite(File2);
  	While not(Finish) and (not(Temp=0)) do
  	Begin
  	   While not(eoln(File1)) do
  	   Begin
  		Read(File1,Ch);
  		Write(File2,Ch)
  	   End;
  	   Readln(File1);
  	   Writeln(File2);
           If Eof(File1) then finish:=true;
  	   Temp:=Temp-1;
  	 End;
         Close(File2);
         Temp:=Num_Of_Lines;
         End
         else Finish:=True;
  	 Until Finish;
         Close(File1);
  End;
  End;


  Begin  {MAIN}
  Readin(Filename,Num_Of_Lines);
  HighVideo;
  Writeln;Writeln;
  Write('                  *************  Split is done  *************');
  LowVideo;
  End.   {MAIN}