-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcprintv.c
64 lines (59 loc) · 923 Bytes
/
cprintv.c
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* This file is part of "jelio".
* jelio is an input/output library that replaces the standard C IO library.
*
* Copyright: Jens Låås, SLU 2004
* Copyright license: According to GPL, see file COPYING in this directory.
*
*/
#include "jelio.h"
#include "jelio_internal.h"
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
/*
%% -> arg expected
\ -> escape next character
*/
int cprintv(const char *fmt, ...)
{
int n=0;
va_list ap;
va_start(ap, fmt);
while(*fmt)
{
switch(*fmt)
{
case '\\':
if(*(fmt+1))
{
fmt++;
n++;
}
break;
case '%':
if(*(fmt+1) == '%')
{
jelio *s;
s = va_arg(ap, jelio*);
if(s)
{
jelio_prot(s->mark);
n+=strlen(s->data);
free(s);
}
fmt++;
}
else
n++;
break;
default:
n++;
break;
}
fmt++;
}
va_end(ap);
return n;
}