home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
s
/
seyon197.tz
/
seyon197
/
seyon
/
SeGeneric.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-02-19
|
4KB
|
209 lines
/*
* This file is part of the Seyon, Copyright (c) 1992-1993 by Muhammad M.
* Saggaf. All rights reserved.
*
* See the file COPYING (1-COPYING) or the manual page seyon(1) for a full
* statement of rights and permissions for this program.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <setjmp.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include <ctype.h>
#include <math.h>
#include "SeDecl.h"
void
ReadCommentedFile(fp, line)
FILE *fp;
char *line[];
{
char buffer[REG_BUF + 1],
*bufPtr,
*ptr;
int i;
for (i = 0; i < MAX_ENT && fgets(buffer, REG_BUF, fp) != NULL;) {
/*Strip newline character from end of string*/
buffer[strlen(buffer) - 1] = '\0';
/*Remove leading and trailing spaces*/
bufPtr = SSpc(buffer);
/*Ignore this line if it is empty or starts with a comment*/
if (bufPtr[0] == '\0' || bufPtr[0] == '#')
continue;
/*Ignore trailing comments*/
if ((ptr = strrchr(bufPtr, '#')) != NULL)
*ptr = '\0';
line[i++] = XtNewString(bufPtr);
}
line[i] = NULL;
}
void
FreeList(listArr)
XtPointer listArr[];
{
int i;
for (i = 0; listArr[i]; i++)
XtFree(listArr[i]);
listArr[0] = NULL;
}
int
ConvertStringToIntArray(str, intArr)
char *str;
int intArr[];
{
char num[TIN_BUF], *numPtr;
int i;
intArr[0] = 0;
if (!str) return 0;
for (i = 0;;) {
while (isspace(*str)) str++;
if (!*str) return 0;
for (numPtr = num; *str && !isspace(*str); *numPtr++ = *str++);
*numPtr = '\0';
intArr[i] = atoi(num);
intArr[++i] = 0;
}
}
jmp_buf read_env;
void
alrm(dummy)
int dummy;
{
longjmp(read_env, 1);
}
/*
* trminp() is used as a single-character terminal input routine.
*/
/* This routine needs a lot of work. In particular, the old siganl handler
for SIGALARM has to be saved and then restored, similary the time remaining
until the next alarm goes off if an alarm is already installed. */
int
trminp(fd, seconds)
int fd,
seconds;
{
/*BUFSIZ is defined in stdio.h*/
static char rxbuf[BUFSIZ],
*p;
static int count = 0;
if (count > 0) {
count--;
return (*p++ & 0xff);
}
if (setjmp(read_env) != 0) {
alarm(0);
return -2;
}
if (seconds > 0) {
signal(SIGALRM, alrm);
alarm((unsigned)seconds);
}
if ((count = read(fd, p = rxbuf, BUFSIZ)) < 0) {
if (errno != EINTR) {
se_perror("character read");
return -3;
}
return -2;
}
if (seconds > 0)
alarm(0);
count--;
return (*p++ & 0xff);
}
int
termInpStr(fd, buf)
int fd;
char *buf;
{
int count;
/* BUFSIZ is defined in stdio.h */
if ((count = read(fd, buf, BUFSIZ)) < 0) {
se_perror("character read");
return -1;
}
return count;
}
/*
* usleep for systems that do not have it
*/
#ifndef HAVE_USLEEP
void
usleep(usec)
unsigned long usec
{
#ifdef HAVE_SELECT
/*
* Orest Zborowski originally wrote this
*/
struct timeval timeout;
timeout.tv_sec = usec / 1000000;
timeout.tv_usec = usec - 1000000 * timeout.tv_sec;
select(1, NULL, NULL, NULL, &timeout);
#else
/*
* This busy-waiting, normally a bad idea on a multi-tasking system, is used
* because sleep(1) is way too much of a delay.
*/
int i;
for (i = 0; i < usec; i++);
#endif
}
#endif
#ifndef HAVE_DUP2 /* For those that do not have dup2()... */
int
dup2(oldfd, newfd)
int oldfd,
newfd;
{
if (fcntl(oldfd, F_GETFL, 0) == -1) /* Valid file descriptor? */
return (-1); /* No, return an error. */
close(newfd); /* Ensure newfd is closed */
return (fcntl(oldfd, F_DUPFD, newfd)); /* Dup oldfd into newfd */
}
#endif /* HAVE_DUP2 Thanks to Bill Allie CIS: 76703,2061 */