#include #include #include #include #include #include #include /*==========================================================================;*/ /* MT:MultiFunction Tools.ver1.025 CopyRight MIYAMA.1999. VYE00525@nifty.or.jp .;*/ /* 1)New Include files. 2)functions pre declear. 3)Main ruitine (cmd promoter.) 4-1):HANDS.out put txt files and else function. 4-2):EARES.input files to as header-Texts. 5)each functions list. 6)Main functions sequence. 7)end ============================================================================;*/ /*1)New Include files.;*/ #include"readmegn.h" #include"odrformp.h" #include"refossil.h" #include"fileback.h" /*2-1)declear functions for operate for header and txt.;*/ void pwinuj(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); void spreaduj(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); void mkodhead(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); void mkrmhead(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); void orirmod(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); /*2-2)each real functions to files.;*/ void newtxtjp(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); void time(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); void txtasm(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); void append(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); void bak2txt(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); void addcont(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); void sepcont(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); void segment(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); void rmvseg(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); void keyfuncs(int fragc,char opt[257],char fargv1[257],char fargv2[257],char fargv3[257]); /* void refossil(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); void enzyme(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); */ void numasm(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); void cleanup(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); /* void trans(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); void pickup(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); void insert(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]); */ /*==========================================================================;*/ /*3)Main ruitene as promoter for each functions;*/ void main(int argc,char *argv[]) { int fargc; fargc=argc-1; char opt[257],fargv1[257],fargv2[257],fargv3[257]; strcpy(opt,argv[1+0]); strcpy(fargv1,argv[1+1]); strcpy(fargv2,argv[2+1]); strcpy(fargv3,argv[3+1]); if(opt[0]=='/') { if((opt[1]=='p')&&(opt[2]=='w')){ pwinuj(fargc,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='s')&&(opt[2]=='r')){spreaduj(fargc,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='m')&&(opt[2]=='r')){mkrmhead(fargc,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='m')&&(opt[2]=='o')){mkodhead(fargc,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='o')&&(opt[2]=='r')){ orirmod(fargc,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='n')&&(opt[2]=='e')){newtxtjp(fargc,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='t')&&(opt[3]=='m')){ time(fargc,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='t')&&(opt[2]=='a')){ txtasm(fargc,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='a')&&(opt[2]=='p')){ append(fargc,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='a')&&(opt[3]=='c')){ addcont(fargc,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='s')&&(opt[3]=='c')){ sepcont(fargc,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='s')&&(opt[3]=='g')){ segment(fargc,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='r')&&(opt[2]=='s')){ rmvseg(fargc,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='b')&&(opt[2]=='2')){ bak2txt(fargc,fargv1,fargv2,fargv3); exit(1);} /*domination for keyword_serching functions.*/ if((opt[1]=='r')&&(opt[3]=='f')){keyfuncs(fargc+1,opt,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='e')&&(opt[2]=='z')){keyfuncs(fargc+1,opt,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='n')&&(opt[2]=='a')){ numasm(fargc,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='c')&&(opt[2]=='l')){cleanup(fargc,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='t')&&(opt[2]=='r')){keyfuncs(fargc+1,opt,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='t')&&(opt[2]=='l')){keyfuncs(fargc+1,opt,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='p')&&(opt[2]=='i')){keyfuncs(fargc+1,opt,fargv1,fargv2,fargv3); exit(1);} if((opt[1]=='i')&&(opt[2]=='n')){keyfuncs(fargc+1,opt,fargv1,fargv2,fargv3); exit(1);} } /* readmetx.bat readme1t.txt pwinjp.bat pwinus.bat; */ FILE *writefp; writefp=fopen("readmetx.bat","w"); fprintf(writefp,"mt /srt\n"); fclose(writefp); writefp=fopen("readme1t.txt","w"); fprintf(writefp,"== JPN Message =====\n"); fprintf(writefp,"これは最も最初のreadmeです。\n"); fprintf(writefp,"\n"); fprintf(writefp,"すべてのドキュメントとバッチファイルはmt.exeのなかに\n"); fprintf(writefp,"動的に梱包されています。\n"); fprintf(writefp,"\n"); fprintf(writefp,"mt.exeをコマンドラインから実行、若しくはクリックすると\n"); fprintf(writefp,"以下の4つの始原ファイルを生成します\n"); fprintf(writefp,"readme1t.txt このファイルです。\n"); fprintf(writefp,"readmetx.bat クリックすると英語版/日本語版のドキュメントを分泌します。\n"); fprintf(writefp,"pwinjp.bat クリックすると日本語版の操作盤呼び出し機能go.batを呼び出します。\n"); fprintf(writefp,"pwinus.bat クリックすると英語版の操作盤呼び出し機能go.batを呼び出します。\n"); fprintf(writefp,"== ENG Message.=====\n"); fprintf(writefp,"/*this is 1st readme document.\n"); fprintf(writefp,"all document and batch file were included into mt.exe.\n"); fprintf(writefp,"only click Mt.exe, it make this 4 small files.\n"); fprintf(writefp,"\n"); fprintf(writefp,"readme1t.txt this file.\n"); fprintf(writefp,"readmetx.bat please click,then main readmejp/us.txt will be created.\n"); fprintf(writefp,"pwinjp.bat please click,then it make CommandTable:go??.bat for Win.\n"); fprintf(writefp,"pwinus.bat please click,then it do on english.\n"); fprintf(writefp,";*/\n"); fclose(writefp); writefp=fopen("pwinjp.bat","w"); fprintf(writefp,"mt /pw j\n"); fclose(writefp); writefp=fopen("pwinus.bat","w"); fprintf(writefp,"mt /pw u\n"); fclose(writefp); /*printf("\n");*/ printf("MultiFunctions for text ver.1.027uniR02TH/(C)MIYAMA.1999 VYE00525@nifty.ne.jp .\n"); /*printf("\n");*/ printf("==Function ==========Usage ===================================Output_files.==\n"); printf("Making today-files. mt /new (return) :YYMMDDaa.txt\n"); printf("TimeStump FOOTER. mt /time filename.txt (sign/comment) :FILENAME.txt\n"); printf("Making Sum-TXT. mt /tasm (return) :sumtxt.txt \n"); printf("Append file. mt /apd headfile.txt backfile.txt :HEADFILE.txt\n"); printf("ADD contents to file. mt /adc filename.txt :FILENAME.txt\n"); printf("SEParation Contents. mt /spc filename.txt :FILENAME.txt\n"); printf("Contents-Call. contcall (return:batch-file).\n"); printf("Segmentize File. mt /seg filename.txt numberline (Keyword):output.txt\n"); printf("Removing Segment. mt /rsg filename.txt :FILENAME.txt\n"); printf("Restore Bakeup-file. mt /b2t filename.bak :output.txt\n"); printf("Repaire CRLFed keyword. \n"); printf(" mt /ref filename.txt keyword :output.txt\n"); printf("Desolve by keyword. mt /ez filename.txt keyword :0-9999.txt\n"); printf("Combine all enzymed. mt /nasm numberoffiles :output.txt\n"); printf("Cleanup all enzymed. mt /cln numberoffiles \n"); printf("Pickup Keyword-line. mt /pik filename.txt keyword :output.txt\n"); printf("Autotranslation. mt /trs filename.txt keyword1 keyword2 :output.txt\n"); printf("AutoTRS,with leftup. mt /tlup filename.txt keyword1 keyword2 :output.txt\n"); printf("Insert. mt /ins file1.txt keyword file2.txt :FILE1.txt\n"); printf("=============================================================================\n"); /*printf("\n");*/ } /*==========================================================================;*/ /* ==CMD for system maintenance and operation.===== 4-1)HANDS functions. 01 pwinuj /pwin (j/u) Promoter for Win95/NT. 02 spreaduj /srd make readmeus.txt and readmejp.txt. 05 orirmod /ori out readmegn/odrformp.txt as original with bilingal. 4-2)EARS functions. 03 mkodhead /moh make headerfile(odrformp.h) to make odrformp(pre).txt. 04 mkrmhead /mrh make headerfile(readmegn.h) to make readmegen(general).txt). ==Simple file operation.===== 1 newtxtjp Making YYMMDDaa.txt(append mode) 2 time APPEND TIMEStump as FOOTER. 3 txtasm Make SumTXT.TXT from aall *.txt. 4 append Append file 2 to file2 with filename-tag. 5 bak2txt Repair *.bat to output.txt. 5)Each CMD. ==CMD for edit.===== 6 addcont Add Contents to files. 7 sepcont Separation Contents from files. 8 segment Add line and Page Number to files. 9 rmvseg Reamving l and p number. ==CMD for changer.===== (From V.1.027, all function without 11/12, included as domain the KEYFUNCS.function.) 10 refossil Repair CRLFed keyword. 11 enzyme Desolve file to faragment(0-9999.txt) with keyword place. 12 numasm Recombine 0-9999.txt to Output.txt 13 cleanup Remove 0-9999.txt 14 trans AutoTranslation. 15 trs l up TRS with Keyword left up.) 16 pickup Pickup Keyword line of files. 17 insert Insert file2.txt to file1.txt's keyword place. 6)Each CMD SEquences. /*=====01 PWINUJ.TXT :Make user operate table.=============================;*/ void pwinuj(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]) { if(2 txtasm.tmp");/*Get TXT file List;*/ if((guidefp=fopen("txtasm.tmp","r"))==NULL) { printf("Error No Exist TXTASM.TMP as Temp-File for Operation.\n"); exit(1); };/*Open TXT file list;*/ writefp=fopen("sumtxt.txt","w");/*TXT assemble file open as append Mode;*/ while((fgets(guide,256,guidefp))!=NULL)/*Read TXT filelist to EOF;*/ { if(guide[9]=='T'){ if(guide[10]=='X'){ if(guide[11]=='T'){ /*only "TXT" included line active.;*/ for (i=0;i<=11;i++) { filename[i]=guide[i]; if(guide[i]==' ')break; } filename[i]='.'; filename[i+1]='\0'; /*To get trunk of filename.;*/ strcat(filename,"TXT"); read_fp=fopen(filename,"r");/*Open TXT by filename got.;*/ fprintf(writefp,"=====%s===========\n",filename); /*Type filename to SUM-TXT.;*/ while((fgets(buf,256,read_fp))!=NULL) { fputs(buf,writefp); } /*Copy filename-TXT to SUM-TXT as apend.;*/ fclose(read_fp);/*Bacuumed End farom filename-TXT.;*/ printf("%s Combined to Sumtxt.txt.\n",filename); }}}/*End of "TXT" hitted line case.;*/ } fclose(guidefp); fclose(writefp); remove("txtasm.tmp"); } /*===== 4 APPEND.TXT :Append file 2 to file1 with filename-tag.============;*/ void append(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]) { if(fargc!=3) { printf("Usage: mt /apd headfile.txt backfile.txt .\n"); exit(1); } char buf[257]; FILE *read_fp; FILE *appendfp; if((read_fp=fopen(fargv1,"r"))==NULL) { printf("No exists %s.\nOpened as New file.\n",fargv1); fclose(read_fp); } if((read_fp=fopen(fargv2,"r"))!=NULL) { appendfp=fopen(fargv1,"a"); fprintf(appendfp,"== %s =====\n",fargv2); while(fgets(buf,256,read_fp)) { fputs(buf,appendfp); } fclose(appendfp); printf("Process succeeded.\n"); } else { printf("No exists %s. Cannot Copy to Append.\n",fargv2); } fclose(read_fp); } /*===== 5 BAK2TXT.TXT :Repair *.bat to output.txt.=========================;*/ void bak2txt(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]) { if (fargc!=2) { printf("Usage: mt /b2t filename.bak .\n"); exit(1); } FILE *read_fp; FILE *writefp; if((read_fp=fopen(fargv1,"r"))!=NULL) { fclose(read_fp); writefp=fopen("output.txt","w"); fclose(writefp); remove("output.txt"); printf("%s changed to output.txt.\n",fargv1); rename(fargv1,"output.txt"); printf("Process succeeded.\n"); } else { printf("No exists %s.\n",fargv1); fclose(read_fp);} } /*===== 6 ADDCONT.TXT :addcont Add Contents to files.=====================;*/ /*ThisProgram have 3 step;*/ /*1)inputted original filename check;*/ /*2)Take contents.txt or new created and write.;*/ /*3)Read Original-txt read and write to work-file(temp.txt) with checking exist of Original-file-txt.;*/ /*4)File rename process for original-bak files.;*/ void addcont(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]) { /* Miss input Check;*/ if (fargc!=2) { printf("Usage: mt /adc filename.txt .\n"); exit(1); } FILE *read_fp; FILE *writefp; char read_filename[257],buf[257]; strcpy(read_filename,fargv1); int i,j; /* *fargv1's \n code remove. ;*/ for(i=0;read_filename[i]!='\0';i++) { if(read_filename[i]=='\n') { read_filename[i]='\0'; } } writefp=fopen("addcont.txt","w"); /* Open "temp.tmp" as OutputWrite.*/ if((read_fp=fopen("contents.txt","r"))==NULL)/*New make "contents.txt";*/ { fprintf(writefp,"~~Contents~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); /* Content zone Add to File Head;*/ for (j=0;j!=5-1;j++) {/* 5-lined \n;*/ fprintf(writefp,"\n"); } fprintf(writefp,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); /* '~' char-s for Contents Remover.;*/ fclose(read_fp); } else /*Take Old "contents.txt" and add to temp.txt;*/ { while(fgets(buf,256,read_fp)!=NULL) { fputs(buf,writefp); } fclose(read_fp); } /*Both cases, Togather same next process.==============================;*/ if((read_fp=fopen(read_filename,"r"))!=NULL) /*When Orignal-txt entirely exist.;*/ { /* copy original-txt to temp.txt.;*/ while((fgets(buf,256,read_fp))!=NULL) { fputs(buf,writefp); } fclose(read_fp); fclose(writefp); /*Two file Close.;*/ printf("ADD Contents Process Succeeded.\n"); filebackup(read_filename,"addcont.txt"); /*Original-file Rename;*/ } else { printf("%s Text-File No exist.",read_filename);/*When Original-TXT Noexist;*/ remove("addcont.txt"); } /*process.end;*/ } /*===== 7 SEPCONT.TXT :Separation Contents from files.=====================;*/ void sepcont(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]){ if (fargc!=2) { printf("Usage: mt /spc filename.txt .\n"); exit(1); } FILE *read_fp; FILE *writefp; char read_filename[257]; strcpy(read_filename,fargv1); int i; for(i=0;read_filename[i]=='\0';i++) /*\n code remove;*/ { if(read_filename[i]=='\n') { read_filename[i]='\0'; } } if((read_fp=fopen(read_filename,"r"))!=NULL)/*When file really exists.;*/ { char buf[257]; int flagwfp; flagwfp=0; fgets(buf,256,read_fp); /*1st line check Contents be or not;*/ if((buf[0]=='~')&&(buf[1]=='~')) { writefp=fopen("contents.txt","w"); flagwfp=1; fputs(buf,writefp); } else /*When Contents is nothing.;*/ { printf("This Text-file has No Contents.\n"); printf("Or 1st line's left side is not Correct.\n"); exit(1); } while((fgets(buf,256,read_fp))!=NULL)/*again roal of reading.*/ { fputs(buf,writefp); if((flagwfp==1)&&(buf[0]=='~')) /*Discover contents's end, Change Write file. for main-trunk.;*/ { flagwfp=-1; fclose(writefp); writefp=fopen("sepcont.txt","w"); } } fclose(writefp); /*Two file pointer ,close.;*/ fclose(read_fp); filebackup(read_filename,"sepcont.txt"); /*Filename,backup.;*/ remove("sepcont.txt"); /*=============================================================;*/ writefp=fopen("contcall.bat","w"); /*Making Call editor Batch.;*/ char cmdstr[257]; fprintf(writefp,"start contents.txt\n"); strcpy(cmdstr,"start "); strcat(cmdstr,read_filename); fprintf(writefp,"%s\n",cmdstr); /*printf(cmdstr);*/ fclose(writefp); /*system("contcall"); Made system error.*/ /*Please click "CONTCALL.BAT" Icon on UserSide.*/ } else {printf("Cannot file open.\n"); fclose(read_fp); } } /*===== 8 SEGMENT.TXT :Add line and Page Number to files.==================;*/ void segment(int fargc,char fargv1[257],char fargv2[257],char fargv3[257]){ if ((fargc<3)||(4 newbufa\n + newbufb\n it is by refossil2-func. ^including 'keyword' repaired. well, bufa<=newbufa, bufb<=newbufb, and pass 'bufa' to many understream branch, after it, bufa < bufb renewal. Most first,bufa=='== Mather filename =====\n' Most EOF, bufa alone executed with out new bufb.; ===================================================;*/ bufbflag=0; again:; line_counter++; /*if read_bufb reach EOF, it skip trunk doing and pass old bufa to off springs branch.;*/ if((fgets(bufb,256,read_fp))==NULL) { /*printf("a");*/ printf("Throw Final- line into Process.\n"); bufbflag=-1; goto fileend; } else{ printf("%dth line readed.\n",line_counter+1); /*chbuf,buffer to check.*/ strcpy(chbuf,bufa); strcat(chbuf,bufb); /*chbuf, it is include inner '\n';*/ /*call repair-function for keyword;*/ strcpy(chbuf_tmp,refossil2(chbuf,keyword)); printf("buf tocheck:%schecked buf:%s\n",chbuf,chbuf_tmp); strcpy(chbuf,chbuf_tmp); /*initialize buffer contents;*/ bufa[0]='\0'; bufb[0]='\0'; /*write before paragraph of (new)chbuf to bufa,;*/ for (i=0;chbuf[i]!='\0';i++) { /*printf("%c",chbuf[i]);*/ bufa[i]=chbuf[i]; if(chbuf[i]=='\n') { bufa[i+1]='\0'; goto nextisbufb; } } printf("BufferingA Logical error of MT."); exit(1); nextisbufb:; /*write back paragraph of (new) chbuf to bufb.;*/ m=i+1; for(j=m;chbuf[j]!='\0';j++) { bufb[j-m]=chbuf[j]; if(chbuf[j]=='\n') { bufb[j-m+1]='\0'; goto nextisescape; } } printf("BufferingB Logical error of MT."); exit(1); nextisescape:; /*printf("bufa:%sbufb:%s\n",bufa,bufb);*/ } /*read_mather file show EOF, then jump to this, be alone bufa only,,with out bufb contents,*/ fileend:; /*printf("b");*/ /*All brach functiones do to execute to bufa, as a New read file line.;*/ d1st=discover1st(bufa,keyword); /*printf("c");*/ /*if keyword not included on bufa, simple it write bufa to file_pointer.;*/ /*but only pickup cmd, it not execute those process.;*/ if(d1st==-1) { if((opt[1]!='p')||(opt[3]!='k')) { fputs(bufa,writefp); printf("fputs event occured.\n"); } } /*if discover keyword,then separated stream by each option cmd demannd.;*/ else { printf("%s discovered in %dth line.\n",keyword,line_counter); /*when choose pik cmd, it type line_counter to file_pointer;*/ if((opt[1]=='p')&&(opt[3]=='k')) { fprintf(writefp,"__%d::",line_counter); } /*write bufa contents just before keyword palce.;*/ if(0