resource.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  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: resource.c /main/4 1996/06/19 09:47:56 mustafa $ */
  24. /*
  25. */
  26. /* *
  27. * (c) Copyright 1993, 1994 Hewlett-Packard Company *
  28. * (c) Copyright 1993, 1994 International Business Machines Corp. *
  29. * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
  30. * (c) Copyright 1993, 1994 Novell, Inc. *
  31. */
  32. /*-
  33. * resource.c - resource management for dtscreen, the X Window System lockscreen.
  34. *
  35. * Copyright (c) 1991 by Patrick J. Naughton.
  36. *
  37. * See dtscreen.c for copying information.
  38. *
  39. * Revision History:
  40. * 25-Sep-91: added worm mode.
  41. * 06-Jun-91: Added flame mode.
  42. * 16-May-91: Added random mode and pyro mode.
  43. * 26-Mar-91: CheckResources: delay must be >= 0.
  44. * 29-Oct-90: Added #include <ctype.h> for missing isupper() on some OS revs.
  45. * moved -mode option, reordered Xrm database evaluation.
  46. * 28-Oct-90: Added text strings.
  47. * 26-Oct-90: Fix bug in mode specific options.
  48. * 31-Jul-90: Fix ':' handling in parsefilepath
  49. * 07-Jul-90: Created from resource work in dtscreen.c
  50. *
  51. */
  52. #include <stdio.h>
  53. #include <stdlib.h>
  54. #include "dtscreen.h"
  55. #include <netdb.h>
  56. #include <math.h>
  57. #include <ctype.h>
  58. #include <X11/Xresource.h>
  59. /* include file for message texts */
  60. #include <limits.h>
  61. #include <nl_types.h>
  62. #define MF_DTSCREEN "dtscreen.cat"
  63. #include <locale.h>
  64. extern nl_catd scmc_catd; /* Cat descriptor for scmc conversion */
  65. /*
  66. * Declare external interface routines for supported screen savers.
  67. */
  68. extern void inithop();
  69. extern void drawhop();
  70. extern void initlife();
  71. extern void drawlife();
  72. extern void initqix();
  73. extern void drawqix();
  74. extern void initimage();
  75. extern void drawimage();
  76. extern void initblank();
  77. extern void drawblank();
  78. extern void initswarm();
  79. extern void drawswarm();
  80. extern void initrotor();
  81. extern void drawrotor();
  82. extern void initpyro();
  83. extern void drawpyro();
  84. extern void initflame();
  85. extern void drawflame();
  86. extern void initworm();
  87. extern void drawworm();
  88. void CheckResources(void);
  89. typedef struct {
  90. char *cmdline_arg;
  91. void (*lp_init) ();
  92. void (*lp_callback) ();
  93. int def_delay;
  94. int def_batchcount;
  95. float def_saturation;
  96. char *desc;
  97. } LockStruct;
  98. static char randomstring[] = "random";
  99. static LockStruct LockProcs[] = {
  100. {"hop", inithop, drawhop, 0, 1000, 1.0, "Hopalong iterated fractals"},
  101. {"qix", initqix, drawqix, 30000, 64, 1.0, "Spinning lines a la Qix(tm)"},
  102. {"image", initimage, drawimage, 2000000, 8, 0.3, "Random bouncing image"},
  103. {"life", initlife, drawlife, 1000000, 100, 1.0, "Conway's game of Life"},
  104. {"swarm", initswarm, drawswarm, 10000, 100, 1.0, "Swarm of bees"},
  105. {"rotor", initrotor, drawrotor, 10000, 4, 0.4, "Rotor"},
  106. {"pyro", initpyro, drawpyro, 15000, 40, 1.0, "Fireworks"},
  107. {"flame", initflame, drawflame, 10000, 20, 1.0, "Cosmic Flame Fractals"},
  108. {"worm", initworm, drawworm, 10000, 20, 1.0, "Wiggly Worms"},
  109. {"blank", initblank, drawblank, 5000000, 1, 1.0, "Blank screen"},
  110. {randomstring, NULL, NULL, 0, 0, 0.0, "Random mode"},
  111. };
  112. #define NUMPROCS (sizeof LockProcs / sizeof LockProcs[0])
  113. extern char *getenv();
  114. #ifndef DEF_FILESEARCHPATH
  115. #define DEF_FILESEARCHPATH "/usr/lib/X11/%T/%N%S"
  116. #endif
  117. #define DEF_DISPLAY ":0"
  118. #define DEF_MODE "swarm"
  119. #define DEF_BG "White"
  120. #define DEF_FG "Black"
  121. #define DEF_BC "100" /* vectors (or whatever) per batch */
  122. #define DEF_DELAY "200000"/* microseconds between batches */
  123. #define DEF_NICE "10" /* dtscreen process nicelevel */
  124. #define DEF_SAT "1.0" /* color ramp saturation 0->1 */
  125. #define DEF_CLASSNAME "Dtscreen"
  126. static char *classname;
  127. static char modename[1024];
  128. static char modeclass[1024];
  129. static XrmOptionDescRec genTable[] = {
  130. {"-mode", ".mode", XrmoptionSepArg, (caddr_t) NULL},
  131. {"-mono", ".mono", XrmoptionNoArg, (caddr_t) "on"},
  132. {"+mono", ".mono", XrmoptionNoArg, (caddr_t) "off"},
  133. {"-nice", ".nice", XrmoptionSepArg, (caddr_t) NULL},
  134. {"-create", ".create", XrmoptionNoArg, (caddr_t) "on"},
  135. };
  136. #define genEntries (sizeof genTable / sizeof genTable[0])
  137. /*************************************************************/
  138. /** This table was changed for AIX. In order to read these **/
  139. /** command line options properly, the specifier field must **/
  140. /** be built on the fly. **/
  141. /*************************************************************/
  142. static XrmOptionDescRec modeTable[] = {
  143. {"-delay", NULL, XrmoptionSepArg, (caddr_t) NULL},
  144. {"-batchcount", NULL, XrmoptionSepArg, (caddr_t) NULL},
  145. {"-saturation", NULL, XrmoptionSepArg, (caddr_t) NULL},
  146. };
  147. #define modeEntries (sizeof modeTable / sizeof modeTable[0])
  148. static XrmOptionDescRec cmdlineTable[] = {
  149. {"-display", ".display", XrmoptionSepArg, (caddr_t) NULL},
  150. {"-xrm", NULL, XrmoptionResArg, (caddr_t) NULL},
  151. };
  152. #define cmdlineEntries (sizeof cmdlineTable / sizeof cmdlineTable[0])
  153. static XrmOptionDescRec nameTable[] = {
  154. {"-name", ".name", XrmoptionSepArg, (caddr_t) NULL},
  155. };
  156. typedef struct {
  157. char *opt;
  158. char *desc;
  159. } OptionStruct;
  160. static OptionStruct opDesc[] = {
  161. {"-help", "print out this message"},
  162. {"-resources", "print default resource file to standard output"},
  163. {"-display displayname", "X server to contact"},
  164. {"-/+mono", "turn on/off monochrome override"},
  165. {"-delay usecs", "microsecond delay between screen updates"},
  166. {"-batchcount num", "number of things per batch"},
  167. {"-nice level", "nice level for dtscreen process"},
  168. {"-saturation value", "saturation of color ramp"},
  169. {"-create", "create a window in which to draw"},
  170. };
  171. #define opDescEntries (sizeof opDesc / sizeof opDesc[0])
  172. char *display;
  173. char *mode;
  174. float saturation;
  175. int nicelevel;
  176. int delay;
  177. int batchcount;
  178. Bool mono;
  179. Bool create;
  180. #define t_String 0
  181. #define t_Float 1
  182. #define t_Int 2
  183. #define t_Bool 3
  184. typedef struct {
  185. caddr_t *var;
  186. char *name;
  187. char *class;
  188. char *def;
  189. int type;
  190. } argtype;
  191. static argtype genvars[] = {
  192. {(caddr_t *) &nicelevel, "nice", "Nice", DEF_NICE, t_Int},
  193. {(caddr_t *) &mono, "mono", "Mono", "off", t_Bool},
  194. {(caddr_t *) &create, "create", "Create", "off", t_Bool},
  195. };
  196. #define NGENARGS (sizeof genvars / sizeof genvars[0])
  197. static argtype modevars[] = {
  198. {(caddr_t *) &delay, "delay", "Delay", DEF_DELAY, t_Int},
  199. {(caddr_t *) &batchcount, "batchcount", "BatchCount", DEF_BC, t_Int},
  200. {(caddr_t *) &saturation, "saturation", "Saturation", DEF_SAT, t_Float},
  201. };
  202. #define NMODEARGS (sizeof modevars / sizeof modevars[0])
  203. static void
  204. Syntax(char *badOption)
  205. {
  206. int col, len, i;
  207. #ifdef MIT_R5
  208. fprintf(stderr, "%s: bad command line option: %s.\n\n",
  209. ProgramName, badOption);
  210. #else
  211. fprintf(stderr, catgets(scmc_catd, 2, 1,
  212. "%s: Bad command line option: %s.\n\n"),
  213. ProgramName, badOption);
  214. #endif
  215. fprintf(stderr, "usage: %s", ProgramName);
  216. col = 8 + strlen(ProgramName);
  217. for (i = 0; i < opDescEntries; i++) {
  218. len = 3 + strlen(opDesc[i].opt); /* space [ string ] */
  219. if (col + len > 79) {
  220. fprintf(stderr, "\n "); /* 3 spaces */
  221. col = 3;
  222. }
  223. fprintf(stderr, " [%s]", opDesc[i].opt);
  224. col += len;
  225. }
  226. len = 8 + strlen(LockProcs[0].cmdline_arg);
  227. if (col + len > 79) {
  228. fprintf(stderr, "\n "); /* 3 spaces */
  229. col = 3;
  230. }
  231. fprintf(stderr, " [-mode %s", LockProcs[0].cmdline_arg);
  232. col += len;
  233. for (i = 1; i < NUMPROCS; i++) {
  234. len = 3 + strlen(LockProcs[i].cmdline_arg);
  235. if (col + len > 79) {
  236. fprintf(stderr, "\n "); /* 3 spaces */
  237. col = 3;
  238. }
  239. fprintf(stderr, " | %s", LockProcs[i].cmdline_arg);
  240. col += len;
  241. }
  242. fprintf(stderr, "]\n");
  243. #ifdef MIT_R5
  244. fprintf(stderr, "\nType %s -help for a full description.\n\n",
  245. ProgramName);
  246. #else
  247. fprintf(stderr, catgets(scmc_catd, 2, 2,
  248. "\nType %s -help for a full description.\n\n"),
  249. ProgramName);
  250. #endif
  251. exit(1);
  252. }
  253. static void
  254. Help(void)
  255. {
  256. int i;
  257. #ifdef MIT_R5
  258. fprintf(stderr, "usage:\n %s [-options ...]\n\n", ProgramName);
  259. fprintf(stderr, "where options include:\n");
  260. #else
  261. fprintf(stderr, catgets(scmc_catd, 2, 3,
  262. "Usage:\n %s [-options ...]\n\n\
  263. where options include:\n"), ProgramName);
  264. #endif
  265. for (i = 0; i < opDescEntries; i++) {
  266. fprintf(stderr, " %-28s %s\n", opDesc[i].opt, opDesc[i].desc);
  267. }
  268. #ifdef MIT_R5
  269. fprintf(stderr, " %-28s %s\n", "-mode mode", "animation mode");
  270. fprintf(stderr, " where mode is one of:\n");
  271. #else
  272. fprintf(stderr, catgets(scmc_catd, 2, 5,
  273. " %-28s %s\n\t where mode is one of:\n"),
  274. "-mode mode", "animation mode");
  275. #endif
  276. for (i = 0; i < NUMPROCS; i++) {
  277. fprintf(stderr, " %-23s %s\n",
  278. LockProcs[i].cmdline_arg, LockProcs[i].desc);
  279. }
  280. putc('\n', stderr);
  281. exit(0);
  282. }
  283. static void
  284. DumpResources(void)
  285. {
  286. int i;
  287. printf("%s.mode: %s\n", classname, DEF_MODE);
  288. for (i = 0; i < NGENARGS; i++)
  289. printf("%s.%s: %s\n",
  290. classname, genvars[i].name, genvars[i].def);
  291. for (i = 0; i < NUMPROCS - 1; i++) {
  292. printf("%s.%s.%s: %d\n", classname, LockProcs[i].cmdline_arg,
  293. "delay", LockProcs[i].def_delay);
  294. printf("%s.%s.%s: %d\n", classname, LockProcs[i].cmdline_arg,
  295. "batchcount", LockProcs[i].def_batchcount);
  296. printf("%s.%s.%s: %g\n", classname, LockProcs[i].cmdline_arg,
  297. "saturation", LockProcs[i].def_saturation);
  298. }
  299. exit(0);
  300. }
  301. static void
  302. LowerString(char *s)
  303. {
  304. while (*s) {
  305. if (isupper(*s))
  306. *s += ('a' - 'A');
  307. s++;
  308. }
  309. }
  310. static void
  311. GetResource(XrmDatabase database, char *parentname, char *parentclass,
  312. char *name, char *class, int valueType, char *def,
  313. caddr_t *valuep /* RETURN */)
  314. {
  315. char *type;
  316. XrmValue value;
  317. char *string;
  318. char buffer[1024];
  319. char fullname[1024];
  320. char fullclass[1024];
  321. int len;
  322. sprintf(fullname, "%s.%s", parentname, name);
  323. sprintf(fullclass, "%s.%s", parentclass, class);
  324. if (XrmGetResource(database, fullname, fullclass, &type, &value)) {
  325. string = value.addr;
  326. len = value.size;
  327. } else {
  328. string = def;
  329. len = strlen(string);
  330. }
  331. (void) strncpy(buffer, string, sizeof(buffer));
  332. buffer[sizeof(buffer) - 1] = '\0';
  333. switch (valueType) {
  334. case t_String:
  335. {
  336. char *s;
  337. s = (char *) malloc(len + 1);
  338. if (s == (char *) NULL)
  339. #ifdef MIT_R5
  340. error("%s: GetResource - couldn't allocate memory");
  341. #else
  342. {
  343. fprintf(stderr, catgets(scmc_catd, 2, 18,
  344. "%s: GetResource - couldn't allocate memory.\n"),ProgramName);
  345. exit(1);
  346. }
  347. #endif
  348. (void) strncpy(s, string, len);
  349. s[len] = '\0';
  350. *((char **) valuep) = s;
  351. }
  352. break;
  353. case t_Bool:
  354. LowerString(buffer);
  355. *((int *) valuep) = (!strcmp(buffer, "true") ||
  356. !strcmp(buffer, "on") ||
  357. !strcmp(buffer, "enabled") ||
  358. !strcmp(buffer, "yes")) ? True : False;
  359. break;
  360. case t_Int:
  361. *((int *) valuep) = atoi(buffer);
  362. break;
  363. case t_Float:
  364. *((float *) valuep) = (float) atof(buffer);
  365. break;
  366. }
  367. }
  368. static XrmDatabase
  369. parsefilepath(char *xfilesearchpath, char *TypeName, char *ClassName)
  370. {
  371. XrmDatabase database = NULL;
  372. char appdefaults[1024];
  373. char *src;
  374. char *dst;
  375. src = xfilesearchpath;
  376. appdefaults[0] = '\0';
  377. dst = appdefaults;
  378. while (1) {
  379. if (*src == '%') {
  380. src++;
  381. switch (*src) {
  382. case '%':
  383. case ':':
  384. *dst++ = *src++;
  385. *dst = '\0';
  386. break;
  387. case 'T':
  388. (void) strcat(dst, TypeName);
  389. src++;
  390. dst += strlen(TypeName);
  391. break;
  392. case 'N':
  393. (void) strcat(dst, ClassName);
  394. src++;
  395. dst += strlen(ClassName);
  396. break;
  397. case 'S':
  398. src++;
  399. break;
  400. default:
  401. src++;
  402. break;
  403. }
  404. } else if (*src == ':') {
  405. database = XrmGetFileDatabase(appdefaults);
  406. if (database == NULL) {
  407. dst = appdefaults;
  408. src++;
  409. } else
  410. break;
  411. } else if (*src == '\0') {
  412. database = XrmGetFileDatabase(appdefaults);
  413. break;
  414. } else {
  415. *dst++ = *src++;
  416. *dst = '\0';
  417. }
  418. }
  419. return database;
  420. }
  421. /*******************************************************************/
  422. /** screenIOErrorHandler **/
  423. /** **/
  424. /** this function will exit cleanly when the connection is broken **/
  425. /*******************************************************************/
  426. static int screenIOErrorHandler(Display *dpy)
  427. {
  428. exit(1);
  429. return 1;
  430. }
  431. static void
  432. open_display(void)
  433. {
  434. if (display != NULL) {
  435. char *colon = strchr(display, ':');
  436. if (colon == NULL)
  437. #ifdef MIT_R5
  438. error("%s: Malformed -display argument, \"%s\"\n", display);
  439. #else
  440. {
  441. fprintf(stderr, catgets(scmc_catd, 2, 19,
  442. "%s: Malformed -display argument: %s.\n"), ProgramName,display);
  443. exit(1);
  444. }
  445. #endif
  446. } else
  447. display = ":0.0";
  448. if (!(dsp = XOpenDisplay(display)))
  449. #ifdef MIT_R5
  450. error("%s: unable to open display %s.\n", display);
  451. #else
  452. {
  453. fprintf(stderr, catgets(scmc_catd, 2, 17,
  454. "%s: Unable to open display %s.\n"),ProgramName, display);
  455. exit(1);
  456. }
  457. #endif
  458. XSetIOErrorHandler(screenIOErrorHandler);
  459. }
  460. void
  461. printvar(char *class, argtype var)
  462. {
  463. switch (var.type) {
  464. case t_String:
  465. fprintf(stderr, "%s.%s: %s\n",
  466. class, var.name, *((char **) var.var));
  467. break;
  468. case t_Bool:
  469. fprintf(stderr, "%s.%s: %s\n",
  470. class, var.name, *((int *) var.var)
  471. ? "True" : "False");
  472. break;
  473. case t_Int:
  474. fprintf(stderr, "%s.%s: %d\n",
  475. class, var.name, *((int *) var.var));
  476. break;
  477. case t_Float:
  478. fprintf(stderr, "%s.%s: %g\n",
  479. class, var.name, *((float *) var.var));
  480. break;
  481. }
  482. }
  483. void
  484. GetResources(int argc, char *argv[])
  485. {
  486. XrmDatabase RDB = NULL;
  487. XrmDatabase modeDB = NULL;
  488. XrmDatabase nameDB = NULL;
  489. XrmDatabase cmdlineDB = NULL;
  490. XrmDatabase generalDB = NULL;
  491. XrmDatabase homeDB = NULL;
  492. XrmDatabase applicationDB = NULL;
  493. XrmDatabase serverDB = NULL;
  494. XrmDatabase userDB = NULL;
  495. char userfile[1024];
  496. char *homeenv;
  497. char *userpath;
  498. char *env;
  499. char *serverString;
  500. int i;
  501. /***************************/
  502. /** new variables for AIX **/
  503. /***************************/
  504. char delaySpecifier[64];
  505. char batchcountSpecifier[64];
  506. char saturationSpecifier[64];
  507. XrmInitialize();
  508. for (i = 0; i < argc; i++) {
  509. if (!strncmp(argv[i], "-help", strlen(argv[i])))
  510. Help();
  511. /* NOTREACHED */
  512. }
  513. /*
  514. * get -name arg from command line so you can have different resource
  515. * files for different configurations/machines etc...
  516. */
  517. XrmParseCommand(&nameDB, nameTable, 1, ProgramName,
  518. &argc, argv);
  519. GetResource(nameDB, ProgramName, "*", "name", "Name", t_String,
  520. DEF_CLASSNAME, &classname);
  521. homeenv = getenv("HOME");
  522. if (!homeenv)
  523. homeenv = "";
  524. env = getenv("XFILESEARCHPATH");
  525. applicationDB = parsefilepath(env ? env : DEF_FILESEARCHPATH,
  526. "app-defaults", classname);
  527. XrmParseCommand(&cmdlineDB, cmdlineTable, cmdlineEntries, ProgramName,
  528. &argc, argv);
  529. userpath = getenv("XUSERFILESEARCHPATH");
  530. if (!userpath) {
  531. env = getenv("XAPPLRESDIR");
  532. if (env)
  533. snprintf(userfile, 1024 - 1, "%s/%%N:%s/%%N", env, homeenv);
  534. else
  535. snprintf(userfile, 1024 - 1, "%s/%%N", homeenv);
  536. userpath = userfile;
  537. }
  538. userDB = parsefilepath(userpath, "app-defaults", classname);
  539. (void) XrmMergeDatabases(applicationDB, &RDB);
  540. (void) XrmMergeDatabases(userDB, &RDB);
  541. (void) XrmMergeDatabases(cmdlineDB, &RDB);
  542. env = getenv("DISPLAY");
  543. GetResource(RDB, ProgramName, classname, "display", "Display", t_String,
  544. env ? env : DEF_DISPLAY, &display);
  545. open_display();
  546. serverString = XResourceManagerString(dsp);
  547. if (serverString) {
  548. serverDB = XrmGetStringDatabase(serverString);
  549. (void) XrmMergeDatabases(serverDB, &RDB);
  550. } else {
  551. char buf[1024];
  552. sprintf(buf, "%s/.Xdefaults", homeenv);
  553. homeDB = XrmGetFileDatabase(buf);
  554. (void) XrmMergeDatabases(homeDB, &RDB);
  555. }
  556. XrmParseCommand(&generalDB, genTable, genEntries, ProgramName, &argc, argv);
  557. (void) XrmMergeDatabases(generalDB, &RDB);
  558. GetResource(RDB, ProgramName, classname, "mode", "Mode", t_String,
  559. DEF_MODE, (caddr_t *) &mode);
  560. /*
  561. * if random< mode, then just grab a random entry from the table
  562. */
  563. if (!strcmp(mode, randomstring))
  564. mode = LockProcs[random() % (NUMPROCS - 2)].cmdline_arg;
  565. sprintf(modename, "%s.%s", ProgramName, mode);
  566. sprintf(modeclass, "%s.%s", classname, mode);
  567. /*********************************************************************/
  568. /** New code for AIX **/
  569. /** We must build the specifier fields of the modeTable on the fly. **/
  570. /*********************************************************************/
  571. sprintf(delaySpecifier, ".%s.delay", mode);
  572. sprintf(batchcountSpecifier, ".%s.batchcount", mode);
  573. sprintf(saturationSpecifier, ".%s.saturation", mode);
  574. modeTable[0].specifier = delaySpecifier;
  575. modeTable[1].specifier = batchcountSpecifier;
  576. modeTable[2].specifier = saturationSpecifier;
  577. XrmParseCommand(&modeDB, modeTable, modeEntries, ProgramName, &argc, argv);
  578. (void) XrmMergeDatabases(modeDB, &RDB);
  579. /* Parse the rest of the command line */
  580. for (argc--, argv++; argc > 0; argc--, argv++) {
  581. if (**argv != '-')
  582. Syntax(*argv);
  583. switch (argv[0][1]) {
  584. case 'r':
  585. DumpResources();
  586. /* NOTREACHED */
  587. default:
  588. Syntax(*argv);
  589. /* NOTREACHED */
  590. }
  591. }
  592. /* the RDB is set, now query load the variables from the database */
  593. for (i = 0; i < NGENARGS; i++)
  594. GetResource(RDB, ProgramName, classname,
  595. genvars[i].name, genvars[i].class,
  596. genvars[i].type, genvars[i].def, genvars[i].var);
  597. for (i = 0; i < NMODEARGS; i++)
  598. GetResource(RDB, modename, modeclass,
  599. modevars[i].name, modevars[i].class,
  600. modevars[i].type, modevars[i].def, modevars[i].var);
  601. (void) XrmDestroyDatabase(RDB);
  602. }
  603. void CheckResources(void)
  604. {
  605. int i;
  606. if (batchcount < 1)
  607. Syntax("-batchcount argument must be positive.");
  608. if (saturation < 0.0 || saturation > 1.0)
  609. Syntax("-saturation argument must be between 0.0 and 1.0.");
  610. if (delay < 0)
  611. Syntax("-delay argument must be positive.");
  612. for (i = 0; i < NUMPROCS; i++) {
  613. if (!strncmp(LockProcs[i].cmdline_arg, mode, strlen(mode))) {
  614. init = LockProcs[i].lp_init;
  615. callback = LockProcs[i].lp_callback;
  616. break;
  617. }
  618. }
  619. if (i == NUMPROCS) {
  620. #ifdef MIT_R5
  621. fprintf(stderr, "Unknown mode: ");
  622. #else
  623. fprintf(stderr, "%s", catgets(scmc_catd, 2, 7,
  624. "Unknown mode: "));
  625. #endif
  626. Syntax(mode);
  627. }
  628. }