USE132.PAS 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. Procedure USE_132(p1,p2,p3:a;var rez:a); {ACCESS LIBRARY FUNCTION}
  2. {$IFDEF WIN}
  3. { Access to library (handle is P1) function with
  4. name in P2 and pass list of parameters from P3;
  5. Returns error code 1000..1020 or return parameter list from
  6. the library function
  7. ERROR CODES
  8. 1000 #CALL_PAS(76) was not called
  9. 1001 1st paramter is not number
  10. 1002 2nd paramter is not atom
  11. 1003 3 handle is less than 32, Library was not opened for access
  12. 1004 no memory 80 bytes
  13. 1005 parameters are not formed in list,
  14. possible atom instead of list
  15. 1006 function not found in library
  16. (function must be declared as FAR and EXPORT)
  17. 1008 descriptor too small (see P_max_size in RIF.PAS )
  18. 1009 too many parameters (see P_max_cnt in RIF.PAS )
  19. 1010 wrong atoms in list of atoms which must represent
  20. super long string (only non numeric atoms allowed)
  21. 1011 wromg element (tree) in parameters
  22. }
  23. Procedure ERL(code:word);
  24. var ms:string[110];
  25. pc:pchar;
  26. qq:mpd;
  27. begin
  28. pointr(p2,qq.sa);
  29. case code of
  30. 1000: ms:=' #CALL_PAS(76) was not called';
  31. 1001: ms:=' 1st paramter(handle) is not number';
  32. 1002: ms:=' 2nd paramter(function name) is not atom';
  33. 1003: ms:=' handle is less than 32, Library was not opened for access';
  34. 1004: ms:=' no memory 80 bytes';
  35. 1005: ms:=' parameters are not formed in list,possible atom instead of list';
  36. 1006: ms:=' function '+AA_Str(qq.sad^.name)+' not found in library ';
  37. 1008: ms:=' descriptor too small (see P_max_size in RIF.PAS )';
  38. 1009: ms:=' too many parameters (see P_max_cnt in RIF.PAS )';
  39. 1010: ms:=' wrong atoms in list of atoms which must represent super long string (only non numeric atoms allowed)';
  40. 1011: ms:=' wromg element (tree) in parameters';
  41. end;
  42. GetMem(pc,120);
  43. StrPCopy(pc,ms);
  44. MessageBox(0,pc,'Internal error in #CALL_PAS(132..) call',16);
  45. writeln(out,pc);
  46. pout(p1);
  47. pout(p2);
  48. pout(p3);
  49. FreeMem(pc,120);
  50. rez:=Long_to_atom(code);
  51. end;
  52. var handle:Thandle; { library handle }
  53. pch:pchar; { function name }
  54. type tfun=procedure(AP1,AP2:Pointer);
  55. var afun:tfun; afar:Tfarproc; {intermed. for function call }
  56. var PP,PLIST:PTR; AP1,AP2:Pointer; A1,A2:a; pc:pchar;
  57. mode:word; er,len,fragnum,len1,k:integer;
  58. {$ENDIF}
  59. begin
  60. rez:=NULL;
  61. {$IFDEF WIN}
  62. if not done76 then begin ERL(1000);exit;end;
  63. if not (PLNUM(p1,IM[1])) then begin ERL(1001);exit;end;
  64. handle:=IM[1];
  65. GetMem(pch,80);
  66. if pch=nil then begin ERL(1004);exit;end;;
  67. if not PLSTR(P2,STR,L,true,SV1) then begin ERL(1002);exit;end;;
  68. StrPcopy(pch,SV1);
  69. if handle<32 then begin ERL(1003);exit;end;
  70. if handle>=32 then begin
  71. afar:=GetProcAddress(handle,pch);
  72. afun:=Tfun(afar);
  73. if @afun=nil then begin ERL(1006);exit;end
  74. else
  75. begin
  76. {================}
  77. AP1:=GlobalLock(GP1);
  78. AP2:=GlobalLock(GP2);
  79. P_clear(AP1); { Rigal->DLL parameters }
  80. P_clear(AP2); { DLL->Rigal parameters }
  81. if P3<>NULL then begin (*0*)
  82. Pointr(P3,X.SA);
  83. if X.SMLD^.DTYPE<>LISTMAIN then
  84. begin ERL(1005);exit;end;
  85. First(p3,PP); { Loop along the list of parameters }
  86. while PP.NEL<>0 do
  87. begin (*1*)
  88. if PP.CEL=NULL then
  89. begin
  90. er:=p_Add_NULL(ap1);
  91. if er<>0 then begin ERL(1007+er);exit;end; { ERROR!}
  92. end
  93. else
  94. begin (*2*)
  95. POINTR(pp.cel,x.sa);
  96. if x.smld^.dtype=listmain then begin (*3*)
  97. First(pp.cel,PLIST);
  98. fragnum:=1;
  99. while Plist.NEL<>0 do begin (*4*)
  100. if plist.CEL<>0 then (* Added 23-NOV-92 *)
  101. begin (*5*)
  102. if PLNUM(plist.cel,IM[1]) then begin
  103. system.Str(IM[1],SV1);
  104. { StrPCopy(STR,SV1);}
  105. L:=Length(SV1);
  106. if fragnum=1 then er:=p_Add_pchar(ap1,@SV1[1],L)
  107. else er:=p_App_pchar(ap1,@SV1[1],L);
  108. Inc(fragnum);
  109. if er<>0 then begin ERL(1007+er);exit;end; { ERROR!}
  110. end else
  111. if PLSTR(plist.cel,STR,L,false,SV1) then
  112. begin
  113. if fragnum=1 then er:=p_Add_pchar(ap1,@STR,L)
  114. else er:=p_App_pchar(ap1,@STR,L);
  115. Inc(fragnum);
  116. if er<>0 then begin ERL(1007+er);exit;end; { ERROR!}
  117. end
  118. else begin ERL(1010);exit;end; {ERROR}
  119. end; (*5*)
  120. Next(PLIST);
  121. end; (*4*)
  122. end (*3*)
  123. else if PLSTR(PP.CEL,STR,L,false,SV1) then
  124. begin
  125. er:=p_Add_pchar(ap1,@STR,L); { Atom of length 0 is also possible}
  126. if er<>0 then begin ERL(1007+er);exit;end; { ERROR!}
  127. end
  128. else if PLNUM(PP.cel,IM[1])
  129. then begin
  130. er:=p_Add_plong(ap1,IM[1]);
  131. if er<>0 then begin ERL(1007+er);exit;end; { ERROR!}
  132. end
  133. else begin ERL(1011);exit;end; { ERROR !}
  134. ;
  135. end; (*2*)
  136. Next(PP);
  137. end; (*1*)
  138. end; (* 0 *)
  139. afun(AP1,AP2); { LIBRARY PROCEDURE NAME }
  140. k:=1;
  141. repeat { Loop along the result parametres }
  142. a1:=NULL;
  143. mode:=P_GetParm(AP2,k,LEN,pc,IM[1]);
  144. { if mode=1 then 5th parameter is used,
  145. otherwise - 3rd and 4th }
  146. case mode of
  147. 0: exit; { End of loop (normal) }
  148. 1: MKNUMB(IM[1],a1);
  149. 2: begin { create atom } (*2*)
  150. { Value of pc is returned }
  151. { CASE WITH SINGLE ATOM }
  152. if (len<>0)and(len<=80) then begin (*3*)
  153. ID := pc[0] in LETTER;
  154. For i:=0 to len-1 do
  155. ID := ID AND ( pc[i] IN SYMBOLS ) ;
  156. PUTATM(pc[0],len,ATM); (* makes A-Address *)
  157. GETS1(a1,x.SA); (* makes S-Address *)
  158. with x.sad^ do begin (* fills descriptor *)
  159. if ID then dtype:=IDATOM else dtype:=ATOM;
  160. NAME:=ATM;
  161. end;
  162. end (*3*)
  163. else
  164. { CASE WITH LARGE "ATOM" }
  165. if (len>80) then begin (*3*)
  166. a1:=Split_Pchar(pc,len);
  167. end (*3*)
  168. else
  169. a1:=NULL; { SAME as 'NULL' protocol value }
  170. end; (*2*)
  171. 4: a1:=NULL; { SAME as string of length 0 }
  172. end;
  173. LCONC(rez,a1);
  174. Inc(k);
  175. until false;
  176. {===============}
  177. end;
  178. end;
  179. Freemem(pch,80);
  180. {$ENDIF}
  181. end;