1
////////////////////////////////////////////////////////////////////////////////
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
4
// (c) copyright 1996, Vrije Universiteit Amsterdam.
5
// Author: Frank Dehne (frank@cs.vu.nl).
7
// TCM is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
12
// TCM is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with TCM; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
////////////////////////////////////////////////////////////////////////////////
23
// Adapted from the book "Motif Programming, The Essentials...and More"
25
// Published by Digital Press, ISBN 1-55558-089-0.
26
// To order the book, call 1-800-DIGITAL and ask for EY-J816E-DP.
28
// Copyright 1992, by Digital Equipment Corp.
30
// This is the implementation of the link library.
33
#if defined(__CYGWIN__)
34
#include <asm/socket.h> // for FIONREAD.
37
#include <termios.h> // for FIONREAD.
38
#elif defined(HPUX) || defined(AIX) || defined(OSF1) || defined(__CYGWIN__)
39
#include <sys/ioctl.h>
41
#include <sys/filio.h>
44
#include <sys/types.h>
47
void Link::Open(const char *name, const char *param) {
50
if((pid = fork()) == 0) { // child
54
close(2); // 2 new lines
59
execlp(name, name, param, (char *)0);
62
fpin = fdopen(pipefd1[0], "r");
63
fpout = fdopen(pipefd2[1], "w");
70
// wait((union wait *) 0);
79
int Link::Read(char *s) {
81
if (fgets(s, 100, fpin) == 0)
83
// linked-to process has terminated on its own.
85
s[strlen(s)-1] = '\0'; // lose the newline character.
91
int Link::InputWaiting() {
93
ioctl(pipefd1[0], FIONREAD, &num); // see how many chars in buffer.
97
void Link::WriteChar(char c) {
98
fprintf(fpout, "%c", c);
102
void Link::Write(const char *s) {
103
fprintf(fpout, "%s\n", s);