rpc_main.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451
  1. /*
  2. * From @(#)rpc_main.c 1.30 89/03/30
  3. *
  4. * Copyright (c) 2010, Oracle America, Inc.
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are
  7. * met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above
  12. * copyright notice, this list of conditions and the following
  13. * disclaimer in the documentation and/or other materials
  14. * provided with the distribution.
  15. * * Neither the name of the "Oracle America, Inc." nor the names of its
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  24. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  26. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. /*
  33. * rpc_main.c, Top level of the RPC protocol compiler.
  34. */
  35. #include <errno.h>
  36. #include <stdio.h>
  37. #include <string.h>
  38. #include <unistd.h>
  39. #include <libintl.h>
  40. #include <locale.h>
  41. #include <ctype.h>
  42. #include <sys/types.h>
  43. #include <sys/param.h>
  44. #include <sys/file.h>
  45. #include <sys/stat.h>
  46. #include <sys/wait.h>
  47. #include "rpc_parse.h"
  48. #include "rpc_util.h"
  49. #include "rpc_scan.h"
  50. #include "proto.h"
  51. #include "../version.h"
  52. #define PACKAGE _libc_intl_domainname
  53. #define EXTEND 1 /* alias for TRUE */
  54. #define DONT_EXTEND 0 /* alias for FALSE */
  55. struct commandline
  56. {
  57. int cflag; /* xdr C routines */
  58. int hflag; /* header file */
  59. int lflag; /* client side stubs */
  60. int mflag; /* server side stubs */
  61. int nflag; /* netid flag */
  62. int sflag; /* server stubs for the given transport */
  63. int tflag; /* dispatch Table file */
  64. int Ssflag; /* produce server sample code */
  65. int Scflag; /* produce client sample code */
  66. int makefileflag; /* Generate a template Makefile */
  67. const char *infile; /* input module name */
  68. const char *outfile; /* output module name */
  69. };
  70. static const char *cmdname;
  71. static const char *svcclosetime = "120";
  72. static int cppDefined; /* explicit path for C preprocessor */
  73. static const char *CPP = "/lib/cpp";
  74. static const char CPPFLAGS[] = "-C";
  75. static char *pathbuf;
  76. static int cpp_pid;
  77. static const char *allv[] =
  78. {
  79. "rpcgen", "-s", "udp", "-s", "tcp"
  80. };
  81. static int allc = sizeof (allv) / sizeof (allv[0]);
  82. static const char *allnv[] =
  83. {
  84. "rpcgen", "-s", "netpath",
  85. };
  86. static int allnc = sizeof (allnv) / sizeof (allnv[0]);
  87. /*
  88. * machinations for handling expanding argument list
  89. */
  90. static void addarg (const char *); /* add another argument to the list */
  91. static void putarg (int, const char *); /* put argument at specified location */
  92. static void clear_args (void); /* clear argument list */
  93. static void checkfiles (const char *, const char *);
  94. /* check if out file already exists */
  95. static void clear_args (void);
  96. static char *extendfile (const char *file, const char *ext);
  97. static void open_output (const char *infile, const char *outfile);
  98. static void add_warning (void);
  99. static void clear_args (void);
  100. static void find_cpp (void);
  101. static void open_input (const char *infile, const char *define);
  102. static int check_nettype (const char *name, const char *list_to_check[]);
  103. static void c_output (const char *infile, const char *define,
  104. int extend, const char *outfile);
  105. static void h_output (const char *infile, const char *define,
  106. int extend, const char *outfile);
  107. static void s_output (int argc, const char *argv[], const char *infile,
  108. const char *define, int extend,
  109. const char *outfile, int nomain, int netflag);
  110. static void l_output (const char *infile, const char *define,
  111. int extend, const char *outfile);
  112. static void t_output (const char *infile, const char *define,
  113. int extend, const char *outfile);
  114. static void svc_output (const char *infile, const char *define,
  115. int extend, const char *outfile);
  116. static void clnt_output (const char *infile, const char *define,
  117. int extend, const char *outfile);
  118. static void mkfile_output (struct commandline *cmd);
  119. static int do_registers (int argc, const char *argv[]);
  120. static void addarg (const char *cp);
  121. static void putarg (int whereto, const char *cp);
  122. static void checkfiles (const char *infile, const char *outfile);
  123. static int parseargs (int argc, const char *argv[], struct commandline *cmd);
  124. static void usage (FILE *stream, int status) __attribute__ ((noreturn));
  125. static void options_usage (FILE *stream, int status) __attribute__ ((noreturn));
  126. static void print_version (void);
  127. static void c_initialize (void);
  128. static char *generate_guard (const char *pathname);
  129. #define ARGLISTLEN 20
  130. #define FIXEDARGS 2
  131. static const char *arglist[ARGLISTLEN];
  132. static int argcount = FIXEDARGS;
  133. int nonfatalerrors; /* errors */
  134. int inetdflag /* = 1 */ ; /* Support for inetd *//* is now the default */
  135. int pmflag; /* Support for port monitors */
  136. int logflag; /* Use syslog instead of fprintf for errors */
  137. int tblflag; /* Support for dispatch table file */
  138. int mtflag; /* Support for MT */
  139. #define INLINE 3
  140. /*length at which to start doing an inline */
  141. int inlineflag = INLINE; /* length at which to start doing an inline. 3 = default
  142. if 0, no xdr_inline code */
  143. int indefinitewait; /* If started by port monitors, hang till it wants */
  144. int exitnow; /* If started by port monitors, exit after the call */
  145. int timerflag; /* TRUE if !indefinite && !exitnow */
  146. int newstyle; /* newstyle of passing arguments (by value) */
  147. int Cflag = 1; /* ANSI C syntax */
  148. int CCflag; /* C++ files */
  149. static int allfiles; /* generate all files */
  150. int tirpcflag; /* generating code for tirpc, by default */
  151. xdrfunc *xdrfunc_head; /* xdr function list */
  152. xdrfunc *xdrfunc_tail; /* xdr function list */
  153. int
  154. main (int argc, const char *argv[])
  155. {
  156. struct commandline cmd;
  157. setlocale (LC_ALL, "");
  158. textdomain (_libc_intl_domainname);
  159. (void) memset ((char *) &cmd, 0, sizeof (struct commandline));
  160. clear_args ();
  161. if (!parseargs (argc, argv, &cmd))
  162. usage (stderr, 1);
  163. if (cmd.cflag || cmd.hflag || cmd.lflag || cmd.tflag || cmd.sflag ||
  164. cmd.mflag || cmd.nflag || cmd.Ssflag || cmd.Scflag)
  165. {
  166. checkfiles (cmd.infile, cmd.outfile);
  167. }
  168. else
  169. checkfiles (cmd.infile, NULL);
  170. if (cmd.cflag)
  171. c_output (cmd.infile, "-DRPC_XDR", DONT_EXTEND, cmd.outfile);
  172. else if (cmd.hflag)
  173. h_output (cmd.infile, "-DRPC_HDR", DONT_EXTEND, cmd.outfile);
  174. else if (cmd.lflag)
  175. l_output (cmd.infile, "-DRPC_CLNT", DONT_EXTEND, cmd.outfile);
  176. else if (cmd.sflag || cmd.mflag || (cmd.nflag))
  177. s_output (argc, argv, cmd.infile, "-DRPC_SVC", DONT_EXTEND,
  178. cmd.outfile, cmd.mflag, cmd.nflag);
  179. else if (cmd.tflag)
  180. t_output (cmd.infile, "-DRPC_TBL", DONT_EXTEND, cmd.outfile);
  181. else if (cmd.Ssflag)
  182. svc_output (cmd.infile, "-DRPC_SERVER", DONT_EXTEND, cmd.outfile);
  183. else if (cmd.Scflag)
  184. clnt_output (cmd.infile, "-DRPC_CLIENT", DONT_EXTEND, cmd.outfile);
  185. else if (cmd.makefileflag)
  186. mkfile_output (&cmd);
  187. else
  188. {
  189. /* the rescans are required, since cpp may effect input */
  190. c_output (cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c");
  191. reinitialize ();
  192. h_output (cmd.infile, "-DRPC_HDR", EXTEND, ".h");
  193. reinitialize ();
  194. l_output (cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c");
  195. reinitialize ();
  196. if (inetdflag || !tirpcflag)
  197. s_output (allc, allv, cmd.infile, "-DRPC_SVC", EXTEND,
  198. "_svc.c", cmd.mflag, cmd.nflag);
  199. else
  200. s_output (allnc, allnv, cmd.infile, "-DRPC_SVC",
  201. EXTEND, "_svc.c", cmd.mflag, cmd.nflag);
  202. if (tblflag)
  203. {
  204. reinitialize ();
  205. t_output (cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
  206. }
  207. if (allfiles)
  208. {
  209. reinitialize ();
  210. svc_output (cmd.infile, "-DRPC_SERVER", EXTEND, "_server.c");
  211. reinitialize ();
  212. clnt_output (cmd.infile, "-DRPC_CLIENT", EXTEND, "_client.c");
  213. }
  214. if (allfiles || (cmd.makefileflag == 1))
  215. {
  216. reinitialize ();
  217. mkfile_output (&cmd);
  218. }
  219. }
  220. return nonfatalerrors;
  221. }
  222. /*
  223. * add extension to filename
  224. */
  225. static char *
  226. extendfile (const char *file, const char *ext)
  227. {
  228. char *res;
  229. const char *p;
  230. res = alloc (strlen (file) + strlen (ext) + 1);
  231. if (res == NULL)
  232. abort ();
  233. p = strrchr (file, '.');
  234. if (p == NULL)
  235. p = file + strlen (file);
  236. strcpy (res, file);
  237. strcpy (res + (p - file), ext);
  238. return res;
  239. }
  240. /*
  241. * Open output file with given extension
  242. */
  243. static void
  244. open_output (const char *infile, const char *outfile)
  245. {
  246. if (outfile == NULL)
  247. {
  248. fout = stdout;
  249. return;
  250. }
  251. if (infile != NULL && streq (outfile, infile))
  252. {
  253. fprintf (stderr, _ ("%s: output would overwrite %s\n"), cmdname,
  254. infile);
  255. crash ();
  256. }
  257. fout = fopen (outfile, "w");
  258. if (fout == NULL)
  259. {
  260. fprintf (stderr, _ ("%s: unable to open %s: %m\n"), cmdname, outfile);
  261. crash ();
  262. }
  263. record_open (outfile);
  264. }
  265. /* Close the output file and check for write errors. */
  266. static void
  267. close_output (const char *outfile)
  268. {
  269. if (fclose (fout) == EOF)
  270. {
  271. fprintf (stderr, _("%s: while writing output %s: %m"), cmdname,
  272. outfile ?: "<stdout>");
  273. crash ();
  274. }
  275. }
  276. static void
  277. add_warning (void)
  278. {
  279. fprintf (fout, "/*\n");
  280. fprintf (fout, " * Please do not edit this file.\n");
  281. fprintf (fout, " * It was generated using rpcgen.\n");
  282. fprintf (fout, " */\n\n");
  283. }
  284. /* clear list of arguments */
  285. static void
  286. clear_args (void)
  287. {
  288. int i;
  289. for (i = FIXEDARGS; i < ARGLISTLEN; ++i)
  290. arglist[i] = NULL;
  291. argcount = FIXEDARGS;
  292. }
  293. /* make sure that a CPP exists */
  294. static void
  295. find_cpp (void)
  296. {
  297. struct stat64 buf;
  298. if (stat64 (CPP, &buf) == 0)
  299. return;
  300. if (cppDefined) /* user specified cpp but it does not exist */
  301. {
  302. fprintf (stderr, _ ("cannot find C preprocessor: %s\n"), CPP);
  303. crash ();
  304. }
  305. /* fall back to system CPP */
  306. CPP = "cpp";
  307. }
  308. /*
  309. * Open input file with given define for C-preprocessor
  310. */
  311. static void
  312. open_input (const char *infile, const char *define)
  313. {
  314. int pd[2];
  315. infilename = (infile == NULL) ? "<stdin>" : infile;
  316. if (pipe (pd) != 0)
  317. {
  318. perror ("pipe");
  319. exit (1);
  320. }
  321. cpp_pid = fork ();
  322. switch (cpp_pid)
  323. {
  324. case 0:
  325. find_cpp ();
  326. putarg (0, CPP);
  327. putarg (1, CPPFLAGS);
  328. addarg (define);
  329. if (infile)
  330. addarg (infile);
  331. addarg ((char *) NULL);
  332. close (1);
  333. dup2 (pd[1], 1);
  334. close (pd[0]);
  335. execvp (arglist[0], (char **) arglist);
  336. if (errno == ENOENT)
  337. {
  338. fprintf (stderr, _ ("cannot find C preprocessor: %s\n"), CPP);
  339. exit (1);
  340. }
  341. perror ("execvp");
  342. exit (1);
  343. case -1:
  344. perror ("fork");
  345. exit (1);
  346. }
  347. close (pd[1]);
  348. fin = fdopen (pd[0], "r");
  349. if (fin == NULL)
  350. {
  351. fprintf (stderr, "%s: ", cmdname);
  352. perror (infilename);
  353. crash ();
  354. }
  355. }
  356. /* Close the connection to the C-preprocessor and check for successfull
  357. termination. */
  358. static void
  359. close_input (void)
  360. {
  361. int status;
  362. fclose (fin);
  363. /* Check the termination status. */
  364. if (waitpid (cpp_pid, &status, 0) < 0)
  365. {
  366. perror ("waitpid");
  367. crash ();
  368. }
  369. if (WIFSIGNALED (status) || WEXITSTATUS (status) != 0)
  370. {
  371. if (WIFSIGNALED (status))
  372. fprintf (stderr, _("%s: C preprocessor failed with signal %d\n"),
  373. cmdname, WTERMSIG (status));
  374. else
  375. fprintf (stderr, _("%s: C preprocessor failed with exit code %d\n"),
  376. cmdname, WEXITSTATUS (status));
  377. crash ();
  378. }
  379. }
  380. /* valid tirpc nettypes */
  381. static const char *valid_ti_nettypes[] =
  382. {
  383. "netpath",
  384. "visible",
  385. "circuit_v",
  386. "datagram_v",
  387. "circuit_n",
  388. "datagram_n",
  389. "udp",
  390. "tcp",
  391. "raw",
  392. NULL
  393. };
  394. /* valid inetd nettypes */
  395. static const char *valid_i_nettypes[] =
  396. {
  397. "udp",
  398. "tcp",
  399. NULL
  400. };
  401. static int
  402. check_nettype (const char *name, const char *list_to_check[])
  403. {
  404. int i;
  405. for (i = 0; list_to_check[i] != NULL; i++)
  406. {
  407. if (strcmp (name, list_to_check[i]) == 0)
  408. {
  409. return 1;
  410. }
  411. }
  412. fprintf (stderr, _ ("illegal nettype: `%s'\n"), name);
  413. return 0;
  414. }
  415. /*
  416. * Compile into an XDR routine output file
  417. */
  418. static void
  419. c_output (const char *infile, const char *define, int extend,
  420. const char *outfile)
  421. {
  422. definition *def;
  423. char *include;
  424. const char *outfilename;
  425. long tell;
  426. c_initialize ();
  427. open_input (infile, define);
  428. outfilename = extend ? extendfile (infile, outfile) : outfile;
  429. open_output (infile, outfilename);
  430. add_warning ();
  431. if (infile && (include = extendfile (infile, ".h")))
  432. {
  433. fprintf (fout, "#include \"%s\"\n", include);
  434. free (include);
  435. /* .h file already contains rpc/rpc.h */
  436. }
  437. else
  438. fprintf (fout, "#include <rpc/rpc.h>\n");
  439. tell = ftell (fout);
  440. while ((def = get_definition ()) != NULL)
  441. emit (def);
  442. if (extend && tell == ftell (fout))
  443. unlink (outfilename);
  444. close_input ();
  445. close_output (outfilename);
  446. }
  447. void
  448. c_initialize (void)
  449. {
  450. /* add all the starting basic types */
  451. add_type (1, "int");
  452. add_type (1, "long");
  453. add_type (1, "short");
  454. add_type (1, "bool");
  455. add_type (1, "u_int");
  456. add_type (1, "u_long");
  457. add_type (1, "u_short");
  458. }
  459. char rpcgen_table_dcl[] = "struct rpcgen_table {\n\
  460. char *(*proc)();\n\
  461. xdrproc_t xdr_arg;\n\
  462. unsigned len_arg;\n\
  463. xdrproc_t xdr_res;\n\
  464. unsigned len_res;\n\
  465. };\n";
  466. static char *
  467. generate_guard (const char *pathname)
  468. {
  469. const char *filename;
  470. char *guard, *tmp;
  471. filename = strrchr (pathname, '/'); /* find last component */
  472. filename = ((filename == NULL) ? pathname : filename + 1);
  473. guard = extendfile (filename, "_H_RPCGEN");
  474. /* convert to upper case */
  475. tmp = guard;
  476. while (*tmp)
  477. {
  478. if (islower (*tmp))
  479. *tmp = toupper (*tmp);
  480. tmp++;
  481. }
  482. return guard;
  483. }
  484. /*
  485. * Compile into an XDR header file
  486. */
  487. static void
  488. h_output (const char *infile, const char *define, int extend,
  489. const char *outfile)
  490. {
  491. xdrfunc *xdrfuncp;
  492. definition *def;
  493. const char *ifilename;
  494. const char *outfilename;
  495. long tell;
  496. char *guard;
  497. list *l;
  498. open_input (infile, define);
  499. outfilename = extend ? extendfile (infile, outfile) : outfile;
  500. open_output (infile, outfilename);
  501. add_warning ();
  502. ifilename = (infile == NULL) ? "STDIN" : infile;
  503. guard = generate_guard (outfilename ? outfilename : ifilename);
  504. fprintf (fout, "#ifndef _%s\n#define _%s\n\n", guard,
  505. guard);
  506. fprintf (fout, "#include <rpc/rpc.h>\n\n");
  507. if (mtflag)
  508. {
  509. fprintf (fout, "#include <pthread.h>\n");
  510. }
  511. /* put the C++ support */
  512. if (Cflag && !CCflag)
  513. {
  514. fprintf (fout, "\n#ifdef __cplusplus\n");
  515. fprintf (fout, "extern \"C\" {\n");
  516. fprintf (fout, "#endif\n\n");
  517. }
  518. tell = ftell (fout);
  519. /* print data definitions */
  520. while ((def = get_definition ()) != NULL)
  521. {
  522. print_datadef (def);
  523. }
  524. /* print function declarations.
  525. Do this after data definitions because they might be used as
  526. arguments for functions */
  527. for (l = defined; l != NULL; l = l->next)
  528. {
  529. print_funcdef (l->val);
  530. }
  531. /* Now print all xdr func declarations */
  532. if (xdrfunc_head != NULL)
  533. {
  534. fprintf (fout, "\n/* the xdr functions */\n");
  535. if (CCflag)
  536. {
  537. fprintf (fout, "\n#ifdef __cplusplus\n");
  538. fprintf (fout, "extern \"C\" {\n");
  539. fprintf (fout, "#endif\n");
  540. }
  541. if (!Cflag)
  542. {
  543. xdrfuncp = xdrfunc_head;
  544. while (xdrfuncp != NULL)
  545. {
  546. print_xdr_func_def (xdrfuncp->name,
  547. xdrfuncp->pointerp, 2);
  548. xdrfuncp = xdrfuncp->next;
  549. }
  550. }
  551. else
  552. {
  553. int i;
  554. for (i = 1; i < 3; ++i)
  555. {
  556. if (i == 1)
  557. fprintf (fout, "\n#if defined(__STDC__) || defined(__cplusplus)\n");
  558. else
  559. fprintf (fout, "\n#else /* K&R C */\n");
  560. xdrfuncp = xdrfunc_head;
  561. while (xdrfuncp != NULL)
  562. {
  563. print_xdr_func_def (xdrfuncp->name,
  564. xdrfuncp->pointerp, i);
  565. xdrfuncp = xdrfuncp->next;
  566. }
  567. }
  568. fprintf (fout, "\n#endif /* K&R C */\n");
  569. }
  570. }
  571. if (extend && tell == ftell (fout))
  572. {
  573. unlink (outfilename);
  574. }
  575. else if (tblflag)
  576. {
  577. fprintf (fout, "%s", rpcgen_table_dcl);
  578. }
  579. if (Cflag)
  580. {
  581. fprintf (fout, "\n#ifdef __cplusplus\n");
  582. fprintf (fout, "}\n");
  583. fprintf (fout, "#endif\n");
  584. }
  585. fprintf (fout, "\n#endif /* !_%s */\n", guard);
  586. free (guard);
  587. close_input ();
  588. close_output (outfilename);
  589. }
  590. /*
  591. * Compile into an RPC service
  592. */
  593. static void
  594. s_output (int argc, const char *argv[], const char *infile, const char *define,
  595. int extend, const char *outfile, int nomain, int netflag)
  596. {
  597. char *include;
  598. definition *def;
  599. int foundprogram = 0;
  600. const char *outfilename;
  601. open_input (infile, define);
  602. outfilename = extend ? extendfile (infile, outfile) : outfile;
  603. open_output (infile, outfilename);
  604. add_warning ();
  605. if (infile && (include = extendfile (infile, ".h")))
  606. {
  607. fprintf (fout, "#include \"%s\"\n", include);
  608. free (include);
  609. }
  610. else
  611. fprintf (fout, "#include <rpc/rpc.h>\n");
  612. fprintf (fout, "#include <stdio.h>\n");
  613. fprintf (fout, "#include <stdlib.h>\n");
  614. fprintf (fout, "#include <rpc/pmap_clnt.h>\n");
  615. if (Cflag)
  616. fprintf (fout, "#include <string.h>\n");
  617. if (strcmp (svcclosetime, "-1") == 0)
  618. indefinitewait = 1;
  619. else if (strcmp (svcclosetime, "0") == 0)
  620. exitnow = 1;
  621. else if (inetdflag || pmflag)
  622. {
  623. fprintf (fout, "#include <signal.h>\n");
  624. timerflag = 1;
  625. }
  626. if (!tirpcflag && inetdflag)
  627. fprintf (fout, "#include <sys/ioctl.h> /* ioctl, TIOCNOTTY */\n");
  628. if (Cflag && (inetdflag || pmflag))
  629. {
  630. fprintf (fout, "#include <sys/types.h> /* open */\n");
  631. fprintf (fout, "#include <sys/stat.h> /* open */\n");
  632. fprintf (fout, "#include <fcntl.h> /* open */\n");
  633. fprintf (fout, "#include <unistd.h> /* getdtablesize */\n");
  634. }
  635. if (tirpcflag && !(Cflag && (inetdflag || pmflag)))
  636. fprintf (fout, "#include <sys/types.h>\n");
  637. fprintf (fout, "#include <memory.h>\n");
  638. if (inetdflag || !tirpcflag)
  639. {
  640. fprintf (fout, "#include <sys/socket.h>\n");
  641. fprintf (fout, "#include <netinet/in.h>\n");
  642. }
  643. if ((netflag || pmflag) && tirpcflag && !nomain)
  644. {
  645. fprintf (fout, "#include <netconfig.h>\n");
  646. }
  647. if ( /*timerflag && */ tirpcflag)
  648. fprintf (fout, "#include <sys/resource.h> /* rlimit */\n");
  649. if (logflag || inetdflag || pmflag)
  650. {
  651. fprintf (fout, "#include <syslog.h>\n");
  652. }
  653. /* for ANSI-C */
  654. if (Cflag)
  655. fprintf (fout, "\n#ifndef SIG_PF\n#define SIG_PF void(*)(int)\n#endif\n");
  656. if (timerflag)
  657. fprintf (fout, "\n#define _RPCSVC_CLOSEDOWN %s\n", svcclosetime);
  658. while ((def = get_definition ()) != NULL)
  659. {
  660. foundprogram |= (def->def_kind == DEF_PROGRAM);
  661. }
  662. if (extend && !foundprogram)
  663. {
  664. unlink (outfilename);
  665. return;
  666. }
  667. write_most (infile, netflag, nomain);
  668. if (!nomain)
  669. {
  670. if (!do_registers (argc, argv))
  671. {
  672. if (outfilename)
  673. unlink (outfilename);
  674. usage (stderr, 1);
  675. }
  676. write_rest ();
  677. }
  678. close_input ();
  679. close_output (outfilename);
  680. }
  681. /*
  682. * generate client side stubs
  683. */
  684. static void
  685. l_output (const char *infile, const char *define, int extend,
  686. const char *outfile)
  687. {
  688. char *include;
  689. definition *def;
  690. int foundprogram = 0;
  691. const char *outfilename;
  692. open_input (infile, define);
  693. outfilename = extend ? extendfile (infile, outfile) : outfile;
  694. open_output (infile, outfilename);
  695. add_warning ();
  696. if (Cflag)
  697. fprintf (fout, "#include <memory.h> /* for memset */\n");
  698. if (infile && (include = extendfile (infile, ".h")))
  699. {
  700. fprintf (fout, "#include \"%s\"\n", include);
  701. free (include);
  702. }
  703. else
  704. fprintf (fout, "#include <rpc/rpc.h>\n");
  705. while ((def = get_definition ()) != NULL)
  706. {
  707. foundprogram |= (def->def_kind == DEF_PROGRAM);
  708. }
  709. if (extend && !foundprogram)
  710. {
  711. unlink (outfilename);
  712. return;
  713. }
  714. write_stubs ();
  715. close_input ();
  716. close_output (outfilename);
  717. }
  718. /*
  719. * generate the dispatch table
  720. */
  721. static void
  722. t_output (const char *infile, const char *define, int extend,
  723. const char *outfile)
  724. {
  725. definition *def;
  726. int foundprogram = 0;
  727. const char *outfilename;
  728. open_input (infile, define);
  729. outfilename = extend ? extendfile (infile, outfile) : outfile;
  730. open_output (infile, outfilename);
  731. add_warning ();
  732. while ((def = get_definition ()) != NULL)
  733. {
  734. foundprogram |= (def->def_kind == DEF_PROGRAM);
  735. }
  736. if (extend && !foundprogram)
  737. {
  738. unlink (outfilename);
  739. return;
  740. }
  741. write_tables ();
  742. close_input ();
  743. close_output (outfilename);
  744. }
  745. /* sample routine for the server template */
  746. static void
  747. svc_output (const char *infile, const char *define, int extend,
  748. const char *outfile)
  749. {
  750. definition *def;
  751. char *include;
  752. const char *outfilename;
  753. long tell;
  754. open_input (infile, define);
  755. outfilename = extend ? extendfile (infile, outfile) : outfile;
  756. checkfiles (infile, outfilename);
  757. /*check if outfile already exists.
  758. if so, print an error message and exit */
  759. open_output (infile, outfilename);
  760. add_sample_msg ();
  761. if (infile && (include = extendfile (infile, ".h")))
  762. {
  763. fprintf (fout, "#include \"%s\"\n", include);
  764. free (include);
  765. }
  766. else
  767. fprintf (fout, "#include <rpc/rpc.h>\n");
  768. tell = ftell (fout);
  769. while ((def = get_definition ()) != NULL)
  770. {
  771. write_sample_svc (def);
  772. }
  773. if (extend && tell == ftell (fout))
  774. {
  775. unlink (outfilename);
  776. }
  777. close_input ();
  778. close_output (outfilename);
  779. }
  780. /* sample main routine for client */
  781. static void
  782. clnt_output (const char *infile, const char *define, int extend,
  783. const char *outfile)
  784. {
  785. definition *def;
  786. char *include;
  787. const char *outfilename;
  788. long tell;
  789. int has_program = 0;
  790. open_input (infile, define);
  791. outfilename = extend ? extendfile (infile, outfile) : outfile;
  792. checkfiles (infile, outfilename);
  793. /*check if outfile already exists.
  794. if so, print an error message and exit */
  795. open_output (infile, outfilename);
  796. add_sample_msg ();
  797. if (infile && (include = extendfile (infile, ".h")))
  798. {
  799. fprintf (fout, "#include \"%s\"\n", include);
  800. free (include);
  801. }
  802. else
  803. fprintf (fout, "#include <rpc/rpc.h>\n");
  804. tell = ftell (fout);
  805. while ((def = get_definition ()) != NULL)
  806. {
  807. has_program += write_sample_clnt (def);
  808. }
  809. if (has_program)
  810. write_sample_clnt_main ();
  811. if (extend && tell == ftell (fout))
  812. {
  813. unlink (outfilename);
  814. }
  815. close_input ();
  816. close_output (outfilename);
  817. }
  818. static const char space[] = " ";
  819. static char *
  820. file_name (const char *file, const char *ext)
  821. {
  822. char *temp;
  823. temp = extendfile (file, ext);
  824. if (access (temp, F_OK) != -1)
  825. return (temp);
  826. free (temp);
  827. return (char *) space;
  828. }
  829. static void
  830. mkfile_output (struct commandline *cmd)
  831. {
  832. char *mkfilename;
  833. char *clientname, *clntname, *xdrname, *hdrname;
  834. char *servername, *svcname, *servprogname, *clntprogname;
  835. svcname = file_name (cmd->infile, "_svc.c");
  836. clntname = file_name (cmd->infile, "_clnt.c");
  837. xdrname = file_name (cmd->infile, "_xdr.c");
  838. hdrname = file_name (cmd->infile, ".h");
  839. if (allfiles)
  840. {
  841. servername = extendfile (cmd->infile, "_server.c");
  842. clientname = extendfile (cmd->infile, "_client.c");
  843. }
  844. else
  845. {
  846. servername = (char *) space;
  847. clientname = (char *) space;
  848. }
  849. servprogname = extendfile (cmd->infile, "_server");
  850. clntprogname = extendfile (cmd->infile, "_client");
  851. if (allfiles)
  852. {
  853. char *cp, *temp;
  854. mkfilename = alloc (strlen ("Makefile.") + strlen (cmd->infile) + 1);
  855. if (mkfilename == NULL)
  856. abort ();
  857. temp = strrchr (cmd->infile, '.');
  858. cp = stpcpy (mkfilename, "Makefile.");
  859. if (temp != NULL)
  860. *((char *) stpncpy (cp, cmd->infile, temp - cmd->infile)) = '\0';
  861. else
  862. stpcpy (cp, cmd->infile);
  863. }
  864. else
  865. mkfilename = (char *) cmd->outfile;
  866. checkfiles (NULL, mkfilename);
  867. open_output (NULL, mkfilename);
  868. fprintf (fout, "\n# This is a template Makefile generated by rpcgen\n");
  869. f_print (fout, "\n# Parameters\n\n");
  870. f_print (fout, "CLIENT = %s\nSERVER = %s\n\n", clntprogname, servprogname);
  871. f_print (fout, "SOURCES_CLNT.c = \nSOURCES_CLNT.h = \n");
  872. f_print (fout, "SOURCES_SVC.c = \nSOURCES_SVC.h = \n");
  873. f_print (fout, "SOURCES.x = %s\n\n", cmd->infile);
  874. f_print (fout, "TARGETS_SVC.c = %s %s %s \n",
  875. svcname, servername, xdrname);
  876. f_print (fout, "TARGETS_CLNT.c = %s %s %s \n",
  877. clntname, clientname, xdrname);
  878. f_print (fout, "TARGETS = %s %s %s %s %s %s\n\n",
  879. hdrname, xdrname, clntname,
  880. svcname, clientname, servername);
  881. f_print (fout, "OBJECTS_CLNT = $(SOURCES_CLNT.c:%%.c=%%.o) \
  882. $(TARGETS_CLNT.c:%%.c=%%.o)");
  883. f_print (fout, "\nOBJECTS_SVC = $(SOURCES_SVC.c:%%.c=%%.o) \
  884. $(TARGETS_SVC.c:%%.c=%%.o)");
  885. f_print (fout, "\n# Compiler flags \n");
  886. if (mtflag)
  887. fprintf (fout, "\nCPPFLAGS += -D_REENTRANT\nCFLAGS += -g \nLDLIBS \
  888. += -lnsl -lpthread \n ");
  889. else
  890. f_print (fout, "\nCFLAGS += -g \nLDLIBS += -lnsl\n");
  891. f_print (fout, "RPCGENFLAGS = \n");
  892. f_print (fout, "\n# Targets \n\n");
  893. f_print (fout, "all : $(CLIENT) $(SERVER)\n\n");
  894. f_print (fout, "$(TARGETS) : $(SOURCES.x) \n");
  895. f_print (fout, "\trpcgen $(RPCGENFLAGS) $(SOURCES.x)\n\n");
  896. f_print (fout, "$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) \
  897. $(TARGETS_CLNT.c) \n\n");
  898. f_print (fout, "$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) \
  899. $(TARGETS_SVC.c) \n\n");
  900. f_print (fout, "$(CLIENT) : $(OBJECTS_CLNT) \n");
  901. f_print (fout, "\t$(LINK.c) -o $(CLIENT) $(OBJECTS_CLNT) \
  902. $(LDLIBS) \n\n");
  903. f_print (fout, "$(SERVER) : $(OBJECTS_SVC) \n");
  904. f_print (fout, "\t$(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n ");
  905. f_print (fout, "clean:\n\t $(RM) core $(TARGETS) $(OBJECTS_CLNT) \
  906. $(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
  907. close_output (mkfilename);
  908. free (clntprogname);
  909. free (servprogname);
  910. if (servername != space)
  911. free (servername);
  912. if (clientname != space)
  913. free (clientname);
  914. if (mkfilename != (char *) cmd->outfile)
  915. free (mkfilename);
  916. if (svcname != space)
  917. free (svcname);
  918. if (clntname != space)
  919. free (clntname);
  920. if (xdrname != space)
  921. free (xdrname);
  922. if (hdrname != space)
  923. free (hdrname);
  924. }
  925. /*
  926. * Perform registrations for service output
  927. * Return 0 if failed; 1 otherwise.
  928. */
  929. static int
  930. do_registers (int argc, const char *argv[])
  931. {
  932. int i;
  933. if (inetdflag || !tirpcflag)
  934. {
  935. for (i = 1; i < argc; i++)
  936. {
  937. if (streq (argv[i], "-s"))
  938. {
  939. if (!check_nettype (argv[i + 1], valid_i_nettypes))
  940. return 0;
  941. write_inetd_register (argv[i + 1]);
  942. i++;
  943. }
  944. }
  945. }
  946. else
  947. {
  948. for (i = 1; i < argc; i++)
  949. if (streq (argv[i], "-s"))
  950. {
  951. if (!check_nettype (argv[i + 1], valid_ti_nettypes))
  952. return 0;
  953. write_nettype_register (argv[i + 1]);
  954. i++;
  955. }
  956. else if (streq (argv[i], "-n"))
  957. {
  958. write_netid_register (argv[i + 1]);
  959. i++;
  960. }
  961. }
  962. return 1;
  963. }
  964. /*
  965. * Add another argument to the arg list
  966. */
  967. static void
  968. addarg (const char *cp)
  969. {
  970. if (argcount >= ARGLISTLEN)
  971. {
  972. fprintf (stderr, _("rpcgen: too many defines\n"));
  973. crash ();
  974. /*NOTREACHED */
  975. }
  976. arglist[argcount++] = cp;
  977. }
  978. static void
  979. putarg (int whereto, const char *cp)
  980. {
  981. if (whereto >= ARGLISTLEN)
  982. {
  983. fprintf (stderr, _("rpcgen: arglist coding error\n"));
  984. crash ();
  985. /*NOTREACHED */
  986. }
  987. arglist[whereto] = cp;
  988. }
  989. /*
  990. * if input file is stdin and an output file is specified then complain
  991. * if the file already exists. Otherwise the file may get overwritten
  992. * If input file does not exist, exit with an error
  993. */
  994. static void
  995. checkfiles (const char *infile, const char *outfile)
  996. {
  997. struct stat64 buf;
  998. if (infile) /* infile ! = NULL */
  999. if (stat64 (infile, &buf) < 0)
  1000. {
  1001. perror (infile);
  1002. crash ();
  1003. }
  1004. if (outfile)
  1005. {
  1006. if (stat64 (outfile, &buf) < 0)
  1007. return; /* file does not exist */
  1008. else
  1009. {
  1010. fprintf (stderr,
  1011. /* TRANS: the file will not be removed; this is an
  1012. TRANS: informative message. */
  1013. _("file `%s' already exists and may be overwritten\n"),
  1014. outfile);
  1015. crash ();
  1016. }
  1017. }
  1018. }
  1019. /*
  1020. * Parse command line arguments
  1021. */
  1022. static int
  1023. parseargs (int argc, const char *argv[], struct commandline *cmd)
  1024. {
  1025. int i;
  1026. int j;
  1027. int c;
  1028. char flag[(1 << 8 * sizeof (char))];
  1029. int nflags;
  1030. cmdname = argv[0];
  1031. cmd->infile = cmd->outfile = NULL;
  1032. if (argc < 2)
  1033. {
  1034. return (0);
  1035. }
  1036. allfiles = 0;
  1037. flag['c'] = 0;
  1038. flag['h'] = 0;
  1039. flag['l'] = 0;
  1040. flag['m'] = 0;
  1041. flag['o'] = 0;
  1042. flag['s'] = 0;
  1043. flag['n'] = 0;
  1044. flag['t'] = 0;
  1045. flag['S'] = 0;
  1046. flag['C'] = 0;
  1047. flag['M'] = 0;
  1048. for (i = 1; i < argc; i++)
  1049. {
  1050. if (argv[i][0] != '-')
  1051. {
  1052. if (cmd->infile)
  1053. {
  1054. fprintf (stderr,
  1055. _("Cannot specify more than one input file!\n"));
  1056. return 0;
  1057. }
  1058. cmd->infile = argv[i];
  1059. }
  1060. else if (strcmp (argv[i], "--help") == 0)
  1061. usage (stdout, 0);
  1062. else if (strcmp (argv[i], "--version") == 0)
  1063. print_version ();
  1064. else
  1065. {
  1066. for (j = 1; argv[i][j] != 0; j++)
  1067. {
  1068. c = argv[i][j];
  1069. switch (c)
  1070. {
  1071. case 'a':
  1072. allfiles = 1;
  1073. break;
  1074. case 'c':
  1075. case 'h':
  1076. case 'l':
  1077. case 'm':
  1078. case 't':
  1079. if (flag[c])
  1080. return 0;
  1081. flag[c] = 1;
  1082. break;
  1083. case 'S':
  1084. /* sample flag: Ss or Sc.
  1085. Ss means set flag['S'];
  1086. Sc means set flag['C'];
  1087. Sm means set flag['M']; */
  1088. c = argv[i][++j]; /* get next char */
  1089. if (c == 's')
  1090. c = 'S';
  1091. else if (c == 'c')
  1092. c = 'C';
  1093. else if (c == 'm')
  1094. c = 'M';
  1095. else
  1096. return 0;
  1097. if (flag[c])
  1098. return 0;
  1099. flag[c] = 1;
  1100. break;
  1101. case 'C': /* ANSI C syntax */
  1102. Cflag = 1;
  1103. break;
  1104. case 'k': /* K&R C syntax */
  1105. Cflag = 0;
  1106. break;
  1107. case 'b': /* turn TIRPC flag off for
  1108. generating backward compatible
  1109. */
  1110. tirpcflag = 0;
  1111. break;
  1112. case '5': /* turn TIRPC flag on for
  1113. generating SysVr4 compatible
  1114. */
  1115. tirpcflag = 1;
  1116. break;
  1117. case 'I':
  1118. inetdflag = 1;
  1119. break;
  1120. case 'N':
  1121. newstyle = 1;
  1122. break;
  1123. case 'L':
  1124. logflag = 1;
  1125. break;
  1126. case 'K':
  1127. if (++i == argc)
  1128. {
  1129. return (0);
  1130. }
  1131. svcclosetime = argv[i];
  1132. goto nextarg;
  1133. case 'T':
  1134. tblflag = 1;
  1135. break;
  1136. case 'M':
  1137. mtflag = 1;
  1138. break;
  1139. case 'i':
  1140. if (++i == argc)
  1141. {
  1142. return (0);
  1143. }
  1144. inlineflag = atoi (argv[i]);
  1145. goto nextarg;
  1146. case 'n':
  1147. case 'o':
  1148. case 's':
  1149. if (argv[i][j - 1] != '-' ||
  1150. argv[i][j + 1] != 0)
  1151. {
  1152. return (0);
  1153. }
  1154. flag[c] = 1;
  1155. if (++i == argc)
  1156. {
  1157. return (0);
  1158. }
  1159. if (c == 's')
  1160. {
  1161. if (!streq (argv[i], "udp") &&
  1162. !streq (argv[i], "tcp"))
  1163. return 0;
  1164. }
  1165. else if (c == 'o')
  1166. {
  1167. if (cmd->outfile)
  1168. return 0;
  1169. cmd->outfile = argv[i];
  1170. }
  1171. goto nextarg;
  1172. case 'D':
  1173. if (argv[i][j - 1] != '-')
  1174. return 0;
  1175. addarg (argv[i]);
  1176. goto nextarg;
  1177. case 'Y':
  1178. if (++i == argc)
  1179. return 0;
  1180. {
  1181. size_t len = strlen (argv[i]);
  1182. pathbuf = malloc (len + 5);
  1183. if (pathbuf == NULL)
  1184. {
  1185. perror (cmdname);
  1186. crash ();
  1187. }
  1188. stpcpy (stpcpy (pathbuf,
  1189. argv[i]),
  1190. "/cpp");
  1191. CPP = pathbuf;
  1192. cppDefined = 1;
  1193. goto nextarg;
  1194. }
  1195. default:
  1196. return 0;
  1197. }
  1198. }
  1199. nextarg:
  1200. ;
  1201. }
  1202. }
  1203. cmd->cflag = flag['c'];
  1204. cmd->hflag = flag['h'];
  1205. cmd->lflag = flag['l'];
  1206. cmd->mflag = flag['m'];
  1207. cmd->nflag = flag['n'];
  1208. cmd->sflag = flag['s'];
  1209. cmd->tflag = flag['t'];
  1210. cmd->Ssflag = flag['S'];
  1211. cmd->Scflag = flag['C'];
  1212. cmd->makefileflag = flag['M'];
  1213. if (tirpcflag)
  1214. {
  1215. pmflag = inetdflag ? 0 : 1; /* pmflag or inetdflag is always TRUE */
  1216. if ((inetdflag && cmd->nflag))
  1217. { /* netid not allowed with inetdflag */
  1218. fprintf (stderr, _("Cannot use netid flag with inetd flag!\n"));
  1219. return 0;
  1220. }
  1221. }
  1222. else
  1223. { /* 4.1 mode */
  1224. pmflag = 0; /* set pmflag only in tirpcmode */
  1225. if (cmd->nflag)
  1226. { /* netid needs TIRPC */
  1227. f_print (stderr, _("Cannot use netid flag without TIRPC!\n"));
  1228. return (0);
  1229. }
  1230. }
  1231. if (newstyle && (tblflag || cmd->tflag))
  1232. {
  1233. f_print (stderr, _("Cannot use table flags with newstyle!\n"));
  1234. return (0);
  1235. }
  1236. /* check no conflicts with file generation flags */
  1237. nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag +
  1238. cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag + cmd->Scflag;
  1239. if (nflags == 0)
  1240. {
  1241. if (cmd->outfile != NULL || cmd->infile == NULL)
  1242. {
  1243. return (0);
  1244. }
  1245. }
  1246. else if (cmd->infile == NULL &&
  1247. (cmd->Ssflag || cmd->Scflag || cmd->makefileflag))
  1248. {
  1249. fprintf (stderr,
  1250. _("\"infile\" is required for template generation flags.\n"));
  1251. return 0;
  1252. }
  1253. if (nflags > 1)
  1254. {
  1255. fprintf (stderr, _("Cannot have more than one file generation flag!\n"));
  1256. return 0;
  1257. }
  1258. return 1;
  1259. }
  1260. static void
  1261. usage (FILE *stream, int status)
  1262. {
  1263. fprintf (stream, _("usage: %s infile\n"), cmdname);
  1264. fprintf (stream, _("\t%s [-abkCLNTM][-Dname[=value]] [-i size] \
  1265. [-I [-K seconds]] [-Y path] infile\n"), cmdname);
  1266. fprintf (stream, _("\t%s [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm] \
  1267. [-o outfile] [infile]\n"), cmdname);
  1268. fprintf (stream, _("\t%s [-s nettype]* [-o outfile] [infile]\n"), cmdname);
  1269. fprintf (stream, _("\t%s [-n netid]* [-o outfile] [infile]\n"), cmdname);
  1270. options_usage (stream, status);
  1271. exit (status);
  1272. }
  1273. static void
  1274. options_usage (FILE *stream, int status)
  1275. {
  1276. f_print (stream, _("options:\n"));
  1277. f_print (stream, _("-a\t\tgenerate all files, including samples\n"));
  1278. f_print (stream, _("-b\t\tbackward compatibility mode (generates code for SunOS 4.1)\n"));
  1279. f_print (stream, _("-c\t\tgenerate XDR routines\n"));
  1280. f_print (stream, _("-C\t\tANSI C mode\n"));
  1281. f_print (stream, _("-Dname[=value]\tdefine a symbol (same as #define)\n"));
  1282. f_print (stream, _("-h\t\tgenerate header file\n"));
  1283. f_print (stream, _("-i size\t\tsize at which to start generating inline code\n"));
  1284. f_print (stream, _("-I\t\tgenerate code for inetd support in server (for SunOS 4.1)\n"));
  1285. f_print (stream, _("-K seconds\tserver exits after K seconds of inactivity\n"));
  1286. f_print (stream, _("-l\t\tgenerate client side stubs\n"));
  1287. f_print (stream, _("-L\t\tserver errors will be printed to syslog\n"));
  1288. f_print (stream, _("-m\t\tgenerate server side stubs\n"));
  1289. f_print (stream, _("-M\t\tgenerate MT-safe code\n"));
  1290. f_print (stream, _("-n netid\tgenerate server code that supports named netid\n"));
  1291. f_print (stream, _("-N\t\tsupports multiple arguments and call-by-value\n"));
  1292. f_print (stream, _("-o outfile\tname of the output file\n"));
  1293. f_print (stream, _("-s nettype\tgenerate server code that supports named nettype\n"));
  1294. f_print (stream, _("-Sc\t\tgenerate sample client code that uses remote procedures\n"));
  1295. f_print (stream, _("-Ss\t\tgenerate sample server code that defines remote procedures\n"));
  1296. f_print (stream, _("-Sm \t\tgenerate makefile template \n"));
  1297. f_print (stream, _("-t\t\tgenerate RPC dispatch table\n"));
  1298. f_print (stream, _("-T\t\tgenerate code to support RPC dispatch tables\n"));
  1299. f_print (stream, _("-Y path\t\tdirectory name to find C preprocessor (cpp)\n"));
  1300. f_print (stream, _("-5\t\tSysVr4 compatibility mode\n"));
  1301. f_print (stream, _("--help\t\tgive this help list\n"));
  1302. f_print (stream, _("--version\tprint program version\n"));
  1303. f_print (stream, _("\n\
  1304. For bug reporting instructions, please see:\n\
  1305. %s.\n"), REPORT_BUGS_TO);
  1306. exit (status);
  1307. }
  1308. static void
  1309. print_version (void)
  1310. {
  1311. printf ("rpcgen %s%s\n", PKGVERSION, VERSION);
  1312. exit (0);
  1313. }