Move to
=> <=
Darueber Spitze
See also
readatom.cのリスト
プリプロセッサによる展開前と後のreadatom.cのリスト
IF Computer > IF/Prolog > Manuals > IF/Prolog V4.1 マニュアル > IF/Prolog Interfaces > IF/PrologからC言語へのインタフェ−ス > バックトラックするProlog述語をC言語で書く > バックトラックをし、Epilogを持つプログラム例 > プリプロセッサによる展開前と後のreadatom.cのリスト

プリプロセッサによる展開前と後の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 */ /*--------------------------------*/

#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)

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

/*-------------------------------------*/

after C preprocessor on cpred.h:

#include

char line[100+1]; FILE *fp, *fopen(); char *name; typedef struct { FILE *fp } READSTATE;

Cboot() { { int readatom (); Cpred("readatom", 2, readatom, sizeof(READSTATE) ); }; } /*-------------------------------------*/

int readatom(port, _ps) int port; OBJECT *_ps { READSTATE * state; state = (READSTATE *)_ps; { switch(port){ case 0:break; case 1: goto Label1; case -1: goto _epilog; default: return 0;};{ if(!XChk(IsString(GoalArg(1), &name), "atom expected for file name")) { return 0; } if(!XChk( (((state->fp)=fopen(name, "r")) != (FILE *)NULL), "Could not open file")){ return 0; }

EnableEpilog();

while ( readline(state->fp) ) { if( UnifyArg(2, (StrAt(line))) ) { return 1; Label1: ;} }

return 0; _epilog: if(state->fp){ fclose(state->fp); printf("file closed by epilog\n"); } } return 0; }

/* ------------- readling() is not changed ----------------*/

read on...
IF/Prolog by Siemens
Sprache
English
Japanese
German
Server
USA
Japan
Site Access
Local Index
Local Contents
Site Contents
Site Index
Printer Friendly
For imode
For PDA
Search
document: http://www.ifcomputer.co.jp/IFProlog/Manuals/v4.1/advanced_feature/c_interface/cpredbw/exampbe/examp/home_de.html
published 2008/11/17 update 1995/11/6 (c) 1996-2006 IF Computer Japan
IF Computer 5-28-2 Sendagi, Bunkyo-ku Tel +81-3-5814-3352 start (AT) ifcomputer.com
Customer Support Tokyo 113-0022 Japan   http://www.ifcomputer.com
scroll to top managed with ubiCMS