
    bif                     X    d dl Z d dlZd dlZd dlmZmZ d Zd Zd Zedk(  r e        yy)    N)FileStrc                  x   t        j                  d      } | j                  dddd       | j                  ddd	d
       | j                  ddt        dd       | j                  dddd       | j                  ddt        d d       | j                  ddt        j
                         | j                         S )NzhOutput pieces of FILE to PREFIXaa, PREFIXab, ...; default size is 1000 lines, and default PREFIX is 'x'.)descriptionfile?-z'File to process, "-" for standard input)nargsdefaulthelpprefixXz"Output file prefix, default is "x"z-lz--linesi  z0Number of lines per output file, default is 1000)typer   r   z-tz--separator
z[Use SEP instead of newline as the record separator; '\0' (zero) specifies the NUL character)r   r   z-nz--numberz.Generate N output files based on size of inputz	--versionversion)actionr   )argparseArgumentParseradd_argumentintstringzilla__version__
parse_args)parsers    D/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cli/split.pyparse_argumentsr   	   s    $$~F c3-V   S/S   ?   k	   =   I{?V?VW    c                    	 |dk(  rd}| dk(  r(t        t        j                  j                               }nt	        |       }t        |      }|Qt        |      }||z  }t        |      D ]2  }	|	|z  }
|	|dz
  k  r|
|z   n|}||
| }| |	 }|j                  |       4 y d}d}	d}|t        |      k  rt        |      D ]  }|j                  ||dz         }|dk(  s n |dk(  r|t        |      k  rt        |      }|dk7  r||z
  nd}|dkD  r)|||dz    }| |	 }|j                  |       |	dz  }	|dz   }|t        |      k  ry y # t        $ r t        d|         Y y t        $ r#}t        d|        t        d	       Y d }~y d }~ww xY w)
Nz\0 r	      r   zNo such file: zAn error occurred: z2Usage example: split.py [-l LINES] [file] [prefix])r   sysstdinreadr   lenrangewrite_tofindFileNotFoundErrorprint	Exception)	file_pathlines_per_fileoutput_prefix	separatornumber_of_filesfile_contentsfile_mappedtotal_length
chunk_size	file_partstartendcurrent_sliceoutput_pathcurrent_positionnewline_position_section_lengthes                      r   
split_filer?   +   s   4DI		 01My/K,M&}-L%8J"?3 	4	!J. !?Q#66 J&% 
 !.eC 8!.	{;&&{3	4 	]!33>* #0#5#5iAQTUAU#V #r)
  2%*:S=O*O#&}#5  8H27M #33ST  ! -.>AQTUAU V!.	{;&&{3Q	#3a#7 ' ]!33*  ,yk*+ D#A3'(BCCDs+   BE <E A)E F!F)FFc                      t               } t        | j                  | j                  | j                  | j
                  | j                         y )N)r   r?   r   linesr   r/   number)argss    r   mainrD   c   s.    Dtyy$**dkk4>>4;;Or   __main__)	r   r"   r   r   r   r   r?   rD   __name__ r   r   <module>rH      s:     
  !D5DpP
 zF r   