readatom.cのリスト
MINERVA superseeded IF/Prolog. Please see http://www.ifcomputer.co.jp/MINERVA for details.

We discontinued to sell IF/Prolog Dec 31. 2003. For current customers, we continue to provide professional support for IF/Prolog until Dec 31, 2008.

以下にディレクトリ$PROROOT/demos/cの中にあるreadatom.cのリストを示します。別のリストは、cpred.hの中のマクロ定義がCプリプロセッサによって展開された後のファイルを示しています。 (注意:stdio.hは重要でないので、プリプロセッサにかけていません)

/*------------------------------------------------------*/ /* filename : $PROROOT/demos/c/readatom.c */ /* demonstrates use of EPILOG: test with: */ /* go :- readatom(Filename,Atom),write(Atom),nl,!,fail. */ /*------------------------------------------------------*/ #include "cpred.h" #include #define MAXLEN 100

char line[MAXLEN+1]; /* max line length */ FILE *fp, *fopen(); char *name; typedef struct { FILE *fp } READSTATE;  /* STATE */

Cboot() { CPRED("readatom", 2, readatom, sizeof(READSTATE) ); } /*------------------------------------------------------*/ COROUTINE( readatom, READSTATE, state) /* FUNCTION */ RESUME(1, Label1); HASEPILOG; BEGIN if(!XChk(IsString(Arg(1), &name), "atom expected for file name")) { FAIL; } if(!XChk( (((state->fp)=fopen(name, "r")) != (FILE *)NULL), "Could not open file")) { FAIL; }

EnableEpilog(); printf("epilog enabled\n"); while ( readline(state->fp) ) { if( UnifyArg(2, (StrAt(line))) ) DETACH(1, Label1) }

EPILOG: printf("start of epilog\n"); if(state->fp){ fclose(state->fp); printf("file closed by epilog\n"); } END

/*------------------------------------------------------*/ int readline(fp) FILE *fp; { char c; int i = 0;

while ( (c = getc(fp)) != EOF && c != '\n' ) { if ( i < MAXLEN ) line[i++] = c; } line[i] = '\0'; if (c != EOF) return(1); else return(0); }


Up read on...