summaryrefslogtreecommitdiff
path: root/x2p
diff options
context:
space:
mode:
authorLarry Wall <larry@wall.org>1988-06-05 00:00:00 +0000
committerLarry Wall <larry@wall.org>1988-06-05 00:00:00 +0000
commit378cc40b38293ffc7298c6a7ed3cd740ad79be52 (patch)
tree87bedf9adc5c88847a2e2d85963df5f94435aaf5 /x2p
parenta4de7c03d0bdc29d9d3a18abad4ac2628182ed7b (diff)
downloadperl-378cc40b38293ffc7298c6a7ed3cd740ad79be52.tar.gz
perl 2.0 (no announcement message available)perl-2.0
Some of the enhancements from Perl1 included: * New regexp routines derived from Henry Spencer's. o Support for /(foo|bar)/. o Support for /(foo)*/ and /(foo)+/. o \s for whitespace, \S for non-, \d for digit, \D nondigit * Local variables in blocks, subroutines and evals. * Recursive subroutine calls are now supported. * Array values may now be interpolated into lists: unlink 'foo', 'bar', @trashcan, 'tmp'; * File globbing. * Use of <> in array contexts returns the whole file or glob list. * New iterator for normal arrays, foreach, that allows both read and write. * Ability to open pipe to a forked off script for secure pipes in setuid scripts. * File inclusion via do 'foo.pl'; * More file tests, including -t to see if, for instance, stdin is a terminal. File tests now behave in a more correct manner. You can do file tests on filehandles as well as filenames. The special filetests -T and -B test a file to see if it's text or binary. * An eof can now be used on each file of the <> input for such purposes as resetting the line numbers or appending to each file of an inplace edit. * Assignments can now function as lvalues, so you can say things like ($HOST = $host) =~ tr/a-z/A-Z/; ($obj = $src) =~ s/\.c$/.o/; * You can now do certain file operations with a variable which holds the name of a filehandle, e.g. open(++$incl,$includefilename); $foo = <$incl>; * Warnings are now available (with -w) on use of uninitialized variables and on identifiers that are mentioned only once, and on reference to various undefined things. * There is now a wait operator. * There is now a sort operator. * The manual is now not lying when it says that perl is generally faster than sed. I hope.
Diffstat (limited to 'x2p')
-rw-r--r--x2p/EXTERN.h6
-rw-r--r--x2p/INTERN.h6
-rw-r--r--x2p/Makefile.SH26
-rw-r--r--x2p/a2p.h17
-rw-r--r--x2p/a2p.man14
-rw-r--r--x2p/a2p.y83
-rw-r--r--x2p/a2py.c81
-rw-r--r--x2p/handy.h6
-rw-r--r--x2p/hash.c6
-rw-r--r--x2p/hash.h6
-rw-r--r--x2p/s2p39
-rw-r--r--x2p/s2p.man14
-rw-r--r--x2p/str.c19
-rw-r--r--x2p/str.h6
-rw-r--r--x2p/util.c17
-rw-r--r--x2p/util.h6
-rw-r--r--x2p/walk.c84
17 files changed, 256 insertions, 180 deletions
diff --git a/x2p/EXTERN.h b/x2p/EXTERN.h
index d0e248160a..66793aff0f 100644
--- a/x2p/EXTERN.h
+++ b/x2p/EXTERN.h
@@ -1,8 +1,8 @@
-/* $Header: EXTERN.h,v 1.0 87/12/18 13:06:44 root Exp $
+/* $Header: EXTERN.h,v 2.0 88/06/05 00:15:24 root Exp $
*
* $Log: EXTERN.h,v $
- * Revision 1.0 87/12/18 13:06:44 root
- * Initial revision
+ * Revision 2.0 88/06/05 00:15:24 root
+ * Baseline version 2.0.
*
*/
diff --git a/x2p/INTERN.h b/x2p/INTERN.h
index 76c51c5df8..42e029d24f 100644
--- a/x2p/INTERN.h
+++ b/x2p/INTERN.h
@@ -1,8 +1,8 @@
-/* $Header: INTERN.h,v 1.0 87/12/18 13:06:48 root Exp $
+/* $Header: INTERN.h,v 2.0 88/06/05 00:15:27 root Exp $
*
* $Log: INTERN.h,v $
- * Revision 1.0 87/12/18 13:06:48 root
- * Initial revision
+ * Revision 2.0 88/06/05 00:15:27 root
+ * Baseline version 2.0.
*
*/
diff --git a/x2p/Makefile.SH b/x2p/Makefile.SH
index 17447db1f6..a00ee89c79 100644
--- a/x2p/Makefile.SH
+++ b/x2p/Makefile.SH
@@ -6,7 +6,7 @@ case $CONFIG in
ln ../../../config.sh . || \
(echo "Can't find config.sh."; exit 1)
fi
- . config.sh
+ . ./config.sh
;;
esac
case "$0" in
@@ -18,14 +18,11 @@ case "$mallocsrc" in
esac
echo "Extracting x2p/Makefile (with variable substitutions)"
cat >Makefile <<!GROK!THIS!
-# $Header: Makefile.SH,v 1.0.1.1 88/01/26 14:15:24 root Exp $
+# $Header: Makefile.SH,v 2.0 88/06/05 00:15:31 root Exp $
#
# $Log: Makefile.SH,v $
-# Revision 1.0.1.1 88/01/26 14:15:24 root
-# Added mallocsrc stuff.
-#
-# Revision 1.0 87/12/18 17:50:17 root
-# Initial revision
+# Revision 2.0 88/06/05 00:15:31 root
+# Baseline version 2.0.
#
#
@@ -79,11 +76,11 @@ a2p: $(obj) a2p.o
$(CC) $(LDFLAGS) $(LARGE) $(obj) a2p.o $(libs) -o a2p
a2p.c: a2p.y
- @ echo Expect 107 shift/reduce errors...
+ @ echo Expect 103 shift/reduce errors...
yacc a2p.y
mv y.tab.c a2p.c
-a2p.o: a2p.c a2py.c a2p.h EXTERN.h util.h INTERN.h handy.h
+a2p.o: a2p.c a2py.c a2p.h EXTERN.h util.h INTERN.h handy.h ../config.h
$(CC) -c $(CFLAGS) $(LARGE) a2p.c
# if a .h file depends on another .h file...
@@ -92,23 +89,22 @@ $(h):
install: a2p s2p
# won't work with csh
export PATH || exit 1
- - mv $(bin)/a2p $(bin)/a2p.old
+ - mv $(bin)/a2p $(bin)/a2p.old 2>/dev/null
- mv $(bin)/s2p $(bin)/s2p.old
- if test `pwd` != $(bin); then cp $(public) $(bin); fi
cd $(bin); \
for pub in $(public); do \
-chmod 755 `basename $$pub`; \
+chmod +x `basename $$pub`; \
done
- - test $(bin) = /bin || rm -f /bin/a2p
-# chmod 755 makedir
-# - makedir `filexp $(lib)`
+# chmod +x makedir
+# - ./makedir `filexp $(lib)`
# - \
#if test `pwd` != `filexp $(lib)`; then \
#cp $(private) `filexp $(lib)`; \
#fi
# cd `filexp $(lib)`; \
#for priv in $(private); do \
-#chmod 755 `basename $$priv`; \
+#chmod +x `basename $$priv`; \
#done
- if test `pwd` != $(mansrc); then \
for page in $(manpages); do \
diff --git a/x2p/a2p.h b/x2p/a2p.h
index b7bc1f19c9..a805e79a90 100644
--- a/x2p/a2p.h
+++ b/x2p/a2p.h
@@ -1,14 +1,8 @@
-/* $Header: a2p.h,v 1.0.1.2 88/02/01 17:33:40 root Exp $
+/* $Header: a2p.h,v 2.0 88/06/05 00:15:33 root Exp $
*
* $Log: a2p.h,v $
- * Revision 1.0.1.2 88/02/01 17:33:40 root
- * patch12: forgot to fix #define YYDEBUG; bug in a2p.
- *
- * Revision 1.0.1.1 88/01/26 09:52:30 root
- * patch 5: a2p didn't use config.h.
- *
- * Revision 1.0 87/12/18 13:06:58 root
- * Initial revision
+ * Revision 2.0 88/06/05 00:15:33 root
+ * Baseline version 2.0.
*
*/
@@ -182,11 +176,6 @@ EXT int mop INIT(1);
#include <stdio.h>
#include <ctype.h>
-#include <setjmp.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <time.h>
-#include <sys/times.h>
typedef struct string STR;
typedef struct htbl HASH;
diff --git a/x2p/a2p.man b/x2p/a2p.man
index d367526893..858ee53272 100644
--- a/x2p/a2p.man
+++ b/x2p/a2p.man
@@ -1,9 +1,9 @@
.rn '' }`
-''' $Header: a2p.man,v 1.0 87/12/18 17:23:56 root Exp $
+''' $Header: a2p.man,v 2.0 88/06/05 00:15:36 root Exp $
'''
''' $Log: a2p.man,v $
-''' Revision 1.0 87/12/18 17:23:56 root
-''' Initial revision
+''' Revision 2.0 88/06/05 00:15:36 root
+''' Baseline version 2.0.
'''
'''
.de Sh
@@ -28,11 +28,11 @@
''' string Tr holds user defined translation string.
''' Bell System Logo is used as a dummy character.
'''
-.tr \(bs-|\(bv\*(Tr
+.tr \(*W-|\(bv\*(Tr
.ie n \{\
-.ds -- \(bs-
-.if (\n(.H=4u)&(1m=24u) .ds -- \(bs\h'-12u'\(bs\h'-12u'-\" diablo 10 pitch
-.if (\n(.H=4u)&(1m=20u) .ds -- \(bs\h'-12u'\(bs\h'-8u'-\" diablo 12 pitch
+.ds -- \(*W-
+.if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
+.if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
.ds L" ""
.ds R" ""
.ds L' '
diff --git a/x2p/a2p.y b/x2p/a2p.y
index 15484d2f3b..d5c7149d97 100644
--- a/x2p/a2p.y
+++ b/x2p/a2p.y
@@ -1,9 +1,9 @@
%{
-/* $Header: a2p.y,v 1.0 87/12/18 13:07:05 root Exp $
+/* $Header: a2p.y,v 2.0 88/06/05 00:15:38 root Exp $
*
* $Log: a2p.y,v $
- * Revision 1.0 87/12/18 13:07:05 root
- * Initial revision
+ * Revision 2.0 88/06/05 00:15:38 root
+ * Baseline version 2.0.
*
*/
@@ -42,14 +42,14 @@ program : junk begin hunks end
{ root = oper4(OPROG,$1,$2,$3,$4); }
;
-begin : BEGIN '{' states '}' junk
- { $$ = oper2(OJUNK,$3,$5); in_begin = FALSE; }
+begin : BEGIN '{' maybe states '}' junk
+ { $$ = oper3(OJUNK,$3,$4,$6); in_begin = FALSE; }
| /* NULL */
{ $$ = Nullop; }
;
-end : END '{' states '}'
- { $$ = $3; }
+end : END '{' maybe states '}'
+ { $$ = oper2(OJUNK,$3,$4); }
| end NEWLINE
{ $$ = $1; }
| /* NULL */
@@ -64,10 +64,10 @@ hunks : hunks hunk junk
hunk : patpat
{ $$ = oper1(OHUNK,$1); need_entire = TRUE; }
- | patpat '{' states '}'
- { $$ = oper2(OHUNK,$1,$3); }
- | '{' states '}'
- { $$ = oper2(OHUNK,Nullop,$2); }
+ | patpat '{' maybe states '}'
+ { $$ = oper2(OHUNK,$1,oper2(OJUNK,$3,$4)); }
+ | '{' maybe states '}'
+ { $$ = oper2(OHUNK,Nullop,oper2(OJUNK,$2,$3)); }
;
patpat : pat
@@ -118,7 +118,7 @@ rel : expr RELOP expr
;
match : expr MATCHOP REGEX
- { $$ = oper3(OMATCHOP,$2,$1,$3); }
+ { $$ = oper3(OMATCHOP,$2,$1,oper1(OREGEX,$3)); }
| '(' match ')'
{ $$ = oper1(OMPAREN,$2); }
;
@@ -198,14 +198,6 @@ variable: NUMBER
{ $$ = oper1(OVFLD,$2); }
;
-maybe : NEWLINE
- { $$ = oper0(ONEWLINE); }
- | /* NULL */
- { $$ = Nullop; }
- | COMMENT
- { $$ = oper1(OCOMMENT,$1); }
- ;
-
print_list
: expr
| clist
@@ -237,15 +229,27 @@ hunksep : ';'
{ $$ = oper1(OCOMMENT,$1); }
;
-separator
- : ';'
- { $$ = oper0(OSEMICOLON); }
- | SEMINEW
- { $$ = oper0(OSNEWLINE); }
- | NEWLINE
- { $$ = oper0(OSNEWLINE); }
+maybe : maybe nlstuff
+ { $$ = oper2(OJUNK,$1,$2); }
+ | /* NULL */
+ { $$ = Nullop; }
+ ;
+
+nlstuff : NEWLINE
+ { $$ = oper0(ONEWLINE); }
| COMMENT
- { $$ = oper1(OSCOMMENT,$1); }
+ { $$ = oper1(OCOMMENT,$1); }
+ ;
+
+separator
+ : ';' maybe
+ { $$ = oper2(OJUNK,oper0(OSEMICOLON),$2); }
+ | SEMINEW maybe
+ { $$ = oper2(OJUNK,oper0(OSNEWLINE),$2); }
+ | NEWLINE maybe
+ { $$ = oper2(OJUNK,oper0(OSNEWLINE),$2); }
+ | COMMENT maybe
+ { $$ = oper2(OJUNK,oper1(OSCOMMENT,$1),$2); }
;
states : states statement
@@ -255,11 +259,20 @@ states : states statement
;
statement
- : simple separator
- { $$ = oper2(OSTATE,$1,$2); }
+ : simple separator maybe
+ { $$ = oper2(OJUNK,oper2(OSTATE,$1,$2),$3); }
+ | ';' maybe
+ { $$ = oper2(OSTATE,Nullop,oper2(OJUNK,oper0(OSEMICOLON),$2)); }
+ | SEMINEW maybe
+ { $$ = oper2(OSTATE,Nullop,oper2(OJUNK,oper0(OSNEWLINE),$2)); }
| compound
;
+simpnull: simple
+ | /* NULL */
+ { $$ = Nullop; }
+ ;
+
simple
: expr
| PRINT print_list redir expr
@@ -292,8 +305,6 @@ simple
{ $$ = oper1(OEXIT,$2); }
| CONTINUE
{ $$ = oper0(OCONTINUE); }
- | /* NULL */
- { $$ = Nullop; }
;
redir : RELOP
@@ -311,14 +322,14 @@ compound
{ $$ = oper3(OIF,$3,bl($6,$5),bl($9,$8)); }
| WHILE '(' cond ')' maybe statement
{ $$ = oper2(OWHILE,$3,bl($6,$5)); }
- | FOR '(' simple ';' cond ';' simple ')' maybe statement
+ | FOR '(' simpnull ';' cond ';' simpnull ')' maybe statement
{ $$ = oper4(OFOR,$3,$5,$7,bl($10,$9)); }
- | FOR '(' simple ';' ';' simple ')' maybe statement
+ | FOR '(' simpnull ';' ';' simpnull ')' maybe statement
{ $$ = oper4(OFOR,$3,string("",0),$6,bl($9,$8)); }
| FOR '(' VAR IN VAR ')' maybe statement
{ $$ = oper3(OFORIN,$3,$5,bl($8,$7)); }
- | '{' states '}'
- { $$ = oper1(OBLOCK,$2); }
+ | '{' maybe states '}' maybe
+ { $$ = oper3(OBLOCK,oper2(OJUNK,$2,$3),Nullop,$5); }
;
%%
diff --git a/x2p/a2py.c b/x2p/a2py.c
index c99504046a..3adbd65fd3 100644
--- a/x2p/a2py.c
+++ b/x2p/a2py.c
@@ -1,11 +1,8 @@
-/* $Header: a2py.c,v 1.0.1.1 88/01/28 11:07:08 root Exp $
+/* $Header: a2py.c,v 2.0 88/06/05 00:15:41 root Exp $
*
* $Log: a2py.c,v $
- * Revision 1.0.1.1 88/01/28 11:07:08 root
- * patch8: added support for FOO=bar switches using eval.
- *
- * Revision 1.0 87/12/18 17:50:33 root
- * Initial revision
+ * Revision 2.0 88/06/05 00:15:41 root
+ * Baseline version 2.0.
*
*/
@@ -14,6 +11,8 @@ char *index();
char *filename;
+int checkers = 0;
+
main(argc,argv,env)
register int argc;
register char **argv;
@@ -116,7 +115,10 @@ register char **env;
/* second pass to produce new program */
tmpstr = walk(0,0,root,&i);
- str = str_make("#!/bin/perl\n\n");
+ str = str_make("#!/usr/bin/perl\neval \"exec /usr/bin/perl -S $0 $*\"\n\
+ if $running_under_some_shell;\n\
+ # this emulates #! processing on NIH machines.\n\
+ # (remove #! line above if indigestible)\n\n");
str_cat(str,
"eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift;\n");
str_cat(str,
@@ -133,6 +135,13 @@ register char **env;
#endif
fixup(str);
putlines(str);
+ if (checkers) {
+ fprintf(stderr,
+ "Please check my work on the %d line%s I've marked with \"#???\".\n",
+ checkers, checkers == 1 ? "" : "s" );
+ fprintf(stderr,
+ "The operation I've selected may be wrong for the operand types.\n");
+ }
exit(0);
}
@@ -214,6 +223,7 @@ yylex()
XTERM(tmp);
case '~':
s++;
+ yylval = string("~",1);
XTERM(MATCHOP);
case '+':
case '-':
@@ -284,6 +294,10 @@ yylex()
case '>':
s++;
tmp = *s++;
+ if (tmp == '>') {
+ yylval = string(">>",2);
+ XTERM(GRGR);
+ }
if (tmp == '=') {
yylval = string(">=",2);
XTERM(RELOP);
@@ -537,7 +551,31 @@ register char *s;
default:
fatal("Search pattern not found:\n%s",str_get(linestr));
}
- s = cpytill(tokenbuf,s,s[-1]);
+
+ d = tokenbuf;
+ for (; *s; s++,d++) {
+ if (*s == '\\') {
+ if (s[1] == '/')
+ *d++ = *s++;
+ else if (s[1] == '\\')
+ *d++ = *s++;
+ }
+ else if (*s == '[') {
+ *d++ = *s++;
+ do {
+ if (*s == '\\' && s[1])
+ *d++ = *s++;
+ if (*s == '/' || (*s == '-' && s[1] == ']'))
+ *d++ = '\\';
+ *d++ = *s++;
+ } while (*s && *s != ']');
+ }
+ else if (*s == '/')
+ break;
+ *d = *s;
+ }
+ *d = '\0';
+
if (!*s)
fatal("Search pattern not terminated:\n%s",str_get(linestr));
s++;
@@ -562,18 +600,22 @@ register char *s;
case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9': case '0' : case '.':
d = tokenbuf;
- while (isdigit(*s) || *s == '_')
- *d++ = *s++;
- if (*s == '.' && index("0123456789eE",s[1]))
- *d++ = *s++;
- while (isdigit(*s) || *s == '_')
- *d++ = *s++;
- if (index("eE",*s) && index("+-0123456789",s[1]))
+ while (isdigit(*s)) {
*d++ = *s++;
- if (*s == '+' || *s == '-')
+ }
+ if (*s == '.' && index("0123456789eE",s[1])) {
*d++ = *s++;
- while (isdigit(*s))
+ while (isdigit(*s)) {
+ *d++ = *s++;
+ }
+ }
+ if (index("eE",*s) && index("+-0123456789",s[1])) {
*d++ = *s++;
+ if (*s == '+' || *s == '-')
+ *d++ = *s++;
+ while (isdigit(*s))
+ *d++ = *s++;
+ }
*d = '\0';
yylval = string(tokenbuf,0);
break;
@@ -728,7 +770,7 @@ int maybe;
return 0;
else if ((ops[arg].ival & 255) != OBLOCK)
return oper2(OBLOCK,arg,maybe);
- else if ((ops[arg].ival >> 8) != 2)
+ else if ((ops[arg].ival >> 8) < 2)
return oper2(OBLOCK,ops[arg+1].ival,maybe);
else
return arg;
@@ -841,12 +883,15 @@ putone()
if (*t == 127) {
*t = ' ';
strcpy(t+strlen(t)-1, "\t#???\n");
+ checkers++;
}
}
t = tokenbuf;
if (*t == '#') {
if (strnEQ(t,"#!/bin/awk",10) || strnEQ(t,"#! /bin/awk",11))
return;
+ if (strnEQ(t,"#!/usr/bin/awk",14) || strnEQ(t,"#! /usr/bin/awk",15))
+ return;
}
fputs(tokenbuf,stdout);
}
diff --git a/x2p/handy.h b/x2p/handy.h
index 441bb4350c..bc0d0d590d 100644
--- a/x2p/handy.h
+++ b/x2p/handy.h
@@ -1,8 +1,8 @@
-/* $Header: handy.h,v 1.0 87/12/18 13:07:15 root Exp $
+/* $Header: handy.h,v 2.0 88/06/05 00:15:47 root Exp $
*
* $Log: handy.h,v $
- * Revision 1.0 87/12/18 13:07:15 root
- * Initial revision
+ * Revision 2.0 88/06/05 00:15:47 root
+ * Baseline version 2.0.
*
*/
diff --git a/x2p/hash.c b/x2p/hash.c
index db32c4c5fe..38932efc49 100644
--- a/x2p/hash.c
+++ b/x2p/hash.c
@@ -1,8 +1,8 @@
-/* $Header: hash.c,v 1.0 87/12/18 13:07:18 root Exp $
+/* $Header: hash.c,v 2.0 88/06/05 00:15:50 root Exp $
*
* $Log: hash.c,v $
- * Revision 1.0 87/12/18 13:07:18 root
- * Initial revision
+ * Revision 2.0 88/06/05 00:15:50 root
+ * Baseline version 2.0.
*
*/
diff --git a/x2p/hash.h b/x2p/hash.h
index 06d803a12d..8d9029515a 100644
--- a/x2p/hash.h
+++ b/x2p/hash.h
@@ -1,8 +1,8 @@
-/* $Header: hash.h,v 1.0 87/12/18 13:07:23 root Exp $
+/* $Header: hash.h,v 2.0 88/06/05 00:15:52 root Exp $
*
* $Log: hash.h,v $
- * Revision 1.0 87/12/18 13:07:23 root
- * Initial revision
+ * Revision 2.0 88/06/05 00:15:52 root
+ * Baseline version 2.0.
*
*/
diff --git a/x2p/s2p b/x2p/s2p
index 6c50cd2a11..1b876c51ba 100644
--- a/x2p/s2p
+++ b/x2p/s2p
@@ -1,4 +1,12 @@
-#!/bin/perl
+#!/usr/bin/perl
+
+# $Header: s2p,v 2.0 88/06/05 00:15:55 root Exp $
+#
+# $Log: s2p,v $
+# Revision 2.0 88/06/05 00:15:55 root
+# Baseline version 2.0.
+#
+#
$indent = 4;
$shiftwidth = 4;
@@ -21,11 +29,11 @@ while ($ARGV[0] =~ '^-') {
$assumep++;
next;
}
- die "I don't recognize this switch: $_";
+ die "I don't recognize this switch: $_\n";
}
unless ($debug) {
- open(body,">/tmp/sperl$$") || do Die("Can't open temp file.");
+ open(body,">/tmp/sperl$$") || do Die("Can't open temp file");
}
if (!$assumen && !$assumep) {
@@ -37,7 +45,7 @@ if (!$assumen && !$assumep) {
$nflag++;
next;
}
- die "I don\'t recognize this switch: $_";
+ die "I don\'t recognize this switch: $_\\n";
}
';
@@ -127,11 +135,12 @@ line: while (<>) {
}
}
} else {
- do Die("Invalid second address at line $.: $_");
+ do Die("Invalid second address at line $.\n");
}
$addr1 .= " .. $addr2";
}
# a { to keep vi happy
+ s/^[ \t]+//;
if ($_ eq '}') {
$indent -= 4;
next;
@@ -220,7 +229,7 @@ continue {
close body;
unless ($debug) {
- open(head,">/tmp/sperl2$$") || do Die("Can't open temp file 2.\n");
+ open(head,">/tmp/sperl2$$.c") || do Die("Can't open temp file 2");
print head "#define PRINTIT\n" if ($printit);
print head "#define APPENDSEEN\n" if ($appendseen);
print head "#define TSEEN\n" if ($tseen);
@@ -228,15 +237,15 @@ unless ($debug) {
print head "#define ASSUMEN\n" if ($assumen);
print head "#define ASSUMEP\n" if ($assumep);
if ($opens) {print head "$opens\n";}
- open(body,"/tmp/sperl$$") || do Die("Can't reopen temp file.");
+ open(body,"/tmp/sperl$$") || do Die("Can't reopen temp file");
while (<body>) {
print head $_;
}
close head;
print "#!/bin/perl\n\n";
- open(body,"cc -E /tmp/sperl2$$ |") ||
- do Die("Can't reopen temp file.");
+ open(body,"cc -E /tmp/sperl2$$.c |") ||
+ do Die("Can't reopen temp file");
while (<body>) {
/^# [0-9]/ && next;
/^[ \t]*$/ && next;
@@ -245,10 +254,10 @@ unless ($debug) {
}
}
-`/bin/rm -f /tmp/sperl$$ /tmp/sperl2$$`;
+unlink "/tmp/sperl$$", "/tmp/sperl2$$";
sub Die {
- `/bin/rm -f /tmp/sperl$$ /tmp/sperl2$$`;
+ unlink "/tmp/sperl$$", "/tmp/sperl2$$";
die $_[0];
}
sub make_filehandle {
@@ -262,7 +271,7 @@ sub make_filehandle {
$_ = $first . $rest;
}
if (!$seen{$_}) {
- $opens .= "open($_,'>$fname') || die \"Can't create $fname.\";\n";
+ $opens .= "open($_,'>$fname') || die \"Can't create $fname\";\n";
}
$seen{$_} = $_;
}
@@ -398,12 +407,12 @@ ${space}next line;";
$len++;
}
}
- print "repl $repl end $end $_\n";
- do Die("Malformed substitution at line $.") unless $end;
+ do Die("Malformed substitution at line $.\n") unless $end;
$pat = substr($_, 0, $repl + 1);
$repl = substr($_, $repl + 1, $end - $repl - 1);
$end = substr($_, $end + 1, 1000);
$dol = '$';
+ $repl =~ s/\$/\\$/;
$repl =~ s'&'$&'g;
$repl =~ s/[\\]([0-9])/$dol$1/g;
$subst = "$pat$repl$delim";
@@ -417,7 +426,7 @@ ${space}next line;";
$end = '';
next;
}
- do Die("Unrecognized substitution command ($end) at line $.");
+ do Die("Unrecognized substitution command ($end) at line $.\n");
}
$_ = $subst . $cmd . ';';
next;
diff --git a/x2p/s2p.man b/x2p/s2p.man
index 6db8a8e7aa..a9d00aa93c 100644
--- a/x2p/s2p.man
+++ b/x2p/s2p.man
@@ -1,9 +1,9 @@
.rn '' }`
-''' $Header: s2p.man,v 1.0 87/12/18 17:37:16 root Exp $
+''' $Header: s2p.man,v 2.0 88/06/05 00:15:59 root Exp $
'''
''' $Log: s2p.man,v $
-''' Revision 1.0 87/12/18 17:37:16 root
-''' Initial revision
+''' Revision 2.0 88/06/05 00:15:59 root
+''' Baseline version 2.0.
'''
'''
.de Sh
@@ -28,11 +28,11 @@
''' string Tr holds user defined translation string.
''' Bell System Logo is used as a dummy character.
'''
-.tr \(bs-|\(bv\*(Tr
+.tr \(*W-|\(bv\*(Tr
.ie n \{\
-.ds -- \(bs-
-.if (\n(.H=4u)&(1m=24u) .ds -- \(bs\h'-12u'\(bs\h'-12u'-\" diablo 10 pitch
-.if (\n(.H=4u)&(1m=20u) .ds -- \(bs\h'-12u'\(bs\h'-8u'-\" diablo 12 pitch
+.ds -- \(*W-
+.if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
+.if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
.ds L" ""
.ds R" ""
.ds L' '
diff --git a/x2p/str.c b/x2p/str.c
index 5de045a3be..6aae90d484 100644
--- a/x2p/str.c
+++ b/x2p/str.c
@@ -1,8 +1,8 @@
-/* $Header: str.c,v 1.0 87/12/18 13:07:26 root Exp $
+/* $Header: str.c,v 2.0 88/06/05 00:16:02 root Exp $
*
* $Log: str.c,v $
- * Revision 1.0 87/12/18 13:07:26 root
- * Initial revision
+ * Revision 2.0 88/06/05 00:16:02 root
+ * Baseline version 2.0.
*
*/
@@ -281,7 +281,7 @@ register FILE *fp;
register char *bp; /* we're going to steal some values */
register int cnt; /* from the stdio struct and put EVERYTHING */
- register char *ptr; /* in the innermost loop into registers */
+ register STDCHAR *ptr; /* in the innermost loop into registers */
register char newline = '\n'; /* (assuming at least 6 registers) */
int i;
int bpx;
@@ -294,9 +294,14 @@ register FILE *fp;
bp = str->str_ptr; /* move these two too to registers */
ptr = fp->_ptr;
for (;;) {
- while (--cnt >= 0) { /* this */ /* eat */
- if ((*bp++ = *ptr++) == newline) /* really */ /* dust */
- goto thats_all_folks; /* screams */ /* sed :-) */
+ while (--cnt >= 0) {
+ if ((*bp++ = *ptr++) == newline)
+ if (bp <= str->str_ptr || bp[-2] != '\\')
+ goto thats_all_folks;
+ else {
+ line++;
+ bp -= 2;
+ }
}
fp->_cnt = cnt; /* deregisterize cnt and ptr */
diff --git a/x2p/str.h b/x2p/str.h
index cbb0c77759..93e4448892 100644
--- a/x2p/str.h
+++ b/x2p/str.h
@@ -1,8 +1,8 @@
-/* $Header: str.h,v 1.0 87/12/18 13:07:30 root Exp $
+/* $Header: str.h,v 2.0 88/06/05 00:16:05 root Exp $
*
* $Log: str.h,v $
- * Revision 1.0 87/12/18 13:07:30 root
- * Initial revision
+ * Revision 2.0 88/06/05 00:16:05 root
+ * Baseline version 2.0.
*
*/
diff --git a/x2p/util.c b/x2p/util.c
index 83adfc276b..0d98de807c 100644
--- a/x2p/util.c
+++ b/x2p/util.c
@@ -1,8 +1,8 @@
-/* $Header: util.c,v 1.0 87/12/18 13:07:34 root Exp $
+/* $Header: util.c,v 2.0 88/06/05 00:16:07 root Exp $
*
* $Log: util.c,v $
- * Revision 1.0 87/12/18 13:07:34 root
- * Initial revision
+ * Revision 2.0 88/06/05 00:16:07 root
+ * Baseline version 2.0.
*
*/
@@ -136,8 +136,12 @@ register char *to, *from;
register int delim;
{
for (; *from; from++,to++) {
- if (*from == '\\' && from[1] == delim)
- *to++ = *from++;
+ if (*from == '\\') {
+ if (from[1] == delim)
+ from++;
+ else if (from[1] == '\\')
+ *to++ = *from++;
+ }
else if (*from == delim)
break;
*to = *from;
@@ -146,13 +150,14 @@ register int delim;
return from;
}
+
char *
cpy2(to,from,delim)
register char *to, *from;
register int delim;
{
for (; *from; from++,to++) {
- if (*from == '\\' && from[1] == delim)
+ if (*from == '\\')
*to++ = *from++;
else if (*from == '$')
*to++ = '\\';
diff --git a/x2p/util.h b/x2p/util.h
index 6249549221..18cca4bb4e 100644
--- a/x2p/util.h
+++ b/x2p/util.h
@@ -1,8 +1,8 @@
-/* $Header: util.h,v 1.0 87/12/18 13:07:37 root Exp $
+/* $Header: util.h,v 2.0 88/06/05 00:16:10 root Exp $
*
* $Log: util.h,v $
- * Revision 1.0 87/12/18 13:07:37 root
- * Initial revision
+ * Revision 2.0 88/06/05 00:16:10 root
+ * Baseline version 2.0.
*
*/
diff --git a/x2p/walk.c b/x2p/walk.c
index 1659e45f2d..344581ea03 100644
--- a/x2p/walk.c
+++ b/x2p/walk.c
@@ -1,17 +1,8 @@
-/* $Header: walk.c,v 1.0.1.3 88/02/02 11:54:58 root Exp $
+/* $Header: walk.c,v 2.0 88/06/05 00:16:12 root Exp $
*
* $Log: walk.c,v $
- * Revision 1.0.1.3 88/02/02 11:54:58 root
- * patch14: got return value of each() backwards in translating 'for (a in b)'.
- *
- * Revision 1.0.1.2 88/02/01 17:34:05 root
- * patch12: made a2p take advantage of new awk-compatible split in perl.
- *
- * Revision 1.0.1.1 88/01/28 11:07:56 root
- * patch8: changed some misleading comments.
- *
- * Revision 1.0 87/12/18 13:07:40 root
- * Initial revision
+ * Revision 2.0 88/06/05 00:16:12 root
+ * Baseline version 2.0.
*
*/
@@ -22,7 +13,10 @@
bool exitval = FALSE;
bool realexit = FALSE;
+bool saw_getline = FALSE;
int maxtmp = 0;
+char *lparen;
+char *rparen;
STR *
walk(useval,level,node,numericptr)
@@ -132,6 +126,18 @@ int *numericptr;
}
if (exitval)
str_cat(str,"exit ExitValue;\n");
+ if (saw_getline) {
+ str_cat(str,"\nsub Getline {\n $_ = <>;\n");
+ tab(str,++level);
+ if (do_chop) {
+ str_cat(str,"chop;\t# strip record separator\n");
+ tab(str,level);
+ }
+ if (do_split)
+ emit_split(str,level);
+ fixtab(str,--level);
+ str_cat(str,"}\n");
+ }
if (do_fancy_opens) {
str_cat(str,"\n\
sub Pick {\n\
@@ -192,6 +198,8 @@ sub Pick {\n\
*d = *s;
}
*d = '\0';
+ for (d=tokenbuf; *d; d++)
+ *d += 128;
str_cat(str,tokenbuf);
str_free(tmpstr);
str_cat(str,"/");
@@ -447,14 +455,8 @@ sub Pick {\n\
break;
case OGETLINE:
str = str_new(0);
- str_set(str,"$_ = <>;\n");
- tab(str,level);
- if (do_chop) {
- str_cat(str,"chop;\t# strip record separator\n");
- tab(str,level);
- }
- if (do_split)
- emit_split(str,level);
+ str_set(str,"do Getline()");
+ saw_getline = TRUE;
break;
case OSPRINTF:
str = str_new(0);
@@ -543,14 +545,25 @@ sub Pick {\n\
case OSTR:
tmpstr = walk(1,level,ops[node+1].ival,&numarg);
s = "'";
- for (t = tmpstr->str_ptr; *t; t++) {
- if (*t == '\\' || *t == '\'')
+ for (t = tmpstr->str_ptr, d=tokenbuf; *t; d++,t++) {
+ if (*t == '\'')
+ s = "\"";
+ else if (*t == '\\') {
s = "\"";
- *t += 128;
+ *d++ = *t++ + 128;
+ switch (*t) {
+ case '\\': case '"': case 'n': case 't':
+ break;
+ default: /* hide this from perl */
+ *d++ = '\\' + 128;
+ }
+ }
+ *d = *t + 128;
}
+ *d = '\0';
str = str_new(0);
str_set(str,s);
- str_scat(str,tmpstr);
+ str_cat(str,tokenbuf);
str_free(tmpstr);
str_cat(str,s);
break;
@@ -683,6 +696,8 @@ sub Pick {\n\
break;
case OPRINTF:
case OPRINT:
+ lparen = ""; /* set to parens if necessary */
+ rparen = "";
str = str_new(0);
if (len == 3) { /* output redirection */
tmpstr = walk(1,level,ops[node+3].ival,&numarg);
@@ -732,10 +747,13 @@ sub Pick {\n\
*tokenbuf = '\0';
str_free(tmpstr);
str_free(tmp2str);
+ lparen = "(";
+ rparen = ")";
}
}
else
strcpy(tokenbuf,"stdout");
+ str_cat(str,lparen); /* may be null */
if (type == OPRINTF)
str_cat(str,"printf");
else
@@ -774,6 +792,7 @@ sub Pick {\n\
else {
str_cat(str," $_");
}
+ str_cat(str,rparen); /* may be null */
str_free(tmpstr);
break;
case OLENGTH:
@@ -947,18 +966,11 @@ sub Pick {\n\
str_cat(str,"[]");
tmp2str = hfetch(symtab,str->str_ptr);
if (tmp2str && atoi(tmp2str->str_ptr)) {
- maxtmp++;
fstr=walk(1,level,ops[node+1].ival,&numarg);
sprintf(tokenbuf,
- "for ($T_%d = 1; ($%s = $%s[$T_%d]) || $T_%d <= $#%s; $T_%d++)%c",
- maxtmp,
+ "foreach $%s (@%s) ",
fstr->str_ptr,
- tmpstr->str_ptr,
- maxtmp,
- maxtmp,
- tmpstr->str_ptr,
- maxtmp,
- 0377);
+ tmpstr->str_ptr);
str_set(str,tokenbuf);
str_free(fstr);
str_scat(str,fstr=walk(0,level,ops[node+3].ival,&numarg));
@@ -979,7 +991,7 @@ sub Pick {\n\
case OBLOCK:
str = str_new(0);
str_set(str,"{");
- if (len == 2) {
+ if (len >= 2 && ops[node+2].ival) {
str_scat(str,fstr=walk(0,level,ops[node+2].ival,&numarg));
str_free(fstr);
}
@@ -990,6 +1002,10 @@ sub Pick {\n\
fixtab(str,--level);
str_cat(str,"}\n");
tab(str,level);
+ if (len >= 3) {
+ str_scat(str,fstr=walk(0,level,ops[node+3].ival,&numarg));
+ str_free(fstr);
+ }
break;
default:
def: