📄 00000003.htm
字号:
<HTML><HEAD> <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>发信人: energy (长白山), 信区: Linux <BR>标 题: CJK+Hyperref中文目录的处理程序 <BR>发信站: BBS 水木清华站 (Wed Dec 1 01:11:17 1999) <BR> <BR>该程序用于把pdflatex生成的*.out文件进行处理, 从*.aux文件中读取目录文本, <BR>写入*.out文件中, 并在头一行加上\let\WriteBookMarks\relax <BR>处理之后生成中间文件*.tmp, 程序里用system的笨办法复制为*.out. <BR>命令行参数为要处理的文件名, 注意别加扩展名. <BR>下面是源代码, 请eggs等大虾试试. <BR> <BR>aux2out.c <BR> <BR>#include <stdio.h> <BR>#include <string.h> <BR>#include <process.h> <BR> <BR>void errmsg() <BR>{ printf("File format not recognized\n"); <BR>} <BR> <BR>int main(int argc, char *argv[]) <BR>{ <BR> FILE *f_aux=0, *f_out=0, *f_tmp=0; <BR> <BR> char aux_fname[256]; <BR> char out_fname[256]; <BR> char tmp_fname[256]; <BR> char line[256], toc[256], buf[256]; <BR> char *str1,*str2; <BR> <BR> int n; <BR> <BR> if (argc!=2) <BR> { printf("Usage:\n\t aux2out file \nNo file extention needed.\n"); <BR> return 0; <BR> } <BR> <BR> strcpy(aux_fname,argv[1]); strcat(aux_fname,".aux"); <BR> strcpy(out_fname,argv[1]); strcat(out_fname,".out"); <BR> strcpy(tmp_fname,argv[1]); strcat(tmp_fname,".tmp"); <BR> <BR> f_aux = fopen( aux_fname, "rt" ); <BR> if (f_aux == NULL) <BR> { printf("File %s not found\n",aux_fname); <BR> return 0; <BR> } <BR> <BR> f_out = fopen( out_fname, "rt" ); <BR> if (f_aux == NULL) <BR> { printf("File %s not found\n",out_fname); <BR> return 0; <BR> } <BR> <BR> f_tmp = fopen( tmp_fname, "wt" ); <BR> if (f_aux == NULL) <BR> { printf("File %s can't create\n",tmp_fname); <BR> return 0; <BR> } <BR> fputs("\\let\\WriteBookMarks\\relax\n",f_tmp); <BR> <BR>loop: <BR> /*read a line from AUX file*/ <BR> str1 = fgets( line, 256, f_aux); <BR> if (str1==NULL) goto over; <BR> <BR> /*find a toc line*/ <BR> if (strstr(line,"\\@writefile{toc}{\\contentsline")==NULL) goto loop; <BR> <BR> /*find the start of toc: the 3rd '}' */ <BR> for (n=0;n<3;n++) <BR> { str1 = strstr(str1,"}"); str1++; <BR> if (str1==NULL){ errmsg(); return 0; } <BR> } <BR> <BR> /*find the end of toc: the next '}'*/ <BR> str2 = strstr(str1,"}"); <BR> if (str2==NULL) { errmsg(); return 0; } <BR> <BR> /*get the toc string into str1, and save it*/ <BR> *str2=0; strcpy(toc, str1); <BR> <BR> /*read line from the OUT file*/ <BR>loop2: <BR> str1 = fgets( line, 256, f_out); <BR> if (str1==NULL) goto over; <BR> <BR> /*find a toc line*/ <BR> if (strstr(line,"\\BOOKMARK")==NULL) goto loop2; <BR> <BR> /*find the start of toc: the first '}' */ <BR> str1 = strstr(str1,"}"); <BR> if (str1==NULL){ errmsg(); return 0; } <BR> str1+=2; <BR> <BR> /*find the rest of the toc. {} may not be empty*/ <BR> str2 = strstr(str1,"}"); <BR> if (str2==NULL){ errmsg(); return 0; } <BR> <BR> /*save the rest of line*/ <BR> strcpy(buf, str2); <BR> <BR> /*insert toc*/ <BR> strcpy(str1, toc); <BR> <BR> /*add the rest of line*/ <BR> strcat(line,buf); <BR> <BR> /*write to TMP file*/ <BR> fputs(line,f_tmp); <BR> <BR> goto loop; <BR> <BR>over: <BR> fclose(f_aux); fclose(f_out); fclose(f_tmp); <BR> <BR>/*The follows is to rename TMP to OUT, and delete TMP*/ <BR>/*May not work on Unix/Linux, modify if needed*/ <BR> sprintf(line,"copy %s %s", tmp_fname, out_fname); <BR> system(line); <BR> <BR> sprintf(line,"del %s", tmp_fname); <BR> system(line); <BR> <BR> return 1; <BR>} <BR> <BR> <BR>-- <BR>※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: 202.192.242.206] <BR><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -