forked from universal-ctags/ctags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtxt2cstr
executable file
·66 lines (53 loc) · 1022 Bytes
/
txt2cstr
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
#!/usr/bin/env perl
#
# txt2cstr - a tool converting a text file into char[].
#
# Copyright (C) 2021 Masatake YAMATO
# Copyright (C) 2021 Red Hat Inc.
#
use File::Basename;
sub show_help {
print<<EOF;
Usage:
$0 --help
$0 INPUT.txt > OUTPUT.c
EOF
}
sub convert {
my $input = $_[0];
my $name = basename $input;
$name =~ s/\.[a-z]+$//g;
open(INPUT, "< " . $input) or die("faild to open " . $input);
print "const char ctags$name []=\n";
while (<INPUT>) {
chop;
$_ =~ s/\\/\\\\/g;
$_ =~ s/\"/\\\"/g;
print '"' . "$_" . '\\n"' . "\n";
}
print ";\n";
close (INPUT);
}
sub main {
my $input;
for (@_) {
if ( ($_ eq '-h') || ($_ eq '--help') ) {
show_help;
exit 0;
} elsif ( /^-.*/ ) {
die "unrecongnized option: $_";
} else {
if ($input) {
die "Don't specify more than 1 input file: @_";
}
$input=$_;
}
}
unless ($input) {
die "No input file given";
}
convert $input;
0;
}
main @ARGV;
# txt2cstr ends here