(c)  騭, ᪢

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

                ணࠬ  ࠧ१ 䠩
                

(".  " 5/2004)
ࠢ   .
 ᫥ ।஢: 2.11.2004.




    । 襬  ணࠬ,   ன
 ࠧ१  䠩   㪠 , 
  䠩 㪠 , 稭  㪠
ᬥ饭,  ய  X ⮢ 䠩,  ⮪
ࠧ१   ࠧ஬ Y ⮢,  ࠧ 䠩 
  X, Y, Z ⮢  ⮪...   㢨 ,
ணࠬ  ࠧ१ 䠩     ᫮
ࠧ.
    (,   ᠬ  "ࠧ१" -  ᮢᥬ 
ନ, ⠪  ணࠬ   室 䠩,  ᮧ
 䠩 -  室.)


㪮⢮ 짮⥫


     ᪥ ணࠬ  㪠   ப 
室 䠩,  砥 䠩 ( ७ - 
㤥 ନ஢ ⮬᪨)  , ।騥, 
 䠩 㤥 ࠧ  .

    ਬ:

file_cut.exe 1.txt aaa 0x735-,92163,*

    室 䠩 । 室騬  ⥪饬 ⠫,
⠬   ନ஢  室 䠩. ७ ࢮ
ନ஢ 䠩 㤥 "001", ண - "002",  ⠪ 
(᫨   999 ⥩,  ᠭ ⮫쪮 
999).
      , ।,   䠩 㤥
ࠧ  .   㪠   ᪮쪮 ;
᫨  ᪮쪮,  ࠧ 묨. ᥣ 
ᯮ짮  ࠧ ⨯ :

    n   -    n ⮢, 稭  ⥪饩
          樨  室 䠩 (᫨   室
          䠩 ⠫  n ⮢, ࠧ ᠭ 
          㤥 ࠢ ⠢襩  䠩);
    n-  - ய n ⮢  ⥪饩 樨  室
          䠩 (᫨   室 䠩 ⠫  n
          ⮢,  ய饭  ⠢訥 );
    n*  - 뢠   n ⮢, 稭  ⥪饩
          樨  室 䠩,   㤥 ⨣
           䠩 (⠪ ࠧ,  ᫥ ᠭ
              n);
    *   -  , 稭  ⥪饩 樨  室
          䠩    䠩.  , 祢, 
           ⮫쪮 ᫥.

       n - ᫮  1  0x7FFFFFFF (2147483647),
ᠭ  筮   ⭠筮  ( 
 ⭠筮  ᫮  । ᨬ
"0x", ॣ ᨬ   ᫠   祭).
    ணࠬ  ࠡ   64  (।
祭 ⠭ MAX_COMM  室 ⥪ ணࠬ), 
⮫쪮    ࠢ   - ࠭祭 
  ப  DOS.
     믮  浪  . । 믮
ࢮ  ⥪   室 䠩 -  砫
䠩.  ணࠬ 稢, ᫨  
믮,  ᫨ ⨣  室 䠩,  ᫨
㦥 ᠭ 999 ⥩ 䠩,  ᫨ ந諠 -
訡  ࠡ  䠩.
    ᥣ   ⨯    筮
ࠧࠧ ࠡ⪨ 䠩.  ਢ ᪮쪮
ਬ஢.

1.   500 ⮢ 䠩.

   500

2. , ய  500 ⮢   ⮪
   䠩.

   500-,*

3.   䠩, 稭  ᬥ饭 0x1000 
   砫   0x300 ⮢.

   0x1000-,0x300

4.  䠩   : 100, 200, 300 ⮢  ⮪.

   100,200,300,*

5.  䠩    10000 ⮢ (஬,  ,
   ᫥ ).

   10000*

6. ய 0x400 ⮢ 䠩,    123
   , ⮬ ய  0x100 ⮢   ⮪.

   0x400-,123,0x100-,*

     ,   祭 ᫮ ࠡ ணࠬ,
  - ⨯ .


室 ⥪ ணࠬ  Turbo C


/* =============================
     File: "file_cut.c"
     Compiler: Turbo C 2.0
 ============================= */

#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <string.h>
#include <limits.h>

void save_part (char *nameonly, long begin_part, long len_part);
int work_com (char* s);
int get_val (char **s, long *v);

#define MAX_COMM 64        /* ᨬ쭮 ⢮ . */

int n_comm=0;              /* ⢮ . */
int comm_type [MAX_COMM];  /*   (0-3). */
long comm_val [MAX_COMM];  /* ᫮   (᫨ ). */
int n_part=1;              /*  뢠 . */
long len_src, point_src=0; /*  室 䠩   㪠⥫. */
FILE *f_src, *f_dst;

void main (int argc, char *argv[])
{
 printf ("\nFile_Cut by Ivan Roshin, 28.03.2004.\n");
 if (argc!=4)
 {printf ("Syntax: file_cut.exe source-file destiny-file(without extension) commands\n"); exit(0);}
 /* ࠥ  . */
 if (work_com(argv[3])==1) {printf ("Incorrect commands!\n"); exit(0);}
 /* ஢塞, ⮡  ନ㥬 ⥩ 뫮   8 ᨬ. */
 if (strlen(argv[2])>8) {printf ("Error in destiny filename!\n"); exit(0);}
 f_src=fopen(argv[1],"rb"); /* 뢠 室 䠩. */
 if (f_src==NULL) {printf ("Can't open source file!\n"); exit(0);}
 len_src=filelength(fileno(f_src)); /* ।塞  室 䠩. */
 if (len_src==-1) {printf ("Can't define source length!\n"); exit(0);}

 /* 믮 㪠  (᫨  室 䠩  0). */
 if (len_src>0)
 {
  int i;
  for (i=0; i<n_comm; i++)
  {
   switch (comm_type[i])
   {
    case 0: /*   䠩  . */
     if (comm_val[i]>(len_src-point_src)) comm_val[i]=len_src-point_src;
     save_part (argv[2], point_src, comm_val[i]);
     point_src+=comm_val[i]; n_part++;
     break;
    case 1: /* ய  䠩  . */
     if (comm_val[i]>(len_src-point_src)) comm_val[i]=len_src-point_src;
     point_src+=comm_val[i];
     break;
    case 2: /*  ⥩  ,    䠩  饥
               ⢮ ᠭ ⥩  ⨣ 999. */
     do
     {
      if (comm_val[i]>(len_src-point_src)) comm_val[i]=len_src-point_src;
      save_part (argv[2], point_src, comm_val[i]);
      point_src+=comm_val[i]; n_part++;
     } while ((point_src<len_src)&&(n_part<=999));
     break;
    case 3: /*  ⪠ 䠩. */
     save_part (argv[2], point_src, len_src-point_src);
     point_src=len_src; n_part++;
   }
   /* ᫨ 䠩 㦥 ࠡ⠭   ᫥饩 뢠  
      ᨬ쭮 (999) - 稢 믮 . */
   if ((point_src==len_src)||(n_part>999)) break;
  }
 }
 if (fclose(f_src)!=0) printf ("Can't close source file!");
 printf("\n");
}

/* ==========================================================================
   㭪 save_part -  䠩-.
   室: nameonly -  뢠 䠩 ( ७),
         n_part -  뢠  (  ନ ७),
         begin_part - ᬥ饭   砫 室 䠩,
         len_part -  .
 ========================================================================= */

void save_part (char *nameonly, long begin_part, long len_part)
{
 long i;
 char dst_ext[4];
 char dst_name[12];

 /* ନ㥬  뢠 䠩  ७. */
 itoa (n_part,dst_ext,10);
 strcpy (dst_name, nameonly);
 strcat (dst_name, ".");
 for (i=strlen(dst_ext);i<3;i++) strcat (dst_name,"0");
 strcat (dst_name, dst_ext);

 /* 뢠. */
 printf ("Creating file: %s   ",dst_name);
 f_dst=fopen(dst_name,"wb");
 if (f_dst==NULL) {printf ("Can't open destiny file!\n"); exit(0);}
 fseek (f_src, begin_part, SEEK_SET);
 for (i=0;i<len_part;i++)
 {
  int c;
  c=fgetc(f_src); if (c==EOF) {printf ("Can't read from source file!\n"); exit(0);}
  if (fputc(c,f_dst)==EOF) {printf ("Can't write to destiny file!\n"); exit(0);}
 }
 if (fclose(f_dst)!=0) {printf ("Can't close destiny file!\n"); exit(0);}
 printf ("OK\n");
}

/* ==========================================================================
   㭪 work_com - ࠧ  .
   室: s - ப  .
   室: 0 - OK, 1 - 訡  ப  .
 ========================================================================= */

int work_com (char *s)
{
m1: /*  横. */
 /* ப   稫? */
 if (*s==0) {if (n_comm==0) return (1); else return (0);}

 /*  ᨢ     ? */
 if (n_comm==MAX_COMM) return (1);

 /*  砫  ᫠? */
 if ((*s>='0')&&(*s<='9'))
 {
  if (get_val(&s,&comm_val[n_comm])==1) return (1); /* 訡! */
  /* ஢塞,    ᫮ ᨬ "-"  "*",   ᨬ
      ⮣ ।塞 ⨯ . */
  if (*s=='-') {comm_type[n_comm]=1; s++; n_comm++; goto end_comm;}
  if (*s=='*') {comm_type[n_comm]=2; s++; n_comm++; goto end_comm;}
  comm_type[n_comm]=0; n_comm++; goto end_comm;
 }

 /*  "*"? */
 if (*s=='*') {comm_type[n_comm]=3; s++; n_comm++; goto end_comm;}

 /*   ᯮ. */
 return (1); /* 訡! */

 /*   稫. ஢塞: ⥯    
    ப ( 0),     㫥 ᨬ (砫 ᫥饩
    ). */
end_comm:
 if (*s==0) goto m1;
 if ((*s==',')&&(*(s+1)!=0)) {s++; goto m1;}
 return (1); /* 訡! */
}

/* ==========================================================================
   㭪 get_val - ८ࠧ ப   ᫠   ᫮.
   ᫮   ।⠢  筮  ⭠筮 
     室   0<x<=LONG_MAX.
   室: s -  㪠⥫  ப, v - , 㤠  ᫮.
   室: ᫨ ᫮  ४⭮, 㭪 頥 0, ᫮ 饭
     v,  㪠⥫  ப 㪠뢠   ᨬ ᫥ ᫠.
   ᫨ ᫮  ४⭮, 㭪 頥 1.
 ========================================================================= */

int get_val (char **s, long *v)
{
 int d;   /* ।  ᫠. */

 /* ᫨  ᨬ ப - '1'-'9',  砫 筮 ᫮. */

 if ((**s>='1')&&(**s<='9'))
 {
  /* 砫 筮 ᫮, ࠡ뢠. */
  *v=**s-'0';
loop_dec:
  (*s)++;
  if ((**s>='0')&&(**s<='9')) /* த ᫠ ( 0-9)? */
  {
   d=**s-'0';
   /* 塞    ( ᫥  ९). */
   if (*v>(LONG_MAX/10)) return (1); /* 訡! */ else *v*=10;
   if ((LONG_MAX-*v)<d) return (1);  /* 訡! */ else *v+=d;
   goto loop_dec;
  }
  return(0); /* OK! */
 }

 /* ᫨  ᨬ ப - '0',  砫 ⭠筮 ᫮
    (筮 ᫮   稭  ). */

 if (**s=='0')
 {
  (*s)++; if ((**s!='x')&&(**s!='X')) return (1); /* 訡! */
  *v=0;
loop_hex:
  (*s)++;
  if (((**s>='0')&&(**s<='9'))||((**s>='a')&&(**s<='f'))||((**s>='A')&&(**s<='F')))
  {
   /* 砥 祭 ।  ᫠. */
   if ((**s>='0')&&(**s<='9')) d=**s-'0';
   if ((**s>='a')&&(**s<='f')) d=**s-'a'+10;
   if ((**s>='A')&&(**s<='F')) d=**s-'A'+10;
   /* 塞    ( ᫥  ९). */
   if (*v>(LONG_MAX/16)) return (1); /* 訡! */ else *v*=16;
   if ((LONG_MAX-*v)<d) return (1);  /* 訡! */ else *v+=d;
   goto loop_hex;
  }
  /* ᫮ 稫. , ᫨ *v=0,   ᫮ ࠢ 0,   ᫥
      뫮   .    㣮 ⨬. */
  if (*v==0) return (1); /* 訡! */ else return (0); /* OK! */
 }

 /* ᫮  ப  㦥. */
 return (1); /* 訡! */
}


⥫쭠 ଠ


    ᫨   ,  믮   - ᪫
䠩  ⥩, - ,    ᤥ  
ᮢ᪮  "copy".   ப  㪠
ࠬ "/b" (筮 ᪫),  ᪫ 䠩 
㦭 浪, ᮥ  "+",   䠩-१.

    ਬ:

copy /b 1.txt+2.txt+3.txt all.txt

     ,  砥 䠩   ᮢ 
-  室 䠩,  ᮤন ⮣ 室
䠩   ﭮ,  믮   
訡!


।०


    ᠭ  ⮩  ணࠬ   ࠡ뢠
䠩,     ࠢ 2  (2147483648 ⮢).
  ⮬,  ᯮ㥬  ணࠬ 筠 㭪
 ।  䠩 (filelength) 頥 १
⨯ long,  ᨬ쭮 ⥫쭮 祭 ⮣ ⨯ 
Turbo C 2.0 ࠢ 0x7FFFFFFF (2147483647), .. 2  - 1. 
祭 ⨯ long ॡ  ⢥ 室 ࠬ 㭪
fseek, ᯮ㥬  ணࠬ  室  㦭 樨 
ࠡ뢠 䠩.
