/metod.awk
AWK | 867 lines | 364 code | 443 blank | 60 comment | 0 complexity | 48b3594fbfdb21e807beaab8b62702ad MD5 | raw file
- ## Prefix="##{"
- ## Suffix="}"
- ## Enc="1251"
- ## End
-
-
-
-
-
-
-
- ##{A}
-
- ##{BEGIN}
-
-
-
- #function ccod(A){ return "" xcod(A,0) "" xcod(A,1)}
- function ccod(A, S,l){
-
-
- S="000000000" (CodLine(A, CodPicDef)) ;
-
- gsub(/ /,"",S);
-
- #S="000000000" xcod(A,1) ""xcod(A);
-
- l=length(S)
-
- return "m"substr(S,l-18+1,18);
- #return xcod(A) ;
-
- }
-
-
-
-
- BEGIN {
-
-
- ArefRegList="refh|ref|aref|apageref|pageref|arefp";
- BrefRegList="bref|bpageref|brefp";
- CrefRegList="cref|cpageref|crefp";
-
- DoPic=1;
-
-
- PicFline="";
- PicFOn=0;
-
- PicDir="picx/"
-
-
-
-
-
-
-
-
- ################################
- MkTeXExist(); #
-
-
- #################################
-
-
- OutTex="out.tex";
-
- CopyPicBat="tmpcppic.bat"
-
- #####################
-
-
-
- MetodPicDef[1]="picdef.tex";
-
-
-
- ReadJobFile(JobFile);
-
-
-
-
-
-
-
-
- for (i=1 ; i in MetodPicDef ; i++){
-
- tmpF=MetodPicDef[i]
-
- while ( (getline line < tmpF) >0) {
-
- #BeginTeX=BeginTeX "\n" line
- print(line) >"picdef.tmp"
-
- }
- if ( (getline line < tmpF) <0 ) Error("file " tmpF " not exist");
-
- close(tmpF);
-
- }
-
-
- close("picdef.tmp");
-
- CodPicDef=CodFile("picdef.tmp");
-
-
- #print(BeginTeX) >"picdef.tmp"
-
-
- BeginTeX="\\batchmode\\documentclass[a5paper]{article}\n" BeginTeX
- #BeginTeX="\\documentclass{article}\n" BeginTeX
-
- BeginTeX=BeginTeX "\\input{../picdef.tmp}" ;
-
- BeginTeX=BeginTeX "\n\\begin{document}\\thispagestyle{empty}"
-
- EndTeX= "\\end{document}"
-
-
-
-
- #InpFileList[1]="text.tex"
- #InpPatchFileList[1]="text2.tex"
-
- BlockCount=2;
-
- ######################
- GoForFiles(InpFileList , 1);
-
- BorderBlocks=BlockCount;
- BlockCount++;
- GoForFiles(InpPatchFileList , 2);
- #####################
- ####################
- #ActAlabel["SistUrNeskResh"]=1;
- MkActualBandL();
- for (i in ActAlabel) ActLabel[i]=1
- for (i in ActBlabel) ActLabel[i]=1
-
- MkActLine(ActLabel);
-
- print("") >OutTex;
-
- PrintAll()
- #####################
-
- #for (i in ActAlabel) print ("ActAlabel", i ,ActAlabel[i])
- #for (i in ActBlabel) print ("ActBlabel", i ,ActBlabel[i])
-
-
- #for (i in ActLabel) print ("ActLabel", i ,ActLabel[i], "Blok- " LabelToBlock[i])
-
- #for (i in ActBegin) print ("ActBegin", i ,ActBegin[i])
- #for (i in ActEnd) print ("ActEnd", i ,ActEnd[i])
- #for (i in IgnoreLine) print ("IgnoreLine", i ,IgnoreLine[i])
-
- #for (i in ActABlock) print ("ActABlock", i ,ActABlock[i])
- #for (i in ActBBlock) print ("ActBBlock", i ,ActBBlock[i])
-
-
-
-
-
- #for (i in BlockToFile) print ("BlockToFile", i ,BlockToFile[i])
-
- #for (i in LabelToBlock) print ("LabelToBlock", i , LabelToBlock[i])
-
- #for (i in BlockToBeginLine) print ("BlockToBeginLine", i , BlockToBeginLine[i])
-
- #for (i in BlockToEndLine) print ("BlockToEndLine", i , BlockToEndLine[i])
-
- #for (i in OldToNewBlock) print ("OldToNewBlock", i , OldToNewBlock[i])
- #for (i in NewToOldBlock) print ("NewToOldBlock", i , NewToOldBlock[i])
-
- #for (i in BlockToAref) print ("BlockToAref", i , BlockToAref[i])
- #for (i in BlockToBref) print ("BlockToBref", i , BlockToBref[i])
- #for (i in BlockToCref) print ("BlockToCref", i , BlockToCref[i])
-
- #for (i in PlaceRef) print ("PlaceRef", i , PlaceRef[i])
-
- }
-
-
-
- function MkTeXExist( line){
-
- if ( PicxDir != "") {
-
- while ( (getline line <PicxDir) >0) {
-
-
- if ( line ~ /\.tex/) {
-
- line=StripLine(line);
-
- sub(/\.tex$/,"",line);
-
- TeXExist[line]=1;
-
- # print(line);
-
- }
-
- }
-
- }
-
- }
-
-
-
-
-
-
-
-
-
-
- ##{}
-
-
-
-
-
-
- function printt(l){print(l) >> OutTex}
-
- function printX(l, ccc, f){
-
-
- ccc=ccod(l);
-
- if ( ccc in TeXExist ) {}
- else {
-
-
- f="" PicDir ccc ".tex";
- print(l) > f;
- close(f)
-
- }
-
- }
-
- function ForCopyPic(n, a ){
-
- print("call askpicx.bat " n " " DPI " " MAG) >CopyPicBat
-
- }
-
-
- ##{PrintOut}
-
- #function PrintOut(l){ print(l) >> OutTex }
-
-
- function PrintOut(l , i,cod,PicFLineAll){
-
-
- if ( DoPic == 0 ) { printt(l) }
- else if (l ~ /^[ \t]*%/) { printt(l) }
- else if (l ~ "\\\\end{PicFormula}" ) {
-
- PicFOn=0;
-
-
- if (MathPicF == 1) { PicFLineAll=BeginTeX "\n$%" PicFline "$\n" EndTeX }
- else if (MathPicF == 2) { PicFLineAll=BeginTeX "\n$$%" PicFline "$$\n" EndTeX }
- else { PicFLineAll=BeginTeX "\n%" PicFline "\n" EndTeX }
-
-
- printX(PicFLineAll) ;
-
- cod=ccod(PicFLineAll);
-
- ForCopyPic(cod);
-
-
- sub(/^.*\\end{PicFormula}/,"",l)
-
-
-
- if (MathPicC != 1) { printt("\\PicFormulaX{%" ( PicFline "%\n}{"cod"}" l) ) }
- else { printt("%%tth:\\begin{center}\n\\PicFormulaX{%" ( PicFline "%\n}{"cod"}\n%%tth:\\end{center}" l) ) };
-
- }
- else if (l ~ "\\\\begin{PicFormula}" ) {
-
- MathPicF=0;
- MathPicC=0;
-
-
- if (l ~ /\[M\]/) { MathPicF=2 }
- else if (l ~ /\[m\]/) { MathPicF=1 }
- else if (l ~ /\[c\]/) { MathPicC=1 }
- else if (l ~ /\[C\]/) { MathPicC=1 }
-
- PicFOn=1;
- PicFline="";
-
- }
- else {
-
-
- if (PicFOn) PicFline=PicFline "\n" l;
- else printt(l)
-
- }
-
-
-
- }
-
-
-
-
-
-
-
-
-
- ##{ReadJobFile}
- function ReadJobFile(JF, line,Arr,i,n){
-
-
- while ( (getline line <JF) >0) {
-
-
- if ( line ~ /^MetodPic/ ) {
-
- DoPic=1; # пока пусть так
-
- sub(/^MetodPic/,"",line);
-
- line=StripLine(line);
-
- if (line == "") {
- DoPic=1; DPI=150; MAG=0.666;
-
- }
- else if ( (0+line) == 0) { DoPic=0;
- }
- else {
- split(line,tmpArr);
- DoPic=1;
- DPI=0+tmpArr[1];
- MAG=0+tmpArr[2];
- if (MAG == 0) MAG=1;
- }
-
-
- }
-
- if ( line ~ /^MetodMain/ ) {
-
- sub(/^MetodMain/,"",line);
-
- line=StripLine(line);
-
- if (line == "") {
- line="ru-mta.tex";
- Warning("Main is ru-mta.tex");
- }
-
- MkScript(line,"starttex.tmp")
-
-
- }
-
-
-
- if ( line ~ /MetodUrl/ ) {
-
- sub(/^MetodUrl/,"",line);
-
- line=StripLine(line);
-
- MetodUrl=line;# Голобальная
-
-
- }
-
-
- if ( line ~ /^MetodDefPic/ ) {
-
- sub(/^MetodDefPic/,"",line);
-
- n=split(line,Arr);
- for ( i = 1 ; i<=n ; i++) {
-
- MetodPicDef[i]=Arr[i]
-
- }
-
- }
-
-
- if ( line ~ /MetodFiles/ ) {
-
- sub(/^MetodFiles/,"",line);
-
- n=split(line,Arr);
-
- if (n == 0) {
-
- DefoultInpFileList("ru-mall.tex","InpAndFN",InpFileList) ;
- Warning("File list from ru-mall.tex");
-
- }
- else {
- for ( i = 1 ; i<=n ; i++) {
-
- InpFileList[i]=Arr[i]
-
- }
- }
- }
-
- if ( line ~ /MetodDopFiles/ ) {
-
- sub(/^MetodDopFiles/,"",line);
-
- n=split(line,Arr);
- for ( i = 1 ; i<=n ; i++) {
-
- InpPatchFileList[i]=Arr[i]
- Warning("Patch file "Arr[i]);
-
- }
-
-
- }
-
- # ActAlabel["SistUrNeskResh"]=1;
-
- if ( line ~ /MetodLabel/ ) {
-
- sub(/^MetodLabel/,"",line);
-
- n=split(line,Arr);
- for ( i = 1 ; i<=n ; i++) {
-
- ActAlabel[Arr[i]]=1
-
- }
-
-
- }
-
-
- }
-
- }
-
-
-
-
- #DefoultInpFileList("ru-mall.tex","InpAndFN",InpFileList)
-
- function DefoultInpFileList(F,S,Arr, i,j,line,n,tmp ){
-
- n=0;
-
-
- while ((getline line <F) >0){
-
- if (line ~ ("^\\\\"S) ) {
-
-
- sub("^\\\\"S".*{","",line);
- sub( /}.*$/,"",line);
-
- line = StripLine(line);
-
- if ((getline tmp <line) >=0 ) {
-
- close(line);
-
- n++;
-
- Arr[n]=line;
-
- Warning("File "line" will be used")
- }
-
- }
-
-
- }
-
- if ((getline line <F) <0) Error("File "F" not exist")
-
- close(F);
-
- }
-
-
-
- function MkScript(FromFl,SriptFl, Line, Ok ){
-
- Ok=0;
-
- print("set MyUrl="MetodUrl) >SriptFl;
-
- while ( (getline line <FromFl) >0) {
-
- if ( line ~ /^[ \t]*BeginMetodTransleteScript/ ) { Ok=1; continue;}
- if ( line ~ /^[ \t]*EndMetodTransleteScript/ ) { Ok=0; continue;}
-
-
- if (Ok==1) {
-
- print(line) >>SriptFl;
-
- }
- }
-
-
- }
-
-
-
- ##{GoForFiles}
- function GoForFiles(List,Tip, i ) {
- for (i=1 ; i in List ; i++) ReadFiles(List[i],Tip)
- }
-
- ##{ReadFiles}
-
- function ReadFiles(InpFile,Tip, IgnoreRead,lineCount,line){
-
- IgnoreRead=1;
- lineCount=0
-
- while ( (getline line <InpFile) >0) {
-
- lineCount++;
-
- if (line ~ /bblock/ ) {
-
- if ( !IgnoreRead) BlockToEndLine[BlockCount]=lineCount-1; #??
-
- IgnoreRead=0;
-
- BlockCount++;
-
- BlockToFile[BlockCount]=InpFile;
- BlockToBeginLine[BlockCount]=lineCount;
-
- continue;
- }
-
- if (IgnoreRead) { continue; } ############
-
- if (line ~ /eblock/ ) {
- IgnoreRead=1;
- BlockToEndLine[BlockCount]=lineCount;
- continue;
- }
-
-
- if (line ~ /^[ \t]*%/ ) { continue; }
-
-
- if (line ~ "\\\\label{") {
-
- sub(/^.*\\label{[ \t]*/,"",line);
- sub(/[ \t]*}.*$/,"",line);
-
- if (Tip == 1) {
-
- if (line in LabelToBlock) Error("Duble Label "line" in "InpFile" in "lineCount )
-
- LabelToBlock[line] = BlockCount;
- }
-
- if (Tip == 2) {
-
- if ( !(line in LabelToBlock)) Error("Unknown Label "line" in "InpFile" in "lineCount )
-
- OldToNewBlock[LabelToBlock[line]] = BlockCount;
- NewToOldBlock[BlockCount] = LabelToBlock[line]
-
- LabelToBlock[line] = BlockCount;
- }
-
- continue;
-
- }
-
-
- ############
- if ( line ~ "\\\\("ArefRegList"){") {
-
-
- sub("^.*\\\\(" ArefRegList "){[ \t]*","",line);
- sub(/[ \t]*}.*$/,"",line);
-
-
- BlockToAref[BlockCount] = BlockToAref[BlockCount] " " line
-
- PlaceRef[lineCount "," InpFile] = line;
-
- continue;
- }
-
- if ( line ~ "\\\\("BrefRegList"){") {
-
-
- sub("^.*\\\\(" BrefRegList "){[ \t]*","",line);
- sub(/[ \t]*}.*$/,"",line);
-
-
-
- BlockToBref[BlockCount] = BlockToBref[BlockCount] " " line
-
- PlaceRef[lineCount "," InpFile] = line;
-
- continue;
-
- }
-
- if ( line ~ "\\\\("CrefRegList"){") {
-
-
- sub("^.*\\\\(" CrefRegList "){[ \t]*","",line);
- sub(/[ \t]*}.*$/,"",line);
-
-
- BlockToCref[BlockCount] = BlockToCref[BlockCount] " " line
-
- PlaceRef[lineCount "," InpFile] = line;
-
- continue;
- }
-
-
- }#while
-
- if ((getline line <InpFile) <0) Warning("File "InpFile" not exist")
-
- close(InpFile);
-
-
- }
-
- ##{MkActualBandL}
- function MkActualBandL( i,n,l,Blk,Arr,Enough){
-
-
- do{
- Enough=1;
-
-
- for ( i in ActAlabel ){
-
- Blk=LabelToBlock[i];
-
- ActABlock[Blk]=1;
-
- }
-
- for ( i in ActBlabel ){
-
- Blk=LabelToBlock[i];
-
- ActBBlock[Blk]=1;
-
- }
-
-
- for ( n in ActABlock) {
-
- split(BlockToAref[n],Arr);
-
- for (i in Arr) {
-
- l=Arr[i];
- if ( !(l in ActAlabel) ) {Enough=0; ActAlabel[l]=1; }
- }
-
-
- split(BlockToBref[n],Arr);
-
- for (i in Arr) {
-
- l=Arr[i];
- if ( !(l in ActBlabel) ) {Enough=0; ActBlabel[l]=1; }
- }
-
-
- }
-
- for ( n in ActBBlock) {
-
- split(BlockToAref[n],Arr);
-
- for (i in Arr) {
-
- l=Arr[i];
- if ( !(l in ActBlabel) ) {Enough=0; ActBlabel[l]=1; }
- }
-
-
- }
-
-
-
-
- if (Enough) break;
-
- }while(1)
-
- #for ( i in ActABlock ) if ( i in ActBBlock) delete ActBBlock[i]
-
- #for ( i in ActAlabel ) if ( i in ActBlabel) delete ActBlabel[i]
- }
-
-
-
-
- ##{MkActLine}
- function MkActLine(ActLabel, ActB,AllActLabel,i,l,n,nn,Bl,El,Fl){
-
- for(l in ActLabel) {
-
- n=LabelToBlock[l];
-
- ActB[n]=1;
- }
-
- for ( n in ActB){
-
- if (n in NewToOldBlock) {
-
- nn=NewToOldBlock[n];
-
- Bl=BlockToBeginLine[nn];
- El=BlockToEndLine[nn];
- Fl=BlockToFile[nn];
- rez=n
- }
- else {
-
- Bl=BlockToBeginLine[n];
- El=BlockToEndLine[n];
- Fl=BlockToFile[n];
- rez=1;
- }
-
- ActBegin[Bl","Fl]=rez;
- ActEnd[El","Fl]=1; # !!!!!!!!!!!!
- }
-
- for (l in LabelToBlock) if (LabelToBlock[l] in ActB) AllActLabel[l]=1
-
- for (i in PlaceRef) if ( !(PlaceRef[i] in AllActLabel) ) IgnoreLine[i]=1
-
- }
-
-
- ##{PrintBlock}
-
- function PrintBlock(n, B,E,F,line,lineCount){
-
- lineCount=0;
-
- B=BlockToBeginLine[n];
- E=BlockToEndLine[n];
- F=BlockToFile[n];
-
- #print(B,E,F)
-
-
- PrintOut("% " B "-" E " "F)
- PrintOut("\\TuT{"F"}{"B"}")
-
- while ( (getline line <F) >0) {
-
- lineCount++;
-
- #if (lineCount == B) line="\\bblock{"F": "B"}"
-
- #if (lineCount == E) line="\\eblock{"F": "E"}"
-
- if( lineCount >= B && lineCount <= E && !( (lineCount "," F) in IgnoreLine ) ) PrintOut(line)
-
- }
-
- close(F)
-
- }
-
-
- ##{PrintAll}
- function PrintAll(NomFile,F,line,lineCount,YesPrint,tmp,Ptmp,n){
-
- for(NomFile=1 ; NomFile in InpFileList ; NomFile++) {
-
- F=InpFileList[NomFile];
-
- lineCount=0;
-
- YesPrint=0;
-
- while ( (getline line <F) >0) {
-
- lineCount++;
-
- tmp=""lineCount","F;
- Ptmp="\\TuT{"F"}{"lineCount"}";
-
- if ( tmp in ActBegin ) {
-
- n=ActBegin[tmp]
- if ( n == 1) {
-
- YesPrint=1
-
- PrintOut("%"Ptmp)
- }
- else { PrintBlock(n) }
- }
-
- if (YesPrint) {
-
- if (line ~ /[ \t]*\\TuT/) sub(/\\TuT/,Ptmp,line);
-
- if ( (tmp in IgnoreLine)) { PrintOut("% ignor ref % "line); }
- else {PrintOut(line);}
- }
-
- if ( (tmp) in ActEnd ) {
-
- PrintOut(Ptmp)
- YesPrint=0;
- }
- }
-
- close(F)
- }
-
-
-
- }
-
-
-
- ##{}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-