w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

utils.c
Go to the documentation of this file.
1 /* dvipos-20070107
2 
3  Copyright (C) 2003 by Jin-Hwan <chofchof@ktug.or.kr>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 */
19 
20 #include "utils.h"
21 
22 #include <stdarg.h>
23 
25 {
26  return (UNSIGNED_BYTE)(fgetc(fp) & 0xFF);
27 }
28 
30 {
32  return (SIGNED_BYTE)(byte & 0x80 ? byte - 0x100 : byte);
33 }
34 
36 {
38  /* Read the second byte */
39  pair = pair << 8; pair += get_unsigned_byte(fp);
40  return pair;
41 }
42 
44 {
45  UNSIGNED_PAIR pair;
47  pair = (byte & 0x80 ? byte - 0x100 : byte);
48  /* Read the second byte */
49  pair = pair << 8; pair += get_unsigned_byte(fp);
50  return (SIGNED_PAIR)pair;
51 }
52 
54 {
56  /* Read the second, the third byte */
57  triple = triple << 8; triple += get_unsigned_byte(fp);
58  triple = triple << 8; triple += get_unsigned_byte(fp);
59  return triple;
60 }
61 
63 {
64  /* yy zz XX -> XXyyzz */
66  triple = triple << 8; triple += get_unsigned_byte(fp);
67  triple += get_unsigned_byte(fp) << 16;
68  return triple;
69 }
70 
72 {
73  UNSIGNED_TRIPLE triple;
74  /* Read the first byte and check the sign */
76  triple = (byte & 0x80 ? byte - 0x100 : byte);
77  /* Read the second, the third byte */
78  triple = triple << 8; triple += get_unsigned_byte(fp);
79  triple = triple << 8; triple += get_unsigned_byte(fp);
80  return (SIGNED_TRIPLE)triple;
81 }
82 
84 {
86  /* Read the second, the third, and the fourth byte */
87  quad = quad << 8; quad += get_unsigned_byte(fp);
88  quad = quad << 8; quad += get_unsigned_byte(fp);
89  quad = quad << 8; quad += get_unsigned_byte(fp);
90  return quad;
91 }
92 
94 {
96  /* Read the first byte and check the sign */
98  quad = (byte & 0x80 ? byte - 0x100 : byte);
99  /* Read the second, the third, and the fourth byte */
100  quad = quad << 8; quad += get_unsigned_byte(fp);
101  quad = quad << 8; quad += get_unsigned_byte(fp);
102  quad = quad << 8; quad += get_unsigned_byte(fp);
103  return (SIGNED_QUAD)quad;
104 }
105 
107 {
108  fputc(quad & 0xff, fp);
109  dbg_location++;
110 }
111 
113 {
114  if (quad < 0) fputc((quad + 0x100) & 0xff, fp);
115  else fputc(quad & 0xff, fp);
116  dbg_location++;
117 }
118 
120 {
121  put_unsigned_byte(quad >> 8, fp);
123 }
124 
126 {
127  put_signed_byte(quad >> 8, fp);
129 }
130 
132 {
133  put_unsigned_byte(quad >> 16, fp);
134  put_unsigned_pair(quad & 0xffff, fp);
135 }
136 
138 {
139  put_signed_byte(quad >> 16, fp);
140  put_unsigned_pair(quad & 0xffff, fp);
141 }
142 
144 {
145  put_signed_byte(quad >> 24, fp);
146  put_unsigned_triple(quad & 0xffffff, fp);
147 }
148 
150 {
151  if (quad < 0) *buf++ = (quad >> 8) + 0x100;
152  else *buf++ = quad >> 8;
153  *buf = quad & 0xff;
154 }
155 
157 {
158  if (quad < 0) *buf++ = (quad >> 24) + 0x100;
159  else *buf++ = quad >> 24;
160  *buf++ = quad >> 16;
161  *buf++ = quad >> 8;
162  *buf = quad & 0xff;
163 }
164 
165 #ifndef KPATHSEA
166 /* Borrowed from the kpathsea library, concat3.c */
167 char *concat (const char *s1, const char *s2)
168 {
169  unsigned s1len = strlen(s1);
170  unsigned s2len = strlen(s2);
171  char *answer = (char *)xmalloc(s1len + s2len + 1);
172  strcpy(answer, s1);
173  strcat(answer + s1len, s2);
174  return answer;
175 }
176 
177 /* Borrowed from the kpathsea library, concat3.c */
178 char *concat3 (const char *s1, const char *s2, const char *s3)
179 {
180  char *answer = (char *)xmalloc(strlen(s1) + strlen(s2) + strlen(s3) + 1);
181  strcpy(answer, s1);
182  strcat(answer, s2);
183  strcat(answer, s3);
184  return answer;
185 }
186 
187 /* Borrowed from the kpathsea library, make-suffix.c */
188 /* Return a new string: S suffixed with SUFFIX, regardless of what it
189  * was before. This returns a newly allocated string. */
190 char *make_suffix (const char *s, const char *suffix)
191 {
192  char *new_s;
193  const char *dot_pos = strrchr(s, '.');
194  const char *slash_pos;
195 
196  for (slash_pos = s + strlen(s) - 1; slash_pos > dot_pos && slash_pos > s; slash_pos--)
197  if (IS_DIR_SEP(*slash_pos)) break;
198 
199  if (dot_pos == NULL || slash_pos > dot_pos)
200  new_s = concat3(s, ".", suffix);
201  else {
202  unsigned past_dot_index = dot_pos + 1 - s;
203  new_s = (char *)xmalloc (past_dot_index + strlen (suffix) + 1);
204  strncpy(new_s, s, dot_pos + 1 - s);
205  strcpy(new_s + past_dot_index, suffix);
206  }
207 
208  return new_s;
209 }
210 #endif
211 
212 void msg_out (int level, const char *fmt, ...)
213 {
214  va_list args;
215  if (verbose & level) {
216  va_start(args, fmt);
217  vfprintf(stdout, fmt, args);
218  va_end(args);
219  }
220  if (level == M_FAIL)
221  exit(1);
222 }
int level
Definition: afm2pl.c:1694
double quad
Definition: aftopl.c:71
#define strrchr
Definition: detex.c:67
#define fgetc
Definition: xxstdio.h:26
char * strncpy()
char * strcpy()
#define IS_DIR_SEP
Definition: dvidvi.c:106
SIGNED_QUAD dbg_location
Definition: dvipos.c:38
#define s
Definition: afcover.h:80
#define byte
Definition: in_pcx.cpp:28
#define NULL
Definition: ftobjs.h:61
void exit()
signed char suffix(char *cs, char *ct)
Definition: utils.c:105
#define buf
unsigned UNSIGNED_PAIR
Definition: numbers.h:35
int UNSIGNED_BYTE
Definition: numbers.h:34
long SIGNED_TRIPLE
Definition: numbers.h:36
int SIGNED_BYTE
Definition: numbers.h:34
long UNSIGNED_TRIPLE
Definition: numbers.h:36
int SIGNED_PAIR
Definition: numbers.h:34
unsigned long UNSIGNED_QUAD
Definition: numbers.h:37
long SIGNED_QUAD
Definition: numbers.h:36
void put_signed_pair(SIGNED_QUAD quad, FILE *fp)
Definition: utils.c:125
UNSIGNED_TRIPLE get_unsigned_triple_kanji(FILE *fp)
Definition: utils.c:62
char * concat3(const char *s1, const char *s2, const char *s3)
Definition: utils.c:178
char * make_suffix(const char *s, const char *suffix)
Definition: utils.c:190
UNSIGNED_QUAD get_unsigned_quad(FILE *fp)
Definition: utils.c:83
SIGNED_PAIR get_signed_pair(FILE *fp)
Definition: utils.c:43
void sput_signed_quad(char *buf, SIGNED_QUAD quad)
Definition: utils.c:156
void put_signed_triple(SIGNED_QUAD quad, FILE *fp)
Definition: utils.c:137
void put_signed_quad(SIGNED_QUAD quad, FILE *fp)
Definition: utils.c:143
UNSIGNED_TRIPLE get_unsigned_triple(FILE *fp)
Definition: utils.c:53
void put_signed_byte(SIGNED_QUAD quad, FILE *fp)
Definition: utils.c:112
SIGNED_BYTE get_signed_byte(FILE *fp)
Definition: utils.c:29
void put_unsigned_byte(SIGNED_QUAD quad, FILE *fp)
Definition: utils.c:106
SIGNED_QUAD get_signed_quad(FILE *fp)
Definition: utils.c:93
void msg_out(int level, const char *fmt,...)
Definition: utils.c:212
void put_unsigned_triple(SIGNED_QUAD quad, FILE *fp)
Definition: utils.c:131
UNSIGNED_PAIR get_unsigned_pair(FILE *fp)
Definition: utils.c:35
void sput_signed_pair(char *buf, SIGNED_QUAD quad)
Definition: utils.c:149
char * concat(const char *s1, const char *s2)
Definition: utils.c:167
UNSIGNED_BYTE get_unsigned_byte(FILE *fp)
Definition: utils.c:24
SIGNED_TRIPLE get_signed_triple(FILE *fp)
Definition: utils.c:71
void put_unsigned_pair(SIGNED_QUAD quad, FILE *fp)
Definition: utils.c:119
#define M_FAIL
Definition: utils.h:68
char args[100]
Definition: fixwrites.c:7
void * xmalloc(size_t size)
Definition: utils.c:240
#define fp
Definition: usprintf.c:39
Definition: axohelp.c:810
#define FILE
Definition: t1stdio.h:34
s1
Definition: t4ht.c:1059
char * s2
Definition: t4ht.c:1062
*job_name strlen((char *) job_name) - 4)
char fmt[256]
Definition: tex4ht.c:3925
#define verbose
Definition: jpeg.c:35
#define s3
Definition: tokst.h:105
#define va_start(pvar)
Definition: varargs.h:30
#define va_end(pvar)
Definition: varargs.h:38
char * va_list
Definition: varargs.h:22