docall.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these librararies and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $TOG: docall.c /main/7 1998/04/17 11:22:59 mgreess $ */
  24. /* Copyright (c) 1991, 1992 UNIX System Laboratories, Inc. */
  25. /* All Rights Reserved */
  26. /* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF */
  27. /* UNIX System Laboratories, Inc. */
  28. /* The copyright notice above does not evidence any */
  29. /* actual or intended publication of such source code. */
  30. #include "stdio.h"
  31. #include "exksh.h" /* which includes sys/types.h */
  32. #include "docall.h"
  33. #include <sys/param.h>
  34. #include <string.h>
  35. #include <search.h>
  36. #include <ctype.h>
  37. #include "struct.h"
  38. #include "misc.h"
  39. #include "exksh_tbls.h"
  40. #include "basetbl.h"
  41. #include "msgs.h"
  42. #include <X11/Xosdefs.h>
  43. #include <errno.h>
  44. #ifdef X_NOT_STDC_ENV
  45. extern int errno;
  46. #endif
  47. static int allprint(
  48. unsigned long *pargs,
  49. memtbl_t *tbls) ;
  50. static pp_usage( void ) ;
  51. static int call_postprompt(
  52. char * argv0,
  53. unsigned long *pargs,
  54. memtbl_t *tbls,
  55. int *freeit) ;
  56. static long get_prdebug( void ) ;
  57. static long set_prdebug(
  58. long n) ;
  59. static int myprompt(
  60. char *prompt) ;
  61. struct memtbl Null_tbl = { NULL };
  62. static char use[] = "0x%x";
  63. static char use2[] = "%s=0x%x";
  64. int Xk_errno = 0;
  65. int Xkdebug = 0;
  66. char xk_ret_buffer[100];
  67. char *xk_ret_buf = xk_ret_buffer;
  68. struct Bfunction xk_prdebug = { get_prdebug, set_prdebug };
  69. int
  70. do_field_get(
  71. int argc,
  72. char **argv )
  73. {
  74. char buf[BIGBUFSIZ], *p, *bufstart;
  75. char *fld, *type, *ptr, *ptr2, **pptr2;
  76. memtbl_t tbl[2], *tbl2;
  77. int i;
  78. char *targvar = NULL;
  79. char fail = 0, always_ptr;
  80. char * errmsg;
  81. always_ptr = 0;
  82. for (i = 1; (i < argc) && argv[i] != NULL && argv[i][0] == '-'; i++) {
  83. switch(argv[i][1]) {
  84. case 'p':
  85. always_ptr = 1;
  86. break;
  87. case 'v':
  88. targvar = argv[++i];
  89. break;
  90. }
  91. }
  92. if ((i + 1) >= argc)
  93. {
  94. XK_USAGE(argv[0]);
  95. }
  96. type = argv[i++];
  97. if (!isdigit(argv[i][0]))
  98. always_ptr = 1;
  99. ptr = (char *) getaddr(argv[i++]);
  100. tbl[1] = Null_tbl;
  101. if (!type || !ptr || (parse_decl(argv[0], tbl, type, 1) == FAIL)) {
  102. if (!type || !ptr)
  103. {
  104. XK_USAGE(argv[0]);
  105. }
  106. else
  107. {
  108. errmsg = strdup(GETMESSAGE(4,1,
  109. "Cannot parse the structure named '%s'; it may not have been defined"));
  110. printerrf(argv[0], errmsg, type, NULL, NULL,
  111. NULL, NULL, NULL, NULL, NULL);
  112. free(errmsg);
  113. return(SH_FAIL);
  114. }
  115. }
  116. if ((always_ptr || !IS_SIMPLE(tbl)) && !tbl->ptr && !(tbl->flags & F_TYPE_IS_PTR))
  117. tbl->ptr = 1;
  118. else while (tbl->ptr > 1) {
  119. ptr = *((void **) ptr);
  120. tbl->ptr--;
  121. }
  122. Pr_tmpnonames = 1;
  123. p = buf;
  124. if (targvar) {
  125. strcpy(p, targvar);
  126. p += strlen(p);
  127. *p++ = '=';
  128. bufstart = p;
  129. }
  130. else
  131. bufstart = buf;
  132. while ((i < argc) && (fld = argv[i++])) {
  133. if (p != bufstart)
  134. *p++ = targvar ? ' ' : '\n';
  135. tbl2 = tbl;
  136. ptr2 = ptr;
  137. pptr2 = &ptr2;
  138. if (!C_PAIR(fld, '.', '\0'))
  139. tbl2 = ffind(tbl, fld, (char **)&pptr2);
  140. if (!tbl2) {
  141. errmsg = strdup(GetSharedMsg(DT_BAD_FIELD_NAME));
  142. printerrf(argv[0], errmsg, fld, type,
  143. NULL, NULL, NULL, NULL, NULL, NULL);
  144. free(errmsg);
  145. fail = 1;
  146. break;
  147. }
  148. if (XK_PRINT(tbl2, &p, (char *)pptr2, 0, 0, NULL,
  149. all_tbl_find) == FAIL)
  150. {
  151. errmsg=strdup(GETMESSAGE(4,2,
  152. "Cannot print the field '%s' in structure '%s'"));
  153. printerrf(argv[0], errmsg, fld, type,
  154. NULL, NULL, NULL, NULL, NULL, NULL);
  155. free(errmsg);
  156. fail = 1;
  157. break;
  158. }
  159. }
  160. if (!fail) {
  161. *p = '\0';
  162. if (targvar)
  163. env_set(buf);
  164. else
  165. ALTPUTS(buf);
  166. }
  167. Pr_tmpnonames = 0;
  168. return(fail ? SH_FAIL : SH_SUCC);
  169. }
  170. static int
  171. allprint(
  172. unsigned long *pargs,
  173. memtbl_t *tbls )
  174. {
  175. char buf[BIGBUFSIZ], *p;
  176. int i;
  177. char * errmsg;
  178. for (i = 0; tbls[i].name; i++) {
  179. errmsg = strdup(GETMESSAGE(4,3, "Argument %d (type %s):\n\t"));
  180. printf(errmsg, i + 1, tbls[i].name);
  181. free(errmsg);
  182. p = buf;
  183. XK_PRINT(tbls + i, &p, (char *)(pargs + i), 0, 0, NULL,
  184. all_tbl_find);
  185. ALTPUTS(buf);
  186. }
  187. }
  188. static
  189. pp_usage( void )
  190. {
  191. char * errmsg;
  192. errmsg = strdup(GETMESSAGE(4,4,
  193. "Please enter p(rint), s(end), q(uit) or field=value\n"));
  194. printf(errmsg);
  195. free(errmsg);
  196. }
  197. static int
  198. call_postprompt(
  199. char * argv0 ,
  200. unsigned long *pargs,
  201. memtbl_t *tbls,
  202. int *freeit )
  203. {
  204. char buf[BUFSIZ];
  205. char * errmsg;
  206. char * quitStr, *printStr, *sendStr, *promptStr;
  207. int returnVal = 0;
  208. quitStr = strdup(GETMESSAGE(4,5, "q"));
  209. printStr = strdup(GETMESSAGE(4,6, "p"));
  210. sendStr = strdup(GETMESSAGE(4,7, "s"));
  211. promptStr = strdup(GETMESSAGE(4,8, "Postprompt: "));
  212. for ( ; ; ) {
  213. myprompt(promptStr);
  214. strcpy(buf, quitStr);
  215. *buf = '\0';
  216. fgets(buf, sizeof(buf), stdin);
  217. if (strlen(buf) && buf[strlen(buf)-1] == '\n')
  218. buf[strlen(buf)-1] = '\0';
  219. if (xk_Strncmp(buf, quitStr, 2) == 0)
  220. {
  221. errmsg=strdup(GETMESSAGE(4,9,
  222. "Warning: command was not executed\n"));
  223. printf(errmsg);
  224. free(errmsg);
  225. returnVal = 0;
  226. break;
  227. }
  228. else if (xk_Strncmp(buf, printStr, 2) == 0)
  229. allprint(pargs, tbls);
  230. else if (xk_Strncmp(buf, sendStr, 2) == 0)
  231. {
  232. returnVal = 1;
  233. break;
  234. }
  235. else if (!strchr(buf, '=') ||
  236. (asl_set(argv0,tbls, buf, (unsigned char **)pargs) == SH_FAIL))
  237. {
  238. pp_usage();
  239. }
  240. }
  241. free(quitStr);
  242. free(printStr);
  243. free(sendStr);
  244. free(promptStr);
  245. return(returnVal);
  246. }
  247. #define ZERORET 0
  248. #define NONZERO 1
  249. #define NONNEGATIVE 2
  250. /* In shell, 0 is success so, ZERORET means direct return, NONZERO means
  251. ** return the opposite of its truth value and NONNEGATIVE means return
  252. ** true if the value IS negative (since FALSE is success)
  253. */
  254. #define CALL_RETURN(RET) return(SET_RET(RET), ((ret_type == ZERORET) ? (RET) : ((ret_type == NONZERO) ? !(RET) : ((RET) < 0))))
  255. #define EARLY_RETURN(RET) return(SET_RET(RET))
  256. #define SET_RET(RET) (((int) sprintf(xk_ret_buffer, use, (RET))), (int) (xk_ret_buf = xk_ret_buffer), RET)
  257. int
  258. do_call(
  259. int argc,
  260. char **argv )
  261. {
  262. void *pargs[MAX_CALL_ARGS];
  263. memtbl_t tblarray[MAX_CALL_ARGS];
  264. char freeit[MAX_CALL_ARGS];
  265. unsigned long (*func)();
  266. char *p;
  267. char dorun, promptflag;
  268. unsigned char freeval, ret_type;
  269. register int i, j, ret;
  270. char * msg;
  271. char * errbuf;
  272. char * errmsg;
  273. promptflag = 0;
  274. freeval = 1;
  275. ret_type = ZERORET;
  276. dorun = 1;
  277. if (argc == 1) {
  278. errmsg = strdup(GetSharedMsg(DT_NO_FUNC_NAME));
  279. printerr(argv[0], errmsg, NULL);
  280. free(errmsg);
  281. xk_usage(argv[0]);
  282. EARLY_RETURN(1);
  283. }
  284. for (j = 1; (j < argc) && argv[j][0] == '-'; j++) {
  285. for (i = 1; argv[j][i]; i++) {
  286. switch(argv[j][i]) {
  287. case 'F':
  288. /* Do not free */
  289. freeval = 0;
  290. break;
  291. case 'r':
  292. /* reverse sense of return value */
  293. ret_type = NONZERO;
  294. break;
  295. case 'n':
  296. /* Non-negative return value is okay */
  297. ret_type = NONNEGATIVE;
  298. break;
  299. default:
  300. errmsg =strdup(GetSharedMsg(DT_UNKNOWN_OPTION));
  301. printerrf(argv[0], errmsg,
  302. argv[j], NULL, NULL, NULL,
  303. NULL, NULL, NULL, NULL);
  304. free(errmsg);
  305. xk_usage(argv[0]);
  306. EARLY_RETURN(1);
  307. }
  308. }
  309. }
  310. if (j >= argc) {
  311. errmsg = strdup(GetSharedMsg(DT_NO_FUNC_NAME));
  312. printerr(argv[0], errmsg, NULL);
  313. free(errmsg);
  314. xk_usage(argv[0]);
  315. CALL_RETURN(1);
  316. }
  317. memset(tblarray, '\0', MAX_CALL_ARGS * sizeof(memtbl_t));
  318. memset(pargs, '\0', MAX_CALL_ARGS * sizeof(void *));
  319. memset(freeit, '\0', MAX_CALL_ARGS * sizeof(char));
  320. func = (unsigned long (*)()) fsym(argv[j], -1);
  321. if (!func && ((argv[j][0] != '0') || (UPP(argv[j][1]) != 'X') || !(func = (unsigned long (*)()) strtoul(argv[j], &p, 16)) || *p)) {
  322. errmsg = strdup(GETMESSAGE(4,10,
  323. "Unable to locate the function '%s'"));
  324. printerrf(argv[0], errmsg,
  325. argv[j], NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  326. free(errmsg);
  327. CALL_RETURN(1);
  328. }
  329. j++;
  330. for (i = 0; (i < MAX_CALL_ARGS) && (j < argc) && argv[j]; j++, i++) {
  331. char *val;
  332. char type[100];
  333. if (C_PAIR(argv[j], '+', '?')) {
  334. promptflag = 1;
  335. continue;
  336. }
  337. else if (C_PAIR(argv[j], '+', '+')) {
  338. j++;
  339. break;
  340. }
  341. if (argv[j][0] == '@') {
  342. if (!(val = strchr(argv[j] + 1, ':'))) {
  343. dorun = 0;
  344. ret = -1;
  345. break;
  346. }
  347. strncpy(type, argv[j] + 1, val - argv[j] - 1);
  348. type[val - argv[j] - 1] = '\0';
  349. val++;
  350. if (parse_decl(argv[0], tblarray + i, type, 1) == FAIL)
  351. {
  352. dorun = 0;
  353. ret = -1;
  354. break;
  355. }
  356. else {
  357. if (!strparse(tblarray + i,
  358. (char **)(pargs + i), val))
  359. {
  360. errmsg=strdup(GETMESSAGE(4,11,
  361. "The value descriptor '%s' does not match the definition for structure '%s'"));
  362. printerrf(argv[0], errmsg,
  363. val, type, NULL, NULL, NULL,
  364. NULL, NULL, NULL);
  365. free(errmsg);
  366. dorun = 0;
  367. ret = -1;
  368. break;
  369. }
  370. else
  371. freeit[i] = freeval;
  372. }
  373. }
  374. else if (isdigit(argv[j][0])) {
  375. char *p;
  376. p = argv[j];
  377. tblarray[i] = T_unsigned_long[0];
  378. xk_par_int(&p, pargs + i, NULL);
  379. }
  380. else if (strcmp(argv[j], (char *) "NULL") == 0) {
  381. tblarray[i] = T_unsigned_long[0];
  382. pargs[i] = NULL;
  383. }
  384. else {
  385. pargs[i] = (void *) argv[j];
  386. tblarray[i] = T_string_t[0];
  387. }
  388. }
  389. /* Process special arguments */
  390. while (j < argc) {
  391. asl_set(argv[0], tblarray, argv[j], (unsigned char **)pargs);
  392. j++;
  393. }
  394. if (dorun) {
  395. if (!promptflag ||
  396. call_postprompt(argv[0], (unsigned long *)pargs, tblarray,
  397. (int *)freeit))
  398. {
  399. ret = (*func)(pargs[0], pargs[1], pargs[2], pargs[3],
  400. pargs[4], pargs[5], pargs[6], pargs[7],
  401. pargs[8], pargs[9], pargs[10], pargs[11],
  402. pargs[12], pargs[13], pargs[14]);
  403. }
  404. else
  405. ret = 0;
  406. Xk_errno = errno;
  407. }
  408. for (i = 0; i < MAX_CALL_ARGS; i++) {
  409. if (pargs[i] && freeit[i])
  410. {
  411. /* There is no recourse for failure */
  412. XK_FREE(tblarray + i, (char *)(pargs + i), 0, 0,
  413. all_tbl_find);
  414. }
  415. }
  416. CALL_RETURN(ret);
  417. }
  418. int _Prdebug;
  419. static long
  420. get_prdebug( void )
  421. {
  422. return(_Prdebug);
  423. }
  424. static long
  425. set_prdebug(
  426. long n )
  427. {
  428. _Prdebug = n;
  429. }
  430. int
  431. asl_set(
  432. char *argv0,
  433. memtbl_t *tblarray,
  434. char *desc,
  435. unsigned char **pargs )
  436. {
  437. char *ptr;
  438. char *val;
  439. memtbl_t *tbl;
  440. memtbl_t usetbl[2];
  441. char op;
  442. char field[80], *fldp = field;
  443. unsigned long intval, i, newval;
  444. unsigned long top, bottom;
  445. char * errmsg;
  446. if ((val = strchr(desc, '=')) == NULL)
  447. return(SH_FAIL);
  448. if (ispunct(val[-1]) && (val[-1] != ']')) {
  449. op = val[-1];
  450. strncpy(field, desc, val - desc - 1);
  451. field[val - desc - 1] = '\0';
  452. val++;
  453. }
  454. else {
  455. op = '\0';
  456. strncpy(field, desc, val - desc);
  457. field[val - desc] = '\0';
  458. val++;
  459. }
  460. if (isdigit(fldp[0])) {
  461. top = bottom = strtoul(fldp, &fldp, 0) - 1;
  462. if (*fldp == '.')
  463. fldp++;
  464. }
  465. else {
  466. top = 9;
  467. bottom = 0;
  468. }
  469. usetbl[1] = Null_tbl;
  470. for (i = bottom; i <= top; i++) {
  471. usetbl[0] = tblarray[i];
  472. ptr = (char *) (pargs + i);
  473. if (tbl = ffind(usetbl, fldp, &ptr))
  474. break;
  475. }
  476. if (!tbl || (i > top)) {
  477. errmsg=strdup(GETMESSAGE(4,12, "Cannot locate the field '%s'"));
  478. printerrf(argv0, errmsg, fldp, NULL, NULL, NULL,
  479. NULL, NULL, NULL, NULL);
  480. free(errmsg);
  481. return(SH_FAIL);
  482. }
  483. if (!op || !(tbl->flags & F_SIMPLE))
  484. {
  485. if (XK_PARSE(tbl, &val, ptr, 0, 0, NULL, all_tbl_find) < 0)
  486. {
  487. errmsg = strdup(GETMESSAGE(4,13,
  488. "Cannot set the following value for the field '%s': %s"));
  489. printerrf(argv0, errmsg, val, NULL,
  490. NULL, NULL, NULL, NULL, NULL, NULL);
  491. free(errmsg);
  492. }
  493. }
  494. else {
  495. xk_par_int(&val, &newval, NULL);
  496. switch (tbl->size) {
  497. case sizeof(long):
  498. intval = ((unsigned long *) ptr)[0];
  499. break;
  500. case sizeof(short):
  501. intval = ((unsigned short *) ptr)[0];
  502. break;
  503. case sizeof(char):
  504. intval = ((unsigned char *) ptr)[0];
  505. break;
  506. default:
  507. if (tbl-size == sizeof(int))
  508. {
  509. intval = ((unsigned int *) ptr)[0];
  510. break;
  511. }
  512. }
  513. switch(op) {
  514. case '+':
  515. intval += newval;
  516. break;
  517. case '-':
  518. intval -= newval;
  519. break;
  520. case '*':
  521. intval *= newval;
  522. break;
  523. case '/':
  524. intval /= newval;
  525. break;
  526. case '%':
  527. intval %= newval;
  528. break;
  529. case '&':
  530. intval &= newval;
  531. break;
  532. case '|':
  533. intval |= newval;
  534. break;
  535. case '^':
  536. intval ^= newval;
  537. break;
  538. }
  539. switch (tbl->size) {
  540. case sizeof(long):
  541. ((unsigned long *) ptr)[0] = intval;
  542. break;
  543. case sizeof(short):
  544. ((unsigned short *) ptr)[0] = intval;
  545. break;
  546. case sizeof(char):
  547. ((unsigned char *) ptr)[0] = intval;
  548. break;
  549. default:
  550. if (tbl->size == sizeof(int))
  551. {
  552. ((unsigned int *) ptr)[0] = intval;
  553. break;
  554. }
  555. }
  556. }
  557. return(SH_SUCC);
  558. }
  559. int
  560. do_field_comp(
  561. int argc,
  562. char **argv )
  563. {
  564. char *val, *type;
  565. void *ptr, *ptr2, **pptr2, *nuptr;
  566. memtbl_t tbl[2], *tbl2;
  567. unsigned int i;
  568. unsigned char always_ptr;
  569. char pr1[5 * BUFSIZ], pr2[5 * BUFSIZ], *p1, *p2;
  570. char * errbuf;
  571. char * msg;
  572. char * errmsg;
  573. i = 1;
  574. if (argc > 1 && C_PAIR(argv[i], '-', 'p')) {
  575. i++;
  576. always_ptr = 1;
  577. }
  578. else
  579. always_ptr = 0;
  580. if ((i + 2) > argc)
  581. {
  582. XK_USAGE(argv[0]);
  583. }
  584. type = argv[i++];
  585. if (!isdigit(argv[i][0]))
  586. always_ptr = 1;
  587. ptr = getaddr(argv[i++]);
  588. tbl[1] = Null_tbl;
  589. if (!type || !ptr || (parse_decl(argv[0], tbl, type, 1) == FAIL))
  590. {
  591. XK_USAGE(argv[0]);
  592. }
  593. if ((always_ptr || !IS_SIMPLE(tbl)) && !tbl->ptr && !(tbl->flags & F_TYPE_IS_PTR))
  594. tbl->ptr = 1;
  595. else while (tbl->ptr > 1) {
  596. ptr = *((void **) ptr);
  597. tbl->ptr--;
  598. }
  599. for ( ; (i < argc) && argv[i]; i++) {
  600. tbl2 = tbl;
  601. ptr2 = ptr;
  602. pptr2 = &ptr2;
  603. if (val = strchr(argv[i], '=')) {
  604. *val++ = '\0';
  605. tbl2 = ffind(tbl, argv[i], (char **)&pptr2);
  606. if (!tbl2) {
  607. errmsg = strdup(GetSharedMsg(DT_BAD_FIELD_NAME));
  608. printerrf(argv[0], errmsg, argv[i],
  609. type, NULL, NULL, NULL, NULL, NULL, NULL);
  610. free(errmsg);
  611. return(SH_FAIL);
  612. }
  613. val[-1] = '=';
  614. }
  615. else
  616. val = argv[i];
  617. p1 = pr1;
  618. p2 = pr2;
  619. Pr_tmpnonames = 1;
  620. XK_PRINT(tbl2, &p1, (char *)pptr2, 0, 0, NULL, all_tbl_find);
  621. if (XK_PARSE(tbl2, &val, (char *)&nuptr, 0, 0, NULL,
  622. all_tbl_find) < 0)
  623. {
  624. errmsg=strdup(GETMESSAGE(4,15,
  625. "Cannot parse the following expression: %s"));
  626. printerrf(argv[0], errmsg, argv[i],
  627. NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  628. free(errmsg);
  629. return(SH_FAIL);
  630. }
  631. XK_PRINT(tbl2, &p2, (char *)&nuptr, 0, 0, NULL, all_tbl_find);
  632. XK_FREE(tbl2, (char *)&nuptr, 0, 0, all_tbl_find);
  633. Pr_tmpnonames = 0;
  634. if (strcmp(pr1, pr2)) {
  635. if (env_get((char *) "PRCOMPARE"))
  636. {
  637. errmsg=strdup(GETMESSAGE(4,16,
  638. "The following comparision failed: '%s'\n\tActual: %s\n\tCompare: %s"));
  639. printerrf(argv[0], errmsg,
  640. argv[i], pr1, pr2, NULL, NULL, NULL,
  641. NULL, NULL);
  642. free(errmsg);
  643. }
  644. return(SH_FAIL);
  645. }
  646. }
  647. return(SH_SUCC);
  648. }
  649. static int
  650. myprompt(
  651. char *prompt )
  652. {
  653. fprintf(stderr,prompt);
  654. }
  655. #if 0
  656. /* This needs a functional proto, and needs to be extern'ed in docall.h */
  657. unsigned long
  658. strprint(va_alist)
  659. va_dcl
  660. {
  661. va_list ap;
  662. char *arg;
  663. char *variable = NULL;
  664. memtbl_t tbl;
  665. char *p;
  666. char buf[5 * BUFSIZ];
  667. char *name;
  668. void *val;
  669. char always_ptr;
  670. int nonames = 0;
  671. int ret;
  672. va_start(ap);
  673. always_ptr = 0;
  674. while ((arg = (char *) va_arg(ap, unsigned long)) && (arg[0] == '-')) {
  675. int i;
  676. for (i = 1; arg[i]; i++) {
  677. switch (arg[i]) {
  678. case 'v':
  679. variable = va_arg(ap, char *);
  680. i = strlen(arg) - 1;
  681. break;
  682. case 'p':
  683. always_ptr = 1;
  684. break;
  685. case 'N':
  686. nonames = 1;
  687. }
  688. }
  689. }
  690. name = arg;
  691. if (!arg) {
  692. printerr(argv[0], "Insufficient arguments", NULL);
  693. va_end(ap);
  694. return(SH_FAIL);
  695. }
  696. val = (void *) va_arg(ap, unsigned long);
  697. va_end(ap);
  698. if (parse_decl("strprintf", &tbl, name, 1) == FAIL)
  699. return(SH_FAIL);
  700. if (variable)
  701. p = buf + lsprintf(buf, "%s=", variable);
  702. else
  703. p = buf;
  704. if ((always_ptr || !IS_SIMPLE(&tbl)) && !tbl.ptr && !(tbl.flags & F_TYPE_IS_PTR))
  705. tbl.ptr = 1;
  706. if (!val && (tbl.ptr || (tbl.flags & F_TYPE_IS_PTR))) {
  707. printerr(argv[0], "NULL value argument to strprint", NULL);
  708. return(SH_FAIL);
  709. }
  710. if (always_ptr && (tbl.flags & F_TYPE_IS_PTR))
  711. val = *((void **) val);
  712. else while (tbl.ptr > 1) {
  713. val = *((void **) val);
  714. tbl.ptr--;
  715. }
  716. Pr_tmpnonames = nonames;
  717. ret = XK_PRINT(&tbl, &p, (void *) &val, 0, 0, NULL, all_tbl_find);
  718. Pr_tmpnonames = 0;
  719. if (ret == FAIL)
  720. return(SH_FAIL);
  721. if (variable)
  722. env_set(buf);
  723. else
  724. ALTPUTS(buf);
  725. return(SH_SUCC);
  726. }
  727. #endif