version 1.1, 1999/11/16 07:57:37 |
version 1.8, 2003/08/22 16:08:23 |
|
|
|
/*&eg |
|
\documentclass{article} |
|
\title{On oxweave.c} |
|
\author{} \date{} |
|
\begin{document} |
|
\maketitle |
|
\section{Introduction} |
|
*/ |
/*&jp |
/*&jp |
\documentclass{jarticle} |
\documentclass{jarticle} |
\title{oxweave $B$N%=!<%9%3!<%I$K$D$$$F$N2r@b(B} |
\title{oxweave $B$N%=!<%9%3!<%I$K$D$$$F$N2r@b(B} |
|
|
\maketitle |
\maketitle |
\section{$BA0=q$-(B} |
\section{$BA0=q$-(B} |
*/ |
*/ |
/* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/kxx/oxweave.c,v 1.7 2001/05/06 07:53:01 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
#define BSIZE 10 |
|
#define VSIZE 10 |
/* Modify here to change the begin tag and EndComment. Less than 9 characters. |
|
*/ |
|
char *BeginTag0="/*\x026"; /* 0x26 = & */ |
|
char *BeginTag1="//\x026"; /* 0x26 = & */ |
|
char *EndComment0="*/"; |
|
char *EndComment1="\n"; |
|
|
|
#define BSIZE 256 |
|
#define VSIZE 256 |
static int Debug = 0; |
static int Debug = 0; |
|
static int Debug2 = 0; |
|
static int Plain = 0; |
/*&jp \noindent |
/*&jp \noindent |
|
$B:F5"(B option $B$r(B on $B$K$7$?>l9g(B ({\tt Recursive = 1}, |
|
{\tt LevelState1} $B$G(B, $B0u:~$9$Y$-(B comment $B$N%M%9%H$N%l%Y%k$rI=$9(B. |
|
{\tt LevelState2} $B$G(B, $B:o=|$9$Y$-(B comment $B$N%M%9%H$N%l%Y%k$rI=$9(B. |
|
*/ |
|
static int Recursive = 0; |
|
static int LevelState1 = 0; |
|
static int LevelState2 = 0; |
|
/*&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. |
{\tt Buf} $B$r%j%s%0>u$K;HMQ$9$k$N$G(B, $B%j%s%0%P%C%U%!$H$h$V(B |
{\tt Buf} $B$r%j%s%0>u$K;HMQ$9$k$N$G(B, $B%j%s%0%P%C%U%!$H$h$V(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. |
*/ |
{\tt --plain} $B$G$O(B, verbatim $B$rMxMQ$;$:$K@8$G=PNO(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; |
int BeginVerbatim = 0; |
int BeginVerbatim = 0; |
|
|
|
|
/*&jp \section{$B%W%m%0%i%`K\BN(B} */ |
/*&jp \section{$B%W%m%0%i%`K\BN(B} */ |
main(int argc,char *argv[]) { |
main(int argc,char *argv[]) { |
|
extern char *BeginTag; |
|
extern char *EndComment0; |
|
extern char *EndComment1; |
|
extern int Plain; |
int c; |
int c; |
int tagc,i; |
int tagc,i; |
char *tagv[VSIZE]; |
char *tagv[VSIZE]; |
int tagc2; |
int tagc2; |
char *tagv2[VSIZE]; |
char *tagv2[VSIZE]; |
char *s = "/*\x026"; /* 0x26 = & */ |
int pos; |
Head = Tail = 0; Buf[0] = ' '; /* initialize */ |
Head = Tail = 0; Buf[0] = ' '; /* initialize */ |
|
|
/* $B%3%a%s%H$N$*$o$j$N5-9f(B. sm1 $B$J$i(B 0xa $B$G$"$k(B. */ |
/*&jp {\tt tagv[]} $B$K%?%0$N$"$D$^$j$r$$$l$k(B. |
tagc2 = 1; tagv2[0] = "*/"; |
{\tt tagv2[]} $B$KBP1~$9$k%?%0$N$*$o$j$N5-9f$r$$$l$k(B. |
/*&jp {\tt tagv[]} $B$K%?%0$N$"$D$^$j$r$$$l$k(B. */ |
*/ |
tagc = 0; |
tagc = tagc2 = 0; |
if (argc <= 1 || argc >= VSIZE) { |
if (argc <= 1 || argc >= VSIZE) { |
usage(); |
usage(); |
exit(); |
exit(0); |
}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{ |
}else if (strcmp(argv[i],"--plain") == 0) { |
tagv[tagc] = (char *) malloc(sizeof(char)*(strlen(argv[i])+4)); |
Plain = 1; OutputNoTaggedSegment = 1; |
strcpy(tagv[tagc],s); |
}else if (strcmp(argv[i],"--recursive") == 0) { |
strcat(tagv[tagc],argv[i]); |
Recursive = 1; |
tagc++; |
}else if (strcmp(argv[i],"--debug") == 0) { |
|
Debug2 = 1; |
|
} else{ |
|
if (strcmp(argv[i]," ") == 0) { |
|
argv[i] = ""; |
|
} |
|
tagv[tagc] = (char *) malloc(sizeof(char)*(strlen(argv[i])+10)); |
|
tagv2[tagc2] = (char *) malloc(sizeof(char)*10); |
|
strcpy(tagv[tagc],BeginTag0); |
|
strcat(tagv[tagc],argv[i]); |
|
tagv2[tagc] = EndComment0; |
|
/* $B%3%a%s%H$N$*$o$j$N5-9f(B. */ |
|
tagc2++; |
|
tagc++; |
|
|
|
tagv[tagc] = (char *) malloc(sizeof(char)*(strlen(argv[i])+10)); |
|
tagv2[tagc2] = (char *) malloc(sizeof(char)*10); |
|
strcpy(tagv[tagc],BeginTag1); |
|
strcat(tagv[tagc],argv[i]); |
|
tagv2[tagc] = EndComment1; |
|
tagc2++; |
|
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. */ |
findNextTag(tagc,tagv,tagc2,tagv2); |
pos = findNextTag(tagc,tagv,tagc2,tagv2); |
/* We are int the state 1 */ |
/* printf(" ===pos=%d=== ",pos); */ |
findEndTag(tagc2,tagv2); |
/* We are in the state 1. */ |
|
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"); |
#include "oxweaveUsage.h" |
fprintf(stderr,"Example 1: oxweave --source jp <oxweave.c >t.tex\n"); |
|
fprintf(stderr,"Example 2: oxweave jp <oxweave.c >t.tex\n"); |
|
} |
} |
|
|
#define inc(a) ((a+1) % BSIZE) |
#define inc(a) ((a+1) % BSIZE) |
/*&jp \noindent {\tt wread()} $B$O(B $BI8=`F~NO$h$j$N%G!<%?$rFI$a$k$@$1(B |
/*&jp \noindent {\tt wread()} $B$O(B $BI8=`F~NO$h$j$N%G!<%?$rFI$a$k$@$1(B |
$B%j%s%0%P%C%U%!(B {\tt Buf] $B$XFI$_9~$`(B.*/ |
$B%j%s%0%P%C%U%!(B {\tt Buf} $B$XFI$_9~$`(B.*/ |
wread() { |
wread() { |
int c,i; |
int c,i; |
static int eof = 0; |
static int eof = 0; |
Line 135 int wgetc(int p) { |
|
Line 187 int wgetc(int p) { |
|
return(c); |
return(c); |
} |
} |
|
|
/*&jp \noindent {\tt findNextTag()} $B$O<!$N(B {\tt /\*\&} $B$J$k%?%0$r$5$,$9(B. |
/*&jp \noindent {\tt findNextTag()} $B$O<!$N(B {\tt / *\&} $B$J$k%?%0$r$5$,$9(B. |
|
( $B$3$l$O(B, {\tt BeginTag0} $B$NCM$rJQ$($k$HJQ99$G$-$k(B.) |
{\tt OutputNoTaggedSegment} $B$,(B 1 $B$J$i%G!<%?$r$=$N$^$^$J$,$9(B. |
{\tt OutputNoTaggedSegment} $B$,(B 1 $B$J$i%G!<%?$r$=$N$^$^$J$,$9(B. |
$BL5;k$9$Y$-%?%0$N$H$-$O(B, $B%?%0FbIt$r%9%-%C%W$7$?$N$A(B |
$BL5;k$9$Y$-%?%0$N$H$-$O(B, $B%?%0FbIt$r%9%-%C%W$7$?$N$A(B |
{\tt findNextTag} $B$r:F5"E*$K8F$V(B. |
{\tt findNextTag} $B$r:F5"E*$K8F$V(B. |
Line 143 int wgetc(int p) { |
|
Line 196 int wgetc(int p) { |
|
findNextTag(int tagc, char *tagv[],int tagc2,char *tagv2[]) { |
findNextTag(int tagc, char *tagv[],int tagc2,char *tagv2[]) { |
int i; |
int i; |
int c,d; |
int c,d; |
|
extern char *BeginTag0; |
|
extern char *BeginTag1; |
do { |
do { |
for (i=0; i<tagc; i++) { |
for (i=0; i<tagc; i++) { |
|
/* fprintf(stderr,"\nChecking %s : ",tagv[i]); */ |
if (wcmp(tagv[i]) == 0) { |
if (wcmp(tagv[i]) == 0) { |
wgetc(strlen(tagv[i])); |
LevelState1++; |
if (OutputNoTaggedSegment == 1 && BeginVerbatim == 1) { |
/* fprintf(stderr," : matched."); */ |
BeginVerbatim = 0; |
wgetc(strlen(tagv[i])+1); |
printf("\\end{verbatim\x07d}\n"); |
if (OutputNoTaggedSegment == 1 && BeginVerbatim == 1) { |
} |
BeginVerbatim = 0; |
OutputtingTaggedSegment = 1; |
if (!Plain) printf("\\end{verbatim\x07d}\n"); |
return; /* Now, state is 1. */ |
} |
|
OutputtingTaggedSegment = 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 */ |
if (wcmp("/*\x026") == 1) { |
if (wcmp(BeginTag0) == 1) { |
wgetc(3); |
LevelState2++; |
|
wgetc(strlen(BeginTag0)); |
while ((d=wgetc(1)) > ' ') ; |
while ((d=wgetc(1)) > ' ') ; |
/* We are in the state 2. */ |
/* We are in the state 2. */ |
skipToEndTag(tagc2,tagv2); |
skipToEndTag(tagc2,tagv2,0); |
/* We are in the state 0. */ |
/* We are in the state 0. */ |
findNextTag(tagc,tagv,tagc2,tagv2); |
return(findNextTag(tagc,tagv,tagc2,tagv2)); |
return; |
}else if (wcmp(BeginTag1) == 1) { |
|
LevelState2++; |
|
wgetc(strlen(BeginTag1)); |
|
while ((d=wgetc(1)) > ' ') ; |
|
/* We are in the state 2. */ |
|
skipToEndTag(tagc2,tagv2,1); |
|
/* We are in the state 0. */ |
|
return(findNextTag(tagc,tagv,tagc2,tagv2)); |
} |
} |
/* 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); |
} |
} |
|
|
/*&jp \noindent {\tt findEndTag()} $B$O<!$N(B {\tt \*\/} $B$J$k%?%0$r$5$,$9(B. |
/*&jp \noindent {\tt findEndTag()} $B$O<!$N(B {\tt * /} $B$J$k%?%0$r$5$,$9(B. |
|
( $B$3$l$O(B, EndComment0 $B$NCM$rJQ$($k$HJQ992DG=(B. ) |
|
{\tt / /} $B$G;O$^$k>l9g$O(B, 0xa $B$,$*$o$j(B. |
*/ |
*/ |
findEndTag(int tagc,char *tagv[]) { |
findEndTag(int tagc,char *tagv[],int rule) { |
int i; |
int i; |
int c; |
int c; |
/* We are in the state 1. */ |
/* We are in the state 1. */ |
do { |
do { |
for (i=0; i<tagc; i++) { |
i = rule; |
if (wcmp(tagv[i]) == 0) { |
if (wcmp(tagv[i]) == 0) { |
wgetc(strlen(tagv[i])); |
LevelState1--; |
OutputtingTaggedSegment = 0; |
if (Debug2) printf("[LevelState1=%d by end of comment in the state 1.]\n",LevelState1); |
if (OutputNoTaggedSegment) { |
if (LevelState1 > 0 && Recursive) { |
printf("\n{\\footnotesize \\begin{verbatim}\n"); |
wgetc(strlen(tagv[i])); |
BeginVerbatim = 1; |
printf("%s",tagv[i]); |
} |
return(findEndTag(tagc,tagv,rule)); |
return; /* Our state is 0. */ |
}else{ |
|
wgetc(strlen(tagv[i])); |
|
if (strcmp(tagv[i],"\n")==0) putchar('\n'); |
|
OutputtingTaggedSegment = 0; |
|
if (OutputNoTaggedSegment) { |
|
if (!Plain) printf("\n{\\footnotesize \\begin{verbatim}\n"); |
|
BeginVerbatim = 1; |
|
} |
|
return; /* Our state is 0. */ |
} |
} |
} |
} |
/* Our state is 1. */ |
/* Our state is 1. */ |
|
if (wcmp("/*") >= 0 ) { |
|
LevelState1++; |
|
if (Debug2) printf("[LevelState1++=%d by / * in state 1.]\n",LevelState1); |
|
} |
c = wgetc(1); |
c = wgetc(1); |
putchar(c); |
putchar(c); |
}while( c!= EOF); |
}while( c!= EOF); |
Line 203 findEndTag(int tagc,char *tagv[]) { |
|
Line 283 findEndTag(int tagc,char *tagv[]) { |
|
irregularExit(); |
irregularExit(); |
} |
} |
|
|
skipToEndTag(int tagc,char *tagv[]) { |
skipToEndTag(int tagc,char *tagv[],int rule) { |
int i; |
int i; |
int c; |
int c; |
|
extern char *EndComment0; |
|
extern char *EndComment1; |
/* our state is 2. */ |
/* our state is 2. */ |
do { |
do { |
for (i=0; i<tagc; i++) { |
if (rule == 0) { |
if (wcmp(tagv[i]) == 0) { |
if (wcmp(EndComment0) == 0) { |
wgetc(strlen(tagv[i])); |
LevelState2--; |
return; /* our state is 0. */ |
if (LevelState2 > 0 && Recursive) { |
|
wgetc(strlen(EndComment0)); |
|
return(skipToEndTag(tagc,tagv,rule)); |
|
}else{ |
|
wgetc(strlen(EndComment0)); |
|
return; /* our state is 0. */ |
|
} |
} |
} |
|
}else if (rule == 1) { |
|
if (wcmp(EndComment1) == 0) { |
|
LevelState2--; |
|
if (LevelState2 > 0 && Recursive) { |
|
wgetc(strlen(EndComment0)); |
|
return(skipToEndTag(tagc,tagv,rule)); |
|
}else{ |
|
wgetc(strlen(EndComment1)); |
|
return; /* our state is 0. */ |
|
} |
|
} |
|
}else{ |
|
for (i=0; i<tagc; i++) { |
|
if (wcmp(tagv[i]) == 0) { |
|
LevelState2--; |
|
if (LevelState2 > 0 && Recursive) { |
|
wgetc(strlen(EndComment0)); |
|
return(skipToEndTag(tagc,tagv,rule)); |
|
}else{ |
|
wgetc(strlen(tagv[i])); |
|
return; /* our state is 0. */ |
|
} |
|
} |
|
} |
|
|
} |
} |
/* our state is 2. */ |
/* our state is 2. */ |
|
if (wcmp("/*") >= 0) LevelState2++; |
c = wgetc(1); |
c = wgetc(1); |
}while( c!= EOF); |
}while( c!= EOF); |
fprintf(stderr,"findEndTag: unexpected EOF.\n"); |
fprintf(stderr,"findEndTag: unexpected EOF.\n"); |
Line 228 skipToEndTag(int tagc,char *tagv[]) { |
|
Line 342 skipToEndTag(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); |
} |
} |
|
|
|
|
/*&jp |
/*&jp |
\end{document} |
\end{document} |
|
*/ |
|
/*&eg |
|
\end{document} |
*/ |
*/ |
|
|
|
|