Skip to content

Commit c5dab85

Browse files
authored
Merge pull request #44 from alexander-bauer/issue-36
Handle filenames with spaces
2 parents ff83754 + c546af1 commit c5dab85

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

tectonic/xetexini.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2851,6 +2851,7 @@ init_io(string input_file_name)
28512851
int k;
28522852
unsigned char *ptr = (unsigned char *) input_file_name;
28532853
UInt32 rval;
2854+
bool name_needs_quotes;
28542855

28552856
stdin_ufile.handle = NULL;
28562857
stdin_ufile.savedChar = -1;
@@ -2862,9 +2863,19 @@ init_io(string input_file_name)
28622863
/* Hacky stuff that sets us up to process the input file, including UTF8
28632864
* interpretation. */
28642865

2866+
/* Check if there is a space in the input_file_name. If so, quote it,
2867+
* because xetex interprets space as the end of the filename. Otherwise, we
2868+
* leave it unquoted, to maintain backwards compatibility. */
2869+
name_needs_quotes = (strchr(input_file_name, ' ') != NULL);
2870+
28652871
buffer[first] = 0;
28662872
k = first;
28672873

2874+
/* If the name needs quotes, start them here. */
2875+
if(name_needs_quotes) {
2876+
buffer[k++] = '"';
2877+
}
2878+
28682879
while ((rval = *(ptr++)) != 0) {
28692880
UInt16 extraBytes = bytesFromUTF8[rval];
28702881

@@ -2881,7 +2892,11 @@ init_io(string input_file_name)
28812892
buffer[k++] = rval;
28822893
}
28832894

2884-
buffer[k] = ' ';
2895+
/* If we quoted earlier, end them here. */
2896+
if(name_needs_quotes) {
2897+
buffer[k++] = '"';
2898+
}
2899+
buffer[k] = ' '; /* Unquoted space terminates filename for xetex engine */
28852900
last = k;
28862901
cur_input.loc = first;
28872902
cur_input.limit = last;

0 commit comments

Comments
 (0)