Debian Codegraph @

texmf-dist/doc/bibtex/ietfbibs/id2bib.awk

raw
1 # Copyright(c) 2000-2016 Richard Mortier <[email protected]>
2 # Copyright(c) 2010 Paul Jakma <[email protected]>
3 #
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
10 #
11 # The above copyright notice and this permission notice shall be included in all
12 # copies or substantial portions of the Software.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 # SOFTWARE.
21
22 BEGIN {
23 FS="[\"<>]";
24 RS="(\n[A-Za-z0-9].*\n[^ ]+\n)* \"";
25
26 # banner
27 printf("% This file auto-generated from id-index.txt by id2bib.awk\n");
28 printf("% by Richard Mortier <[email protected]>.\n");
29 printf("%\n");
30 printf("% Date: %s\n", strftime());
31 printf("\n");
32 printf("@string{ietf=\"{IETF}\"}\n\n");
33 }
34
35 function get_authors(field, i, first) {
36 first = 1;
37 authors = "";
38
39 for (i = field; i <= NF; i++) {
40 if (length($i) == 0) continue;
41 if ($i ~ /[0-9]{1,2}[-/][[:alpha:]]{3}[-/][0-9]{2}/)
42 break;
43 if ($i ~ /(19|20)[0-9]{2}-[0-9]{2}-[0-9]{2}/)
44 break;
45
46 if (first) first = 0;
47 else authors = authors " and ";
48 authors = authors $i;
49 }
50 return i;
51 }
52
53 NF > 1 {
54 # guard '$', '_', '#' from BibTeX/LaTeX in all fields
55 gsub(/\$/, "\\$", $0 ); # ");
56 gsub(/_/, "\\_", $0 ); # ");
57 gsub(/#/, "\\" "#", $0 ); # ");
58
59 for (i = 1; i <= NF; i++) {
60 gsub(/[ \n\t]+/, " ", $i);
61 sub(/^[ ]+/,"",$i);
62 }
63
64 title = gensub(/([A-Z])/, "{\\1}", "g", $1);
65 idstr = $3;
66 abstract = $4;
67
68 authors = "";
69 n=split($2, authors_date, ",");
70 for (i=0; i<n-1; i++)
71 {
72 a = authors_date[i];
73 gsub(/[ \n\t]+/, " ", a);
74 sub(/^[ ]+/, "", a);
75
76 if(a == "") continue;
77 else if(authors == "") authors = a
78 else authors = authors " and " a;
79 }
80 date = authors_date[n-1];
81 split(date, ymd, "-");
82 year = ymd[1];
83 month = ymd[2];
84 day = ymd[3];
85
86 printf("@Misc{id:%s,\n", idstr) ;
87 printf(" author = {%s},\n", authors) ;
88 printf(" title = {%s},\n", title) ;
89 printf(" howpublished = {Internet Draft},\n") ;
90 printf(" month = %s,\n", month) ;
91 printf(" year = %s,\n", year) ;
92 printf(" note = {%s},\n", "<" idstr ".txt>") ;
93 printf(" abstract = {%s},\n", abstract) ;
94 printf(" url = {{http://tools.ietf.org/html/%s}},\n", idstr);
95 printf("}\n\n") ;
96 }