config/make.tmpl: pass -nix flag also to LDFLAGS of configure
[AROS.git] / tools / toollib / stringcb.c
blob490dea1e04547a307f196877626e9d084e92db76
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <string.h>
7 #include <errno.h>
8 #include <toollib/error.h>
9 #include <toollib/stringcb.h>
11 static int
12 StringGetCB (StringStream * ss, int dummy, CBD data)
14 int c;
16 if (ss->pos == ss->max)
18 errno = 0;
19 c = -1;
21 else
22 c = ss->string[ss->pos++];
24 if (c == '\n')
25 Str_NextLine (ss);
27 return c;
30 static int
31 StringUngetCB (StringStream * ss, int c, CBD data)
33 if (!ss->pos)
35 errno = EINVAL;
36 c = -2;
38 else if (c != -1)
40 ss->pos --;
42 if (c != ss->string[ss->pos])
44 errno = EINVAL;
45 c = -2;
48 else /* EOF */
50 if (ss->pos != ss->max)
52 errno = EINVAL;
53 c = -2;
57 return c;
60 static int
61 StringPutCB (StringStream * ss, int c, CBD data)
63 if (!ss->out)
64 ss->out = VS_New (NULL);
66 VS_AppendChar (ss->out, c);
68 return c;
71 static int
72 StringPutsCB (StringStream * ss, const char * str, CBD data)
74 if (!ss->out)
75 ss->out = VS_New (NULL);
77 VS_AppendString (ss->out, str);
79 return 1;
82 StringStream *
83 StrStr_New (const char * string)
85 StringStream * ss = new (StringStream);
87 Str_Init (&ss->stream, "string");
89 ss->stream.get = (CB) StringGetCB;
90 ss->stream.unget = (CB) StringUngetCB;
91 ss->stream.put = (CB) StringPutCB;
92 ss->stream.puts = (CB) StringPutsCB;
94 ss->string = string;
95 ss->out = NULL;
96 ss->pos = 0;
97 ss->max = strlen (string);
99 return ss;
102 void
103 StrStr_Delete (StringStream * ss)
105 if (ss->out)
106 VS_Delete (ss->out);
108 Str_Delete (&ss->stream);
110 xfree (ss);