Newer
Older
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
*
* All rights reserved.
*
* This file is part of Obarun. It is subject to the license terms in
* the LICENSE file found in the top-level directory of this
* distribution.
* This file may not be copied, modified, propagated, or distributed
* except according to the terms contained in the LICENSE file./
* */
#include <stddef.h>
#include <oblibs/log.h>
#include <skalibs/stralloc.h>
#include <skalibs/buffer.h>
#include <skalibs/lolstdio.h>
#include <66/info.h>
void info_display_list(char const *field, stralloc *list)
{
log_flow() ;
size_t a = 0 , b, cols, padding = 0, slen = 0 ;
unsigned short maxcols = info_getcols_fd(1) ;
padding = info_length_from_wchar(field) + 1 ;
cols = padding ;
for (; a < list->len ; a += strlen(list->s + a) + 1)
{
char const *str = list->s + a ;
slen = info_length_from_wchar(str) ;
if((maxcols > padding) && (cols + slen + 2 >= maxcols))
{
cols = padding ;
if (buffer_puts(buffer_1,"\n") == -1) goto err ;
for(b = 1 ; b <= padding ; b++)
if (buffer_puts(buffer_1," ") == -1) goto err ;
}
else if (cols != padding)
{
if (buffer_puts(buffer_1," ") == -1) goto err ;
cols += 2 ;
}
if (!bprintf(buffer_1,"%s",str)) goto err ;
cols += slen ;
}
if (buffer_puts(buffer_1,"\n") == -1) goto err ;
return ;
err:
log_dieusys(LOG_EXIT_SYS,"write to stdout") ;
}