File: grtermio.c

package info (click to toggle)
pgplot5 5.2-13
  • links: PTS
  • area: non-free
  • in suites: potato
  • size: 6,280 kB
  • ctags: 5,903
  • sloc: fortran: 37,938; ansic: 18,809; sh: 1,147; objc: 532; makefile: 363; perl: 234; pascal: 233; tcl: 178; awk: 51; csh: 25
file content (127 lines) | stat: -rw-r--r-- 3,016 bytes parent folder | download | duplicates (52)
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
/* Support routines for terminal I/O. This module defines the following
   Fortran-callable routines: GROTER, GRCTER, GRWTER, GRRTER. */

#include <sys/ioctl.h>

long int groter_(cdev, ldev, cdev_len)
char *cdev;
long int *ldev;
int cdev_len;

/* Open a channel to the device specified by 'cdev'.
 *
 * cdev      I    The name of the device to be opened
 * ldev      I    Number of valid characters in cdev
 * cdev_len  I    Used by Fortran compiler to pass character length
 * groter      O  The open channel number (-1 indicates an error)
 */
{
    int fd, n;
    char name[64];

    n = *ldev;
    if (n > 63)
        n = 63;
    strncpy(name, cdev, n);
    name[n] = '\0';
    if ((fd = open(name, 2)) == -1)
        {
/*      perror("Cannot access graphics device");
 */
        perror(name);
        return -1;
        }
    else
        {
        return fd;
        }
}

grcter_(fd)
int *fd;

/* Close a previously opened channel.
 *
 * fd        I    The channel number to be closed
 */
{
    close(*fd);
}

grwter_(fd, cbuf, lbuf, cbuf_len)
int *fd;
char *cbuf;
long int *lbuf;
int cbuf_len;

/* Write lbuf bytes from cbuf to the channel fd.  Data is written in
 * CBREAK mode.
 *
 * fd        I    The channel number
 * cbuf      I    Character array of data to be written
 * lbuf      I/O  The number of bytes to write, set to zero on return
 * cbuf_len  I    Used by Fortran compiler to pass character length
 */
{
    int nwritten;
    struct sgttyb tty;
    int save_flags;

/*    printf ("writing %d bytes on unit %d\n", *lbuf, *fd);  */

    ioctl(*fd, TIOCGETP, &tty);
    save_flags = tty.sg_flags;
    tty.sg_flags |= CBREAK;
    ioctl(*fd, TIOCSETP, &tty);
    tty.sg_flags = save_flags;

    nwritten = write (*fd, cbuf, *lbuf);
    ioctl(*fd, TIOCSETP, &tty);
    if (nwritten != *lbuf)
        perror("Error writing to graphics device");
    *lbuf = 0;
    return;
}

grpter_(fd, cprom, lprom, cbuf, lbuf, cprom_len, cbuf_len)
int  *fd;
char *cprom, *cbuf;
long int *lprom, *lbuf;
int  cprom_len, cbuf_len;

/* Write prompt string on terminal and then read response.  This version
 * will try to read lbuf characters.
 *
 * fd        I    The channel number
 * cprom     I    An optional prompt string
 * lprom     I    Number of valid characters in cprom
 * cbuf        O  Character array of data read
 * lbuf      I/O  The number of bytes to read, on return number read
 * cbuf_len  I    Used by Fortran compiler to pass character length
 */
{
    int i0, nread, ntry;
    struct sgttyb tty;
    int save_flags;

    ioctl(*fd, TIOCGETP, &tty);
    save_flags = tty.sg_flags;
    tty.sg_flags |= CBREAK;
    ioctl(*fd, TIOCSETP, &tty);
    tty.sg_flags = save_flags;

    if( *lprom>0)
      write (*fd, cprom, *lprom);
    i0=0;
    ntry=*lbuf;
    do {
        nread = read (*fd, &cbuf[i0], ntry);
 /*   printf("Nread=%d, Ntry=%d\n",nread,ntry); */
        i0=i0+nread;
        ntry=*lbuf-i0-1;
    } while (nread>0 && ntry>0);

    ioctl(*fd, TIOCSETP, &tty);
    *lbuf=i0;
    return;
}