2 Copyright 1992 Karl Berry
\r
3 Copyright 2007 TeX Users Group
\r
4 Copyright 2014 Clerk Ma
\r
6 This program is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 This program is distributed in the hope that it will be useful, but
\r
12 WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
14 General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with this program; if not, write to the Free Software
\r
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
\r
24 #include "yandytex.h"
\r
26 #define dump_ext_length 4
\r
27 #define edit_value tex_edit_value
\r
29 extern char * replacement[];
\r
37 int main (int ac, char *av[])
\r
39 int flag = 0, ret = 0;
\r
44 if (main_init(gargc, gargv))
\r
47 TEX_format_default = " plain.fmt";
\r
48 format_default_length = strlen(TEX_format_default + 1);
\r
52 ret = setjmp(jumpbuffer);
\r
56 flag = main_program();
\r
59 printf("EXITING at %s: flag = %d, ret = %d, jump_used = %d\n", "main", flag, ret, jump_used);
\r
64 printf("EXITING at %s: flag = %d, ret = %d, jump_used = %d\n", "jump_out", flag, ret, jump_used);
\r
67 if (endit(flag) != 0)
\r
68 flag = 1; /* do final clean up in local.c */
\r
76 /* texk/web2c/lib/texmfmp.c */
\r
77 void t_open_in (void)
\r
83 if (gargc > optind && optind > 0)
\r
85 for (i = optind; i < gargc; i++)
\r
87 if (allow_quoted_names && strchr(gargv[i], ' ') != NULL)
\r
89 (void) strcat ((char *) &buffer[first], "\"");
\r
90 (void) strcat ((char *) &buffer[first], gargv[i]);
\r
91 (void) strcat ((char *) &buffer[first], "\"");
\r
94 (void) strcat ((char *) &buffer[first], gargv[i]);
\r
96 (void) strcat ((char *) &buffer[first], " ");
\r
102 /* Find the end of the buffer. */
\r
103 for (last = first; buffer[last]; ++last)
\r
106 for (--last; last >= first && ISBLANK(buffer[last]) && buffer[last] != '\r'; --last)
\r
113 for (i = first; i < last; i++)
\r
114 buffer[i] = xord[buffer[i]];
\r
118 static void catch_interrupt (int err)
\r
121 (void) signal(SIGINT, SIG_IGN);
\r
123 if (interrupt++ >= 3)
\r
126 (void) signal(SIGINT, catch_interrupt);
\r
129 void fix_date_and_time (void)
\r
134 (void) time(&clock);
\r
137 printf("The time is %lld\n", (long long)clock);
\r
140 puts("Time not available!");
\r
142 tmptr = localtime (&clock);
\r
146 printf("Cannot convert time (%0lld)!\n", (long long)clock);
\r
150 tex_time = 22 * 60 + 14;
\r
154 tex_time = tmptr->tm_hour * 60 + tmptr->tm_min;
\r
155 day = tmptr->tm_mday;
\r
156 month = tmptr->tm_mon + 1;
\r
157 year = tmptr->tm_year + 1900;
\r
160 printf("%d-%d-%d %d:%d\n",
\r
161 tmptr->tm_year + 1900,
\r
170 if (signal(SIGINT, catch_interrupt) == SIG_ERR)
\r
172 puts(" CTRL-C handler not installed");
\r
173 uexit(EXIT_FAILURE);
\r
176 void (*old_handler)();
\r
178 old_handler = signal(SIGINT, catch_interrupt);
\r
180 if (old_handler != SIG_DFL)
\r
181 (void) signal(SIGINT, old_handler);
\r
186 /* I/O for TeX and Metafont. */
\r
187 void complain_line (FILE * output)
\r
189 show_line("\n", 0);
\r
191 #ifdef ALLOCATEBUFFER
\r
192 sprintf(log_line, "! Unable to read an entire line---buf_size=%d.\n", current_buf_size);
\r
194 sprintf(log_line, "! Unable to read an entire line---buf_size=%d.\n", buf_size);
\r
197 fputs(log_line, output);
\r
198 puts(" (File may have a line termination problem.)");
\r
201 void show_bad_line (FILE * output, int first, int last)
\r
204 char *s = log_line;
\r
206 for (i = first; i <= last; i++)
\r
210 if (show_in_hex && (ch > 127))
\r
235 *s++ = (char) (ch + 64);
\r
237 else if (ch == 127)
\r
241 *s++ = (char) (ch - 64);
\r
252 fputs(log_line, output); // log_file
\r
255 boolean input_line_finish (void)
\r
260 buffer[last] = ' ';
\r
262 if (last >= max_buf_stack)
\r
263 max_buf_stack = last;
\r
265 while (last > first)
\r
267 i = buffer[last - 1];
\r
269 if (i == ' ' || i == '\t')
\r
275 if (restrict_to_ascii)
\r
279 for (i = first; i <= last; i++)
\r
283 if (ch > 126 || (ch < ' ' && ch != '\t' && ch != '\f' && ch != '\r' && ch != '\n'))
\r
285 sprintf(log_line, "\n! non ASCII char (%d) in line: ", ch);
\r
286 show_line(log_line, 1);
\r
289 fprintf(log_file, "\n! non ASCII char (%d) in line: ", ch);
\r
298 show_bad_line(errout, first, last);
\r
301 show_bad_line(log_file, first, last);
\r
307 for (i = first; i <= last; i++)
\r
308 buffer[i] = xord[buffer[i]];
\r
314 boolean input_line (FILE * f)
\r
316 char * u; /* 1994/July/3 for key_replace */
\r
320 /* following is new version with tab expansion and key replacement */
\r
321 /* may want to expand out separately for speed 1994/July/3 */
\r
322 /* different versions depending on return_flag / tabexpand / key_replace */
\r
323 /* while (last < buf_size && (i = getc (f)) != EOF) */
\r
324 #ifdef ALLOCATEBUFFER
\r
327 while (last < buf_size)
\r
334 if (i == EOF || i == '\n' || (i == '\r' && return_flag))
\r
336 else if (i == '\t' && tab_step != 0)
\r
338 buffer[last++] = (ASCII_code) ' ';
\r
340 #ifdef ALLOCATEBUFFER
\r
341 if (last >= current_buf_size)
\r
343 buffer = realloc_buffer(increment_buf_size);
\r
345 if (last >= current_buf_size)
\r
350 #ifdef ALLOCATEBUFFER
\r
351 while ((last - first) % tab_step != 0)
\r
353 while (last < buf_size && (last - first) % tab_step != 0)
\r
357 buffer[last++] = (ASCII_code) ' ';
\r
359 #ifdef ALLOCATEBUFFER
\r
360 if (last >= current_buf_size)
\r
362 buffer = realloc_buffer(increment_buf_size);
\r
364 if (last >= current_buf_size)
\r
374 if (key_replace && (u = replacement[i]) != NULL)
\r
376 #ifdef ALLOCATEBUFFER
\r
377 while (*u != '\0')
\r
379 while (last < buf_size && *u != '\0')
\r
382 buffer[last++] = (ASCII_code) *u++;
\r
384 #ifdef ALLOCATEBUFFER
\r
385 if (last >= current_buf_size)
\r
387 buffer = realloc_buffer(increment_buf_size);
\r
389 if (last >= current_buf_size)
\r
395 else /* normal case */
\r
397 buffer[last++] = (ASCII_code) i;
\r
399 #ifdef ALLOCATEBUFFER
\r
400 if (last >= current_buf_size)
\r
402 buffer = realloc_buffer(increment_buf_size);
\r
404 if (last >= current_buf_size)
\r
411 if (return_flag) /* let return terminate line as well as newline */
\r
413 if (i == '\r') /* see whether return followed by newline */
\r
415 i = getc(f); /* in which case throw away the newline */
\r
422 /* else buffer[last-1] = (ASCII_code) i; */
\r
426 // Turn Ctrl-Z at end of file into newline 2000 June 22
\r
427 if (i == EOF && trimeof && buffer[last - 1] == 26)
\r
432 if (i == EOF && last == first)
\r
435 /* Didn't get the whole line because buffer was too small? */
\r
436 /* This shouldn't happen anymore 99/Jan/23 */
\r
437 if (i != EOF && i != '\n' && i != '\r')
\r
439 complain_line(errout);
\r
442 complain_line(log_file);
\r
444 /* This may no longer be needed ... now that we grow it */
\r
445 if (truncate_long_lines)
\r
447 while (i != EOF && i != '\n' && i != '\r')
\r
449 i = getc (f); // discard rest of line
\r
452 last--; /* just in case */
\r
455 uexit(EXIT_FAILURE); /* line too long */
\r
458 return input_line_finish();
\r
461 static char * edit_value = "c:\\yandy\\WinEdt\\WinEdt.exe [Open('%s');SelLine(%d,7)]";
\r
464 static inline int Isspace (char c)
\r
466 return (c == ' ' || c == '\t');
\r
470 void call_edit (ASCII_code * filename, pool_pointer fnstart, integer fnlength, integer linenumber)
\r
472 char *temp, *command, *fullcmd;
\r
474 int sdone, ddone, i;
\r
477 char *fp, *ffp, *env, editorname[256], buffer[256];
\r
479 int dontchange = 0;
\r
483 filename += fnstart;
\r
485 /* Close any open input files, since we're going to kill the job. */
\r
486 for (i = 1; i <= in_open; i++)
\r
488 xfclose(input_file[i]->f, "inputfile");
\r
490 xfclose(input_file[i], "inputfile");
\r
493 /* Replace the default with the value of the appropriate environment
\r
494 variable or config file value, if it's set. */
\r
495 temp = kpse_var_value("TEXEDIT");
\r
500 /* Construct the command string. The `11' is the maximum length an
\r
501 integer might be. */
\r
502 command = (char *) xmalloc (strlen (edit_value) + fnlength + 11);
\r
504 /* So we can construct it as we go. */
\r
509 if ((isalpha(*edit_value) && *(edit_value + 1) == ':'
\r
510 && IS_DIR_SEP (*(edit_value + 2)))
\r
511 || (*edit_value == '"' && isalpha(*(edit_value + 1))
\r
512 && *(edit_value + 2) == ':'
\r
513 && IS_DIR_SEP (*(edit_value + 3)))
\r
518 while ((c = *edit_value++) != 0)
\r
522 switch (c = *edit_value++)
\r
526 FATAL ("call_edit: `%%d' appears twice in editor command");
\r
527 sprintf (temp, "%ld", (long int)linenumber);
\r
528 while (*temp != '\0')
\r
535 FATAL ("call_edit: `%%s' appears twice in editor command");
\r
536 for (i = 0; i < fnlength; i++)
\r
537 *temp++ = xchr[(filename[i])];
\r
543 /* Back up to the null to force termination. */
\r
560 if(Isspace(c) && cnt == 0)
\r
567 else if(!Isspace(c) && cnt == 0)
\r
585 if (dontchange == 0) {
\r
586 if(editorname[0] == '.' ||
\r
587 editorname[0] == '/' ||
\r
588 editorname[0] == '\\') {
\r
589 fprintf(stderr, "%s is not allowed to execute.\n", editorname);
\r
592 env = (char *)getenv("PATH");
\r
593 if(SearchPath(env, editorname, ".exe", 256, buffer, &ffp)==0) {
\r
594 if(SearchPath(env, editorname, ".bat", 256, buffer, &ffp)==0) {
\r
595 fprintf(stderr, "I cannot find %s in the PATH.\n", editorname);
\r
599 fullcmd = (char *)xmalloc(strlen(buffer)+strlen(command)+5);
\r
600 strcpy(fullcmd, "\"");
\r
601 strcat(fullcmd, buffer);
\r
602 strcat(fullcmd, "\"");
\r
603 strcat(fullcmd, command);
\r
608 /* Execute the command. */
\r
609 if (system (fullcmd) != 0)
\r
610 fprintf(stderr, "! Trouble executing `%s'.\n", command);
\r
612 /* Quit, since we found an error. */
\r
617 #if !defined (WORDS_BIGENDIAN) && !defined (NO_FMTBASE_SWAP)
\r
619 #define SWAP(x, y) temp = (x); (x) = (y); (y) = temp;
\r
622 /* Make the NITEMS items pointed at by P, each of size SIZE, be the
\r
623 opposite-endianness of whatever they are now. */
\r
625 static int swap_items (char *p, int nitems, int size)
\r
629 /* Since `size' does not change, we can write a while loop for each
\r
630 case, and avoid testing `size' for each time. */
\r
662 /* Nothing to do. */
\r
666 show_line("\n", 0);
\r
667 sprintf(log_line, "! I can't (un)dump a %d byte item.\n", size);
\r
668 show_line(log_line, 1);
\r
669 uexit(EXIT_FAILURE);
\r
673 #endif /* not WORDS_BIGENDIAN and not NO_FMTBASE_SWAP */
\r
675 #ifdef COMPACTFORMAT
\r
676 int do_dump (char *p, int item_size, int nitems, gzFile out_file)
\r
678 int do_dump (char *p, int item_size, int nitems, FILE *out_file)
\r
681 #if !defined (WORDS_BIGENDIAN) && !defined (NO_FMTBASE_SWAP)
\r
682 swap_items (p, nitems, item_size);
\r
685 #ifdef COMPACTFORMAT
\r
686 if (gzwrite(out_file, p, (item_size * nitems)) != (item_size * nitems))
\r
688 if ((int) fwrite(p, item_size, nitems, out_file) != nitems)
\r
691 printf("\n! Could not write %d %d-byte item%s.\n",
\r
692 nitems, item_size, (nitems > 1) ? "s" : "");
\r
693 uexit(EXIT_FAILURE);
\r
696 /* Have to restore the old contents of memory, since some of it might get used again. */
\r
697 #if !defined (WORDS_BIGENDIAN) && !defined (NO_FMTBASE_SWAP)
\r
698 swap_items (p, nitems, item_size);
\r
704 #ifdef COMPACTFORMAT
\r
705 int do_undump (char *p, int item_size, int nitems, gzFile in_file)
\r
707 int do_undump (char *p, int item_size, int nitems, FILE *in_file)
\r
710 #ifdef COMPACTFORMAT
\r
711 if (gzread(in_file, (void *) p, (unsigned int) (item_size * nitems)) <= 0)
\r
713 if ((int) fread((void *) p, item_size, nitems, in_file) != nitems)
\r
716 printf("\n! Could not read %d %d-byte item%s.\n",
\r
717 nitems, item_size, (nitems > 1) ? "s" : "");
\r
718 uexit(EXIT_FAILURE);
\r
721 #if !defined (WORDS_BIGENDIAN) && !defined (NO_FMTBASE_SWAP)
\r
722 swap_items (p, nitems, item_size);
\r