aboutsummaryrefslogtreecommitdiff
path: root/unix/os/zfioty.c
blob: b885b3544523d32c6f846dd81d3d32a1d06e8a9e (plain) (blame)
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
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
 */

#include <stdio.h>

#define	import_kernel
#define	import_knames
#define import_spp
#include <iraf.h>


extern  int  ZOPNTX (), ZCLSTX (), ZFLSTX (), ZGETTX ();
extern  int  ZNOTTX (), ZPUTTX (), ZSEKTX (), ZSTTTX ();


/*
 * ZFIOTY -- Device driver for terminals.  In the 4.1BSD UNIX kernel the same
 * driver is used for both terminals and ordinary text files, hence all we
 * need do to implement a TY routine is call the corresponding TX routine.
 * See "zfiotx.c" for the real driver.
 */

/* ZOPNTY -- Open or create a text file.  The special name "dev$tty" denotes
 * the user terminal and is passed to us via TTOPEN (in etc).  Direct access
 * to the terminal in this way (possibly from a subprocess) may not be possible
 * on all host systems.
 */
int
ZOPNTY (
  PKCHAR  *osfn,		/* UNIX filename			*/
  XINT	  *mode,		/* file access mode			*/
  XINT	  *chan 		/* UNIX channel of file (output)	*/
)
{
	PKCHAR	ttyname[SZ_FNAME+1];

	if (strcmp ((char *)osfn, "dev$tty") == 0)
	    strcpy ((char *)ttyname, TTYNAME);
	else
	    strcpy ((char *)ttyname, (char *)osfn);

	return ZOPNTX (ttyname, mode, chan);
}


/* ZCLSTY -- Close a text file.
 */
int
ZCLSTY (XINT *fd, XINT *status)
{
	return ZCLSTX (fd, status);
}


/* ZFLSTY -- Flush any buffered textual output.
 */
int
ZFLSTY (XINT *fd, XINT *status)
{
	return ZFLSTX (fd, status);
}


/* ZGETTY -- Get a line of text from a text file.  Unpack machine chars
 * into type XCHAR.  If output buffer is filled before newline is encountered,
 * the remainder of the line will be returned in the next call, and the
 * current line will NOT be newline terminated.  If maxchar==1 assert
 * character mode, otherwise assert line mode.
 */
int
ZGETTY (XINT *fd, XCHAR *buf, XINT *maxchars, XINT *status)
{
	return ZGETTX (fd, buf, maxchars, status);
}


/* ZNOTTY -- Return the seek offset of the beginning of the current line
 * of text.
 */
int
ZNOTTY (XINT *fd, XLONG *offset)
{
	return ZNOTTX (fd, offset);
}


/* ZPUTTY -- Put "nchars" characters into the text file "fd".   The final
 * character will always be a newline, unless the FIO line buffer overflowed,
 * in which case the correct thing to do is to write out the line without
 * artificially adding a newline.  We do not check for newlines in the text,
 * hence ZNOTTY will return the offset of the next write, which will be the
 * offset of the beginning of a line of text only if we are called to write
 * full lines of text.
 */
int
ZPUTTY (
  XINT	*fd,				/* file to be written to	*/
  XCHAR	*buf,				/* data to be output		*/
  XINT	*nchars,			/* nchars to write to file	*/
  XINT	*status 			/* return status		*/
)
{
	return ZPUTTX (fd, buf, nchars, status);
}


/* ZSEKTY -- Seek on a text file to the character offset given by a prior
 * call to ZNOTTY.  This offset should always refer to the beginning of a line.
 */
int
ZSEKTY (XINT *fd, XLONG *znotty_offset, XINT *status)
{
	return ZSEKTX (fd, znotty_offset, status);
}


/* ZSTTTY -- Get file status for a text file.
 */
int
ZSTTTY (
  XINT	*fd,			/* file number				*/
  XINT	*param,			/* status parameter to be returned	*/
  XLONG	*value 			/* return value				*/
)
{
	return ZSTTTX (fd, param, value);
}