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-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

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

Cache object: c90113ebdb5756ff8ea25521110b1a24


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