Print this page
XXX Remove nawk(1)


   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 #
  23 # Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 #
  26 #ident  "%Z%%M% %I%     %E% SMI"
  27 #
  28 
  29 #
  30 # Given a header file, extract function prototypes and global variable
  31 # declarations in a form that can be used in a mapfile.  The list of extracted
  32 # functions and variables will be combined with a user-specified template to
  33 # create a complete mapfile.
  34 #
  35 # Template
  36 # --------
  37 #
  38 # The template contains two sections - the prologue, and the epilogue.  These
  39 # sections are used, verbatim, as the beginning and the end of the mapfile.
  40 # Sections begin and end with single-line comments whose sole contents are
  41 # "/* BEGIN $section */" and "/* END $section */".
  42 #
  43 # Template example:
  44 #
  45 # /* BEGIN PROLOGUE */
  46 # [ ... prologue goes here ... ]
  47 # /* END PROLOGUE */


  95 # "/* Internal */" comments would be excluded.  Note that the comment must be at
  96 # the end of the first line.  If the declaration spans multiple lines, the
  97 # exclusion comment must appear on the first line.
  98 #
  99 # Examples of functions excluded from exportation:
 100 #
 101 # MAPFILE: exclude "Internal"
 102 #
 103 # extern int foo(int);          /* Internal */
 104 # extern void bar(int, int,     /* Internal */
 105 #       int, void *);
 106 #
 107 # Selective Exclusion may not be used in the same file as Selective Exportation.
 108 #
 109 
 110 function extract_prototypes
 111 {
 112         typeset header="$1"
 113         typeset prefix="$2"
 114 
 115         nawk -v prefix="$prefix" <$header '
 116                 /^.*MAPFILE: export \"[^\"]*\"$/ {
 117                         if (protoexclude) {
 118                                 print "ERROR: export after exclude\n";
 119                                 exit(1);
 120                         }
 121                 
 122                         sub(/^[^\"]*\"/, "");
 123                         sub(/\"$/, "");
 124 
 125                         exportmark=sprintf("/* %s */", $0);
 126                         next;
 127                 }
 128 
 129                 /^.*MAPFILE: exclude \"[^\"]*\"$/ {
 130                         if (protomatch) {
 131                                 print "ERROR: exclude after export";
 132                                 exit(1);
 133                         }
 134 
 135                         sub(/^[^\"]*\"/, "");


 177 
 178                 # Global variables
 179                 /^extern[^\(\)]*;/ {
 180                         for (i = 1; i <= NF; i++) {
 181                                 if (match($i, /;$/)) {
 182                                         printf("%s%s; /* variable */\n", prefix,
 183                                             substr($i, 1, length($i) - 1));
 184                                         break;
 185                                 }
 186                         }
 187                         next;
 188                 }
 189         ' || die "Extraction failed"
 190 }
 191 
 192 function extract_section
 193 {
 194         typeset skel="$1"
 195         typeset secname="$2"
 196 
 197         nawk <$skel -v name=$secname -v skel=$skel '
 198             /\/\* [^ ]* [^ ]* \*\// && $3 == name {
 199                 if ($2 == "BEGIN") {
 200                         printing = 1;
 201                 } else {
 202                         printing = 0;
 203                 }
 204                 next;
 205             }
 206 
 207             printing != 0 { print; }
 208         '
 209 }
 210 
 211 function die
 212 {
 213         echo "$PROGNAME: $@" >&2
 214         exit 1
 215 }
 216 
 217 function usage




   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 #
  23 # Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 #


  26 
  27 #
  28 # Given a header file, extract function prototypes and global variable
  29 # declarations in a form that can be used in a mapfile.  The list of extracted
  30 # functions and variables will be combined with a user-specified template to
  31 # create a complete mapfile.
  32 #
  33 # Template
  34 # --------
  35 #
  36 # The template contains two sections - the prologue, and the epilogue.  These
  37 # sections are used, verbatim, as the beginning and the end of the mapfile.
  38 # Sections begin and end with single-line comments whose sole contents are
  39 # "/* BEGIN $section */" and "/* END $section */".
  40 #
  41 # Template example:
  42 #
  43 # /* BEGIN PROLOGUE */
  44 # [ ... prologue goes here ... ]
  45 # /* END PROLOGUE */


  93 # "/* Internal */" comments would be excluded.  Note that the comment must be at
  94 # the end of the first line.  If the declaration spans multiple lines, the
  95 # exclusion comment must appear on the first line.
  96 #
  97 # Examples of functions excluded from exportation:
  98 #
  99 # MAPFILE: exclude "Internal"
 100 #
 101 # extern int foo(int);          /* Internal */
 102 # extern void bar(int, int,     /* Internal */
 103 #       int, void *);
 104 #
 105 # Selective Exclusion may not be used in the same file as Selective Exportation.
 106 #
 107 
 108 function extract_prototypes
 109 {
 110         typeset header="$1"
 111         typeset prefix="$2"
 112 
 113         /usr/xpg4/bin/awk -v prefix="$prefix" <$header '
 114                 /^.*MAPFILE: export \"[^\"]*\"$/ {
 115                         if (protoexclude) {
 116                                 print "ERROR: export after exclude\n";
 117                                 exit(1);
 118                         }
 119                 
 120                         sub(/^[^\"]*\"/, "");
 121                         sub(/\"$/, "");
 122 
 123                         exportmark=sprintf("/* %s */", $0);
 124                         next;
 125                 }
 126 
 127                 /^.*MAPFILE: exclude \"[^\"]*\"$/ {
 128                         if (protomatch) {
 129                                 print "ERROR: exclude after export";
 130                                 exit(1);
 131                         }
 132 
 133                         sub(/^[^\"]*\"/, "");


 175 
 176                 # Global variables
 177                 /^extern[^\(\)]*;/ {
 178                         for (i = 1; i <= NF; i++) {
 179                                 if (match($i, /;$/)) {
 180                                         printf("%s%s; /* variable */\n", prefix,
 181                                             substr($i, 1, length($i) - 1));
 182                                         break;
 183                                 }
 184                         }
 185                         next;
 186                 }
 187         ' || die "Extraction failed"
 188 }
 189 
 190 function extract_section
 191 {
 192         typeset skel="$1"
 193         typeset secname="$2"
 194 
 195         /usr/xpg4/bin/awk <$skel -v name=$secname -v skel=$skel '
 196             /\/\* [^ ]* [^ ]* \*\// && $3 == name {
 197                 if ($2 == "BEGIN") {
 198                         printing = 1;
 199                 } else {
 200                         printing = 0;
 201                 }
 202                 next;
 203             }
 204 
 205             printing != 0 { print; }
 206         '
 207 }
 208 
 209 function die
 210 {
 211         echo "$PROGNAME: $@" >&2
 212         exit 1
 213 }
 214 
 215 function usage