File: stralign.c

package info (click to toggle)
partman-base 105
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,620 kB
  • ctags: 172
  • sloc: ansic: 2,111; sh: 1,674; makefile: 63
file content (41 lines) | stat: -rw-r--r-- 986 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>

int
main(int argc, char **argv)
{
        int space;
        int length;
        int width;
        wchar_t *string;
        setlocale(LC_ALL, "");
        sscanf(argv[1], "%i", &space);
        length = strlen(argv[2]);
        string = (wchar_t *) malloc(sizeof(wchar_t[length]));
        mbstowcs(string, argv[2], length + 2);
        width = wcswidth(string, length + 2);
        if (space > 0 && space > width) {
                int i;
                for (i = width; i < space; i++)
                        putchar(' ');
        }
        printf("%s", argv[2]);
        if (space < 0 && -space > width) {
                int i;
                for (i = width; i < -space; i++)
                        putchar(' ');
        }
        return 0;
}


/*
Local variables:
indent-tabs-mode: nil
c-file-style: "linux"
c-font-lock-extra-types: ("FILE" "\\sw+_t" "bool" "Ped\\sw+")
End:
*/