3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
28 /*
29 * University Copyright- Copyright (c) 1982, 1986, 1988
30 * The Regents of the University of California
31 * All Rights Reserved
32 *
33 * University Acknowledgment- Portions of this document are derived from
34 * software developed by the University of California, Berkeley, and its
35 * contributors.
36 */
37
38 /*
39 * rpc_main.c, Top level of the RPC protocol compiler.
40 */
41
42 #include <stdio.h>
119 int inetdflag; /* Support for inetd is now the default */
120 int pmflag; /* Support for port monitors */
121 int logflag; /* Use syslog instead of fprintf for errors */
122 int tblflag; /* Support for dispatch table file */
123 int mtflag = 0; /* Support for MT */
124 int mtauto = 0; /* Enable automatic mode */
125 int rflag = 1; /* Eliminate tail recursion from structures */
126 #define INLINE 5
127 /* length at which to start doing an inline */
128
129 int inlinelen = INLINE;
130 /*
131 * Length at which to start doing an inline. INLINE = default
132 * if 0, no xdr_inline code
133 */
134
135 int indefinitewait; /* If started by port monitors, hang till it wants */
136 int exitnow; /* If started by port monitors, exit after the call */
137 int timerflag; /* TRUE if !indefinite && !exitnow */
138 int newstyle; /* newstyle of passing arguments (by value) */
139 int Cflag = 0; /* ANSI C syntax */
140 int CCflag = 0; /* C++ files */
141 static int allfiles; /* generate all files */
142 int tirpcflag = 1; /* generating code for tirpc, by default */
143 xdrfunc *xdrfunc_head = NULL; /* xdr function list */
144 xdrfunc *xdrfunc_tail = NULL; /* xdr function list */
145 pid_t childpid;
146
147
148 int
149 main(int argc, char *argv[])
150 {
151 struct commandline cmd;
152
153 (void) memset(&cmd, 0, sizeof (struct commandline));
154 clear_args();
155 if (!parseargs(argc, argv, &cmd))
156 usage();
157 /*
158 * Only the client and server side stubs are likely to be customized,
159 * so in that case only, check if the outfile exists, and if so,
498 if (!isalpha(guard[0]))
499 guard[0] = '_';
500
501 return (guard);
502 }
503
504 /*
505 * Compile into an XDR header file
506 */
507
508
509 static void
510 h_output(char *infile, char *define, int extend, char *outfile)
511 {
512 definition *def;
513 char *outfilename;
514 long tell;
515 char *guard;
516 list *l;
517 xdrfunc *xdrfuncp;
518 int i;
519
520 open_input(infile, define);
521 outfilename = extend ? extendfile(infile, outfile) : outfile;
522 open_output(infile, outfilename);
523 add_warning();
524 if (outfilename || infile)
525 guard = generate_guard(outfilename ? outfilename: infile);
526 else
527 guard = "STDIN_";
528
529 f_print(fout, "#ifndef _%s\n#define _%s\n\n", guard, guard);
530
531 f_print(fout, "#include <rpc/rpc.h>\n");
532
533 if (mtflag) {
534 f_print(fout, "#ifndef _KERNEL\n");
535 f_print(fout, "#include <synch.h>\n");
536 f_print(fout, "#include <thread.h>\n");
537 f_print(fout, "#endif /* !_KERNEL */\n");
538 };
539
540 /* put the C++ support */
541 if (Cflag && !CCflag) {
542 f_print(fout, "\n#ifdef __cplusplus\n");
543 f_print(fout, "extern \"C\" {\n");
544 f_print(fout, "#endif\n\n");
545 }
546
547 /* put in a typedef for quadprecision. Only with Cflag */
548
549 /*
550 * declaration of struct rpcgen_table must go before
551 * the definition of arrays like *_1_table[]
552 */
553 if (tblflag) {
554 f_print(fout, rpcgen_table_dcl1);
555 if (tirpcflag)
556 f_print(fout, rpcgen_table_proc);
557 else
558 f_print(fout, rpcgen_table_proc_b);
559 f_print(fout, rpcgen_table_dcl2);
560 }
561
562 tell = ftell(fout);
563
564 /* print data definitions */
565 while (def = get_definition())
566 print_datadef(def);
567
568 /*
569 * print function declarations.
570 * Do this after data definitions because they might be used as
571 * arguments for functions
572 */
573 for (l = defined; l != NULL; l = l->next)
574 print_funcdef(l->val);
575 /* Now print all xdr func declarations */
576 if (xdrfunc_head != NULL) {
577 f_print(fout, "\n/* the xdr functions */\n");
578
579 if (CCflag) {
580 f_print(fout, "\n#ifdef __cplusplus\n");
581 f_print(fout, "extern \"C\" {\n");
582 f_print(fout, "#endif\n");
583 }
584
585 if (!Cflag) {
586 xdrfuncp = xdrfunc_head;
587 while (xdrfuncp != NULL) {
588 print_xdr_func_def(xdrfuncp->name,
589 xdrfuncp->pointerp, 2);
590 xdrfuncp = xdrfuncp->next;
591 }
592 } else {
593 for (i = 1; i < 3; i++) {
594 if (i == 1)
595 f_print(fout,
596 "\n#if defined(__STDC__) || defined(__cplusplus)\n");
597 else
598 f_print(fout, "\n#else /* K&R C */\n");
599
600 xdrfuncp = xdrfunc_head;
601 while (xdrfuncp != NULL) {
602 print_xdr_func_def(xdrfuncp->name,
603 xdrfuncp->pointerp, i);
604 xdrfuncp = xdrfuncp->next;
605 }
606 }
607 f_print(fout, "\n#endif /* K&R C */\n");
608 }
609 }
610
611 if (extend && tell == ftell(fout)) {
612 (void) unlink(outfilename);
613 }
614
615 if (Cflag) {
616 f_print(fout, "\n#ifdef __cplusplus\n");
617 f_print(fout, "}\n");
618 f_print(fout, "#endif\n");
619 }
620
621 f_print(fout, "\n#endif /* !_%s */\n", guard);
622 }
623
624 /*
625 * Compile into an RPC service
626 */
627 static void
628 s_output(int argc, char *argv[], char *infile, char *define, int extend,
629 char *outfile, int nomain, int netflag)
630 {
631 char *include;
632 definition *def;
633 int foundprogram = 0;
634 char *outfilename;
635
636 open_input(infile, define);
637 outfilename = extend ? extendfile(infile, outfile) : outfile;
638 open_output(infile, outfilename);
639 add_warning();
640 if (infile && (include = extendfile(infile, ".h"))) {
641 f_print(fout, "#include \"%s\"\n", include);
642 free(include);
643 } else
644 f_print(fout, "#include <rpc/rpc.h>\n");
645
646 f_print(fout, "#include <stdio.h>\n");
647 f_print(fout, "#include <stdlib.h> /* getenv, exit */\n");
648 f_print(fout, "#include <signal.h>\n");
649
650 if (Cflag) {
651 f_print(fout,
652 "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n");
653 f_print(fout, "#include <string.h> /* strcmp */\n");
654 }
655 if (strcmp(svcclosetime, "-1") == 0)
656 indefinitewait = 1;
657 else if (strcmp(svcclosetime, "0") == 0)
658 exitnow = 1;
659 else if (inetdflag || pmflag)
660 timerflag = 1;
661
662 if (!tirpcflag && inetdflag)
663 f_print(fout, "#include <sys/termios.h> /* TIOCNOTTY */\n");
664 if (Cflag && (inetdflag || pmflag))
665 if (tirpcflag)
666 f_print(fout, "#include <unistd.h> /* setsid */\n");
667 if (tirpcflag)
668 f_print(fout, "#include <sys/types.h>\n");
669
670 f_print(fout, "#include <memory.h>\n");
671 f_print(fout, "#include <stropts.h>\n");
672 if (inetdflag || !tirpcflag) {
673 f_print(fout, "#include <sys/socket.h>\n");
674 f_print(fout, "#include <netinet/in.h>\n");
675 f_print(fout, "#include <rpc/svc_soc.h>\n");
676 }
677
678 if ((netflag || pmflag) && tirpcflag && !nomain)
679 f_print(fout, "#include <netconfig.h>\n");
680 if (tirpcflag)
681 f_print(fout, "#include <sys/resource.h> /* rlimit */\n");
682 if (logflag || inetdflag || pmflag)
683 f_print(fout, "#include <syslog.h>\n");
684
685 /* for ANSI-C */
686 if (Cflag)
687 f_print(fout,
688 "\n#ifndef SIG_PF\n#define SIG_PF void(*)\
689 (int)\n#endif\n");
690
691 f_print(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n");
692 if (timerflag)
693 f_print(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n",
694 svcclosetime);
695 while (def = get_definition())
696 foundprogram |= (def->def_kind == DEF_PROGRAM);
697 if (extend && !foundprogram) {
698 (void) unlink(outfilename);
699 return;
700 }
701 write_most(infile, netflag, nomain);
702 if (!nomain) {
703 if (!do_registers(argc, argv)) {
704 if (outfilename)
705 (void) unlink(outfilename);
706 usage();
707 }
708 write_rest();
709 }
710 }
711
712 /*
713 * generate client side stubs
714 */
715 static void
716 l_output(char *infile, char *define, int extend, char *outfile)
717 {
718 char *include;
719 definition *def;
720 int foundprogram = 0;
721 char *outfilename;
722
723 open_input(infile, define);
724 outfilename = extend ? extendfile(infile, outfile) : outfile;
725 open_output(infile, outfilename);
726 add_warning();
727 if (Cflag)
728 f_print(fout, "#include <memory.h> /* for memset */\n");
729 if (infile && (include = extendfile(infile, ".h"))) {
730 f_print(fout, "#include \"%s\"\n", include);
731 free(include);
732 } else
733 f_print(fout, "#include <rpc/rpc.h>\n");
734
735 f_print(fout, "#ifndef _KERNEL\n");
736 f_print(fout, "#include <stdio.h>\n");
737 f_print(fout, "#include <stdlib.h> /* getenv, exit */\n");
738 f_print(fout, "#endif /* !_KERNEL */\n");
739
740 while (def = get_definition())
741 foundprogram |= (def->def_kind == DEF_PROGRAM);
742 if (extend && !foundprogram) {
743 (void) unlink(outfilename);
744 return;
745 }
746 write_stubs();
747 }
1085 /*
1086 * sample flag: Ss or Sc.
1087 * Ss means set flag['S'];
1088 * Sc means set flag['C'];
1089 * Sm means set flag['M'];
1090 */
1091 ch = argv[i][++j]; /* get next char */
1092 if (ch == 's')
1093 ch = 'S';
1094 else if (ch == 'c')
1095 ch = 'C';
1096 else if (ch == 'm')
1097 ch = 'M';
1098 else
1099 return (0);
1100
1101 if (flag[ch])
1102 return (0);
1103 flag[ch] = 1;
1104 break;
1105 case 'C': /* ANSI C syntax */
1106 Cflag = 1;
1107 ch = argv[i][j+1]; /* get next char */
1108
1109 if (ch != 'C')
1110 break;
1111 CCflag = 1;
1112 break;
1113 case 'b':
1114 /*
1115 * Turn TIRPC flag off for
1116 * generating backward compatible
1117 * code
1118 */
1119 tirpcflag = 0;
1120 break;
1121
1122 case 'I':
1123 inetdflag = 1;
1124 break;
1125 case 'N':
1126 newstyle = 1;
1127 break;
1128 case 'L':
1129 logflag = 1;
1130 break;
|
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24 *
25 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
27 */
28 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
30 /*
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
34 *
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
38 */
39
40 /*
41 * rpc_main.c, Top level of the RPC protocol compiler.
42 */
43
44 #include <stdio.h>
121 int inetdflag; /* Support for inetd is now the default */
122 int pmflag; /* Support for port monitors */
123 int logflag; /* Use syslog instead of fprintf for errors */
124 int tblflag; /* Support for dispatch table file */
125 int mtflag = 0; /* Support for MT */
126 int mtauto = 0; /* Enable automatic mode */
127 int rflag = 1; /* Eliminate tail recursion from structures */
128 #define INLINE 5
129 /* length at which to start doing an inline */
130
131 int inlinelen = INLINE;
132 /*
133 * Length at which to start doing an inline. INLINE = default
134 * if 0, no xdr_inline code
135 */
136
137 int indefinitewait; /* If started by port monitors, hang till it wants */
138 int exitnow; /* If started by port monitors, exit after the call */
139 int timerflag; /* TRUE if !indefinite && !exitnow */
140 int newstyle; /* newstyle of passing arguments (by value) */
141 int CCflag = 0; /* C++ files */
142 static int allfiles; /* generate all files */
143 int tirpcflag = 1; /* generating code for tirpc, by default */
144 xdrfunc *xdrfunc_head = NULL; /* xdr function list */
145 xdrfunc *xdrfunc_tail = NULL; /* xdr function list */
146 pid_t childpid;
147
148
149 int
150 main(int argc, char *argv[])
151 {
152 struct commandline cmd;
153
154 (void) memset(&cmd, 0, sizeof (struct commandline));
155 clear_args();
156 if (!parseargs(argc, argv, &cmd))
157 usage();
158 /*
159 * Only the client and server side stubs are likely to be customized,
160 * so in that case only, check if the outfile exists, and if so,
499 if (!isalpha(guard[0]))
500 guard[0] = '_';
501
502 return (guard);
503 }
504
505 /*
506 * Compile into an XDR header file
507 */
508
509
510 static void
511 h_output(char *infile, char *define, int extend, char *outfile)
512 {
513 definition *def;
514 char *outfilename;
515 long tell;
516 char *guard;
517 list *l;
518 xdrfunc *xdrfuncp;
519
520 open_input(infile, define);
521 outfilename = extend ? extendfile(infile, outfile) : outfile;
522 open_output(infile, outfilename);
523 add_warning();
524 if (outfilename || infile)
525 guard = generate_guard(outfilename ? outfilename: infile);
526 else
527 guard = "STDIN_";
528
529 f_print(fout, "#ifndef _%s\n#define _%s\n\n", guard, guard);
530
531 f_print(fout, "#include <rpc/rpc.h>\n");
532
533 if (mtflag) {
534 f_print(fout, "#ifndef _KERNEL\n");
535 f_print(fout, "#include <synch.h>\n");
536 f_print(fout, "#include <thread.h>\n");
537 f_print(fout, "#endif /* !_KERNEL */\n");
538 };
539
540 /* put the C++ support */
541 if (!CCflag) {
542 f_print(fout, "\n#ifdef __cplusplus\n");
543 f_print(fout, "extern \"C\" {\n");
544 f_print(fout, "#endif\n\n");
545 }
546
547 /* put in a typedef for quadprecision. */
548
549 /*
550 * declaration of struct rpcgen_table must go before
551 * the definition of arrays like *_1_table[]
552 */
553 if (tblflag) {
554 f_print(fout, rpcgen_table_dcl1);
555 if (tirpcflag)
556 f_print(fout, rpcgen_table_proc);
557 else
558 f_print(fout, rpcgen_table_proc_b);
559 f_print(fout, rpcgen_table_dcl2);
560 }
561
562 tell = ftell(fout);
563
564 /* print data definitions */
565 while (def = get_definition())
566 print_datadef(def);
567
568 /*
569 * print function declarations.
570 * Do this after data definitions because they might be used as
571 * arguments for functions
572 */
573 for (l = defined; l != NULL; l = l->next)
574 print_funcdef(l->val);
575 /* Now print all xdr func declarations */
576 if (xdrfunc_head != NULL) {
577 f_print(fout, "\n/* the xdr functions */\n");
578
579 if (CCflag) {
580 f_print(fout, "\n#ifdef __cplusplus\n");
581 f_print(fout, "extern \"C\" {\n");
582 f_print(fout, "#endif\n");
583 }
584
585 f_print(fout, "\n");
586
587 xdrfuncp = xdrfunc_head;
588 while (xdrfuncp != NULL) {
589 print_xdr_func_def(xdrfuncp->name, xdrfuncp->pointerp);
590 xdrfuncp = xdrfuncp->next;
591 }
592 f_print(fout, "\n");
593 }
594
595 if (extend && tell == ftell(fout)) {
596 (void) unlink(outfilename);
597 }
598
599 f_print(fout, "\n#ifdef __cplusplus\n");
600 f_print(fout, "}\n");
601 f_print(fout, "#endif\n");
602
603 f_print(fout, "\n#endif /* !_%s */\n", guard);
604 }
605
606 /*
607 * Compile into an RPC service
608 */
609 static void
610 s_output(int argc, char *argv[], char *infile, char *define, int extend,
611 char *outfile, int nomain, int netflag)
612 {
613 char *include;
614 definition *def;
615 int foundprogram = 0;
616 char *outfilename;
617
618 open_input(infile, define);
619 outfilename = extend ? extendfile(infile, outfile) : outfile;
620 open_output(infile, outfilename);
621 add_warning();
622 if (infile && (include = extendfile(infile, ".h"))) {
623 f_print(fout, "#include \"%s\"\n", include);
624 free(include);
625 } else
626 f_print(fout, "#include <rpc/rpc.h>\n");
627
628 f_print(fout, "#include <stdio.h>\n");
629 f_print(fout, "#include <stdlib.h> /* getenv, exit */\n");
630 f_print(fout, "#include <signal.h>\n");
631
632 f_print(fout,
633 "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n");
634 f_print(fout, "#include <string.h> /* strcmp */\n");
635
636 if (strcmp(svcclosetime, "-1") == 0)
637 indefinitewait = 1;
638 else if (strcmp(svcclosetime, "0") == 0)
639 exitnow = 1;
640 else if (inetdflag || pmflag)
641 timerflag = 1;
642
643 if (!tirpcflag && inetdflag)
644 f_print(fout, "#include <sys/termios.h> /* TIOCNOTTY */\n");
645 if (inetdflag || pmflag)
646 if (tirpcflag)
647 f_print(fout, "#include <unistd.h> /* setsid */\n");
648 if (tirpcflag)
649 f_print(fout, "#include <sys/types.h>\n");
650
651 f_print(fout, "#include <stropts.h>\n");
652 if (inetdflag || !tirpcflag) {
653 f_print(fout, "#include <sys/socket.h>\n");
654 f_print(fout, "#include <netinet/in.h>\n");
655 f_print(fout, "#include <rpc/svc_soc.h>\n");
656 }
657
658 if ((netflag || pmflag) && tirpcflag && !nomain)
659 f_print(fout, "#include <netconfig.h>\n");
660 if (tirpcflag)
661 f_print(fout, "#include <sys/resource.h> /* rlimit */\n");
662 if (logflag || inetdflag || pmflag)
663 f_print(fout, "#include <syslog.h>\n");
664
665 /* for ANSI-C */
666 f_print(fout, "\n#ifndef SIG_PF\n"
667 "#define SIG_PF void(*)(int)\n#endif\n");
668
669 f_print(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n");
670 if (timerflag)
671 f_print(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n",
672 svcclosetime);
673 while (def = get_definition())
674 foundprogram |= (def->def_kind == DEF_PROGRAM);
675 if (extend && !foundprogram) {
676 (void) unlink(outfilename);
677 return;
678 }
679 write_most(infile, netflag, nomain);
680 if (!nomain) {
681 if (!do_registers(argc, argv)) {
682 if (outfilename)
683 (void) unlink(outfilename);
684 usage();
685 }
686 write_rest();
687 }
688 }
689
690 /*
691 * generate client side stubs
692 */
693 static void
694 l_output(char *infile, char *define, int extend, char *outfile)
695 {
696 char *include;
697 definition *def;
698 int foundprogram = 0;
699 char *outfilename;
700
701 open_input(infile, define);
702 outfilename = extend ? extendfile(infile, outfile) : outfile;
703 open_output(infile, outfilename);
704 add_warning();
705 f_print(fout, "#include <memory.h> /* for memset */\n");
706 if (infile && (include = extendfile(infile, ".h"))) {
707 f_print(fout, "#include \"%s\"\n", include);
708 free(include);
709 } else
710 f_print(fout, "#include <rpc/rpc.h>\n");
711
712 f_print(fout, "#ifndef _KERNEL\n");
713 f_print(fout, "#include <stdio.h>\n");
714 f_print(fout, "#include <stdlib.h> /* getenv, exit */\n");
715 f_print(fout, "#endif /* !_KERNEL */\n");
716
717 while (def = get_definition())
718 foundprogram |= (def->def_kind == DEF_PROGRAM);
719 if (extend && !foundprogram) {
720 (void) unlink(outfilename);
721 return;
722 }
723 write_stubs();
724 }
1062 /*
1063 * sample flag: Ss or Sc.
1064 * Ss means set flag['S'];
1065 * Sc means set flag['C'];
1066 * Sm means set flag['M'];
1067 */
1068 ch = argv[i][++j]; /* get next char */
1069 if (ch == 's')
1070 ch = 'S';
1071 else if (ch == 'c')
1072 ch = 'C';
1073 else if (ch == 'm')
1074 ch = 'M';
1075 else
1076 return (0);
1077
1078 if (flag[ch])
1079 return (0);
1080 flag[ch] = 1;
1081 break;
1082 case 'C': /* ANSI C syntax (default) */
1083 ch = argv[i][j+1]; /* get next char */
1084
1085 if (ch != 'C')
1086 break;
1087 /* Undocumented C++ mode */
1088 CCflag = 1;
1089 break;
1090 case 'b':
1091 /*
1092 * Turn TIRPC flag off for
1093 * generating backward compatible
1094 * code
1095 */
1096 tirpcflag = 0;
1097 break;
1098
1099 case 'I':
1100 inetdflag = 1;
1101 break;
1102 case 'N':
1103 newstyle = 1;
1104 break;
1105 case 'L':
1106 logflag = 1;
1107 break;
|