PageRenderTime 1117ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/cde/programs/dtimsstart/main.c

https://bitbucket.org/tifan/cde
C | 1369 lines | 1118 code | 188 blank | 63 comment | 308 complexity | 2e77aeb3231748796a98eb6c5ba6bcec MD5 | raw file
Possible License(s): LGPL-2.1, IPL-1.0, 0BSD
  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. /* $XConsortium: main.c /main/10 1996/10/28 12:41:03 cde-hp $ */
  24. /*
  25. * (c) Copyright 1996 Digital Equipment Corporation.
  26. * (c) Copyright 1996 Hewlett-Packard Company.
  27. * (c) Copyright 1996 International Business Machines Corp.
  28. * (c) Copyright 1996 Sun Microsystems, Inc.
  29. * (c) Copyright 1996 Novell, Inc.
  30. * (c) Copyright 1996 FUJITSU LIMITED.
  31. * (c) Copyright 1996 Hitachi.
  32. */
  33. #ifndef lint
  34. static char *RCS_ID = "@(#)dtimsstart $Revision: /main/10 $ $Date: 1996/10/28 12:41:03 $";
  35. #endif
  36. char *ProgramRevision = "dtimsstart $Revision: /main/10 $";
  37. #define _EXTERN_DEFINE_
  38. #include "xims.h"
  39. #undef _EXTERN_DEFINE_
  40. #include <signal.h>
  41. #include <locale.h>
  42. #ifndef NLS
  43. #define catgets(i, sn,mn,s) (s)
  44. #else
  45. #define NL_SETN 1 /* set number */
  46. #include <nl_types.h>
  47. static nl_catd catd = (nl_catd) -1;
  48. #endif /* NLS */
  49. extern char *find_system_locale_name(char *);
  50. /* local functions */
  51. static int IsNoError(/* error */);
  52. static int EnvNeeded(/* error */);
  53. static int ErrMsgDisabled(/* error */);
  54. static int ximsShowImsList(/* */);
  55. static int ximsShowCurrentIms(/* */);
  56. static int prepare_remote(/* win_st */);
  57. static int ximsRemoteConf(/* */);
  58. static int ximsSetMode(/* */);
  59. static void show_select_mode(/* mode */);
  60. static int set_locale_env(/* locale */);
  61. static void init_command(/* progname */);
  62. static bool optname_match(/* name, str, minlen */);
  63. static int parse_options(/* argc, argv */);
  64. static void usage(/* force */);
  65. static int exitSignalNumber = 0;
  66. static bool do_usage = False;
  67. main (argc, argv)
  68. int argc;
  69. char **argv;
  70. {
  71. int ret = NoError;
  72. int ret2;
  73. init_command(argv[0]);
  74. ret = parse_options(argc, argv);
  75. ret2 = set_locale_env(Opt.LocaleName); /* set LANG, LC_ALL, msg cat */
  76. /* get_user_environ() does check ErrNoLocale */
  77. if (do_usage) { /* '-help' option */
  78. usage(True);
  79. Exit(NoError);
  80. }
  81. if (ret != NoError)
  82. Exit(ret);
  83. if (OpMode == MODE_START && getenv(ENV_NO_DTIMSSTART))
  84. Exit(ErrDisabled);
  85. if ((ret = set_cmd_env()) != NoError) {
  86. /* get_user_environ()) & read_cmd_conf()) */
  87. Exit(ret);
  88. }
  89. #ifdef DEBUG
  90. if (DebugLvl > 2) { pr_CmdConf(); }
  91. if (DebugLvl > 1) { pr_CmdOpt(), pr_OpModeFlag(); pr_UserEnv(); }
  92. #endif
  93. /* set signal handler */
  94. if (signal(SIGINT, SIG_IGN) != SIG_IGN) signal(SIGINT, sigExit);
  95. signal(SIGTERM, sigExit);
  96. signal(SIGHUP, sigExit);
  97. signal(SIGQUIT, sigExit);
  98. /* create $HOME/.xims if needed */
  99. if (OpMode == MODE_START
  100. || (OpMode == MODE_MODE && Opt.SelectMode != SEL_MODE_QUERY)) {
  101. if ((ret = create_xims_dir()) != NoError) {
  102. OpErrCode = ret;
  103. OpState = State_Init_Err;
  104. ximsMain(); /* abort with error msg */
  105. }
  106. }
  107. OpState = State_Init_Done;
  108. switch (OpMode) {
  109. case MODE_LISTNAME:
  110. case MODE_LIST: ret = ximsShowImsList(); break;
  111. case MODE_CURRENT: ret = ximsShowCurrentIms(); break;
  112. case MODE_MODE: ret = ximsSetMode(); break;
  113. case MODE_REMCONF: ret = ximsRemoteConf(); break;
  114. case MODE_START:
  115. #ifndef DEBUG2
  116. # ifdef __osf__
  117. setsid();
  118. # else
  119. setpgrp();
  120. # endif
  121. #endif
  122. ximsMain(); /* never returns */
  123. }
  124. Exit(ret);
  125. }
  126. void sigExit(sig)
  127. int sig;
  128. {
  129. DPR(("sigExit: %s (%d)\n", sig_name(sig), sig));
  130. signal(sig, SIG_IGN);
  131. exitSignalNumber = sig;
  132. Exit(ErrSignaled);
  133. }
  134. void Exit(err_code)
  135. int err_code;
  136. {
  137. int exit_code = IsNoError(err_code) ? 0 : 1;
  138. DPR(("Exit(%s[%d]): exit(%d)\n",
  139. error_name(err_code), err_code, exit_code));
  140. if (Verbose > 0 && err_code != LastErrMsg) {
  141. if (exit_code != 0 && !ErrMsgDisabled(err_code)) {
  142. UseMsgWindow = False; /* disable msg window */
  143. put_xims_errmsg(err_code, 0, 0, 0);
  144. }
  145. }
  146. if (OpFlag & FLAG_NOTIFY)
  147. NotifyErrCode(exit_code == 0 ? NoError : err_code);
  148. /*
  149. * if the reason we're exiting is because of a syntax
  150. * error, set the exit code to 2.
  151. */
  152. if (ErrSyntax == err_code)
  153. exit_code = 2;
  154. exit(exit_code);
  155. }
  156. int NotifyErrCode(err_code)
  157. int err_code;
  158. {
  159. char buf[BUFSIZ], *bp, val[20];
  160. static bool notify_done = False;
  161. if (/* !(OpFlag & FLAG_NOTIFY) || */ notify_done)
  162. return False;
  163. notify_done = True;
  164. buf[0] = 0; bp = buf;
  165. bp = strcpyx(bp, STR_ERRORCODE);
  166. *bp++ = '=';
  167. sprintf(val, "%ld", (long)err_code);
  168. bp = strcpyx(bp, val);
  169. *bp++ = '\n'; *bp = 0;
  170. if (ErrFilePathNeeded(err_code)) {
  171. bp = strcpyx(bp, STR_ERRORPATH);
  172. *bp++ = '=';
  173. if (err_code == ErrImsAborted)
  174. bp = strcpyx(bp, Opt.LogPath);
  175. else
  176. bp = strcpyx(bp, errFilePath);
  177. *bp++ = '\n'; *bp = 0;
  178. }
  179. if (OpMode == MODE_REMCONF) {
  180. send_dtims_msg(WIN_ST_REMOTE_CONF, err_code);
  181. } else if (OpMode == MODE_START && (OpFlag & FLAG_REMOTERUN)) {
  182. send_dtims_msg(WIN_ST_REMOTE_RUN, err_code);
  183. } else {
  184. fflush(stdout); fflush(stderr);
  185. (void) fwrite((void *)buf, (size_t)(bp - buf), (size_t)1, stdout);
  186. fflush(stdout);
  187. }
  188. return True;
  189. }
  190. static int IsNoError(error)
  191. ximsError error;
  192. {
  193. switch (error) {
  194. case NoError: case ErrIsNone: case ErrNotRun:
  195. case ErrImsWaiting: case ErrImsWaitDone:
  196. case ErrImsConnecting: case ErrImsConnectDone:
  197. case ErrNoImsEntry: case ErrNoLocaleConf:
  198. case ErrNoSelectionFile: case ErrNoSelection: case ErrSaveSelection:
  199. case ErrDisabled:
  200. return True;
  201. }
  202. return False;
  203. }
  204. static int EnvNeeded(error)
  205. ximsError error;
  206. {
  207. switch (error) {
  208. case NoError: case ErrIsNone: case ErrNotRun:
  209. case ErrImsWaiting: case ErrImsWaitDone:
  210. case ErrImsRunning: case ErrImsTimeout:
  211. /* case ErrImsExecution: case ErrImsAborted: */
  212. case ErrOpenResource: /* case ErrSignaled: */
  213. return True;
  214. }
  215. return False;
  216. }
  217. static int ErrMsgDisabled(error)
  218. ximsError error;
  219. {
  220. switch (error) {
  221. case NoError: case ErrIsNone: case ErrNotRun:
  222. case ErrImsWaiting: case ErrImsWaitDone:
  223. case ErrImsConnecting: case ErrImsConnectDone:
  224. return True;
  225. case ErrSignaled:
  226. return (Verbose <= 2);
  227. case ErrInvState: case ErrInternal:
  228. return (Verbose <= 3);
  229. }
  230. return False;
  231. }
  232. int ErrFilePathNeeded(error)
  233. ximsError error;
  234. {
  235. switch (error) {
  236. case ErrFileOpen: case ErrFileCreate: case ErrDirCreate:
  237. case ErrMissEntry: case ErrNoExecutable: case ErrImsAborted:
  238. case ErrOpenResource:
  239. return True;
  240. }
  241. return False;
  242. }
  243. int InWaitingState()
  244. {
  245. switch (OpState) {
  246. case State_Init_Err:
  247. case State_Finish_Defered:
  248. case State_Mode_Done:
  249. return True;
  250. }
  251. return False;
  252. }
  253. void ximsMain()
  254. {
  255. static int call_cnt = 0;
  256. call_cnt++;
  257. DPR(("\nximsMain(call_cnt=%d): OpState=%s OpErrCode=%s[%d]\n",
  258. call_cnt, StateName(), error_name(OpErrCode), OpErrCode));
  259. #ifdef DEBUG
  260. pr_brk("ximsMain");
  261. #endif
  262. if (OpFlag & FLAG_REMOTERUN) {
  263. int ret;
  264. if ((ret = prepare_remote(WIN_ST_REMOTE_RUN)) != NoError) {
  265. Exit(ret);
  266. }
  267. }
  268. switch (OpState) {
  269. case State_Init_Done: if (Verbose > 1)
  270. put_xims_log("Started.", 0, 0, 0);
  271. ximsSelect();
  272. case State_Select_Done:
  273. case State_Select_Canceled: ximsStart();
  274. case State_Start_Done: ximsWait();
  275. case State_Init_Err:
  276. case State_Select_Err:
  277. case State_Start_Err:
  278. case State_Wait_Err:
  279. if (!WaitingDialogReply && !IsNoError(OpErrCode)) {
  280. LastErrMsg = OpErrCode;
  281. put_xims_errmsg(OpErrCode, 0, 0, 0);
  282. }
  283. case State_Wait_Done:
  284. ximsFinish();
  285. case State_Finish:
  286. if (WaitingDialogReply) {
  287. DPR(("ximsMain(): enter xevent_loop()\n"));
  288. xevent_loop(); /* never returns */
  289. WaitingDialogReply = False; /* if failed */
  290. }
  291. case State_Finish_Defered:
  292. if (OpState == State_Finish_Defered) {
  293. WaitingDialogReply = False;
  294. ximsFinish();
  295. }
  296. case State_Finish_Done: break;
  297. case State_Finish_Err: break;
  298. case State_Mode_Done:
  299. case State_Mode_Canceled: break;
  300. default:
  301. OpErrCode = ErrInvState; break;
  302. }
  303. Exit(OpErrCode);
  304. }
  305. void ximsFinish()
  306. {
  307. OpStateVal oldOpState = OpState;
  308. DPR(("ximsFinish(): OpState=%s OpErrCode=%s[%d]\n",
  309. StateName(), error_name(OpErrCode), OpErrCode));
  310. OpState = State_Finish;
  311. if (oldOpState != State_Finish_Defered) {
  312. if (!(OpFlag & FLAG_NORESOURCE) && isXsession())
  313. restore_resources();
  314. if (WaitingDialogReply) {
  315. DPR2(("ximsFinish(): OpState => State_Finish_Defered\n"));;
  316. OpState = State_Finish_Defered;
  317. return;
  318. }
  319. }
  320. if (OpMode == MODE_START && (OpFlag & FLAG_ENV)) {
  321. if (userSel.name && EnvNeeded(OpErrCode)) {
  322. OutEnv outEnv;
  323. CLR(&outEnv, OutEnv);
  324. if (make_new_environ(&outEnv, &userSel) == NoError) {
  325. put_new_environ(&outEnv);
  326. clear_OutEnv(&outEnv);
  327. }
  328. } else {
  329. DPR(("ximsFinish(): Not put env (pri->status=%s[%d])\n",
  330. error_name(userSel.renv->status), userSel.renv->status));
  331. }
  332. }
  333. /* if (IsNoError(OpErrCode)) OpErrCode = NoError; */
  334. OpState = State_Finish_Done;
  335. return;
  336. }
  337. static int ximsShowImsList()
  338. {
  339. int ret;
  340. int i;
  341. int host_type = HOST_LOCAL;
  342. char *hostname;
  343. ImsList *list = (ImsList *) 0;
  344. DPR(("ximsShowImsList()\n"));
  345. hostname = Opt.HostName;
  346. if (hostname) {
  347. host_type = check_hostname(hostname);
  348. userSel.hostname = NEWSTR(hostname); /* for error msg */
  349. }
  350. switch (host_type) {
  351. case HOST_UNKNOWN:
  352. ret = ErrUnknownHost;
  353. break;
  354. case HOST_REMOTE:
  355. ret = get_remote_conf(&list, hostname, NULL, NULL);
  356. break;
  357. case HOST_LOCAL:
  358. ret = get_ims_list(&list, NULL, True);
  359. break;
  360. }
  361. if (ret != NoError) {
  362. DPR2(("ximsShowImsList: ret=%s[%d]\n", error_name(ret), ret));
  363. /* return ret; */
  364. } else if (Verbose < 1) {
  365. for (i = 0; i < list->num_ent; i++)
  366. puts(list->elist[i]->name);
  367. } else {
  368. int err, len;
  369. for (i = 0; i < list->num_ent; i++) {
  370. /* If invoked from dtstyle with -listname put the "#" if this is
  371. the default one. */
  372. if (Opt.Listname == 1)
  373. if (i == list->default_idx)
  374. putchar('#');
  375. err = list->elist[i]->status;
  376. if (err) putchar('(');
  377. fputs(list->elist[i]->name, stdout);
  378. if (err) putchar(')');
  379. /* If invoked from dtstyle with -listname put the label */
  380. if (Opt.Listname == 1) {
  381. putchar(' ');
  382. fputs(list->elist[i]->label, stdout);
  383. }
  384. if (Verbose > 1) {
  385. char *msg = "cannot execute";
  386. switch (err) {
  387. case NoError:
  388. msg = "ok"; break;
  389. case ErrNoExecutable:
  390. msg = "no executable file"; break;
  391. case ErrNoImsConf:
  392. msg = "no configuration file"; break;
  393. case ErrMissEntry:
  394. msg = "invalid configuration file"; break;
  395. }
  396. len = strlen(list->elist[i]->name) + (err ? 2 : 0);
  397. for ( ; len < 16; len++) putchar(' ');
  398. putchar(' '); putchar('['); fputs(msg, stdout); putchar(']');
  399. }
  400. putchar('\n');
  401. }
  402. }
  403. fflush(stdout);
  404. if (list) {
  405. clear_ImsList(list); FREE(list);
  406. }
  407. return NoError;
  408. }
  409. static int ximsShowCurrentIms()
  410. {
  411. int ret = NoError;
  412. FileSel *fsel;
  413. DPR(("ximsShowCurrentIms()\n"));
  414. if (read_user_selection(&fsel, NULL) != NoError) {
  415. DPR2(("No selection file.\n"));
  416. return ErrNoSelectionFile;
  417. }
  418. if (fsel->name) {
  419. if (fsel->hostname)
  420. printf("%s\t[on %s]\n", fsel->name, fsel->hostname);
  421. else
  422. puts(fsel->name);
  423. fflush(stdout);
  424. } else {
  425. DPR2(("No IMS selected.\n"));
  426. ret = ErrNoSelection;
  427. }
  428. clear_FileSel(fsel); FREE(fsel);
  429. return ret;
  430. }
  431. static int prepare_remote(win_st)
  432. int win_st;
  433. {
  434. int ret;
  435. char **av = NULL;
  436. int ac = 0;
  437. int cur_st;
  438. DPR(("prepare_remote()\n"));
  439. #ifndef DEBUG
  440. Verbose = DebugLvl = 0; /* disable error messages */
  441. #endif
  442. UseMsgWindow = False;
  443. if ((ret = init_window_env()) != NoError)
  444. return ret;
  445. if (winEnv.atom_owner == None)
  446. return ErrRemoteData;
  447. cur_st = get_window_status();
  448. if (cur_st != win_st) {
  449. DPR(("prepare_remote(): invalid status '%d', should be '%d'\n",
  450. cur_st, win_st));
  451. return ErrRemoteData;
  452. }
  453. ret = get_window_data(&ac, &av); /* additional options */
  454. if (ret != NoError) {
  455. DPR(("prepare_remote(): get_window_data (%s[%d])\n",
  456. error_name(ret), ret));
  457. }
  458. if (ret == NoError) {
  459. ret = parse_options(ac, av);
  460. if (ret != NoError) {
  461. DPR(("secondary parse_options(): failed (%s[%d])\n",
  462. error_name(ret), ret));
  463. }
  464. }
  465. return NoError;
  466. }
  467. static int ximsRemoteConf()
  468. {
  469. int ret;
  470. char *locale;
  471. DPR(("ximsRemoteConf()\n"));
  472. if ((ret = prepare_remote(WIN_ST_REMOTE_CONF)) != NoError)
  473. return ret;
  474. locale = userEnv.real_locale ? userEnv.real_locale : userEnv.locale;
  475. ret = put_remote_conf(locale, Opt.ImsName);
  476. return ret;
  477. }
  478. static int ximsSetMode()
  479. {
  480. int ret = NoError;
  481. int cur_mode = SEL_MODE_NONE;
  482. ImsList imsList;
  483. DPR(("ximsSetMode(op=%d)\n", Opt.SelectMode));
  484. OpState = State_Mode;
  485. if ((ret = read_localeconf(&imsList, NULL)) != NoError) {
  486. DPR(("ximsSetMode(%s) locale '%s' isn't supported\n", userEnv.locale));
  487. /* return ErrNoLocaleConf; */
  488. }
  489. cur_mode = get_select_mode();
  490. if (cur_mode != SEL_MODE_AUTO && cur_mode != SEL_MODE_NOAUTO)
  491. cur_mode = imsList.def_selmode;
  492. switch (Opt.SelectMode) {
  493. case SEL_MODE_NONE:
  494. case SEL_MODE_QUERY: show_select_mode(cur_mode);
  495. break;
  496. case SEL_MODE_WIN: start_mode_window(cur_mode);
  497. /* never returned */
  498. break;
  499. #ifdef SelectMode_ONCE
  500. case SEL_MODE_ONCE:
  501. #endif /* SelectMode_ONCE */
  502. case SEL_MODE_AUTO:
  503. case SEL_MODE_NOAUTO: ret = set_select_mode(cur_mode, Opt.SelectMode);
  504. break;
  505. }
  506. OpErrCode = ret;
  507. OpState = State_Mode_Done;
  508. return ret;
  509. }
  510. static void show_select_mode(mode)
  511. int mode;
  512. {
  513. char *valp;
  514. printf("%s: \t", (catgets(catd,NL_SETN,20, "SelectMode")));
  515. switch (mode) {
  516. default:
  517. #ifdef DEBUG
  518. case SEL_MODE_NONE: valp = "<NOT DEFINED>"; /* break; */
  519. #endif
  520. case SEL_MODE_NOAUTO:
  521. valp = (catgets(catd,NL_SETN,21, "ask_at_login"));
  522. break;
  523. case SEL_MODE_AUTO:
  524. valp = (catgets(catd,NL_SETN,22, "resume_current_input_method"));
  525. break;
  526. #ifdef SelectMode_ONCE
  527. case SEL_MODE_ONCE:
  528. valp = "auto-selection if once selected";
  529. break;
  530. #endif /* SelectMode_ONCE */
  531. }
  532. puts(valp); fflush(stdout);
  533. return;
  534. }
  535. static int set_locale_env(locale)
  536. char *locale;
  537. {
  538. char *env_name, *env_value, *bp, *vp, buf[BUFSIZ], buf2[BUFSIZ];
  539. static char *last_lang_env[2] = { NULL, NULL };
  540. buf[0] = buf2[0] = 0;
  541. env_name = "LANG";
  542. env_value = getenv(env_name);
  543. if (env_value)
  544. strcpy(buf, env_value);
  545. if (locale && *locale) {
  546. if (!*buf || strcmp(locale, buf)) {
  547. bp = strcpyx(buf, env_name); *bp++ = '=';
  548. strcpyx(bp, locale);
  549. putenv(bp = NEWSTR(buf));
  550. FREE(last_lang_env[0]);
  551. last_lang_env[0] = bp;
  552. }
  553. } else if (*buf)
  554. locale = buf;
  555. else
  556. return ErrNoLocale;
  557. env_name = "LC_ALL";
  558. env_value = getenv(env_name);
  559. if (env_value)
  560. strcpy(buf2, env_value);
  561. if (!*buf2 || strcmp(locale, buf2)) {
  562. bp = strcpyx(buf2, env_name); *bp++ = '=';
  563. strcpyx(bp, locale);
  564. putenv(bp = NEWSTR(buf2));
  565. FREE(last_lang_env[1]);
  566. last_lang_env[1] = bp;
  567. }
  568. setlocale(LC_ALL, locale);
  569. /* set XFILESEARCHPATH */
  570. vp = getenv(ENV_XFILESEARCHPATH);
  571. bp = strcpyx(buf, ENV_XFILESEARCHPATH);
  572. bp = strcpyx(bp, "=");
  573. if (vp) {
  574. bp = strcpyx(bp, vp);
  575. bp = strcpyx(bp, ":");
  576. }
  577. bp = strcpyx(bp, ENV_XFILESEARCHPATH_STRING);
  578. putenv(NEWSTR(buf));
  579. /* set NLSPATH */
  580. vp = getenv(ENV_NLSPATH);
  581. bp = strcpyx(buf, ENV_NLSPATH);
  582. bp = strcpyx(bp, "=");
  583. if (vp) {
  584. bp = strcpyx(bp, vp);
  585. bp = strcpyx(bp, ":");
  586. }
  587. bp = strcpyx(bp, ENV_NLSPATH_STRING);
  588. putenv(NEWSTR(buf));
  589. #ifdef NLS
  590. if (catd != (nl_catd) -1) (void) catclose(catd);
  591. catd = (nl_catd) -1; (void) catclose(catd);
  592. if (Verbose > 0) {
  593. catd = catopen(DTIMS_PROGNAME, 0);
  594. }
  595. #endif /* NLS */
  596. return NoError;
  597. }
  598. static void init_command(progname)
  599. char *progname;
  600. {
  601. /* globals */
  602. ProgramName = progname;
  603. if (progname = strrchr(progname, '/'))
  604. ProgramName = progname + 1;
  605. #ifdef unused
  606. if (strstr(ProgramName, "mode")) ProgramType = MODE_MODE;
  607. else if (strstr(ProgramName, "list")) ProgramType = MODE_LIST;
  608. else if (strstr(ProgramName, "current")) ProgramType = MODE_CURRENT;
  609. else if (strstr(ProgramName, "conf")) ProgramType = MODE_REMCONF;
  610. else
  611. #endif
  612. ProgramType = MODE_START;
  613. OpState = State_None;
  614. OpMode = ProgramType;
  615. OpFlag = FLAG_DEFAULT;
  616. OpErrCode = NoError;
  617. LogFp = stderr;
  618. Wargc = 0;
  619. Wargv = NULL;
  620. WaitingDialogReply = False;
  621. WaitingActionDone = False;
  622. UseMsgWindow = True;
  623. IsRemote = False;
  624. LastErrMsg = NoError;
  625. Verbose = 1;
  626. DebugLvl = 0;
  627. ximsErrArgs[0] = ximsErrArgs[1] = ximsErrArgs[2] = (void *) 0;
  628. errFilePath[0] = 0;
  629. errFuncName = NULL;
  630. CLR(&Conf, CmdConf);
  631. CLR(&Opt, CmdOpt);
  632. CLR(&winEnv, WinEnv);
  633. CLR(&userEnv, UserEnv);
  634. CLR(&userSel, UserSelection);
  635. localList = (ImsList *) 0;
  636. return;
  637. }
  638. static bool optname_match(name, str, minlen)
  639. char *name, *str;
  640. int minlen;
  641. {
  642. int nlen, slen;
  643. if (strcmp(name, str) == 0) return True;
  644. nlen = strlen(name);
  645. slen = strlen(str);
  646. if (slen >= nlen || slen < minlen) return False;
  647. if (strncmp(name, str, slen) == 0) return True;
  648. return False;
  649. }
  650. static int parse_options(argc, argv)
  651. int argc;
  652. char **argv;
  653. {
  654. char *opt;
  655. int i, n;
  656. int wac = 1;
  657. char *wav[80];
  658. int orgMode;
  659. static bool first_time = True;
  660. #define SET_FLAG(f) OpFlag |= (f)
  661. #define CLR_FLAG(f) OpFlag &= ~(f)
  662. #define CHK_FLAG(f) (OpFlag & (f))
  663. if (first_time) {
  664. argc--; argv++;
  665. /* preset */
  666. Opt.Listname = 0;
  667. orgMode = OpMode;
  668. if (orgMode == MODE_START) SET_FLAG(FLAG_WINDOW);
  669. Opt.SelectMode = SEL_MODE_NONE;
  670. }
  671. for (i = 0; i < argc; i++) {
  672. opt = argv[i];
  673. if (*opt++ != '-') goto _inv_opt;
  674. /* option for MODE */
  675. if (optname_match("mode", opt, 2)) {
  676. if (orgMode != MODE_START && orgMode != MODE_MODE)
  677. goto _inv_opt;
  678. OpMode = MODE_MODE;
  679. #if 0 /* not implemented yet */
  680. } else if (optname_match("style", opt, 3)) {
  681. if (orgMode != MODE_START && orgMode != MODE_MODE)
  682. goto _inv_opt;
  683. OpMode = MODE_STYLE;
  684. #endif
  685. } else if (optname_match("listname", opt, 5)) {
  686. if (orgMode != MODE_START && orgMode != MODE_LISTNAME)
  687. goto _inv_opt;
  688. OpMode = MODE_LISTNAME;
  689. Opt.Listname = 1;
  690. } else if (optname_match("list", opt, 2)) {
  691. if (orgMode != MODE_START && orgMode != MODE_LIST)
  692. goto _inv_opt;
  693. OpMode = MODE_LIST;
  694. } else if (optname_match("current", opt, 2)) {
  695. if (orgMode != MODE_START && orgMode != MODE_CURRENT)
  696. goto _inv_opt;
  697. OpMode = MODE_CURRENT;
  698. } else if (optname_match("remoteconf", opt, 7)) {
  699. if (orgMode != MODE_START && orgMode != MODE_REMCONF)
  700. goto _inv_opt;
  701. OpMode = MODE_REMCONF;
  702. SET_FLAG(FLAG_NOTIFY);
  703. /* option for FLAG */
  704. } else if (optname_match("nosave", opt, 4)) {
  705. SET_FLAG(FLAG_NOSAVE);
  706. } else if (optname_match("nostart", opt, 4)) {
  707. SET_FLAG(FLAG_NOSTART);
  708. } else if (optname_match("noenv", opt, 4)) {
  709. CLR_FLAG(FLAG_ENV);
  710. } else if (optname_match("envonly", opt, 4)) {
  711. SET_FLAG(FLAG_NOSTART|FLAG_ENV);
  712. } else if (optname_match("env", opt, 2)) {
  713. SET_FLAG(FLAG_ENV);
  714. } else if (optname_match("nowait", opt, 4)) {
  715. SET_FLAG(FLAG_NOWAIT);
  716. } else if (optname_match("notimeout", opt, 5)) {
  717. SET_FLAG(FLAG_NOTIMEOUT);
  718. } else if (optname_match("noresource", opt, 5)) {
  719. SET_FLAG(FLAG_NORESOURCE);
  720. } else if (optname_match("noremote", opt, 5)) {
  721. SET_FLAG(FLAG_NOREMOTE);
  722. } else if (optname_match("notify", opt, 5)) {
  723. SET_FLAG(FLAG_NOTIFY);
  724. } else if (optname_match("connect", opt, 4)) {
  725. SET_FLAG(FLAG_CONNECT);
  726. } else if (optname_match("dt", opt, 2)) {
  727. SET_FLAG(FLAG_DT);
  728. # ifdef old_hpux
  729. CLR_FLAG(FLAG_VUE);
  730. } else if (optname_match("vue", opt, 2)) {
  731. SET_FLAG(FLAG_VUE);
  732. CLR_FLAG(FLAG_DT);
  733. # endif /* old_hpux */
  734. } else if (optname_match("window", opt, 2)) {
  735. SET_FLAG(FLAG_WINDOW);
  736. } else if (optname_match("nowindow", opt, 4)) {
  737. CLR_FLAG(FLAG_WINDOW);
  738. } else if (optname_match("remoterun", opt, 7)) {
  739. SET_FLAG(FLAG_REMOTERUN);
  740. SET_FLAG(FLAG_NOTIFY);
  741. } else if (optname_match("auto", opt, 2)) {
  742. Opt.SelectMode = SEL_MODE_AUTO;
  743. } else if (optname_match("noauto", opt, 3)) {
  744. Opt.SelectMode = SEL_MODE_NOAUTO;
  745. #ifdef SelectMode_ONCE
  746. } else if (optname_match("once", opt, 3)) {
  747. Opt.SelectMode = SEL_MODE_ONCE;
  748. #endif /* SelectMode_ONCE */
  749. /* help, verbose & debug options */
  750. } else if (optname_match("help", opt, 1)) {
  751. if (first_time)
  752. do_usage = True;
  753. } else if (optname_match("quiet", opt, 1)) {
  754. Verbose = DebugLvl = 0;
  755. } else if (optname_match("verbose", opt, 1)) {
  756. Verbose++;
  757. } else if (optname_match("debug", opt, 2)) {
  758. Verbose++; DebugLvl++;
  759. } else if (i >= argc - 1 || !*(argv[i+1])) {
  760. goto _inv_opt; /* the rest options need an argument */
  761. /* options with an argument */
  762. } else if (optname_match("imsoption", opt, 4)) {
  763. i++;
  764. Opt.ImsOption = argv[i];
  765. } else if (optname_match("ims", opt, 2)) {
  766. i++;
  767. Opt.ImsName = argv[i];
  768. } else if (optname_match("display", opt, 2)) {
  769. i++;
  770. Opt.DisplayName = argv[i];
  771. wav[wac++] = argv[i - 1]; wav[wac++] = argv[i]; /* ??? */
  772. } else if (optname_match("locale", opt, 2)) {
  773. i++;
  774. Opt.LocaleName = argv[i];
  775. } else if (optname_match("CDE_locale", opt, 2)) {
  776. i++;
  777. Opt.LocaleName = find_system_locale_name(argv[i]);
  778. } else if (optname_match("hostname", opt, 2)) {
  779. i++;
  780. Opt.HostName = argv[i];
  781. } else if (optname_match("config", opt, 2)) {
  782. i++;
  783. Opt.ConfPath = argv[i];
  784. } else if (optname_match("file", opt, 2)) {
  785. i++;
  786. Opt.UserPath = argv[i];
  787. } else if (optname_match("log", opt, 2)) {
  788. i++;
  789. Opt.LogPath = argv[i];
  790. } else if (optname_match("resource", opt, 3)) {
  791. i++;
  792. Opt.ResourceFile = argv[i];
  793. } else if (optname_match("shell", opt, 2)) {
  794. i++;
  795. Opt.ShellName = argv[i];
  796. } else if (optname_match("timeout", opt, 3)) {
  797. i++;
  798. if (str_to_int(argv[i], &n) && n >= 0)
  799. Opt.Timeout = n;
  800. } else if (optname_match("interval", opt, 3)) {
  801. i++;
  802. if (str_to_int(argv[i], &n) && n >= 0)
  803. Opt.Interval = n;
  804. /* Xt options */
  805. } else if (optname_match("font", opt, 2)
  806. || optname_match("fn", opt, 2)
  807. || optname_match("fg", opt, 2)
  808. || optname_match("bg", opt, 2)
  809. || optname_match("bd", opt, 2)
  810. || optname_match("foreground", opt, 4)
  811. || optname_match("backgroundg", opt, 4)
  812. || optname_match("bordercolor", opt, 4)
  813. || optname_match("geometry", opt, 2)
  814. || optname_match("title", opt, 2)
  815. || optname_match("xnlLanguage", opt, 3)
  816. /* || optname_match("iconic", opt, 4) */
  817. || optname_match("xrm", opt, 2)) {
  818. i++;
  819. wav[wac++] = argv[i - 1]; wav[wac++] = argv[i];
  820. } else
  821. goto _inv_opt;
  822. }
  823. first_time = False;
  824. if (do_usage) return NoError;
  825. switch (OpMode) { /* adjust OpFlag */
  826. #if 0 /* noy implemented yet */
  827. case MODE_STYLE:
  828. SET_FLAG(FLAG_DT | FLAG_WINDOW);
  829. CLR_FLAG(FLAG_VUE);
  830. break;
  831. #endif
  832. case MODE_START:
  833. if (Opt.ImsName) {
  834. SET_FLAG(FLAG_NOSAVE);
  835. /* CLR_FLAG(USE_WINDOW_MASK); */
  836. Opt.SelectMode = SEL_MODE_GIVEN;
  837. }
  838. if (Opt.LogPath) { /* open log file */
  839. if (set_errorlog(Opt.LogPath) != NoError)
  840. Opt.LogPath = NULL;
  841. }
  842. if (CHK_FLAG(FLAG_REMOTERUN)) {
  843. SET_FLAG(FLAG_NOTIFY);
  844. SET_FLAG(FLAG_NOSAVE);
  845. CLR_FLAG(USE_WINDOW_MASK);
  846. }
  847. break;
  848. case MODE_MODE:
  849. if (CHK_FLAG(FLAG_WINDOW)) {
  850. Opt.SelectMode = SEL_MODE_WIN;
  851. } else if (Opt.SelectMode == SEL_MODE_NONE) {
  852. Opt.SelectMode = SEL_MODE_QUERY;
  853. CLR_FLAG(USE_WINDOW_MASK);
  854. }
  855. break;
  856. case MODE_LISTNAME:
  857. SET_FLAG(FLAG_WINDOW);
  858. break;
  859. default:
  860. CLR_FLAG(USE_WINDOW_MASK);
  861. break;
  862. }
  863. if (CHK_FLAG(USE_WINDOW_MASK)) {
  864. /* create argc & argv for window */
  865. Wargv = ALLOC(wac + 1 + 4, char *); /* spare for '-xnlLanguage' */
  866. memcpy(Wargv, wav, sizeof(char *) * wac);
  867. Wargv[0] = ProgramName;
  868. Wargv[wac] = NULL;
  869. Wargc = wac;
  870. } else {
  871. UseMsgWindow = False; /* disable msg window */
  872. }
  873. #undef CLR_FLAG
  874. #undef SET_FLAG
  875. #undef CHK_FLAG
  876. return NoError;
  877. _inv_opt:
  878. DPR(("%s: invalid option '%s'\n", ProgramName, argv[i]));
  879. setErrArg1(argv[i]);
  880. return ErrSyntax;
  881. }
  882. /* ******** usage ******** */
  883. #ifdef DEBUG
  884. typedef struct {
  885. char *name;
  886. char *desc;
  887. } OptDesc;
  888. #if 0
  889. static OptDesc opts_start[] = {
  890. { "-env", "print modified environment variables" },
  891. { "-shell <name>", "override $SHELL" },
  892. { "-ims <name>", "specifies input method name" },
  893. { "-imsopt <string>", "specifies command options for input method server" },
  894. { "-host <name>", "specifies host where input method server should be run" },
  895. { "-mode", "change input method selection mode" },
  896. { "-list", "show registered input method" },
  897. { "-help", "show this message" },
  898. { NULL, NULL }
  899. };
  900. static OptDesc opts_mode[] = {
  901. { "-auto", "enable auto-selection mode" },
  902. { "-noauto", "disable auto-selection mode" },
  903. { NULL, NULL }
  904. };
  905. #endif
  906. static OptDesc opts_internal[] = {
  907. { "-display <dpy>", "override $DISPLAY" },
  908. { "-current", "show selected input method" },
  909. { "-listname", "show registered input method for dtstyle" },
  910. { "-remoteconf", "print IMS configuration data for remote execution" },
  911. { "-remoterun", "start IMS as remote execution" },
  912. { "-nosave", "not save the selection" },
  913. { "-select", "force select" },
  914. { "-noenv", "disable printing environment variables" },
  915. { "-envonly", "-noenv & -nostart" },
  916. { "-nostart", "not start IMS" },
  917. { "-noresouce", "not load session resource files" },
  918. { "-nowait", "immediately exits after IMS invocation" },
  919. { "-notimeout", "do not timeout" },
  920. { "-noremote", "disable remote execution" },
  921. { "-notify", "print error code to stderr" },
  922. # ifdef old_hpux
  923. { "-vue", "in VUE environment" },
  924. { "-connect", "enable try_connect" },
  925. # endif /* old_hpux */
  926. #ifdef SelectMode_ONCE
  927. { "-once", "auto-selection once selected" },
  928. #endif /* SelectMode_ONCE */
  929. { "-dt" , "in CDE environment" },
  930. { "-window", "use window environment" },
  931. { "-nowindow", "do not use window environment" },
  932. { "-timeout <num>", "specifies timeout period (sec.)" },
  933. { "-interval <num>", "specifies check interval (msec.)" },
  934. { "-locale <locale>", "override $LANG" },
  935. { "-CDE_locale <CDE_locale>", "CDE generic locale name" },
  936. { "-resource <file>", "specifies resource file" },
  937. { "-config <file>", "specifies configuration file" },
  938. { "-file <file>", "specifies user selection file" },
  939. { "-log <file>", "specifies log file" },
  940. { "-fn <fontlist>", "specifies font" },
  941. { "-quiet", "print no messages" },
  942. { "-verbose", "print verbose messages" },
  943. { "-debug", "print debug messages" },
  944. { "<Xt options>", "standard X toolkit options" },
  945. { NULL, NULL }
  946. };
  947. #endif /* DEBUG */
  948. static void usage(force)
  949. int force;
  950. {
  951. char *fmt = "\t%-20s%s\n";
  952. if (!force && Verbose <= 0) return;
  953. fprintf(LogFp, (catgets(catd,NL_SETN,1, "usage: %s [options ..]")),
  954. ProgramName);
  955. putc('\n', LogFp);
  956. if (OpMode != MODE_MODE) {
  957. fprintf(LogFp, fmt,
  958. "-env", (catgets(catd,NL_SETN,2, "print modified environment variables")));
  959. fprintf(LogFp, fmt,
  960. "-shell <name>", (catgets(catd,NL_SETN,3, "override $SHELL")));
  961. fprintf(LogFp, fmt,
  962. "-ims <name>", (catgets(catd,NL_SETN,4, "specifies input method name")));
  963. fprintf(LogFp, fmt,
  964. "-imsopt <string>", (catgets(catd,NL_SETN,5, "specifies command options for input method server")));
  965. fprintf(LogFp, fmt,
  966. "-host <name>", (catgets(catd,NL_SETN,6, "specifies host where input method server should be run")));
  967. fprintf(LogFp, fmt,
  968. "-mode", (catgets(catd,NL_SETN,7, "change input method selection mode")));
  969. fprintf(LogFp, fmt,
  970. "-list", (catgets(catd,NL_SETN,8, "print registered input method")));
  971. fprintf(LogFp, fmt,
  972. "-help", (catgets(catd,NL_SETN,9, "show this message")));
  973. } else {
  974. fprintf(LogFp, fmt,
  975. "-auto", (catgets(catd,NL_SETN,23, "force 'resume_current_input_method' mode")));
  976. fprintf(LogFp, fmt,
  977. "-noauto", (catgets(catd,NL_SETN,24, "force 'ask_at_login' mode")));
  978. }
  979. #ifdef DEBUG
  980. if (Verbose > 1) {
  981. OptDesc *opts;
  982. fprintf(LogFp, "\n <internal options>\n");
  983. for (opts = opts_internal; opts->name; opts++)
  984. fprintf(LogFp, fmt, opts->name, opts->desc);
  985. }
  986. #endif
  987. }
  988. /* ******** error messages ******** */
  989. char *xims_errmsg(err_num, arg1, arg2, arg3)
  990. int err_num;
  991. void *arg1, *arg2, *arg3;
  992. {
  993. char *fmt = NULL, *bp;
  994. int len;
  995. static char msgbuf[BUFSIZ];
  996. switch (err_num) {
  997. case NoError:
  998. break;
  999. case ErrSyntax: /* arg1: option string */
  1000. fmt = (catgets(catd,NL_SETN,31, "invalid option '%s'"));
  1001. break;
  1002. case ErrNoHome:
  1003. fmt = (catgets(catd,NL_SETN,32, "environment variable 'HOME' not defined"));
  1004. break;
  1005. case ErrNoLocale:
  1006. fmt = (catgets(catd,NL_SETN,33, "environment variable 'LANG' not defined"));
  1007. break;
  1008. case ErrNoCDELocale:
  1009. fmt = (catgets(catd,NL_SETN,34, "this locale is not supported by the desktop."));
  1010. break;
  1011. case ErrNoDisplay:
  1012. fmt = (catgets(catd,NL_SETN,35, "environment variable 'DISPLAY' not defined"));
  1013. break;
  1014. case ErrFileOpen: /* arg1: file name */
  1015. fmt = (catgets(catd,NL_SETN,36, "cannot open file\n [%s]"));
  1016. setErrArg1(errFilePath);
  1017. break;
  1018. case ErrFileCreate: /* arg1: file name */
  1019. fmt = (catgets(catd,NL_SETN,37, "cannot create file\n [%s]"));
  1020. setErrArg1(errFilePath);
  1021. break;
  1022. case ErrDirCreate: /* arg1: dir name */
  1023. fmt = (catgets(catd,NL_SETN,38, "cannot create directory\n [%s]"));
  1024. setErrArg1(errFilePath);
  1025. break;
  1026. case ErrMissEntry: /* arg1: entry name, arg2: file name */
  1027. fmt = (catgets(catd,NL_SETN,39, "missing '%s' entry in configuration file\n [%s]"));
  1028. setErrArg2(errFilePath);
  1029. break;
  1030. case ErrAnotherProg:
  1031. fmt = (catgets(catd,NL_SETN,40, "another '%s' is already running"));
  1032. setErrArg1(ProgramName);
  1033. break;
  1034. case ErrNoSelectionFile: /* arg1: locale name */
  1035. fmt = (catgets(catd,NL_SETN,41, "no selection file for '%s'"));
  1036. setErrArg1(userEnv.locale);
  1037. break;
  1038. case ErrSaveSelection: /* arg1: file name */
  1039. fmt = (catgets(catd,NL_SETN,42, "cannot create selection file\n [%s]"));
  1040. setErrArg1(errFilePath);
  1041. break;
  1042. case ErrNoSelection: /* arg1: locale name */
  1043. fmt = (catgets(catd,NL_SETN,43, "no ims selected for '%s'"));
  1044. setErrArg1(userEnv.locale);
  1045. break;
  1046. case ErrNoLocaleConf: /* arg1: file name */
  1047. fmt = (catgets(catd,NL_SETN,44, "no locale configuration file for '%s'"));
  1048. setErrArg1(userEnv.locale);
  1049. break;
  1050. case ErrNoImsEntry: /* arg1: locale name */
  1051. fmt = (catgets(catd,NL_SETN,45, "no ims configured for '%s'"));
  1052. setErrArg1(userEnv.locale);
  1053. break;
  1054. case ErrNoImsConf: /* arg1: ims name */
  1055. fmt = (catgets(catd,NL_SETN,46, "no ims configuration file for '%s'"));
  1056. setErrArg1(userSel.name);
  1057. break;
  1058. case ErrNotRegistered: /* arg1: ims name */
  1059. fmt = (catgets(catd,NL_SETN,47, "ims '%s' not registered"));
  1060. setErrArg1(userSel.name);
  1061. break;
  1062. case ErrNoExecutable: /* arg1: ims name, arg2: file name */
  1063. fmt = (catgets(catd,NL_SETN,48, "no executable file for '%s'\n [%s]"));
  1064. setErrArg1(userSel.name);
  1065. setErrArg2(userSel.ent->ims->cmd_path);
  1066. break;
  1067. case ErrImsRunning: /* arg1: ims name */
  1068. fmt = (catgets(catd,NL_SETN,49, "ims '%s' is already running"));
  1069. setErrArg1(userSel.name);
  1070. break;
  1071. case ErrImsExecution: /* arg1: ims name */
  1072. fmt = (catgets(catd,NL_SETN,50, "cannot execute ims '%s'"));
  1073. setErrArg1(userSel.name);
  1074. break;
  1075. case ErrImsAborted: /* arg1: ims name, arg2: log file */
  1076. fmt = (catgets(catd,NL_SETN,51, "ims '%s' aborted. See log file.\n [%s]"));
  1077. setErrArg1(userSel.name);
  1078. if (userSel.host_type == HOST_REMOTE)
  1079. setErrArg2(errFilePath);
  1080. else
  1081. setErrArg2(Opt.LogPath);
  1082. break;
  1083. case ErrImsTimeout: /* arg1: file name */
  1084. fmt = (catgets(catd,NL_SETN,52, "ims '%s' is not available yet"));
  1085. setErrArg1(userSel.name);
  1086. break;
  1087. case ErrUnknownHost: /* arg1: host name */
  1088. fmt = (catgets(catd,NL_SETN,53, "unknown host '%s'"));
  1089. setErrArg1(userSel.hostname);
  1090. break;
  1091. case ErrRemoteAction: /* arg1: action name */
  1092. fmt = (catgets(catd,NL_SETN,54, "action '%s' failed"));
  1093. setErrArg1(errFuncName);
  1094. break;
  1095. case ErrRemoteData: /* arg1: host name */
  1096. fmt = (catgets(catd,NL_SETN,55, "remote execution failed on '%s'"));
  1097. setErrArg1(userSel.hostname);
  1098. break;
  1099. case ErrNoImsstart: /* arg1: host name */
  1100. fmt = (catgets(catd,NL_SETN,56, "remote functionality is not available on '%s'"));
  1101. setErrArg1(userSel.hostname);
  1102. break;
  1103. case ErrRemoteNoIms: /* arg1: host name */
  1104. fmt = (catgets(catd,NL_SETN,57, "no ims registered on '%s'"));
  1105. setErrArg1(userSel.hostname);
  1106. break;
  1107. case ErrRemoteMissIms: /* arg1: ims name, arg2: host name */
  1108. fmt = (catgets(catd,NL_SETN,58, "ims '%1$s' not registered on '%2$s'"));
  1109. setErrArg1(userSel.name);
  1110. setErrArg2(userSel.hostname);
  1111. break;
  1112. case ErrOpenDpy: /* arg1: display name */
  1113. fmt = (catgets(catd,NL_SETN,59, "cannot open display '%s'"));
  1114. setErrArg1(userEnv.displayname);
  1115. break;
  1116. #ifdef DEBUG
  1117. case ErrSignaled: /* arg1: signal number */
  1118. fmt = "terminated by signal (signal=%d)";
  1119. setErrArg1(exitSignalNumber);
  1120. break;
  1121. case ErrDisabled: /* arg1: program name, arg2: env name */
  1122. fmt = "ximsstart is disabled ('%s' is set)";
  1123. setErrArg1(ENV_NO_DTIMSSTART);
  1124. break;
  1125. case ErrRemoteIms: /* arg1: ims name, arg2: host name */
  1126. fmt = "cannot execute ims '%s' on '%s'";
  1127. setErrArg1(userSel.name);
  1128. setErrArg2(userSel.hostname);
  1129. break;
  1130. case ErrOpenResource: /* arg1: file name */
  1131. fmt = "cannot open resource file\n [%s]";
  1132. setErrArg1(Opt.ResourceFile);
  1133. break;
  1134. case ErrMemory: /* arg1: function name */
  1135. fmt = "cannot allocate memory in %s()";
  1136. setErrArg1(errFuncName);
  1137. break;
  1138. case ErrIsNone: /* arg1: ims name */
  1139. fmt = "the selected ims is '%s'";
  1140. setErrArg1(userSel.name);
  1141. break;
  1142. case ErrNotRun: /* arg1: ims name */
  1143. fmt = "the selected ims '%s' need not to run";
  1144. setErrArg1(userSel.name);
  1145. break;
  1146. case ErrImsWaiting: /* arg1: ims name */
  1147. fmt = "internal error [ImsWaiting] (ims='%s')";
  1148. setErrArg1(userSel.name);
  1149. break;
  1150. case ErrImsWaitDone: /* arg1: ims name */
  1151. fmt = "internal error [ImsWaitDone] (ims='%s')";
  1152. setErrArg1(userSel.name);
  1153. break;
  1154. case ErrImsConnecting: /* arg1: ims name */
  1155. fmt = "internal error [ImsConnecting] (ims='%s')";
  1156. setErrArg1(userSel.name);
  1157. break;
  1158. case ErrImsConnectDone: /* arg1: ims name */
  1159. fmt = "internal error [ImsConnectDone] (ims='%s')";
  1160. setErrArg1(userSel.name);
  1161. break;
  1162. case ErrInvState: /* arg1: OpStateVal */
  1163. fmt = "internal error [invalid state: '%d']";
  1164. setErrArg1(OpState);
  1165. break;
  1166. case ErrInternal: /* arg1: function name */
  1167. fmt = "internal error in %s()";
  1168. setErrArg1(errFuncName);
  1169. break;
  1170. #endif /* DEBUG */
  1171. }
  1172. if (!fmt) return NULL;
  1173. bp = strcpyx(msgbuf, ProgramName); *bp++ = ':'; *bp++ = ' ';
  1174. if (!arg1) arg1 = ximsErrArgs[0];
  1175. if (!arg2) arg2 = ximsErrArgs[1];
  1176. if (!arg3) arg3 = ximsErrArgs[2];
  1177. sprintf(bp, fmt, arg1, arg2, arg3);
  1178. len = strlen(bp);
  1179. bp[len++] = '\n'; bp[len] = '\0';
  1180. return msgbuf;
  1181. }