Use re in stead of regex.

This commit is contained in:
Jack Jansen 2001-01-02 22:02:02 +00:00
parent ef92edd903
commit be614ee732
3 changed files with 34 additions and 31 deletions

View File

@ -16,7 +16,7 @@
# #
from MkDistr_ui import * from MkDistr_ui import *
import fnmatch import fnmatch
import regex import re
import os import os
import sys import sys
import macfs import macfs
@ -187,7 +187,7 @@ class ExcMatcher(Matcher):
pat = fnmatch.translate(src) pat = fnmatch.translate(src)
if DEBUG: if DEBUG:
print 'PATTERN', `src`, 'REGEX', `pat` print 'PATTERN', `src`, 'REGEX', `pat`
self.relist.append(regex.compile(pat)) self.relist.append(re.compile(pat))
def unrebuild1(self, num, src): def unrebuild1(self, num, src):
del self.relist[num] del self.relist[num]
@ -196,7 +196,7 @@ class ExcMatcher(Matcher):
comps = os.path.split(path) comps = os.path.split(path)
file = comps[-1] file = comps[-1]
for pat in self.relist: for pat in self.relist:
if pat and pat.match(file) == len(file): if pat and pat.match(file):
if DEBUG: if DEBUG:
print 'excmatch', file, pat print 'excmatch', file, pat
return 1 return 1

View File

@ -16,7 +16,7 @@ import sys
import macfs import macfs
import MacOS import MacOS
import EasyDialogs import EasyDialogs
import regex import re
import string import string
import aetools import aetools
@ -278,11 +278,11 @@ def incbuildno(filename):
line = fp.readline() line = fp.readline()
fp.close() fp.close()
pat = regex.compile('#define BUILD \([0-9][0-9]*\)') pat = re.compile('#define BUILD ([0-9]+)')
pat.match(line) m = pat.search(line)
buildno = pat.group(1) if not m or not m.group(1):
if not buildno:
raise 'Incorrect macbuildno.h line', line raise 'Incorrect macbuildno.h line', line
buildno = m.group(1)
new = string.atoi(buildno) + 1 new = string.atoi(buildno) + 1
fp = open(filename, 'w') fp = open(filename, 'w')
fp.write('#define BUILD %d\n'%new) fp.write('#define BUILD %d\n'%new)

View File

@ -1,6 +1,6 @@
"""Parse sys/errno.h and Errors.h and create Estr resource""" """Parse sys/errno.h and Errors.h and create Estr resource"""
import regex import re
import macfs import macfs
import string import string
import Res import Res
@ -11,25 +11,25 @@ WRITE = 2
smAllScripts = -3 smAllScripts = -3
ERRNO_PROG="#define[ \t]+" \ ERRNO_PROG="#define[ \t]+" \
"\([A-Z0-9a-z_]+\)" \ "([A-Z0-9a-z_]+)" \
"[ \t]+" \ "[ \t]+" \
"\([0-9]+\)" \ "([0-9]+)" \
"[ \t]*/\*[ \t]*" \ "[ \t]*/\*[ \t]*" \
"\(.*\)" \ "(.*)" \
"[ \t]*\*/" "[ \t]*\*/"
ERRORS_PROG="[ \t]*" \ ERRORS_PROG="[ \t]*" \
"\([A-Z0-9a-z_]+\)" \ "([A-Z0-9a-z_]+)" \
"[ \t]*=[ \t]*" \ "[ \t]*=[ \t]*" \
"\([-0-9]+\)" \ "([-0-9]+)" \
"[, \t]*/\*[ \t]*" \ "[, \t]*/\*[ \t]*" \
"\(.*\)" \ "(.*)" \
"[ \t]*\*/" "[ \t]*\*/"
ERRORS_PROG_2="[ \t]*" \ ERRORS_PROG_2="[ \t]*" \
"\([A-Z0-9a-z_]+\)" \ "([A-Z0-9a-z_]+)" \
"[ \t]*=[ \t]*" \ "[ \t]*=[ \t]*" \
"\([-0-9]+\)" \ "([-0-9]+)" \
"[, \t]*" "[, \t]*"
def Pstring(str): def Pstring(str):
@ -58,12 +58,13 @@ def writepython(fp, dict):
def parse_errno_h(fp, dict): def parse_errno_h(fp, dict):
errno_prog = regex.compile(ERRNO_PROG) errno_prog = re.compile(ERRNO_PROG)
for line in fp.readlines(): for line in fp.readlines():
if errno_prog.match(line) > 0: m = errno_prog.match(line)
number = string.atoi(errno_prog.group(2)) if m:
name = errno_prog.group(1) number = string.atoi(m.group(2))
desc = string.strip(errno_prog.group(3)) name = m.group(1)
desc = string.strip(m.group(3))
if not dict.has_key(number): if not dict.has_key(number):
dict[number] = desc, name dict[number] = desc, name
@ -73,18 +74,20 @@ def parse_errno_h(fp, dict):
print '\t', (desc, name) print '\t', (desc, name)
def parse_errors_h(fp, dict): def parse_errors_h(fp, dict):
errno_prog = regex.compile(ERRORS_PROG) errno_prog = re.compile(ERRORS_PROG)
errno_prog_2 = regex.compile(ERRORS_PROG_2) errno_prog_2 = re.compile(ERRORS_PROG_2)
for line in fp.readlines(): for line in fp.readlines():
match = 0 match = 0
if errno_prog.match(line) > 0: m = errno_prog.match(line)
number = string.atoi(errno_prog.group(2)) m2 = errno_prog_2.match(line)
name = errno_prog.group(1) if m:
desc = string.strip(errno_prog.group(3)) number = string.atoi(m.group(2))
name = m.group(1)
desc = string.strip(m.group(3))
match=1 match=1
elif errno_prog_2.match(line) > 0: elif m2:
number = string.atoi(errno_prog_2.group(2)) number = string.atoi(m2.group(2))
name = errno_prog_2.group(1) name = m2.group(1)
desc = name desc = name
match=1 match=1
if match: if match: