matchgen.py revision df2d754b38796e0c49c70e0a67f7d383e3079ff2
1#!/usr/bin/env python
2
3# Copyright (C) 2017 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the 'License');
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an 'AS IS' BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import collections
18
19TYPES = {
20    "AID_MEDIA_AUDIO": ["aac","aac","amr","awb","snd","flac","flac","mp3","mpga","mpega","mp2","m4a","aif","aiff","aifc","gsm","mka","m3u","wma","wax","ra","rm","ram","ra","pls","sd2","wav","ogg","oga"],
21    "AID_MEDIA_VIDEO": ["3gpp","3gp","3gpp2","3g2","avi","dl","dif","dv","fli","m4v","ts","mpeg","mpg","mpe","mp4","vob","qt","mov","mxu","webm","lsf","lsx","mkv","mng","asf","asx","wm","wmv","wmx","wvx","movie","wrf"],
22    "AID_MEDIA_IMAGE": ["bmp","gif","jpg","jpeg","jpe","pcx","png","svg","svgz","tiff","tif","wbmp","webp","dng","cr2","ras","art","jng","nef","nrw","orf","rw2","pef","psd","pnm","pbm","pgm","ppm","srw","arw","rgb","xbm","xpm","xwd"]
23}
24
25print """/*
26 * Copyright (C) 2017 The Android Open Source Project
27 *
28 * Licensed under the Apache License, Version 2.0 (the "License");
29 * you may not use this file except in compliance with the License.
30 * You may obtain a copy of the License at
31 *
32 *      http://www.apache.org/licenses/LICENSE-2.0
33 *
34 * Unless required by applicable law or agreed to in writing, software
35 * distributed under the License is distributed on an "AS IS" BASIS,
36 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37 * See the License for the specific language governing permissions and
38 * limitations under the License.
39 */
40
41/******************************************************************
42 * THIS CODE WAS GENERATED BY matchgen.py, DO NOT MODIFY DIRECTLY *
43 ******************************************************************/
44
45#include <private/android_filesystem_config.h>
46
47int MatchExtension(const char* ext) {
48"""
49
50trie = collections.defaultdict(lambda: collections.defaultdict(lambda: collections.defaultdict(lambda: collections.defaultdict(lambda: collections.defaultdict(lambda: collections.defaultdict(lambda: ""))))))
51
52for t in TYPES:
53    for v in TYPES[t]:
54        v = v.lower()
55        target = trie
56        for c in v:
57            target = target[c]
58        target["\0"] = t
59
60def dump(target, index):
61    prefix = "    " * (index + 1)
62    print "%sswitch (ext[%d]) {" % (prefix, index)
63    for k in sorted(target.keys()):
64        if k == "\0":
65            print "%scase '\\0': return %s;" % (prefix, target[k])
66        else:
67            upper = k.upper()
68            if k != upper:
69                print "%scase '%s': case '%s':" % (prefix, k, upper)
70            else:
71                print "%scase '%s':" % (prefix, k)
72            dump(target[k], index + 1)
73    print "%s}" % (prefix)
74
75dump(trie, 0)
76
77print """
78    return 0;
79}
80"""
81