Deleted Added
full compact
buf.c (228072) buf.c (250125)
1/* flex - tool to generate fast lexical analyzers */
2
3/* Copyright (c) 1990 The Regents of the University of California. */
4/* All rights reserved. */
5
6/* This code is derived from software contributed to Berkeley by */
7/* Vern Paxson. */
8

--- 60 unchanged lines hidden (view full) ---

69
70/* Append a "%s" formatted string to a string buffer */
71struct Buf *buf_prints (struct Buf *buf, const char *fmt, const char *s)
72{
73 char *t;
74 size_t tsz;
75
76 t = flex_alloc (tsz = strlen (fmt) + strlen (s) + 1);
1/* flex - tool to generate fast lexical analyzers */
2
3/* Copyright (c) 1990 The Regents of the University of California. */
4/* All rights reserved. */
5
6/* This code is derived from software contributed to Berkeley by */
7/* Vern Paxson. */
8

--- 60 unchanged lines hidden (view full) ---

69
70/* Append a "%s" formatted string to a string buffer */
71struct Buf *buf_prints (struct Buf *buf, const char *fmt, const char *s)
72{
73 char *t;
74 size_t tsz;
75
76 t = flex_alloc (tsz = strlen (fmt) + strlen (s) + 1);
77 if (!t)
78 flexfatal (_("Allocation of buffer to print string failed"));
77 snprintf (t, tsz, fmt, s);
78 buf = buf_strappend (buf, t);
79 flex_free (t);
80 return buf;
81}
82
83/** Append a line directive to the string buffer.
84 * @param buf A string buffer.
85 * @param filename file name
86 * @param lineno line number
87 * @return buf
88 */
89struct Buf *buf_linedir (struct Buf *buf, const char* filename, int lineno)
90{
79 snprintf (t, tsz, fmt, s);
80 buf = buf_strappend (buf, t);
81 flex_free (t);
82 return buf;
83}
84
85/** Append a line directive to the string buffer.
86 * @param buf A string buffer.
87 * @param filename file name
88 * @param lineno line number
89 * @return buf
90 */
91struct Buf *buf_linedir (struct Buf *buf, const char* filename, int lineno)
92{
91 char *t, *fmt = "#line %d \"%s\"\n";
92 size_t tsz;
93
94 t = flex_alloc (tsz = strlen (fmt) + strlen (filename) + (int)(1 + log10(lineno>=0?lineno:-lineno)) + 1);
95 snprintf (t, tsz, fmt, lineno, filename);
93 char *dst, *src, *t;
94
95 t = flex_alloc (strlen ("#line \"\"\n") + /* constant parts */
96 2 * strlen (filename) + /* filename with possibly all backslashes escaped */
97 (int) (1 + log10 (abs (lineno))) + /* line number */
98 1); /* NUL */
99 if (!t)
100 flexfatal (_("Allocation of buffer for line directive failed"));
101 for (dst = t + sprintf (t, "#line %d \"", lineno), src = filename; *src; *dst++ = *src++)
102 if (*src == '\\') /* escape backslashes */
103 *dst++ = '\\';
104 *dst++ = '"';
105 *dst++ = '\n';
106 *dst = '\0';
96 buf = buf_strappend (buf, t);
97 flex_free (t);
98 return buf;
99}
100
101
102/** Append the contents of @a src to @a dest.
103 * @param @a dest the destination buffer

--- 53 unchanged lines hidden (view full) ---

157struct Buf *buf_m4_define (struct Buf *buf, const char* def, const char* val)
158{
159 const char * fmt = "m4_define( [[%s]], [[%s]])m4_dnl\n";
160 char * str;
161 size_t strsz;
162
163 val = val?val:"";
164 str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(def) + strlen(val) + 2);
107 buf = buf_strappend (buf, t);
108 flex_free (t);
109 return buf;
110}
111
112
113/** Append the contents of @a src to @a dest.
114 * @param @a dest the destination buffer

--- 53 unchanged lines hidden (view full) ---

168struct Buf *buf_m4_define (struct Buf *buf, const char* def, const char* val)
169{
170 const char * fmt = "m4_define( [[%s]], [[%s]])m4_dnl\n";
171 char * str;
172 size_t strsz;
173
174 val = val?val:"";
175 str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(def) + strlen(val) + 2);
176 if (!str)
177 flexfatal (_("Allocation of buffer for m4 def failed"));
165
166 snprintf(str, strsz, fmt, def, val);
167 buf_append(buf, &str, 1);
168 return buf;
169}
170
171/** Pushes "m4_undefine([[def]])m4_dnl" to end of buffer.
172 * @param buf A buffer as a list of strings.
173 * @param def The m4 symbol to undefine.
174 * @return buf
175 */
176struct Buf *buf_m4_undefine (struct Buf *buf, const char* def)
177{
178 const char * fmt = "m4_undefine( [[%s]])m4_dnl\n";
179 char * str;
180 size_t strsz;
181
182 str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(def) + 2);
178
179 snprintf(str, strsz, fmt, def, val);
180 buf_append(buf, &str, 1);
181 return buf;
182}
183
184/** Pushes "m4_undefine([[def]])m4_dnl" to end of buffer.
185 * @param buf A buffer as a list of strings.
186 * @param def The m4 symbol to undefine.
187 * @return buf
188 */
189struct Buf *buf_m4_undefine (struct Buf *buf, const char* def)
190{
191 const char * fmt = "m4_undefine( [[%s]])m4_dnl\n";
192 char * str;
193 size_t strsz;
194
195 str = (char*)flex_alloc(strsz = strlen(fmt) + strlen(def) + 2);
196 if (!str)
197 flexfatal (_("Allocation of buffer for m4 undef failed"));
183
184 snprintf(str, strsz, fmt, def);
185 buf_append(buf, &str, 1);
186 return buf;
187}
188
189/* create buf with 0 elements, each of size elem_size. */
190void buf_init (buf, elem_size)

--- 68 unchanged lines hidden ---
198
199 snprintf(str, strsz, fmt, def);
200 buf_append(buf, &str, 1);
201 return buf;
202}
203
204/* create buf with 0 elements, each of size elem_size. */
205void buf_init (buf, elem_size)

--- 68 unchanged lines hidden ---