~ubuntu-branches/ubuntu/wily/luatex/wily

« back to all changes in this revision

Viewing changes to source/texk/web2c/lib/openclose.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2010-04-29 00:47:19 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20100429004719-o42etkqe90n97b9e
Tags: 0.60.1-1
* new upstream release, adapt build-script patch
* disable patch: upstream-epstopdf_cc_no_xpdf_patching, included upstream
* disable patch: libpoppler-0.12, not needed anymore

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* openclose.c: open and close files for TeX, Metafont, and BibTeX.
2
2
 
3
 
   Written 1995, 96 Karl Berry.  Public domain.  */
 
3
   Written 1995 Karl Berry.  Public domain.  */
4
4
 
5
5
#include "config.h"
6
6
#include "lib.h"
8
8
#include <kpathsea/tex-file.h>
9
9
#include <kpathsea/variable.h>
10
10
#include <kpathsea/absolute.h>
 
11
#ifdef PTEX
 
12
#include <ptexenc/ptexenc.h>
 
13
#endif
11
14
 
12
15
/* The globals we use to communicate.  */
13
16
extern string nameoffile;
14
17
extern unsigned namelength;
15
 
/* For "file:line:error style error messages. */
16
 
extern string fullnameoffile;
17
 
/* For the filename recorder. */
18
 
extern boolean recorder_enabled;
19
 
/* For the output-dir option. */
20
 
extern string output_directory;
21
18
 
22
19
/* Define some variables. */
 
20
/* For "file:line:error" style error messages. */
23
21
string fullnameoffile;       /* Defaults to NULL.  */
24
22
static string recorder_name; /* Defaults to NULL.  */
25
23
static FILE *recorder_file;  /* Defaults to NULL.  */
 
24
/* For the filename recorder. */
26
25
boolean recorder_enabled;    /* Defaults to false. */
 
26
/* For the output-dir option. */
27
27
string output_directory;     /* Defaults to NULL.  */
28
28
 
29
29
/* For TeX and MetaPost.  See below.  Always defined so we don't have to
37
37
static void
38
38
recorder_start(void)
39
39
{
40
 
    /* Alas, while we might want to use mkstemp it is not portable.
41
 
       So we have to be content with using a default name... */
 
40
    /* Alas, while we'd like to use mkstemp it is not portable,
 
41
       and doing the autoconfiscation (and providing fallbacks) is more
 
42
       than we want to cope with.  So we have to be content with using a
 
43
       default name.  Throw in the pid so at least parallel builds might
 
44
       work (Debian bug 575731).  */
42
45
    string cwd;
 
46
    pid_t pid = getpid();
 
47
    char pid_str[MAX_INT_LENGTH];
 
48
    sprintf (pid_str, "%ld", (long) pid);
43
49
    
44
 
    recorder_name = (string)xmalloc(strlen(kpse_program_name)+5);
 
50
    recorder_name = xmalloc(strlen(kpse_program_name)
 
51
                                    + strlen (pid_str) + 5);
45
52
    strcpy(recorder_name, kpse_program_name);
 
53
    strcat(recorder_name, pid_str);
46
54
    strcat(recorder_name, ".fls");
47
55
    
48
56
    /* If an output directory was specified, use it instead of cwd.  */
72
80
 
73
81
/* helper for recorder_record_* */
74
82
static void
75
 
recorder_record_name (string prefix, const_string nameoffile)
 
83
recorder_record_name (const_string prefix, const_string name)
76
84
{
77
85
    if (recorder_enabled) {
78
86
        if (!recorder_file)
79
87
            recorder_start();
80
 
        fprintf(recorder_file, "%s %s\n", prefix, nameoffile);
 
88
        fprintf(recorder_file, "%s %s\n", prefix, name);
81
89
        fflush(recorder_file);
82
90
    }
83
91
}
84
92
 
85
 
/* record an input file */
 
93
/* record an input file name */
86
94
void
87
 
recorder_record_input (const_string nameoffile)
 
95
recorder_record_input (const_string name)
88
96
{
89
 
    recorder_record_name ("INPUT", nameoffile);
 
97
    recorder_record_name ("INPUT", name);
90
98
}
91
99
 
92
 
/* record an output file */
 
100
/* record an output file name */
93
101
void
94
 
recorder_record_output (const_string nameoffile)
 
102
recorder_record_output (const_string name)
95
103
{
96
 
    recorder_record_name ("OUTPUT", nameoffile);
 
104
    recorder_record_name ("OUTPUT", name);
97
105
}
98
106
 
99
107
/* Open an input file F, using the kpathsea format FILEFMT and passing
121
129
        free(fullnameoffile);
122
130
    fullnameoffile = NULL;
123
131
    
124
 
    /* Handle -output-directory.
125
 
       FIXME: We assume that it is OK to look here first.  Possibly it
126
 
       would be better to replace lookups in "." with lookups in the
127
 
       output_directory followed by "." but to do this requires much more
128
 
       invasive surgery in libkpathsea.  */
129
 
    /* FIXME: This code assumes that the filename of the input file is
130
 
       not an absolute filename. */
131
 
    if (output_directory) {
132
 
        fname = concat3(output_directory, DIR_SEP_STRING, nameoffile + 1);
133
 
        *f_ptr = fopen(fname, fopen_mode);
 
132
    /* Look in -output-directory first, if the filename is not
 
133
       absolute.  This is because .aux and other such files will get
 
134
       written to the output directory, and we have to be able to read
 
135
       them from there.  We only look for the name as-is.  */
 
136
    if (output_directory && !kpse_absolute_p (nameoffile+1, false)) {
 
137
        fname = concat3 (output_directory, DIR_SEP_STRING, nameoffile + 1);
 
138
        *f_ptr = fopen (fname, fopen_mode);
134
139
        if (*f_ptr) {
135
 
            free(nameoffile);
 
140
            free (nameoffile);
136
141
            namelength = strlen (fname);
137
 
            nameoffile = (string)xmalloc (namelength + 2);
 
142
            nameoffile = xmalloc (namelength + 2);
138
143
            strcpy (nameoffile + 1, fname);
139
144
            fullnameoffile = fname;
140
145
        } else {
141
 
            free(fname);
 
146
            free (fname);
142
147
        }
143
148
    }
144
149
 
181
186
                /* kpse_find_file always returns a new string. */
182
187
                free (nameoffile);
183
188
                namelength = strlen (fname);
184
 
                nameoffile = (string)xmalloc (namelength + 2);
 
189
                nameoffile = xmalloc (namelength + 2);
185
190
                strcpy (nameoffile + 1, fname);
186
191
                free (fname);
187
192
 
188
193
                /* This fopen is not allowed to fail. */
 
194
#ifdef PTEX
 
195
                if (filefmt == kpse_tex_format ||
 
196
                    filefmt == kpse_bib_format) {
 
197
                    *f_ptr = nkf_open (nameoffile + 1, fopen_mode);
 
198
                } else
 
199
#endif
189
200
                *f_ptr = xfopen (nameoffile + 1, fopen_mode);
190
201
            }
191
202
        }
241
252
        string texmfoutput = kpse_var_value("TEXMFOUTPUT");
242
253
 
243
254
        if (texmfoutput && *texmfoutput && !absolute) {
244
 
            string fname = concat3(texmfoutput, DIR_SEP_STRING, nameoffile+1);
 
255
            if (fname != nameoffile + 1)
 
256
                free(fname);
 
257
            fname = concat3(texmfoutput, DIR_SEP_STRING, nameoffile+1);
245
258
            *f_ptr = fopen(fname, fopen_mode);
246
259
        }
247
260
    }
250
263
        if (fname != nameoffile + 1) {
251
264
            free (nameoffile);
252
265
            namelength = strlen (fname);
253
 
            nameoffile = (string)xmalloc (namelength + 2);
 
266
            nameoffile = xmalloc (namelength + 2);
254
267
            strcpy (nameoffile + 1, fname);
255
268
        }
256
269
        recorder_record_output (fname);
270
283
  if (!f)
271
284
    return;
272
285
    
 
286
#ifdef PTEX
 
287
  if (nkf_close (f) == EOF) {
 
288
#else
273
289
  if (fclose (f) == EOF) {
 
290
#endif
274
291
    /* It's not always nameoffile, we might have opened something else
275
292
       in the meantime.  And it's not easy to extract the filenames out
276
293
       of the pool array.  So just punt on the filename.  Sigh.  This