ngspice/src/frontend/parser/input.c

67 lines
1.2 KiB
C
Raw Normal View History

2000-04-27 22:03:57 +02:00
/**********
Copyright 1990 Regents of the University of California. All rights reserved.
Author: 1988 Jeffrey M. Hsu
$Id$
2000-04-27 22:03:57 +02:00
**********/
/*
* Stand-alone input routine.
*/
#include <config.h>
#include <ngspice.h>
#include <errno.h>
2000-04-27 22:03:57 +02:00
#include "fteinput.h"
#include "input.h"
#include "cpextern.h"
#include "../display.h"
2011-07-05 00:00:18 +02:00
#ifdef _MSC_VER
2011-07-05 00:03:16 +02:00
#include "BaseTsd.h" /* for SSIZE_T */
2011-07-05 00:00:18 +02:00
#define ssize_t SSIZE_T
#define read _read
#endif
/* A special 'getc' so that we can deal with ^D properly. There is no way for
* stdio to know if we have typed a ^D after some other characters, so
* don't use buffering at all
*/
int
inchar(FILE *fp)
{
2000-04-27 22:03:57 +02:00
2002-01-03 23:44:21 +01:00
#ifndef HAS_WINDOWS
2010-11-06 18:29:28 +01:00
char c;
2011-07-05 00:00:18 +02:00
ssize_t i;
if (cp_interactive && !cp_nocc) {
do {
2010-11-06 18:29:28 +01:00
i = read(fileno(fp), &c, 1);
} while (i == -1 && errno == EINTR);
if (i == 0 || c == '\004')
return (EOF);
else if (i == -1) {
perror("read");
return (EOF);
} else
return ((int) c);
} else
2002-01-03 23:44:21 +01:00
#endif
2010-11-06 18:29:28 +01:00
return (getc(fp));
}
2000-04-27 22:03:57 +02:00
int
input(FILE *fp)
2000-04-27 22:03:57 +02:00
{
REQUEST request;
RESPONSE response;
request.option = char_option;
request.fp = fp;
Input(&request, &response);
return(inchar(fp));
2000-04-27 22:03:57 +02:00
}