1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
/* V0.52 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
#define sCopy(x,y) strcpy(search,x); strcpy(replace,y);
#define CHG(x,y) sCopy(x,y) CHGI CHGII CHGIII CHGIV
#define CHGI pos=posi(search);j=(int)strlen(replace);
#define CHGII while(pos>=0){for(i=pos;i<j+pos;++i) Line[i]=replace[i-pos];
#define CHGIII for(i=pos+(int)strlen(search);i<=(int)strlen(Line);++i)
#define CHGIV Line[i-((int)strlen(search)-j)]=Line[i];pos=posi(search);}
#define ChG(x,y) sCopy(x,y) ChGi ChGii ChGiii ChGiv
#define ChGi pos=posi(search);j=(int)strlen(replace);diff=j-(int)strlen(search);
#define ChGii while(pos>=0){ ii=pos+(int)strlen(search);for(i=(int)strlen(Line);
#define ChGiii i>ii-1;--i) Line[i+diff]=Line[i];for(i=pos;
#define ChGiv i<j+pos;++i)Line[i]=replace[i-pos];pos=posi(search);}
FILE *infile, *outfile;
char Line[256];
char name_of_file[256], n_o_f[256], name_tok[256], search[256], replace[256];
int posi(char dest[]){
int i=0, j=0, Dest=(int)strlen(dest), Src=(int)strlen(Line);
while (i < Src)
{ if (Line[i]==dest[j]) {++j; if (j==Dest) break;}
else j=0;
++i;}
if (j==Dest) return(++i-j); else return(-1);}
int main( int argc, char *argv[] ){
register int pos, i, j, ii;
int posi(), diff;
if (argc<2) {printf("No filename ?"); exit(3);}
strcpy(name_of_file, argv[1]);
strcpy(n_o_f, strtok(name_of_file, "."));
strcpy(name_tok, n_o_f);
strcat(name_of_file, ".tex");
infile = fopen( name_of_file, "r");
if (!infile)
{printf("\nFile not found: %s\n", name_of_file); exit(3);}
strcat(n_o_f, ".tey");
outfile = fopen( n_o_f, "w");
if (!outfile)
{printf("\nCan't create: %s\n", n_o_f); exit(3);}
while (fgets(Line, (int) sizeof(Line), infile))
{
/* few namechanges */
CHG("musix", "opus");
CHG("\\MusiX", "\\Opus");
CHG("\\leftrightrepeat", "\\rightleftrepeat");
CHG("\\setleftrightrepeat", "\\setrightleftrepeat");
CHG("\\upzst", "\\ustpo");
CHG("\\dpzst", "\\dstpo");
CHG("\\ust\n", "\\upo\n");
CHG("\\dst\n", "\\dpo\n");
CHG("\\ust{", "\\upo{");
CHG("\\dst{", "\\dpo{");
CHG("\\ust ", "\\upo ");
CHG("\\dst ", "\\dpo ");
CHG("\\ust%%", "\\upo%%");
CHG("\\dst%%", "\\dpo%%");
CHG("\\bust", "\\bupo");
CHG("\\bdst", "\\bdpo");
CHG("\\stemust", "\\stemupo");
CHG("\\stemdst", "\\stemdpo");
CHG("\\upz", "\\ust");
CHG("\\dpz", "\\dst");
CHG("\\bupz", "\\bust");
CHG("\\bdpz", "\\bdst");
CHG("\\stemdpz", "\\stemdst");
CHG("\\stemupz", "\\stemust");
CHG("\\dbow", "\\vbow");
CHG("\\bdbow", "\\bvbow");
CHG("\\stdstemfalse", "\\nostdstem");
CHG("\\zmidstaff", "\\zmidtext");
CHG("\\lmidstaff", "\\lmidtext");
CHG("\\cmidstaff", "\\cmidtext");
CHG("\\setslurtext", "\\slurtext");
CHG("\\ibslur", "\\imslur");
CHG("\\tubslur", "\\tumslur");
CHG("\\tdbslur", "\\tdmslur");
CHG("\\tbsluru", "\\tumslur");
CHG("\\tbslurd", "\\tdmslur");
CHG("\\songraise", "\\raisesong");
CHG("\\setsongraise", "\\setraisesong");
fputs(Line,outfile);
}
fclose(infile);
fclose(outfile);
if (!outfile) printf("\n File error: Disk full ?\n");
strcat (name_tok, ".ori");
rename (name_of_file, name_tok);
rename (n_o_f, name_of_file);
return(0);
}
|