OSDN Git Service

removed libmd5.
[putex/putex.git] / src / texsourc / yandytex.c
index 133b50d..fefec3e 100644 (file)
-/* Copyright 1992 Karl Berry
-   Copyright 2007 TeX Users Group
-   Copyright 2014 Clerk Ma
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301 USA.  */
-
-#define EXTERN
-
-#include "yandytex.h"
-
-#define dump_ext_length     4
-#define edit_value          tex_edit_value
-
-extern char * replacement[];
-int    gargc;
-char **gargv;
-
-int jump_used = 0;
-
-jmp_buf jumpbuffer;
-
-int main (int ac, char *av[])
-{
-  int flag = 0, ret = 0;
-
-  gargc = ac;
-  gargv = av;
-
-  if (main_init(gargc, gargv))
-    return -1;
-
-  TEX_format_default = " plain.fmt";
-  format_default_length = strlen(TEX_format_default + 1);
-
-  jump_used = 0;
-
-  ret = setjmp(jumpbuffer);
-
-  if (ret == 0)
-  {
-    flag = main_program();
-
-    if (trace_flag)
-      printf("EXITING at %s: flag = %d, ret = %d, jump_used = %d\n", "main", flag, ret, jump_used);
-  }
-  else
-  {
-    if (trace_flag)
-      printf("EXITING at %s: flag = %d, ret = %d, jump_used =  %d\n", "jump_out", flag, ret, jump_used);
-  }
-
-  if (endit(flag) != 0)
-    flag = 1; /* do final clean up in local.c */
-
-  if (flag == 0)
-    return 0;
-  else
-    exit (flag);
-}
-
-/* texk/web2c/lib/texmfmp.c */
-void t_open_in (void)
-{
-  int i;
-
-  buffer[first] = 0;
-
-  if (gargc > optind && optind > 0)
-  {
-    for (i = optind; i < gargc; i++)
-    {
-      if (allow_quoted_names && strchr(gargv[i], ' ') != NULL)
-      {
-        (void) strcat ((char *) &buffer[first], "\"");
-        (void) strcat ((char *) &buffer[first], gargv[i]);
-        (void) strcat ((char *) &buffer[first], "\"");
-      }
-      else
-        (void) strcat ((char *) &buffer[first], gargv[i]);
-
-      (void) strcat ((char *) &buffer[first], " ");
-    }
-    
-    gargc = 0;
-  }
-
-  /* Find the end of the buffer.  */
-  for (last = first; buffer[last]; ++last)
-    do_nothing();
-
-  for (--last; last >= first && ISBLANK (buffer[last]) && buffer[last] != '\r'; --last)
-    do_nothing();
-
-  last++;
-
-/* One more time, this time converting to TeX's internal character
-   representation.  */ /* for command line input in this case */
-  if (non_ascii)
-  {
-    for (i = first; i < last; i++)
-      buffer[i] = xord[buffer[i]];
-  }
-}
-
-static void catch_interrupt (int err)
-{
-  (void) err;
-  (void) signal(SIGINT, SIG_IGN);
-
-  if (interrupt++ >= 3)
-    exit(1);
-
-  (void) signal(SIGINT, catch_interrupt);
-}
-
-void fix_date_and_time (void)
-{
-  time_t clock;
-  struct tm *tmptr;
-
-  (void) time(&clock);
-
-  if (trace_flag)
-    printf("The time is %lld\n", (long long)clock);
-
-  if (clock < 0)
-    puts("Time not available!");
-
-  tmptr = localtime (&clock);
-
-  if (tmptr == NULL)
-  {
-    printf("Cannot convert time (%0lld)!\n", (long long)clock);
-    year     = 2038;
-    month    = 1;
-    day      = 18;
-    tex_time = 22 * 60 + 14;
-  }
-  else
-  {
-    tex_time = tmptr->tm_hour * 60 + tmptr->tm_min;
-    day      = tmptr->tm_mday;
-    month    = tmptr->tm_mon + 1;
-    year     = tmptr->tm_year + 1900;
-
-    if (trace_flag)
-      printf("%d-%d-%d %d:%d\n",
-        tmptr->tm_year + 1900,
-        tmptr->tm_mon + 1,
-        tmptr->tm_mday,
-        tmptr->tm_hour,
-        tmptr->tm_min);
-  }
-
-  {
-#ifdef _WIN32
-    if (signal(SIGINT, catch_interrupt) == SIG_ERR)
-    {
-      puts(" CTRL-C handler not installed");
-      uexit(EXIT_FAILURE);
-    }
-#else
-    void (*old_handler)();
-
-    old_handler = signal(SIGINT, catch_interrupt);
-
-    if (old_handler != SIG_DFL)
-      (void) signal(SIGINT, old_handler);
-#endif
-  }
-}
-
-/* I/O for TeX and Metafont. */
-void complain_line (FILE * output)
-{
-  show_line("\n", 0);
-
-#ifdef ALLOCATEBUFFER
-  sprintf(log_line, "! Unable to read an entire line---buf_size=%d.\n", current_buf_size);
-#else
-  sprintf(log_line, "! Unable to read an entire line---buf_size=%d.\n", buf_size);
-#endif
-
-  fputs(log_line, output);
-  puts("  (File may have a line termination problem.)");
-}
-
-void show_bad_line (FILE * output, int first, int last)
-{
-  int i, c, d, ch;
-  char *s = log_line;
-
-  for (i = first; i <= last; i++)
-  {
-    ch = buffer[i];
-
-    if (show_in_hex && (ch > 127))
-    {
-      c = ch >> 4;
-      d = ch & 15;
-
-      if (c > 9)
-        c = c + 'a' - 10;
-      else
-        c = c + '0';
-
-      if (d > 9)
-        d = d + 'a' - 10;
-      else
-        d = d + '0';
-
-      *s++ = '^';
-      *s++ = '^';
-
-      *s++ = (char) c;
-      *s++ = (char) d;
-    }
-    else if (ch < 32)
-    {
-      *s++ = '^';
-      *s++ = '^';
-      *s++ = (char) (ch + 64);
-    }
-    else if (ch == 127)
-    {
-      *s++ = '^';
-      *s++ = '^';
-      *s++ = (char) (ch - 64);
-    }
-    else
-    {
-      *s++ = (char) ch;
-    }
-  }
-
-  *s++ = ' ';
-  *s++ = '\0';
-
-  fputs(log_line, output);   // log_file
-}
-
-boolean input_line_finish (void)
-{
-  int i = '\0';
-  int ch, flag;
-
-  buffer[last] = ' ';
-
-  if (last >= max_buf_stack)
-    max_buf_stack = last;
-
-  while (last > first)
-  {
-    i = buffer[last - 1];
-
-    if (i == ' ' || i == '\t')
-      --last;
-    else
-      break;
-  }
-
-  if (restrict_to_ascii)
-  {
-    flag = 0;
-
-    for (i = first; i <= last; i++)
-    {
-      ch = buffer[i];
-
-      if (ch > 126 ||  (ch < ' ' && ch != '\t' && ch != '\f' && ch != '\r' && ch != '\n'))
-      {
-        sprintf(log_line, "\n! non ASCII char (%d) in line: ", ch);
-        show_line(log_line, 1);
-
-        if (log_opened)
-          fprintf(log_file, "\n! non ASCII char (%d) in line: ", ch);
-
-        flag = 1;
-        break;
-      }
-    }
-
-    if (flag)
-    {
-      show_bad_line(errout, first, last);
-
-      if (log_opened)
-        show_bad_line(log_file, first, last);
-    }
-  }
-
-  if (non_ascii)
-  {
-    for (i = first; i <= last; i++)
-      buffer[i] = xord[buffer[i]];
-  }
-
-  return true;
-}
-
-/* Read a line of input into buffer as efficiently as possible (ha ha)
-   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)
-{
-  char * u;        /* 1994/July/3 for key_replace */
-  int i = '\0';
-
-  last = first;
-/*  following is new version with tab expansion and key replacement */
-/*  may want to expand out separately for speed 1994/July/3 */
-/*  different versions depending on return_flag / tabexpand / key_replace */
-/*  while (last < buf_size && (i = getc (f)) != EOF)  */
-#ifdef ALLOCATEBUFFER
-  for ( ; ; ) 
-#else
-  while (last < buf_size) 
-#endif
-  {
-    i = getc(f);
-
-    if (i < ' ')
-    {
-      if (i == EOF || i == '\n' || (i == '\r' && return_flag))
-        break;
-      else if (i == '\t' && tab_step != 0)
-      {
-        buffer[last++] = (ASCII_code) ' ';
-
-#ifdef ALLOCATEBUFFER
-        if (last >= current_buf_size)
-        {
-          buffer = realloc_buffer(increment_buf_size);  
-
-          if (last >= current_buf_size)
-            break;
-        }
-#endif
-
-#ifdef ALLOCATEBUFFER
-        while ((last - first) % tab_step != 0) 
-#else
-        while (last < buf_size && (last - first) % tab_step != 0)
-#endif
-        {
-
-          buffer[last++] = (ASCII_code) ' ';
-
-#ifdef ALLOCATEBUFFER
-          if (last >= current_buf_size)
-          {
-            buffer = realloc_buffer(increment_buf_size);
-
-            if (last >= current_buf_size)
-              break;
-          }
-#endif
-        }
-
-        continue;
-      }
-    }
-
-    if (key_replace && (u = replacement[i]) != NULL)
-    {
-#ifdef ALLOCATEBUFFER
-      while (*u != '\0') 
-#else
-      while (last < buf_size && *u != '\0')  
-#endif
-      {
-        buffer[last++] = (ASCII_code) *u++;
-
-#ifdef ALLOCATEBUFFER
-        if (last >= current_buf_size)
-        {
-          buffer = realloc_buffer(increment_buf_size);
-
-          if (last >= current_buf_size)
-            break;
-        }
-#endif
-      }
-    }
-    else       /* normal case */
-    {
-      buffer[last++] = (ASCII_code) i;
-
-#ifdef ALLOCATEBUFFER
-      if (last >= current_buf_size)
-      {
-        buffer = realloc_buffer(increment_buf_size);
-
-        if (last >= current_buf_size)
-          break;
-      }
-#endif
-    }
-  }
-
-  if (return_flag)    /* let return terminate line as well as newline */
-  {
-    if (i == '\r')      /* see whether return followed by newline */
-    {
-      i = getc (f);       /* in which case throw away the newline */
-
-      if (i != '\n')
-      {
-        ungetc (i, f);
-        i = '\r';
-      }
-/*      else  buffer[last-1] = (ASCII_code) i; */
-    }
-  }
-
-  //  Turn Ctrl-Z at end of file into newline 2000 June 22
-  if (i == EOF && trimeof && buffer[last - 1] == 26)
-  {
-    last--;
-  }
-
-  if (i == EOF && last == first)
-    return false;
-
-/*  Didn't get the whole line because buffer was too small?  */
-/*  This shouldn't happen anymore 99/Jan/23 */
-  if (i != EOF && i != '\n' && i != '\r')
-  {
-    complain_line(errout);
-
-    if (log_opened)
-      complain_line(log_file);
-
-    /* This may no longer be needed ... now that we grow it */
-    if (truncate_long_lines)
-    {
-      while (i != EOF && i != '\n' && i != '\r')
-      {
-        i = getc (f);     // discard rest of line
-      }
-
-      last--;       /* just in case */
-    }
-    else
-      uexit(EXIT_FAILURE);      /* line too long */
-  }
-
-  return input_line_finish();
-}
-
-static char * edit_value = "c:\\yandy\\WinEdt\\WinEdt.exe [Open('%s');SelLine(%d,7)]";
-
-static inline int Isspace (char c)
-{
-  return (c == ' ' || c == '\t');
-}
-
-void call_edit (ASCII_code * filename, pool_pointer fnstart, integer fnlength, integer linenumber)
-{
-  char *temp, *command, *fullcmd;
-  char c;
-  int sdone, ddone, i;
-
-#ifdef WIN32
-  char *fp, *ffp, *env, editorname[256], buffer[256];
-  int cnt = 0;
-  int dontchange = 0;
-#endif
-
-  sdone = ddone = 0;
-  filename += fnstart;
-
-  /* Close any open input files, since we're going to kill the job.  */
-  for (i = 1; i <= in_open; i++)
-#ifdef XeTeX
-    xfclose (input_file[i]->f, "inputfile");
-#else
-    xfclose (input_file[i], "inputfile");
-#endif
-
-  /* Replace the default with the value of the appropriate environment
-     variable or config file value, if it's set.  */
-  temp = kpse_var_value("TEXEDIT");
-
-  if (temp != NULL)
-    edit_value = temp;
-
-  /* Construct the command string.  The `11' is the maximum length an
-     integer might be.  */
-  command = (char *) xmalloc (strlen (edit_value) + fnlength + 11);
-
-  /* So we can construct it as we go.  */
-  temp = command;
-
-#ifdef WIN32
-  fp = editorname;
-  if ((isalpha(*edit_value) && *(edit_value + 1) == ':'
-        && IS_DIR_SEP (*(edit_value + 2)))
-      || (*edit_value == '"' && isalpha(*(edit_value + 1))
-        && *(edit_value + 2) == ':'
-        && IS_DIR_SEP (*(edit_value + 3)))
-     )
-    dontchange = 1;
-#endif
-
-  while ((c = *edit_value++) != 0)
-  {
-    if (c == '%')
-    {
-      switch (c = *edit_value++)
-      {
-        case 'd':
-          if (ddone)
-            FATAL ("call_edit: `%%d' appears twice in editor command");
-          sprintf (temp, "%ld", (long int)linenumber);
-          while (*temp != '\0')
-            temp++;
-          ddone = 1;
-          break;
-        
-        case 's':
-          if (sdone)
-            FATAL ("call_edit: `%%s' appears twice in editor command");
-          for (i = 0; i < fnlength; i++)
-            *temp++ = xchr[(filename[i])];
-          sdone = 1;
-          break;
-        
-        case '\0':
-          *temp++ = '%';
-          /* Back up to the null to force termination.  */
-          edit_value--;
-          break;
-        
-        default:
-          *temp++ = '%';
-          *temp++ = c;
-          break;
-      }
-    }
-    else
-    {
-#ifdef WIN32
-      if (dontchange)
-        *temp++ = c;
-      else 
-      { 
-        if(Isspace(c) && cnt == 0)
-        {
-          cnt++;
-          temp = command;
-          *temp++ = c;
-          *fp = '\0';
-        }
-        else if(!Isspace(c) && cnt == 0)
-        {
-          *fp++ = c;
-        }
-        else
-        {
-          *temp++ = c;
-        }
-      }
-#else
-      *temp++ = c;
-#endif
-    }
-  }
-
-  *temp = 0;
-
-#ifdef WIN32
-  if (dontchange == 0) {
-    if(editorname[0] == '.' ||
-       editorname[0] == '/' ||
-       editorname[0] == '\\') {
-      fprintf(stderr, "%s is not allowed to execute.\n", editorname);
-      uexit(1);
-    }
-    env = (char *)getenv("PATH");
-    if(SearchPath(env, editorname, ".exe", 256, buffer, &ffp)==0) {
-      if(SearchPath(env, editorname, ".bat", 256, buffer, &ffp)==0) {
-        fprintf(stderr, "I cannot find %s in the PATH.\n", editorname);
-        uexit(1);
-      }
-    }
-    fullcmd = (char *)xmalloc(strlen(buffer)+strlen(command)+5);
-    strcpy(fullcmd, "\"");
-    strcat(fullcmd, buffer);
-    strcat(fullcmd, "\"");
-    strcat(fullcmd, command);
-  } else
-#endif
-  fullcmd = command;
-
-  /* Execute the command.  */
-  if (system (fullcmd) != 0)
-    fprintf(stderr, "! Trouble executing `%s'.\n", command);
-
-  /* Quit, since we found an error.  */
-  uexit(1);
-}
-
-
-#if !defined (WORDS_BIGENDIAN) && !defined (NO_FMTBASE_SWAP)
-
-/* We don't REALLY care what `endian' the machine is after all ! */
-
-// #ifdef MYDEBUG
-// char swapmarkerstring="ERROR: SWAPPING - NOT BigEndian AND NOT NoFmtBaseSwap";
-// #endif
-
-/* This macro is always invoked as a statement.  It assumes a variable
-   `temp'.  */
-   
-#define SWAP(x, y) temp = (x); (x) = (y); (y) = temp;
-
-
-/* Make the NITEMS items pointed at by P, each of size SIZE, be the
-   opposite-endianness of whatever they are now.  */
-
-static int swap_items (char *p, int nitems, int size)
-{
-  char temp;
-
-  /* Since `size' does not change, we can write a while loop for each
-     case, and avoid testing `size' for each time.  */
-  switch (size)
-  {
-    case 8:
-      while (nitems--)
-      {
-        SWAP (p[0], p[7]);
-        SWAP (p[1], p[6]);
-        SWAP (p[2], p[5]);
-        SWAP (p[3], p[4]);
-        p += size;
-      }
-      break;
-
-    case 4:
-      while (nitems--)
-      {
-        SWAP (p[0], p[3]);
-        SWAP (p[1], p[2]);
-        p += size;
-      }
-      break;
-
-    case 2:
-      while (nitems--)
-      {
-        SWAP (p[0], p[1]);
-        p += size;
-      }
-      break;
-
-    case 1:
-    /* Nothing to do.  */
-      break;
-
-    default:
-      show_line("\n", 0);
-      sprintf(log_line, "! I can't (un)dump a %d byte item.\n", size);
-      show_line(log_line, 1);
-      uexit(EXIT_FAILURE);
-  }
-  return 0;
-}
-#endif /* not WORDS_BIGENDIAN and not NO_FMTBASE_SWAP */
-
-#ifdef COMPACTFORMAT
-int do_dump (char *p, int item_size, int nitems, gzFile out_file)
-#else
-int do_dump (char *p, int item_size, int nitems, FILE *out_file)
-#endif
-{
-#if !defined (WORDS_BIGENDIAN) && !defined (NO_FMTBASE_SWAP)
-  swap_items (p, nitems, item_size);
-#endif
-
-#ifdef COMPACTFORMAT
-  if (gzwrite(out_file, p, (item_size * nitems)) != (item_size * nitems))
-#else
-  if ((int) fwrite(p, item_size, nitems, out_file) != nitems)
-#endif
-  {
-    printf("\n! Could not write %d %d-byte item%s.\n",
-               nitems, item_size, (nitems > 1) ? "s" : "");
-    uexit(EXIT_FAILURE);
-  }
-
-/* Have to restore the old contents of memory, since some of it might get used again.  */
-#if !defined (WORDS_BIGENDIAN) && !defined (NO_FMTBASE_SWAP)
-  swap_items (p, nitems, item_size);
-#endif
-
-  return 0;
-}
-
-#ifdef COMPACTFORMAT
-int do_undump (char *p, int item_size, int nitems, gzFile in_file)
-#else
-int do_undump (char *p, int item_size, int nitems, FILE *in_file)
-#endif
-{
-#ifdef COMPACTFORMAT
-  if (gzread(in_file, (void *) p, (unsigned int) (item_size * nitems)) <= 0)
-#else
-  if ((int) fread((void *) p, item_size, nitems, in_file) != nitems)
-#endif
-  {
-    printf("\n! Could not read %d %d-byte item%s.\n",
-               nitems, item_size, (nitems > 1) ? "s" : "");
-    uexit(EXIT_FAILURE);
-  }
-
-#if !defined (WORDS_BIGENDIAN) && !defined (NO_FMTBASE_SWAP)
-  swap_items (p, nitems, item_size);
-#endif
-
-  return 0;
-}
-
-#ifdef FUNNY_CORE_DUMP
-
-void funny_core_dump (void)
-{
-  int pid, w;
-  union wait status;
-
-  switch (pid = vfork ())
-  {
-    case -1:
-      perrormod ("vfork");
-      exit (-1);
-
-    case 0:
-       (void) signal (SIGQUIT, SIG_DFL);
-       (void) kill (getpid (), SIGQUIT);
-       (void) write (2, "how did we get here?\n", 21);
-       exit (1);
-
-    default:
-      while ((w = wait (&status)) != pid && w != -1)
-        ;
-
-      if (status.w_coredump)
-        exit (0);
-
-      (void) write (2, "attempt to dump core failed\n", 28);
-      exit (1);
-  }
-}
+/* Copyright 1992 Karl Berry\r
+   Copyright 2007 TeX Users Group\r
+   Copyright 2014 Clerk Ma\r
+\r
+   This program is free software; you can redistribute it and/or modify\r
+   it under the terms of the GNU General Public License as published by\r
+   the Free Software Foundation; either version 2 of the License, or\r
+   (at your option) any later version.\r
+\r
+   This program is distributed in the hope that it will be useful, but\r
+   WITHOUT ANY WARRANTY; without even the implied warranty of\r
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+   General Public License for more details.\r
+\r
+   You should have received a copy of the GNU General Public License\r
+   along with this program; if not, write to the Free Software\r
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\r
+   02110-1301 USA.  */\r
+\r
+#define EXTERN\r
+\r
+#include "yandytex.h"\r
+\r
+#define dump_ext_length     4\r
+#define edit_value          tex_edit_value\r
+\r
+extern char * replacement[];\r
+int    gargc;\r
+char **gargv;\r
+\r
+int jump_used = 0;\r
+\r
+jmp_buf jumpbuffer;\r
+\r
+int main (int ac, char *av[])\r
+{\r
+  int flag = 0, ret = 0;\r
+\r
+  gargc = ac;\r
+  gargv = av;\r
+\r
+  if (main_init(gargc, gargv))\r
+    return -1;\r
+\r
+  TEX_format_default = " plain.fmt";\r
+  format_default_length = strlen(TEX_format_default + 1);\r
+\r
+  jump_used = 0;\r
+\r
+  ret = setjmp(jumpbuffer);\r
+\r
+  if (ret == 0)\r
+  {\r
+    flag = main_program();\r
+\r
+    if (trace_flag)\r
+      printf("EXITING at %s: flag = %d, ret = %d, jump_used = %d\n", "main", flag, ret, jump_used);\r
+  }\r
+  else\r
+  {\r
+    if (trace_flag)\r
+      printf("EXITING at %s: flag = %d, ret = %d, jump_used =  %d\n", "jump_out", flag, ret, jump_used);\r
+  }\r
+\r
+  if (endit(flag) != 0)\r
+    flag = 1; /* do final clean up in local.c */\r
+\r
+  if (flag == 0)\r
+    return 0;\r
+  else\r
+    exit (flag);\r
+}\r
+\r
+/* texk/web2c/lib/texmfmp.c */\r
+void t_open_in (void)\r
+{\r
+  int i;\r
+\r
+  buffer[first] = 0;\r
+\r
+  if (gargc > optind && optind > 0)\r
+  {\r
+    for (i = optind; i < gargc; i++)\r
+    {\r
+      if (allow_quoted_names && strchr(gargv[i], ' ') != NULL)\r
+      {\r
+        (void) strcat ((char *) &buffer[first], "\"");\r
+        (void) strcat ((char *) &buffer[first], gargv[i]);\r
+        (void) strcat ((char *) &buffer[first], "\"");\r
+      }\r
+      else\r
+        (void) strcat ((char *) &buffer[first], gargv[i]);\r
+\r
+      (void) strcat ((char *) &buffer[first], " ");\r
+    }\r
+    \r
+    gargc = 0;\r
+  }\r
+\r
+  /* Find the end of the buffer.  */\r
+  for (last = first; buffer[last]; ++last)\r
+    do_nothing();\r
+\r
+  for (--last; last >= first && ISBLANK (buffer[last]) && buffer[last] != '\r'; --last)\r
+    do_nothing();\r
+\r
+  last++;\r
+\r
+/* One more time, this time converting to TeX's internal character\r
+   representation.  */ /* for command line input in this case */\r
+  if (non_ascii)\r
+  {\r
+    for (i = first; i < last; i++)\r
+      buffer[i] = xord[buffer[i]];\r
+  }\r
+}\r
+\r
+static void catch_interrupt (int err)\r
+{\r
+  (void) err;\r
+  (void) signal(SIGINT, SIG_IGN);\r
+\r
+  if (interrupt++ >= 3)\r
+    exit(1);\r
+\r
+  (void) signal(SIGINT, catch_interrupt);\r
+}\r
+\r
+void fix_date_and_time (void)\r
+{\r
+  time_t clock;\r
+  struct tm *tmptr;\r
+\r
+  (void) time(&clock);\r
+\r
+  if (trace_flag)\r
+    printf("The time is %lld\n", (long long)clock);\r
+\r
+  if (clock < 0)\r
+    puts("Time not available!");\r
+\r
+  tmptr = localtime (&clock);\r
+\r
+  if (tmptr == NULL)\r
+  {\r
+    printf("Cannot convert time (%0lld)!\n", (long long)clock);\r
+    year     = 2038;\r
+    month    = 1;\r
+    day      = 18;\r
+    tex_time = 22 * 60 + 14;\r
+  }\r
+  else\r
+  {\r
+    tex_time = tmptr->tm_hour * 60 + tmptr->tm_min;\r
+    day      = tmptr->tm_mday;\r
+    month    = tmptr->tm_mon + 1;\r
+    year     = tmptr->tm_year + 1900;\r
+\r
+    if (trace_flag)\r
+      printf("%d-%d-%d %d:%d\n",\r
+        tmptr->tm_year + 1900,\r
+        tmptr->tm_mon + 1,\r
+        tmptr->tm_mday,\r
+        tmptr->tm_hour,\r
+        tmptr->tm_min);\r
+  }\r
+\r
+  {\r
+#ifdef _WIN32\r
+    if (signal(SIGINT, catch_interrupt) == SIG_ERR)\r
+    {\r
+      puts(" CTRL-C handler not installed");\r
+      uexit(EXIT_FAILURE);\r
+    }\r
+#else\r
+    void (*old_handler)();\r
+\r
+    old_handler = signal(SIGINT, catch_interrupt);\r
+\r
+    if (old_handler != SIG_DFL)\r
+      (void) signal(SIGINT, old_handler);\r
+#endif\r
+  }\r
+}\r
+\r
+/* I/O for TeX and Metafont. */\r
+void complain_line (FILE * output)\r
+{\r
+  show_line("\n", 0);\r
+\r
+#ifdef ALLOCATEBUFFER\r
+  sprintf(log_line, "! Unable to read an entire line---buf_size=%d.\n", current_buf_size);\r
+#else\r
+  sprintf(log_line, "! Unable to read an entire line---buf_size=%d.\n", buf_size);\r
+#endif\r
+\r
+  fputs(log_line, output);\r
+  puts("  (File may have a line termination problem.)");\r
+}\r
+\r
+void show_bad_line (FILE * output, int first, int last)\r
+{\r
+  int i, c, d, ch;\r
+  char *s = log_line;\r
+\r
+  for (i = first; i <= last; i++)\r
+  {\r
+    ch = buffer[i];\r
+\r
+    if (show_in_hex && (ch > 127))\r
+    {\r
+      c = ch >> 4;\r
+      d = ch & 15;\r
+\r
+      if (c > 9)\r
+        c = c + 'a' - 10;\r
+      else\r
+        c = c + '0';\r
+\r
+      if (d > 9)\r
+        d = d + 'a' - 10;\r
+      else\r
+        d = d + '0';\r
+\r
+      *s++ = '^';\r
+      *s++ = '^';\r
+\r
+      *s++ = (char) c;\r
+      *s++ = (char) d;\r
+    }\r
+    else if (ch < 32)\r
+    {\r
+      *s++ = '^';\r
+      *s++ = '^';\r
+      *s++ = (char) (ch + 64);\r
+    }\r
+    else if (ch == 127)\r
+    {\r
+      *s++ = '^';\r
+      *s++ = '^';\r
+      *s++ = (char) (ch - 64);\r
+    }\r
+    else\r
+    {\r
+      *s++ = (char) ch;\r
+    }\r
+  }\r
+\r
+  *s++ = ' ';\r
+  *s++ = '\0';\r
+\r
+  fputs(log_line, output);   // log_file\r
+}\r
+\r
+boolean input_line_finish (void)\r
+{\r
+  int i = '\0';\r
+  int ch, flag;\r
+\r
+  buffer[last] = ' ';\r
+\r
+  if (last >= max_buf_stack)\r
+    max_buf_stack = last;\r
+\r
+  while (last > first)\r
+  {\r
+    i = buffer[last - 1];\r
+\r
+    if (i == ' ' || i == '\t')\r
+      --last;\r
+    else\r
+      break;\r
+  }\r
+\r
+  if (restrict_to_ascii)\r
+  {\r
+    flag = 0;\r
+\r
+    for (i = first; i <= last; i++)\r
+    {\r
+      ch = buffer[i];\r
+\r
+      if (ch > 126 ||  (ch < ' ' && ch != '\t' && ch != '\f' && ch != '\r' && ch != '\n'))\r
+      {\r
+        sprintf(log_line, "\n! non ASCII char (%d) in line: ", ch);\r
+        show_line(log_line, 1);\r
+\r
+        if (log_opened)\r
+          fprintf(log_file, "\n! non ASCII char (%d) in line: ", ch);\r
+\r
+        flag = 1;\r
+        break;\r
+      }\r
+    }\r
+\r
+    if (flag)\r
+    {\r
+      show_bad_line(errout, first, last);\r
+\r
+      if (log_opened)\r
+        show_bad_line(log_file, first, last);\r
+    }\r
+  }\r
+\r
+  if (non_ascii)\r
+  {\r
+    for (i = first; i <= last; i++)\r
+      buffer[i] = xord[buffer[i]];\r
+  }\r
+\r
+  return true;\r
+}\r
+\r
+/* Read a line of input into buffer as efficiently as possible (ha ha)\r
+   while still looking like Pascal.\r
+   We set `last' to `first' and return `false' if we get to eof.\r
+   Otherwise, we return `true' and set last = first +\r
+   length(line except trailing whitespace).  */\r
+\r
+boolean input_line (FILE * f)\r
+{\r
+  char * u;        /* 1994/July/3 for key_replace */\r
+  int i = '\0';\r
+\r
+  last = first;\r
+/*  following is new version with tab expansion and key replacement */\r
+/*  may want to expand out separately for speed 1994/July/3 */\r
+/*  different versions depending on return_flag / tabexpand / key_replace */\r
+/*  while (last < buf_size && (i = getc (f)) != EOF)  */\r
+#ifdef ALLOCATEBUFFER\r
+  for ( ; ; ) \r
+#else\r
+  while (last < buf_size) \r
+#endif\r
+  {\r
+    i = getc(f);\r
+\r
+    if (i < ' ')\r
+    {\r
+      if (i == EOF || i == '\n' || (i == '\r' && return_flag))\r
+        break;\r
+      else if (i == '\t' && tab_step != 0)\r
+      {\r
+        buffer[last++] = (ASCII_code) ' ';\r
+\r
+#ifdef ALLOCATEBUFFER\r
+        if (last >= current_buf_size)\r
+        {\r
+          buffer = realloc_buffer(increment_buf_size);  \r
+\r
+          if (last >= current_buf_size)\r
+            break;\r
+        }\r
+#endif\r
+\r
+#ifdef ALLOCATEBUFFER\r
+        while ((last - first) % tab_step != 0) \r
+#else\r
+        while (last < buf_size && (last - first) % tab_step != 0)\r
+#endif\r
+        {\r
+\r
+          buffer[last++] = (ASCII_code) ' ';\r
+\r
+#ifdef ALLOCATEBUFFER\r
+          if (last >= current_buf_size)\r
+          {\r
+            buffer = realloc_buffer(increment_buf_size);\r
+\r
+            if (last >= current_buf_size)\r
+              break;\r
+          }\r
+#endif\r
+        }\r
+\r
+        continue;\r
+      }\r
+    }\r
+\r
+    if (key_replace && (u = replacement[i]) != NULL)\r
+    {\r
+#ifdef ALLOCATEBUFFER\r
+      while (*u != '\0') \r
+#else\r
+      while (last < buf_size && *u != '\0')  \r
+#endif\r
+      {\r
+        buffer[last++] = (ASCII_code) *u++;\r
+\r
+#ifdef ALLOCATEBUFFER\r
+        if (last >= current_buf_size)\r
+        {\r
+          buffer = realloc_buffer(increment_buf_size);\r
+\r
+          if (last >= current_buf_size)\r
+            break;\r
+        }\r
+#endif\r
+      }\r
+    }\r
+    else       /* normal case */\r
+    {\r
+      buffer[last++] = (ASCII_code) i;\r
+\r
+#ifdef ALLOCATEBUFFER\r
+      if (last >= current_buf_size)\r
+      {\r
+        buffer = realloc_buffer(increment_buf_size);\r
+\r
+        if (last >= current_buf_size)\r
+          break;\r
+      }\r
+#endif\r
+    }\r
+  }\r
+\r
+  if (return_flag)    /* let return terminate line as well as newline */\r
+  {\r
+    if (i == '\r')      /* see whether return followed by newline */\r
+    {\r
+      i = getc (f);       /* in which case throw away the newline */\r
+\r
+      if (i != '\n')\r
+      {\r
+        ungetc (i, f);\r
+        i = '\r';\r
+      }\r
+/*      else  buffer[last-1] = (ASCII_code) i; */\r
+    }\r
+  }\r
+\r
+  //  Turn Ctrl-Z at end of file into newline 2000 June 22\r
+  if (i == EOF && trimeof && buffer[last - 1] == 26)\r
+  {\r
+    last--;\r
+  }\r
+\r
+  if (i == EOF && last == first)\r
+    return false;\r
+\r
+/*  Didn't get the whole line because buffer was too small?  */\r
+/*  This shouldn't happen anymore 99/Jan/23 */\r
+  if (i != EOF && i != '\n' && i != '\r')\r
+  {\r
+    complain_line(errout);\r
+\r
+    if (log_opened)\r
+      complain_line(log_file);\r
+\r
+    /* This may no longer be needed ... now that we grow it */\r
+    if (truncate_long_lines)\r
+    {\r
+      while (i != EOF && i != '\n' && i != '\r')\r
+      {\r
+        i = getc (f);     // discard rest of line\r
+      }\r
+\r
+      last--;       /* just in case */\r
+    }\r
+    else\r
+      uexit(EXIT_FAILURE);      /* line too long */\r
+  }\r
+\r
+  return input_line_finish();\r
+}\r
+\r
+static char * edit_value = "c:\\yandy\\WinEdt\\WinEdt.exe [Open('%s');SelLine(%d,7)]";\r
+\r
+static inline int Isspace (char c)\r
+{\r
+  return (c == ' ' || c == '\t');\r
+}\r
+\r
+void call_edit (ASCII_code * filename, pool_pointer fnstart, integer fnlength, integer linenumber)\r
+{\r
+  char *temp, *command, *fullcmd;\r
+  char c;\r
+  int sdone, ddone, i;\r
+\r
+#ifdef WIN32\r
+  char *fp, *ffp, *env, editorname[256], buffer[256];\r
+  int cnt = 0;\r
+  int dontchange = 0;\r
+#endif\r
+\r
+  sdone = ddone = 0;\r
+  filename += fnstart;\r
+\r
+  /* Close any open input files, since we're going to kill the job.  */\r
+  for (i = 1; i <= in_open; i++)\r
+#ifdef XeTeX\r
+    xfclose (input_file[i]->f, "inputfile");\r
+#else\r
+    xfclose (input_file[i], "inputfile");\r
+#endif\r
+\r
+  /* Replace the default with the value of the appropriate environment\r
+     variable or config file value, if it's set.  */\r
+  temp = kpse_var_value("TEXEDIT");\r
+\r
+  if (temp != NULL)\r
+    edit_value = temp;\r
+\r
+  /* Construct the command string.  The `11' is the maximum length an\r
+     integer might be.  */\r
+  command = (char *) xmalloc (strlen (edit_value) + fnlength + 11);\r
+\r
+  /* So we can construct it as we go.  */\r
+  temp = command;\r
+\r
+#ifdef WIN32\r
+  fp = editorname;\r
+  if ((isalpha(*edit_value) && *(edit_value + 1) == ':'\r
+        && IS_DIR_SEP (*(edit_value + 2)))\r
+      || (*edit_value == '"' && isalpha(*(edit_value + 1))\r
+        && *(edit_value + 2) == ':'\r
+        && IS_DIR_SEP (*(edit_value + 3)))\r
+     )\r
+    dontchange = 1;\r
+#endif\r
+\r
+  while ((c = *edit_value++) != 0)\r
+  {\r
+    if (c == '%')\r
+    {\r
+      switch (c = *edit_value++)\r
+      {\r
+        case 'd':\r
+          if (ddone)\r
+            FATAL ("call_edit: `%%d' appears twice in editor command");\r
+          sprintf (temp, "%ld", (long int)linenumber);\r
+          while (*temp != '\0')\r
+            temp++;\r
+          ddone = 1;\r
+          break;\r
+        \r
+        case 's':\r
+          if (sdone)\r
+            FATAL ("call_edit: `%%s' appears twice in editor command");\r
+          for (i = 0; i < fnlength; i++)\r
+            *temp++ = xchr[(filename[i])];\r
+          sdone = 1;\r
+          break;\r
+        \r
+        case '\0':\r
+          *temp++ = '%';\r
+          /* Back up to the null to force termination.  */\r
+          edit_value--;\r
+          break;\r
+        \r
+        default:\r
+          *temp++ = '%';\r
+          *temp++ = c;\r
+          break;\r
+      }\r
+    }\r
+    else\r
+    {\r
+#ifdef WIN32\r
+      if (dontchange)\r
+        *temp++ = c;\r
+      else \r
+      { \r
+        if(Isspace(c) && cnt == 0)\r
+        {\r
+          cnt++;\r
+          temp = command;\r
+          *temp++ = c;\r
+          *fp = '\0';\r
+        }\r
+        else if(!Isspace(c) && cnt == 0)\r
+        {\r
+          *fp++ = c;\r
+        }\r
+        else\r
+        {\r
+          *temp++ = c;\r
+        }\r
+      }\r
+#else\r
+      *temp++ = c;\r
+#endif\r
+    }\r
+  }\r
+\r
+  *temp = 0;\r
+\r
+#ifdef WIN32\r
+  if (dontchange == 0) {\r
+    if(editorname[0] == '.' ||\r
+       editorname[0] == '/' ||\r
+       editorname[0] == '\\') {\r
+      fprintf(stderr, "%s is not allowed to execute.\n", editorname);\r
+      uexit(1);\r
+    }\r
+    env = (char *)getenv("PATH");\r
+    if(SearchPath(env, editorname, ".exe", 256, buffer, &ffp)==0) {\r
+      if(SearchPath(env, editorname, ".bat", 256, buffer, &ffp)==0) {\r
+        fprintf(stderr, "I cannot find %s in the PATH.\n", editorname);\r
+        uexit(1);\r
+      }\r
+    }\r
+    fullcmd = (char *)xmalloc(strlen(buffer)+strlen(command)+5);\r
+    strcpy(fullcmd, "\"");\r
+    strcat(fullcmd, buffer);\r
+    strcat(fullcmd, "\"");\r
+    strcat(fullcmd, command);\r
+  } else\r
+#endif\r
+  fullcmd = command;\r
+\r
+  /* Execute the command.  */\r
+  if (system (fullcmd) != 0)\r
+    fprintf(stderr, "! Trouble executing `%s'.\n", command);\r
+\r
+  /* Quit, since we found an error.  */\r
+  uexit(1);\r
+}\r
+\r
+\r
+#if !defined (WORDS_BIGENDIAN) && !defined (NO_FMTBASE_SWAP)\r
+\r
+/* We don't REALLY care what `endian' the machine is after all ! */\r
+\r
+// #ifdef MYDEBUG\r
+// char swapmarkerstring="ERROR: SWAPPING - NOT BigEndian AND NOT NoFmtBaseSwap";\r
+// #endif\r
+\r
+/* This macro is always invoked as a statement.  It assumes a variable\r
+   `temp'.  */\r
+   \r
+#define SWAP(x, y) temp = (x); (x) = (y); (y) = temp;\r
+\r
+\r
+/* Make the NITEMS items pointed at by P, each of size SIZE, be the\r
+   opposite-endianness of whatever they are now.  */\r
+\r
+static int swap_items (char *p, int nitems, int size)\r
+{\r
+  char temp;\r
+\r
+  /* Since `size' does not change, we can write a while loop for each\r
+     case, and avoid testing `size' for each time.  */\r
+  switch (size)\r
+  {\r
+    case 8:\r
+      while (nitems--)\r
+      {\r
+        SWAP (p[0], p[7]);\r
+        SWAP (p[1], p[6]);\r
+        SWAP (p[2], p[5]);\r
+        SWAP (p[3], p[4]);\r
+        p += size;\r
+      }\r
+      break;\r
+\r
+    case 4:\r
+      while (nitems--)\r
+      {\r
+        SWAP (p[0], p[3]);\r
+        SWAP (p[1], p[2]);\r
+        p += size;\r
+      }\r
+      break;\r
+\r
+    case 2:\r
+      while (nitems--)\r
+      {\r
+        SWAP (p[0], p[1]);\r
+        p += size;\r
+      }\r
+      break;\r
+\r
+    case 1:\r
+    /* Nothing to do.  */\r
+      break;\r
+\r
+    default:\r
+      show_line("\n", 0);\r
+      sprintf(log_line, "! I can't (un)dump a %d byte item.\n", size);\r
+      show_line(log_line, 1);\r
+      uexit(EXIT_FAILURE);\r
+  }\r
+  return 0;\r
+}\r
+#endif /* not WORDS_BIGENDIAN and not NO_FMTBASE_SWAP */\r
+\r
+#ifdef COMPACTFORMAT\r
+int do_dump (char *p, int item_size, int nitems, gzFile out_file)\r
+#else\r
+int do_dump (char *p, int item_size, int nitems, FILE *out_file)\r
+#endif\r
+{\r
+#if !defined (WORDS_BIGENDIAN) && !defined (NO_FMTBASE_SWAP)\r
+  swap_items (p, nitems, item_size);\r
+#endif\r
+\r
+#ifdef COMPACTFORMAT\r
+  if (gzwrite(out_file, p, (item_size * nitems)) != (item_size * nitems))\r
+#else\r
+  if ((int) fwrite(p, item_size, nitems, out_file) != nitems)\r
+#endif\r
+  {\r
+    printf("\n! Could not write %d %d-byte item%s.\n",\r
+               nitems, item_size, (nitems > 1) ? "s" : "");\r
+    uexit(EXIT_FAILURE);\r
+  }\r
+\r
+/* Have to restore the old contents of memory, since some of it might get used again.  */\r
+#if !defined (WORDS_BIGENDIAN) && !defined (NO_FMTBASE_SWAP)\r
+  swap_items (p, nitems, item_size);\r
+#endif\r
+\r
+  return 0;\r
+}\r
+\r
+#ifdef COMPACTFORMAT\r
+int do_undump (char *p, int item_size, int nitems, gzFile in_file)\r
+#else\r
+int do_undump (char *p, int item_size, int nitems, FILE *in_file)\r
+#endif\r
+{\r
+#ifdef COMPACTFORMAT\r
+  if (gzread(in_file, (void *) p, (unsigned int) (item_size * nitems)) <= 0)\r
+#else\r
+  if ((int) fread((void *) p, item_size, nitems, in_file) != nitems)\r
+#endif\r
+  {\r
+    printf("\n! Could not read %d %d-byte item%s.\n",\r
+               nitems, item_size, (nitems > 1) ? "s" : "");\r
+    uexit(EXIT_FAILURE);\r
+  }\r
+\r
+#if !defined (WORDS_BIGENDIAN) && !defined (NO_FMTBASE_SWAP)\r
+  swap_items (p, nitems, item_size);\r
+#endif\r
+\r
+  return 0;\r
+}\r
+\r
+#ifdef FUNNY_CORE_DUMP\r
+\r
+void funny_core_dump (void)\r
+{\r
+  int pid, w;\r
+  union wait status;\r
+\r
+  switch (pid = vfork ())\r
+  {\r
+    case -1:\r
+      perrormod ("vfork");\r
+      exit (-1);\r
+\r
+    case 0:\r
+       (void) signal (SIGQUIT, SIG_DFL);\r
+       (void) kill (getpid (), SIGQUIT);\r
+       (void) write (2, "how did we get here?\n", 21);\r
+       exit (1);\r
+\r
+    default:\r
+      while ((w = wait (&status)) != pid && w != -1)\r
+        ;\r
+\r
+      if (status.w_coredump)\r
+        exit (0);\r
+\r
+      (void) write (2, "attempt to dump core failed\n", 28);\r
+      exit (1);\r
+  }\r
+}\r
 #endif /* FUNNY_CORE_DUMP */
\ No newline at end of file