-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconv.c
61 lines (49 loc) · 1.17 KB
/
conv.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
// Miscellaneous conversion functions for the print library.
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <netdb.h>
#include <stddef.h>
#include "print.h"
// %I prints a IPv4 address in dotted quad form.
int
print_inaddr_conv(Format *format, int c)
{
struct in_addr *in;
in = va_arg(format->args, struct in_addr *);
fmtcat(format, (in != NULL) ? inet_ntoa(*in) : "0.0.0.0");
return FMT_verb;
}
// %R writes a string quoted for reading by /bin/rc.
int
print_rcquote_conv(Format *format, int c)
{
unsigned char *s = va_arg(format->args, unsigned char *);
unsigned char ch;
while ((ch = *s++) != '\0') {
if (ch == '\'')
fmtputc(format, ch);
fmtputc(format, ch);
}
return FMT_verb;
}
// %Q writes a string quoted as a literal C string.
int
print_cquote_conv(Format *format, int c)
{
unsigned char *s = va_arg(format->args, unsigned char *);
unsigned char ch;
// XXX - ignores f1 and f2
while ((ch = *s++) != '\0') {
if (!isascii(ch) || !isalnum(ch)) {
fmtprint(format, "\\%03uo", ch);
continue;
}
if (ch == '\\')
fmtputc(format, ch);
fmtputc(format, ch);
}
return FMT_verb;
}