home *** CD-ROM | disk | FTP | other *** search
- %config "prolog.cfg"
- /***************************************************************************
-
- Testing of editor extensions with the ED_ApplicationFunction Predicate
- ======================================================================
-
- In the editor the user has a choice of nine special keys which he can
- define the fuunction of himself. When one of these keys are pressed the
- editor calls the C routine:
-
- void ED_EditHook(
- INT KeyNo, /* from 1 to 8 depending of key */
- CHAR *EditText, /* Whole editor text */
- INT Currentpos, /* Current cursor position in text */
- INT BeginBlock, INT BlockLen, /* If <> 0; a marked block */
- INT BlockMarkingMode, /* 0 if in markingmode, 1 if not */
- INT *NewCurPos, /* If <>0; new position after return */
- INT *NewBlockStart, INT *NewBlockLen, /* If <>0; new marked block */
- INT *NewBlockMarkingMode, /* 0 if in markingmode, 1 if not */
- INT *DeleteFrom, INT *DeleteLen,/* If <>0; block to delete */
- INT *PastePos) /* If <>0; place to insert paste buf */
- { /* Default definition */
- *NewCurPos=0;
- *NewBlockStart=0;
- *NewBlockLen=0;
- *DeleteFrom=0;
- *DeleteLen=0;
- *PastePos=0;
- }
-
- You can only use this facility if you are linking your program to an .EXE
- file. If you define clauses for the ED_ApplicationFunction routine in you
- prolog program, the linker will uuse this instead of the default definition
- in the library.
-
- This demo shows how to paste prototypes for prolog standard predicates by
- searching for the definition in the PROLOG.HLP file.
-
- ***************************************************************************/
-
-
- GLOBAL PREDICATES
- /* Define the predicate as a C routine */
- ED_AppFunc(INTEGER,STRING,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER)
- - (i,i,i,i,i,i,o,o,o,o,o,o,o) language c as "_ED_EditHook"
-
-
- /***************************************************************************
- Locate PROLOG.HLP
- ***************************************************************************/
-
- DATABASE
- determ filename(STRING)
-
- PREDICATES
- checkhelp
-
- CLAUSES
- checkhelp:-
- syspath(Path,_),
- concat(Path,"PROLOG.HLP",HelpName),
- existfile(HelpName),!,
- assert(filename(HelpName));
-
- envsymbol("path",SearchPath),
- SearchFile(SearchPath,"PROLOG.HLP",HelpName),!,
- assert(filename(HelpName));
-
- write("\nCant find: PROLOG.HLP"),
- fail.
-
-
- /***************************************************************************
- Search for the prototype in PROLOG.HLP
- ***************************************************************************/
-
- PREDICATES
- get_prototype(String,String)
-
- CLAUSES
- get_prototype(PRED,PROTO):-
- filename(HelpName),
- file_str(HelpName,HLP),
- concat(PRED,"(",PRED_START),
- searchstring(HLP,PRED_START,POS),
- str_len(PRED,PL),
- ptr_dword(HLP,Seg,Off),
- Off1=Off+Pos+PL-1,
- ptr_dword(Start,Seg,Off1),
- searchchar(Start,')',P2),
- substring(Start,1,P2,PROTO).
-
-
- /***************************************************************************
- Return the last token in a string
- ***************************************************************************/
-
- PREDICATES
- get_last_tok(String,String,String)
-
- CLAUSES
- get_last_tok("",X,X):-!.
- get_last_tok(STR,_,OUT):-
- fronttoken(STR,TOK,REST),
- get_last_tok(REST,TOK,OUT).
-
-
- /***************************************************************************
- Editor extensions
- ***************************************************************************/
-
- CLAUSES
- % Paste prototype for prolog standard predicate
- ED_AppFunc(1,TXT,CP,_,_,MM,CP,0,0,MM,0,0,CP):-
- NCP=CP-1,
- frontstr(NCP,TXT,FRONT,_),
- get_last_tok(FRONT,"",PRED),
- get_prototype(PRED,PROTO),
- Pastebuffer(PROTO),!.
-
- % Print info of parameters and paste "Hello mum"
- ED_AppFunc(2,TEXT,CP,BP,BL,MM,CP,0,0,MM,0,0,3):-
- Pastebuffer(PASTEBUF),
- makewindow(10,7,7,"",10,10,10,40),
- frontstr(5,TEXT,FR,_),
- writef("PASTEBUF: % \nTEXT: % \nCursorpos: % \nBlockstart: %\nBlockLen %\nMarking Mode %",PASTEBUF,FR,CP,BP,BL,MM),
- readchar(_),
- Pastebuffer("Hello from function 2"),
- removewindow,!.
-
- % Edit pastebuffer
- ED_AppFunc(3,_,CP,BP,BL,MM,CP,BP,BL,MM,0,0,0):-
- Pastebuffer(PASTEBUF),
- makewindow(10,7,7,"",10,10,10,40),
- edit(PASTEBUF,NEW),
- Pastebuffer(NEW),
- removewindow,!.
-
- % Default definition
- ED_AppFunc(_,_,_,_,_,MM,0,0,0,MM,0,0,0):-!.
-
-
-
- /***************************************************************************
- Main goal
- ***************************************************************************/
-
- GOAL checkhelp,
- makewindow(11,7,7,"",0,0,20,70),
- edit("\nmakewindow\nTry to press Alt-F1 1\n"
- ,_,"","","",11,"",1,1,1,0,_,_,1,0,1),
- removewindow.
-