Personal tools
You are here: Home Projects LISP XLISP XLISP 0.0 Sources unpacked xlio.c
Document Actions

xlio.c

by Paul McJones last modified 2011-01-24 09:58

Click here to get the file

Size 1.2 kB - File type text/x-csrc

File contents

/* xlio - xlisp i/o routines */

#include <stdio.h>
#include "xlisp.h"

/* global variables */
int (*xlgetc)();
int xlpvals;

/* local variables */
static int prompt;
static FILE *ifp;

/* tgetc - get a character from the terminal */
static int tgetc()
{
    int ch;

    /* prompt if necessary */
    if (prompt) {
	printf("> ");
	prompt = FALSE;
    }

    /* get the character */
    if ((ch = getchar()) == '\n')
	prompt = TRUE;

    /* return the character */
    return (ch);
}

/* xltin - setup terminal input */
int xltin()
{
    /* initialize */
    prompt = TRUE;
    xlgetc = tgetc;
    xlpvals = TRUE;
}

/* fgetc - get a character from a file */
static int fgetc()
{
    int ch;

    /* get a character */
    if ((ch = getc(ifp)) <= 0) {
	xlgetc = tgetc;
	xlpvals = TRUE;
	return (tgetc());
    }

    /* return it */
    return (ch);
}

/* xlfin - setup file input */
xlfin(str)
  char *str;
{
    char fname[100];

    /* create the file name */
    strcpy(fname,str);

    /* open the input file */
    if ((ifp = fopen(fname,"r")) == NULL) {
	printf("can't open \"%s\" for input\n",fname);
	return;
    }

    /* setup input from the file */
    xlgetc = fgetc;
    xlpvals = FALSE;
}
« May 2013 »
Su Mo Tu We Th Fr Sa
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
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: