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

📄 makestrs.c

📁 unix vnc 协议源码. VNC是一款远程控制工具软件.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $XConsortium: makestrs.c /main/10 1996/11/22 07:27:41 kaleb $ *//*Copyright (c) 1991  X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shall not beused in advertising or otherwise to promote the sale, use or other dealingsin this Software without prior written authorization from the X Consortium.*//* Constructs string definitions */#include <stdio.h>#include <X11/Xos.h>#ifndef X_NOT_STDC_ENV#include <stdlib.h>#elsechar *malloc();#endif#if defined(macII) && !defined(__STDC__)  /* stdlib.h fails to define these */char *malloc();#endif /* macII */typedef struct _TableEnt {    struct _TableEnt* next;    char* left;    char* right;    int offset;} TableEnt;typedef struct _Table {    struct _Table* next;    TableEnt* tableent;    TableEnt* tableentcurrent;    TableEnt** tableenttail;    char* name;    int offset;} Table;typedef struct _File {    struct _File* next;    FILE* tmpl;    char* name;    Table* table;    Table* tablecurrent;    Table** tabletail;} File;static File* file = NULL;static File* filecurrent = NULL;static File** filetail = &file;static char* conststr;static char* prefixstr = NULL;static char* featurestr = NULL;static char* ctmplstr = NULL;static char* fileprotstr;static char* externrefstr;static char* externdefstr;#define X_DEFAULT_ABI	0#define X_ARRAYPER_ABI	1#define X_INTEL_ABI	2#define X_INTEL_ABI_BC	3#define X_SPARC_ABI	4#define X_FUNCTION_ABI	5#define X_MAGIC_STRING "<<<STRING_TABLE_GOES_HERE>>>"static void WriteHeaderProlog (f, phile)    FILE* f;    File* phile;{    Table* t;    TableEnt* te;    (void) fprintf (f, "#ifdef %s\n", featurestr);    for (t = phile->table; t; t = t->next)	for (te = t->tableent; te; te = te->next) {	    if (strcmp (te->left, "RAtom") == 0) {		(void) fprintf (f, 			"#ifndef %s%s\n#define %s%s \"%s\"\n#endif\n",			prefixstr, te->left, prefixstr, te->left, te->right);	    } else {		(void) fprintf (f, 			"#define %s%s \"%s\"\n",			prefixstr, te->left, te->right);	    }	}    (void) fprintf (f, "%s", "#else\n");}static void IntelABIWriteHeader (f, phile)    FILE* f;    File* phile;{    Table* t;    TableEnt* te;    WriteHeaderProlog (f, phile);    for (t = phile->table; t; t = t->next) {      (void) fprintf (f, "%s %sConst char %s[];\n", 		      externrefstr, conststr ? conststr : fileprotstr, t->name);	for (te = t->tableent; te; te = te->next)	    (void) fprintf (f, 		"#ifndef %s%s\n#define %s%s ((char*)&%s[%d])\n#endif\n",		prefixstr, te->left, prefixstr, te->left, t->name, te->offset);    }    (void) fprintf (f, "#endif /* %s */\n", featurestr);}static void SPARCABIWriteHeader (f, phile)    FILE* f;    File* phile;{    Table* t;    TableEnt* te;    for (t = phile->table; t; t = t->next)	for (te = t->tableent; te; te = te->next)	    (void) fprintf (f, "#define %s%s \"%s\"\n",			    prefixstr, te->left, te->right);}static void FunctionWriteHeader (f, phile)    FILE* f;    File* phile;{    Table* t;    TableEnt* te;    WriteHeaderProlog (f, phile);    (void) fprintf (f, "%s %sConst char* %s();\n", 		    externrefstr, conststr ? conststr : fileprotstr, 		    phile->table->name);    for (t = phile->table; t; t = t->next)	for (te = t->tableent; te; te = te->next)	    (void) fprintf (f, 		"#ifndef %s%s\n#define %s%s (%s(%d))\n#endif\n",		prefixstr, te->left, prefixstr, te->left, phile->table->name, 		te->offset);    (void) fprintf (f, "#endif /* %s */\n", featurestr);}static void ArrayperWriteHeader (f, phile)    FILE* f;    File* phile;{    Table* t;    TableEnt* te;    WriteHeaderProlog (f, phile);    for (t = phile->table; t; t = t->next)        for (te = t->tableent; te; te = te->next)	    (void) fprintf (f, 			    "#ifndef %s%s\n%s %sConst char %s%s[];\n#endif\n",			    prefixstr, te->left, 			    externrefstr, conststr ? conststr : fileprotstr, 			    prefixstr, te->left);    (void) fprintf (f, "#endif /* %s */\n", featurestr);}static void DefaultWriteHeader (f, phile)    FILE* f;    File* phile;{    Table* t;    TableEnt* te;    WriteHeaderProlog (f, phile);    (void) fprintf (f, "%s %sConst char %s[];\n", 		    externrefstr, conststr ? conststr : fileprotstr, 		    phile->table->name);    for (t = phile->table; t; t = t->next)	for (te = t->tableent; te; te = te->next)	    (void) fprintf (f, 		"#ifndef %s%s\n#define %s%s ((char*)&%s[%d])\n#endif\n",		prefixstr, te->left, prefixstr, te->left, phile->table->name, 		te->offset);    (void) fprintf (f, "#endif /* %s */\n", featurestr);}static void CopyTmplProlog (tmpl, f)    FILE* tmpl;    FILE* f;{    char buf[1024];    static char* magic_string = X_MAGIC_STRING;    int magic_string_len = strlen (magic_string);    while (fgets (buf, sizeof buf, tmpl)) {	if (strncmp (buf, magic_string, magic_string_len) == 0) {	    return;	}	(void) fputs (buf, f);    }}static void CopyTmplEpilog (tmpl, f)    FILE* tmpl;    FILE* f;{    char buf[1024];    while (fgets (buf, sizeof buf, tmpl))	(void) fputs (buf, f);}static char* abistring[] = {    "Default", "Array per string", "Intel", "Intel BC", "SPARC", "Function" };static void WriteHeader (tagline, phile, abi)    char* tagline;    File* phile;    int abi;{    FILE* f;    char* tmp;    Table* t;    TableEnt* te;    static void (*headerproc[])() = { 	DefaultWriteHeader, ArrayperWriteHeader,	IntelABIWriteHeader, IntelABIWriteHeader,	SPARCABIWriteHeader, FunctionWriteHeader };    if ((f = fopen (phile->name, "w+")) == NULL) exit (1);    if (phile->tmpl) CopyTmplProlog (phile->tmpl, f);    (void) fprintf (f, 	"%s\n%s\n/* %s ABI version -- Do not edit */\n", 	"/* $XConsortium: makestrs.c /main/10 1996/11/22 07:27:41 kaleb $ */",	"/* This file is automatically generated. */",	abistring[abi]);    if (tagline) (void) fprintf (f, "/* %s */\n\n", tagline);    /* do the right thing for Motif, i.e. avoid _XmXmStrDefs_h_ */    if (strcmp (prefixstr, "Xm") == 0) {	if ((fileprotstr = malloc (strlen (phile->name) + 3)) == NULL)	   exit (1);	(void) sprintf (fileprotstr, "_%s_", phile->name);    } else {	if ((fileprotstr = malloc (strlen (phile->name) + strlen (prefixstr) +  3)) == NULL)	   exit (1);	(void) sprintf (fileprotstr, "_%s%s_", prefixstr, phile->name);    }    for (tmp = fileprotstr; *tmp; tmp++) if (*tmp == '.') *tmp = '_';    (*headerproc[abi])(f, phile);    if (phile->tmpl) CopyTmplEpilog (phile->tmpl, f);    (void) free (fileprotstr);    (void) fclose (phile->tmpl);    (void) fclose (f);}static void WriteSourceLine (te, abi, fudge)    TableEnt* te;    int abi;{    char* c;    for (c = te->right; *c; c++) (void) printf ("'%c',", *c);    (void) printf ("%c", '0');    if (te->next || fudge) (void) printf ("%c", ',');    (void) printf ("%s", "\n");}static char* const_string = "%s %sConst char %s[] = {\n";static void IntelABIWriteSource (abi)    int abi;{    File* phile;    for (phile = file; phile; phile = phile->next) {	Table* t;	TableEnt* te;	for (t = phile->table; t; t = t->next) {	    (void) printf (const_string, externdefstr, 			   conststr ? conststr : "", t->name);	    for (te = t->tableent; te; te = te->next)		WriteSourceLine (te, abi, 0);	    (void) printf ("%s\n\n", "};");	}    }}static void IntelABIBCWriteSource (abi)    int abi;{    File* phile;    for (phile = file; phile; phile = phile->next) {	Table* t;	TableEnt* te;	(void) printf (const_string, externdefstr, 		       conststr ? conststr : "", phile->table->name);	for (t = phile->table; t; t = t->next) 	    for (te = t->tableent; te; te = te->next)		WriteSourceLine (te, abi, t->next ? 1 : 0);	(void) printf ("%s\n\n", "};");	if (phile->table->next) {	    (void) printf (const_string, externdefstr, 			   conststr ? conststr : "", phile->table->next->name);	    for (t = phile->table->next; t; t = t->next) 		for (te = t->tableent; te; te = te->next)		    WriteSourceLine (te, abi, 0);	    (void) printf ("%s\n\n", "};");	}    }}static void FunctionWriteSource (abi)    int abi;{    File* phile;    for (phile = file; phile; phile = phile->next) {	Table* t;	TableEnt* te;	(void) printf ("static %sConst char _%s[] = {\n", 		       conststr ? conststr : "", phile->table->name);	for (t = phile->table; t; t = t->next) 	    for (te = t->tableent; te; te = te->next)		WriteSourceLine (te, abi, t->next ? 1 : 0);	(void) printf ("%s\n\n", "};");	(void) printf ("%sConst char* %s(index)\n    int index;\n{\n    return &_%s[index];\n}\n\n",		       conststr ? conststr : "", 		       phile->table->name, phile->table->name);    }}

⌨️ 快捷键说明

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