diff options
Diffstat (limited to 'x2p')
-rw-r--r-- | x2p/a2p.h | 25 | ||||
-rw-r--r-- | x2p/a2py.c | 14 | ||||
-rw-r--r-- | x2p/s2p.PL | 44 |
3 files changed, 52 insertions, 31 deletions
@@ -9,12 +9,37 @@ */ #define VOIDUSED 1 + +#ifdef WIN32 +#define _INC_WIN32_PERL5 /* kludge around win32 stdio layer */ +#endif + #ifdef VMS # include "config.h" #else # include "../config.h" #endif +#ifdef WIN32 +#undef USE_STDIO_PTR /* XXX fast gets won't work, must investigate */ +# ifndef STANDARD_C +# define STANDARD_C +# endif +# if defined(__BORLANDC__) +# pragma warn -ccc +# pragma warn -rch +# pragma warn -sig +# pragma warn -pia +# pragma warn -par +# pragma warn -aus +# pragma warn -use +# pragma warn -csu +# pragma warn -pro +# elif defined(_MSC_VER) +# elif defined(__MINGW32__) +# endif +#endif + #if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus) # define STANDARD_C 1 #endif diff --git a/x2p/a2py.c b/x2p/a2py.c index 202d5921e0..fefa81da7e 100644 --- a/x2p/a2py.c +++ b/x2p/a2py.c @@ -8,7 +8,7 @@ * $Log: a2py.c,v $ */ -#ifdef OS2 +#if defined(OS2) || defined(WIN32) #include "../patchlevel.h" #endif #include "util.h" @@ -26,7 +26,9 @@ int oper4(int type, int arg1, int arg2, int arg3, int arg4); int oper5(int type, int arg1, int arg2, int arg3, int arg4, int arg5); STR *walk(int useval, int level, register int node, int *numericptr, int minprec); -#ifdef OS2 +#if defined(OS2) || defined(WIN32) +static void usage(void); + static void usage() { @@ -86,9 +88,11 @@ main(register int argc, register char **argv, register char **env) case 0: break; default: - fatal("Unrecognized switch: %s\n",argv[0]); -#ifdef OS2 +#if defined(OS2) || defined(WIN32) + fprintf(stderr, "Unrecognized switch: %s\n",argv[0]); usage(); +#else + fatal("Unrecognized switch: %s\n",argv[0]); #endif } } @@ -97,7 +101,7 @@ main(register int argc, register char **argv, register char **env) /* open script */ if (argv[0] == Nullch) { -#ifdef OS2 +#if defined(OS2) || defined(WIN32) if ( isatty(fileno(stdin)) ) usage(); #endif diff --git a/x2p/s2p.PL b/x2p/s2p.PL index 73f67872de..fa0d567b6c 100644 --- a/x2p/s2p.PL +++ b/x2p/s2p.PL @@ -135,7 +135,7 @@ while ($ARGV[0] =~ /^-/) { } unless ($debug) { - open(BODY,">/tmp/sperl$$") || + open(BODY,"+>/tmp/sperl$$") || &Die("Can't open temp file: $!\n"); } @@ -343,26 +343,7 @@ print BODY &q(<<'EOT'); EOT } -close BODY; - unless ($debug) { - open(HEAD,">/tmp/sperl2$$.c") - || &Die("Can't open temp file 2: $!\n"); - print HEAD "#define PRINTIT\n" if $printit; - print HEAD "#define APPENDSEEN\n" if $appendseen; - print HEAD "#define TSEEN\n" if $tseen; - print HEAD "#define DSEEN\n" if $dseen; - print HEAD "#define ASSUMEN\n" if $assumen; - print HEAD "#define ASSUMEP\n" if $assumep; - print HEAD "#define TOPLABEL\n" if $toplabel; - print HEAD "#define SAWNEXT\n" if $sawnext; - if ($opens) {print HEAD "$opens\n";} - open(BODY,"/tmp/sperl$$") - || &Die("Can't reopen temp file: $!\n"); - while (<BODY>) { - print HEAD $_; - } - close HEAD; print &q(<<"EOT"); : $startperl @@ -370,11 +351,13 @@ unless ($debug) { : if \$running_under_some_shell; : EOT - open(BODY,"cc -E /tmp/sperl2$$.c |") || - &Die("Can't reopen temp file: $!\n"); + print"$opens\n" if $opens; + seek(BODY, 0, 0) || die "Can't rewind temp file: $!\n"; while (<BODY>) { - /^# [0-9]/ && next; /^[ \t]*$/ && next; + /^#ifdef (\w+)/ && ((${lc $1} || &skip), next); + /^#else/ && (&skip, next); + /^#endif/ && next; s/^<><>//; print; } @@ -384,8 +367,7 @@ EOT exit; sub Cleanup { - chdir "/tmp"; - unlink "sperl$$", "sperl2$$", "sperl2$$.c"; + unlink "/tmp/sperl$$"; } sub Die { &Cleanup; @@ -603,7 +585,6 @@ EOT $repl = substr($_, $repl+1, $end-$repl-1); $end = substr($_, $end + 1, 1000); &simplify($pat); - $dol = '$'; $subst = "$pat$repl$delim"; $cmd = ''; while ($end) { @@ -846,6 +827,17 @@ sub simplify { $_[0] =~ s/([\w\s!@#%^&-=,:;'"])\1\*/$1+/g; } +sub skip { + local($level) = 0; + + while(<BODY>) { + /^#ifdef/ && $level++; + /^#else/ && !$level && return; + /^#endif/ && !$level-- && return; + } + + die "Unterminated `#ifdef' conditional\n"; +} !NO!SUBS! close OUT or die "Can't close $file: $!"; |