summaryrefslogtreecommitdiff
path: root/pp_pack.c
diff options
context:
space:
mode:
authorTon Hospel <perl5-porters@ton.iguana.be>2005-03-19 22:00:45 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2005-03-21 10:27:44 +0000
commit246f24af48839a0c276d6836d932a864d54afe73 (patch)
tree720117a6bd27a8543d8bf6424de90c20f7f758fb /pp_pack.c
parentf1aa04aa98e25c473fc39871251cb722556cefa9 (diff)
downloadperl-246f24af48839a0c276d6836d932a864d54afe73.tar.gz
pack / for general types
Message-Id: <d1i7ed$62c$1@post.home.lunix> Allow "len/format" to work for any format type, not just strings. p4raw-id: //depot/perl@24052
Diffstat (limited to 'pp_pack.c')
-rw-r--r--pp_pack.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/pp_pack.c b/pp_pack.c
index e62f56d1e4..1b56392239 100644
--- a/pp_pack.c
+++ b/pp_pack.c
@@ -2471,13 +2471,26 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist )
/* Look ahead for next symbol. Do we have code/code? */
lookahead = *symptr;
found = next_symbol(&lookahead);
- if ( symptr->flags & FLAG_SLASH ) {
+ if (symptr->flags & FLAG_SLASH) {
+ IV count;
if (!found) Perl_croak(aTHX_ "Code missing after '/' in pack");
- if ( 0 == strchr( "aAZ", lookahead.code ) ||
- e_star != lookahead.howlen )
- Perl_croak(aTHX_ "'/' must be followed by 'a*', 'A*' or 'Z*' in pack");
- lengthcode =
- sv_2mortal(newSViv((items > 0 ? DO_UTF8(*beglist) ? sv_len_utf8(*beglist) : sv_len(*beglist) : 0) + (lookahead.code == 'Z' ? 1 : 0)));
+ if (strchr("aAZ", lookahead.code)) {
+ if (lookahead.howlen == e_number) count = lookahead.length;
+ else {
+ if (items > 0)
+ count = DO_UTF8(*beglist) ?
+ sv_len_utf8(*beglist) : sv_len(*beglist);
+ else count = 0;
+ if (lookahead.code == 'Z') count++;
+ }
+ } else {
+ if (lookahead.howlen == e_number && lookahead.length < items)
+ count = lookahead.length;
+ else count = items;
+ }
+ lookahead.howlen = e_number;
+ lookahead.length = count;
+ lengthcode = sv_2mortal(newSViv(count));
}
/* Code inside the switch must take care to properly update