-
Notifications
You must be signed in to change notification settings - Fork 0
/
arg.c
executable file
·55 lines (40 loc) · 804 Bytes
/
arg.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
#!/usr/bin/tcc -run
#ifdef _WIN32
#include <io.h> // for isatty()
#endif
#ifdef __linux__
#include <unistd.h> // for isatty()
#endif
#include <stdio.h> // for fileno(), printf(), stderr, stdout, fprintf()
int count_chars(char *p[]) {
int count = 0;
for (; *p; p++) {
for (char *c = *p; *c; c++) {
count++;
}
}
return count;
}
int main(int argc, char *argv[]) {
if ( isatty(fileno(stdout)) ) {
fprintf(stderr, "%i:%i ", (argc - 1), count_chars(argv + 1) );
}
if (*(argv+1)) for (char **ptr = argv+1; ;) {
printf("%c", '\'');
for (char *c = *ptr; *c; c++) {
if (*c == '\'') {
printf("%s", "'\\''");
} else {
printf("%c", *c);
}
}
ptr++;
if (! *ptr) {
printf("%c", '\'');
break;
}
printf("%s", "' ");
}
printf("%c", '\n');
return 0;
}