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/tools/acpi_quirks2h.awk

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 #!/usr/bin/awk -f
    2 #
    3 # $FreeBSD$
    4 
    5 #-
    6 # Copyright (c) 2004 Mark Santcroos <marks@ripe.net>
    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 #
   18 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   21 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   24 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   25 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   27 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   28 # SUCH DAMAGE.
   29 #
   30 
   31 BEGIN {
   32         OUTPUT="acpi_quirks.h"
   33 }
   34 
   35 # Print header and id
   36 NR == 1 {
   37         VERSION = $0;
   38         gsub("\^# ", "", VERSION)
   39         gsub("\\$", "", VERSION)
   40 
   41         printf("/*\n") > OUTPUT;
   42         printf(" * THIS FILE IS AUTOMAGICALLY GENERATED.  DO NOT EDIT.\n") \
   43             > OUTPUT;
   44         printf(" *\n") > OUTPUT;
   45         printf(" * Generated from:\n") > OUTPUT;
   46         printf(" * %s\n", VERSION) > OUTPUT;
   47         printf(" */\n\n") > OUTPUT;
   48 }
   49 
   50 # Ignore comments and empty lines
   51 /^#/, NF == 0 {
   52 }
   53 
   54 #
   55 # NAME field: this is the first line of every entry
   56 #
   57 $1 == "name:" {
   58         ENTRY_NAME = $2;
   59         printf("const struct acpi_q_rule %s[] = {\n", ENTRY_NAME) > OUTPUT;
   60 }
   61 
   62 #
   63 # OEM field
   64 #
   65 $1 == "oem:" {
   66         LENGTH = length();
   67 
   68         # Parse table type to match
   69         TABLE = $2;
   70 
   71         # Parse OEM ID
   72         M = match ($0, /\"[^\"]*\"/);
   73         OEM_ID = substr($0, M, RLENGTH);
   74 
   75         # Parse OEM Table ID
   76         ANCHOR = LENGTH - (M + RLENGTH - 1);
   77         REMAINDER = substr($0, M + RLENGTH, ANCHOR);
   78         M = match (REMAINDER, /\"[^\"]*\"/);
   79         OEM_TABLE_ID = substr(REMAINDER, M, RLENGTH);
   80 
   81         printf("\t{ \"%s\", OEM, {%s}, {%s} },\n",
   82             TABLE, OEM_ID, OEM_TABLE_ID) > OUTPUT;
   83 }
   84 
   85 #
   86 # CREATOR field
   87 #
   88 $1 == "creator:" {
   89         # Parse table type to match
   90         TABLE = $2;
   91 
   92         M = match ($0, /\"[^\"]*\"/);
   93         CREATOR = substr($0, M, RLENGTH);
   94 
   95         printf("\t{ \"%s\", CREATOR, {%s} },\n",
   96             TABLE, CREATOR) > OUTPUT;
   97 }
   98 
   99 #
  100 # OEM REVISION field
  101 #
  102 $1 == "oem_rev:" {
  103         TABLE = $2;
  104         SIGN = $3;
  105         VALUE = $4;
  106 
  107         # Parse operand
  108         OPERAND = trans_sign(SIGN);
  109 
  110         printf("\t{ \"%s\", OEM_REV, {.op = %s}, {.rev = %s} },\n",
  111             TABLE, OPERAND, VALUE) > OUTPUT;
  112 }
  113 
  114 #
  115 # CREATOR REVISION field
  116 #
  117 $1 == "creator_rev:" {
  118         TABLE = $2;
  119         SIGN = $3;
  120         VALUE = $4;
  121 
  122         # Parse operand
  123         OPERAND = trans_sign(SIGN);
  124 
  125         printf("\t{ \"%s\", CREATOR_REV, {.op = %s}, {.rev = %s} },\n",
  126             TABLE, OPERAND, VALUE) > OUTPUT;
  127 }
  128 
  129 #
  130 # QUIRKS field: This is the last line of every entry
  131 #
  132 $1 == "quirks:" {
  133         printf("\t{ \"\" }\n};\n\n") > OUTPUT;
  134 
  135         QUIRKS = $0;
  136         sub(/^quirks:[ ]*/ , "", QUIRKS);
  137 
  138         QUIRK_COUNT++;
  139         QUIRK_LIST[QUIRK_COUNT] = QUIRKS;
  140         QUIRK_NAME[QUIRK_COUNT] = ENTRY_NAME;
  141 }
  142 
  143 #
  144 # All information is gathered, now create acpi_quirks_table
  145 #
  146 END {
  147         # Header
  148         printf("const struct acpi_q_entry acpi_quirks_table[] = {\n") \
  149             > OUTPUT;
  150 
  151         # Array of all quirks
  152         for (i = 1; i <= QUIRK_COUNT; i++) {
  153                 printf("\t{ %s, %s },\n", QUIRK_NAME[i], QUIRK_LIST[i]) \
  154                     > OUTPUT;
  155         }
  156 
  157         # Footer
  158         printf("\t{ NULL, 0 }\n") > OUTPUT;
  159         printf("};\n") > OUTPUT;
  160 
  161         exit(0);
  162 }
  163 
  164 #
  165 # Translate math SIGN into verbal OPERAND
  166 #
  167 function trans_sign(TMP_SIGN)
  168 {
  169         if (TMP_SIGN == "=")
  170                 TMP_OPERAND = "OP_EQL";
  171         else if (TMP_SIGN == "!=")
  172                 TMP_OPERAND = "OP_NEQ";
  173         else if (TMP_SIGN == "<=")
  174                 TMP_OPERAND = "OP_LEQ";
  175         else if (TMP_SIGN == ">=")
  176                 TMP_OPERAND = "OP_GEQ";
  177         else if (TMP_SIGN == ">")
  178                 TMP_OPERAND = "OP_GTR";
  179         else if (TMP_SIGN == "<")
  180                 TMP_OPERAND = "OP_LES";
  181         else {
  182                 printf("error: unknown sign: " TMP_SIGN "\n");
  183                 exit(1);
  184         }
  185 
  186         return (TMP_OPERAND);
  187 }

Cache object: 564efa3f70c5030ef6f5544145549ecf


[ 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.