-
Notifications
You must be signed in to change notification settings - Fork 6
/
msc
executable file
·137 lines (130 loc) · 3.67 KB
/
msc
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
#!/bin/bash
# msc - A wrapper script for nicer output of mathscinet.pl
#
# Authors: Roland Herzog <[email protected]>
# Gerd Wachsmuth <[email protected]>
# Version: 0.2
# Licence: GPL v3, see http://www.gnu.org/licenses/gpl.html
PROG1='
BEGIN {
delete_this_entry = 0;
};
/^@/ {
# Print the header of the entry.
gsub(" ", "");
print(toupper($0));
next;
}
/^ *(MRNUMBER|MRREVIEWER|MRCLASS|CODEN|[^F]JOURNAL|URL = {http[s]?:\/\/dx\.doi\.org)/ {
# Delete certain unnecessary entries.
delete_this_entry = 1;
next;
};
/^ *[A-Z]+ =/ {
# Do not delete the remaining entries.
delete_this_entry = 0;
gsub("FJOURNAL", " JOURNAL");
print;
next;
};
/^}$/ {
print;
next;
};
// {
if (delete_this_entry == 0)
print;
};'
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;
have_read_doi=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++ ) {
# First, try whether the names are given as "lastname, firstname"
idx=match(author_array[i],", ");
lastname=substr(author_array[i],0,idx-1);
if( idx == 0 ) {
# Now, try for "firstname lastname"
idx=match(author_array[i]," [^ ]*$");
lastname=substr(author_array[i],idx+1,length(author_array[i]));
}
lastname=gensub("{\\\\\"([a-zA-Z])}","\\1e","g", lastname); # test for {\"umlauts}
lastname=gensub("\\\\\"{([a-zA-Z])}","\\1e","g", lastname); # test for \"{umlauts}
lastname=gensub("\\\\\"([a-zA-Z])","\\1e","g", lastname); # test for umlauts
lastname=gensub("{\\\\ss}","ss","g", lastname); # test for eszett
lastname=gensub("\\\\l","l","g", lastname); # test for \l
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
lastname=gensub("'\''","","g", lastname); # Remove apostroph
lastname=gensub("},$","","g", lastname); # Remove closing }
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;
print "";
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 {
authors_active=0;
if($1 == "YEAR"){
year=substr($0,match($0,"[[0-9]]*"),4)
}
};
# Extract DOI from URL if no DOI was previously found
if( $1 == "DOI" ) {
have_read_doi=1;
};
if ($1 == "URL") {
if ( (have_read_doi == 0) && match($3, "https://doi.org/") ) {
gsub("URL", "DOI");
gsub("https://doi.org/", "");
}
else {
next
};
};
}
/^[^=]*$/{
if(authors_active){
authors=authors $0;
}
}
//{
body=body $0 "\n";
next;
}'
# mathscinet.pl "$@" | awk "$PROG1" | gawk "$PROG2" | awk '!seen[$0]++'
mathscinet.pl "$@" | awk "$PROG1" | gawk "$PROG2"
# add a newline
echo