Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

ptypes2tcl.cc

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <ctype.h>
00003 #include "packet.h"
00004 
00005 // The following copied from ~tclcl/tcl2c++.c
00006 /*
00007  * Define TCL2C_INT if your compiler has problems with long strings.
00008  */
00009 #if defined(WIN32) || defined(_WIN32) || defined(__alpha__) || defined(__hpux)
00010 #define TCL2C_INT
00011 #endif
00012 
00013 char* p_info::name_[PT_NTYPE+1];
00014 
00015 void
00016 printLine(char *s) {
00017 #ifdef TCL2C_INT
00018         for (unsigned int i = 0; i < strlen(s); i++) 
00019                 if ((i > 0) && ((i % 20) == 0))
00020                         printf("%u,\n", s[i]);
00021                 else
00022                         printf("%u,", s[i]);
00023         printf("%u,%u,\n", '\\', '\n');
00024 #else
00025         printf("%s\\n\\\n", s);
00026 #endif
00027 }
00028 
00029 char *
00030 lcase(const char *s) {
00031         static char charbuf[512];
00032         char* to = charbuf;
00033         while ((*to++ = tolower(*s++)))
00034                 /* NOTHING */;
00035         *to = '\0';
00036         return charbuf;
00037 }
00038 
00039 int main() {
00040         p_info pinfo;
00041 
00042 #ifdef TCL2C_INT
00043         printf("static const char code[] = {\n");
00044 #else
00045         printLine("static const char code[] = \"");
00046 #endif
00047         printLine("global ptype pvals");
00048         printLine("set ptype(error) -1");
00049         printLine("set pvals(-1) error");
00050         char strbuf[512];
00051         for (int i = 0; i < PT_NTYPE; i++) {
00052                 sprintf(strbuf, "set ptype(%s) %d", lcase(pinfo.name(packet_t(i))), i);
00053                 printLine(strbuf);
00054                 sprintf(strbuf, "set pvals(%d) %s", i, pinfo.name(packet_t(i)));
00055                 printLine(strbuf);
00056         }
00057         printLine("proc ptype2val {str} {");
00058         printLine("global ptype");
00059         printLine("set str [string tolower $str]");
00060         printLine("if ![info exists ptype($str)] {");
00061         printLine("set str error");
00062         printLine("}");
00063         printLine("set ptype($str)");
00064         printLine("}");
00065         printLine("proc pval2type {val} {");
00066         printLine("global pvals");
00067         printLine("if ![info exists pvals($val)] {");
00068         printLine("set val -1");
00069         printLine("}");
00070         printLine("set pvals($val)");
00071         printLine("}");
00072 #ifdef TCL2C_INT
00073         printf("0 };\n");
00074 #else
00075         printf("\";\n");
00076 #endif
00077         printf("#include \"config.h\"\n");
00078         printf("EmbeddedTcl et_ns_ptypes(code);\n");
00079         return 0;
00080 }

Generated on Tue Apr 20 12:14:27 2004 for NS2.26SourcesOriginal by doxygen 1.3.3