3 if test ! -f config.sh; then
5 ln ../../config.sh . || \
6 ln ../../../config.sh . || \
7 (echo "Can't find config.sh."; exit 1)
12 : This forces SH files to create target in same directory as SH file.
13 : This is so that make depend always knows where to find SH derivatives.
15 */*) cd `expr X$0 : 'X\(.*\)/'` ;;
17 echo "Extracting c2ph (with variable substitutions)"
18 : This section of the file will have variable substitutions done on it.
19 : Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
20 : Protect any dollar signs and backticks that you do not want interpreted
21 : by putting a backslash in front. You may delete these comments.
22 $spitshell >c2ph <<!GROK!THIS!
27 : In the following dollars and backticks do not need the extra backslash.
28 $spitshell >>c2ph <<'!NO!SUBS!'
31 # Tom Christiansen, <tchrist@convex.com>
33 # As pstruct, dump C structures as generated from 'cc -g -S' stabs.
34 # As c2ph, do this PLUS generate perl code for getting at the structures.
36 # See the usage message for more. If this isn't enough, read the code.
39 $RCSID = '$RCSfile: c2ph.SH,v $$Revision: 4.0.1.1 $$Date: 91/11/05 16:02:29 $';
42 ######################################################################
44 # some handy data definitions. many of these can be reset later.
46 $bitorder = 'b'; # ascending; set to B for descending bit fields
54 'unsigned short', 'S',
55 'unsigned short int', 'S',
56 'short unsigned int', 'S',
63 'long unsigned int', 'L',
64 'unsigned long int', 'L',
67 'unsigned long long', 'Q',
68 'unsigned long long int', 'Q',
78 delete $intrinsics{'neganull'};
79 delete $intrinsics{'bit'};
80 delete $intrinsics{'null'};
82 # use -s to recompute sizes
88 'unsigned short', '2',
89 'unsigned short int', '2',
90 'short unsigned int', '2',
96 'unsigned long int', '4',
97 'long unsigned int', '4',
100 'unsigned long long', '8',
101 'unsigned long long int', '8',
107 ($type_width, $member_width, $offset_width, $size_width) = (20, 20, 6, 5);
109 ($offset_fmt, $size_fmt) = ('d', 'd');
117 $perl++ if $0 =~ m#/?c2ph$#;
119 require 'getopts.pl';
121 eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift;
123 &Getopts('aixdpvtnws:') || &usage(0);
128 $opt_v && $verbose++;
129 $opt_n && ($perl = 0);
132 ($type_width, $member_width, $offset_width) = (45, 35, 8);
135 ($offset_fmt, $offset_width, $size_fmt, $size_width) = ( 'x', '08', 'x', 04 );
138 eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift;
142 print "oops, apperent pager foulup\n";
154 print "hit <RETURN> for further explanation: ";
156 open (PIPE, "|". ($ENV{PAGER} || 'more'));
157 $SIG{PIPE} = PLUMBER;
161 print "usage: $0 [-dpnP] [var=val] [files ...]\n";
169 -w wide; short for: type_width=45 member_width=35 offset_width=8
170 -x hex; short for: offset_fmt=x offset_width=08 size_fmt=x size_width=04
172 -n do not generate perl code (default when invoked as pstruct)
173 -p generate perl code (default when invoked as c2ph)
174 -v generate perl code, with C decls as comments
176 -i do NOT recompute sizes for intrinsic datatypes
177 -a dump information on intrinsics also
180 -d spew reams of debugging output
182 -slist give comma-separated list a structures to dump
185 Var Name Default Value Meaning
189 &defvar('CC', 'which_compiler to call');
190 &defvar('CFLAGS', 'how to generate *.s files with stabs');
191 &defvar('DEFINES','any extra cflags or cpp defines, like -I, -D, -U');
195 &defvar('type_width', 'width of type field (column 1)');
196 &defvar('member_width', 'width of member field (column 2)');
197 &defvar('offset_width', 'width of offset field (column 3)');
198 &defvar('size_width', 'width of size field (column 4)');
202 &defvar('offset_fmt', 'sprintf format type for offset');
203 &defvar('size_fmt', 'sprintf format type for size');
207 &defvar('indent', 'how far to indent each nesting level');
211 If any *.[ch] files are given, these will be catted together into
212 a temporary *.c file and sent through:
214 and the resulting *.s groped for stab information. If no files are
215 supplied, then stdin is read directly with the assumption that it
216 contains stab information. All other liens will be ignored. At
217 most one *.s file should be supplied.
225 local($var, $msg) = @_;
226 printf "%-16s%-15s %s\n", $var, eval "\$$var", $msg;
232 if (grep(!/\.[csh]$/,@ARGV)) {
233 warn "Only *.[csh] files expected!\n";
236 elsif (grep(/\.s$/,@ARGV)) {
238 warn "Only one *.s file allowed!\n";
242 elsif (@ARGV == 1 && $ARGV[0] =~ /\.c$/) {
243 local($dir, $file) = $ARGV[0] =~ m#(.*/)?(.*)$#;
244 $chdir = "cd $dir; " if $dir;
245 &system("$chdir$CC $CFLAGS $DEFINES $file") && exit 1;
246 $ARGV[0] =~ s/\.c$/.s/;
249 $TMP = "/tmp/c2ph.$$.c";
250 &system("cat @ARGV > $TMP") && exit 1;
251 &system("cd /tmp; $CC $CFLAGS $DEFINES $TMP") && exit 1;
259 for (split(/[\s,]+/, $opt_s)) {
271 print STDERR "reading from your keyboard: ";
273 print STDERR "reading from " . (@ARGV ? "@ARGV" : "<STDIN>").": ";
278 if ($trace && !($. % 10)) {
280 print STDERR $lineno, "\b" x length($lineno);
282 next unless /^\s*\.stabs\s+/;
287 print STDERR "$.\n" if $trace;
290 &compute_intrinsics if $perl && !$opt_i;
292 print STDERR "resolving types\n" if $trace;
297 $sum = 2 + $type_width + $member_width;
298 $pmask1 = "%-${type_width}s %-${member_width}s";
299 $pmask2 = "%-${sum}s %${offset_width}${offset_fmt}%s %${size_width}${size_fmt}%s";
302 # resolve template -- should be in stab define order, but even this isn't enough.
303 print STDERR "\nbuilding type templates: " if $trace;
304 for $i (reverse 0..$#type) {
305 next unless defined($name = $type[$i]);
306 next unless defined $struct{$name};
308 &build_template($name) unless defined $template{&psou($name)} ||
309 $opt_s && !$interested{$name};
311 print STDERR "\n\n" if $trace;
314 print STDERR "dumping structs: " if $trace;
317 foreach $name (sort keys %struct) {
318 next if $opt_s && !$interested{$name};
319 print STDERR "$name " if $trace;
327 $mname = &munge($name);
329 $fname = &psou($name);
331 print "# " if $perl && $verbose;
333 print "$fname {\n" if !$perl || $verbose;
334 $template{$fname} = &scrunch($template{$fname}) if $perl;
335 &pstruct($name,$name,0);
336 print "# " if $perl && $verbose;
337 print "}\n" if !$perl || $verbose;
338 print "\n" if $perl && $verbose;
343 printf("\nsub %-32s { %4d; }\n\n", "${mname}'struct", $countof{$name});
346 sub ${mname}'typedef {
347 local(\$${mname}'index) = shift;
348 defined \$${mname}'index
349 ? \$${mname}'typedef[\$${mname}'index]
350 : \$${mname}'typedef;
355 sub ${mname}'sizeof {
356 local(\$${mname}'index) = shift;
357 defined \$${mname}'index
358 ? \$${mname}'sizeof[\$${mname}'index]
364 sub ${mname}'offsetof {
365 local(\$${mname}'index) = shift;
366 defined \$${mname}index
367 ? \$${mname}'offsetof[\$${mname}'index]
373 sub ${mname}'typeof {
374 local(\$${mname}'index) = shift;
375 defined \$${mname}index
376 ? \$${mname}'typeof[\$${mname}'index]
382 print "\$${mname}'typedef = '" . &scrunch($template{$fname})
385 print "\$${mname}'sizeof = $sizeof{$name};\n\n";
388 print "\@${mname}'indices = (", &squishseq(@indices), ");\n";
392 print "\@${mname}'typedef[\@${mname}'indices] = (",
393 join("\n\t", '', @typedef), "\n );\n\n";
394 print "\@${mname}'sizeof[\@${mname}'indices] = (",
395 join("\n\t", '', @sizeof), "\n );\n\n";
396 print "\@${mname}'offsetof[\@${mname}'indices] = (",
397 join("\n\t", '', @offsetof), "\n );\n\n";
398 print "\@${mname}'typeof[\@${mname}'indices] = (",
399 join("\n\t", '', @typeof), "\n );\n\n";
401 $template_printed{$fname}++;
402 $size_printed{$fname}++;
407 print STDERR "\n" if $trace;
409 unless ($perl && $opt_a) {
416 foreach $name (sort bysizevalue keys %intrinsics) {
417 next if $size_printed{$name};
418 print '$',&munge($name),"'sizeof = ", $sizeof{$name}, ";\n";
423 sub bysizevalue { $sizeof{$a} <=> $sizeof{$b}; }
426 foreach $name (sort keys %intrinsics) {
427 print '$',&munge($name),"'typedef = '", $template{$name}, "';\n";
435 ########################################################################################
439 next unless /:[\$\w]+(\(\d+,\d+\))?=[\*\$\w]+/; # (\d+,\d+) is for sun
441 s/",([x\d]+),([x\d]+),([x\d]+),.*// || next;
450 if (($name, $pdecl) = /^([\$ \w]+):[tT]((\d+)(=[rufs*](\d+))+)$/) {
451 print "$name is a typedef for some funky pointers: $pdecl\n" if $debug;
458 if (/(([ \w]+):t(\d+|\(\d+,\d+\)))=r?(\d+|\(\d+,\d+\))(;\d+;\d+;)?/) {
460 push(@intrinsics, $ident);
461 $typeno = &typeno($3);
462 $type[$typeno] = $ident;
463 print STDERR "intrinsic $ident in new type $typeno\n" if $debug;
467 if (($name, $typeordef, $typeno, $extra, $struct, $_)
468 = /^([\$ \w]+):([ustT])(\d+|\(\d+,\d+\))(=[rufs*](\d+))?(.*)$/)
470 $typeno = &typeno($typeno); # sun foolery
472 elsif (/^[\$\w]+:/) {
476 warn "can't grok stab: <$_> in: $line " if $_;
480 #warn "got size $size for $name\n";
481 $sizeof{$name} = $size if $size;
483 s/;[-\d]*;[-\d]*;$//; # we don't care about ranges
485 $typenos{$name} = $typeno;
487 unless (defined $type[$typeno]) {
488 &panic("type 0??") unless $typeno;
489 $type[$typeno] = $name unless defined $type[$typeno];
490 printf "new type $typeno is $name" if $debug;
491 if ($extra =~ /\*/ && defined $type[$struct]) {
492 print ", a typedef for a pointer to " , $type[$struct] if $debug;
495 printf "%s is type %d", $name, $typeno if $debug;
496 print ", a typedef for " , $type[$typeno] if $debug;
498 print "\n" if $debug;
499 #next unless $extra =~ /[su*]/;
501 #$type[$struct] = $name;
503 if ($extra =~ /[us*]/) {
505 $_ = &sdecl($name, $_, 0);
508 print "it's a bare array typedef -- that's pretty sick\n" if $debug;
514 elsif (s/((\w+):t(\d+|\(\d+,\d+\)))?=r?(;\d+;\d+;)?//) { # the ?'s are for gcc
515 push(@intrinsics, $2);
516 $typeno = &typeno($3);
518 print STDERR "intrinsic $2 in new type $typeno\n" if $debug;
520 elsif (s/^=e//) { # blessed by thy compiler; mine won't do this
524 warn "Funny remainder for $name on line $_ left in $line " if $_;
528 sub typeno { # sun thinks types are (0,27) instead of just 27
535 local($what,$prefix,$base) = @_;
536 local($field, $fieldname, $typeno, $count, $offset, $entry);
538 local($type, $tname);
539 local($mytype, $mycount, $entry2);
540 local($struct_count) = 0;
541 local($pad, $revpad, $length, $prepad, $lastoffset, $lastlength, $fmt);
546 local($mname) = &munge($name);
554 local($sname) = &psou($what);
558 for $field (split(/;/, $struct{$what})) {
561 ($fieldname, $typeno, $count, $offset, $length) = split(/,/, $field);
563 $type = $type[$typeno];
565 $type =~ /([^[]*)(\[.*\])?/;
568 $fieldtype = &psou($mytype);
570 local($fname) = &psou($name);
572 if ($build_templates) {
574 $pad = ($offset - ($lastoffset + $lastlength))/8
575 if defined $lastoffset;
577 if (! $finished_template{$sname}) {
578 if ($isaunion{$what}) {
579 $template{$sname} .= 'X' x $revpad . ' ' if $revpad;
581 $template{$sname} .= 'x' x $pad . ' ' if $pad;
585 $template = &fetch_template($type) x
586 ($count ? &scripts2count($count) : 1);
588 if (! $finished_template{$sname}) {
589 $template{$sname} .= $template;
592 $revpad = $length/8 if $isaunion{$what};
594 ($lastoffset, $lastlength) = ($offset, $length);
597 print '# ' if $perl && $verbose;
598 $entry = sprintf($pmask1,
599 ' ' x ($nesting * $indent) . $fieldtype,
600 "$prefix.$fieldname" . $count);
602 $entry =~ s/(\*+)( )/$2$1/;
607 ($bits = ($base+$offset)%8) ? ".$bits" : " ",
609 ($bits = $length % 8) ? ".$bits": ""
610 if !$perl || $verbose;
613 if ($perl && $nesting == 1) {
614 $template = &scrunch(&fetch_template($type) x
615 ($count ? &scripts2count($count) : 1));
616 push(@sizeof, int($length/8) .",\t# $fieldname");
617 push(@offsetof, int($offset/8) .",\t# $fieldname");
618 push(@typedef, "'$template', \t# $fieldname");
619 $type =~ s/(struct|union) //;
620 push(@typeof, "'$type" . ($count ? $count : '') .
624 print ' ', ' ' x $indent x $nesting, $template
625 if $perl && $verbose;
627 print "\n" if !$perl || $verbose;
631 local($mycount) = defined $struct{$mytype} ? $countof{$mytype} : 1;
632 $mycount *= &scripts2count($count) if $count;
633 if ($nesting==1 && !$build_templates) {
634 $pcode .= sprintf("sub %-32s { %4d; }\n",
635 "${mname}'${fieldname}", $struct_count);
636 push(@indices, $struct_count);
638 $struct_count += $mycount;
642 &pstruct($type, "$prefix.$fieldname", $base+$offset)
643 if $recurse && defined $struct{$type};
646 $countof{$what} = $struct_count unless defined $countof{$whati};
648 $template{$sname} .= '$' if $build_templates;
649 $finished_template{$sname}++;
651 if ($build_templates && !defined $sizeof{$name}) {
652 local($fmt) = &scrunch($template{$sname});
653 print STDERR "no size for $name, punting with $fmt..." if $debug;
654 eval '$sizeof{$name} = length(pack($fmt, ()))';
657 warn "couldn't get size for \$name: $@";
659 print STDERR $sizeof{$name}, "\n" if $debUg;
669 local($amstruct) = $struct{$me} ? 'struct ' : '';
671 print '$sizeof{\'', $amstruct, $me, '\'} = ';
672 printf "%d;\n", $sizeof{$me};
680 warn "pdecl: $pdecl\n" if $debug;
682 $pdecl =~ s/\(\d+,(\d+)\)/$1/g;
684 @pdecls = split(/=/, $pdecl);
685 $typeno = $pdecls[0];
686 $tname = pop @pdecls;
688 if ($tname =~ s/^f//) { $tname = "$tname&"; }
689 #else { $tname = "$tname*"; }
691 for (reverse @pdecls) {
692 $tname .= s/^f// ? "&" : "*";
693 #$tname =~ s/^f(.*)/$1&/;
694 print "type[$_] is $tname\n" if $debug;
695 $type[$_] = $tname unless defined $type[$_];
702 ($arraytype, $unknown, $lower, $upper) = ();
704 # global $typeno, @type
705 local($_, $typedef) = @_;
707 while (s/^((\d+)=)?ar(\d+);//) {
708 ($arraytype, $unknown) = ($2, $3);
709 if (s/^(\d+);(\d+);//) {
710 ($lower, $upper) = ($1, $2);
711 $scripts .= '[' . ($upper+1) . ']';
713 warn "can't find array bounds: $_";
716 if (s/^([\d*f=]*),(\d+),(\d+);//) {
717 ($start, $length) = ($2, $3);
719 if ($whatis =~ /^(\d+)=/) {
725 } elsif (s/^(\d+)(=[*suf]\d*)//) {
728 if ($whatis =~ /[f*]/) {
730 } elsif ($whatis =~ /[su]/) { #
731 print "$prefix.$fieldname is an array$scripts anon structs; disgusting\n"
733 #$type[$typeno] = $name unless defined $type[$typeno];
734 ##printf "new type $typeno is $name" if $debug;
736 $type[$typeno] = "$prefix.$fieldname";
737 local($name) = $type[$typeno];
738 &sou($name, $whatis);
739 $_ = &sdecl($name, $_, $start+$offset);
741 $start = $start{$name};
742 $offset = $sizeof{$name};
745 warn "what's this? $whatis in $line ";
750 warn "bad array stab: $_ in $line ";
753 #local($wasdef) = defined($type[$typeno]) && $debug;
755 #print "redefining $type[$typeno] to " if $wasdef;
756 #$type[$typeno] = "$whatis$scripts"; # unless defined $type[$typeno];
757 #print "$type[$typeno]\n" if $wasdef;
759 #$type[$arraytype] = $type[$typeno] unless defined $type[$arraytype];
761 $type[$arraytype] = "$type[$typeno]$scripts" if defined $type[$typeno];
762 print "type[$arraytype] is $type[$arraytype]\n" if $debug;
763 print "$prefix.$fieldname is an array of $type[$arraytype]\n" if $debug;
770 local($prefix, $_, $offset) = @_;
772 local($fieldname, $scripts, $type, $arraytype, $unknown,
773 $whatis, $pdecl, $upper,$lower, $start,$length) = ();
778 while (/^([^;]+);/) {
780 warn "sdecl $_\n" if $debug;
781 if (s/^([\$\w]+)://) {
783 } elsif (s/(\d+)=([us])(\d+|\(\d+,\d+\))//) { #
784 $typeno = &typeno($1);
785 $type[$typeno] = "$prefix.$fieldname";
786 local($name) = "$prefix.$fieldname";
788 $_ = &sdecl("$prefix.$fieldname", $_, $start+$offset);
789 $start = $start{$name};
790 $offset += $sizeof{$name};
791 #print "done with anon, start is $start, offset is $offset\n";
794 warn "weird field $_ of $line" if $debug;
796 #$fieldname = &gensym;
797 #$_ = &sdecl("$prefix.$fieldname", $_, $start+$offset);
803 elsif (s/^(\d+|\(\d+,\d+\))?,(\d+),(\d+);//) {
804 ($start, $length) = ($2, $3);
805 &panic("no length?") unless $length;
806 $typeno = &typeno($1) if $1;
808 elsif (s/^((\d+|\(\d+,\d+\))(=[*f](\d+|\(\d+,\d+\)))+),(\d+),(\d+);//) {
809 ($pdecl, $start, $length) = ($1,$5,$6);
812 elsif (s/(\d+)=([us])(\d+|\(\d+,\d+\))//) { # the dratted anon struct
813 ($typeno, $sou) = ($1, $2);
814 $typeno = &typeno($typeno);
815 if (defined($type[$typeno])) {
816 warn "now how did we get type $1 in $fieldname of $line?";
818 print "anon type $typeno is $prefix.$fieldname\n" if $debug;
819 $type[$typeno] = "$prefix.$fieldname" unless defined $type[$typeno];
821 local($name) = "$prefix.$fieldname";
823 print "anon ".($isastruct{$name}) ? "struct":"union"." for $prefix.$fieldname\n" if $debug;
824 $type[$typeno] = "$prefix.$fieldname";
825 $_ = &sdecl("$prefix.$fieldname", $_, $start+$offset);
826 $start = $start{$name};
827 $length = $sizeof{$name};
830 warn "can't grok stab for $name ($_) in line $line ";
834 &panic("no length for $prefix.$fieldname") unless $length;
835 $struct{$name} .= join(',', $fieldname, $typeno, $scripts, $start, $length) . ';';
837 if (s/;\d*,(\d+),(\d+);//) {
838 local($start, $size) = ($1, $2);
839 $sizeof{$prefix} = $size;
840 print "start of $prefix is $start, size of $sizeof{$prefix}\n" if $debug;
841 $start{$prefix} = $start;
854 for $i (0 .. $#type) {
855 next unless defined $type[$i];
858 print "type[$i] $type[$i]\n" if $debug;
861 print "type[$i] $_ ==> " if $debug;
862 s/^(\d+)(\**)\&\*(\**)/"$2($3".&type($1) . ')()'/e;
863 s/^(\d+)\&/&type($1)/e;
864 s/^(\d+)/&type($1)/e;
865 s/(\*+)([^*]+)(\*+)/$1$3$2/;
866 s/\((\*+)(\w+)(\*+)\)/$3($1$2)/;
867 s/^(\d+)([\*\[].*)/&type($1).$2/e;
868 #s/(\d+)(\*|(\[[\[\]\d\*]+]\])+)/&type($1).$2/ge;
870 print "$_\n" if $debug;
873 sub type { &psou($type[$_[0]] || "<UNDEFINED>"); }
875 sub adjust_start_addrs {
876 for (sort keys %start) {
877 ($basename = $_) =~ s/\.[^.]+$//;
878 $start{$_} += $start{$basename};
879 print "start: $_ @ $start{$_}\n" if $debug;
884 local($what, $_) = @_;
885 /u/ && $isaunion{$what}++;
886 /s/ && $isastruct{$what}++;
892 if ($isaunion{$what}) {
894 } elsif ($isastruct{$what}) {
907 1 while s/(\w) \1/$1$1/g;
909 # i wanna say this, but perl resists my efforts:
910 # s/(\w)(\1+)/$2 . length($1)/ge;
919 sub buildscrunchlist {
920 $scrunch_code = "sub quick_scrunch {\n";
921 for (values %intrinsics) {
922 $scrunch_code .= "\ts/($_{2,})/'$_' . length(\$1)/ge;\n";
924 $scrunch_code .= "}\n";
925 print "$scrunch_code" if $debug;
927 &panic("can't eval scrunch_code $@ \nscrunch_code") if $@;
935 &panic("why do you care?") unless $perl;
937 if ($mytype =~ s/(\[\d+\])+$//) {
941 if ($mytype =~ /\*/) {
942 $fmt = $template{'pointer'};
944 elsif (defined $template{$mytype}) {
945 $fmt = $template{$mytype};
947 elsif (defined $struct{$mytype}) {
948 if (!defined $template{&psou($mytype)}) {
949 &build_template($mytype) unless $mytype eq $name;
951 elsif ($template{&psou($mytype)} !~ /\$$/) {
952 #warn "incomplete template for $mytype\n";
954 $fmt = $template{&psou($mytype)} || '?';
957 warn "unknown fmt for $mytype\n";
964 sub compute_intrinsics {
965 local($TMP) = "/tmp/c2ph-i.$$.c";
966 open (TMP, ">$TMP") || die "can't open $TMP: $!";
969 print STDERR "computing intrinsic sizes: " if $trace;
975 char *mask = "%d %s\n";
978 for $type (@intrinsics) {
979 next if $type eq 'void';
981 printf(mask,sizeof($type), "$type");
986 printf(mask,sizeof(char *), "pointer");
993 open(PIPE, "cd /tmp && $CC $TMP && /tmp/a.out|");
997 print "intrinsic $_[1] is size $_[0]\n" if $debug;
998 $sizeof{$_[1]} = $_[0];
999 $intrinsics{$_[1]} = $template{$_[0]};
1001 close(PIPE) || die "couldn't read intrinsics!";
1002 unlink($TMP, '/tmp/a.out');
1003 print STDERR "done\n" if $trace;
1013 &panic("$_: $@") if $@;
1018 print STDERR "@_\n" if $trace;
1022 sub build_template {
1025 &panic("already got a template for $name") if defined $template{$name};
1027 local($build_templates) = 1;
1029 local($lparen) = '(' x $build_recursed;
1030 local($rparen) = ')' x $build_recursed;
1032 print STDERR "$lparen$name$rparen " if $trace;
1034 &pstruct($name,$name,0);
1035 print STDERR "TEMPLATE for $name is ", $template{&psou($name)}, "\n" if $debug;
1044 print "\npanic: @_\n";
1046 exit 1 if $] <= 4.003; # caller broken
1049 local($p,$f,$l,$s,$h,$a,@a,@sub);
1050 for ($i = 0; ($p,$f,$l,$s,$h,$w) = caller($i); $i++) {
1053 if (/^StB\000/ && length($_) == length($_main{'_main'})) {
1054 $_ = sprintf("%s",$_);
1058 s/([^\0]*)/'$1'/ unless /^-?[\d.]+$/;
1059 s/([\200-\377])/sprintf("M-%c",ord($1)&0177)/eg;
1060 s/([\0-\37\177])/sprintf("^%c",ord($1)^64)/eg;
1063 $w = $w ? '@ = ' : '$ = ';
1064 $a = $h ? '(' . join(', ', @a) . ')' : '';
1065 push(@sub, "$w&$s$a from file $f line $l\n");
1068 for ($i=0; $i <= $#sub; $i++) {
1077 local($last) = -1e8;
1081 while (defined($num = shift)) {
1082 if ($num == ($last + 1)) {
1083 $string .= $seq unless $inseq++;
1087 $string .= $last unless $last == -1e8;
1090 $string .= ',' if defined $string;
1095 $string .= $last if $inseq && $last != -e18;