main.c 35 KB

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