1# Licensed to the Apache Software Foundation (ASF) under one or more
2# contributor license agreements.  See the NOTICE file distributed with
3# this work for additional information regarding copyright ownership.
4# The ASF licenses this file to You under the Apache License, Version 2.0
5# (the "License"); you may not use this file except in compliance with
6# the License.  You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16# Based on apr's make_export.awk, which is
17# based on Ryan Bloom's make_export.pl
18#
19
20BEGIN {
21}
22
23function add_symbol(sym_name) {
24    sub(" ", "", sym_name)
25    exports[++idx] = sym_name
26}
27
28# List of functions that we don't support, yet??
29#/ap_some_name/{next}
30
31/^[ \t]*(AP|DAV)([RU]|_CORE)?_DECLARE[^(]*[(][^)]*[)]([^ ]* )*[^(]+[(]/ {
32    sub("[ \t]*(AP|DAV)([RU]|_CORE)?_DECLARE[^(]*[(][^)]*[)][ \t]*", "")
33    sub("[(].*", "")
34    sub("([^ ]* (^([ \t]*[(])))+", "")
35    add_symbol($0)
36    next
37}
38
39/^[ \t]*AP_DECLARE_HOOK[^(]*[(][^)]*/ {
40    split($0, args, ",")
41    symbol = args[2]
42    sub("^[ \t]+", "", symbol)
43    sub("[ \t]+$", "", symbol)
44    add_symbol("ap_hook_" symbol)
45    add_symbol("ap_hook_get_" symbol)
46    add_symbol("ap_run_" symbol)
47    next
48}
49
50/^[ \t]*AP[RU]?_DECLARE_EXTERNAL_HOOK[^(]*[(][^)]*/ {
51    split($0, args, ",")
52    prefix = args[1]
53    sub("^.*[(]", "", prefix)
54    symbol = args[4]
55    sub("^[ \t]+", "", symbol)
56    sub("[ \t]+$", "", symbol)
57    add_symbol(prefix "_hook_" symbol)
58    add_symbol(prefix "_hook_get_" symbol)
59    add_symbol(prefix "_run_" symbol)
60    next
61}
62
63/^[ \t]*APR_POOL_DECLARE_ACCESSOR[^(]*[(][^)]*[)]/ {
64    sub("[ \t]*APR_POOL_DECLARE_ACCESSOR[^(]*[(]", "", $0)
65    sub("[)].*$", "", $0)
66    add_symbol("apr_" $0 "_pool_get")
67    next
68}
69
70/^[ \t]*APR_DECLARE_INHERIT_SET[^(]*[(][^)]*[)]/ {
71    sub("[ \t]*APR_DECLARE_INHERIT_SET[^(]*[(]", "", $0)
72    sub("[)].*$", "", $0)
73    add_symbol("apr_" $0 "_inherit_set")
74    next
75}
76
77/^[ \t]*APR_DECLARE_INHERIT_UNSET[^(]*[(][^)]*[)]/ {
78    sub("[ \t]*APR_DECLARE_INHERIT_UNSET[^(]*[(]", "", $0)
79    sub("[)].*$", "", $0)
80    add_symbol("apr_" $0 "_inherit_unset")
81    next
82}
83
84/^[ \t]*(extern[ \t]+)?AP[RU]?_DECLARE_DATA .*;/ {
85    gsub(/[*;\n\r]/, "")
86    gsub(/\[.*\]/, "")
87    add_symbol($NF)
88}
89
90
91END {
92    printf("Added %d symbols to export list.\n", idx) > "/dev/stderr"
93    # sort symbols with shell sort
94    increment = int(idx / 2)
95    while (increment > 0) {
96        for (i = increment+1; i <= idx; i++) {
97            j = i
98            temp = exports[i]
99            while ((j >= increment+1) && (exports[j-increment] > temp)) {
100                exports[j] = exports[j-increment]
101                j -= increment
102            }
103            exports[j] = temp
104        }
105        if (increment == 2)
106            increment = 1
107        else
108            increment = int(increment*5/11)
109    }
110    # print the array
111    printf(" (%s)\n", EXPPREFIX)
112    while (x < idx - 1) {
113        printf(" %s,\n", exports[++x])
114    }
115    printf(" %s\n", exports[++x])
116}
117
118