Ejemplo n.º 1
0
static void
write_program(definition * def, char *storage)
{
    version_list *vp;
    proc_list *proc;
    int filled;

    for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
	f_print(fout, "\n");
	if (storage != NULL) {
	    f_print(fout, "%s ", storage);
	}
	f_print(fout, "void\n");
	pvname(def->def_name, vp->vers_num);
	f_print(fout, "(%s, %s)\n", RQSTP, TRANSP);
	f_print(fout, "	struct svc_req *%s;\n", RQSTP);
	f_print(fout, "	SVCXPRT *%s;\n", TRANSP);
	f_print(fout, "{\n");

	filled = 0;
	f_print(fout, "\tunion {\n");
	for (proc = vp->procs; proc != NULL; proc = proc->next) {
	    if (streq(proc->arg_type, "void")) {
		continue;
	    }
	    filled = 1;
	    f_print(fout, "\t\t");
	    ptype(proc->arg_prefix, proc->arg_type, 0);
	    pvname(proc->proc_name, vp->vers_num);
	    f_print(fout, "_arg;\n");
	}
	if (!filled) {
	    f_print(fout, "\t\tint fill;\n");
	}
	f_print(fout, "\t} %s;\n", ARG);
	f_print(fout, "\tchar *%s;\n", RESULT);
	f_print(fout, "\tbool_t (*xdr_%s)(), (*xdr_%s)();\n", ARG, RESULT);
	f_print(fout, "\tchar *(*%s)();\n", ROUTINE);
	f_print(fout, "\n");
	f_print(fout, "\tswitch (%s->rq_proc) {\n", RQSTP);

	if (!nullproc(vp->procs)) {
	    f_print(fout, "\tcase NULLPROC:\n");
	    f_print(fout, "\t\tsvc_sendreply(%s, xdr_void, NULL);\n", TRANSP);
	    f_print(fout, "\t\treturn;\n\n");
	}
	for (proc = vp->procs; proc != NULL; proc = proc->next) {
	    f_print(fout, "\tcase %s:\n", proc->proc_name);
	    f_print(fout, "\t\txdr_%s = xdr_%s;\n", ARG,
		    stringfix(proc->arg_type));
	    f_print(fout, "\t\txdr_%s = xdr_%s;\n", RESULT,
		    stringfix(proc->res_type));
	    f_print(fout, "\t\t%s = (char *(*)()) ", ROUTINE);
	    pvname(proc->proc_name, vp->vers_num);
	    f_print(fout, ";\n");
	    f_print(fout, "\t\tbreak;\n\n");
	}
	f_print(fout, "\tdefault:\n");
	printerr("noproc", TRANSP);
	f_print(fout, "\t\treturn;\n");
	f_print(fout, "\t}\n");

	f_print(fout, "\tmemset(&%s, 0, sizeof(%s));\n", ARG, ARG);
	printif("getargs", TRANSP, "&", ARG);
	printerr("decode", TRANSP);
	f_print(fout, "\t\treturn;\n");
	f_print(fout, "\t}\n");

	f_print(fout, "\t%s = (*%s)(&%s, %s);\n", RESULT, ROUTINE, ARG,
		RQSTP);
	f_print(fout,
		"\tif (%s != NULL && !svc_sendreply(%s, xdr_%s, %s)) {\n",
		RESULT, TRANSP, RESULT, RESULT);
	printerr("systemerr", TRANSP);
	f_print(fout, "\t}\n");

	printif("freeargs", TRANSP, "&", ARG);
	f_print(fout,
		"\t\tfprintf(stderr, \"unable to free arguments\\n\");\n");
	f_print(fout, "\t\texit(1);\n");
	f_print(fout, "\t}\n");

	f_print(fout, "}\n\n");
    }
}
Ejemplo n.º 2
0
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;
    s_print (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;
      f_print (fout, "%s", null_entry);
    }
    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;
      }
      f_print (fout, "    {\n\t(char *(*)())RPCGEN_ACTION(");

      /* routine to invoke */
      if (!newstyle)
	pvname_svc (proc->proc_name, vp->vers_num);
      else {
	if (newstyle)
	  f_print (fout, "_");	/* calls internal func */
	pvname (proc->proc_name, vp->vers_num);
      }
      f_print (fout, "),\n");

      /* argument info */
      if (proc->arg_num > 1)
	printit ((char *) 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);
      f_print (fout, "    },\n");
    }

    /* print the table trailer */
    f_print (fout, "%s", tbl_end);
    f_print (fout, tbl_nproc, progvers, progvers, progvers);

    f_print (fout,
	     "const struct rpc_program_tc %s = {\n"
	     "\t%s, %s, %s_table,\n"
	     "\tsizeof (%s_table) / sizeof (%s_table[0])\n"
	     "};\n\n",
	     progvers, def->def_name, vp->vers_num, progvers,
	     progvers, progvers);
	     
  }
}