NAME ^

tools/build/c2str.pl - constant string support

print <<"HEADER"; /* * !!!!!!! DO NOT EDIT THIS FILE !!!!!!! * * This file is generated automatically from '$infile' * by $0. * * Any changes made here will be lost! * */

#define CONCAT(a,b) a##b #define _S(name) (__PARROT_STATIC_STR(__LINE__)) #define __PARROT_STATIC_STR(line) CONCAT(&static_string_, line)

#if ! DISABLE_GC_DEBUG # define GC_DEBUG_VERSION ,0 #else # define GC_DEBUG_VERSION #endif

HEADER

# currently unused true const strings sub output_string { my ($text, $line) = @_;

  if (exists $known_strings{$text}) {
    <<"DATA";
#define static_string_${line} static_string_$known_strings{$text}

DATA } else { $known_strings{$text} = $line; my $h = hash_val($text); <<"DATA"; static /*const*/ char static_string_${line}_data\[\] = $text; static /*const*/ struct parrot_string_t static_string_${line} = { { /* pobj_t */ {{ static_string_${line}_data, sizeof(static_string_${line}_data) }}, (PObj_constant_FLAG|PObj_external_FLAG) GC_DEBUG_VERSION }, sizeof(static_string_${line}_data), static_string_${line}_data, sizeof(static_string_${line}_data) - 1, 1, $h };

DATA } }

open IN, $infile;

my $line = 0; while (<IN>) { $line++; next if m/^\s*#/; # ignore preprocessor next unless s/.*\b_S\b//;

  my $str = extract_bracketed $_, '(")';

  print output_string (substr($str,1,-1), $line);
}


parrot