home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / c / echo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  1.6 KB  |  89 lines

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