Nife version Beta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

743 lines
20 KiB

  1. /* Copyright (C) 2011-2022 Patrick H. E. Foubet - S.E.R.I.A.N.E.
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or any
  5. later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>
  12. *******************************************************************/
  13. #include "conf.h"
  14. /* lib.c librairie de base */
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include "nife.h"
  19. #include "mth.h"
  20. #include "err.h"
  21. #include "histo.h"
  22. #include "foncs.h"
  23. #include "tasks.h"
  24. #include "stackN.h"
  25. #include "stackL.h"
  26. #include "stackC.h"
  27. #include "stackF.h"
  28. #include "stackV.h"
  29. #include "libmath.h"
  30. #include "help.h"
  31. #include "dev.h"
  32. #include "i2c.h"
  33. #include "net.h"
  34. #include "gplot.h"
  35. #include "debug.h"
  36. /* familles des fonctions */
  37. #define F_CORE 1 /* Core */
  38. #define F_MATH 2 /* Mathematiques */
  39. #define F_PROG 4 /* Programmation, variables, tasks, ... */
  40. #define F_TOOL 8 /* External Tools Graphical or others */
  41. #define F_DEV 16 /* devices, comedi interfaces, ... */
  42. #define F_NET 32 /* networking functions */
  43. #define F_USR 64 /* user system functions */
  44. struct fonction {
  45. char * nam;
  46. void (* fct)(void);
  47. short typ; /* 0 fct, 1 instruction, 2 externe, 3 usr fct */
  48. short fam; /* cf F_xxx ci-dessus */
  49. };
  50. #define NBFONC 400
  51. #define NBCMOY 12 /* nb de car. en moyenne */
  52. static char Libelles[NBFONC*NBCMOY], *pLibs=Libelles;
  53. static struct fonction Fonctions[NBFONC];
  54. static int NBFonc=0;
  55. int InstallOn=0;
  56. static void IF_INSTALL(void) { InstallOn=1; }
  57. static void IF_INSTALLF(void) { InstallOn=2; }
  58. static void IF_INSTALLV(void) { InstallOn=3; }
  59. /* for dynamic functions */
  60. static void IF_DF_INIT(void) { InstallOn=8; }
  61. static void IF_DF_START(void) { InstallOn=9; }
  62. static void IF_DF_STOP(void) { InstallOn=10; }
  63. static void addFoncT(char *l, void (*f)(void), short T, short F)
  64. {
  65. char *LMax;
  66. if (NBFonc >= NBFONC) stopErr("addFonc : NBFONC !",NULL);
  67. LMax = Libelles + (NBFONC*NBCMOY);
  68. if (pLibs + strlen(l) + 1 >= LMax) stopErr("addFonc : Libelles !",NULL);
  69. Fonctions[NBFonc].nam = pLibs;
  70. Fonctions[NBFonc].typ = T;
  71. Fonctions[NBFonc].fam = F;
  72. Fonctions[NBFonc++].fct = f;
  73. strcpy(pLibs,l);
  74. pLibs += strlen(l);
  75. *pLibs++ = '\0';
  76. }
  77. void rmAllFonU(void)
  78. {
  79. while (Fonctions[NBFonc-1].fam == F_USR) NBFonc--;
  80. }
  81. static void addFonc(char *l, void (*f)(void))
  82. {
  83. addFoncT(l,f,0,F_CORE);
  84. }
  85. static void addFonM(char *l, void (*f)(void))
  86. {
  87. addFoncT(l,f,0,F_MATH);
  88. }
  89. static void addFonP(char *l, void (*f)(void))
  90. {
  91. addFoncT(l,f,0,F_PROG);
  92. }
  93. static void addFonG(char *l, void (*f)(void))
  94. {
  95. addFoncT(l,f,0,F_TOOL);
  96. }
  97. static void addFonD(char *l, void (*f)(void))
  98. {
  99. addFoncT(l,f,0,F_DEV);
  100. }
  101. static void addFonN(char *l, void (*f)(void))
  102. {
  103. addFoncT(l,f,0,F_NET);
  104. }
  105. void addFonU(char *l, void *A)
  106. {
  107. PFV f;
  108. f = (PFV)A;
  109. addFoncT(l,f,0,F_USR);
  110. }
  111. static void addFonE(char *l, void (*f)(void), short F) /* External functions */
  112. { /* not beetween : and ;*/
  113. addFoncT(l,f,2,F);
  114. }
  115. static void addInst(char *l, void (*f)(void))
  116. {
  117. addFoncT(l,f,1,F_PROG);
  118. }
  119. static char **ListFonc = (char**)NULL;
  120. static void show_lib_addr (void)
  121. {
  122. int i,j=0;
  123. for (i=0;i<NBFonc;i++) {
  124. printf("%-13s 0x%.8lx ",Fonctions[i].nam,(unsigned long)Fonctions[i].fct);
  125. j++;
  126. if (j == 3) {
  127. j=0;
  128. printf("\n");
  129. }
  130. }
  131. if (j) printf("\n");
  132. }
  133. static void Show_library(int NbF)
  134. {
  135. int i,j=0;
  136. for (i=0;i<NbF;i++) {
  137. /* printf("%-13s",Fonctions[i].nam);*/
  138. printf("%-13s",ListFonc[i]);
  139. j++;
  140. if (j == 6) {
  141. j=0;
  142. printf("\n");
  143. }
  144. }
  145. if (j) printf("\n");
  146. }
  147. static int triList(short F)
  148. {
  149. void * M;
  150. char * T;
  151. int i,j, NbF;
  152. if (ListFonc != (char**)NULL) free((void*)ListFonc);
  153. if ((M = malloc(sizeof(char*)* NBFonc)) == NULL) stopErr("triList","malloc");
  154. ListFonc = (char**)M;
  155. j=0;
  156. for(i=0;i<NBFonc;i++) {
  157. if (Fonctions[i].fam & F) ListFonc[j++]=Fonctions[i].nam;
  158. }
  159. NbF = j;
  160. for(i=0; i<NbF-1; i++) /* avant NbF-2 */
  161. for(j=i+1; j<NbF; j++)
  162. if(strcmp(ListFonc[j],ListFonc[i]) < 0) {
  163. T=ListFonc[i]; ListFonc[i]=ListFonc[j]; ListFonc[j]=T;
  164. }
  165. return NbF;
  166. }
  167. void listLibBegin(char * b)
  168. {
  169. int i,j=0,l,n;
  170. l=strlen(b);
  171. n=triList(0xFF);
  172. for(i=0;i<n;i++) {
  173. if (strncmp(ListFonc[i],b,l)==0){
  174. printf("%-13s",ListFonc[i]);
  175. j++;
  176. if (j == 6) {
  177. j=0;
  178. printf("\n");
  179. }
  180. } else
  181. if (strncmp(ListFonc[i],b,l)>0) break;
  182. }
  183. if (j) printf("\n");
  184. }
  185. char * getLibBegin(char * b)
  186. {
  187. int i,l;
  188. l=strlen(b);
  189. for(i=0;i<NBFonc;i++) {
  190. if (strncmp(Fonctions[i].nam,b,l)==0) break;
  191. }
  192. if (i==NBFonc) return NULL;
  193. return Fonctions[i].nam;
  194. }
  195. static char Rac[20]; /* longueur maxi d'une commande */
  196. int nbLibBegin(char * b, char ** r)
  197. {
  198. int i,n, first=1;
  199. unsigned int j, l,t=0;
  200. n=triList(0xFF);
  201. l=strlen(b);
  202. *Rac='\0';
  203. for (i=0;i<n;i++) {
  204. if (strncmp(ListFonc[i],b,l)>0) break;
  205. if (strncmp(ListFonc[i],b,l)==0) {
  206. t++;
  207. if (first) {
  208. strcpy(Rac,ListFonc[i]);
  209. first=0;
  210. } else {
  211. if (strlen(Rac) > l) {
  212. for(j=l;j<strlen(Rac);j++)
  213. if (strncmp(Rac,ListFonc[i],j) != 0) break;
  214. if (j!=strlen(Rac)) Rac[j-1]='\0';
  215. else
  216. if (Rac[j-1] != ListFonc[i][j-1]) Rac[j-1]='\0';
  217. }
  218. }
  219. }
  220. }
  221. if (strlen(Rac) > l) *r = Rac;
  222. else *r = NULL;
  223. return(t);
  224. }
  225. void IF_show_liball(void)
  226. {
  227. Show_library(triList(0xFF));
  228. }
  229. void IF_show_libstd(void)
  230. {
  231. Show_library(triList(F_CORE));
  232. }
  233. void IF_show_libmath(void)
  234. {
  235. Show_library(triList(F_MATH));
  236. }
  237. void IF_show_libprog(void)
  238. {
  239. Show_library(triList(F_PROG));
  240. }
  241. void IF_show_libtools(void)
  242. {
  243. Show_library(triList(F_TOOL));
  244. }
  245. void IF_show_libdev(void)
  246. {
  247. Show_library(triList(F_DEV));
  248. }
  249. void IF_show_libnet(void)
  250. {
  251. Show_library(triList(F_NET));
  252. }
  253. void IF_show_libusr(void)
  254. {
  255. Show_library(triList(F_USR));
  256. }
  257. void IF_new_stackAll(void)
  258. {
  259. IF_new_stackN();
  260. IF_new_stackC();
  261. IF_new_stackL();
  262. }
  263. void IF_old_stackAll(void)
  264. {
  265. IF_old_stackN();
  266. IF_old_stackC();
  267. IF_old_stackL();
  268. }
  269. void initLib(void)
  270. {
  271. addFonc(".",IF_point);
  272. addFonc("+",IF_plus);
  273. addFonc("-",IF_moins);
  274. addFonc("=",IF_Legal);
  275. addFonc("<>",IF_Ldiff);
  276. addFonc(">",IF_Lsup);
  277. addFonc("<",IF_Linf);
  278. addFonc(">=",IF_Lsupeg);
  279. addFonc("<=",IF_Linfeg);
  280. addFonc("*",IF_mult);
  281. addFonc("/",IF_div);
  282. addFonc("neg",IF_neg);
  283. addFonc("min",IF_min);
  284. addFonc("max",IF_max);
  285. addFonc("modulo",IF_modulo);
  286. addFonc("**",IF_puiss);
  287. addFonc("[]-sub",IF_subTab);
  288. addFonc("[]sub",IF_subTabR);
  289. addFonc("*[]-sub",IF_NsubTab);
  290. addFonc("*[]sub",IF_NsubTabR);
  291. addFonc("[]rev",IF_TabRev);
  292. addFonc("*[]rev",IF_NTabRev);
  293. addFonc("[]crot",IF_TabTransp);
  294. addFonc("[]transp",IF_TabTranspN);
  295. addFonc("[]trot",IF_TabTranspT);
  296. addFonc("[]>>",IF_TNShiftR);
  297. addFonc("[]<<",IF_TNShiftL);
  298. addFonc("*[]>>",IF_NTNShiftR);
  299. addFonc("*[]<<",IF_NTNShiftL);
  300. addFonc("[]>",IF_TShiftR);
  301. addFonc("[]<",IF_TShiftL);
  302. addFonc("*[]>",IF_NTShiftR);
  303. addFonc("*[]<",IF_NTShiftL);
  304. addFonc("[]min",IF_TABMin);
  305. addFonc("[]max",IF_TABMax);
  306. addFonc("[]sum",IF_TABSum);
  307. addFonc("[]prod",IF_TABProd);
  308. addFonc("[]min/max",IF_TABMinMax);
  309. addFonc(">array",IF_toArray);
  310. addFonc(">scalar",IF_toScalar);
  311. addFonc(">-scalar",IF_toScalarR);
  312. addFonc("\"",IF_debString);
  313. addFonc("\"drop",IF_dropC);
  314. addFonc("\"dup",IF_dupC);
  315. addFonc("\"over",IF_overC);
  316. addFonc("\"swap",IF_swapC);
  317. addFonc("\"type",IF_typeC);
  318. addFonc("\"cat",IF_catC);
  319. addFonc("\"cats",IF_catsC);
  320. addFonc("cr",IF_crC);
  321. addFonc("\"time",IF_timeC);
  322. addFonc("\"date",IF_dateC);
  323. addFonc("sleep",IF_sleep);
  324. addFonc("sh",IF_sh);
  325. addFonc("?drop",IF_dropL);
  326. addFonc("?dup",IF_dupL);
  327. addFonc("?swap",IF_swapL);
  328. addFonc("?over",IF_overL);
  329. addFonc("?t/f",IF_typeL);
  330. addFonc("and",IF_andL);
  331. addFonc("or",IF_orL);
  332. addFonc("xor",IF_xorL);
  333. addFonP("fdrop",rmLastFct);
  334. addFonE("del_func",IF_delFct, F_PROG);
  335. addFonE("del_afunc",IF_delAFct, F_PROG);
  336. addFonE("del_ofunc",IF_delOFct, F_PROG);
  337. addFonE("fscan",IF_scanFct, F_PROG);
  338. addFonc("?cs",IF_show_stackC);
  339. addFonP("_?cs",IFD_show_stackC);
  340. addFonP("?f",IF_show_stackF);
  341. addFonP("_?f",IFD_show_stackF);
  342. /* addFonP("?l",IF_showFD); for internal debugging */
  343. addFonP("?v",IF_show_stackV);
  344. addFonP("_?v",IFD_show_stackV);
  345. addFonE("del_var",IF_delVar,F_PROG);
  346. addFonP("vdrop",rmLastVar);
  347. addFonP("reset_var",IF_setVarI);
  348. addFonP(">v",IF_setVarN);
  349. addFonP("?>v",IF_setVarB);
  350. addFonP("\">v",IF_setVarC);
  351. addFonP("in",IF_setVarLF);
  352. addFonP("install",IF_INSTALL);
  353. addFonP("install_f",IF_INSTALLF);
  354. addFonP("install_v",IF_INSTALLV);
  355. /* pas pour le moment !!
  356. addFonP("df_init",IF_DF_INIT);
  357. addFonP("df_start",IF_DF_START);
  358. addFonP("df_stop",IF_DF_STOP);
  359. ****************/
  360. addFonc("?ls",IF_show_stackL);
  361. addFonP("_?ls",IFD_show_stackL);
  362. addFonc("?s",IF_show_stack);
  363. addFonP("_?s",IFD_show_stack);
  364. addFonc("?ms",IF_show_TStacks);
  365. addFonc("[",IF_new_stackN);
  366. addFonc("]",IF_old_stackN);
  367. addFonc("{",IF_new_stackC);
  368. addFonc("}",IF_old_stackC);
  369. addFonc("(",IF_new_stackL);
  370. addFonc(")",IF_old_stackL);
  371. addFonc("[*",IF_new_stackAll);
  372. addFonc("]*",IF_old_stackAll);
  373. /* addFonc("?libX",show_lib_addr); for internal debugging */
  374. addFonc("?libs",IF_show_liball);
  375. addFonc("?lib",IF_show_libstd);
  376. addFonc("?libM",IF_show_libmath);
  377. addFonc("?libT",IF_show_libtools);
  378. addFonc("?libP",IF_show_libprog);
  379. addFonc("?libD",IF_show_libdev);
  380. addFonc("?libN",IF_show_libnet);
  381. addFonc("?libU",IF_show_libusr);
  382. addFonc("?lasterr",IF_showError);
  383. addFonc("?err",IF_IsError);
  384. addFonc("noerr",IF_NoError);
  385. addFonc("messerr",IF_LibError);
  386. addFonc("ls_clear",IF_stackL_clear);
  387. addFonc("cs_clear",IF_stackC_clear);
  388. addFonc("REAL",IF_REAL);
  389. addFonc("INTEGER",IF_INTEGER);
  390. addFonc("DEC",IF_DEC);
  391. addFonc("HEX",IF_HEX);
  392. addFonc("OCT",IF_OCT);
  393. addFonc("BIN",IF_BIN);
  394. addFonc("echo_on",IF_ECHOON);
  395. addFonc("echo_off",IF_ECHOFF);
  396. addFonP("DEBUG_I/O",IFD_Update);
  397. addFonP("\"saveLog",IFD_SaveLog);
  398. /* addFonP("?logs",IFD_DebugTOn); */
  399. addFonc("NBTAB",IF_NBTAB);
  400. addFonc("NBLIG",IF_NBLIG);
  401. addFonE("Var",IF_debVar, F_PROG);
  402. addFonc("\"Var",IF_debVarCS);
  403. addFonP("var_off",IF_VAROFF);
  404. addFonP("var_up",IF_VARUP);
  405. addFonP("var_down",IF_VARDOWN);
  406. addFonc("?vars",IF_vars);
  407. addFonP("_?vars",IFD_vars);
  408. addFonc("drop",IF_drop);
  409. addFonc("dup",IF_dup);
  410. addFonc("swap",IF_swap);
  411. addFonc("over",IF_over);
  412. addFonc("pick",IF_pick);
  413. addFonc("rot",IF_rot);
  414. addFonc("unrot",IF_unrot);
  415. addFonc("roll",IF_roll);
  416. addFonc("unroll",IF_unroll);
  417. addFonc("*drop",IF_Ndrop);
  418. addFonc("*dup",IF_Ndup);
  419. addFonc("depth",IF_depth);
  420. addFonc("exit",IF_exit);
  421. addFonc("false",IF_false);
  422. addFonc("not",negBool);
  423. addFonc("ramp",IF_ramp);
  424. addFonc("dramp",IF_dramp);
  425. addFonc("rusage",IF_resUsage);
  426. addFonc("s_clear",IF_stack_clear);
  427. addFonM("inv",IF_inv);
  428. addFonM("sqrt",IF_sqrt);
  429. addFonM("cbrt",IF_cbrt);
  430. addFonM("round",IF_round);
  431. addFonM("floor",IF_floor);
  432. addFonM("ceil",IF_ceil);
  433. addFonM("sgn",IF_sgn);
  434. addFonM("abs",IF_abs);
  435. addFonM("pi",IF_pi);
  436. addFonM("sin",IF_sin);
  437. addFonM("cos",IF_cos);
  438. addFonM("tan",IF_tan);
  439. addFonM("asin",IF_asin);
  440. addFonM("acos",IF_acos);
  441. addFonM("atan",IF_atan);
  442. addFonM("sinh",IF_sinh);
  443. addFonM("cosh",IF_cosh);
  444. addFonM("tanh",IF_tanh);
  445. addFonM("asinh",IF_asinh);
  446. addFonM("acosh",IF_acosh);
  447. addFonM("atanh",IF_atanh);
  448. addFonM("ln",IF_ln);
  449. addFonM("log",IF_log);
  450. addFonM("exp",IF_exp);
  451. addFonM("j0",IF_j0);
  452. addFonM("j1",IF_j1);
  453. addFonM("y0",IF_y0);
  454. addFonM("y1",IF_y1);
  455. addFonc("time",IF_time);
  456. addFonc("true",IF_true);
  457. addFonc("about",IF_about);
  458. addFonc("vers",IF_vers);
  459. addFonE("load",IF_Load, F_PROG);
  460. addFonE("dump",IF_Dump, F_PROG);
  461. addFonE("restore",IF_Restore, F_PROG);
  462. addFonP("\"load",IF_LoadCS);
  463. addFonP("\"exec",IF_ExecCS);
  464. addFonP("\"execf",IF_ExecCSf);
  465. addInst("\"execk",IF_EXEK);
  466. addFonG(">csv",IF_toCsv);
  467. addFonG("y_xgraph",IF_yXgraph);
  468. addFonG("yt_xgraph",IF_ytXgraph);
  469. addFonG("xy_xgraph",IF_xyXgraph);
  470. addFonG("xyt_xgraph",IF_xytXgraph);
  471. addFonG("?gp",IF_show_stackGP);
  472. addFonP("_?gp",IFD_show_stackGP);
  473. addFonG("gplot",IF_gplot_new);
  474. addFonG("gplotM",IF_gplot_newM);
  475. addFonG("gplotRaz",IF_delAllGP);
  476. addFonG("gplotCmd",IF_gplot_commapp);
  477. addFonG("gplotAdd",IF_gplot_append);
  478. addFonG("gplotRepl",IF_gplot_replace);
  479. addFonG("del_gplot",IF_gplot_del);
  480. addFonG("gplotClear",IF_gplot_clear);
  481. addFonP(":",IF_debFct);
  482. addFonP(":!",IF_debFctS);
  483. addFonP("Task",IF_NewTask);
  484. addFonP("?t",IF_show_Tasks);
  485. addFonP("_?t",IFD_show_Tasks);
  486. addFonP("?task_run",IF_statusTask);
  487. addFonP("del_task",IF_delTask);
  488. addFonP("\"f",IF_execCS);
  489. addFonP("\"v",IF_execCSv);
  490. addFonP("\"f?",IF_execCSl);
  491. addFonP("\"v?",IF_execCSvl);
  492. addFonP("stop_task",IF_stopTask);
  493. addFonP("?console",IF_showCons);
  494. addFonP("_?console",IFD_showCons);
  495. addInst(";",IF_finFct);
  496. addInst("'",IF_debBackC);
  497. addInst("`",IF_debBackC1);
  498. addInst("return",IF_RET);
  499. addInst("if",IF_IF);
  500. addInst("else",IF_ELSE);
  501. addInst("then",IF_THEN);
  502. addInst("begin",IF_BEGIN);
  503. addInst("again",IF_AGAIN);
  504. addInst("until",IF_UNTIL);
  505. addInst("while",IF_WHILE);
  506. addInst("repeat",IF_REPEAT);
  507. addInst("do",IF_DO);
  508. addFonc("do_leave",IF_DO_Leave);
  509. addFonc("*do_leave",IF_DO_MLeave);
  510. addFonc("do_next",IF_DO_Next);
  511. /* addFonc("?do",IF_DO_Show); for internal debugging */
  512. addFonc("ndo",IF_nDO);
  513. addInst("loop",IF_LOOP);
  514. addInst("+loop",IF_PLOOP);
  515. addInst("I",IF_I_DO);
  516. addInst("J",IF_J_DO);
  517. addInst("K",IF_K_DO);
  518. addInst("break",IF_BREAK);
  519. addInst("myself",IF_MYSELF);
  520. addInst("onerr:",IF_ONERR);
  521. addInst("end:",IF_END);
  522. addInst("goto_end",IF_JEND);
  523. addFonE("help",IF_help, F_CORE);
  524. addFonD("?dev",IF_listDev);
  525. addFonP("_?dev",IFD_listDev);
  526. addFonD("dev_info",IF_showDev);
  527. addFonP("_dev_info",IFD_showDev);
  528. addFonD("dev_read",IF_devRead);
  529. addFonD("dev_write",IF_devWrite);
  530. addFonD("dev_dflt",IF_devDflt);
  531. addFonD("?dev_dflt",IF_devShowDflt);
  532. addFonP("_?dev_dflt",IFD_devShowDflt);
  533. addFonD("dev_dflW",IF_devDflW);
  534. addFonD("dev_dflR",IF_devDflR);
  535. addFonD("?i2c",IF_listI2C);
  536. addFonP("_?i2c",IFD_listI2C);
  537. addFonD("i2c_info",IF_showI2C);
  538. addFonP("_i2c_info",IFD_showI2C);
  539. addFonD("i2c_read",IF_I2CRead);
  540. addFonD("i2c_write",IF_I2CWrite);
  541. addFonN("?n",IF_netList);
  542. addFonP("_?n",IFD_netList);
  543. addFonN("netOn",IF_netOn);
  544. addFonN("netOff",IF_netOff);
  545. addFonN("netDt>",IF_netDt);
  546. addFonN("netExec",IF_netExec);
  547. addFonN("netCompile",IF_netCompile);
  548. addFonN("ndepth",IF_netDepth);
  549. addFonN("stopServer",IF_netStopS);
  550. addFonN("NetServer",IF_NetServer);
  551. addFonN("srusage",IF_netRusage);
  552. addFonN("NetKey",IF_NetKey);
  553. addFonN("NetErr",IF_NetErrVal);
  554. addFonN("Me",IF_Me);
  555. addFonN("?ns",IF_netStackList);
  556. addFonP("_?ns",IFD_netStackList);
  557. addFonN(">net",IF_netU2S);
  558. addFonN("net>",IF_netS2U);
  559. addFonN("ndrop",IF_netDropS);
  560. /* triList(); */
  561. }
  562. int fctExists(char * L)
  563. {
  564. int i;
  565. for (i=0;i<NBFonc;i++) {
  566. if (strcmp(L,Fonctions[i].nam) == 0) return 1;
  567. }
  568. return 0;
  569. }
  570. void * libByName(char * L)
  571. {
  572. int i;
  573. for (i=0;i<NBFonc;i++) {
  574. if (strcmp(L,Fonctions[i].nam) == 0) {
  575. if (Fonctions[i].typ) break;
  576. else return((void*)Fonctions[i].fct);
  577. }
  578. }
  579. return VIDE;
  580. }
  581. void * libByInd(long i)
  582. {
  583. return((void*)Fonctions[i].fct);
  584. }
  585. int execLibNrpc(char *C)
  586. {
  587. int i;
  588. if (sigsetjmp(ENV_INT,1)) {
  589. return 0;
  590. }
  591. if (IF_execFct(C)) return 1;
  592. for (i=0;i<NBFonc;i++) {
  593. if (strcmp(C,Fonctions[i].nam) == 0) {
  594. switch (Fonctions[i].typ) {
  595. case 1:
  596. case 3: /* usr fct */
  597. return 0;
  598. break;
  599. default: /* typ = 0 et 2 */
  600. Fonctions[i].fct();
  601. break;
  602. }
  603. return 1;
  604. }
  605. }
  606. if (IF_execVar(C)) return 1; /* VARS DOWN */
  607. return 0;
  608. }
  609. int execLib(char *C)
  610. {
  611. int i;
  612. void * A;
  613. short T=0;
  614. InExec = C;
  615. /* D_Trace(C); pas pour le moment */
  616. if (sigsetjmp(ENV_INT,1)) {
  617. interInfos("execLib",C);
  618. return 1;
  619. }
  620. if (InstallOn) {
  621. switch (InstallOn) {
  622. case 1 : /* lib first */
  623. A=libByName(C);
  624. if (A==VIDE) {
  625. A=fctByName(C);
  626. if (A!=VIDE) T=2;
  627. } else T=1;
  628. break;
  629. case 2 : /* user functions first */
  630. A=fctByName(C);
  631. if (A==VIDE) {
  632. A=libByName(C);
  633. if (A!=VIDE) T=1;
  634. } else T=2;
  635. break;
  636. case 3 : /* variables only */
  637. A=varByName(C);
  638. if (A!=VIDE) T=3;
  639. break;
  640. case 8 : /* df_init */
  641. A=fctByName(C);
  642. updDynFct(A,0);
  643. break;
  644. case 9 : /* df_start */
  645. A=fctByName(C);
  646. updDynFct(A,1);
  647. break;
  648. case 10 : /* df_stop */
  649. A=fctByName(C);
  650. updDynFct(A,2);
  651. break;
  652. default :
  653. break;
  654. }
  655. _MODIF_FCT_INST_(A);
  656. _MODIF_FCT_TYP_(T);
  657. InstallOn=0;
  658. return 1;
  659. }
  660. if ((VARS==2) && (IF_execVar(C))) return 1; /* VARS UP */
  661. if (IF_execFct(C)) return 1;
  662. for (i=0;i<NBFonc;i++) {
  663. /* printf("execLib : teste %s !\n", Fonctions[i].nam); */
  664. if (strcmp(C,Fonctions[i].nam) == 0) {
  665. switch (Fonctions[i].typ) {
  666. case 1:
  667. if (fctEnCours) Fonctions[i].fct();
  668. else messErr(13);
  669. break;
  670. case 2:
  671. if (fctEnCours) messErr(25);
  672. else Fonctions[i].fct();
  673. break;
  674. case 3: /* usr fct */
  675. break;
  676. default: /* typ = 0 */
  677. if (fctEnCours) {
  678. if (strcmp(C,":") == 0) messErr(15);
  679. else {
  680. if (strcmp(C,"\"") == 0) Fonctions[i].fct();
  681. else makeFct(T_LIB,(void*)Fonctions[i].fct);
  682. }
  683. } else Fonctions[i].fct();
  684. break;
  685. }
  686. return 1;
  687. }
  688. }
  689. if ((VARS==1) && (IF_execVar(C))) return 1; /* VARS DOWN */
  690. /* printf("execLib : appel putVal(%s)\n",C); */
  691. return(putVal(C));
  692. }
  693. char * libByAddr(void *A)
  694. {
  695. PFC f;
  696. int i;
  697. f = (PFC)A;
  698. for (i=0;i<NBFonc;i++) {
  699. if (f == (PFC)(Fonctions[i].fct)) return Fonctions[i].nam;
  700. }
  701. return NULL;
  702. }
  703. long iLibByAddr(void *A)
  704. {
  705. PFC f;
  706. int i;
  707. f = (PFC)A;
  708. for (i=0;i<NBFonc;i++) {
  709. if (f == (PFC)(Fonctions[i].fct)) return (long)i;
  710. }
  711. return 0L;
  712. }