OSDN Git Service

6176640609554f94657b27a2edfb49cba76a79be
[putex/putex.git] / src / texsourc / subroute.c
1 /* Copyright 2007 TeX Users Group
2    Copyright 2014 Clerk Ma
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License as published by
5    the Free Software Foundation; either version 2 of the License, or
6    (at your option) any later version.
7
8    This program is distributed in the hope that it will be useful, but
9    WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11    General Public License for more details.
12
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16    02110-1301 USA.  */
17
18 #ifdef _WINDOWS
19   #define NOCOMM
20   #define NOSOUND
21   #define NODRIVERS
22   #define STRICT
23   #pragma warning(disable:4115) // kill rpcasync.h complaint
24   #include <windows.h>
25   #define MYLIBAPI __declspec(dllexport)
26 #endif
27
28 #pragma warning(disable:4996)
29 #pragma warning(disable:4131) // old style declarator
30 #pragma warning(disable:4135) // conversion between different integral types
31 #pragma warning(disable:4127) // conditional expression is constant
32
33 #include <setjmp.h>
34
35 #define EXTERN extern
36
37 #include "texd.h"
38
39 #include <io.h>    // needed for _finddata_t
40 #include <ctype.h> // needed for isascii and isalpha
41
42 #define NAME_MAX 255      // max size of name component
43
44 #define PATH_SEP              '/'
45 #define PATH_SEP_STRING       "/"
46 #define PATH_DELIMITER        ';'
47 #define PATH_DELIMITER_STRING ";"
48
49 // default paths to look for things
50
51 #define TEXPATH    "C:/yandy/yandytex/"
52 #define TEXFORMATS "C:/yandy/yandytex/fmt"
53 #define TEXPOOL    "C:/yandy/yandytex/pool"
54 #define TEXFONTS   "C:/yandy/yandytex/tfm"
55 #define TEXINPUTS  TEXPATH "tex//;" "C:/tex;" "C:/texinput"
56
57 extern bool usesourcedirectory; /* in local.c */
58
59 extern bool workingdirectory;   /* in local.c */
60
61 string truncate_pathname (string name);
62
63 // the following do *not* use MALLOC
64 extern char * xconcat  (char *buffer, char *s1, char *s2);           /* openinou.c */
65 extern char * xconcat3 (char *buffer, char *s1, char *s2, char *s3); /* openinou.c */
66
67 /////////////////////////////////////////////////////////////////////////
68
69 // used only in jump_out in tex0.c, and in texbody in itex.c
70 // and main in texmf.c and a few other abort situations in texmf.c
71 /* texk/web2c/lib/uexit.c */
72 void uexit (int unix_code)
73 {
74   int final_code;
75
76 #ifndef _WINDOWS
77   fflush(stdout);
78 #endif
79
80   if (unix_code == 0)
81     final_code = EXIT_SUCCESS;
82   else if (unix_code == 1)
83     final_code = EXIT_FAILURE;
84   else
85     final_code = unix_code;
86
87   if (jump_used)
88   {
89     show_line("Jump Buffer already used\n", 1);
90     exit(1);
91   }
92
93   jump_used++;
94   exit(final_code);
95 }
96 /* texk/web2c/lib/zround.c */
97 integer zround (double r)
98 {
99   integer i;
100
101   if (r > 2147483647.0)
102     i = 2147483647;
103   else if (r < -2147483647.0)
104     i = -2147483647;
105   else if (r >= 0.0)
106     i = (integer) (r + 0.5);
107   else
108     i = (integer) (r - 0.5);
109
110   return i;
111 }
112 /* texk/web2c/lib/eofeoln.c */
113 bool eoln (FILE * file)
114 {
115   register int c;
116
117   if (feof (file))
118     return true;
119
120   c = getc (file);
121
122   if (c != EOF)
123     (void) ungetc (c, file);
124
125   return c == '\n' || c == '\r' || c == EOF;
126 }
127
128 char * read_a_line (FILE *f,  char *line, int limit)
129 {
130   int c;
131   int loc = 0;
132
133   while ((c = getc (f)) != EOF)
134   {
135     if (c == '\n' || c == '\r')
136     {
137       if (loc > 0) break;
138       else continue;        /* ignore \r\n and blank lines */
139     }
140
141     line[loc] = (char) c;
142     loc++;
143
144     if (loc == limit - 1)
145     {
146       sprintf(log_line, " ERROR: line too long\n");
147       show_line(log_line, 1);
148       show_line(line, 0);
149       show_line("\n", 0);
150       break;
151     }
152   }
153
154   if (c != EOF || loc > 0)
155   {
156     line[loc] = '\0';       /* terminate */
157     return line;          /* and return */
158   }
159   else
160     return(NULL);          /* true EOF */
161 }
162
163 /* Modified 97/May/17 to avoid malloc for each line read */
164
165 #ifndef MALLOCLINE
166   #define MAXLINE 256
167 #endif
168
169 /* Unixify filename and path (turn \ into /) --- assumes null terminated */
170 /* NEED HACK! */
171 char *unixify (char * t)
172 {
173   char * s = t;
174
175   if (s == NULL)
176     return s;    /* paranoia -- 1993/Apr/10 */
177
178 #ifdef MSDOS
179   if (t != '\0')
180   {
181     while (*s != '\0') {        /* paranoia -- 1997/Oct/23 */
182 /*      if (*s == '\\') *s = '/'; */
183       if (*s == '\\')
184         *s = PATH_SEP;
185
186       s++;
187     }       /* endwhile */
188   }
189 // #ifdef MYDEBUG
190   if (trace_flag)
191   {
192     sprintf(log_line, "Unixified name: %s\n", t);
193     show_line(log_line, 0);
194   }
195 // #endif
196 #endif /* DOS */
197   return t;
198 }
199
200 /* NOTE: _dos_find... prevents running under Windows NT as console app ??? */
201 /* Yes, so lets flush it! use _findfirst, _findnext, _findclose instead */
202
203 char *get_env_shroud (char *);    /* in texmf.c */