projects
/
libfirm
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
and again
[libfirm]
/
ir
/
libcore
/
lc_printf.c
diff --git
a/ir/libcore/lc_printf.c
b/ir/libcore/lc_printf.c
index
f311fae
..
f623d09
100644
(file)
--- a/
ir/libcore/lc_printf.c
+++ b/
ir/libcore/lc_printf.c
@@
-81,8
+81,7
@@
static int lc_arg_cmp(const void *p1, const void *p2, UNUSED(size_t size))
lc_arg_env_t *lc_arg_new_env(void)
{
lc_arg_env_t *lc_arg_new_env(void)
{
- lc_arg_env_t *env = xmalloc(sizeof(*env));
- memset(env, 0, sizeof(*env));
+ lc_arg_env_t *env = XMALLOCZ(lc_arg_env_t);
env->args = new_set(lc_arg_cmp, 16);
return env;
}
env->args = new_set(lc_arg_cmp, 16);
return env;
}
@@
-130,7
+129,7
@@
int lc_arg_append(lc_appendable_t *app, const lc_arg_occ_t *occ, const char *str
char pad = ' ';
/* Set the padding to zero, if the zero is given and we are not left
char pad = ' ';
/* Set the padding to zero, if the zero is given and we are not left
- * justified. (A minus ov
ve
rides the zero). See printf(3). */
+ * justified. (A minus ov
er
rides the zero). See printf(3). */
if(!occ->flag_minus && occ->flag_zero)
pad = '0';
if(!occ->flag_minus && occ->flag_zero)
pad = '0';
@@
-184,23
+183,20
@@
static char *make_fmt(char *buf, size_t len, const lc_arg_occ_t *occ)
return buf;
}
return buf;
}
-/*
+/*
*
* Standard argument handler.
*/
static int std_get_lc_arg_type(const lc_arg_occ_t *occ)
{
int modlen = occ->modifier_length;
* Standard argument handler.
*/
static int std_get_lc_arg_type(const lc_arg_occ_t *occ)
{
int modlen = occ->modifier_length;
- const char *mod = occ->modifier;
- int res = -1;
-
/* check, if the type can be derived from the modifier */
/* check, if the type can be derived from the modifier */
- if(modlen > 0) {
- switch(mod[0]) {
+ if (modlen > 0) {
+ const char *mod = occ->modifier;
+ switch (mod[0]) {
case 'l':
case 'l':
- res = modlen > 1 && mod[1] == 'l' ? lc_arg_type_long_long : lc_arg_type_long;
- break;
-#define TYPE_CASE(letter,type) case letter: res = lc_arg_type_ ## type; break
+ return modlen > 1 && mod[1] == 'l' ? lc_arg_type_long_long : lc_arg_type_long;
+#define TYPE_CASE(letter,type) case letter: return lc_arg_type_ ## type;
#if 0
TYPE_CASE('j', intmax_t);
TYPE_CASE('z', size_t);
#if 0
TYPE_CASE('j', intmax_t);
TYPE_CASE('z', size_t);
@@
-213,27
+209,21
@@
static int std_get_lc_arg_type(const lc_arg_occ_t *occ)
/* The type is given by the conversion specifier and cannot be
* determined from the modifier. */
/* The type is given by the conversion specifier and cannot be
* determined from the modifier. */
- if(res == -1) {
- switch(occ->conversion) {
- case 'e':
- case 'E':
- case 'f':
- case 'F':
- case 'g':
- case 'G':
- res = lc_arg_type_double;
- break;
- case 's':
- case 'n':
- case 'p':
- res = lc_arg_type_ptr;
- break;
- default:
- res = lc_arg_type_int;
- }
+ switch (occ->conversion) {
+ case 'e':
+ case 'E':
+ case 'f':
+ case 'F':
+ case 'g':
+ case 'G':
+ return lc_arg_type_double;
+ case 's':
+ case 'n':
+ case 'p':
+ return lc_arg_type_ptr;
+ default:
+ return lc_arg_type_int;
}
}
-
- return res;
}
static int std_emit(lc_appendable_t *app, const lc_arg_occ_t *occ, const lc_arg_value_t *val)
}
static int std_emit(lc_appendable_t *app, const lc_arg_occ_t *occ, const lc_arg_value_t *val)
@@
-266,10
+256,10
@@
static int std_emit(lc_appendable_t *app, const lc_arg_occ_t *occ, const lc_arg_
default:
{
int len = LC_MAX(128, occ->width + 1);
default:
{
int len = LC_MAX(128, occ->width + 1);
- char *buf =
malloc(len * sizeof(char)
);
+ char *buf =
XMALLOCN(char, len
);
res = dispatch_snprintf(buf, len, fmt, occ->lc_arg_type, val);
res = lc_appendable_snadd(app, buf, res);
res = dispatch_snprintf(buf, len, fmt, occ->lc_arg_type, val);
res = lc_appendable_snadd(app, buf, res);
- free(buf);
+
x
free(buf);
}
}
}
}
@@
-321,7
+311,7
@@
int lc_evpprintf(const lc_arg_env_t *env, lc_appendable_t *app, const char *fmt,
const char *s;
const char *last = fmt + strlen(fmt);
const char *s;
const char *last = fmt + strlen(fmt);
- /* Find the fi
sr
t % */
+ /* Find the fi
rs
t % */
s = strchr(fmt, '%');
/* Emit the text before the first % was found */
s = strchr(fmt, '%');
/* Emit the text before the first % was found */
@@
-440,7
+430,7
@@
int lc_evpprintf(const lc_arg_env_t *env, lc_appendable_t *app, const char *fmt,
}
if(map[ch - base] != NULL) {
}
if(map[ch - base] != NULL) {
- occ.modifier =
s
;
+ occ.modifier =
mod
;
occ.modifier_length = s - mod;
occ.conversion = ch;
arg = map[ch - base];
occ.modifier_length = s - mod;
occ.conversion = ch;
arg = map[ch - base];