diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /biblio/bibtex/utils/bibsort |
Initial commit
Diffstat (limited to 'biblio/bibtex/utils/bibsort')
-rw-r--r-- | biblio/bibtex/utils/bibsort/Makefile | 157 | ||||
-rw-r--r-- | biblio/bibtex/utils/bibsort/README | 15 | ||||
-rw-r--r-- | biblio/bibtex/utils/bibsort/bibsort.hlp | 200 | ||||
-rw-r--r-- | biblio/bibtex/utils/bibsort/bibsort.man | 291 | ||||
-rw-r--r-- | biblio/bibtex/utils/bibsort/bibsort.sh | 163 | ||||
-rw-r--r-- | biblio/bibtex/utils/bibsort/bibsort.txt | 264 | ||||
-rw-r--r-- | biblio/bibtex/utils/bibsort/rofvms.awk | 60 |
7 files changed, 1150 insertions, 0 deletions
diff --git a/biblio/bibtex/utils/bibsort/Makefile b/biblio/bibtex/utils/bibsort/Makefile new file mode 100644 index 0000000000..88f1ace3bd --- /dev/null +++ b/biblio/bibtex/utils/bibsort/Makefile @@ -0,0 +1,157 @@ +#======================================================================= +# Makefile for bibsort, a BibTeX bibliography file sort utility. +# +# Current target list: +# +# all make documentation files +# bibsort.hlp VAX VMS HELP file of manual pages +# bibsort.shar UNIX shar bundle for e-mail distribution +# bibsort.tar UNIX tar archive bundle +# bibsort.txt ASCII text file of manual pages +# bibsort.zip Info-ZIP archive bundle +# bibsort.zoo Zoo archive bundle +# clean remove temporary files +# clobber remove all automatically recreatable files +# install install bibsort on system +# install.time installation time stamp +# install-ftp install bibsort on anonymous ftp directory +# install-ftp.time installation time stamp +# test-version test extraction of version number +# uninstall remove installed executable and man pages +# uninstall-ftp remove installed files in anonymous ftp +# directory +# +# [19-Oct-1992] +#======================================================================= + +# Change these two directories to match local conventions if you +# wish to do "make install" and "make install-ftp": +BINDIR = /usr/local/bin +MANDIR = /usr/local/man/man1 +MANEXT = 1 +FTPDIR = /usr/spool/ftp/pub/tex/bib + +# Need new awk (nawk) or gawk here: +AWK = nawk + +CHMOD = chmod + +COL = col -b + +COMPRESS = compress + +CP = /bin/cp + +DIST-FILES = README Makefile bibsort.man bibsort.hlp bibsort.sh \ + bibsort.txt rofvms.awk + +LN = ln -s + +NROFF = nroff + +RM = /bin/rm -f + +SHELL = /bin/sh + +UNZIP = unzip + +VERSION = `$(AWK) '/^\#\#\#[ \t]*version *= *"[0-9.]+", *$$/ \ + { gsub(/[^0-9.]/,"",$$4); print $$4 }' bibsort.sh` + +ZIP = zip + +ZOO = zoo + +#======================================================================= + +all: bibsort.txt bibsort.hlp + +# VAX VMS help file format from bibsort.txt +bibsort.hlp: bibsort.txt rofvms.awk + $(AWK) -f rofvms.awk <bibsort.txt >bibsort.hlp + +bibsort.shar: $(DIST-FILES) + shar -b -c -v $(DIST-FILES) >bibsort.shar + +bibsort.tar: $(DIST-FILES) + -$(RM) bibsort.tar bibsort.tar-lst + tar chf bibsort.tar $(DIST-FILES) + -mkdir bibsort-$(VERSION) + cd bibsort-$(VERSION); tar xf ../bibsort.tar + tar cf bibsort-$(VERSION).tar bibsort-$(VERSION) + -$(RM) -r bibsort-$(VERSION) + -$(RM) bibsort.tar + $(LN) bibsort-$(VERSION).tar bibsort.tar + +bibsort.txt: bibsort.man + $(NROFF) -man $? | $(COL) >$@ + +bibsort.zip: $(DIST-FILES) + -$(RM) bibsort*.zip + -$(RM) bibsort*.zip-lst + $(ZIP) bibsort-$(VERSION).zip $(DIST-FILES) + $(UNZIP) -v bibsort-$(VERSION).zip >bibsort-$(VERSION).zip-lst + $(LN) bibsort-$(VERSION).zip bibsort.zip + +bibsort.zoo: $(DIST-FILES) + -$(RM) bibsort*.zoo + -$(RM) bibsort*.zoo-lst + $(ZOO) a bibsort-$(VERSION).zoo $(DIST-FILES) + $(ZOO) v bibsort-$(VERSION).zoo >bibsort-$(VERSION).zoo-lst + $(LN) bibsort-$(VERSION).zoo bibsort.zoo + +clean: + -$(RM) *.o + -$(RM) *.shar + -$(RM) *.tar + -$(RM) *.tar-lst + -$(RM) *.zip + -$(RM) *.zip-lst + -$(RM) *.zoo + -$(RM) *.zoo-lst + -$(RM) *~ + -$(RM) \#* + -$(RM) core + +clobber: clean + -$(RM) bibsort.hlp + -$(RM) bibsort.txt + -$(RM) install.time install-ftp.time + +install: install.time + +install.time: bibsort.sh bibsort.man + $(CP) bibsort.sh $(BINDIR)/bibsort + $(CHMOD) 755 $(BINDIR)/bibsort + $(CP) bibsort.man $(MANDIR)/bibsort.$(MANEXT) + $(CHMOD) 644 $(MANDIR)/bibsort.$(MANEXT) + touch install.time + +install-ftp: install-ftp.time + +install-ftp.time: bibsort.tar bibsort.zip bibsort.zoo + tar tvf bibsort-$(VERSION).tar >$(FTPDIR)/bibsort-$(VERSION).tar-lst + $(COMPRESS) <bibsort-$(VERSION).tar \ + >$(FTPDIR)/bibsort-$(VERSION).tar.z + $(CP) bibsort-$(VERSION).zip $(FTPDIR) + $(CP) bibsort-$(VERSION).zip-lst $(FTPDIR) + $(CP) bibsort-$(VERSION).zoo $(FTPDIR) + $(CP) bibsort-$(VERSION).zoo-lst $(FTPDIR) + ls -l $(FTPDIR)/bibsort* + date >install-ftp.time + +test-version: + @echo "Version number is ""'"$(VERSION)"'" + +uninstall: + -$(RM) $(BINDIR)/bibsort $(MANDIR)/bibsort.$(MANEXT) + -$(RM) install.time + +uninstall-ftp: + -$(RM) $(FTPDIR)/bibsort-$(VERSION).tar + -$(RM) $(FTPDIR)/bibsort-$(VERSION).tar-lst + -$(RM) $(FTPDIR)/bibsort-$(VERSION).zip + -$(RM) $(FTPDIR)/bibsort-$(VERSION).zip-lst + -$(RM) $(FTPDIR)/bibsort-$(VERSION).zoo + -$(RM) $(FTPDIR)/bibsort-$(VERSION).zoo-lst + -$(RM) install-ftp.time diff --git a/biblio/bibtex/utils/bibsort/README b/biblio/bibtex/utils/bibsort/README new file mode 100644 index 0000000000..27820c3ea6 --- /dev/null +++ b/biblio/bibtex/utils/bibsort/README @@ -0,0 +1,15 @@ +/u/sy/beebe/tex/bibsort/README, Tue Oct 13 19:07:33 1992 +Edit by Nelson H. F. Beebe <beebe@plot79.math.utah.edu> + +This directory contains bibsort, a UNIX tool for sorting BibTeX +bibliography files. The contents are: + +Makefile UNIX makefile +README This file +bibsort.hlp ASCII text file with formatted manual pages in VAX VMS + HELP format +bibsort.man manual pages (nroff/troff input) +bibsort.sh bibsort program, implemented as a UNIX sh script using + nawk, egrep, sort, and, tr. +bibsort.txt ASCII text file with formatted manual pages +rofvms.awk AWK script to convert .txt file to .hlp file diff --git a/biblio/bibtex/utils/bibsort/bibsort.hlp b/biblio/bibtex/utils/bibsort/bibsort.hlp new file mode 100644 index 0000000000..2dc7845201 --- /dev/null +++ b/biblio/bibtex/utils/bibsort/bibsort.hlp @@ -0,0 +1,200 @@ +1 DVI + bibsort - sort a BibTeX bibliography file + +2 SYNOPSIS + SYNOPSIS + bibsort [optional sort(1) switches] < infile >outfile + +2 DESCRIPTION + DESCRIPTION + bibsort filters a BibTeX bibliography, or bibliography frag- + ment, on its standard input, printing on standard output a + sorted bibliography. + + Sorting is by BibTeX tag name, or by @String macro name, and + letter case is ignored in the sorting. + + If no command-line switches are provided for sort(1), then + -f is supplied to cause letter case to be ignored. If you + also want to remove duplicate entries, you could specify the + switches -f -u. + + The input stream is conceptually divided into four parts, + any of which may be absent. + +2 --1.--Introductory--material--such--as -comments,---file + 1. Introductory material such as comments, file +2 ------headers, and-edit-logs-that-are-ignored-by-BibTeX. + headers, and edit logs that are ignored by BibTeX. +2 ------No-line-in-this-part-begins-with-an-at-sign,-``@''. + No line in this part begins with an at-sign, ``@''. + +2 --2.--Preamble-material delineated-by-``@Preamble{''--and + 2. Preamble material delineated by ``@Preamble{'' and +2 ------a -matching-closing-``}'',-intended-to-be processed + a matching closing ``}'', intended to be processed +2 ------by-TeX.--Normally,-there-is-only-one-such entry--in + by TeX. Normally, there is only one such entry in +2 ------a -bibliography-file,-although-BibTeX,-and-bibsort, + a bibliography file, although BibTeX, and bibsort, +2 ------permit-more-than-one. + permit more than one. + +2 --3.--Macro-definitions of-the-form-``@String{...}''. A + 3. Macro definitions of the form ``@String{...}''. A +2 ------single--macro--definition -may-span-multiple-lines, + single macro definition may span multiple lines, +2 ------and-there are-usually-several-such-definitions. + and there are usually several such definitions. + +2 --4.--Bibliography--entries--such--as--``@Article{...}'', + 4. Bibliography entries such as ``@Article{...}'', +2 ------``@Book{...}'',--``@Proceedings{...}'',--and-so-on. + ``@Book{...}'', ``@Proceedings{...}'', and so on. +2 ------For-bibsort,-any-line-that--begins--with an--``@'' + For bibsort, any line that begins with an ``@'' +2 ------immediately--followed--by letters and-digits-and-an + immediately followed by letters and digits and an +2 ------open-brace-is-considered-to-be-such-an-entry. + open brace is considered to be such an entry. + + The order of these parts is preserved in the output stream. + Part 1 will be unchanged, but parts 2--4 will be sorted + within themselves. + + The sort key of ``@Preamble'' entries is their initial line, + of ``@String'' entries, the macro name, and of all BibTeX + entries, the citation tag between the open curly brace and + the trailing comma. + + bibsort will correctly handle UNIX files with LF line termi- + nators, as well as IBM PC DOS files with CR LF line termina- + tors; the essential requirement is that input lines be del- + ineated by LF characters. + +2 CAVEATS + CAVEATS + BibTeX has loose syntactical requirements that the current + simple implementation of bibsort does not support. In par- + ticular, outer parentheses may not be used in place of + braces following ``@keyword'' patterns, nor may there be + leading or embedded whitespace. + + If you have such a file, you can use bibclean(1) to pretty- + print it into a form that bibsort can handle successfully. + + The user must be aware that sorting a bibliography is not + without peril, for at least these reasons: + +2 --1.--BibTeX-has-a-requirement-that-entry-tags given--in + 1. BibTeX has a requirement that entry tags given in +2 ------crossref =--tag-pairs-in a-bibliography-entry-must + crossref = tag pairs in a bibliography entry must +2 ------refer-to-entries-defined-later,--rather--than--ear- + refer to entries defined later, rather than ear- +2 ------lier,--in -the-bibliography-file. -This-regrettable + lier, in the bibliography file. This regrettable +2 ------implementation-limitation of-the-current (pre-1.0) + implementation limitation of the current (pre-1.0) +2 ------BibTeX--prevents-arbitrary-ordering-of-entries-when + BibTeX prevents arbitrary ordering of entries when +2 ------crossref-values-are-present. + crossref values are present. + +2 --2.--If-the-BibTeX-file-contains-interspersed-commentary + 2. If the BibTeX file contains interspersed commentary +2 ------between--``@keyword{...}''--entries,--this-material + between ``@keyword{...}'' entries, this material +2 ------will-be-considered-part-of-the-preceding-entry,-and + will be considered part of the preceding entry, and +2 ------will-be-sorted-with-it.--Leading-commentary-is-more + will be sorted with it. Leading commentary is more +2 ------common,-and-will-be-moved elsewhere-in-the-file. + common, and will be moved elsewhere in the file. + +2 ------This-is-normally-not--a--problem for--the--part 1 + This is normally not a problem for the part 1 +2 ------material-before-the-``@Preamble'',-since-it-is-kept + material before the ``@Preamble'', since it is kept +2 ------together-at-the-beginning of-the-output-stream. + together at the beginning of the output stream. + +2 --3.--Some-kinds-of-bibliography-files-should-be-kept--in + 3. Some kinds of bibliography files should be kept in +2 ------a -different--order-than-alphabetically-by-tags. A + a different order than alphabetically by tags. A +2 ------good-example-is-a bibliography-file-with the--con- + good example is a bibliography file with the con- +2 ------tents--of a-journal,-for-which-publication-order-is + tents of a journal, for which publication order is +2 ------likely-more-suitable. + likely more suitable. + + While a much more sophisticated implementation of bibsort + could deal with the first point, solving the second one + requires human intelligence and natural language understand- + ing that computers lack. + + bibsort uses ASCII control characters 001 through 007 for + temporary modifications of the input stream. If any of + these are already present in the input, they will be altered + on output. This is unlikely to be a problem, because those + characters have neither a printable representation, nor are + they conventionally used to mark line or page boundaries in + text files. + +2 PROGRAMMING-NOTES + PROGRAMMING NOTES + Some text editors permit application of an arbitrary filter + command to a region of text. For example, in GNU emacs(1), + the command C-u M-x shell-command-on-region, or + equivalently, C-u M-|, can be used to run bibsort on a + region of the buffer that is devoid of cross references and + other material that cannot be safely sorted. + + Some implementations of BibTeX editing support in GNU + emacs(1) have a sort-bibtex-entries command that is func- + tionally similar to bibsort. However, the file size that + can be processed by emacs(1) is limited, while bibsort can + be used on arbitrarily large files, since it acts as a + filter, processing a small amount of data at a time. The + sort stage needs the entire data stream, but fortunately, + the UNIX sort(1) command is clever enough to deal with very + large inputs. + + The current implementation of bibsort follows the UNIX trad- + ition of combining simple already-available tools. A six- + stage pipeline of egrep(1), nawk(1), sort(1), and tr(1) + accomplishes the job in one pass with about 70 lines of + shell script, 60 lines of which is a nawk(1) program for + insertion of sort keys. bibsort was written and tested on + several large bibliographies in a couple of hours. By con- + trast, bibtex(1) is more than 11 000 lines of code and docu- + mentation, and bibclean(1) is about 1500 lines long. + +2 BUGS + BUGS + bibsort may fail on some UNIX systems if their sort(1) + implementations cannot handle very long lines, because for + sorting purposes, each complete bibliography entry is tem- + porarily folded into a single line. You may be able to + overcome this problem by adding a -znnnnn switch to the + sort(1) command (passed via the command line to bibsort) to + increase the maximum line size to some larger value of nnnnn + bytes. + +2 SEE-ALSO + SEE ALSO + bibclean(1), bibtex(1), egrep(1), emacs(1), nawk(1), + sort(1), tr(1). + +2 AUTHOR + AUTHOR + Nelson H. F. Beebe, Ph.D. + Center for Scientific Computing + Department of Mathematics + University of Utah + Salt Lake City, UT 84112 + Tel: (801) 581-5254 + FAX: (801) 581-4148 + Email: <beebe@math.utah.edu> diff --git a/biblio/bibtex/utils/bibsort/bibsort.man b/biblio/bibtex/utils/bibsort/bibsort.man new file mode 100644 index 0000000000..7dcfb2d320 --- /dev/null +++ b/biblio/bibtex/utils/bibsort/bibsort.man @@ -0,0 +1,291 @@ +.\" ==================================================================== +.\" @Troff-man-file{ +.\" author = "Nelson H. F. Beebe", +.\" version = "0.00", +.\" date = "13 October 1992", +.\" time = "19:32:55 MDT", +.\" filename = "bibsort.man", +.\" address = "Center for Scientific Computing +.\" Department of Mathematics +.\" University of Utah +.\" Salt Lake City, UT 84112 +.\" USA", +.\" telephone = "+1 801 581 5254", +.\" FAX = "+1 801 581 4148", +.\" checksum = "45983 291 1296 8946", +.\" email = "beebe@math.utah.edu (Internet)", +.\" codetable = "ISO/ASCII", +.\" keywords = "bibliography, sorting, BibTeX", +.\" supported = "yes", +.\" docstring = "This file contains the UNIX manual pages +.\" for the bibsort utility, a program for +.\" sorting BibTeX data base files by their +.\" BibTeX tag names. +.\" +.\" The checksum field above contains a CRC-16 +.\" checksum as the first value, followed by the +.\" equivalent of the standard UNIX wc (word +.\" count) utility output of lines, words, and +.\" characters. This is produced by Robert +.\" Solovay's checksum utility.", +.\" } +.\" ==================================================================== +.if t .ds Bi B\s-2IB\s+2T\\h'-0.1667m'\\v'0.20v'E\\v'-0.20v'\\h'-0.125m'X +.if n .ds Bi BibTeX +.if t .ds Te T\\h'-0.1667m'\\v'0.20v'E\\v'-0.20v'\\h'-0.125m'X +.if n .ds Te TeX +.TH BIBSORT 1 "13 October 1992" "Version 0.00" +.\"====================================================================== +.SH NAME +bibsort \- sort a BibTeX bibliography file +.\"====================================================================== +.SH SYNOPSIS +.B "bibsort [optional sort(1) switches]" +< infile >outfile +.\"====================================================================== +.SH DESCRIPTION +.I bibsort +filters a \*(Bi\& bibliography, or bibliography +fragment, on its standard input, printing on +standard output a sorted bibliography. +.PP +Sorting is by \*(Bi\& tag name, or by +.I @String +macro name, and letter case is +ignored in the sorting. +.PP +If no command-line switches are provided for +.IR sort (1), +then +.I \-f +is supplied to cause letter case to be ignored. +If you also want to remove duplicate entries, you +could specify the switches +.IR "\-f \-u" . +.PP +The input stream is conceptually divided into four +parts, any of which may be absent. +.RS +.TP \w'1.'u+2n +1. +Introductory material such as comments, file +headers, and edit logs that are ignored by +\*(Bi\&. No line in this part begins with an +at-sign, ``@''. +.TP +2. +Preamble material delineated by ``@Preamble{'' and +a matching closing ``}'', intended to be processed +by \*(Te\&. Normally, there is only one such +entry in a bibliography file, although \*(Bi\&, +and +.IR bibsort , +permit more than one. +.TP +3. +Macro definitions of the form +``@String{.\|.\|.}''. A single macro definition +may span multiple lines, and there are usually +several such definitions. +.TP +4. +Bibliography entries such as ``@Article{.\|.\|.}'', +``@Book{.\|.\|.}'', ``@Proceedings{.\|.\|.}'', and +so on. For +.IR bibsort , +any line that begins with an ``@'' immediately +followed by letters and digits and an open brace +is considered to be such an entry. +.RE +.PP +The order of these parts is preserved in the +output stream. Part 1 will be unchanged, but +parts 2--4 will be sorted within themselves. +.PP +The sort key of ``@Preamble'' entries is their +initial line, of ``@String'' entries, the macro +name, and of all \*(Bi\& entries, the citation tag +between the open curly brace and the trailing +comma. +.PP +.I bibsort +will correctly handle UNIX files with LF line +terminators, as well as IBM PC DOS files with CR +LF line terminators; the essential requirement is +that input lines be delineated by LF characters. +.\"====================================================================== +.SH CAVEATS +\*(Bi\& has loose syntactical requirements that +the current simple implementation of +.I bibsort +does not support. In particular, outer +parentheses may +.I not +be used in place of braces following ``@keyword'' +patterns, nor may there be leading or embedded +whitespace. +.PP +If you have such a file, you can use +.IR bibclean (1) +to prettyprint it into a form that +.I bibsort +can handle successfully. +.PP +The user must be aware that sorting a bibliography +is not without peril, for at least these reasons: +.RS +.TP \w'1.'u+2n +1. +\*(Bi\& has a +requirement that entry tags given in +.IR "crossref" " = " "tag" +pairs in a bibliography entry +.I must +refer to entries defined +.IR later , +rather than earlier, in the bibliography file. +This regrettable implementation limitation of the +current (pre-1.0) \*(Bi\& prevents arbitrary +ordering of entries when +.I crossref +values are present. +.TP +2. +If the BibTeX file contains interspersed +commentary between ``@keyword{.\|.\|.}'' entries, +this material will be considered part of the +.I preceding +entry, and will be sorted with it. Leading +commentary is more common, and will be moved +elsewhere in the file. +.IP +This is normally not a problem for the part 1 +material before the ``@Preamble'', since it is kept +together at the beginning of the output stream. +.TP +3. +Some kinds of bibliography files should be kept in +a different order than alphabetically by tags. A +good example is a bibliography file with the +contents of a journal, for which publication order +is likely more suitable. +.RE +.PP +While a much more sophisticated implementation of +.I bibsort +could deal with the first point, solving the +second one requires human intelligence and natural +language understanding that computers lack. +.PP +.I bibsort +uses ASCII control characters 001 through 007 for +temporary modifications of the input stream. If +any of these are already present in the input, +they will be altered on output. This is unlikely +to be a problem, because those characters have +neither a printable representation, nor are they +conventionally used to mark line or page +boundaries in text files. +.\"====================================================================== +.SH "PROGRAMMING NOTES" +Some text editors permit application of an +arbitrary filter command to a region of text. +For example, in GNU +.IR emacs (1), +the command +.IR "C-u M-x shell-command-on-region" , +or equivalently, +.IR "C-u M-|" , +can be used to run +.I bibsort +on a region of the buffer that is devoid of cross +references and other material that cannot be +safely sorted. +.PP +Some implementations of \*(Bi\& editing support in +GNU +.IR emacs (1) +have a +.I sort-bibtex-entries +command that is functionally similar to +.IR bibsort . +However, the file size that can be processed +by +.IR emacs (1) +is limited, while +.I bibsort +can be used on arbitrarily large files, since it +acts as a filter, processing a small amount of +data at a time. The sort stage needs the entire +data stream, but fortunately, the UNIX +.IR sort (1) +command is clever enough to deal with very large +inputs. +.PP +The current implementation of +.I bibsort +follows the UNIX tradition of combining simple +already-available tools. A six-stage pipeline of +.IR egrep (1), +.IR nawk (1), +.IR sort (1), +and +.IR tr (1) +accomplishes the job in one pass with about 70 +lines of shell script, 60 lines of which is a +.IR nawk (1) +program for insertion of sort keys. +.I bibsort +was written and tested on several large +bibliographies in a couple of hours. By contrast, +.IR bibtex (1) +is more than 11\0000 lines of code and +documentation, and +.IR bibclean (1) +is about 1500 lines long. +.\"====================================================================== +.SH BUGS +.I bibsort +may fail on some UNIX systems if their +.IR sort (1) +implementations cannot handle very long lines, +because for sorting purposes, each complete +bibliography entry is temporarily folded into a +single line. You may be able to overcome this +problem by adding a +.BI -z nnnnn +switch to the +.IR sort (1) +command (passed via the command line to +.IR bibsort ) +to increase the maximum line size to some larger +value of +.I nnnnn +bytes. +.\"====================================================================== +.SH "SEE ALSO" +.BR bibclean (1), +.BR bibtex (1), +.BR egrep (1), +.BR emacs (1), +.BR nawk (1), +.BR sort (1), +.BR tr (1). +.\"====================================================================== +.SH AUTHOR +Nelson H. F. Beebe, Ph.D. +.br +Center for Scientific Computing +.br +Department of Mathematics +.br +University of Utah +.br +Salt Lake City, UT 84112 +.br +Tel: (801) 581-5254 +.br +FAX: (801) 581-4148 +.br +Email: <beebe@math.utah.edu> +.\"==============================[The End]============================== diff --git a/biblio/bibtex/utils/bibsort/bibsort.sh b/biblio/bibtex/utils/bibsort/bibsort.sh new file mode 100644 index 0000000000..fe8a2281ef --- /dev/null +++ b/biblio/bibtex/utils/bibsort/bibsort.sh @@ -0,0 +1,163 @@ +#!/bin/sh +### ==================================================================== +### @UNIX-shell-file{ +### author = "Nelson H. F. Beebe", +### version = "0.00", +### date = "13 October 1992", +### time = "19:33:14 MDT", +### filename = "bibsort.sh", +### address = "Center for Scientific Computing +### Department of Mathematics +### University of Utah +### Salt Lake City, UT 84112 +### USA", +### telephone = "+1 801 581 5254", +### FAX = "+1 801 581 4148", +### checksum = "35811 163 700 5138", +### email = "beebe@math.utah.edu (Internet)", +### codetable = "ISO/ASCII", +### keywords = "bibliography, sorting, BibTeX", +### supported = "yes", +### docstring = "This file contains the bibsort utility, a +### program for sorting BibTeX data base files +### by their BibTeX tag names. +### +### The checksum field above contains a CRC-16 +### checksum as the first value, followed by the +### equivalent of the standard UNIX wc (word +### count) utility output of lines, words, and +### characters. This is produced by Robert +### Solovay's checksum utility.", +### } +# ==================================================================== +# Sort a BibTeX file fragment by citation tags, filtering stdin to +# stdout. +# +# Usage: +# bibsort [optional sort(1) switches] <infile >outfile +# +# If the sort switches are omitted, -f (ignore letter case +# differences) is used. "bibsort -f -u" would remove duplicate +# bibliography entries from the input stream. +# +# Note that this operation cannot be done in general, because @string +# and @preamble entries need to come first, and cross-references last. +# +# In general, you should only apply this command to a fragment of a +# .bib file that you know in advance can be sorted. +# +# We deal with leading commentary, @preamble, and @string by giving +# them temporary sort keys that place them before other bibliography +# entries. +# +######################################################################## +# WARNINGS: +# +# (1) This simple version does NOT recognize bib entries with outer +# parentheses instead of braces. +# +# (2) It may fail on some UNIX sort implementations that cannot handle +# very long lines, because for sorting purposes, each complete bib +# entry is temporarily folded into a single line. You may be able to +# overcome this problem by adding a -z nnnnn switch to the sort +# command to set the maximum line size to nnnnn bytes. +# +######################################################################## +# +# The sorting is implemented as a filter pipeline: +# +# Stage 1 (nawk) finds bib file entries and prefixes them with a line +# containing a sort key, where each such line begins with a Ctl-E, and +# the file ends with Ctl-E. +# +# Stage 2 (tr) turns LF into Ctl-G and Ctl-E into LF. This hides +# line boundaries and makes each item a separate `line'. +# +# Stage 3 (sort) sorts `lines' (i.e. bib entries), ignoring +# letter case differences. +# +# Stage 4 (tr) turns LF into Ctl-E, and Ctl-G back into LF. This +# restores the original line boundaries. +# +# Stage 5 (tr) deletes all Ctl-E and Ctl-F characters. +# +# Stage 6 (egrep) removes the sort key lines. +# + +if [ $# -gt 0 ] +then + SORTFLAGS="$*" +else + SORTFLAGS="-f" +fi + +nawk ' +BEGIN { + sort_prefix = "\005" + sort_key = sort_prefix "%%SORTKEY:" + hidden_newline = "\006" + print sort_key "\001" hidden_newline +} + +/^@[Pp][Rr][Ee][Aa][Mm][Bb][Ll][Ee]{/ { + k = index($0,"{") + 1 + print sort_key "\002" substr($0,k) hidden_newline + printbraceditem() + next +} +/^@[sS][tT][rR][iI][nN][gG]{/ { + k = index($0,"{") + 1 + m = index($0,"=") + print sort_key "\003" substr($0,k,m-k) hidden_newline + printbraceditem() + next +} + +# "@keyword{tag," +/^@[a-zA-Z0-9]*{/ { + k = index($0,"{") + 1 + m = index($0,",") + print sort_key "\004" substr($0,k,m-k) hidden_newline + print + next +} + +{ print } + +END { printf(sort_prefix) } + +function bracecount(s, k,n) +{ + n = 0 + for (k = 1; k <= length(s); ++k) + { + if (substr(s,k,1) == "{") + n++ + else if (substr(s,k,1) == "}") + n-- + } + return (n) +} + +# Starting with the current contents of $0, print lines until we +# reach a zero brace count. + +function printbraceditem(count) +{ + count = bracecount($0) + print $0 + while (count != 0) + { + if (getline <= 0) + break + printf("%s\007",$0) + count += bracecount($0) + } +} +' | \ + tr '\012\005' '\007\012' | \ + sort ${SORTFLAGS} | \ + tr '\007\012' '\012\005' | \ + tr -d '\005\006' | \ + egrep -v '^%%SORTKEY:' +################################[The End]############################### diff --git a/biblio/bibtex/utils/bibsort/bibsort.txt b/biblio/bibtex/utils/bibsort/bibsort.txt new file mode 100644 index 0000000000..20dffe15cd --- /dev/null +++ b/biblio/bibtex/utils/bibsort/bibsort.txt @@ -0,0 +1,264 @@ + + + +BIBSORT(1) USER COMMANDS BIBSORT(1) + + + +NAME + bibsort - sort a BibTeX bibliography file + +SYNOPSIS + bibsort [optional sort(1) switches] < infile >outfile + +DESCRIPTION + bibsort filters a BibTeX bibliography, or bibliography frag- + ment, on its standard input, printing on standard output a + sorted bibliography. + + Sorting is by BibTeX tag name, or by @String macro name, and + letter case is ignored in the sorting. + + If no command-line switches are provided for sort(1), then + -f is supplied to cause letter case to be ignored. If you + also want to remove duplicate entries, you could specify the + switches -f -u. + + The input stream is conceptually divided into four parts, + any of which may be absent. + + 1. Introductory material such as comments, file + headers, and edit logs that are ignored by BibTeX. + No line in this part begins with an at-sign, ``@''. + + 2. Preamble material delineated by ``@Preamble{'' and + a matching closing ``}'', intended to be processed + by TeX. Normally, there is only one such entry in + a bibliography file, although BibTeX, and bibsort, + permit more than one. + + 3. Macro definitions of the form ``@String{...}''. A + single macro definition may span multiple lines, + and there are usually several such definitions. + + 4. Bibliography entries such as ``@Article{...}'', + ``@Book{...}'', ``@Proceedings{...}'', and so on. + For bibsort, any line that begins with an ``@'' + immediately followed by letters and digits and an + open brace is considered to be such an entry. + + The order of these parts is preserved in the output stream. + Part 1 will be unchanged, but parts 2--4 will be sorted + within themselves. + + The sort key of ``@Preamble'' entries is their initial line, + of ``@String'' entries, the macro name, and of all BibTeX + entries, the citation tag between the open curly brace and + the trailing comma. + + + + + +Version 0.00 Last change: 13 October 1992 1 + + + + + + +BIBSORT(1) USER COMMANDS BIBSORT(1) + + + + bibsort will correctly handle UNIX files with LF line termi- + nators, as well as IBM PC DOS files with CR LF line termina- + tors; the essential requirement is that input lines be del- + ineated by LF characters. + +CAVEATS + BibTeX has loose syntactical requirements that the current + simple implementation of bibsort does not support. In par- + ticular, outer parentheses may not be used in place of + braces following ``@keyword'' patterns, nor may there be + leading or embedded whitespace. + + If you have such a file, you can use bibclean(1) to pretty- + print it into a form that bibsort can handle successfully. + + The user must be aware that sorting a bibliography is not + without peril, for at least these reasons: + + 1. BibTeX has a requirement that entry tags given in + crossref = tag pairs in a bibliography entry must + refer to entries defined later, rather than ear- + lier, in the bibliography file. This regrettable + implementation limitation of the current (pre-1.0) + BibTeX prevents arbitrary ordering of entries when + crossref values are present. + + 2. If the BibTeX file contains interspersed commentary + between ``@keyword{...}'' entries, this material + will be considered part of the preceding entry, and + will be sorted with it. Leading commentary is more + common, and will be moved elsewhere in the file. + + This is normally not a problem for the part 1 + material before the ``@Preamble'', since it is kept + together at the beginning of the output stream. + + 3. Some kinds of bibliography files should be kept in + a different order than alphabetically by tags. A + good example is a bibliography file with the con- + tents of a journal, for which publication order is + likely more suitable. + + While a much more sophisticated implementation of bibsort + could deal with the first point, solving the second one + requires human intelligence and natural language understand- + ing that computers lack. + + bibsort uses ASCII control characters 001 through 007 for + temporary modifications of the input stream. If any of + these are already present in the input, they will be altered + on output. This is unlikely to be a problem, because those + characters have neither a printable representation, nor are + + + +Version 0.00 Last change: 13 October 1992 2 + + + + + + +BIBSORT(1) USER COMMANDS BIBSORT(1) + + + + they conventionally used to mark line or page boundaries in + text files. + +PROGRAMMING NOTES + Some text editors permit application of an arbitrary filter + command to a region of text. For example, in GNU emacs(1), + the command C-u M-x shell-command-on-region, or + equivalently, C-u M-|, can be used to run bibsort on a + region of the buffer that is devoid of cross references and + other material that cannot be safely sorted. + + Some implementations of BibTeX editing support in GNU + emacs(1) have a sort-bibtex-entries command that is func- + tionally similar to bibsort. However, the file size that + can be processed by emacs(1) is limited, while bibsort can + be used on arbitrarily large files, since it acts as a + filter, processing a small amount of data at a time. The + sort stage needs the entire data stream, but fortunately, + the UNIX sort(1) command is clever enough to deal with very + large inputs. + + The current implementation of bibsort follows the UNIX trad- + ition of combining simple already-available tools. A six- + stage pipeline of egrep(1), nawk(1), sort(1), and tr(1) + accomplishes the job in one pass with about 70 lines of + shell script, 60 lines of which is a nawk(1) program for + insertion of sort keys. bibsort was written and tested on + several large bibliographies in a couple of hours. By con- + trast, bibtex(1) is more than 11 000 lines of code and docu- + mentation, and bibclean(1) is about 1500 lines long. + +BUGS + bibsort may fail on some UNIX systems if their sort(1) + implementations cannot handle very long lines, because for + sorting purposes, each complete bibliography entry is tem- + porarily folded into a single line. You may be able to + overcome this problem by adding a -znnnnn switch to the + sort(1) command (passed via the command line to bibsort) to + increase the maximum line size to some larger value of nnnnn + bytes. + +SEE ALSO + bibclean(1), bibtex(1), egrep(1), emacs(1), nawk(1), + sort(1), tr(1). + +AUTHOR + Nelson H. F. Beebe, Ph.D. + Center for Scientific Computing + Department of Mathematics + University of Utah + Salt Lake City, UT 84112 + Tel: (801) 581-5254 + + + +Version 0.00 Last change: 13 October 1992 3 + + + + + + +BIBSORT(1) USER COMMANDS BIBSORT(1) + + + + FAX: (801) 581-4148 + Email: <beebe@math.utah.edu> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Version 0.00 Last change: 13 October 1992 4 + + + diff --git a/biblio/bibtex/utils/bibsort/rofvms.awk b/biblio/bibtex/utils/bibsort/rofvms.awk new file mode 100644 index 0000000000..469786a3c6 --- /dev/null +++ b/biblio/bibtex/utils/bibsort/rofvms.awk @@ -0,0 +1,60 @@ +# rofvms.awk -*-awk-*- +# Filter to convert nroff -man output to VMS .hlp file format according +# to the rules: +# +# 13 or more consecutive blank lines are reduced to 1 +# 3--12 consecutive blank lines are dropped +# 2 consecutive blank lines are reduced to 1 +# All others output verbatim. +# +# The peculiar number 13 handles the case where a paragraph break +# coincides with a page break. +# +# In addition, whenever a line in non-blank in column 1, and then +# previous line was blank, we insert a blank line; this provides +# vertical space before a section heading. +# +# The output of nroff -man on different UNIX systems is regrettably +# quite variable in appearance; this file is likely to need +# modifications on other than Sun OS. +# +# Too bad nroff doesn't have an option to suppress titling! +# +# The NAME section head becomes 1 DVI, and others become +# 2 XXX followed by XXX. +# [05-Aug-89] + +# Match and delete page headers: xxx(nnn) .... xxx(nnn) +/^[A-Za-z][-_A-Za-z0-9]*\([0-9A-Za-z]+\).*[A-Za-z][-_A-Za-z0-9]*\([0-9A-Za-z]+\)$/ {next;} + +# Match and delete page footers: Sun Release ...nnn +# These vary from system to system, so extra patterns may be needed here +/^Sun Release.*[0-9]+$/ {next;} # Sun OS x.x +/^Printed.*[0-9]+$/ {next;} # BSD 4.3 +/^Page [0-9].*$/ {next;} # Silicon Graphics +/^Version.*Last change:/ {next;}# bibclean.txt on SunOS 4.1.1 + + +# Match all lines and do blank line processing +{ + if (NF == 0) # blank line + nb++; + else # non blank line + { + if ((nb == 1) || (nb == 2) || (nb >= 13)) + printf("\n"); + else if ((nb > 0) && (substr($0,1,1) != " ") && (nf > 0)) + printf("\n"); + if ($0 == "NAME") # level 1 header + $0 = "1 DVI"; + else if (substr($0,1,1) != " ") # level 2 header + { + header = $0; + gsub(/ /,"-",header); + $0 = "2 " header "\n " $0; + } + printf("%s\n",$0); + nb = 0; + nf++; + } +} |