B
    18™\–	  ã               @   s€   d Z ddlZddlZdejdd…  Zdejdd…  ZdZedfdd	„Zd
d„ ZdZ	dZ
e
fdd„Zdd„ Zedkr|eƒ  dS )aE  nm2def.py

Helpers to extract symbols from Unix libs and auto-generate
Windows definition files from them. Depends on nm(1). Tested
on Linux and Solaris only (-p option to nm is for Solaris only).

By Marc-Andre Lemburg, Aug 1998.

Additional notes: the output of nm is supposed to look like this:

acceler.o:
000001fd T PyGrammar_AddAccelerators
         U PyGrammar_FindDFA
00000237 T PyGrammar_RemoveAccelerators
         U _IO_stderr_
         U exit
         U fprintf
         U free
         U malloc
         U printf

grammar1.o:
00000000 T PyGrammar_FindDFA
00000034 T PyGrammar_LabelRepr
         U _PyParser_TokenNames
         U abort
         U printf
         U sprintf

...

Even if this isn't the default output of your nm, there is generally an
option to produce this format (since it is the original v7 Unix format).

é    Nzlibpython%d.%d.aé   zPython%d%d.dllznm -p -g %s)ÚTÚCÚDc       	      C   s‚   t  t|  ¡ ¡ }dd„ |D ƒ}i }xX|D ]P}t|ƒdks*d|krDq*| ¡ }t|ƒdkrZq*|\}}}||krnq*||f||< q*W |S )Nc             S   s   g | ]}|  ¡ ‘qS © )Ústrip)Ú.0Úsr   r   úT/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Tools/scripts/nm2def.pyú
<listcomp>.   s    zsymbols.<locals>.<listcomp>r   ú:é   )ÚosÚpopenÚNMÚ	readlinesÚlenÚsplit)	ÚlibÚtypesÚlinesÚsymbolsÚlineÚitemsÚaddressÚtypeÚnamer   r   r
   r   +   s    

r   c             C   sz   g }g }x>|   ¡ D ]2\}\}}|dkr6| d| ¡ q| d| ¡ qW | ¡  | d¡ | ¡  d |¡d d |¡ S )N)r   r   ú	Ú z DATA
Ú
)r   ÚappendÚsortÚjoin)r   ÚdataÚcoder   Úaddrr   r   r   r
   Úexport_list<   s    
r&   zEXPORTS
%s
r   c             C   sJ   xDt |  ¡ ƒD ]4}|d d… dksB|d d… dkr4q||kr| |= qW d S )Nr   ÚPyr   Ú_Py)ÚlistÚkeys)r   Úspecialsr   r   r   r
   Úfilter_PythonU   s
     r,   c              C   s8   t tƒ} t| ƒ t| ƒ}tj}| t| ¡ | ¡  d S )N)	r   Ú	PYTHONLIBr,   r&   ÚsysÚstdoutÚwriteÚDEF_TEMPLATEÚclose)r	   ZexportsÚfr   r   r
   Úmain]   s    r4   Ú__main__)Ú__doc__r   r.   Úversion_infor-   ZPC_PYTHONLIBr   r   r&   r1   ZSPECIALSr,   r4   Ú__name__r   r   r   r
   Ú<module>$   s   	