Пример #1
0
func (b *BibTeX) Diff(srcA, srcB string) string {
	var out []string
	listA, err := bibtex.Parse([]byte(srcA))
	if err != nil {
		println(err)
	}
	listB, err := bibtex.Parse([]byte(srcB))
	if err != nil {
		println(err)
	}
	listC := bibtex.Diff(listA, listB)
	for _, element := range listC {
		out = append(out, element.String())
	}
	return strings.Join(out, "\n")
}
Пример #2
0
func (b *BibTeX) Parse(buf, include, exclude string) string {
	var out []string
	elements, err := bibtex.Parse([]byte(buf))
	if err != nil {
		println(err)
	}
	if include == "" {
		include = bibtex.DefaultInclude
	}
	for _, element := range elements {
		if strings.Contains(include, element.Type) {
			if len(exclude) == 0 || strings.Contains(exclude, element.Type) == false {
				out = append(out, element.String())
			}
		}
	}
	return strings.Join(out, "\n")
}
Пример #3
0
func main() {
	appname := path.Base(os.Args[0])
	flag.Parse()

	if showHelp == true {
		fmt.Printf(`
 USAGE: %s [OPTION] BIBFILE

 OPTIONS:

`, appname)

		flag.VisitAll(func(f *flag.Flag) {
			fmt.Printf("    -%s %s\n", f.Name, f.Usage)
		})

		fmt.Printf("\n\n Version %s\n", bibtex.Version)
		os.Exit(0)
	}

	if showVersion == true {
		fmt.Printf(" Version %s\n", bibtex.Version)
		os.Exit(0)
	}

	if showLicense == true {
		fmt.Printf(`
 %s
 
 copyright (c) 2016, Caltech
 All rights not granted herein are expressly reserved by Caltech.

 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 
 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 
 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 
 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

`, appname)
		os.Exit(0)
	}

	var (
		err      error
		elements []*bibtex.Element
		buf      []byte
	)

	in := os.Stdin
	out := os.Stdout

	args := flag.Args()
	if len(args) > 0 {
		fname := args[0]
		args = args[1:]
		buf, err = ioutil.ReadFile(fname)
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s, %s\n", fname, err)
			os.Exit(1)
		}
	} else {
		data := make([]byte, 100)
		for {
			_, err = in.Read(data)
			if err != nil {
				break
			}
			buf = append(buf[:], data[:]...)
		}
	}

	if len(args) > 0 {
		fname := args[0]
		args = args[1:]
		out, err := os.Create(fname)
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s, %s\n", fname, err)
		}
		defer out.Close()
	}

	elements, err = bibtex.Parse(buf)

	for _, element := range elements {
		if strings.Contains(include, element.Type) {
			if len(exclude) == 0 || strings.Contains(exclude, element.Type) == false {
				fmt.Fprintf(out, "%s\n", element)
			}
		}
	}
}
Пример #4
0
func main() {
	appname := path.Base(os.Args[0])
	flag.Parse()

	if showHelp == true {
		fmt.Printf(`
 USAGE: %s [OPTION] BIBFILE1 BIBFILE2

 OPTIONS:

`, appname)

		flag.VisitAll(func(f *flag.Flag) {
			fmt.Printf("    -%s %s\n", f.Name, f.Usage)
		})

		fmt.Printf("\n\n Version %s\n", bibtex.Version)
		os.Exit(0)
	}

	if showVersion == true {
		fmt.Printf(" Version %s\n", bibtex.Version)
		os.Exit(0)
	}

	if showLicense == true {
		fmt.Printf(`
 %s
 
 copyright (c) 2016, Caltech
 All rights not granted herein are expressly reserved by Caltech.

 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 
 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 
 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 
 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

`, appname)
		os.Exit(0)
	}

	var (
		err   error
		listA []*bibtex.Element
		listB []*bibtex.Element
		listC []*bibtex.Element
	)

	args := flag.Args()
	if len(args) != 2 {
		fmt.Fprintf(os.Stderr, "Must include two BibTeX filenames, try %s -h for details", appname)
		os.Exit(1)
	}
	src, err := ioutil.ReadFile(args[0])
	if err != nil {
		fmt.Fprintf(os.Stderr, "Can't read %s, %s", args[0], err)
		os.Exit(1)
	}
	listA, err = bibtex.Parse(src)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Can't parse %s, %s", args[0], err)
	}
	src, err = ioutil.ReadFile(args[1])
	if err != nil {
		fmt.Fprintf(os.Stderr, "Can't read %s, %s", args[1], err)
		os.Exit(1)
	}
	listB, err = bibtex.Parse(src)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Can't parse %s, %s", args[1], err)
	}
	switch {
	case mergeJoin:
		listC = bibtex.Join(listA, listB)
	case mergeDiff:
		listC = bibtex.Diff(listA, listB)
	case mergeIntersect:
		listC = bibtex.Intersect(listA, listB)
	case mergeExclusive:
		listC = bibtex.Exclusive(listA, listB)
	default:
		fmt.Fprintf(os.Stderr, "Missing type of merge operation, try %s -h for details", appname)
		os.Exit(1)
	}
	for _, elem := range listC {
		fmt.Fprintf(os.Stdout, "%s\n", elem)
	}
}