(c)  騭, ᪢

ZXNet : 500:95/462.53
E-mail: bestview@mtu-net.ru
WWW   : http://www.ivr.da.ru

              ணࠬ  ଠ஢ ⥪⮢
              

(".  " 6/2005)




     室    ⥪⮢묨 䠩,  
  ।⠢     ப (ਬ,
⠪ 䠩   ᯮ짮   DOC ->
TXT - . [1]),   ८ࠧ   "" , 
 ࠧ  ப, ਭ    㪠, 
ࢠ ப   뤥 㯮 
稭.  ⮩ 楫  ᠫ  ணࠬ 
Turbo C,  । 襬 .


 ணࠬ


/* =============================
     File: "txt_form.c"
     Compiler: Turbo C 2.01
 ============================= */

#include <stdio.h>
#include <stdlib.h>

/* ==================== ᠭ 㭪権 ==================== */

int fgetc_2 (FILE* f);
FILE* fopen_1 (char* name, char* mode);
void fcloseall_1 ();
int fgetc_1 (FILE* f);
void ungetc_1 (int c, FILE* f);
void fputc_1 (int c, FILE* f);
long ftell_1 (FILE* f);
void fseek_1 (FILE* f, long offset, int whence);

/* ================== 諠 ᠬ ணࠬ ================== */

int main (int argc, char *argv[])
{
 FILE *f_src, *f_dst;
 unsigned int text_width; /* ਭ ନ㥬 ⥪ (..
                             ᨬ쭠  ப). */
 unsigned int text_indent; /* 塞  . */
 long begin_str; /* 饭 砫 ⥪饩 ப  室
                    ⥪⮢ 䠩. */
 long len_str;   /*  ⥪饩 ப. */
 long cut_str;   /* 饭 ᫥ (  )
                    樨  室 ⥪⮢ 䠩,
                    ᮮ⢥饩   ७
                    ⥪饩 ப (..  ⮩ 樨 ஡).
                    ᫨ cut_str=-1 - , ⠪ 樨 
                     㦥. */
 long i;         /* 稪. */
 int c;          /* 騩 ᨬ. */
 int first_str;  /* ਧ "뢮  ப " (1 -
                    , 0 - . */
 long n=0;       /*  ࠡ뢠 . */

 printf ("\n\
Ŀ\n\
                      Text Formatter                      \n\
Ĵ\n\
(c) Ivan Roshin, Moscow, 26 Sep 2004                      \n\
E-mail: bestview@mtu-net.ru      WWW: http://www.ivr.da.ru\n\
\n\
");

 if (argc!=5)
 {
  printf ("\nSyntax: txt_form text_width text_indent \
source_file destiny_file\n\n");
  exit(1);
 }
 if (sscanf(argv[1],"%u",&text_width)!=1)
 {
  printf ("\nIncorrect text_width!\n\n"); exit (1);
 }
 if (sscanf(argv[2],"%u",&text_indent)!=1)
 {
  printf ("\nIncorrect text_indent!\n\n"); exit (1);
 }
 f_src=fopen_1(argv[3],"rb");
 f_dst=fopen_1(argv[4],"wb");

/* ======================  横 ====================== */

 while (c=fgetc_2(f_src),c!=EOF)  /*    ⥪. */
 {
  printf ("\rParagraph: %li",++n);
  if (c==13) /* ⮩ . */
  {
   fputc_1 (13,f_dst);
   fputc_1 (10,f_dst);
   continue; /*  砫  横. */
  }

  /* ⮩ . */

  ungetc_1(c,f_src);
  for (i=0;i<text_indent;i++) fputc_1(' ',f_dst); /* . */
  len_str=text_indent;
  first_str=1;
  begin_str=ftell_1(f_src);
  cut_str=-1;

  /* ࠡ⪠ . */

  while (c=fgetc_2(f_src),(c!=13)&&(c!=EOF))
  /*      ⥪. */
  {
   len_str++;

   /* ᫨ ⥪騩 ᨬ - ஡,   ⮬  ப
        ࠧࢠ;   ஡. */

   if (c==' ') cut_str=ftell_1(f_src)-1;

   /* ᫨  ப ॢᨫ ᨬ,   ⮬ 
      ,  ஬ ப   ࠧࢠ,  뤠
       ନ㥬 䠩  ப  砫  
      ࠧ뢠  ⥬   ப; ᫥ ⮣ 
      砫 ப  室 䠩 -   ᫥ ⮣
      ஡,   ࠧ. */

   if ((len_str>text_width)&&(cut_str!=-1))
   {
    fseek_1 (f_src,begin_str,SEEK_SET);
    for (i=begin_str;i<cut_str;i++)
    {
     fputc_1(fgetc_2(f_src),f_dst);
    }
    fputc_1 (13,f_dst);
    fputc_1 (10,f_dst);
    begin_str=cut_str+1;
    fseek_1 (f_src,begin_str,SEEK_SET);
    len_str=0;
    first_str=0;
    cut_str=-1;
   }
  }

  /* 諨   . ᫨  ⮪ ப
     (len_str!=0),  뢮     ப. */

  if (len_str!=0)
  {
   long temp=ftell_1(f_src);         /*  . */
   fseek_1 (f_src,begin_str,SEEK_SET);
   for (i=0;i<len_str-first_str*text_indent;i++)
   {
    fputc_1(fgetc_2(f_src),f_dst);
   }
   fseek_1 (f_src,temp,SEEK_SET);    /* ⠭ . */
   fputc_1 (13,f_dst);
   fputc_1 (10,f_dst);
  }

 }  /*   横. */

/* ==================  ⥪ ࠡ⠭ ================== */

 fcloseall_1 ();
 printf ("\nOK!\n\n");
 exit (0);
}

/* =============================================================
   㭪 fgetc_2 - ᫨  䠩 f  ⥪饩 樨 室
    ⮢ 13,10,  㭪 ⠥    頥
   13,  ⠥    頥  祭.
 ============================================================ */

int fgetc_2 (FILE* f)
{
 int c;
 c=fgetc_1(f);
 if (c==13)
 {
  c=fgetc_1(f);
  if (c!=10) ungetc_1(c,f);
  return 13;
 }
 return c;
}

/* =============================================================
     㭪権  ࠡ  䠩 (fopen,
   fcloseall, fgetc, ungetc, fputc, ftell, fseek).  訡
   뢠 믮 ணࠬ,  ᮮ⢥饥
   ᮮ饭; ⠪ ࠧ, ᫥ 맮  㭪権  
   ஢, 뫠  訡.
 ============================================================ */

FILE* fopen_1 (char* name, char* mode)
{
 FILE* f;
 char* s;
 char* s1="read";
 char* s2="write";

 f=fopen(name,mode);
 if (f==NULL)
 {
  if (mode[0]=='r') s=s1; else s=s2;
  printf ("\nCan't open file \"%s\" for %s!\n\n",name,s);
  exit (1);
 }
 return (f);
}

void fcloseall_1 ()
{
 if (fcloseall()==EOF)
 {
  printf ("\nClose error!\n\n"); exit (1);
 }
}

int fgetc_1 (FILE* f)
{
 int c;
 c=fgetc(f);
 if ferror(f) {printf ("\nRead error!\n\n"); exit (1);}
 return c;
}

void ungetc_1 (int c, FILE* f)
{
 if (ungetc(c,f)==EOF)
 {
  printf ("\nUNGETC error!\n\n"); exit (1);
 }
}

void fputc_1 (int c, FILE* f)
{
 if (fputc(c,f)==EOF) {printf ("\nWrite error!\n\n"); exit (1);}
}

long ftell_1 (FILE* f)
{
 long a;
 a=ftell(f);
 if (a==-1L) {printf ("\nFTELL error!\n\n"); exit (1);}
}

void fseek_1 (FILE* f, long offset, int whence)
{
 if (fseek(f,offset,whence)!=0)
 {printf ("\nPosition error!\n\n"); exit (1);}
}


ਨ


     樨 ⮩ ணࠬ ।⢥  ।
Turbo C   exe-䠩.     ⪨
com-䠩, ᫨ ᯮ짮 騬  Turbo C ஬
"tcc.exe".  ਢ  ப  맮 ⮣
 ( "c:\work\tc2" , 筮,  ⠢
᢮   ⠫ Turbo C):

c:\work\tc2\tcc.exe -O -Z -mt -lt -Ic:\work\tc2\include -Lc:\work\tc2\lib txt_form.c

    樨 "-O"  "-Z"  ⮩ ப - ᮮ⢥⢥ 祭
⨬樨 室  祭 ⨬樨 ᯮ짮
ॣ஢,  ⠪ ᯮᮡ 㬥襭 ࠧ
ᯮ塞 䠩 ணࠬ.
    ⮡  㬥 ࠧ,  ᯮ짮 ᢮
࠭塞 ஬ ᯮ塞 䠩 UPX
(http://upx.sourceforge.net),   ᦨ DOS-䠩
 ଠ COM  EXE (⨬, 筮,   
࠭稢).  ᯮ ᫥   ᠭ ⮩
  UPX - 1.24. 稢 㪠  㬥樨 UPX 
⮬,   ᨬ쭮 ⥯ ᦠ,  ᮧ 
䠩 "compress.bat", ᮤঠ騩   ( 
ᦨ 䠩 ᢮ ⮤):

upx --best --crp-ms=999999 --nrv2b --8086 -o result_2b.com txt_form.com
upx --best --crp-ms=999999 --nrv2d --8086 -o result_2d.com txt_form.com

    ᫥ ᪠ ⮣  䠩 UPX ᮧ  ᦠ
䠩 - "result_2b.com"  "result_2d.com".    
訩,  㣮 - . ᫥ ⮣ 室 䠩
"txt_form.com" 㦥  㦥,       
⠢襬 ᦠ⮬ 䠩. ᯮ塞 䠩 ணࠬ, 
뫮   web-࠭   ᠩ ୠ, 祭 
⠪ ࠧ.
     稬,  ᦠ⨨ com-䠩  
䠩 "result_2b.com"  "result_2d.com"   祬- ᥣ
ᮢ,    ᦠ⨨ exe-䠩 - ⢨⥫쭮
ࠧ砫.
       ਬ砭: 㪠뢠  맮 UPX 
"--8086" 㦭, ⮡ 塞  ᦠ⮩ ணࠬ 
ᯠ騪 ᯮ짮 ⮫쪮 樨  8086 -
⮣ ᦠ ணࠬ ᬮ ᯠ   
 ⠪ ஬ (ਬ,  IBM PC XT). ᫨  
     祭,   "--8086" 
 , ⠪ ࠧ,  - ᮪ ࠧ ᦠ⮩
ணࠬ (⠪  ᯠ騪 㤥  ⪨).  ⮬
砥  ᪠ ᦠ⮩ ணࠬ ॡ   
 286- ஬.


㪮⢮ 짮⥫


     祭 :  ᪥ ணࠬ   ப
᭠砫  㪠 ࠬ ଠ஢ (ࢮ ᫮ -
ਭ 砥 ⥪  ᨬ, .. ᨬ쭠 
ப; ஥ ᫮ - 稭 歮 㯠, .. ᪮쪮
஡    砫 ࢮ ப  ),
 ⥬ -  室 䠩 (  室  ⥪饬
⠫)   ନ㥬 䠩 ( ᮧ ⠪  ⥪饬
⠫). ᫨  ணࠬ  㬥⮢  
ࠢ  ⢮,   뤠  ࠢ 
⮬,  㬥    浪  㪠뢠.
    ਬ  ப:

txt_form 64 4 text_1.txt text_2.txt

      ࠡ ணࠬ ⮡ࠦ 浪 
ଠ㥬      ⠪ ࠧ 
,    ᫠. :)
    ணࠬ 頥 樮 ⥬  襭:
0 - ᯥ譮 襭, 1 - ந諠 訡  ࠡ 
䠩 (  ⠪ 訡 ணࠬ 뢮
ᮮ⢥饥 ᮮ饭  蠥 ᢮ ࠡ).
    ,  ᫨  ࠡ뢠 ⥪  ᫨誮
 ᫮ (, 祬 㪠  ᪥ ணࠬ
ਭ ⥪),   ᫮  㤥 ࠧࢠ,   ப
 ⨬ ᫮   ᨬ쭮.
     ࠡ뢠 䠩   ப   
ன ⮢ 13,10, ⠪   ⮬ 13 -  
 ଠ஢ txt-䠩  doc-䠩  ஢
Windows-1251 ( ⠪ doc-䠩,   , 
।⠢  ࠧ    ப, 稢
⮬ 13).
     ନ㥬 ⥪⮢ 䠩 ப 稢 ன
⮢ 13,10.





1. .騭. "⥩訩  DOC -> TXT". ". 
   " 10/2003.
