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.
 
 
 
 

720 lines
19 KiB

  1. /* Copyright (C) 2011-2015 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 initLib(void)
  258. {
  259. addFonc(".",IF_point);
  260. addFonc("+",IF_plus);
  261. addFonc("-",IF_moins);
  262. addFonc("=",IF_Legal);
  263. addFonc("<>",IF_Ldiff);
  264. addFonc(">",IF_Lsup);
  265. addFonc("<",IF_Linf);
  266. addFonc(">=",IF_Lsupeg);
  267. addFonc("<=",IF_Linfeg);
  268. addFonc("*",IF_mult);
  269. addFonc("/",IF_div);
  270. addFonc("neg",IF_neg);
  271. addFonc("min",IF_min);
  272. addFonc("max",IF_max);
  273. addFonc("modulo",IF_modulo);
  274. addFonc("**",IF_puiss);
  275. addFonc("[]-sub",IF_subTab);
  276. addFonc("[]sub",IF_subTabR);
  277. addFonc("*[]-sub",IF_NsubTab);
  278. addFonc("*[]sub",IF_NsubTabR);
  279. addFonc("[]rev",IF_TabRev);
  280. addFonc("*[]rev",IF_NTabRev);
  281. addFonc("[]crot",IF_TabTransp);
  282. addFonc("[]transp",IF_TabTranspN);
  283. addFonc("[]trot",IF_TabTranspT);
  284. addFonc("[]>>",IF_TNShiftR);
  285. addFonc("[]<<",IF_TNShiftL);
  286. addFonc("*[]>>",IF_NTNShiftR);
  287. addFonc("*[]<<",IF_NTNShiftL);
  288. addFonc("[]>",IF_TShiftR);
  289. addFonc("[]<",IF_TShiftL);
  290. addFonc("*[]>",IF_NTShiftR);
  291. addFonc("*[]<",IF_NTShiftL);
  292. addFonc("[]min",IF_TABMin);
  293. addFonc("[]max",IF_TABMax);
  294. addFonc("[]sum",IF_TABSum);
  295. addFonc("[]prod",IF_TABProd);
  296. addFonc("[]min/max",IF_TABMinMax);
  297. addFonc(">array",IF_toArray);
  298. addFonc(">scalar",IF_toScalar);
  299. addFonc(">-scalar",IF_toScalarR);
  300. addFonc("\"",IF_debString);
  301. addFonc("\"drop",IF_dropC);
  302. addFonc("\"dup",IF_dupC);
  303. addFonc("\"over",IF_overC);
  304. addFonc("\"swap",IF_swapC);
  305. addFonc("\"type",IF_typeC);
  306. addFonc("\"cat",IF_catC);
  307. addFonc("\"cats",IF_catsC);
  308. addFonc("cr",IF_crC);
  309. addFonc("\"time",IF_timeC);
  310. addFonc("\"date",IF_dateC);
  311. addFonc("sleep",IF_sleep);
  312. addFonc("sh",IF_sh);
  313. addFonc("?drop",IF_dropL);
  314. addFonc("?dup",IF_dupL);
  315. addFonc("?swap",IF_swapL);
  316. addFonc("?over",IF_overL);
  317. addFonc("?t/f",IF_typeL);
  318. addFonc("and",IF_andL);
  319. addFonc("or",IF_orL);
  320. addFonc("xor",IF_xorL);
  321. addFonP("fdrop",rmLastFct);
  322. addFonE("del_func",IF_delFct, F_PROG);
  323. addFonE("del_afunc",IF_delAFct, F_PROG);
  324. addFonE("del_ofunc",IF_delOFct, F_PROG);
  325. addFonE("fscan",IF_scanFct, F_PROG);
  326. addFonc("?cs",IF_show_stackC);
  327. addFonP("_?cs",IFD_show_stackC);
  328. addFonP("?f",IF_show_stackF);
  329. addFonP("_?f",IFD_show_stackF);
  330. /* addFonP("?l",IF_showFD); for internal debugging */
  331. addFonP("?v",IF_show_stackV);
  332. addFonP("_?v",IFD_show_stackV);
  333. addFonE("del_var",IF_delVar,F_PROG);
  334. addFonP("vdrop",rmLastVar);
  335. addFonP("reset_var",IF_setVarI);
  336. addFonP(">v",IF_setVarN);
  337. addFonP("?>v",IF_setVarB);
  338. addFonP("\">v",IF_setVarC);
  339. addFonP("in",IF_setVarLF);
  340. addFonP("install",IF_INSTALL);
  341. addFonP("install_f",IF_INSTALLF);
  342. addFonP("install_v",IF_INSTALLV);
  343. /* pas pour le moment !!
  344. addFonP("df_init",IF_DF_INIT);
  345. addFonP("df_start",IF_DF_START);
  346. addFonP("df_stop",IF_DF_STOP);
  347. ****************/
  348. addFonc("?ls",IF_show_stackL);
  349. addFonP("_?ls",IFD_show_stackL);
  350. addFonc("?s",IF_show_stack);
  351. addFonP("_?s",IFD_show_stack);
  352. /* addFonc("?libX",show_lib_addr); for internal debugging */
  353. addFonc("?libs",IF_show_liball);
  354. addFonc("?lib",IF_show_libstd);
  355. addFonc("?libM",IF_show_libmath);
  356. addFonc("?libT",IF_show_libtools);
  357. addFonc("?libP",IF_show_libprog);
  358. addFonc("?libD",IF_show_libdev);
  359. addFonc("?libN",IF_show_libnet);
  360. addFonc("?libU",IF_show_libusr);
  361. addFonc("?lasterr",IF_showError);
  362. addFonc("?err",IF_IsError);
  363. addFonc("noerr",IF_NoError);
  364. addFonc("messerr",IF_LibError);
  365. addFonc("ls_clear",IF_stackL_clear);
  366. addFonc("cs_clear",IF_stackC_clear);
  367. addFonc("REAL",IF_REAL);
  368. addFonc("INTEGER",IF_INTEGER);
  369. addFonc("DEC",IF_DEC);
  370. addFonc("HEX",IF_HEX);
  371. addFonc("OCT",IF_OCT);
  372. addFonc("BIN",IF_BIN);
  373. addFonc("echo_on",IF_ECHOON);
  374. addFonc("echo_off",IF_ECHOFF);
  375. addFonP("DEBUG_I/O",IFD_Update);
  376. addFonP("\"saveLog",IFD_SaveLog);
  377. /* addFonP("?logs",IFD_DebugTOn); */
  378. addFonc("NBTAB",IF_NBTAB);
  379. addFonc("NBLIG",IF_NBLIG);
  380. addFonE("Var",IF_debVar, F_PROG);
  381. addFonc("\"Var",IF_debVarCS);
  382. addFonP("var_off",IF_VAROFF);
  383. addFonP("var_up",IF_VARUP);
  384. addFonP("var_down",IF_VARDOWN);
  385. addFonc("?vars",IF_vars);
  386. addFonP("_?vars",IFD_vars);
  387. addFonc("drop",IF_drop);
  388. addFonc("dup",IF_dup);
  389. addFonc("swap",IF_swap);
  390. addFonc("over",IF_over);
  391. addFonc("pick",IF_pick);
  392. addFonc("rot",IF_rot);
  393. addFonc("unrot",IF_unrot);
  394. addFonc("roll",IF_roll);
  395. addFonc("unroll",IF_unroll);
  396. addFonc("*drop",IF_Ndrop);
  397. addFonc("*dup",IF_Ndup);
  398. addFonc("depth",IF_depth);
  399. addFonc("exit",IF_exit);
  400. addFonc("false",IF_false);
  401. addFonc("not",negBool);
  402. addFonc("ramp",IF_ramp);
  403. addFonc("dramp",IF_dramp);
  404. addFonc("rusage",IF_resUsage);
  405. addFonc("s_clear",IF_stack_clear);
  406. addFonM("inv",IF_inv);
  407. addFonM("sqrt",IF_sqrt);
  408. addFonM("cbrt",IF_cbrt);
  409. addFonM("round",IF_round);
  410. addFonM("floor",IF_floor);
  411. addFonM("ceil",IF_ceil);
  412. addFonM("sgn",IF_sgn);
  413. addFonM("abs",IF_abs);
  414. addFonM("pi",IF_pi);
  415. addFonM("sin",IF_sin);
  416. addFonM("cos",IF_cos);
  417. addFonM("tan",IF_tan);
  418. addFonM("asin",IF_asin);
  419. addFonM("acos",IF_acos);
  420. addFonM("atan",IF_atan);
  421. addFonM("sinh",IF_sinh);
  422. addFonM("cosh",IF_cosh);
  423. addFonM("tanh",IF_tanh);
  424. addFonM("asinh",IF_asinh);
  425. addFonM("acosh",IF_acosh);
  426. addFonM("atanh",IF_atanh);
  427. addFonM("ln",IF_ln);
  428. addFonM("log",IF_log);
  429. addFonM("exp",IF_exp);
  430. addFonM("j0",IF_j0);
  431. addFonM("j1",IF_j1);
  432. addFonM("y0",IF_y0);
  433. addFonM("y1",IF_y1);
  434. addFonc("time",IF_time);
  435. addFonc("true",IF_true);
  436. addFonc("about",IF_about);
  437. addFonc("vers",IF_vers);
  438. addFonE("load",IF_Load, F_PROG);
  439. addFonE("dump",IF_Dump, F_PROG);
  440. addFonE("restore",IF_Restore, F_PROG);
  441. addFonP("\"load",IF_LoadCS);
  442. addFonP("\"exec",IF_ExecCS);
  443. addFonP("\"execf",IF_ExecCSf);
  444. addInst("\"execk",IF_EXEK);
  445. addFonG(">csv",IF_toCsv);
  446. addFonG("y_xgraph",IF_yXgraph);
  447. addFonG("yt_xgraph",IF_ytXgraph);
  448. addFonG("xy_xgraph",IF_xyXgraph);
  449. addFonG("xyt_xgraph",IF_xytXgraph);
  450. addFonG("?gp",IF_show_stackGP);
  451. addFonP("_?gp",IFD_show_stackGP);
  452. addFonG("gplot",IF_gplot_new);
  453. addFonG("gplotM",IF_gplot_newM);
  454. addFonG("gplotRaz",IF_delAllGP);
  455. addFonG("gplotCmd",IF_gplot_commapp);
  456. addFonG("gplotAdd",IF_gplot_append);
  457. addFonG("gplotRepl",IF_gplot_replace);
  458. addFonG("del_gplot",IF_gplot_del);
  459. addFonG("gplotClear",IF_gplot_clear);
  460. addFonP(":",IF_debFct);
  461. addFonP(":!",IF_debFctS);
  462. addFonP("Task",IF_NewTask);
  463. addFonP("?t",IF_show_Tasks);
  464. addFonP("_?t",IFD_show_Tasks);
  465. addFonP("?task_run",IF_statusTask);
  466. addFonP("del_task",IF_delTask);
  467. addFonP("\"f",IF_execCS);
  468. addFonP("\"v",IF_execCSv);
  469. addFonP("\"f?",IF_execCSl);
  470. addFonP("\"v?",IF_execCSvl);
  471. addFonP("stop_task",IF_stopTask);
  472. addFonP("?console",IF_showCons);
  473. addFonP("_?console",IFD_showCons);
  474. addInst(";",IF_finFct);
  475. addInst("'",IF_debBackC);
  476. addInst("`",IF_debBackC1);
  477. addInst("return",IF_RET);
  478. addInst("if",IF_IF);
  479. addInst("else",IF_ELSE);
  480. addInst("then",IF_THEN);
  481. addInst("begin",IF_BEGIN);
  482. addInst("again",IF_AGAIN);
  483. addInst("until",IF_UNTIL);
  484. addInst("while",IF_WHILE);
  485. addInst("repeat",IF_REPEAT);
  486. addInst("do",IF_DO);
  487. addFonc("do_leave",IF_DO_Leave);
  488. addFonc("*do_leave",IF_DO_MLeave);
  489. addFonc("do_next",IF_DO_Next);
  490. /* addFonc("?do",IF_DO_Show); for internal debugging */
  491. addFonc("ndo",IF_nDO);
  492. addInst("loop",IF_LOOP);
  493. addInst("+loop",IF_PLOOP);
  494. addInst("I",IF_I_DO);
  495. addInst("J",IF_J_DO);
  496. addInst("K",IF_K_DO);
  497. addInst("break",IF_BREAK);
  498. addInst("myself",IF_MYSELF);
  499. addInst("onerr:",IF_ONERR);
  500. addInst("end:",IF_END);
  501. addInst("goto_end",IF_JEND);
  502. addFonE("help",IF_help, F_CORE);
  503. addFonD("?dev",IF_listDev);
  504. addFonP("_?dev",IFD_listDev);
  505. addFonD("dev_info",IF_showDev);
  506. addFonP("_dev_info",IFD_showDev);
  507. addFonD("dev_read",IF_devRead);
  508. addFonD("dev_write",IF_devWrite);
  509. addFonD("dev_dflt",IF_devDflt);
  510. addFonD("?dev_dflt",IF_devShowDflt);
  511. addFonP("_?dev_dflt",IFD_devShowDflt);
  512. addFonD("dev_dflW",IF_devDflW);
  513. addFonD("dev_dflR",IF_devDflR);
  514. addFonD("?i2c",IF_listI2C);
  515. addFonP("_?i2c",IFD_listI2C);
  516. addFonD("i2c_info",IF_showI2C);
  517. addFonP("_i2c_info",IFD_showI2C);
  518. addFonD("i2c_read",IF_I2CRead);
  519. addFonD("i2c_write",IF_I2CWrite);
  520. addFonN("?n",IF_netList);
  521. addFonP("_?n",IFD_netList);
  522. addFonN("netOn",IF_netOn);
  523. addFonN("netOff",IF_netOff);
  524. addFonN("netDt>",IF_netDt);
  525. addFonN("netExec",IF_netExec);
  526. addFonN("netCompile",IF_netCompile);
  527. addFonN("ndepth",IF_netDepth);
  528. addFonN("stopServer",IF_netStopS);
  529. addFonN("NetServer",IF_NetServer);
  530. addFonN("srusage",IF_netRusage);
  531. addFonN("NetKey",IF_NetKey);
  532. addFonN("NetErr",IF_NetErrVal);
  533. addFonN("Me",IF_Me);
  534. addFonN("?ns",IF_netStackList);
  535. addFonP("_?ns",IFD_netStackList);
  536. addFonN(">net",IF_netU2S);
  537. addFonN("net>",IF_netS2U);
  538. addFonN("ndrop",IF_netDropS);
  539. /* triList(); */
  540. }
  541. int fctExists(char * L)
  542. {
  543. int i;
  544. for (i=0;i<NBFonc;i++) {
  545. if (strcmp(L,Fonctions[i].nam) == 0) return 1;
  546. }
  547. return 0;
  548. }
  549. void * libByName(char * L)
  550. {
  551. int i;
  552. for (i=0;i<NBFonc;i++) {
  553. if (strcmp(L,Fonctions[i].nam) == 0) {
  554. if (Fonctions[i].typ) break;
  555. else return((void*)Fonctions[i].fct);
  556. }
  557. }
  558. return VIDE;
  559. }
  560. void * libByInd(long i)
  561. {
  562. return((void*)Fonctions[i].fct);
  563. }
  564. int execLibNrpc(char *C)
  565. {
  566. int i;
  567. if (sigsetjmp(ENV_INT,1)) {
  568. return 0;
  569. }
  570. if (IF_execFct(C)) return 1;
  571. for (i=0;i<NBFonc;i++) {
  572. if (strcmp(C,Fonctions[i].nam) == 0) {
  573. switch (Fonctions[i].typ) {
  574. case 1:
  575. case 3: /* usr fct */
  576. return 0;
  577. break;
  578. default: /* typ = 0 et 2 */
  579. Fonctions[i].fct();
  580. break;
  581. }
  582. return 1;
  583. }
  584. }
  585. if (IF_execVar(C)) return 1; /* VARS DOWN */
  586. return 0;
  587. }
  588. int execLib(char *C)
  589. {
  590. int i;
  591. void * A;
  592. short T=0;
  593. InExec = C;
  594. /* D_Trace(C); pas pour le moment */
  595. if (sigsetjmp(ENV_INT,1)) {
  596. interInfos("execLib",C);
  597. return 1;
  598. }
  599. if (InstallOn) {
  600. switch (InstallOn) {
  601. case 1 : /* lib first */
  602. A=libByName(C);
  603. if (A==VIDE) {
  604. A=fctByName(C);
  605. if (A!=VIDE) T=2;
  606. } else T=1;
  607. break;
  608. case 2 : /* user functions first */
  609. A=fctByName(C);
  610. if (A==VIDE) {
  611. A=libByName(C);
  612. if (A!=VIDE) T=1;
  613. } else T=2;
  614. break;
  615. case 3 : /* variables only */
  616. A=varByName(C);
  617. if (A!=VIDE) T=3;
  618. break;
  619. case 8 : /* df_init */
  620. A=fctByName(C);
  621. updDynFct(A,0);
  622. break;
  623. case 9 : /* df_start */
  624. A=fctByName(C);
  625. updDynFct(A,1);
  626. break;
  627. case 10 : /* df_stop */
  628. A=fctByName(C);
  629. updDynFct(A,2);
  630. break;
  631. default :
  632. break;
  633. }
  634. _MODIF_FCT_INST_(A);
  635. _MODIF_FCT_TYP_(T);
  636. InstallOn=0;
  637. return 1;
  638. }
  639. if ((VARS==2) && (IF_execVar(C))) return 1; /* VARS UP */
  640. if (IF_execFct(C)) return 1;
  641. for (i=0;i<NBFonc;i++) {
  642. /* printf("execLib : teste %s !\n", Fonctions[i].nam); */
  643. if (strcmp(C,Fonctions[i].nam) == 0) {
  644. switch (Fonctions[i].typ) {
  645. case 1:
  646. if (fctEnCours) Fonctions[i].fct();
  647. else messErr(13);
  648. break;
  649. case 2:
  650. if (fctEnCours) messErr(25);
  651. else Fonctions[i].fct();
  652. break;
  653. case 3: /* usr fct */
  654. break;
  655. default: /* typ = 0 */
  656. if (fctEnCours) {
  657. if (strcmp(C,":") == 0) messErr(15);
  658. else {
  659. if (strcmp(C,"\"") == 0) Fonctions[i].fct();
  660. else makeFct(T_LIB,(void*)Fonctions[i].fct);
  661. }
  662. } else Fonctions[i].fct();
  663. break;
  664. }
  665. return 1;
  666. }
  667. }
  668. if ((VARS==1) && (IF_execVar(C))) return 1; /* VARS DOWN */
  669. /* printf("execLib : appel putVal(%s)\n",C); */
  670. return(putVal(C));
  671. }
  672. char * libByAddr(void *A)
  673. {
  674. PFC f;
  675. int i;
  676. f = (PFC)A;
  677. for (i=0;i<NBFonc;i++) {
  678. if (f == (PFC)(Fonctions[i].fct)) return Fonctions[i].nam;
  679. }
  680. return NULL;
  681. }
  682. long iLibByAddr(void *A)
  683. {
  684. PFC f;
  685. int i;
  686. f = (PFC)A;
  687. for (i=0;i<NBFonc;i++) {
  688. if (f == (PFC)(Fonctions[i].fct)) return (long)i;
  689. }
  690. return 0L;
  691. }