2
This software may only be used by you under license from AT&T Corp.
3
("AT&T"). A copy of AT&T's Source Code Agreement is available at
4
AT&T's Internet website having the URL:
5
<http://www.research.att.com/sw/tools/graphviz/license/source.html>
6
If you received this software without first entering into a license
7
with AT&T, you have an infringing copy of this software and cannot use
8
it without violating AT&T's intellectual property rights.
12
/* Lefteris Koutsofios - AT&T Bell Laboratories */
14
#define LEFTYVERSION "27 Nov 2001 (graphviz 1.7.16)"
36
#include <sys/resource.h>
41
#define canread(fp) ((fp)->next < (fp)->endb)
44
#define canread(fp) ((fp)->_IO_read_end > (fp)->_IO_read_ptr)
46
#ifdef NO_CNT_IN_FILESTRUCT
47
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__Mac_OSX__)
48
#define canread(fp) ((fp)->_r > 0)
50
#define canread(fp) ((fp)->_IO_read_end > (fp)->_IO_read_ptr)
53
#define canread(fp) ((fp)->_cnt > 0)
62
static Grect_t txtcoords = {
63
{ 1, 1 }, { 449, 599 },
70
static int endflag = FALSE;
75
static int processinput (int);
76
static void processargs (int, char **);
77
static void processstr (char *);
78
static void printusage (void);
80
#if defined(FEATURE_X11) || defined(FEATURE_NONE)
82
int main (int argc, char **argv) {
87
extern int Mt_certify;
100
FD_SET (Gxfd, &inputfds);
107
processstr (leftyoptions);
109
processargs (argc, argv);
111
if (setjmp (exitljbuf))
125
gmapon = TRUE, G2Linit ();
129
src.flag = CHARSRC, src.s = exprstr, src.fp = NULL;
130
src.tok = -1, src.lnum = 1;
131
while ((co = Punit (&src)))
135
src.flag = FILESRC, src.s = NULL, src.fp = fp;
136
src.tok = -1, src.lnum = 1;
137
while ((co = Punit (&src)))
148
GFXredraw (), Gneedredraw = FALSE;
149
if (Gbuttonsdown > 0) {
150
GFXmove (), Gprocessevents (FALSE, G_ONEEVENT);
151
processinput (FALSE);
154
if (!processinput (FALSE))
158
if (!processinput (FALSE))
168
TXTupdate (), Erun = FALSE;
188
FD_CLR (Gxfd, &inputfds);
197
extern char ** __argv;
200
HANDLE hinstance, hprevinstance;
202
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
203
LPSTR lpCmdLine, int nCmdShow) {
207
hinstance = hInstance;
208
hprevinstance = hPrevInstance;
215
FD_SET (Gxfd, &inputfds);
223
processstr (leftyoptions);
225
processargs (__argc, __argv);
227
if (setjmp (exitljbuf))
243
src.flag = CHARSRC, src.s = exprstr, src.fp = NULL;
244
src.tok = -1, src.lnum = 1;
245
while ((co = Punit (&src)))
249
src.flag = FILESRC, src.s = NULL, src.fp = fp;
250
src.tok = -1, src.lnum = 1;
251
while ((co = Punit (&src)))
262
GFXredraw (), Gneedredraw = FALSE;
263
if (Gbuttonsdown > 0)
264
GFXmove (), Gprocessevents (FALSE, G_ONEEVENT);
267
if (!processinput (FALSE))
269
} else if (idlerunmode) {
270
if (!processinput (FALSE))
276
TXTupdate (), Erun = FALSE;
302
static struct timeval longwait = { 1000, 0 };
303
static struct timeval zerowait = { 0, 0 };
306
static int processinput (int waitflag) {
309
struct timeval tz, *tzp;
311
HANDLE evs[MAXIMUM_WAIT_OBJECTS];
318
while (Gprocessevents (FALSE, G_MANYEVENTS))
321
for (ioi = 0, n = 0; ioi < ion; ioi++)
322
if (iop[ioi].inuse && iop[ioi].ismonitored &&
323
FD_ISSET (fileno (iop[ioi].ifp), &inputfds) &&
324
canread (iop[ioi].ifp))
325
GFXmonitorfile (ioi), n++;
330
tz = (waitflag && !rtn) ? longwait : zerowait;
333
if ((n = select (FD_SETSIZE, &fdset, NULL, NULL, tzp)) <= 0)
336
if (FD_ISSET (Gxfd, &fdset))
337
Gprocessevents (TRUE, G_MANYEVENTS), n--;
341
for (ioi = 0; n > 0 && ioi < ion; ioi++)
342
if (iop[ioi].inuse && iop[ioi].ismonitored &&
343
FD_ISSET (fileno (iop[ioi].ifp), &fdset))
344
GFXmonitorfile (ioi), n--;
346
for (ioi = 0, n = 0, evn = 0; ioi < ion; ioi++) {
347
if (!iop[ioi].inuse || !IOismonitored (ioi, inputfds))
349
if ((iop[ioi].type == IO_FILE && canread (iop[ioi].ifp)) ||
350
(iop[ioi].type == IO_PIPE && iop[ioi].buf[0]))
351
GFXmonitorfile (ioi), n++;
352
if (iop[ioi].type != IO_PIPE)
354
evs[evn++] = iop[ioi].ifp;
360
n = MsgWaitForMultipleObjects (evn, evs, FALSE,
361
(waitflag && !rtn) ? 1 : 0, QS_ALLINPUT);
362
if (n == WAIT_TIMEOUT || n < WAIT_OBJECT_0 || n > WAIT_OBJECT_0 + evn)
364
if (n == WAIT_OBJECT_0 + evn)
365
Gprocessevents (TRUE, G_MANYEVENTS);
367
for (ioi = 0; ioi < ion; ioi++)
368
if (iop[ioi].inuse && IOismonitored (ioi) &&
369
(iop[ioi].type == IO_FILE || (iop[ioi].type == IO_PIPE &&
370
evs[n - WAIT_OBJECT_0] == iop[ioi].ifp)))
371
GFXmonitorfile (ioi);
376
static void processstr (char *buf) {
381
if (!(s = buf) || *s == 0)
384
for (i = 0, s1 = s; *s1; ) {
385
for (; *s1 && *s1 == ' '; s1++)
390
for (; *s1 && *s1 != ' '; s1++)
396
processargs (i, words);
400
static void processargs (int argc, char *argv[]) {
402
if (Strcmp (argv[0], "-x") == 0)
404
else if (Strcmp (argv[0], "-e") == 0)
405
exprstr = argv[1], argv++, argc--;
406
else if (Strcmp (argv[0], "-el") == 0)
407
Eerrlevel = atoi (argv[1]), argv++, argc--;
408
else if (Strcmp (argv[0], "-sd") == 0)
409
Estackdepth = atoi (argv[1]), argv++, argc--;
410
else if (Strcmp (argv[0], "-sb") == 0)
411
Eshowbody = atoi (argv[1]), argv++, argc--;
412
else if (Strcmp (argv[0], "-sc") == 0)
413
Eshowcalls = atoi (argv[1]), argv++, argc--;
414
else if (Strcmp (argv[0], "-df") == 0)
415
Gdefaultfont = argv[1], argv++, argc--;
416
else if (Strcmp (argv[0], "-w") == 0)
418
else if (Strcmp (argv[0], "-ps") == 0)
419
Gpscanvasname = argv[1], argv++, argc--;
420
else if (Strcmp (argv[0], "-V") == 0)
421
fprintf (stderr, "lefty version %s\n", LEFTYVERSION);
422
else if (Strcmp (argv[0], "-") == 0)
425
if ((fp = fopen (argv[0], "r")) == NULL)
426
panic (POS, "main", "cannot open input file: %s", argv[0]);
434
static void printusage (void) {
438
getrusage (RUSAGE_SELF, &ru);
440
#ifdef FEATURE_RUSAGE
441
printf ("user time %13.3lf\n",
442
ru.ru_utime.tv_sec + ru.ru_utime.tv_nsec / 1000000000.0);
443
printf ("system time %13.3lf\n",
444
ru.ru_stime.tv_sec + ru.ru_stime.tv_nsec / 1000000000.0);
446
printf ("user time %13.3lf\n",
447
ru.ru_utime.tv_sec + ru.ru_utime.tv_usec / 1000000.0);
448
printf ("system time %13.3lf\n",
449
ru.ru_stime.tv_sec + ru.ru_stime.tv_usec / 1000000.0);
451
printf ("resident size %10d\n", ru.ru_maxrss * getpagesize ());
452
printf ("input %8d\n", ru.ru_inblock);
453
printf ("output %8d\n", ru.ru_oublock);
454
printf ("socket msgs sent %8d\n", ru.ru_msgsnd);
455
printf ("socket msgs rcvd %8d\n", ru.ru_msgrcv);
456
printf ("real time %8d\n", time (NULL) - stime);