📄 makestrs.c
字号:
static void ArrayperWriteSource (abi) int abi;{ File* phile; static int done_atom; for (phile = file; phile; phile = phile->next) { Table* t; TableEnt* te; for (t = phile->table; t; t = t->next) for (te = t->tableent; te; te = te->next) { if (strcmp (te->left, "RAtom") == 0) { if (done_atom) return; done_atom = 1; } (void) printf ("%s %sConst char %s%s[] = \"%s\";\n", externdefstr, conststr ? conststr : "", prefixstr, te->left, te->right); } }}static void DefaultWriteSource (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", "};"); }}static void WriteSource(tagline, abi) char* tagline; int abi;{ static void (*sourceproc[])() = { DefaultWriteSource, ArrayperWriteSource, IntelABIWriteSource, IntelABIBCWriteSource, DefaultWriteSource, FunctionWriteSource }; FILE* tmpl; if (ctmplstr) { tmpl = fopen (ctmplstr, "r"); if (tmpl) CopyTmplProlog (tmpl, stdout); else { (void) fprintf (stderr, "Expected template %s, not found\n", ctmplstr); exit (1); } } else tmpl = NULL; (void) printf ("%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) printf ("/* %s */\n\n", tagline); (*sourceproc[abi])(abi); if (tmpl) CopyTmplEpilog (tmpl, stdout);}static void DoLine(buf) char* buf;{#define X_NO_TOKEN 0#define X_FILE_TOKEN 1#define X_TABLE_TOKEN 2#define X_PREFIX_TOKEN 3#define X_FEATURE_TOKEN 4#define X_EXTERNREF_TOKEN 5#define X_EXTERNDEF_TOKEN 6#define X_CTMPL_TOKEN 7#define X_HTMPL_TOKEN 8#define X_CONST_TOKEN 9 int token; char lbuf[1024]; static char* file_str = "#file"; static char* table_str = "#table"; static char* prefix_str = "#prefix"; static char* feature_str = "#feature"; static char* externref_str = "#externref"; static char* externdef_str = "#externdef"; static char* ctmpl_str = "#ctmpl"; static char* htmpl_str = "#htmpl"; static char* const_str = "#const"; if (strncmp (buf, file_str, strlen (file_str)) == 0) token = X_FILE_TOKEN; else if (strncmp (buf, table_str, strlen (table_str)) == 0) token = X_TABLE_TOKEN; else if (strncmp (buf, prefix_str, strlen (prefix_str)) == 0) token = X_PREFIX_TOKEN; else if (strncmp (buf, feature_str, strlen (feature_str)) == 0) token = X_FEATURE_TOKEN; else if (strncmp (buf, externref_str, strlen (externref_str)) == 0) token = X_EXTERNREF_TOKEN; else if (strncmp (buf, externdef_str, strlen (externdef_str)) == 0) token = X_EXTERNDEF_TOKEN; else if (strncmp (buf, ctmpl_str, strlen (ctmpl_str)) == 0) token = X_CTMPL_TOKEN; else if (strncmp (buf, htmpl_str, strlen (htmpl_str)) == 0) token = X_HTMPL_TOKEN; else if (strncmp (buf, const_str, strlen (const_str)) == 0) token = X_CONST_TOKEN; else token = X_NO_TOKEN; switch (token) { case X_FILE_TOKEN: { File* phile; if ((phile = (File*) malloc (sizeof(File))) == NULL) exit(1); if ((phile->name = malloc (strlen (buf + strlen (file_str)) + 1)) == NULL) exit(1); (void) strcpy (phile->name, buf + strlen (file_str) + 1); phile->table = NULL; phile->tablecurrent = NULL; phile->tabletail = &phile->table; phile->next = NULL; phile->tmpl = NULL; *filetail = phile; filetail = &phile->next; filecurrent = phile; } break; case X_TABLE_TOKEN: { Table* table; if ((table = (Table*) malloc (sizeof(Table))) == NULL) exit(1); if ((table->name = malloc (strlen (buf + strlen (table_str)) + 1)) == NULL) exit(1); (void) strcpy (table->name, buf + strlen (table_str) + 1); table->tableent = NULL; table->tableentcurrent = NULL; table->tableenttail = &table->tableent; table->next = NULL; table->offset = 0; *filecurrent->tabletail = table; filecurrent->tabletail = &table->next; filecurrent->tablecurrent = table; } break; case X_PREFIX_TOKEN: if ((prefixstr = malloc (strlen (buf + strlen (prefix_str)) + 1)) == NULL) exit(1); (void) strcpy (prefixstr, buf + strlen (prefix_str) + 1); break; case X_FEATURE_TOKEN: if ((featurestr = malloc (strlen (buf + strlen (feature_str)) + 1)) == NULL) exit(1); (void) strcpy (featurestr, buf + strlen (feature_str) + 1); break; case X_EXTERNREF_TOKEN: if ((externrefstr = malloc (strlen (buf + strlen (externref_str)) + 1)) == NULL) exit(1); (void) strcpy (externrefstr, buf + strlen (externref_str) + 1); break; case X_EXTERNDEF_TOKEN: if ((externdefstr = malloc (strlen (buf + strlen (externdef_str)) + 1)) == NULL) exit(1); (void) strcpy (externdefstr, buf + strlen (externdef_str) + 1); break; case X_CTMPL_TOKEN: if ((ctmplstr = malloc (strlen (buf + strlen (ctmpl_str)) + 1)) == NULL) exit(1); (void) strcpy (ctmplstr, buf + strlen (ctmpl_str) + 1); break; case X_HTMPL_TOKEN: if ((filecurrent->tmpl = fopen (buf + strlen (htmpl_str) + 1, "r")) == NULL) { (void) fprintf (stderr, "Expected template %s, not found\n", htmpl_str); exit (1); } break; case X_CONST_TOKEN: if ((conststr = malloc (strlen (buf + strlen (const_str)) + 1)) == NULL) exit(1); (void) strcpy (conststr, buf + strlen (const_str) + 1); break; default: { char* right; TableEnt* tableent; int llen; int rlen; int len; if (right = index(buf, ' ')) *right++ = 0; else right = buf + 1; if (buf[0] == 'H') { strcpy (lbuf, prefixstr); strcat (lbuf, right); right = lbuf; } llen = len = strlen(buf) + 1; rlen = strlen(right) + 1; if (right != buf + 1) len += rlen; if ((tableent = (TableEnt*)malloc(sizeof(TableEnt) + len)) == NULL) exit(1); tableent->left = (char *)(tableent + 1); strcpy(tableent->left, buf); if (llen != len) { tableent->right = tableent->left + llen; strcpy(tableent->right, right); } else { tableent->right = tableent->left + 1; } tableent->next = NULL; *filecurrent->tablecurrent->tableenttail = tableent; filecurrent->tablecurrent->tableenttail = &tableent->next; filecurrent->tablecurrent->tableentcurrent = tableent; } break; }}static void IntelABIIndexEntries (file) File* file;{ Table* t; TableEnt* te; for (t = file->table; t; t = t->next) for (te = t->tableent; te; te = te->next) { te->offset = t->offset; t->offset += strlen (te->right); t->offset++; }}static void DefaultIndexEntries (file) File* file;{ Table* t; TableEnt* te; int offset = 0; for (t = file->table; t; t = t->next) for (te = t->tableent; te; te = te->next) { te->offset = offset; offset += strlen (te->right); offset++; }}static void IndexEntries (file,abi) File* file; int abi;{ switch (abi) { case X_SPARC_ABI: break; case X_INTEL_ABI: case X_INTEL_ABI_BC: IntelABIIndexEntries (file); break; default: DefaultIndexEntries (file); break; }}static char* DoComment (line) char* line;{ char* tag; char* eol; char* ret; int len; /* assume that the first line with two '$' in it is the RCS tag line */ if ((tag = index (line, '$')) == NULL) return NULL; if ((eol = index (tag + 1, '$')) == NULL) return NULL; len = eol - tag; if ((ret = malloc (len)) == NULL) exit (1); (void) strncpy (ret, tag + 1, len - 1); ret[len - 2] = 0; return ret;}int main(argc, argv) int argc; char** argv;{ int len, i; char* tagline = NULL; File* phile; FILE *f; char buf[1024]; int abi = #ifndef ARRAYPERSTR X_DEFAULT_ABI;#else X_ARRAYPER_ABI;#endif f = stdin; if (argc > 1) { for (i = 1; i < argc; i++) { if (strcmp (argv[i], "-f") == 0) { if (++i < argc) f = fopen (argv[i], "r"); else return 1; } if (strcmp (argv[i], "-sparcabi") == 0) abi = X_SPARC_ABI; if (strcmp (argv[i], "-intelabi") == 0) abi = X_INTEL_ABI; if (strcmp (argv[i], "-functionabi") == 0) abi = X_FUNCTION_ABI; if (strcmp (argv[i], "-earlyR6bc") == 0 && abi == X_INTEL_ABI) abi = X_INTEL_ABI_BC; if (strcmp (argv[i], "-arrayperabi") == 0) abi = X_ARRAYPER_ABI;#ifdef ARRAYPERSTR if (strcmp (argv[i], "-defaultabi") == 0) abi = X_DEFAULT_ABI;#endif } } if (f == NULL) return 1; while (fgets(buf, sizeof buf, f)) { if (!buf[0] || buf[0] == '\n') continue; if (buf[0] == '!') { if (tagline) continue; tagline = DoComment (buf); continue; } if (buf[(len = strlen (buf) - 1)] == '\n') buf[len] = '\0'; DoLine(buf); } for (phile = file; phile; phile = phile->next) { if (abi != X_ARRAYPER_ABI) IndexEntries (phile, abi); WriteHeader (tagline, phile, abi); } WriteSource(tagline, abi); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -