[gs-cvs] rev 6996 - trunk/gs/lib
leonardo at ghostscript.com
leonardo at ghostscript.com
Thu Aug 17 08:27:55 PDT 2006
Author: leonardo
Date: 2006-08-17 08:27:55 -0700 (Thu, 17 Aug 2006)
New Revision: 6996
Modified:
trunk/gs/lib/gs_init.ps
trunk/gs/lib/gs_res.ps
Log:
Fix (resource machinery) : 'resourceforall' truncated names of file-based resources.
DETAILS :
Bug 688737 "'resourceforall' truncates names of file-based resources".
Thanks to SaGS for the good analyzis done in the bug report.
When enumerating file-based resources, the library
enumerates resource file paths and then needs to
decompose a file path into a directory name and the resource name.
The resource name, which matches the specified template,
is always a suffix of the path. Thus to know the resource name,
one needs to compute the length of the suffix.
However the latter is not trivial
due to mixing 2 syntacies : the Postscript template string syntax,
and the file path syntax of the underlying operating system.
To know the suffix length, the old code computed
the difference of the directory path template length,
and the template argument length.
Hoewver the directory path length in not equal to
the directory path template length if the patch
includes symbols, which need an escapement when converting
a string to a template string.
The new code passes lengthes of source directory paths though the
.generate_dir_list_templates procedure, so that they don't need to
restore from the generated templates.
The patch enhances the function with inserting source length between the
generated template list elements. The new function
gets an additional boolean operand, which tells whether to insert
lenthes or not. The enhanced function is renemaed into
.generate_dir_list_templates_with_length .
The old name .generate_dir_list_templates is defined for
the backward compatibility as a specialization of the new function.
The new function works for ResourceForAll .
DIFFERENCES :
None.
Modified: trunk/gs/lib/gs_init.ps
===================================================================
--- trunk/gs/lib/gs_init.ps 2006-08-16 17:23:10 UTC (rev 6995)
+++ trunk/gs/lib/gs_init.ps 2006-08-17 15:27:55 UTC (rev 6996)
@@ -1558,19 +1558,21 @@
0 exch getinterval exch pop
} bind def
-% <dir_list> <template> .generate_dir_list_templates <t1> ... <tN>
+% false <dir_list> <template> .generate_dir_list_templates_with_length <t1> ... <tN>
+% true <dir_list> <template> .generate_dir_list_templates_with_length <t1> <l1> ... <tN> <ln>
%
% Generates various valid templates combining a directory list with a given template.
+% With 'true' operand it also returns lengths of directory pathes.
%
% Example1 (DOS, Windows) :
-% [(/gs/lib) (/gs/Resource/) (\gs8.00\Resource)] (*/*) -->
+% false [(/gs/lib) (/gs/Resource/) (\gs8.00\Resource)] (*/*) -->
% (/gs/lib/*/*) (/gs/Resource/*/*) (\\gs8.00\\Resource/*/*)
%
% Example2 (OpenVMS) :
-% [(gs:[lib]) (gs:[Resource]) (gs800:[Resource)] (*]*) -->
+% false [(gs:[lib]) (gs:[Resource]) (gs800:[Resource)] (*]*) -->
% ((gs:[lib.*]*) [gs:[Resource.*]*) ([gs800:[Resource.*]*)
%
-/.generate_dir_list_templates
+/.generate_dir_list_templates_with_length
{ % [dl] (templ)
% We need to convert paths into templates,
% because it can include '\' on DOS.
@@ -1585,60 +1587,78 @@
%
% Create the fake file name :
- dup dup length string copy % [dl] (templ) (ffn)
- (*) 0 get (?) 0 get (\\) 0 get (x) 0 get 0 0 % [dl] (templ) (ffn) * ? \ x i j
+ dup dup length string copy % b [dl] (templ) (ffn)
+ (*) 0 get (?) 0 get (\\) 0 get (x) 0 get 0 0 % b [dl] (templ) (ffn) * ? \ x i j
{ 1 index 7 index length ge { exit } if
- 6 index 2 index get % [dl] (templ) (ffn) * ? \ x i j c
- dup 7 index eq % [dl] (templ) (ffn) * ? \ x i j c bool
+ 6 index 2 index get % b [dl] (templ) (ffn) * ? \ x i j c
+ dup 7 index eq % b [dl] (templ) (ffn) * ? \ x i j c bool
1 index 7 index eq or { % *?
pop 2 index
- } if % [dl] (templ) (ffn) * ? \ x i j C
+ } if % b [dl] (templ) (ffn) * ? \ x i j C
dup 5 index eq { % \
- 3 2 roll 1 add 3 1 roll % [dl] (templ) (ffn) * ? \ x i' j C
+ 3 2 roll 1 add 3 1 roll % b [dl] (templ) (ffn) * ? \ x i' j C
2 index 8 index length ge { pop exit } if
- pop 6 index 2 index get % [dl] (templ) (ffn) * ? \ x i' j C'
+ pop 6 index 2 index get % b [dl] (templ) (ffn) * ? \ x i' j C'
} if
- 7 index 2 index 3 2 roll put % [dl] (templ) (ffn) * ? \ x i' j
- 1 add exch 1 add exch % [dl] (templ) (ffn) * ? \ x i'' j'
- } loop % [dl] (templ) (ffn) * ? \ x i j
- 6 1 roll pop % [dl] (templ) (ffn) j * ? \ x
- exch pop exch pop exch pop exch % [dl] (templ) (ffn) x j
+ 7 index 2 index 3 2 roll put % b [dl] (templ) (ffn) * ? \ x i' j
+ 1 add exch 1 add exch % b [dl] (templ) (ffn) * ? \ x i'' j'
+ } loop % b [dl] (templ) (ffn) * ? \ x i j
+ 6 1 roll pop % b [dl] (templ) (ffn) j * ? \ x
+ exch pop exch pop exch pop exch % b [dl] (templ) (ffn) x j
{ dup 3 index length ge { exit } if
3 copy exch put
1 add
} loop
- pop pop % [dl] (templ) (ffn)
+ pop pop % b [dl] (templ) (ffn)
% An internal procedure :
- { % {} [dl] (templ) (ffn) (dffn)
- .makepathtemplate % {} [dl] (templ) (ffn) (Dffn)
- dup % {} [dl] (templ) (ffn) (Dffn) (Dffn)
- 3 index length dup % {} [dl] (templ) (ffn) (Dffn) (Dffn) templL templL
- 2 index length % {} [dl] (templ) (ffn) (Dffn) (Dffn) templL templL DffnL
- exch sub % {} [dl] (templ) (ffn) (Dffn) (Dffn) templL i
- exch getinterval % {} [dl] (templ) (ffn) (Dffn) (suffix)
- 3 index exch copy pop % {} [dl] (templ) (ffn) (dt)
- 5 1 roll % (dt) {} [dl] (templ) (ffn)
+ { % {} b [dl] (templ) (ffn) (dffn)
+ dup length
+ 1 sub % drop 'x', which was added above.
+ exch % {} b [dl] (templ) (ffn) ldffn (dffn)
+ .makepathtemplate % {} b [dl] (templ) (ffn) ldffn (Dffn)
+ dup % {} b [dl] (templ) (ffn) ldffn (Dffn) (Dffn)
+ 4 index length dup % {} b [dl] (templ) (ffn) ldffn (Dffn) (Dffn) templL templL
+ 2 index length % {} b [dl] (templ) (ffn) ldffn (Dffn) (Dffn) templL templL DffnL
+ exch sub % {} b [dl] (templ) (ffn) ldffn (Dffn) (Dffn) templL i
+ exch getinterval % {} b [dl] (templ) (ffn) ldffn (Dffn) (suffix)
+ 4 index exch copy pop % {} b [dl] (templ) (ffn) ldffn (dt)
+ 5 index {
+ exch % {} b [dl] (templ) (ffn) (dt) ldffn
+ 7 2 roll % (dt) ldffn {} b [dl] (templ) (ffn)
+ } {
+ exch pop % {} b [dl] (templ) (ffn) (dt)
+ 6 1 roll % (dt) {} b [dl] (templ) (ffn)
+ } ifelse
}
- 4 1 roll % {} [dl] (templ) (ffn)
+ 5 1 roll % {} b [dl] (templ) (ffn)
% Generate templates :
dup .file_name_is_absolute {
- dup % {} [dl] (templ) (ffn) (ffn)
- 4 index exec % (t1) {} [dl] (templ) (ffn)
+ dup % {} b [dl] (templ) (ffn) (ffn)
+ 5 index exec % (t1) {} b [dl] (templ) (ffn)
} {
- 2 index { % {} [dl] (templ) (ffn) (d)
- 1 index % {} [dl] (templ) (ffn) (d) (ffn)
- false .file_name_combine { % {} [dl] (templ) (ffn) (dffn)
- 4 index exec % (t1) {} [dl] (templ) (ffn)
- } { % {} [dl] (templ) (ffn) (d) (ffn)
- pop pop % {} [dl] (templ) (ffn)
+ 2 index { % ... {} b [dl] (templ) (ffn) (d)
+ 1 index % ... {} b [dl] (templ) (ffn) (d) (ffn)
+ false .file_name_combine { % ... {} b [dl] (templ) (ffn) (dffn)
+ 5 index exec % ... (t1) ?l1 {} b [dl] (templ) (ffn)
+ } { % ... {} b [dl] (templ) (ffn) (d) (ffn)
+ pop pop % ... {} b [dl] (templ) (ffn)
} ifelse
} forall
- } ifelse % (t1) (t2) ... (tN) {} [dl] (templ) (ffn)
- pop pop pop pop % (t1) (t2) ... (tN)
+ } ifelse % (t1) ?l1 (t2) ?l2 ... (tN) ?ln {} b [dl] (templ) (ffn)
+ pop pop pop pop pop % (t1) ?l1 (t2) ?l2 ... (tN) ?ln
} bind def
+% <dir_list> <template> .generate_dir_list_templates <t1> ... <tN>
+%
+% Generates various valid templates combining a directory list with a given template.
+% It's the 'false' case of the function above.
+%
+/.generate_dir_list_templates
+{ //false 3 1 roll //.generate_dir_list_templates_with_length exec
+} bind def
+
% Load the initialization files for optional features.
%% Replace 4 INITFILES
systemdict /INITFILES known
Modified: trunk/gs/lib/gs_res.ps
===================================================================
--- trunk/gs/lib/gs_res.ps 2006-08-16 17:23:10 UTC (rev 6995)
+++ trunk/gs/lib/gs_res.ps 2006-08-17 15:27:55 UTC (rev 6996)
@@ -458,29 +458,31 @@
dup length 3 1 roll % args [ l (c/) (t)
concatstrings % args [ l (c/t)
[
- /LIBPATH .systemvar 2 index
- .generate_dir_list_templates % args (t) [ l [(pt)]
+ true /LIBPATH .systemvar 3 index
+ .generate_dir_list_templates_with_length % args (t) [ l [(pt) Lp ...]
% also add on the Resources as specified by the GenericResourceDir
- [ currentsystemparams /GenericResourceDir get]
- counttomark 1 add index .generate_dir_list_templates
- % Resource files on OpenVMS requires a separate template (gs:[dir.*]*)
- [ currentsystemparams /GenericResourceDir get]
+ true [ currentsystemparams /GenericResourceDir get]
+ counttomark 1 add index .generate_dir_list_templates_with_length
+ % Resource files on OpenVMS require a separate template (gs:[dir.*]*)
+ true [ currentsystemparams /GenericResourceDir get]
counttomark 1 add index .file_name_separator (*)
- concatstrings concatstrings .generate_dir_list_templates
+ concatstrings concatstrings .generate_dir_list_templates_with_length
] exch pop
- { % args [ l (pt)
- dup length 2 index sub exch % args [ l Lp (pt)
+ dup length 1 sub 0 exch 2 exch { % args [ l [] i
+ 2 copy get % args [ l [] i (pt)
+ exch 2 index exch 1 add get % args [ l [] (pt) Lp
+ exch % args [ l [] Lp (pt)
- { % args [ l Lp (pf)
- dup length % args [ l Lp (pf) Lpf
- 2 index sub % args [ l Lp (pf) Lf
- 2 index exch % args [ l Lp (pf) Lp Lf
- getinterval cvn dup % args [ l Lp /n /n
- 4 2 roll % args [ /n /n l Lp
+ { % args [ l [] Lp (pf)
+ dup length % args [ l [] Lp (pf) Lpf
+ 2 index sub % args [ l [] Lp (pf) Lf
+ 2 index exch % args [ l [] Lp (pf) Lp Lf
+ getinterval cvn dup % args [ l [] Lp /n /n
+ 5 2 roll % args [ /n /n l [] Lp
} //.rfnstring filenameforall
- pop % args [ l /n1 /n1 ... /nN /nN l
- } forall % args [ l /n1 /n1 ... /nN /nN
- pop
+ pop % args [ /n1 /n1 ... /nN /nN l []
+ } for % args [ /n1 /n1 ... /nN /nN l []
+ pop pop
.dicttomark % An easy way to exclude duplicates. % args <</n/n>>
% {
{ pop } 0 get
More information about the gs-cvs
mailing list