⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gen.c

📁 ncurses 库 可能有用酒用 没用就算了 我觉得还可以用
💻 C
📖 第 1 页 / 共 3 页
字号:
/**************************************************************************** * Copyright (c) 1998,2004,2005 Free Software Foundation, Inc.              * *                                                                          * * Permission is hereby granted, free of charge, to any person obtaining a  * * copy of this software and associated documentation files (the            * * "Software"), to deal in the Software without restriction, including      * * without limitation the rights to use, copy, modify, merge, publish,      * * distribute, distribute with modifications, sublicense, and/or sell       * * copies of the Software, and to permit persons to whom the Software is    * * furnished to do so, subject to the following conditions:                 * *                                                                          * * The above copyright notice and this permission notice shall be included  * * in all copies or substantial portions of the Software.                   * *                                                                          * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  * * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               * * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   * * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   * * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    * * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    * * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               * *                                                                          * * Except as contained in this notice, the name(s) of the above copyright   * * holders shall not be used in advertising or otherwise to promote the     * * sale, use or other dealings in this Software without prior written       * * authorization.                                                           * ****************************************************************************//**************************************************************************** *   Author:  Juergen Pfeifer, 1996                                         * ****************************************************************************//*    Version Control    $Id: gen.c,v 1.40 2005/01/22 17:03:48 tom Exp $  --------------------------------------------------------------------------*//*  This program generates various record structures and constants from the  ncurses header file for the Ada95 packages. Essentially it produces  Ada95 source on stdout, which is then merged using m4 into a template  to produce the real source.  */#include <stdlib.h>#include <stddef.h>#include <string.h>#include <assert.h>#include <ctype.h>#include <menu.h>#include <form.h>#define RES_NAME "Reserved"static const char *model = "";static int little_endian = 0;typedef struct  {    const char *name;    unsigned long attr;  }name_attribute_pair;static intfind_pos(char *s, unsigned len, int *low, int *high){  unsigned int i, j;  int l = 0;  *high = -1;  *low = 8 * len;  for (i = 0; i < len; i++, s++)    {      if (*s)	{	  for (j = 0; j < 8 * sizeof(char); j++)	    {	      if (((little_endian && ((*s) & 0x01)) ||		   (!little_endian && ((*s) & 0x80))))		{		  if (l > *high)		    *high = l;		  if (l < *low)		    *low = l;		}	      l++;	      if (little_endian)		*s >>= 1;	      else		*s <<= 1;	    }	}      else	l += 8;    }  return (*high >= 0 && (*low <= *high)) ? *low : -1;}/* * This helper routine generates a representation clause for a * record type defined in the binding. * We are only dealing with record types which are of 32 or 16 * bit size, i.e. they fit into an (u)int or a (u)short. */static void  gen_reps  (const name_attribute_pair * nap,	/* array of name_attribute_pair records */   const char *name,		/* name of the represented record type  */   int len,			/* size of the record in bytes          */   int bias){  int i, n, l, cnt = 0, low, high;  int width = strlen(RES_NAME) + 3;  unsigned long a;  unsigned long mask = 0;  assert(nap != NULL);  for (i = 0; nap[i].name != (char *)0; i++)    {      cnt++;      l = strlen(nap[i].name);      if (l > width)	width = l;    }  assert(width > 0);  printf("   type %s is\n", name);  printf("      record\n");  for (i = 0; nap[i].name != (char *)0; i++)    {      printf("         %-*s : Boolean;\n", width, nap[i].name);    }  printf("      end record;\n");  printf("   pragma Convention (C, %s);\n\n", name);  printf("   for %s use\n", name);  printf("      record\n");  for (i = 0; nap[i].name != (char *)0; i++)    {      a = nap[i].attr;      mask |= a;      l = find_pos((char *)&a, sizeof(a), &low, &high);      if (l >= 0)	printf("         %-*s at 0 range %2d .. %2d;\n", width, nap[i].name,	       low - bias, high - bias);    }  i = 1;  n = cnt;  printf("      end record;\n");  printf("   for %s'Size use %d;\n", name, 8 * len);  printf("   --  Please note: this rep. clause is generated and may be\n");  printf("   --               different on your system.");}static voidchtype_rep(const char *name, attr_t mask){  attr_t x = -1;  attr_t t = x & mask;  int low, high;  int l = find_pos((char *)&t, sizeof(t), &low, &high);  if (l >= 0)    printf("         %-5s at 0 range %2d .. %2d;\n", name, low, high);}static voidgen_chtype_rep(const char *name){  printf("   for %s use\n      record\n", name);  chtype_rep("Ch", A_CHARTEXT);  chtype_rep("Color", A_COLOR);  chtype_rep("Attr", (A_ATTRIBUTES & ~A_COLOR));  printf("      end record;\n   for %s'Size use %ld;\n",	 name, (long)(8 * sizeof(chtype)));  printf("      --  Please note: this rep. clause is generated and may be\n");  printf("      --               different on your system.\n");}static voidmrep_rep(const char *name, void *rec){  int low, high;  int l = find_pos((char *)rec, sizeof(MEVENT), &low, &high);  if (l >= 0)    printf("         %-7s at 0 range %3d .. %3d;\n", name, low, high);}static voidgen_mrep_rep(const char *name){  MEVENT x;  printf("   for %s use\n      record\n", name);  memset(&x, 0, sizeof(x));  x.id = -1;  mrep_rep("Id", &x);  memset(&x, 0, sizeof(x));  x.x = -1;  mrep_rep("X", &x);  memset(&x, 0, sizeof(x));  x.y = -1;  mrep_rep("Y", &x);  memset(&x, 0, sizeof(x));  x.z = -1;  mrep_rep("Z", &x);  memset(&x, 0, sizeof(x));  x.bstate = -1;  mrep_rep("Bstate", &x);  printf("      end record;\n");  printf("      --  Please note: this rep. clause is generated and may be\n");  printf("      --               different on your system.\n");}static voidgen_attr_set(const char *name){  /* All of the A_xxx symbols are defined in ncurses, but not all are nonzero   * if "configure --enable-widec" is specified.   */  static const name_attribute_pair nap[] =  {#if A_STANDOUT    {"Stand_Out", A_STANDOUT},#endif#if A_UNDERLINE    {"Under_Line", A_UNDERLINE},#endif#if A_REVERSE    {"Reverse_Video", A_REVERSE},#endif#if A_BLINK    {"Blink", A_BLINK},#endif#if A_DIM    {"Dim_Character", A_DIM},#endif#if A_BOLD    {"Bold_Character", A_BOLD},#endif#if A_ALTCHARSET    {"Alternate_Character_Set", A_ALTCHARSET},#endif#if A_INVIS    {"Invisible_Character", A_INVIS},#endif#if A_PROTECT    {"Protected_Character", A_PROTECT},#endif#if A_HORIZONTAL    {"Horizontal", A_HORIZONTAL},#endif#if A_LEFT    {"Left", A_LEFT},#endif#if A_LOW    {"Low", A_LOW},#endif#if A_RIGHT    {"Right", A_RIGHT},#endif#if A_TOP    {"Top", A_TOP},#endif#if A_VERTICAL    {"Vertical", A_VERTICAL},#endif    {(char *)0, 0}  };  chtype attr = A_ATTRIBUTES & ~A_COLOR;  int start = -1;  int len = 0;  int i, set;  for (i = 0; i < (int)(8 * sizeof(chtype)); i++)    {      set = attr & 1;      if (set)	{	  if (start < 0)	    start = i;	  if (start >= 0)	    {	      len++;	    }	}      attr = attr >> 1;    }  gen_reps(nap, name, (len + 7) / 8, little_endian ? start : 0);}static voidgen_trace(const char *name){  static const name_attribute_pair nap[] =  {    {"Times", TRACE_TIMES},    {"Tputs", TRACE_TPUTS},    {"Update", TRACE_UPDATE},    {"Cursor_Move", TRACE_MOVE},    {"Character_Output", TRACE_CHARPUT},    {"Calls", TRACE_CALLS},    {"Virtual_Puts", TRACE_VIRTPUT},    {"Input_Events", TRACE_IEVENT},    {"TTY_State", TRACE_BITS},    {"Internal_Calls", TRACE_ICALLS},    {"Character_Calls", TRACE_CCALLS},    {"Termcap_TermInfo", TRACE_DATABASE},    {(char *)0, 0}  };  gen_reps(nap, name, sizeof(int), 0);}static voidgen_menu_opt_rep(const char *name){  static const name_attribute_pair nap[] =  {#ifdef O_ONEVALUE    {"One_Valued", O_ONEVALUE},#endif#ifdef O_SHOWDESC    {"Show_Descriptions", O_SHOWDESC},#endif#ifdef O_ROWMAJOR    {"Row_Major_Order", O_ROWMAJOR},#endif#ifdef O_IGNORECASE    {"Ignore_Case", O_IGNORECASE},#endif#ifdef O_SHOWMATCH    {"Show_Matches", O_SHOWMATCH},#endif#ifdef O_NONCYCLIC    {"Non_Cyclic", O_NONCYCLIC},#endif    {(char *)0, 0}  };  gen_reps(nap, name, sizeof(int), 0);}static voidgen_item_opt_rep(const char *name){  static const name_attribute_pair nap[] =  {#ifdef O_SELECTABLE    {"Selectable", O_SELECTABLE},#endif    {(char *)0, 0}  };  gen_reps(nap, name, sizeof(int), 0);}static voidgen_form_opt_rep(const char *name){  static const name_attribute_pair nap[] =  {#ifdef O_NL_OVERLOAD    {"NL_Overload", O_NL_OVERLOAD},#endif#ifdef O_BS_OVERLOAD    {"BS_Overload", O_BS_OVERLOAD},#endif    {(char *)0, 0}  };  gen_reps(nap, name, sizeof(int), 0);}/* * Generate the representation clause for the Field_Option_Set record */static voidgen_field_opt_rep(const char *name){  static const name_attribute_pair nap[] =  {#ifdef O_VISIBLE    {"Visible", O_VISIBLE},#endif#ifdef O_ACTIVE    {"Active", O_ACTIVE},#endif#ifdef O_PUBLIC    {"Public", O_PUBLIC},#endif#ifdef O_EDIT    {"Edit", O_EDIT},#endif#ifdef O_WRAP    {"Wrap", O_WRAP},#endif#ifdef O_BLANK    {"Blank", O_BLANK},#endif#ifdef O_AUTOSKIP    {"Auto_Skip", O_AUTOSKIP},#endif#ifdef O_NULLOK    {"Null_Ok", O_NULLOK},#endif#ifdef O_PASSOK    {"Pass_Ok", O_PASSOK},#endif#ifdef O_STATIC    {"Static", O_STATIC},#endif    {(char *)0, 0}  };  gen_reps(nap, name, sizeof(int), 0);}/* * Generate a single key code constant definition. */static voidkeydef(const char *name, const char *old_name, int value, int mode){  if (mode == 0)		/* Generate the new name */    printf("   %-30s : constant Special_Key_Code := 8#%3o#;\n", name, value);  else    {				/* generate the old name, but only if it doesn't conflict with the old				 * name (Ada95 isn't case sensitive!)				 */      const char *s = old_name;      const char *t = name;      while (*s && *t && (toupper(*s++) == toupper(*t++)));      if (*s || *t)	printf("   %-16s : Special_Key_Code renames %s;\n", old_name, name);    }}/* * Generate constants for the key codes. When called with mode==0, a * complete list with nice constant names in proper casing style will * be generated. Otherwise a list of old (i.e. C-style) names will be * generated, given that the name wasn't already defined in the "nice" * list. */static voidgen_keydefs(int mode){  char buf[16];  char obuf[16];  int i;#ifdef KEY_CODE_YES  keydef("Key_Code_Yes", "KEY_CODE_YES", KEY_CODE_YES, mode);#endif#ifdef KEY_MIN  keydef("Key_Min", "KEY_MIN", KEY_MIN, mode);#endif#ifdef KEY_BREAK  keydef("Key_Break", "KEY_BREAK", KEY_BREAK, mode);#endif#ifdef KEY_DOWN  keydef("Key_Cursor_Down", "KEY_DOWN", KEY_DOWN, mode);#endif#ifdef KEY_UP  keydef("Key_Cursor_Up", "KEY_UP", KEY_UP, mode);#endif#ifdef KEY_LEFT  keydef("Key_Cursor_Left", "KEY_LEFT", KEY_LEFT, mode);#endif#ifdef KEY_RIGHT  keydef("Key_Cursor_Right", "KEY_RIGHT", KEY_RIGHT, mode);#endif#ifdef KEY_HOME  keydef("Key_Home", "KEY_HOME", KEY_HOME, mode);#endif#ifdef KEY_BACKSPACE  keydef("Key_Backspace", "KEY_BACKSPACE", KEY_BACKSPACE, mode);#endif#ifdef KEY_F0  keydef("Key_F0", "KEY_F0", KEY_F0, mode);#endif#ifdef KEY_F  for (i = 1; i <= 24; i++)    {      sprintf(buf, "Key_F%d", i);      sprintf(obuf, "KEY_F%d", i);      keydef(buf, obuf, KEY_F(i), mode);    }#endif#ifdef KEY_DL  keydef("Key_Delete_Line", "KEY_DL", KEY_DL, mode);#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -