OSDN Git Service

bool to boolean.
[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 #define EXTERN extern
19
20 #include "texd.h"
21
22 #define PATH_SEP '/'
23
24 // texk/web2c/lib/uexit.c
25 void uexit (int unix_code)
26 {
27   int final_code;
28
29 #ifndef _WINDOWS
30   fflush(stdout);
31 #endif
32
33   if (unix_code == 0)
34     final_code = EXIT_SUCCESS;
35   else if (unix_code == 1)
36     final_code = EXIT_FAILURE;
37   else
38     final_code = unix_code;
39
40   if (jump_used)
41   {
42     show_line("Jump Buffer already used\n", 1);
43     exit(1);
44   }
45
46   jump_used++;
47   exit(final_code);
48 }
49 // texk/web2c/lib/zround.c
50 integer zround (double r)
51 {
52   integer i;
53
54   if (r > 2147483647.0)
55     i = 2147483647;
56   else if (r < -2147483647.0)
57     i = -2147483647;
58   else if (r >= 0.0)
59     i = (integer) (r + 0.5);
60   else
61     i = (integer) (r - 0.5);
62
63   return i;
64 }
65 // texk/web2c/lib/eofeoln.c
66 boolean eoln (FILE * file)
67 {
68   register int c;
69
70   if (feof (file))
71     return true;
72
73   c = getc (file);
74
75   if (c != EOF)
76     (void) ungetc (c, file);
77
78   return c == '\n' || c == '\r' || c == EOF;
79 }
80 // Unixify filename and path (turn \ into /)
81 // --- assumes null terminated
82 char * unixify (char * t)
83 {
84   char * s = t;
85
86   if (s == NULL)
87     return s;
88
89   if (t != '\0')
90   {
91     while (*s != '\0')
92     {
93       if (*s == '\\')
94         *s = PATH_SEP;
95
96       s++;
97     }
98   }
99
100   if (trace_flag)
101   {
102     printf("Unixified name: %s\n", t);
103     //sprintf(log_line, "Unixified name: %s\n", t);
104     //show_line(log_line, 0);
105   }
106
107   return t;
108 }
109
110 char * md5_file_name(const char * file_name)
111 {
112   md5_state_t md5_ship;
113   md5_byte_t  md5_data[1024];
114   md5_byte_t  md5_digest[16];
115   static char md5_hex[33];
116   int         md5_len;
117   FILE * ship_file;
118   int i;
119
120   ship_file = fopen(file_name, "rb");
121
122   md5_init(&md5_ship);
123
124   while ((md5_len = fread(md5_data, 1, 1024, ship_file)) != 0)
125     md5_append(&md5_ship, md5_data, md5_len);
126
127   md5_finish(&md5_ship, md5_digest);
128
129   fclose(ship_file);
130
131   for (i = 0; i < 16; ++i)
132     sprintf(md5_hex + i * 2, "%02X", md5_digest[i]);
133
134   return md5_hex;
135 }
136
137 char * md5_file(FILE * in_file)
138 {
139   md5_state_t md5_ship;
140   md5_byte_t  md5_data[1024];
141   md5_byte_t  md5_digest[16];
142   static char md5_hex[33];
143   int         md5_len;
144   int i;
145
146   md5_init(&md5_ship);
147
148   while ((md5_len = fread(md5_data, 1, 1024, in_file)) != 0)
149     md5_append(&md5_ship, md5_data, md5_len);
150
151   md5_finish(&md5_ship, md5_digest);
152
153   fclose(in_file);
154
155   for (i = 0; i < 16; ++i)
156     sprintf(md5_hex + i * 2, "%02X", md5_digest[i]);
157
158   return md5_hex;
159 }