blob: 1a13fbb71f78c53d438e1fae5c8c77247e51cd1a (
plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
|
/** \file gen_hdr2.c
A program that reads data from stdin and outputs it as a C string.
It is used as a part of the build process to generate help texts
for the built in commands.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/**
The main function, does all the work
*/
int main()
{
int line = 0;
printf( "\t\t\"" );
int c;
int count=0;
while( (c=getchar()) != EOF )
{
if( c == '\n' )
line++;
if( line > 4 )
break;
}
while( (c=getchar()) != EOF )
{
if( (c >= 'a' && c <= 'z' ) ||
(c >= 'A' && c <= 'Z' ) ||
(c >= '0' && c <= '9' ) ||
( strchr(" ,.!;:-_#$%&(){}[]<>=?+-*/'",c) != 0) )
{
count++;
putchar(c);
}
else
{
switch(c)
{
case '\n':
printf( "\\n" );
printf( "\"\n\t\t\"" );
count =0;
break;
case '\t':
printf( "\\t" );
count +=2;
break;
case '\r':
printf( "\\r" );
count +=2;
break;
case '\"':
case '\\':
printf( "\\%c",c );
count +=2;
break;
default:
count +=7;
printf( "\\x%02x\" \"", c );
break;
}
}
if( count > 60 )
{
count=0;
printf( "\"\n\t\t\"" );
}
}
printf( "\"" );
return 0;
}
|