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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define HEXA_STRING "0123456789abcdef"
#ifdef WIN32
#include <io.h>
#include <ctype.h>
#define MKSTEMP mktemp
#else
#define MKSTEMP mkstemp
#endif
int to_8bit(char *);
main(int argc, char *argv[])
{
int i;
char args[128], cmd[128];
#ifdef WIN32
strcpy(args, "");
#else
bzero(args, 128);
#endif
for(i=1; i<argc; i++) {
strcat(args, " ");
strcat(args, argv[i]);
}
to_8bit(argv[argc-1]);
sprintf(cmd, "bibtex %s", args);
system(cmd);
exit(0);
}
int to_8bit(char *bib) {
FILE *in, *out;
int x;
char line[1024], *l, *h1, *h2, tempfile[10];
l=strrchr(bib, '.');
if(l==NULL || strcmp(l, ".aux")!=0) {
strcat(bib, ".aux");
}
in = fopen(bib, "r");
if(!in) {
printf("\tError opening auxiliary file \"%s\"!!!\n", bib);
exit(1);
}
strcpy(tempfile, "BIBXXXXXX");
MKSTEMP(tempfile);
out = fopen(tempfile, "w");
if(!out) {
printf("\tError opening temporary file \"%s\"!!!\n", tempfile);
exit(1);
}
while(fgets(line, 1024, in)) {
l=line;
while(*l) {
if(*l=='^'&&*(l+1)=='^'
&&(h1=strchr(HEXA_STRING, *(l+2)))
&&(h2=strchr(HEXA_STRING, *(l+3)))) {
if(*h1>'9') x=*h1-87;
else x=*h1-48;
x*=16;
if(*h2>'9') x+=*h2-87;
else x+=*h2-48;
fputc(x, out);
l+=4;
}
else {
fputc(*l++, out);
}
}
}
fflush(NULL);
fclose(in);
fclose(out);
rename(tempfile, bib);
return(1);
}
|