Язык Си шаг за шагом

  • Просмотров 15887
  • Скачиваний 2166
  • Размер файла 405
    Кб

#include <stdio.h> #include <dir.h> #define FA_DIREC 0x10 #define CONTROL '$' #define OPEN "<174>" #define CLOSE "<175>" #define DEFIS "<197>" #define NUM "<102>" #define EOLN ' ' #define ITALIC "<I>" #define BOLD "<D>" // $$narg=1; char in[20],x[40],z[80],str[120],img[80]; int empty,befor; FILE *fdi, *fdo; int c0num,cnum,inum,nstr,tnum; int sign,old,expand; int GetStr() { befor = old; old = 1; if (empty==0) { nstr++; if (fgets(str,80,fdi)==NULL) return(-1); if (str[0]==0 || str[0]=='\n') { befor=1; nstr++; if (fgets(str,80,fdi)==NULL) return(-1); if (str[0]==0 || str[0]=='\n') return(2); else { empty=1; return(1); } } else { old=0; return(0); } } else { empty=0; old=0;

return(0); } } int NoLF() { int i; for (i=0; str[i]!=0; i++) if (str[i]=='\n') break; str[i]=0; } Cat(s,pi,ss) char s[],ss[]; int *pi; { int i; for (i=0; ss[i]!=0; i++,(*pi)++) s[*pi]=ss[i]; } void ProcProg() { int i,j,n,k; char xx[120]; strcpy(xx,str); for (i=j=n=k=0; xx[j]!=0; j++) { switch (xx[j]) { case '<': case '>': str[i++]=xx[j]; str[i++]=xx[j]; break; case '/': if (xx[j+1]=='/') { k++; str[i++] = xx[j++]; str[i++] = xx[j]; Cat(str,&i,ITALIC); } else str[i++] = xx[j]; break; case '\"': if (n) { Cat(str,&i,BOLD); str[i++] = xx[j]; } else { str[i++] = xx[j]; Cat(str,&i,ITALIC); } n = !n; break; default: str[i++] = xx[j]; } } if (k) Cat(str,&i,BOLD); str[i]=0; } int Proc() { int i,j,n,k; char xx[120]; if (str[0]=='\t' && str[1]=='-')

fprintf(fdo,"\n\n"); for (i=0; str[i]!=0; i++) xx[i]=str[i]; xx[i]=0; for (i=j=n=0; xx[j]!=0; j++) { switch (xx[j]) { case '\n': case '\t': case ' ': n++; if (n==1) str[i++]=' '; break; case '-': if (!expand) str[i++]=xx[j]; break; n=0; if (xx[j+1]!=0 || xx[j-1]==' ') Cat(str,&i,DEFIS); else str[i++]='-'; break; case '\"': if (!expand) str[i++]=xx[j]; break; n=0; if (sign) Cat(str,&i,CLOSE); else Cat(str,&i,OPEN); sign = !sign; break; default: n=0; str[i++] = xx[j]; } } str[i]=0; for (i--; i>=0 && str[i]==' '; i--) str[i]=0; if (str[i]=='-' && str[i-1]!=' ') { str[i]=0; fprintf(fdo,"%s",str); } else fprintf(fdo,"%s%c",str,EOLN); } int Copy(ext,num,mode) char *ext; int num; int mode; { FILE *fd1; int n;

sprintf(x,"%s%d.%s",in,num,ext); puts(x); if ((fd1=fopen(x,"w"))==NULL) return(0); fprintf(fdo,"\n{ %s }\n\n",x); if (mode==1) { sprintf(z,"//────────────────────────────────────────────── %s\n",x); fprintf(fd1,"%s",z); } if ((mode & 1) && expand) ProcProg(); if (mode!=0) fprintf(fd1,"%s\n",str); if (mode==0) sprintf(img,"\n Рис.%s%d. %s",in,num,str+1); while ((n=GetStr())!=-1) { NoLF(); if ((mode & 1) && expand)

{ fprintf(fd1,"\n"); ProcProg(); } if (n==2 || str[0]==CONTROL || mode==2 && n==1) { if (mode==0) fprintf(fd1,"%s\n",img); fclose(fd1); return(1); } if (n==1) fprintf(fd1,"\n"); else fprintf(fd1,"%s\n",str); } fclose(fd1); return(0); } char A[]="АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩъЫЬЭЮЯ"; char B[]="абвгдежзийклмнопрстуфхцчшщъыьэюя"; char Alpha(c) char c; { int i; for (i=0; A[i]!=0; i++) if (c==A[i]) return(B[i]); return(0); } void keywords() { FILE *fdi,*fdo; int i,j,n; char cc,out[100]; sprintf(x,"%s0.txt",in); if ((fdi=fopen(x,"r"))==NULL) return; if ((fdo=fopen("keys.txt","a"))==NULL) return; fseek(fdo,0L,2); while