blob: 42ce82b4b422fe4eec2d5a99b0400a1cda778a8b [file] [log] [blame]
Jeff Sharkeydf2d7542017-01-07 09:19:35 -07001#!/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
Jeff Sharkeyb22e7a72017-02-01 00:09:11 -070017import collections, sys
Jeff Sharkeydf2d7542017-01-07 09:19:35 -070018
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
Jeff Sharkeyb22e7a72017-02-01 00:09:11 -070025if "--rc" in sys.argv:
26 print "on early-boot"
27 print " mkdir /config/sdcardfs/extensions/1055"
28 print " mkdir /config/sdcardfs/extensions/1056"
29 print " mkdir /config/sdcardfs/extensions/1057"
30 for gid, exts in TYPES.iteritems():
31 if gid is "AID_MEDIA_AUDIO": gid = "1055"
32 if gid is "AID_MEDIA_VIDEO": gid = "1056"
33 if gid is "AID_MEDIA_IMAGE": gid = "1057"
34 for ext in exts:
35 print " mkdir /config/sdcardfs/extensions/%s/%s" % (gid, ext)
36 exit()
37
Jeff Sharkeydf2d7542017-01-07 09:19:35 -070038print """/*
39 * Copyright (C) 2017 The Android Open Source Project
40 *
41 * Licensed under the Apache License, Version 2.0 (the "License");
42 * you may not use this file except in compliance with the License.
43 * You may obtain a copy of the License at
44 *
45 * http://www.apache.org/licenses/LICENSE-2.0
46 *
47 * Unless required by applicable law or agreed to in writing, software
48 * distributed under the License is distributed on an "AS IS" BASIS,
49 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
50 * See the License for the specific language governing permissions and
51 * limitations under the License.
52 */
53
54/******************************************************************
55 * THIS CODE WAS GENERATED BY matchgen.py, DO NOT MODIFY DIRECTLY *
56 ******************************************************************/
57
58#include <private/android_filesystem_config.h>
59
60int MatchExtension(const char* ext) {
61"""
62
63trie = collections.defaultdict(lambda: collections.defaultdict(lambda: collections.defaultdict(lambda: collections.defaultdict(lambda: collections.defaultdict(lambda: collections.defaultdict(lambda: ""))))))
64
65for t in TYPES:
66 for v in TYPES[t]:
67 v = v.lower()
68 target = trie
69 for c in v:
70 target = target[c]
71 target["\0"] = t
72
73def dump(target, index):
74 prefix = " " * (index + 1)
75 print "%sswitch (ext[%d]) {" % (prefix, index)
76 for k in sorted(target.keys()):
77 if k == "\0":
78 print "%scase '\\0': return %s;" % (prefix, target[k])
79 else:
80 upper = k.upper()
81 if k != upper:
82 print "%scase '%s': case '%s':" % (prefix, k, upper)
83 else:
84 print "%scase '%s':" % (prefix, k)
85 dump(target[k], index + 1)
86 print "%s}" % (prefix)
Jeff Sharkey725ae2b2018-09-28 10:07:14 -060087 if index > 0:
88 print "%sbreak;" % (prefix)
Jeff Sharkeydf2d7542017-01-07 09:19:35 -070089
90dump(trie, 0)
91
92print """
93 return 0;
94}
95"""