gen.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524
  1. /****************************************************************************
  2. * Copyright (c) 1998,2007,2008 Free Software Foundation, Inc. *
  3. * *
  4. * Permission is hereby granted, free of charge, to any person obtaining a *
  5. * copy of this software and associated documentation files (the *
  6. * "Software"), to deal in the Software without restriction, including *
  7. * without limitation the rights to use, copy, modify, merge, publish, *
  8. * distribute, distribute with modifications, sublicense, and/or sell *
  9. * copies of the Software, and to permit persons to whom the Software is *
  10. * furnished to do so, subject to the following conditions: *
  11. * *
  12. * The above copyright notice and this permission notice shall be included *
  13. * in all copies or substantial portions of the Software. *
  14. * *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
  16. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
  18. * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
  19. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
  20. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
  21. * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
  22. * *
  23. * Except as contained in this notice, the name(s) of the above copyright *
  24. * holders shall not be used in advertising or otherwise to promote the *
  25. * sale, use or other dealings in this Software without prior written *
  26. * authorization. *
  27. ****************************************************************************/
  28. /****************************************************************************
  29. * Author: Juergen Pfeifer, 1996 *
  30. ****************************************************************************/
  31. /*
  32. Version Control
  33. $Id: gen.c,v 1.49 2008/10/04 21:59:37 tom Exp $
  34. --------------------------------------------------------------------------*/
  35. /*
  36. This program generates various record structures and constants from the
  37. ncurses header file for the Ada95 packages. Essentially it produces
  38. Ada95 source on stdout, which is then merged using m4 into a template
  39. to produce the real source.
  40. */
  41. #include <ncurses_cfg.h>
  42. #include <stdlib.h>
  43. #include <stddef.h>
  44. #include <string.h>
  45. #include <assert.h>
  46. #include <ctype.h>
  47. #include <menu.h>
  48. #include <form.h>
  49. #define RES_NAME "Reserved"
  50. static const char *model = "";
  51. static int little_endian = 0;
  52. typedef struct
  53. {
  54. const char *name;
  55. unsigned long attr;
  56. }
  57. name_attribute_pair;
  58. static int
  59. find_pos(char *s, unsigned len, int *low, int *high)
  60. {
  61. unsigned int i, j;
  62. int l = 0;
  63. *high = -1;
  64. *low = 8 * len;
  65. for (i = 0; i < len; i++, s++)
  66. {
  67. if (*s)
  68. {
  69. for (j = 0; j < 8 * sizeof(char); j++)
  70. {
  71. if (((little_endian && ((*s) & 0x01)) ||
  72. (!little_endian && ((*s) & 0x80))))
  73. {
  74. if (l > *high)
  75. *high = l;
  76. if (l < *low)
  77. *low = l;
  78. }
  79. l++;
  80. if (little_endian)
  81. *s >>= 1;
  82. else
  83. *s <<= 1;
  84. }
  85. }
  86. else
  87. l += 8;
  88. }
  89. return (*high >= 0 && (*low <= *high)) ? *low : -1;
  90. }
  91. /*
  92. * This helper routine generates a representation clause for a
  93. * record type defined in the binding.
  94. * We are only dealing with record types which are of 32 or 16
  95. * bit size, i.e. they fit into an (u)int or a (u)short.
  96. */
  97. static void
  98. gen_reps
  99. (const name_attribute_pair * nap, /* array of name_attribute_pair records */
  100. const char *name, /* name of the represented record type */
  101. int len, /* size of the record in bytes */
  102. int bias)
  103. {
  104. int i, n, l, cnt = 0, low, high;
  105. int width = strlen(RES_NAME) + 3;
  106. unsigned long a;
  107. unsigned long mask = 0;
  108. assert(nap != NULL);
  109. for (i = 0; nap[i].name != (char *)0; i++)
  110. {
  111. cnt++;
  112. l = strlen(nap[i].name);
  113. if (l > width)
  114. width = l;
  115. }
  116. assert(width > 0);
  117. printf(" type %s is\n", name);
  118. printf(" record\n");
  119. for (i = 0; nap[i].name != (char *)0; i++)
  120. {
  121. printf(" %-*s : Boolean;\n", width, nap[i].name);
  122. }
  123. printf(" end record;\n");
  124. printf(" pragma Convention (C, %s);\n\n", name);
  125. printf(" for %s use\n", name);
  126. printf(" record\n");
  127. for (i = 0; nap[i].name != (char *)0; i++)
  128. {
  129. a = nap[i].attr;
  130. mask |= a;
  131. l = find_pos((char *)&a, sizeof(a), &low, &high);
  132. if (l >= 0)
  133. printf(" %-*s at 0 range %2d .. %2d;\n", width, nap[i].name,
  134. low - bias, high - bias);
  135. }
  136. i = 1;
  137. n = cnt;
  138. printf(" end record;\n");
  139. printf(" for %s'Size use %d;\n", name, 8 * len);
  140. printf(" -- Please note: this rep. clause is generated and may be\n");
  141. printf(" -- different on your system.");
  142. }
  143. static void
  144. chtype_rep(const char *name, attr_t mask)
  145. {
  146. attr_t x = -1;
  147. attr_t t = x & mask;
  148. int low, high;
  149. int l = find_pos((char *)&t, sizeof(t), &low, &high);
  150. if (l >= 0)
  151. printf(" %-5s at 0 range %2d .. %2d;\n", name, low, high);
  152. }
  153. static void
  154. gen_chtype_rep(const char *name)
  155. {
  156. printf(" for %s use\n record\n", name);
  157. chtype_rep("Ch", A_CHARTEXT);
  158. chtype_rep("Color", A_COLOR);
  159. chtype_rep("Attr", (A_ATTRIBUTES & ~A_COLOR));
  160. printf(" end record;\n for %s'Size use %ld;\n",
  161. name, (long)(8 * sizeof(chtype)));
  162. printf(" -- Please note: this rep. clause is generated and may be\n");
  163. printf(" -- different on your system.\n");
  164. }
  165. static void
  166. mrep_rep(const char *name, void *rec)
  167. {
  168. int low, high;
  169. int l = find_pos((char *)rec, sizeof(MEVENT), &low, &high);
  170. if (l >= 0)
  171. printf(" %-7s at 0 range %3d .. %3d;\n", name, low, high);
  172. }
  173. static void
  174. gen_mrep_rep(const char *name)
  175. {
  176. MEVENT x;
  177. printf(" for %s use\n record\n", name);
  178. memset(&x, 0, sizeof(x));
  179. x.id = -1;
  180. mrep_rep("Id", &x);
  181. memset(&x, 0, sizeof(x));
  182. x.x = -1;
  183. mrep_rep("X", &x);
  184. memset(&x, 0, sizeof(x));
  185. x.y = -1;
  186. mrep_rep("Y", &x);
  187. memset(&x, 0, sizeof(x));
  188. x.z = -1;
  189. mrep_rep("Z", &x);
  190. memset(&x, 0, sizeof(x));
  191. x.bstate = -1;
  192. mrep_rep("Bstate", &x);
  193. printf(" end record;\n");
  194. printf(" -- Please note: this rep. clause is generated and may be\n");
  195. printf(" -- different on your system.\n");
  196. }
  197. static void
  198. gen_attr_set(const char *name)
  199. {
  200. /* All of the A_xxx symbols are defined in ncurses, but not all are nonzero
  201. * if "configure --enable-widec" is specified.
  202. */
  203. static const name_attribute_pair nap[] =
  204. {
  205. #if A_STANDOUT
  206. {"Stand_Out", A_STANDOUT},
  207. #endif
  208. #if A_UNDERLINE
  209. {"Under_Line", A_UNDERLINE},
  210. #endif
  211. #if A_REVERSE
  212. {"Reverse_Video", A_REVERSE},
  213. #endif
  214. #if A_BLINK
  215. {"Blink", A_BLINK},
  216. #endif
  217. #if A_DIM
  218. {"Dim_Character", A_DIM},
  219. #endif
  220. #if A_BOLD
  221. {"Bold_Character", A_BOLD},
  222. #endif
  223. #if A_ALTCHARSET
  224. {"Alternate_Character_Set", A_ALTCHARSET},
  225. #endif
  226. #if A_INVIS
  227. {"Invisible_Character", A_INVIS},
  228. #endif
  229. #if A_PROTECT
  230. {"Protected_Character", A_PROTECT},
  231. #endif
  232. #if A_HORIZONTAL
  233. {"Horizontal", A_HORIZONTAL},
  234. #endif
  235. #if A_LEFT
  236. {"Left", A_LEFT},
  237. #endif
  238. #if A_LOW
  239. {"Low", A_LOW},
  240. #endif
  241. #if A_RIGHT
  242. {"Right", A_RIGHT},
  243. #endif
  244. #if A_TOP
  245. {"Top", A_TOP},
  246. #endif
  247. #if A_VERTICAL
  248. {"Vertical", A_VERTICAL},
  249. #endif
  250. {(char *)0, 0}
  251. };
  252. chtype attr = A_ATTRIBUTES & ~A_COLOR;
  253. int start = -1;
  254. int len = 0;
  255. int i, set;
  256. for (i = 0; i < (int)(8 * sizeof(chtype)); i++)
  257. {
  258. set = attr & 1;
  259. if (set)
  260. {
  261. if (start < 0)
  262. start = i;
  263. if (start >= 0)
  264. {
  265. len++;
  266. }
  267. }
  268. attr = attr >> 1;
  269. }
  270. gen_reps(nap, name, (len + 7) / 8, little_endian ? start : 0);
  271. }
  272. static void
  273. gen_trace(const char *name)
  274. {
  275. static const name_attribute_pair nap[] =
  276. {
  277. {"Times", TRACE_TIMES},
  278. {"Tputs", TRACE_TPUTS},
  279. {"Update", TRACE_UPDATE},
  280. {"Cursor_Move", TRACE_MOVE},
  281. {"Character_Output", TRACE_CHARPUT},
  282. {"Calls", TRACE_CALLS},
  283. {"Virtual_Puts", TRACE_VIRTPUT},
  284. {"Input_Events", TRACE_IEVENT},
  285. {"TTY_State", TRACE_BITS},
  286. {"Internal_Calls", TRACE_ICALLS},
  287. {"Character_Calls", TRACE_CCALLS},
  288. {"Termcap_TermInfo", TRACE_DATABASE},
  289. {(char *)0, 0}
  290. };
  291. gen_reps(nap, name, sizeof(int), 0);
  292. }
  293. static void
  294. gen_menu_opt_rep(const char *name)
  295. {
  296. static const name_attribute_pair nap[] =
  297. {
  298. #ifdef O_ONEVALUE
  299. {"One_Valued", O_ONEVALUE},
  300. #endif
  301. #ifdef O_SHOWDESC
  302. {"Show_Descriptions", O_SHOWDESC},
  303. #endif
  304. #ifdef O_ROWMAJOR
  305. {"Row_Major_Order", O_ROWMAJOR},
  306. #endif
  307. #ifdef O_IGNORECASE
  308. {"Ignore_Case", O_IGNORECASE},
  309. #endif
  310. #ifdef O_SHOWMATCH
  311. {"Show_Matches", O_SHOWMATCH},
  312. #endif
  313. #ifdef O_NONCYCLIC
  314. {"Non_Cyclic", O_NONCYCLIC},
  315. #endif
  316. {(char *)0, 0}
  317. };
  318. gen_reps(nap, name, sizeof(int), 0);
  319. }
  320. static void
  321. gen_item_opt_rep(const char *name)
  322. {
  323. static const name_attribute_pair nap[] =
  324. {
  325. #ifdef O_SELECTABLE
  326. {"Selectable", O_SELECTABLE},
  327. #endif
  328. {(char *)0, 0}
  329. };
  330. gen_reps(nap, name, sizeof(int), 0);
  331. }
  332. static void
  333. gen_form_opt_rep(const char *name)
  334. {
  335. static const name_attribute_pair nap[] =
  336. {
  337. #ifdef O_NL_OVERLOAD
  338. {"NL_Overload", O_NL_OVERLOAD},
  339. #endif
  340. #ifdef O_BS_OVERLOAD
  341. {"BS_Overload", O_BS_OVERLOAD},
  342. #endif
  343. {(char *)0, 0}
  344. };
  345. gen_reps(nap, name, sizeof(int), 0);
  346. }
  347. /*
  348. * Generate the representation clause for the Field_Option_Set record
  349. */
  350. static void
  351. gen_field_opt_rep(const char *name)
  352. {
  353. static const name_attribute_pair nap[] =
  354. {
  355. #ifdef O_VISIBLE
  356. {"Visible", O_VISIBLE},
  357. #endif
  358. #ifdef O_ACTIVE
  359. {"Active", O_ACTIVE},
  360. #endif
  361. #ifdef O_PUBLIC
  362. {"Public", O_PUBLIC},
  363. #endif
  364. #ifdef O_EDIT
  365. {"Edit", O_EDIT},
  366. #endif
  367. #ifdef O_WRAP
  368. {"Wrap", O_WRAP},
  369. #endif
  370. #ifdef O_BLANK
  371. {"Blank", O_BLANK},
  372. #endif
  373. #ifdef O_AUTOSKIP
  374. {"Auto_Skip", O_AUTOSKIP},
  375. #endif
  376. #ifdef O_NULLOK
  377. {"Null_Ok", O_NULLOK},
  378. #endif
  379. #ifdef O_PASSOK
  380. {"Pass_Ok", O_PASSOK},
  381. #endif
  382. #ifdef O_STATIC
  383. {"Static", O_STATIC},
  384. #endif
  385. {(char *)0, 0}
  386. };
  387. gen_reps(nap, name, sizeof(int), 0);
  388. }
  389. /*
  390. * Generate a single key code constant definition.
  391. */
  392. static void
  393. keydef(const char *name, const char *old_name, int value, int mode)
  394. {
  395. if (mode == 0) /* Generate the new name */
  396. printf(" %-30s : constant Special_Key_Code := 8#%3o#;\n", name, value);
  397. else
  398. { /* generate the old name, but only if it doesn't conflict with the old
  399. * name (Ada95 isn't case sensitive!)
  400. */
  401. const char *s = old_name;
  402. const char *t = name;
  403. while (*s && *t && (toupper(*s++) == toupper(*t++)));
  404. if (*s || *t)
  405. printf(" %-16s : Special_Key_Code renames %s;\n", old_name, name);
  406. }
  407. }
  408. /*
  409. * Generate constants for the key codes. When called with mode==0, a
  410. * complete list with nice constant names in proper casing style will
  411. * be generated. Otherwise a list of old (i.e. C-style) names will be
  412. * generated, given that the name wasn't already defined in the "nice"
  413. * list.
  414. */
  415. static void
  416. gen_keydefs(int mode)
  417. {
  418. char buf[16];
  419. char obuf[16];
  420. int i;
  421. #ifdef KEY_CODE_YES
  422. keydef("Key_Code_Yes", "KEY_CODE_YES", KEY_CODE_YES, mode);
  423. #endif
  424. #ifdef KEY_MIN
  425. keydef("Key_Min", "KEY_MIN", KEY_MIN, mode);
  426. #endif
  427. #ifdef KEY_BREAK
  428. keydef("Key_Break", "KEY_BREAK", KEY_BREAK, mode);
  429. #endif
  430. #ifdef KEY_DOWN
  431. keydef("Key_Cursor_Down", "KEY_DOWN", KEY_DOWN, mode);
  432. #endif
  433. #ifdef KEY_UP
  434. keydef("Key_Cursor_Up", "KEY_UP", KEY_UP, mode);
  435. #endif
  436. #ifdef KEY_LEFT
  437. keydef("Key_Cursor_Left", "KEY_LEFT", KEY_LEFT, mode);
  438. #endif
  439. #ifdef KEY_RIGHT
  440. keydef("Key_Cursor_Right", "KEY_RIGHT", KEY_RIGHT, mode);
  441. #endif
  442. #ifdef KEY_HOME
  443. keydef("Key_Home", "KEY_HOME", KEY_HOME, mode);
  444. #endif
  445. #ifdef KEY_BACKSPACE
  446. keydef("Key_Backspace", "KEY_BACKSPACE", KEY_BACKSPACE, mode);
  447. #endif
  448. #ifdef KEY_F0
  449. keydef("Key_F0", "KEY_F0", KEY_F0, mode);
  450. #endif
  451. #ifdef KEY_F
  452. for (i = 1; i <= 24; i++)
  453. {
  454. sprintf(buf, "Key_F%d", i);
  455. sprintf(obuf, "KEY_F%d", i);
  456. keydef(buf, obuf, KEY_F(i), mode);
  457. }
  458. #endif
  459. #ifdef KEY_DL
  460. keydef("Key_Delete_Line", "KEY_DL", KEY_DL, mode);
  461. #endif
  462. #ifdef KEY_IL
  463. keydef("Key_Insert_Line", "KEY_IL", KEY_IL, mode);
  464. #endif
  465. #ifdef KEY_DC
  466. keydef("Key_Delete_Char", "KEY_DC", KEY_DC, mode);
  467. #endif
  468. #ifdef KEY_IC
  469. keydef("Key_Insert_Char", "KEY_IC", KEY_IC, mode);
  470. #endif
  471. #ifdef KEY_EIC
  472. keydef("Key_Exit_Insert_Mode", "KEY_EIC", KEY_EIC, mode);
  473. #endif
  474. #ifdef KEY_CLEAR
  475. keydef("Key_Clear_Screen", "KEY_CLEAR", KEY_CLEAR, mode);
  476. #endif
  477. #ifdef KEY_EOS
  478. keydef("Key_Clear_End_Of_Screen", "KEY_EOS", KEY_EOS, mode);
  479. #endif
  480. #ifdef KEY_EOL
  481. keydef("Key_Clear_End_Of_Line", "KEY_EOL", KEY_EOL, mode);
  482. #endif
  483. #ifdef KEY_SF
  484. keydef("Key_Scroll_1_Forward", "KEY_SF", KEY_SF, mode);
  485. #endif
  486. #ifdef KEY_SR
  487. keydef("Key_Scroll_1_Backward", "KEY_SR", KEY_SR, mode);
  488. #endif
  489. #ifdef KEY_NPAGE
  490. keydef("Key_Next_Page", "KEY_NPAGE", KEY_NPAGE, mode);
  491. #endif
  492. #ifdef KEY_PPAGE
  493. keydef("Key_Previous_Page", "KEY_PPAGE", KEY_PPAGE, mode);
  494. #endif
  495. #ifdef KEY_STAB
  496. keydef("Key_Set_Tab", "KEY_STAB", KEY_STAB, mode);
  497. #endif
  498. #ifdef KEY_CTAB
  499. keydef("Key_Clear_Tab", "KEY_CTAB", KEY_CTAB, mode);
  500. #endif
  501. #ifdef KEY_CATAB
  502. keydef("Key_Clear_All_Tabs", "KEY_CATAB", KEY_CATAB, mode);
  503. #endif
  504. #ifdef KEY_ENTER
  505. keydef("Key_Enter_Or_Send", "KEY_ENTER", KEY_ENTER, mode);
  506. #endif
  507. #ifdef KEY_SRESET
  508. keydef("Key_Soft_Reset", "KEY_SRESET", KEY_SRESET, mode);
  509. #endif
  510. #ifdef KEY_RESET
  511. keydef("Key_Reset", "KEY_RESET", KEY_RESET, mode);
  512. #endif
  513. #ifdef KEY_PRINT
  514. keydef("Key_Print", "KEY_PRINT", KEY_PRINT, mode);
  515. #endif
  516. #ifdef KEY_LL
  517. keydef("Key_Bottom", "KEY_LL", KEY_LL, mode);
  518. #endif
  519. #ifdef KEY_A1
  520. keydef("Key_Upper_Left_Of_Keypad", "KEY_A1", KEY_A1, mode);
  521. #endif
  522. #ifdef KEY_A3
  523. keydef("Key_Upper_Right_Of_Keypad", "KEY_A3", KEY_A3, mode);
  524. #endif
  525. #ifdef KEY_B2
  526. keydef("Key_Center_Of_Keypad", "KEY_B2", KEY_B2, mode);
  527. #endif
  528. #ifdef KEY_C1
  529. keydef("Key_Lower_Left_Of_Keypad", "KEY_C1", KEY_C1, mode);
  530. #endif
  531. #ifdef KEY_C3
  532. keydef("Key_Lower_Right_Of_Keypad", "KEY_C3", KEY_C3, mode);
  533. #endif
  534. #ifdef KEY_BTAB
  535. keydef("Key_Back_Tab", "KEY_BTAB", KEY_BTAB, mode);
  536. #endif
  537. #ifdef KEY_BEG
  538. keydef("Key_Beginning", "KEY_BEG", KEY_BEG, mode);
  539. #endif
  540. #ifdef KEY_CANCEL
  541. keydef("Key_Cancel", "KEY_CANCEL", KEY_CANCEL, mode);
  542. #endif
  543. #ifdef KEY_CLOSE
  544. keydef("Key_Close", "KEY_CLOSE", KEY_CLOSE, mode);
  545. #endif
  546. #ifdef KEY_COMMAND
  547. keydef("Key_Command", "KEY_COMMAND", KEY_COMMAND, mode);
  548. #endif
  549. #ifdef KEY_COPY
  550. keydef("Key_Copy", "KEY_COPY", KEY_COPY, mode);
  551. #endif
  552. #ifdef KEY_CREATE
  553. keydef("Key_Create", "KEY_CREATE", KEY_CREATE, mode);
  554. #endif
  555. #ifdef KEY_END
  556. keydef("Key_End", "KEY_END", KEY_END, mode);
  557. #endif
  558. #ifdef KEY_EXIT
  559. keydef("Key_Exit", "KEY_EXIT", KEY_EXIT, mode);
  560. #endif
  561. #ifdef KEY_FIND
  562. keydef("Key_Find", "KEY_FIND", KEY_FIND, mode);
  563. #endif
  564. #ifdef KEY_HELP
  565. keydef("Key_Help", "KEY_HELP", KEY_HELP, mode);
  566. #endif
  567. #ifdef KEY_MARK
  568. keydef("Key_Mark", "KEY_MARK", KEY_MARK, mode);
  569. #endif
  570. #ifdef KEY_MESSAGE
  571. keydef("Key_Message", "KEY_MESSAGE", KEY_MESSAGE, mode);
  572. #endif
  573. #ifdef KEY_MOVE
  574. keydef("Key_Move", "KEY_MOVE", KEY_MOVE, mode);
  575. #endif
  576. #ifdef KEY_NEXT
  577. keydef("Key_Next", "KEY_NEXT", KEY_NEXT, mode);
  578. #endif
  579. #ifdef KEY_OPEN
  580. keydef("Key_Open", "KEY_OPEN", KEY_OPEN, mode);
  581. #endif
  582. #ifdef KEY_OPTIONS
  583. keydef("Key_Options", "KEY_OPTIONS", KEY_OPTIONS, mode);
  584. #endif
  585. #ifdef KEY_PREVIOUS
  586. keydef("Key_Previous", "KEY_PREVIOUS", KEY_PREVIOUS, mode);
  587. #endif
  588. #ifdef KEY_REDO
  589. keydef("Key_Redo", "KEY_REDO", KEY_REDO, mode);
  590. #endif
  591. #ifdef KEY_REFERENCE
  592. keydef("Key_Reference", "KEY_REFERENCE", KEY_REFERENCE, mode);
  593. #endif
  594. #ifdef KEY_REFRESH
  595. keydef("Key_Refresh", "KEY_REFRESH", KEY_REFRESH, mode);
  596. #endif
  597. #ifdef KEY_REPLACE
  598. keydef("Key_Replace", "KEY_REPLACE", KEY_REPLACE, mode);
  599. #endif
  600. #ifdef KEY_RESTART
  601. keydef("Key_Restart", "KEY_RESTART", KEY_RESTART, mode);
  602. #endif
  603. #ifdef KEY_RESUME
  604. keydef("Key_Resume", "KEY_RESUME", KEY_RESUME, mode);
  605. #endif
  606. #ifdef KEY_SAVE
  607. keydef("Key_Save", "KEY_SAVE", KEY_SAVE, mode);
  608. #endif
  609. #ifdef KEY_SBEG
  610. keydef("Key_Shift_Begin", "KEY_SBEG", KEY_SBEG, mode);
  611. #endif
  612. #ifdef KEY_SCANCEL
  613. keydef("Key_Shift_Cancel", "KEY_SCANCEL", KEY_SCANCEL, mode);
  614. #endif
  615. #ifdef KEY_SCOMMAND
  616. keydef("Key_Shift_Command", "KEY_SCOMMAND", KEY_SCOMMAND, mode);
  617. #endif
  618. #ifdef KEY_SCOPY
  619. keydef("Key_Shift_Copy", "KEY_SCOPY", KEY_SCOPY, mode);
  620. #endif
  621. #ifdef KEY_SCREATE
  622. keydef("Key_Shift_Create", "KEY_SCREATE", KEY_SCREATE, mode);
  623. #endif
  624. #ifdef KEY_SDC
  625. keydef("Key_Shift_Delete_Char", "KEY_SDC", KEY_SDC, mode);
  626. #endif
  627. #ifdef KEY_SDL
  628. keydef("Key_Shift_Delete_Line", "KEY_SDL", KEY_SDL, mode);
  629. #endif
  630. #ifdef KEY_SELECT
  631. keydef("Key_Select", "KEY_SELECT", KEY_SELECT, mode);
  632. #endif
  633. #ifdef KEY_SEND
  634. keydef("Key_Shift_End", "KEY_SEND", KEY_SEND, mode);
  635. #endif
  636. #ifdef KEY_SEOL
  637. keydef("Key_Shift_Clear_End_Of_Line", "KEY_SEOL", KEY_SEOL, mode);
  638. #endif
  639. #ifdef KEY_SEXIT
  640. keydef("Key_Shift_Exit", "KEY_SEXIT", KEY_SEXIT, mode);
  641. #endif
  642. #ifdef KEY_SFIND
  643. keydef("Key_Shift_Find", "KEY_SFIND", KEY_SFIND, mode);
  644. #endif
  645. #ifdef KEY_SHELP
  646. keydef("Key_Shift_Help", "KEY_SHELP", KEY_SHELP, mode);
  647. #endif
  648. #ifdef KEY_SHOME
  649. keydef("Key_Shift_Home", "KEY_SHOME", KEY_SHOME, mode);
  650. #endif
  651. #ifdef KEY_SIC
  652. keydef("Key_Shift_Insert_Char", "KEY_SIC", KEY_SIC, mode);
  653. #endif
  654. #ifdef KEY_SLEFT
  655. keydef("Key_Shift_Cursor_Left", "KEY_SLEFT", KEY_SLEFT, mode);
  656. #endif
  657. #ifdef KEY_SMESSAGE
  658. keydef("Key_Shift_Message", "KEY_SMESSAGE", KEY_SMESSAGE, mode);
  659. #endif
  660. #ifdef KEY_SMOVE
  661. keydef("Key_Shift_Move", "KEY_SMOVE", KEY_SMOVE, mode);
  662. #endif
  663. #ifdef KEY_SNEXT
  664. keydef("Key_Shift_Next_Page", "KEY_SNEXT", KEY_SNEXT, mode);
  665. #endif
  666. #ifdef KEY_SOPTIONS
  667. keydef("Key_Shift_Options", "KEY_SOPTIONS", KEY_SOPTIONS, mode);
  668. #endif
  669. #ifdef KEY_SPREVIOUS
  670. keydef("Key_Shift_Previous_Page", "KEY_SPREVIOUS", KEY_SPREVIOUS, mode);
  671. #endif
  672. #ifdef KEY_SPRINT
  673. keydef("Key_Shift_Print", "KEY_SPRINT", KEY_SPRINT, mode);
  674. #endif
  675. #ifdef KEY_SREDO
  676. keydef("Key_Shift_Redo", "KEY_SREDO", KEY_SREDO, mode);
  677. #endif
  678. #ifdef KEY_SREPLACE
  679. keydef("Key_Shift_Replace", "KEY_SREPLACE", KEY_SREPLACE, mode);
  680. #endif
  681. #ifdef KEY_SRIGHT
  682. keydef("Key_Shift_Cursor_Right", "KEY_SRIGHT", KEY_SRIGHT, mode);
  683. #endif
  684. #ifdef KEY_SRSUME
  685. keydef("Key_Shift_Resume", "KEY_SRSUME", KEY_SRSUME, mode);
  686. #endif
  687. #ifdef KEY_SSAVE
  688. keydef("Key_Shift_Save", "KEY_SSAVE", KEY_SSAVE, mode);
  689. #endif
  690. #ifdef KEY_SSUSPEND
  691. keydef("Key_Shift_Suspend", "KEY_SSUSPEND", KEY_SSUSPEND, mode);
  692. #endif
  693. #ifdef KEY_SUNDO
  694. keydef("Key_Shift_Undo", "KEY_SUNDO", KEY_SUNDO, mode);
  695. #endif
  696. #ifdef KEY_SUSPEND
  697. keydef("Key_Suspend", "KEY_SUSPEND", KEY_SUSPEND, mode);
  698. #endif
  699. #ifdef KEY_UNDO
  700. keydef("Key_Undo", "KEY_UNDO", KEY_UNDO, mode);
  701. #endif
  702. #ifdef KEY_MOUSE
  703. keydef("Key_Mouse", "KEY_MOUSE", KEY_MOUSE, mode);
  704. #endif
  705. #ifdef KEY_RESIZE
  706. keydef("Key_Resize", "KEY_RESIZE", KEY_RESIZE, mode);
  707. #endif
  708. }
  709. /*
  710. * Generate a constant with the given name. The second parameter
  711. * is a reference to the ACS character in the acs_map[] array and
  712. * will be translated into an index.
  713. */
  714. static void
  715. acs_def(const char *name, chtype *a)
  716. {
  717. int c = a - &acs_map[0];
  718. printf(" %-24s : constant Character := ", name);
  719. if (isprint(c) && (c != '`'))
  720. printf("'%c';\n", c);
  721. else
  722. printf("Character'Val (%d);\n", c);
  723. }
  724. /*
  725. * Generate the constants for the ACS characters
  726. */
  727. static void
  728. gen_acs(void)
  729. {
  730. printf(" type C_ACS_Map is array (Character'Val (0) .. Character'Val (127))\n");
  731. printf(" of Attributed_Character;\n");
  732. #if USE_REENTRANT || BROKEN_LINKER
  733. printf(" type C_ACS_Ptr is access C_ACS_Map;\n");
  734. printf(" function ACS_Map return C_ACS_Ptr;\n");
  735. printf(" pragma Import (C, ACS_Map, \"_nc_acs_map\");\n");
  736. #else
  737. printf(" ACS_Map : C_ACS_Map;\n");
  738. printf(" pragma Import (C, ACS_Map, \"acs_map\");\n");
  739. #endif
  740. printf(" --\n");
  741. printf(" --\n");
  742. printf(" -- Constants for several characters from the Alternate Character Set\n");
  743. printf(" -- You must use these constants as indices into the ACS_Map array\n");
  744. printf(" -- to get the corresponding attributed character at runtime.\n");
  745. printf(" --\n");
  746. #ifdef ACS_ULCORNER
  747. acs_def("ACS_Upper_Left_Corner", &ACS_ULCORNER);
  748. #endif
  749. #ifdef ACS_LLCORNER
  750. acs_def("ACS_Lower_Left_Corner", &ACS_LLCORNER);
  751. #endif
  752. #ifdef ACS_URCORNER
  753. acs_def("ACS_Upper_Right_Corner", &ACS_URCORNER);
  754. #endif
  755. #ifdef ACS_LRCORNER
  756. acs_def("ACS_Lower_Right_Corner", &ACS_LRCORNER);
  757. #endif
  758. #ifdef ACS_LTEE
  759. acs_def("ACS_Left_Tee", &ACS_LTEE);
  760. #endif
  761. #ifdef ACS_RTEE
  762. acs_def("ACS_Right_Tee", &ACS_RTEE);
  763. #endif
  764. #ifdef ACS_BTEE
  765. acs_def("ACS_Bottom_Tee", &ACS_BTEE);
  766. #endif
  767. #ifdef ACS_TTEE
  768. acs_def("ACS_Top_Tee", &ACS_TTEE);
  769. #endif
  770. #ifdef ACS_HLINE
  771. acs_def("ACS_Horizontal_Line", &ACS_HLINE);
  772. #endif
  773. #ifdef ACS_VLINE
  774. acs_def("ACS_Vertical_Line", &ACS_VLINE);
  775. #endif
  776. #ifdef ACS_PLUS
  777. acs_def("ACS_Plus_Symbol", &ACS_PLUS);
  778. #endif
  779. #ifdef ACS_S1
  780. acs_def("ACS_Scan_Line_1", &ACS_S1);
  781. #endif
  782. #ifdef ACS_S9
  783. acs_def("ACS_Scan_Line_9", &ACS_S9);
  784. #endif
  785. #ifdef ACS_DIAMOND
  786. acs_def("ACS_Diamond", &ACS_DIAMOND);
  787. #endif
  788. #ifdef ACS_CKBOARD
  789. acs_def("ACS_Checker_Board", &ACS_CKBOARD);
  790. #endif
  791. #ifdef ACS_DEGREE
  792. acs_def("ACS_Degree", &ACS_DEGREE);
  793. #endif
  794. #ifdef ACS_PLMINUS
  795. acs_def("ACS_Plus_Minus", &ACS_PLMINUS);
  796. #endif
  797. #ifdef ACS_BULLET
  798. acs_def("ACS_Bullet", &ACS_BULLET);
  799. #endif
  800. #ifdef ACS_LARROW
  801. acs_def("ACS_Left_Arrow", &ACS_LARROW);
  802. #endif
  803. #ifdef ACS_RARROW
  804. acs_def("ACS_Right_Arrow", &ACS_RARROW);
  805. #endif
  806. #ifdef ACS_DARROW
  807. acs_def("ACS_Down_Arrow", &ACS_DARROW);
  808. #endif
  809. #ifdef ACS_UARROW
  810. acs_def("ACS_Up_Arrow", &ACS_UARROW);
  811. #endif
  812. #ifdef ACS_BOARD
  813. acs_def("ACS_Board_Of_Squares", &ACS_BOARD);
  814. #endif
  815. #ifdef ACS_LANTERN
  816. acs_def("ACS_Lantern", &ACS_LANTERN);
  817. #endif
  818. #ifdef ACS_BLOCK
  819. acs_def("ACS_Solid_Block", &ACS_BLOCK);
  820. #endif
  821. #ifdef ACS_S3
  822. acs_def("ACS_Scan_Line_3", &ACS_S3);
  823. #endif
  824. #ifdef ACS_S7
  825. acs_def("ACS_Scan_Line_7", &ACS_S7);
  826. #endif
  827. #ifdef ACS_LEQUAL
  828. acs_def("ACS_Less_Or_Equal", &ACS_LEQUAL);
  829. #endif
  830. #ifdef ACS_GEQUAL
  831. acs_def("ACS_Greater_Or_Equal", &ACS_GEQUAL);
  832. #endif
  833. #ifdef ACS_PI
  834. acs_def("ACS_PI", &ACS_PI);
  835. #endif
  836. #ifdef ACS_NEQUAL
  837. acs_def("ACS_Not_Equal", &ACS_NEQUAL);
  838. #endif
  839. #ifdef ACS_STERLING
  840. acs_def("ACS_Sterling", &ACS_STERLING);
  841. #endif
  842. }
  843. #define GEN_EVENT(name,value) \
  844. printf(" %-25s : constant Event_Mask := 8#%011lo#;\n", \
  845. #name, value)
  846. #define GEN_MEVENT(name) \
  847. printf(" %-25s : constant Event_Mask := 8#%011lo#;\n", \
  848. #name, name)
  849. static void
  850. gen_mouse_events(void)
  851. {
  852. mmask_t all1 = 0;
  853. mmask_t all2 = 0;
  854. mmask_t all3 = 0;
  855. mmask_t all4 = 0;
  856. #ifdef BUTTON1_RELEASED
  857. GEN_MEVENT(BUTTON1_RELEASED);
  858. all1 |= BUTTON1_RELEASED;
  859. #endif
  860. #ifdef BUTTON1_PRESSED
  861. GEN_MEVENT(BUTTON1_PRESSED);
  862. all1 |= BUTTON1_PRESSED;
  863. #endif
  864. #ifdef BUTTON1_CLICKED
  865. GEN_MEVENT(BUTTON1_CLICKED);
  866. all1 |= BUTTON1_CLICKED;
  867. #endif
  868. #ifdef BUTTON1_DOUBLE_CLICKED
  869. GEN_MEVENT(BUTTON1_DOUBLE_CLICKED);
  870. all1 |= BUTTON1_DOUBLE_CLICKED;
  871. #endif
  872. #ifdef BUTTON1_TRIPLE_CLICKED
  873. GEN_MEVENT(BUTTON1_TRIPLE_CLICKED);
  874. all1 |= BUTTON1_TRIPLE_CLICKED;
  875. #endif
  876. #ifdef BUTTON1_RESERVED_EVENT
  877. GEN_MEVENT(BUTTON1_RESERVED_EVENT);
  878. all1 |= BUTTON1_RESERVED_EVENT;
  879. #endif
  880. #ifdef BUTTON2_RELEASED
  881. GEN_MEVENT(BUTTON2_RELEASED);
  882. all2 |= BUTTON2_RELEASED;
  883. #endif
  884. #ifdef BUTTON2_PRESSED
  885. GEN_MEVENT(BUTTON2_PRESSED);
  886. all2 |= BUTTON2_PRESSED;
  887. #endif
  888. #ifdef BUTTON2_CLICKED
  889. GEN_MEVENT(BUTTON2_CLICKED);
  890. all2 |= BUTTON2_CLICKED;
  891. #endif
  892. #ifdef BUTTON2_DOUBLE_CLICKED
  893. GEN_MEVENT(BUTTON2_DOUBLE_CLICKED);
  894. all2 |= BUTTON2_DOUBLE_CLICKED;
  895. #endif
  896. #ifdef BUTTON2_TRIPLE_CLICKED
  897. GEN_MEVENT(BUTTON2_TRIPLE_CLICKED);
  898. all2 |= BUTTON2_TRIPLE_CLICKED;
  899. #endif
  900. #ifdef BUTTON2_RESERVED_EVENT
  901. GEN_MEVENT(BUTTON2_RESERVED_EVENT);
  902. all2 |= BUTTON2_RESERVED_EVENT;
  903. #endif
  904. #ifdef BUTTON3_RELEASED
  905. GEN_MEVENT(BUTTON3_RELEASED);
  906. all3 |= BUTTON3_RELEASED;
  907. #endif
  908. #ifdef BUTTON3_PRESSED
  909. GEN_MEVENT(BUTTON3_PRESSED);
  910. all3 |= BUTTON3_PRESSED;
  911. #endif
  912. #ifdef BUTTON3_CLICKED
  913. GEN_MEVENT(BUTTON3_CLICKED);
  914. all3 |= BUTTON3_CLICKED;
  915. #endif
  916. #ifdef BUTTON3_DOUBLE_CLICKED
  917. GEN_MEVENT(BUTTON3_DOUBLE_CLICKED);
  918. all3 |= BUTTON3_DOUBLE_CLICKED;
  919. #endif
  920. #ifdef BUTTON3_TRIPLE_CLICKED
  921. GEN_MEVENT(BUTTON3_TRIPLE_CLICKED);
  922. all3 |= BUTTON3_TRIPLE_CLICKED;
  923. #endif
  924. #ifdef BUTTON3_RESERVED_EVENT
  925. GEN_MEVENT(BUTTON3_RESERVED_EVENT);
  926. all3 |= BUTTON3_RESERVED_EVENT;
  927. #endif
  928. #ifdef BUTTON4_RELEASED
  929. GEN_MEVENT(BUTTON4_RELEASED);
  930. all4 |= BUTTON4_RELEASED;
  931. #endif
  932. #ifdef BUTTON4_PRESSED
  933. GEN_MEVENT(BUTTON4_PRESSED);
  934. all4 |= BUTTON4_PRESSED;
  935. #endif
  936. #ifdef BUTTON4_CLICKED
  937. GEN_MEVENT(BUTTON4_CLICKED);
  938. all4 |= BUTTON4_CLICKED;
  939. #endif
  940. #ifdef BUTTON4_DOUBLE_CLICKED
  941. GEN_MEVENT(BUTTON4_DOUBLE_CLICKED);
  942. all4 |= BUTTON4_DOUBLE_CLICKED;
  943. #endif
  944. #ifdef BUTTON4_TRIPLE_CLICKED
  945. GEN_MEVENT(BUTTON4_TRIPLE_CLICKED);
  946. all4 |= BUTTON4_TRIPLE_CLICKED;
  947. #endif
  948. #ifdef BUTTON4_RESERVED_EVENT
  949. GEN_MEVENT(BUTTON4_RESERVED_EVENT);
  950. all4 |= BUTTON4_RESERVED_EVENT;
  951. #endif
  952. #ifdef BUTTON_CTRL
  953. GEN_MEVENT(BUTTON_CTRL);
  954. #endif
  955. #ifdef BUTTON_SHIFT
  956. GEN_MEVENT(BUTTON_SHIFT);
  957. #endif
  958. #ifdef BUTTON_ALT
  959. GEN_MEVENT(BUTTON_ALT);
  960. #endif
  961. #ifdef REPORT_MOUSE_POSITION
  962. GEN_MEVENT(REPORT_MOUSE_POSITION);
  963. #endif
  964. #ifdef ALL_MOUSE_EVENTS
  965. GEN_MEVENT(ALL_MOUSE_EVENTS);
  966. #endif
  967. GEN_EVENT(BUTTON1_EVENTS, all1);
  968. GEN_EVENT(BUTTON2_EVENTS, all2);
  969. GEN_EVENT(BUTTON3_EVENTS, all3);
  970. GEN_EVENT(BUTTON4_EVENTS, all4);
  971. }
  972. static void
  973. wrap_one_var(const char *c_var,
  974. const char *c_type,
  975. const char *ada_func,
  976. const char *ada_type)
  977. {
  978. #if USE_REENTRANT
  979. /* must wrap variables */
  980. printf("\n");
  981. printf(" function %s return %s\n", ada_func, ada_type);
  982. printf(" is\n");
  983. printf(" function Result return %s;\n", c_type);
  984. printf(" pragma Import (C, Result, \"_nc_%s\");\n", c_var);
  985. printf(" begin\n");
  986. if (strcmp(c_type, ada_type))
  987. printf(" return %s (Result);\n", ada_type);
  988. else
  989. printf(" return Result;\n");
  990. printf(" end %s;\n", ada_func);
  991. #else
  992. /* global variables are really global */
  993. printf("\n");
  994. printf(" function %s return %s\n", ada_func, ada_type);
  995. printf(" is\n");
  996. printf(" Result : %s;\n", c_type);
  997. printf(" pragma Import (C, Result, \"%s\");\n", c_var);
  998. printf(" begin\n");
  999. if (strcmp(c_type, ada_type))
  1000. printf(" return %s (Result);\n", ada_type);
  1001. else
  1002. printf(" return Result;\n");
  1003. printf(" end %s;\n", ada_func);
  1004. #endif
  1005. }
  1006. #define GEN_PUBLIC_VAR(c_var, c_type, ada_func, ada_type) \
  1007. wrap_one_var(#c_var, #c_type, #ada_func, #ada_type)
  1008. static void
  1009. gen_public_vars(void)
  1010. {
  1011. GEN_PUBLIC_VAR(stdscr, Window, Standard_Window, Window);
  1012. GEN_PUBLIC_VAR(curscr, Window, Current_Window, Window);
  1013. GEN_PUBLIC_VAR(LINES, C_Int, Lines, Line_Count);
  1014. GEN_PUBLIC_VAR(COLS, C_Int, Columns, Column_Count);
  1015. GEN_PUBLIC_VAR(TABSIZE, C_Int, Tab_Size, Natural);
  1016. GEN_PUBLIC_VAR(COLORS, C_Int, Number_Of_Colors, Natural);
  1017. GEN_PUBLIC_VAR(COLOR_PAIRS, C_Int, Number_Of_Color_Pairs, Natural);
  1018. }
  1019. /*
  1020. * Output some comment lines indicating that the file is generated.
  1021. * The name parameter is the name of the facility to be used in
  1022. * the comment.
  1023. */
  1024. static void
  1025. prologue(const char *name)
  1026. {
  1027. printf("-- %s binding.\n", name);
  1028. printf("-- This module is generated. Please don't change it manually!\n");
  1029. printf("-- Run the generator instead.\n-- |");
  1030. printf("define(`M4_BIT_ORDER',`%s_Order_First')",
  1031. little_endian ? "Low" : "High");
  1032. }
  1033. /*
  1034. * Write the prologue for the curses facility and make sure that
  1035. * KEY_MIN and KEY_MAX are defined for the rest of this source.
  1036. */
  1037. static void
  1038. basedefs(void)
  1039. {
  1040. prologue("curses");
  1041. #ifndef KEY_MAX
  1042. # define KEY_MAX 0777
  1043. #endif
  1044. printf("define(`M4_KEY_MAX',`8#%o#')", KEY_MAX);
  1045. #ifndef KEY_MIN
  1046. # define KEY_MIN 0401
  1047. #endif
  1048. if (KEY_MIN == 256)
  1049. {
  1050. fprintf(stderr, "Unexpected value for KEY_MIN: %d\n", KEY_MIN);
  1051. exit(1);
  1052. }
  1053. printf("define(`M4_SPECIAL_FIRST',`8#%o#')", KEY_MIN - 1);
  1054. }
  1055. /*
  1056. * Write out the comment lines for the menu facility
  1057. */
  1058. static void
  1059. menu_basedefs(void)
  1060. {
  1061. prologue("menu");
  1062. }
  1063. /*
  1064. * Write out the comment lines for the form facility
  1065. */
  1066. static void
  1067. form_basedefs(void)
  1068. {
  1069. prologue("form");
  1070. }
  1071. /*
  1072. * Write out the comment lines for the mouse facility
  1073. */
  1074. static void
  1075. mouse_basedefs(void)
  1076. {
  1077. prologue("mouse");
  1078. }
  1079. /*
  1080. * Write the definition of a single color
  1081. */
  1082. static void
  1083. color_def(const char *name, int value)
  1084. {
  1085. printf(" %-16s : constant Color_Number := %d;\n", name, value);
  1086. }
  1087. /*
  1088. * Generate all color definitions
  1089. */
  1090. static void
  1091. gen_color(void)
  1092. {
  1093. #if HAVE_USE_DEFAULT_COLORS
  1094. color_def("Default_Color", -1);
  1095. #endif
  1096. #ifdef COLOR_BLACK
  1097. color_def("Black", COLOR_BLACK);
  1098. #endif
  1099. #ifdef COLOR_RED
  1100. color_def("Red", COLOR_RED);
  1101. #endif
  1102. #ifdef COLOR_GREEN
  1103. color_def("Green", COLOR_GREEN);
  1104. #endif
  1105. #ifdef COLOR_YELLOW
  1106. color_def("Yellow", COLOR_YELLOW);
  1107. #endif
  1108. #ifdef COLOR_BLUE
  1109. color_def("Blue", COLOR_BLUE);
  1110. #endif
  1111. #ifdef COLOR_MAGENTA
  1112. color_def("Magenta", COLOR_MAGENTA);
  1113. #endif
  1114. #ifdef COLOR_CYAN
  1115. color_def("Cyan", COLOR_CYAN);
  1116. #endif
  1117. #ifdef COLOR_WHITE
  1118. color_def("White", COLOR_WHITE);
  1119. #endif
  1120. }
  1121. /*
  1122. * Generate the linker options for the base facility
  1123. */
  1124. static void
  1125. gen_linkopts(void)
  1126. {
  1127. printf(" pragma Linker_Options (\"-lncurses%s\");\n", model);
  1128. }
  1129. /*
  1130. * Generate the linker options for the menu facility
  1131. */
  1132. static void
  1133. gen_menu_linkopts(void)
  1134. {
  1135. printf(" pragma Linker_Options (\"-lmenu%s\");\n", model);
  1136. }
  1137. /*
  1138. * Generate the linker options for the form facility
  1139. */
  1140. static void
  1141. gen_form_linkopts(void)
  1142. {
  1143. printf(" pragma Linker_Options (\"-lform%s\");\n", model);
  1144. }
  1145. /*
  1146. * Generate the linker options for the panel facility
  1147. */
  1148. static void
  1149. gen_panel_linkopts(void)
  1150. {
  1151. printf(" pragma Linker_Options (\"-lpanel%s\");\n", model);
  1152. }
  1153. static void
  1154. gen_version_info(void)
  1155. {
  1156. static const char *v1 =
  1157. " NC_Major_Version : constant := %d; -- Major version of the library\n";
  1158. static const char *v2 =
  1159. " NC_Minor_Version : constant := %d; -- Minor version of the library\n";
  1160. static const char *v3 =
  1161. " NC_Version : constant String := %c%d.%d%c; -- Version of library\n";
  1162. printf(v1, NCURSES_VERSION_MAJOR);
  1163. printf(v2, NCURSES_VERSION_MINOR);
  1164. printf(v3, '"', NCURSES_VERSION_MAJOR, NCURSES_VERSION_MINOR, '"');
  1165. }
  1166. static int
  1167. eti_gen(char *buf, int code, const char *name, int *etimin, int *etimax)
  1168. {
  1169. sprintf(buf, " E_%-16s : constant Eti_Error := %d;\n", name, code);
  1170. if (code < *etimin)
  1171. *etimin = code;
  1172. if (code > *etimax)
  1173. *etimax = code;
  1174. return strlen(buf);
  1175. }
  1176. static void
  1177. gen_offsets(void)
  1178. {
  1179. const char *s_bool = "";
  1180. if (sizeof(bool) == sizeof(char))
  1181. {
  1182. s_bool = "char";
  1183. }
  1184. else if (sizeof(bool) == sizeof(short))
  1185. {
  1186. s_bool = "short";
  1187. }
  1188. else if (sizeof(bool) == sizeof(int))
  1189. {
  1190. s_bool = "int";
  1191. }
  1192. printf(" Sizeof%-*s : constant Natural := %2ld; -- %s\n",
  1193. 12, "_bool", (long)sizeof(bool), "bool");
  1194. /* In ncurses _maxy and _maxx needs an offset for the "public"
  1195. * value
  1196. */
  1197. printf(" Offset%-*s : constant Natural := %2d; -- %s\n",
  1198. 12, "_XY", 1, "int");
  1199. printf("\n");
  1200. printf(" type Curses_Bool is mod 2 ** Interfaces.C.%s'Size;\n", s_bool);
  1201. }
  1202. /*
  1203. * main() expects two arguments on the commandline, both single characters.
  1204. * The first character denotes the facility for which we generate output.
  1205. * Possible values are
  1206. * B - Base
  1207. * M - Menus
  1208. * F - Forms
  1209. * P - Pointer Device (Mouse)
  1210. * E - ETI base definitions
  1211. *
  1212. * The second character then denotes the specific output that should be
  1213. * generated for the selected facility.
  1214. */
  1215. int
  1216. main(int argc, char *argv[])
  1217. {
  1218. int x = 0x12345678;
  1219. char *s = (char *)&x;
  1220. if (*s == 0x78)
  1221. little_endian = 1;
  1222. if (argc != 4)
  1223. exit(1);
  1224. model = *++argv;
  1225. switch (argv[1][0])
  1226. {
  1227. /* --------------------------------------------------------------- */
  1228. case 'B': /* The Base facility */
  1229. switch (argv[2][0])
  1230. {
  1231. case 'A': /* chtype translation into Ada95 record type */
  1232. gen_attr_set("Character_Attribute_Set");
  1233. break;
  1234. case 'B': /* write some initial comment lines */
  1235. basedefs();
  1236. break;
  1237. case 'C': /* generate color constants */
  1238. gen_color();
  1239. break;
  1240. case 'D': /* generate displacements of fields in WINDOW struct. */
  1241. gen_offsets();
  1242. break;
  1243. case 'E': /* generate Mouse Event codes */
  1244. gen_mouse_events();
  1245. break;
  1246. case 'K': /* translation of keycodes */
  1247. gen_keydefs(0);
  1248. break;
  1249. case 'L': /* generate the Linker_Options pragma */
  1250. gen_linkopts();
  1251. break;
  1252. case 'M': /* generate constants for the ACS characters */
  1253. gen_acs();
  1254. break;
  1255. case 'O': /* generate definitions of the old key code names */
  1256. gen_keydefs(1);
  1257. break;
  1258. case 'P': /* generate definitions of the public variables */
  1259. gen_public_vars();
  1260. break;
  1261. case 'R': /* generate representation clause for Attributed character */
  1262. gen_chtype_rep("Attributed_Character");
  1263. break;
  1264. case 'T': /* generate the Trace info */
  1265. gen_trace("Trace_Attribute_Set");
  1266. break;
  1267. case 'V': /* generate version info */
  1268. gen_version_info();
  1269. break;
  1270. default:
  1271. break;
  1272. }
  1273. break;
  1274. /* --------------------------------------------------------------- */
  1275. case 'M': /* The Menu facility */
  1276. switch (argv[2][0])
  1277. {
  1278. case 'R': /* generate representation clause for Menu_Option_Set */
  1279. gen_menu_opt_rep("Menu_Option_Set");
  1280. break;
  1281. case 'B': /* write some initial comment lines */
  1282. menu_basedefs();
  1283. break;
  1284. case 'L': /* generate the Linker_Options pragma */
  1285. gen_menu_linkopts();
  1286. break;
  1287. case 'I': /* generate representation clause for Item_Option_Set */
  1288. gen_item_opt_rep("Item_Option_Set");
  1289. break;
  1290. default:
  1291. break;
  1292. }
  1293. break;
  1294. /* --------------------------------------------------------------- */
  1295. case 'F': /* The Form facility */
  1296. switch (argv[2][0])
  1297. {
  1298. case 'R': /* generate representation clause for Form_Option_Set */
  1299. gen_form_opt_rep("Form_Option_Set");
  1300. break;
  1301. case 'B': /* write some initial comment lines */
  1302. form_basedefs();
  1303. break;
  1304. case 'L': /* generate the Linker_Options pragma */
  1305. gen_form_linkopts();
  1306. break;
  1307. case 'I': /* generate representation clause for Field_Option_Set */
  1308. gen_field_opt_rep("Field_Option_Set");
  1309. break;
  1310. default:
  1311. break;
  1312. }
  1313. break;
  1314. /* --------------------------------------------------------------- */
  1315. case 'P': /* The Pointer(=Mouse) facility */
  1316. switch (argv[2][0])
  1317. {
  1318. case 'B': /* write some initial comment lines */
  1319. mouse_basedefs();
  1320. break;
  1321. case 'M': /* generate representation clause for Mouse_Event */
  1322. gen_mrep_rep("Mouse_Event");
  1323. break;
  1324. case 'L': /* generate the Linker_Options pragma */
  1325. gen_panel_linkopts();
  1326. break;
  1327. default:
  1328. break;
  1329. }
  1330. break;
  1331. /* --------------------------------------------------------------- */
  1332. case 'E': /* chtype size detection */
  1333. switch (argv[2][0])
  1334. {
  1335. case 'C':
  1336. {
  1337. const char *fmt = " type C_Chtype is new %s;\n";
  1338. const char *afmt = " type C_AttrType is new %s;\n";
  1339. if (sizeof(chtype) == sizeof(int))
  1340. {
  1341. if (sizeof(int) == sizeof(long))
  1342. printf(fmt, "C_ULong");
  1343. else
  1344. printf(fmt, "C_UInt");
  1345. }
  1346. else if (sizeof(chtype) == sizeof(long))
  1347. {
  1348. printf(fmt, "C_ULong");
  1349. }
  1350. else
  1351. printf("Error\n");
  1352. if (sizeof(attr_t) == sizeof(int))
  1353. {
  1354. if (sizeof(int) == sizeof(long))
  1355. printf(afmt, "C_ULong");
  1356. else
  1357. printf(afmt, "C_UInt");
  1358. }
  1359. else if (sizeof(attr_t) == sizeof(long))
  1360. {
  1361. printf(afmt, "C_ULong");
  1362. }
  1363. else
  1364. printf("Error\n");
  1365. printf("define(`CF_CURSES_OK',`%d')", OK);
  1366. printf("define(`CF_CURSES_ERR',`%d')", ERR);
  1367. printf("define(`CF_CURSES_TRUE',`%d')", TRUE);
  1368. printf("define(`CF_CURSES_FALSE',`%d')", FALSE);
  1369. }
  1370. break;
  1371. case 'E':
  1372. {
  1373. char *buf = (char *)malloc(2048);
  1374. char *p = buf;
  1375. int etimin = E_OK;
  1376. int etimax = E_OK;
  1377. if (p)
  1378. {
  1379. p += eti_gen(p, E_OK, "Ok", &etimin, &etimax);
  1380. p += eti_gen(p, E_SYSTEM_ERROR, "System_Error", &etimin, &etimax);
  1381. p += eti_gen(p, E_BAD_ARGUMENT, "Bad_Argument", &etimin, &etimax);
  1382. p += eti_gen(p, E_POSTED, "Posted", &etimin, &etimax);
  1383. p += eti_gen(p, E_CONNECTED, "Connected", &etimin, &etimax);
  1384. p += eti_gen(p, E_BAD_STATE, "Bad_State", &etimin, &etimax);
  1385. p += eti_gen(p, E_NO_ROOM, "No_Room", &etimin, &etimax);
  1386. p += eti_gen(p, E_NOT_POSTED, "Not_Posted", &etimin, &etimax);
  1387. p += eti_gen(p, E_UNKNOWN_COMMAND,
  1388. "Unknown_Command", &etimin, &etimax);
  1389. p += eti_gen(p, E_NO_MATCH, "No_Match", &etimin, &etimax);
  1390. p += eti_gen(p, E_NOT_SELECTABLE,
  1391. "Not_Selectable", &etimin, &etimax);
  1392. p += eti_gen(p, E_NOT_CONNECTED,
  1393. "Not_Connected", &etimin, &etimax);
  1394. p += eti_gen(p, E_REQUEST_DENIED,
  1395. "Request_Denied", &etimin, &etimax);
  1396. p += eti_gen(p, E_INVALID_FIELD,
  1397. "Invalid_Field", &etimin, &etimax);
  1398. p += eti_gen(p, E_CURRENT,
  1399. "Current", &etimin, &etimax);
  1400. }
  1401. printf(" subtype Eti_Error is C_Int range %d .. %d;\n\n",
  1402. etimin, etimax);
  1403. printf(buf);
  1404. }
  1405. break;
  1406. default:
  1407. break;
  1408. }
  1409. break;
  1410. /* --------------------------------------------------------------- */
  1411. case 'V': /* plain version dump */
  1412. {
  1413. switch (argv[2][0])
  1414. {
  1415. case '1': /* major version */
  1416. #ifdef NCURSES_VERSION_MAJOR
  1417. printf("%d", NCURSES_VERSION_MAJOR);
  1418. #endif
  1419. break;
  1420. case '2': /* minor version */
  1421. #ifdef NCURSES_VERSION_MINOR
  1422. printf("%d", NCURSES_VERSION_MINOR);
  1423. #endif
  1424. break;
  1425. case '3': /* patch level */
  1426. #ifdef NCURSES_VERSION_PATCH
  1427. printf("%d", NCURSES_VERSION_PATCH);
  1428. #endif
  1429. break;
  1430. default:
  1431. break;
  1432. }
  1433. }
  1434. break;
  1435. /* --------------------------------------------------------------- */
  1436. default:
  1437. break;
  1438. }
  1439. return 0;
  1440. }