File: text2h.cc

package info (click to toggle)
cdcover 0.9.1-12
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 400 kB
  • sloc: cpp: 3,257; makefile: 91
file content (62 lines) | stat: -rw-r--r-- 2,064 bytes parent folder | download | duplicates (9)
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
/*
    text2h - Converting textfiles to C/C++ includefiles 
    Copyright (C) 2000	Ulli Meybohm, www.meybohm.de (ulli@meybohm.de)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include "bytevector.h"

Bytevector head("#ifndef %VAR%_H\n#define %VAR%_H\n\n");
Bytevector pcharstart("char * %VAR%V[]=\n{\n");
Bytevector pcharend("};\n");
Bytevector linecount("\nint %VAR%C=%COUNT%;\n\n");
Bytevector tail("\n#endif\n");

int main(int argc, char* argv[]){
	Bytevector varname;
	Bytevector input;
	int count=0;
	if (argc<=1) {
		fprintf(stderr,"text2h, converts any text to a c-headerfile with a char* vector[]\n");
		fprintf(stderr,"example:  cat <inputfile> | text2h <VARNAME>  >  <outputfile>\n");
		exit(1);
	}
	varname=argv[1];	
	head.replace("%VAR%",varname);
	tail.replace("%VAR%",varname);
	pcharstart.replace("%VAR%",varname);
	pcharend.replace("%VAR%",varname);
	linecount.replace("%VAR%",varname);
	
	Bytevector("/* Created by text2h , (c) by Ulli Meybohm, www.meybohm.de   */").fwriteln(1);
	head.fwrite(1);
	pcharstart.fwrite(1);
	
	while( input.freadln(0) ) {
		count++;
		Bytevector("{\"").fwrite(1);
		input.replace("\\","\\\\");
		input.replace("\"","\\\"");
		input.fwrite(1);
		Bytevector("\"},").fwriteln(1);
	}	
	Bytevector("{\"\"}\n").fwrite(1);
	pcharend.fwrite(1);
	linecount.replace("%COUNT%",Bytevector(count));
	linecount.fwrite(1);
	tail.fwrite(1);
	return 0;
}