Skip to content

Commit fde46ec

Browse files
committed
Use stack accumulation for GS1 wrapper input building
1 parent c8ef400 commit fde46ec

File tree

7 files changed

+86
-138
lines changed

7 files changed

+86
-138
lines changed

src/databarexpanded.ps.src

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
%
44
% vim: set sw=4 sts=4 et:
55
%
6-
% Copyright (c) 2004-2025 Terry Burton
6+
% Copyright (c) 2004-2026 Terry Burton
77
%
88
% $Id$
99
%
@@ -427,24 +427,18 @@ begin
427427
} ifelse
428428

429429
%
430-
% Append the remaining AI data
430+
% Append the remaining AI data using stack-based accumulation
431431
%
432+
mark gpf aload pop
432433
0 1 ais length 1 sub {
433434
/i exch def
434-
/ai ais i get def
435-
/val vals i get def
436-
gpf length ai length add val length add array
437-
dup 0 gpf putinterval
438-
dup gpf length ai [ exch {} forall ] putinterval
439-
dup gpf length ai length add val [ exch {} forall ] putinterval
440-
/gpf exch def
441-
i ais length 1 sub ne fncs i get and { % Append FNC1
442-
gpf length 1 add array
443-
dup 0 gpf putinterval
444-
dup gpf length fnc1 put
445-
/gpf exch def
435+
ais i get { } forall % Push AI characters
436+
vals i get { } forall % Push value characters
437+
i ais length 1 sub ne fncs i get and {
438+
fnc1 % Push FNC1 separator
446439
} if
447440
} for
441+
counttomark array astore /gpf exch def pop
448442

449443
%
450444
% Calculate the number of bits remaining to the next valid symbol size

src/gs1-128.ps.src

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
%
44
% vim: set sw=4 sts=4 et:
55
%
6-
% Copyright (c) 2004-2025 Terry Burton
6+
% Copyright (c) 2004-2026 Terry Burton
77
%
88
% $Id$
99
%
@@ -85,42 +85,34 @@ begin
8585
/ais exch def
8686

8787
%
88-
% Create the code128 data
88+
% Create the code128 data using stack-based accumulation
8989
%
9090
/fnc1 -1 def
91-
/c128 [ fnc1 ] def
91+
mark fnc1
9292
0 1 ais length 1 sub {
9393
/i exch def
94-
/ai ais i get def
95-
/val vals i get def
96-
c128 length ai length add val length add array
97-
dup 0 c128 putinterval
98-
dup c128 length ai [ exch {} forall ] putinterval
99-
dup c128 length ai length add val [ exch {} forall ] putinterval
100-
/c128 exch def
101-
i ais length 1 sub ne fncs i get and { % Append FNC1
102-
c128 length 1 add array
103-
dup 0 c128 putinterval
104-
dup c128 length fnc1 put
105-
/c128 exch def
94+
ais i get { } forall % Push AI characters
95+
vals i get { } forall % Push value characters
96+
i ais length 1 sub ne fncs i get and {
97+
fnc1 % Push FNC1 separator
10698
} if
10799
} for
100+
counttomark array astore /c128 exch def pop
108101

109102
%
110103
% Compose input to code128
111104
%
112105
/barcode c128 length 1 add 5 mul string def
113-
/i 0 def /j 0 def {
114-
i c128 length eq {exit} if
115-
c128 i get dup fnc1 eq {
106+
/j 0 def
107+
c128 {
108+
dup fnc1 eq {
116109
pop barcode j (^FNC1) putinterval
117-
/j j 4 add def
110+
/j j 5 add def
118111
} {
119112
barcode exch j exch put
113+
/j j 1 add def
120114
} ifelse
121-
/i i 1 add def
122-
/j j 1 add def
123-
} loop
115+
} forall
124116
linkagea linkagec or {
125117
barcode j linkagea {(^LNKA)} {(^LNKC)} ifelse putinterval
126118
/j j 5 add def

src/gs1-cc.ps.src

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -426,24 +426,18 @@ begin
426426
} if
427427

428428
%
429-
% Append the remaining AI data
429+
% Append the remaining AI data using stack-based accumulation
430430
%
431+
mark gpf aload pop
431432
0 1 ais length 1 sub {
432433
/i exch def
433-
/ai ais i get def
434-
/val vals i get def
435-
gpf length ai length add val length add array
436-
dup 0 gpf putinterval
437-
dup gpf length ai [ exch {} forall ] putinterval
438-
dup gpf length ai length add val [ exch {} forall ] putinterval
439-
/gpf exch def
440-
i ais length 1 sub ne fncs i get and { % Append FNC1
441-
gpf length 1 add array
442-
dup 0 gpf putinterval
443-
dup gpf length //gs1-cc.fnc1 put
444-
/gpf exch def
434+
ais i get { } forall % Push AI characters
435+
vals i get { } forall % Push value characters
436+
i ais length 1 sub ne fncs i get and {
437+
//gs1-cc.fnc1 % Push FNC1 separator
445438
} if
446439
} for
440+
counttomark array astore /gpf exch def pop
447441

448442
%
449443
% Calculate the number of bits remaining to the next valid symbol size

src/gs1datamatrix.ps.src

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
%
44
% vim: set sw=4 sts=4 et:
55
%
6-
% Copyright (c) 2004-2025 Terry Burton
6+
% Copyright (c) 2004-2026 Terry Burton
77
%
88
% $Id$
99
%
@@ -71,42 +71,34 @@ begin
7171
/ais exch def
7272

7373
%
74-
% Create the datamatrix data
74+
% Create the datamatrix data using stack-based accumulation
7575
%
7676
/fnc1 -1 def
77-
/dmtx [ fnc1 ] def
77+
mark fnc1
7878
0 1 ais length 1 sub {
7979
/i exch def
80-
/ai ais i get def
81-
/val vals i get def
82-
dmtx length ai length add val length add array
83-
dup 0 dmtx putinterval
84-
dup dmtx length ai [ exch {} forall ] putinterval
85-
dup dmtx length ai length add val [ exch {} forall ] putinterval
86-
/dmtx exch def
87-
i ais length 1 sub ne fncs i get and { % Append FNC1
88-
dmtx length 1 add array
89-
dup 0 dmtx putinterval
90-
dup dmtx length gssep {29} {fnc1} ifelse put
91-
/dmtx exch def
80+
ais i get { } forall % Push AI characters
81+
vals i get { } forall % Push value characters
82+
i ais length 1 sub ne fncs i get and {
83+
gssep {29} {fnc1} ifelse % Push separator
9284
} if
9385
} for
86+
counttomark array astore /dmtx exch def pop
9487

9588
%
9689
% Compose input to datamatrix
9790
%
9891
/barcode dmtx length 1 add 5 mul string def
99-
/i 0 def /j 0 def {
100-
i dmtx length eq {exit} if
101-
dmtx i get dup fnc1 eq {
92+
/j 0 def
93+
dmtx {
94+
dup fnc1 eq {
10295
pop barcode j (^FNC1) putinterval
103-
/j j 4 add def
96+
/j j 5 add def
10497
} {
10598
barcode exch j exch put
99+
/j j 1 add def
106100
} ifelse
107-
/i i 1 add def
108-
/j j 1 add def
109-
} loop
101+
} forall
110102
/barcode barcode 0 j getinterval def
111103

112104
%

src/gs1datamatrixrectangular.ps.src

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
%
44
% vim: set sw=4 sts=4 et:
55
%
6-
% Copyright (c) 2004-2025 Terry Burton
6+
% Copyright (c) 2004-2026 Terry Burton
77
%
88
% $Id$
99
%
@@ -71,42 +71,34 @@ begin
7171
/ais exch def
7272

7373
%
74-
% Create the datamatrix data
74+
% Create the datamatrix data using stack-based accumulation
7575
%
7676
/fnc1 -1 def
77-
/dmtx [ fnc1 ] def
77+
mark fnc1
7878
0 1 ais length 1 sub {
7979
/i exch def
80-
/ai ais i get def
81-
/val vals i get def
82-
dmtx length ai length add val length add array
83-
dup 0 dmtx putinterval
84-
dup dmtx length ai [ exch {} forall ] putinterval
85-
dup dmtx length ai length add val [ exch {} forall ] putinterval
86-
/dmtx exch def
87-
i ais length 1 sub ne fncs i get and { % Append FNC1
88-
dmtx length 1 add array
89-
dup 0 dmtx putinterval
90-
dup dmtx length gssep {29} {fnc1} ifelse put
91-
/dmtx exch def
80+
ais i get { } forall % Push AI characters
81+
vals i get { } forall % Push value characters
82+
i ais length 1 sub ne fncs i get and {
83+
gssep {29} {fnc1} ifelse % Push separator
9284
} if
9385
} for
86+
counttomark array astore /dmtx exch def pop
9487

9588
%
9689
% Compose input to datamatrix
9790
%
9891
/barcode dmtx length 1 add 5 mul string def
99-
/i 0 def /j 0 def {
100-
i dmtx length eq {exit} if
101-
dmtx i get dup fnc1 eq {
92+
/j 0 def
93+
dmtx {
94+
dup fnc1 eq {
10295
pop barcode j (^FNC1) putinterval
103-
/j j 4 add def
96+
/j j 5 add def
10497
} {
10598
barcode exch j exch put
99+
/j j 1 add def
106100
} ifelse
107-
/i i 1 add def
108-
/j j 1 add def
109-
} loop
101+
} forall
110102
/barcode barcode 0 j getinterval def
111103

112104
%

src/gs1dotcode.ps.src

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
%
44
% vim: set sw=4 sts=4 et:
55
%
6-
% Copyright (c) 2004-2025 Terry Burton
6+
% Copyright (c) 2004-2026 Terry Burton
77
%
88
% $Id$
99
%
@@ -70,42 +70,34 @@ begin
7070
/ais exch def
7171

7272
%
73-
% Create the dotcode data
73+
% Create the dotcode data using stack-based accumulation
7474
%
7575
/fnc1 -1 def
76-
/dmtx [ fnc1 ] def
76+
mark fnc1
7777
0 1 ais length 1 sub {
7878
/i exch def
79-
/ai ais i get def
80-
/val vals i get def
81-
dmtx length ai length add val length add array
82-
dup 0 dmtx putinterval
83-
dup dmtx length ai [ exch {} forall ] putinterval
84-
dup dmtx length ai length add val [ exch {} forall ] putinterval
85-
/dmtx exch def
86-
i ais length 1 sub ne fncs i get and { % Append FNC1
87-
dmtx length 1 add array
88-
dup 0 dmtx putinterval
89-
dup dmtx length fnc1 put
90-
/dmtx exch def
79+
ais i get { } forall % Push AI characters
80+
vals i get { } forall % Push value characters
81+
i ais length 1 sub ne fncs i get and {
82+
fnc1 % Push FNC1 separator
9183
} if
9284
} for
85+
counttomark array astore /dcode exch def pop
9386

9487
%
9588
% Compose input to dotcode
9689
%
97-
/barcode dmtx length 1 add 5 mul string def
98-
/i 0 def /j 0 def {
99-
i dmtx length eq {exit} if
100-
dmtx i get dup fnc1 eq {
90+
/barcode dcode length 1 add 5 mul string def
91+
/j 0 def
92+
dcode {
93+
dup fnc1 eq {
10194
pop barcode j (^FNC1) putinterval
102-
/j j 4 add def
95+
/j j 5 add def
10396
} {
10497
barcode exch j exch put
98+
/j j 1 add def
10599
} ifelse
106-
/i i 1 add def
107-
/j j 1 add def
108-
} loop
100+
} forall
109101
/barcode barcode 0 j getinterval def
110102

111103
%

src/gs1qrcode.ps.src

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
%
44
% vim: set sw=4 sts=4 et:
55
%
6-
% Copyright (c) 2004-2025 Terry Burton
6+
% Copyright (c) 2004-2026 Terry Burton
77
%
88
% $Id$
99
%
@@ -69,42 +69,34 @@ begin
6969
/ais exch def
7070

7171
%
72-
% Create the qrcode data
72+
% Create the qrcode data using stack-based accumulation
7373
%
7474
/fnc1 -1 def
75-
/qrc [ fnc1 ] def
75+
mark fnc1
7676
0 1 ais length 1 sub {
7777
/i exch def
78-
/ai ais i get def
79-
/val vals i get def
80-
qrc length ai length add val length add array
81-
dup 0 qrc putinterval
82-
dup qrc length ai [ exch {} forall ] putinterval
83-
dup qrc length ai length add val [ exch {} forall ] putinterval
84-
/qrc exch def
85-
i ais length 1 sub ne fncs i get and { % Append FNC1
86-
qrc length 1 add array
87-
dup 0 qrc putinterval
88-
dup qrc length fnc1 put
89-
/qrc exch def
78+
ais i get { } forall % Push AI characters
79+
vals i get { } forall % Push value characters
80+
i ais length 1 sub ne fncs i get and {
81+
fnc1 % Push FNC1 separator
9082
} if
9183
} for
84+
counttomark array astore /qrc exch def pop
9285

9386
%
9487
% Compose input to qrcode
9588
%
9689
/barcode qrc length 1 add 5 mul string def
97-
/i 0 def /j 0 def {
98-
i qrc length eq {exit} if
99-
qrc i get dup fnc1 eq {
90+
/j 0 def
91+
qrc {
92+
dup fnc1 eq {
10093
pop barcode j (^FNC1) putinterval
101-
/j j 4 add def
94+
/j j 5 add def
10295
} {
10396
barcode exch j exch put
97+
/j j 1 add def
10498
} ifelse
105-
/i i 1 add def
106-
/j j 1 add def
107-
} loop
99+
} forall
108100
/barcode barcode 0 j getinterval def
109101

110102
%

0 commit comments

Comments
 (0)