- Timestamp:
- Jan 20, 2011, 7:59:38 PM (12 years ago)
- Branches:
- master, release-1.8, release-1.9
- Children:
- c426bc2
- Parents:
- 443dcfa
- git-author:
- Nelson Elhage <nelhage@mit.edu> (01/03/11 21:18:17)
- git-committer:
- David Benjamin <davidben@mit.edu> (01/20/11 19:59:38)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
util.c
r2bc6ad35 rf47696f 8 8 #include <sys/types.h> 9 9 #include <assert.h> 10 #include <stdarg.h> 10 11 #include <glib.h> 11 12 #include <glib/gstdio.h> … … 226 227 } 227 228 229 /* 230 * Appends 'tmpl' to 'buf', replacing any instances of '%q' with arguments from 231 * the varargs provided, quoting them to be safe for placing in a barnowl 232 * command line. 233 */ 234 void owl_string_appendf_quoted(GString *buf, const char *tmpl, ...) 235 { 236 va_list ap; 237 va_start(ap, tmpl); 238 owl_string_vappendf_quoted(buf, tmpl, ap); 239 va_end(ap); 240 } 241 242 void owl_string_vappendf_quoted(GString *buf, const char *tmpl, va_list ap) 243 { 244 const char *p = tmpl, *last = tmpl; 245 while (true) { 246 p = strchr(p, '%'); 247 if (p == NULL) break; 248 if (*(p+1) != 'q') { 249 p++; 250 if (*p) p++; 251 continue; 252 } 253 g_string_append_len(buf, last, p - last); 254 owl_string_append_quoted_arg(buf, va_arg(ap, char *)); 255 p += 2; last = p; 256 } 257 258 g_string_append(buf, last); 259 } 260 261 char *owl_string_build_quoted(const char *tmpl, ...) 262 { 263 GString *buf = g_string_new(""); 264 va_list ap; 265 va_start(ap, tmpl); 266 owl_string_vappendf_quoted(buf, tmpl, ap); 267 va_end(ap); 268 return g_string_free(buf, false); 269 } 270 228 271 /* Returns a quoted version of arg suitable for placing in a 229 272 * command-line. Result should be freed with owl_free. */
Note: See TracChangeset
for help on using the changeset viewer.