summaryrefslogtreecommitdiff
path: root/tools/cvt_emit
blob: c4b0172e58162da727ec405feceadaff29b1c61f (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
#!/usr/local/bin/perl

while(<>) {
  if (/`/) {
    print $`;
    $_ = $';
    print "(";
    $first = 1;
# Split into literal strings and {...} blocks
    while(1) {
      if (/^`/) {
        $_ = $';
        last;
      }
      elsif (/^{([^}]*)}/) {
        $_ = $';
        if ($first) { $first = 0; } else { print "; "; }
        print $1;
      }
      elsif (/^(([^`{\\]|\\[`"ntbr{\\]|\\[0-9][0-9][0-9])*)/) {
        $_ = $';
        $string = $1;
        $string =~ s/\\([`{])/\1/g;
        if ($first) { $first = 0; } else { print "; "; }
        print "emit_string \"", $string, "\"";
      }
      else {
        print STDERR "Unterminated `...` at line $.\n";
        exit(2);
      }
    }
    print ")", $_;
  } else {
    print $_;
  }
}