- char *redir_word;
- int redir_len;
- char *full_line;
- char *document = (char *)NULL;
- int document_index = 0, document_size = 0;
-
-#if !defined (POSIX_HERE_DOCUMENTS)
- /* Because of Bourne shell semantics, we turn off globbing, but
- only for this style of redirection. I feel a little ill. */
- {
- int old_value = disallow_filename_globbing;
- disallow_filename_globbing = 1;
-
- redir_word = redirection_expand (temp->redirectee.filename);
-
- disallow_filename_globbing = old_value;
- }
-#else /* POSIX_HERE_DOCUMENTS */
- /* Quote removal is the only expansion performed on the delimiter
- for here documents, making it an extremely special case. I
- still feel ill. */
- redir_word = string_quote_removal (temp->redirectee.filename->word, 0);
-#endif /* POSIX_HERE_DOCUMENTS */
-
- /* redirection_expand will return NULL if the expansion results in
- multiple words or no words. Check for that here, and just abort
- this here document if it does. */
- if (redir_word)
- redir_len = strlen (redir_word);
- else
- {
- temp->here_doc_eof = savestring ("");
- goto document_done;
- }
-
- free (temp->redirectee.filename->word);
- temp->here_doc_eof = redir_word;
-
- /* Read lines from wherever lines are coming from.
- For each line read, if kill_leading, then kill the
- leading tab characters.
- If the line matches redir_word exactly, then we have
- manufactured the document. Otherwise, add the line to the
- list of lines in the document. */
-
- /* If the here-document delimiter was quoted, the lines should
- be read verbatim from the input. If it was not quoted, we
- need to perform backslash-quoted newline removal. */
- while (full_line = read_secondary_line
- (temp->redirectee.filename->quoted == 0))
- {
- register char *line = full_line;
- int len;
-
- line_number++;
-
- if (kill_leading && *line)
- {
- /* Hack: To be compatible with some Bourne shells, we
- check the word before stripping the whitespace. This
- is a hack, though. */
- if (STREQN (line, redir_word, redir_len) &&
- line[redir_len] == '\n')
- goto document_done;
-
- while (*line == '\t')
- line++;
- }
-
- if (!*line)
- continue;
-
- if (STREQN (line, redir_word, redir_len) &&
- line[redir_len] == '\n')
- goto document_done;
-
- len = strlen (line);
- if (len + document_index >= document_size)
- {
- document_size = document_size ? 2 * (document_size + len)
- : 1000; /* XXX */
- document = xrealloc (document, document_size);
- }
-
- /* len is guaranteed to be > 0 because of the check for line
- being an empty string before the call to strlen. */
- FASTCOPY (line, document + document_index, len);
- document_index += len;
- }
-
- document_done:
- if (document)
- document[document_index] = '\0';
- else
- document = savestring ("");
- temp->redirectee.filename->word = document;