2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
8 #include <proto/exec.h>
9 #include <dos/rdargs.h>
10 #include <dos/dosasl.h>
11 #include <dos/dosextens.h>
12 #include "dos_intern.h"
14 /*****************************************************************************
17 #include <proto/dos.h>
19 AROS_LH3(LONG
, ReadItem
,
22 AROS_LHA(STRPTR
, buffer
, D1
),
23 AROS_LHA(LONG
, maxchars
, D2
),
24 AROS_LHA(struct CSource
*, input
, D3
),
27 struct DosLibrary
*, DOSBase
, 135, Dos
)
30 Read an item from a given character source. Items are words
31 or quoted strings seperated by whitespace or '=' just like on
32 the commandline. The seperator is unread and the read string
33 is terminated by a NUL character.
36 buffer - Buffer to be filled.
37 maxchars - Size of the buffer. Must be at least 1 (for the terminator).
38 input - A ready to use CSource structure or NULL which means
39 "read from the input stream".
42 One of ITEM_UNQUOTED - Normal word read.
43 ITEM_QUOTED - Quoted string read.
44 ITEM_NOTHING - End of line found. Nothing read.
45 ITEM_EQUAL - '=' read. Buffer is empty.
46 ITEM_ERROR - An error happened. IoErr() gives additional
47 information in that case.
50 This function handles conversion of '**', '*"', etc inside quotes.
60 *****************************************************************************/
63 AROS_LIBBASE_EXT_DECL(struct DosLibrary
*,DOSBase
)
65 /* Macro to get a character from the input source */
69 if(input->CS_CurChr>=input->CS_Length) \
72 c=input->CS_Buffer[input->CS_CurChr++]; \
80 /* Macro to push the character back */
81 #define UNGET() {if(input!=NULL) input->CS_CurChr--; else UnGetC(Input(),-1);}
85 LONG
*result
=&((struct Process
*)FindTask(NULL
))->pr_Result2
;
87 /* Skip leading whitespace characters */
91 }while(c
==' '||c
=='\t'||c
=='\n');
93 if(!c
||c
=='\n'||c
==EOF
)
96 End of line found. Note that unlike the Amiga DOS original
97 this funtion doesn't know about ';' comments. Comments are
98 the shell's job, IMO. I don't need them here.
106 /* Found '='. Return it. */
110 /* Quoted item found. Convert Contents. */
116 *result
=ERROR_BUFFER_OVERFLOW
;
121 /* Convert ** to *, *" to ", *n to \n and *e to 0x1b. */
125 /* Check for premature end of line. */
126 if(!c
||c
=='\n'||c
==EOF
)
131 *result
=ERROR_UNMATCHED_QUOTES
;
133 }else if(c
=='n'||c
=='N')
135 else if(c
=='e'||c
=='E')
137 }else if(!c
||c
=='\n'||c
==EOF
)
142 *result
=ERROR_UNMATCHED_QUOTES
;
146 /* " ends the item. */
154 /* Unquoted item. Store first character. */
158 *result
=ERROR_BUFFER_OVERFLOW
;
163 /* Read upto the next terminator. */
169 *result
=ERROR_BUFFER_OVERFLOW
;
174 /* Check for terminator */
175 if(!c
||c
==' '||c
=='\t'||c
=='\n'||c
=='='||c
==EOF
)
180 return ITEM_UNQUOTED
;