移動
次へ 前へ
上へ 最上
参考
readatom.cのリスト
プリプロセッサによる展開前と後のreadatom.cのリスト
イフコンピュータ > IF/Prolog > マニュアル > 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 ----------------*/

続く..
IF/Prolog by Siemens
言語
English
Japanese
German
サーバー
USA
Japan
サイトマップ
索引
目次
全体目次
全体索引
印刷向き
imode
PDA
探索
document: http://www.ifcomputer.co.jp/IFProlog/Manuals/v4.1/advanced_feature/c_interface/cpredbw/exampbe/examp/home_jp.html
published 2008/11/17 update 1995/11/6 (c) 1996-2006 IF Computer Japan
IF Computer 〒113-0022 Tel 03-5814-3352 start (AT) ifcomputer.com
Customer Support 東京都文京区千駄木5-28-2   http://www.ifcomputer.co.jp
冒頭へ managed with ubiCMS