USEDLL.PAS 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. {$IFDEF WIN}
  2. const done76:boolean=false;
  3. { controlls if global memory blocks GP1 and GP2 are
  4. already allocated by #CALL_PAS(76) }
  5. var GP1,GP2:Word; { handle to global memory block }
  6. {$ENDIF}
  7. {===========================================================}
  8. Procedure USE_104(p1,p2,p3:a;var rez:a); { EXECUTE A FILE}
  9. { EXECUTE A FILE WITH (default) return message wm_user+105}
  10. begin
  11. rez:=NULL;
  12. {$IFDEF WIN}
  13. if PLSTR(P1,STR,L,true,SV1) then begin
  14. if not PLNUM(p2,IM[2]) then IM[2]:=105;
  15. rez:=long_to_atom(Wexec(@STR,sw_normal,IM[2]));
  16. end;
  17. {$ENDIF}
  18. end;
  19. {****************************************}
  20. Procedure USE_109(p1,p2,p3:a;var rez:a); { CUT A FILE}
  21. var f1,f2:text;s:string;i:integer;
  22. begin
  23. if PLSTR(P1,STR,L,true,SV1) then begin
  24. if PLSTR(P2,STR,L,true,SV2) then begin
  25. Assign(f1,SV1);Reset(f1);
  26. Assign(f2,SV2);Rewrite(f2);
  27. while not(eof(f1)) do begin
  28. readln(f1,s);
  29. i:=pos(';',s);
  30. if i=0 then writeln(f2,s)
  31. else if i<>1 then writeln(f2,copy(s,1,i-1));
  32. end;
  33. Close(f1);Close(f2);
  34. end;end;
  35. end;
  36. {===========================================================}
  37. Procedure USE_106(p1,p2,p3:a;var rez:a);
  38. { EXECUTE A FILE WITH (default) return message wm_user+104}
  39. begin
  40. rez:=NULL;
  41. {$IFDEF WIN}
  42. if PLSTR(P1,STR,L,true,SV1) then begin
  43. if not PLNUM(p2,IM[2]) then IM[2]:=104;
  44. rez:=long_to_atom(Wexec(@STR,sw_normal,IM[2]));
  45. end;
  46. {$ENDIF}
  47. end;
  48. {===========================================================}
  49. Procedure USE_107(p1,p2,p3:a;var rez:a); { EXECUTE A BATCH file}
  50. begin
  51. rez:=NULL;
  52. {$IFDEF WIN}
  53. if PLSTR(P1,STR,L,true,SV1) then begin
  54. rez:=long_to_atom(Winexec(@STR,sw_normal));
  55. end;
  56. {$ENDIF}
  57. end;
  58. Procedure USE_101(p1,p2,p3:a;var rez:a); {LOAD LIBRARY}
  59. { Loads DLL Library, is unsuccesful returns NULL, else returns
  60. library handle; handle is wrong if it is less than 32 }
  61. { handle return codes are:
  62. (0) no memory
  63. (2) File is absent and the dialogue with
  64. request to find it was unsuccessful
  65. (5) attempt to link task
  66. (6) multiple data segments
  67. (10) invalid Windows version
  68. (11) invalid EXE file
  69. (12) OS/2 app
  70. (13) DOS 4.0 app
  71. (14) Invalid EXE type
  72. (15) not protect mode
  73. }
  74. {$IFDEF WIN} var pc:pchar; { place for library name }
  75. handle:Thandle; { handle (word) }
  76. {$ENDIF}
  77. begin
  78. rez:=NULL;
  79. {$IFDEF WIN}
  80. GetMem(pc,80);
  81. if pc=nil then begin rez:=Long_to_atom(-1);exit;end;
  82. { no memory 80 bytes }
  83. if not PLSTR(P1,STR,L,true,SV1) then begin
  84. rez:=Long_to_atom(-2);exit;end; { wrong parameter }
  85. StrPcopy(pc,SV1);
  86. handle:=LoadLibrary(pc);
  87. rez:=Long_to_atom(handle);
  88. Freemem(pc,80);
  89. {$ENDIF}
  90. end;
  91. {=================================================================}
  92. {$IFDEF win}
  93. Function Split_Pchar(pc:Pchar;len:integer):a;
  94. { The function splits one big PCHAR array "pc" of
  95. length "len" to many atoms, cancatenated in list }
  96. { here the atoms never can be used as identifiers,
  97. so the are not checked for being identifiers }
  98. var A1:A;
  99. A2:a;
  100. c_pos { current position in "pc" }
  101. :integer;
  102. begin
  103. A1:=NULL;
  104. c_pos:=0;
  105. while c_pos<len do
  106. begin (*4*)
  107. { THE FIRST PARTS OF LARGE "ATOM" }
  108. if len-c_pos>80 then begin (*5*)
  109. PUTATM(pc[c_pos],80,ATM);
  110. Gets1(a2,x.sa);
  111. with x.sad^ do begin dtype:=ATOM;Name:=ATM;end;
  112. c_pos:=c_pos+80;
  113. end (*5*)
  114. else begin (*5*)
  115. { THE ONE LAST PART OF LARGE "ATOM" }
  116. PUTATM(pc[c_pos],len-c_pos,aTM);
  117. Gets1(a2,x.sa);
  118. with x.sad^ do begin dtype:=ATOM;Name:=ATM;end;
  119. c_pos:=len;
  120. end; (*5*)
  121. LCONC(a1,a2);
  122. end; (*4*)
  123. Split_Pchar:=a1;
  124. end;
  125. {$ENDIF}
  126. Procedure USE_102(p1,p2,p3:a;var rez:a); {ACCESS LIBRARY FUNTION}
  127. {$IFDEF WIN}
  128. { Access to library (handle is P1) function with
  129. name in P2 and pass list of parameters from P3;
  130. Returns error code 1000..1020 or return parameter list from
  131. the library function
  132. ERROR CODES
  133. 1000 #CALL_PAS(76) was not called
  134. 1001 1st paramter is not number
  135. 1002 2nd paramter is not atom
  136. 1003 3 handle is less than 32, Library was not opened for access
  137. 1004 no memory 80 bytes
  138. 1005 parameters are not formed in list,
  139. possible atom instead of list
  140. 1006 function not found in library
  141. (function must be declared as FAR and EXPORT)
  142. 1008 descriptor too small (see P_max_size in RIF.PAS )
  143. 1009 too many parameters (see P_max_cnt in RIF.PAS )
  144. 1010 wrong atoms in list of atoms which must represent
  145. super long string (only non numeric atoms allowed)
  146. 1011 wromg element (tree) in parameters
  147. }
  148. Procedure ERL(code:word);
  149. var ms:string[110];pc:pchar;
  150. begin
  151. case code of
  152. 1000: ms:=' #CALL_PAS(76) was not called';
  153. 1001: ms:=' 1st paramter(handle) is not number';
  154. 1002: ms:=' 2nd paramter(function name) is not atom';
  155. 1003: ms:=' handle is less than 32, Library was not opened for access';
  156. 1004: ms:=' no memory 80 bytes';
  157. 1005: ms:=' parameters are not formed in list,possible atom instead of list';
  158. 1006: ms:=' function not found in library ';
  159. 1008: ms:=' descriptor too small (see P_max_size in RIF.PAS )';
  160. 1009: ms:=' too many parameters (see P_max_cnt in RIF.PAS )';
  161. 1010: ms:=' wrong atoms in list of atoms which must represent super long string (only non numeric atoms allowed)';
  162. 1011: ms:=' wromg element (tree) in parameters';
  163. end;
  164. GetMem(pc,120);
  165. StrPCopy(pc,ms);
  166. MessageBox(0,pc,'Internal error in #CALL_PAS(102..) call',16);
  167. writeln(out,pc);
  168. pout(p1);
  169. pout(p2);
  170. pout(p3);
  171. FreeMem(pc,120);
  172. rez:=Long_to_atom(code);
  173. end;
  174. var handle:Thandle; { library handle }
  175. pch:pchar; { function name }
  176. {$IFDEF OLDVER}
  177. type tfun=procedure(AP1,AP2:Pointer);
  178. {$ENDIF}
  179. type tfun=procedure(FUNNAME:Pchar;AP1,AP2:Pointer);
  180. var afun:tfun; afar:Tfarproc; {intermed. for function call }
  181. var PP,PLIST:PTR; AP1,AP2:Pointer; A1,A2:a; pc:pchar;
  182. mode:word; er,len,fragnum,len1,k:integer;
  183. {$ENDIF}
  184. begin
  185. rez:=NULL;
  186. {$IFDEF WIN}
  187. if not done76 then begin ERL(1000);exit;end;
  188. if not (PLNUM(p1,IM[1])) then begin ERL(1001);exit;end;
  189. handle:=IM[1];
  190. GetMem(pch,80);
  191. if pch=nil then begin ERL(1004);exit;end;;
  192. if not PLSTR(P2,STR,L,true,SV1) then begin ERL(1002);exit;end;;
  193. StrPcopy(pch,SV1);
  194. if handle<32 then begin ERL(1003);exit;end;
  195. if handle>=32 then begin
  196. afar:=GetProcAddress(handle,pchar(51){'fun_disp'});
  197. afun:=Tfun(afar);
  198. {$IFDEF OLDVER}
  199. afar:=GetProcAddress(handle,pch);
  200. afun:=Tfun(afar);
  201. {$ENDIF}
  202. if @afun=nil then begin ERL(1006);exit;end
  203. else
  204. begin
  205. {================}
  206. AP1:=GlobalLock(GP1);
  207. AP2:=GlobalLock(GP2);
  208. P_clear(AP1); { Rigal->DLL parameters }
  209. P_clear(AP2); { DLL->Rigal parameters }
  210. if P3<>NULL then begin (*0*)
  211. Pointr(P3,X.SA);
  212. if X.SMLD^.DTYPE<>LISTMAIN then
  213. begin ERL(1005);exit;end;
  214. First(p3,PP); { Loop along the list of parameters }
  215. while PP.NEL<>0 do
  216. begin (*1*)
  217. if PP.CEL=NULL then
  218. begin
  219. er:=p_Add_NULL(ap1);
  220. if er<>0 then begin ERL(1007+er);exit;end; { ERROR!}
  221. end
  222. else
  223. begin (*2*)
  224. POINTR(pp.cel,x.sa);
  225. if x.smld^.dtype=listmain then begin (*3*)
  226. First(pp.cel,PLIST);
  227. fragnum:=1;
  228. while Plist.NEL<>0 do begin (*4*)
  229. if plist.CEL<>0 then (* Added 23-NOV-92 *)
  230. begin (*5*)
  231. if PLNUM(plist.cel,IM[1]) then begin
  232. system.Str(IM[1],SV1);
  233. { StrPCopy(STR,SV1);}
  234. L:=Length(SV1);
  235. if fragnum=1 then er:=p_Add_pchar(ap1,@SV1[1],L)
  236. else er:=p_App_pchar(ap1,@SV1[1],L);
  237. Inc(fragnum);
  238. if er<>0 then begin ERL(1007+er);exit;end; { ERROR!}
  239. end else
  240. if PLSTR(plist.cel,STR,L,false,SV1) then
  241. begin
  242. if fragnum=1 then er:=p_Add_pchar(ap1,@STR,L)
  243. else er:=p_App_pchar(ap1,@STR,L);
  244. Inc(fragnum);
  245. if er<>0 then begin ERL(1007+er);exit;end; { ERROR!}
  246. end
  247. else begin ERL(1010);exit;end; {ERROR}
  248. end; (*5*)
  249. Next(PLIST);
  250. end; (*4*)
  251. end (*3*)
  252. else if PLSTR(PP.CEL,STR,L,false,SV1) then
  253. begin
  254. er:=p_Add_pchar(ap1,@STR,L); { Atom of length 0 is also possible}
  255. if er<>0 then begin ERL(1007+er);exit;end; { ERROR!}
  256. end
  257. else if PLNUM(PP.cel,IM[1])
  258. then begin
  259. er:=p_Add_plong(ap1,IM[1]);
  260. if er<>0 then begin ERL(1007+er);exit;end; { ERROR!}
  261. end
  262. else begin ERL(1011);exit;end; { ERROR !}
  263. ;
  264. end; (*2*)
  265. Next(PP);
  266. end; (*1*)
  267. end; (* 0 *)
  268. afun(pch,AP1,AP2); { LIBRARY PROCEDURE NAME }
  269. k:=1;
  270. repeat { Loop along the result parametres }
  271. a1:=NULL;
  272. mode:=P_GetParm(AP2,k,LEN,pc,IM[1]);
  273. { if mode=1 then 5th parameter is used,
  274. otherwise - 3rd and 4th }
  275. case mode of
  276. 0: exit; { End of loop (normal) }
  277. 1: MKNUMB(IM[1],a1);
  278. 2: begin { create atom } (*2*)
  279. { Value of pc is returned }
  280. { CASE WITH SINGLE ATOM }
  281. if (len<>0)and(len<=80) then begin (*3*)
  282. ID := pc[0] in LETTER;
  283. For i:=0 to len-1 do
  284. ID := ID AND ( pc[i] IN SYMBOLS ) ;
  285. PUTATM(pc[0],len,ATM); (* makes A-Address *)
  286. GETS1(a1,x.SA); (* makes S-Address *)
  287. with x.sad^ do begin (* fills descriptor *)
  288. if ID then dtype:=IDATOM else dtype:=ATOM;
  289. NAME:=ATM;
  290. end;
  291. end (*3*)
  292. else
  293. { CASE WITH LARGE "ATOM" }
  294. if (len>80) then begin (*3*)
  295. a1:=Split_Pchar(pc,len);
  296. end (*3*)
  297. else
  298. a1:=NULL; { SAME as 'NULL' protocol value }
  299. end; (*2*)
  300. 4: a1:=NULL; { SAME as string of length 0 }
  301. end;
  302. LCONC(rez,a1);
  303. Inc(k);
  304. until false;
  305. {===============}
  306. end;
  307. end;
  308. Freemem(pch,80);
  309. {$ENDIF}
  310. end;
  311. Procedure USE_103(p1,p2,p3:a;var rez:a); {LOAD LIBRARY}
  312. begin
  313. {$IFDEF WIN}
  314. IF not PLNUM(p1,IM[1]) then Exit;
  315. if IM[1]>=32 then FreeLibrary(Im[1]);
  316. {$ENDIF}
  317. end;
  318. Procedure USE_76(p1,p2,p3:a;var rez:a); {CREATE P1P2}
  319. { Allocates piece of global memory }
  320. {If successful , returns 1st argument,
  321. Utherwise returns NULL }
  322. begin
  323. {$IFDEF WIN}
  324. rez:=0;
  325. done76:=true;
  326. rez:=p1;
  327. GP1:=GlobalAlloc(gmem_moveable,sizeof(pmain_type));
  328. if GP1=0 then rez:=0;
  329. GP2:=GlobalAlloc(gmem_moveable,sizeof(pmain_type));
  330. if GP2=0 then rez:=0;
  331. {$ENDIF}
  332. end;
  333. Procedure USE_117(p1,p2,p3:a;var rez:a);
  334. { Calls LIBRARY procedure FARDLL from
  335. Dynamic Link Library
  336. Returns list of result parameters
  337. or NULL if call was unsuccessful
  338. String of length 0 is accepted as NULL
  339. }
  340. {$IFDEF DLL}
  341. var PP,PLIST:PTR; AP1,AP2:Pointer; A1,A2:a; pc:pchar;
  342. mode:word; er,len,fragnum,len1,k:integer;
  343. {$ENDIF}
  344. begin
  345. Rez:=0;
  346. {$IFDEF DLL}
  347. AP1:=GlobalLock(GP1);
  348. AP2:=GlobalLock(GP2);
  349. P_clear(AP1); { Rigal->DLL parameters }
  350. P_clear(AP2); { DLL->Rigal parameters }
  351. First(p1,PP); { Loop along the list of parameters }
  352. while PP.NEL<>0 do
  353. begin (*1*)
  354. if PP.CEL=NULL then
  355. begin
  356. er:=p_Add_NULL(ap1);
  357. if er<>0 then Exit; { ERROR!}
  358. end
  359. else
  360. begin (*2*)
  361. POINTR(pp.cel,x.sa);
  362. if x.smld^.dtype=listmain then begin (*3*)
  363. First(pp.cel,PLIST);
  364. fragnum:=1;
  365. while Plist.NEL<>0 do begin (*4*)
  366. if plist.CEL<>0 then (* Added 23-NOV-92 *)
  367. begin (*5*)
  368. if PLSTR(plist.cel,STR,L,false,SV1) then
  369. begin
  370. if fragnum=1 then er:=p_Add_pchar(ap1,@STR,L)
  371. else er:=p_App_pchar(ap1,@STR,L);
  372. Inc(fragnum);
  373. if er<>0 then Exit; { ERROR!}
  374. end
  375. else EXIT; {ERROR}
  376. end; (*5*)
  377. Next(PLIST);
  378. end; (*4*)
  379. end (*3*)
  380. else if PLSTR(PP.CEL,STR,L,false,SV1) then
  381. begin
  382. er:=p_Add_pchar(ap1,@STR,L); { Atom of length 0 is also possible}
  383. if er<>0 then Exit; { ERROR!}
  384. end
  385. else if PLNUM(PP.cel,IM[1])
  386. then begin
  387. er:=p_Add_plong(ap1,IM[1]);
  388. if er<>0 then Exit; { ERROR!}
  389. end
  390. else Exit { ERROR !}
  391. ;
  392. end; (*2*)
  393. Next(PP);
  394. end; (*1*)
  395. RFFARDLL(AP1,AP2); { LIBRARY PROCEDURE NAME }
  396. k:=1;
  397. repeat { Loop along the result parametres }
  398. a1:=NULL;
  399. mode:=P_GetParm(AP2,k,LEN,pc,IM[1]);
  400. { if mode=1 then 5th parameter is used,
  401. otherwise - 3rd and 4th }
  402. case mode of
  403. 0: exit; { End of loop (normal) }
  404. 1: MKNUMB(IM[1],a1);
  405. 2: begin { create atom } (*2*)
  406. { Value of pc is returned }
  407. { CASE WITH SINGLE ATOM }
  408. if (len<>0)and(len<=80) then begin (*3*)
  409. ID := pc[0] in LETTER;
  410. For i:=0 to len-1 do
  411. ID := ID AND ( pc[i] IN SYMBOLS ) ;
  412. PUTATM(pc[0],len,ATM); (* makes A-Address *)
  413. GETS1(a1,x.SA); (* makes S-Address *)
  414. with x.sad^ do begin (* fills descriptor *)
  415. if ID then dtype:=IDATOM else dtype:=ATOM;
  416. NAME:=ATM;
  417. end;
  418. end (*3*)
  419. else
  420. { CASE WITH LARGE "ATOM" }
  421. if (len>80) then begin (*3*)
  422. a1:=Split_Pchar(pc,len);
  423. end (*3*)
  424. else
  425. a1:=NULL; { SAME as 'NULL' protocol value }
  426. end; (*2*)
  427. 4: a1:=NULL; { SAME as string of length 0 }
  428. end;
  429. LCONC(rez,a1);
  430. Inc(k);
  431. until false;
  432. {$ENDIF}
  433. end;
  434. Procedure USE_118(p1,p2,p3:a;var rez:a);
  435. { Calls LIBRARY procedure FARDLL from
  436. Dynamic Link Library
  437. Returns list of result parameters
  438. or NULL if call was unsuccessful
  439. String of length 0 is accepted as NULL
  440. }
  441. {$IFDEF DLL}
  442. var PP,PLIST:PTR; AP1,AP2:Pointer; A1,A2:a; pc:pchar;
  443. mode:word; er,len,fragnum,len1,k:integer;
  444. {$ENDIF}
  445. begin
  446. Rez:=0;
  447. {$IFDEF DLL}
  448. AP1:=GlobalLock(GP1);
  449. AP2:=GlobalLock(GP2);
  450. P_clear(AP1); { Rigal->DLL parameters }
  451. P_clear(AP2); { DLL->Rigal parameters }
  452. First(p1,PP); { Loop along the list of parameters }
  453. while PP.NEL<>0 do
  454. begin (*1*)
  455. if PP.CEL=NULL then
  456. begin
  457. er:=p_Add_NULL(ap1);
  458. if er<>0 then Exit; { ERROR!}
  459. end
  460. else
  461. begin (*2*)
  462. POINTR(pp.cel,x.sa);
  463. if x.smld^.dtype=listmain then begin (*3*)
  464. First(pp.cel,PLIST);
  465. fragnum:=1;
  466. while Plist.NEL<>0 do begin (*4*)
  467. if plist.CEL<>0 then (* Added 23-NOV-92 *)
  468. begin (*5*)
  469. if PLSTR(plist.cel,STR,L,false,SV1) then
  470. begin
  471. if fragnum=1 then er:=p_Add_pchar(ap1,@STR,L)
  472. else er:=p_App_pchar(ap1,@STR,L);
  473. Inc(fragnum);
  474. if er<>0 then Exit; { ERROR!}
  475. end
  476. else EXIT; {ERROR}
  477. end; (*5*)
  478. Next(PLIST);
  479. end; (*4*)
  480. end (*3*)
  481. else if PLSTR(PP.CEL,STR,L,false,SV1) then
  482. begin
  483. er:=p_Add_pchar(ap1,@STR,L); { Atom of length 0 is also possible}
  484. if er<>0 then Exit; { ERROR!}
  485. end
  486. else if PLNUM(PP.cel,IM[1])
  487. then begin
  488. er:=p_Add_plong(ap1,IM[1]);
  489. if er<>0 then Exit; { ERROR!}
  490. end
  491. else Exit { ERROR !}
  492. ;
  493. end; (*2*)
  494. Next(PP);
  495. end; (*1*)
  496. PFFARDLL(AP1,AP2); { LIBRARY PROCEDURE NAME }
  497. k:=1;
  498. repeat { Loop along the result parametres }
  499. a1:=NULL;
  500. mode:=P_GetParm(AP2,k,LEN,pc,IM[1]);
  501. { if mode=1 then 5th parameter is used,
  502. otherwise - 3rd and 4th }
  503. case mode of
  504. 0: exit; { End of loop (normal) }
  505. 1: MKNUMB(IM[1],a1);
  506. 2: begin { create atom } (*2*)
  507. { Value of pc is returned }
  508. { CASE WITH SINGLE ATOM }
  509. if (len<>0)and(len<=80) then begin (*3*)
  510. ID := pc[0] in LETTER;
  511. For i:=0 to len-1 do
  512. ID := ID AND ( pc[i] IN SYMBOLS ) ;
  513. PUTATM(pc[0],len,ATM); (* makes A-Address *)
  514. GETS1(a1,x.SA); (* makes S-Address *)
  515. with x.sad^ do begin (* fills descriptor *)
  516. if ID then dtype:=IDATOM else dtype:=ATOM;
  517. NAME:=ATM;
  518. end;
  519. end (*3*)
  520. else
  521. { CASE WITH LARGE "ATOM" }
  522. if (len>80) then begin (*3*)
  523. a1:=Split_Pchar(pc,len);
  524. end (*3*)
  525. else
  526. a1:=NULL; { SAME as 'NULL' protocol value }
  527. end; (*2*)
  528. 4: a1:=NULL; { SAME as string of length 0 }
  529. end;
  530. LCONC(rez,a1);
  531. Inc(k);
  532. until false;
  533. {$ENDIF}
  534. end;
  535. Procedure USE_77(p1,p2,p3:a;var rez:a);
  536. { Calls LIBRARY procedure FARDLL from
  537. Dynamic Link Library
  538. Returns list of result parameters
  539. or NULL if call was unsuccessful
  540. String of length 0 is accepted as NULL
  541. }
  542. {$IFDEF DLL}
  543. var PP,PLIST:PTR; AP1,AP2:Pointer; A1,A2:a; pc:pchar;
  544. mode:word; er,len,fragnum,len1,k:integer;
  545. {$ENDIF}
  546. begin
  547. Rez:=0;
  548. {$IFDEF DLL}
  549. AP1:=GlobalLock(GP1);
  550. AP2:=GlobalLock(GP2);
  551. P_clear(AP1); { Rigal->DLL parameters }
  552. P_clear(AP2); { DLL->Rigal parameters }
  553. First(p1,PP); { Loop along the list of parameters }
  554. while PP.NEL<>0 do
  555. begin (*1*)
  556. if PP.CEL=NULL then
  557. begin
  558. er:=p_Add_NULL(ap1);
  559. if er<>0 then Exit; { ERROR!}
  560. end
  561. else
  562. begin (*2*)
  563. POINTR(pp.cel,x.sa);
  564. if x.smld^.dtype=listmain then begin (*3*)
  565. First(pp.cel,PLIST);
  566. fragnum:=1;
  567. while Plist.NEL<>0 do begin (*4*)
  568. if plist.CEL<>0 then (* Added 23-NOV-92 *)
  569. begin (*5*)
  570. if PLSTR(plist.cel,STR,L,false,SV1) then
  571. begin
  572. if fragnum=1 then er:=p_Add_pchar(ap1,@STR,L)
  573. else er:=p_App_pchar(ap1,@STR,L);
  574. Inc(fragnum);
  575. if er<>0 then Exit; { ERROR!}
  576. end
  577. else EXIT; {ERROR}
  578. end;(*5*)
  579. Next(PLIST);
  580. end; (*4*)
  581. end (*3*)
  582. else if PLSTR(PP.CEL,STR,L,false,SV1) then
  583. begin
  584. er:=p_Add_pchar(ap1,@STR,L); { Atom of length 0 is also possible}
  585. if er<>0 then Exit; { ERROR!}
  586. end
  587. else if PLNUM(PP.cel,IM[1])
  588. then begin
  589. er:=p_Add_plong(ap1,IM[1]);
  590. if er<>0 then Exit; { ERROR!}
  591. end
  592. else Exit { ERROR !}
  593. ;
  594. end; (*2*)
  595. Next(PP);
  596. end; (*1*)
  597. SFFARDLL(AP1,AP2); { LIBRARY PROCEDURE NAME }
  598. k:=1;
  599. repeat { Loop along the result parametres }
  600. a1:=NULL;
  601. mode:=P_GetParm(AP2,k,LEN,pc,IM[1]);
  602. { if mode=1 then 5th parameter is used,
  603. otherwise - 3rd and 4th }
  604. case mode of
  605. 0: exit; { End of loop (normal) }
  606. 1: MKNUMB(IM[1],a1);
  607. 2: begin { create atom } (*2*)
  608. { Value of pc is returned }
  609. { CASE WITH SINGLE ATOM }
  610. if (len<>0)and(len<=80) then begin (*3*)
  611. ID := pc[0] in LETTER;
  612. For i:=0 to len-1 do
  613. ID := ID AND ( pc[i] IN SYMBOLS ) ;
  614. PUTATM(pc[0],len,ATM); (* makes A-Address *)
  615. GETS1(a1,x.SA); (* makes S-Address *)
  616. with x.sad^ do begin (* fills descriptor *)
  617. if ID then dtype:=IDATOM else dtype:=ATOM;
  618. NAME:=ATM;
  619. end;
  620. end (*3*)
  621. else
  622. { CASE WITH LARGE "ATOM" }
  623. if (len>80) then begin (*3*)
  624. a1:=Split_Pchar(pc,len);
  625. end (*3*)
  626. else
  627. a1:=NULL; { SAME as 'NULL' protocol value }
  628. end; (*2*)
  629. 4: a1:=NULL; { SAME as string of length 0 }
  630. end;
  631. LCONC(rez,a1);
  632. Inc(k);
  633. until false;
  634. {$ENDIF}
  635. end;