1
0
mirror of https://github.com/golang/go synced 2024-11-22 06:54:39 -07:00

unicode: add maketables to build, fix build

R=r
CC=golang-dev
https://golang.org/cl/4073046
This commit is contained in:
Russ Cox 2011-01-30 16:09:16 -05:00
parent 5038792837
commit 0f0f34ee05
2 changed files with 32 additions and 33 deletions

View File

@ -18,13 +18,12 @@ maketables: maketables.go
$(LD) -o maketables maketables.$O $(LD) -o maketables maketables.$O
tables: maketables tables: maketables
$(GC) maketables.go
$(LD) -o maketables maketables.$O
./maketables --tables=all > tables.go ./maketables --tables=all > tables.go
gofmt -w tables.go gofmt -w tables.go
rm -f maketables
testtables: maketables testtables: maketables
echo '***' Be sure to make tables and make install first @echo '***' Be sure to make tables and make install first
./maketables -test ./maketables -test
rm -f maketables
all: maketables
CLEANFILES+=maketables

View File

@ -50,8 +50,8 @@ var test = flag.Bool("test",
false, false,
"test existing tables; can be used to compare web data with package data") "test existing tables; can be used to compare web data with package data")
var scriptRe = regexp.MustCompile(`([0-9A-F]+)(\.\.[0-9A-F]+)? *; ([A-Za-z_]+)`) var scriptRe = regexp.MustCompile(`^([0-9A-F]+)(\.\.[0-9A-F]+)? *; ([A-Za-z_]+)$`)
var die = log.New(os.Stderr, nil, "", log.Lexit|log.Lshortfile) var logger = log.New(os.Stderr, "", log.Lshortfile)
var category = map[string]bool{"letter": true} // Nd Lu etc. letter is a special case var category = map[string]bool{"letter": true} // Nd Lu etc. letter is a special case
@ -141,11 +141,11 @@ const (
func parseCategory(line string) (state State) { func parseCategory(line string) (state State) {
field := strings.Split(line, ";", -1) field := strings.Split(line, ";", -1)
if len(field) != NumField { if len(field) != NumField {
die.Logf("%5s: %d fields (expected %d)\n", line, len(field), NumField) logger.Exitf("%5s: %d fields (expected %d)\n", line, len(field), NumField)
} }
point, err := strconv.Btoui64(field[FCodePoint], 16) point, err := strconv.Btoui64(field[FCodePoint], 16)
if err != nil { if err != nil {
die.Log("%.5s...:", err) logger.Exitf("%.5s...: %s", line, err)
} }
lastChar = uint32(point) lastChar = uint32(point)
if point == 0 { if point == 0 {
@ -157,7 +157,7 @@ func parseCategory(line string) (state State) {
char := &chars[point] char := &chars[point]
char.field = field char.field = field
if char.codePoint != 0 { if char.codePoint != 0 {
die.Logf("point %U reused\n") logger.Exitf("point %U reused", point)
} }
char.codePoint = lastChar char.codePoint = lastChar
char.category = field[FGeneralCategory] char.category = field[FGeneralCategory]
@ -167,7 +167,7 @@ func parseCategory(line string) (state State) {
// Decimal digit // Decimal digit
_, err := strconv.Atoi(field[FNumericValue]) _, err := strconv.Atoi(field[FNumericValue])
if err != nil { if err != nil {
die.Log("%U: bad numeric field: %s", point, err) logger.Exitf("%U: bad numeric field: %s", point, err)
} }
case "Lu": case "Lu":
char.letter(field[FCodePoint], field[FSimpleLowercaseMapping], field[FSimpleTitlecaseMapping]) char.letter(field[FCodePoint], field[FSimpleLowercaseMapping], field[FSimpleTitlecaseMapping])
@ -208,7 +208,7 @@ func (char *Char) letterValue(s string, cas string) int {
v, err := strconv.Btoui64(s, 16) v, err := strconv.Btoui64(s, 16)
if err != nil { if err != nil {
char.dump(cas) char.dump(cas)
die.Logf("%U: bad letter(%s): %s", char.codePoint, s, err) logger.Exitf("%U: bad letter(%s): %s", char.codePoint, s, err)
} }
return int(v) return int(v)
} }
@ -242,7 +242,7 @@ func version() string {
return f return f
} }
} }
die.Log("unknown version") logger.Exit("unknown version")
return "Unknown" return "Unknown"
} }
@ -260,10 +260,10 @@ func loadChars() {
} }
resp, _, err := http.Get(*dataURL) resp, _, err := http.Get(*dataURL)
if err != nil { if err != nil {
die.Log(err) logger.Exit(err)
} }
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
die.Log("bad GET status for UnicodeData.txt", resp.Status) logger.Exit("bad GET status for UnicodeData.txt", resp.Status)
} }
input := bufio.NewReader(resp.Body) input := bufio.NewReader(resp.Body)
var first uint32 = 0 var first uint32 = 0
@ -273,21 +273,21 @@ func loadChars() {
if err == os.EOF { if err == os.EOF {
break break
} }
die.Log(err) logger.Exit(err)
} }
switch parseCategory(line[0 : len(line)-1]) { switch parseCategory(line[0 : len(line)-1]) {
case SNormal: case SNormal:
if first != 0 { if first != 0 {
die.Logf("bad state normal at U+%04X", lastChar) logger.Exitf("bad state normal at U+%04X", lastChar)
} }
case SFirst: case SFirst:
if first != 0 { if first != 0 {
die.Logf("bad state first at U+%04X", lastChar) logger.Exitf("bad state first at U+%04X", lastChar)
} }
first = lastChar first = lastChar
case SLast: case SLast:
if first == 0 { if first == 0 {
die.Logf("bad state last at U+%04X", lastChar) logger.Exitf("bad state last at U+%04X", lastChar)
} }
for i := first + 1; i <= lastChar; i++ { for i := first + 1; i <= lastChar; i++ {
chars[i] = chars[first] chars[i] = chars[first]
@ -336,7 +336,7 @@ func printCategories() {
ndecl := 0 ndecl := 0
for _, name := range list { for _, name := range list {
if _, ok := category[name]; !ok { if _, ok := category[name]; !ok {
die.Log("unknown category", name) logger.Exit("unknown category", name)
} }
// We generate an UpperCase name to serve as concise documentation and an _UnderScored // We generate an UpperCase name to serve as concise documentation and an _UnderScored
// name to store the data. This stops godoc dumping all the tables but keeps them // name to store the data. This stops godoc dumping all the tables but keeps them
@ -437,11 +437,11 @@ func dumpRange(header string, inCategory Op) {
func fullCategoryTest(list []string) { func fullCategoryTest(list []string) {
for _, name := range list { for _, name := range list {
if _, ok := category[name]; !ok { if _, ok := category[name]; !ok {
die.Log("unknown category", name) logger.Exit("unknown category", name)
} }
r, ok := unicode.Categories[name] r, ok := unicode.Categories[name]
if !ok { if !ok {
die.Log("unknown table", name) logger.Exit("unknown table", name)
} }
if name == "letter" { if name == "letter" {
verifyRange(name, letterOp, r) verifyRange(name, letterOp, r)
@ -475,21 +475,21 @@ func parseScript(line string, scripts map[string][]Script) {
} }
field := strings.Split(line, ";", -1) field := strings.Split(line, ";", -1)
if len(field) != 2 { if len(field) != 2 {
die.Logf("%s: %d fields (expected 2)\n", line, len(field)) logger.Exitf("%s: %d fields (expected 2)\n", line, len(field))
} }
matches := scriptRe.MatchStrings(line) matches := scriptRe.FindStringSubmatch(line)
if len(matches) != 4 { if len(matches) != 4 {
die.Logf("%s: %d matches (expected 3)\n", line, len(matches)) logger.Exitf("%s: %d matches (expected 3)\n", line, len(matches))
} }
lo, err := strconv.Btoui64(matches[1], 16) lo, err := strconv.Btoui64(matches[1], 16)
if err != nil { if err != nil {
die.Log("%.5s...:", err) logger.Exitf("%.5s...: %s", line, err)
} }
hi := lo hi := lo
if len(matches[2]) > 2 { // ignore leading .. if len(matches[2]) > 2 { // ignore leading ..
hi, err = strconv.Btoui64(matches[2][2:], 16) hi, err = strconv.Btoui64(matches[2][2:], 16)
if err != nil { if err != nil {
die.Log("%.5s...:", err) logger.Exitf("%.5s...: %s", line, err)
} }
} }
name := matches[3] name := matches[3]
@ -515,11 +515,11 @@ func foldAdjacent(r []Script) []unicode.Range {
func fullScriptTest(list []string, installed map[string][]unicode.Range, scripts map[string][]Script) { func fullScriptTest(list []string, installed map[string][]unicode.Range, scripts map[string][]Script) {
for _, name := range list { for _, name := range list {
if _, ok := scripts[name]; !ok { if _, ok := scripts[name]; !ok {
die.Log("unknown script", name) logger.Exit("unknown script", name)
} }
_, ok := installed[name] _, ok := installed[name]
if !ok { if !ok {
die.Log("unknown table", name) logger.Exit("unknown table", name)
} }
for _, script := range scripts[name] { for _, script := range scripts[name] {
for r := script.lo; r <= script.hi; r++ { for r := script.lo; r <= script.hi; r++ {
@ -551,10 +551,10 @@ func printScriptOrProperty(doProps bool) {
var err os.Error var err os.Error
resp, _, err := http.Get(*url + file) resp, _, err := http.Get(*url + file)
if err != nil { if err != nil {
die.Log(err) logger.Exit(err)
} }
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
die.Log("bad GET status for ", file, ":", resp.Status) logger.Exit("bad GET status for ", file, ":", resp.Status)
} }
input := bufio.NewReader(resp.Body) input := bufio.NewReader(resp.Body)
for { for {
@ -563,7 +563,7 @@ func printScriptOrProperty(doProps bool) {
if err == os.EOF { if err == os.EOF {
break break
} }
die.Log(err) logger.Exit(err)
} }
parseScript(line[0:len(line)-1], table) parseScript(line[0:len(line)-1], table)
} }
@ -808,7 +808,7 @@ func printCaseRange(lo, hi *caseState) {
fmt.Printf("\tCaseRange{0x%04X, 0x%04X, d{UpperLower, UpperLower, UpperLower}},\n", fmt.Printf("\tCaseRange{0x%04X, 0x%04X, d{UpperLower, UpperLower, UpperLower}},\n",
lo.point, hi.point) lo.point, hi.point)
case hi.point > lo.point && lo.isLowerUpper(): case hi.point > lo.point && lo.isLowerUpper():
die.Log("LowerUpper sequence: should not happen: U+%04X. If it's real, need to fix To()", lo.point) logger.Exitf("LowerUpper sequence: should not happen: U+%04X. If it's real, need to fix To()", lo.point)
fmt.Printf("\tCaseRange{0x%04X, 0x%04X, d{LowerUpper, LowerUpper, LowerUpper}},\n", fmt.Printf("\tCaseRange{0x%04X, 0x%04X, d{LowerUpper, LowerUpper, LowerUpper}},\n",
lo.point, hi.point) lo.point, hi.point)
default: default: