version 1.3, 1999/12/13 07:55:23 |
version 1.4, 1999/12/13 14:47:41 |
|
|
\maketitle |
\maketitle |
\section{$BA0=q$-(B} |
\section{$BA0=q$-(B} |
*/ |
*/ |
/* $OpenXM: OpenXM/src/kxx/oxweave.c,v 1.2 1999/11/16 11:48:12 takayama Exp $ */ |
/* $OpenXM: OpenXM/src/kxx/oxweave.c,v 1.3 1999/12/13 07:55:23 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
|
|
/* Modify here to change the begin tag and EndComment. Less than 9 characters. |
/* Modify here to change the begin tag and EndComment. Less than 9 characters. |
Line 19 char *EndComment1="\n"; |
|
Line 19 char *EndComment1="\n"; |
|
#define BSIZE 256 |
#define BSIZE 256 |
#define VSIZE 256 |
#define VSIZE 256 |
static int Debug = 0; |
static int Debug = 0; |
|
static int Plain = 0; |
/*&jp \noindent |
/*&jp \noindent |
{\tt Buf} $B$OI8=`=PNO$h$j$N%G!<%?$r0l;~3JG<$7$F$*$/NN0h(B. |
{\tt Buf} $B$OI8=`=PNO$h$j$N%G!<%?$r0l;~3JG<$7$F$*$/NN0h(B. |
{\tt Head} $B$,:G=i$NJ8;z$r$5$7(B, {\tt Tail} $B$O:G8e$NJ8;z$r$5$9(B. |
{\tt Head} $B$,:G=i$NJ8;z$r$5$7(B, {\tt Tail} $B$O:G8e$NJ8;z$r$5$9(B. |
|
|
int Tail = 0; |
int Tail = 0; |
char *Tag = NULL; |
char *Tag = NULL; |
/*&jp \noindent {\tt OutputNoTaggedSegment = 1} |
/*&jp \noindent {\tt OutputNoTaggedSegment = 1} |
$B$J$i(B $B%3%a%s%H5-9f$N30$O(B verbatim $B$rMQ$$$F=PNO(B. |
$B$J$i(B $B%3%a%s%H5-9f$N30$O(B verbatim $B$rMQ$$$F=PNO(B. |
{\tt --source} $B%*%W%7%g%s$G$3$NJQ?t$r(B1$B$K$G$-$k(B. |
{\tt --source} $B%*%W%7%g%s$G$3$NJQ?t$r(B1$B$K$G$-$k(B. |
*/ |
*/ |
int OutputNoTaggedSegment = 0; |
int OutputNoTaggedSegment = 0; |
/*&jp \noindent 1 $B$J$i%?%0$N$D$$$?>l=j$r=PNOCf(B. */ |
/*&jp \noindent 1 $B$J$i%?%0$N$D$$$?>l=j$r=PNOCf(B. */ |
int OutputtingTaggedSegment = 0; |
int OutputtingTaggedSegment = 0; |
Line 44 main(int argc,char *argv[]) { |
|
Line 45 main(int argc,char *argv[]) { |
|
extern char *BeginTag; |
extern char *BeginTag; |
extern char *EndComment0; |
extern char *EndComment0; |
extern char *EndComment1; |
extern char *EndComment1; |
|
extern int Plain; |
int c; |
int c; |
int tagc,i; |
int tagc,i; |
char *tagv[VSIZE]; |
char *tagv[VSIZE]; |
Line 52 main(int argc,char *argv[]) { |
|
Line 54 main(int argc,char *argv[]) { |
|
int pos; |
int pos; |
Head = Tail = 0; Buf[0] = ' '; /* initialize */ |
Head = Tail = 0; Buf[0] = ' '; /* initialize */ |
|
|
/*&jp {\tt tagv[]} $B$K%?%0$N$"$D$^$j$r$$$l$k(B. */ |
/*&jp {\tt tagv[]} $B$K%?%0$N$"$D$^$j$r$$$l$k(B. |
|
{\tt tagv2[]} $B$KBP1~$9$k%?%0$N$*$o$j$N5-9f$r$$$l$k(B. |
|
*/ |
tagc = tagc2 = 0; |
tagc = tagc2 = 0; |
if (argc <= 1 || argc >= VSIZE) { |
if (argc <= 1 || argc >= VSIZE) { |
usage(); |
usage(); |
Line 60 main(int argc,char *argv[]) { |
|
Line 64 main(int argc,char *argv[]) { |
|
}else{ |
}else{ |
for (i=1; i< argc ; i++) { |
for (i=1; i< argc ; i++) { |
if (strcmp(argv[i],"--source") == 0) { |
if (strcmp(argv[i],"--source") == 0) { |
OutputNoTaggedSegment = 1; |
OutputNoTaggedSegment = 1; |
|
}else if (strcmp(argv[i],"--plain") == 0) { |
|
Plain = 1; OutputNoTaggedSegment = 1; |
} else{ |
} else{ |
tagv[tagc] = (char *) malloc(sizeof(char)*(strlen(argv[i])+10)); |
tagv[tagc] = (char *) malloc(sizeof(char)*(strlen(argv[i])+10)); |
tagv2[tagc2] = (char *) malloc(sizeof(char)*10); |
tagv2[tagc2] = (char *) malloc(sizeof(char)*10); |
strcpy(tagv[tagc],BeginTag0); |
strcpy(tagv[tagc],BeginTag0); |
strcat(tagv[tagc],argv[i]); |
strcat(tagv[tagc],argv[i]); |
tagv2[tagc] = EndComment0; |
tagv2[tagc] = EndComment0; |
/* $B%3%a%s%H$N$*$o$j$N5-9f(B. sm1 $B$J$i(B 0xa $B$G$"$k(B. */ |
/* $B%3%a%s%H$N$*$o$j$N5-9f(B. */ |
tagc2++; |
tagc2++; |
tagc++; |
tagc++; |
|
|
tagv[tagc] = (char *) malloc(sizeof(char)*(strlen(argv[i])+10)); |
tagv[tagc] = (char *) malloc(sizeof(char)*(strlen(argv[i])+10)); |
tagv2[tagc2] = (char *) malloc(sizeof(char)*10); |
tagv2[tagc2] = (char *) malloc(sizeof(char)*10); |
strcpy(tagv[tagc],BeginTag1); |
strcpy(tagv[tagc],BeginTag1); |
strcat(tagv[tagc],argv[i]); |
strcat(tagv[tagc],argv[i]); |
tagv2[tagc] = EndComment1; |
tagv2[tagc] = EndComment1; |
tagc2++; |
tagc2++; |
tagc++; |
tagc++; |
} |
} |
} |
} |
} |
} |
/*&jp $B%W%m%0%i%`$O#3$D$N>uBV$r;}$D(B. $B>uBV(B 0 $B$O%?%0IU$-%3%a%s%H5-9f$N30(B. |
/*&jp $B%W%m%0%i%`$O#3$D$N>uBV$r;}$D(B. $B>uBV(B 0 $B$O%?%0IU$-%3%a%s%H5-9f$N30(B. |
$B>uBV(B 1 $B$O;XDj$5$l$?%?%0$NIU$$$?%3%a%s%H$NCf(B. |
$B>uBV(B 1 $B$O;XDj$5$l$?%?%0$NIU$$$?%3%a%s%H$NCf(B. |
$B>uBV(B 2 $B$O;XDj$5$l$F$$$J$$%?%0$NIU$$$?%3%a%s%H$NCf(B |
$B>uBV(B 2 $B$O;XDj$5$l$F$$$J$$%?%0$NIU$$$?%3%a%s%H$NCf(B |
($B>uBV#2$K$"$k$H$-$O0u:~$5$l$J$$(B.) */ |
($B>uBV#2$K$"$k$H$-$O0u:~$5$l$J$$(B.) */ |
/* |
/* |
state 0 -- / * & jp ---> state 1 |
state 0 -- / * & jp ---> state 1 |
if ( BeginVerbatim & OutputNoTaggedSegment ) end-verbatim |
if ( BeginVerbatim & OutputNoTaggedSegment ) end-verbatim |
<--- * / --- state 1 |
<--- * / --- state 1 |
if ( OutputNoTaggedSegment ) begin-verbatim |
if ( OutputNoTaggedSegment ) begin-verbatim |
|
|
state 0 -- / * & unknown ---> state 2 |
state 0 -- / * & unknown ---> state 2 |
<--- * / --- state 2 |
<--- * / --- state 2 |
|
|
state 0 & OutputNoTaggedSegment ==> putchar() |
state 0 & OutputNoTaggedSegment ==> putchar() |
state 1 ==> putchar() |
state 1 ==> putchar() |
state 2 ==> skip |
state 2 ==> skip |
*/ |
*/ |
while (notEOF()) { |
while (notEOF()) { |
/* We are in the state 0. */ |
/* We are in the state 0. */ |
pos = findNextTag(tagc,tagv,tagc2,tagv2); |
pos = findNextTag(tagc,tagv,tagc2,tagv2); |
|
/* printf(" ===pos=%d=== ",pos); */ |
/* We are in the state 1. */ |
/* We are in the state 1. */ |
findEndTag(tagc2,tagv2,pos); |
findEndTag(tagc2,tagv2,pos); |
} |
} |
if (BeginVerbatim) { |
if (BeginVerbatim) { |
printf("\n\\end{verbatim\x07d}\n"); |
if (!Plain) printf("\n\\end{verbatim\x07d}\n"); |
} |
} |
exit(0); |
exit(0); |
} |
} |
|
|
/*&jp \noindent $B<!$N4X?t$OMxMQK!$rI=<($9$k(B. */ |
/*&jp \noindent $B<!$N4X?t$OMxMQK!$rI=<($9$k(B. */ |
usage() { |
usage() { |
fprintf(stderr,"oxweave [--source] [key1 key2 ...]\n"); |
fprintf(stderr,"oxweave [--plain] [--source] [key1 key2 ...]\n"); |
fprintf(stderr,"Example 1: oxweave --source jp <oxweave.c >t.tex\n"); |
fprintf(stderr,"Example 1: oxweave --source jp <oxweave.c >t.tex\n"); |
fprintf(stderr,"Example 2: oxweave jp <oxweave.c >t.tex\n"); |
fprintf(stderr,"Example 2: oxweave jp <oxweave.c >t.tex\n"); |
|
fprintf(stderr,"Example 2: oxweave --plain <oxweave.c >t.tex\n"); |
} |
} |
|
|
#define inc(a) ((a+1) % BSIZE) |
#define inc(a) ((a+1) % BSIZE) |
Line 172 findNextTag(int tagc, char *tagv[],int tagc2,char *tag |
|
Line 180 findNextTag(int tagc, char *tagv[],int tagc2,char *tag |
|
for (i=0; i<tagc; i++) { |
for (i=0; i<tagc; i++) { |
/* fprintf(stderr,"\nChecking %s : ",tagv[i]); */ |
/* fprintf(stderr,"\nChecking %s : ",tagv[i]); */ |
if (wcmp(tagv[i]) == 0) { |
if (wcmp(tagv[i]) == 0) { |
/* fprintf(stderr," : matched."); */ |
/* fprintf(stderr," : matched."); */ |
wgetc(strlen(tagv[i])); |
wgetc(strlen(tagv[i])); |
if (OutputNoTaggedSegment == 1 && BeginVerbatim == 1) { |
if (OutputNoTaggedSegment == 1 && BeginVerbatim == 1) { |
BeginVerbatim = 0; |
BeginVerbatim = 0; |
printf("\\end{verbatim\x07d}\n"); |
if (!Plain) printf("\\end{verbatim\x07d}\n"); |
} |
} |
OutputtingTaggedSegment = 1; |
OutputtingTaggedSegment = 1; |
return(i); /* Now, state is 1. */ |
return(i); /* Now, state is 1. */ |
} |
} |
} |
} |
/*&jp {\tt /\*\&} $B$@$1$I$I$N%?%0$K$b0lCW$7$J$$(B */ |
/*&jp {\tt /\*\&} $B$@$1$I$I$N%?%0$K$b0lCW$7$J$$(B */ |
Line 201 findNextTag(int tagc, char *tagv[],int tagc2,char *tag |
|
Line 209 findNextTag(int tagc, char *tagv[],int tagc2,char *tag |
|
/* We are in the state 0 */ |
/* We are in the state 0 */ |
c = wgetc(1); |
c = wgetc(1); |
if (OutputNoTaggedSegment) { |
if (OutputNoTaggedSegment) { |
putchar(c); |
if (c != EOF) putchar(c); |
} |
} |
}while( c!= EOF); |
}while( c!= EOF); |
if (BeginVerbatim == 1) { |
if (BeginVerbatim == 1) { |
printf("\n\\quad\n\\end{verbatim\x07d}\n"); |
if (!Plain) printf("\n\\quad\n\\end{verbatim\x07d}\n"); |
} |
} |
exit(0); |
exit(0); |
} |
} |
Line 221 findEndTag(int tagc,char *tagv[],int rule) { |
|
Line 229 findEndTag(int tagc,char *tagv[],int rule) { |
|
i = rule; |
i = rule; |
if (wcmp(tagv[i]) == 0) { |
if (wcmp(tagv[i]) == 0) { |
wgetc(strlen(tagv[i])); |
wgetc(strlen(tagv[i])); |
|
if (strcmp(tagv[i],"\n")==0) putchar('\n'); |
OutputtingTaggedSegment = 0; |
OutputtingTaggedSegment = 0; |
if (OutputNoTaggedSegment) { |
if (OutputNoTaggedSegment) { |
printf("\n{\\footnotesize \\begin{verbatim}\n"); |
if (!Plain) printf("\n{\\footnotesize \\begin{verbatim}\n"); |
BeginVerbatim = 1; |
BeginVerbatim = 1; |
} |
} |
return; /* Our state is 0. */ |
return; /* Our state is 0. */ |
} |
} |
Line 245 skipToEndTag(int tagc,char *tagv[],int rule) { |
|
Line 254 skipToEndTag(int tagc,char *tagv[],int rule) { |
|
do { |
do { |
if (rule == 0) { |
if (rule == 0) { |
if (wcmp(EndComment0) == 0) { |
if (wcmp(EndComment0) == 0) { |
wgetc(strlen(EndComment0)); |
wgetc(strlen(EndComment0)); |
return; /* our state is 0. */ |
return; /* our state is 0. */ |
} |
} |
}else if (rule == 1) { |
}else if (rule == 1) { |
if (wcmp(EndComment1) == 0) { |
if (wcmp(EndComment1) == 0) { |
wgetc(strlen(EndComment1)); |
wgetc(strlen(EndComment1)); |
return; /* our state is 0. */ |
return; /* our state is 0. */ |
} |
} |
}else{ |
}else{ |
for (i=0; i<tagc; i++) { |
for (i=0; i<tagc; i++) { |
if (wcmp(tagv[i]) == 0) { |
if (wcmp(tagv[i]) == 0) { |
wgetc(strlen(tagv[i])); |
wgetc(strlen(tagv[i])); |
return; /* our state is 0. */ |
return; /* our state is 0. */ |
} |
} |
} |
} |
|
|
} |
} |
Line 275 skipToEndTag_old(int tagc,char *tagv[]) { |
|
Line 284 skipToEndTag_old(int tagc,char *tagv[]) { |
|
do { |
do { |
for (i=0; i<tagc; i++) { |
for (i=0; i<tagc; i++) { |
if (wcmp(tagv[i]) == 0) { |
if (wcmp(tagv[i]) == 0) { |
wgetc(strlen(tagv[i])); |
wgetc(strlen(tagv[i])); |
return; /* our state is 0. */ |
return; /* our state is 0. */ |
} |
} |
} |
} |
/* our state is 2. */ |
/* our state is 2. */ |
Line 293 skipToEndTag_old(int tagc,char *tagv[]) { |
|
Line 302 skipToEndTag_old(int tagc,char *tagv[]) { |
|
$B$"$H$N%P%$%H$,(B 0x20 $B0J2<$G$J$$$,(B, $B$=$NB>$N%P%$%H$,0lCW$9$k$H$-$O(B |
$B$"$H$N%P%$%H$,(B 0x20 $B0J2<$G$J$$$,(B, $B$=$NB>$N%P%$%H$,0lCW$9$k$H$-$O(B |
1 $B$rLa$9(B. |
1 $B$rLa$9(B. |
$B0J>eFs$D$N>l9g$K9gCW$7$J$$>l9g$O(B -1 $B$rLa$9(B. |
$B0J>eFs$D$N>l9g$K9gCW$7$J$$>l9g$O(B -1 $B$rLa$9(B. |
|
{\tt s} $B$,(B 0xa,0 $B$N$H$-$O(B, Buf[Head] $B$,(B 0xa $B$J$i(B, 0 $B$rLa$9(B. |
|
$B$=$&$G$J$$$J$i(B, -1 $B$rLa$9(B. |
*/ |
*/ |
wcmp(char *s) { |
wcmp(char *s) { |
int n; |
int n; |
int i,j; |
int i,j; |
wread(); |
wread(); |
if (Debug == 2) fprintf(stderr,"[Checking %s]\n",s); |
if (Debug == 2) fprintf(stderr,"[Checking %s]\n",s); |
|
if (strcmp(s,"\n") == 0) { |
|
if (s[0] == Buf[Head]) return(0); |
|
else return(-1); |
|
} |
n = strlen(s); |
n = strlen(s); |
j = Head; |
j = Head; |
for (i=0; i<n; i++) { |
for (i=0; i<n; i++) { |
|
|
|
|
irregularExit() { |
irregularExit() { |
if (BeginVerbatim == 1) { |
if (BeginVerbatim == 1) { |
printf("\\end{verbatim\x07d}\n"); |
if (!Plain) printf("\\end{verbatim\x07d}\n"); |
} |
} |
exit(-1); |
exit(-1); |
} |
} |