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)  

psio.c
Go to the documentation of this file.
1 /*
2  * DEVICE dependent I/O
3  */
4 
5 #include "defs.h"
6 #include "emit.h"
7 #include "global.h"
8 #include "ps.h"
9 #ifdef KPATHSEA
10 #include <kpathsea/tex-file.h>
11 #endif
12 
13 static void copyfile();
14 static void createpipe();
15 
16 void
18 char *str;
19 {
20  EMIT(outfp, "%%%%BeginFile: %s\n", str);
21  copyfile(str, FALSE);
22  EMIT(outfp, "%%%%EndFile\n");
23 }
24 
25 void
27 char *str;
28 {
29  int found;
30  char newf[PATHLEN];
31 
32  if (found = ps_searchfile(str, newf)) {
34  } else
35  Warning("File %s not found", str);
36 }
37 
38 void
40 char *str;
41 {
42  int found;
43  char newf[PATHLEN];
44 
45  if (found = ps_searchfile(str, newf)) {
47  } else
48  Warning("File %s not found", str);
49 }
50 
51 void
53 char *str;
54 {
55  int found;
56  char newf[PATHLEN];
57 
58  if (found = ps_searchfile(str, newf)) {
59  EMIT(outfp, "%%%%BeginDocument: %s\n", str);
61  EMIT(outfp, "%%%%EndDocument\n");
62  } else
63  Warning("File %s not found", str);
64 }
65 
67 char *f, *newf;
68 {
69  char *filename;
70 
71  if (f[0] == '/') {
72  if (access(f, R_OK) == 0)
73  return SEARCH_ORIG;
74  } else {
75  if (dvidirpath[0] != '\0') {
76  (void)strcpy(newf, dvidirpath);
77  (void)strcat(newf, f);
78  if (access(newf, R_OK) == 0)
79  return SEARCH_NEW;
80  }
81 #ifdef KPATHSEA
82  filename = kpsearch_file(f, f, kpse_tex_ps_header_format);
83  if (filename != NULL) {
84  (void)strcpy(newf, filename);
85  return SEARCH_NEW;
86  }
87 #else
88  if (access(f, R_OK) == 0)
89  return SEARCH_ORIG;
90 #endif
91  (void)strcpy(newf, dvi2lib);
92  (void)strcat(newf, "/");
93  (void)strcat(newf, f);
94  if (access(newf, R_OK) == 0)
95  return SEARCH_NEW;
96  }
97  return SEARCH_FAIL;
98 }
99 
100 void
102 char *str;
103 {
104  EMIT(outfp, "%%%%BeginDocument: %s\n", str);
106  EMIT(outfp, "%%%%EndDocument\n");
107 }
108 
109 void
111 char *str;
112 {
113  EMIT(outfp, "%s\n", str);
114 }
115 
116 void
118 char *str;
119 {
120  int i;
121  int instring = 0;
122  int lastc = 0;
123 
124  i = 0 ;
125  while (*str) {
126  if (i > 65 && *str == ' ' && instring == 0) {
127  EMITC('\n');
128  i = 0;
129  } else {
130  EMITC(*str);
131  i++;
132  }
133  if (*str == '(' && lastc != '\\')
134  instring = 1;
135  else if (*str == ')' && lastc != '\\')
136  instring = 0;
137  lastc = *str;
138  str++;
139  }
140 }
141 
143 int c;
144 {
145  if (c < ' ' || c >= 0177)
146  EMITO(c);
147  else if (c == '(' || c == ')' || c == '\\') {
148  EMITC('\\');
149  EMITC(c);
150  } else
151  EMITC(c);
152 }
153 
155 int code, n;
156 {
157  EMITC('(');
158  c2pstr(code, n);
159  EMITS(") ");
160 }
161 
162 c2pstr(int code, int n)
163 {
164  if (n > 0) {
165  c2pstr(code>>8, n-1);
166  pschar(code&0xff);
167  }
168  return 0;
169 }
170 
171 
172 cpfile(spfp, remcom, fn)
173 FILE *spfp;
174 __BOOLEAN__ remcom;
175 char *fn;
176 {
177  int t, pt;
178 
179  if ((t = getc(spfp)) == 0x80) {
180  copy_type1_pfb(spfp, fn);
181  } else if (remcom) {
182  for (pt = '\n'; t != EOF; t = getc(spfp)) {
183  if (t == '%' && pt == '\n') {
184  while ((t = getc(spfp)) != EOF) /* remove comments */
185  if (t == '\n')
186  break;
187  } else {
188  EMITC(t);
189  pt = t;
190  }
191  }
192  } else
193  for (; t != EOF; t = getc(spfp))
194  EMITC(t);
195 }
196 
197 /*-->copyfile*/ /* copy a file straight through to output */
198 /*********************************************************************/
199 /***************************** copyfile ******************************/
200 /*********************************************************************/
201 static void
202 copyfile(fn, remcom)
203 char *fn;
204 __BOOLEAN__ remcom;
205 {
206  FILE *spfp;
207 
208  if ((spfp = fopen(fn,"r")) == NULL) {
209  Warning("Unable to open file %s", fn);
210  return;
211  }
212  if (!G_quiet)
213  (void)fprintf(stderr, "[%s", fn);
214  cpfile(spfp, remcom, fn);
215  (void)fclose(spfp);
216  if (!G_quiet) {
217  (void)fprintf(stderr, "] ");
218  (void)fflush(stderr);
219  }
220 }
221 
222 /*-->createpipe*/ /* create pipe */
223 /*********************************************************************/
224 /***************************** createpipe ******************************/
225 /*********************************************************************/
226 static void
227 createpipe(fn, remcom)
228 char *fn;
229 __BOOLEAN__ remcom;
230 {
231  FILE *spfp;
232  int t, pt;
233 
234 #ifdef MSDOS
235  Warning("MSDOS does not have pipes");
236  return;
237 #else
238  if ((spfp = (FILE *)BINARYPOPEN(fn)) != NULL) {
239  Warning("Unable to create pipe %s", fn);
240  return;
241  }
242  if (!G_quiet)
243  (void)fprintf(stderr, "[%s", fn);
244  cpfile(spfp, remcom, fn);
245  (void)pclose(spfp);
246  if (!G_quiet) {
247  (void)fprintf(stderr, "] ");
248  (void)fflush(stderr);
249  }
250 #endif
251 }
int code
Definition: aftopl.c:52
FILE * outfp
Definition: aftopl.c:22
#define n
Definition: t4ht.c:1290
@ FALSE
Definition: dd.h:101
void Warning(const char *sb1, const char *sb2)
Definition: detex.c:4677
#define BINARYPOPEN(f)
Definition: defs.h:102
#define R_OK
Definition: defs.h:31
#define PATHLEN
Definition: defs.h:141
int G_quiet
Definition: dvi2.c:78
char * dvi2lib
Definition: dvi2.c:54
char dvidirpath[1024]
Definition: dvi2.c:63
int G_removecomments
Definition: dvi2.c:80
#define fopen
Definition: xxstdio.h:21
#define fflush
Definition: xxstdio.h:24
int __BOOLEAN__
Definition: defs.h:174
add_include_spec(char *f, void *op)
Definition: fontdesc.c:777
add_setup_spec(char *f, void *op)
Definition: fontdesc.c:791
char * strcpy()
#define EMIT
Definition: emit.h:2
#define EMITO(c)
Definition: emit.h:6
#define EMITC(c)
Definition: emit.h:13
#define EMITS(s)
Definition: emit.h:4
static void
Definition: fpif.c:118
mpz_t * f
Definition: gen-fib.c:34
#define t
Definition: afcover.h:96
#define c(n)
Definition: gpos-common.c:150
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
#define EOF
Definition: afmparse.c:59
int instring
Definition: dvi.c:296
#define fclose
Definition: debug.h:100
#define getc
Definition: line.c:39
@ kpse_tex_ps_header_format
Definition: types.h:133
#define access
Definition: win32lib.h:59
#define pclose(file)
Definition: win32lib.h:271
#define fprintf
Definition: mendex.h:64
string fn
Definition: fc-lang.py:335
char * filename[256]
Definition: pbmtopk.c:46
#define str(s)
Definition: sh6.c:399
Definition: inftrees.h:24
Definition: dvips.h:235
#define FILE
Definition: t1stdio.h:34
found
Definition: tex4ht.c:5000
#define SEARCH_FAIL
Definition: ps.h:22
#define SEARCH_NEW
Definition: ps.h:24
#define SEARCH_ORIG
Definition: ps.h:23
void copy_type1_pfb()
pschar(int c)
Definition: psio.c:142
void ps_createpipe(char *str)
Definition: psio.c:101
c2pstr(int code, int n)
Definition: psio.c:162
void ps_string(char *str)
Definition: psio.c:117
static void copyfile()
ps_searchfile(char *f, char *newf)
Definition: psio.c:66
void dev_copystring(char *str)
Definition: psio.c:110
void dev_copyfile(char *str)
Definition: psio.c:17
void ps_copyfigfile(char *str)
Definition: psio.c:52
codetopsstr(int code, int n)
Definition: psio.c:154
void ps_add_setup(char *str)
Definition: psio.c:39
static void createpipe()
void ps_add_include(char *str)
Definition: psio.c:26
cpfile(FILE *spfp, __BOOLEAN__ remcom, char *fn)
Definition: psio.c:172
PATTERN * pt
Definition: vlna.c:74