Initial xloong code
[xloong.git] / lib / libc / str_fmt.c
blobddd852e9bee56ee34f884e8040c5ab865b9d71ff
1 /* $Id: str_fmt.c,v 1.1.1.1 2006/09/14 01:59:06 root Exp $ */
3 /*
4 * Copyright (c) 2000-2002 Opsycon AB (www.opsycon.se)
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Opsycon AB.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
21 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
33 #include <string.h>
36 * Format string by inserting blanks.
39 void
40 str_fmt(char *p, int size, int fmt)
42 int n, m, len;
44 len = strlen (p);
45 switch (fmt) {
46 case FMT_RJUST:
47 for (n = size - len; n > 0; n--)
48 strichr (p, ' ');
49 break;
50 case FMT_LJUST:
51 for (m = size - len; m > 0; m--)
52 strcat (p, " ");
53 break;
54 case FMT_RJUST0:
55 for (n = size - len; n > 0; n--)
56 strichr (p, '0');
57 break;
58 case FMT_CENTER:
59 m = (size - len) / 2;
60 n = size - (len + m);
61 for (; m > 0; m--)
62 strcat (p, " ");
63 for (; n > 0; n--)
64 strichr (p, ' ');
65 break;