summaryrefslogtreecommitdiff
path: root/dviware/quicspool/libqmsquery/qmsquery.c
blob: be3730eb66ad3849bb31008b6bc77e51b81d9578 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#ifndef lint
static char *rcs = "$Header: qmsquery.c,v 1.1 88/01/15 12:19:30 simpson Rel $";
#endif
#include <stdio.h>
#include <signal.h>
#include <setjmp.h>
#include <local/standard.h>
#include "qms.h"

FILE	*_Ifp, *_Ofp;	/* Input and output file pointer */
Boolean	    _FirstChar;
static int	(*OldAlarm)();	/* Saves the old SIGALRM value */
static jmp_buf	Env;

int qmsopen(writefd, readfd)
int writefd, readfd;
{
    int		    timeout();

    if (!(_Ofp = fdopen(writefd, "w")))
	return FALSE;
    if (!(_Ifp = fdopen(readfd, "r")))
	return FALSE;
    setbuffer(_Ifp, (char *)NULL, 0);	    /* Turn off buffering on input */
    OldAlarm = signal(SIGALRM, timeout);
    return TRUE;
}

int qmsclose()
{
    (void)signal(SIGALRM, OldAlarm);
    (void)fclose(_Ofp), (void)fclose(_Ifp);
    return TRUE;
}

int timedgetc(f)
FILE	*f;
{
    int	    c;

    /* The amount of time to wait until we have decided it is EOF is
     * hard to select.  The printer does not always send the status
     * information out of the debugger port upon immediately receiving the
     * ^INFO command.  It will accept the ^INFO command, put it in its
     * buffer, and send the status information when it finally interprets
     * the ^INFO command.  I have seen it take as long as 11 seconds
     * between the time the ^INFO command was sent and the time the status
     * information is sent out the debugger port.  We don't want to wait 11
     * or 15 seconds each time we wish to read data.  We observe that each
     * ^INFO command returns at least one character and that when the ^INFO
     * command is finally interpreted, all the information is sent out to
     * the debugger port very quickly.  Consequently, we can wait a long
     * time before reading the first character, but after reading the
     * subsequent characters we wait a short time.
     */
    if (_FirstChar)
        (void)alarm(300);	/* Wait 5 minutes maximum */
    else
	(void)alarm(3);
    if (setjmp(Env)) {
	(void)alarm(0);
	return EOF;
    }
    c = getc(f);
    (void)alarm(0);
    _FirstChar = FALSE;
    return c;
}

static timeout()
{
    longjmp(Env, TRUE);
}

void qmsmapfree(mapinfo)
struct qmsmap	*mapinfo;
{
    struct qmsmap   *p;

    for (; mapinfo; mapinfo = p) {
	if (mapinfo->data)
	    free(mapinfo->data);
	p = mapinfo->next;
	free((char *)mapinfo);
    }
}

void qmsovlfree(ovlinfo)
struct qmsovl	*ovlinfo;
{
    struct qmsovl   *p;

    for (; ovlinfo; ovlinfo = p) {
	p = ovlinfo->next;
	free((char *)ovlinfo);
    }
}

void qmspfpfree(pfpinfo)
struct qmspfp	*pfpinfo;
{
    struct qmspfp   *p;

    for (; pfpinfo; pfpinfo = p) {
	if (pfpinfo->module)
	    free(pfpinfo->module);
	p = pfpinfo->next;
	free((char *)pfpinfo);
    }
}

void qmsopcfree(opcinfo)
struct qmsopc	*opcinfo;
{
    struct optnode  *p1, *p2;

    for (p1 = opcinfo->OC1; p1; p1 = p2) {
	p2 = p1->next;
	free((char *)p1);
    }
    for (p1 = opcinfo->OC2; p1; p1 = p2) {
	p2 = p1->next;
	free((char *)p1);
    }
    for (p1 = opcinfo->OC3; p1; p1 = p2) {
	p2 = p1->next;
	free((char *)p1);
    }
    for (p1 = opcinfo->OC4; p1; p1 = p2) {
	p2 = p1->next;
	free((char *)p1);
    }
    for (p1 = opcinfo->OC5; p1; p1 = p2) {
	p2 = p1->next;
	free((char *)p1);
    }
}

void qmsfntfree(fntinfo)
struct qmsfnt	*fntinfo;
{
    struct fontnode *p1, *p2;

    for (p1 = fntinfo->rom; p1; p1 = p2) {
	p2 = p1->next;
	free((char *)p1);
    }
    for (p1 = fntinfo->ram; p1; p1 = p2) {
	p2 = p1->next;
	free((char *)p1);
    }
}