The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/kern/makedevops.sh

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 #!/bin/sh -
    2 #
    3 # Copyright (c) 1992, 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 # From @(#)vnode_if.sh  8.1 (Berkeley) 6/10/93
   35 # $FreeBSD$
   36 #
   37 
   38 # Script to produce device front-end sugar.
   39 #
   40 # usage: makedevops.sh srcfile
   41 #
   42 # These awk scripts are not particularly well written, specifically they
   43 # don't use arrays well and figure out the same information repeatedly.
   44 # Please rewrite them if you actually understand how to use awk.  Note,
   45 # they use nawk extensions and gawk's toupper.
   46 
   47 if [ $# -ne 2 ] ; then
   48         echo 'usage: makedevops.sh [-c|-h] srcfile'
   49         exit 1
   50 fi
   51 
   52 makec=0
   53 makeh=0
   54 
   55 if [ "$1" = "-c" ]; then
   56     makec=1
   57 fi
   58 
   59 if [ "$1" = "-h" ]; then
   60     makeh=1
   61 fi
   62 
   63 # Name of the source file.
   64 SRC=$2
   65 
   66 # Names of the created files.
   67 CTMP=ctmp$$
   68 HTMP=htmp$$
   69 
   70 CFILE=`basename $SRC .m`.c
   71 HFILE=`basename $SRC .m`.h
   72 
   73 # Awk program (must support nawk extensions and gawk's "toupper")
   74 # Use "awk" at Berkeley, "gawk" elsewhere.
   75 AWK=awk
   76 
   77 # Awk script to take file.do and turn it into file.h and file.c
   78 $AWK "
   79         BEGIN {
   80                 src = \"$SRC\";
   81                 header = \"$HTMP\";
   82                 cfile = \"$CTMP\";
   83                 hfile = \"$HFILE\";
   84                 "'
   85 
   86                 printf("/*\n")                                          > header;
   87                 printf(" * This file is produced automatically.\n")     > header;
   88                 printf(" * Do not modify anything in here by hand.\n")  > header;
   89                 printf(" *\n")                                          > header;
   90                 printf(" * Created from %s with makedevops.sh\n", src)  > header;
   91                 printf(" */\n\n")                                       > header;
   92 
   93                 printf("/*\n")                                          > cfile;
   94                 printf(" * This file is produced automatically.\n")     > cfile;
   95                 printf(" * Do not modify anything in here by hand.\n")  > cfile;
   96                 printf(" *\n")                                          > cfile;
   97                 printf(" * Created from %s with makedevops.sh\n", src)  > cfile;
   98                 printf(" */\n\n")                                       > cfile;
   99                 printf("#include <sys/param.h>\n")                      > cfile;
  100                 printf("#include <sys/queue.h>\n")                      > cfile;
  101                 printf("#include <sys/bus_private.h>\n")                > cfile;
  102 
  103                 methodcount = 0
  104         }
  105         NF == 0 {
  106                 next;
  107         }
  108         /^#include/ {
  109                 print $0 > cfile;
  110         }
  111         /^#/ {
  112                 next;
  113         }
  114         /^INTERFACE/ {
  115                 intname = $2;
  116                 printf("#ifndef _%s_if_h_\n", intname)          > header;
  117                 printf("#define _%s_if_h_\n\n", intname)        > header;
  118                 printf("#include \"%s\"\n\n", hfile)                    > cfile;
  119         }
  120         /^METHOD/ {
  121                 # Get the function name and return type.
  122                 ret = "";
  123                 sep = "";
  124                 for (i = 2; i < NF - 1; i++) {
  125                         ret = sep $i;
  126                         sep = " ";
  127                 }
  128                 name = $i;
  129 
  130                 # Get the function arguments.
  131                 for (c1 = 0;; ++c1) {
  132                         if (getline <= 0)
  133                                 exit
  134                         if ($0 ~ "^};")
  135                                 break;
  136                         a[c1] = $0;
  137                 }
  138 
  139                 methods[methodcount++] = name;
  140 
  141                 mname = intname "_" name;
  142                 umname = toupper(mname);
  143 
  144                 # Print out the method declaration
  145                 printf("extern struct device_op_desc %s_desc;\n", mname) > header;
  146                 printf("%s %s(", ret, umname) > header;
  147                 sep = ", ";
  148                 for (c2 = 0; c2 < c1; ++c2) {
  149                         if (c2 == c1 - 1)
  150                                 sep = " );\n";
  151                         c3 = split(a[c2], t);
  152                         for (c4 = 0; c4 < c3; ++c4)
  153                                 printf("%s ", t[c4]) > header;
  154                         beg = match(t[c3], "[^*]");
  155                         end = match(t[c3], ";");
  156                         printf("%s%s%s",
  157                             substr(t[c4], 0, beg - 1),
  158                             substr(t[c4], beg, end - beg), sep) > header;
  159                 }
  160 
  161                 # Print the method desc
  162                 printf("struct device_op_desc %s_desc = {\n", mname) > cfile;
  163                 printf("\t0,\n") > cfile;
  164                 printf("\t\"%s\"\n", mname) > cfile;
  165                 printf("};\n\n") > cfile;
  166 
  167                 # Print out the method typedef
  168                 printf("typedef %s %s_t(\n", ret, mname) > cfile;
  169                 sep = ",\n";
  170                 for (c2 = 0; c2 < c1; ++c2) {
  171                         if (c2 == c1 - 1)
  172                                 sep = ");\n";
  173                         c3 = split(a[c2], t);
  174                         printf("\t") > cfile;
  175                         for (c4 = 0; c4 < c3; ++c4)
  176                                 printf("%s ", t[c4]) > cfile;
  177                         beg = match(t[c3], "[^*]");
  178                         end = match(t[c3], ";");
  179                         printf("%s%s%s",
  180                             substr(t[c4], 0, beg - 1),
  181                             substr(t[c4], beg, end - beg), sep) > cfile;
  182                 }
  183 
  184                 # Print out the method itself
  185                 printf("%s %s(\n", ret, umname) > cfile;
  186                 sep = ",\n";
  187                 for (c2 = 0; c2 < c1; ++c2) {
  188                         if (c2 == c1 - 1)
  189                                 sep = ")\n";
  190                         c3 = split(a[c2], t);
  191                         printf("\t") > cfile;
  192                         for (c4 = 0; c4 < c3; ++c4)
  193                                 printf("%s ", t[c4]) > cfile;
  194                         beg = match(t[c3], "[^*]");
  195                         end = match(t[c3], ";");
  196                         printf("%s%s%s",
  197                             substr(t[c4], 0, beg - 1),
  198                             substr(t[c4], beg, end - beg), sep) > cfile;
  199                 }
  200                 printf("{\n") > cfile;
  201                 printf("\t%s_t *m = (%s_t *) DEVOPMETH(dev, %s);\n",
  202                         mname, mname, mname) > cfile;
  203                 if (ret != "void")
  204                         printf("\treturn m(") > cfile;
  205                 else
  206                         printf("\tm(") > cfile;
  207                 sep = ", ";
  208                 for (c2 = 0; c2 < c1; ++c2) {
  209                         if (c2 == c1 - 1)
  210                                 sep = ");\n";
  211                         c3 = split(a[c2], t);
  212                         beg = match(t[c3], "[^*]");
  213                         end = match(t[c3], ";");
  214                         printf("%s%s", substr(t[c3], beg, end - beg), sep) > cfile;
  215                 }
  216                 printf("}\n\n") > cfile;
  217         }
  218         END {
  219                 printf("\n#endif /* _%s_if_h_ */\n", intname)   > header;
  220         }' < $SRC
  221 
  222 if [ $makec = 1 ]; then
  223     mv $CTMP $CFILE
  224 else
  225     rm $CTMP
  226 fi
  227 
  228 if [ $makeh = 1 ]; then
  229     mv $HTMP $HFILE
  230 else
  231     rm $HTMP
  232 fi

Cache object: f5d56566909d085ad3b3ed618977863a


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.