1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-01-15 07:54:13 +00:00
Nick Briggs 0ad69fc6fe Create a new inc/xxxdefs.h for each src/xxx.c containing appropriate function prototypes.
This also involves removing unnecessary forward declarations, inserting
       includes for all cross-file function references, making some definitions
       static if they are not otherwise used, correcting errors that were exposed
       by having correct prototypes.

	new file:   inc/allocmdsdefs.h
	new file:   inc/arith2defs.h
	new file:   inc/arith3defs.h
	new file:   inc/arith4defs.h
	new file:   inc/array2defs.h
	new file:   inc/array3defs.h
	new file:   inc/array4defs.h
	new file:   inc/array5defs.h
	new file:   inc/array6defs.h
	new file:   inc/arraydefs.h
	new file:   inc/bbtsubdefs.h
	new file:   inc/bindefs.h
	new file:   inc/bindsdefs.h
	new file:   inc/bitbltdefs.h
	new file:   inc/bltdefs.h
	new file:   inc/byteswapdefs.h
	new file:   inc/car-cdrdefs.h
	new file:   inc/chardevdefs.h
	new file:   inc/commondefs.h
	new file:   inc/conspagedefs.h
	new file:   inc/dbgtooldefs.h
	new file:   inc/dirdefs.h
	new file:   inc/drawdefs.h
	new file:   inc/dskdefs.h
	new file:   inc/dspifdefs.h
	new file:   inc/dspsubrsdefs.h
	new file:   inc/eqfdefs.h
	new file:   inc/etherdefs.h
	new file:   inc/findkeydefs.h
	new file:   inc/fpdefs.h
	new file:   inc/fvardefs.h
	new file:   inc/gc2defs.h
	new file:   inc/gcarraydefs.h
	new file:   inc/gccodedefs.h
	new file:   inc/gcdefs.h
	new file:   inc/gcfinaldefs.h
	new file:   inc/gchtfinddefs.h
	new file:   inc/gcmain3defs.h
	new file:   inc/gcoflowdefs.h
	new file:   inc/gcrcelldefs.h
	new file:   inc/gcrdefs.h
	new file:   inc/gcscandefs.h
	new file:   inc/gvar2defs.h
	new file:   inc/hacksdefs.h
	new file:   inc/hardrtndefs.h
	new file:   inc/inetdefs.h
	new file:   inc/initdspdefs.h
	new file:   inc/initkbddefs.h
	new file:   inc/initsoutdefs.h
	modified:   inc/inlineC.h
	new file:   inc/intcalldefs.h
	new file:   inc/kbdsubrsdefs.h
	new file:   inc/keyeventdefs.h
	new file:   inc/keylibdefs.h
	new file:   inc/kprintdefs.h
	new file:   inc/ldsoutdefs.h
	new file:   inc/lineblt8defs.h
	new file:   inc/lisp2cdefs.h
	modified:   inc/lispemul.h
	new file:   inc/llcolordefs.h
	new file:   inc/llstkdefs.h
	modified:   inc/lnk-inlineC.h
	new file:   inc/loopsopsdefs.h
	new file:   inc/lowlev1defs.h
	new file:   inc/lowlev2defs.h
	new file:   inc/lsthandldefs.h
	new file:   inc/maindefs.h
	new file:   inc/misc7defs.h
	new file:   inc/miscndefs.h
	new file:   inc/mkatomdefs.h
	new file:   inc/mkcelldefs.h
	new file:   inc/mvsdefs.h
	new file:   inc/osmsgdefs.h
	new file:   inc/perrnodefs.h
	new file:   inc/returndefs.h
	new file:   inc/rpcdefs.h
	new file:   inc/rplconsdefs.h
	new file:   inc/shiftdefs.h
	new file:   inc/storagedefs.h
	new file:   inc/subr0374defs.h
	new file:   inc/subrdefs.h
	new file:   inc/sxhashdefs.h
	new file:   inc/testtooldefs.h
	new file:   inc/timerdefs.h
	new file:   inc/typeofdefs.h
	new file:   inc/ubf1defs.h
	new file:   inc/ubf2defs.h
	new file:   inc/ubf3defs.h
	new file:   inc/ufsdefs.h
	new file:   inc/unixcommdefs.h
	new file:   inc/unwinddefs.h
	new file:   inc/uraiddefs.h
	new file:   inc/usrsubrdefs.h
	new file:   inc/uutilsdefs.h
	new file:   inc/vars3defs.h
	new file:   inc/vmemsavedefs.h
	new file:   inc/xbbtdefs.h
	new file:   inc/xcdefs.h
	new file:   inc/xcursordefs.h
	new file:   inc/xinitdefs.h
	new file:   inc/xlspwindefs.h
	new file:   inc/xmkicondefs.h
	new file:   inc/xrdoptdefs.h
	new file:   inc/xscrolldefs.h
	new file:   inc/xwinmandefs.h
	new file:   inc/z2defs.h
	modified:   src/allocmds.c
	modified:   src/arith2.c
	modified:   src/arith3.c
	modified:   src/arith4.c
	modified:   src/array.c
	modified:   src/array2.c
	modified:   src/array3.c
	modified:   src/array4.c
	modified:   src/array5.c
	modified:   src/array6.c
	modified:   src/bbtsub.c
	modified:   src/bin.c
	modified:   src/binds.c
	modified:   src/bitblt.c
	modified:   src/blt.c
	modified:   src/byteswap.c
	modified:   src/car-cdr.c
	modified:   src/chardev.c
	modified:   src/common.c
	modified:   src/conspage.c
	modified:   src/dbgtool.c
	modified:   src/dir.c
	modified:   src/draw.c
	modified:   src/dsk.c
	modified:   src/dspif.c
	modified:   src/dspsubrs.c
	modified:   src/eqf.c
	modified:   src/ether.c
	modified:   src/findkey.c
	modified:   src/foreign.c
	modified:   src/fp.c
	modified:   src/fvar.c
	modified:   src/gc.c
	modified:   src/gc2.c
	modified:   src/gcarray.c
	modified:   src/gccode.c
	modified:   src/gcfinal.c
	modified:   src/gchtfind.c
	modified:   src/gcmain3.c
	modified:   src/gcoflow.c
	modified:   src/gcr.c
	modified:   src/gcrcell.c
	modified:   src/gcscan.c
	modified:   src/gvar2.c
	modified:   src/hacks.c
	modified:   src/hardrtn.c
	modified:   src/inet.c
	modified:   src/initdsp.c
	modified:   src/initkbd.c
	modified:   src/initsout.c
	modified:   src/intcall.c
	modified:   src/kbdsubrs.c
	modified:   src/keyevent.c
	modified:   src/keylib.c
	modified:   src/kprint.c
	modified:   src/ldsout.c
	modified:   src/lineblt8.c
	modified:   src/lisp2c.c
	modified:   src/llcolor.c
	modified:   src/llstk.c
	modified:   src/loopsops.c
	modified:   src/lowlev1.c
	modified:   src/lowlev2.c
	modified:   src/lsthandl.c
	modified:   src/main.c
	modified:   src/misc7.c
	modified:   src/miscn.c
	modified:   src/mkatom.c
	modified:   src/mkcell.c
	modified:   src/mvs.c
	modified:   src/osmsg.c
	modified:   src/perrno.c
	modified:   src/return.c
	modified:   src/rpc.c
	modified:   src/rplcons.c
	modified:   src/setsout.c
	modified:   src/shift.c
	modified:   src/storage.c
	modified:   src/subr.c
	modified:   src/subr0374.c
	modified:   src/sxhash.c
	modified:   src/testtool.c
	modified:   src/timer.c
	modified:   src/truecolor.c
	modified:   src/tstsout.c
	modified:   src/typeof.c
	modified:   src/ubf1.c
	modified:   src/ubf2.c
	modified:   src/ubf3.c
	modified:   src/ufn.c
	modified:   src/ufs.c
	modified:   src/unixcomm.c
	modified:   src/unwind.c
	modified:   src/uraid.c
	modified:   src/usrsubr.c
	modified:   src/uutils.c
	modified:   src/vars3.c
	modified:   src/vmemsave.c
	modified:   src/xbbt.c
	modified:   src/xc.c
	modified:   src/xcursor.c
	modified:   src/xinit.c
	modified:   src/xlspwin.c
	modified:   src/xmkicon.c
	modified:   src/xrdopt.c
	modified:   src/xscroll.c
	modified:   src/xwinman.c
	modified:   src/z2.c
2020-09-04 18:21:44 -07:00

409 lines
11 KiB
C

/* $Id: osmsg.c,v 1.2 1999/01/03 02:07:29 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved */
static char *id = "$Id: osmsg.c,v 1.2 1999/01/03 02:07:29 sybalsky Exp $ Copyright (C) Venue";
/************************************************************************/
/* */
/* O S M E S S A G E . C */
/* */
/* Functions for handling the redirection of console and stan- */
/* dard-error output so it appears in the prompt window. */
/* */
/* */
/************************************************************************/
/************************************************************************/
/* */
/* (C) Copyright 1989-95 Venue. All Rights Reserved. */
/* Manufactured in the United States of America. */
/* */
/************************************************************************/
#include "version.h"
#ifndef DOS
#include <pwd.h>
#include <sys/types.h>
#include <unistd.h>
#ifdef ISC
#include <sys/bsdtypes.h>
#endif /* ISC */
#include <sys/file.h>
#include <sys/stat.h>
#ifndef AIX
#include <sys/ioctl.h>
#endif /* AIX */
#include <sys/time.h>
#ifndef AIX
#ifndef APOLLO
#ifndef MACOSX
#ifndef FREEBSD
#include <sys/vfs.h>
#endif /* FREEBSD */
#endif /* MACOSX */
#endif /* APOLLO */
#endif /* AIX */
#ifndef SYSVONLY
#include <strings.h>
#endif /* SYSVONLY */
#endif /* DOS */
#include <setjmp.h>
#include <stdio.h>
#include <errno.h>
#include "lispemul.h"
#include "lispmap.h"
#include "adr68k.h"
#include "lsptypes.h"
#include "arith.h"
#include "stream.h"
#include "lspglob.h"
#include "timeout.h"
#include "locfile.h"
#include "osmsg.h"
#include "dbprint.h"
#include "osmsgdefs.h"
#ifdef OS4
#include <stropts.h>
#endif
#define MESSAGE_BUFFER_SIZE 1024
int cons_tty;
int cons_pty;
char logfile[100];
int log_id;
int previous_size;
int logChanged; /* T if log file has changed since last READ */
/* Set by flush_pty, to avoid the stat call */
u_int LogFileFd;
extern u_int LispReadFds;
/************************************************************************/
/* */
/* m e s s _ i n i t */
/* */
/* Initialize console-message handling. Console & Log msgs */
/* are redirected to a pty; when messages appear, we get the */
/* interrupt, and signal a Lisp interrupt to print each msg */
/* in the prompt window. For historical reasons, the msgs */
/* are saved on the file tmp/<username>-log. */
/* */
/************************************************************************/
void mess_init() {
#ifndef XWINDOW
#ifndef DOS
int id;
struct passwd *pwd;
int ttyfd;
int ptyfd, ptynum;
char *ptyname, *ttyname;
int temp, flags;
int on = 1;
ptyname = "/dev/ptypx";
ttyname = "/dev/ttypx";
/* Get pty and tty */
ptynum = 0;
needpty:
while (ptynum < 16) {
ptyname[9] = "0123456789abcdef"[ptynum];
if ((ptyfd = open(ptyname, 2)) >= 0) goto gotpty;
ptynum++;
}
return;
gotpty:
ttyname[9] = ptyname[9];
if ((ttyfd = open(ttyname, 2)) < 0) {
ptynum++;
close(ptyfd);
goto needpty;
}
/* Set tty parameters same as stderr */
ioctl(2, TIOCGETD, &temp); /* Line discipline */
ioctl(ttyfd, TIOCSETD, &temp);
ioctl(2, TIOCGETP, &temp); /* TTY parameters */
ioctl(ttyfd, TIOCSETP, &temp);
ioctl(2, TIOCLGET, &temp);
ioctl(ttyfd, TIOCLSET, &temp);
ioctl(2, TIOCGETC, &temp); /* Terminal characters */
ioctl(ttyfd, TIOCSETC, &temp);
ioctl(2, TIOCGLTC, &temp); /* Local special characters */
ioctl(ttyfd, TIOCSLTC, &temp);
/* Get console IO */
ioctl(ptyfd, FIOCLEX, 0);
#ifndef AIX
if ((ioctl(ttyfd, TIOCCONS, 0)) == -1) {
OSMESSAGE_PRINT(printf("TIOCCONS error\n"));
exit(-1);
}
#endif /* AIX */
cons_pty = ptyfd;
cons_tty = ttyfd;
/* Initialize log file */
pwd = getpwuid(getuid());
sprintf(logfile, "/tmp/%s-lisp.log", pwd->pw_name);
if (unlink(logfile) == -1) { /* delete old log file */
if (errno != ENOENT) return;
}
if ((log_id = open(logfile, (O_RDWR | O_CREAT), 0666)) < 0) return;
#ifdef LOGINT
LogFileFd = 1 << cons_pty;
flags = fcntl(cons_pty, F_GETFL, 0);
flags = fcntl(cons_pty, F_SETFL, (flags | FASYNC | FNDELAY));
if (fcntl(cons_pty, F_SETOWN, getpid()) == -1) {
#ifdef DEBUG
perror("fcntl F_SETOWN of log PTY");
#endif
};
LispReadFds |= LogFileFd;
flush_pty();
#endif
previous_size = 0;
DBPRINT(("Console logging started.\n"));
#endif /* DOS */
#endif /* XWINDOW */
}
/************************************************************************/
/* */
/* m e s s _ r e s e t */
/* */
/* Undo the redirection of console and standard-error outputs */
/* presumably preparatory to shutting down lisp. Closes the */
/* TTY/PTY pair used for logging the messages */
/* */
/************************************************************************/
void mess_reset() {
#ifndef DOS
#ifndef XWINDOW
int console_fd;
close(log_id);
close(cons_tty);
close(cons_pty);
/* Try to make /dev/console be the real console again */
/*** This sequence sometimes cause SunOs panic on SunOS4.0(and 4.0.1).
TIOCCONS probelm ???
if ((console_fd = open("/dev/console", 0)) >= 0) {
ioctl(console_fd, TIOCCONS, 0);
close(console_fd);
}
***/
#endif /* XWINDOW */
#endif /* DOS */
}
/************************************************************************/
/* */
/* m e s s _ r e a d p */
/* */
/* Returns T if there are log/console messages waiting */
/* to be printed. More accurately, if the logChanged flag */
/* has been set by flush_pty(). */
/* */
/************************************************************************/
#ifndef DOS
static struct timeval selecttimeout = {0, 0};
#endif
LispPTR mess_readp() {
#ifndef DOS
#ifndef XWINDOW
int id;
struct stat sbuf;
int size;
int rval;
struct statfs fsbuf;
/* polling pty nd flush os message to log file */
flush_pty();
/* * * * * * * * * * * * COMMENTED OUT * * * * * * * * *
SETJMP(NIL);
TIMEOUT( rval=stat(logfile, &sbuf) );
if(rval != 0)
{
error("osmessage error: can not find a log file under /tmp");
return(NIL);
}
if( previous_size < (int)(sbuf.st_size) ) return(ATOM_T);
* * * * * * * * * * * * * */
if (logChanged) return (ATOM_T);
#endif /* XWINDOW */
#endif /* DOS */
return (NIL);
}
/************************************************************************/
/* */
/* m e s s _ r e a d */
/* */
/* Read up to 1024 chars of log and console message(s) */
/* that are waiting to be printed, into a buffer supplied */
/* by the caller. If all pending message text gets read in */
/* this call, reset the logChanged flag; Otherwise, leave */
/* it set, so Lisp knows there is more to read. */
/* */
/************************************************************************/
LispPTR mess_read(LispPTR *args)
/* args[0] buffer */
{
#if defined(DOS) || defined(XWINDOW)
return (NIL);
#else
int id;
struct stat sbuf;
int size, save_size;
char *base;
LispPTR *naddress;
int i;
static char temp_buf[MESSAGE_BUFFER_SIZE];
SETJMP(NIL);
/* Get buff address from LISP */
naddress = (LispPTR *)(Addr68k_from_LADDR(args[0]));
base = (char *)(Addr68k_from_LADDR(((OneDArray *)naddress)->base));
close(log_id);
TIMEOUT(log_id = open(logfile, O_RDONLY));
if (log_id == -1) return (NIL);
TIMEOUT(i = fstat(log_id, &sbuf));
if (i != 0) {
OSMESSAGE_PRINT(printf("stat err\n"));
return (NIL);
}
save_size = (int)(sbuf.st_size);
size = save_size - previous_size;
if (size > MESSAGE_BUFFER_SIZE)
size = MESSAGE_BUFFER_SIZE;
else
logChanged = 0; /* only reset msg-pending flg if we cleaned it out! */
TIMEOUT(i = lseek(log_id, previous_size, L_SET));
if (i == -1) {
OSMESSAGE_PRINT(printf("seek err\n"));
return (NIL);
}
/* Now, read "console output" */
TIMEOUT(size = read(log_id, temp_buf, size));
if (size == -1) {
OSMESSAGE_PRINT(printf("read err\n"));
return (NIL);
}
TIMEOUT(i = lseek(log_id, save_size, L_SET));
if (i == -1) {
OSMESSAGE_PRINT(printf("seek err\n"));
return (NIL);
}
/*
TIMEOUT( close(id) );
*/
previous_size += size;
for (i = 0; i < size; ++i) {
if (temp_buf[i] == '\n') temp_buf[i] = '\000';
}
/* COPY actual Lisp Buffer(for BYTESWAP magic) */
StrNCpyFromCToLisp(base, temp_buf, size);
return (GetSmallp(size));
#endif /* DOS | XWINDOW*/
}
/************************************************************************/
/* */
/* f l u s h _ p t y */
/* */
/* Called whenever the console/standard-error PTY signals (IO) */
/* that there's a message waiting to be printed. Copies the */
/* msg to the log file, sets the "msg waiting" semaphore, and */
/* signals the log-message-waiting Lisp interrupt. */
/* */
/************************************************************************/
LispPTR flush_pty() {
#if defined(DOS) || defined(XWINDOW)
return (NIL);
#else
int id;
struct stat sbuf;
char buf[MESSAGE_BUFFER_SIZE]; /* Buffer between pty and log file */
int size;
static int rfds;
int rval;
struct statfs fsbuf;
SETJMP(NIL);
DBPRINT(("flush_pty() called.\n"));
/* polling pty nd flush os message to log file */
#ifndef LOGINT
rfds = (1 << cons_pty);
if (select(32, &rfds, NULL, NULL, &selecttimeout) < 0) return (NIL);
if ((cons_pty >= 0) && (rfds & (1 << cons_pty)))
#else /* LOGINT */
if ((cons_pty >= 0) && ((size = read(cons_pty, buf, MESSAGE_BUFFER_SIZE - 1)) > 0))
#endif
{ /* There are messages to log in the file. */
DBPRINT(("Log msgs being printed...\n"));
close(log_id);
TIMEOUT(log_id = open(logfile, O_WRONLY | O_APPEND, 0666));
if (log_id == -1) return (NIL);
#ifndef LOGINT
size = read(cons_pty, buf, MESSAGE_BUFFER_SIZE - 1);
#endif
if (size == -1) return (NIL);
/* Check free space to avoid print System Error Mesage
to /dev/console */
TIMEOUT(rval = statfs("/tmp", &fsbuf));
if (rval != 0) return (NIL);
if (fsbuf.f_bavail <= (long)0) {
/* No Free Space */
error("osmessage error: No free space on file system (/tmp).");
return (NIL);
}
logChanged = 1; /* Note the change, for READP */
TIMEOUT(rval = write(log_id, buf, size));
if (rval == -1) {
if (errno == ENOSPC) /* == 28 on Sun, ibm */
{
/* No free space, but it's too late to avoid
print system Error Message. */
error("osmessage error: No free space on file system (/tmp).");
return (NIL);
} else {
error("osmessage error: cannot write to log file (/tmp)");
return (NIL);
}
} else {
/**
close(id);
**/
return (ATOM_T);
}
}
#endif /* XWINDOW | DOS */
}