static void pprogramdef(definition *def) { version_list *vers; proc_list *proc; int i; char *ext; pargdef(def); puldefine(def->def_name, def->def.pr.prog_num, PROGRAM); for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { if (tblflag) { f_print(fout, "extern struct rpcgen_table %s_%s_table[];\n", locase(def->def_name), vers->vers_num); f_print(fout, "extern int %s_%s_nproc;\n", locase(def->def_name), vers->vers_num); } puldefine(vers->vers_name, vers->vers_num, VERSION); /* * Print out 2 definitions, one for ANSI-C, another for * old K & R C */ if (!Cflag) { ext = "extern "; for (proc = vers->procs; proc != NULL; proc = proc->next) { if (!define_printed(proc, def->def.pr.versions)) puldefine(proc->proc_name, proc->proc_num, PROCEDURE); f_print(fout, "%s", ext); pprocdef(proc, vers, NULL, 0, 2); if (mtflag) { f_print(fout, "%s", ext); pprocdef(proc, vers, NULL, 1, 2); } } pfreeprocdef(def->def_name, vers->vers_num, 2); } else { for (i = 1; i < 3; i++) { if (i == 1) { f_print(fout, "\n#if defined(__STDC__)" " || defined(__cplusplus)\n"); ext = "extern "; } else { f_print(fout, "\n#else /* K&R C */\n"); ext = "extern "; } for (proc = vers->procs; proc != NULL; proc = proc->next) { if (!define_printed(proc, def->def.pr.versions)) { puldefine(proc->proc_name, proc->proc_num, PROCEDURE); } f_print(fout, "%s", ext); pprocdef(proc, vers, "CLIENT *", 0, i); f_print(fout, "%s", ext); pprocdef(proc, vers, "struct svc_req *", 1, i); } pfreeprocdef(def->def_name, vers->vers_num, i); } f_print(fout, "#endif /* K&R C */\n"); } } }
void mda_dump_scan( XDR *xdrs) { int i, j; short int rank, num_pos, num_det, num_trg; long int req_pts, cmp_pts; long int *offsets; offsets = NULL; rank = si_print( xdrs, "This scan's rank = %i\n"); req_pts = li_print( xdrs, "Number of requested points = %li\n"); cmp_pts = li_print( xdrs, "Last completed point = %li\n"); if( (rank <= 0) || (req_pts <= 0) || (cmp_pts < 0) ) { fflush(stdout); exit(1); } if( rank > 1) { offsets = (long int *) malloc( sizeof( long int) * req_pts); print("Offsets to lower scans = "); for( i = 0; i < req_pts; i++) { if( i) print(", "); offsets[i] = li_print( xdrs, "%li"); } print("\n"); } cs_print( xdrs, "Scan name = \"%s\"\n"); cs_print( xdrs, "Scan time = \"%s\"\n"); num_pos = si_print( xdrs, "Number of positioners = %i\n"); num_det = si_print( xdrs, "Number of detectors = %i\n"); num_trg = si_print( xdrs, "Number of triggers = %i\n"); if( num_pos < 0) { fflush(stdout); exit(1); } for( i = 0; i < num_pos; i++) { print( "\nPositioner Data Set #%i\n", i+1); si_print( xdrs, " Positioner: %i\n"); cs_print( xdrs, " Name: %s\n"); cs_print( xdrs, " Description: %s\n"); cs_print( xdrs, " Step Mode: %s\n"); cs_print( xdrs, " Unit: %s\n"); cs_print( xdrs, " Readback Name: %s\n"); cs_print( xdrs, " Readback Description: %s\n"); cs_print( xdrs, " Readback Unit: %s\n"); } if( num_det < 0) { fflush(stdout); exit(1); } for( i = 0; i < num_det; i++) { print( "\nDetector Data Set #%i\n", i+1); si_print( xdrs, " Detector: %2i\n"); cs_print( xdrs, " Name: %s\n"); cs_print( xdrs, " Description: %s\n"); cs_print( xdrs, " Unit: %s\n"); } if( num_trg < 0) { fflush(stdout); exit(1); } for( i = 0; i < num_trg; i++) { print( "\nTrigger #%i\n", i+1); si_print( xdrs, " Trigger: %i\n"); cs_print( xdrs, " Name: %s\n"); f_print( xdrs, " Command: %g\n"); } for( i = 0; i < num_pos; i++) { print( "\nPositioner #%i data:\n", i+1); for( j = 0; j < req_pts; j++) d_print( xdrs, "%.9lg "); print( "\n"); } for( i = 0; i < num_det; i++) { print( "\nDetector #%i data:\n", i+1); for( j = 0; j < req_pts; j++) f_print( xdrs, "%.9g "); print( "\n"); } if( rank > 1) for( i = 0; i < req_pts; i++) { if( offsets[i] == 0) break; print( "\n\n%i-D Subscan #%i\n", rank - 1, i+1); print( "Offset = %li\n\n", xdr_getpos( xdrs) ); mda_dump_scan( xdrs); } }
static void print_trailer(void) { f_print(fout, "\treturn (TRUE);\n"); f_print(fout, "}\n"); }
static void emit_struct (definition * def) { decl_list *dl; int i, j, size, flag; decl_list *cur = NULL, *psav; bas_type *ptr; char *sizestr, *plus; char ptemp[256]; int can_inline; if (doinline == 0) { for (dl = def->def.st.decls; dl != NULL; dl = dl->next) print_stat (1, &dl->decl); return; } for (dl = def->def.st.decls; dl != NULL; dl = dl->next) if (dl->decl.rel == REL_VECTOR) { f_print (fout, "\t int i;\n"); break; } size = 0; can_inline = 0; for (dl = def->def.st.decls; dl != NULL; dl = dl->next) if ((dl->decl.prefix == NULL) && ((ptr = find_type (dl->decl.type)) != NULL) && ((dl->decl.rel == REL_ALIAS) || (dl->decl.rel == REL_VECTOR))) { if (dl->decl.rel == REL_ALIAS) size += ptr->length; else { can_inline = 1; break; /* can be inlined */ }; } else { if (size >= doinline) { can_inline = 1; break; /* can be inlined */ } size = 0; } if (size > doinline) can_inline = 1; if (can_inline == 0) { /* can not inline, drop back to old mode */ for (dl = def->def.st.decls; dl != NULL; dl = dl->next) print_stat (1, &dl->decl); return; }; flag = PUT; for (j = 0; j < 2; j++) { if (flag == PUT) f_print (fout, "\n\t if (xdrs->x_op == XDR_ENCODE) {\n"); else f_print (fout, "\n \t return (TRUE);\n\t} else if (xdrs->x_op == XDR_DECODE) {\n"); i = 0; size = 0; sizestr = NULL; for (dl = def->def.st.decls; dl != NULL; dl = dl->next) { /* xxx */ /* now walk down the list and check for basic types */ if ((dl->decl.prefix == NULL) && ((ptr = find_type (dl->decl.type)) != NULL) && ((dl->decl.rel == REL_ALIAS) || (dl->decl.rel == REL_VECTOR))) { if (i == 0) cur = dl; i++; if (dl->decl.rel == REL_ALIAS) size += ptr->length; else { /* this is required to handle arrays */ if (sizestr == NULL) plus = " "; else plus = "+"; if (ptr->length != 1) s_print (ptemp, " %s %s * %d", plus, dl->decl.array_max, ptr->length); else s_print (ptemp, " %s %s ", plus, dl->decl.array_max); /* now concatenate to sizestr !!!! */ if (sizestr == NULL) sizestr = strdup (ptemp); else { sizestr = (char *) realloc (sizestr, strlen (sizestr) + strlen (ptemp) + 1); if (sizestr == NULL) { f_print (stderr, "Fatal error : no memory \n"); crash (); }; sizestr = strcat (sizestr, ptemp); /* build up length of * array */ } } } else { if (i > 0) { if (sizestr == NULL && size < doinline) { /* don't expand into inline * code if size < doinline */ while (cur != dl) { print_stat (1, &cur->decl); cur = cur->next; } } else { /* were already looking at a * xdr_inlineable structure */ if (sizestr == NULL) f_print (fout, "\t buf = (int32_t *)XDR_INLINE(xdrs,%d * BYTES_PER_XDR_UNIT);", size); else if (size == 0) f_print (fout, "\t buf = (int32_t *)XDR_INLINE(xdrs,%s * BYTES_PER_XDR_UNIT);", sizestr); else f_print (fout, "\t buf = (int32_t *)XDR_INLINE(xdrs,(%d + %s)* BYTES_PER_XDR_UNIT);", size, sizestr); f_print (fout, "\n\t if (buf == NULL) {\n"); psav = cur; while (cur != dl) { print_stat (2, &cur->decl); cur = cur->next; } f_print (fout, "\n\t }\n\t else {\n"); cur = psav; while (cur != dl) { emit_inline (&cur->decl, flag); cur = cur->next; } f_print (fout, "\t }\n"); } } size = 0; i = 0; sizestr = NULL; print_stat (1, &dl->decl); } } if (i > 0) { if (sizestr == NULL && size < doinline) { /* don't expand into inline code if size < * doinline */ while (cur != dl) { print_stat (1, &cur->decl); cur = cur->next; } } else { /* were already looking at a xdr_inlineable * structure */ if (sizestr == NULL) f_print (fout, "\t\tbuf = (int32_t *)XDR_INLINE(xdrs,%d * BYTES_PER_XDR_UNIT);", size); else if (size == 0) f_print (fout, "\t\tbuf = (int32_t *)XDR_INLINE(xdrs,%s * BYTES_PER_XDR_UNIT);", sizestr); else f_print (fout, "\t\tbuf = (int32_t *)XDR_INLINE(xdrs,(%d + %s)* BYTES_PER_XDR_UNIT);", size, sizestr); f_print (fout, "\n\t\tif (buf == NULL) {\n"); psav = cur; while (cur != NULL) { print_stat (2, &cur->decl); cur = cur->next; } f_print (fout, "\n\t }\n\t else {\n"); cur = psav; while (cur != dl) { emit_inline (&cur->decl, flag); cur = cur->next; } f_print (fout, "\t }\n"); } } flag = GET; } f_print (fout, "\t return(TRUE);\n\t}\n\n"); /* now take care of XDR_FREE case */ for (dl = def->def.st.decls; dl != NULL; dl = dl->next) print_stat (1, &dl->decl); }
static void write_table(definition *def) { version_list *vp; proc_list *proc; int current; int expected; char progvers[100]; int warning; for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { warning = 0; (void) snprintf(progvers, sizeof (progvers), "%s_%s", locase(def->def_name), vp->vers_num); /* print the table header */ f_print(fout, tbl_hdr, progvers); if (nullproc(vp->procs)) { expected = 0; } else { expected = 1; if (tirpcflag) f_print(fout, null_entry); else f_print(fout, null_entry_b); } for (proc = vp->procs; proc != NULL; proc = proc->next) { current = atoi(proc->proc_num); if (current != expected++) { f_print(fout, "\n/*\n * WARNING: table out of order\n */\n"); if (warning == 0) { f_print(stderr, "WARNING %s table is out of order\n", progvers); warning = 1; nonfatalerrors = 1; } expected = current + 1; } if (tirpcflag) f_print(fout, "\n\t(void *(*)())RPCGEN_ACTION("); else f_print(fout, "\n\t(char *(*)())RPCGEN_ACTION("); /* routine to invoke */ if (Cflag && !newstyle) pvname_svc(proc->proc_name, vp->vers_num); else { if (newstyle) /* calls internal func */ f_print(fout, "_"); pvname(proc->proc_name, vp->vers_num); } f_print(fout, "),\n"); /* argument info */ if (proc->arg_num > 1) printit(NULL, proc->args.argname); else /* do we have to do something special for newstyle */ printit(proc->args.decls->decl.prefix, proc->args.decls->decl.type); /* result info */ printit(proc->res_prefix, proc->res_type); } /* print the table trailer */ f_print(fout, tbl_end); f_print(fout, tbl_nproc, progvers, progvers, progvers); } }
static void print_generic_header (char *procname, int pointerp) { f_print (fout, "\n"); f_print (fout, "bool_t\n"); if (Cflag) { f_print (fout, "xdr_%s(", procname); f_print (fout, "XDR *xdrs, "); f_print (fout, "%s ", procname); if (pointerp) f_print (fout, "*"); f_print (fout, "objp)\n{\n\n"); } else { f_print (fout, "xdr_%s(xdrs, objp)\n", procname); f_print (fout, "\tXDR *xdrs;\n"); f_print (fout, "\t%s ", procname); if (pointerp) f_print (fout, "*"); f_print (fout, "objp;\n{\n\n"); } }
static void print_ifstat (int indent, char *prefix, char *type, relation rel, char *amax, char *objname, char *name) { char *alt = NULL; switch (rel) { case REL_POINTER: print_ifopen (indent, "pointer"); print_ifarg ("(char **)"); f_print (fout, "%s", objname); print_ifsizeof (prefix, type); break; case REL_VECTOR: if (streq (type, "string")) { alt = "string"; } else if (streq (type, "opaque")) { alt = "opaque"; } if (alt) { print_ifopen (indent, alt); print_ifarg (objname); } else { print_ifopen (indent, "vector"); print_ifarg ("(char *)"); f_print (fout, "%s", objname); } print_ifarg (amax); if (!alt) { print_ifsizeof (prefix, type); } break; case REL_ARRAY: if (streq (type, "string")) { alt = "string"; } else if (streq (type, "opaque")) { alt = "bytes"; } if (streq (type, "string")) { print_ifopen (indent, alt); print_ifarg (objname); } else { if (alt) { print_ifopen (indent, alt); } else { print_ifopen (indent, "array"); } print_ifarg ("(char **)"); #if 0 if (*objname == '&') { f_print (fout, "%s.%s_val, (u_int *)%s.%s_len", objname, name, objname, name); } else { f_print (fout, "&%s->%s_val, (u_int *)&%s->%s_len", objname, name, objname, name); } #else if (*objname == '&') { /* Don't know what this does but it seems broken */ f_print (fout, "%s.val, (u_int *)%s.len", objname, objname); } else { f_print (fout, "&%s->val, (u_int *)&%s->len", objname, objname); } #endif } print_ifarg (amax); if (!alt) { print_ifsizeof (prefix, type); } break; case REL_ALIAS: print_ifopen (indent, type); print_ifarg (objname); break; } print_ifclose (indent); }
Variant invoke(const char *function, CArrRef params, int64 hash, bool tryinterp, bool fatal) { // for TestExtFunction if (strcasecmp(function, "test") == 0) { return params[0]; } // for TestExtPreg::test_preg_replace_callback if (strcasecmp(function, "next_year") == 0) { Array matches = params[0].toArray(); return matches[1].toString() + String(matches[2].toInt32() + 1); } // for TestExtArray::test_array_filter if (strcasecmp(function, "odd") == 0) { return params[0].toInt32() & 1; } if (strcasecmp(function, "even") == 0) { return !(params[0].toInt32() & 1); } // for TestExtArray::test_array_map if (strcasecmp(function, "cube") == 0) { int n = params[0].toInt32(); return n * n * n; } // for TestExtArray::test_array_multisort if (strcasecmp(function, "strtolower") == 0) { return f_strtolower(params[0]); } // for TestExtArray::test_array_reduce if (strcasecmp(function, "rsum") == 0) { int v = params[0].toInt32(); int w = params[1].toInt32(); v += w; return v; } if (strcasecmp(function, "rmul") == 0) { int v = params[0].toInt32(); int w = params[1].toInt32(); v *= w; return v; } // for TestExtArray::test_array_walk_recursive if (strcasecmp(function, "test_print") == 0) { String item = params[0].toString(); String key = params[1].toString(); echo(key + ": " + item + "\n"); } // for TestExtArray::test_array_walk if (strcasecmp(function, "test_alter") == 0) { Variant &item1 = lval(((Array&)params).lvalAt(0)); String key = params[1]; String prefix = params[2]; item1 = prefix + ": " + item1; } // for TestExtArray::test_array_udiff if (strcasecmp(function, "comp_func") == 0) { int n1 = params[0].toInt32(); int n2 = params[1].toInt32(); if (n1 == n2) return 0; return n1 > n2 ? 1 : -1; } // for TestExtArray::test_usort if (strcasecmp(function, "reverse_comp_func") == 0) { int n1 = params[0].toInt32(); int n2 = params[1].toInt32(); if (n1 == n2) return 0; return n1 > n2 ? -1 : 1; } // for TestExtArray::test_array_uintersect if (strcasecmp(function, "strcasecmp") == 0) { String s1 = params[0].toString(); String s2 = params[1].toString(); return strcasecmp(s1.data(), s2.data()); } // for TestExtArray::test_uasort if (strcasecmp(function, "reverse_strcasecmp") == 0) { String s1 = params[0].toString(); String s2 = params[1].toString(); return strcasecmp(s2.data(), s1.data()); } // for TestExtFbml if (strcasecmp(function, "urltr") == 0) { String s1 = params[0].toString(); String s2 = params[1].toString(); return String("url:") + s1 + "=" + s2; } // for TestExtCurl::test_curl_exec if (strcasecmp(function, "curl_write_func") == 0) { f_print("curl_write_func called with "); f_print(params[1]); return params[1].toString().size(); } // for TestExtPreg::test_preg_replace if (strcasecmp(function, "strtoupper") == 0) { return f_strtoupper(params[0].toString()); } if (strcasecmp(function, "test_preg_rep") == 0) { return test_preg_rep(params[0].toString(), params[1].toString(), params[2].toString()); } if (strcasecmp(function, "sprintf") == 0) { return f_sprintf(params.size(), params[0], params.slice(1, params.size() - 1, false)); } // for TestExtSqlite3::test_sqlite3 if (strcasecmp(function, "lower") == 0) { return f_strtolower(params[0]); } if (strcasecmp(function, "sumlen_step") == 0) { return params[0].toInt64() + f_strlen(params[2]); } if (strcasecmp(function, "sumlen_fini") == 0) { return params[0].toInt64(); } // for TestExtSoap if (strcasecmp(function, "hello") == 0) { return "Hello World"; } if (strcasecmp(function, "add") == 0) { return params[0].toInt32() + params[1].toInt32(); } if (strcasecmp(function, "sub") == 0) { return params[0].toInt32() - params[1].toInt32(); } if (strcasecmp(function, "sum") == 0) { int sum = 0; for (ArrayIter iter(params[0]); iter; ++iter) { sum += iter.second().toInt32(); } return sum; } if (strcasecmp(function, "strlen") == 0) { return f_strlen(params[0]); } if (strcasecmp(function, "fault") == 0) { return Object((NEW(c_soapfault)())->create("MyFault","My fault string")); } // for TestExtServer if (strcasecmp(function, "xbox_process_message") == 0) { return StringUtil::Reverse(params[0]); } return true; }
static void printdirective(const char *line) { f_print(fout, "%s", line + 1); }
/* * Compile into an XDR header file */ static void h_output(char *infile, char *define, int extend, char *outfile, int append) { definition *def; char *outfilename; long tell; char fullname[1024], *p; open_input(infile, define); hflag = 1; memset(fullname, 0, sizeof(fullname)); if (append) { strcpy(fullname, prefix); strcat(fullname, infile); } else strcpy(fullname, infile); outfilename = extend ? extendfile(fullname, outfile) : outfile; open_output(infile, outfilename); strcpy(fullname, outfilename); if ((p = strchr(fullname, '.'))) *p = '\0'; f_print(fout, "/* Machine generated file -- Do NOT edit */\n\n"); f_print(fout, "#ifndef _RXGEN_%s_\n", uppercase(fullname)); f_print(fout, "#define _RXGEN_%s_\n\n", uppercase(fullname)); f_print(fout, "#ifdef KERNEL\n"); f_print(fout, "/* The following 'ifndefs' are not a good solution to the vendor's omission of surrounding all system includes with 'ifndef's since it requires that this file is included after the system includes...*/\n"); f_print(fout, "#include <afsconfig.h>\n"); f_print(fout, "#include \"afs/param.h\"\n"); f_print(fout, "#ifdef UKERNEL\n"); f_print(fout, "#include \"afs/sysincludes.h\"\n"); f_print(fout, "#include \"rx/xdr.h\"\n"); f_print(fout, "#include \"rx/rx.h\"\n"); if (xflag) { f_print(fout, "#include \"rx/rx_globals.h\"\n"); } if (brief_flag) { f_print(fout, "#include \"rx/rx_opaque.h\"\n"); } if (uflag) f_print(fout, "#include <ubik.h>\n"); f_print(fout, "#else /* UKERNEL */\n"); f_print(fout, "#include \"h/types.h\"\n"); f_print(fout, "#ifndef SOCK_DGRAM /* XXXXX */\n"); f_print(fout, "#include \"h/socket.h\"\n"); f_print(fout, "#endif\n"); f_print(fout, "struct ubik_client;\n"); f_print(fout, "#ifndef DTYPE_SOCKET /* XXXXX */\n"); f_print(fout, "#ifndef AFS_LINUX22_ENV\n"); f_print(fout, "#include \"h/file.h\"\n"); f_print(fout, "#endif\n"); f_print(fout, "#endif\n"); f_print(fout, "#ifndef S_IFMT /* XXXXX */\n"); f_print(fout, "#include \"h/stat.h\"\n"); f_print(fout, "#endif\n"); f_print(fout, "#if defined (AFS_OBSD_ENV) && !defined (MLEN)\n"); f_print(fout, "#include \"sys/mbuf.h\"\n"); f_print(fout, "#endif\n"); f_print(fout, "#ifndef IPPROTO_UDP /* XXXXX */\n"); f_print(fout, "#include \"netinet/in.h\"\n"); f_print(fout, "#endif\n"); f_print(fout, "#ifndef DST_USA /* XXXXX */\n"); f_print(fout, "#include \"h/time.h\"\n"); f_print(fout, "#endif\n"); f_print(fout, "#ifndef AFS_LINUX22_ENV\n"); f_print(fout, "#include \"rpc/types.h\"\n"); f_print(fout, "#endif /* AFS_LINUX22_ENV */\n"); f_print(fout, "#ifndef XDR_GETLONG /* XXXXX */\n"); f_print(fout, "#ifdef AFS_LINUX22_ENV\n"); f_print(fout, "#ifndef quad_t\n"); f_print(fout, "#define quad_t __quad_t\n"); f_print(fout, "#define u_quad_t __u_quad_t\n"); f_print(fout, "#endif\n"); f_print(fout, "#endif\n"); f_print(fout, "#include \"rx/xdr.h\"\n"); f_print(fout, "#endif /* XDR_GETLONG */\n"); f_print(fout, "#endif /* UKERNEL */\n"); f_print(fout, "#include \"afs/rxgen_consts.h\"\n"); f_print(fout, "#include \"afs_osi.h\"\n"); f_print(fout, "#include \"rx/rx.h\"\n"); if (xflag) { f_print(fout, "#include \"rx/rx_globals.h\"\n"); } if (brief_flag) { f_print(fout, "#include \"rx/rx_opaque.h\"\n"); } f_print(fout, "#else /* KERNEL */\n"); f_print(fout, "#include <afs/param.h>\n"); f_print(fout, "#include <afs/stds.h>\n"); f_print(fout, "#include <sys/types.h>\n"); f_print(fout, "#include <rx/xdr.h>\n"); f_print(fout, "#include <rx/rx.h>\n"); if (xflag) { f_print(fout, "#include <rx/rx_globals.h>\n"); } if (brief_flag) { f_print(fout, "#include <rx/rx_opaque.h>\n"); } f_print(fout, "#include <afs/rxgen_consts.h>\n"); if (uflag) f_print(fout, "#include <ubik.h>\n"); f_print(fout, "#endif /* KERNEL */\n\n"); f_print(fout, "#ifdef AFS_NT40_ENV\n"); f_print(fout, "#ifndef AFS_RXGEN_EXPORT\n"); f_print(fout, "#define AFS_RXGEN_EXPORT __declspec(dllimport)\n"); f_print(fout, "#endif /* AFS_RXGEN_EXPORT */\n"); f_print(fout, "#else /* AFS_NT40_ENV */\n"); f_print(fout, "#define AFS_RXGEN_EXPORT\n"); f_print(fout, "#endif /* AFS_NT40_ENV */\n\n"); tell = ftell(fout); while ((def = get_definition())) { print_datadef(def); } h_Proc_CodeGeneration(); h_opcode_stats(); hflag = 0; f_print(fout, "#endif /* _RXGEN_%s_ */\n", uppercase(fullname)); if (extend && tell == ftell(fout)) { (void)unlink(outfilename); } }
static void S_output(char *infile, char *define, int extend, char *outfile, int append) { char *include; char *outfilename; char fullname[1024]; definition *def; long tell; char *currfile = (OutFileFlag ? OutFile : infile); Sflag = 1; open_input(infile, define); memset(fullname, 0, sizeof(fullname)); if (append) { strcpy(fullname, prefix); strcat(fullname, infile); } else strcpy(fullname, infile); outfilename = extend ? extendfile(fullname, outfile) : outfile; open_output(infile, outfilename); f_print(fout, "/* Machine generated file -- Do NOT edit */\n\n"); if (currfile && (include = extendfile(currfile, ".h"))) { if (kflag) { f_print(fout, "#include \"%s\"\n", include); } else { f_print(fout, "#include <afsconfig.h>\n"); f_print(fout, "#include <afs/param.h>\n"); f_print(fout, "#include <roken.h>\n"); f_print(fout, "#include \"%s\"\n\n", include); } free(include); } else { if (kflag) { f_print(fout, "#include \"h/types.h\"\n"); f_print(fout, "#include \"h/socket.h\"\n"); f_print(fout, "#include \"h/file.h\"\n"); f_print(fout, "#include \"h/stat.h\"\n"); f_print(fout, "#include \"netinet/in.h\"\n"); f_print(fout, "#include \"h/time.h\"\n"); f_print(fout, "#include \"rpc/types.h\"\n"); f_print(fout, "#include \"rx/xdr.h\"\n"); f_print(fout, "#include \"afs/rxgen_consts.h\"\n"); f_print(fout, "#include \"afs/afs_osi.h\"\n"); f_print(fout, "#include \"rx/rx.h\"\n"); if (xflag) { f_print(fout, "#include \"rx/rx_globals.h\"\n"); } if (brief_flag) { f_print(fout, "#include \"rx/rx_opaque.h\"\n"); } } else { f_print(fout, "#include <sys/types.h>\n"); f_print(fout, "#include <rx/xdr.h>\n"); f_print(fout, "#include <rx/rx.h>\n"); if (xflag) { f_print(fout, "#include <rx/rx_globals.h>\n"); } if (brief_flag) { f_print(fout, "#include <rx/rx_opaque.h>\n"); } f_print(fout, "#include <afs/rxgen_consts.h>\n"); } } tell = ftell(fout); fflush(fout); while ((def = get_definition())) { fflush(fout); print_datadef(def); } er_Proc_CodeGeneration(); if (extend && tell == ftell(fout)) { (void)unlink(outfilename); } Sflag = 0; }
/* * Compile into an XDR routine output file */ static void c_output(char *infile, char *define, int extend, char *outfile, int append) { definition *def; char *include; char *outfilename; long tell; char fullname[1024]; char *currfile = (OutFileFlag ? OutFile : infile); int i, j; open_input(infile, define); cflag = 1; memset(fullname, 0, sizeof(fullname)); if (append) { strcpy(fullname, prefix); strcat(fullname, infile); } else strcpy(fullname, infile); outfilename = extend ? extendfile(fullname, outfile) : outfile; open_output(infile, outfilename); f_print(fout, "/* Machine generated file -- Do NOT edit */\n\n"); if (xflag) { if (kflag) { f_print(fout, "#include \"afsconfig.h\"\n"); f_print(fout, "#include \"afs/param.h\"\n"); } else { f_print(fout, "#include <afsconfig.h>\n"); f_print(fout, "#include <afs/param.h>\n"); f_print(fout, "#include <roken.h>\n"); } f_print(fout, "#ifdef AFS_NT40_ENV\n"); f_print(fout, "#define AFS_RXGEN_EXPORT __declspec(dllexport)\n"); f_print(fout, "#endif /* AFS_NT40_ENV */\n"); } if (currfile && (include = extendfile(currfile, ".h"))) { if (kflag) { f_print(fout, "#include \"%s\"\n\n", include); } else f_print(fout, "#include \"%s\"\n\n", include); free(include); } else { /* In case we can't include the interface's own header file... */ if (kflag) { f_print(fout, "#include \"h/types.h\"\n"); f_print(fout, "#include \"h/socket.h\"\n"); f_print(fout, "#include \"h/file.h\"\n"); f_print(fout, "#include \"h/stat.h\"\n"); f_print(fout, "#include \"netinet/in.h\"\n"); f_print(fout, "#include \"h/time.h\"\n"); f_print(fout, "#include \"rx/xdr.h\"\n"); f_print(fout, "#include \"afs/rxgen_consts.h\"\n"); } else { f_print(fout, "#include <rx/xdr.h>\n"); } } tell = ftell(fout); while ((def = get_definition())) { if (!yflag) { if ((!IsRxgenDefinition(def)) && def->def_kind != DEF_CUSTOMIZED) emit(def); } } /* * Print out array containing list of all functions in the interface * in order */ if (xflag) { for (j = 0; j <= PackageIndex; j++) { f_print(fout, "AFS_RXGEN_EXPORT\n"); f_print(fout, "const char *%sfunction_names[] = {\n", PackagePrefix[j]); for (i = 0; i < no_of_stat_funcs_header[j]; i++) { if (i == 0) { f_print(fout, "\t\"%s\"", function_list[j][i]); } else { f_print(fout, ",\n\t\"%s\"", function_list[j][i]); } } f_print(fout, "\n};\n"); } er_Proc_CodeGeneration(); } if (extend && tell == ftell(fout)) { (void)unlink(outfilename); } cflag = 0; }
int main(int argc, char *argv[]) { struct commandline cmd; #ifdef AFS_NT40_ENV /* initialize CPP with the correct pre-processor for Windows */ CPP = getenv("RXGEN_CPPCMD"); if (!CPP) CPP = "cl /EP /C /nologo"; #endif /* AFS_NT40_ENV */ #ifdef AFS_AIX32_ENV /* * The following signal action for AIX is necessary so that in case of a * crash (i.e. core is generated) we can include the user's data section * in the core dump. Unfortunately, by default, only a partial core is * generated which, in many cases, isn't too useful. */ struct sigaction nsa; sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; sigaction(SIGSEGV, &nsa, NULL); #endif reinitialize(); if (!parseargs(argc, argv, &cmd)) { f_print(stderr, "usage: %s infile\n", cmdname); f_print(stderr, " %s [-c | -h | -l | -m | -C | -S | -r | -b | -k | -R | -p | -d | -z | -u] [-Pprefix] [-Idir] [-o outfile] [infile]\n", cmdname); f_print(stderr, " %s [-s udp|tcp]* [-o outfile] [infile]\n", cmdname); exit(1); } OutFileFlag = cmd.outfile; if (OutFileFlag) strcpy(OutFile, cmd.outfile); if (cmd.cflag) { OutFileFlag = NULL; c_output(cmd.infile, "-DRPC_XDR", !EXTEND, cmd.outfile, 0); } else if (cmd.hflag) { h_output(cmd.infile, "-DRPC_HDR", !EXTEND, cmd.outfile, 0); } else if (cmd.lflag) { l_output(cmd.infile, "-DRPC_CLNT", !EXTEND, cmd.outfile); } else if (cmd.sflag || cmd.mflag) { s_output(argc, argv, cmd.infile, "-DRPC_SVC", !EXTEND, cmd.outfile, cmd.mflag); } else if (cmd.Cflag) { OutFileFlag = NULL; C_output(cmd.infile, "-DRPC_CLIENT", !EXTEND, cmd.outfile, 1); } else if (cmd.Sflag) { OutFileFlag = NULL; S_output(cmd.infile, "-DRPC_SERVER", !EXTEND, cmd.outfile, 1); } else { if (OutFileFlag && (strrchr(OutFile, '.') == NULL)) strcat(OutFile, "."); if (cmd.rflag) { C_output((OutFileFlag ? OutFile : cmd.infile), "-DRPC_CLIENT", EXTEND, ".cs.c", 1); reinitialize(); S_output((OutFileFlag ? OutFile : cmd.infile), "-DRPC_SERVER", EXTEND, ".ss.c", 1); reinitialize(); } else { reinitialize(); c_output((OutFileFlag ? OutFile : cmd.infile), "-DRPC_XDR", EXTEND, ".xdr.c", 0); reinitialize(); h_output((OutFileFlag ? OutFile : cmd.infile), "-DRPC_HDR", EXTEND, ".h", 0); reinitialize(); C_output((OutFileFlag ? OutFile : cmd.infile), "-DRPC_CLIENT", EXTEND, ".cs.c", 1); reinitialize(); S_output((OutFileFlag ? OutFile : cmd.infile), "-DRPC_SERVER", EXTEND, ".ss.c", 1); reinitialize(); } } if (fin && pclose_fin) { /* the cpp command we called returned a non-zero exit status */ if (pclose(fin)) { crash(); } } exit(0); }
static void puldefine(const char *name, const char *num) { f_print(fout, "#define %s %s\n", name, num); }
void pdeclaration (char *name, declaration * dec, int tab, char *separator) { char buf[8]; /* enough to hold "struct ", include NUL */ char *prefix; char *type; if (streq (dec->type, "void")) { return; } tabify (fout, tab); if (streq (dec->type, name) && !dec->prefix) { f_print (fout, "struct "); } if (streq (dec->type, "string")) { f_print (fout, "char *%s", dec->name); } else { prefix = ""; if (streq (dec->type, "bool")) { type = "bool_t"; } else if (streq (dec->type, "opaque")) { type = "char"; } else { if (dec->prefix) { s_print (buf, "%s ", dec->prefix); prefix = buf; } type = dec->type; } switch (dec->rel) { case REL_ALIAS: f_print (fout, "%s%s %s", prefix, type, dec->name); break; case REL_VECTOR: f_print (fout, "%s%s %s[%s]", prefix, type, dec->name, dec->array_max); break; case REL_POINTER: f_print (fout, "%s%s *%s", prefix, type, dec->name); break; case REL_ARRAY: f_print (fout, "struct {\n"); tabify (fout, tab); /* f_print (fout, "\tu_int %s_len;\n", dec->name); */ f_print (fout, "\tu_int len;\n"); if (compatflag) f_print (fout, "#undef %s_len\n#define %s_len len\n", dec->name, dec->name); tabify (fout, tab); /* f_print (fout, "\t%s%s *%s_val;\n", prefix, type, dec->name); */ f_print (fout, "\t%s%s *val;\n", prefix, type); if (compatflag) f_print (fout, "#undef %s_val\n#define %s_val val\n", dec->name, dec->name); tabify (fout, tab); f_print (fout, "} %s", dec->name); break; } } f_print (fout, separator); }
static void psproc1(definition * defp, int callTconnF, char *type, char *prefix, int iomask) { proc1_list *plist; f_print(fout, "\nextern %s %s%s%s(\n", type, prefix, defp->pc.proc_prefix, defp->pc.proc_name); if (callTconnF == 1 || callTconnF == 3) { f_print(fout, "\t/*IN */ struct rx_call *z_call"); } else if (callTconnF == 2) { f_print(fout, "\tstruct ubik_client *aclient, afs_int32 aflags"); } else { f_print(fout, "\t/*IN */ struct rx_connection *z_conn"); } for (plist = defp->pc.plists; plist; plist = plist->next) { if (plist->component_kind == DEF_PARAM && (iomask & (1 << plist->pl.param_kind))) { switch (plist->pl.param_kind) { case DEF_INPARAM: f_print(fout, ",\n\t/*IN %d*/ ",callTconnF); if ((callTconnF != 3) && strcmp(plist->pl.param_type, "char *")== 0) f_print(fout, "const "); break; case DEF_OUTPARAM: f_print(fout, ",\n\t/*OUT*/ "); break; case DEF_INOUTPARAM: f_print(fout, ",\n\t/*I/O*/ "); break; default: break; } if (plist->pl.param_flag & OUT_STRING) { f_print(fout, "%s *%s", plist->pl.param_type, plist->pl.param_name); } else { f_print(fout, "%s %s", plist->pl.param_type, plist->pl.param_name); } } } f_print(fout, ");\n"); }
static void print_ifstat(int indent, char *prefix, char *type, relation rel, char *amax, char *objname, char *name) { char *alt = NULL; switch (rel) { case REL_POINTER: print_ifopen(indent, "pointer"); print_ifarg("(char **)"); f_print(fout, "%s", objname); print_ifsizeof(prefix, type); break; case REL_VECTOR: if (streq(type, "string")) { alt = "string"; } else if (streq(type, "opaque")) { alt = "opaque"; } if (alt) { print_ifopen(indent, alt); print_ifarg(objname); } else { print_ifopen(indent, "vector"); print_ifarg("(char *)"); f_print(fout, "%s", objname); } print_ifarg(amax); if (!alt) { print_ifsizeof(prefix, type); } break; case REL_ARRAY: if (streq(type, "string")) { alt = "string"; } else if (streq(type, "opaque")) { alt = "bytes"; } if (streq(type, "string")) { print_ifopen(indent, alt); print_ifarg(objname); } else { if (alt) { print_ifopen(indent, alt); } else { print_ifopen(indent, "array"); } /* The (void*) avoids a gcc-4.1 warning */ print_ifarg("(char **)(void*)"); if (*objname == '&') { f_print(fout, "%s.%s_val, (u_int *)%s.%s_len", objname, name, objname, name); } else { f_print(fout, "&%s->%s_val, (u_int *)&%s->%s_len", objname, name, objname, name); } } print_ifarg(amax); if (!alt) { print_ifsizeof(prefix, type); } break; case REL_ALIAS: print_ifopen(indent, type); print_ifarg(objname); break; } print_ifclose(indent); }
static void ptypedef(definition * def) { char *name = def->def_name; char *old = def->def.ty.old_type; char prefix[8]; /* enough to contain "struct ", including NUL */ relation rel = def->def.ty.rel; if (!streq(name, old)) { if (streq(old, "string")) { old = "char"; rel = REL_POINTER; } else if (!brief_flag && streq(old, "opaque")) { old = "char"; } else if (streq(old, "bool")) { old = "bool_t"; } if (undefined2(old, name) && def->def.ty.old_prefix) { s_print(prefix, "%s ", def->def.ty.old_prefix); } else { prefix[0] = 0; } f_print(fout, "typedef "); switch (rel) { case REL_ARRAY: if (brief_flag) { if (streq(old, "opaque")) { f_print(fout, "struct rx_opaque %s", name); } else { f_print(fout, "struct {\n"); f_print(fout, "\tu_int len;\n"); f_print(fout, "\t%s%s *val;\n", prefix, old); f_print(fout, "} %s", name); } } else { f_print(fout, "struct %s {\n", name); f_print(fout, "\tu_int %s_len;\n", name); f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name); f_print(fout, "} %s", name); } break; case REL_POINTER: f_print(fout, "%s%s *%s", prefix, old, name); break; case REL_VECTOR: f_print(fout, "%s%s %s[%s]", prefix, old, name, def->def.ty.array_max); break; case REL_ALIAS: f_print(fout, "%s%s %s", prefix, old, name); break; } def->pc.rel = rel; STOREVAL(&typedef_defined, def); f_print(fout, ";\n"); } }
static void print_ifarg (char *arg) { f_print (fout, ", %s", arg); }
static void puldefine(char *name, char *num) { f_print(fout, "#define %s ((afs_uint32)%s)\n", name, num); }
static void emit_union (definition * def) { declaration *dflt; case_list *cl; declaration *cs; char *object; #if 1 char *vecformat = "objp->RPC_UNION_NAME(%s).%s"; char *format = "&objp->RPC_UNION_NAME(%s).%s"; #else char *vecformat = "objp->u.%s"; char *format = "&objp->u.%s"; #endif print_stat (1, &def->def.un.enum_decl); f_print (fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name); for (cl = def->def.un.cases; cl != NULL; cl = cl->next) { f_print (fout, "\tcase %s:\n", cl->case_name); if (cl->contflag == 1) /* a continued case statement */ continue; cs = &cl->case_decl; if (!streq (cs->type, "void")) { object = alloc (strlen (def->def_name) + strlen (format) + strlen (cs->name) + 1); #if 1 if (isvectordef (cs->type, cs->rel)) { s_print (object, vecformat, def->def_name, cs->name); } else { s_print (object, format, def->def_name, cs->name); } #else if (isvectordef (cs->type, cs->rel)) s_print (object, vecformat, cs->name); else s_print (object, format, cs->name); #endif print_ifstat (2, cs->prefix, cs->type, cs->rel, cs->array_max, object, cs->name); free (object); } f_print (fout, "\t\tbreak;\n"); } dflt = def->def.un.default_decl; if (dflt != NULL) { if (!streq (dflt->type, "void")) { f_print (fout, "\tdefault:\n"); object = alloc (strlen (def->def_name) + strlen (format) + strlen (dflt->name) + 1); #if 1 if (isvectordef (dflt->type, dflt->rel)) { s_print (object, vecformat, def->def_name, dflt->name); } else { s_print (object, format, def->def_name, dflt->name); } #else if (isvectordef (dflt->type, dflt->rel)) s_print (object, vecformat, dflt->name); else s_print (object, format, dflt->name); #endif print_ifstat (2, dflt->prefix, dflt->type, dflt->rel, dflt->array_max, object, dflt->name); free (object); f_print (fout, "\t\tbreak;\n"); } } else { f_print (fout, "\tdefault:\n"); f_print (fout, "\t\treturn (FALSE);\n"); } f_print (fout, "\t}\n"); }
int main(int argc, char * argv[]) { int x = 0, z = 1; if (argv[1] != NULL) { do { if (strcmp(argv[z], help) == 0) { f_help(); } if (strcmp(argv[z], print) == 0) { x = 0; f_print(x); } if (strcmp(argv[z], removeall) == 0) { f_removeall(); } if (strcmp(argv[z], add) == 0) { f_add(); } if (strcmp(argv[z], remov) == 0) { f_remov(); } if (strcmp(argv[z], findname) == 0) { x = 0; f_find(x); } if (strcmp(argv[z], findsname) == 0) { x = 1; f_find(x); } if (strcmp(argv[z], findlname) == 0) { x = 2; f_find(x); } if (strcmp(argv[z], findgr) == 0) { x = 3; f_find(x); } if (strcmp(argv[z], sortname) == 0) { x = 1; f_sort(x); } if (strcmp(argv[z], sortsname) == 0) { x = 2; f_sort(x); } if (strcmp(argv[z], sortlname) == 0) { x = 3; f_sort(x); } if (strcmp(argv[z], sortgr) == 0) { x = 4; f_sort(x); } if (strcmp(argv[z], kol) == 0) { x = 1; f_print(x); } z++; } while (argv[z] != NULL); } return 0; }
void printdirective(char *line) { f_print(fout, "%s", line + 1); }
static void pdefine (char *name, char *num) { f_print (fout, "#define %s %s\n", name, num); }
static void printbody(proc_list *proc) { decl_list *l; bool_t args2 = (proc->arg_num > 1); /* * For new style with multiple arguments, need a structure in which * to stuff the arguments. */ if (newstyle && args2) { f_print(fout, "\t%s", proc->args.argname); f_print(fout, " arg;\n"); } if (!mtflag) { f_print(fout, "\tstatic "); if (streq(proc->res_type, "void")) f_print(fout, "char "); else ptype(proc->res_prefix, proc->res_type, 0); f_print(fout, "%s;\n", RESULT); f_print(fout, "\n"); f_print(fout, "\tmemset((char *)%s%s, 0, sizeof (%s));\n", ampr(proc->res_type), RESULT, RESULT); } if (newstyle && !args2 && (streq(proc->args.decls->decl.type, "void"))) { /* newstyle, 0 arguments */ if (mtflag) f_print(fout, "\t return "); else f_print(fout, "\t if "); f_print(fout, "(clnt_call(clnt, %s,\n\t\t(xdrproc_t) xdr_void, ", proc->proc_name); f_print(fout, "(caddr_t) NULL,\n\t\t(xdrproc_t) xdr_%s, " "(caddr_t) %s%s,", stringfix(proc->res_type), (mtflag) ? "" : ampr(proc->res_type), RESULT); if (mtflag) f_print(fout, "\n\t\tTIMEOUT));\n"); else f_print(fout, "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n"); } else if (newstyle && args2) { /* * Newstyle, multiple arguments * stuff arguments into structure */ for (l = proc->args.decls; l != NULL; l = l->next) { f_print(fout, "\targ.%s = %s;\n", l->decl.name, l->decl.name); } if (mtflag) f_print(fout, "\treturn "); else f_print(fout, "\tif "); f_print(fout, "(clnt_call(clnt, %s,\n\t\t(xdrproc_t) xdr_%s", proc->proc_name,proc->args.argname); f_print(fout, ", (caddr_t) &arg,\n\t\t(xdrproc_t) xdr_%s, " "(caddr_t) %s%s,", stringfix(proc->res_type), (mtflag) ? "" : ampr(proc->res_type), RESULT); if (mtflag) f_print(fout, "\n\t\tTIMEOUT));\n"); else f_print(fout, "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n"); } else { /* single argument, new or old style */ if (!mtflag) { f_print(fout, "\tif (clnt_call(clnt, %s,\n" "\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,\n" "\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,\n" "\t\tTIMEOUT) != RPC_SUCCESS) {\n", proc->proc_name, stringfix(proc->args.decls->decl.type), (newstyle ? "&" : ""), (newstyle) ? proc->args.decls->decl.name : "argp", stringfix(proc->res_type), ampr(proc->res_type), RESULT); } else { f_print(fout, "\treturn (clnt_call(clnt, %s,\n" "\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,\n" "\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,\n" "\t\tTIMEOUT));\n", proc->proc_name, stringfix(proc->args.decls->decl.type), (newstyle ? "&" : ""), (newstyle) ? proc->args.decls->decl.name : "argp", stringfix(proc->res_type), "", RESULT); } } if (!mtflag) { f_print(fout, "\t\treturn (NULL);\n"); f_print(fout, "\t}\n"); if (streq(proc->res_type, "void")) { f_print(fout, "\treturn ((void *)%s%s);\n", ampr(proc->res_type), RESULT); } else { f_print(fout, "\treturn (%s%s);\n", ampr(proc->res_type), RESULT); } } }
static void puldefine (char *name, char *num) { f_print (fout, "#define %s ((u_long)%s)\n", name, num); }
void pvname (const char *pname, const char *vnum) { f_print (fout, "%s_%s", locase (pname), vnum); }
static void ptypedef (definition * def) { char *name = def->def_name; char *old = def->def.ty.old_type; char prefix[8]; /* enough to contain "struct ", including NUL */ relation rel = def->def.ty.rel; if (!streq (name, old)) { if (streq (old, "string")) { old = "char"; rel = REL_POINTER; } else if (streq (old, "opaque")) { old = "char"; } else if (streq (old, "bool")) { old = "bool_t"; } if (undefined2 (old, name) && def->def.ty.old_prefix) { s_print (prefix, "%s ", def->def.ty.old_prefix); } else { prefix[0] = 0; } f_print (fout, "typedef "); switch (rel) { case REL_ARRAY: f_print (fout, "struct {\n"); #if 0 f_print (fout, "\tu_int %s_len;\n", name); f_print (fout, "\t%s%s *%s_val;\n", prefix, old, name); #else f_print (fout, "\tu_int len;\n"); if (compatflag) f_print (fout, "#ifndef %s_len\n#define %s_len len\n#endif\n", name, name); f_print (fout, "\t%s%s *val;\n", prefix, old); if (compatflag) f_print (fout, "#ifndef %s_val\n#define %s_val val\n#endif\n", name, name); #endif f_print (fout, "} %s", name); break; case REL_POINTER: f_print (fout, "%s%s *%s", prefix, old, name); break; case REL_VECTOR: f_print (fout, "%s%s %s[%s]", prefix, old, name, def->def.ty.array_max); break; case REL_ALIAS: f_print (fout, "%s%s %s", prefix, old, name); break; } f_print (fout, ";\n"); } }
static void print_ifopen(int indent, const char *name) { tabify(fout, indent); f_print(fout, "if (!xdr_%s(xdrs", name); }
static void space() { f_print(fout, "\n\n"); }