Movatterモバイル変換


[0]ホーム

URL:


Google Git
Sign in
android /platform /bionic /refs/heads/main /. /libc /tools /genserv.py
blob: acbfea2f0d263293120b7504701b39592c40f0ae [file] [log] [blame]
Elliott Hughes6b586e72021-04-15 13:39:08 -0700[diff] [blame]1#!/usr/bin/env python3
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800[diff] [blame]2#
3
4import sys, os, string, re
5
6def usage():
7print"""\
Elliott Hughese6ddfc52013-03-25 14:09:52 -0700[diff] [blame]8 usage: genserv < /etc/services > libc/netbsd/net/services.h
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800[diff] [blame]9
10 this program is used to generate the hard-coded internet service list for the
11 Bionic C library.
12"""
13
14re_service= re.compile(r"([\d\w\-_]+)\s+(\d+)/(tcp|udp)(.*)")
15re_alias= re.compile(r"([\d\w\-_]+)(.*)")
16
17classService:
18def __init__(self,name,port,proto):
19 self.name= name
20 self.port= port
21 self.proto= proto
22 self.aliases=[]
23
24def add_alias(self,alias):
25 self.aliases.append(alias)
26
27def __str__(self):
28 result="\\%0o%s"%(len(self.name),self.name)
29 result+="\\%0o\\%0o"%(((self.port>>8)&255), self.port&255)
30if self.proto=="tcp":
31 result+="t"
32else:
33 result+="u"
34
35 result+="\\%0o"% len(self.aliases)
36for aliasin self.aliases:
37 result+="\\%0o%s"%(len(alias), alias)
38
39return result
40
41def parse(f):
42 result=[]# list of Service objects
43for linein f.xreadlines():
44if len(line)>0and line[-1]=="\n":
45 line= line[:-1]
46if len(line)>0and line[-1]=="\r":
47 line= line[:-1]
48
49 line= string.strip(line)
50if len(line)==0or line[0]=="#":
51continue
52
53 m= re_service.match(line)
54if m:
55 service=Service( m.group(1), int(m.group(2)), m.group(3))
56 rest= string.strip(m.group(4))
57
58while1:
59 m= re_alias.match(rest)
60ifnot m:
61break
62 service.add_alias(m.group(1))
63 rest= string.strip(m.group(2))
64
65 result.append(service)
66
67return result
68
69services= parse(sys.stdin)
70line='/* generated by genserv.py - do not edit */\nstatic const char _services[] = "\\\n'
71for sin services:
72 line+= str(s)+"\\\n"
73line+='\\0";\n'
74print line

[8]ページ先頭

©2009-2025 Movatter.jp