-
Notifications
You must be signed in to change notification settings - Fork 6
/
zentralblatt
executable file
·186 lines (180 loc) · 4.7 KB
/
zentralblatt
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
# zentralblatt - A wrapper script for nicer output of zentralblatt
#
# Authors: Roland Herzog <[email protected]>
# Gerd Wachsmuth <[email protected]>
# Version: 0.2
# Licence: GPL v3, see http://www.gnu.org/licenses/gpl.html
PROG1='
function ltrim(s) { sub(/^[ \t\r\n]+/, "", s); return s }
function rtrim(s) { sub(/[ \t\r\n]+$/, "", s); return s }
function trim(s) { return rtrim(ltrim(s)); }
BEGIN {
delete_this_entry = 0;
spaces = " ";
};
/^@/ {
# Print the header of the entry.
print(toupper($0));
next;
}
/^ *(Journal|Language|MSC2010|Zbl)/ {
# Delete certain unnecessary entries.
delete_this_entry = 1;
next;
};
/^ *[a-zA-Z]+ *=/ {
# Nicer formatting of the remaining entries.
delete_this_entry = 0;
sub("=[\"{]", " = {");
sub("\",$", "},");
gsub("FJournal", " journal");
split($0,strarray,"=");
# Uppercase the left-hand side
strarray[1] = trim(toupper(strarray[1]))
# Fill in some spaces
strarray[1] = substr(spaces, 0, (10-length(strarray[1]) +1)) strarray[1]
print strarray[1] " = " trim(strarray[2]);
next;
};
/^}$/ {
print;
next;
};
// {
if (delete_this_entry == 0) {
sub("\",$", "},");
# Fill in some spaces
print " " $0;
}
};
'
PROG2='
/@[A-Z]*{[A-Za-z0-9.]*,/{
# Save the header and init some variables.
head=substr($0,0,match($0,"{"));
body="";
authors_active=0;
have_read_authors=0;
year=0;
next;
}
/^}$/{
# This is the end of the entry. Print everything!
body=body $0;
printf "%s",head;
# Create a nice label (authors or editors and year) for the entry.
count=split(authors,author_array," +and +");
for( i=1; i<=count; i++ ) {
# printf "--\"%s\"--", author_array[i];
lastname=gensub("^.*{([^}]*)}.*$", "\\1", "g", author_array[i]);
lastname=gensub("\\\\\"([a-zA-Z])","\\1e","g", lastname); # test for umlauts
lastname=gensub("\\\\ss","ss","g", lastname); # test for eszett
lastname=gensub("\\\\[^{}]*{([a-zA-Z])}","\\1","g", lastname); # test for accents (this is needed two times, e.g. for "{\v{c}}")
lastname=gensub("\\\\[^{}]*{([a-zA-Z])}","\\1","g", lastname);
lastname=gensub("'\''","","g", lastname); # Remove apostroph
word_count = split( lastname, lastname_array, " "); # Split lastname into words and capitalize each of them
lastname = "";
for( j=1; j<= word_count; j++ ) { # Fuer Juan Carlos ;)
lastname = lastname toupper(substr(lastname_array[j],1,1)) substr(lastname_array[j],2,1000);
}
printf "%s",lastname;
};
print year ",";
print body "\n";
next;
}
/ *[A-Z]* =/{
if( $1 == "AUTHOR" ) {
# If we already have read the editors, we overwrite them.
authors=substr($0,match($0,"{")+1,100);
authors_active=1;
have_read_authors=1;
}
else if( ($1 == "EDITOR") && !have_read_authors){
# If we already have read the authors, we skip the editors.
authors=substr($0,match($0,"{")+1,100);
authors_active=1;
}
else if( $1 == "TITLE" ) {
gsub(".}},$", "}},");
}
else {
authors_active=0;
if($1 == "YEAR"){
year=substr($0,match($0,"[[0-9]]*"),4)
}
};
}
/^[^=]*$/{
if(authors_active){
authors=authors $0;
}
}
//{
body=body $0 "\n";
next;
}'
# The last program changes the format of the authors from
# A. {Thor}
# (which causes some trouble with biber/biblatex) to
# Thor, A.
PROG3='
/@[A-Z]*{[A-Za-z0-9.]*,/{
# Print the header and init some variables.
head=substr($0,0,match($0,"{"));
authors_active=0;
print; next;
}
/^[^=]*$/{
if(authors_active){
authors=authors $0;
next;
}
}
/ *[A-Z]* =/{
if( $1 == "AUTHOR" ) {
authors=substr($0,match($0,"{")+1,100);
authors_active=1;
next;
}
else {
if( authors_active ) {
# Remove trailing "},"
authors = substr(authors,0,match(authors,"},$")-1);
count=split(authors,author_array," +and +");
authors = "";
for( i=1; i<=count; i++ ) {
name = author_array[i];
# printf "--\"%s\"--", name;
# Find the split point between first name and last name.
# This should be the last space which is outside of braces
braces = 0;
for( j = 0; j < length(name); j++ ) {
char = substr(name,j,1);
if( char == "{" ) {
braces++;
}
else if( char == "}" ) {
braces--;
}
else if( char == " " && braces == 0 ) {
splitpoint = j;
}
}
givenname = substr(name, 0, splitpoint - 1);
lastname = substr(name, splitpoint+2, match(name,"}$")-splitpoint-2);
if( authors != "" ) {
authors = authors " and ";
}
authors = authors lastname ", " givenname;
}
# Output the authors
print " AUTHOR = {" authors "},";
}
authors_active=0;
};
}
//
'
zentralblatt.pl "$@" | awk "$PROG1" | gawk "$PROG2" | awk "$PROG3"