texfileio.h /size: 3820 b    last modification: 2024-01-16 10:22
1/*
2    See license.txt in the root of this project.
3*/
4
5# ifndef LMT_TEXFILEIO_H
6# define LMT_TEXFILEIO_H
7
8# include "textypes.h"
9
10# define FOPEN_R_MODE    "r"
11# define FOPEN_W_MODE    "wb"
12# define FOPEN_RBIN_MODE "rb"
13# define FOPEN_WBIN_MODE "wb"
14
15# define IS_SPC_OR_EOL(c) ((c) == ' ' || (c) == '\r' || (c) == '\n')
16
17extern void tex_initialize_fileio_state (void);
18extern bool tex_room_in_buffer          (int top);
19extern int  tex_lua_a_open_in           (const char *fn);
20extern void tex_lua_a_close_in          (void);
21extern int  tex_lua_input_ln            (void);
22
23/*tex
24
25    The user's terminal acts essentially like other files of text, except that it is used both for
26    input and for output. In traditional \TEX, when the terminal is considered an input file, the
27    file variable is called |term_in|, and when it is considered an output file the file variable
28    is |term_out|.
29
30    However, in \LUATEX\ in addition to files we also have pseudo files (something \ETEX) and input
31    coming from \LUA, which makes for a much more complex system. In \LUAMETATEX\ the model has
32    been stepwise simplified: pseudo files are gone and use a mechanism simular to \LUA\ input, and
33    the terminal is left up to the (anyway kind of mandate) file related callbacks, with read file
34    id zero still being the console. Output to the console is part of a model that intercepts output
35    to the log file and/or the console and can delegate handling to callbacks as well.
36
37    So, in the end, the terminal code in \LUAMETATEX\ is gone as all goes through \LUA, which also
38    means that |terminal_update|, |clear_terminal| and |wake_up_terminal| are no longer needed.
39
40    It is important to notice that reading from files is split into two: the files explicitly opened
41    with |\openin| are managed independent from the files opened with |\input|.  The first category
42    is not part of input file nesting management.
43
44*/
45
46# define format_extension     ".fmt"
47# define transcript_extension ".log"
48# define texinput_extension   ".tex"
49
50typedef struct fileio_state_info {
51    unsigned char *io_buffer;           /*tex lines of characters being read */
52    memory_data    io_buffer_data;
53    int            io_first;            /*tex the first unused position in |buffer| */
54    int            io_last;             /*tex end of the line just input to |buffer| */
55    int            name_in_progress;    /*tex Is a file name being scanned? */
56    int            log_opened;          /*tex the transcript file has been opened */
57    char          *job_name;            /*tex the principal file name */
58    char          *log_name;            /*tex full name of the log file */
59    char          *fmt_name;
60} fileio_state_info ;
61
62extern fileio_state_info lmt_fileio_state;
63
64# define emergency_job_name (lmt_fileio_state.job_name ? lmt_fileio_state.job_name : "unknown job name")
65# define emergency_log_name (lmt_fileio_state.log_name ? lmt_fileio_state.log_name : "unknown log name")
66# define emergency_fmt_name (lmt_fileio_state.fmt_name ? lmt_fileio_state.fmt_name : "unknown fmt name")
67
68extern void        tex_terminal_update   (void);
69extern void        tex_open_log_file     (void);
70extern void        tex_close_log_file    (void);
71extern void        tex_start_input       (char *fn, halfword at_end_of_file);
72extern void        tex_check_fmt_name    (void);
73extern void        tex_check_job_name    (char *fn);
74extern dumpstream  tex_open_fmt_file     (int writemode);
75extern void        tex_close_fmt_file    (dumpstream f);
76extern char       *tex_read_file_name    (int optionalequal, const char * name, const char* ext);
77extern void        tex_print_file_name   (unsigned char *name);
78extern void        tex_report_start_file (unsigned char *name);
79extern void        tex_report_stop_file  (void);
80
81# endif
82