summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/luatex.c
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/luatex.c')
-rw-r--r--Build/source/texk/web2c/luatexdir/luatex.c756
1 files changed, 277 insertions, 479 deletions
diff --git a/Build/source/texk/web2c/luatexdir/luatex.c b/Build/source/texk/web2c/luatexdir/luatex.c
index 5dc5d64636a..5e9e61b919e 100644
--- a/Build/source/texk/web2c/luatexdir/luatex.c
+++ b/Build/source/texk/web2c/luatexdir/luatex.c
@@ -32,9 +32,9 @@
stick to "0" upto "9" so users can expect a number represented as string.
*/
-int luatex_version = 106;
-int luatex_revision = '3';
-const char *luatex_version_string = "1.06.3";
+int luatex_version = 107;
+int luatex_revision = '0';
+const char *luatex_version_string = "1.07.0";
const char *engine_name = my_name;
#include <kpathsea/c-ctype.h>
@@ -63,53 +63,51 @@ const char *engine_name = my_name;
#include <signal.h> /* Catch interrupts. */
-
-
-/* Shell escape.
-
- If shellenabledp == 0, all shell escapes are forbidden.
- If (shellenabledp == 1 && restrictedshell == 0), any command
- is allowed for a shell escape.
- If (shellenabledp == 1 && restrictedshell == 1), only commands
- given in the configuration file as
- shell_escape_commands = kpsewhich,ebb,extractbb,mpost,metafun,...
- (no spaces between commands) in texmf.cnf are allowed for a shell
- escape in a restricted form: command name and arguments should be
- separated by a white space. The first word should be a command
- name. The quotation character for an argument with spaces,
- including a pathname, should be ". ' should not be used.
-
- Internally, all arguments are quoted by ' (Unix) or " (Windows)
- before calling the system() function in order to forbid execution
- of any embedded command.
-
- If the --shell-escape option is given, we set
- shellenabledp = 1 and restrictedshell = 0, i.e., any command is allowed.
- If the --shell-restricted option is given, we set
- shellenabledp = 1 and restrictedshell = 1, i.e., only given cmds allowed.
- If the --no-shell-escape option is given, we set
- shellenabledp = -1 (and restrictedshell is irrelevant).
- If none of these option are given, there are three cases:
- (1) In the case where
- shell_escape = y or
- shell_escape = t or
- shell_escape = 1
- it becomes shellenabledp = 1 and restrictedshell = 0,
- that is, any command is allowed.
- (2) In the case where
- shell_escape = p
- it becomes shellenabledp = 1 and restrictedshell = 1,
- that is, restricted shell escape is allowed.
- (3) In all other cases, shellenabledp = 0, that is, shell
- escape is forbidden. The value of restrictedshell is
- irrelevant if shellenabledp == 0.
+/*
+ Shell escape.
+
+ If shellenabledp == 0, all shell escapes are forbidden.
+
+ If (shellenabledp == 1 && restrictedshell == 0), any command is allowed for a
+ shell escape.
+
+ If (shellenabledp == 1 && restrictedshell == 1), only commands given in the
+ configuration file as shell_escape_commands =
+ kpsewhich,ebb,extractbb,mpost,metafun,... (no spaces between commands) in
+ texmf.cnf are allowed for a shell escape in a restricted form: command name
+ and arguments should be separated by a white space. The first word should be
+ a command name. The quotation character for an argument with spaces,
+ including a pathname, should be ". ' should not be used. Internally, all
+ arguments are quoted by ' (Unix) or " (Windows) before calling the system()
+ function in order to forbid execution of any embedded command.
+
+ If the --shell-escape option is given, we set shellenabledp = 1 and
+ restrictedshell = 0, i.e., any command is allowed.
+
+ If the --shell-restricted option is given, we set shellenabledp = 1 and
+ restrictedshell = 1, i.e., only given cmds allowed.
+
+ If the --no-shell-escape option is given, we set shellenabledp = -1 (and
+ restrictedshell is irrelevant).
+
+ If none of these option are given, there are three cases:
+
+ (1) In the case where shell_escape = y or shell_escape = t or shell_escape =
+ 1 it becomes shellenabledp = 1 and restrictedshell = 0, that is, any
+ command is allowed.
+ (2) In the case where shell_escape = p it becomes shellenabledp = 1 and
+ restrictedshell = 1, that is, restricted shell escape is allowed.
+ (3) In all other cases, shellenabledp = 0, that is, shell escape is
+ forbidden. The value of restrictedshell is irrelevant if shellenabledp ==
+ 0.
*/
#ifdef TeX
-/* cmdlist is a list of allowed commands which are given like this:
- shell_escape_commands = kpsewhich,ebb,extractbb,mpost,metafun
- in texmf.cnf. */
+/*
+ The cmdlist is a list of allowed commands which are given like this:
+ shell_escape_commands = kpsewhich,ebb,extractbb,mpost,metafun in texmf.cnf.
+*/
static char **cmdlist = NULL;
@@ -122,8 +120,10 @@ void mk_shellcmdlist(char *v)
q = v;
n = 1;
-/* analyze the variable shell_escape_commands = foo,bar,...
- spaces before and after (,) are not allowed. */
+ /*
+ Analyze the variable shell_escape_commands = foo,bar,... spaces before
+ and after (,) are not allowed.
+ */
while ((r = strchr(q, ',')) != 0) {
n++;
@@ -144,22 +144,22 @@ void mk_shellcmdlist(char *v)
*p = NULL;
}
-/* Called from maininit. Not static because also called from
- luatexdir/lua/luainit.c. */
-
/*
- In order to avoid all kind of time code in the backend code we use a function.
- The start time can be overloaded in several ways:
+ Called from maininit. Not static because also called from
+ luatexdir/lua/luainit.c.
+
+ In order to avoid all kind of time code in the backend code we use a
+ function. The start time can be overloaded in several ways:
- (1) By setting the environmment variable SOURCE_DATE_EPOCH. This will influence
- the tex parameters, random seed, pdf timestamp and pdf id that is derived
- from the time. This variable is consulted when the kpse library is enabled
- which is analogue to other properties.
+ (1) By setting the environmment variable SOURCE_DATE_EPOCH. This will
+ influence the tex parameters, random seed, pdf timestamp and pdf id that is
+ derived from the time. This variable is consulted when the kpse library is
+ enabled which is analogue to other properties.
- (2) By setting the texconfig.start_time variable (as with other variables
- we use the internal name there). This has the same effect as (1) and is
- provided for when kpse is not used to set these variables or when an overloaded
- is wanted. This is analogue to other properties.
+ (2) By setting the texconfig.start_time variable (as with other variables we
+ use the internal name there). This has the same effect as (1) and is provided
+ for when kpse is not used to set these variables or when an overloaded is
+ wanted. This is analogue to other properties.
When an utc time is needed one can provide the flag --utc. This property is
independent of this time hackery. This flag has a corresponding texconfig
@@ -181,9 +181,10 @@ int get_start_time(void) {
}
/*
- This one is called as part of the kpse initialization which only happens
- when this library is enabled.
+ This one is called as part of the kpse initialization which only happens when
+ this library is enabled.
*/
+
#if defined(_MSC_VER)
#define strtoull _strtoui64
#endif
@@ -196,7 +197,6 @@ void init_start_time(void) {
We don't really care how kpse sets up this variable but we prefer to
just use its abstract interface.
*/
- /* char *source_date_epoch = getenv("SOURCE_DATE_EPOCH"); */
char *source_date_epoch = kpse_var_value("SOURCE_DATE_EPOCH");
if (source_date_epoch && source_date_epoch != '\0' ) {
errno = 0;
@@ -205,10 +205,11 @@ void init_start_time(void) {
epoch = 0;
}
#if defined(_MSC_VER)
- /* We avoid to crash if users test a large value which is not
- * supported by Visual Studio 2010:
- * a later time than 3001/01/01 20:59:59.
- */
+ /*
+ We avoid to crash if users test a large value which is not
+ supported by Visual Studio 2010: a later time than 3001/01/01
+ 20:59:59.
+ */
if (epoch > 32535291599ULL)
epoch = 32535291599ULL;
#endif
@@ -231,11 +232,13 @@ void set_start_time(int s) {
void init_shell_escape(void)
{
- if (shellenabledp < 0) { /* --no-shell-escape on cmd line */
+ if (shellenabledp < 0) {
+ /* --no-shell-escape on cmd line */
shellenabledp = 0;
} else {
- if (shellenabledp == 0) { /* no shell options on cmd line, check cnf */
+ if (shellenabledp == 0) {
+ /* no shell options on cmd line, check cnf */
char *v1 = kpse_var_value("shell_escape");
if (v1) {
if (*v1 == 't' || *v1 == 'y' || *v1 == '1') {
@@ -247,8 +250,7 @@ void init_shell_escape(void)
free(v1);
}
}
-
- /* If shell escapes are restricted, get allowed cmds from cnf. */
+ /* If shell escapes are restricted, get allowed cmds from cnf. */
if (shellenabledp && restrictedshell == 1) {
char *v2 = kpse_var_value("shell_escape_commands");
if (v2) {
@@ -269,8 +271,7 @@ void init_shell_escape(void)
# ifdef WIN32
static int char_needs_quote(int c)
{
-/* special characters of cmd.exe */
-
+ /* special characters of cmd.exe */
return (c == '&' || c == '|' || c == '%' || c == '<' ||
c == '>' || c == ';' || c == ',' || c == '(' || c == ')');
}
@@ -282,14 +283,17 @@ static int Isspace(char c)
return (c == ' ' || c == '\t');
}
-/* return values:
- -1 : invalid quotation of an argument
- 0 : command is not allowed
- 2 : restricted shell escape, CMD is allowed.
+/*
+ Return values:
+
+ -1 : invalid quotation of an argument
+ 0 : command is not allowed
+ 2 : restricted shell escape, CMD is allowed.
- We set *SAFECMD to a safely-quoted version of *CMD; this is what
- should get executed. And we set CMDNAME to its first word; this is
- what is checked against the shell_escape_commands list. */
+ We set *SAFECMD to a safely-quoted version of *CMD; this is what should get
+ executed. And we set CMDNAME to its first word; this is what is checked
+ against the shell_escape_commands list.
+*/
int shell_cmd_is_allowed(const char *cmd, char **safecmd, char **cmdname)
{
@@ -301,8 +305,10 @@ int shell_cmd_is_allowed(const char *cmd, char **safecmd, char **cmdname)
unsigned spaces;
int allow = 0;
- /* pre == 1 means that the previous character is a white space
- pre == 0 means that the previous character is not a white space */
+ /*
+ pre == 1 means that the previous character is a white space
+ pre == 0 means that the previous character is not a white space
+ */
buf = xmalloc(strlen(cmd) + 1);
strcpy(buf, cmd);
c = buf;
@@ -313,21 +319,27 @@ int shell_cmd_is_allowed(const char *cmd, char **safecmd, char **cmdname)
d++;
*d = '\0';
- /* *cmdname is the first word of the command line. For example,
- *cmdname == "kpsewhich" for
- \write18{kpsewhich --progname=dvipdfm --format="other text files" config}
- */
+ /*
+ *cmdname is the first word of the command line. For example, *cmdname ==
+ "kpsewhich" for:
+
+ \write18{kpsewhich --progname=dvipdfm --format="other text files" config}
+ */
*cmdname = xstrdup(c);
free(buf);
- /* Is *cmdname listed in a texmf.cnf vriable as
- shell_escape_commands = foo,bar,... ? */
+ /*
+ Is *cmdname listed in a texmf.cnf vriable as shell_escape_commands =
+ foo,bar,... ?
+ */
p = cmdlist;
if (p) {
while (*p) {
if (strcmp(*p, *cmdname) == 0) {
- /* *cmdname is found in the list, so restricted shell escape
- is allowed */
+ /*
+ *cmdname is found in the list, so restricted shell escape is
+ allowed
+ */
allow = 2;
break;
}
@@ -358,22 +370,25 @@ int shell_cmd_is_allowed(const char *cmd, char **safecmd, char **cmdname)
pre = 1;
while (*s) {
- /* Quotation given by a user. " should always be used; we
- transform it below. On Unix, if ' is used, simply immediately
- return a quotation error. */
+ /*
+ Quotation given by a user. " should always be used; we transform
+ it below. On Unix, if ' is used, simply immediately return a
+ quotation error.
+ */
if (*s == '\'') {
return -1;
}
if (*s == '"') {
- /* All arguments are quoted as 'foo' (Unix) or "foo" (Windows)
- before calling system(). Therefore closing QUOTE is necessary
- if the previous character is not a white space.
- example:
- --format="other text files" becomes
- '--format=''other text files' (Unix)
- "--format"="other text files" (Windows) */
-
+ /*
+ All arguments are quoted as 'foo' (Unix) or "foo" (Windows)
+ before calling system(). Therefore closing QUOTE is necessary
+ if the previous character is not a white space. For example:
+
+ --format="other text files" becomes
+ '--format=''other text files' (Unix)
+ "--format"="other text files" (Windows)
+ */
if (pre == 0) {
# ifdef WIN32
if (*(s-1) == '=') {
@@ -386,14 +401,17 @@ int shell_cmd_is_allowed(const char *cmd, char **safecmd, char **cmdname)
*d++ = QUOTE;
# endif
}
-
pre = 0;
- /* output the quotation mark for the quoted argument */
+ /*
+ Output the quotation mark for the quoted argument.
+ */
*d++ = QUOTE;
s++;
while (*s != '"') {
- /* Illegal use of ', or closing quotation mark is missing */
+ /*
+ Illegal use of ', or closing quotation mark is missing
+ */
if (*s == '\'' || *s == '\0')
return -1;
# if 0
@@ -404,17 +422,20 @@ int shell_cmd_is_allowed(const char *cmd, char **safecmd, char **cmdname)
# endif
*d++ = *s++;
}
-
- /* Closing quotation mark will be output afterwards, so
- we do nothing here */
+ /*
+ Closing quotation mark will be output afterwards, so we do
+ nothing here.
+ */
s++;
-
- /* The character after the closing quotation mark
- should be a white space or NULL */
+ /*
+ The character after the closing quotation mark should be a
+ white space or NULL.
+ */
if (!Isspace(*s) && *s)
return -1;
-
- /* Beginning of a usual argument */
+ /*
+ Beginning of a usual argument.
+ */
} else if (pre == 1 && !Isspace(*s)) {
pre = 0;
*d++ = QUOTE;
@@ -425,15 +446,18 @@ int shell_cmd_is_allowed(const char *cmd, char **safecmd, char **cmdname)
# endif
# endif
*d++ = *s++;
- /* Ending of a usual argument */
-
+ /*
+ Ending of a usual argument.
+ */
} else if (pre == 0 && Isspace(*s)) {
pre = 1;
/* Closing quotation mark */
*d++ = QUOTE;
*d++ = *s++;
} else {
- /* Copy a character from cmd to *safecmd. */
+ /*
+ Copy a character from cmd to *safecmd.
+ */
# if 0
# ifdef WIN32
if (char_needs_quote(*s))
@@ -443,7 +467,9 @@ int shell_cmd_is_allowed(const char *cmd, char **safecmd, char **cmdname)
*d++ = *s++;
}
}
- /* End of the command line */
+ /*
+ End of the command line.
+ */
if (pre == 0) {
*d++ = QUOTE;
}
@@ -464,44 +490,45 @@ int shell_cmd_is_allowed(const char *cmd, char **safecmd, char **cmdname)
} else if (!IS_DIR_SEP (p[0]) && !(p[1] == ':' && IS_DIR_SEP (p[2]))) {
p = kpse_var_value ("SELFAUTOLOC");
if (p) {
- r = *safecmd;
- while (*r && !Isspace(*r))
- r++;
- if (*r == '\0')
- q = concatn ("\"", p, "/", *safecmd, "\"", NULL);
- else {
- *r = '\0';
- r++;
- while (*r && Isspace(*r))
- r++;
- if (*r)
- q = concatn ("\"", p, "/", *safecmd, "\" ", r, NULL);
- else
- q = concatn ("\"", p, "/", *safecmd, "\"", NULL);
- }
- free (p);
- free (*safecmd);
- *safecmd = q;
+ r = *safecmd;
+ while (*r && !Isspace(*r))
+ r++;
+ if (*r == '\0')
+ q = concatn ("\"", p, "/", *safecmd, "\"", NULL);
+ else {
+ *r = '\0';
+ r++;
+ while (*r && Isspace(*r))
+ r++;
+ if (*r)
+ q = concatn ("\"", p, "/", *safecmd, "\" ", r, NULL);
+ else
+ q = concatn ("\"", p, "/", *safecmd, "\"", NULL);
+ }
+ free (p);
+ free (*safecmd);
+ *safecmd = q;
}
}
}
#endif
}
-
return allow;
}
#endif
-
-/* What we were invoked as and with. */
+/* What we were invoked as and with. */
+
char **argv;
int argc;
/* The C version of what might wind up in |TEX_format_default|. */
+
string dump_name;
/* The C version of the jobname, if given. */
+
const_string c_job_name;
const char *luatex_banner;
@@ -509,28 +536,28 @@ const char *luatex_banner;
#ifdef _MSC_VER
/* Invalid parameter handler */
static void myInvalidParameterHandler(const wchar_t * expression,
- const wchar_t * function,
- const wchar_t * file,
- unsigned int line,
- uintptr_t pReserved)
+ const wchar_t * function,
+ const wchar_t * file,
+ unsigned int line,
+ uintptr_t pReserved)
{
/*
- printf(L"Invalid parameter detected in function %s."
- L" File: %s Line: %d\n", function, file, line);
- printf(L"Expression: %s\n", expression);
-*/
-/*
- I return silently to avoid an exit with the error 0xc0000417
- (invalid parameter) when we use non-embedded fonts in luatex-ja,
- which works without any problem on Unix systems.
- I hope it is not dangerous.
+ printf(L"Invalid parameter detected in function %s."
+ L" File: %s Line: %d\n", function, file, line);
+ printf(L"Expression: %s\n", expression);
+
+ I return silently to avoid an exit with the error 0xc0000417 (invalid
+ parameter) when we use non-embedded fonts in luatex-ja, which works without
+ any problem on Unix systems. I hope it is not dangerous.
*/
return;
}
#endif
-/* The entry point: set up for reading the command line, which will
- happen in `topenin', then call the main body. */
+/*
+ The entry point: set up for reading the command line, which will happen in
+ `topenin', then call the main body.
+*/
int
#if defined(DLLPROC)
@@ -551,9 +578,10 @@ main (int ac, string *av)
av[0] = kpse_program_basename (av[0]);
_setmaxstdio(2048);
/*
- * We choose to crash for fatal errors
+ We choose to crash for fatal errors:
+
SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
- */
+*/
setmode(fileno(stdin), _O_BINARY);
# endif
@@ -561,24 +589,23 @@ main (int ac, string *av)
# ifdef WIN32
if (ac > 1) {
- char *pp;
- if ((strlen(av[ac-1]) > 2) &&
- isalpha(av[ac-1][0]) &&
- (av[ac-1][1] == ':') &&
- (av[ac-1][2] == '\\')) {
- for (pp=av[ac-1]+2; *pp; pp++) {
- if (IS_KANJI(pp)) {
- pp++;
- continue;
- }
- if (*pp == '\\')
- *pp = '/';
+ char *pp;
+ if ((strlen(av[ac-1]) > 2) && isalpha(av[ac-1][0]) && (av[ac-1][1] == ':') && (av[ac-1][2] == '\\')) {
+ for (pp=av[ac-1]+2; *pp; pp++) {
+ if (IS_KANJI(pp)) {
+ pp++;
+ continue;
+ }
+ if (*pp == '\\')
+ *pp = '/';
+ }
}
- }
}
# endif
- /* Call the real main program. */
+ /*
+ Call the real main program.
+ */
main_body();
return EXIT_SUCCESS;
@@ -586,20 +613,20 @@ main (int ac, string *av)
/*
- This is supposed to ``open the terminal for input'', but what we
- really do is copy command line arguments into TeX's or Metafont's
- buffer, so they can handle them. If nothing is available, or we've
- been called already (and hence, argc==0), we return with
- `last=first'.
+ This is supposed to ``open the terminal for input'', but what we really do is
+ copy command line arguments into TeX's or Metafont's buffer, so they can
+ handle them. If nothing is available, or we've been called already (and
+ hence, argc==0), we return with `last=first'.
*/
void topenin(void)
{
int i;
- buffer[first] = 0; /* In case there are no arguments. */
+ buffer[first] = 0; /* In case there are no arguments. */
- if (optind < argc) { /* We have command line arguments. */
+ if (optind < argc) {
+ /* We have command line arguments. */
int k = first;
for (i = optind; i < argc; i++) {
char *ptr = &(argv[i][0]);
@@ -611,7 +638,8 @@ void topenin(void)
}
buffer[k++] = ' ';
}
- argc = 0; /* Don't do this again. */
+ /* Don't do this again. */
+ argc = 0;
buffer[k] = 0;
}
@@ -649,268 +677,19 @@ void topenin(void)
*/
#define IS_SPC_OR_EOL(c) ((c) == ' ' || (c) == '\r' || (c) == '\n')
- for (--last; last >= first && IS_SPC_OR_EOL (buffer[last]); --last)
- ;
- last++;
-
+ for (--last; last >= first && IS_SPC_OR_EOL (buffer[last]); --last);
+ last++;
/*
One more time, this time converting to TeX's internal character
representation.
*/
}
-/* IPC for TeX. By Tom Rokicki for the NeXT; it makes TeX ship out the
- DVI file in a pipe to TeXView so that the output can be displayed
- incrementally. Shamim Mohamed adapted it for Web2c. */
-
-#if defined (TeX) && defined (IPC)
-
-#ifdef WIN32
-#undef _WINSOCKAPI_
-#include <winsock2.h>
-#else
-#include <sys/socket.h>
-#include <fcntl.h>
-#ifndef O_NONBLOCK /* POSIX */
-#ifdef O_NDELAY /* BSD */
-#define O_NONBLOCK O_NDELAY
-#elif defined(O_FNDELAY) /* NeXT */
-#define O_NONBLOCK O_FNDELAY
-#else
-what the fcntl? cannot implement IPC without equivalent for O_NONBLOCK.
-#endif
-#endif /* no O_NONBLOCK */
-#endif /* !WIN32 */
-
-#ifdef WIN32
-# define IPC_AF AF_INET
-# ifndef IPC_LOCAL_HOST
-# define IPC_LOCAL_HOST "127.0.0.1"
-# define FIXED_PORT (unsigned short)4242
-# endif
-#else
-# define IPC_AF AF_UNIX
-# ifndef IPC_PIPE_NAME /* $HOME is prepended to this. */
-# define IPC_PIPE_NAME "/.TeXview_Pipe"
-# endif
-#endif
-#ifndef IPC_SERVER_CMD /* Command to run to start the server. */
-# ifdef WIN32
-# define IPC_SERVER_CMD "texview.exe"
-# else
-# define IPC_SERVER_CMD "open `which TeXview`"
-# endif
-#endif
-
-struct msg
-{
- int namelength; /* length of auxiliary data */
- int eof; /* new eof for dvi file */
-#if 0 /* see usage of struct msg below */
- char more_data[0]; /* where the rest of the stuff goes */
-#endif
-};
-
-static struct sockaddr *ipc_addr;
-static int ipc_addr_len;
-
-static int
-ipc_make_name (void)
-{
- if (ipc_addr_len == 0) {
-#ifdef WIN32
- unsigned long remote_addr = inet_addr(IPC_LOCAL_HOST);
- if (remote_addr != INADDR_NONE) {
- struct sockaddr_in *ipc_sin_addr = xmalloc (sizeof (struct sockaddr_in));
- ipc_sin_addr->sin_family = AF_INET;
- ipc_sin_addr->sin_addr.s_addr = remote_addr;
- ipc_sin_addr->sin_port = htons (FIXED_PORT);
- ipc_addr = ((struct sockaddr *) ipc_sin_addr);
- ipc_addr_len = sizeof(struct sockaddr_in);
- }
-#else
- string s = getenv ("HOME");
- if (s) {
- char *ipc_name;
- ipc_addr = xmalloc (strlen (s) + 40);
- ipc_addr->sa_family = 0;
- ipc_name = ipc_addr->sa_data;
- strcpy (ipc_name, s);
- strcat (ipc_name, IPC_PIPE_NAME);
- ipc_addr_len = strlen (ipc_name) + 3;
- }
-#endif
- }
- return ipc_addr_len;
-}
-
-static int sock = -1;
-
-#ifdef WIN32
-# define CLOSE_SOCKET(s) closesocket (s); WSACleanup ()
-#else
-# define CLOSE_SOCKET(s) close (s)
-#endif
-
-static int
-ipc_is_open (void)
-{
- return sock != -1;
-}
-
-static void
-ipc_open_out (void) {
-#ifdef WIN32
- struct WSAData wsaData;
- int nCode;
- unsigned long mode = 1;
-#endif
-#ifdef IPC_DEBUG
- fputs ("tex: Opening socket for IPC output ...\n", stderr);
-#endif
- if (sock != -1) {
- return;
- }
-
-#ifdef WIN32
- if ((nCode = WSAStartup(MAKEWORD(1, 1), &wsaData)) != 0) {
- fprintf(stderr,"WSAStartup() returned error code %d.\n", nCode);
- return;
- }
-#endif
-
- if (ipc_make_name () <= 0)
- return;
-
- sock = socket (IPC_AF, SOCK_STREAM, 0);
-#ifdef IPC_DEBUG
- if(sock != -1)
- fprintf(stderr, "tex: Socket handle is %d\n", sock);
- else
- fprintf(stderr, "tex: Socket is invalid.\n");
-#endif
-
- if (sock != -1) {
- if (connect (sock, ipc_addr, ipc_addr_len) != 0 ||
-#ifdef WIN32
- ioctlsocket (sock, FIONBIO, &mode) < 0
-#else
- fcntl (sock, F_SETFL, O_NONBLOCK) < 0
-#endif
- ) {
- CLOSE_SOCKET (sock);
- sock = -1;
-#ifdef IPC_DEBUG
- fputs ("tex: IPC socket cannot be connected.\n", stderr);
- fputs ("tex: Socket is closed.\n", stderr);
-#endif
- return;
- }
-#ifdef IPC_DEBUG
- fputs ("tex: Successfully opened IPC socket.\n", stderr);
-#endif
- }
-}
-
-static void
-ipc_close_out (void)
-{
-#ifdef IPC_DEBUG
- fputs ("tex: Closing output socket ...\n", stderr);
-#endif
- if (ipc_is_open ()) {
- CLOSE_SOCKET (sock);
- sock = -1;
- }
-}
-
-static void
-ipc_snd (int n, int is_eof, char *data)
-{
- struct
- {
- struct msg msg;
- char more_data[1024];
- } ourmsg;
-
- if (!ipc_is_open ()) {
- return;
- }
-
-#ifdef IPC_DEBUG
- fprintf(stderr, "%d\t%d\n", ourmsg.msg.namelength, ourmsg.msg.eof);
- fputs ("tex: Sending message to socket ...\n", stderr);
-#endif
- ourmsg.msg.namelength = n;
- ourmsg.msg.eof = is_eof;
- if (n) {
- strcpy (ourmsg.more_data, data);
- }
- n += sizeof (struct msg);
-#ifdef IPC_DEBUG
- fprintf(stderr, "%d\t%d\n", ourmsg.msg.namelength, ourmsg.msg.eof);
- fputs ("tex: Writing to socket...\n", stderr);
-#endif
-#if defined(WIN32)
- if (send (sock, (char *)&ourmsg, n, 0) != n) {
-#else
- if (write (sock, &ourmsg, n) != n) {
-#endif
- ipc_close_out ();
- }
-#ifdef IPC_DEBUG
- fputs ("tex: IPC message sent.\n", stderr);
-#endif
-}
-
-/* This routine notifies the server if there is an eof, or the filename
- if a new DVI file is starting. This is the routine called by TeX.
- Aleph defines str_start(#) as str_start_ar[# - too_big_char], with
- too_big_char = biggest_char + 1 = 65536 (omstr.ch). */
-
-void
-ipcpage (int is_eof)
-{
- static boolean begun = false;
- unsigned len = 0;
- string p = NULL;
-
- if (!begun) {
- string name; /* Just the filename. */
- string cwd = xgetcwd ();
-
- ipc_open_out ();
-
- /* Have to pass whole filename to the other end, since it may have
- been started up and running as a daemon, e.g., as with the NeXT
- preview program. */
- name = static_pdf->file_name;
- p = concat3 (cwd, DIR_SEP_STRING, name);
- free (cwd);
- free (name);
-
-#if defined (WIN32)
- { char *q;
- for (q = p; *q; q++) {
- if (*q == '\\')
- *q = '/';
- else if (IS_KANJI(q))
- q++;
- }
- }
-#endif
- len = strlen(p);
- begun = true;
- }
- ipc_snd (len, is_eof, p);
-
- if (p)
- free (p);
-}
-#endif /* TeX && IPC */
+/*
+ Normalize quoting of filename -- that is, only quote if there is a space, and
+ always use the quote-name-quote style.
+*/
-/* Normalize quoting of filename -- that is, only quote if there is a space,
- and always use the quote-name-quote style. */
string normalize_quotes(const_string name, const_string mesg)
{
boolean quoted = false;
@@ -939,8 +718,11 @@ string normalize_quotes(const_string name, const_string mesg)
}
-/* All our interrupt handler has to do is set TeX's or Metafont's global
- variable `interrupt'; then they will do everything needed. */
+/*
+ All our interrupt handler has to do is set TeX's or Metafont's global
+ variable `interrupt'; then they will do everything needed.
+*/
+
#ifdef WIN32
/* Win32 doesn't set SIGINT ... */
static BOOL WINAPI catch_interrupt(DWORD arg)
@@ -955,7 +737,7 @@ static BOOL WINAPI catch_interrupt(DWORD arg)
return FALSE;
}
}
-#else /* not WIN32 */
+#else /* not WIN32 */
static RETSIGTYPE catch_interrupt(int arg)
{
(void) arg;
@@ -964,15 +746,16 @@ static RETSIGTYPE catch_interrupt(int arg)
(void) signal(SIGINT, SIG_ACK);
# else
(void) signal(SIGINT, catch_interrupt);
-# endif /* not OS2 */
+# endif /* not OS2 */
}
-#endif /* not WIN32 */
+#endif /* not WIN32 */
-/* Besides getting the date and time here, we also set up the interrupt
- handler, for no particularly good reason. It's just that since the
- `fix_date_and_time' routine is called early on (section 1337 in TeX,
- ``Get the first line of input and prepare to start''), this is as
- good a place as any. */
+/*
+ Besides getting the date and time here, we also set up the interrupt handler,
+ for no particularly good reason. It's just that since the `fix_date_and_time'
+ routine is called early on (section 1337 in TeX, ``Get the first line of
+ input and prepare to start''), this is as good a place as any.
+*/
void get_date_and_time(int *minutes, int *day, int *month, int *year)
{
@@ -991,11 +774,14 @@ void get_date_and_time(int *minutes, int *day, int *month, int *year)
{
#ifdef SA_INTERRUPT
- /* Under SunOS 4.1.x, the default action after return from the
- signal handler is to restart the I/O if nothing has been
- transferred. The effect on TeX is that interrupts are ignored if
- we are waiting for input. The following tells the system to
- return EINTR from read() in this case. From ken@cs.toronto.edu. */
+
+ /*
+ Under SunOS 4.1.x, the default action after return from the signal
+ handler is to restart the I/O if nothing has been transferred. The
+ effect on TeX is that interrupts are ignored if we are waiting for
+ input. The following tells the system to return EINTR from read() in
+ this case. From ken@cs.toronto.edu.
+ */
struct sigaction a, oa;
@@ -1006,23 +792,24 @@ void get_date_and_time(int *minutes, int *day, int *month, int *year)
sigaction(SIGINT, &a, &oa);
if (oa.sa_handler != SIG_DFL)
sigaction(SIGINT, &oa, (struct sigaction *) 0);
-#else /* no SA_INTERRUPT */
+#else /* no SA_INTERRUPT */
# ifdef WIN32
SetConsoleCtrlHandler(catch_interrupt, TRUE);
-# else /* not WIN32 */
+# else /* not WIN32 */
RETSIGTYPE(*old_handler) (int);
old_handler = signal(SIGINT, catch_interrupt);
if (old_handler != SIG_DFL)
signal(SIGINT, old_handler);
-# endif /* not WIN32 */
-#endif /* no SA_INTERRUPT */
+# endif /* not WIN32 */
+#endif /* no SA_INTERRUPT */
}
}
-
+
/*
- Getting a high resolution time.
- */
+ Getting a high resolution time.
+*/
+
void get_seconds_and_micros(int *seconds, int *micros)
{
#if defined (HAVE_GETTIMEOFDAY)
@@ -1043,8 +830,9 @@ void get_seconds_and_micros(int *seconds, int *micros)
}
/*
- Generating a better seed numbers
- */
+ Generating a better seed numbers
+*/
+
int getrandomseed(void)
{
#if defined (HAVE_GETTIMEOFDAY)
@@ -1066,11 +854,13 @@ int getrandomseed(void)
return (tmptr->tm_sec + 60 * (tmptr->tm_min + 60 * tmptr->tm_hour));
#endif
}
-
-/* Read a line of input as efficiently as possible while still looking
- like Pascal. We set `last' to `first' and return `false' if we get
- to eof. Otherwise, we return `true' and set last = first +
- length(line except trailing whitespace). */
+
+/*
+ Read a line of input as efficiently as possible while still looking like
+ Pascal. We set `last' to `first' and return `false' if we get to eof.
+ Otherwise, we return `true' and set last = first + length(line except
+ trailing whitespace).
+*/
boolean input_line(FILE * f)
{
@@ -1079,15 +869,14 @@ boolean input_line(FILE * f)
#ifdef WIN32
if (f != Poptr && fileno (f) != fileno (stdin)) {
long position = ftell (f);
-
- if (position == 0L) { /* Detect and skip Byte order marks. */
+ if (position == 0L) {
+ /* Detect and skip Byte order marks. */
int k1 = getc (f);
if (k1 != 0xff && k1 != 0xfe && k1 != 0xef)
rewind (f);
else {
int k2 = getc (f);
-
if (k2 != 0xff && k2 != 0xfe && k2 != 0xbb)
rewind (f);
else if ((k1 == 0xff && k2 == 0xfe) || /* UTF-16(LE) */
@@ -1106,7 +895,9 @@ boolean input_line(FILE * f)
}
}
#endif
- /* Recognize either LF or CR as a line terminator. */
+ /*
+ Recognize either LF or CR as a line terminator.
+ */
last = first;
while (last < buf_size && (i = getc(f)) != EOF && i != '\n' && i != '\r')
buffer[last++] = (packed_ASCII_code) i;
@@ -1114,7 +905,9 @@ boolean input_line(FILE * f)
if (i == EOF && errno != EINTR && last == first)
return false;
- /* We didn't get the whole line because our buffer was too small. */
+ /*
+ We didn't get the whole line because our buffer was too small.
+ */
if (i != EOF && i != '\n' && i != '\r') {
fprintf(stderr, "! Unable to read an entire line---bufsize=%u.\n",
(unsigned) buf_size);
@@ -1126,32 +919,37 @@ boolean input_line(FILE * f)
if (last >= max_buf_stack)
max_buf_stack = last;
- /* If next char is LF of a CRLF, read it. */
+ /*
+ If next char is LF of a CRLF, read it.
+ */
if (i == '\r') {
while ((i = getc(f)) == EOF && errno == EINTR);
if (i != '\n')
ungetc(i, f);
}
- /* Trim trailing space character (but not, e.g., tabs). We can't have
- line terminators because we stopped reading at the first \r or \n.
- TeX's rule is to strip only trailing spaces (and eols). David
- Fuchs mentions that this stripping was done to ensure portability
- of TeX documents given the padding with spaces on fixed-record
- "lines" on some systems of the time, e.g., IBM VM/CMS and OS/360. */
- while (last > first && buffer[last - 1] == ' ')
+ /*
+ Trim trailing space character (but not, e.g., tabs). We can't have line
+ terminators because we stopped reading at the first \r or \n. TeX's rule
+ is to strip only trailing spaces (and eols). David Fuchs mentions that
+ this stripping was done to ensure portability of TeX documents given the
+ padding with spaces on fixed-record "lines" on some systems of the time,
+ e.g., IBM VM/CMS and OS/360.
+ */
+ while (last > first && buffer[last - 1] == ' ')
--last;
- /* Don't bother using xord if we don't need to. */
+ /*
+ Don't bother using xord if we don't need to.
+ */
return true;
}
+/*
+ Get the job name to be used, which may have been set from the command line.
+*/
-
-
-/* Get the job name to be used, which may have been set from the
- command line. */
str_number getjobname(str_number name)
{
str_number ret = name;