diff options
author | Larry Wall <larry@wall.org> | 1988-06-05 00:00:00 +0000 |
---|---|---|
committer | Larry Wall <larry@wall.org> | 1988-06-05 00:00:00 +0000 |
commit | 378cc40b38293ffc7298c6a7ed3cd740ad79be52 (patch) | |
tree | 87bedf9adc5c88847a2e2d85963df5f94435aaf5 /array.c | |
parent | a4de7c03d0bdc29d9d3a18abad4ac2628182ed7b (diff) | |
download | perl-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 'array.c')
-rw-r--r-- | array.c | 63 |
1 files changed, 47 insertions, 16 deletions
@@ -1,16 +1,12 @@ -/* $Header: array.c,v 1.0 87/12/18 13:04:42 root Exp $ +/* $Header: array.c,v 2.0 88/06/05 00:08:17 root Exp $ * * $Log: array.c,v $ - * Revision 1.0 87/12/18 13:04:42 root - * Initial revision + * Revision 2.0 88/06/05 00:08:17 root + * Baseline version 2.0. * */ -#include <stdio.h> #include "EXTERN.h" -#include "handy.h" -#include "util.h" -#include "search.h" #include "perl.h" STR * @@ -18,7 +14,7 @@ afetch(ar,key) register ARRAY *ar; int key; { - if (key < 0 || key > ar->ary_max) + if (key < 0 || key > ar->ary_fill) return Nullstr; return ar->ary_array[key]; } @@ -42,8 +38,12 @@ STR *val; (newmax - ar->ary_max) * sizeof(STR*)); ar->ary_max = newmax; } - if (key > ar->ary_fill) - ar->ary_fill = key; + while (ar->ary_fill < key) { + if (++ar->ary_fill < key && ar->ary_array[ar->ary_fill] != Nullstr) { + str_free(ar->ary_array[ar->ary_fill]); + ar->ary_array[ar->ary_fill] = Nullstr; + } + } retval = (ar->ary_array[key] != Nullstr); if (retval) str_free(ar->ary_array[key]); @@ -67,18 +67,36 @@ int key; } ARRAY * -anew() +anew(stab) +STAB *stab; { register ARRAY *ar = (ARRAY*)safemalloc(sizeof(ARRAY)); ar->ary_array = (STR**) safemalloc(5 * sizeof(STR*)); + ar->ary_magic = str_new(0); + ar->ary_magic->str_link.str_magic = stab; ar->ary_fill = -1; + ar->ary_index = -1; ar->ary_max = 4; bzero((char*)ar->ary_array, 5 * sizeof(STR*)); return ar; } void +aclear(ar) +register ARRAY *ar; +{ + register int key; + + if (!ar) + return; + for (key = 0; key <= ar->ary_max; key++) + str_free(ar->ary_array[key]); + ar->ary_fill = -1; + bzero((char*)ar->ary_array, (ar->ary_max+1) * sizeof(STR*)); +} + +void afree(ar) register ARRAY *ar; { @@ -86,8 +104,9 @@ register ARRAY *ar; if (!ar) return; - for (key = 0; key <= ar->ary_fill; key++) + for (key = 0; key <= ar->ary_max; key++) str_free(ar->ary_array[key]); + str_free(ar->ary_magic); safefree((char*)ar->ary_array); safefree((char*)ar); } @@ -123,8 +142,8 @@ register int num; if (num <= 0) return; astore(ar,ar->ary_fill+num,(STR*)0); /* maybe extend array */ - sstr = ar->ary_array + ar->ary_fill; - dstr = sstr + num; + dstr = ar->ary_array + ar->ary_fill; + sstr = dstr - num; for (i = ar->ary_fill; i >= 0; i--) { *dstr-- = *sstr--; } @@ -146,11 +165,23 @@ register ARRAY *ar; return retval; } -long +int alen(ar) register ARRAY *ar; { - return (long)ar->ary_fill; + return ar->ary_fill; +} + +afill(ar, fill) +register ARRAY *ar; +int fill; +{ + if (fill < 0) + fill = -1; + if (fill <= ar->ary_max) + ar->ary_fill = fill; + else + astore(ar,fill,Nullstr); } void |