home *** CD-ROM | disk | FTP | other *** search
/ Troubleshooting Netware Systems / CSTRIAL0196.BIN / attach / pcc / v08n03 / netwrk.exe / FAXBAT13.ZIP / FAXBATCH.PAS < prev    next >
Pascal/Delphi Source File  |  1994-05-27  |  5KB  |  206 lines

  1. {$A+,B-,D+,E-,F-,I-,L-,N-,O-,R+,S+,V-}
  2. {$M 16384,0,655360}
  3.  
  4. program faxbatch;
  5.  
  6. {
  7.   A utility to mail files to a fax gateway by Peter Summers
  8.   <U5533129@ucsvc.ucs.unimelb.edu.au>
  9.  
  10.   Uses code from a variety of sources.
  11.  
  12.   Free distributable.
  13. }
  14.  
  15. uses dos,novell;
  16.  
  17. const   delflag : boolean = false;
  18.         faxacc  : string  = '';
  19.         faxdir  : string  = '';
  20.  
  21. var     infilename  : pathstr;
  22.         outfilename : pathstr;
  23.         batfilename : pathstr;
  24.         path        : dirstr;
  25.         name        : namestr;
  26.         extn        : extstr;
  27.         version     : string;
  28.         infile      : file;
  29.         outfile     : file;
  30.         batfile     : text;
  31.         station     : integer;
  32.         sender      : string;
  33.         faxid       : string;
  34.         retcode     : integer;
  35.         number      : string;
  36.         i           : integer;
  37.         numread     : word;
  38.         block       : array[1..2048] of byte;
  39.         argument    : string;
  40.  
  41.  
  42. function nextarg:string;     {retrieves the next argument from command line}
  43.  
  44.   const param : integer = 1;         {used for parsing command line}
  45.   var   arg   : string;
  46.         i     : byte;
  47.  
  48.   begin
  49.     if param>paramcount then
  50.       nextarg:=''
  51.     else
  52.       begin
  53.         arg := paramstr(param);
  54.         for i := 1 to length(arg) do arg[i] := upcase(arg[i]);
  55.         param := param + 1;
  56.         nextarg := arg;
  57.       end;
  58.   end;
  59.  
  60.  
  61. begin { program faxbatch }
  62.  
  63.   if (paramcount = 0) or (paramstr(1) = '/?') then
  64.     begin
  65.       writeln('Simple FAX-Batching program v1.3. - Peter Summers, 25 May 94');
  66.       writeln('SYNTAX: FAXBATCH <file> [<number>] [/DEL] [/FAX <user>] [/DIR <faxdir>]');
  67.       halt(1);
  68.     end;
  69.  
  70.   infilename := nextarg;
  71.  
  72.   assign(infile,infilename);
  73.   reset(infile,1);
  74.   if IOResult<>0 then
  75.     begin
  76.       writeln('Can''t open file '+infilename+'.');
  77.       halt(2);
  78.     end;
  79.  
  80.   argument := nextarg;
  81.  
  82.   while argument<>'' do
  83.     begin
  84.       if argument = '/DEL' then
  85.         delflag := true
  86.       else if argument = '/ACC' then
  87.         faxacc := nextarg
  88.       else if argument = '/DIR' then
  89.         faxdir := nextarg+'\'
  90.       else if argument[1]='/' then
  91.         begin
  92.           writeln(argument+' is not a valid switch.');
  93.           halt(11);
  94.         end
  95.       else number := number + argument;
  96.       argument := nextarg;
  97.     end;
  98.  
  99.   if (faxdir='') and (faxacc='') then faxdir := getenv('fbdir');
  100.  
  101.   if faxdir='' then
  102.     begin
  103.       get_server_version(version);
  104.       if version='' then
  105.         begin
  106.           writeln('You MUST be logged in to a Novell server or specify a directory.');
  107.           halt(1);
  108.         end;
  109.       if faxacc='' then faxacc := getenv('fbacc');
  110.       if faxacc='' then faxacc := 'FAX';
  111.       gethexid(faxacc,faxid,retcode);
  112.       if retcode<>0 then
  113.         begin
  114.           writeln('Can''t get id for user '+faxacc+'.');
  115.           halt(3);
  116.         end;
  117.       faxdir:='SYS:MAIL\'+faxid+'\';
  118.     end;
  119.  
  120.   if number='' then
  121.     begin
  122.       write('FAX Number .. ');
  123.       readln(number);
  124.     end;
  125.  
  126.   i:=1;
  127.   while i <= length(number) do
  128.     if not (number[i] in ['0','1','2','3','4','5','6','7','8','9']) then
  129.       delete(number,i,1)
  130.     else
  131.       i:=i+1;
  132.  
  133.   if number='' then
  134.     begin
  135.       writeln('No number given, fax not sent.');
  136.       halt(10);
  137.     end;
  138.  
  139.   fsplit(infilename,path,name,extn);
  140.  
  141.   randomize;
  142.   name:='';
  143.   for i:=1 to 8 do
  144.     name:=name+chr(ord('A')+random(26));
  145.  
  146.   if extn = '.BAT' then extn := '.BA&';
  147.  
  148.   outfilename:=faxdir+name+extn;
  149.   batfilename:=faxdir+name+'.BAT';
  150.  
  151.   assign(outfile,outfilename);
  152.   rewrite(outfile,1);
  153.   if IOresult<>0 then
  154.     begin
  155.       writeln('Can''t open file '+outfilename);
  156.       halt(5);
  157.     end;
  158.  
  159.   while not eof(infile) do
  160.     begin
  161.       blockread(infile,block[1],sizeof(block),numread);
  162.       if (IOresult<>0) and not eof(infile) then
  163.         begin
  164.           writeln('Can''t read from file '+infilename);
  165.           halt(6);
  166.         end;
  167.       blockwrite(outfile,block[1],numread);
  168.       if IOresult<>0 then
  169.         begin
  170.           writeln('Can''t write to file '+outfilename);
  171.           halt(7);
  172.         end;
  173.     end;
  174.  
  175.   close(infile);
  176.   close(outfile);
  177.  
  178.   assign(batfile,batfilename);
  179.   rewrite(batfile);
  180.   if IOresult<>0 then
  181.     begin
  182.       writeln('Can''t open file '+outfilename);
  183.       halt(8);
  184.     end;
  185.  
  186.   delete(extn,1,1);
  187.  
  188.   getstation(station,retcode);
  189.   getuser(station,sender,retcode);
  190.   getserverinfo;
  191.  
  192.   writeln(batfile,'sendafax '+name+' '+extn+' '+number+' '
  193.     +serverinfo.name+'/'+sender);
  194.  
  195.   if IOresult<>0 then
  196.     begin
  197.       writeln('Can''t open file '+batfilename);
  198.       halt(9);
  199.     end;
  200.  
  201.   close(batfile);
  202.  
  203.   if delflag then erase(infile);
  204.  
  205. end.
  206.