~ubuntu-branches/ubuntu/jaunty/texlive-bin/jaunty

« back to all changes in this revision

Viewing changes to build/TeX/texk/web2c/window/mftalk.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2008-06-26 23:14:59 UTC
  • mfrom: (2.1.30 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080626231459-y02rjsrgtafu83yr
Tags: 2007.dfsg.2-3
add missing source roadmap.fig of roadmap.eps in fontinst documentation
(Closes: #482915) (urgency medium due to RC bug)
(new patch add-missing-fontinst-source)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* mftalk.c -- generic Metafont window server.
2
 
   Copyright (C) 1994 Ralph Schleicher
3
 
   Slightly modified for Web2c 7.0 by kb@mail.tug.org.
4
 
   Further modifications for Web2C 7.2 by Mathias.Herberts@irisa.fr  */
5
 
 
6
 
/* This library is free software; you can redistribute it and/or
7
 
   modify it under the terms of the GNU General Public License as
8
 
   published by the Free Software Foundation; either version 2 of
9
 
   the License, or (at your option) any later version.
10
 
 
11
 
   This library is distributed in the hope that it will be useful,
12
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
   GNU General Public License for more details.
15
 
 
16
 
   You should have received a copy of the GNU General Public License
17
 
   along with this library; if not, write to the Free Software
18
 
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
 
 
20
 
/* Please remember the following for porting to UNIX:
21
 
 
22
 
        pid = fork ();
23
 
        if (pid == 0)
24
 
          execve (...);         pid = spawnve (mode, ...);
25
 
        else if (pid == -1)     if (pid == -1)
26
 
          error ();               error ();
27
 
        else                    else
28
 
          success ();             success ();
29
 
 
30
 
   Spawnve(2) has many different modes and a `session' is indicated by
31
 
   running on an extra terminal.  */
32
 
 
33
 
 
34
 
#define EXTERN          extern
35
 
#include "../mfd.h"
36
 
 
37
 
#ifdef MFTALKWIN
38
 
 
39
 
#undef input
40
 
#undef output
41
 
#undef read
42
 
#undef write
43
 
#ifdef OS2
44
 
#include <sys/param.h>
45
 
#include <process.h>
46
 
extern int close (int);
47
 
extern int pipe (int *);
48
 
extern int read (int, void *, size_t);
49
 
extern int setmode (int, int);
50
 
extern int write (int, const void *, size_t);
51
 
#endif
52
 
#include <fcntl.h>
53
 
#include <signal.h>
54
 
#include <kpathsea/variable.h>
55
 
#include "mftalk.h"
56
 
 
57
 
/* We use SIGCHLD, but fall back on SIGCLD if that's all we have. */
58
 
#if !defined (SIGCHLD) && defined (SIGCLD)
59
 
#define SIGCHLD SIGCLD
60
 
#endif
61
 
 
62
 
#define fatal(func, cond) do { if (cond) FATAL_PERROR ("perror"); } while (0)
63
 
 
64
 
static RETSIGTYPE child_died P1H(int sig);
65
 
static string app_type P2H(char *prog, int *app);
66
 
 
67
 
static int pid = -1;                    /* Process ID of our child. */
68
 
static int win = -1;                    /* Write handle to the `window'. */
69
 
static int buf[8];                      /* Temporary buffer. */
70
 
static RETSIGTYPE (*old) ();            /* Old signal handler. */
71
 
 
72
 
 
73
 
boolean
74
 
mf_mftalk_initscreen P1H(void)
75
 
{
76
 
  int app;                              /* Client application type. */
77
 
  char *prog, *name;                    /* Client program name. */
78
 
    /* Size of METAFONT window. */
79
 
  char height[MAX_INT_LENGTH], width[MAX_INT_LENGTH];
80
 
    /* Inherited pipe handles. */
81
 
  char input[MAX_INT_LENGTH], output[MAX_INT_LENGTH];
82
 
  char parent[MAX_INT_LENGTH];          /* My own process ID. */
83
 
  int sc_pipe[2];                       /* Server->Client pipe. */
84
 
  int cs_pipe[2];                       /* Client->Server pipe. */
85
 
  int res, ack;                         /* Wait until child is ready. */
86
 
 
87
 
  prog = kpse_var_value ("MFTALK");
88
 
  if (prog == NULL)
89
 
    prog = "mftalk.exe";
90
 
 
91
 
  name = app_type (prog, &app);
92
 
  if (!name)
93
 
    return 0;
94
 
 
95
 
  if (pipe (sc_pipe) == -1)
96
 
    return 0;
97
 
  if (pipe (cs_pipe) == -1)
98
 
    {
99
 
      close (sc_pipe[0]);
100
 
      close (sc_pipe[1]);
101
 
      return 0;
102
 
    }
103
 
#ifdef OS2
104
 
  fatal (setmode, setmode (sc_pipe[0], O_BINARY) == -1);
105
 
  fatal (setmode, setmode (sc_pipe[1], O_BINARY) == -1);
106
 
  fatal (setmode, setmode (cs_pipe[0], O_BINARY) == -1);
107
 
  fatal (setmode, setmode (cs_pipe[1], O_BINARY) == -1);
108
 
#endif
109
 
 
110
 
  old = signal (SIGCHLD, child_died);
111
 
  fatal (old, old == SIG_ERR);
112
 
 
113
 
  sprintf (height, "-h%d", screendepth);
114
 
  sprintf (width, "-w%d", screenwidth);
115
 
  sprintf (input, "-i%d", sc_pipe[0]);
116
 
  sprintf (output, "-o%d", cs_pipe[1]);
117
 
  sprintf (parent, "-p%d", getpid ());
118
 
 
119
 
#ifdef OS2
120
 
  pid = spawnl (app, name, prog, height, width, input, output, parent, NULL);
121
 
#else
122
 
  pid = fork ();
123
 
  if (pid == 0)
124
 
    {
125
 
      fatal (close, close (0) == -1);
126
 
      fatal (dup, dup (sc_pipe[0]) != 0);
127
 
      fatal (close, close (sc_pipe[0]) == -1);
128
 
      fatal (close, close (sc_pipe[1]) == -1);      
129
 
      fatal (close, close (1) == -1);
130
 
      fatal (dup, dup (cs_pipe[1]) != 1);
131
 
      fatal (close, close (cs_pipe[0]) == -1);
132
 
      fatal (close, close (cs_pipe[1]) == -1);      
133
 
      
134
 
      /* We still pass the file handles as parameters for
135
 
       * backward compatibility. instead of sc_pipe[0] and
136
 
       * cs_pipe[1] we just pass 0 (stdin) and 1 (stdout).
137
 
       */
138
 
 
139
 
      sprintf (input, "-i0");
140
 
      sprintf (output, "-o1");
141
 
      
142
 
      execl (name, prog, height, width, input, output, parent, NULL);
143
 
    }
144
 
#endif /* not OS2 */
145
 
  switch (pid)
146
 
    {
147
 
    case -1:
148
 
    failure:
149
 
      fatal (close, close (sc_pipe[0]) == -1);
150
 
      fatal (close, close (sc_pipe[1]) == -1);
151
 
      fatal (close, close (cs_pipe[0]) == -1);
152
 
      fatal (close, close (cs_pipe[1]) == -1);
153
 
      fatal (signal, signal (SIGCHLD, old) == SIG_ERR);
154
 
      break;
155
 
    default:
156
 
      res = read (cs_pipe[0], &ack, sizeof (int));
157
 
      if (res != sizeof (int) || ack != MF_ACK)
158
 
        goto failure;
159
 
      fatal (close, close (cs_pipe[0]) == -1);
160
 
      win = sc_pipe[1];
161
 
      break;
162
 
    }
163
 
 
164
 
  return (win == -1) ? 0 : 1;
165
 
}
166
 
 
167
 
 
168
 
void
169
 
mf_mftalk_updatescreen P1H(void)
170
 
{
171
 
  buf[0] = MF_FLUSH;
172
 
  write (win, buf, sizeof (int));
173
 
}
174
 
 
175
 
 
176
 
void
177
 
mf_mftalk_blankrectangle P4C(screencol, left,
178
 
                             screencol, right,
179
 
                             screenrow, top,
180
 
                             screenrow, bottom)
181
 
{
182
 
  buf[0] = MF_RECT;
183
 
  buf[1] = MF_WHITE;
184
 
  buf[2] = left;
185
 
  buf[3] = bottom;
186
 
  buf[4] = right;
187
 
  buf[5] = top;
188
 
 
189
 
  write (win, buf, 6 * sizeof (int));
190
 
}
191
 
 
192
 
 
193
 
void
194
 
mf_mftalk_paintrow P4C(screenrow, row,
195
 
                       pixelcolor, init_color,
196
 
                       transspec, transition_vector,
197
 
                       screencol, vector_size)
198
 
{
199
 
  buf[0] = MF_LINE;
200
 
  buf[1] = init_color == 0 ? MF_WHITE : MF_BLACK;
201
 
  buf[2] = *transition_vector++;
202
 
  buf[3] = row;
203
 
  buf[4] = --vector_size;
204
 
 
205
 
  write (win, buf, 5 * sizeof (int));
206
 
  write (win, transition_vector, vector_size * sizeof (int));
207
 
}
208
 
 
209
 
 
210
 
static string
211
 
app_type P2C(string, prog,  int *, app)
212
 
{
213
 
#ifdef OS2
214
 
  int res, app;
215
 
 
216
 
  res = DosSearchPath (0x02 | 0x01, "PATH", prog, buf, len);
217
 
  if (res != 0)
218
 
    return -1;
219
 
 
220
 
  res = DosQueryAppType (buf, &app);
221
 
  if (res != 0)
222
 
    return -1;
223
 
 
224
 
  switch (app & 0x07)                   /* Quick guess. */
225
 
    {
226
 
    case 0x00: return (P_SESSION | P_DEFAULT);
227
 
    case 0x01: return (P_SESSION | P_FULLSCREEN);
228
 
    case 0x02: return (P_SESSION | P_WINDOWED);
229
 
    case 0x03: return (P_PM);
230
 
    }
231
 
#endif /* OS2 */
232
 
 
233
 
  *app = 0; /* Irrelevant.  */
234
 
  return prog;
235
 
}
236
 
 
237
 
 
238
 
static RETSIGTYPE
239
 
child_died (int sig)
240
 
{
241
 
#ifdef OS2
242
 
  fatal (signal, signal (sig, SIG_ACK) == SIG_ERR);
243
 
#endif
244
 
  fatal (signal, signal (sig, SIG_IGN) == SIG_ERR);
245
 
 
246
 
  if (pid == -1 || kill (-pid, 0) == 0) /* This was not our child. */
247
 
    {
248
 
      if (old != SIG_IGN)
249
 
        {
250
 
          fatal (signal, signal (sig, old) == SIG_ERR);
251
 
          fatal (raise, raise (sig) == -1);
252
 
        }
253
 
      fatal (signal, signal (sig, child_died) == SIG_ERR);
254
 
    }
255
 
  else
256
 
    {
257
 
      close (win);                      /* This may fail. */
258
 
      win = -1;
259
 
 
260
 
      pid = -1;
261
 
 
262
 
      screenstarted = false;            /* METAFONT variables. */
263
 
      screenOK = false;
264
 
 
265
 
      fatal (signal, signal (sig, old) == SIG_ERR);
266
 
    }
267
 
}
268
 
 
269
 
#else /* !MFTALKWIN */
270
 
 
271
 
int mftalk_dummy;
272
 
 
273
 
#endif /* !MFTALKWIN */