summaryrefslogtreecommitdiff
path: root/obsolete/biblio/bibtex/utils/misc/rfc2bib.awk
blob: 6b5fa043ee03855ad73dd47df90ab30fef84de75 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
######################################################################
#
# $Id: rfc2bib.awk,v 1.19 2001/02/14 10:41:50 rmm1002 Exp $
#

# Translates rfc-index.txt to a BibTeX file; probably GNU gawk
# specific.

# 20010214: fixed up handling of periods in titles (eg. HTTP1.1) by
# changing FS.  Also dealt with altered date parsing for RFC768 (why
# the removal of hyphens?  Wierd...)

# (C) 2000 Richard Mortier, rmm1002@cl.cam.ac.uk

# See http://www.cl.cam.ac.uk/~rmm1002/code.html for updates, etc.

######################################################################
#

BEGIN { 

    FS="[.] " ; RS="\n\n" ; 

    # banner
    printf ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
    printf ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
    printf ("%%\n");
    printf ("%% Date: %s\n", strftime());
    printf ("%%\n");
    printf ("%% This file is auto-generated from rfc-index.txt by rfc2bib.awk\n") ;
    printf ("%% by Richard Mortier (rmm1002 at cl.cam.ac.uk).  Consequently it gets\n") ;
    printf ("%% slightly confused by some entries, so as always\n") ;
    printf ("%%\n");
    printf ("%%                      PROOF-READ YOUR DOCUMENT!\n")
    printf ("%%\n");
    printf ("\n");
    printf ("@string{ietf=\"{IETF}\"}\n\n") ; 

}

######################################################################
#

/^[0-9][0-9][0-9][0-9]/{
    
    gsub(/[\n]/, "", $0) ;
    gsub(/[ ]+/, " ", $0) ;

    # guard '$', '_', '#' from BibTeX/LaTeX in all fields
    gsub(/\$/, "\\$", $0 ) ; # ");
    gsub(/_/, "\\_", $0 ) ; # ");
    gsub(/\#/, "\\" "\#", $0 ) ; # ");

    number = substr($1, 0, 4) ;
    printf ("@TechReport{rfc:%s,\n", number ) ;
    printf ("  key = {{\\sc rfc%s}},\n", number );

    # authors are all the fields "in the middle"; can be separated by
    # commas or ampersands
    authors = $2 ;
    for (i=3 ; i < NF-1 ; i++)
    {
        if (length( $ (i) ) > 1)
        {
            authors = ( authors ".~" $ (i) ) ;
        }
        else
        {
            authors = ( authors "." $ (i) ) ;
        }
    }
    gsub(/,| &/, " and", authors) ;
    gsub(/^ /, "", authors) ;
    if (length(authors) == 0)
    {
	authors = "author list not available" ;
    }
    printf ("  author = {%s},\n", authors ) ;

    # guard capitals and '&' in the title
    tmp = substr($1, 6) ;
    title = gensub(/([A-Z])/, "{\\1}", "g", tmp) ;
    gsub(/&/, "\\" "\\&", title ) ; # ");
    printf ("  title = {%s},\n", title) ;    

    # just let the institution be the IETF for now
    printf ("  institution = ietf,\n") ;

    y_fld = $ (NF-1) ;
    y_pos = length(y_fld) - 3 ;
    year  = substr(y_fld, y_pos, 4) ;
    if (length(year) == 0)
    {
	year = "{year not available}" ;
    }
    printf ("  year = %s,\n", year) ;

    printf ("  type = {{\\sc rfc}},\n") ;
    printf ("  number = %s,\n", number) ;

    # early RFCs: mmm-dd-yyyy ; later RFCs: month yyyy
    m_fld = $ (NF-1) ;
    gsub(/-| |\n|[0-9]/, "", m_fld) ;
    month = substr(tolower(m_fld), 0, 3) ;
    if (length(month) == 0) 
    {
	month = "{month not available}" ;
    }
    printf ("  month = %s,\n", month) ;

    printf ("  annote = {%s},\n", $NF) ;
    printf ("}\n\n") ;

}

######################################################################
######################################################################