home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / workbench / c / echo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  1.7 KB  |  92 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: echo.c,v 1.6 1997/01/27 00:22:37 ldp Exp $
  4.     $Log: echo.c,v $
  5.     Revision 1.6  1997/01/27 00:22:37  ldp
  6.     Include proto instead of clib
  7.  
  8.     Revision 1.5  1996/09/17 16:43:00  digulla
  9.     Use general startup code
  10.  
  11.     Revision 1.4  1996/09/13 17:52:10  digulla
  12.     Use IPTR
  13.  
  14.     Revision 1.3  1996/08/13 15:34:04  digulla
  15.     #include <exec/execbase.h> was missing
  16.  
  17.     Revision 1.2  1996/08/01 17:40:44  digulla
  18.     Added standard header for all files
  19.  
  20.     Desc:
  21.     Lang:
  22. */
  23. #include <exec/execbase.h>
  24. #include <exec/libraries.h>
  25. #include <proto/exec.h>
  26. #include <dos/dos.h>
  27. #include <proto/dos.h>
  28.  
  29. int main (int argc, char ** argv)
  30. {
  31.     IPTR args[5]={ 0, 0, 0, 0, 0 };
  32.     struct RDArgs *rda;
  33.     STRPTR *a, b;
  34.     ULONG l, max=~0ul;
  35.     BPTR out=Output();
  36.     LONG error=0;
  37. #define ERROR(a) { error=a; goto end; }
  38.  
  39.     rda=ReadArgs("/M,NOLINE/S,FIRST/K/N,LEN/K/N,TO/K",args,NULL);
  40.     if(rda==NULL)
  41.     ERROR(RETURN_FAIL);
  42.  
  43.     if(args[3])
  44.     max=*(ULONG *)args[3];
  45.  
  46.     if(args[4])
  47.     {
  48.     out=Open((STRPTR)args[4],MODE_NEWFILE);
  49.     if(!out)
  50.         ERROR(RETURN_ERROR);
  51.     }
  52.  
  53.     a=(STRPTR *)args[0];
  54.     while(*a!=NULL)
  55.     {
  56.     b=*a;
  57.     while(*b++)
  58.         ;
  59.     l=b-*a-1;
  60.     b=*a;
  61.     if(args[2]&&*(ULONG *)args[2])
  62.     {
  63.         if(*(ULONG *)args[2]-1<l)
  64.         b+=*(ULONG *)args[2]-1;
  65.         else
  66.         b+=l;
  67.     }else
  68.         if(l>max)
  69.         b+=l-max;
  70.     l=max;
  71.     while(l--&&*b)
  72.         if(FPutC(out,*b++)<0)
  73.         ERROR(RETURN_ERROR);
  74.     a++;
  75.     if(*a)
  76.         if(FPutC(out,' ')<0)
  77.         ERROR(RETURN_ERROR);
  78.     }
  79.     if(!args[1])
  80.     if(FPutC(out,'\n')<0)
  81.         ERROR(RETURN_ERROR);
  82.     if(!Flush(out))
  83.     ERROR(RETURN_ERROR);
  84. end:
  85.     if(args[4])
  86.     Close(out);
  87.     FreeArgs(rda);
  88.     if(error)
  89.     PrintFault(IoErr(),"Echo");
  90.     return error;
  91. }
  92.