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
|
// Stringify.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int main(int argc, char* argv[])
{
if (argc != 4)
{
fprintf(stderr, "Usage: %s TEXT_FILENAME VARIABLE_NAME OUTPUT_FILE\n", argv[0]);
exit(1);
}
const char* pFilenameIn = argv[1];
const char* pVariableName = argv[2];
const char *pFilenameOut = argv[3];
FILE *fpIn = fopen(pFilenameIn, "r");
if (!fpIn)
{
fprintf(stderr, "Error: Failed to open %s\n", pFilenameIn);
exit(1);
}
FILE *fpOut = fopen(pFilenameOut, "w");
if (!fpOut)
{
fprintf(stderr, "Error: Failed to open %s\n", pFilenameOut);
exit(1);
}
fprintf(fpOut, "static const char* %s =\n", pVariableName);
char row[1024];
while (fgets(row, sizeof(row), fpIn))
{
row[strlen(row) - 1] = 0; // remove \n
fprintf(fpOut, "\"%s\\n\"\n", row);
}
fprintf(fpOut, ";\n");
fclose(fpIn);
fclose(fpOut);
return 0;
}
|