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

📄 gen.c

📁 ncurses 库 可能有用酒用 没用就算了 我觉得还可以用
💻 C
📖 第 1 页 / 共 3 页
字号:
}/* * Output some comment lines indicating that the file is generated. * The name parameter is the name of the facility to be used in * the comment. */static voidprologue(const char *name){  printf("--  %s binding.\n", name);  printf("--  This module is generated. Please don't change it manually!\n");  printf("--  Run the generator instead.\n--  |");  printf("define(`M4_BIT_ORDER',`%s_Order_First')",	 little_endian ? "Low" : "High");}/* * Write the prologue for the curses facility and make sure that * KEY_MIN and KEY_MAX are defined for the rest of this source. */static voidbasedefs(void){  prologue("curses");#ifndef KEY_MAX#  define KEY_MAX 0777#endif  printf("define(`M4_KEY_MAX',`8#%o#')", KEY_MAX);#ifndef KEY_MIN#  define KEY_MIN 0401#endif  if (KEY_MIN == 256)    {      fprintf(stderr, "Unexpected value for KEY_MIN: %d\n", KEY_MIN);      exit(1);    }  printf("define(`M4_SPECIAL_FIRST',`8#%o#')", KEY_MIN - 1);}/* * Write out the comment lines for the menu facility */static voidmenu_basedefs(void){  prologue("menu");}/* * Write out the comment lines for the form facility */static voidform_basedefs(void){  prologue("form");}/* * Write out the comment lines for the mouse facility */static voidmouse_basedefs(void){  prologue("mouse");}/* * Write the definition of a single color */static voidcolor_def(const char *name, int value){  printf("   %-16s : constant Color_Number := %d;\n", name, value);}#define HAVE_USE_DEFAULT_COLORS 1/* * Generate all color definitions */static voidgen_color(void){#ifdef HAVE_USE_DEFAULT_COLORS  color_def("Default_Color", -1);#endif#ifdef COLOR_BLACK  color_def("Black", COLOR_BLACK);#endif#ifdef COLOR_RED  color_def("Red", COLOR_RED);#endif#ifdef COLOR_GREEN  color_def("Green", COLOR_GREEN);#endif#ifdef COLOR_YELLOW  color_def("Yellow", COLOR_YELLOW);#endif#ifdef COLOR_BLUE  color_def("Blue", COLOR_BLUE);#endif#ifdef COLOR_MAGENTA  color_def("Magenta", COLOR_MAGENTA);#endif#ifdef COLOR_CYAN  color_def("Cyan", COLOR_CYAN);#endif#ifdef COLOR_WHITE  color_def("White", COLOR_WHITE);#endif}/* * Generate the linker options for the base facility */static voidgen_linkopts(void){  printf("   pragma Linker_Options (\"-lncurses%s\");\n", model);}/* * Generate the linker options for the menu facility */static voidgen_menu_linkopts(void){  printf("   pragma Linker_Options (\"-lmenu%s\");\n", model);}/* * Generate the linker options for the form facility */static voidgen_form_linkopts(void){  printf("   pragma Linker_Options (\"-lform%s\");\n", model);}/* * Generate the linker options for the panel facility */static voidgen_panel_linkopts(void){  printf("   pragma Linker_Options (\"-lpanel%s\");\n", model);}static voidgen_version_info(void){  static const char *v1 =  "   NC_Major_Version : constant := %d; --  Major version of the library\n";  static const char *v2 =  "   NC_Minor_Version : constant := %d; --  Minor version of the library\n";  static const char *v3 =  "   NC_Version : constant String := %c%d.%d%c;  --  Version of library\n";  printf(v1, NCURSES_VERSION_MAJOR);  printf(v2, NCURSES_VERSION_MINOR);  printf(v3, '"', NCURSES_VERSION_MAJOR, NCURSES_VERSION_MINOR, '"');}static inteti_gen(char *buf, int code, const char *name, int *etimin, int *etimax){  sprintf(buf, "   E_%-16s : constant Eti_Error := %d;\n", name, code);  if (code < *etimin)    *etimin = code;  if (code > *etimax)    *etimax = code;  return strlen(buf);}#define GEN_OFFSET(member,itype)                                    \  if (sizeof(((WINDOW*)0)->member)==sizeof(itype)) {                \    o = offsetof(WINDOW, member);                                   \    if ((o%sizeof(itype) == 0)) {                                   \       printf("   Offset%-*s : constant Natural := %2ld; --  %s\n", \              12, #member, (long)(o/sizeof(itype)),#itype);         \    }                                                               \  }static voidgen_offsets(void){  long o;  const char *s_bool = "";  GEN_OFFSET(_maxy, short);  GEN_OFFSET(_maxx, short);  GEN_OFFSET(_begy, short);  GEN_OFFSET(_begx, short);  GEN_OFFSET(_cury, short);  GEN_OFFSET(_curx, short);  GEN_OFFSET(_yoffset, short);  GEN_OFFSET(_pary, int);  GEN_OFFSET(_parx, int);  if (sizeof(bool) == sizeof(char))    {      GEN_OFFSET(_notimeout, char);      GEN_OFFSET(_clear, char);      GEN_OFFSET(_leaveok, char);      GEN_OFFSET(_scroll, char);      GEN_OFFSET(_idlok, char);      GEN_OFFSET(_idcok, char);      GEN_OFFSET(_immed, char);      GEN_OFFSET(_sync, char);      GEN_OFFSET(_use_keypad, char);      s_bool = "char";    }  else if (sizeof(bool) == sizeof(short))    {      GEN_OFFSET(_notimeout, short);      GEN_OFFSET(_clear, short);      GEN_OFFSET(_leaveok, short);      GEN_OFFSET(_scroll, short);      GEN_OFFSET(_idlok, short);      GEN_OFFSET(_idcok, short);      GEN_OFFSET(_immed, short);      GEN_OFFSET(_sync, short);      GEN_OFFSET(_use_keypad, short);      s_bool = "short";    }  else if (sizeof(bool) == sizeof(int))    {      GEN_OFFSET(_notimeout, int);      GEN_OFFSET(_clear, int);      GEN_OFFSET(_leaveok, int);      GEN_OFFSET(_scroll, int);      GEN_OFFSET(_idlok, int);      GEN_OFFSET(_idcok, int);      GEN_OFFSET(_immed, int);      GEN_OFFSET(_sync, int);      GEN_OFFSET(_use_keypad, int);      s_bool = "int";    }  printf("   Sizeof%-*s : constant Natural := %2ld; --  %s\n",	 12, "_bool", (long)sizeof(bool), "bool");  /* In ncurses _maxy and _maxx needs an offset for the "public"   * value   */  printf("   Offset%-*s : constant Natural := %2d; --  %s\n",	 12, "_XY", 1, "int");  printf("\n");  printf("   type Curses_Bool is mod 2 ** Interfaces.C.%s'Size;\n", s_bool);}/* * main() expects two arguments on the commandline, both single characters. * The first character denotes the facility for which we generate output. * Possible values are *   B - Base *   M - Menus *   F - Forms *   P - Pointer Device (Mouse) *   E - ETI base definitions * * The second character then denotes the specific output that should be * generated for the selected facility. */intmain(int argc, char *argv[]){  int x = 0x12345678;  char *s = (char *)&x;  if (*s == 0x78)    little_endian = 1;  if (argc != 4)    exit(1);  model = *++argv;  switch (argv[1][0])    {      /* --------------------------------------------------------------- */    case 'B':			/* The Base facility */      switch (argv[2][0])	{	case 'A':		/* chtype translation into Ada95 record type */	  gen_attr_set("Character_Attribute_Set");	  break;	case 'K':		/* translation of keycodes */	  gen_keydefs(0);	  break;	case 'B':		/* write some initial comment lines */	  basedefs();	  break;	case 'C':		/* generate color constants */	  gen_color();	  break;	case 'D':		/* generate displacements of fields in WINDOW struct. */	  gen_offsets();	  break;	case 'E':		/* generate Mouse Event codes */	  gen_mouse_events();	  break;	case 'M':		/* generate constants for the ACS characters */	  gen_acs();	  break;	case 'L':		/* generate the Linker_Options pragma */	  gen_linkopts();	  break;	case 'O':		/* generate definitions of the old key code names */	  gen_keydefs(1);	  break;	case 'R':		/* generate representation clause for Attributed character */	  gen_chtype_rep("Attributed_Character");	  break;	case 'V':		/* generate version info */	  gen_version_info();	  break;	case 'T':		/* generate the Trace info */	  gen_trace("Trace_Attribute_Set");	  break;	default:	  break;	}      break;      /* --------------------------------------------------------------- */    case 'M':			/* The Menu facility */      switch (argv[2][0])	{	case 'R':		/* generate representation clause for Menu_Option_Set */	  gen_menu_opt_rep("Menu_Option_Set");	  break;	case 'B':		/* write some initial comment lines */	  menu_basedefs();	  break;	case 'L':		/* generate the Linker_Options pragma */	  gen_menu_linkopts();	  break;	case 'I':		/* generate representation clause for Item_Option_Set */	  gen_item_opt_rep("Item_Option_Set");	  break;	default:	  break;	}      break;      /* --------------------------------------------------------------- */    case 'F':			/* The Form facility */      switch (argv[2][0])	{	case 'R':		/* generate representation clause for Form_Option_Set */	  gen_form_opt_rep("Form_Option_Set");	  break;	case 'B':		/* write some initial comment lines */	  form_basedefs();	  break;	case 'L':		/* generate the Linker_Options pragma */	  gen_form_linkopts();	  break;	case 'I':		/* generate representation clause for Field_Option_Set */	  gen_field_opt_rep("Field_Option_Set");	  break;	default:	  break;	}      break;      /* --------------------------------------------------------------- */    case 'P':			/* The Pointer(=Mouse) facility */      switch (argv[2][0])	{	case 'B':		/* write some initial comment lines */	  mouse_basedefs();	  break;	case 'M':		/* generate representation clause for Mouse_Event */	  gen_mrep_rep("Mouse_Event");	  break;	case 'L':		/* generate the Linker_Options pragma */	  gen_panel_linkopts();	  break;	default:	  break;	}      break;      /* --------------------------------------------------------------- */    case 'E':			/* chtype size detection */      switch (argv[2][0])	{	case 'C':	  {	    const char *fmt = "   type    C_Chtype   is new %s;\n";	    const char *afmt = "   type    C_AttrType is new %s;\n";	    if (sizeof(chtype) == sizeof(int))	      {		if (sizeof(int) == sizeof(long))		    printf(fmt, "C_ULong");		else		  printf(fmt, "C_UInt");	      }	    else if (sizeof(chtype) == sizeof(long))	      {		printf(fmt, "C_ULong");	      }	    else	      printf("Error\n");	    if (sizeof(attr_t) == sizeof(int))	      {		if (sizeof(int) == sizeof(long))		    printf(afmt, "C_ULong");		else		  printf(afmt, "C_UInt");	      }	    else if (sizeof(attr_t) == sizeof(long))	      {		printf(afmt, "C_ULong");	      }	    else	      printf("Error\n");	    printf("define(`CF_CURSES_OK',`%d')", OK);	    printf("define(`CF_CURSES_ERR',`%d')", ERR);	    printf("define(`CF_CURSES_TRUE',`%d')", TRUE);	    printf("define(`CF_CURSES_FALSE',`%d')", FALSE);	  }	  break;	case 'E':	  {	    char *buf = (char *)malloc(2048);	    char *p = buf;	    int etimin = E_OK;	    int etimax = E_OK;	    if (p)	      {		p += eti_gen(p, E_OK, "Ok", &etimin, &etimax);		p += eti_gen(p, E_SYSTEM_ERROR, "System_Error", &etimin, &etimax);		p += eti_gen(p, E_BAD_ARGUMENT, "Bad_Argument", &etimin, &etimax);		p += eti_gen(p, E_POSTED, "Posted", &etimin, &etimax);		p += eti_gen(p, E_CONNECTED, "Connected", &etimin, &etimax);		p += eti_gen(p, E_BAD_STATE, "Bad_State", &etimin, &etimax);		p += eti_gen(p, E_NO_ROOM, "No_Room", &etimin, &etimax);		p += eti_gen(p, E_NOT_POSTED, "Not_Posted", &etimin, &etimax);		p += eti_gen(p, E_UNKNOWN_COMMAND,			     "Unknown_Command", &etimin, &etimax);		p += eti_gen(p, E_NO_MATCH, "No_Match", &etimin, &etimax);		p += eti_gen(p, E_NOT_SELECTABLE,			     "Not_Selectable", &etimin, &etimax);		p += eti_gen(p, E_NOT_CONNECTED,			     "Not_Connected", &etimin, &etimax);		p += eti_gen(p, E_REQUEST_DENIED,			     "Request_Denied", &etimin, &etimax);		p += eti_gen(p, E_INVALID_FIELD,			     "Invalid_Field", &etimin, &etimax);		p += eti_gen(p, E_CURRENT,			     "Current", &etimin, &etimax);	      }	    printf("   subtype Eti_Error is C_Int range %d .. %d;\n\n",		   etimin, etimax);	    printf(buf);	  }	  break;	default:	  break;	}      break;      /* --------------------------------------------------------------- */    case 'V':			/* plain version dump */      {	switch (argv[2][0])	  {	  case '1':		/* major version */#ifdef NCURSES_VERSION_MAJOR	    printf("%d", NCURSES_VERSION_MAJOR);#endif	    break;	  case '2':		/* minor version */#ifdef NCURSES_VERSION_MINOR	    printf("%d", NCURSES_VERSION_MINOR);#endif	    break;	  case '3':		/* patch level */#ifdef NCURSES_VERSION_PATCH	    printf("%d", NCURSES_VERSION_PATCH);#endif	    break;	  default:	    break;	  }      }      break;      /* --------------------------------------------------------------- */    default:      break;    }  return 0;}

⌨️ 快捷键说明

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