예제 #1
0
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");
	}
	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 */
		f_print(fout,
			"\tif (clnt_call(clnt, %s, (xdrproc_t) xdr_void, (caddr_t) NULL, "
			"(xdrproc_t) xdr_%s, (caddr_t) %s%s, TIMEOUT) != RPC_SUCCESS) {\n",
			proc->proc_name,
			stringfix(proc->res_type), ampr(proc->res_type), RESULT);

	} 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);
		}
		f_print(fout,
			"\tif (clnt_call(clnt, %s, (xdrproc_t) xdr_%s, (caddr_t) &arg, "
			"(xdrproc_t) xdr_%s, (caddr_t) %s%s, TIMEOUT) != RPC_SUCCESS) {\n",
			proc->proc_name, proc->args.argname,
			stringfix(proc->res_type), ampr(proc->res_type), RESULT);
	} else {		/* single argument, new or old style */
		f_print(fout,
			"\tif (clnt_call(clnt, %s, (xdrproc_t) xdr_%s, "
			"(caddr_t) %s%s, (xdrproc_t) xdr_%s, (caddr_t) %s%s, TIMEOUT) != 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);
	}
	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);
	}
}
예제 #2
0
static void
printbody(proc_list *proc)
{
	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, "res;\n");
	f_print(fout, "\n");
 	f_print(fout, "\tbzero((char *)%sres, sizeof(res));\n",
 		ampr(proc->res_type));
	f_print(fout,
		"\tif (clnt_call(clnt, %s, xdr_%s, argp, xdr_%s, %sres, TIMEOUT) != RPC_SUCCESS) {\n",
		proc->proc_name, stringfix(proc->arg_type),
		stringfix(proc->res_type), ampr(proc->res_type));
	f_print(fout, "\t\treturn (NULL);\n");
	f_print(fout, "\t}\n");
	if (streq(proc->res_type, "void")) {
		f_print(fout, "\treturn ((void *)%sres);\n",
			ampr(proc->res_type));
	} else {
		f_print(fout, "\treturn (%sres);\n", ampr(proc->res_type));
	}
}
예제 #3
0
static void
printit (char *prefix, char *type)
{
  int len;
  int tabs;


  len = fprintf (fout, "\t(xdrproc_t) xdr_%s,", stringfix (type));
  /* account for leading tab expansion */
  len += TABSIZE - 1;
  /* round up to tabs required */
  tabs = (TABSTOP - len + TABSIZE - 1) / TABSIZE;
  f_print (fout, "%s", &tabstr[TABCOUNT - tabs]);

  if (streq (type, "void")) {
    f_print (fout, "0");
  }
  else {
    f_print (fout, "sizeof ( ");
    /* XXX: should "follow" be 1 ??? */
    ptype (prefix, type, 0);
    f_print (fout, ")");
  }
  f_print (fout, ",\n");
}
예제 #4
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");
    }
}