├── README ├── Makefile ├── ctopy.spec ├── COPYING ├── ctopy.1 ├── ctopy.xml └── ctopy /README: -------------------------------------------------------------------------------- 1 | README for ctopy 2 | 3 | ctopy automates the parts of translating C source code to Python 4 | source code that are difficult for a human but easy for a 5 | machine. This allows a human programmer to concentrate on the 6 | nontrivial parts of the translation. 7 | 8 | ctopy is issued under the BSD license, 9 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for the ctopy project 2 | 3 | VERS=$(shell sed $(MANDIR)/ctopy.1.gz 16 | 17 | ctopy.1: ctopy.xml 18 | xmlto man ctopy.xml 19 | ctopy.html: ctopy.xml 20 | xmlto html-nochunks ctopy.xml 21 | 22 | ctopy-$(VERS).tar.gz: $(SOURCES) 23 | @mkdir ctopy-$(VERS) 24 | @cp $(SOURCES) ctopy-$(VERS) 25 | @tar -czf ctopy-$(VERS).tar.gz ctopy-$(VERS) 26 | @rm -fr ctopy-$(VERS) 27 | 28 | makeregress: 29 | ctopy ctopy.py 30 | 31 | regress: 32 | @ctopy ctopy.py-trial 33 | @if diff -u ctopy.py ctopy.py-trial; \ 34 | then echo "Test succeeded"; \ 35 | else echo "Test failed"; fi 36 | @rm -f ctopy.py-trial 37 | 38 | clean: 39 | rm -f *.html *.1 *.pyc ctopy.py-trial SHIPPER.* 40 | 41 | dist: ctopy-$(VERS).tar.gz 42 | 43 | release: ctopy-$(VERS).tar.gz ctopy.html 44 | shipper -u -m -t; make clean 45 | 46 | 47 | -------------------------------------------------------------------------------- /ctopy.spec: -------------------------------------------------------------------------------- 1 | Name: ctopy 2 | Version: 1.1 3 | Release: 1 4 | URL: http://www.catb.org/~esr/ctopy/ 5 | Source0: %{name}-%{version}.tar.gz 6 | License: BSD 7 | Group: Development 8 | Summary: a quick and dirty (but nevertheless effective) C to Python translator 9 | BuildRoot: %{_tmppath}/%{name}-root 10 | BuildArch: noarch 11 | 12 | %description 13 | ctopy automates the parts of translating C source code to Python 14 | source code that are difficult for a human but easy for a 15 | machine. This allows a human programmer to concentrate on the 16 | nontrivial parts of the translation. 17 | 18 | %prep 19 | %setup -q 20 | 21 | %build 22 | make %{?_smp_mflags} ctopy.1 23 | 24 | %install 25 | [ "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != / ] && rm -rf "$RPM_BUILD_ROOT" 26 | mkdir -p "$RPM_BUILD_ROOT"%{_bindir} 27 | mkdir -p "$RPM_BUILD_ROOT"%{_mandir}/man1/ 28 | cp ctopy "$RPM_BUILD_ROOT"%{_bindir} 29 | cp ctopy.1 "$RPM_BUILD_ROOT"%{_mandir}/man1/ 30 | 31 | %clean 32 | [ "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != / ] && rm -rf "$RPM_BUILD_ROOT" 33 | 34 | %files 35 | %doc README COPYING 36 | %defattr(-,root,root,-) 37 | %{_mandir}/man1/ctopy.1* 38 | %{_bindir}/ctopy 39 | 40 | %changelog 41 | * Tue Oct 18 2010 Eric S. Raymond - 1.1-1 42 | - Add a regression test. 43 | 44 | * Wed Oct 18 2006 Eric S. Raymond - 1.0-1 45 | - Initial build. 46 | 47 | 48 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | ctopy is distributec under the BSD license. 2 | 3 | Copyright(c) 2006 Eric S. Raymond. All rights reserved. 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions 8 | are met: 9 | 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | * Neither the name Intel Corporation nor the names of its 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | -------------------------------------------------------------------------------- /ctopy.1: -------------------------------------------------------------------------------- 1 | '\" t 2 | .\" Title: ctopy 3 | .\" Author: [see the "AUTHORS" section] 4 | .\" Generator: DocBook XSL Stylesheets v1.75.2 5 | .\" Date: 10/19/2010 6 | .\" Manual: Development Tools 7 | .\" Source: ctopy 8 | .\" Language: English 9 | .\" 10 | .TH "CTOPY" "1" "10/19/2010" "ctopy" "Development Tools" 11 | .\" ----------------------------------------------------------------- 12 | .\" * Define some portability stuff 13 | .\" ----------------------------------------------------------------- 14 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 15 | .\" http://bugs.debian.org/507673 16 | .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html 17 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 18 | .ie \n(.g .ds Aq \(aq 19 | .el .ds Aq ' 20 | .\" ----------------------------------------------------------------- 21 | .\" * set default formatting 22 | .\" ----------------------------------------------------------------- 23 | .\" disable hyphenation 24 | .nh 25 | .\" disable justification (adjust text to left margin only) 26 | .ad l 27 | .\" ----------------------------------------------------------------- 28 | .\" * MAIN CONTENT STARTS HERE * 29 | .\" ----------------------------------------------------------------- 30 | .SH "NAME" 31 | ctopy \- a quick and dirty C to Python translator) 32 | .SH "SYNOPSIS" 33 | .HP \w'\fBctopy\fR\ 'u 34 | \fBctopy\fR 35 | .SH "DESCRIPTION" 36 | .PP 37 | ctopy automates the parts of translating C source code to Python source code that are difficult for a human but easy for a machine\&. This allows a human programmer to concentrate on the parts of the translation that actually require human attention\&. 38 | .PP 39 | ctopy uses regular expressions rather than actually parsing the C, so it is easily confused by syntactically invalid C or even irregular indentation styles\&. On the other hand, this approach makes it easier to preserve the location of comments\&. 40 | .PP 41 | ctopy relies on the fact that C and Python have fundamentally similar constant and expression syntax; the only parts of C expressions that don\*(Aqt map over in a completely trivial way are ?: and comma expressions\&. These will be passed through unaltered\&. Exception: passing a comma expression as an argument to a C library function call may confuse ctopy into translating the function call incorrectly\&. 42 | .PP 43 | ctopy also relies on the fact that C is normally indented in a way that indicates its block structure\&. It expects code to be indented in one of the canonical (K&R or Berkeley/C++) styles\&. Running it on GNU\-style code is not recommended\&. To avoid problems, run your code through 44 | \fBindent\fR(1) 45 | before handing it to copy; 46 | \fBindent \-orig\fR 47 | or 48 | \fBindent \-kr\fR 49 | should produce good results\&. 50 | .PP 51 | Finally, ctopy relies on the fact that C and Python have several control structures that are both syntactically and semantically similar\&. It translates if/else, while, and do/while (the termination clause in each do/while will require re\-indenting)\&. It doesn\*(Aqt try to translate switch/case statements\&. 52 | .PP 53 | ctopy will translate C for loops that map directly to a Python loop of the form "for var in range(maxval)" or "for var in range(minval, maxval)", where minval and maxval may be expressions\&. More complex loops it will pass through unaltered\&. It recognizes C idioms for looping forever and translates those into "while True:"\&. 54 | .PP 55 | ctopy throws away all type information and removes all variable declarations that don\*(Aqt have initializers\&. It maps the C \*(Aq\->\*(Aq operator as well as the C \*(Aq\&.\*(Aq operator to Python \*(Aq\&.\*(Aq; this works because in Python all non\-scalars are passed by reference\&. The C99 boolean constants \*(Aqtrue\*(Aq and \*(Aqfalse\*(Aq are mapped to Python \*(AqTrue\*(Aq and \*(AqFalse\*(Aq 56 | .PP 57 | ctopy does not translate C structure and union declarations\&. It cannot tell the member declarations in these from variable declarations, and will try to remove them\&. Nor will ctopy translate most structure initializations correctly\&. Important exception: it can translate one\-dimensional array initializers containing only scalars into Python tuples\&. 58 | .PP 59 | ctopy does translate preprocessor defines and certain simple uses of enum types into Python\&. It also translates preprocessor macros with arguments into Python functions\&. Preprocessor macros that expand to syntactically invalid C fragments will be heedlessly translated into broken Python\&. 60 | .PP 61 | ctopy knows a large number of mappings between C library headers and Python standard library modules, and applies them\&. Where possible, it translates C library functions to equivalent Python standard library calls\&. It emits warnings to standard error when calling conventions don\*(Aqt match\&. 62 | .PP 63 | You can give ctopy hints\&. A hint may be a line in a file pulled in by the \-h option, or tokens in a source file comment beginning with \*(Aq$ctopy\*(Aq\&. Available hints are as follows: 64 | .PP 65 | type 66 | .RS 4 67 | Treat as a scalar type, not requiring initialization except by first assignment\&. 68 | .RE 69 | .PP 70 | class 71 | .RS 4 72 | Treat name as a class; variables of this type must be initialized by calling the class\*(Aqs contructor and assigning the returned value to the variable\&. 73 | .RE 74 | .PP 75 | stringify 76 | .RS 4 77 | When this name occurs surrounded by word boundaries, put string quotes around it\&. Useful for translating enumerated\-type values into string literals, which Python has as a first\-class type\&. 78 | .RE 79 | .PP 80 | printflike 81 | .RS 4 82 | declarates that a function is like printf; its string arguments containing, if any, should be treated like printf formats and their arg lists replaced with % followed by a tuple containing the args\&. 83 | .RE 84 | .SH "AUTHORS" 85 | .PP 86 | Eric S\&. Raymond \&. See ESR\*(Aqs home page at 87 | \m[blue]\fBhttp://www\&.catb\&.org/~esr/\fR\m[] 88 | for updates and other resources\&. 89 | .SH "BUGS" 90 | .PP 91 | 92 | -------------------------------------------------------------------------------- /ctopy.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | ctopy 7 | 1 8 | Oct 20 2006 9 | ctopy 10 | ctopy 11 | Development Tools 12 | 13 | 14 | ctopy 15 | a quick and dirty C to Python translator) 16 | 17 | 18 | 19 | 20 | ctopy 21 | 22 | 23 | 24 | 25 | DESCRIPTION 26 | 27 | ctopy automates the parts of translating C source code to Python 28 | source code that are difficult for a human but easy for a 29 | machine. This allows a human programmer to concentrate on the 30 | parts of the translation that actually require human attention. 31 | 32 | ctopy uses regular expressions rather than actually parsing the 33 | C, so it is easily confused by syntactically invalid C or even 34 | irregular indentation styles. On the other hand, this approach makes 35 | it easier to preserve the location of comments. 36 | 37 | ctopy relies on the fact that C and Python have fundamentally 38 | similar constant and expression syntax; the only parts of C 39 | expressions that don't map over in a completely trivial way are ?: and 40 | comma expressions. These will be passed through unaltered. 41 | Exception: passing a comma expression as an argument to a C library 42 | function call may confuse ctopy into translating the function call 43 | incorrectly. 44 | 45 | ctopy also relies on the fact that C is normally indented in a 46 | way that indicates its block structure. It expects code to be 47 | indented in one of the canonical (K&R or Berkeley/C++) styles. 48 | Running it on GNU-style code is not recommended. To avoid problems, 49 | run your code through 50 | indent1 51 | before handing it to copy; indent -orig or 52 | indent -kr should produce good results. 53 | 54 | Finally, ctopy relies on the fact that C and Python have several 55 | control structures that are both syntactically and semantically 56 | similar. It translates if/else, while, and do/while (the termination 57 | clause in each do/while will require re-indenting). It doesn't try to 58 | translate switch/case statements. 59 | 60 | ctopy will translate C for loops that map directly to a Python 61 | loop of the form "for var in range(maxval)" or "for var in 62 | range(minval, maxval)", where minval and maxval may be expressions. 63 | More complex loops it will pass through unaltered. It recognizes C 64 | idioms for looping forever and translates those into "while 65 | True:". 66 | 67 | ctopy throws away all type information and removes all variable 68 | declarations that don't have initializers. It maps the C '->' 69 | operator as well as the C '.' operator to Python '.'; this works 70 | because in Python all non-scalars are passed by reference. The C99 71 | boolean constants 'true' and 'false' are mapped to Python 'True' and 72 | 'False' 73 | 74 | ctopy does not translate C structure and union declarations. It 75 | cannot tell the member declarations in these from variable 76 | declarations, and will try to remove them. Nor will ctopy translate 77 | most structure initializations correctly. Important exception: it can 78 | translate one-dimensional array initializers containing only scalars 79 | into Python tuples. 80 | 81 | ctopy does translate preprocessor defines and certain simple 82 | uses of enum types into Python. It also translates preprocessor 83 | macros with arguments into Python functions. Preprocessor macros that 84 | expand to syntactically invalid C fragments will be heedlessly 85 | translated into broken Python. 86 | 87 | ctopy knows a large number of mappings between C library headers 88 | and Python standard library modules, and applies them. Where possible, 89 | it translates C library functions to equivalent Python standard 90 | library calls. It emits warnings to standard error when calling 91 | conventions don't match. 92 | 93 | You can give ctopy hints. A hint may be a line in a file pulled in 94 | by the -h option, or tokens in a source file comment beginning with 95 | '$ctopy'. Available hints are as follows: 96 | 97 | 98 | 99 | type <name> 100 | Treat <name> as a scalar type, not requiring 101 | initialization except by first assignment. 102 | 103 | 104 | class <name> 105 | Treat name as a class; variables of this type 106 | must be initialized by calling the class's contructor 107 | and assigning the returned value to the variable. 108 | 109 | 110 | stringify <name> 111 | When this name occurs surrounded by word boundaries, 112 | put string quotes around it. Useful for translating enumerated-type 113 | values into string literals, which Python has as a first-class 114 | type. 115 | 116 | 117 | printflike <name> 118 | declarates that a function is like printf; its string 119 | arguments containing, if any, should be treated like printf formats 120 | and their arg lists replaced with % followed by a tuple containing the 121 | args. 122 | 123 | 124 | 125 | 126 | AUTHORS 127 | Eric S. Raymond <esr@snark.thyrsus.com>. See ESR's home 128 | page at http://www.catb.org/~esr/ for 130 | updates and other resources. 131 | 132 | 133 | BUGS 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /ctopy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | ctopy -- a quick and dirty C-to-Python translator. 4 | 5 | Libraries not mapped that theoretically could be: curses.panel, dbm, 6 | md5, popen2, pty, resource, sha, subprocess, syslog, time. Some of these 7 | would need more elaborate machinery for method translation. 8 | 9 | Python library bindings are as of 2.6a0. 10 | """ 11 | import sys, re 12 | 13 | stringify = [] 14 | 15 | printflike = ["printf", "sprintf", "vfprintf", 16 | "printw", "mvprintw", "wprintw", "mvwprintw"] 17 | 18 | types = ["void", "int", "bool", "char", "short", "double", "long", "float", 19 | "time_t", "FILE", "WINDOW", "uint8_t", "uint16_t", "uint32_t"] 20 | 21 | shorthands = { 22 | 'id' : r"[a-zA-Z_][a-zA-Z0-9._]*", 23 | 'exp' : r"[a-zA-Z0-9._\-+\*/]+", 24 | 'type' : r"\b" + r"\b|\b".join(types) + r"\b", 25 | 'class' : r"\b__dummyclass__\b", 26 | 'ind' : r"(\n[ \t]*)", # Whitespace at start of line 27 | 'eol' : r"[ \t]*(?=\n|\Z)", # Whitespace to end of line or comment 28 | 'arg' : r"([^,]+),\s*", # initial or medial argument 29 | 'farg' : r"([^)]+)", # final argument 30 | } 31 | 32 | # C functions and constants to be mapped into Python standard library bindings. 33 | funmappings = ( 34 | # File object methods (from C stdlib). 35 | (r"\bfclose\(%(farg)s\)", r"\1.close()", None), 36 | (r"\bfflush\(%(farg)s\)", r"\1.flush()", None), 37 | (r"\bfileno\(%(farg)s\)", r"\1.fileno()", None), 38 | (r"\bfprintf\(%(arg)s\)", r"\1.write()", None), 39 | (r"\bfseek\(%(arg)s", r"\1.seek(", None), 40 | (r"\bftell\(%(farg)s\)", r"\1.tell()", None), 41 | (r"\bftruncate\(%(arg)s", r"\1.truncate(", None), 42 | # Python atexit library 43 | (r"\batexit\(", r"atexit.register(", "atexit"), 44 | # Python crypt library 45 | (r"\bcrypt\(", r"crypt.crypt(", "crypt"), 46 | # Curses library. Below are all function calls listed in the 47 | # ncurses(3) version 5.5 manual page in the order they are listed. 48 | # The ones we don't translate have been left in as comments, 49 | # pending future improvements. The largest category of things not 50 | # translated is the wide-character support; it's possible there's 51 | # an easy way to map this, but I don't have a need for it. 52 | # Mappings marked "EXCEPTION" violate the convention that the C names 53 | # of window methods begin with 'w'. Mappings marked "NONTRIVIAL" 54 | # map a C entry point into a Python entry point with a different name, 55 | # usually to throw away a length argument Python doesn't need or vecause 56 | # the Python method handles a position as the first two arguments. 57 | (r"\bCOLOR_PAIR\(", "curses.color_pair(", "curses"), 58 | (r"\bPAIR_NUMBER\(", "curses.pair_number(", "curses"), 59 | #_nc_tracebits curs_trace(3X)* 60 | #_traceattr curs_trace(3X)* 61 | #_traceattr2 curs_trace(3X)* 62 | #_tracechar curs_trace(3X)* 63 | #_tracechtype curs_trace(3X)* 64 | #_tracechtype2 curs_trace(3X)* 65 | #_tracedump curs_trace(3X)* 66 | #_tracef curs_trace(3X)* 67 | #_tracemouse curs_trace(3X)* 68 | #add_wch curs_add_wch(3X) 69 | #add_wchnstr curs_add_wchstr(3X) 70 | #add_wchstr curs_add_wchstr(3X) 71 | (r"\baddch\(", r"stdscr.addch(", "curses"), 72 | #addchnstr curs_addchstr(3X) 73 | #addchstr curs_addchstr(3X) 74 | (r"\baddnstr\(", r"stdscr.addnstr(", "curses"), 75 | #addnwstr curs_addwstr(3X) 76 | (r"\baddstr\(", r"stdscr.addstr(", "curses"), 77 | #addwstr curs_addwstr(3X) 78 | #assume_default_colors default_colors(3X)* 79 | #attr_get curs_attr(3X) 80 | (r"\battr_off\(", r"stdscr.attrof(", r"curses"), 81 | (r"\battr_on\(", r"stdscr.attron(", r"curses"), 82 | (r"\battr_set\(", r"stdscr.attrset(", r"curses"), 83 | (r"\battroff\(", r"stdscr.attrof(", r"curses"), 84 | (r"\battron\(", r"stdscr.attron(", r"curses"), 85 | (r"\battrset\(", r"stdscr.attrset(", r"curses"), 86 | (r"\bbaudrate\(", r"curses.baudrate(", r"curses"), 87 | (r"\bbeep\(", r"curses.beep(", r"curses"), 88 | (r"\bbkgd\(", r"stdscr.bkgd(", r"curses"), 89 | (r"\bbkgdset\(", r"stsdcr.bkgdset(", r"curses"), 90 | #bkgrnd curs_bkgrnd(3X) 91 | #bkgrndset curs_bkgrnd(3X) 92 | (r"\bborder\(", r"stdscr.border(", r"curses"), 93 | #border_set curs_border_set(3X) 94 | (r"\bbox\(%(arg)s", r"\1.box(", r"curses"), # EXCEPTION 95 | #box_set curs_border_set(3X) 96 | (r"\bcan_change_color\(", r"curses.can_change_color(", r"curses"), 97 | (r"\bcbreak\(", r"curses.cbreak(", r"curses"), 98 | #chgat curs_attr(3X) 99 | (r"\bclear\(", r"stdscr.clear(", r"curses"), 100 | (r"\bclearok\(", r"stdscr.clearok(", r"curses"), 101 | (r"\bclrtobot\(", r"stdscr.clrtobot(", r"curses"), 102 | (r"\bclrtoeol\(", r"stdscr.clrtoeol(", r"curses"), 103 | (r"\bcolor_content\(", r"curses.color_content(", r"curses"), 104 | #color_set curs_attr(3X) 105 | #copywin curs_overlay(3X) 106 | (r"\bcurs_set\(", r"curses.curs_set(", r"curses"), 107 | #curses_version curs_extend(3X)* 108 | (r"\bdef_prog_mode\(", r"curses.def_prog_mode(", r"curses"), 109 | (r"\bdef_shell_mode\(", r"curses.def_shell_mode(", r"curses"), 110 | #define_key define_key(3X)* 111 | #del_curterm curs_terminfo(3X) 112 | (r"\bdelay_output\(", r"curses.delay_output(", r"curses"), 113 | (r"\bdelch\(", r"stdscr.delch(", r"curses"), 114 | (r"\bdeleteln\(\)", r"stdscr.deleteln()", r"curses"), 115 | #delscreen curs_initscr(3X) 116 | #delwin curs_window(3X) 117 | (r"\bderwin\(%(arg)s", r"\1.derwin(", "curses"), # EXCEPTION 118 | (r"\bdoupdate\(\)", r"curses.doupdate()", "curses"), 119 | #dupwin curs_window(3X) 120 | (r"\becho\(", r"curses.echo(", "curses"), 121 | #echo_wchar curs_add_wch(3X) 122 | (r"\bechochar\(", r"stdscr.echochar(", "curses"), 123 | (r"\bendwin\(", r"curses.endwin(", "curses"), 124 | (r"\berase\(", r"stdscr.erase(", "curses"), 125 | #erasechar curs_termattrs(3X) 126 | #erasewchar curs_termattrs(3X) 127 | (r"\bfilter\(\)", r"curses.filter()", "curses"), 128 | (r"\bflash\(\)", r"curses.flash()", "curses"), 129 | (r"\bflushinp\(\)", r"curses.flushinp()", "curses"), 130 | #get_wch curs_get_wch(3X) 131 | #get_wstr curs_get_wstr(3X) 132 | (r"\bgetbegyx\(%(arg)s%(arg)s%(farg)s\)", # EXCEPTION 133 | r"(\2, \3) = \1.getbegyx()", "curses"), 134 | (r"\bgetbkgd\(", r"\1.getbkgd(", "curses"), # EXCEPTION 135 | #getbkgrnd curs_bkgrnd(3X) 136 | #getcchar curs_getcchar(3X) 137 | (r"\bgetch\(", r"stdscr.getch(", "curses"), 138 | (r"\bgetmaxyx\(%(arg)s", r"\1.getmaxyx(", "curses"), # EXCEPTION 139 | (r"\bgetmouse\(%(farg)s\)", r"\1 = curses.getmouse()", "curses"), 140 | #getn_wstr curs_get_wstr(3X) 141 | (r"\bgetnstr\(%(arg)s%(farg)s\)", # NONTRIVIAL 142 | r"\1 = stdscr.getstr()", "curses"), 143 | (r"\bgetparyx\(%(arg)s%(arg)s%(farg)s\)", # EXCEPTION 144 | r"(\2, \3) = \1.getparyx()", "curses"), 145 | (r"\bgetsyx\(%(arg)s%(farg)s\)", r"(\1, \2) = curses.getsyx()", "curses"), 146 | (r"\bgetstr\(\)", r"stdscr.getstr()", "curses"), 147 | (r"\bgetyx\(%(arg)s%(arg)s%(farg)s\)", #EXCEPTION 148 | r"(\2, \3) = \1.getyx()", "curses"), 149 | (r"\bgetwin\(", r"curses.getwin(", "curses"), 150 | (r"\bhalfdelay\(", r"curses.halfdelay(", "curses"), 151 | (r"\bhas_colors\(", r"curses.has_colors(", "curses"), 152 | (r"\bhas_ic\(", r"curses.has_ic(", "curses"), 153 | (r"\bhas_il\(", r"curses.has_il(", "curses"), 154 | (r"\bhas_key\(", r"curses.has_key(", "curses"), 155 | (r"\bhline\(", r"stdscr.hline(", "curses"), 156 | #hline_set curs_border_set(3X) 157 | (r"\bidcok\(%(arg)s", r"\1.idcok(", "curses"), # EXCEPTION 158 | (r"\bidlok\(%(arg)s", r"\1.idlok(", "curses"), # EXCEPTION 159 | (r"\bimmedok\(%(arg)s", r"\1.immedok(", "curses"), # EXCEPTION 160 | # in_wch curs_in_wch(3X) 161 | # in_wchnstr curs_in_wchstr(3X) 162 | # in_wchstr curs_in_wchstr(3X) 163 | (r"\binch\(", r"stdscr.inch(", "curses"), 164 | #inchnstr curs_inchstr(3X) 165 | #inchstr curs_inchstr(3X) 166 | (r"\binit_color\(", r"curses.init_color(", "curses"), 167 | (r"\binit_pair\(", r"curses.init_pair(", "curses"), 168 | (r"\binitscr\(", r"curses.initscr(", "curses"), 169 | (r"\binnstr\(%(arg)s", r"\1.instr(", "curses"), # NONTRIVIAL 170 | #innwstr curs_inwstr(3X) 171 | #ins_nwstr curs_ins_wstr(3X) 172 | #ins_wch curs_ins_wch(3X) 173 | #ins_wstr curs_ins_wstr(3X) 174 | (r"\binsch\(", r"stdscr.insch(", "curses"), 175 | (r"\binsdelln\(", r"stdscr.insdelln(", "curses"), 176 | (r"\binsertln\(", r"stdscr.insertln(", "curses"), 177 | (r"\binsnstr\(", r"stdscr.insnstr(", "curses"), 178 | (r"\binsstr\(", r"stdscr.insstr(", "curses"), 179 | (r"\binstr\(%(farg)s\)", r"\1 = stdscr.instr()", "curses"), 180 | (r"\bintrflush\(\)", r"curses.intrflush()", "curses"), 181 | #inwstr curs_inwstr(3X) 182 | (r"\bis_linetouched\(%(arg)s", r"\1.is_linetouched(", "curses"),# EXCEPTION 183 | (r"\bis_wintouched\(%(farg)s\)", r"\1.is_wintouched()", "curses"),# EXCEPTION 184 | (r"\bisendwin\(\)", r"curses.isendwin()", "curses"), 185 | #key_defined key_defined(3X)* 186 | #key_name curs_util(3X) 187 | #keybound keybound(3X)* 188 | (r"\bkeyname\(", r"curses.keyname(", "curses"), 189 | #keyok keyok(3X)* 190 | (r"\bkeypad\(%(arg)s", r"\1.keypad(", "curses"), # EXCEPTION 191 | (r"\bkillchar\(\)", r"curses.killchar()", "curses"), 192 | #killwchar curs_termattrs(3X) 193 | (r"\bleaveok\(%(arg)s", r"\1.leaveok(", "curses"), # EXCEPTION 194 | (r"\blongname\(\)", r"curses.longname()", "curses"), 195 | #mcprint curs_print(3X)* 196 | (r"\bmeta\(", r"curses.meta(", "curses"), 197 | #mouse_trafo curs_mouse(3X)* 198 | (r"\bmouseinterval\(", r"curses.mouseinterval(", "curses"), 199 | (r"\bmousemask\(", r"curses.mousemask(", "curses"), 200 | (r"\bmove\(", r"stdscr.move(", "curses"), 201 | #mvadd_wch curs_add_wch(3X) 202 | #mvadd_wchnstr curs_add_wchstr(3X) 203 | #mvadd_wchstr curs_add_wchstr(3X) 204 | (r"\bmvaddch\(", r"stdscr.addch(", "curses"), # NONTRIVIAL 205 | #mvaddchnstr curs_addchstr(3X) 206 | #mvaddchstr curs_addchstr(3X) 207 | (r"\bmvaddnstr\(", r"stdscr.addnstr(", "curses"), # NONTRIVIAL 208 | #mvaddnwstr curs_addwstr(3X) 209 | (r"\bmvaddstr\(", r"stdscr.addstr(", "curses"), # NONTRIVIAL 210 | #mvaddwstr curs_addwstr(3X) 211 | #mvchgat curs_attr(3X) 212 | #mvcur curs_terminfo(3X) 213 | (r"\bmvdelch\(", r"stdscr.delch(", "curses"), # NONTRIVIAL 214 | (r"\bmvderwin\(%(arg)s", r"\1.derwin(", "curses"), # NONTRIVIAL,EXCEPTION 215 | #mvget_wch curs_get_wch(3X) 216 | #mvget_wstr curs_get_wstr(3X) 217 | (r"\bmvgetch\(%(arg)s", r"stdscr.getch(", "curses"), # NONTRIVIAL 218 | #mvgetn_wstr curs_get_wstr(3X) 219 | (r"\bmvgetnstr\(%(arg)s%(arg)s%(arg)s%(farg)s\)", # NONTRIVIAL 220 | r"\3 = stdscr.getstr(\1, \2)", "curses"), 221 | (r"\bmvgetstr\(%(arg)s%(arg)s%(farg)s\)", # NONTRIVIAL 222 | r"\3 = stdscr.getstr(\1, \2)", "curses"), 223 | (r"\bmvhline\(", r"stdscr.hline(", "curses"), # NONTRIVIAL 224 | #mvhline_set curs_border_set(3X) 225 | #mvin_wch curs_in_wch(3X) 226 | #mvin_wchnstr curs_in_wchstr(3X) 227 | #mvin_wchstr curs_in_wchstr(3X) 228 | (r"\bmvinch\(", r"stdscr.inch(", "curses"), # NONTRIVIAL 229 | (r"\bmvinchnstr\(", r"stdscr.instr(", "curses"), # NONTRIVIAL 230 | (r"\bmvinchstr\(", r"stdscr.instr(", "curses"), # NONTRIVIAL 231 | (r"\bmvinnstr\(", r"stdscr.instr(", "curses"), # NONTRIVIAL 232 | #mvinnwstr curs_inwstr(3X) 233 | #mvins_nwstr curs_ins_wstr(3X) 234 | #mvins_wch curs_ins_wch(3X) 235 | #mvins_wstr curs_ins_wstr(3X) 236 | (r"\bmvinsch\(", r"stdscr.insch(", "curses"), # NONTRIVIAL 237 | (r"\bmvinsnstr\(", r"stdscr.instr(", "curses"), # NONTRIVIAL 238 | (r"\bmvinsstr\(", r"stdscr.instr(", "curses"), # NONTRIVIAL 239 | (r"\bmvinstr\(", r"stdscr.instr(", "curses"), # NONTRIVIAL 240 | #mvwinwstr curs_inwstr(3X) 241 | (r"\bmvprintw\(", r"stdscr.addstr(", "curses"), # NONTRIVIAL 242 | # mvscanw curs_scanw(3X) 243 | (r"\bmvvline\(", r"stdscr.vline(", "curses"), # NONTRIVIAL 244 | #mvvline_set curs_border_set(3X) 245 | #mvwadd_wch curs_add_wch(3X) 246 | #mvwadd_wchnstr curs_add_wchstr(3X) 247 | #mvwadd_wchstr curs_add_wchstr(3X) 248 | (r"\bmvwaddch\(%(arg)s", r"\1.addch(", "curses"), # NONTRIVIAL 249 | #mvwaddchnstr curs_addchstr(3X) 250 | #mvwaddchstr curs_addchstr(3X) 251 | (r"\bmvwaddnstr\(%(arg)s", r"\1.addnstr(", "curses"), # NONTRIVIAL 252 | #mvwaddnwstr curs_addwstr(3X) 253 | (r"\bmvwaddstr\(%(arg)s", r"\1.addstr(", "curses"), # NONTRIVIAL 254 | #mvwaddwstr curs_addwstr(3X) 255 | #mvwchgat curs_attr(3X) 256 | (r"\bmvwdelch\(%(arg)s", r"\1.delch(", "curses"), # NONTRIVIAL 257 | #mvwget_wch curs_get_wch(3X) 258 | #mvwget_wstr curs_get_wstr(3X) 259 | (r"\bmvwgetch\(%(arg)s", r"\1.getch(", "curses"), # NONTRIVIAL 260 | #mvwgetn_wstr curs_get_wstr(3X) 261 | (r"\bmvwgetnstr\(%(arg)s", r"\1.getstr(", "curses"), # NONTRIVIAL 262 | (r"\bmvwgetstr\(%(arg)s", r"\1.getstr(", "curses"), # NONTRIVIAL 263 | (r"\bmvwhline\(%(arg)s", r"\1.hline(", "curses"), # NONTRIVIAL 264 | #mvwhline_set curs_border_set(3X) 265 | (r"\bmvwin\(%(arg)s", r"\1.mvwin(", "curses"), # EXCEPTION 266 | #mvwin_wch curs_in_wch(3X) 267 | #mvwin_wchnstr curs_in_wchstr(3X) 268 | #mvwin_wchstr curs_in_wchstr(3X) 269 | (r"\bmvwinch\(%(arg)s", r"\1.inch(", "curses"), # NONTRIVIAL 270 | #mvwinchnstr curs_inchstr(3X) 271 | #mvwinchstr curs_inchstr(3X) 272 | (r"\bmvwinnstr\(%(arg)s%(arg)s%(arg)s", # NONTRIVIAL 273 | r"\3 = \1.instr(\1, \2", "curses"), 274 | #mvwinnwstr curs_inwstr(3X) 275 | #mvwins_nwstr curs_ins_wstr(3X) 276 | #mvwins_wch curs_ins_wch(3X) 277 | #mvwins_wstr curs_ins_wstr(3X) 278 | (r"\bmvwinsch\(%(arg)s", r"\1.insch(", "curses"), # NONTRIVIAL 279 | (r"\bmvwinsnstr\(%(arg)s", r"\1.insnstr(", "curses"), # NONTRIVIAL 280 | (r"\bmvwinsstr\(%(arg)s", r"\1.insstr(", "curses"), # NONTRIVIAL 281 | (r"\bmvwinstr\(%(arg)s", r"\1.instr(", "curses"), # NONTRIVIAL 282 | #mvwinwstr curs_inwstr(3X) 283 | (r"\bmvwprintw\(%(arg)s", r"\1.addstr(", "curses"), # NONTRIVIAL 284 | #mvwscanw curs_scanw(3X) 285 | (r"\bmvwvline\(%(arg)s", r"\1.vline(", "curses"), # NONTRIVIAL 286 | #mvwvline_set curs_border_set(3X) 287 | (r"\bnapms\(", r"curses.napms(", "curses"), 288 | (r"\bnewpad\(", r"curses.newpad(", "curses"), 289 | #newterm curs_initscr(3X) 290 | (r"\bnewwin\(", r"curses.newwin(", "curses"), 291 | (r"\bnl\(", r"curses.nl(", "curses"), 292 | (r"\bnocbreak\(", r"curses.nocbreak(", "curses"), 293 | (r"\bnodelay\(%(arg)s", r"\1.nodelay(", "curses"), # EXCEPTION 294 | (r"\bnoecho\(", r"curses.noecho(", "curses"), 295 | (r"\bnonl\(", r"curses.nonl(", "curses"), 296 | (r"\bnoqiflush\(", r"curses.noqiflush(", "curses"), 297 | (r"\bnoraw\(", r"curses.noraw(", "curses"), 298 | (r"\bnotimeout\(%(arg)s", r"\1.notimeout(", "curses"), 299 | (r"\boverlay\(%(arg)s", r"\1.overlay(", "curses"), 300 | (r"\boverwrite\(%(arg)s", r"\1.overwrite(", "curses"), 301 | (r"\bpair_content\(", r"curses.pair_content(", "curses"), 302 | #pechochar curs_pad(3X) 303 | #pnoutrefresh curs_pad(3X) 304 | #prefresh curs_pad(3X) 305 | (r"\bprintw\(%(arg)s", r"\1.addstr(", "curses"), # NONTRIVIAL 306 | #putp curs_terminfo(3X) 307 | #putwin curs_util(3X) 308 | (r"\bqiflush\(", r"curses.qiflush(", "curses"), 309 | (r"\braw\(", r"curses.raw(", "curses"), 310 | (r"\bredrawwin\(%(farg)s\)", r"\1.redrawwin()", "curses"), # EXCEPTION 311 | (r"\brefresh\(\)", r"stdscr.refresh()", "curses"), 312 | (r"\breset_prog_mode\(", r"curses.reset_prog_mode(", "curses"), 313 | (r"\breset_shell_mode\(", r"curses.reset_shell_mode(", "curses"), 314 | #resetty curs_kernel(3X) 315 | #resizeterm resizeterm(3X)* 316 | #restartterm curs_terminfo(3X) 317 | #ripoffline curs_kernel(3X) 318 | #savetty curs_kernel(3X) 319 | #scanw curs_scanw(3X) 320 | #scr_dump curs_scr_dump(3X) 321 | #scr_init curs_scr_dump(3X) 322 | #scr_restore curs_scr_dump(3X) 323 | #scr_set curs_scr_dump(3X) 324 | (r"\bscrl\(", r"stdscr.scroll(", "curses"), # NONTRIVIAL 325 | (r"\bscroll\(%(farg)s\)", r"\1.scroll(1)", "curses"), # NONTRIVIAL 326 | (r"\bscrollok\(%(arg)s", r"\1.scrollok(", "curses"), # EXCEPTION 327 | #set_curterm curs_terminfo(3X) 328 | #set_term curs_initscr(3X) 329 | #setcchar curs_getcchar(3X) 330 | (r"\bsetscrreg\(", r"stdscr.setscrreg(", "curses"), 331 | (r"\bsetsyx\(", r"curses.setsyx(", "curses"), 332 | #setterm curs_terminfo(3X) 333 | (r"\bsetupterm\(", r"curses.setupterm(", "curses"), 334 | #slk_attr curs_slk(3X)* 335 | #slk_attr_off curs_slk(3X) 336 | #slk_attr_on curs_slk(3X) 337 | #slk_attr_set curs_slk(3X) 338 | #slk_attroff curs_slk(3X) 339 | #slk_attron curs_slk(3X) 340 | #slk_attrset curs_slk(3X) 341 | #slk_clear curs_slk(3X) 342 | #slk_color curs_slk(3X) 343 | #slk_init curs_slk(3X) 344 | #slk_label curs_slk(3X) 345 | #slk_noutrefresh curs_slk(3X) 346 | #slk_refresh curs_slk(3X) 347 | #slk_restore curs_slk(3X) 348 | #slk_set curs_slk(3X) 349 | #slk_touch curs_slk(3X) 350 | (r"\bstandend\(", r"stdscr.standend(", "curses"), 351 | (r"\bstandout\(", r"stdscr.standout(", "curses"), 352 | (r"\bstart_color\(", r"curses.start_color(", "curses"), 353 | (r"\bsubpad\(%(arg)s", r"\1.subpad(", "curses"), # EXCEPTION 354 | (r"\bsubwin\(%(arg)s", r"\1.subwin(", "curses"), # EXCEPTION 355 | (r"\bsyncok\(%(arg)s", r"\1.syncok(", "curses"), # EXCEPTION 356 | #term_attrs curs_termattrs(3X) 357 | (r"\btermattrs\(", r"curses.termattrs(", "curses"), 358 | (r"\btermname\(", r"curses.termname(", "curses"), 359 | #tgetent curs_termcap(3X) 360 | #tgetflag curs_termcap(3X) 361 | #tgetnum curs_termcap(3X) 362 | #tgetstr curs_termcap(3X) 363 | #tgoto curs_termcap(3X) 364 | (r"\btigetflag\(", r"curses.tigetflag(", "curses"), 365 | (r"\btigetnum\(", r"curses.tigetnum(", "curses"), 366 | (r"\btigetstr\(", r"curses.tigetstr(", "curses"), 367 | (r"\btimeout\(", r"stdscr.timeout(", "curses"), 368 | (r"\btouchline\(%(arg)s", r"\1.touchline(", "curses"), # EXCEPTION 369 | (r"\btouchwin\(%(farg)s\)", r"\1.touchwin()", "curses"), # EXCEPTION 370 | (r"\btparm\(", r"curses.tparm(", "curses"), 371 | #tputs curs_termcap(3X) 372 | #tputs curs_terminfo(3X) 373 | #trace curs_trace(3X)* 374 | (r"\btypeahead\(", r"curses.typeahead(", "curses"), 375 | (r"\bunctrl\(", r"curses.unctrl(", "curses"), 376 | #unget_wch curs_get_wch(3X) 377 | (r"\bungetch\(", r"curses.ungetch(", "curses"), 378 | (r"\bungetmouse\(%(arg)s", r"\1.ungetmouse(", "curses"), # False friend 379 | (r"\buntouchwin\(%(farg)s\)", r"\1.untouchwin()", "curses"), 380 | (r"\buse_default_colors\(", r"curses.use_default_colors(", "curses"), 381 | (r"use_env\(", r"use_env(", "curses"), 382 | #use_extended_names curs_extend(3X)* 383 | #vid_attr curs_terminfo(3X) 384 | #vid_puts curs_terminfo(3X) 385 | #vidattr curs_terminfo(3X) 386 | #vidputs curs_terminfo(3X) 387 | (r"vline\(", "stdscr.vline(", "curses"), 388 | #vline_set curs_border_set(3X) 389 | #vw_printw curs_printw(3X) 390 | #vw_scanw curs_scanw(3X) 391 | #vwprintw curs_printw(3X) 392 | #vwscanw curs_scanw(3X) 393 | #wadd_wch curs_add_wch(3X) 394 | #wadd_wchnstr curs_add_wchstr(3X) 395 | #wadd_wchstr curs_add_wchstr(3X) 396 | (r"\bwaddch\(%(arg)s", "\1.addch(", "curses"), # NONTRIVIAL 397 | #waddchnstr curs_addchstr(3X) 398 | #waddchstr curs_addchstr(3X) 399 | (r"\bwaddnstr\(%(arg)s", "\1.addnstr(", "curses"), # NONTRIVIAL 400 | #waddnwstr curs_addwstr(3X) 401 | (r"\bwaddstr\(%(arg)s", "\1.addstr(", "curses"), # NONTRIVIAL 402 | #waddwstr curs_addwstr(3X) 403 | #wattr_get curs_attr(3X) 404 | #wattr_off curs_attr(3X) 405 | #wattr_on curs_attr(3X) 406 | #wattr_set curs_attr(3X) 407 | (r"\bwattroff\(%(arg)s", "\1.attroff(", "curses"), # NONTRIVIAL 408 | (r"\bwattron\(%(arg)s", "\1.attron(", "curses"), # NONTRIVIAL 409 | (r"\bwattrset\(%(arg)s", "\1.attrset(", "curses"), # NONTRIVIAL 410 | (r"\bwbkgd\(%(arg)s", "\1.bkgd(", "curses"), # NONTRIVIAL 411 | (r"\bwbkgdset\(%(arg)s", "\1.bkgdset(", "curses"), # NONTRIVIAL 412 | #wbkgrnd curs_bkgrnd(3X) 413 | #wbkgrndset curs_bkgrnd(3X) 414 | (r"\bwborder\(%(arg)s", "\1.border(", "curses"), # NONTRIVIAL 415 | #wborder_set curs_border_set(3X) 416 | #wchgat curs_attr(3X) 417 | (r"\bwclear\(%(farg)s\)", "\1.clear()", "curses"), # NONTRIVIAL 418 | (r"\bwclrtobot\(%(farg)s\)", "\1.clrtobot()", "curses"), # NONTRIVIAL 419 | (r"\bwclrtoeol\(%(farg)s\)", "\1.clrtoeol()", "curses"), # NONTRIVIAL 420 | #wcolor_set curs_attr(3X) 421 | #wcursyncup curs_window(3X) 422 | (r"\bwdelch\(%(arg)s", "\1.delch(", "curses"), # NONTRIVIAL 423 | (r"\bwdeleteln\(%(farg)s\)", "\1.deleteln()", "curses"), # NONTRIVIAL 424 | #wecho_wchar curs_add_wch(3X) 425 | (r"\bwechochar\(%(arg)s", "\1.echochar(", "curses"), # NONTRIVIAL 426 | (r"\bwenclose\(%(arg)s", "\1.enclose(", "curses"), # NONTRIVIAL 427 | (r"\bwerase\(%(farg)s\)", "\1.erase()", "curses"), # NONTRIVIAL 428 | #wget_wch curs_get_wch(3X) 429 | #wget_wstr curs_get_wstr(3X) 430 | #wgetbkgrnd curs_bkgrnd(3X) 431 | (r"\bwgetch\(%(farg)s\)", "\1.getch()", "curses"), # NONTRIVIAL 432 | #wgetn_wstr curs_get_wstr(3X) 433 | (r"\bwgetnstr\(%(arg)s", "\1.getstr(", "curses"), # NONTRIVIAL 434 | (r"\bwgetstr\(%(arg)s", "\1.getstr(", "curses"), # NONTRIVIAL 435 | (r"\bwhline\(%(arg)s", "\1.hline(", "curses"), # NONTRIVIAL 436 | #whline_set curs_border_set(3X) 437 | #win_wch curs_in_wch(3X) 438 | #win_wchnstr curs_in_wchstr(3X) 439 | #win_wchstr curs_in_wchstr(3X) 440 | (r"\bwinch\(%(arg)s", "\1.inch(", "curses"), # NONTRIVIAL 441 | #winchnstr curs_inchstr(3X) 442 | #winchstr curs_inchstr(3X) 443 | (r"\bwinnstr\(%(arg)s", "\1.instr(", "curses"), # NONTRIVIAL 444 | #winnwstr curs_inwstr(3X) 445 | #wins_nwstr curs_ins_wstr(3X) 446 | #wins_wch curs_ins_wch(3X) 447 | #wins_wstr curs_ins_wstr(3X) 448 | (r"\bwinsch\(%(arg)s", "\1.insch(", "curses"), # NONTRIVIAL 449 | (r"\bwinsdelln\(%(arg)s", "\1.insdelln(", "curses"), # NONTRIVIAL 450 | (r"\bwinsertln\(%(farg)s\)", "\1.insertln()", "curses"), # NONTRIVIAL 451 | (r"\bwinsnstr\(%(arg)s", "\1.insnstr(", "curses"), # NONTRIVIAL 452 | (r"\binsstr\(%(arg)s", "\1.insstr(", "curses"), # NONTRIVIAL 453 | (r"\bwinstr\(%(arg)s", "\1.instr(", "curses"), # NONTRIVIAL 454 | #winwstr curs_inwstr(3X) 455 | #wmouse_trafo curs_mouse(3X)* 456 | (r"\bwmove\(%(arg)s", "\1.move(", "curses"), # NONTRIVIAL 457 | (r"\bwnoutrefresh\(%(arg)s", "\1.noutrefresh(", "curses"), # NONTRIVIAL 458 | (r"\bwprintw\(%(arg)s", "\1.addstr(", "curses"), # NONTRIVIAL 459 | (r"\bwredrawln\(%(arg)s", "\1.redrawln(", "curses"), # NONTRIVIAL 460 | (r"\bwrefresh\(%(arg)s", "\1.refresh(", "curses"), # NONTRIVIAL 461 | (r"\bwresize\(%(arg)s", "\1.resize(", "curses"), # NONTRIVIAL 462 | #wscanw curs_scanw(3X) 463 | (r"\bwscrl\(%(arg)s", r"\1.scroll(", "curses"), # NINTRIVIAL 464 | (r"\bwsetscrreg\(%(arg)s", "\1.setscrreg(", "curses"), # NONTRIVIAL 465 | (r"\bwstandend\(%(arg)s", "\1.standend(", "curses"), # NONTRIVIAL 466 | (r"\bwstandout\(%(arg)s", "\1.standout(", "curses"), # NONTRIVIAL 467 | (r"\bwsyncdown\(%(farg)s\)", "\1.syncdown()", "curses"), # NONTRIVIAL 468 | (r"\bwsyncup\(%(arg)s", "\1.syncup(", "curses"), # NONTRIVIAL 469 | (r"\bwtimeout\(%(arg)s", "\1.timeout(", "curses"), # NONTRIVIAL 470 | (r"\bwtouchln\(%(arg)s", "\1.touchln(", "curses"), # NONTRIVIAL 471 | (r"\bwunctrl\(%(arg)s", r"\1.unctrl(", "curses"), # NONTRIVIAL 472 | (r"\bwvline\(%(arg)s", r"\1.vline(", "curses"), # NONTRIVIAL 473 | #wvline_set curs_border_set(3X) 474 | # And this does the curses library constants 475 | (r"\bA_ATTRIBUTES\b", r"curses.A_ATTRIBUTES", "curses"), 476 | (r"\bA_NORMAL\b", r"curses.A_NORMAL", "curses"), 477 | (r"\bA_STANDOUT\b", r"curses.A_STANDOUT", "curses"), 478 | (r"\bA_UNDERLINE\b", r"curses.A_UNDERLINE", "curses"), 479 | (r"\bA_REVERSE\b", r"curses.A_REVERSE", "curses"), 480 | (r"\bA_BLINK\b", r"curses.A_BLINK", "curses"), 481 | (r"\bA_DIM\b", r"curses.A_DIM", "curses"), 482 | (r"\bA_BOLDW\b", r"curses.A_BOLDW", "curses"), 483 | (r"\bA_ALTCHARSET\b", r"curses.A_ALTCHARSET", "curses"), 484 | (r"\bA_INVIS\b", r"curses.A_INVIS", "curses"), 485 | (r"\bA_PROTECT\b", r"curses.A_PROTECT", "curses"), 486 | (r"\bA_HORIZONTAL\b", r"curses.A_HORIZONTAL", "curses"), 487 | (r"\bA_LEFT\b", r"curses.A_LEFT", "curses"), 488 | (r"\bA_LOW\b", r"curses.A_LOW", "curses"), 489 | (r"\bA_RIGHT\b", r"curses.A_RIGHT", "curses"), 490 | (r"\bA_TOP\b", r"curses.A_TOP", "curses"), 491 | (r"\bA_VERTICAL\b", r"curses.A_VERTICAL", "curses"), 492 | (r"\bOLOR_BLACK\b", r"curses.OLOR_BLACK", "curses"), 493 | (r"\bOLOR_RED\b", r"curses.OLOR_RED", "curses"), 494 | (r"\bOLOR_GREEN\b", r"curses.OLOR_GREEN", "curses"), 495 | (r"\bOLOR_YELLOW\b", r"curses.OLOR_YELLOW", "curses"), 496 | (r"\bOLOR_BLUE\b", r"curses.OLOR_BLUE", "curses"), 497 | (r"\bOLOR_MAGENTA\b", r"curses.OLOR_MAGENTA", "curses"), 498 | (r"\bOLOR_CYAN\b", r"curses.OLOR_CYAN", "curses"), 499 | (r"\bOLOR_WHITE\b", r"curses.OLOR_WHITE", "curses"), 500 | (r"\bACS_ULCORNER\b", r"curses.ACS_ULCORNER", "curses"), 501 | (r"\bACS_LLCORNER\b", r"curses.ACS_LLCORNER", "curses"), 502 | (r"\bACS_URCORNER\b", r"curses.ACS_URCORNER", "curses"), 503 | (r"\bACS_LRCORNER\b", r"curses.ACS_LRCORNER", "curses"), 504 | (r"\bACS_LTEE\b", r"curses.ACS_LTEE", "curses"), 505 | (r"\bACS_RTEE\b", r"curses.ACS_RTEE", "curses"), 506 | (r"\bACS_BTEE\b", r"curses.ACS_BTEE", "curses"), 507 | (r"\bACS_TTEE\b", r"curses.ACS_TTEE", "curses"), 508 | (r"\bACS_HLINE\b", r"curses.ACS_HLINE", "curses"), 509 | (r"\bACS_VLINE\b", r"curses.ACS_VLINE", "curses"), 510 | (r"\bACS_PLUS\b", r"curses.ACS_PLUS", "curses"), 511 | (r"\bACS_S1\b", r"curses.ACS_S1", "curses"), 512 | (r"\bACS_S9\b", r"curses.ACS_S9", "curses"), 513 | (r"\bACS_DIAMOND\b", r"curses.ACS_DIAMOND", "curses"), 514 | (r"\bACS_CKBOARD\b", r"curses.ACS_CKBOARD", "curses"), 515 | (r"\bACS_DEGREE\b", r"curses.ACS_DEGREE", "curses"), 516 | (r"\bACS_PLMINUS\b", r"curses.ACS_PLMINUS", "curses"), 517 | (r"\bACS_BULLET\b", r"curses.ACS_BULLET", "curses"), 518 | (r"\bACS_LARROW\b", r"curses.ACS_LARROW", "curses"), 519 | (r"\bACS_RARROW\b", r"curses.ACS_RARROW", "curses"), 520 | (r"\bACS_DARROW\b", r"curses.ACS_DARROW", "curses"), 521 | (r"\bACS_UARROW\b", r"curses.ACS_UARROW", "curses"), 522 | (r"\bACS_BOARD\b", r"curses.ACS_BOARD", "curses"), 523 | (r"\bACS_LANTERN\b", r"curses.ACS_LANTERN", "curses"), 524 | (r"\bACS_BLOCK\b", r"curses.ACS_BLOCK", "curses"), 525 | (r"\bBUTTON(\d)_PRESSED\b", r"BUTTON\1_PRESSED", "curses"), 526 | (r"\bBUTTON(\d)_RELEASED\b", r"BUTTON\1_RELEASED", "curses"), 527 | (r"\bBUTTON(\d)_CLICKED\b", r"BUTTON\1_CLICKED", "curses"), 528 | (r"\bBUTTON(\d)_DOUBLE_CLICKED\b", r"BUTTON\1_DOUBLE_CLICKED", "curses"), 529 | (r"\bBUTTON(\d)_TRIPLE_CLICKED\b", r"BUTTON\1_TRIPLE_CLICKED", "curses"), 530 | (r"\bBUTTON_SHIFT\b", r"BUTTON_SHIFT", "curses"), 531 | (r"\bBUTTON_CTRL\b", r"BUTTON_CTRL", "curses"), 532 | (r"\bBUTTON_ALT\b", r"BUTTON_ALT", "curses"), 533 | (r"\bALL_MOUSE_EVENTS\b", r"ALL_MOUSE_EVENTS", "curses"), 534 | (r"\bREPORT_MOUSE_POSITION\b", r"REPORT_MOUSE_POSITION", "curses"), 535 | # Python curses.ascii library 536 | (r"\bisalnum\(", r"curses.ascii.isalnum(", "curses.ascii"), 537 | (r"\bisalpha\(", r"curses.ascii.isalpha(", "curses.ascii"), 538 | (r"\bisascii\(", r"curses.ascii.isascii(", "curses.ascii"), 539 | (r"\bisblank\(", r"curses.ascii.isblank(", "curses.ascii"), 540 | (r"\biscntrl\(", r"curses.ascii.iscntrl(", "curses.ascii"), 541 | (r"\bisdigit\(", r"curses.ascii.isdigit(", "curses.ascii"), 542 | (r"\bisgraph\(", r"curses.ascii.isgraph(", "curses.ascii"), 543 | (r"\bislower\(", r"curses.ascii.islower(", "curses.ascii"), 544 | (r"\bisprint\(", r"curses.ascii.isprint(", "curses.ascii"), 545 | (r"\bispunct\(", r"curses.ascii.ispunct(", "curses.ascii"), 546 | (r"\bisspace\(", r"curses.ascii.isspace(", "curses.ascii"), 547 | (r"\bisupper\(", r"curses.ascii.isupper(", "curses.ascii"), 548 | (r"\bisxdigit\(", r"curses.ascii.isxdigit(", "curses.ascii"), 549 | (r"\bisctrl\(", r"curses.ascii.isctrl(", "curses.ascii"), 550 | (r"\bismeta\(", r"curses.ascii.ismeta(", "curses.ascii"), 551 | # Python errno library 552 | (r"\bEPERM\b", r"errno.EPERM", "errno"), 553 | (r"\bENOENT\b", r"errno.ENOENT", "errno"), 554 | (r"\bESRCH\b", r"errno.ESRCH", "errno"), 555 | (r"\bEINTR\b", r"errno.EINTR", "errno"), 556 | (r"\bEIO\b", r"errno.EIO", "errno"), 557 | (r"\bENXIO\b", r"errno.ENXIO", "errno"), 558 | (r"\bE2BIG\b", r"errno.E2BIG", "errno"), 559 | (r"\bENOEXEC\b", r"errno.ENOEXEC", "errno"), 560 | (r"\bEBADF\b", r"errno.EBADF", "errno"), 561 | (r"\bECHILD\b", r"errno.ECHILD", "errno"), 562 | (r"\bEAGAIN\b", r"errno.EAGAIN", "errno"), 563 | (r"\bENOMEM\b", r"errno.ENOMEM", "errno"), 564 | (r"\bEACCES\b", r"errno.EACCES", "errno"), 565 | (r"\bEFAULT\b", r"errno.EFAULT", "errno"), 566 | (r"\bENOTBLK\b", r"errno.ENOTBLK", "errno"), 567 | (r"\bEBUSY\b", r"errno.EBUSY", "errno"), 568 | (r"\bEEXIST\b", r"errno.EEXIST", "errno"), 569 | (r"\bEXDEV\b", r"errno.EXDEV", "errno"), 570 | (r"\bENODEV\b", r"errno.ENODEV", "errno"), 571 | (r"\bENOTDIR\b", r"errno.ENOTDIR", "errno"), 572 | (r"\bEISDIR\b", r"errno.EISDIR", "errno"), 573 | (r"\bEINVAL\b", r"errno.EINVAL", "errno"), 574 | (r"\bENFILE\b", r"errno.ENFILE", "errno"), 575 | (r"\bEMFILE\b", r"errno.EMFILE", "errno"), 576 | (r"\bENOTTY\b", r"errno.ENOTTY", "errno"), 577 | (r"\bETXTBSY\b", r"errno.ETXTBSY", "errno"), 578 | (r"\bEFBIG\b", r"errno.EFBIG", "errno"), 579 | (r"\bENOSPC\b", r"errno.ENOSPC", "errno"), 580 | (r"\bESPIPE\b", r"errno.ESPIPE", "errno"), 581 | (r"\bEROFS\b", r"errno.EROFS", "errno"), 582 | (r"\bEMLINK\b", r"errno.EMLINK", "errno"), 583 | (r"\bEPIPE\b", r"errno.EPIPE", "errno"), 584 | (r"\bEDOM\b", r"errno.EDOM", "errno"), 585 | (r"\bERANGE\b", r"errno.ERANGE", "errno"), 586 | (r"\bEDEADLK\b", r"errno.EDEADLK", "errno"), 587 | (r"\bENAMETOOLONG\b", r"errno.ENAMETOOLONG", "errno"), 588 | (r"\bENOLCK\b", r"errno.ENOLCK", "errno"), 589 | (r"\bENOSYS\b", r"errno.ENOSYS", "errno"), 590 | (r"\bENOTEMPTY\b", r"errno.ENOTEMPTY", "errno"), 591 | (r"\bELOOP\b", r"errno.ELOOP", "errno"), 592 | (r"\bEWOULDBLOCK\b", r"errno.EWOULDBLOCK", "errno"), 593 | (r"\bENOMSG\b", r"errno.ENOMSG", "errno"), 594 | (r"\bEIDRM\b", r"errno.EIDRM", "errno"), 595 | (r"\bECHRNG\b", r"errno.ECHRNG", "errno"), 596 | (r"\bEL2NSYNC\b", r"errno.EL2NSYNC", "errno"), 597 | (r"\bEL3HLT\b", r"errno.EL3HLT", "errno"), 598 | (r"\bEL3RST\b", r"errno.EL3RST", "errno"), 599 | (r"\bELNRNG\b", r"errno.ELNRNG", "errno"), 600 | (r"\bEUNATCH\b", r"errno.EUNATCH", "errno"), 601 | (r"\bENOCSI\b", r"errno.ENOCSI", "errno"), 602 | (r"\bEL2HLT\b", r"errno.EL2HLT", "errno"), 603 | (r"\bEBADE\b", r"errno.EBADE", "errno"), 604 | (r"\bEBADR\b", r"errno.EBADR", "errno"), 605 | (r"\bEXFULL\b", r"errno.EXFULL", "errno"), 606 | (r"\bENOANO\b", r"errno.ENOANO", "errno"), 607 | (r"\bEBADRQC\b", r"errno.EBADRQC", "errno"), 608 | (r"\bEBADSLT\b", r"errno.EBADSLT", "errno"), 609 | (r"\bEDEADLOCK\b", r"errno.EDEADLOCK", "errno"), 610 | (r"\bEBFONT\b", r"errno.EBFONT", "errno"), 611 | (r"\bENOSTR\b", r"errno.ENOSTR", "errno"), 612 | (r"\bENODATA\b", r"errno.ENODATA", "errno"), 613 | (r"\bETIME\b", r"errno.ETIME", "errno"), 614 | (r"\bENOSR\b", r"errno.ENOSR", "errno"), 615 | (r"\bENONET\b", r"errno.ENONET", "errno"), 616 | (r"\bENOPKG\b", r"errno.ENOPKG", "errno"), 617 | (r"\bEREMOTE\b", r"errno.EREMOTE", "errno"), 618 | (r"\bENOLINK\b", r"errno.ENOLINK", "errno"), 619 | (r"\bEADV\b", r"errno.EADV", "errno"), 620 | (r"\bESRMNT\b", r"errno.ESRMNT", "errno"), 621 | (r"\bECOMM\b", r"errno.ECOMM", "errno"), 622 | (r"\bEPROTO\b", r"errno.EPROTO", "errno"), 623 | (r"\bEMULTIHOP\b", r"errno.EMULTIHOP", "errno"), 624 | (r"\bEDOTDOT\b", r"errno.EDOTDOT", "errno"), 625 | (r"\bEBADMSG\b", r"errno.EBADMSG", "errno"), 626 | (r"\bEOVERFLOW\b", r"errno.EOVERFLOW", "errno"), 627 | (r"\bENOTUNIQ\b", r"errno.ENOTUNIQ", "errno"), 628 | (r"\bEBADFD\b", r"errno.EBADFD", "errno"), 629 | (r"\bEREMCHG\b", r"errno.EREMCHG", "errno"), 630 | (r"\bELIBACC\b", r"errno.ELIBACC", "errno"), 631 | (r"\bELIBBAD\b", r"errno.ELIBBAD", "errno"), 632 | (r"\bELIBSCN\b", r"errno.ELIBSCN", "errno"), 633 | (r"\bELIBMAX\b", r"errno.ELIBMAX", "errno"), 634 | (r"\bELIBEXEC\b", r"errno.ELIBEXEC", "errno"), 635 | (r"\bEILSEQ\b", r"errno.EILSEQ", "errno"), 636 | (r"\bERESTART\b", r"errno.ERESTART", "errno"), 637 | (r"\bESTRPIPE\b", r"errno.ESTRPIPE", "errno"), 638 | (r"\bEUSERS\b", r"errno.EUSERS", "errno"), 639 | (r"\bENOTSOCK\b", r"errno.ENOTSOCK", "errno"), 640 | (r"\bEDESTADDRREQ\b", r"errno.EDESTADDRREQ", "errno"), 641 | (r"\bEMSGSIZE\b", r"errno.EMSGSIZE", "errno"), 642 | (r"\bEPROTOTYPE\b", r"errno.EPROTOTYPE", "errno"), 643 | (r"\bENOPROTOOPT\b", r"errno.ENOPROTOOPT", "errno"), 644 | (r"\bEPROTONOSUPPORT\b", r"errno.EPROTONOSUPPORT", "errno"), 645 | (r"\bESOCKTNOSUPPORT\b", r"errno.ESOCKTNOSUPPORT", "errno"), 646 | (r"\bEOPNOTSUPP\b", r"errno.EOPNOTSUPP", "errno"), 647 | (r"\bEPFNOSUPPORT\b", r"errno.EPFNOSUPPORT", "errno"), 648 | (r"\bEAFNOSUPPORT\b", r"errno.EAFNOSUPPORT", "errno"), 649 | (r"\bEADDRINUSE\b", r"errno.EADDRINUSE", "errno"), 650 | (r"\bEADDRNOTAVAIL\b", r"errno.EADDRNOTAVAIL", "errno"), 651 | (r"\bENETDOWN\b", r"errno.ENETDOWN", "errno"), 652 | (r"\bENETUNREACH\b", r"errno.ENETUNREACH", "errno"), 653 | (r"\bENETRESET\b", r"errno.ENETRESET", "errno"), 654 | (r"\bECONNABORTED\b", r"errno.ECONNABORTED", "errno"), 655 | (r"\bECONNRESET\b", r"errno.ECONNRESET", "errno"), 656 | (r"\bENOBUFS\b", r"errno.ENOBUFS", "errno"), 657 | (r"\bEISCONN\b", r"errno.EISCONN", "errno"), 658 | (r"\bENOTCONN\b", r"errno.ENOTCONN", "errno"), 659 | (r"\bESHUTDOWN\b", r"errno.ESHUTDOWN", "errno"), 660 | (r"\bETOOMANYREFS\b", r"errno.ETOOMANYREFS", "errno"), 661 | (r"\bETIMEDOUT\b", r"errno.ETIMEDOUT", "errno"), 662 | (r"\bECONNREFUSED\b", r"errno.ECONNREFUSED", "errno"), 663 | (r"\bEHOSTDOWN\b", r"errno.EHOSTDOWN", "errno"), 664 | (r"\bEHOSTUNREACH\b", r"errno.EHOSTUNREACH", "errno"), 665 | (r"\bEALREADY\b", r"errno.EALREADY", "errno"), 666 | (r"\bEINPROGRESS\b", r"errno.EINPROGRESS", "errno"), 667 | (r"\bESTALE\b", r"errno.ESTALE", "errno"), 668 | (r"\bEUCLEAN\b", r"errno.EUCLEAN", "errno"), 669 | (r"\bENOTNAM\b", r"errno.ENOTNAM", "errno"), 670 | (r"\bENAVAIL\b", r"errno.ENAVAIL", "errno"), 671 | (r"\bEISNAM\b", r"errno.EISNAM", "errno"), 672 | (r"\bEREMOTEIO\b", r"errno.EREMOTEIO", "errno"), 673 | (r"\bEDQUOT\b", r"errno.EDQUOT", "errno"), 674 | # Python fcntl library 675 | (r"\bfcntl\(", r"fcntl.fcntl(", "fcntl"), 676 | (r"\bflock\(", r"fcntl.lockf(", "fcntl"), 677 | (r"\blockf\(", r"fcntl.lockf(", "fcntl"), 678 | (r"\bLOCK_UN\b", r"fcntl.LOCK_UN", "fcntl"), 679 | (r"\bLOCK_EX\b", r"fcntl.LOCK_EX", "fcntl"), 680 | (r"\bLOCK_SH\b", r"fcntl.LOCK_SH", "fcntl"), 681 | (r"\bLOCK_NB\b", r"fcntl.LOCK_NB", "fcntl"), 682 | # Python getpass library 683 | (r"\bgetpass\(", r"getpass.getpass(", "getpass"), 684 | # Python glob library 685 | (r"\bglob\(", r"glob.glob(", "glob"), # Calling conventions differ 686 | # Python grp library 687 | (r"\bgetgrgid\(", r"grp.getgrgid(", "grp"), 688 | (r"\bgetgrnam\(", r"grp.getgrnam(", "grp"), 689 | # Python math library 690 | (r"\bacos\(", r"math.acos(", "math"), 691 | (r"\basin\(", r"math.asin(", "math"), 692 | (r"\batan\(", r"math.atan(", "math"), 693 | (r"\batan2\(", r"math.atan2(", "math"), 694 | (r"\bceil\(", r"math.ceil(", "math"), 695 | (r"\bcos\(", r"math.cos(", "math"), 696 | (r"\bcosh\(", r"math.cosh(", "math"), 697 | (r"\bexp\(", r"math.exp(", "math"), 698 | (r"\bfabs\(", r"math.fabs(", "math"), 699 | (r"\bfloor\(", r"math.floor(", "math"), 700 | (r"\bfmod\(", r"math.fmod(", "math"), 701 | (r"\bfrexp\(", r"math.frexp(", "math"), # Calling conventions differ 702 | (r"\bldexp\(", r"math.ldexp(", "math"), 703 | (r"\blog10\(", r"math.log10(", "math"), 704 | (r"\blog\(", r"math.log(", "math"), 705 | (r"\bmodf\(", r"math.modf(", "math"), # Calling conventions differ 706 | (r"\bpow\(", r"math.pow(", "math"), 707 | (r"\bsinh\(", r"math.sinh(", "math"), 708 | (r"\bsin\(", r"math.sin(", "math"), 709 | (r"\bsqrt\(", r"math.sqrt(", "math"), 710 | (r"\btan\(", r"math.tan(", "math"), 711 | (r"\btanh\(", r"math.tanh(", "math"), 712 | # Python os library 713 | (r"\babort\(", r"os.abort(", "os"), 714 | (r"\baccess\(", r"os.access(", "os"), 715 | (r"\bchdir\(", r"os.chdir(", "os"), 716 | (r"\bclose\(", r"os.close(", "os"), 717 | (r"\benviron\(", r"os.environ(", "os"), 718 | (r"\bfchdir\(", r"os.fchdir(", "os"), 719 | (r"\bchroot\(", r"os.chroot(", "os"), 720 | (r"\bchmod\(", r"os.chmod(", "os"), 721 | (r"\bchown\(", r"os.chown(", "os"), 722 | (r"\bctermid\(", r"os.ctermid(", "os"), 723 | (r"\bdup\(", r"os.dup(", "os"), 724 | (r"\bdup2\(", r"os.dup2(", "os"), 725 | (r"\bexecl\(", r"os.execl(", "os"), 726 | (r"\bexecle\(", r"os.execle(", "os"), 727 | (r"\bexeclp\(", r"os.execlp(", "os"), 728 | (r"\bexeclpe\(", r"os.execlpe(", "os"), 729 | (r"\bexecv\(", r"os.execv(", "os"), 730 | (r"\bexecve\(", r"os.execve(", "os"), 731 | (r"\bexecvp\(", r"os.execvp(", "os"), 732 | (r"\bexecvpe\(", r"os.execvpe(", "os"), 733 | (r"\b_exit\(", r"os._exit(", "os"), 734 | (r"\bexit\(", r"os.exit(", "os"), 735 | (r"\bfdopen\(", r"os.fdopen(", "os"), 736 | (r"\bfork\(", r"os.fork(", "os"), 737 | (r"\bfsync\(", r"os.fsync(", "os"), 738 | (r"\bftruncate\(", r"os.ftruncate(", "os"), 739 | (r"\bgetcwd\(", r"os.getcwd(", "os"), 740 | (r"\bgetegid\(", r"os.getegid(", "os"), 741 | (r"\bgeteuid\(", r"os.geteuid(", "os"), 742 | (r"\bgetenv\(", r"os.getenv(", "os"), 743 | (r"\bgetgid\(", r"os.getgid(", "os"), 744 | (r"\bgetgroups\(", r"os.getgroups(", "os"), 745 | (r"\bgetlogin\(", r"os.getlogin(", "os"), 746 | (r"\bgetpgid\(", r"os.getpgid(", "os"), 747 | (r"\bgetpgrp\(", r"os.getpgrp(", "os"), 748 | (r"\bgetpid\(", r"os.getpid(", "os"), 749 | (r"\bgetppid\(", r"os.getppid(", "os"), 750 | (r"\bgetuid\(", r"os.getuid(", "os"), 751 | (r"\bkill\(", r"os.kill(", "os"), 752 | (r"\bkillpg\(", r"os.killpg(", "os"), 753 | (r"\bisatty\(", r"os.isatty(", "os"), 754 | (r"\blseek\(", r"os.lseek(", "os"), 755 | (r"\blchown\(", r"os.lchown(", "os"), 756 | (r"\bgetcwd\(", r"os.getcwd(", "os"), 757 | (r"\blstat\(", r"os.lstat(", "os"), 758 | (r"\bmkfifo\(", r"os.mkfifo(", "os"), 759 | (r"\bmknod\(", r"os.mknod(", "os"), 760 | (r"\bmkdir\(", r"os.mkdir(", "os"), 761 | (r"\bnice\(", r"os.nice(", "os"), 762 | (r"\bopen\(", r"os.open(", "os"), 763 | (r"\bpathconf\(", r"os.pathconf(", "os"), 764 | (r"\bpipe\(", r"os.pipe(", "os"), 765 | (r"\bplock\(", r"os.plock(", "os"), 766 | (r"\bputenv\(", r"os.putenv(", "os"), 767 | (r"\bread\(", r"os.read(", "os"), 768 | (r"\brmdir\(", r"os.rmdir(", "os"), 769 | (r"\bsetegid\(", r"os.setegid(", "os"), 770 | (r"\bseteuid\(", r"os.seteuid(", "os"), 771 | (r"\bsetgid\(", r"os.setgid(", "os"), 772 | (r"\bsetgroups\(", r"os.setgroups(", "os"), 773 | (r"\bsetpgrp\(", r"os.setpgrp(", "os"), 774 | (r"\bsetpgid\(", r"os.setpgid(", "os"), 775 | (r"\bsetreuid\(", r"os.setreuid(", "os"), 776 | (r"\bsetregid\(", r"os.setregid(", "os"), 777 | (r"\bsetsid\(", r"os.setsid(", "os"), 778 | (r"\bsetuid\(", r"os.setuid(", "os"), 779 | (r"\bstrerror\(", r"os.strerror(", "os"), 780 | (r"\bumask\(", r"os.umask(", "os"), 781 | (r"\bsymlink\(", r"os.symlink(", "os"), 782 | (r"\bsystem\(", r"os.system(", "os"), 783 | (r"\btcgetpgrp\(", r"os.tcgetpgrp(", "os"), 784 | (r"\btcsetpgrp\(", r"os.tcsetpgrp(", "os"), 785 | (r"\btmpfile\(", r"os.tmpfile(", "os"), 786 | (r"\bttyname\(", r"os.ttyname(", "os"), 787 | (r"\bunlink\(", r"os.unlink(", "os"), 788 | (r"\bwrite\(", r"os.write(", "os"), 789 | (r"\bwait\(", r"os.wait(", "os"), 790 | (r"\bwaitpid\(", r"os.waitpid(", "os"), 791 | (r"\bWNOHANG\b", r"os.WNOHANG", "os"), 792 | (r"\bWCONTINUED\b", r"os.WCONTINUED", "os"), 793 | (r"\bWUNTRACED\b", r"os.WUNTRACED", "os"), 794 | (r"\bWCOREDUMP\b", r"os.WCOREDUMP", "os"), 795 | (r"\bWIFCONTINUED\b", r"os.WIFCONTINUED", "os"), 796 | (r"\bWIFSTOPPED\b", r"os.WIFSTOPPED", "os"), 797 | (r"\bWIFSIGNALED\b", r"os.WIFSIGNALED", "os"), 798 | (r"\bWIFEXITED\b", r"os.WIFEXITED", "os"), 799 | (r"\bWEXITSTATUS\b", r"os.WEXITSTATUS", "os"), 800 | (r"\bWSTOPSIG\b", r"os.WSTOPSIG", "os"), 801 | (r"\bWTERMSIG\b", r"os.WTERMSIG", "os"), 802 | (r"\bO_RDONLY\b", r"os.O_RDONLY", "os"), 803 | (r"\bO_WRONLY\b", r"os.O_WRONLY", "os"), 804 | (r"\bO_RDWR\b", r"os.O_RDWR", "os"), 805 | (r"\bO_NDELAY\b", r"os.O_NDELAY", "os"), 806 | (r"\bO_NONBLOCK\b", r"os.O_NONBLOCK", "os"), 807 | (r"\bO_APPEND\b", r"os.O_APPEND", "os"), 808 | (r"\bO_DSYNC\b", r"os.O_DSYNC", "os"), 809 | (r"\bO_RSYNC\b", r"os.O_RSYNC", "os"), 810 | (r"\bO_SYNC\b", r"os.O_SYNC", "os"), 811 | (r"\bO_NOCTTY\b", r"os.O_NOCTTY", "os"), 812 | (r"\bO_CREAT\b", r"os.O_CREAT", "os"), 813 | (r"\bO_EXCL\b", r"os.O_EXCL", "os"), 814 | (r"\bO_TRUNC\b", r"os.O_TRUNC", "os"), 815 | (r"\bF_OK\b", r"os.F_OK", "os"), 816 | (r"\bR_OK\b", r"os.R_OK", "os"), 817 | (r"\bW_OK\b", r"os.W_OK", "os"), 818 | (r"\bX_OK\b", r"os.X_OK", "os"), 819 | (r"\bS_ISUID\b", r"os.S_ISUID", "os"), 820 | (r"\bS+ISGID\b", r"os.S+ISGID", "os"), 821 | (r"\bS_ENFMT\b", r"os.S_ENFMT", "os"), 822 | (r"\bS_ISVTX\b", r"os.S_ISVTX", "os"), 823 | (r"\bS_IREAD\b", r"os.S_IREAD", "os"), 824 | (r"\bS_IWRITE\b", r"os.S_IWRITE", "os"), 825 | (r"\bS_IEXEC\b", r"os.S_IEXEC", "os"), 826 | (r"\bS_IRWXU\b", r"os.S_IRWXU", "os"), 827 | (r"\bS_IRUSR\b", r"os.S_IRUSR", "os"), 828 | (r"\bS_IXUSR\b", r"os.S_IXUSR", "os"), 829 | (r"\bS_IRWXG\b", r"os.S_IRWXG", "os"), 830 | (r"\bS_IRGRP\b", r"os.S_IRGRP", "os"), 831 | (r"\bS_IWGRP\b", r"os.S_IWGRP", "os"), 832 | (r"\bS_IXGRP\b", r"os.S_IXGRP", "os"), 833 | (r"\bS_IRWXO\b", r"os.S_IRWXO", "os"), 834 | (r"\bS_IROTH\b", r"os.S_IROTH", "os"), 835 | (r"\bS_IWOTH\b", r"os.S_IWOTH", "os"), 836 | (r"\bS_IXOTH\b", r"os.S_IXOTH", "os"), 837 | # Python os.path library 838 | (r"\bbasename\(", r"os.path.basename(", "os.path"), 839 | (r"\bdirname\(", r"os.path.dirname(", "os.path"), 840 | # Python pwd library 841 | (r"\bgetpwuid\(", r"pwd.getpwuid(", "pwd"), 842 | (r"\bgetpwnam\(", r"pwd.getpwnam(", "pwd"), 843 | # Python random library -- alas, C rand() doesn't map cleanly 844 | (r"\bsrand48\(", r"random.seed(", "random"), 845 | (r"\bsrand\(", r"random.seed(", "random"), 846 | # Python string library 847 | (r"\btoupper\(%(farg)s\)", r"\1.upper(", None), 848 | (r"\btolower\(%(farg)s\)", r"\1.lower(", None), 849 | # Python sys library 850 | (r"\bargv\(", r"sys.argv(", "sys"), 851 | (r"\bstdin\(", r"sys.stdin(", "sys"), 852 | (r"\bstdout\(", r"sys.stdout(", "sys"), 853 | (r"\bstderr\(", r"sys.stderr(", "sys"), 854 | # Python termios library 855 | (r"\btcgetattr\(", r"termios.tcgetattr(", "termios"), # Calling conventions differ 856 | (r"\btcsetattr\(", r"termios.tcsetattr(", "termios"), # Calling conventions differ 857 | (r"\btcsendbreak\(", r"termios.tcsendbreak(", "termios"), 858 | (r"\btcflush\(", r"termios.tcflush(", "termios"), 859 | (r"\btcdrain\(", r"termios.tcdrain(", "termios"), 860 | (r"\btcflow\(", r"termios.tcflow(", "termios"), 861 | (r"\bVMIN\b", r"termios.VMIN", "termios"), 862 | (r"\bVMAX\b", r"termios.VMAX", "termios"), 863 | (r"\bTCSANOW\b", r"termios.TCSANOW", "termios"), 864 | (r"\bTCSADRAIN\b", r"termios.TCSADRAIN", "termios"), 865 | (r"\bTCSAFLUSH\b", r"termios.TCSAFLUSH", "termios"), 866 | (r"\bTCIFLUSH\b", r"termios.TCIFLUSH", "termios"), 867 | (r"\bTCOFLUSH\b", r"termios.TCOFLUSH", "termios"), 868 | (r"\bTCOOFF\b", r"termios.TCOOFF", "termios"), 869 | (r"\bTCOON\b", r"termios.TCOON", "termios"), 870 | ) 871 | 872 | falsefriends = ( 873 | r"frexp", r"glob", r"ioctl", r"modf", r"tcgetattr", r"tcsetattr", 874 | r"ungetmouse", 875 | ) 876 | 877 | # These have to be applied to the entire file without breaking it into regions 878 | file_transformations = ( 879 | # Simple initializers to tuples 880 | (r"(?:static)?\s+(?:%(type)s|%(class)s)\s+(%(id)s)\[[a-zA-Z0-9._]*]\s*=\s*{([^}]+)}", 881 | r"\1 = (\2)"), 882 | (r"enum\s+(%(id)s\s*){\s*", r"enum \1{\n"), 883 | (r"enum\s+{\s*", r"enum {\n"), 884 | (r"%(ind)s#\s*\$ctopy.*", r""), # Make hints go away 885 | (r"(?:int )?main\(int\s+argc,\s+char\s+\*argv\)\s*{", 886 | "if __name__ == '__main__':"), 887 | ) 888 | 889 | # These need to be applied repeatedly within regions. 890 | # They rely on semicolons as statatement end markers. 891 | repeat_transformations = ( 892 | ( 893 | # Group 1: What we're doing here is stripping out prefix, suffix, 894 | # and wrapper parts of declarations in order to reduce everything 895 | # to base type followed by whitespace followed by id. This is 896 | # significant for simplifying both function formal parameter lists 897 | # and variable declaration lines. We'll get rid of the remaining 898 | # type stuff in a later pass. 899 | (r"(%(type)s|%(class)s)\s*\*", r"\1 "), # Pointer type decls 900 | (r"(%(type)s|%(class)s)(.*), \*", r"\1\2, "), # Pointer type decls 901 | (r"(%(type)s|%(class)s)\s*\((%(id)s)\)\(\)", r"\1 \2"), # Function pointer wrappers 902 | (r"(%(type)s|%(class)s)\s*(%(id)s)\[\]", r"\1 \2"), # Array declarators 903 | ), 904 | ( 905 | # Group 2: Translate function headers. This needs to happen after 906 | # reduction to base types (just above) but before scalar types 907 | # have been removed entirely. 908 | (r"\n(?:static\s+)?(?:%(type)s|%(class)s) +(.*\)) *\n", r"\ndef \1:\n"), 909 | ), 910 | ( 911 | # Group 3: What we're doing here is trying to get rid of variable 912 | # declarations that don't have initializer parts. 913 | # Scalar-vars just after the type and before a comma go away. 914 | (r"(\n[ \t]*(?:%(type)s))(\s*%(id)s),", r"\1 "), 915 | # Scalar-vars just after type and before a semi go away, but semi stays. 916 | (r"(\n[ \t]*(?:%(type)s))(\s*%(id)s);", r"\1;"), 917 | # Class-vars after class names and before comma or semi get an initializer. 918 | (r"(\n[ \t]*)(%(class)s)(\s*%(id)s)([;,])", r"\1\2\3 = \2()\4"), 919 | # Scalar-vars between a comma and a trailing semicolon go away. 920 | (r"(\n[ \t]*)((?:%(type)s).*)(,\s*%(id)s\s*);", r"\1\2;"), 921 | # Class-Vars between comma and semicolon get a following initializer 922 | (r"(\n[ \t]*)(%(class)s)(.*,\s)*(%(id)s)(\s*;)", r"\1\2\3\4 = \2()\5"), 923 | # Scalar-vars between commas in a declaration line go away. 924 | (r"(\n[ \t]*(?:%(type)s)\s+.*)(,\s*%(id)s)(,.*);", r"\1\3;"), 925 | # Bare class-vars between commas get an initializer 926 | (r"(\n[ \t]*)(%(class)s)(\s+.*,)(\s*%(id)s),(.*);",r"\1\2\3\4 = \2(),\5;"), 927 | # Any declaration line not containing an initializer goes away. 928 | (r"\n[ \t]*(?:%(type)s|%(class)s)[^=;]*;", r""), 929 | ), 930 | ( 931 | # Group 4: At this point all declarations left have initializers. 932 | # Replace commas in declaration lines with semis, otherwise Python will 933 | # barf later because it thinks that, e.g., a=4, b=5 is an attempt to 934 | # assign a constant to a tuple. 935 | # FIXME: This will fail messily on GCC structure intializers. 936 | (r"(\n[ \t]*(?:%(type)s|%(class)s).*),(.*);", r"\1;\2"), 937 | ), 938 | ( 939 | # Group 5: Now rip out all remaining base type information. 940 | # This will strip remaining type declarators out of formal parameter lists. 941 | # It will also remove types from the beginning of declaration lines. 942 | # Won't nuke casts because it looks for at least one following whitespace. 943 | (r"(?:%(type)s|%(class)s)[\s;]\s*", r""), 944 | ), 945 | ) 946 | 947 | # These get applied once within regions, before type info has been stripped 948 | pre_transformations = ( 949 | # We used to do function header translation here. We leave 950 | # this in place because we'll probably need to do things here again. 951 | ) 952 | 953 | # These get applied once within regions, after type info has been stripped 954 | post_transformations = ( 955 | # some consequences of having translated function headers 956 | (r"\(void\):\n", r"():\n"), 957 | (r"def(.*):\n\Z", r"def\1:\n "), # indent comment on line after def 958 | # externs can just disappear -- this may discard a following comment 959 | (r"extern[^;]+;.*\n", r""), 960 | # macros 961 | (r"#define\s+(%(id)s)\s+(.*)", r"\1\t= \2"), 962 | (r"#define\s+(%(id)s)\(([^)]*)\)\s+(.*\))", r"def \1(\2):\treturn \3"), 963 | (r"#define\s+(%(id)s)\(([^)]*)\)\s+([^(].*)", r"def \1(\2):\t\3"), 964 | # control structure 965 | (r"\bif *\((.*)\)(\s*{)?", r"if \1:"), 966 | (r"\bdo\s*{", r"while True:"), 967 | (r"}\s*while\s*(\(.*\));", r" if not \1: break # DO-WHILE TERMINATOR -- INDENTATION CAN BE WRONG"), 968 | (r"\bwhile *\((.*)\)(\s*{)?", r"while \1:"), 969 | (r"\bwhile 1:", r"while True:"), 970 | (r"\bfor \(;;\)(\s*{)?", r"while True:"), 971 | (r"\bfor \((%(id)s) *= *0; *\1 *<= *([^;]+); *\1\+\+\)(\s*{)?", 972 | r"for \1 in range(\2+1):"), 973 | (r"\bfor \((%(id)s) *= *([^;]+); *\1 *<= *([^;]+); *\1\+\+\)(\s*{)?", 974 | r"for \1 in range(\2, \3+1):"), 975 | (r"\bfor \((%(id)s) *= *0; *\1 *< *([^;]+); *\1\+\+\)\s*{", 976 | r"for \1 in range(\2):"), 977 | (r"\bfor \((%(id)s) *= *([^;]+); *\1 *< *([^;]+); *\1\+\+\)(\s*{)?", 978 | r"for \1 in range(\2, \3):"), 979 | (r"else if", r"elif"), 980 | (r"(?:} )?else\s*{", r"else"), 981 | (r"(?", r"."), 992 | (r"!(?!=) *", r"not "), 993 | (r"(and|or) *\n", r"\1 \\\n"), 994 | # most common uses of address operator 995 | (r"return *&", r"return "), 996 | (r"= *&", r"= "), 997 | # increment and decrement statements 998 | (r"(%(id)s)\+\+([;\n])", r"\1 += 1\2"), 999 | (r"(%(id)s)--([;\n])", r"\1 -= 1\2"), 1000 | (r"\+\+(%(id)s)([;\n])", r"\1 += 1\2"), 1001 | (r"--(%(id)s)([;\n])", r"\1 -= 1\2"), 1002 | # no-op voids 1003 | (r"\n[ \t]*\(void\)", r"\n"), 1004 | # C functions that turn into Python builtins 1005 | (r"\batoi\(", r"int("), 1006 | (r"\batof\(", r"float("), 1007 | (r"\batol\(", r"long("), 1008 | (r"\bfopen\(", r"open("), 1009 | (r"\bputchar\(", r"stdout.write("), 1010 | (r"\bgetchar\(\)", r"stdout.read(1)"), 1011 | (r"\bstrlen\(", r"len("), 1012 | (r"\bstrcmp\((%(exp)s),\s*(%(exp)s)\)\s*==\s*0", r"\1 == \2"), 1013 | (r"\bstrcmp\((%(exp)s),\s*(%(exp)s)\)\s*!=\s*0", r"\1 != \2"), 1014 | (r"\bstrcpy\((%(exp)s),\s*(%(exp)s)\)", r"\1 = \2"), 1015 | # Python time library 1016 | (r"\btime\(NULL\)", r"time.time()"), 1017 | # well-known includes 1018 | (r"#include \\n", r""), 1019 | (r"#include \\n", r""), 1020 | (r"#include \\n", r""), 1021 | (r"#include \\n", r"import sys\n"), 1022 | (r"#include \\n", r"import math\n"), 1023 | (r"#include \\n", r"import time\n"), 1024 | (r"#include \\n", r"import re\n"), 1025 | (r"#include \\n", r"import curses\n"), 1026 | (r"#include \\n", r"import termios\n"), 1027 | ) 1028 | 1029 | final_transformations = ( 1030 | # block delimiters -- do these as late as possible, they're useful 1031 | (r";(%(eol)s)", r"\1"), 1032 | (r"\n[ \t]*}%(eol)s", r""), 1033 | (r"(?= 2 and text != oldtext: 1046 | print "%s transforms '%s' to '%s'" % ((fro, to), `oldtext`, `text`) 1047 | return text 1048 | 1049 | def repeat_apply(transforms, text): 1050 | "Repeatedly apply specified transformations to text until it's stable." 1051 | while True: 1052 | transformed = single_apply(transforms, text) 1053 | if transformed != text: 1054 | text = transformed 1055 | else: 1056 | break 1057 | return text 1058 | 1059 | def ctopy(input): 1060 | "Transform C to Python." 1061 | if debug >= 2: 1062 | print "Gathering hints" 1063 | hints = re.finditer(r"\$ctopy (.*)", input) 1064 | for hint in hints: 1065 | process_hint(hint.group(1)) 1066 | if debug >= 2: 1067 | print "Processing inline enums" 1068 | global stringify 1069 | enums = re.finditer(r"enum[ \t]*{(.*)} (%(id)s)" % shorthands, input) 1070 | for instance in enums: 1071 | stringify += instance.group(1).replace(" ", "").split(",") 1072 | input = input[:instance.start(0)] + input[instance.start(2):] 1073 | if debug: 1074 | print "Pre-transformations begin" 1075 | input = repeat_apply(file_transformations, input) 1076 | if debug >= 2: 1077 | print "After pre-transformations: %s" % `code` 1078 | if debug: 1079 | print "Region analysis begins" 1080 | boundaries = [0] 1081 | state = "text" 1082 | for i in range(len(input)): 1083 | if state == "text": 1084 | if input[i] == '"' and (i == 0 or input[i-1] != '\\'): 1085 | if debug >= 2: 1086 | print "String literal starts at %d" % i 1087 | boundaries.append(i) 1088 | state = "stringliteral" 1089 | elif input[i:i+2] == "/*": 1090 | if debug >= 2: 1091 | print "Closed comment starts at %d" % (i-1) 1092 | boundaries.append(i) 1093 | state = "closedcomment" 1094 | elif input[i:i+2] == "//": 1095 | if debug >= 2: 1096 | print "Open comment starts at %d" % i 1097 | boundaries.append(i) 1098 | state = "opencomment" 1099 | elif input[i:].startswith("typedef enum {") or input[i:].startswith("enum {"): 1100 | if debug >= 2: 1101 | print "enumeration starts at %d" % i 1102 | if input[i-2:i+1] != 'f e': 1103 | boundaries.append(i) 1104 | boundaries.append(i + input[i:].find("enum") + 5) 1105 | elif input[i:].startswith("\n}"): 1106 | if debug >= 2: 1107 | print "start-of-line brace at %d" % i 1108 | boundaries.append(i) 1109 | boundaries.append(i+2) 1110 | elif state == "stringliteral": 1111 | if input[i] == '"' and (i == 0 or input[i-1] != '\\'): 1112 | if debug >= 2: 1113 | print "String ends at %d" % i 1114 | boundaries.append(i+1) 1115 | state = "text" 1116 | elif state == "closedcomment": 1117 | if input[i:i+2] == "*/": 1118 | if debug >= 2: 1119 | print "closed comment ends at %d" % (i+1) 1120 | boundaries.append(i+2) 1121 | state = "text" 1122 | elif state == "opencomment": 1123 | if input[i] == "\n": 1124 | if debug >= 2: 1125 | print "Open comment ends at %d" % (i+1) 1126 | boundaries.append(i+1) 1127 | state = "text" 1128 | boundaries.append(len(input)) 1129 | if debug >= 2: 1130 | print "Boundaries:", boundaries 1131 | regions = [] 1132 | for i in range(len(boundaries)-1): 1133 | regions.append(input[boundaries[i]:boundaries[i+1]]) 1134 | regions = filter(lambda x: x != '', regions) 1135 | if debug: 1136 | print "Regexp transformation begins" 1137 | if debug: 1138 | import pprint 1139 | pp = pprint.PrettyPrinter(indent=4) 1140 | print "Regions:" 1141 | pp.pprint(regions) 1142 | if debug >= 2: 1143 | print "Processing printf-like functions" 1144 | for (i, here) in enumerate(regions): 1145 | if regions[i][0] != '"' or not "%" in here: 1146 | continue 1147 | else: 1148 | for func in printflike: 1149 | if re.search(r"\b%s\([^;]*\Z" % func, regions[i]): 1150 | break 1151 | else: 1152 | continue # Didn't find printf-like function 1153 | # Found printf-like function. Replace first comma in the 1154 | # argument region with " % (". This copes gracefully with the 1155 | # case where the format string is wrapped in _( ) for 1156 | # initialization. 1157 | regions[i+1] = re.sub(r",\s*", r" % (", regions[i+1], 1) 1158 | j = regions[i+1].find("%") + 2 1159 | parenlevel = 0 1160 | while j < len(regions[i+1]): 1161 | if regions[i+1][j] == "(": 1162 | parenlevel += 1 1163 | if regions[i+1][j] == ")": 1164 | parenlevel -= 1 1165 | if parenlevel == 0: 1166 | regions[i+1] = regions[i+1][:j] + ")" + regions[i+1][j:] 1167 | break 1168 | j += 1 1169 | importlist = [] 1170 | try: 1171 | for i in range(len(regions)): 1172 | if regions[i][:2] == "/*": 1173 | if regions[i].count("\n") <= 1: # winged comment 1174 | regions[i] = "#" + regions[i][2:-2] 1175 | elif re.search("/\*+\n", regions[i]): # boxed comment 1176 | regions[i] = re.sub(r"\n([ \t]*) \* ?", r"\n\1",regions[i]) 1177 | regions[i] = re.sub(r"\n([ \t]*)\*", r"\n\1", regions[i]) 1178 | regions[i] = re.sub(r"^([ \t]*)/\*+\n", r"\1#\n", regions[i]) 1179 | regions[i] = re.sub(r"\n([ \t]*)\**/", r"\n\1", regions[i]) 1180 | regions[i] = re.sub(r"\n([ \t]*)(?!#)", r"\n\1# ", regions[i]) 1181 | else: 1182 | regions[i] = regions[i].replace("/*", "#") 1183 | regions[i] = regions[i].replace("\n*/", "\n#") 1184 | regions[i] = regions[i].replace("*/", "") 1185 | regions[i] = regions[i].replace("\n *", "\n") 1186 | regions[i] = regions[i].replace("\n", "\n#") 1187 | elif regions[i][:2] == "//": 1188 | regions[i] = "#" + regions[i][2:] 1189 | elif regions[i][0] != '"': 1190 | if debug >= 2: 1191 | print "Doing pre transformations" 1192 | regions[i] = single_apply(pre_transformations, regions[i]) 1193 | if debug >= 2: 1194 | print "Doing repeated transformations" 1195 | for (j, hack) in enumerate(repeat_transformations): 1196 | if debug >= 2: 1197 | print "Repeat transformations group %d" % (j+1) 1198 | regions[i] = repeat_apply(hack, regions[i]) 1199 | if debug: 1200 | print "Function and method mappings begin" 1201 | for (fro, to, module) in funmappings: 1202 | if re.search(fro, regions[i]): 1203 | regions[i] = re.sub(fro, to, regions[i]) 1204 | if module not in importlist and module: 1205 | importlist.append(module) 1206 | for name in falsefriends: 1207 | if re.search(r"\b" + name + r"\b\(", regions[i]): 1208 | sys.stderr.write("warning: %s calling conventions differ between C and Python." % name) 1209 | if debug >= 2: 1210 | print "Doing post transformations" 1211 | regions[i] = single_apply(post_transformations, regions[i]) 1212 | for str in stringify: 1213 | regions[i] = re.sub(r"\b" + str + r"\b", 1214 | '"' + str + '"', regions[i]) 1215 | except IndexError: 1216 | sys.stderr.write("ctopy: pathological string literal at %d.\n" % boundaries[i]) 1217 | raise SystemExit, 1 1218 | if debug: 1219 | print "Enumeration processing" 1220 | state = "plain" 1221 | for (i, region) in enumerate(regions): 1222 | # first compute a parse state 1223 | if region.startswith("typedef enum"): 1224 | state = "typedef" 1225 | elif region.startswith("enum"): 1226 | state = "enum" 1227 | elif region == "\n}": 1228 | if state in ("typedef", "enum"): 1229 | regions[i] = '' 1230 | state = "plain" 1231 | # now do something useful with it 1232 | if debug >= 3: 1233 | print "Enumeration processing: state = %s, region = %s" % (state, `regions[i]`) 1234 | if state in ("enum", "typedef"): 1235 | if regions[i] == "enum ": 1236 | m = re.match("(%(id)s) {" % shorthands, regions[i+1]) 1237 | if m: 1238 | shorthands['type'] += "|" + m.group(1) 1239 | regions[i] = '# From enumerated type \'%s\'\n' % m.group(1) 1240 | regions[i+1] = regions[i+1][m.end(0)+1:] 1241 | else: 1242 | regions[i] = '# From anonymous enumerated type\n' 1243 | elif regions[i] == "typedef enum ": 1244 | m = re.match("\s* (%(id)s)\s*;?" % shorthands, regions[i+3]) 1245 | if m: 1246 | shorthands['type'] += "|" + m.group(1) 1247 | regions[i] = '# From enumerated type \'%s\'\n' % m.group(1) 1248 | regions[i+3] = regions[i+3][:m.start(0)] + "\n\n" 1249 | else: 1250 | regions[i] = '# From anonymous typedefed enum (?!)\n' 1251 | else: 1252 | regions[i] = re.sub(",\s*", "\n", regions[i]) 1253 | val = 0 1254 | txt = regions[i].split("\n") 1255 | for j in range(len(txt)): 1256 | if txt[j] == '' or txt[j].startswith("{"): 1257 | pass 1258 | elif '=' not in txt[j]: 1259 | txt[j] += " = %d" % val 1260 | val += 1 1261 | regions[i] = "\n".join(txt) 1262 | if debug: 1263 | print "Final transformations begin" 1264 | regions = map(lambda r: repeat_apply(final_transformations, r),regions) 1265 | text = "".join(regions) 1266 | if importlist: 1267 | importlist = "import " + ", ".join(importlist) + "\n" 1268 | text = importlist + text 1269 | # Emit what we got. Preserve imports in case this is a .h file 1270 | return text 1271 | 1272 | def process_hint(line): 1273 | "Process a translation-hints line." 1274 | if line[0] == "#": 1275 | pass 1276 | else: 1277 | global stringify, printflike 1278 | if debug >= 2: 1279 | print "Hint: %s" % `line` 1280 | lst = line.replace(",", " ").split() 1281 | if lst[0] == "stringify": 1282 | stringify += lst[1:] 1283 | elif lst[0] == "type": 1284 | for tok in lst[1:]: 1285 | shorthands["type"] += r"|\b" + tok + r"\b" 1286 | elif lst[0] == "class": 1287 | for tok in lst[1:]: 1288 | shorthands["class"] += r"|\b" + tok + r"\b" 1289 | elif lst[0] == "printflike": 1290 | printflike += lst[1:] 1291 | 1292 | if __name__ == "__main__": 1293 | import getopt 1294 | (options, arguments) = getopt.getopt(sys.argv[1:], "c:h:ds:t:") 1295 | debug = 0; 1296 | for (switch, val) in options: 1297 | if (switch == '-c'): 1298 | shorthands["class"] += r"|\b" + val + r"\b" 1299 | elif (switch == '-d'): 1300 | debug += 1 1301 | elif (switch == '-h'): 1302 | for line in open(val): 1303 | process_hint(line) 1304 | elif (switch == '-s'): 1305 | stringify.append(val) 1306 | elif (switch == '-t'): 1307 | shorthands["type"] += r"|\b" + val + r"\b" 1308 | 1309 | try: 1310 | code = sys.stdin.read() 1311 | if debug >= 2: 1312 | print "Input is: %s" % `code` 1313 | text = ctopy(code) 1314 | if debug: 1315 | print "Output:" 1316 | sys.stdout.write(text) 1317 | except KeyboardInterrupt: 1318 | pass 1319 | --------------------------------------------------------------------------------