New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / workbench / c / shellcommands / Echo.c
blob5f1e3bb30183831ede3aeb918d7d46af89da58b8
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang:
7 */
9 /******************************************************************************
11 NAME
13 Echo [<string>] [NOLINE] [FIRST <n>] [LEN <n>] [TO <filename>]
15 SYNOPSIS
17 STRING/M,NOLINE/S,FIRST/K/N,LEN/K/N,TO/K
19 LOCATION
21 Workbench:C
23 FUNCTION
25 Displays string.
27 INPUTS
29 STRING -- the strings to display
30 NOLINE -- no newline at end of string
31 FIRST -- first displayed character
32 LEN -- number of characters to display
33 TO -- file or device to output to
35 RESULT
37 NOTES
39 EXAMPLE
41 BUGS
43 SEE ALSO
45 INTERNALS
47 HISTORY
49 ******************************************************************************/
51 #define DEBUG 0
53 #include <exec/execbase.h>
54 #include <exec/libraries.h>
55 #include <proto/exec.h>
56 #include <dos/dos.h>
57 #include <proto/dos.h>
58 #include <string.h>
59 #include <aros/shcommands.h>
62 AROS_SH5(Echo, 41.1,
63 AROS_SHA(STRPTR *, , , /M, NULL),
64 AROS_SHA(BOOL, , NOLINE, /S, FALSE),
65 AROS_SHA(ULONG *, , FIRST, /K/N, NULL),
66 AROS_SHA(ULONG *, , LEN, /K/N, NULL),
67 AROS_SHA(STRPTR, , TO, /K, NULL))
69 AROS_SHCOMMAND_INIT
71 STRPTR *a, b;
72 ULONG l, max=~0ul;
73 BPTR out=Output();
74 LONG error=0;
76 #define ERROR(a) { error=a; goto end; }
79 if (SHArg(LEN))
81 max = *SHArg(LEN);
84 if (SHArg(TO))
86 out = Open(SHArg(TO),MODE_NEWFILE);
88 if (!out)
90 ERROR(RETURN_ERROR);
94 a = SHArg( );
96 if (a) while (*a != NULL)
98 b = *a;
100 while (*b++);
102 l = b - *a - 1;
103 b = *a;
105 if (SHArg(FIRST) && *SHArg(FIRST))
107 if (*SHArg(FIRST) - 1 < l)
109 b += *SHArg(FIRST)-1;
111 else
113 b += l;
116 else if(l > max)
118 b += l - max;
121 l = max;
123 while (l-- && *b)
125 if (FPutC(out, *b++) < 0)
127 ERROR(RETURN_ERROR);
131 a++;
133 if(*a)
135 if (FPutC(out,' ') < 0)
137 ERROR(RETURN_ERROR);
142 if (!SHArg(NOLINE))
144 if (FPutC(out, '\n') < 0)
146 ERROR(RETURN_ERROR);
150 if (!Flush(out))
152 ERROR(RETURN_ERROR);
155 end:
156 if (SHArg(TO) && out)
158 Close(out);
161 return error;
163 AROS_SHCOMMAND_EXIT