X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=ir%2Flibcore%2Flc_appendable.c;h=b772256b23458a096ae574a726657d6a719b534c;hb=8aca33381b3dea1ef0bb6c120f59989075c438d1;hp=ca0637b89f70a9ceb9e0210f0ede0f37b009764a;hpb=0fbcef83aa6060534172bb13e71cdadb04428806;p=libfirm diff --git a/ir/libcore/lc_appendable.c b/ir/libcore/lc_appendable.c index ca0637b89..b772256b2 100644 --- a/ir/libcore/lc_appendable.c +++ b/ir/libcore/lc_appendable.c @@ -1,29 +1,14 @@ /* - libcore: library for basic data structures and algorithms. - Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + * This file is part of libFirm. + * Copyright (C) 2012 IPD Goos, Universit"at Karlsruhe, Germany + */ #include "config.h" #include #include #include -#include "lc_common_t.h" -#include "lc_defines.h" +#include "util.h" #include "lc_printf.h" /* Default appendable implementations */ @@ -32,18 +17,18 @@ int lc_appendable_snwadd(lc_appendable_t *app, const char *str, size_t len, unsigned int width, int left_just, char pad) { int res = 0; - int i; - int to_pad = width - len; + size_t i; + size_t to_pad = width > len ? width - len : 0; /* If not left justified, pad left */ - for(i = 0; !left_just && i < to_pad; ++i) + for (i = 0; !left_just && i < to_pad; ++i) res += lc_appendable_chadd(app, pad); /* Send the visible portion of the string to the output. */ res += lc_appendable_snadd(app, str, len); /* If left justified, pad right. */ - for(i = 0; left_just && i < to_pad; ++i) + for (i = 0; left_just && i < to_pad; ++i) res += lc_appendable_chadd(app, pad); return res; @@ -61,12 +46,14 @@ void lc_appendable_init(lc_appendable_t *env, const lc_appendable_funcs_t *app, app->init(env); } -static void default_init(UNUSED(lc_appendable_t *env)) +static void default_init(lc_appendable_t *env) { + (void) env; } -static void default_finish(UNUSED(lc_appendable_t *env)) +static void default_finish(lc_appendable_t *env) { + (void) env; } /* @@ -76,13 +63,13 @@ static void default_finish(UNUSED(lc_appendable_t *env)) static int file_snadd(lc_appendable_t *obj, const char *str, size_t n) { obj->written += n; - fwrite(str, sizeof(char), n, obj->obj); + fwrite(str, sizeof(char), n, (FILE*)obj->obj); return n; } static int file_chadd(lc_appendable_t *obj, int ch) { - fputc(ch, obj->obj); + fputc(ch, (FILE*)obj->obj); obj->written++; return 1; } @@ -103,13 +90,13 @@ const lc_appendable_funcs_t *lc_appendable_file = &app_file; static void str_init(lc_appendable_t *obj) { - strncpy(obj->obj, "", obj->limit); + strncpy((char*)obj->obj, "", obj->limit); } static int str_snadd(lc_appendable_t *obj, const char *str, size_t n) { - size_t to_write = LC_MIN(obj->limit - obj->written - 1, n); - char *tgt = obj->obj; + size_t to_write = MIN(obj->limit - obj->written - 1, n); + char *tgt = (char*)obj->obj; strncpy(tgt + obj->written, str, to_write); obj->written += to_write; return to_write; @@ -117,8 +104,8 @@ static int str_snadd(lc_appendable_t *obj, const char *str, size_t n) static int str_chadd(lc_appendable_t *obj, int ch) { - if(obj->limit - obj->written > 1) { - char *tgt = obj->obj; + if (obj->limit - obj->written > 1) { + char *tgt = (char*)obj->obj; tgt[obj->written++] = (char) ch; return 1; } @@ -128,7 +115,7 @@ static int str_chadd(lc_appendable_t *obj, int ch) static void str_finish(lc_appendable_t *obj) { - char *str = obj->obj; + char *str = (char*)obj->obj; str[obj->written] = '\0'; } @@ -147,7 +134,7 @@ const lc_appendable_funcs_t *lc_appendable_string = &app_string; static int obst_snadd(lc_appendable_t *obj, const char *str, size_t n) { - struct obstack *obst = obj->obj; + struct obstack *obst = (struct obstack*)obj->obj; obj->written += n; obstack_grow(obst, str, n); return n; @@ -155,7 +142,7 @@ static int obst_snadd(lc_appendable_t *obj, const char *str, size_t n) static int obst_chadd(lc_appendable_t *obj, int ch) { - struct obstack *obst = obj->obj; + struct obstack *obst = (struct obstack*)obj->obj; obstack_1grow(obst, (char) ch); obj->written++; return 1;