├── .upstream_base_commits ├── asa ├── asa.1 ├── asa.c ├── asa.plist.part └── tests │ └── asa_test.sh ├── ctags ├── C.c ├── ctags.1 ├── ctags.c ├── ctags.h ├── ctags.plist ├── fortran.c ├── lisp.c ├── print.c ├── test │ └── ctags.test ├── tree.c └── yacc.c ├── developer_cmds.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── indent ├── README ├── args.c ├── indent.1 ├── indent.c ├── indent.h ├── indent.plist.part ├── indent_codes.h ├── indent_globs.h ├── io.c ├── lexi.c ├── parse.c ├── pr_comment.c └── tests │ ├── binary.0 │ ├── binary.0.stdout │ ├── comments.0 │ ├── comments.0.pro │ ├── comments.0.stdout │ ├── cs.0 │ ├── cs.0.pro │ ├── cs.0.stdout │ ├── declarations.0 │ ├── declarations.0.stdout │ ├── elsecomment.0 │ ├── elsecomment.0.pro │ ├── elsecomment.0.stdout │ ├── f_decls.0 │ ├── f_decls.0.stdout │ ├── float.0 │ ├── float.0.stdout │ ├── functional_test.sh │ ├── label.0 │ ├── label.0.pro │ ├── label.0.stdout │ ├── list_head.0 │ ├── list_head.0.stdout │ ├── ncs.0 │ ├── ncs.0.pro │ ├── ncs.0.stdout │ ├── offsetof.0 │ ├── offsetof.0.stdout │ ├── parens.0 │ ├── parens.0.pro │ ├── parens.0.stdout │ ├── pcs.0 │ ├── pcs.0.pro │ ├── pcs.0.stdout │ ├── ps.0 │ ├── ps.0.pro │ ├── ps.0.stdout │ ├── struct.0 │ ├── struct.0.stdout │ ├── surplusbad.0 │ ├── surplusbad.0.pro │ ├── surplusbad.0.stdout │ ├── types_from_file.0 │ ├── types_from_file.0.list │ ├── types_from_file.0.pro │ ├── types_from_file.0.stdout │ ├── wchar.0 │ └── wchar.0.stdout ├── lorder ├── lorder.1 └── lorder.sh ├── rpcgen ├── rpc_clntout.c ├── rpc_cout.c ├── rpc_hout.c ├── rpc_main.c ├── rpc_parse.c ├── rpc_parse.h ├── rpc_sample.c ├── rpc_scan.c ├── rpc_scan.h ├── rpc_svcout.c ├── rpc_tblout.c ├── rpc_util.c ├── rpc_util.h └── rpcgen.1 ├── tests └── developer_cmds.plist.in ├── unifdef ├── tests │ └── unifdef_test.sh ├── tree.h ├── unifdef.1 ├── unifdef.c ├── unifdef.h ├── unifdef.plist.part ├── unifdefall.sh └── version.h └── xcodescripts ├── install-lorder.sh ├── install-opensource.sh ├── install-test-files.sh └── install-unifdefall.sh /.upstream_base_commits: -------------------------------------------------------------------------------- 1 | #freebsd = https://git.freebsd.org/src.git 2 | 3 | asa/asa.1 freebsd usr.bin/asa/asa.1 fa9896e082a1046ff4fbc75fcba4d18d1f2efc19 4 | asa/asa.c freebsd usr.bin/asa/asa.c c2356a440db91c106867d45c94b3d6d7bc0e50f0 5 | asa/tests/asa_test.sh freebsd usr.bin/asa/tests/asa_test.sh c2356a440db91c106867d45c94b3d6d7bc0e50f0 6 | 7 | ctags/C.c freebsd usr.bin/ctags/C.c 7ba6119e22b54c2104b1948f0e8a4157d4112958 8 | ctags/ctags.1 freebsd usr.bin/ctags/ctags.1 430d064ba5b0cb2e91a26af34c15df48d290e417 9 | ctags/ctags.c freebsd usr.bin/ctags/ctags.c 430d064ba5b0cb2e91a26af34c15df48d290e417 10 | ctags/ctags.h freebsd usr.bin/ctags/ctags.h 8a16b7a18f5d0b031f09832fd7752fba717e2a97 11 | ctags/fortran.c freebsd usr.bin/ctags/fortran.c 8a16b7a18f5d0b031f09832fd7752fba717e2a97 12 | ctags/lisp.c freebsd usr.bin/ctags/lisp.c 8a16b7a18f5d0b031f09832fd7752fba717e2a97 13 | ctags/print.c freebsd usr.bin/ctags/print.c 8a16b7a18f5d0b031f09832fd7752fba717e2a97 14 | ctags/tree.c freebsd usr.bin/ctags/tree.c 8a16b7a18f5d0b031f09832fd7752fba717e2a97 15 | ctags/yacc.c freebsd usr.bin/ctags/yacc.c 8a16b7a18f5d0b031f09832fd7752fba717e2a97 16 | ctags/test/ctags.test freebsd usr.bin/ctags/test/ctags.test 9b50d9027575220cb6dd09b3e62f03f511e908b8 17 | 18 | indent/README freebsd usr.bin/indent/README dc51023cb319a421c1d1f7bfb06f90e5e0fb500a 19 | indent/args.c freebsd usr.bin/indent/args.c b5b9eaa96274a9c40b06999cadc777c8aeb71d09 20 | indent/indent.1 freebsd usr.bin/indent/indent.1 b5b9eaa96274a9c40b06999cadc777c8aeb71d09 21 | indent/indent.c freebsd usr.bin/indent/indent.c 5088a2d18c93fe5361bb914ca1b1f4cce1067707 22 | indent/indent.h freebsd usr.bin/indent/indent.h 4d846d260e2b9a3d4d0a701462568268cbfe7a5b 23 | indent/indent_codes.h freebsd usr.bin/indent/indent_codes.h f9287a9d85e47b4ac0c2ed7891d0b9d472f36243 24 | indent/indent_globs.h freebsd usr.bin/indent/indent_globs.h b5b9eaa96274a9c40b06999cadc777c8aeb71d09 25 | indent/io.c freebsd usr.bin/indent/io.c 02bde5cf13354d39157b9f43fb99ff0d34bf5b35 26 | indent/lexi.c freebsd usr.bin/indent/lexi.c b5b9eaa96274a9c40b06999cadc777c8aeb71d09 27 | indent/parse.c freebsd usr.bin/indent/parse.c 5088a2d18c93fe5361bb914ca1b1f4cce1067707 28 | indent/pr_comment.c freebsd usr.bin/indent/pr_comment.c 7e53aaedd3dbcf37c1f40a5fd290886fdd7fe08d 29 | indent/tests/binary.0 freebsd usr.bin/indent/tests/binary.0 bd2969a00d614adfa6fe37b96bc15ca4cdcb3f3e 30 | indent/tests/binary.0.stdout freebsd usr.bin/indent/tests/binary.0.stdout a3abcad0b7ada3ebabbab2f5074608caf0689802 31 | indent/tests/comments.0 freebsd usr.bin/indent/tests/comments.0 3c51c3cf5ffe336cc7f1e74d8d90ec7af6930219 32 | indent/tests/comments.0.pro freebsd usr.bin/indent/tests/comments.0.pro d0d51a33222e56cb38f7fc6a758914c1503c43ad 33 | indent/tests/comments.0.stdout freebsd usr.bin/indent/tests/comments.0.stdout 3c51c3cf5ffe336cc7f1e74d8d90ec7af6930219 34 | indent/tests/cs.0 freebsd usr.bin/indent/tests/cs.0 bb92a28b2f6c66d9dc3eab0ee00963dd02e9241d 35 | indent/tests/cs.0.pro freebsd usr.bin/indent/tests/cs.0.pro bb92a28b2f6c66d9dc3eab0ee00963dd02e9241d 36 | indent/tests/cs.0.stdout freebsd usr.bin/indent/tests/cs.0.stdout bb92a28b2f6c66d9dc3eab0ee00963dd02e9241d 37 | indent/tests/declarations.0 freebsd usr.bin/indent/tests/declarations.0 3bbaa755f34eaf2073f2f0c1fd537e96e26c81e8 38 | indent/tests/declarations.0.stdout freebsd usr.bin/indent/tests/declarations.0.stdout b06c2eb7b1a9e02ad9b84062fef889fa2bd0d253 39 | indent/tests/elsecomment.0 freebsd usr.bin/indent/tests/elsecomment.0 ec5ac89ecd18114d986b2ecaf099443080b15a5e 40 | indent/tests/elsecomment.0.pro freebsd usr.bin/indent/tests/elsecomment.0.pro 7d9ade5da19faff73191fa7fc3e09c2ab3b5e6bf 41 | indent/tests/elsecomment.0.stdout freebsd usr.bin/indent/tests/elsecomment.0.stdout ec5ac89ecd18114d986b2ecaf099443080b15a5e 42 | indent/tests/f_decls.0 freebsd usr.bin/indent/tests/f_decls.0 9522d0b0d2c9418330de71422a6b4688cb000de6 43 | indent/tests/f_decls.0.stdout freebsd usr.bin/indent/tests/f_decls.0.stdout 9522d0b0d2c9418330de71422a6b4688cb000de6 44 | indent/tests/float.0 freebsd usr.bin/indent/tests/float.0 dad19de0e6685ea176c82d57c79803954d706760 45 | indent/tests/float.0.stdout freebsd usr.bin/indent/tests/float.0.stdout dad19de0e6685ea176c82d57c79803954d706760 46 | indent/tests/functional_test.sh freebsd usr.bin/indent/tests/functional_test.sh 7d9ade5da19faff73191fa7fc3e09c2ab3b5e6bf 47 | indent/tests/label.0 freebsd usr.bin/indent/tests/label.0 61fd3be0b0fb9df04ea6ac47d552ceaff0a75aa6 48 | indent/tests/label.0.pro freebsd usr.bin/indent/tests/label.0.pro 7d9ade5da19faff73191fa7fc3e09c2ab3b5e6bf 49 | indent/tests/label.0.stdout freebsd usr.bin/indent/tests/label.0.stdout a3abcad0b7ada3ebabbab2f5074608caf0689802 50 | indent/tests/list_head.0 freebsd usr.bin/indent/tests/list_head.0 61fd3be0b0fb9df04ea6ac47d552ceaff0a75aa6 51 | indent/tests/list_head.0.stdout freebsd usr.bin/indent/tests/list_head.0.stdout 61fd3be0b0fb9df04ea6ac47d552ceaff0a75aa6 52 | indent/tests/ncs.0 freebsd usr.bin/indent/tests/ncs.0 bb92a28b2f6c66d9dc3eab0ee00963dd02e9241d 53 | indent/tests/ncs.0.pro freebsd usr.bin/indent/tests/ncs.0.pro bb92a28b2f6c66d9dc3eab0ee00963dd02e9241d 54 | indent/tests/ncs.0.stdout freebsd usr.bin/indent/tests/ncs.0.stdout bb92a28b2f6c66d9dc3eab0ee00963dd02e9241d 55 | indent/tests/offsetof.0 freebsd usr.bin/indent/tests/offsetof.0 61fd3be0b0fb9df04ea6ac47d552ceaff0a75aa6 56 | indent/tests/offsetof.0.stdout freebsd usr.bin/indent/tests/offsetof.0.stdout a3abcad0b7ada3ebabbab2f5074608caf0689802 57 | indent/tests/parens.0 freebsd usr.bin/indent/tests/parens.0 2364d1a74ecc5e7f6b92e8459660889b5359e0ba 58 | indent/tests/parens.0.pro freebsd usr.bin/indent/tests/parens.0.pro 2364d1a74ecc5e7f6b92e8459660889b5359e0ba 59 | indent/tests/parens.0.stdout freebsd usr.bin/indent/tests/parens.0.stdout 2364d1a74ecc5e7f6b92e8459660889b5359e0ba 60 | indent/tests/pcs.0 freebsd usr.bin/indent/tests/pcs.0 1d018043092b0a0a1aa20c0e498b94897fa096a4 61 | indent/tests/pcs.0.pro freebsd usr.bin/indent/tests/pcs.0.pro 1d018043092b0a0a1aa20c0e498b94897fa096a4 62 | indent/tests/pcs.0.stdout freebsd usr.bin/indent/tests/pcs.0.stdout 1d018043092b0a0a1aa20c0e498b94897fa096a4 63 | indent/tests/ps.0 freebsd usr.bin/indent/tests/ps.0 b5b9eaa96274a9c40b06999cadc777c8aeb71d09 64 | indent/tests/ps.0.pro freebsd usr.bin/indent/tests/ps.0.pro b5b9eaa96274a9c40b06999cadc777c8aeb71d09 65 | indent/tests/ps.0.stdout freebsd usr.bin/indent/tests/ps.0.stdout b5b9eaa96274a9c40b06999cadc777c8aeb71d09 66 | indent/tests/struct.0 freebsd usr.bin/indent/tests/struct.0 f9287a9d85e47b4ac0c2ed7891d0b9d472f36243 67 | indent/tests/struct.0.stdout freebsd usr.bin/indent/tests/struct.0.stdout f9287a9d85e47b4ac0c2ed7891d0b9d472f36243 68 | indent/tests/surplusbad.0 freebsd usr.bin/indent/tests/surplusbad.0 61fd3be0b0fb9df04ea6ac47d552ceaff0a75aa6 69 | indent/tests/surplusbad.0.pro freebsd usr.bin/indent/tests/surplusbad.0.pro 7d9ade5da19faff73191fa7fc3e09c2ab3b5e6bf 70 | indent/tests/surplusbad.0.stdout freebsd usr.bin/indent/tests/surplusbad.0.stdout 61fd3be0b0fb9df04ea6ac47d552ceaff0a75aa6 71 | indent/tests/types_from_file.0 freebsd usr.bin/indent/tests/types_from_file.0 61fd3be0b0fb9df04ea6ac47d552ceaff0a75aa6 72 | indent/tests/types_from_file.0.list freebsd usr.bin/indent/tests/types_from_file.0.list 7d9ade5da19faff73191fa7fc3e09c2ab3b5e6bf 73 | indent/tests/types_from_file.0.pro freebsd usr.bin/indent/tests/types_from_file.0.pro 7d9ade5da19faff73191fa7fc3e09c2ab3b5e6bf 74 | indent/tests/types_from_file.0.stdout freebsd usr.bin/indent/tests/types_from_file.0.stdout 61fd3be0b0fb9df04ea6ac47d552ceaff0a75aa6 75 | indent/tests/wchar.0 freebsd usr.bin/indent/tests/wchar.0 61fd3be0b0fb9df04ea6ac47d552ceaff0a75aa6 76 | indent/tests/wchar.0.stdout freebsd usr.bin/indent/tests/wchar.0.stdout 61fd3be0b0fb9df04ea6ac47d552ceaff0a75aa6 77 | 78 | unifdef/tree.h freebsd sys/sys/tree.h 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f 79 | unifdef/unifdef.1 freebsd contrib/unifdef/unifdef.1 049b7608f41bf4e93ac6de718c45bef261f6977d 80 | unifdef/unifdef.c freebsd contrib/unifdef/unifdef.c aacbe7384221d2eafa326864bbbe2f22a10063ce 81 | unifdef/unifdef.h freebsd contrib/unifdef/unifdef.h 343b776fd0280f4dc95a1a61fd9ac40c78ce684e 82 | unifdef/unifdefall.sh freebsd contrib/unifdef/unifdefall.sh fb3ef04d2028110f06d68b09009f1f2ca0f4128e 83 | unifdef/version.h freebsd contrib/unifdef/version.h fb3ef04d2028110f06d68b09009f1f2ca0f4128e 84 | unifdef/tests/unifdef_test.sh freebsd usr.bin/unifdef/tests/unifdef_test.sh aacbe7384221d2eafa326864bbbe2f22a10063ce 85 | -------------------------------------------------------------------------------- /asa/asa.1: -------------------------------------------------------------------------------- 1 | .\" $NetBSD: asa.1,v 1.11 2002/02/08 01:36:18 ross Exp $ 2 | .\" 3 | .\" Copyright (c) 1993 Winning Strategies, Inc. 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions 8 | .\" are met: 9 | .\" 1. Redistributions of source code must retain the above copyright 10 | .\" notice, this list of conditions and the following disclaimer. 11 | .\" 2. Redistributions in binary form must reproduce the above copyright 12 | .\" notice, this list of conditions and the following disclaimer in the 13 | .\" documentation and/or other materials provided with the distribution. 14 | .\" 3. All advertising materials mentioning features or use of this software 15 | .\" must display the following acknowledgement: 16 | .\" This product includes software developed by Winning Strategies, Inc. 17 | .\" 4. The name of the author may not be used to endorse or promote products 18 | .\" derived from this software without specific prior written permission 19 | .\" 20 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 | .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | .\" 31 | .Dd May 9, 2002 32 | .Dt ASA 1 33 | .Os 34 | .Sh NAME 35 | .Nm asa 36 | .Nd interpret carriage-control characters 37 | .Sh SYNOPSIS 38 | .Nm 39 | .Op Ar 40 | .Sh DESCRIPTION 41 | The 42 | .Nm 43 | utility reads files sequentially, mapping 44 | .Tn FORTRAN 45 | carriage-control characters to line-printer control sequences, 46 | and writes them to the standard output. 47 | .Pp 48 | The first character of each line is interpreted as a carriage-control 49 | character. 50 | The following characters are interpreted as follows: 51 | .Bl -tag -width ".Aq space" 52 | .It Aq space 53 | Output the rest of the line without change. 54 | .It 0 55 | Output a 56 | .Aq newline 57 | character before printing the rest of the line. 58 | .It 1 59 | Output a 60 | .Aq formfeed 61 | character before printing the rest of the line. 62 | .It \&+ 63 | The trailing 64 | .Aq newline 65 | of the previous line is replaced by a 66 | .Aq carriage-return 67 | before printing the rest of the line. 68 | .El 69 | .Pp 70 | Lines beginning with characters other than the above are treated as if they 71 | begin with 72 | .Aq space . 73 | .Sh EXIT STATUS 74 | .Ex -std 75 | .Sh EXAMPLES 76 | To view a file containing the output of a 77 | .Tn FORTRAN 78 | program: 79 | .Pp 80 | .Dl "asa file" 81 | .Pp 82 | To format the output of a 83 | .Tn FORTRAN 84 | program and redirect it to a line-printer: 85 | .Pp 86 | .Dl "a.out | asa | lpr" 87 | .Sh SEE ALSO 88 | .Xr f77 1 89 | .Sh STANDARDS 90 | The 91 | .Nm 92 | utility conforms to 93 | .St -p1003.1-2001 . 94 | .Sh AUTHORS 95 | .An J.T. Conklin , 96 | Winning Strategies, Inc. 97 | -------------------------------------------------------------------------------- /asa/asa.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: asa.c,v 1.17 2016/09/05 00:40:28 sevan Exp $ */ 2 | 3 | /*- 4 | * SPDX-License-Identifier: BSD-4-Clause 5 | * 6 | * Copyright (c) 1993,94 Winning Strategies, Inc. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. All advertising materials mentioning features or use of this software 18 | * must display the following acknowledgement: 19 | * This product includes software developed by Winning Strategies, Inc. 20 | * 4. The name of the author may not be used to endorse or promote products 21 | * derived from this software without specific prior written permission 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | static void asa(FILE *); 43 | static void usage(void) __dead2; 44 | 45 | int 46 | main(int argc, char *argv[]) 47 | { 48 | FILE *fp; 49 | int ch, exval; 50 | 51 | while ((ch = getopt(argc, argv, "")) != -1) { 52 | switch (ch) { 53 | default: 54 | usage(); 55 | } 56 | } 57 | argc -= optind; 58 | argv += optind; 59 | 60 | exval = 0; 61 | if (*argv == NULL) { 62 | asa(stdin); 63 | } else { 64 | do { 65 | if (strcmp(*argv, "-") == 0) { 66 | asa(stdin); 67 | } else if ((fp = fopen(*argv, "r")) == NULL) { 68 | warn("%s", *argv); 69 | exval = 1; 70 | } else { 71 | asa(fp); 72 | fclose(fp); 73 | } 74 | } while (*++argv != NULL); 75 | } 76 | 77 | if (fflush(stdout) != 0) 78 | err(1, "stdout"); 79 | 80 | exit(exval); 81 | } 82 | 83 | static void 84 | usage(void) 85 | { 86 | fprintf(stderr, "usage: asa [file ...]\n"); 87 | exit(1); 88 | } 89 | 90 | static void 91 | asa(FILE *f) 92 | { 93 | char *buf; 94 | size_t len; 95 | bool eol = false; 96 | 97 | while ((buf = fgetln(f, &len)) != NULL) { 98 | /* in all cases but '+', terminate previous line, if any */ 99 | if (buf[0] != '+' && eol) 100 | putchar('\n'); 101 | /* examine and translate the control character */ 102 | switch (buf[0]) { 103 | default: 104 | /* 105 | * “It is suggested that implementations treat 106 | * characters other than 0, 1, and '+' as 107 | * in the absence of any compelling reason to do 108 | * otherwise” (POSIX.1-2017) 109 | */ 110 | case ' ': 111 | /* nothing */ 112 | break; 113 | case '0': 114 | putchar('\n'); 115 | break; 116 | case '1': 117 | putchar('\f'); 118 | break; 119 | case '+': 120 | /* 121 | * “If the '+' is the first character in the 122 | * input, it shall be equivalent to .” 123 | * (POSIX.1-2017) 124 | */ 125 | if (eol) 126 | putchar('\r'); 127 | break; 128 | } 129 | /* trim newline if there is one */ 130 | if ((eol = (buf[len - 1] == '\n'))) 131 | --len; 132 | /* print the rest of the input line */ 133 | if (len > 1 && buf[0] && buf[1]) 134 | fwrite(buf + 1, 1, len - 1, stdout); 135 | } 136 | /* terminate the last line, if any */ 137 | if (eol) 138 | putchar('\n'); 139 | /* check for output errors */ 140 | if (ferror(stdout) != 0) 141 | err(1, "stdout"); 142 | } 143 | -------------------------------------------------------------------------------- /asa/asa.plist.part: -------------------------------------------------------------------------------- 1 | 2 | OpenSourceProject 3 | asa 4 | OpenSourceVersion 5 | 2024-01-09 6 | OpenSourceWebsiteURL 7 | https://cgit.freebsd.org/src/tree/usr.bin/asa?id=c2356a440db91c106867d45c94b3d6d7bc0e50f0 8 | OpenSourceImportDate 9 | 2023-01-09 10 | OpenSourceLicense 11 | BSD 12 | OpenSourceModifications 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /asa/tests/asa_test.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 Klara, Inc. 3 | # 4 | # SPDX-License-Identifier: BSD-2-Clause 5 | # 6 | 7 | a="The magic words are" 8 | b="Squeamish Ossifrage" 9 | 10 | atf_check_asa() { 11 | atf_check -o file:"$2" asa "$1" 12 | atf_check -o file:"$2" asa <"$1" 13 | atf_check -o file:"$2" asa - <"$1" 14 | } 15 | 16 | atf_test_case space 17 | space_head() { 18 | atf_set descr "First character on line is ' '" 19 | } 20 | space_body() { 21 | printf " %s\n %s\n" "$a" "$b" >infile 22 | printf "%s\n%s\n" "$a" "$b" >outfile 23 | atf_check_asa infile outfile 24 | } 25 | 26 | atf_test_case zero 27 | zero_head() { 28 | atf_set descr "First character on line is '0'" 29 | } 30 | zero_body() { 31 | printf " %s\n0%s\n" "$a" "$b" >infile 32 | printf "%s\n\n%s\n" "$a" "$b" >outfile 33 | atf_check_asa infile outfile 34 | } 35 | 36 | atf_test_case one 37 | one_head() { 38 | atf_set descr "First character on line is '1'" 39 | } 40 | one_body() { 41 | printf "1%s\n1%s\n" "$a" "$b" >infile 42 | printf "\f%s\n\f%s\n" "$a" "$b" >outfile 43 | atf_check_asa infile outfile 44 | } 45 | 46 | atf_test_case plus 47 | plus_head() { 48 | atf_set descr "First character on line is '+'" 49 | } 50 | plus_body() { 51 | printf " %s\n+%s\n" "$a" "$b" >infile 52 | printf "%s\r%s\n" "$a" "$b" >outfile 53 | atf_check_asa infile outfile 54 | } 55 | 56 | atf_test_case plus_top 57 | plus_top_head() { 58 | atf_set descr "First character in input is '+'" 59 | } 60 | plus_top_body() { 61 | printf "+%s\n+%s\n" "$a" "$b" >infile 62 | printf "%s\r%s\n" "$a" "$b" >outfile 63 | atf_check_asa infile outfile 64 | } 65 | 66 | atf_test_case stdout 67 | stdout_head() { 68 | atf_set descr "Failure to write to stdout" 69 | } 70 | stdout_body() { 71 | ( 72 | trap "" PIPE 73 | echo " $a $b" | asa 2>stderr 74 | echo $? >result 75 | ) | true 76 | atf_check -o inline:"1\n" cat result 77 | atf_check -o match:"stdout" cat stderr 78 | } 79 | 80 | atf_test_case dashdash 81 | dashdash_head() { 82 | atf_set descr "Use -- to end options" 83 | } 84 | dashdash_body() { 85 | echo " $a $b" >-infile 86 | atf_check -s not-exit:0 -e match:"illegal option" asa -infile 87 | atf_check -o inline:"$a $b\n" asa -- -infile 88 | } 89 | 90 | atf_test_case unterminated 91 | unterminated_head() { 92 | atf_set descr "Unterminated input" 93 | } 94 | unterminated_body() { 95 | printf " %s\n %s" "$a" "$b" >infile 96 | printf "%s\n%s" "$a" "$b" >outfile 97 | atf_check_asa infile outfile 98 | } 99 | 100 | atf_init_test_cases() 101 | { 102 | atf_add_test_case space 103 | atf_add_test_case zero 104 | atf_add_test_case one 105 | atf_add_test_case plus 106 | atf_add_test_case plus_top 107 | atf_add_test_case stdout 108 | atf_add_test_case dashdash 109 | atf_add_test_case unterminated 110 | } 111 | -------------------------------------------------------------------------------- /ctags/ctags.1: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1987, 1990, 1993 2 | .\" The Regents of the University of California. All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 3. Neither the name of the University nor the names of its contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" @(#)ctags.1 8.1 (Berkeley) 6/6/93 29 | .\" $FreeBSD$ 30 | .\" 31 | .Dd May 23, 2023 32 | .Dt CTAGS 1 33 | .Os 34 | .Sh NAME 35 | .Nm ctags 36 | .Nd create a 37 | .Pa tags 38 | file 39 | .Sh SYNOPSIS 40 | .Nm 41 | .Op Fl BFTaduwvx 42 | .Op Fl f Ar tagsfile 43 | .Ar 44 | .Sh DESCRIPTION 45 | The 46 | .Nm 47 | utility makes a 48 | .Pa tags 49 | file for 50 | .Xr ex 1 51 | from the specified C, 52 | Pascal, Fortran, 53 | .Xr yacc 1 , 54 | .Xr lex 1 , 55 | and Lisp sources. 56 | A tags file gives the locations of specified objects in a group of files. 57 | Each line of the tags file contains the object name, the file in which it 58 | is defined, and a search pattern for the object definition, separated by 59 | white-space. 60 | Using the 61 | .Pa tags 62 | file, 63 | .Xr ex 1 64 | can quickly locate these object definitions. 65 | Depending upon the options provided to 66 | .Nm , 67 | objects will consist of subroutines, typedefs, defines, structs, 68 | enums and unions. 69 | .Pp 70 | The following options are available: 71 | .Bl -tag -width indent 72 | .It Fl B 73 | Use backward searching patterns 74 | .Pq Li ?...? . 75 | .It Fl F 76 | Use forward searching patterns 77 | .Pq Li /.../ 78 | (the default). 79 | .It Fl T 80 | Do not create tags for typedefs, structs, unions, and enums. 81 | .It Fl a 82 | Append to 83 | .Pa tags 84 | file. 85 | .It Fl d 86 | Create tags for 87 | .Li #defines 88 | that do not take arguments; 89 | .Li #defines 90 | that take arguments are tagged automatically. 91 | .It Fl f 92 | Place the tag descriptions in a file called 93 | .Ar tagsfile . 94 | The default behaviour is to place them in a file called 95 | .Pa tags . 96 | If 97 | .Ar tagsfile 98 | is 99 | .Dq - , 100 | the tags will be written to standard output instead. 101 | .It Fl u 102 | Update the specified files in the 103 | .Pa tags 104 | file, that is, all 105 | references to them are deleted, and the new values are appended to the 106 | file. 107 | This is ignored if the tags file does not exist or is not a regular 108 | file (e.g. 109 | .Fl f Ns - 110 | was used to write to standard output). 111 | .Pp 112 | Beware: this option is implemented in a way which is rather 113 | slow; it is usually faster to simply rebuild the 114 | .Pa tags 115 | file. 116 | .It Fl v 117 | An index of the form expected by 118 | .Xr vgrind 1 119 | is produced on the standard output. 120 | This listing 121 | contains the object name, file name, and page number (assuming 64 122 | line pages). 123 | Since the output will be sorted into lexicographic order, 124 | it may be desired to run the output through 125 | .Xr sort 1 . 126 | Sample use: 127 | .Bd -literal -offset indent 128 | ctags -v files | sort -f > index 129 | vgrind -x index 130 | .Ed 131 | .It Fl w 132 | Suppress warning diagnostics. 133 | .It Fl x 134 | .Nm 135 | produces a list of object 136 | names, the line number and file name on which each is defined, as well 137 | as the text of that line and prints this on the standard output. 138 | This 139 | is a simple index which can be printed out as an off-line readable 140 | function index. 141 | .El 142 | .Pp 143 | Files whose names end in 144 | .Pa .c 145 | or 146 | .Pa .h 147 | are assumed to be C 148 | source files and are searched for C style routine and macro definitions. 149 | Files whose names end in 150 | .Pa .y 151 | are assumed to be 152 | .Xr yacc 1 153 | source files. 154 | Files whose names end in 155 | .Pa .l 156 | are assumed to be Lisp files if their 157 | first non-blank character is 158 | .Ql \&; , 159 | .Ql \&( , 160 | or 161 | .Ql \&[ , 162 | otherwise, they are 163 | treated as 164 | .Xr lex 1 165 | files. 166 | Other files are first examined to see if they 167 | contain any Pascal or Fortran routine definitions, and, if not, are 168 | searched for C style definitions. 169 | .Pp 170 | The tag 171 | .Dq Li main 172 | is treated specially in C programs. 173 | The tag formed 174 | is created by prepending 175 | .Ql M 176 | to the name of the file, with the 177 | trailing 178 | .Pa .c 179 | and any leading pathname components removed. 180 | This makes use of 181 | .Nm 182 | practical in directories with more than one 183 | program. 184 | .Pp 185 | The 186 | .Xr yacc 1 187 | and 188 | .Xr lex 1 189 | files each have a special tag. 190 | .Dq Li yyparse 191 | is the start 192 | of the second section of the 193 | .Xr yacc 1 194 | file, and 195 | .Dq Li yylex 196 | is the start of 197 | the second section of the 198 | .Xr lex 1 199 | file. 200 | .Sh FILES 201 | .Bl -tag -width ".Pa tags" -compact 202 | .It Pa tags 203 | default output tags file 204 | .El 205 | .Sh EXIT STATUS 206 | The 207 | .Nm 208 | utility exits with a value of 1 if an error occurred, 0 otherwise. 209 | Duplicate objects are not considered errors. 210 | .Sh COMPATIBILITY 211 | The 212 | .Fl t 213 | option is a no-op for compatibility with previous versions of 214 | .Nm 215 | that did not create tags for typedefs, enums, structs and unions 216 | by default. 217 | .Sh SEE ALSO 218 | .Xr ex 1 , 219 | .Xr vi 1 220 | .Sh STANDARDS 221 | The 222 | .Nm 223 | utility conforms to 224 | .St -p1003.1-2001 . 225 | .Sh HISTORY 226 | The 227 | .Nm 228 | utility appeared in 229 | .Bx 3.0 . 230 | .Sh BUGS 231 | Recognition of functions, subroutines and procedures 232 | for Fortran and Pascal is done in a very simpleminded way. 233 | No attempt 234 | is made to deal with block structure; if you have two Pascal procedures 235 | in different blocks with the same name you lose. 236 | The 237 | .Nm 238 | utility does not 239 | understand about Pascal types. 240 | .Pp 241 | The method of deciding whether to look for C, Pascal or 242 | Fortran 243 | functions is a hack. 244 | .Pp 245 | The 246 | .Nm 247 | utility relies on the input being well formed, and any syntactical 248 | errors will completely confuse it. 249 | It also finds some legal syntax 250 | confusing; for example, since it does not understand 251 | .Li #ifdef Ns 's 252 | (incidentally, that is a feature, not a bug), any code with unbalanced 253 | braces inside 254 | .Li #ifdef Ns 's 255 | will cause it to become somewhat disoriented. 256 | In a similar fashion, multiple line changes within a definition will 257 | cause it to enter the last line of the object, rather than the first, as 258 | the searching pattern. 259 | The last line of multiple line 260 | .Li typedef Ns 's 261 | will similarly be noted. 262 | -------------------------------------------------------------------------------- /ctags/ctags.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | * 4 | * Copyright (c) 1987, 1993, 1994, 1995 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef lint 33 | static const char copyright[] = 34 | "@(#) Copyright (c) 1987, 1993, 1994, 1995\n\ 35 | The Regents of the University of California. All rights reserved.\n"; 36 | #endif 37 | 38 | #if 0 39 | #ifndef lint 40 | static char sccsid[] = "@(#)ctags.c 8.4 (Berkeley) 2/7/95"; 41 | #endif 42 | #endif 43 | 44 | #include 45 | __FBSDID("$FreeBSD$"); 46 | 47 | #include 48 | #include 49 | #include 50 | 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | 61 | #include "ctags.h" 62 | 63 | /* 64 | * ctags: create a tags file 65 | */ 66 | 67 | NODE *head; /* head of the sorted binary tree */ 68 | 69 | /* boolean "func" (see init()) */ 70 | bool _wht[256], _etk[256], _itk[256], _btk[256], _gd[256]; 71 | 72 | FILE *inf; /* ioptr for current input file */ 73 | FILE *outf; /* ioptr for tags file */ 74 | 75 | long lineftell; /* ftell after getc( inf ) == '\n' */ 76 | 77 | int lineno; /* line number of current line */ 78 | int dflag; /* -d: non-macro defines */ 79 | int tflag; /* -t: create tags for typedefs */ 80 | int vflag; /* -v: vgrind style index output */ 81 | int wflag; /* -w: suppress warnings */ 82 | int xflag; /* -x: cxref style output */ 83 | 84 | char *curfile; /* current input file name */ 85 | char searchar = '/'; /* use /.../ searches by default */ 86 | char lbuf[LINE_MAX]; 87 | 88 | void init(void); 89 | void find_entries(char *); 90 | static void usage(void); 91 | 92 | int 93 | main(int argc, char **argv) 94 | { 95 | static const char *outfile = "tags"; /* output file */ 96 | int aflag; /* -a: append to tags */ 97 | int uflag; /* -u: update tags */ 98 | int exit_val; /* exit value */ 99 | int step; /* step through args */ 100 | int ch; /* getopts char */ 101 | 102 | setlocale(LC_ALL, ""); 103 | 104 | aflag = uflag = NO; 105 | tflag = YES; 106 | while ((ch = getopt(argc, argv, "BFTadf:tuwvx")) != -1) 107 | switch(ch) { 108 | case 'B': 109 | searchar = '?'; 110 | break; 111 | case 'F': 112 | searchar = '/'; 113 | break; 114 | case 'T': 115 | tflag = NO; 116 | break; 117 | case 'a': 118 | aflag++; 119 | break; 120 | case 'd': 121 | dflag++; 122 | break; 123 | case 'f': 124 | outfile = optarg; 125 | break; 126 | case 't': 127 | tflag = YES; 128 | break; 129 | case 'u': 130 | uflag++; 131 | break; 132 | case 'w': 133 | wflag++; 134 | break; 135 | case 'v': 136 | vflag++; 137 | case 'x': 138 | xflag++; 139 | break; 140 | case '?': 141 | default: 142 | usage(); 143 | } 144 | argv += optind; 145 | argc -= optind; 146 | if (!argc) 147 | usage(); 148 | 149 | if (strcmp(outfile, "-") == 0) 150 | outfile = "/dev/stdout"; 151 | 152 | if (!xflag) 153 | setlocale(LC_COLLATE, "C"); 154 | 155 | init(); 156 | 157 | for (exit_val = step = 0; step < argc; ++step) 158 | if (!(inf = fopen(argv[step], "r"))) { 159 | warn("%s", argv[step]); 160 | exit_val = 1; 161 | } 162 | else { 163 | curfile = argv[step]; 164 | find_entries(argv[step]); 165 | (void)fclose(inf); 166 | } 167 | 168 | if (head) { 169 | if (xflag) 170 | put_entries(head); 171 | else { 172 | if (uflag) { 173 | struct stat sb; 174 | FILE *oldf; 175 | regex_t *regx; 176 | 177 | if ((oldf = fopen(outfile, "r")) == NULL) { 178 | if (errno == ENOENT) { 179 | uflag = 0; 180 | goto udone; 181 | } 182 | err(1, "opening %s", outfile); 183 | } 184 | if (fstat(fileno(oldf), &sb) != 0 || 185 | !S_ISREG(sb.st_mode)) { 186 | fclose(oldf); 187 | uflag = 0; 188 | goto udone; 189 | } 190 | if (unlink(outfile)) 191 | err(1, "unlinking %s", outfile); 192 | if ((outf = fopen(outfile, "w")) == NULL) 193 | err(1, "recreating %s", outfile); 194 | if ((regx = calloc(argc, sizeof(regex_t))) == NULL) 195 | err(1, "RE alloc"); 196 | for (step = 0; step < argc; step++) { 197 | (void)strcpy(lbuf, "\t"); 198 | (void)strlcat(lbuf, argv[step], LINE_MAX); 199 | (void)strlcat(lbuf, "\t", LINE_MAX); 200 | if (regcomp(regx + step, lbuf, 201 | REG_NOSPEC)) 202 | warn("RE compilation failed"); 203 | } 204 | nextline: 205 | while (fgets(lbuf, LINE_MAX, oldf)) { 206 | for (step = 0; step < argc; step++) 207 | if (regexec(regx + step, 208 | lbuf, 0, NULL, 0) == 0) 209 | goto nextline; 210 | fputs(lbuf, outf); 211 | } 212 | for (step = 0; step < argc; step++) 213 | regfree(regx + step); 214 | free(regx); 215 | fclose(oldf); 216 | fclose(outf); 217 | ++aflag; 218 | } 219 | udone: 220 | if (!(outf = fopen(outfile, aflag ? "a" : "w"))) 221 | err(1, "%s", outfile); 222 | put_entries(head); 223 | (void)fclose(outf); 224 | if (uflag) { 225 | pid_t pid; 226 | 227 | if ((pid = fork()) == -1) 228 | err(1, "fork failed"); 229 | else if (pid == 0) { 230 | execlp("sort", "sort", "-o", outfile, 231 | outfile, NULL); 232 | err(1, "exec of sort failed"); 233 | } 234 | /* Just assume the sort went OK. The old code 235 | did not do any checks either. */ 236 | (void)wait(NULL); 237 | } 238 | } 239 | } 240 | if (ferror(stdout) != 0 || fflush(stdout) != 0) 241 | err(1, "stdout"); 242 | exit(exit_val); 243 | } 244 | 245 | static void 246 | usage(void) 247 | { 248 | (void)fprintf(stderr, "usage: ctags [-BFTaduwvx] [-f tagsfile] file ...\n"); 249 | exit(1); 250 | } 251 | 252 | /* 253 | * init -- 254 | * this routine sets up the boolean pseudo-functions which work by 255 | * setting boolean flags dependent upon the corresponding character. 256 | * Every char which is NOT in that string is false with respect to 257 | * the pseudo-function. Therefore, all of the array "_wht" is NO 258 | * by default and then the elements subscripted by the chars in 259 | * CWHITE are set to YES. Thus, "_wht" of a char is YES if it is in 260 | * the string CWHITE, else NO. 261 | */ 262 | void 263 | init(void) 264 | { 265 | int i; 266 | const char *sp; 267 | 268 | for (i = 0; i < 256; i++) { 269 | _wht[i] = _etk[i] = _itk[i] = _btk[i] = NO; 270 | _gd[i] = YES; 271 | } 272 | #define CWHITE " \f\t\n" 273 | for (sp = CWHITE; *sp; sp++) /* white space chars */ 274 | _wht[*sp] = YES; 275 | #define CTOKEN " \t\n\"'#()[]{}=-+%*/&|^~!<>;,.:?" 276 | for (sp = CTOKEN; *sp; sp++) /* token ending chars */ 277 | _etk[*sp] = YES; 278 | #define CINTOK "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz0123456789" 279 | for (sp = CINTOK; *sp; sp++) /* valid in-token chars */ 280 | _itk[*sp] = YES; 281 | #define CBEGIN "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" 282 | for (sp = CBEGIN; *sp; sp++) /* token starting chars */ 283 | _btk[*sp] = YES; 284 | #define CNOTGD ",;" 285 | for (sp = CNOTGD; *sp; sp++) /* invalid after-function chars */ 286 | _gd[*sp] = NO; 287 | } 288 | 289 | /* 290 | * find_entries -- 291 | * this routine opens the specified file and calls the function 292 | * which searches the file. 293 | */ 294 | void 295 | find_entries(char *file) 296 | { 297 | char *cp; 298 | 299 | lineno = 0; /* should be 1 ?? KB */ 300 | if ((cp = strrchr(file, '.'))) { 301 | if (cp[1] == 'l' && !cp[2]) { 302 | int c; 303 | 304 | for (;;) { 305 | if (GETC(==, EOF)) 306 | return; 307 | if (!iswhite(c)) { 308 | rewind(inf); 309 | break; 310 | } 311 | } 312 | #define LISPCHR ";([" 313 | /* lisp */ if (strchr(LISPCHR, c)) { 314 | l_entries(); 315 | return; 316 | } 317 | /* lex */ else { 318 | /* 319 | * we search all 3 parts of a lex file 320 | * for C references. This may be wrong. 321 | */ 322 | toss_yysec(); 323 | (void)strcpy(lbuf, "%%$"); 324 | pfnote("yylex", lineno); 325 | rewind(inf); 326 | } 327 | } 328 | /* yacc */ else if (cp[1] == 'y' && !cp[2]) { 329 | /* 330 | * we search only the 3rd part of a yacc file 331 | * for C references. This may be wrong. 332 | */ 333 | toss_yysec(); 334 | (void)strcpy(lbuf, "%%$"); 335 | pfnote("yyparse", lineno); 336 | y_entries(); 337 | } 338 | /* fortran */ else if ((cp[1] != 'c' && cp[1] != 'h') && !cp[2]) { 339 | if (PF_funcs()) 340 | return; 341 | rewind(inf); 342 | } 343 | } 344 | /* C */ c_entries(); 345 | } 346 | -------------------------------------------------------------------------------- /ctags/ctags.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | * 4 | * Copyright (c) 1987, 1993, 1994 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | * @(#)ctags.h 8.3 (Berkeley) 4/2/94 32 | * 33 | * $FreeBSD$ 34 | * 35 | */ 36 | 37 | #define bool char 38 | 39 | #define YES 1 40 | #define NO 0 41 | #define EOS '\0' 42 | 43 | #define ENDLINE 50 /* max length of pattern */ 44 | #define MAXTOKEN 250 /* max size of single token */ 45 | 46 | #define SETLINE {++lineno;lineftell = ftell(inf);} 47 | #define GETC(op,exp) ((c = getc(inf)) op (int)exp) 48 | 49 | /* 50 | * These character classification macros assume that the (EOF & 0xff) element 51 | * of the arrays is always 'NO', as the EOF return from getc() gets masked 52 | * to that value. Masking with 0xff has no effect for normal characters 53 | * returned by getc() provided chars have 8 bits. 54 | */ 55 | 56 | #define iswhite(arg) _wht[arg & 0xff] /* T if char is white */ 57 | #define begtoken(arg) _btk[arg & 0xff] /* T if char can start token */ 58 | #define intoken(arg) _itk[arg & 0xff] /* T if char can be in token */ 59 | #define endtoken(arg) _etk[arg & 0xff] /* T if char ends tokens */ 60 | #define isgood(arg) _gd[arg & 0xff] /* T if char can be after ')' */ 61 | 62 | typedef struct nd_st { /* sorting structure */ 63 | struct nd_st *left, 64 | *right; /* left and right sons */ 65 | char *entry, /* function or type name */ 66 | *file, /* file name */ 67 | *pat; /* search pattern */ 68 | int lno; /* for -x option */ 69 | bool been_warned; /* set if noticed dup */ 70 | } NODE; 71 | 72 | extern char *curfile; /* current input file name */ 73 | extern NODE *head; /* head of the sorted binary tree */ 74 | extern FILE *inf; /* ioptr for current input file */ 75 | extern FILE *outf; /* ioptr for current output file */ 76 | extern long lineftell; /* ftell after getc( inf ) == '\n' */ 77 | extern int lineno; /* line number of current line */ 78 | extern int dflag; /* -d: non-macro defines */ 79 | extern int tflag; /* -t: create tags for typedefs */ 80 | extern int vflag; /* -v: vgrind style index output */ 81 | extern int wflag; /* -w: suppress warnings */ 82 | extern int xflag; /* -x: cxref style output */ 83 | extern bool _wht[], _etk[], _itk[], _btk[], _gd[]; 84 | extern char lbuf[LINE_MAX]; 85 | extern char *lbp; 86 | extern char searchar; /* ex search character */ 87 | 88 | extern int cicmp(const char *); 89 | extern void get_line(void); 90 | extern void pfnote(const char *, int); 91 | extern int skip_key(int); 92 | extern void put_entries(NODE *); 93 | extern void toss_yysec(void); 94 | extern void l_entries(void); 95 | extern void y_entries(void); 96 | extern int PF_funcs(void); 97 | extern void c_entries(void); 98 | extern void skip_comment(int); 99 | -------------------------------------------------------------------------------- /ctags/ctags.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | OpenSourceProject 7 | ctags 8 | OpenSourceVersion 9 | 2023-06-05 10 | OpenSourceWebsiteURL 11 | https://cgit.freebsd.org/src/commit/usr.bin/ctags?id=7ba6119e22b54c2104b1948f0e8a4157d4112958 12 | OpenSourceImportDate 13 | 2023-06-05 14 | OpenSourceLicense 15 | BSD 16 | OpenSourceModifications 17 | 18 | C.c: Ignore comment between struct name and opening brace (4137025) 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /ctags/fortran.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | * 4 | * Copyright (c) 1987, 1993, 1994 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #if 0 33 | #ifndef lint 34 | static char sccsid[] = "@(#)fortran.c 8.3 (Berkeley) 4/2/94"; 35 | #endif 36 | #endif 37 | 38 | #include 39 | __FBSDID("$FreeBSD$"); 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include "ctags.h" 47 | 48 | static void takeprec(void); 49 | 50 | char *lbp; /* line buffer pointer */ 51 | 52 | int 53 | PF_funcs(void) 54 | { 55 | bool pfcnt; /* pascal/fortran functions found */ 56 | char *cp; 57 | char tok[MAXTOKEN]; 58 | 59 | for (pfcnt = NO;;) { 60 | lineftell = ftell(inf); 61 | if (!fgets(lbuf, sizeof(lbuf), inf)) 62 | return (pfcnt); 63 | ++lineno; 64 | lbp = lbuf; 65 | if (*lbp == '%') /* Ratfor escape to fortran */ 66 | ++lbp; 67 | for (; isspace(*lbp); ++lbp) 68 | continue; 69 | if (!*lbp) 70 | continue; 71 | switch (*lbp | ' ') { /* convert to lower-case */ 72 | case 'c': 73 | if (cicmp("complex") || cicmp("character")) 74 | takeprec(); 75 | break; 76 | case 'd': 77 | if (cicmp("double")) { 78 | for (; isspace(*lbp); ++lbp) 79 | continue; 80 | if (!*lbp) 81 | continue; 82 | if (cicmp("precision")) 83 | break; 84 | continue; 85 | } 86 | break; 87 | case 'i': 88 | if (cicmp("integer")) 89 | takeprec(); 90 | break; 91 | case 'l': 92 | if (cicmp("logical")) 93 | takeprec(); 94 | break; 95 | case 'r': 96 | if (cicmp("real")) 97 | takeprec(); 98 | break; 99 | } 100 | for (; isspace(*lbp); ++lbp) 101 | continue; 102 | if (!*lbp) 103 | continue; 104 | switch (*lbp | ' ') { 105 | case 'f': 106 | if (cicmp("function")) 107 | break; 108 | continue; 109 | case 'p': 110 | if (cicmp("program") || cicmp("procedure")) 111 | break; 112 | continue; 113 | case 's': 114 | if (cicmp("subroutine")) 115 | break; 116 | default: 117 | continue; 118 | } 119 | for (; isspace(*lbp); ++lbp) 120 | continue; 121 | if (!*lbp) 122 | continue; 123 | for (cp = lbp + 1; *cp && intoken(*cp); ++cp) 124 | continue; 125 | if (cp == lbp + 1) 126 | continue; 127 | *cp = EOS; 128 | (void)strlcpy(tok, lbp, sizeof(tok)); /* possible trunc */ 129 | get_line(); /* process line for ex(1) */ 130 | pfnote(tok, lineno); 131 | pfcnt = YES; 132 | } 133 | /*NOTREACHED*/ 134 | } 135 | 136 | /* 137 | * cicmp -- 138 | * do case-independent strcmp 139 | */ 140 | int 141 | cicmp(const char *cp) 142 | { 143 | int len; 144 | char *bp; 145 | 146 | for (len = 0, bp = lbp; *cp && (*cp &~ ' ') == (*bp++ &~ ' '); 147 | ++cp, ++len) 148 | continue; 149 | if (!*cp) { 150 | lbp += len; 151 | return (YES); 152 | } 153 | return (NO); 154 | } 155 | 156 | static void 157 | takeprec(void) 158 | { 159 | for (; isspace(*lbp); ++lbp) 160 | continue; 161 | if (*lbp == '*') { 162 | for (++lbp; isspace(*lbp); ++lbp) 163 | continue; 164 | if (!isdigit(*lbp)) 165 | --lbp; /* force failure */ 166 | else 167 | while (isdigit(*++lbp)) 168 | continue; 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /ctags/lisp.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | * 4 | * Copyright (c) 1987, 1993, 1994 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #if 0 33 | #ifndef lint 34 | static char sccsid[] = "@(#)lisp.c 8.3 (Berkeley) 4/2/94"; 35 | #endif 36 | #endif 37 | 38 | #include 39 | __FBSDID("$FreeBSD$"); 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include "ctags.h" 47 | 48 | /* 49 | * lisp tag functions 50 | * just look for (def or (DEF 51 | */ 52 | void 53 | l_entries(void) 54 | { 55 | int special; 56 | char *cp; 57 | char savedc; 58 | char tok[MAXTOKEN]; 59 | 60 | for (;;) { 61 | lineftell = ftell(inf); 62 | if (!fgets(lbuf, sizeof(lbuf), inf)) 63 | return; 64 | ++lineno; 65 | lbp = lbuf; 66 | if (!cicmp("(def")) 67 | continue; 68 | special = NO; 69 | switch(*lbp | ' ') { 70 | case 'm': 71 | if (cicmp("method")) 72 | special = YES; 73 | break; 74 | case 'w': 75 | if (cicmp("wrapper") || cicmp("whopper")) 76 | special = YES; 77 | } 78 | for (; !isspace(*lbp); ++lbp) 79 | continue; 80 | for (; isspace(*lbp); ++lbp) 81 | continue; 82 | for (cp = lbp; *cp && *cp != '\n'; ++cp) 83 | continue; 84 | *cp = EOS; 85 | if (special) { 86 | if (!(cp = strchr(lbp, ')'))) 87 | continue; 88 | for (; cp >= lbp && *cp != ':'; --cp) 89 | continue; 90 | if (cp < lbp) 91 | continue; 92 | lbp = cp; 93 | for (; *cp && *cp != ')' && *cp != ' '; ++cp) 94 | continue; 95 | } 96 | else 97 | for (cp = lbp + 1; 98 | *cp && *cp != '(' && *cp != ' '; ++cp) 99 | continue; 100 | savedc = *cp; 101 | *cp = EOS; 102 | (void)strlcpy(tok, lbp, sizeof(tok)); /* possible trunc */ 103 | *cp = savedc; 104 | get_line(); 105 | pfnote(tok, lineno); 106 | } 107 | /*NOTREACHED*/ 108 | } 109 | -------------------------------------------------------------------------------- /ctags/print.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | * 4 | * Copyright (c) 1987, 1993, 1994 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #if 0 33 | #ifndef lint 34 | static char sccsid[] = "@(#)print.c 8.3 (Berkeley) 4/2/94"; 35 | #endif 36 | #endif 37 | 38 | #include 39 | __FBSDID("$FreeBSD$"); 40 | 41 | #include 42 | #include 43 | #include 44 | 45 | #include "ctags.h" 46 | 47 | /* 48 | * get_line -- 49 | * get the line the token of interest occurred on, 50 | * prepare it for printing. 51 | */ 52 | void 53 | get_line(void) 54 | { 55 | long saveftell; 56 | int c; 57 | int cnt; 58 | char *cp; 59 | 60 | saveftell = ftell(inf); 61 | (void)fseek(inf, lineftell, L_SET); 62 | if (xflag) 63 | for (cp = lbuf; GETC(!=, EOF) && c != '\n'; *cp++ = c) 64 | continue; 65 | /* 66 | * do all processing here, so we don't step through the 67 | * line more than once; means you don't call this routine 68 | * unless you're sure you've got a keeper. 69 | */ 70 | else for (cnt = 0, cp = lbuf; GETC(!=, EOF) && cnt < ENDLINE; ++cnt) { 71 | if (c == '\\') { /* backslashes */ 72 | if (cnt > ENDLINE - 2) 73 | break; 74 | *cp++ = '\\'; *cp++ = '\\'; 75 | ++cnt; 76 | } 77 | else if (c == (int)searchar) { /* search character */ 78 | if (cnt > ENDLINE - 2) 79 | break; 80 | *cp++ = '\\'; *cp++ = c; 81 | ++cnt; 82 | } 83 | else if (c == '\n') { /* end of keep */ 84 | *cp++ = '$'; /* can find whole line */ 85 | break; 86 | } 87 | else 88 | *cp++ = c; 89 | } 90 | *cp = EOS; 91 | (void)fseek(inf, saveftell, L_SET); 92 | } 93 | 94 | /* 95 | * put_entries -- 96 | * write out the tags 97 | */ 98 | void 99 | put_entries(NODE *node) 100 | { 101 | 102 | if (node->left) 103 | put_entries(node->left); 104 | if (vflag) 105 | printf("%s %s %d\n", 106 | node->entry, node->file, (node->lno + 63) / 64); 107 | else if (xflag) 108 | printf("%-16s %4d %-16s %s\n", 109 | node->entry, node->lno, node->file, node->pat); 110 | else 111 | fprintf(outf, "%s\t%s\t%c^%s%c\n", 112 | node->entry, node->file, searchar, node->pat, searchar); 113 | if (node->right) 114 | put_entries(node->right); 115 | } 116 | -------------------------------------------------------------------------------- /ctags/test/ctags.test: -------------------------------------------------------------------------------- 1 | int bar = (1 + 5); 2 | 3 | FOO("here is a #define test: ) {"); 4 | char sysent[20]; 5 | int nsysent = sizeof (sysent) / sizeof (sysent[0]); 6 | /* 7 | * now is the time for a comment. 8 | * four lines in length... 9 | */struct struct_xtra{int list;};r4(x,y){};typedef struct{int bar;}struct_xxe; 10 | #define FOO BAR 11 | struct struct_three { 12 | int list; 13 | }; 14 | #define SINGLE 15 | int BAD(); 16 | enum color {red, green, gold, brown}; 17 | char qq[] = " quote(one,two) {int bar;} "; 18 | typedef struct { 19 | int bar; 20 | struct struct_two { 21 | int foo; 22 | union union_3 { 23 | struct struct_three entry; 24 | char size[25]; 25 | }; 26 | struct last { 27 | struct struct_three xentry; 28 | char list[34]; 29 | }; 30 | }; 31 | } struct_one; 32 | #define TWOLINE ((MAXLIST + FUTURE + 15) \ 33 | / (time_to_live ? 3 : 4)) 34 | #if (defined(BAR)) 35 | int bar; 36 | #endif 37 | #define MULTIPLE {\ 38 | multiple(one,two); \ 39 | lineno++; \ 40 | callroute(one,two); \ 41 | } 42 | #if defined(BAR) 43 | int bar; 44 | #endif 45 | union union_one { 46 | struct struct_three s3; 47 | char foo[25]; 48 | }; 49 | #define XYZ(A,B) (A + B / 2) * (3 - 26 + l_lineno) 50 | routine1(one,two) /* comments here are fun... */ 51 | struct { 52 | int entry; 53 | char bar[34]; 54 | } *one; 55 | char two[10]; 56 | { 57 | typedef unsigned char u_char; 58 | register struct buf *bp; 59 | five(one,two); 60 | } 61 | routine2 (one,two) { puts("hello\n"); } 62 | routine3 63 | (one, 64 | two) { puts("world\n"); } 65 | routine4(int one, char (*two)(void)) /* test ANSI arguments */ 66 | { 67 | } 68 | -------------------------------------------------------------------------------- /ctags/tree.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | * 4 | * Copyright (c) 1987, 1993, 1994 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #if 0 33 | #ifndef lint 34 | static char sccsid[] = "@(#)tree.c 8.3 (Berkeley) 4/2/94"; 35 | #endif 36 | #endif 37 | 38 | #include 39 | __FBSDID("$FreeBSD$"); 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #include "ctags.h" 48 | 49 | static void add_node(NODE *, NODE *); 50 | static void free_tree(NODE *); 51 | 52 | /* 53 | * pfnote -- 54 | * enter a new node in the tree 55 | */ 56 | void 57 | pfnote(const char *name, int ln) 58 | { 59 | NODE *np; 60 | char *fp; 61 | char nbuf[MAXTOKEN]; 62 | 63 | /*NOSTRICT*/ 64 | if (!(np = (NODE *)malloc(sizeof(NODE)))) { 65 | warnx("too many entries to sort"); 66 | put_entries(head); 67 | free_tree(head); 68 | /*NOSTRICT*/ 69 | if (!(head = np = (NODE *)malloc(sizeof(NODE)))) 70 | errx(1, "out of space"); 71 | } 72 | if (!xflag && !strcmp(name, "main")) { 73 | if (!(fp = strrchr(curfile, '/'))) 74 | fp = curfile; 75 | else 76 | ++fp; 77 | (void)snprintf(nbuf, sizeof(nbuf), "M%s", fp); 78 | fp = strrchr(nbuf, '.'); 79 | if (fp && !fp[2]) 80 | *fp = EOS; 81 | name = nbuf; 82 | } 83 | if (!(np->entry = strdup(name))) 84 | err(1, NULL); 85 | np->file = curfile; 86 | np->lno = ln; 87 | np->left = np->right = 0; 88 | if (!(np->pat = strdup(lbuf))) 89 | err(1, NULL); 90 | if (!head) 91 | head = np; 92 | else 93 | add_node(np, head); 94 | } 95 | 96 | static void 97 | add_node(NODE *node, NODE *cur_node) 98 | { 99 | int dif; 100 | 101 | dif = strcoll(node->entry, cur_node->entry); 102 | if (!dif) { 103 | if (node->file == cur_node->file) { 104 | if (!wflag) 105 | fprintf(stderr, "Duplicate entry in file %s, line %d: %s\nSecond entry ignored\n", node->file, lineno, node->entry); 106 | return; 107 | } 108 | if (!cur_node->been_warned) 109 | if (!wflag) 110 | fprintf(stderr, "Duplicate entry in files %s and %s: %s (Warning only)\n", node->file, cur_node->file, node->entry); 111 | cur_node->been_warned = YES; 112 | } 113 | else if (dif < 0) 114 | if (cur_node->left) 115 | add_node(node, cur_node->left); 116 | else 117 | cur_node->left = node; 118 | else if (cur_node->right) 119 | add_node(node, cur_node->right); 120 | else 121 | cur_node->right = node; 122 | } 123 | 124 | static void 125 | free_tree(NODE *node) 126 | { 127 | NODE *node_next; 128 | while (node) { 129 | if (node->right) 130 | free_tree(node->right); 131 | node_next = node->left; 132 | free(node); 133 | node = node_next; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /ctags/yacc.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | * 4 | * Copyright (c) 1987, 1993, 1994 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #if 0 33 | #ifndef lint 34 | static char sccsid[] = "@(#)yacc.c 8.3 (Berkeley) 4/2/94"; 35 | #endif 36 | #endif 37 | 38 | #include 39 | __FBSDID("$FreeBSD$"); 40 | 41 | #include 42 | #include 43 | #include 44 | 45 | #include "ctags.h" 46 | 47 | /* 48 | * y_entries: 49 | * find the yacc tags and put them in. 50 | */ 51 | void 52 | y_entries(void) 53 | { 54 | int c; 55 | char *sp; 56 | bool in_rule; 57 | char tok[MAXTOKEN]; 58 | 59 | in_rule = NO; 60 | 61 | while (GETC(!=, EOF)) 62 | switch (c) { 63 | case '\n': 64 | SETLINE; 65 | /* FALLTHROUGH */ 66 | case ' ': 67 | case '\f': 68 | case '\r': 69 | case '\t': 70 | break; 71 | case '{': 72 | if (skip_key('}')) 73 | in_rule = NO; 74 | break; 75 | case '\'': 76 | case '"': 77 | if (skip_key(c)) 78 | in_rule = NO; 79 | break; 80 | case '%': 81 | if (GETC(==, '%')) 82 | return; 83 | (void)ungetc(c, inf); 84 | break; 85 | case '/': 86 | if (GETC(==, '*') || c == '/') 87 | skip_comment(c); 88 | else 89 | (void)ungetc(c, inf); 90 | break; 91 | case '|': 92 | case ';': 93 | in_rule = NO; 94 | break; 95 | default: 96 | if (in_rule || (!isalpha(c) && c != '.' && c != '_')) 97 | break; 98 | sp = tok; 99 | *sp++ = c; 100 | while (GETC(!=, EOF) && (intoken(c) || c == '.')) 101 | *sp++ = c; 102 | *sp = EOS; 103 | get_line(); /* may change before ':' */ 104 | while (iswhite(c)) { 105 | if (c == '\n') 106 | SETLINE; 107 | if (GETC(==, EOF)) 108 | return; 109 | } 110 | if (c == ':') { 111 | pfnote(tok, lineno); 112 | in_rule = YES; 113 | } 114 | else 115 | (void)ungetc(c, inf); 116 | } 117 | } 118 | 119 | /* 120 | * toss_yysec -- 121 | * throw away lines up to the next "\n%%\n" 122 | */ 123 | void 124 | toss_yysec(void) 125 | { 126 | int c; /* read character */ 127 | int state; 128 | 129 | /* 130 | * state == 0 : waiting 131 | * state == 1 : received a newline 132 | * state == 2 : received first % 133 | * state == 3 : received second % 134 | */ 135 | lineftell = ftell(inf); 136 | for (state = 0; GETC(!=, EOF);) 137 | switch (c) { 138 | case '\n': 139 | ++lineno; 140 | lineftell = ftell(inf); 141 | if (state == 3) /* done! */ 142 | return; 143 | state = 1; /* start over */ 144 | break; 145 | case '%': 146 | if (state) /* if 1 or 2 */ 147 | ++state; /* goto 3 */ 148 | break; 149 | default: 150 | state = 0; /* reset */ 151 | break; 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /developer_cmds.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /indent/README: -------------------------------------------------------------------------------- 1 | 2 | $FreeBSD$ 3 | 4 | This is the C indenter, it originally came from the University of Illinois 5 | via some distribution tape for PDP-11 Unix. It has subsequently been 6 | hacked upon by James Gosling @ CMU. It isn't very pretty, and really needs 7 | to be completely redone, but it is probably the nicest C pretty printer 8 | around. 9 | 10 | Further additions to provide "Kernel Normal Form" were contributed 11 | by the folks at Sun Microsystems. 12 | 13 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 14 | > From mnetor!yunexus!oz@uunet.UU.NET Wed Mar 9 15:30:55 1988 15 | > Date: Tue, 8 Mar 88 18:36:25 EST 16 | > From: yunexus!oz@uunet.UU.NET (Ozan Yigit) 17 | > To: bostic@okeeffe.berkeley.edu 18 | > Cc: ccvaxa!willcox@uunet.UU.NET, jag@sun.com, rsalz@uunet.UU.NET 19 | > In-Reply-To: Keith Bostic's message of Tue, 16 Feb 88 16:09:06 PST 20 | > Subject: Re: Indent... 21 | 22 | Thank you for your response about indent. I was wrong in my original 23 | observation (or mis-observation :-). UCB did keep the Illinois 24 | copyright intact. 25 | 26 | The issue still is whether we can distribute indent, and if we can, which 27 | version. David Willcox (the author) states that: 28 | 29 | | Several people have asked me on what basis I claim that indent is in 30 | | the public domain. I knew I would be sorry I made that posting. 31 | | 32 | | Some history. Way back in 1976, the project I worked on at the 33 | | University of Illinois Center for Advanced Computation had a huge 34 | | battle about how to format C code. After about a week of fighting, I 35 | | got disgusted and wrote a program, which I called indent, to reformat C 36 | | code. It had a bunch of different options that would let you format 37 | | the output the way you liked. In particular, all of the different 38 | | formats being championed were supported. 39 | | 40 | | It was my first big C program. It was ugly. It wasn't designed, it 41 | | just sort of grew. But it pretty much worked, and it stopped most of 42 | | the fighting. 43 | | 44 | | As a matter of form, I included a University of Illinois Copyright 45 | | notice. However, my understanding was that, since the work was done 46 | | on an ARPA contract, it was in the public domain. 47 | | 48 | | Time passed. Some years later, indent showed up on one of the early 49 | | emacs distributions. 50 | | 51 | | Later still, someone from UC Berkeley called the UofI and asked if 52 | | indent was in the public domain. They wanted to include it in their 53 | | UNIX distributions, along with the emacs stuff. I was no longer at the 54 | | UofI, but Rob Kolstad, who was, asked me about it. I told him I didn't 55 | | care if they used it, and since then it has been on the BSD distributions. 56 | | 57 | | Somewhere along the way, several other unnamed people have had their 58 | | hands in it. It was converted to understand version 7 C. (The 59 | | original was version 6.) It was converted from its original filter 60 | | interface to its current "blow away the user's file" interface. 61 | | The $HOME/.indent.pro file parsing was added. Some more formatting 62 | | options were added. 63 | | 64 | | The source I have right now has two copyright notices. One is the 65 | | original from the UofI. One is from Berkeley. 66 | | 67 | | I am not a lawyer, and I certainly do not understand copyright law. As 68 | | far as I am concerned, the bulk of this program, everything covered by 69 | | the UofI copyright, is in the public domain, and worth every penny. 70 | | Berkeley's copyright probably should only cover their changes, and I 71 | | don't know their feelings about sending it out. 72 | 73 | In any case, there appears to be none at UofI to clarify/and change 74 | that copyright, but I am confident (based on the statements of its 75 | author) that the code, as it stands with its copyright, is 76 | distributable, and will not cause any legal problems. 77 | 78 | Hence, the issue reduces to *which* one to distribute through 79 | comp.sources.unix. I would suggest that with the permission of you 80 | folks (given that you have parts copyrighted), we distribute the 4.3 81 | version of indent, which appears to be the most up-to-date version. I 82 | happen to have just about every known version of indent, including the 83 | very original submission from the author to a unix tape, later the 84 | G-Emacs version, any 4.n version, sun version and the Unipress 85 | version. I still think we should not have to "go-back-in-time" and 86 | re-do all the work you people have done. 87 | 88 | I hope to hear from you as to what you think about this. You may of 89 | course send 4.3 version to the moderator directly, or you can let me 90 | know of your permission, and I will send the sources, or you can let 91 | me know that 4.3 version is off-limits, in which case we would probably 92 | have to revert to an older version. One way or another, I hope to get 93 | a version of indent to comp.sources.unix. 94 | 95 | regards.. oz 96 | 97 | cc: ccvaxa!willcox 98 | sun.com!jar 99 | uunet!rsalz 100 | 101 | -------------------------------------------------------------------------------- /indent/args.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-4-Clause 3 | * 4 | * Copyright (c) 1985 Sun Microsystems, Inc. 5 | * Copyright (c) 1980, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. All advertising materials mentioning features or use of this software 18 | * must display the following acknowledgement: 19 | * This product includes software developed by the University of 20 | * California, Berkeley and its contributors. 21 | * 4. Neither the name of the University nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 | * SUCH DAMAGE. 36 | */ 37 | 38 | #if 0 39 | #ifndef lint 40 | static char sccsid[] = "@(#)args.c 8.1 (Berkeley) 6/6/93"; 41 | #endif /* not lint */ 42 | #endif 43 | 44 | #include 45 | __FBSDID("$FreeBSD$"); 46 | 47 | /* 48 | * Argument scanning and profile reading code. Default parameters are set 49 | * here as well. 50 | */ 51 | 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include "indent_globs.h" 59 | #include "indent.h" 60 | 61 | #define INDENT_VERSION "2.0" 62 | 63 | /* profile types */ 64 | #define PRO_SPECIAL 1 /* special case */ 65 | #define PRO_BOOL 2 /* boolean */ 66 | #define PRO_INT 3 /* integer */ 67 | 68 | /* profile specials for booleans */ 69 | #define ON 1 /* turn it on */ 70 | #define OFF 0 /* turn it off */ 71 | 72 | /* profile specials for specials */ 73 | #define IGN 1 /* ignore it */ 74 | #define CLI 2 /* case label indent (float) */ 75 | #define STDIN 3 /* use stdin */ 76 | #define KEY 4 /* type (keyword) */ 77 | 78 | static void scan_profile(FILE *); 79 | 80 | #define KEY_FILE 5 /* only used for args */ 81 | #define VERSION 6 /* only used for args */ 82 | 83 | const char *option_source = "?"; 84 | 85 | void add_typedefs_from_file(const char *str); 86 | 87 | /* 88 | * N.B.: because of the way the table here is scanned, options whose names are 89 | * substrings of other options must occur later; that is, with -lp vs -l, -lp 90 | * must be first. Also, while (most) booleans occur more than once, the last 91 | * default value is the one actually assigned. 92 | */ 93 | struct pro { 94 | const char *p_name; /* name, e.g. -bl, -cli */ 95 | int p_type; /* type (int, bool, special) */ 96 | int p_default; /* the default value (if int) */ 97 | int p_special; /* depends on type */ 98 | int *p_obj; /* the associated variable */ 99 | } pro[] = { 100 | 101 | {"T", PRO_SPECIAL, 0, KEY, 0}, 102 | {"U", PRO_SPECIAL, 0, KEY_FILE, 0}, 103 | {"-version", PRO_SPECIAL, 0, VERSION, 0}, 104 | {"P", PRO_SPECIAL, 0, IGN, 0}, 105 | {"bacc", PRO_BOOL, false, ON, &opt.blanklines_around_conditional_compilation}, 106 | {"badp", PRO_BOOL, false, ON, &opt.blanklines_after_declarations_at_proctop}, 107 | {"bad", PRO_BOOL, false, ON, &opt.blanklines_after_declarations}, 108 | {"bap", PRO_BOOL, false, ON, &opt.blanklines_after_procs}, 109 | {"bbb", PRO_BOOL, false, ON, &opt.blanklines_before_blockcomments}, 110 | {"bc", PRO_BOOL, true, OFF, &opt.leave_comma}, 111 | {"bl", PRO_BOOL, true, OFF, &opt.btype_2}, 112 | {"br", PRO_BOOL, true, ON, &opt.btype_2}, 113 | {"bs", PRO_BOOL, false, ON, &opt.Bill_Shannon}, 114 | {"cdb", PRO_BOOL, true, ON, &opt.comment_delimiter_on_blankline}, 115 | {"cd", PRO_INT, 0, 0, &opt.decl_com_ind}, 116 | {"ce", PRO_BOOL, true, ON, &opt.cuddle_else}, 117 | {"ci", PRO_INT, 0, 0, &opt.continuation_indent}, 118 | {"cli", PRO_SPECIAL, 0, CLI, 0}, 119 | {"cs", PRO_BOOL, false, ON, &opt.space_after_cast}, 120 | {"c", PRO_INT, 33, 0, &opt.com_ind}, 121 | {"di", PRO_INT, 16, 0, &opt.decl_indent}, 122 | {"dj", PRO_BOOL, false, ON, &opt.ljust_decl}, 123 | {"d", PRO_INT, 0, 0, &opt.unindent_displace}, 124 | {"eei", PRO_BOOL, false, ON, &opt.extra_expression_indent}, 125 | {"ei", PRO_BOOL, true, ON, &opt.else_if}, 126 | {"fbs", PRO_BOOL, true, ON, &opt.function_brace_split}, 127 | {"fc1", PRO_BOOL, true, ON, &opt.format_col1_comments}, 128 | {"fcb", PRO_BOOL, true, ON, &opt.format_block_comments}, 129 | {"ip", PRO_BOOL, true, ON, &opt.indent_parameters}, 130 | {"i", PRO_INT, 8, 0, &opt.ind_size}, 131 | {"lc", PRO_INT, 0, 0, &opt.block_comment_max_col}, 132 | {"ldi", PRO_INT, -1, 0, &opt.local_decl_indent}, 133 | {"lpl", PRO_BOOL, false, ON, &opt.lineup_to_parens_always}, 134 | {"lp", PRO_BOOL, true, ON, &opt.lineup_to_parens}, 135 | {"l", PRO_INT, 78, 0, &opt.max_col}, 136 | {"nbacc", PRO_BOOL, false, OFF, &opt.blanklines_around_conditional_compilation}, 137 | {"nbadp", PRO_BOOL, false, OFF, &opt.blanklines_after_declarations_at_proctop}, 138 | {"nbad", PRO_BOOL, false, OFF, &opt.blanklines_after_declarations}, 139 | {"nbap", PRO_BOOL, false, OFF, &opt.blanklines_after_procs}, 140 | {"nbbb", PRO_BOOL, false, OFF, &opt.blanklines_before_blockcomments}, 141 | {"nbc", PRO_BOOL, true, ON, &opt.leave_comma}, 142 | {"nbs", PRO_BOOL, false, OFF, &opt.Bill_Shannon}, 143 | {"ncdb", PRO_BOOL, true, OFF, &opt.comment_delimiter_on_blankline}, 144 | {"nce", PRO_BOOL, true, OFF, &opt.cuddle_else}, 145 | {"ncs", PRO_BOOL, false, OFF, &opt.space_after_cast}, 146 | {"ndj", PRO_BOOL, false, OFF, &opt.ljust_decl}, 147 | {"neei", PRO_BOOL, false, OFF, &opt.extra_expression_indent}, 148 | {"nei", PRO_BOOL, true, OFF, &opt.else_if}, 149 | {"nfbs", PRO_BOOL, true, OFF, &opt.function_brace_split}, 150 | {"nfc1", PRO_BOOL, true, OFF, &opt.format_col1_comments}, 151 | {"nfcb", PRO_BOOL, true, OFF, &opt.format_block_comments}, 152 | {"nip", PRO_BOOL, true, OFF, &opt.indent_parameters}, 153 | {"nlpl", PRO_BOOL, false, OFF, &opt.lineup_to_parens_always}, 154 | {"nlp", PRO_BOOL, true, OFF, &opt.lineup_to_parens}, 155 | {"npcs", PRO_BOOL, false, OFF, &opt.proc_calls_space}, 156 | {"npro", PRO_SPECIAL, 0, IGN, 0}, 157 | {"npsl", PRO_BOOL, true, OFF, &opt.procnames_start_line}, 158 | {"nps", PRO_BOOL, false, OFF, &opt.pointer_as_binop}, 159 | {"nsc", PRO_BOOL, true, OFF, &opt.star_comment_cont}, 160 | {"nsob", PRO_BOOL, false, OFF, &opt.swallow_optional_blanklines}, 161 | {"nut", PRO_BOOL, true, OFF, &opt.use_tabs}, 162 | {"nv", PRO_BOOL, false, OFF, &opt.verbose}, 163 | {"pcs", PRO_BOOL, false, ON, &opt.proc_calls_space}, 164 | {"psl", PRO_BOOL, true, ON, &opt.procnames_start_line}, 165 | {"ps", PRO_BOOL, false, ON, &opt.pointer_as_binop}, 166 | {"sc", PRO_BOOL, true, ON, &opt.star_comment_cont}, 167 | {"sob", PRO_BOOL, false, ON, &opt.swallow_optional_blanklines}, 168 | {"st", PRO_SPECIAL, 0, STDIN, 0}, 169 | {"ta", PRO_BOOL, false, ON, &opt.auto_typedefs}, 170 | {"ts", PRO_INT, 8, 0, &opt.tabsize}, 171 | {"ut", PRO_BOOL, true, ON, &opt.use_tabs}, 172 | {"v", PRO_BOOL, false, ON, &opt.verbose}, 173 | /* whew! */ 174 | {0, 0, 0, 0, 0} 175 | }; 176 | 177 | /* 178 | * set_profile reads $HOME/.indent.pro and ./.indent.pro and handles arguments 179 | * given in these files. 180 | */ 181 | void 182 | set_profile(const char *profile_name) 183 | { 184 | FILE *f; 185 | char fname[PATH_MAX]; 186 | static char prof[] = ".indent.pro"; 187 | 188 | if (profile_name == NULL) 189 | snprintf(fname, sizeof(fname), "%s/%s", getenv("HOME"), prof); 190 | else 191 | snprintf(fname, sizeof(fname), "%s", profile_name + 2); 192 | if ((f = fopen(option_source = fname, "r")) != NULL) { 193 | scan_profile(f); 194 | (void) fclose(f); 195 | } 196 | if ((f = fopen(option_source = prof, "r")) != NULL) { 197 | scan_profile(f); 198 | (void) fclose(f); 199 | } 200 | option_source = "Command line"; 201 | } 202 | 203 | static void 204 | scan_profile(FILE *f) 205 | { 206 | int comment, i; 207 | char *p; 208 | char buf[BUFSIZ]; 209 | 210 | while (1) { 211 | p = buf; 212 | comment = 0; 213 | while ((i = getc(f)) != EOF) { 214 | if (i == '*' && !comment && p > buf && p[-1] == '/') { 215 | comment = p - buf; 216 | *p++ = i; 217 | } else if (i == '/' && comment && p > buf && p[-1] == '*') { 218 | p = buf + comment - 1; 219 | comment = 0; 220 | } else if (isspace((unsigned char)i)) { 221 | if (p > buf && !comment) 222 | break; 223 | } else { 224 | *p++ = i; 225 | } 226 | } 227 | if (p != buf) { 228 | *p++ = 0; 229 | if (opt.verbose) 230 | printf("profile: %s\n", buf); 231 | set_option(buf); 232 | } 233 | else if (i == EOF) 234 | return; 235 | } 236 | } 237 | 238 | static const char * 239 | eqin(const char *s1, const char *s2) 240 | { 241 | while (*s1) { 242 | if (*s1++ != *s2++) 243 | return (NULL); 244 | } 245 | return (s2); 246 | } 247 | 248 | /* 249 | * Set the defaults. 250 | */ 251 | void 252 | set_defaults(void) 253 | { 254 | struct pro *p; 255 | 256 | /* 257 | * Because ps.case_indent is a float, we can't initialize it from the 258 | * table: 259 | */ 260 | opt.case_indent = 0.0; /* -cli0.0 */ 261 | for (p = pro; p->p_name; p++) 262 | if (p->p_type != PRO_SPECIAL) 263 | *p->p_obj = p->p_default; 264 | } 265 | 266 | void 267 | set_option(char *arg) 268 | { 269 | struct pro *p; 270 | const char *param_start; 271 | 272 | arg++; /* ignore leading "-" */ 273 | for (p = pro; p->p_name; p++) 274 | if (*p->p_name == *arg && (param_start = eqin(p->p_name, arg)) != NULL) 275 | goto found; 276 | errx(1, "%s: unknown parameter \"%s\"", option_source, arg - 1); 277 | found: 278 | switch (p->p_type) { 279 | 280 | case PRO_SPECIAL: 281 | switch (p->p_special) { 282 | 283 | case IGN: 284 | break; 285 | 286 | case CLI: 287 | if (*param_start == 0) 288 | goto need_param; 289 | opt.case_indent = atof(param_start); 290 | break; 291 | 292 | case STDIN: 293 | if (input == NULL) 294 | input = stdin; 295 | if (output == NULL) 296 | output = stdout; 297 | break; 298 | 299 | case KEY: 300 | if (*param_start == 0) 301 | goto need_param; 302 | add_typename(param_start); 303 | break; 304 | 305 | case KEY_FILE: 306 | if (*param_start == 0) 307 | goto need_param; 308 | add_typedefs_from_file(param_start); 309 | break; 310 | 311 | case VERSION: 312 | printf("FreeBSD indent %s\n", INDENT_VERSION); 313 | exit(0); 314 | 315 | default: 316 | errx(1, "set_option: internal error: p_special %d", p->p_special); 317 | } 318 | break; 319 | 320 | case PRO_BOOL: 321 | if (p->p_special == OFF) 322 | *p->p_obj = false; 323 | else 324 | *p->p_obj = true; 325 | break; 326 | 327 | case PRO_INT: 328 | if (!isdigit((unsigned char)*param_start)) { 329 | need_param: 330 | errx(1, "%s: ``%s'' requires a parameter", option_source, p->p_name); 331 | } 332 | *p->p_obj = atoi(param_start); 333 | break; 334 | 335 | default: 336 | errx(1, "set_option: internal error: p_type %d", p->p_type); 337 | } 338 | } 339 | 340 | void 341 | add_typedefs_from_file(const char *str) 342 | { 343 | FILE *file; 344 | char line[BUFSIZ]; 345 | 346 | if ((file = fopen(str, "r")) == NULL) { 347 | fprintf(stderr, "indent: cannot open file %s\n", str); 348 | exit(1); 349 | } 350 | while ((fgets(line, BUFSIZ, file)) != NULL) { 351 | /* Remove trailing whitespace */ 352 | line[strcspn(line, " \t\n\r")] = '\0'; 353 | add_typename(line); 354 | } 355 | fclose(file); 356 | } 357 | -------------------------------------------------------------------------------- /indent/indent.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-2-Clause 3 | * 4 | * Copyright (c) 2001 Jens Schweikhardt 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | * SUCH DAMAGE. 27 | */ 28 | 29 | #if 0 30 | __FBSDID("$FreeBSD$"); 31 | #endif 32 | 33 | void add_typename(const char *); 34 | void alloc_typenames(void); 35 | int compute_code_target(void); 36 | int compute_label_target(void); 37 | int count_spaces(int, char *); 38 | int count_spaces_until(int, char *, char *); 39 | void init_constant_tt(void); 40 | int lexi(struct parser_state *); 41 | void diag2(int, const char *); 42 | void diag3(int, const char *, int); 43 | void diag4(int, const char *, int, int); 44 | void dump_line(void); 45 | void fill_buffer(void); 46 | void parse(int); 47 | void pr_comment(void); 48 | void set_defaults(void); 49 | void set_option(char *); 50 | void set_profile(const char *); 51 | -------------------------------------------------------------------------------- /indent/indent.plist.part: -------------------------------------------------------------------------------- 1 | 2 | OpenSourceProject 3 | indent 4 | OpenSourceVersion 5 | 2023-06-29 6 | OpenSourceWebsiteURL 7 | https://cgit.freebsd.org/src/commit/usr.bin/indent?id=b5b9eaa96274a9c40b06999cadc777c8aeb71d09 8 | OpenSourceImportDate 9 | 2023-06-29 10 | OpenSourceLicense 11 | BSD 12 | 13 | 14 | -------------------------------------------------------------------------------- /indent/indent_codes.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-4-Clause 3 | * 4 | * Copyright (c) 1985 Sun Microsystems, Inc. 5 | * Copyright (c) 1980, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. All advertising materials mentioning features or use of this software 18 | * must display the following acknowledgement: 19 | * This product includes software developed by the University of 20 | * California, Berkeley and its contributors. 21 | * 4. Neither the name of the University nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 | * SUCH DAMAGE. 36 | * 37 | * @(#)indent_codes.h 8.1 (Berkeley) 6/6/93 38 | * $FreeBSD$ 39 | */ 40 | 41 | #define newline 1 42 | #define lparen 2 43 | #define rparen 3 44 | #define unary_op 4 45 | #define binary_op 5 46 | #define postop 6 47 | #define question 7 48 | #define casestmt 8 49 | #define colon 9 50 | #define semicolon 10 51 | #define lbrace 11 52 | #define rbrace 12 53 | #define ident 13 54 | #define comma 14 55 | #define comment 15 56 | #define swstmt 16 57 | #define preesc 17 58 | #define form_feed 18 59 | #define decl 19 60 | #define sp_paren 20 61 | #define sp_nparen 21 62 | #define ifstmt 22 63 | #define whilestmt 23 64 | #define forstmt 24 65 | #define stmt 25 66 | #define stmtl 26 67 | #define elselit 27 68 | #define dolit 28 69 | #define dohead 29 70 | #define ifhead 30 71 | #define elsehead 31 72 | #define period 32 73 | #define strpfx 33 74 | #define storage 34 75 | #define funcname 35 76 | #define type_def 36 77 | #define structure 37 78 | -------------------------------------------------------------------------------- /indent/parse.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-4-Clause 3 | * 4 | * Copyright (c) 1985 Sun Microsystems, Inc. 5 | * Copyright (c) 1980, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. All advertising materials mentioning features or use of this software 18 | * must display the following acknowledgement: 19 | * This product includes software developed by the University of 20 | * California, Berkeley and its contributors. 21 | * 4. Neither the name of the University nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 | * SUCH DAMAGE. 36 | */ 37 | 38 | #if 0 39 | #ifndef lint 40 | static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/6/93"; 41 | #endif /* not lint */ 42 | #endif 43 | 44 | #include 45 | __FBSDID("$FreeBSD$"); 46 | 47 | #include 48 | #include 49 | #include "indent_globs.h" 50 | #include "indent_codes.h" 51 | #include "indent.h" 52 | 53 | /* Globals */ 54 | int break_comma; 55 | float case_ind; 56 | 57 | static void reduce(void); 58 | 59 | void 60 | parse(int tk) /* tk: the code for the construct scanned */ 61 | { 62 | int i; 63 | 64 | #ifdef debug 65 | printf("%2d - %s\n", tk, token); 66 | #endif 67 | 68 | while (ps.p_stack[ps.tos] == ifhead && tk != elselit) { 69 | /* true if we have an if without an else */ 70 | ps.p_stack[ps.tos] = stmt; /* apply the if(..) stmt ::= stmt 71 | * reduction */ 72 | reduce(); /* see if this allows any reduction */ 73 | } 74 | 75 | 76 | switch (tk) { /* go on and figure out what to do with the 77 | * input */ 78 | 79 | case decl: /* scanned a declaration word */ 80 | ps.search_brace = opt.btype_2; 81 | /* indicate that following brace should be on same line */ 82 | if (ps.p_stack[ps.tos] != decl) { /* only put one declaration 83 | * onto stack */ 84 | break_comma = true; /* while in declaration, newline should be 85 | * forced after comma */ 86 | ps.p_stack[++ps.tos] = decl; 87 | ps.il[ps.tos] = ps.i_l_follow; 88 | 89 | if (opt.ljust_decl) {/* only do if we want left justified 90 | * declarations */ 91 | ps.ind_level = 0; 92 | for (i = ps.tos - 1; i > 0; --i) 93 | if (ps.p_stack[i] == decl) 94 | ++ps.ind_level; /* indentation is number of 95 | * declaration levels deep we are */ 96 | ps.i_l_follow = ps.ind_level; 97 | } 98 | } 99 | break; 100 | 101 | case ifstmt: /* scanned if (...) */ 102 | if (ps.p_stack[ps.tos] == elsehead && opt.else_if) /* "else if ..." */ 103 | /* 104 | * Note that the stack pointer here is decremented, effectively 105 | * reducing "else if" to "if". This saves a lot of stack space 106 | * in case of a long "if-else-if ... else-if" sequence. 107 | */ 108 | ps.i_l_follow = ps.il[ps.tos--]; 109 | /* the rest is the same as for dolit and forstmt */ 110 | /* FALLTHROUGH */ 111 | case dolit: /* 'do' */ 112 | case forstmt: /* for (...) */ 113 | ps.p_stack[++ps.tos] = tk; 114 | ps.il[ps.tos] = ps.ind_level = ps.i_l_follow; 115 | ++ps.i_l_follow; /* subsequent statements should be indented 1 */ 116 | ps.search_brace = opt.btype_2; 117 | break; 118 | 119 | case lbrace: /* scanned { */ 120 | break_comma = false; /* don't break comma in an initial list */ 121 | if (ps.p_stack[ps.tos] == stmt || ps.p_stack[ps.tos] == decl 122 | || ps.p_stack[ps.tos] == stmtl) 123 | ++ps.i_l_follow; /* it is a random, isolated stmt group or a 124 | * declaration */ 125 | else { 126 | if (s_code == e_code) { 127 | /* 128 | * only do this if there is nothing on the line 129 | */ 130 | --ps.ind_level; 131 | /* 132 | * it is a group as part of a while, for, etc. 133 | */ 134 | if (ps.p_stack[ps.tos] == swstmt && opt.case_indent >= 1) 135 | --ps.ind_level; 136 | /* 137 | * for a switch, brace should be two levels out from the code 138 | */ 139 | } 140 | } 141 | 142 | ps.p_stack[++ps.tos] = lbrace; 143 | ps.il[ps.tos] = ps.ind_level; 144 | ps.p_stack[++ps.tos] = stmt; 145 | /* allow null stmt between braces */ 146 | ps.il[ps.tos] = ps.i_l_follow; 147 | break; 148 | 149 | case whilestmt: /* scanned while (...) */ 150 | if (ps.p_stack[ps.tos] == dohead) { 151 | /* it is matched with do stmt */ 152 | ps.ind_level = ps.i_l_follow = ps.il[ps.tos]; 153 | ps.p_stack[++ps.tos] = whilestmt; 154 | ps.il[ps.tos] = ps.ind_level = ps.i_l_follow; 155 | } 156 | else { /* it is a while loop */ 157 | ps.p_stack[++ps.tos] = whilestmt; 158 | ps.il[ps.tos] = ps.i_l_follow; 159 | ++ps.i_l_follow; 160 | ps.search_brace = opt.btype_2; 161 | } 162 | 163 | break; 164 | 165 | case elselit: /* scanned an else */ 166 | 167 | if (ps.p_stack[ps.tos] != ifhead) 168 | diag2(1, "Unmatched 'else'"); 169 | else { 170 | ps.ind_level = ps.il[ps.tos]; /* indentation for else should 171 | * be same as for if */ 172 | ps.i_l_follow = ps.ind_level + 1; /* everything following should 173 | * be in 1 level */ 174 | ps.p_stack[ps.tos] = elsehead; 175 | /* remember if with else */ 176 | ps.search_brace = opt.btype_2 | opt.else_if; 177 | } 178 | break; 179 | 180 | case rbrace: /* scanned a } */ 181 | /* stack should have or */ 182 | if (ps.tos > 0 && ps.p_stack[ps.tos - 1] == lbrace) { 183 | ps.ind_level = ps.i_l_follow = ps.il[--ps.tos]; 184 | ps.p_stack[ps.tos] = stmt; 185 | } 186 | else 187 | diag2(1, "Statement nesting error"); 188 | break; 189 | 190 | case swstmt: /* had switch (...) */ 191 | ps.p_stack[++ps.tos] = swstmt; 192 | ps.cstk[ps.tos] = case_ind; 193 | /* save current case indent level */ 194 | ps.il[ps.tos] = ps.i_l_follow; 195 | case_ind = ps.i_l_follow + opt.case_indent; /* cases should be one 196 | * level down from 197 | * switch */ 198 | ps.i_l_follow += opt.case_indent + 1; /* statements should be two 199 | * levels in */ 200 | ps.search_brace = opt.btype_2; 201 | break; 202 | 203 | case semicolon: /* this indicates a simple stmt */ 204 | break_comma = false; /* turn off flag to break after commas in a 205 | * declaration */ 206 | ps.p_stack[++ps.tos] = stmt; 207 | ps.il[ps.tos] = ps.ind_level; 208 | break; 209 | 210 | default: /* this is an error */ 211 | diag2(1, "Unknown code to parser"); 212 | return; 213 | 214 | 215 | } /* end of switch */ 216 | 217 | if (ps.tos >= STACKSIZE - 1) 218 | errx(1, "Parser stack overflow"); 219 | 220 | reduce(); /* see if any reduction can be done */ 221 | 222 | #ifdef debug 223 | for (i = 1; i <= ps.tos; ++i) 224 | printf("(%d %d)", ps.p_stack[i], ps.il[i]); 225 | printf("\n"); 226 | #endif 227 | 228 | return; 229 | } 230 | 231 | /* 232 | * NAME: reduce 233 | * 234 | * FUNCTION: Implements the reduce part of the parsing algorithm 235 | * 236 | * ALGORITHM: The following reductions are done. Reductions are repeated 237 | * until no more are possible. 238 | * 239 | * Old TOS New TOS 240 | * 241 | * 242 | * do "dostmt" 243 | * if "ifstmt" 244 | * switch 245 | * decl 246 | * "ifelse" 247 | * for 248 | * while 249 | * "dostmt" while 250 | * 251 | * On each reduction, ps.i_l_follow (the indentation for the following line) 252 | * is set to the indentation level associated with the old TOS. 253 | * 254 | * PARAMETERS: None 255 | * 256 | * RETURNS: Nothing 257 | * 258 | * GLOBALS: ps.cstk ps.i_l_follow = ps.il ps.p_stack = ps.tos = 259 | * 260 | * CALLS: None 261 | * 262 | * CALLED BY: parse 263 | * 264 | * HISTORY: initial coding November 1976 D A Willcox of CAC 265 | * 266 | */ 267 | /*----------------------------------------------*\ 268 | | REDUCTION PHASE | 269 | \*----------------------------------------------*/ 270 | static void 271 | reduce(void) 272 | { 273 | int i; 274 | 275 | for (;;) { /* keep looping until there is nothing left to 276 | * reduce */ 277 | 278 | switch (ps.p_stack[ps.tos]) { 279 | 280 | case stmt: 281 | switch (ps.p_stack[ps.tos - 1]) { 282 | 283 | case stmt: 284 | case stmtl: 285 | /* stmtl stmt or stmt stmt */ 286 | ps.p_stack[--ps.tos] = stmtl; 287 | break; 288 | 289 | case dolit: /* */ 290 | ps.p_stack[--ps.tos] = dohead; 291 | ps.i_l_follow = ps.il[ps.tos]; 292 | break; 293 | 294 | case ifstmt: 295 | /* */ 296 | ps.p_stack[--ps.tos] = ifhead; 297 | for (i = ps.tos - 1; 298 | ( 299 | ps.p_stack[i] != stmt 300 | && 301 | ps.p_stack[i] != stmtl 302 | && 303 | ps.p_stack[i] != lbrace 304 | ); 305 | --i); 306 | ps.i_l_follow = ps.il[i]; 307 | /* 308 | * for the time being, we will assume that there is no else on 309 | * this if, and set the indentation level accordingly. If an 310 | * else is scanned, it will be fixed up later 311 | */ 312 | break; 313 | 314 | case swstmt: 315 | /* */ 316 | case_ind = ps.cstk[ps.tos - 1]; 317 | /* FALLTHROUGH */ 318 | case decl: /* finish of a declaration */ 319 | case elsehead: 320 | /* < else> */ 321 | case forstmt: 322 | /* */ 323 | case whilestmt: 324 | /* */ 325 | ps.p_stack[--ps.tos] = stmt; 326 | ps.i_l_follow = ps.il[ps.tos]; 327 | break; 328 | 329 | default: /* */ 330 | return; 331 | 332 | } /* end of section for on top of stack */ 333 | break; 334 | 335 | case whilestmt: /* while (...) on top */ 336 | if (ps.p_stack[ps.tos - 1] == dohead) { 337 | /* it is termination of a do while */ 338 | ps.tos -= 2; 339 | break; 340 | } 341 | else 342 | return; 343 | 344 | default: /* anything else on top */ 345 | return; 346 | 347 | } 348 | } 349 | } 350 | -------------------------------------------------------------------------------- /indent/pr_comment.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-4-Clause 3 | * 4 | * Copyright (c) 1985 Sun Microsystems, Inc. 5 | * Copyright (c) 1980, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 3. All advertising materials mentioning features or use of this software 18 | * must display the following acknowledgement: 19 | * This product includes software developed by the University of 20 | * California, Berkeley and its contributors. 21 | * 4. Neither the name of the University nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 | * SUCH DAMAGE. 36 | */ 37 | 38 | #if 0 39 | #ifndef lint 40 | static char sccsid[] = "@(#)pr_comment.c 8.1 (Berkeley) 6/6/93"; 41 | #endif /* not lint */ 42 | #endif 43 | 44 | #include 45 | __FBSDID("$FreeBSD$"); 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include "indent_globs.h" 52 | #include "indent_codes.h" 53 | #include "indent.h" 54 | /* 55 | * NAME: 56 | * pr_comment 57 | * 58 | * FUNCTION: 59 | * This routine takes care of scanning and printing comments. 60 | * 61 | * ALGORITHM: 62 | * 1) Decide where the comment should be aligned, and if lines should 63 | * be broken. 64 | * 2) If lines should not be broken and filled, just copy up to end of 65 | * comment. 66 | * 3) If lines should be filled, then scan thru input_buffer copying 67 | * characters to com_buf. Remember where the last blank, tab, or 68 | * newline was. When line is filled, print up to last blank and 69 | * continue copying. 70 | * 71 | * HISTORY: 72 | * November 1976 D A Willcox of CAC Initial coding 73 | * 12/6/76 D A Willcox of CAC Modification to handle 74 | * UNIX-style comments 75 | * 76 | */ 77 | 78 | /* 79 | * this routine processes comments. It makes an attempt to keep comments from 80 | * going over the max line length. If a line is too long, it moves everything 81 | * from the last blank to the next comment line. Blanks and tabs from the 82 | * beginning of the input line are removed 83 | */ 84 | 85 | void 86 | pr_comment(void) 87 | { 88 | int now_col; /* column we are in now */ 89 | int adj_max_col; /* Adjusted max_col for when we decide to 90 | * spill comments over the right margin */ 91 | char *last_bl; /* points to the last blank in the output 92 | * buffer */ 93 | char *t_ptr; /* used for moving string */ 94 | int break_delim = opt.comment_delimiter_on_blankline; 95 | int l_just_saw_decl = ps.just_saw_decl; 96 | 97 | adj_max_col = opt.max_col; 98 | ps.just_saw_decl = 0; 99 | last_bl = NULL; /* no blanks found so far */ 100 | ps.box_com = false; /* at first, assume that we are not in 101 | * a boxed comment or some other 102 | * comment that should not be touched */ 103 | ++ps.out_coms; /* keep track of number of comments */ 104 | 105 | /* Figure where to align and how to treat the comment */ 106 | 107 | if (ps.col_1 && !opt.format_col1_comments) { /* if comment starts in column 108 | * 1 it should not be touched */ 109 | ps.box_com = true; 110 | break_delim = false; 111 | ps.com_col = 1; 112 | } 113 | else { 114 | if (*buf_ptr == '-' || *buf_ptr == '*' || 115 | (*buf_ptr == '\n' && !opt.format_block_comments)) { 116 | ps.box_com = true; /* A comment with a '-' or '*' immediately 117 | * after the /+* is assumed to be a boxed 118 | * comment. A comment with a newline 119 | * immediately after the /+* is assumed to 120 | * be a block comment and is treated as a 121 | * box comment unless format_block_comments 122 | * is nonzero (the default). */ 123 | break_delim = false; 124 | } 125 | if ( /* ps.bl_line && */ (s_lab == e_lab) && (s_code == e_code)) { 126 | /* klg: check only if this line is blank */ 127 | /* 128 | * If this (*and previous lines are*) blank, dont put comment way 129 | * out at left 130 | */ 131 | ps.com_col = (ps.ind_level - opt.unindent_displace) * opt.ind_size + 1; 132 | adj_max_col = opt.block_comment_max_col; 133 | if (ps.com_col <= 1) 134 | ps.com_col = 1 + !opt.format_col1_comments; 135 | } 136 | else { 137 | int target_col; 138 | break_delim = false; 139 | if (s_code != e_code) 140 | target_col = count_spaces(compute_code_target(), s_code); 141 | else { 142 | target_col = 1; 143 | if (s_lab != e_lab) 144 | target_col = count_spaces(compute_label_target(), s_lab); 145 | } 146 | ps.com_col = ps.decl_on_line || ps.ind_level == 0 ? opt.decl_com_ind : opt.com_ind; 147 | if (ps.com_col <= target_col) 148 | ps.com_col = opt.tabsize * (1 + (target_col - 1) / opt.tabsize) + 1; 149 | if (ps.com_col + 24 > adj_max_col) 150 | adj_max_col = ps.com_col + 24; 151 | } 152 | } 153 | if (ps.box_com) { 154 | /* 155 | * Find out how much indentation there was originally, because that 156 | * much will have to be ignored by pad_output() in dump_line(). This 157 | * is a box comment, so nothing changes -- not even indentation. 158 | * 159 | * The comment we're about to read usually comes from in_buffer, 160 | * unless it has been copied into save_com. 161 | */ 162 | char *start; 163 | 164 | start = buf_ptr >= save_com && buf_ptr < save_com + sc_size ? 165 | sc_buf : in_buffer; 166 | ps.n_comment_delta = 1 - count_spaces_until(1, start, buf_ptr - 2); 167 | } 168 | else { 169 | ps.n_comment_delta = 0; 170 | while (*buf_ptr == ' ' || *buf_ptr == '\t') 171 | buf_ptr++; 172 | } 173 | ps.comment_delta = 0; 174 | *e_com++ = '/'; /* put '/' followed by '*' into buffer */ 175 | *e_com++ = '*'; 176 | if (*buf_ptr != ' ' && !ps.box_com) 177 | *e_com++ = ' '; 178 | 179 | /* 180 | * Don't put a break delimiter if this is a one-liner that won't wrap. 181 | */ 182 | if (break_delim) 183 | for (t_ptr = buf_ptr; *t_ptr != '\0' && *t_ptr != '\n'; t_ptr++) { 184 | if (t_ptr >= buf_end) 185 | fill_buffer(); 186 | if (t_ptr[0] == '*' && t_ptr[1] == '/') { 187 | if (adj_max_col >= count_spaces_until(ps.com_col, buf_ptr, t_ptr + 2)) 188 | break_delim = false; 189 | break; 190 | } 191 | } 192 | 193 | if (break_delim) { 194 | char *t = e_com; 195 | e_com = s_com + 2; 196 | *e_com = 0; 197 | if (opt.blanklines_before_blockcomments && ps.last_token != lbrace) 198 | prefix_blankline_requested = 1; 199 | dump_line(); 200 | e_com = s_com = t; 201 | if (!ps.box_com && opt.star_comment_cont) 202 | *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' '; 203 | } 204 | 205 | /* Start to copy the comment */ 206 | 207 | while (1) { /* this loop will go until the comment is 208 | * copied */ 209 | switch (*buf_ptr) { /* this checks for various spcl cases */ 210 | case 014: /* check for a form feed */ 211 | CHECK_SIZE_COM(3); 212 | if (!ps.box_com) { /* in a text comment, break the line here */ 213 | ps.use_ff = true; 214 | /* fix so dump_line uses a form feed */ 215 | dump_line(); 216 | last_bl = NULL; 217 | if (!ps.box_com && opt.star_comment_cont) 218 | *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' '; 219 | while (*++buf_ptr == ' ' || *buf_ptr == '\t') 220 | ; 221 | } 222 | else { 223 | if (++buf_ptr >= buf_end) 224 | fill_buffer(); 225 | *e_com++ = 014; 226 | } 227 | break; 228 | 229 | case '\n': 230 | if (had_eof) { /* check for unexpected eof */ 231 | printf("Unterminated comment\n"); 232 | dump_line(); 233 | return; 234 | } 235 | last_bl = NULL; 236 | CHECK_SIZE_COM(4); 237 | if (ps.box_com || ps.last_nl) { /* if this is a boxed comment, 238 | * we dont ignore the newline */ 239 | if (s_com == e_com) 240 | *e_com++ = ' '; 241 | if (!ps.box_com && e_com - s_com > 3) { 242 | dump_line(); 243 | if (opt.star_comment_cont) 244 | *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' '; 245 | } 246 | dump_line(); 247 | if (!ps.box_com && opt.star_comment_cont) 248 | *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' '; 249 | } 250 | else { 251 | ps.last_nl = 1; 252 | if (*(e_com - 1) == ' ' || *(e_com - 1) == '\t') 253 | last_bl = e_com - 1; 254 | /* 255 | * if there was a space at the end of the last line, remember 256 | * where it was 257 | */ 258 | else { /* otherwise, insert one */ 259 | last_bl = e_com; 260 | *e_com++ = ' '; 261 | } 262 | } 263 | ++line_no; /* keep track of input line number */ 264 | if (!ps.box_com) { 265 | int nstar = 1; 266 | do { /* flush any blanks and/or tabs at start of 267 | * next line */ 268 | if (++buf_ptr >= buf_end) 269 | fill_buffer(); 270 | if (*buf_ptr == '*' && --nstar >= 0) { 271 | if (++buf_ptr >= buf_end) 272 | fill_buffer(); 273 | if (*buf_ptr == '/') 274 | goto end_of_comment; 275 | } 276 | } while (*buf_ptr == ' ' || *buf_ptr == '\t'); 277 | } 278 | else if (++buf_ptr >= buf_end) 279 | fill_buffer(); 280 | break; /* end of case for newline */ 281 | 282 | case '*': /* must check for possibility of being at end 283 | * of comment */ 284 | if (++buf_ptr >= buf_end) /* get to next char after * */ 285 | fill_buffer(); 286 | CHECK_SIZE_COM(4); 287 | if (*buf_ptr == '/') { /* it is the end!!! */ 288 | end_of_comment: 289 | if (++buf_ptr >= buf_end) 290 | fill_buffer(); 291 | if (break_delim) { 292 | if (e_com > s_com + 3) { 293 | dump_line(); 294 | } 295 | else 296 | s_com = e_com; 297 | *e_com++ = ' '; 298 | } 299 | if (e_com[-1] != ' ' && e_com[-1] != '\t' && !ps.box_com) 300 | *e_com++ = ' '; /* ensure blank before end */ 301 | *e_com++ = '*', *e_com++ = '/', *e_com = '\0'; 302 | ps.just_saw_decl = l_just_saw_decl; 303 | return; 304 | } 305 | else /* handle isolated '*' */ 306 | *e_com++ = '*'; 307 | break; 308 | default: /* we have a random char */ 309 | now_col = count_spaces_until(ps.com_col, s_com, e_com); 310 | do { 311 | CHECK_SIZE_COM(1); 312 | *e_com = *buf_ptr++; 313 | if (buf_ptr >= buf_end) 314 | fill_buffer(); 315 | if (*e_com == ' ' || *e_com == '\t') 316 | last_bl = e_com; /* remember we saw a blank */ 317 | ++e_com; 318 | now_col++; 319 | } while (!memchr("*\n\r\b\t", *buf_ptr, 6) && 320 | (now_col <= adj_max_col || !last_bl)); 321 | ps.last_nl = false; 322 | if (now_col > adj_max_col && !ps.box_com && e_com[-1] > ' ') { 323 | /* 324 | * the comment is too long, it must be broken up 325 | */ 326 | if (last_bl == NULL) { 327 | dump_line(); 328 | if (!ps.box_com && opt.star_comment_cont) 329 | *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' '; 330 | break; 331 | } 332 | *e_com = '\0'; 333 | e_com = last_bl; 334 | dump_line(); 335 | if (!ps.box_com && opt.star_comment_cont) 336 | *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' '; 337 | for (t_ptr = last_bl + 1; *t_ptr == ' ' || *t_ptr == '\t'; 338 | t_ptr++) 339 | ; 340 | last_bl = NULL; 341 | /* 342 | * t_ptr will be somewhere between e_com (dump_line() reset) 343 | * and l_com. So it's safe to copy byte by byte from t_ptr 344 | * to e_com without any CHECK_SIZE_COM(). 345 | */ 346 | while (*t_ptr != '\0') { 347 | if (*t_ptr == ' ' || *t_ptr == '\t') 348 | last_bl = e_com; 349 | *e_com++ = *t_ptr++; 350 | } 351 | } 352 | break; 353 | } 354 | } 355 | } 356 | -------------------------------------------------------------------------------- /indent/tests/binary.0: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | #define b00101010 -1 3 | void t(void) { 4 | unsigned a[] = {0b00101010, 0x00005678, 02, 17U}; 5 | float x[] = {.7f, 0.7f}; 6 | unsigned long ul[] = {0b00001111UL, 0x01010101UL, 02UL, 17UL}; 7 | 8 | if (0 b00101010) 9 | return; 10 | } 11 | -------------------------------------------------------------------------------- /indent/tests/binary.0.stdout: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | #define b00101010 -1 3 | void 4 | t(void) 5 | { 6 | unsigned a[] = {0b00101010, 0x00005678, 02, 17U}; 7 | float x[] = {.7f, 0.7f}; 8 | unsigned long ul[] = {0b00001111UL, 0x01010101UL, 02UL, 17UL}; 9 | 10 | if (0 b00101010) 11 | return; 12 | } 13 | -------------------------------------------------------------------------------- /indent/tests/comments.0: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | typedef enum x { 3 | aaaaaaaaaaaaaaaaaaaaaa = 1 << 0, /* test a */ 4 | bbbbbbbbbbbbbbbbb = 1 << 1, /* test b */ 5 | cccccccccccccc = 1 << 1, /* test c */ 6 | dddddddddddddddddddddddddddddd = 1 << 2 /* test d */ 7 | } x; 8 | 9 | /* See r303597, r303598, r309219, and r309343 */ 10 | void t(void) { 11 | /* 12 | * Old indent wrapped the URL near where this sentence ends. 13 | * 14 | * https://www.freebsd.org/cgi/man.cgi?query=indent&apropos=0&sektion=0&manpath=FreeBSD+12-current&arch=default&format=html 15 | */ 16 | 17 | /* 18 | * Old indent did not wrap to column 78 19 | * 20 | * aaaaaa bbbbbb cccccc dddddd eeeeee ffffff ggggg hhhhh iiiii jjjj kk 21 | */ 22 | 23 | /* 24 | * Old indent unnecessarily removed the star comment continuation on the next line. 25 | * 26 | * *test* 27 | */ 28 | 29 | /* r309219 Go through linked list, freeing from the malloced (t[-1]) address. */ 30 | 31 | /* r309343 */ 32 | } 33 | 34 | int c(void) 35 | { 36 | if (1) { /*- a christmas tree * 37 | *** 38 | ***** */ 39 | /*- another one * 40 | *** 41 | ***** */ 42 | 7; 43 | } 44 | 45 | if (1) /*- a christmas tree * 46 | *** 47 | ***** */ 48 | /*- another one * 49 | *** 50 | ***** */ 51 | 1; 52 | } 53 | -------------------------------------------------------------------------------- /indent/tests/comments.0.pro: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | -bbb 3 | -------------------------------------------------------------------------------- /indent/tests/comments.0.stdout: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | typedef enum x { 3 | aaaaaaaaaaaaaaaaaaaaaa = 1 << 0, /* test a */ 4 | bbbbbbbbbbbbbbbbb = 1 << 1, /* test b */ 5 | cccccccccccccc = 1 << 1, /* test c */ 6 | dddddddddddddddddddddddddddddd = 1 << 2 /* test d */ 7 | } x; 8 | 9 | /* See r303597, r303598, r309219, and r309343 */ 10 | void 11 | t(void) 12 | { 13 | /* 14 | * Old indent wrapped the URL near where this sentence ends. 15 | * 16 | * https://www.freebsd.org/cgi/man.cgi?query=indent&apropos=0&sektion=0&manpath=FreeBSD+12-current&arch=default&format=html 17 | */ 18 | 19 | /* 20 | * Old indent did not wrap to column 78 21 | * 22 | * aaaaaa bbbbbb cccccc dddddd eeeeee ffffff ggggg hhhhh iiiii jjjj 23 | * kk 24 | */ 25 | 26 | /* 27 | * Old indent unnecessarily removed the star comment continuation on 28 | * the next line. 29 | * 30 | * *test* 31 | */ 32 | 33 | /* 34 | * r309219 Go through linked list, freeing from the malloced (t[-1]) 35 | * address. 36 | */ 37 | 38 | /* r309343 */ 39 | } 40 | 41 | int 42 | c(void) 43 | { 44 | if (1) { /*- a christmas tree * 45 | *** 46 | ***** */ 47 | /*- another one * 48 | *** 49 | ***** */ 50 | 7; 51 | } 52 | 53 | if (1) /*- a christmas tree * 54 | *** 55 | ***** */ 56 | /*- another one * 57 | *** 58 | ***** */ 59 | 1; 60 | } 61 | -------------------------------------------------------------------------------- /indent/tests/cs.0: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | void t(void) { 3 | int a = (double) 8; 4 | } 5 | -------------------------------------------------------------------------------- /indent/tests/cs.0.pro: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | -cs 3 | -------------------------------------------------------------------------------- /indent/tests/cs.0.stdout: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | void 3 | t(void) 4 | { 5 | int a = (double) 8; 6 | } 7 | -------------------------------------------------------------------------------- /indent/tests/declarations.0: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | /* See r303570 */ 3 | 4 | typedef void (*voidptr) (int *); 5 | 6 | static const struct 7 | { 8 | double x; 9 | double y, z; 10 | } n[m + 1] = 11 | { 12 | { 13 | .0, 14 | .9, 15 | 5 16 | } 17 | }; 18 | 19 | typedef struct Complex 20 | { 21 | double x; 22 | double y; 23 | } Complex; 24 | 25 | void 26 | t1 (char *a, int b, 27 | void (*fn)(void)) 28 | {} 29 | 30 | void t2 (char *x, int y) 31 | { 32 | int a, 33 | b, 34 | c; 35 | int 36 | *d, 37 | *e, 38 | *f; 39 | int (*g)(), 40 | (*h)(), 41 | (*i)(); 42 | int j, 43 | k, 44 | l; 45 | int m 46 | ,n 47 | ,o 48 | ; 49 | int chars[ /* push the comma beyond column 74 .... */ ], x; 50 | } 51 | 52 | const int int_minimum_size = 53 | MAXALIGN(offsetof(int, test)) + MAXIMUM_ALIGNOF; 54 | 55 | int *int_create(void) 56 | { 57 | 58 | } 59 | 60 | static 61 | _attribute_printf(1, 2) 62 | void 63 | print_error(const char *fmt,...) 64 | { 65 | 66 | } 67 | 68 | static LIST_HEAD(, alq) ald_active; 69 | static int ald_shutingdown = 0; 70 | struct thread *ald_thread; 71 | 72 | static int 73 | do_execve(td, args, mac_p) 74 | struct thread *td; 75 | struct image_args *args; 76 | struct mac *mac_p; 77 | { 78 | 79 | } 80 | -------------------------------------------------------------------------------- /indent/tests/declarations.0.stdout: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | /* See r303570 */ 3 | 4 | typedef void (*voidptr) (int *); 5 | 6 | static const struct { 7 | double x; 8 | double y, z; 9 | } n[m + 1] = 10 | { 11 | { 12 | .0, 13 | .9, 14 | 5 15 | } 16 | }; 17 | 18 | typedef struct Complex { 19 | double x; 20 | double y; 21 | } Complex; 22 | 23 | void 24 | t1(char *a, int b, 25 | void (*fn) (void)) 26 | { 27 | } 28 | 29 | void 30 | t2(char *x, int y) 31 | { 32 | int a, b, c; 33 | int 34 | *d, *e, *f; 35 | int (*g) (), (*h) (), (*i) (); 36 | int j, k, l; 37 | int m 38 | ,n 39 | ,o 40 | ; 41 | int chars[ /* push the comma beyond column 74 .... */ ], 42 | x; 43 | } 44 | 45 | const int int_minimum_size = 46 | MAXALIGN(offsetof(int, test)) + MAXIMUM_ALIGNOF; 47 | 48 | int * 49 | int_create(void) 50 | { 51 | 52 | } 53 | 54 | static 55 | _attribute_printf(1, 2) 56 | void 57 | print_error(const char *fmt,...) 58 | { 59 | 60 | } 61 | 62 | static LIST_HEAD(, alq) ald_active; 63 | static int ald_shutingdown = 0; 64 | struct thread *ald_thread; 65 | 66 | static int 67 | do_execve(td, args, mac_p) 68 | struct thread *td; 69 | struct image_args *args; 70 | struct mac *mac_p; 71 | { 72 | 73 | } 74 | -------------------------------------------------------------------------------- /indent/tests/elsecomment.0: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | /* See r303484 and r309342 */ 3 | void t(void) { 4 | /* The two if statements below excercise two different code paths. */ 5 | 6 | if (1) /* a */ int a; else /* b */ int b; 7 | 8 | if (1) /* a */ 9 | int a; 10 | else /* b */ 11 | int b; 12 | 13 | if (1) { 14 | 15 | } 16 | 17 | 18 | 19 | /* Old indent would remove the 3 blank lines above, awaiting "else". */ 20 | 21 | if (1) { 22 | int a; 23 | } 24 | 25 | 26 | else if (0) { 27 | int b; 28 | } 29 | /* test */ 30 | else 31 | ; 32 | 33 | if (1) 34 | ; 35 | else /* Old indent would get very confused here */ 36 | /* We also mustn't assume that there's only one comment */ 37 | /* before the left brace. */ 38 | { 39 | 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /indent/tests/elsecomment.0.pro: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | -bl 3 | -------------------------------------------------------------------------------- /indent/tests/elsecomment.0.stdout: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | /* See r303484 and r309342 */ 3 | void 4 | t(void) 5 | { 6 | /* The two if statements below excercise two different code paths. */ 7 | 8 | if (1) /* a */ 9 | int a; 10 | else /* b */ 11 | int b; 12 | 13 | if (1) /* a */ 14 | int a; 15 | else /* b */ 16 | int b; 17 | 18 | if (1) 19 | { 20 | 21 | } 22 | 23 | 24 | 25 | /* Old indent would remove the 3 blank lines above, awaiting "else". */ 26 | 27 | if (1) 28 | { 29 | int a; 30 | } else if (0) 31 | { 32 | int b; 33 | } 34 | /* test */ 35 | else 36 | ; 37 | 38 | if (1) 39 | ; 40 | else /* Old indent would get very confused here */ 41 | /* We also mustn't assume that there's only one comment */ 42 | /* before the left brace. */ 43 | { 44 | 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /indent/tests/f_decls.0: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | 3 | char * x(void) 4 | { 5 | type identifier; 6 | type *pointer; 7 | unused * value; 8 | (void)unused * value; 9 | 10 | dmax = (double)3 * 10.0; 11 | dmin = (double)dmax * 10.0; 12 | davg = (double)dmax * dmin; 13 | 14 | return NULL; 15 | } 16 | 17 | int * 18 | y(void) { 19 | 20 | } 21 | 22 | int 23 | z(void) { 24 | 25 | } 26 | 27 | int x; 28 | int *y; 29 | int * * * * z; 30 | -------------------------------------------------------------------------------- /indent/tests/f_decls.0.stdout: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | 3 | char * 4 | x(void) 5 | { 6 | type identifier; 7 | type *pointer; 8 | unused *value; 9 | (void)unused * value; 10 | 11 | dmax = (double)3 * 10.0; 12 | dmin = (double)dmax * 10.0; 13 | davg = (double)dmax * dmin; 14 | 15 | return NULL; 16 | } 17 | 18 | int * 19 | y(void) 20 | { 21 | 22 | } 23 | 24 | int 25 | z(void) 26 | { 27 | 28 | } 29 | 30 | int x; 31 | int *y; 32 | int ****z; 33 | -------------------------------------------------------------------------------- /indent/tests/float.0: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | void t(void) { 3 | unsigned long x = 314UL; 4 | double y[] = {0x1P+9F, 0.3, .1, 1.2f, 0xa.p01f, 3.14f, 2.L}; 5 | int z = 0b0101; 6 | DO_NOTHING; 7 | x._y = 5; 8 | } 9 | -------------------------------------------------------------------------------- /indent/tests/float.0.stdout: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | void 3 | t(void) 4 | { 5 | unsigned long x = 314UL; 6 | double y[] = {0x1P+9F, 0.3, .1, 1.2f, 0xa.p01f, 3.14f, 2.L}; 7 | int z = 0b0101; 8 | DO_NOTHING; 9 | x._y = 5; 10 | } 11 | -------------------------------------------------------------------------------- /indent/tests/functional_test.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Dell EMC 3 | # All rights reserved. 4 | # 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 copyright 12 | # notice, this list of conditions and the following disclaimer in the 13 | # documentation and/or other materials provided with the distribution. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | # 27 | # $FreeBSD$ 28 | 29 | SRCDIR=$(atf_get_srcdir) 30 | 31 | check() 32 | { 33 | local tc=${1}; shift 34 | 35 | local indent=$(atf_config_get usr.bin.indent.test_indent indent) 36 | 37 | # All of the files need to be in the ATF sandbox in order for the tests 38 | # to pass. 39 | atf_check cp ${SRCDIR}/${tc}* . 40 | 41 | # Remove $FreeBSD$ RCS expansions because they get re-indented, which 42 | # changes the output 43 | local out_file="${tc}.stdout" 44 | if [ -f "${out_file}" ]; then 45 | parsed_file=output_file.parsed 46 | 47 | atf_check -o save:$parsed_file sed -e '/\$FreeBSD.*\$/d' \ 48 | ${tc}.stdout 49 | out_flag="-o file:$parsed_file" 50 | fi 51 | local profile_file="${tc}.pro" 52 | if [ -f "${profile_file}" ]; then 53 | profile_flag="-P${profile_file}" 54 | else 55 | # Make sure we don't implicitly use ~/.indent.pro from the test 56 | # host, for determinism purposes. 57 | profile_flag="-npro" 58 | fi 59 | sed -e '/\$FreeBSD.*\$/d' ${tc} > input_file.parsed 60 | atf_check -s exit:${tc##*.} ${out_flag} ${indent} ${profile_flag} < input_file.parsed 61 | } 62 | 63 | add_testcase() 64 | { 65 | local tc=${1} 66 | local tc_escaped word 67 | 68 | case "${tc%.*}" in 69 | *-*) 70 | local IFS="-" 71 | for word in ${tc%.*}; do 72 | tc_escaped="${tc_escaped:+${tc_escaped}_}${word}" 73 | done 74 | ;; 75 | *) 76 | tc_escaped=${tc%.*} 77 | ;; 78 | esac 79 | 80 | atf_test_case ${tc_escaped} 81 | eval "${tc_escaped}_body() { check ${tc}; }" 82 | atf_add_test_case ${tc_escaped} 83 | } 84 | 85 | atf_init_test_cases() 86 | { 87 | for path in $(find -Es "${SRCDIR}" -regex '.*\.[0-9]+$'); do 88 | add_testcase ${path##*/} 89 | done 90 | } 91 | -------------------------------------------------------------------------------- /indent/tests/label.0: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | /* See r303489 */ 3 | void t(void) { 4 | switch (1) 5 | { 6 | case 1: /* test */ 7 | case 2: /* test */ 8 | } 9 | CLEANUP: 10 | ; 11 | V: ; 12 | U: ; 13 | } 14 | -------------------------------------------------------------------------------- /indent/tests/label.0.pro: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | -nut 3 | -------------------------------------------------------------------------------- /indent/tests/label.0.stdout: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | /* See r303489 */ 3 | void 4 | t(void) 5 | { 6 | switch (1) { 7 | case 1: /* test */ 8 | case 2: /* test */ 9 | } 10 | CLEANUP: 11 | ; 12 | V: ; 13 | U: ; 14 | } 15 | -------------------------------------------------------------------------------- /indent/tests/list_head.0: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | /* See r309380 */ 3 | static int 4 | do_execve(td, args, mac_p) 5 | struct thread *td; 6 | struct image_args *args; 7 | struct mac *mac_p; 8 | { 9 | 10 | } 11 | 12 | static LIST_HEAD(, alq) ald_active; 13 | static int ald_shuttingdown = 0; 14 | struct thread *ald_thread; 15 | 16 | 17 | -------------------------------------------------------------------------------- /indent/tests/list_head.0.stdout: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | /* See r309380 */ 3 | static int 4 | do_execve(td, args, mac_p) 5 | struct thread *td; 6 | struct image_args *args; 7 | struct mac *mac_p; 8 | { 9 | 10 | } 11 | 12 | static LIST_HEAD(, alq) ald_active; 13 | static int ald_shuttingdown = 0; 14 | struct thread *ald_thread; 15 | -------------------------------------------------------------------------------- /indent/tests/ncs.0: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | void t(void) { 3 | int a = (double) 8; 4 | } 5 | -------------------------------------------------------------------------------- /indent/tests/ncs.0.pro: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | -ncs 3 | -------------------------------------------------------------------------------- /indent/tests/ncs.0.stdout: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | void 3 | t(void) 4 | { 5 | int a = (double)8; 6 | } 7 | -------------------------------------------------------------------------------- /indent/tests/offsetof.0: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | /* See r303718 */ 3 | void t(void) { 4 | int n = malloc(offsetof(struct s, f) + 1); 5 | } 6 | -------------------------------------------------------------------------------- /indent/tests/offsetof.0.stdout: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | /* See r303718 */ 3 | void 4 | t(void) 5 | { 6 | int n = malloc(offsetof(struct s, f) + 1); 7 | } 8 | -------------------------------------------------------------------------------- /indent/tests/parens.0: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | typedef void (*xxxxxxxxxxx) (int, 3 | char); 4 | 5 | typedef char (*xxxxxxxxxxxxxxxxxxxxxxxxxxxx) (int *, 6 | unsigned *, 7 | char, 8 | float *); 9 | 10 | void 11 | test(void) 12 | { 13 | char chars[secondf(firstf(B), 14 | *here)]; 15 | 16 | float xxx = yyyyyyyyyyyyyy(zzzzzzzzzzzzz(p1, 17 | (p2), 18 | p3)); 19 | 20 | if (1) { 21 | char *xxx = firstf(secondf2(p1, 22 | p2)); 23 | } 24 | 25 | rb->allocfunc(1); 26 | rb2.allocfunc(7); 27 | } 28 | -------------------------------------------------------------------------------- /indent/tests/parens.0.pro: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | -ts4 -i4 -di12 -Tallocfunc 3 | -------------------------------------------------------------------------------- /indent/tests/parens.0.stdout: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | typedef void (*xxxxxxxxxxx) (int, 3 | char); 4 | 5 | typedef char (*xxxxxxxxxxxxxxxxxxxxxxxxxxxx) (int *, 6 | unsigned *, 7 | char, 8 | float *); 9 | 10 | void 11 | test(void) 12 | { 13 | char chars[secondf(firstf(B), 14 | *here)]; 15 | 16 | float xxx = yyyyyyyyyyyyyy(zzzzzzzzzzzzz(p1, 17 | (p2), 18 | p3)); 19 | 20 | if (1) { 21 | char *xxx = firstf(secondf2(p1, 22 | p2)); 23 | } 24 | 25 | rb->allocfunc(1); 26 | rb2.allocfunc(7); 27 | } 28 | -------------------------------------------------------------------------------- /indent/tests/pcs.0: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | #include 3 | 4 | int main(void) { 5 | puts("Hello"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /indent/tests/pcs.0.pro: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | -pcs 3 | -------------------------------------------------------------------------------- /indent/tests/pcs.0.stdout: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | #include 3 | 4 | int 5 | main(void) 6 | { 7 | puts ("Hello"); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /indent/tests/ps.0: -------------------------------------------------------------------------------- 1 | struct s { int i; }; 2 | void f(struct s *p) { 3 | p->i--; 4 | } 5 | -------------------------------------------------------------------------------- /indent/tests/ps.0.pro: -------------------------------------------------------------------------------- 1 | -ps 2 | -------------------------------------------------------------------------------- /indent/tests/ps.0.stdout: -------------------------------------------------------------------------------- 1 | struct s { 2 | int i; 3 | }; 4 | void 5 | f(struct s *p) 6 | { 7 | p -> i--; 8 | } 9 | -------------------------------------------------------------------------------- /indent/tests/struct.0: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | 3 | int f(struct x *a); 4 | 5 | /* See r303485 */ 6 | void 7 | t(void) 8 | { 9 | static const struct { 10 | int a; 11 | int b; 12 | } c[] = { 13 | { D, E }, 14 | { F, G } 15 | }; 16 | } 17 | 18 | void u(struct x a) { 19 | int b; 20 | struct y c = (struct y *)&a; 21 | } 22 | -------------------------------------------------------------------------------- /indent/tests/struct.0.stdout: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | 3 | int f(struct x *a); 4 | 5 | /* See r303485 */ 6 | void 7 | t(void) 8 | { 9 | static const struct { 10 | int a; 11 | int b; 12 | } c[] = { 13 | {D, E}, 14 | {F, G} 15 | }; 16 | } 17 | 18 | void 19 | u(struct x a) 20 | { 21 | int b; 22 | struct y c = (struct y *)&a; 23 | } 24 | -------------------------------------------------------------------------------- /indent/tests/surplusbad.0: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | /* See r303599 */ 3 | #if defined(__i386__) 4 | int a; 5 | #elif defined(__amd64__) 6 | int b; 7 | #else 8 | #error "Port me" 9 | #endif 10 | -------------------------------------------------------------------------------- /indent/tests/surplusbad.0.pro: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | -bad 3 | -------------------------------------------------------------------------------- /indent/tests/surplusbad.0.stdout: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | /* See r303599 */ 3 | #if defined(__i386__) 4 | int a; 5 | #elif defined(__amd64__) 6 | int b; 7 | #else 8 | #error "Port me" 9 | #endif 10 | -------------------------------------------------------------------------------- /indent/tests/types_from_file.0: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | /* See r303735 */ 3 | void t(a *x, b *y, c *z); 4 | -------------------------------------------------------------------------------- /indent/tests/types_from_file.0.list: -------------------------------------------------------------------------------- 1 | b 2 | a -------------------------------------------------------------------------------- /indent/tests/types_from_file.0.pro: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | -Utypes_from_file.0.list 3 | -------------------------------------------------------------------------------- /indent/tests/types_from_file.0.stdout: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | /* See r303735 */ 3 | void t(a *x, b *y, c * z); 4 | -------------------------------------------------------------------------------- /indent/tests/wchar.0: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | /* See r309220 */ 3 | #include 4 | 5 | wchar_t *x = L"test"; 6 | wchar_t y = L't'; 7 | -------------------------------------------------------------------------------- /indent/tests/wchar.0.stdout: -------------------------------------------------------------------------------- 1 | /* $FreeBSD$ */ 2 | /* See r309220 */ 3 | #include 4 | 5 | wchar_t *x = L"test"; 6 | wchar_t y = L't'; 7 | -------------------------------------------------------------------------------- /lorder/lorder.1: -------------------------------------------------------------------------------- 1 | .\" $NetBSD: lorder.1,v 1.6 1997/10/19 04:21:49 lukem Exp $ 2 | .\" 3 | .\" Copyright (c) 1990, 1993 4 | .\" The Regents of the University of California. All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions 8 | .\" are met: 9 | .\" 1. Redistributions of source code must retain the above copyright 10 | .\" notice, this list of conditions and the following disclaimer. 11 | .\" 2. Redistributions in binary form must reproduce the above copyright 12 | .\" notice, this list of conditions and the following disclaimer in the 13 | .\" documentation and/or other materials provided with the distribution. 14 | .\" 3. All advertising materials mentioning features or use of this software 15 | .\" must display the following acknowledgement: 16 | .\" This product includes software developed by the University of 17 | .\" California, Berkeley and its contributors. 18 | .\" 4. Neither the name of the University nor the names of its contributors 19 | .\" may be used to endorse or promote products derived from this software 20 | .\" without specific prior written permission. 21 | .\" 22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | .\" SUCH DAMAGE. 33 | .\" 34 | .\" @(#)lorder.1 8.2 (Berkeley) 4/28/95 35 | .\" 36 | .Dd April 28, 1995 37 | .Dt LORDER 1 38 | .Os 39 | .Sh NAME 40 | .Nm lorder 41 | .Nd list dependencies for object files 42 | .Sh SYNOPSIS 43 | .Nm 44 | .Ar 45 | .Sh DESCRIPTION 46 | The 47 | .Nm 48 | utility uses 49 | .Xr nm 1 50 | to determine interdependencies in the list of object files 51 | specified on the command line. 52 | .Nm 53 | outputs a list of file names where the first file contains a symbol 54 | which is defined by the second file. 55 | .Pp 56 | The output is normally used with 57 | .Xr tsort 1 58 | when a library is created to determine the optimum ordering of the 59 | object modules so that all references may be resolved in a single 60 | pass of the loader. 61 | .Sh EXAMPLES 62 | .Bd -literal -offset indent 63 | ar cr library.a `lorder ${OBJS} | tsort` 64 | .Ed 65 | .Sh SEE ALSO 66 | .Xr ar 1 , 67 | .Xr ld 1 , 68 | .Xr nm 1 , 69 | .Xr ranlib 1 , 70 | .Xr tsort 1 71 | .Sh HISTORY 72 | An 73 | .Nm 74 | utility appeared in 75 | .At v7 . 76 | -------------------------------------------------------------------------------- /lorder/lorder.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh - 2 | # $NetBSD: lorder.sh,v 1.7 1998/04/09 05:28:07 fair Exp $ 3 | # 4 | # Copyright (c) 1990, 1993 5 | # The Regents of the University of California. All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 1. Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # 2. Redistributions in binary form must reproduce the above copyright 13 | # notice, this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | # 3. All advertising materials mentioning features or use of this software 16 | # must display the following acknowledgement: 17 | # This product includes software developed by the University of 18 | # California, Berkeley and its contributors. 19 | # 4. Neither the name of the University nor the names of its contributors 20 | # may be used to endorse or promote products derived from this software 21 | # without specific prior written permission. 22 | # 23 | # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | # SUCH DAMAGE. 34 | # 35 | # @(#)lorder.sh 8.1 (Berkeley) 6/6/93 36 | # 37 | 38 | # If the user has set ${NM} then we use it, otherwise we use 'nm'. 39 | # We try to find the compiler in the user's path, and if that fails we 40 | # try to find it in the default path. If we can't find it, we punt. 41 | # Once we find it, we canonicalize its name and set the path to the 42 | # default path so that other commands we use are picked properly. 43 | 44 | if ! type "${NM:=nm}" > /dev/null 2>&1; then 45 | PATH=/bin:/usr/bin 46 | export PATH 47 | if ! type "${NM}" > /dev/null 2>&1; then 48 | echo "lorder: ${NM}: not found" 49 | exit 1 50 | fi 51 | fi 52 | cmd='set `type "${NM}"` ; eval echo \$$#' 53 | NM=`eval $cmd` 54 | 55 | # only one argument is a special case, just output the name twice 56 | case $# in 57 | 0) 58 | echo "usage: lorder file ..."; 59 | exit ;; 60 | 1) 61 | echo $1 $1; 62 | exit ;; 63 | esac 64 | 65 | # temporary files 66 | R=/tmp/_reference_$$ 67 | S=/tmp/_symbol_$$ 68 | 69 | # remove temporary files on HUP, INT, QUIT, PIPE, TERM 70 | trap "rm -f $R $S; exit 1" 1 2 3 13 15 71 | 72 | # if the line ends in a colon, assume it's the first occurrence of a new 73 | # object file. Echo it twice, just to make sure it gets into the output. 74 | # 75 | # if the line has " T " or " D " it's a globally defined symbol, put it 76 | # into the symbol file. 77 | # 78 | # if the line has " U " it's a globally undefined symbol, put it into 79 | # the reference file. 80 | (for file in $* ; do echo $file":" ; done ; $NM -go $*) | sed " 81 | /:$/ { 82 | s/:// 83 | s/.*/& &/ 84 | p 85 | d 86 | } 87 | / [TDGR] / { 88 | s/:.* [TDGR] / / 89 | w $S 90 | d 91 | } 92 | / U / { 93 | s/:.* U / / 94 | w $R 95 | } 96 | d 97 | " 98 | 99 | # sort symbols and references on the first field (the symbol) 100 | # join on that field, and print out the file names. 101 | sort -k 2 $R -o $R 102 | sort -k 2 $S -o $S 103 | join -j 2 -o "1.1 2.1" $R $S 104 | rm -f $R $S 105 | -------------------------------------------------------------------------------- /rpcgen/rpc_clntout.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: rpc_clntout.c,v 1.8 1997/10/18 10:53:37 lukem Exp $ */ 2 | /* 3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 4 | * unrestricted use provided that this legend is included on all tape 5 | * media and as a part of the software program in whole or part. Users 6 | * may copy or modify Sun RPC without charge, but are not authorized 7 | * to license or distribute it to anyone else except as part of a product or 8 | * program developed by the user or with the express written consent of 9 | * Sun Microsystems, Inc. 10 | * 11 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 12 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 13 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 14 | * 15 | * Sun RPC is provided with no support and without any obligation on the 16 | * part of Sun Microsystems, Inc. to assist in its use, correction, 17 | * modification or enhancement. 18 | * 19 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 20 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 21 | * OR ANY PART THEREOF. 22 | * 23 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 24 | * or profits or other special, indirect and consequential damages, even if 25 | * Sun has been advised of the possibility of such damages. 26 | * 27 | * Sun Microsystems, Inc. 28 | * 2550 Garcia Avenue 29 | * Mountain View, California 94043 30 | */ 31 | 32 | #include 33 | #ifndef lint 34 | #if 0 35 | static char sccsid[] = "@(#)rpc_clntout.c 1.11 89/02/22 (C) 1987 SMI"; 36 | #else 37 | __RCSID("$NetBSD: rpc_clntout.c,v 1.8 1997/10/18 10:53:37 lukem Exp $"); 38 | #endif 39 | #endif 40 | 41 | /* 42 | * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler 43 | * Copyright (C) 1987, Sun Microsytsems, Inc. 44 | */ 45 | #include 46 | #include 47 | #include 48 | #include "rpc_scan.h" 49 | #include "rpc_parse.h" 50 | #include "rpc_util.h" 51 | 52 | static void write_program __P((definition *)); 53 | static char *ampr __P((char *)); 54 | static void printbody __P((proc_list *)); 55 | 56 | #define DEFAULT_TIMEOUT 25 /* in seconds */ 57 | static char RESULT[] = "clnt_res"; 58 | 59 | 60 | void 61 | write_stubs() 62 | { 63 | list *l; 64 | definition *def; 65 | 66 | f_print(fout, 67 | "\n/* Default timeout can be changed using clnt_control() */\n"); 68 | f_print(fout, "static struct timeval TIMEOUT = { %d, 0 };\n", 69 | DEFAULT_TIMEOUT); 70 | for (l = defined; l != NULL; l = l->next) { 71 | def = (definition *) l->val; 72 | if (def->def_kind == DEF_PROGRAM) { 73 | write_program(def); 74 | } 75 | } 76 | } 77 | 78 | static void 79 | write_program(def) 80 | definition *def; 81 | { 82 | version_list *vp; 83 | proc_list *proc; 84 | 85 | for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { 86 | for (proc = vp->procs; proc != NULL; proc = proc->next) { 87 | f_print(fout, "\n"); 88 | ptype(proc->res_prefix, proc->res_type, 1); 89 | f_print(fout, "*\n"); 90 | pvname(proc->proc_name, vp->vers_num); 91 | printarglist(proc, "clnt", "CLIENT *"); 92 | f_print(fout, "{\n"); 93 | printbody(proc); 94 | f_print(fout, "}\n"); 95 | } 96 | } 97 | } 98 | /* Writes out declarations of procedure's argument list. 99 | In either ANSI C style, in one of old rpcgen style (pass by reference), 100 | or new rpcgen style (multiple arguments, pass by value); 101 | */ 102 | 103 | /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */ 104 | 105 | void 106 | printarglist(proc, addargname, addargtype) 107 | proc_list *proc; 108 | char *addargname, *addargtype; 109 | { 110 | 111 | decl_list *l; 112 | 113 | if (!newstyle) { /* old style: always pass argument by 114 | * reference */ 115 | if (Cflag) { /* C++ style heading */ 116 | f_print(fout, "("); 117 | ptype(proc->args.decls->decl.prefix, proc->args.decls->decl.type, 1); 118 | f_print(fout, "*argp, %s%s)\n", addargtype, addargname); 119 | } else { 120 | f_print(fout, "(argp, %s)\n", addargname); 121 | f_print(fout, "\t"); 122 | ptype(proc->args.decls->decl.prefix, proc->args.decls->decl.type, 1); 123 | f_print(fout, "*argp;\n"); 124 | } 125 | } else 126 | if (streq(proc->args.decls->decl.type, "void")) { 127 | /* newstyle, 0 argument */ 128 | if (Cflag) 129 | f_print(fout, "(%s%s)\n", addargtype, addargname); 130 | else 131 | f_print(fout, "(%s)\n", addargname); 132 | } else { 133 | /* new style, 1 or multiple arguments */ 134 | if (!Cflag) { 135 | f_print(fout, "("); 136 | for (l = proc->args.decls; l != NULL; l = l->next) 137 | f_print(fout, "%s, ", l->decl.name); 138 | f_print(fout, "%s)\n", addargname); 139 | for (l = proc->args.decls; l != NULL; l = l->next) { 140 | pdeclaration(proc->args.argname, &l->decl, 1, ";\n"); 141 | } 142 | } else {/* C++ style header */ 143 | f_print(fout, "("); 144 | for (l = proc->args.decls; l != NULL; l = l->next) { 145 | pdeclaration(proc->args.argname, &l->decl, 0, ", "); 146 | } 147 | f_print(fout, " %s%s)\n", addargtype, addargname); 148 | } 149 | } 150 | 151 | if (!Cflag) 152 | f_print(fout, "\t%s%s;\n", addargtype, addargname); 153 | } 154 | 155 | 156 | 157 | static char * 158 | ampr(type) 159 | char *type; 160 | { 161 | if (isvectordef(type, REL_ALIAS)) { 162 | return (""); 163 | } else { 164 | return ("&"); 165 | } 166 | } 167 | 168 | static void 169 | printbody(proc) 170 | proc_list *proc; 171 | { 172 | decl_list *l; 173 | bool_t args2 = (proc->arg_num > 1); 174 | 175 | /* For new style with multiple arguments, need a structure in which to 176 | * stuff the arguments. */ 177 | if (newstyle && args2) { 178 | f_print(fout, "\t%s", proc->args.argname); 179 | f_print(fout, " arg;\n"); 180 | } 181 | f_print(fout, "\tstatic "); 182 | if (streq(proc->res_type, "void")) { 183 | f_print(fout, "char "); 184 | } else { 185 | ptype(proc->res_prefix, proc->res_type, 0); 186 | } 187 | f_print(fout, "%s;\n", RESULT); 188 | f_print(fout, "\n"); 189 | f_print(fout, "\tmemset((char *)%s%s, 0, sizeof(%s));\n", 190 | ampr(proc->res_type), RESULT, RESULT); 191 | if (newstyle && !args2 && (streq(proc->args.decls->decl.type, "void"))) { 192 | /* newstyle, 0 arguments */ 193 | f_print(fout, 194 | "\tif (clnt_call(clnt, %s, xdr_void", proc->proc_name); 195 | f_print(fout, 196 | ", NULL, xdr_%s, %s%s, TIMEOUT) != RPC_SUCCESS) {\n", 197 | stringfix(proc->res_type), ampr(proc->res_type), RESULT); 198 | 199 | } else 200 | if (newstyle && args2) { 201 | /* newstyle, multiple arguments: stuff arguments into 202 | * structure */ 203 | for (l = proc->args.decls; l != NULL; l = l->next) { 204 | f_print(fout, "\targ.%s = %s;\n", 205 | l->decl.name, l->decl.name); 206 | } 207 | f_print(fout, 208 | "\tif (clnt_call(clnt, %s, xdr_%s, &arg, xdr_%s, %s%s, TIMEOUT) != RPC_SUCCESS)\n", 209 | proc->proc_name, 210 | proc->args.argname, 211 | stringfix(proc->res_type), 212 | ampr(proc->res_type), RESULT); 213 | } else { /* single argument, new or old style */ 214 | f_print(fout, 215 | "\tif (clnt_call(clnt, %s, xdr_%s, %s%s, xdr_%s, %s%s, TIMEOUT) != RPC_SUCCESS)\n", 216 | proc->proc_name, 217 | stringfix(proc->args.decls->decl.type), 218 | (newstyle ? "&" : ""), 219 | (newstyle ? proc->args.decls->decl.name : "argp"), 220 | stringfix(proc->res_type), 221 | ampr(proc->res_type), RESULT); 222 | } 223 | f_print(fout, "\t\treturn (NULL);\n"); 224 | if (streq(proc->res_type, "void")) { 225 | f_print(fout, "\treturn ((void *)%s%s);\n", 226 | ampr(proc->res_type), RESULT); 227 | } else { 228 | f_print(fout, "\treturn (%s%s);\n", ampr(proc->res_type), RESULT); 229 | } 230 | } 231 | -------------------------------------------------------------------------------- /rpcgen/rpc_parse.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: rpc_parse.h,v 1.4 1997/10/11 21:01:42 christos Exp $ */ 2 | /* 3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 4 | * unrestricted use provided that this legend is included on all tape 5 | * media and as a part of the software program in whole or part. Users 6 | * may copy or modify Sun RPC without charge, but are not authorized 7 | * to license or distribute it to anyone else except as part of a product or 8 | * program developed by the user or with the express written consent of 9 | * Sun Microsystems, Inc. 10 | * 11 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 12 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 13 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 14 | * 15 | * Sun RPC is provided with no support and without any obligation on the 16 | * part of Sun Microsystems, Inc. to assist in its use, correction, 17 | * modification or enhancement. 18 | * 19 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 20 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 21 | * OR ANY PART THEREOF. 22 | * 23 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 24 | * or profits or other special, indirect and consequential damages, even if 25 | * Sun has been advised of the possibility of such damages. 26 | * 27 | * Sun Microsystems, Inc. 28 | * 2550 Garcia Avenue 29 | * Mountain View, California 94043 30 | */ 31 | 32 | /* @(#)rpc_parse.h 1.3 90/08/29 (C) 1987 SMI */ 33 | 34 | /* 35 | * rpc_parse.h, Definitions for the RPCL parser 36 | */ 37 | 38 | enum defkind { 39 | DEF_CONST, 40 | DEF_STRUCT, 41 | DEF_UNION, 42 | DEF_ENUM, 43 | DEF_TYPEDEF, 44 | DEF_PROGRAM 45 | }; 46 | typedef enum defkind defkind; 47 | 48 | typedef char *const_def; 49 | 50 | enum relation { 51 | REL_VECTOR, /* fixed length array */ 52 | REL_ARRAY, /* variable length array */ 53 | REL_POINTER, /* pointer */ 54 | REL_ALIAS, /* simple */ 55 | }; 56 | typedef enum relation relation; 57 | 58 | struct typedef_def { 59 | char *old_prefix; 60 | char *old_type; 61 | relation rel; 62 | char *array_max; 63 | }; 64 | typedef struct typedef_def typedef_def; 65 | 66 | struct enumval_list { 67 | char *name; 68 | char *assignment; 69 | struct enumval_list *next; 70 | }; 71 | typedef struct enumval_list enumval_list; 72 | 73 | struct enum_def { 74 | enumval_list *vals; 75 | }; 76 | typedef struct enum_def enum_def; 77 | 78 | struct declaration { 79 | char *prefix; 80 | char *type; 81 | char *name; 82 | relation rel; 83 | char *array_max; 84 | }; 85 | typedef struct declaration declaration; 86 | 87 | struct decl_list { 88 | declaration decl; 89 | struct decl_list *next; 90 | }; 91 | typedef struct decl_list decl_list; 92 | 93 | struct struct_def { 94 | decl_list *decls; 95 | }; 96 | typedef struct struct_def struct_def; 97 | 98 | struct case_list { 99 | char *case_name; 100 | int contflag; 101 | declaration case_decl; 102 | struct case_list *next; 103 | }; 104 | typedef struct case_list case_list; 105 | 106 | struct union_def { 107 | declaration enum_decl; 108 | case_list *cases; 109 | declaration *default_decl; 110 | }; 111 | typedef struct union_def union_def; 112 | 113 | struct arg_list { 114 | char *argname; /* name of struct for arg*/ 115 | decl_list *decls; 116 | }; 117 | 118 | typedef struct arg_list arg_list; 119 | 120 | struct proc_list { 121 | char *proc_name; 122 | char *proc_num; 123 | arg_list args; 124 | int arg_num; 125 | char *res_type; 126 | char *res_prefix; 127 | struct proc_list *next; 128 | }; 129 | typedef struct proc_list proc_list; 130 | 131 | struct version_list { 132 | char *vers_name; 133 | char *vers_num; 134 | proc_list *procs; 135 | struct version_list *next; 136 | }; 137 | typedef struct version_list version_list; 138 | 139 | struct program_def { 140 | char *prog_num; 141 | version_list *versions; 142 | }; 143 | typedef struct program_def program_def; 144 | 145 | struct definition { 146 | char *def_name; 147 | defkind def_kind; 148 | union { 149 | const_def co; 150 | struct_def st; 151 | union_def un; 152 | enum_def en; 153 | typedef_def ty; 154 | program_def pr; 155 | } def; 156 | }; 157 | typedef struct definition definition; 158 | 159 | definition *get_definition __P((void)); 160 | 161 | struct bas_type 162 | { 163 | char *name; 164 | int length; 165 | struct bas_type *next; 166 | }; 167 | 168 | typedef struct bas_type bas_type; 169 | -------------------------------------------------------------------------------- /rpcgen/rpc_sample.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: rpc_sample.c,v 1.5 1997/10/18 10:54:01 lukem Exp $ */ 2 | /* 3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 4 | * unrestricted use provided that this legend is included on all tape 5 | * media and as a part of the software program in whole or part. Users 6 | * may copy or modify Sun RPC without charge, but are not authorized 7 | * to license or distribute it to anyone else except as part of a product or 8 | * program developed by the user or with the express written consent of 9 | * Sun Microsystems, Inc. 10 | * 11 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 12 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 13 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 14 | * 15 | * Sun RPC is provided with no support and without any obligation on the 16 | * part of Sun Microsystems, Inc. to assist in its use, correction, 17 | * modification or enhancement. 18 | * 19 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 20 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 21 | * OR ANY PART THEREOF. 22 | * 23 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 24 | * or profits or other special, indirect and consequential damages, even if 25 | * Sun has been advised of the possibility of such damages. 26 | * 27 | * Sun Microsystems, Inc. 28 | * 2550 Garcia Avenue 29 | * Mountain View, California 94043 30 | */ 31 | 32 | #include 33 | #ifndef lint 34 | #if 0 35 | static char sccsid[] = "@(#)rpc_sample.c 1.1 90/08/30 (C) 1987 SMI"; 36 | #else 37 | __RCSID("$NetBSD: rpc_sample.c,v 1.5 1997/10/18 10:54:01 lukem Exp $"); 38 | #endif 39 | #endif 40 | 41 | /* 42 | * rpc_sample.c, Sample client-server code outputter for the RPC protocol compiler 43 | */ 44 | 45 | #include 46 | #include 47 | #include "rpc_scan.h" 48 | #include "rpc_parse.h" 49 | #include "rpc_util.h" 50 | 51 | static char RQSTP[] = "rqstp"; 52 | 53 | static void write_sample_client __P((char *, version_list *)); 54 | static void write_sample_server __P((definition *)); 55 | static void return_type __P((proc_list *)); 56 | 57 | void 58 | write_sample_svc(def) 59 | definition *def; 60 | { 61 | 62 | if (def->def_kind != DEF_PROGRAM) 63 | return; 64 | write_sample_server(def); 65 | } 66 | 67 | 68 | int 69 | write_sample_clnt(def) 70 | definition *def; 71 | { 72 | version_list *vp; 73 | int count = 0; 74 | 75 | if (def->def_kind != DEF_PROGRAM) 76 | return (0); 77 | /* generate sample code for each version */ 78 | for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { 79 | write_sample_client(def->def_name, vp); 80 | ++count; 81 | } 82 | return (count); 83 | } 84 | 85 | 86 | static void 87 | write_sample_client(program_name, vp) 88 | char *program_name; 89 | version_list *vp; 90 | { 91 | proc_list *proc; 92 | int i; 93 | decl_list *l; 94 | 95 | f_print(fout, "\n\nvoid\n"); 96 | pvname(program_name, vp->vers_num); 97 | if (Cflag) 98 | f_print(fout, "( char* host )\n{\n"); 99 | else 100 | f_print(fout, "(host)\nchar *host;\n{\n"); 101 | f_print(fout, "\tCLIENT *clnt;\n"); 102 | 103 | i = 0; 104 | for (proc = vp->procs; proc != NULL; proc = proc->next) { 105 | f_print(fout, "\t"); 106 | ptype(proc->res_prefix, proc->res_type, 1); 107 | f_print(fout, " *result_%d;\n", ++i); 108 | /* print out declarations for arguments */ 109 | if (proc->arg_num < 2 && !newstyle) { 110 | f_print(fout, "\t"); 111 | if (!streq(proc->args.decls->decl.type, "void")) 112 | ptype(proc->args.decls->decl.prefix, proc->args.decls->decl.type, 1); 113 | else 114 | f_print(fout, "char* "); /* cannot have "void" 115 | * type */ 116 | f_print(fout, " "); 117 | pvname(proc->proc_name, vp->vers_num); 118 | f_print(fout, "_arg;\n"); 119 | } else 120 | if (!streq(proc->args.decls->decl.type, "void")) { 121 | for (l = proc->args.decls; l != NULL; l = l->next) { 122 | f_print(fout, "\t"); 123 | ptype(l->decl.prefix, l->decl.type, 1); 124 | f_print(fout, " "); 125 | pvname(proc->proc_name, vp->vers_num); 126 | f_print(fout, "_%s;\n", l->decl.name); 127 | /* pdeclaration(proc->args.argname, &l->decl, 1, ";\n" );*/ 128 | } 129 | } 130 | } 131 | 132 | /* generate creation of client handle */ 133 | f_print(fout, "\tclnt = clnt_create(host, %s, %s, \"%s\");\n", 134 | program_name, vp->vers_name, tirpcflag ? "netpath" : "udp"); 135 | f_print(fout, "\tif (clnt == NULL) {\n"); 136 | f_print(fout, "\t\tclnt_pcreateerror(host);\n"); 137 | f_print(fout, "\t\texit(1);\n\t}\n"); 138 | 139 | /* generate calls to procedures */ 140 | i = 0; 141 | for (proc = vp->procs; proc != NULL; proc = proc->next) { 142 | f_print(fout, "\tresult_%d = ", ++i); 143 | pvname(proc->proc_name, vp->vers_num); 144 | if (proc->arg_num < 2 && !newstyle) { 145 | f_print(fout, "("); 146 | if (streq(proc->args.decls->decl.type, "void")) /* cast to void* */ 147 | f_print(fout, "(void*)"); 148 | f_print(fout, "&"); 149 | pvname(proc->proc_name, vp->vers_num); 150 | f_print(fout, "_arg, clnt);\n"); 151 | } else 152 | if (streq(proc->args.decls->decl.type, "void")) { 153 | f_print(fout, "(clnt);\n"); 154 | } else { 155 | f_print(fout, "("); 156 | for (l = proc->args.decls; l != NULL; l = l->next) { 157 | pvname(proc->proc_name, vp->vers_num); 158 | f_print(fout, "_%s, ", l->decl.name); 159 | } 160 | f_print(fout, "clnt);\n"); 161 | } 162 | f_print(fout, "\tif (result_%d == NULL) {\n", i); 163 | f_print(fout, "\t\tclnt_perror(clnt, \"call failed:\");\n"); 164 | f_print(fout, "\t}\n"); 165 | } 166 | 167 | f_print(fout, "\tclnt_destroy( clnt );\n"); 168 | f_print(fout, "}\n"); 169 | } 170 | 171 | static void 172 | write_sample_server(def) 173 | definition *def; 174 | { 175 | version_list *vp; 176 | proc_list *proc; 177 | 178 | for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { 179 | for (proc = vp->procs; proc != NULL; proc = proc->next) { 180 | f_print(fout, "\n"); 181 | /* if( Cflag ) 182 | f_print( fout, "extern \"C\"{\n"); 183 | */ 184 | return_type(proc); 185 | f_print(fout, "*\n"); 186 | if (Cflag) 187 | pvname_svc(proc->proc_name, vp->vers_num); 188 | else 189 | pvname(proc->proc_name, vp->vers_num); 190 | printarglist(proc, RQSTP, "struct svc_req *"); 191 | 192 | f_print(fout, "{\n"); 193 | f_print(fout, "\n\tstatic "); 194 | if (!streq(proc->res_type, "void")) 195 | return_type(proc); 196 | else 197 | f_print(fout, "char*"); /* cannot have void type */ 198 | f_print(fout, " result;\n"); 199 | f_print(fout, 200 | "\n\t/*\n\t * insert server code here\n\t */\n\n"); 201 | if (!streq(proc->res_type, "void")) 202 | f_print(fout, "\treturn(&result);\n}\n"); 203 | else /* cast back to void * */ 204 | f_print(fout, "\treturn((void*) &result);\n}\n"); 205 | /* if( Cflag) 206 | f_print( fout, "};\n"); 207 | */ 208 | 209 | } 210 | } 211 | } 212 | 213 | static void 214 | return_type(plist) 215 | proc_list *plist; 216 | { 217 | ptype(plist->res_prefix, plist->res_type, 1); 218 | } 219 | 220 | void 221 | add_sample_msg() 222 | { 223 | f_print(fout, "/*\n"); 224 | f_print(fout, " * This is sample code generated by rpcgen.\n"); 225 | f_print(fout, " * These are only templates and you can use them\n"); 226 | f_print(fout, " * as a guideline for developing your own functions.\n"); 227 | f_print(fout, " */\n\n"); 228 | } 229 | 230 | void 231 | write_sample_clnt_main() 232 | { 233 | list *l; 234 | definition *def; 235 | version_list *vp; 236 | 237 | f_print(fout, "\n\n"); 238 | if (Cflag) 239 | f_print(fout, "main( int argc, char* argv[] )\n{\n"); 240 | else 241 | f_print(fout, "main(argc, argv)\nint argc;\nchar *argv[];\n{\n"); 242 | 243 | f_print(fout, "\tchar *host;"); 244 | f_print(fout, "\n\n\tif(argc < 2) {"); 245 | f_print(fout, "\n\t\tprintf(\"usage: %%s server_host\\n\", argv[0]);\n"); 246 | f_print(fout, "\t\texit(1);\n\t}"); 247 | f_print(fout, "\n\thost = argv[1];\n"); 248 | 249 | for (l = defined; l != NULL; l = l->next) { 250 | def = l->val; 251 | if (def->def_kind != DEF_PROGRAM) { 252 | continue; 253 | } 254 | for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { 255 | f_print(fout, "\t"); 256 | pvname(def->def_name, vp->vers_num); 257 | f_print(fout, "( host );\n"); 258 | } 259 | } 260 | f_print(fout, "}\n"); 261 | } 262 | -------------------------------------------------------------------------------- /rpcgen/rpc_scan.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: rpc_scan.c,v 1.6 1997/10/18 10:54:05 lukem Exp $ */ 2 | /* 3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 4 | * unrestricted use provided that this legend is included on all tape 5 | * media and as a part of the software program in whole or part. Users 6 | * may copy or modify Sun RPC without charge, but are not authorized 7 | * to license or distribute it to anyone else except as part of a product or 8 | * program developed by the user or with the express written consent of 9 | * Sun Microsystems, Inc. 10 | * 11 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 12 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 13 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 14 | * 15 | * Sun RPC is provided with no support and without any obligation on the 16 | * part of Sun Microsystems, Inc. to assist in its use, correction, 17 | * modification or enhancement. 18 | * 19 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 20 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 21 | * OR ANY PART THEREOF. 22 | * 23 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 24 | * or profits or other special, indirect and consequential damages, even if 25 | * Sun has been advised of the possibility of such damages. 26 | * 27 | * Sun Microsystems, Inc. 28 | * 2550 Garcia Avenue 29 | * Mountain View, California 94043 30 | */ 31 | 32 | #include 33 | #ifndef lint 34 | #if 0 35 | static char sccsid[] = "@(#)rpc_scan.c 1.11 89/02/22 (C) 1987 SMI"; 36 | #else 37 | __RCSID("$NetBSD: rpc_scan.c,v 1.6 1997/10/18 10:54:05 lukem Exp $"); 38 | #endif 39 | #endif 40 | 41 | /* 42 | * rpc_scan.c, Scanner for the RPC protocol compiler 43 | * Copyright (C) 1987, Sun Microsystems, Inc. 44 | */ 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include "rpc_scan.h" 50 | #include "rpc_parse.h" 51 | #include "rpc_util.h" 52 | 53 | #define startcomment(where) (where[0] == '/' && where[1] == '*') 54 | #define endcomment(where) (where[-1] == '*' && where[0] == '/') 55 | 56 | static void unget_token __P((token *)); 57 | static void findstrconst __P((char **, char **)); 58 | static void findchrconst __P((char **, char **)); 59 | static void findconst __P((char **, char **)); 60 | static void findkind __P((char **, token *)); 61 | static int cppline __P((char *)); 62 | static int directive __P((char *)); 63 | static void printdirective __P((char *)); 64 | static void docppline __P((char *, int *, char **)); 65 | 66 | static int pushed = 0; /* is a token pushed */ 67 | static token lasttok; /* last token, if pushed */ 68 | 69 | /* 70 | * scan expecting 1 given token 71 | */ 72 | void 73 | scan(expect, tokp) 74 | tok_kind expect; 75 | token *tokp; 76 | { 77 | get_token(tokp); 78 | if (tokp->kind != expect) { 79 | expected1(expect); 80 | } 81 | } 82 | /* 83 | * scan expecting any of the 2 given tokens 84 | */ 85 | void 86 | scan2(expect1, expect2, tokp) 87 | tok_kind expect1; 88 | tok_kind expect2; 89 | token *tokp; 90 | { 91 | get_token(tokp); 92 | if (tokp->kind != expect1 && tokp->kind != expect2) { 93 | expected2(expect1, expect2); 94 | } 95 | } 96 | /* 97 | * scan expecting any of the 3 given token 98 | */ 99 | void 100 | scan3(expect1, expect2, expect3, tokp) 101 | tok_kind expect1; 102 | tok_kind expect2; 103 | tok_kind expect3; 104 | token *tokp; 105 | { 106 | get_token(tokp); 107 | if (tokp->kind != expect1 && tokp->kind != expect2 108 | && tokp->kind != expect3) { 109 | expected3(expect1, expect2, expect3); 110 | } 111 | } 112 | /* 113 | * scan expecting a constant, possibly symbolic 114 | */ 115 | void 116 | scan_num(tokp) 117 | token *tokp; 118 | { 119 | get_token(tokp); 120 | switch (tokp->kind) { 121 | case TOK_IDENT: 122 | break; 123 | default: 124 | error("constant or identifier expected"); 125 | } 126 | } 127 | /* 128 | * Peek at the next token 129 | */ 130 | void 131 | peek(tokp) 132 | token *tokp; 133 | { 134 | get_token(tokp); 135 | unget_token(tokp); 136 | } 137 | /* 138 | * Peek at the next token and scan it if it matches what you expect 139 | */ 140 | int 141 | peekscan(expect, tokp) 142 | tok_kind expect; 143 | token *tokp; 144 | { 145 | peek(tokp); 146 | if (tokp->kind == expect) { 147 | get_token(tokp); 148 | return (1); 149 | } 150 | return (0); 151 | } 152 | /* 153 | * Get the next token, printing out any directive that are encountered. 154 | */ 155 | void 156 | get_token(tokp) 157 | token *tokp; 158 | { 159 | int commenting; 160 | int stat = 0; 161 | 162 | if (pushed) { 163 | pushed = 0; 164 | *tokp = lasttok; 165 | return; 166 | } 167 | commenting = 0; 168 | for (;;) { 169 | if (*where == 0) { 170 | for (;;) { 171 | if (!fgets(curline, MAXLINESIZE, fin)) { 172 | tokp->kind = TOK_EOF; 173 | /* now check if cpp returned non NULL value */ 174 | waitpid(childpid, &stat, WUNTRACED); 175 | if (stat > 0) { 176 | /* Set return value from rpcgen */ 177 | nonfatalerrors = stat >> 8; 178 | } 179 | *where = 0; 180 | return; 181 | } 182 | linenum++; 183 | if (commenting) { 184 | break; 185 | } else 186 | /* skip lines beginning with #pragma */ 187 | if (!strncmp(curline, "#pragma", 7)) *curline = 0; 188 | else if (cppline(curline)) { 189 | docppline(curline, &linenum, 190 | &infilename); 191 | } else 192 | if (directive(curline)) { 193 | printdirective(curline); 194 | } else { 195 | break; 196 | } 197 | } 198 | where = curline; 199 | } else 200 | if (isspace(*where)) { 201 | while (isspace(*where)) { 202 | where++; /* eat */ 203 | } 204 | } else 205 | if (commenting) { 206 | for (where++; *where; where++) { 207 | if (endcomment(where)) { 208 | where++; 209 | commenting--; 210 | break; 211 | } 212 | } 213 | } else 214 | if (startcomment(where)) { 215 | where += 2; 216 | commenting++; 217 | } else { 218 | break; 219 | } 220 | } 221 | 222 | /* 223 | * 'where' is not whitespace, comment or directive Must be a token! 224 | */ 225 | switch (*where) { 226 | case ':': 227 | tokp->kind = TOK_COLON; 228 | where++; 229 | break; 230 | case ';': 231 | tokp->kind = TOK_SEMICOLON; 232 | where++; 233 | break; 234 | case ',': 235 | tokp->kind = TOK_COMMA; 236 | where++; 237 | break; 238 | case '=': 239 | tokp->kind = TOK_EQUAL; 240 | where++; 241 | break; 242 | case '*': 243 | tokp->kind = TOK_STAR; 244 | where++; 245 | break; 246 | case '[': 247 | tokp->kind = TOK_LBRACKET; 248 | where++; 249 | break; 250 | case ']': 251 | tokp->kind = TOK_RBRACKET; 252 | where++; 253 | break; 254 | case '{': 255 | tokp->kind = TOK_LBRACE; 256 | where++; 257 | break; 258 | case '}': 259 | tokp->kind = TOK_RBRACE; 260 | where++; 261 | break; 262 | case '(': 263 | tokp->kind = TOK_LPAREN; 264 | where++; 265 | break; 266 | case ')': 267 | tokp->kind = TOK_RPAREN; 268 | where++; 269 | break; 270 | case '<': 271 | tokp->kind = TOK_LANGLE; 272 | where++; 273 | break; 274 | case '>': 275 | tokp->kind = TOK_RANGLE; 276 | where++; 277 | break; 278 | 279 | case '"': 280 | tokp->kind = TOK_STRCONST; 281 | findstrconst(&where, &tokp->str); 282 | break; 283 | case '\'': 284 | tokp->kind = TOK_CHARCONST; 285 | findchrconst(&where, &tokp->str); 286 | break; 287 | 288 | case '-': 289 | case '0': 290 | case '1': 291 | case '2': 292 | case '3': 293 | case '4': 294 | case '5': 295 | case '6': 296 | case '7': 297 | case '8': 298 | case '9': 299 | tokp->kind = TOK_IDENT; 300 | findconst(&where, &tokp->str); 301 | break; 302 | 303 | default: 304 | if (!(isalpha(*where) || *where == '_')) { 305 | char buf[100]; 306 | char *p; 307 | 308 | s_print(buf, "illegal character in file: "); 309 | p = buf + strlen(buf); 310 | if (isprint(*where)) { 311 | s_print(p, "%c", *where); 312 | } else { 313 | s_print(p, "%d", *where); 314 | } 315 | error(buf); 316 | } 317 | findkind(&where, tokp); 318 | break; 319 | } 320 | } 321 | 322 | static void 323 | unget_token(tokp) 324 | token *tokp; 325 | { 326 | lasttok = *tokp; 327 | pushed = 1; 328 | } 329 | 330 | static void 331 | findstrconst(str, val) 332 | char **str; 333 | char **val; 334 | { 335 | char *p; 336 | int size; 337 | 338 | p = *str; 339 | do { 340 | p++; 341 | } while (*p && *p != '"'); 342 | if (*p == 0) { 343 | error("unterminated string constant"); 344 | } 345 | p++; 346 | size = p - *str; 347 | *val = alloc(size + 1); 348 | (void) strncpy(*val, *str, size); 349 | (*val)[size] = 0; 350 | *str = p; 351 | } 352 | 353 | static void 354 | findchrconst(str, val) 355 | char **str; 356 | char **val; 357 | { 358 | char *p; 359 | int size; 360 | 361 | p = *str; 362 | do { 363 | p++; 364 | } while (*p && *p != '\''); 365 | if (*p == 0) { 366 | error("unterminated string constant"); 367 | } 368 | p++; 369 | size = p - *str; 370 | if (size != 3) { 371 | error("empty char string"); 372 | } 373 | *val = alloc(size + 1); 374 | (void) strncpy(*val, *str, size); 375 | (*val)[size] = 0; 376 | *str = p; 377 | } 378 | 379 | static void 380 | findconst(str, val) 381 | char **str; 382 | char **val; 383 | { 384 | char *p; 385 | int size; 386 | 387 | p = *str; 388 | if (*p == '0' && *(p + 1) == 'x') { 389 | p++; 390 | do { 391 | p++; 392 | } while (isxdigit(*p)); 393 | } else { 394 | do { 395 | p++; 396 | } while (isdigit(*p)); 397 | } 398 | size = p - *str; 399 | *val = alloc(size + 1); 400 | (void) strncpy(*val, *str, size); 401 | (*val)[size] = 0; 402 | *str = p; 403 | } 404 | 405 | static token symbols[] = { 406 | {TOK_CONST, "const"}, 407 | {TOK_UNION, "union"}, 408 | {TOK_SWITCH, "switch"}, 409 | {TOK_CASE, "case"}, 410 | {TOK_DEFAULT, "default"}, 411 | {TOK_STRUCT, "struct"}, 412 | {TOK_TYPEDEF, "typedef"}, 413 | {TOK_ENUM, "enum"}, 414 | {TOK_OPAQUE, "opaque"}, 415 | {TOK_BOOL, "bool"}, 416 | {TOK_VOID, "void"}, 417 | {TOK_CHAR, "char"}, 418 | {TOK_INT, "int"}, 419 | {TOK_UNSIGNED, "unsigned"}, 420 | {TOK_SHORT, "short"}, 421 | {TOK_LONG, "long"}, 422 | {TOK_HYPER, "hyper"}, 423 | {TOK_FLOAT, "float"}, 424 | {TOK_DOUBLE, "double"}, 425 | {TOK_QUAD, "quadruple"}, 426 | {TOK_STRING, "string"}, 427 | {TOK_PROGRAM, "program"}, 428 | {TOK_VERSION, "version"}, 429 | {TOK_EOF, "??????"}, 430 | }; 431 | 432 | static void 433 | findkind(mark, tokp) 434 | char **mark; 435 | token *tokp; 436 | { 437 | int len; 438 | token *s; 439 | char *str; 440 | 441 | str = *mark; 442 | for (s = symbols; s->kind != TOK_EOF; s++) { 443 | len = strlen(s->str); 444 | if (strncmp(str, s->str, len) == 0) { 445 | if (!isalnum(str[len]) && str[len] != '_') { 446 | tokp->kind = s->kind; 447 | tokp->str = s->str; 448 | *mark = str + len; 449 | return; 450 | } 451 | } 452 | } 453 | tokp->kind = TOK_IDENT; 454 | for (len = 0; isalnum(str[len]) || str[len] == '_'; len++); 455 | tokp->str = alloc(len + 1); 456 | (void) strncpy(tokp->str, str, len); 457 | tokp->str[len] = 0; 458 | *mark = str + len; 459 | } 460 | 461 | static int 462 | cppline(line) 463 | char *line; 464 | { 465 | return (line == curline && *line == '#'); 466 | } 467 | 468 | static int 469 | directive(line) 470 | char *line; 471 | { 472 | return (line == curline && *line == '%'); 473 | } 474 | 475 | static void 476 | printdirective(line) 477 | char *line; 478 | { 479 | f_print(fout, "%s", line + 1); 480 | } 481 | 482 | static void 483 | docppline(line, lineno, fname) 484 | char *line; 485 | int *lineno; 486 | char **fname; 487 | { 488 | char *file; 489 | int num; 490 | char *p; 491 | 492 | line++; 493 | while (isspace(*line)) { 494 | line++; 495 | } 496 | num = atoi(line); 497 | while (isdigit(*line)) { 498 | line++; 499 | } 500 | while (isspace(*line)) { 501 | line++; 502 | } 503 | if (*line != '"') { 504 | error("preprocessor error"); 505 | } 506 | line++; 507 | p = file = alloc(strlen(line) + 1); 508 | while (*line && *line != '"') { 509 | *p++ = *line++; 510 | } 511 | if (*line == 0) { 512 | error("preprocessor error"); 513 | } 514 | *p = 0; 515 | if (*file == 0) { 516 | *fname = NULL; 517 | } else { 518 | *fname = file; 519 | } 520 | *lineno = num - 1; 521 | } 522 | -------------------------------------------------------------------------------- /rpcgen/rpc_scan.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: rpc_scan.h,v 1.4 1997/10/11 21:01:50 christos Exp $ */ 2 | /* 3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 4 | * unrestricted use provided that this legend is included on all tape 5 | * media and as a part of the software program in whole or part. Users 6 | * may copy or modify Sun RPC without charge, but are not authorized 7 | * to license or distribute it to anyone else except as part of a product or 8 | * program developed by the user or with the express written consent of 9 | * Sun Microsystems, Inc. 10 | * 11 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 12 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 13 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 14 | * 15 | * Sun RPC is provided with no support and without any obligation on the 16 | * part of Sun Microsystems, Inc. to assist in its use, correction, 17 | * modification or enhancement. 18 | * 19 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 20 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 21 | * OR ANY PART THEREOF. 22 | * 23 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 24 | * or profits or other special, indirect and consequential damages, even if 25 | * Sun has been advised of the possibility of such damages. 26 | * 27 | * Sun Microsystems, Inc. 28 | * 2550 Garcia Avenue 29 | * Mountain View, California 94043 30 | */ 31 | 32 | /* @(#)rpc_scan.h 1.3 90/08/29 (C) 1987 SMI */ 33 | 34 | /* 35 | * rpc_scan.h, Definitions for the RPCL scanner 36 | */ 37 | 38 | /* 39 | * kinds of tokens 40 | */ 41 | enum tok_kind { 42 | TOK_IDENT, 43 | TOK_CHARCONST, 44 | TOK_STRCONST, 45 | TOK_LPAREN, 46 | TOK_RPAREN, 47 | TOK_LBRACE, 48 | TOK_RBRACE, 49 | TOK_LBRACKET, 50 | TOK_RBRACKET, 51 | TOK_LANGLE, 52 | TOK_RANGLE, 53 | TOK_STAR, 54 | TOK_COMMA, 55 | TOK_EQUAL, 56 | TOK_COLON, 57 | TOK_SEMICOLON, 58 | TOK_CONST, 59 | TOK_STRUCT, 60 | TOK_UNION, 61 | TOK_SWITCH, 62 | TOK_CASE, 63 | TOK_DEFAULT, 64 | TOK_ENUM, 65 | TOK_TYPEDEF, 66 | TOK_INT, 67 | TOK_SHORT, 68 | TOK_LONG, 69 | TOK_HYPER, 70 | TOK_UNSIGNED, 71 | TOK_FLOAT, 72 | TOK_DOUBLE, 73 | TOK_QUAD, 74 | TOK_OPAQUE, 75 | TOK_CHAR, 76 | TOK_STRING, 77 | TOK_BOOL, 78 | TOK_VOID, 79 | TOK_PROGRAM, 80 | TOK_VERSION, 81 | TOK_EOF 82 | }; 83 | typedef enum tok_kind tok_kind; 84 | 85 | /* 86 | * a token 87 | */ 88 | struct token { 89 | tok_kind kind; 90 | char *str; 91 | }; 92 | typedef struct token token; 93 | 94 | 95 | /* 96 | * routine interface 97 | */ 98 | void scan __P((tok_kind, token *)); 99 | void scan2 __P((tok_kind, tok_kind, token *)); 100 | void scan3 __P((tok_kind, tok_kind, tok_kind, token *)); 101 | void scan_num __P((token *)); 102 | void peek __P((token *)); 103 | int peekscan __P((tok_kind, token *)); 104 | void get_token __P((token *)); 105 | -------------------------------------------------------------------------------- /rpcgen/rpc_tblout.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: rpc_tblout.c,v 1.7 1997/10/18 10:54:11 lukem Exp $ */ 2 | /* 3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 4 | * unrestricted use provided that this legend is included on all tape 5 | * media and as a part of the software program in whole or part. Users 6 | * may copy or modify Sun RPC without charge, but are not authorized 7 | * to license or distribute it to anyone else except as part of a product or 8 | * program developed by the user or with the express written consent of 9 | * Sun Microsystems, Inc. 10 | * 11 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 12 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 13 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 14 | * 15 | * Sun RPC is provided with no support and without any obligation on the 16 | * part of Sun Microsystems, Inc. to assist in its use, correction, 17 | * modification or enhancement. 18 | * 19 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 20 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 21 | * OR ANY PART THEREOF. 22 | * 23 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 24 | * or profits or other special, indirect and consequential damages, even if 25 | * Sun has been advised of the possibility of such damages. 26 | * 27 | * Sun Microsystems, Inc. 28 | * 2550 Garcia Avenue 29 | * Mountain View, California 94043 30 | */ 31 | 32 | #include 33 | #ifndef lint 34 | #if 0 35 | static char sccsid[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI"; 36 | #else 37 | __RCSID("$NetBSD: rpc_tblout.c,v 1.7 1997/10/18 10:54:11 lukem Exp $"); 38 | #endif 39 | #endif 40 | 41 | /* 42 | * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler 43 | */ 44 | #include 45 | #include 46 | #include 47 | #include "rpc_scan.h" 48 | #include "rpc_parse.h" 49 | #include "rpc_util.h" 50 | 51 | #define TABSIZE 8 52 | #define TABCOUNT 5 53 | #define TABSTOP (TABSIZE*TABCOUNT) 54 | 55 | static char tabstr[TABCOUNT + 1] = "\t\t\t\t\t"; 56 | 57 | static char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n"; 58 | static char tbl_end[] = "};\n"; 59 | 60 | static char null_entry[] = "\t(char *(*)())0,\n\ 61 | \t(xdrproc_t)xdr_void,\t\t0,\n\ 62 | \t(xdrproc_t)xdr_void,\t\t0,\n"; 63 | 64 | static char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n"; 65 | 66 | static void write_table __P((definition *)); 67 | static void printit __P((char *, char *)); 68 | 69 | void 70 | write_tables() 71 | { 72 | list *l; 73 | definition *def; 74 | 75 | f_print(fout, "\n"); 76 | for (l = defined; l != NULL; l = l->next) { 77 | def = (definition *) l->val; 78 | if (def->def_kind == DEF_PROGRAM) { 79 | write_table(def); 80 | } 81 | } 82 | } 83 | 84 | static void 85 | write_table(def) 86 | definition *def; 87 | { 88 | version_list *vp; 89 | proc_list *proc; 90 | int current; 91 | int expected; 92 | char progvers[100]; 93 | int warning; 94 | 95 | for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { 96 | warning = 0; 97 | s_print(progvers, "%s_%s", 98 | locase(def->def_name), vp->vers_num); 99 | /* print the table header */ 100 | f_print(fout, tbl_hdr, progvers); 101 | 102 | if (nullproc(vp->procs)) { 103 | expected = 0; 104 | } else { 105 | expected = 1; 106 | f_print(fout, "%s", null_entry); 107 | } 108 | for (proc = vp->procs; proc != NULL; proc = proc->next) { 109 | if (expected != 0) 110 | f_print(fout, "\n"); 111 | current = atoi(proc->proc_num); 112 | if (current != expected++) { 113 | f_print(fout, 114 | "/*\n * WARNING: table out of order\n */\n\n"); 115 | if (warning == 0) { 116 | f_print(stderr, 117 | "WARNING %s table is out of order\n", 118 | progvers); 119 | warning = 1; 120 | nonfatalerrors = 1; 121 | } 122 | expected = current + 1; 123 | } 124 | f_print(fout, "\t(char *(*)())RPCGEN_ACTION("); 125 | 126 | /* routine to invoke */ 127 | if (!newstyle) 128 | pvname_svc(proc->proc_name, vp->vers_num); 129 | else { 130 | if (newstyle) 131 | f_print(fout, "_"); /* calls internal func */ 132 | pvname(proc->proc_name, vp->vers_num); 133 | } 134 | f_print(fout, "),\n"); 135 | 136 | /* argument info */ 137 | if (proc->arg_num > 1) 138 | printit((char *) NULL, proc->args.argname); 139 | else 140 | /* do we have to do something special for 141 | * newstyle */ 142 | printit(proc->args.decls->decl.prefix, 143 | proc->args.decls->decl.type); 144 | /* result info */ 145 | printit(proc->res_prefix, proc->res_type); 146 | } 147 | 148 | /* print the table trailer */ 149 | f_print(fout, "%s", tbl_end); 150 | f_print(fout, tbl_nproc, progvers, progvers, progvers); 151 | } 152 | } 153 | 154 | static void 155 | printit(prefix, type) 156 | char *prefix; 157 | char *type; 158 | { 159 | int len; 160 | int tabs; 161 | 162 | 163 | len = fprintf(fout, "\txdr_%s,", stringfix(type)); 164 | /* account for leading tab expansion */ 165 | len += TABSIZE - 1; 166 | /* round up to tabs required */ 167 | tabs = (TABSTOP - len + TABSIZE - 1) / TABSIZE; 168 | f_print(fout, "%s", &tabstr[TABCOUNT - tabs]); 169 | 170 | if (streq(type, "void")) { 171 | f_print(fout, "0"); 172 | } else { 173 | f_print(fout, "sizeof ( "); 174 | /* XXX: should "follow" be 1 ??? */ 175 | ptype(prefix, type, 0); 176 | f_print(fout, ")"); 177 | } 178 | f_print(fout, ",\n"); 179 | } 180 | -------------------------------------------------------------------------------- /rpcgen/rpc_util.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: rpc_util.c,v 1.8 1997/10/18 10:54:14 lukem Exp $ */ 2 | /* 3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 4 | * unrestricted use provided that this legend is included on all tape 5 | * media and as a part of the software program in whole or part. Users 6 | * may copy or modify Sun RPC without charge, but are not authorized 7 | * to license or distribute it to anyone else except as part of a product or 8 | * program developed by the user or with the express written consent of 9 | * Sun Microsystems, Inc. 10 | * 11 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 12 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 13 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 14 | * 15 | * Sun RPC is provided with no support and without any obligation on the 16 | * part of Sun Microsystems, Inc. to assist in its use, correction, 17 | * modification or enhancement. 18 | * 19 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 20 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 21 | * OR ANY PART THEREOF. 22 | * 23 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 24 | * or profits or other special, indirect and consequential damages, even if 25 | * Sun has been advised of the possibility of such damages. 26 | * 27 | * Sun Microsystems, Inc. 28 | * 2550 Garcia Avenue 29 | * Mountain View, California 94043 30 | */ 31 | 32 | #include 33 | #ifndef lint 34 | #if 0 35 | static char sccsid[] = "@(#)rpc_util.c 1.11 89/02/22 (C) 1987 SMI"; 36 | #else 37 | __RCSID("$NetBSD: rpc_util.c,v 1.8 1997/10/18 10:54:14 lukem Exp $"); 38 | #endif 39 | #endif 40 | 41 | /* 42 | * rpc_util.c, Utility routines for the RPC protocol compiler 43 | */ 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include "rpc_scan.h" 50 | #include "rpc_parse.h" 51 | #include "rpc_util.h" 52 | 53 | #define ARGEXT "argument" 54 | 55 | static void printwhere __P((void)); 56 | 57 | char curline[MAXLINESIZE]; /* current read line */ 58 | char *where = curline; /* current point in line */ 59 | int linenum = 0; /* current line number */ 60 | 61 | char *infilename; /* input filename */ 62 | 63 | #define NFILES 7 64 | char *outfiles[NFILES]; /* output file names */ 65 | int nfiles; 66 | 67 | FILE *fout; /* file pointer of current output */ 68 | FILE *fin; /* file pointer of current input */ 69 | 70 | list *defined; /* list of defined things */ 71 | 72 | static char *toktostr __P((tok_kind)); 73 | static void printbuf __P((void)); 74 | static void printwhere __P((void)); 75 | static int findit __P((definition *, char *)); 76 | static char *fixit __P((char *, char *)); 77 | static int typedefed __P((definition *, char *)); 78 | 79 | /* 80 | * Reinitialize the world 81 | */ 82 | void 83 | reinitialize() 84 | { 85 | memset(curline, 0, MAXLINESIZE); 86 | where = curline; 87 | linenum = 0; 88 | defined = NULL; 89 | } 90 | /* 91 | * string equality 92 | */ 93 | int 94 | streq(a, b) 95 | char *a; 96 | char *b; 97 | { 98 | return (strcmp(a, b) == 0); 99 | } 100 | /* 101 | * find a value in a list 102 | */ 103 | definition * 104 | findval(lst, val, cmp) 105 | list *lst; 106 | char *val; 107 | int (*cmp) __P((definition *, char *)); 108 | 109 | { 110 | 111 | for (; lst != NULL; lst = lst->next) { 112 | if ((*cmp) (lst->val, val)) { 113 | return (lst->val); 114 | } 115 | } 116 | return (NULL); 117 | } 118 | /* 119 | * store a value in a list 120 | */ 121 | void 122 | storeval(lstp, val) 123 | list **lstp; 124 | definition *val; 125 | { 126 | list **l; 127 | list *lst; 128 | 129 | 130 | for (l = lstp; *l != NULL; l = (list **) & (*l)->next); 131 | lst = ALLOC(list); 132 | lst->val = val; 133 | lst->next = NULL; 134 | *l = lst; 135 | } 136 | 137 | static int 138 | findit(def, type) 139 | definition *def; 140 | char *type; 141 | { 142 | return (streq(def->def_name, type)); 143 | } 144 | 145 | static char * 146 | fixit(type, orig) 147 | char *type; 148 | char *orig; 149 | { 150 | definition *def; 151 | 152 | def = (definition *) FINDVAL(defined, type, findit); 153 | if (def == NULL || def->def_kind != DEF_TYPEDEF) { 154 | return (orig); 155 | } 156 | switch (def->def.ty.rel) { 157 | case REL_VECTOR: 158 | return (def->def.ty.old_type); 159 | case REL_ALIAS: 160 | return (fixit(def->def.ty.old_type, orig)); 161 | default: 162 | return (orig); 163 | } 164 | } 165 | 166 | char * 167 | fixtype(type) 168 | char *type; 169 | { 170 | return (fixit(type, type)); 171 | } 172 | 173 | char * 174 | stringfix(type) 175 | char *type; 176 | { 177 | if (streq(type, "string")) { 178 | return ("wrapstring"); 179 | } else { 180 | return (type); 181 | } 182 | } 183 | 184 | void 185 | ptype(prefix, type, follow) 186 | char *prefix; 187 | char *type; 188 | int follow; 189 | { 190 | if (prefix != NULL) { 191 | if (streq(prefix, "enum")) { 192 | f_print(fout, "enum "); 193 | } else { 194 | f_print(fout, "struct "); 195 | } 196 | } 197 | if (streq(type, "bool")) { 198 | f_print(fout, "bool_t "); 199 | } else 200 | if (streq(type, "string")) { 201 | f_print(fout, "char *"); 202 | } else { 203 | f_print(fout, "%s ", follow ? fixtype(type) : type); 204 | } 205 | } 206 | 207 | static int 208 | typedefed(def, type) 209 | definition *def; 210 | char *type; 211 | { 212 | if (def->def_kind != DEF_TYPEDEF || def->def.ty.old_prefix != NULL) { 213 | return (0); 214 | } else { 215 | return (streq(def->def_name, type)); 216 | } 217 | } 218 | 219 | int 220 | isvectordef(type, rel) 221 | char *type; 222 | relation rel; 223 | { 224 | definition *def; 225 | 226 | for (;;) { 227 | switch (rel) { 228 | case REL_VECTOR: 229 | return (!streq(type, "string")); 230 | case REL_ARRAY: 231 | return (0); 232 | case REL_POINTER: 233 | return (0); 234 | case REL_ALIAS: 235 | def = (definition *) FINDVAL(defined, type, typedefed); 236 | if (def == NULL) { 237 | return (0); 238 | } 239 | type = def->def.ty.old_type; 240 | rel = def->def.ty.rel; 241 | } 242 | } 243 | } 244 | 245 | char * 246 | locase(str) 247 | char *str; 248 | { 249 | char c; 250 | static char buf[100]; 251 | char *p = buf; 252 | 253 | while ((c = *str++) != '\0') { 254 | *p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c; 255 | } 256 | *p = 0; 257 | return (buf); 258 | } 259 | 260 | void 261 | pvname_svc(pname, vnum) 262 | char *pname; 263 | char *vnum; 264 | { 265 | f_print(fout, "%s_%s_svc", locase(pname), vnum); 266 | } 267 | 268 | void 269 | pvname(pname, vnum) 270 | char *pname; 271 | char *vnum; 272 | { 273 | f_print(fout, "%s_%s", locase(pname), vnum); 274 | } 275 | /* 276 | * print a useful (?) error message, and then die 277 | */ 278 | void 279 | error(msg) 280 | char *msg; 281 | { 282 | printwhere(); 283 | f_print(stderr, "%s, line %d: ", infilename, linenum); 284 | f_print(stderr, "%s\n", msg); 285 | crash(); 286 | } 287 | /* 288 | * Something went wrong, unlink any files that we may have created and then 289 | * die. 290 | */ 291 | void 292 | crash() 293 | { 294 | int i; 295 | 296 | for (i = 0; i < nfiles; i++) { 297 | (void) unlink(outfiles[i]); 298 | } 299 | exit(1); 300 | } 301 | 302 | void 303 | record_open(file) 304 | char *file; 305 | { 306 | if (nfiles < NFILES) { 307 | outfiles[nfiles++] = file; 308 | } else { 309 | f_print(stderr, "too many files!\n"); 310 | crash(); 311 | } 312 | } 313 | 314 | static char expectbuf[100]; 315 | 316 | /* 317 | * error, token encountered was not the expected one 318 | */ 319 | void 320 | expected1(exp1) 321 | tok_kind exp1; 322 | { 323 | s_print(expectbuf, "expected '%s'", 324 | toktostr(exp1)); 325 | error(expectbuf); 326 | } 327 | /* 328 | * error, token encountered was not one of two expected ones 329 | */ 330 | void 331 | expected2(exp1, exp2) 332 | tok_kind exp1, exp2; 333 | { 334 | s_print(expectbuf, "expected '%s' or '%s'", 335 | toktostr(exp1), 336 | toktostr(exp2)); 337 | error(expectbuf); 338 | } 339 | /* 340 | * error, token encountered was not one of 3 expected ones 341 | */ 342 | void 343 | expected3(exp1, exp2, exp3) 344 | tok_kind exp1, exp2, exp3; 345 | { 346 | s_print(expectbuf, "expected '%s', '%s' or '%s'", 347 | toktostr(exp1), 348 | toktostr(exp2), 349 | toktostr(exp3)); 350 | error(expectbuf); 351 | } 352 | 353 | void 354 | tabify(f, tab) 355 | FILE *f; 356 | int tab; 357 | { 358 | while (tab--) { 359 | (void) fputc('\t', f); 360 | } 361 | } 362 | 363 | 364 | static token tokstrings[] = { 365 | {TOK_IDENT, "identifier"}, 366 | {TOK_CONST, "const"}, 367 | {TOK_RPAREN, ")"}, 368 | {TOK_LPAREN, "("}, 369 | {TOK_RBRACE, "}"}, 370 | {TOK_LBRACE, "{"}, 371 | {TOK_LBRACKET, "["}, 372 | {TOK_RBRACKET, "]"}, 373 | {TOK_STAR, "*"}, 374 | {TOK_COMMA, ","}, 375 | {TOK_EQUAL, "="}, 376 | {TOK_COLON, ":"}, 377 | {TOK_SEMICOLON, ";"}, 378 | {TOK_UNION, "union"}, 379 | {TOK_STRUCT, "struct"}, 380 | {TOK_SWITCH, "switch"}, 381 | {TOK_CASE, "case"}, 382 | {TOK_DEFAULT, "default"}, 383 | {TOK_ENUM, "enum"}, 384 | {TOK_TYPEDEF, "typedef"}, 385 | {TOK_INT, "int"}, 386 | {TOK_SHORT, "short"}, 387 | {TOK_LONG, "long"}, 388 | {TOK_UNSIGNED, "unsigned"}, 389 | {TOK_DOUBLE, "double"}, 390 | {TOK_FLOAT, "float"}, 391 | {TOK_CHAR, "char"}, 392 | {TOK_STRING, "string"}, 393 | {TOK_OPAQUE, "opaque"}, 394 | {TOK_BOOL, "bool"}, 395 | {TOK_VOID, "void"}, 396 | {TOK_PROGRAM, "program"}, 397 | {TOK_VERSION, "version"}, 398 | {TOK_EOF, "??????"} 399 | }; 400 | 401 | static char * 402 | toktostr(kind) 403 | tok_kind kind; 404 | { 405 | token *sp; 406 | 407 | for (sp = tokstrings; sp->kind != TOK_EOF && sp->kind != kind; sp++); 408 | return (sp->str); 409 | } 410 | 411 | static void 412 | printbuf() 413 | { 414 | char c; 415 | int i; 416 | int cnt; 417 | 418 | #define TABSIZE 4 419 | 420 | for (i = 0; (c = curline[i]) != '\0'; i++) { 421 | if (c == '\t') { 422 | cnt = 8 - (i % TABSIZE); 423 | c = ' '; 424 | } else { 425 | cnt = 1; 426 | } 427 | while (cnt--) { 428 | (void) fputc(c, stderr); 429 | } 430 | } 431 | } 432 | 433 | static void 434 | printwhere() 435 | { 436 | int i; 437 | char c; 438 | int cnt; 439 | 440 | printbuf(); 441 | for (i = 0; i < where - curline; i++) { 442 | c = curline[i]; 443 | if (c == '\t') { 444 | cnt = 8 - (i % TABSIZE); 445 | } else { 446 | cnt = 1; 447 | } 448 | while (cnt--) { 449 | (void) fputc('^', stderr); 450 | } 451 | } 452 | (void) fputc('\n', stderr); 453 | } 454 | 455 | char * 456 | make_argname(pname, vname) 457 | char *pname; 458 | char *vname; 459 | { 460 | char *name; 461 | 462 | name = (char *) malloc(strlen(pname) + strlen(vname) + strlen(ARGEXT) + 3); 463 | if (!name) { 464 | fprintf(stderr, "failed in malloc"); 465 | exit(1); 466 | } 467 | sprintf(name, "%s_%s_%s", locase(pname), vname, ARGEXT); 468 | return (name); 469 | } 470 | 471 | bas_type *typ_list_h; 472 | bas_type *typ_list_t; 473 | 474 | void 475 | add_type(len, type) 476 | int len; 477 | char *type; 478 | { 479 | bas_type *ptr; 480 | 481 | if ((ptr = (bas_type *) malloc(sizeof(bas_type))) == (bas_type *) NULL) { 482 | fprintf(stderr, "failed in malloc"); 483 | exit(1); 484 | } 485 | ptr->name = type; 486 | ptr->length = len; 487 | ptr->next = NULL; 488 | if (typ_list_t == NULL) { 489 | typ_list_t = ptr; 490 | typ_list_h = ptr; 491 | } else { 492 | typ_list_t->next = ptr; 493 | typ_list_t = ptr; 494 | } 495 | } 496 | 497 | bas_type * 498 | find_type(type) 499 | char *type; 500 | { 501 | bas_type *ptr; 502 | 503 | ptr = typ_list_h; 504 | 505 | 506 | while (ptr != NULL) { 507 | if (strcmp(ptr->name, type) == 0) 508 | return (ptr); 509 | else 510 | ptr = ptr->next; 511 | } 512 | return (NULL); 513 | } 514 | -------------------------------------------------------------------------------- /rpcgen/rpc_util.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: rpc_util.h,v 1.4 1997/10/11 21:01:58 christos Exp $ */ 2 | /* 3 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 4 | * unrestricted use provided that this legend is included on all tape 5 | * media and as a part of the software program in whole or part. Users 6 | * may copy or modify Sun RPC without charge, but are not authorized 7 | * to license or distribute it to anyone else except as part of a product or 8 | * program developed by the user or with the express written consent of 9 | * Sun Microsystems, Inc. 10 | * 11 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 12 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 13 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 14 | * 15 | * Sun RPC is provided with no support and without any obligation on the 16 | * part of Sun Microsystems, Inc. to assist in its use, correction, 17 | * modification or enhancement. 18 | * 19 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 20 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 21 | * OR ANY PART THEREOF. 22 | * 23 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue 24 | * or profits or other special, indirect and consequential damages, even if 25 | * Sun has been advised of the possibility of such damages. 26 | * 27 | * Sun Microsystems, Inc. 28 | * 2550 Garcia Avenue 29 | * Mountain View, California 94043 30 | */ 31 | 32 | /* @(#)rpc_util.h 1.5 90/08/29 (C) 1987 SMI */ 33 | 34 | /* 35 | * rpc_util.h, Useful definitions for the RPC protocol compiler 36 | */ 37 | #include 38 | #include 39 | 40 | #define alloc(size) (void *)malloc((unsigned)(size)) 41 | #define ALLOC(object) (object *) malloc(sizeof(object)) 42 | 43 | #define s_print (void) sprintf 44 | #define f_print (void) fprintf 45 | 46 | struct list { 47 | definition *val; 48 | struct list *next; 49 | }; 50 | typedef struct list list; 51 | 52 | #define PUT 1 53 | #define GET 2 54 | 55 | /* 56 | * Global variables 57 | */ 58 | #define MAXLINESIZE 1024 59 | extern char curline[MAXLINESIZE]; 60 | extern char *where; 61 | extern int linenum; 62 | 63 | extern char *infilename; 64 | extern FILE *fout; 65 | extern FILE *fin; 66 | 67 | extern list *defined; 68 | 69 | 70 | extern bas_type *typ_list_h; 71 | extern bas_type *typ_list_t; 72 | 73 | /* 74 | * All the option flags 75 | */ 76 | extern int inetdflag; 77 | extern int pmflag; 78 | extern int tblflag; 79 | extern int logflag; 80 | extern int newstyle; 81 | extern int Cflag; /* C++ flag */ 82 | extern int tirpcflag; /* flag for generating tirpc code */ 83 | extern int doinline; /* if this is 0, then do not generate inline code */ 84 | extern int callerflag; 85 | 86 | /* 87 | * Other flags related with inetd jumpstart. 88 | */ 89 | extern int indefinitewait; 90 | extern int exitnow; 91 | extern int timerflag; 92 | 93 | extern int nonfatalerrors; 94 | 95 | extern pid_t childpid; 96 | 97 | /* 98 | * rpc_util routines 99 | */ 100 | 101 | #define STOREVAL(list,item) \ 102 | storeval(list,item) 103 | 104 | #define FINDVAL(list,item,finder) \ 105 | findval(list, item, finder) 106 | 107 | void reinitialize __P((void)); 108 | int streq __P((char *, char *)); 109 | definition *findval __P((list *, char *, int (*)(definition *, char *))); 110 | void storeval __P((list **, definition *)); 111 | char *fixtype __P((char *)); 112 | char *stringfix __P((char *)); 113 | void ptype __P((char *, char *, int)); 114 | int isvectordef __P((char *, relation)); 115 | char *locase __P((char *)); 116 | void pvname_svc __P((char *, char *)); 117 | void pvname __P((char *, char *)); 118 | void error __P((char *)); 119 | void crash __P((void)); 120 | void record_open __P((char *)); 121 | void expected1 __P((tok_kind)); 122 | void expected2 __P((tok_kind, tok_kind )); 123 | void expected3 __P((tok_kind, tok_kind, tok_kind)); 124 | void tabify __P((FILE *, int)); 125 | void record_open __P((char *)); 126 | char *make_argname __P((char *, char *)); 127 | void add_type __P((int, char *)); 128 | bas_type *find_type __P((char *)); 129 | /* 130 | * rpc_cout routines 131 | */ 132 | void emit __P((definition *)); 133 | void emit_inline __P((declaration *, int)); 134 | void emit_single_in_line __P((declaration *, int, relation)); 135 | char *upcase __P((char *)); 136 | 137 | /* 138 | * rpc_hout routines 139 | */ 140 | 141 | void print_datadef __P((definition *)); 142 | void print_funcdef __P((definition *)); 143 | void pxdrfuncdecl __P((char *, int)); 144 | void pprocdef __P((proc_list *, version_list *, char *, int, int)); 145 | void pdeclaration __P((char *, declaration *, int, char *)); 146 | 147 | /* 148 | * rpc_svcout routines 149 | */ 150 | void write_most __P((char *, int, int)); 151 | void write_netid_register __P((char *)); 152 | void write_nettype_register __P((char *)); 153 | void write_rest __P((void)); 154 | void write_programs __P((char *)); 155 | int nullproc __P((proc_list *)); 156 | void write_svc_aux __P((int)); 157 | void write_msg_out __P((void)); 158 | void write_inetd_register __P((char *)); 159 | 160 | /* 161 | * rpc_clntout routines 162 | */ 163 | void write_stubs __P((void)); 164 | void printarglist __P((proc_list *, char *, char *)); 165 | 166 | 167 | /* 168 | * rpc_tblout routines 169 | */ 170 | void write_tables __P((void)); 171 | 172 | /* 173 | * rpc_sample routines 174 | */ 175 | void write_sample_svc __P((definition *)); 176 | int write_sample_clnt __P((definition *)); 177 | void add_sample_msg __P((void)); 178 | void write_sample_clnt_main __P((void)); 179 | -------------------------------------------------------------------------------- /rpcgen/rpcgen.1: -------------------------------------------------------------------------------- 1 | .\" $NetBSD: rpcgen.1,v 1.8 1998/04/28 07:19:29 fair Exp $ 2 | .\" from: @(#)rpcgen.new.1 1.1 90/11/09 TIRPC 1.0; from 40.10 of 10/10/89 3 | .\" Copyright (c) 1988,1990 Sun Microsystems, Inc. - All Rights Reserved. 4 | .Dd June 11, 1995 5 | .Dt RPCGEN 1 6 | .Sh NAME 7 | .Nm rpcgen 8 | .Nd Remote Procedure Call (RPC) protocol compiler 9 | .Sh SYNOPSIS 10 | .Nm 11 | .Ar infile 12 | .Nm 13 | .Op Fl D Op Ar name=value 14 | .Op Fl A 15 | .Op Fl M 16 | .Op Fl T 17 | .Op Fl K Ar secs 18 | .Ar infile 19 | .Nm 20 | .Op Fl L 21 | .Fl c Li | 22 | .Fl h Li | 23 | .Fl l Li | 24 | .Fl m Li | 25 | .Fl t Li | 26 | .Fl S\&c Li | 27 | .Fl S\&s Li | 28 | .Op Fl o Ar outfile 29 | .Op Ar infile 30 | .Nm 31 | .Fl c Li | 32 | .Ar nettype 33 | .Op Fl o Ar outfile 34 | .Op Ar infile 35 | .Nm 36 | .Fl s Li | 37 | .Ar netid 38 | .Op Fl o Ar outfile 39 | .Op Ar infile 40 | .Sh DESCRIPTION 41 | .Nm 42 | is a tool that generates C code to implement an 43 | .Tn RPC 44 | protocol. 45 | The input to 46 | .Nm 47 | is a language similar to C known as 48 | .Tn RPC 49 | Language (Remote Procedure Call Language). 50 | .Nm 51 | is normally used as in the first synopsis where 52 | it takes an input file and generates up to four output files. 53 | If the 54 | .Ar infile 55 | is named 56 | .Pa proto.x , 57 | then 58 | .Nm 59 | will generate a header file in 60 | .Pa proto.h , 61 | .Tn XDR 62 | routines in 63 | .Pa proto_xdr.c , 64 | server-side stubs in 65 | .Pa proto_svc.c , 66 | and client-side stubs in 67 | .Pa proto_clnt.c . 68 | With the 69 | .Fl T 70 | option, 71 | it will also generate the 72 | .Tn RPC 73 | dispatch table in 74 | .Pa proto_tbl.i . 75 | With the 76 | .Fl S\&c 77 | option, 78 | it will also generate sample code which would illustrate how to use the 79 | remote procedures on the client side. This code would be created in 80 | .Pa proto_client.c . 81 | With the 82 | .Fl S\&s 83 | option, 84 | it will also generate a sample server code which would illustrate how to write 85 | the remote procedures. This code would be created in 86 | .Pa proto_server.c . 87 | .Pp 88 | The server created can be started both by the port monitors 89 | (for example, 90 | .Em inetd 91 | or 92 | .Em listen ) 93 | or by itself. 94 | When it is started by a port monitor, 95 | it creates servers only for the transport for which 96 | the file descriptor 0 was passed. 97 | The name of the transport must be specified 98 | by setting up the environmental variable 99 | .Ev PM_TRANSPORT . 100 | When the server generated by 101 | .Nm 102 | is executed, 103 | it creates server handles for all the transports 104 | specified in 105 | .Ev NETPATH 106 | environment variable, 107 | or if it is unset, 108 | it creates server handles for all the visible transports from 109 | .Pa /etc/netconfig 110 | file. 111 | .Pp 112 | .Em Note: 113 | the transports are chosen at run time and not at compile time. 114 | When the server is self-started, 115 | it backgrounds itself by default. 116 | A special define symbol 117 | .Dv RPC_SVC_FG 118 | can be used to run the server process in foreground. 119 | .P 120 | The second synopsis provides special features which allow 121 | for the creation of more sophisticated 122 | .Tn RPC 123 | servers. 124 | These features include support for user provided 125 | .Li #defines 126 | and 127 | .Tn RPC 128 | dispatch tables. 129 | The entries in the 130 | .Tn RPC 131 | dispatch table contain: 132 | .Pp 133 | .Bl -inset -offset indent -compact 134 | .It + 135 | pointers to the service routine corresponding to that procedure, 136 | .It + 137 | a pointer to the input and output arguments, 138 | .It + 139 | the size of these routines 140 | .El 141 | .Pp 142 | A server can use the dispatch table to check authorization 143 | and then to execute the service routine; 144 | a client library may use it to deal with the details of storage 145 | management and 146 | .Tn XDR 147 | data conversion. 148 | .Pp 149 | The other three synopses shown above are used when 150 | one does not want to generate all the output files, 151 | but only a particular one. 152 | Some examples of their usage is described in the 153 | EXAMPLE 154 | section below. 155 | When 156 | .Nm 157 | is executed with the 158 | .Fl s 159 | option, 160 | it creates servers for that particular class of transports. 161 | When 162 | executed with the 163 | .Fl n 164 | option, 165 | it creates a server for the transport specified by 166 | .Em netid . 167 | If 168 | .Ar infile 169 | is not specified, 170 | .Nm 171 | accepts the standard input. 172 | .Pp 173 | The C preprocessor, 174 | .Xr cpp 1 175 | is run on the input file before it is actually interpreted by 176 | .Nm 177 | For each type of output file, 178 | .Nm 179 | defines a special preprocessor symbol for use by the 180 | .Nm 181 | programmer: 182 | .Bl -tag -width RPC_CLNT 183 | .It Dv RPC_HDR 184 | defined when compiling into header files 185 | .It Dv RPC_XDR 186 | defined when compiling into 187 | .Tn XDR 188 | routines 189 | .It Dv RPC_SVC 190 | defined when compiling into server-side stubs 191 | .It Dv RPC_CLNT 192 | defined when compiling into client-side stubs 193 | .It Dv RPC_TBL 194 | defined when compiling into 195 | .Tn RPC 196 | dispatch tables 197 | .El 198 | .Pp 199 | Any line beginning with 200 | .Sq % 201 | is passed directly into the output file, 202 | uninterpreted by 203 | .Nm . 204 | .Pp 205 | For every data type referred to in 206 | .Ar infile 207 | .Nm 208 | assumes that there exists a 209 | routine with the string 210 | .Dq xdr_ 211 | prepended to the name of the data type. 212 | If this routine does not exist in the 213 | .Tn RPC/XDR 214 | library, it must be provided. 215 | Providing an undefined data type 216 | allows customization of 217 | .Tn XDR 218 | routines. 219 | .Sh OPTIONS 220 | .Bl -tag -width indent 221 | .It Fl a 222 | Generate all the files including sample code for client and server side. 223 | .It Fl b 224 | This generates code for the 225 | .Tn "SunOS 4.1" 226 | style of 227 | .Tn RPC . 228 | This is the default. 229 | .It Fl C 230 | Generate code in 231 | .Tn ANSI 232 | C. 233 | This option also generates code that could be compiled with the 234 | C++ compiler. 235 | .It Fl c 236 | Compile into 237 | .Tn XDR 238 | routines. 239 | .It Fl D Ar name Ns Op Ar =value 240 | Define a symbol 241 | .Dv name . 242 | Equivalent to the 243 | .Dv #define 244 | directive in the source. 245 | If no 246 | .Dv value 247 | is given, 248 | .Dv value 249 | is defined as 1. 250 | This option may be specified more than once. 251 | .It Fl h 252 | Compile into C data-definitions (a header file). 253 | The 254 | .Fl T 255 | option can be used in conjunction to produce a 256 | header file which supports 257 | .Tn RPC 258 | dispatch tables. 259 | .It Fl K Ar secs 260 | By default, services created using 261 | .Nm 262 | wait 120 seconds 263 | after servicing a request before exiting. 264 | That interval can be changed using the 265 | .Fl K 266 | flag. 267 | To create a server that exits immediately upon servicing a request, 268 | .Dq Fl K No 0 269 | can be used. 270 | To create a server that never exits, the appropriate argument is 271 | .Dq Fl K No -1 . 272 | .Pp 273 | When monitoring for a server, 274 | some port monitors, like the 275 | .At V.4 276 | utility 277 | .Xr listen 1 , 278 | .Em always 279 | spawn a new process in response to a service request. 280 | If it is known that a server will be used with such a monitor, the 281 | server should exit immediately on completion. 282 | For such servers, 283 | .Nm 284 | should be used with 285 | .Dq Fl K No -1 . 286 | .It Fl L 287 | Server errors will be sent to syslog instead of stderr. 288 | .It Fl l 289 | Compile into client-side stubs. 290 | .It Fl m 291 | Compile into server-side stubs, 292 | but do not generate a 293 | .Fn main 294 | routine. 295 | This option is useful for doing callback-routines 296 | and for users who need to write their own 297 | .Fn main 298 | routine to do initialization. 299 | .It Fl N 300 | Use the newstyle of 301 | .Nm . 302 | This allows procedures to have multiple arguments. 303 | It also uses the style of parameter passing that closely resembles C. 304 | So, when passing an argument to a remote procedure you do not have 305 | to pass a pointer to the argument but the argument itself. 306 | This behaviour is different from the oldstyle 307 | of 308 | .Nm 309 | generated code. 310 | The newstyle is not the default case because of backward compatibility. 311 | .It Fl n Ar netid 312 | Compile into server-side stubs for the transport 313 | specified by 314 | .Ar netid. 315 | There should be an entry for 316 | .Ar netid 317 | in the 318 | netconfig database. 319 | This option may be specified more than once, 320 | so as to compile a server that serves multiple transports. 321 | .It Fl o Ar outfile 322 | Specify the name of the output file. 323 | If none is specified, 324 | standard output is used 325 | .Po 326 | .Fl c Fl h Fl l 327 | .Fl m Fl n Fl s 328 | modes only 329 | .Pc 330 | .It Fl S\&c 331 | Generate sample code to show the use of remote procedure and how to bind 332 | to the server before calling the client side stubs generated by 333 | .Nm . 334 | .It Fl S\&s 335 | Generate skeleton code for the remote procedures on the server side. You would need 336 | to fill in the actual code for the remote procedures. 337 | .It Fl s Ar nettype 338 | Compile into server-side stubs for all the 339 | transports belonging to the class 340 | .Ar nettype . 341 | The supported classes are 342 | .Em netpath, 343 | .Em visible, 344 | .Em circuit_n, 345 | .Em circuit_v, 346 | .Em datagram_n, 347 | .Em datagram_v, 348 | .Em tcp, 349 | and 350 | .Em udp 351 | [see 352 | .Xr rpc 3 353 | for the meanings associated with these classes. 354 | .Em Note: 355 | .Bx 356 | currently supports only the 357 | .Em tcp 358 | and 359 | .Em udp 360 | classes]. 361 | This option may be specified more than once. 362 | .Em Note: 363 | the transports are chosen at run time and not at compile time. 364 | .It Fl T 365 | Generate the code to support 366 | .Tn RPC 367 | dispatch tables. 368 | .It Fl t 369 | Compile into 370 | .Tn RPC 371 | dispatch table. 372 | .El 373 | .Pp 374 | The options 375 | .Fl c , 376 | .Fl h , 377 | .Fl l , 378 | .Fl m , 379 | .Fl s , 380 | and 381 | .Fl t 382 | are used exclusively to generate a particular type of file, 383 | while the options 384 | .Fl D 385 | and 386 | .Fl T 387 | are global and can be used with the other options. 388 | .Sh NOTES 389 | The 390 | .Tn RPC 391 | Language does not support nesting of structures. 392 | As a work-around, 393 | structures can be declared at the top-level, 394 | and their name used inside other structures in 395 | order to achieve the same effect. 396 | .Pp 397 | Name clashes can occur when using program definitions, 398 | since the apparent scoping does not really apply. 399 | Most of these can be avoided by giving 400 | unique names for programs, 401 | versions, 402 | procedures and types. 403 | .Pp 404 | The server code generated with 405 | .Fl n 406 | option refers to the transport indicated by 407 | .Em netid 408 | and hence is very site specific. 409 | .Sh EXAMPLE 410 | .Pp 411 | The command 412 | .Pp 413 | .Bd -literal -offset indent 414 | $ rpcgen -T prot.x 415 | .Ed 416 | .Pp 417 | generates the five files: 418 | .Pa prot.h , 419 | .Pa prot_clnt.c , 420 | .Pa prot_svc.c , 421 | .Pa prot_xdr.c 422 | and 423 | .Pa prot_tbl.i . 424 | .Pp 425 | The following example sends the C data-definitions (header file) 426 | to standard output. 427 | .Pp 428 | .Bd -literal -offset indent 429 | $ rpcgen -h prot.x 430 | .Ed 431 | .Pp 432 | To send the test version of the 433 | .Dv -DTEST , 434 | server side stubs for 435 | all the transport belonging to the class 436 | .Em datagram_n 437 | to standard output, use: 438 | .Pp 439 | .Bd -literal -offset indent 440 | $ rpcgen -s datagram_n -DTEST prot.x 441 | .Ed 442 | .Pp 443 | To create the server side stubs for the transport indicated by 444 | .Em netid 445 | .Em tcp , 446 | use: 447 | .Pp 448 | .Bd -literal -offset indent 449 | $ rpcgen -n tcp -o prot_svc.c prot.x 450 | .Ed 451 | .Sh SEE ALSO 452 | .Xr cpp 1 453 | -------------------------------------------------------------------------------- /unifdef/tests/unifdef_test.sh: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2023 Klara, Inc. 3 | # 4 | # SPDX-License-Identifier: BSD-2-Clause 5 | # 6 | 7 | atf_test_case hash_comment 8 | hash_comment_head() { 9 | atf_set descr "multiline comment follows directive" 10 | } 11 | hash_comment_body() { 12 | cat >f <file < 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 | * SUCH DAMAGE. 24 | */ 25 | 26 | #include 27 | #include 28 | #ifndef __APPLE__ 29 | #include 30 | #else 31 | #include 32 | #include "tree.h" 33 | #endif 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | /* portability stubs */ 46 | 47 | #define fbinmode(fp) (fp) 48 | 49 | #ifdef __APPLE__ 50 | #define replace(old, new) _apple_replace(old, new) 51 | static __inline int _apple_replace(char *old, char *new) { 52 | int ret; 53 | copyfile_state_t s; 54 | s = copyfile_state_alloc(); 55 | 56 | ret = copyfile(old, new, s, COPYFILE_ALL); 57 | copyfile_state_free(s); 58 | 59 | if (ret < 0) { 60 | return -1; 61 | } 62 | 63 | return unlink(old); 64 | } 65 | #else 66 | #define replace(old,new) rename(old,new) 67 | #endif 68 | 69 | 70 | 71 | static FILE * 72 | mktempmode(char *tmp, int mode) 73 | { 74 | int fd = mkstemp(tmp); 75 | if (fd < 0) return (NULL); 76 | fchmod(fd, mode & (S_IRWXU|S_IRWXG|S_IRWXO)); 77 | return (fdopen(fd, "wb")); 78 | } 79 | -------------------------------------------------------------------------------- /unifdef/unifdef.plist.part: -------------------------------------------------------------------------------- 1 | 2 | OpenSourceProject 3 | unifdef 4 | OpenSourceVersion 5 | 2023-09-06 6 | OpenSourceWebsiteURL 7 | https://cgit.freebsd.org/src/tree/contrib/unifdef?id=aacbe7384221d2eafa326864bbbe2f22a10063ce 8 | OpenSourceImportDate 9 | 2023-09-06 10 | OpenSourceLicense 11 | BSD 12 | OpenSourceModifications 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /unifdef/unifdefall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # unifdefall: remove all the #if's from a source file 4 | # 5 | # Copyright (c) 2002 - 2013 Tony Finch 6 | # Copyright (c) 2009 - 2010 Jonathan Nieder 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 1. Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 21 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | # SUCH DAMAGE. 28 | 29 | set -e 30 | 31 | unifdef="$(dirname "$0")/unifdef" 32 | if [ ! -e "$unifdef" ] 33 | then 34 | unifdef=unifdef 35 | fi 36 | 37 | case "$@" in 38 | "-d "*) echo DEBUGGING 1>&2 39 | debug=-d 40 | shift 41 | esac 42 | 43 | tmp=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXXXXXX") || exit 2 44 | trap 'rm -r "$tmp" || exit 2' EXIT 45 | 46 | export LC_ALL=C 47 | 48 | # list of all controlling macros; assume these are undefined 49 | "$unifdef" $debug -s "$@" | sort -u | sed 's/^/#undef /' >"$tmp/undefs" 50 | # list of all macro definitions 51 | cc -E -dM "$@" | sort >"$tmp/defs" 52 | 53 | case $debug in 54 | -d) cat "$tmp/undefs" "$tmp/defs" 1>&2 55 | esac 56 | 57 | # order of -f arguments means definitions override undefs 58 | "$unifdef" $debug -k -f "$tmp/undefs" -f "$tmp/defs" "$@" 59 | -------------------------------------------------------------------------------- /unifdef/version.h: -------------------------------------------------------------------------------- 1 | "@(#) $Version: unifdef-2.12 $\n" 2 | "@(#) $Date: 2020-02-14 16:37:16 +0000 $\n" 3 | -------------------------------------------------------------------------------- /xcodescripts/install-lorder.sh: -------------------------------------------------------------------------------- 1 | set -ex 2 | 3 | BINDIR="$DSTROOT"/"$DT_TOOLCHAIN_DIR"/usr/bin 4 | 5 | install -c \ 6 | "$PROJECT_DIR"/lorder/lorder.sh \ 7 | "$BINDIR"/lorder 8 | -------------------------------------------------------------------------------- /xcodescripts/install-opensource.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Generate and install open source plist 3 | 4 | set -e 5 | 6 | OSV="$DSTROOT"/usr/local/OpenSourceVersions 7 | install -m 0755 -d "$OSV" 8 | 9 | tmplist=$(mktemp -t developer_cmds_osv_plist) 10 | trap 'rm "$tmplist"' EXIT 11 | 12 | ( 13 | echo '' 14 | echo '' 15 | echo '' 16 | echo '' 17 | for plistpart in "$SRCROOT"/*/*.plist.part ; do 18 | cat "$plistpart" 19 | done 20 | echo '' 21 | echo '' 22 | ) >"$tmplist" 23 | 24 | plutil -lint "$tmplist" 25 | install -m 0644 "$tmplist" "$OSV"/developer_cmds.plist 26 | -------------------------------------------------------------------------------- /xcodescripts/install-test-files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e -x 3 | 4 | install -d -m 0755 \ 5 | "$DSTROOT"/AppleInternal/Tests/developer_cmds 6 | 7 | install -d -m 0755 \ 8 | "$DSTROOT"/AppleInternal/Tests/developer_cmds/indent 9 | install -m 0644 "$SRCROOT"/indent/tests/*0* \ 10 | "$DSTROOT"/AppleInternal/Tests/developer_cmds/indent 11 | install -m 0755 "$SRCROOT"/indent/tests/functional_test.sh \ 12 | "$DSTROOT"/AppleInternal/Tests/developer_cmds/indent/indent_test.sh 13 | 14 | install -d -m 0755 \ 15 | "$DSTROOT"/AppleInternal/Tests/developer_cmds/unifdef 16 | install -m 0755 "$SRCROOT"/unifdef/tests/unifdef_test.sh \ 17 | "$DSTROOT"/AppleInternal/Tests/developer_cmds/unifdef/unifdef_test.sh 18 | 19 | install -d -m 0755 \ 20 | "$DSTROOT"/AppleInternal/CoreOS/BATS/unit_tests 21 | 22 | # The plist will use TARGET_* conditionals to avoid atf-sh tests on !macOS 23 | tmplist=$(mktemp -t developer_cmds_test_plist) 24 | trap 'rm "$tmplist"' EXIT 25 | xcrun clang -x c -C -P -E -imacros TargetConditionals.h \ 26 | -Wno-invalid-pp-token \ 27 | "$SRCROOT"/tests/developer_cmds.plist.in \ 28 | -o "$tmplist" 29 | plutil -lint "$tmplist" 30 | install -m 0644 "$tmplist" \ 31 | "$DSTROOT"/AppleInternal/CoreOS/BATS/unit_tests/developer_cmds.plist 32 | -------------------------------------------------------------------------------- /xcodescripts/install-unifdefall.sh: -------------------------------------------------------------------------------- 1 | set -e -x 2 | 3 | BINDIR="$DSTROOT"/"$DT_TOOLCHAIN_DIR"/usr/bin 4 | MANDIR="$DSTROOT"/"$DT_TOOLCHAIN_DIR"/usr/share/man/man1 5 | 6 | ln -f "$MANDIR"/unifdef.1 "$MANDIR"/unifdefall.1 7 | install -c -m 0755 \ 8 | "$PROJECT_DIR"/unifdef/unifdefall.sh \ 9 | "$BINDIR"/unifdefall 10 | --------------------------------------------------------------------------------