summaryrefslogtreecommitdiff
path: root/sort.go
blob: 44b0798596132875e8b4ae92a85a200b35f039de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main

import (
	"fmt"
	"os"
)

// this file is named poorly. It has more than Sort()

func (pb *Files) makeNewSortfile(pf *File) error {
	w, _ := os.OpenFile(pf.Filebase+".sort.pb.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)

	header(w, pf)
	pf.syncLock(w)

	if argv.Mutex {
		// use the mutex lock from the modified protoc.pb.go file
		pf.Bases.Lockname = "all.Lock"
	}

	pf.Base.iterTop(w)
	pf.Base.iterNext(w)
	pf.selectAllFunc(w)
	pf.iterSelect(w)

	fmt.Fprintln(w, "// maybe seperate files here?")

	pf.appendUnique(w) // Append() enforce no unique keys
	pf.sortByFunc(w)
	if argv.Delete {
		pf.deleteWithCopyFunc(w)
	} else {
		pf.deleteFunc(w)
	}
	pf.findFunc(w)
	return nil
}