More spaces-in-filenames code (Was: [tex-live] #5000)

Olaf Weber olaf at infovore.xs4all.nl
Mon Jun 7 19:14:44 CEST 2004


Olaf Weber writes:
> Sebastian Rahtz writes:

>> a) source freeze by Olaf., Martin and Thanh, followed by new
>> compilation all around

> It has been pointed out to me that the spaces-in-filenames code needs
> more work.  :-(

Here are additional changes that should catch some of the cases I
overlooked earlier in my eagerness to get the overly-intrusive code
out.  Some of it is rather ugly.  :-(

Corresponding changes for mf and mpost have still to be done.  (Same
for omega, aleph.)


infovore:/home/olaf/web2c/texlive/development/TeX/texk/web2c$ p4 changes -l tex.ch#28,#head
Change 5025 on 2004/06/07 by olaf at olaf

        More changes to support spaces in filenames.  In particular, keep
        quotes around |cur_name|, |cur_ext|, and |cur_area| iff these
        contain spaces.  This incurs complications because we re-parse
        |name_of_file| into these components after opening a file.  The
        file-printing routine is changed to ensure that we print quotes
        if needed, but do not print any quotes contained in the parameters
        themselves.

        This fixes a problem reported by Akira Kakuto where LaTeX would
        be confused by an unquoted space in \jobname.

infovore:/home/olaf/web2c/texlive/development/TeX/texk/web2c$ p4 diff2 -du tex.ch#27 tex.ch#28
==== //depot/Build/source.development/TeX/texk/web2c/tex.ch#27 (text) - //depot/Build/source.development/TeX/texk/web2c/tex.ch#28 (text) ==== content
@@ -1934,13 +1934,12 @@
 @x [29.516] l.9992 - filenames: more_name
 begin if c=" " then more_name:=false
 @y
-begin
-if c="""" then begin
+begin if (c=" ") and stop_at_space and (not quoted_filename) then
+  more_name:=false
+else  if c="""" then begin
   quoted_filename:=not quoted_filename;
   more_name:=true;
   end
-else if (c=" ") and stop_at_space and (not quoted_filename) then
-  more_name:=false
 @z

 @x [29.516] l.9994 - filenames: more_name
@@ -1971,7 +1970,67 @@

 @p procedure end_name;
 var temp_str: str_number; {result of file name cache lookups}
-@!j: pool_pointer; {running index}
+@!j,@!s,@!t: pool_pointer; {running indices}
+@!must_quote:boolean; {whether we need to quote a string}
+ at z
+
+ at x [29.517] l.10022 - end_name: spaces in filenames
+@:TeX capacity exceeded number of strings}{\quad number of strings@>
+ at y
+@:TeX capacity exceeded number of strings}{\quad number of strings@>
+str_room(6); {Room for quotes, if needed.}
+{add quotes if needed}
+if area_delimiter<>0 then begin
+  {maybe quote |cur_area|}
+  must_quote:=false;
+  s:=str_start[str_ptr];
+  t:=str_start[str_ptr]+area_delimiter;
+  j:=s;
+  while (not must_quote) and (j<>t) do begin
+    must_quote:=str_pool[j]=' '; incr(j);
+    end;
+  if must_quote then begin
+    for j:=pool_ptr-1 downto t do str_pool[j+2]:=str_pool[j];
+    str_pool[t+1]:="""";
+    for j:=t-1 downto s do str_pool[j+1]:=str_pool[j];
+    str_pool[s]:="""";
+    if ext_delimiter<>0 then ext_delimiter:=ext_delimiter+2;
+    area_delimiter:=area_delimiter+2;
+    pool_ptr:=pool_ptr+2;
+    end;
+  end;
+{maybe quote |cur_name|}
+s:=str_start[str_ptr]+area_delimiter;
+if ext_delimiter=0 then t:=pool_ptr else t:=str_start[str_ptr]+ext_delimiter-1;
+must_quote:=false;
+j:=s;
+while (not must_quote) and (j<>t) do begin
+  must_quote:=str_pool[j]=' '; incr(j);
+  end;
+if must_quote then begin
+  for j:=pool_ptr-1 downto t do str_pool[j+2]:=str_pool[j];
+  str_pool[t+1]:="""";
+  for j:=t-1 downto s do str_pool[j+1]:=str_pool[j];
+  str_pool[s]:="""";
+  if ext_delimiter<>0 then ext_delimiter:=ext_delimiter+2;
+  pool_ptr:=pool_ptr+2;
+  end;
+if ext_delimiter<>0 then begin
+  {maybe quote |cur_ext|}
+  s:=str_start[str_ptr]+ext_delimiter-1;
+  t:=pool_ptr;
+  must_quote:=false;
+  j:=s;
+  while (not must_quote) and (j<>t) do begin
+    must_quote:=str_pool[j]=' '; incr(j);
+    end;
+  if must_quote then begin
+    str_pool[t+1]:="""";
+    for j:=t-1 downto s do str_pool[j+1]:=str_pool[j];
+    str_pool[s]:="""";
+    pool_ptr:=pool_ptr+2;
+    end;
+  end;
 @z

 @x [29.517] l.10011 - end_name: string recycling
@@ -2041,11 +2100,26 @@
     must_quote:=str_pool[j]=' '; incr(j);
   end;
 end;
-if must_quote then slow_print("""");
-if a<>0 then slow_print(a);
-if n<>0 then slow_print(n);
-if e<>0 then slow_print(e);
-if must_quote then slow_print("""");
+{FIXME: Alternative is to assume that any filename that has to be quoted has
+ at least one quoted component...if we pick this, a number of insertions
+ of |print_file_name| should go away.
+|must_quote|:=((|a|<>0)and(|str_pool|[|str_star|t[|a|]]=""""))or
+              ((|n|<>0)and(|str_pool|[|str_start|[|n|]]=""""))or
+              ((|e|<>0)and(|str_pool|[|str_start|[|e|]]=""""));}
+if must_quote then print_char("""");
+if a<>0 then
+  for j:=str_start[a] to str_start[a+1]-1 do
+    if so(str_pool[j])<>"""" then
+      print_char(so(str_pool[j]));
+if n<>0 then
+  for j:=str_start[n] to str_start[n+1]-1 do
+    if so(str_pool[j])<>"""" then
+      print_char(so(str_pool[j]));
+if e<>0 then
+  for j:=str_start[e] to str_start[e+1]-1 do
+    if so(str_pool[j])<>"""" then
+      print_char(so(str_pool[j]));
+if must_quote then print_char("""");
 @z

 @x [29.519] l.10051 - have append_to_name skip quotes.
@@ -2154,6 +2228,39 @@
 @.I can't find the format...@>
 @z

+ at x [29.525] l.10163 - make_name_string
+ at p function make_name_string:str_number;
+var k:1..file_name_size; {index into |name_of_file|}
+begin if (pool_ptr+name_length>pool_size)or(str_ptr=max_strings)or
+ (cur_length>0) then
+  make_name_string:="?"
+else  begin for k:=1 to name_length do append_char(xord[name_of_file[k]]);
+  make_name_string:=make_string;
+  end;
+end;
+ at y
+ at p function make_name_string:str_number;
+var k:1..file_name_size; {index into |name_of_file|}
+begin if (pool_ptr+name_length>pool_size)or(str_ptr=max_strings)or
+ (cur_length>0) then
+  make_name_string:="?"
+else  begin for k:=1 to name_length do append_char(xord[name_of_file[k]]);
+  make_name_string:=make_string;
+  end;
+  {At this point we also set |cur_name|, |cur_ext|, and |cur_area| to
+   match the contents of |name_of_file|.}
+  k:=1;
+  name_in_progress:=true;
+  begin_name;
+  stop_at_space:=false;
+  while (k<=name_length)and(more_name(name_of_file[k])) do
+    incr(k);
+  stop_at_space:=true;
+  end_name;
+  name_in_progress:=false;
+end;
+ at z
+
 @x [29.526] l.10194 - stop scanning file name if we're at end-of-line.
   if not more_name(cur_chr) then goto done;
 @y
@@ -2282,19 +2389,7 @@
   {Kpathsea tries all the various ways to get the file.}
   if open_in_name_ok(stringcast(name_of_file+1))
      and a_open_in(cur_file, kpse_tex_format) then
-    {At this point |name_of_file| contains the actual name found.
-     We extract the |cur_area|, |cur_name|, and |cur_ext| from it.}
-    begin k:=1;
-    name_in_progress:=true;
-    begin_name;
-    stop_at_space:=false;
-    while (k<=name_length)and(more_name(name_of_file[k])) do
-      incr(k);
-    stop_at_space:=true;
-    end_name;
-    name_in_progress:=false;
     goto done;
-    end;
 @z

 @x [29.537] l.10348 - start_input: don't force ".tex" extension.
@@ -3756,17 +3851,7 @@
   tex_input_type:=0; {Tell |open_input| we are \.{\\openin}.}
   if open_in_name_ok(stringcast(name_of_file+1))
      and a_open_in(read_file[n], kpse_tex_format) then
-    begin k:=1;
-    name_in_progress:=true;
-    begin_name;
-    stop_at_space:=false;
-    while (k<=name_length)and(more_name(name_of_file[k])) do
-      incr(k);
-    stop_at_space:=true;
-    end_name;
-    name_in_progress:=false;
     read_open[n]:=just_open;
-    end;
 @z

 @x [49.1279] - encTeX: implement \noconvert

-- 
Olaf Weber

               (This space left blank for technical reasons.)



More information about the tex-live mailing list