2 Copyright © 1995-2007, 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 separated by whitespace or '=' just like on
32 the commandline. The separator is unread and the output 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 NUL
39 input - A ready to use CSource structure or NULL which means
40 "read from the input stream".
43 One of ITEM_UNQUOTED - Normal word read.
44 ITEM_QUOTED - Quoted string read.
45 ITEM_NOTHING - End of line found. Nothing read.
46 ITEM_EQUAL - '=' read. Buffer is empty.
47 ITEM_ERROR - An error happened. IoErr() gives additional
48 information in that case.
51 This function handles conversion of '**', '*"', etc inside quotes.
61 *****************************************************************************/
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');
93 if(!c
||c
=='\n'||c
==EOF
||c
==';')
99 /* Found '='. Return it. */
103 /* Quoted item found. Convert Contents. */
109 *result
=ERROR_BUFFER_OVERFLOW
;
114 /* Convert ** to *, *" to ", *n to \n and *e to 0x1b. */
118 /* Check for premature end of line. */
119 if(!c
||c
=='\n'||c
==EOF
)
124 *result
=ERROR_UNMATCHED_QUOTES
;
126 }else if(c
=='n'||c
=='N')
128 else if(c
=='e'||c
=='E')
130 }else if(!c
||c
=='\n'||c
==EOF
)
135 *result
=ERROR_UNMATCHED_QUOTES
;
139 /* " ends the item. */
147 /* Unquoted item. Store first character. */
151 *result
=ERROR_BUFFER_OVERFLOW
;
156 /* Read up to the next terminator. */
162 *result
=ERROR_BUFFER_OVERFLOW
;
167 /* Check for terminator */
168 if(!c
||c
==' '||c
=='\t'||c
=='\n'||c
=='='||c
==EOF
)
173 return ITEM_UNQUOTED
;