
    Pi                        d Z ddlmZ ddlZddlmZmZ g dZ ej        dej	                  Z
 ej        d          Z ej        dej	                  ZddZdS )z
Awk command handler for Dippy.

Awk is safe for text processing, but -f flag runs scripts
and the program can contain output redirects.
    )annotationsN)ClassificationHandlerContext)awkgawkmawknawka  
    (?:print|printf)\s*[^}]*\s*      # print/printf followed by content
    (?:
        >\s*["']                      # > followed by quote (file redirect)
        |
        >>\s*["']                     # >> followed by quote (append redirect)
        |
        >\s*\(                        # > followed by ( (dynamic filename)
        |
        >>\s*\(                       # >> followed by ( (dynamic append)
        |
        >\s*\$                        # > followed by $ (variable filename)
    )
    z1(?:print|printf)\s*[^}]*\s*>>?\s*["']([^"']+)["']z
    (?:print|printf)\s*[^}]*\s*      # print/printf followed by content
    \|\s*["']                         # | followed by quote (pipe to command)
    ctxr   returnr   c                    | j         }|r|d         nd}|dd         D ]d}|dk    s|                    d          rt          d| d          c S |d	k    s|                    d
          rt          d| d          c S ed}d}|t          |          k     r||         }|                    d          rp|dv r|dz  }:|                    d          s|                    d          r|dz  }j|                    d          s|                    d          r|dz  }|dz  }|}	 |st          d|          S d|v rt          d| d          S t                              |          rt          d| d          S t                              |          rRt          t          	                    |                    }|rt          d| d|          S t          d| d          S t          d|          S )zCClassify awk command (no script files or output redirects is safe).r   r      Nz-faskz -f)descriptionz--filez--file=z --file-)-F-vz--field-separator   r   r   z--field-separator=allowzsystem(z	 system()z pipez	 redirect)r   redirect_targets)
tokens
startswithr   lenPIPE_PATTERNsearchFILE_REDIRECT_PATTERNtupleLITERAL_REDIRECT_PATTERNfindall)r
   r   basetprogramiliteral_targetss          ./root/projects/gits/Dippy/src/dippy/cli/awk.pyclassifyr%   3   s   ZF)6!99EDABBZ G G99T**9!%\\\BBBBBB==ALL33=!%5E5E5EFFFFFF  G	A
c&kk//1I<< 	555Qd## q||D'9'9 Q233 q||D7I7I QFA 9g48888 GeD1C1C1CDDDD 7## AeD@@@@ ##G,, I 8 @ @ I IJJ 		I!#...!0    "%5G5G5GHHHH't4444    )r
   r   r   r   )__doc__
__future__r   re	dippy.clir   r   COMMANDScompileVERBOSEr   r   r   r%    r&   r$   <module>r/      s     # " " " " " 				 4 4 4 4 4 4 4 4*** #
 J  & &2:<  
 rz J ;5 ;5 ;5 ;5 ;5 ;5r&   