Style changes

This commit is contained in:
Alex Yatskov 2015-08-11 14:56:14 +09:00
parent 408830ec4e
commit d4137012b8
2 changed files with 17 additions and 25 deletions

View File

@ -41,8 +41,8 @@ func usage() {
}
func main() {
cols := flag.Int("cols", DEFAULT_NUM_COLUMNS, "number of columns to use for layout")
tabs := flag.Int("tabs", DEFAULT_TAB_SIZE, "tab width specified in number of spaces")
cols := flag.Int("cols", defNumCols, "number of columns to use for layout")
tabs := flag.Int("tabs", defTabSize, "tab width specified in number of spaces")
notoc := flag.Bool("notoc", false, "do not generate table of contents for headings")
norules := flag.Bool("norules", false, "do not generate horizontal rules above headings")
pascal := flag.Bool("pascal", false, "use PascalCase for abbreviating tags")
@ -58,18 +58,18 @@ func main() {
input, err := ioutil.ReadFile(args[0])
if err != nil {
log.Fatalf("error: unable to read from file %s", args[0])
log.Fatalf("unable to read from file: %s", args[0])
}
flags := 0
if *notoc {
flags |= FLAG_NO_TOC
flags |= flagNoToc
}
if *norules {
flags |= FLAG_NO_RULES
flags |= flagNoRules
}
if *pascal {
flags |= FLAG_PASCAL
flags |= flagPascal
}
renderer := VimDocRenderer(args[1], *desc, *cols, *tabs, flags)
@ -78,11 +78,11 @@ func main() {
file, err := os.Create(args[1])
if err != nil {
log.Fatalf("error: unable to write to file %s", args[1])
log.Fatalf("unable to write to file: %s", args[1])
}
defer file.Close()
if _, err := file.Write(output); err != nil {
log.Fatal("error: unable to write output")
log.Fatal("unable to write output")
}
}

View File

@ -34,14 +34,14 @@ import (
)
const (
DEFAULT_NUM_COLUMNS = 80
DEFAULT_TAB_SIZE = 4
defNumCols = 80
defTabSize = 4
)
const (
FLAG_NO_TOC = 1 << iota
FLAG_NO_RULES
FLAG_PASCAL
flagNoToc = 1 << iota
flagNoRules
flagPascal
)
type list struct {
@ -73,7 +73,7 @@ func VimDocRenderer(filename, desc string, cols, tabs, flags int) blackfriday.Re
if index := strings.LastIndex(filename, "."); index > -1 {
title = filename[:index]
if flags&FLAG_PASCAL == 0 {
if flags&flagPascal == 0 {
title = strings.ToLower(title)
}
}
@ -93,18 +93,10 @@ func (v *vimDoc) pushl() {
}
func (v *vimDoc) popl() {
if len(v.lists) == 0 {
log.Fatal("error: invalid list operation")
}
v.lists = v.lists[:len(v.lists)-1]
}
func (v *vimDoc) getl() *list {
if len(v.lists) == 0 {
log.Fatal("error: invalid list operation")
}
return v.lists[len(v.lists)-1]
}
@ -118,7 +110,7 @@ func (v *vimDoc) fixupHeader(text []byte) []byte {
}
func (v *vimDoc) buildTag(text []byte) []byte {
if v.flags&FLAG_PASCAL == 0 {
if v.flags&flagPascal == 0 {
text = bytes.ToLower(text)
text = bytes.Replace(text, []byte{' '}, []byte{'_'}, -1)
} else {
@ -195,7 +187,7 @@ func (v *vimDoc) BlockHtml(out *bytes.Buffer, text []byte) {
func (v *vimDoc) Header(out *bytes.Buffer, text func() bool, level int, id string) {
initPos := out.Len()
if v.flags&FLAG_NO_RULES == 0 {
if v.flags&flagNoRules == 0 {
switch level {
case 1:
v.writeRule(out, "=")
@ -397,7 +389,7 @@ func (v *vimDoc) DocumentHeader(out *bytes.Buffer) {
func (v *vimDoc) DocumentFooter(out *bytes.Buffer) {
var temp bytes.Buffer
if v.tocPos > 0 && v.flags&FLAG_NO_TOC == 0 {
if v.tocPos > 0 && v.flags&flagNoToc == 0 {
temp.Write(out.Bytes()[:v.tocPos])
v.writeToc(&temp, v.rootHead, 0)
temp.WriteString("\n")