home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l217 / 2.ddi / PROGRAMS / EDITHOOK.PRO < prev    next >
Encoding:
Text File  |  1990-03-26  |  4.7 KB  |  153 lines

  1. %config "prolog.cfg"
  2. /***************************************************************************
  3.  
  4.   Testing of editor extensions with the ED_ApplicationFunction Predicate
  5.   ======================================================================
  6.  
  7. In the editor the user has a choice of nine special keys which he can
  8. define the fuunction of himself. When one of these keys are pressed the
  9. editor calls the C routine:
  10.  
  11. void ED_EditHook(
  12.     INT KeyNo,            /* from 1 to 8 depending of key */
  13.     CHAR *EditText,            /* Whole editor text */
  14.     INT Currentpos,            /* Current cursor position in text */
  15.     INT BeginBlock, INT BlockLen,    /* If <> 0; a marked block */
  16.     INT BlockMarkingMode,        /* 0 if in markingmode, 1 if not */
  17.     INT *NewCurPos,            /* If <>0; new position after return */
  18.     INT *NewBlockStart, INT *NewBlockLen, /* If <>0; new marked block */
  19.     INT *NewBlockMarkingMode,    /* 0 if in markingmode, 1 if not */
  20.     INT *DeleteFrom, INT *DeleteLen,/* If <>0; block to delete */
  21.     INT *PastePos)            /* If <>0; place  to insert paste buf */
  22. { /* Default definition */
  23.   *NewCurPos=0;
  24.   *NewBlockStart=0;
  25.   *NewBlockLen=0;
  26.   *DeleteFrom=0;
  27.   *DeleteLen=0;
  28.   *PastePos=0;
  29. }
  30.  
  31. You can only use this facility if you are linking your program to an .EXE
  32. file. If you define clauses for the ED_ApplicationFunction routine in you
  33. prolog program, the linker will uuse this instead of the default definition
  34. in the library.
  35.  
  36. This demo shows how to paste prototypes for prolog standard predicates by
  37. searching for the definition in the PROLOG.HLP file.
  38.  
  39. ***************************************************************************/
  40.  
  41.  
  42. GLOBAL PREDICATES
  43.   /* Define the predicate as a C routine */
  44.   ED_AppFunc(INTEGER,STRING,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER) 
  45.      - (i,i,i,i,i,i,o,o,o,o,o,o,o) language c as "_ED_EditHook"
  46.  
  47.  
  48. /***************************************************************************
  49.     Locate PROLOG.HLP
  50. ***************************************************************************/
  51.  
  52. DATABASE
  53.   determ filename(STRING)
  54.  
  55. PREDICATES
  56.   checkhelp
  57.  
  58. CLAUSES
  59.   checkhelp:-
  60.     syspath(Path,_),
  61.     concat(Path,"PROLOG.HLP",HelpName),
  62.     existfile(HelpName),!,
  63.     assert(filename(HelpName));
  64.     
  65.     envsymbol("path",SearchPath),
  66.     SearchFile(SearchPath,"PROLOG.HLP",HelpName),!,
  67.     assert(filename(HelpName));
  68.  
  69.     write("\nCant find: PROLOG.HLP"),
  70.     fail.
  71.  
  72.  
  73. /***************************************************************************
  74.     Search for the prototype in PROLOG.HLP
  75. ***************************************************************************/
  76.  
  77. PREDICATES
  78.   get_prototype(String,String)
  79.  
  80. CLAUSES
  81.   get_prototype(PRED,PROTO):-
  82.      filename(HelpName),
  83.      file_str(HelpName,HLP),
  84.     concat(PRED,"(",PRED_START),
  85.      searchstring(HLP,PRED_START,POS),
  86.      str_len(PRED,PL),
  87.     ptr_dword(HLP,Seg,Off),
  88.     Off1=Off+Pos+PL-1,
  89.     ptr_dword(Start,Seg,Off1),
  90.      searchchar(Start,')',P2),
  91.      substring(Start,1,P2,PROTO).
  92.  
  93.  
  94. /***************************************************************************
  95.     Return the last token in a string
  96. ***************************************************************************/
  97.  
  98. PREDICATES
  99.   get_last_tok(String,String,String)
  100.  
  101. CLAUSES
  102.   get_last_tok("",X,X):-!.
  103.   get_last_tok(STR,_,OUT):-
  104.      fronttoken(STR,TOK,REST),
  105.      get_last_tok(REST,TOK,OUT).
  106.  
  107.  
  108. /***************************************************************************
  109.     Editor extensions
  110. ***************************************************************************/
  111.  
  112. CLAUSES
  113.   % Paste prototype for prolog standard predicate
  114.   ED_AppFunc(1,TXT,CP,_,_,MM,CP,0,0,MM,0,0,CP):-
  115.     NCP=CP-1,
  116.     frontstr(NCP,TXT,FRONT,_),
  117.     get_last_tok(FRONT,"",PRED),
  118.     get_prototype(PRED,PROTO),
  119.     Pastebuffer(PROTO),!.
  120.  
  121.   % Print info of parameters and paste "Hello mum"
  122.   ED_AppFunc(2,TEXT,CP,BP,BL,MM,CP,0,0,MM,0,0,3):-
  123.     Pastebuffer(PASTEBUF),
  124.     makewindow(10,7,7,"",10,10,10,40),
  125.     frontstr(5,TEXT,FR,_),
  126.     writef("PASTEBUF: % \nTEXT: % \nCursorpos: % \nBlockstart: %\nBlockLen %\nMarking Mode %",PASTEBUF,FR,CP,BP,BL,MM), 
  127.     readchar(_),
  128.     Pastebuffer("Hello from function 2"),
  129.     removewindow,!.
  130.  
  131.   % Edit pastebuffer
  132.   ED_AppFunc(3,_,CP,BP,BL,MM,CP,BP,BL,MM,0,0,0):-
  133.     Pastebuffer(PASTEBUF),
  134.     makewindow(10,7,7,"",10,10,10,40),
  135.     edit(PASTEBUF,NEW),
  136.     Pastebuffer(NEW),
  137.     removewindow,!.
  138.  
  139.   % Default definition
  140.   ED_AppFunc(_,_,_,_,_,MM,0,0,0,MM,0,0,0):-!.
  141.  
  142.  
  143.  
  144. /***************************************************************************
  145.     Main goal
  146. ***************************************************************************/
  147.  
  148. GOAL    checkhelp,
  149.     makewindow(11,7,7,"",0,0,20,70),
  150.     edit("\nmakewindow\nTry to press Alt-F1 1\n"
  151.         ,_,"","","",11,"",1,1,1,0,_,_,1,0,1),
  152.     removewindow.
  153.