cpython/Modules/_cursesmodule.c
Thomas Wouters 00ee7baf49 Merge current trunk into p3yk. This includes the PyNumber_Index API change,
which unfortunately means the errors from the bytes type change somewhat:

bytes([300]) still raises a ValueError, but bytes([10**100]) now raises a
TypeError (either that, or bytes(1.0) also raises a ValueError --
PyNumber_AsSsize_t() can only raise one type of exception.)

Merged revisions 51188-51433 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r51189 | kurt.kaiser | 2006-08-10 19:11:09 +0200 (Thu, 10 Aug 2006) | 4 lines

  Retrieval of previous shell command was not always preserving indentation
  since 1.2a1) Patch 1528468 Tal Einat.
........
  r51190 | guido.van.rossum | 2006-08-10 19:41:07 +0200 (Thu, 10 Aug 2006) | 3 lines

  Chris McDonough's patch to defend against certain DoS attacks on FieldStorage.
  SF bug #1112549.
........
  r51191 | guido.van.rossum | 2006-08-10 19:42:50 +0200 (Thu, 10 Aug 2006) | 2 lines

  News item for SF bug 1112549.
........
  r51192 | guido.van.rossum | 2006-08-10 20:09:25 +0200 (Thu, 10 Aug 2006) | 2 lines

  Fix title -- it's rc1, not beta3.
........
  r51194 | martin.v.loewis | 2006-08-10 21:04:00 +0200 (Thu, 10 Aug 2006) | 3 lines

  Update dangling references to the 3.2 database to
  mention that this is UCD 4.1 now.
........
  r51195 | tim.peters | 2006-08-11 00:45:34 +0200 (Fri, 11 Aug 2006) | 6 lines

  Followup to bug #1069160.

  PyThreadState_SetAsyncExc():  internal correctness changes wrt
  refcount safety and deadlock avoidance.  Also added a basic test
  case (relying on ctypes) and repaired the docs.
........
  r51196 | tim.peters | 2006-08-11 00:48:45 +0200 (Fri, 11 Aug 2006) | 2 lines

  Whitespace normalization.
........
  r51197 | tim.peters | 2006-08-11 01:22:13 +0200 (Fri, 11 Aug 2006) | 5 lines

  Whitespace normalization broke test_cgi, because a line
  of quoted test data relied on preserving a single trailing
  blank.  Changed the string from raw to regular, and forced
  in the trailing blank via an explicit \x20 escape.
........
  r51198 | tim.peters | 2006-08-11 02:49:01 +0200 (Fri, 11 Aug 2006) | 10 lines

  test_PyThreadState_SetAsyncExc():  This is failing on some
  64-bit boxes.  I have no idea what the ctypes docs mean
  by "integers", and blind-guessing here that it intended to
  mean the signed C "int" type, in which case perhaps I can
  repair this by feeding the thread id argument to type
  ctypes.c_long().

  Also made the worker thread daemonic, so it doesn't hang
  Python shutdown if the test continues to fail.
........
  r51199 | tim.peters | 2006-08-11 05:49:10 +0200 (Fri, 11 Aug 2006) | 6 lines

  force_test_exit():  This has been completely ineffective
  at stopping test_signal from hanging forever on the Tru64
  buildbot.  That could be because there's no such thing as
  signal.SIGALARM.  Changed to the idiotic (but standard)
  signal.SIGALRM instead, and added some more debug output.
........
  r51202 | neal.norwitz | 2006-08-11 08:09:41 +0200 (Fri, 11 Aug 2006) | 6 lines

  Fix the failures on cygwin (2006-08-10 fixed the actual locking issue).

  The first hunk changes the colon to an ! like other Windows variants.
  We need to always wait on the child so the lock gets released and
  no other tests fail.  This is the try/finally in the second hunk.
........
  r51205 | georg.brandl | 2006-08-11 09:15:38 +0200 (Fri, 11 Aug 2006) | 3 lines

  Add Chris McDonough (latest cgi.py patch)
........
  r51206 | georg.brandl | 2006-08-11 09:26:10 +0200 (Fri, 11 Aug 2006) | 3 lines

  logging's atexit hook now runs even if the rest of the module has
  already been cleaned up.
........
  r51212 | thomas.wouters | 2006-08-11 17:02:39 +0200 (Fri, 11 Aug 2006) | 4 lines


  Add ignore of *.pyc and *.pyo to Lib/xml/etree/.
........
  r51215 | thomas.heller | 2006-08-11 21:55:35 +0200 (Fri, 11 Aug 2006) | 7 lines

  When a ctypes C callback function is called, zero out the result
  storage before converting the result to C data.  See the comment in
  the code for details.

  Provide a better context for errors when the conversion of a callback
  function's result cannot be converted.
........
  r51218 | neal.norwitz | 2006-08-12 03:43:40 +0200 (Sat, 12 Aug 2006) | 6 lines

  Klocwork made another run and found a bunch more problems.
  This is the first batch of fixes that should be easy to verify based on context.

  This fixes problem numbers: 220 (ast), 323-324 (symtable),
  321-322 (structseq), 215 (array), 210 (hotshot), 182 (codecs), 209 (etree).
........
  r51219 | neal.norwitz | 2006-08-12 03:45:47 +0200 (Sat, 12 Aug 2006) | 9 lines

  Even though _Py_Mangle() isn't truly public anyone can call it and
  there was no verification that privateobj was a PyString.  If it wasn't
  a string, this could have allowed a NULL pointer to creep in below and crash.

  I wonder if this should be PyString_CheckExact?  Must identifiers be strings
  or can they be subclasses?

  Klocwork #275
........
  r51220 | neal.norwitz | 2006-08-12 03:46:42 +0200 (Sat, 12 Aug 2006) | 5 lines

  It's highly unlikely, though possible for PyEval_Get*() to return NULLs.
  So be safe and do an XINCREF.

  Klocwork # 221-222.
........
  r51221 | neal.norwitz | 2006-08-12 03:47:59 +0200 (Sat, 12 Aug 2006) | 7 lines

  This code is actually not used unless WITHOUT_COMPLEX is defined.
  However, there was no error checking that PyFloat_FromDouble returned
  a valid pointer.  I believe this change is correct as it seemed
  to follow other code in the area.

  Klocwork # 292.
........
  r51222 | neal.norwitz | 2006-08-12 03:49:12 +0200 (Sat, 12 Aug 2006) | 5 lines

  Handle NULL nodes while parsing.  I'm not entirely sure this is correct.
  There might be something else that needs to be done to setup the error.

  Klocwork #295.
........
  r51223 | neal.norwitz | 2006-08-12 03:50:38 +0200 (Sat, 12 Aug 2006) | 6 lines

  If _stat_float_times is false, we will try to INCREF ival which could be NULL.
  Return early in that case.  The caller checks for PyErr_Occurred so this
  should be ok.

  Klocwork #297
........
  r51224 | neal.norwitz | 2006-08-12 03:51:12 +0200 (Sat, 12 Aug 2006) | 3 lines

  Move the assert which checks for a NULL pointer first.
  Klocwork #274.
........
  r51225 | neal.norwitz | 2006-08-12 03:53:28 +0200 (Sat, 12 Aug 2006) | 5 lines

  Try to handle a malloc failure.  I'm not entirely sure this is correct.
  There might be something else we need to do to handle the exception.

  Klocwork # 212-213
........
  r51226 | neal.norwitz | 2006-08-12 03:57:47 +0200 (Sat, 12 Aug 2006) | 6 lines

  I'm not sure why this code allocates this string for the error message.
  I think it would be better to always use snprintf and have the format
  limit the size of the name appropriately (like %.200s).

  Klocwork #340
........
  r51227 | neal.norwitz | 2006-08-12 04:06:34 +0200 (Sat, 12 Aug 2006) | 3 lines

  Check returned pointer is valid.
  Klocwork #233
........
  r51228 | neal.norwitz | 2006-08-12 04:12:30 +0200 (Sat, 12 Aug 2006) | 1 line

  Whoops, how did that get in there. :-)  Revert all the parts of 51227 that were not supposed to go it.  Only Modules/_ctypes/cfields.c was supposed to be changed
........
  r51229 | neal.norwitz | 2006-08-12 04:33:36 +0200 (Sat, 12 Aug 2006) | 4 lines

  Don't deref v if it's NULL.

  Klocwork #214
........
  r51230 | neal.norwitz | 2006-08-12 05:16:54 +0200 (Sat, 12 Aug 2006) | 5 lines

  Check return of PyMem_MALLOC (garbage) is non-NULL.
  Check seq in both portions of if/else.

  Klocwork #289-290.
........
  r51231 | neal.norwitz | 2006-08-12 05:17:41 +0200 (Sat, 12 Aug 2006) | 4 lines

  PyModule_GetDict() can fail, produce fatal errors if this happens on startup.

  Klocwork #298-299.
........
  r51232 | neal.norwitz | 2006-08-12 05:18:50 +0200 (Sat, 12 Aug 2006) | 5 lines

  Verify verdat which is returned from malloc is not NULL.
  Ensure we don't pass NULL to free.

  Klocwork #306 (at least the first part, checking malloc)
........
  r51233 | tim.peters | 2006-08-12 06:42:47 +0200 (Sat, 12 Aug 2006) | 35 lines

  test_signal:  Signal handling on the Tru64 buildbot
  appears to be utterly insane.  Plug some theoretical
  insecurities in the test script:

  - Verify that the SIGALRM handler was actually installed.

  - Don't call alarm() before the handler is installed.

  - Move everything that can fail inside the try/finally,
    so the test cleans up after itself more often.

  - Try sending all the expected signals in
    force_test_exit(), not just SIGALRM.  Since that was
    fixed to actually send SIGALRM (instead of invisibly
    dying with an AttributeError), we've seen that sending
    SIGALRM alone does not stop this from hanging.

  - Move the "kill the child" business into the finally
    clause, so the child doesn't survive test failure
    to send SIGALRM to other tests later (there are also
    baffling SIGALRM-related failures in test_socket).

  - Cancel the alarm in the finally clause -- if the
    test dies early, we again don't want SIGALRM showing
    up to confuse a later test.

  Alas, this still relies on timing luck wrt the spawned
  script that sends the test signals, but it's hard to see
  how waiting for seconds can so often be so unlucky.

  test_threadedsignals:  curiously, this test never fails
  on Tru64, but doesn't normally signal SIGALRM.  Anyway,
  fixed an obvious (but probably inconsequential) logic
  error.
........
  r51234 | tim.peters | 2006-08-12 07:17:41 +0200 (Sat, 12 Aug 2006) | 8 lines

  Ah, fudge.  One of the prints here actually "shouldn't be"
  protected by "if verbose:", which caused the test to fail on
  all non-Windows boxes.

  Note that I deliberately didn't convert this to unittest yet,
  because I expect it would be even harder to debug this on Tru64
  after conversion.
........
  r51235 | georg.brandl | 2006-08-12 10:32:02 +0200 (Sat, 12 Aug 2006) | 3 lines

  Repair logging test spew caused by rev. 51206.
........
  r51236 | neal.norwitz | 2006-08-12 19:03:09 +0200 (Sat, 12 Aug 2006) | 8 lines

  Patch #1538606, Patch to fix __index__() clipping.

  I modified this patch some by fixing style, some error checking, and adding
  XXX comments.  This patch requires review and some changes are to be expected.
  I'm checking in now to get the greatest possible review and establish a
  baseline for moving forward.  I don't want this to hold up release if possible.
........
  r51238 | neal.norwitz | 2006-08-12 20:44:06 +0200 (Sat, 12 Aug 2006) | 10 lines

  Fix a couple of bugs exposed by the new __index__ code.  The 64-bit buildbots
  were failing due to inappropriate clipping of numbers larger than 2**31
  with new-style classes. (typeobject.c)  In reviewing the code for classic
  classes, there were 2 problems.  Any negative value return could be returned.
  Always return -1 if there was an error.  Also make the checks similar
  with the new-style classes.  I believe this is correct for 32 and 64 bit
  boxes, including Windows64.

  Add a test of classic classes too.
........
  r51240 | neal.norwitz | 2006-08-13 02:20:49 +0200 (Sun, 13 Aug 2006) | 1 line

  SF bug #1539336, distutils example code missing
........
  r51245 | neal.norwitz | 2006-08-13 20:10:10 +0200 (Sun, 13 Aug 2006) | 6 lines

  Move/copy assert for tstate != NULL before first use.
  Verify that PyEval_Get{Globals,Locals} returned valid pointers.

  Klocwork 231-232
........
  r51246 | neal.norwitz | 2006-08-13 20:10:28 +0200 (Sun, 13 Aug 2006) | 5 lines

  Handle a whole lot of failures from PyString_FromInternedString().

  Should fix most of Klocwork 234-272.
........
  r51247 | neal.norwitz | 2006-08-13 20:10:47 +0200 (Sun, 13 Aug 2006) | 8 lines

  cpathname could be NULL if it was longer than MAXPATHLEN.  Don't try
  to write the .pyc to NULL.

  Check results of PyList_GetItem() and PyModule_GetDict() are not NULL.

  Klocwork 282, 283, 285
........
  r51248 | neal.norwitz | 2006-08-13 20:11:08 +0200 (Sun, 13 Aug 2006) | 6 lines

  Fix segfault when doing string formatting on subclasses of long if
  __oct__, __hex__ don't return a string.

  Klocwork 308
........
  r51250 | neal.norwitz | 2006-08-13 20:11:27 +0200 (Sun, 13 Aug 2006) | 5 lines

  Check return result of PyModule_GetDict().
  Fix a bunch of refleaks in the init of the module.  This would only be found
  when running python -v.
........
  r51251 | neal.norwitz | 2006-08-13 20:11:43 +0200 (Sun, 13 Aug 2006) | 5 lines

  Handle malloc and fopen failures more gracefully.

  Klocwork 180-181
........
  r51252 | neal.norwitz | 2006-08-13 20:12:03 +0200 (Sun, 13 Aug 2006) | 7 lines

  It's very unlikely, though possible that source is not a string.  Verify
  that PyString_AsString() returns a valid pointer.  (The problem can
  arise when zlib.decompress doesn't return a string.)

  Klocwork 346
........
  r51253 | neal.norwitz | 2006-08-13 20:12:26 +0200 (Sun, 13 Aug 2006) | 5 lines

  Handle failures from lookup.

  Klocwork 341-342
........
  r51254 | neal.norwitz | 2006-08-13 20:12:45 +0200 (Sun, 13 Aug 2006) | 6 lines

  Handle failure from PyModule_GetDict() (Klocwork 208).

  Fix a bunch of refleaks in the init of the module.  This would only be found
  when running python -v.
........
  r51255 | neal.norwitz | 2006-08-13 20:13:02 +0200 (Sun, 13 Aug 2006) | 4 lines

  Really address the issue of where to place the assert for leftblock.
  (Followup of Klocwork 274)
........
  r51256 | neal.norwitz | 2006-08-13 20:13:36 +0200 (Sun, 13 Aug 2006) | 4 lines

  Handle malloc failure.

  Klocwork 281
........
  r51258 | neal.norwitz | 2006-08-13 20:40:39 +0200 (Sun, 13 Aug 2006) | 4 lines

  Handle alloca failures.

  Klocwork 225-228
........
  r51259 | neal.norwitz | 2006-08-13 20:41:15 +0200 (Sun, 13 Aug 2006) | 1 line

  Get rid of compiler warning
........
  r51261 | neal.norwitz | 2006-08-14 02:51:15 +0200 (Mon, 14 Aug 2006) | 1 line

  Ignore pgen.exe and kill_python.exe for cygwin
........
  r51262 | neal.norwitz | 2006-08-14 02:59:03 +0200 (Mon, 14 Aug 2006) | 4 lines

  Can't return NULL from a void function.  If there is a memory error,
  about the best we can do is call PyErr_WriteUnraisable and go on.
  We won't be able to do the call below either, so verify delstr is valid.
........
  r51263 | neal.norwitz | 2006-08-14 03:49:54 +0200 (Mon, 14 Aug 2006) | 1 line

  Update purify doc some.
........
  r51264 | thomas.heller | 2006-08-14 09:13:05 +0200 (Mon, 14 Aug 2006) | 2 lines

  Remove unused, buggy test function.
  Fixes klockwork issue #207.
........
  r51265 | thomas.heller | 2006-08-14 09:14:09 +0200 (Mon, 14 Aug 2006) | 2 lines

  Check for NULL return value from new_CArgObject().
  Fixes klockwork issues #183, #184, #185.
........
  r51266 | thomas.heller | 2006-08-14 09:50:14 +0200 (Mon, 14 Aug 2006) | 2 lines

  Check for NULL return value of GenericCData_new().
  Fixes klockwork issues #188, #189.
........
  r51274 | thomas.heller | 2006-08-14 12:02:24 +0200 (Mon, 14 Aug 2006) | 2 lines

  Revert the change that tries to zero out a closure's result storage
  area because the size if unknown in source/callproc.c.
........
  r51276 | marc-andre.lemburg | 2006-08-14 12:55:19 +0200 (Mon, 14 Aug 2006) | 11 lines

  Slightly revised version of patch #1538956:

  Replace UnicodeDecodeErrors raised during == and !=
  compares of Unicode and other objects with a new
  UnicodeWarning.

  All other comparisons continue to raise exceptions.
  Exceptions other than UnicodeDecodeErrors are also left
  untouched.
........
  r51277 | thomas.heller | 2006-08-14 13:17:48 +0200 (Mon, 14 Aug 2006) | 13 lines

  Apply the patch #1532975 plus ideas from the patch #1533481.

  ctypes instances no longer have the internal and undocumented
  '_as_parameter_' attribute which was used to adapt them to foreign
  function calls; this mechanism is replaced by a function pointer in
  the type's stgdict.

  In the 'from_param' class methods, try the _as_parameter_ attribute if
  other conversions are not possible.

  This makes the documented _as_parameter_ mechanism work as intended.

  Change the ctypes version number to 1.0.1.
........
  r51278 | marc-andre.lemburg | 2006-08-14 13:44:34 +0200 (Mon, 14 Aug 2006) | 3 lines

  Readd NEWS items that were accidentally removed by r51276.
........
  r51279 | georg.brandl | 2006-08-14 14:36:06 +0200 (Mon, 14 Aug 2006) | 3 lines

  Improve markup in PyUnicode_RichCompare.
........
  r51280 | marc-andre.lemburg | 2006-08-14 14:57:27 +0200 (Mon, 14 Aug 2006) | 3 lines

  Correct an accidentally removed previous patch.
........
  r51281 | thomas.heller | 2006-08-14 18:17:41 +0200 (Mon, 14 Aug 2006) | 3 lines

  Patch #1536908: Add support for AMD64 / OpenBSD.
  Remove the -no-stack-protector compiler flag for OpenBSD
  as it has been reported to be unneeded.
........
  r51282 | thomas.heller | 2006-08-14 18:20:04 +0200 (Mon, 14 Aug 2006) | 1 line

  News item for rev 51281.
........
  r51283 | georg.brandl | 2006-08-14 22:25:39 +0200 (Mon, 14 Aug 2006) | 3 lines

  Fix refleak introduced in rev. 51248.
........
  r51284 | georg.brandl | 2006-08-14 23:34:08 +0200 (Mon, 14 Aug 2006) | 5 lines

  Make tabnanny recognize IndentationErrors raised by tokenize.
  Add a test to test_inspect to make sure indented source
  is recognized correctly. (fixes #1224621)
........
  r51285 | georg.brandl | 2006-08-14 23:42:55 +0200 (Mon, 14 Aug 2006) | 3 lines

  Patch #1535500: fix segfault in BZ2File.writelines and make sure it
  raises the correct exceptions.
........
  r51287 | georg.brandl | 2006-08-14 23:45:32 +0200 (Mon, 14 Aug 2006) | 3 lines

  Add an additional test: BZ2File write methods should raise IOError
  when file is read-only.
........
  r51289 | georg.brandl | 2006-08-14 23:55:28 +0200 (Mon, 14 Aug 2006) | 3 lines

  Patch #1536071: trace.py should now find the full module name of a
  file correctly even on Windows.
........
  r51290 | georg.brandl | 2006-08-15 00:01:24 +0200 (Tue, 15 Aug 2006) | 3 lines

  Cookie.py shouldn't "bogusly" use string._idmap.
........
  r51291 | georg.brandl | 2006-08-15 00:10:24 +0200 (Tue, 15 Aug 2006) | 3 lines

  Patch #1511317: don't crash on invalid hostname info
........
  r51292 | tim.peters | 2006-08-15 02:25:04 +0200 (Tue, 15 Aug 2006) | 2 lines

  Whitespace normalization.
........
  r51293 | neal.norwitz | 2006-08-15 06:14:57 +0200 (Tue, 15 Aug 2006) | 3 lines

  Georg fixed one of my bugs, so I'll repay him with 2 NEWS entries.
  Now we're even. :-)
........
  r51295 | neal.norwitz | 2006-08-15 06:58:28 +0200 (Tue, 15 Aug 2006) | 8 lines

  Fix the test for SocketServer so it should pass on cygwin and not fail
  sporadically on other platforms.  This is really a band-aid that doesn't
  fix the underlying issue in SocketServer.  It's not clear if it's worth
  it to fix SocketServer, however, I opened a bug to track it:

  	http://python.org/sf/1540386
........
  r51296 | neal.norwitz | 2006-08-15 06:59:30 +0200 (Tue, 15 Aug 2006) | 3 lines

  Update the docstring to use a version a little newer than 1999.  This was
  taken from a Debian patch.  Should we update the version for each release?
........
  r51298 | neal.norwitz | 2006-08-15 08:29:03 +0200 (Tue, 15 Aug 2006) | 2 lines

  Subclasses of int/long are allowed to define an __index__.
........
  r51300 | thomas.heller | 2006-08-15 15:07:21 +0200 (Tue, 15 Aug 2006) | 1 line

  Check for NULL return value from new_CArgObject calls.
........
  r51303 | kurt.kaiser | 2006-08-16 05:15:26 +0200 (Wed, 16 Aug 2006) | 2 lines

  The 'with' statement is now a Code Context block opener
........
  r51304 | anthony.baxter | 2006-08-16 05:42:26 +0200 (Wed, 16 Aug 2006) | 1 line

  preparing for 2.5c1
........
  r51305 | anthony.baxter | 2006-08-16 05:58:37 +0200 (Wed, 16 Aug 2006) | 1 line

  preparing for 2.5c1 - no, really this time
........
  r51306 | kurt.kaiser | 2006-08-16 07:01:42 +0200 (Wed, 16 Aug 2006) | 9 lines

  Patch #1540892: site.py Quitter() class attempts to close sys.stdin
  before raising SystemExit, allowing IDLE to honor quit() and exit().

  M    Lib/site.py
  M    Lib/idlelib/PyShell.py
  M    Lib/idlelib/CREDITS.txt
  M    Lib/idlelib/NEWS.txt
  M    Misc/NEWS
........
  r51307 | ka-ping.yee | 2006-08-16 09:02:50 +0200 (Wed, 16 Aug 2006) | 6 lines

  Update code and tests to support the 'bytes_le' attribute (for
  little-endian byte order on Windows), and to work around clocks
  with low resolution yielding duplicate UUIDs.

  Anthony Baxter has approved this change.
........
  r51308 | kurt.kaiser | 2006-08-16 09:04:17 +0200 (Wed, 16 Aug 2006) | 2 lines

  Get quit() and exit() to work cleanly when not using subprocess.
........
  r51309 | marc-andre.lemburg | 2006-08-16 10:13:26 +0200 (Wed, 16 Aug 2006) | 2 lines

  Revert to having static version numbers again.
........
  r51310 | martin.v.loewis | 2006-08-16 14:55:10 +0200 (Wed, 16 Aug 2006) | 2 lines

  Build _hashlib on Windows. Build OpenSSL with masm assembler code.
  Fixes #1535502.
........
  r51311 | thomas.heller | 2006-08-16 15:03:11 +0200 (Wed, 16 Aug 2006) | 6 lines

  Add commented assert statements to check that the result of
  PyObject_stgdict() and PyType_stgdict() calls are non-NULL before
  dereferencing the result.  Hopefully this fixes what klocwork is
  complaining about.

  Fix a few other nits as well.
........
  r51312 | anthony.baxter | 2006-08-16 15:08:25 +0200 (Wed, 16 Aug 2006) | 1 line

  news entry for 51307
........
  r51313 | andrew.kuchling | 2006-08-16 15:22:20 +0200 (Wed, 16 Aug 2006) | 1 line

  Add UnicodeWarning
........
  r51314 | andrew.kuchling | 2006-08-16 15:41:52 +0200 (Wed, 16 Aug 2006) | 1 line

  Bump document version to 1.0; remove pystone paragraph
........
  r51315 | andrew.kuchling | 2006-08-16 15:51:32 +0200 (Wed, 16 Aug 2006) | 1 line

  Link to docs; remove an XXX comment
........
  r51316 | martin.v.loewis | 2006-08-16 15:58:51 +0200 (Wed, 16 Aug 2006) | 1 line

  Make cl build step compile-only (/c). Remove libs from source list.
........
  r51317 | thomas.heller | 2006-08-16 16:07:44 +0200 (Wed, 16 Aug 2006) | 5 lines

  The __repr__ method of a NULL py_object does no longer raise an
  exception.  Remove a stray '?' character from the exception text
  when the value is retrieved of such an object.

  Includes tests.
........
  r51318 | andrew.kuchling | 2006-08-16 16:18:23 +0200 (Wed, 16 Aug 2006) | 1 line

  Update bug/patch counts
........
  r51319 | andrew.kuchling | 2006-08-16 16:21:14 +0200 (Wed, 16 Aug 2006) | 1 line

  Wording/typo fixes
........
  r51320 | thomas.heller | 2006-08-16 17:10:12 +0200 (Wed, 16 Aug 2006) | 9 lines

  Remove the special casing of Py_None when converting the return value
  of the Python part of a callback function to C.  If it cannot be
  converted, call PyErr_WriteUnraisable with the exception we got.
  Before, arbitrary data has been passed to the calling C code in this
  case.

  (I'm not really sure the NEWS entry is understandable, but I cannot
  find better words)
........
  r51321 | marc-andre.lemburg | 2006-08-16 18:11:01 +0200 (Wed, 16 Aug 2006) | 2 lines

  Add NEWS item mentioning the reverted distutils version number patch.
........
  r51322 | fredrik.lundh | 2006-08-16 18:47:07 +0200 (Wed, 16 Aug 2006) | 5 lines

  SF#1534630

  ignore data that arrives before the opening start tag
........
  r51324 | andrew.kuchling | 2006-08-16 19:11:18 +0200 (Wed, 16 Aug 2006) | 1 line

  Grammar fix
........
  r51328 | thomas.heller | 2006-08-16 20:02:11 +0200 (Wed, 16 Aug 2006) | 12 lines

  Tutorial:

      Clarify somewhat how parameters are passed to functions
      (especially explain what integer means).

      Correct the table - Python integers and longs can both be used.
      Further clarification to the table comparing ctypes types, Python
      types, and C types.

  Reference:

      Replace integer by C ``int`` where it makes sense.
........
  r51329 | kurt.kaiser | 2006-08-16 23:45:59 +0200 (Wed, 16 Aug 2006) | 8 lines

  File menu hotkeys: there were three 'p' assignments.  Reassign the
  'Save Copy As' and 'Print' hotkeys to 'y' and 't'.  Change the
  Shell menu hotkey from 's' to 'l'.

  M    Bindings.py
  M    PyShell.py
  M    NEWS.txt
........
  r51330 | neil.schemenauer | 2006-08-17 01:38:05 +0200 (Thu, 17 Aug 2006) | 3 lines

  Fix a bug in the ``compiler`` package that caused invalid code to be
  generated for generator expressions.
........
  r51342 | martin.v.loewis | 2006-08-17 21:19:32 +0200 (Thu, 17 Aug 2006) | 3 lines

  Merge 51340 and 51341 from 2.5 branch:
  Leave tk build directory to restore original path.
  Invoke debug mk1mf.pl after running Configure.
........
  r51354 | martin.v.loewis | 2006-08-18 05:47:18 +0200 (Fri, 18 Aug 2006) | 3 lines

  Bug #1541863: uuid.uuid1 failed to generate unique identifiers
  on systems with low clock resolution.
........
  r51355 | neal.norwitz | 2006-08-18 05:57:54 +0200 (Fri, 18 Aug 2006) | 1 line

  Add template for 2.6 on HEAD
........
  r51356 | neal.norwitz | 2006-08-18 06:01:38 +0200 (Fri, 18 Aug 2006) | 1 line

  More post-release wibble
........
  r51357 | neal.norwitz | 2006-08-18 06:58:33 +0200 (Fri, 18 Aug 2006) | 1 line

  Try to get Windows bots working again
........
  r51358 | neal.norwitz | 2006-08-18 07:10:00 +0200 (Fri, 18 Aug 2006) | 1 line

  Try to get Windows bots working again. Take 2
........
  r51359 | neal.norwitz | 2006-08-18 07:39:20 +0200 (Fri, 18 Aug 2006) | 1 line

  Try to get Unix bots install working again.
........
  r51360 | neal.norwitz | 2006-08-18 07:41:46 +0200 (Fri, 18 Aug 2006) | 1 line

  Set version to 2.6a0, seems more consistent.
........
  r51362 | neal.norwitz | 2006-08-18 08:14:52 +0200 (Fri, 18 Aug 2006) | 1 line

  More version wibble
........
  r51364 | georg.brandl | 2006-08-18 09:27:59 +0200 (Fri, 18 Aug 2006) | 4 lines

  Bug #1541682: Fix example in the "Refcount details" API docs.
  Additionally, remove a faulty example showing PySequence_SetItem applied
  to a newly created list object and add notes that this isn't a good idea.
........
  r51366 | anthony.baxter | 2006-08-18 09:29:02 +0200 (Fri, 18 Aug 2006) | 3 lines

  Updating IDLE's version number to match Python's (as per python-dev
  discussion).
........
  r51367 | anthony.baxter | 2006-08-18 09:30:07 +0200 (Fri, 18 Aug 2006) | 1 line

  RPM specfile updates
........
  r51368 | georg.brandl | 2006-08-18 09:35:47 +0200 (Fri, 18 Aug 2006) | 2 lines

  Typo in tp_clear docs.
........
  r51378 | andrew.kuchling | 2006-08-18 15:57:13 +0200 (Fri, 18 Aug 2006) | 1 line

  Minor edits
........
  r51379 | thomas.heller | 2006-08-18 16:38:46 +0200 (Fri, 18 Aug 2006) | 6 lines

  Add asserts to check for 'impossible' NULL values, with comments.
  In one place where I'n not 1000% sure about the non-NULL, raise
  a RuntimeError for safety.

  This should fix the klocwork issues that Neal sent me.  If so,
  it should be applied to the release25-maint branch also.
........
  r51400 | neal.norwitz | 2006-08-19 06:22:33 +0200 (Sat, 19 Aug 2006) | 5 lines

  Move initialization of interned strings to before allocating the
  object so we don't leak op.  (Fixes an earlier patch to this code)

  Klockwork #350
........
  r51401 | neal.norwitz | 2006-08-19 06:23:04 +0200 (Sat, 19 Aug 2006) | 4 lines

  Move assert to after NULL check, otherwise we deref NULL in the assert.

  Klocwork #307
........
  r51402 | neal.norwitz | 2006-08-19 06:25:29 +0200 (Sat, 19 Aug 2006) | 2 lines

  SF #1542693: Remove semi-colon at end of PyImport_ImportModuleEx macro
........
  r51403 | neal.norwitz | 2006-08-19 06:28:55 +0200 (Sat, 19 Aug 2006) | 6 lines

  Move initialization to after the asserts for non-NULL values.

  Klocwork 286-287.

  (I'm not backporting this, but if someone wants to, feel free.)
........
  r51404 | neal.norwitz | 2006-08-19 06:52:03 +0200 (Sat, 19 Aug 2006) | 6 lines

  Handle PyString_FromInternedString() failing (unlikely, but possible).

  Klocwork #325

  (I'm not backporting this, but if someone wants to, feel free.)
........
  r51416 | georg.brandl | 2006-08-20 15:15:39 +0200 (Sun, 20 Aug 2006) | 2 lines

  Patch #1542948: fix urllib2 header casing issue. With new test.
........
  r51428 | jeremy.hylton | 2006-08-21 18:19:37 +0200 (Mon, 21 Aug 2006) | 3 lines

  Move peephole optimizer to separate file.
........
  r51429 | jeremy.hylton | 2006-08-21 18:20:29 +0200 (Mon, 21 Aug 2006) | 2 lines

  Move peephole optimizer to separate file.  (Forgot .h in previous checkin.)
........
  r51432 | neal.norwitz | 2006-08-21 19:59:46 +0200 (Mon, 21 Aug 2006) | 5 lines

  Fix bug #1543303, tarfile adds padding that breaks gunzip.
  Patch # 1543897.

  Will backport to 2.5
........
  r51433 | neal.norwitz | 2006-08-21 20:01:30 +0200 (Mon, 21 Aug 2006) | 2 lines

  Add assert to make Klocwork happy (#276)
........
2006-08-21 19:07:27 +00:00

2696 lines
74 KiB
C

/*
* This is a curses module for Python.
*
* Based on prior work by Lance Ellinghaus and Oliver Andrich
* Version 1.2 of this module: Copyright 1994 by Lance Ellinghouse,
* Cathedral City, California Republic, United States of America.
*
* Version 1.5b1, heavily extended for ncurses by Oliver Andrich:
* Copyright 1996,1997 by Oliver Andrich, Koblenz, Germany.
*
* Tidied for Python 1.6, and currently maintained by <amk@amk.ca>.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this source file to use, copy, modify, merge, or publish it
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or in any new file that contains a substantial portion of
* this file.
*
* THE AUTHOR MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF
* THE SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT
* EXPRESS OR IMPLIED WARRANTY. THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE, STRICT LIABILITY OR
* ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* CVS: $Id$ */
/*
A number of SysV or ncurses functions don't have wrappers yet; if you need
a given function, add it and send a patch. Here's a list of currently
unsupported functions:
addchnstr addchstr chgat color_set define_key
del_curterm delscreen dupwin inchnstr inchstr innstr keyok
mcprint mvaddchnstr mvaddchstr mvchgat mvcur mvinchnstr
mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr mvwchgat
mvwinchnstr mvwinchstr mvwinnstr newterm
restartterm ripoffline scr_dump
scr_init scr_restore scr_set scrl set_curterm set_term setterm
tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
vidattr vidputs waddchnstr waddchstr wchgat
wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
Low-priority:
slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
slk_attron slk_attrset slk_clear slk_color slk_init slk_label
slk_noutrefresh slk_refresh slk_restore slk_set slk_touch
Menu extension (ncurses and probably SYSV):
current_item free_item free_menu item_count item_description
item_index item_init item_name item_opts item_opts_off
item_opts_on item_term item_userptr item_value item_visible
menu_back menu_driver menu_fore menu_format menu_grey
menu_init menu_items menu_mark menu_opts menu_opts_off
menu_opts_on menu_pad menu_pattern menu_request_by_name
menu_request_name menu_spacing menu_sub menu_term menu_userptr
menu_win new_item new_menu pos_menu_cursor post_menu
scale_menu set_current_item set_item_init set_item_opts
set_item_term set_item_userptr set_item_value set_menu_back
set_menu_fore set_menu_format set_menu_grey set_menu_init
set_menu_items set_menu_mark set_menu_opts set_menu_pad
set_menu_pattern set_menu_spacing set_menu_sub set_menu_term
set_menu_userptr set_menu_win set_top_row top_row unpost_menu
Form extension (ncurses and probably SYSV):
current_field data_ahead data_behind dup_field
dynamic_fieldinfo field_arg field_back field_buffer
field_count field_fore field_index field_info field_init
field_just field_opts field_opts_off field_opts_on field_pad
field_status field_term field_type field_userptr form_driver
form_fields form_init form_opts form_opts_off form_opts_on
form_page form_request_by_name form_request_name form_sub
form_term form_userptr form_win free_field free_form
link_field link_fieldtype move_field new_field new_form
new_page pos_form_cursor post_form scale_form
set_current_field set_field_back set_field_buffer
set_field_fore set_field_init set_field_just set_field_opts
set_field_pad set_field_status set_field_term set_field_type
set_field_userptr set_fieldtype_arg set_fieldtype_choice
set_form_fields set_form_init set_form_opts set_form_page
set_form_sub set_form_term set_form_userptr set_form_win
set_max_field set_new_page unpost_form
*/
/* Release Number */
char *PyCursesVersion = "2.2";
/* Includes */
#include "Python.h"
#ifdef __osf__
#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
#endif
#ifdef __hpux
#define STRICT_SYSV_CURSES
#endif
#define CURSES_MODULE
#include "py_curses.h"
/* These prototypes are in <term.h>, but including this header
#defines many common symbols (such as "lines") which breaks the
curses module in other ways. So the code will just specify
explicit prototypes here. */
extern int setupterm(char *,int,int *);
#ifdef __sgi
#include <term.h>
#endif
#if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5))
#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
typedef chtype attr_t; /* No attr_t type is available */
#endif
#if defined(_AIX)
#define STRICT_SYSV_CURSES
#endif
/* Definition of exception curses.error */
static PyObject *PyCursesError;
/* Tells whether setupterm() has been called to initialise terminfo. */
static int initialised_setupterm = FALSE;
/* Tells whether initscr() has been called to initialise curses. */
static int initialised = FALSE;
/* Tells whether start_color() has been called to initialise color usage. */
static int initialisedcolors = FALSE;
/* Utility Macros */
#define PyCursesSetupTermCalled \
if (initialised_setupterm != TRUE) { \
PyErr_SetString(PyCursesError, \
"must call (at least) setupterm() first"); \
return 0; }
#define PyCursesInitialised \
if (initialised != TRUE) { \
PyErr_SetString(PyCursesError, \
"must call initscr() first"); \
return 0; }
#define PyCursesInitialisedColor \
if (initialisedcolors != TRUE) { \
PyErr_SetString(PyCursesError, \
"must call start_color() first"); \
return 0; }
#ifndef MIN
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#endif
/* Utility Functions */
/*
* Check the return code from a curses function and return None
* or raise an exception as appropriate. These are exported using the
* CObject API.
*/
static PyObject *
PyCursesCheckERR(int code, char *fname)
{
if (code != ERR) {
Py_INCREF(Py_None);
return Py_None;
} else {
if (fname == NULL) {
PyErr_SetString(PyCursesError, catchall_ERR);
} else {
PyErr_Format(PyCursesError, "%s() returned ERR", fname);
}
return NULL;
}
}
static int
PyCurses_ConvertToChtype(PyObject *obj, chtype *ch)
{
if (PyInt_Check(obj)) {
*ch = (chtype) PyInt_AsLong(obj);
} else if(PyString_Check(obj)
&& (PyString_Size(obj) == 1)) {
*ch = (chtype) *PyString_AsString(obj);
} else {
return 0;
}
return 1;
}
/* Function versions of the 3 functions for tested whether curses has been
initialised or not. */
static int func_PyCursesSetupTermCalled(void)
{
PyCursesSetupTermCalled;
return 1;
}
static int func_PyCursesInitialised(void)
{
PyCursesInitialised;
return 1;
}
static int func_PyCursesInitialisedColor(void)
{
PyCursesInitialisedColor;
return 1;
}
/*****************************************************************************
The Window Object
******************************************************************************/
/* Definition of the window type */
PyTypeObject PyCursesWindow_Type;
/* Function prototype macros for Window object
X - function name
TYPE - parameter Type
ERGSTR - format string for construction of the return value
PARSESTR - format string for argument parsing
*/
#define Window_NoArgNoReturnFunction(X) \
static PyObject *PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
{ return PyCursesCheckERR(X(self->win), # X); }
#define Window_NoArgTrueFalseFunction(X) \
static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
{ \
if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
else { Py_INCREF(Py_True); return Py_True; } }
#define Window_NoArgNoReturnVoidFunction(X) \
static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
{ \
X(self->win); Py_INCREF(Py_None); return Py_None; }
#define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self) \
{ \
TYPE arg1, arg2; \
X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
#define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
{ \
TYPE arg1; \
if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \
X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
#define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
{ \
TYPE arg1; \
if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \
return PyCursesCheckERR(X(self->win, arg1), # X); }
#define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
{ \
TYPE arg1, arg2; \
if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \
return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
/* ------------- WINDOW routines --------------- */
Window_NoArgNoReturnFunction(untouchwin)
Window_NoArgNoReturnFunction(touchwin)
Window_NoArgNoReturnFunction(redrawwin)
Window_NoArgNoReturnFunction(winsertln)
Window_NoArgNoReturnFunction(werase)
Window_NoArgNoReturnFunction(wdeleteln)
Window_NoArgTrueFalseFunction(is_wintouched)
Window_NoArgNoReturnVoidFunction(wsyncup)
Window_NoArgNoReturnVoidFunction(wsyncdown)
Window_NoArgNoReturnVoidFunction(wstandend)
Window_NoArgNoReturnVoidFunction(wstandout)
Window_NoArgNoReturnVoidFunction(wcursyncup)
Window_NoArgNoReturnVoidFunction(wclrtoeol)
Window_NoArgNoReturnVoidFunction(wclrtobot)
Window_NoArgNoReturnVoidFunction(wclear)
Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)")
Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)")
Window_OneArgNoReturnVoidFunction(wtimeout, int, "i;delay")
Window_NoArg2TupleReturnFunction(getyx, int, "ii")
Window_NoArg2TupleReturnFunction(getbegyx, int, "ii")
Window_NoArg2TupleReturnFunction(getmaxyx, int, "ii")
Window_NoArg2TupleReturnFunction(getparyx, int, "ii")
Window_OneArgNoReturnFunction(wattron, attr_t, "l;attr")
Window_OneArgNoReturnFunction(wattroff, attr_t, "l;attr")
Window_OneArgNoReturnFunction(wattrset, attr_t, "l;attr")
Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)")
Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)")
#if defined(__NetBSD__)
Window_OneArgNoReturnVoidFunction(keypad, int, "i;True(1) or False(0)")
#else
Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)")
#endif
Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)")
#if defined(__NetBSD__)
Window_OneArgNoReturnVoidFunction(nodelay, int, "i;True(1) or False(0)")
#else
Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)")
#endif
Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)")
Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)")
Window_OneArgNoReturnFunction(winsdelln, int, "i;nlines")
Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)")
Window_TwoArgNoReturnFunction(mvwin, int, "ii;y,x")
Window_TwoArgNoReturnFunction(mvderwin, int, "ii;y,x")
Window_TwoArgNoReturnFunction(wmove, int, "ii;y,x")
#ifndef STRICT_SYSV_CURSES
Window_TwoArgNoReturnFunction(wresize, int, "ii;lines,columns")
#endif
/* Allocation and deallocation of Window Objects */
static PyObject *
PyCursesWindow_New(WINDOW *win)
{
PyCursesWindowObject *wo;
wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
if (wo == NULL) return NULL;
wo->win = win;
return (PyObject *)wo;
}
static void
PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
{
if (wo->win != stdscr) delwin(wo->win);
PyObject_DEL(wo);
}
/* Addch, Addstr, Addnstr */
static PyObject *
PyCursesWindow_AddCh(PyCursesWindowObject *self, PyObject *args)
{
int rtn, x, y, use_xy = FALSE;
PyObject *temp;
chtype ch = 0;
attr_t attr = A_NORMAL;
switch (PyTuple_Size(args)) {
case 1:
if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
return NULL;
break;
case 2:
if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &attr))
return NULL;
break;
case 3:
if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp))
return NULL;
use_xy = TRUE;
break;
case 4:
if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr",
&y, &x, &temp, &attr))
return NULL;
use_xy = TRUE;
break;
default:
PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments");
return NULL;
}
if (!PyCurses_ConvertToChtype(temp, &ch)) {
PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
return NULL;
}
if (use_xy == TRUE)
rtn = mvwaddch(self->win,y,x, ch | attr);
else {
rtn = waddch(self->win, ch | attr);
}
return PyCursesCheckERR(rtn, "addch");
}
static PyObject *
PyCursesWindow_AddStr(PyCursesWindowObject *self, PyObject *args)
{
int rtn;
int x, y;
char *str;
attr_t attr = A_NORMAL , attr_old = A_NORMAL;
int use_xy = FALSE, use_attr = FALSE;
switch (PyTuple_Size(args)) {
case 1:
if (!PyArg_ParseTuple(args,"s;str", &str))
return NULL;
break;
case 2:
if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &attr))
return NULL;
use_attr = TRUE;
break;
case 3:
if (!PyArg_ParseTuple(args,"iis;int,int,str", &y, &x, &str))
return NULL;
use_xy = TRUE;
break;
case 4:
if (!PyArg_ParseTuple(args,"iisl;int,int,str,attr", &y, &x, &str, &attr))
return NULL;
use_xy = use_attr = TRUE;
break;
default:
PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments");
return NULL;
}
if (use_attr == TRUE) {
attr_old = getattrs(self->win);
wattrset(self->win,attr);
}
if (use_xy == TRUE)
rtn = mvwaddstr(self->win,y,x,str);
else
rtn = waddstr(self->win,str);
if (use_attr == TRUE)
wattrset(self->win,attr_old);
return PyCursesCheckERR(rtn, "addstr");
}
static PyObject *
PyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args)
{
int rtn, x, y, n;
char *str;
attr_t attr = A_NORMAL , attr_old = A_NORMAL;
int use_xy = FALSE, use_attr = FALSE;
switch (PyTuple_Size(args)) {
case 2:
if (!PyArg_ParseTuple(args,"si;str,n", &str, &n))
return NULL;
break;
case 3:
if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &attr))
return NULL;
use_attr = TRUE;
break;
case 4:
if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n))
return NULL;
use_xy = TRUE;
break;
case 5:
if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &attr))
return NULL;
use_xy = use_attr = TRUE;
break;
default:
PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments");
return NULL;
}
if (use_attr == TRUE) {
attr_old = getattrs(self->win);
wattrset(self->win,attr);
}
if (use_xy == TRUE)
rtn = mvwaddnstr(self->win,y,x,str,n);
else
rtn = waddnstr(self->win,str,n);
if (use_attr == TRUE)
wattrset(self->win,attr_old);
return PyCursesCheckERR(rtn, "addnstr");
}
static PyObject *
PyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args)
{
PyObject *temp;
chtype bkgd;
attr_t attr = A_NORMAL;
switch (PyTuple_Size(args)) {
case 1:
if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
return NULL;
break;
case 2:
if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &attr))
return NULL;
break;
default:
PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments");
return NULL;
}
if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
return NULL;
}
return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd");
}
static PyObject *
PyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args)
{
PyObject *temp;
chtype bkgd;
attr_t attr = A_NORMAL;
switch (PyTuple_Size(args)) {
case 1:
if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
return NULL;
break;
case 2:
if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &attr))
return NULL;
break;
default:
PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments");
return NULL;
}
if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
return NULL;
}
wbkgdset(self->win, bkgd | attr);
return PyCursesCheckERR(0, "bkgdset");
}
static PyObject *
PyCursesWindow_Border(PyCursesWindowObject *self, PyObject *args)
{
PyObject *temp[8];
chtype ch[8];
int i;
/* Clear the array of parameters */
for(i=0; i<8; i++) {
temp[i] = NULL;
ch[i] = 0;
}
if (!PyArg_ParseTuple(args,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br",
&temp[0], &temp[1], &temp[2], &temp[3],
&temp[4], &temp[5], &temp[6], &temp[7]))
return NULL;
for(i=0; i<8; i++) {
if (temp[i] != NULL && !PyCurses_ConvertToChtype(temp[i], &ch[i])) {
PyErr_Format(PyExc_TypeError,
"argument %i must be a ch or an int", i+1);
return NULL;
}
}
wborder(self->win,
ch[0], ch[1], ch[2], ch[3],
ch[4], ch[5], ch[6], ch[7]);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
PyCursesWindow_Box(PyCursesWindowObject *self, PyObject *args)
{
chtype ch1=0,ch2=0;
switch(PyTuple_Size(args)){
case 0: break;
default:
if (!PyArg_ParseTuple(args,"ll;vertint,horint", &ch1, &ch2))
return NULL;
}
box(self->win,ch1,ch2);
Py_INCREF(Py_None);
return Py_None;
}
#if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION)
#define py_mvwdelch mvwdelch
#else
int py_mvwdelch(WINDOW *w, int y, int x)
{
mvwdelch(w,y,x);
/* On HP/UX, mvwdelch already returns. On other systems,
we may well run into this return statement. */
return 0;
}
#endif
static PyObject *
PyCursesWindow_DelCh(PyCursesWindowObject *self, PyObject *args)
{
int rtn;
int x, y;
switch (PyTuple_Size(args)) {
case 0:
rtn = wdelch(self->win);
break;
case 2:
if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x))
return NULL;
rtn = py_mvwdelch(self->win,y,x);
break;
default:
PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments");
return NULL;
}
return PyCursesCheckERR(rtn, "[mv]wdelch");
}
static PyObject *
PyCursesWindow_DerWin(PyCursesWindowObject *self, PyObject *args)
{
WINDOW *win;
int nlines, ncols, begin_y, begin_x;
nlines = 0;
ncols = 0;
switch (PyTuple_Size(args)) {
case 2:
if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x))
return NULL;
break;
case 4:
if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
&nlines,&ncols,&begin_y,&begin_x))
return NULL;
break;
default:
PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments");
return NULL;
}
win = derwin(self->win,nlines,ncols,begin_y,begin_x);
if (win == NULL) {
PyErr_SetString(PyCursesError, catchall_NULL);
return NULL;
}
return (PyObject *)PyCursesWindow_New(win);
}
static PyObject *
PyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args)
{
PyObject *temp;
chtype ch;
attr_t attr = A_NORMAL;
switch (PyTuple_Size(args)) {
case 1:
if (!PyArg_ParseTuple(args,"O;ch or int", &temp))
return NULL;
break;
case 2:
if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &attr))
return NULL;
break;
default:
PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
return NULL;
}
if (!PyCurses_ConvertToChtype(temp, &ch)) {
PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
return NULL;
}
#ifdef WINDOW_HAS_FLAGS
if (self->win->_flags & _ISPAD)
return PyCursesCheckERR(pechochar(self->win, ch | attr),
"echochar");
else
#endif
return PyCursesCheckERR(wechochar(self->win, ch | attr),
"echochar");
}
#ifdef NCURSES_MOUSE_VERSION
static PyObject *
PyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args)
{
int x, y;
if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x))
return NULL;
return PyInt_FromLong( wenclose(self->win,y,x) );
}
#endif
static PyObject *
PyCursesWindow_GetBkgd(PyCursesWindowObject *self)
{
return PyInt_FromLong((long) getbkgd(self->win));
}
static PyObject *
PyCursesWindow_GetCh(PyCursesWindowObject *self, PyObject *args)
{
int x, y;
int rtn;
switch (PyTuple_Size(args)) {
case 0:
Py_BEGIN_ALLOW_THREADS
rtn = wgetch(self->win);
Py_END_ALLOW_THREADS
break;
case 2:
if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
return NULL;
Py_BEGIN_ALLOW_THREADS
rtn = mvwgetch(self->win,y,x);
Py_END_ALLOW_THREADS
break;
default:
PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
return NULL;
}
return PyInt_FromLong((long)rtn);
}
static PyObject *
PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
{
int x, y;
int rtn;
switch (PyTuple_Size(args)) {
case 0:
Py_BEGIN_ALLOW_THREADS
rtn = wgetch(self->win);
Py_END_ALLOW_THREADS
break;
case 2:
if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
return NULL;
Py_BEGIN_ALLOW_THREADS
rtn = mvwgetch(self->win,y,x);
Py_END_ALLOW_THREADS
break;
default:
PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments");
return NULL;
}
if (rtn == ERR) {
/* getch() returns ERR in nodelay mode */
PyErr_SetString(PyCursesError, "no input");
return NULL;
} else if (rtn<=255)
return Py_BuildValue("c", rtn);
else
#if defined(__NetBSD__)
return PyString_FromString(unctrl(rtn));
#else
return PyString_FromString((char *)keyname(rtn));
#endif
}
static PyObject *
PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
{
int x, y, n;
char rtn[1024]; /* This should be big enough.. I hope */
int rtn2;
switch (PyTuple_Size(args)) {
case 0:
Py_BEGIN_ALLOW_THREADS
rtn2 = wgetnstr(self->win,rtn, 1023);
Py_END_ALLOW_THREADS
break;
case 1:
if (!PyArg_ParseTuple(args,"i;n", &n))
return NULL;
Py_BEGIN_ALLOW_THREADS
rtn2 = wgetnstr(self->win,rtn,MIN(n, 1023));
Py_END_ALLOW_THREADS
break;
case 2:
if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
return NULL;
Py_BEGIN_ALLOW_THREADS
#ifdef STRICT_SYSV_CURSES
rtn2 = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, 1023);
#else
rtn2 = mvwgetnstr(self->win,y,x,rtn, 1023);
#endif
Py_END_ALLOW_THREADS
break;
case 3:
if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n))
return NULL;
#ifdef STRICT_SYSV_CURSES
Py_BEGIN_ALLOW_THREADS
rtn2 = wmove(self->win,y,x)==ERR ? ERR :
wgetnstr(self->win, rtn, MIN(n, 1023));
Py_END_ALLOW_THREADS
#else
Py_BEGIN_ALLOW_THREADS
rtn2 = mvwgetnstr(self->win, y, x, rtn, MIN(n, 1023));
Py_END_ALLOW_THREADS
#endif
break;
default:
PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments");
return NULL;
}
if (rtn2 == ERR)
rtn[0] = 0;
return PyString_FromString(rtn);
}
static PyObject *
PyCursesWindow_Hline(PyCursesWindowObject *self, PyObject *args)
{
PyObject *temp;
chtype ch;
int n, x, y, code = OK;
attr_t attr = A_NORMAL;
switch (PyTuple_Size(args)) {
case 2:
if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n))
return NULL;
break;
case 3:
if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &attr))
return NULL;
break;
case 4:
if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
return NULL;
code = wmove(self->win, y, x);
break;
case 5:
if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr",
&y, &x, &temp, &n, &attr))
return NULL;
code = wmove(self->win, y, x);
break;
default:
PyErr_SetString(PyExc_TypeError, "hline requires 2 to 5 arguments");
return NULL;
}
if (code != ERR) {
if (!PyCurses_ConvertToChtype(temp, &ch)) {
PyErr_SetString(PyExc_TypeError,
"argument 1 or 3 must be a ch or an int");
return NULL;
}
return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline");
} else
return PyCursesCheckERR(code, "wmove");
}
static PyObject *
PyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args)
{
int rtn, x, y, use_xy = FALSE;
PyObject *temp;
chtype ch = 0;
attr_t attr = A_NORMAL;
switch (PyTuple_Size(args)) {
case 1:
if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
return NULL;
break;
case 2:
if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &attr))
return NULL;
break;
case 3:
if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp))
return NULL;
use_xy = TRUE;
break;
case 4:
if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", &y, &x, &temp, &attr))
return NULL;
use_xy = TRUE;
break;
default:
PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments");
return NULL;
}
if (!PyCurses_ConvertToChtype(temp, &ch)) {
PyErr_SetString(PyExc_TypeError,
"argument 1 or 3 must be a ch or an int");
return NULL;
}
if (use_xy == TRUE)
rtn = mvwinsch(self->win,y,x, ch | attr);
else {
rtn = winsch(self->win, ch | attr);
}
return PyCursesCheckERR(rtn, "insch");
}
static PyObject *
PyCursesWindow_InCh(PyCursesWindowObject *self, PyObject *args)
{
int x, y, rtn;
switch (PyTuple_Size(args)) {
case 0:
rtn = winch(self->win);
break;
case 2:
if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
return NULL;
rtn = mvwinch(self->win,y,x);
break;
default:
PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
return NULL;
}
return PyInt_FromLong((long) rtn);
}
static PyObject *
PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
{
int x, y, n;
char rtn[1024]; /* This should be big enough.. I hope */
int rtn2;
switch (PyTuple_Size(args)) {
case 0:
rtn2 = winnstr(self->win,rtn, 1023);
break;
case 1:
if (!PyArg_ParseTuple(args,"i;n", &n))
return NULL;
rtn2 = winnstr(self->win,rtn,MIN(n,1023));
break;
case 2:
if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
return NULL;
rtn2 = mvwinnstr(self->win,y,x,rtn,1023);
break;
case 3:
if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))
return NULL;
rtn2 = mvwinnstr(self->win, y, x, rtn, MIN(n,1023));
break;
default:
PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
return NULL;
}
if (rtn2 == ERR)
rtn[0] = 0;
return PyString_FromString(rtn);
}
static PyObject *
PyCursesWindow_InsStr(PyCursesWindowObject *self, PyObject *args)
{
int rtn;
int x, y;
char *str;
attr_t attr = A_NORMAL , attr_old = A_NORMAL;
int use_xy = FALSE, use_attr = FALSE;
switch (PyTuple_Size(args)) {
case 1:
if (!PyArg_ParseTuple(args,"s;str", &str))
return NULL;
break;
case 2:
if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &attr))
return NULL;
use_attr = TRUE;
break;
case 3:
if (!PyArg_ParseTuple(args,"iis;y,x,str", &y, &x, &str))
return NULL;
use_xy = TRUE;
break;
case 4:
if (!PyArg_ParseTuple(args,"iisl;y,x,str,attr", &y, &x, &str, &attr))
return NULL;
use_xy = use_attr = TRUE;
break;
default:
PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments");
return NULL;
}
if (use_attr == TRUE) {
attr_old = getattrs(self->win);
wattrset(self->win,attr);
}
if (use_xy == TRUE)
rtn = mvwinsstr(self->win,y,x,str);
else
rtn = winsstr(self->win,str);
if (use_attr == TRUE)
wattrset(self->win,attr_old);
return PyCursesCheckERR(rtn, "insstr");
}
static PyObject *
PyCursesWindow_InsNStr(PyCursesWindowObject *self, PyObject *args)
{
int rtn, x, y, n;
char *str;
attr_t attr = A_NORMAL , attr_old = A_NORMAL;
int use_xy = FALSE, use_attr = FALSE;
switch (PyTuple_Size(args)) {
case 2:
if (!PyArg_ParseTuple(args,"si;str,n", &str, &n))
return NULL;
break;
case 3:
if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &attr))
return NULL;
use_attr = TRUE;
break;
case 4:
if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n))
return NULL;
use_xy = TRUE;
break;
case 5:
if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &attr))
return NULL;
use_xy = use_attr = TRUE;
break;
default:
PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments");
return NULL;
}
if (use_attr == TRUE) {
attr_old = getattrs(self->win);
wattrset(self->win,attr);
}
if (use_xy == TRUE)
rtn = mvwinsnstr(self->win,y,x,str,n);
else
rtn = winsnstr(self->win,str,n);
if (use_attr == TRUE)
wattrset(self->win,attr_old);
return PyCursesCheckERR(rtn, "insnstr");
}
static PyObject *
PyCursesWindow_Is_LineTouched(PyCursesWindowObject *self, PyObject *args)
{
int line, erg;
if (!PyArg_ParseTuple(args,"i;line", &line))
return NULL;
erg = is_linetouched(self->win, line);
if (erg == ERR) {
PyErr_SetString(PyExc_TypeError,
"is_linetouched: line number outside of boundaries");
return NULL;
} else
if (erg == FALSE) {
Py_INCREF(Py_False);
return Py_False;
} else {
Py_INCREF(Py_True);
return Py_True;
}
}
static PyObject *
PyCursesWindow_NoOutRefresh(PyCursesWindowObject *self, PyObject *args)
{
int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
int rtn;
#ifndef WINDOW_HAS_FLAGS
if (0) {
#else
if (self->win->_flags & _ISPAD) {
#endif
switch(PyTuple_Size(args)) {
case 6:
if (!PyArg_ParseTuple(args,
"iiiiii;" \
"pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
&pminrow, &pmincol, &sminrow,
&smincol, &smaxrow, &smaxcol))
return NULL;
Py_BEGIN_ALLOW_THREADS
rtn = pnoutrefresh(self->win,
pminrow, pmincol, sminrow,
smincol, smaxrow, smaxcol);
Py_END_ALLOW_THREADS
return PyCursesCheckERR(rtn, "pnoutrefresh");
default:
PyErr_SetString(PyCursesError,
"noutrefresh() called for a pad "
"requires 6 arguments");
return NULL;
}
} else {
if (!PyArg_ParseTuple(args, ":noutrefresh"))
return NULL;
Py_BEGIN_ALLOW_THREADS
rtn = wnoutrefresh(self->win);
Py_END_ALLOW_THREADS
return PyCursesCheckERR(rtn, "wnoutrefresh");
}
}
static PyObject *
PyCursesWindow_Overlay(PyCursesWindowObject *self, PyObject *args)
{
PyCursesWindowObject *temp;
int use_copywin = FALSE;
int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
int rtn;
switch (PyTuple_Size(args)) {
case 1:
if (!PyArg_ParseTuple(args, "O!;window object",
&PyCursesWindow_Type, &temp))
return NULL;
break;
case 7:
if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int",
&PyCursesWindow_Type, &temp, &sminrow, &smincol,
&dminrow, &dmincol, &dmaxrow, &dmaxcol))
return NULL;
use_copywin = TRUE;
break;
default:
PyErr_SetString(PyExc_TypeError,
"overlay requires one or seven arguments");
return NULL;
}
if (use_copywin == TRUE) {
rtn = copywin(self->win, temp->win, sminrow, smincol,
dminrow, dmincol, dmaxrow, dmaxcol, TRUE);
return PyCursesCheckERR(rtn, "copywin");
}
else {
rtn = overlay(self->win, temp->win);
return PyCursesCheckERR(rtn, "overlay");
}
}
static PyObject *
PyCursesWindow_Overwrite(PyCursesWindowObject *self, PyObject *args)
{
PyCursesWindowObject *temp;
int use_copywin = FALSE;
int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
int rtn;
switch (PyTuple_Size(args)) {
case 1:
if (!PyArg_ParseTuple(args, "O!;window object",
&PyCursesWindow_Type, &temp))
return NULL;
break;
case 7:
if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int",
&PyCursesWindow_Type, &temp, &sminrow, &smincol,
&dminrow, &dmincol, &dmaxrow, &dmaxcol))
return NULL;
use_copywin = TRUE;
break;
default:
PyErr_SetString(PyExc_TypeError,
"overwrite requires one or seven arguments");
return NULL;
}
if (use_copywin == TRUE) {
rtn = copywin(self->win, temp->win, sminrow, smincol,
dminrow, dmincol, dmaxrow, dmaxcol, FALSE);
return PyCursesCheckERR(rtn, "copywin");
}
else {
rtn = overwrite(self->win, temp->win);
return PyCursesCheckERR(rtn, "overwrite");
}
}
static PyObject *
PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *args)
{
PyObject *temp;
if (!PyArg_ParseTuple(args, "O;fileobj", &temp))
return NULL;
if (!PyFile_Check(temp)) {
PyErr_SetString(PyExc_TypeError, "argument must be a file object");
return NULL;
}
return PyCursesCheckERR(putwin(self->win, PyFile_AsFile(temp)),
"putwin");
}
static PyObject *
PyCursesWindow_RedrawLine(PyCursesWindowObject *self, PyObject *args)
{
int beg, num;
if (!PyArg_ParseTuple(args,"ii;beg,num", &beg, &num))
return NULL;
return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln");
}
static PyObject *
PyCursesWindow_Refresh(PyCursesWindowObject *self, PyObject *args)
{
int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
int rtn;
#ifndef WINDOW_HAS_FLAGS
if (0) {
#else
if (self->win->_flags & _ISPAD) {
#endif
switch(PyTuple_Size(args)) {
case 6:
if (!PyArg_ParseTuple(args,
"iiiiii;" \
"pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
&pminrow, &pmincol, &sminrow,
&smincol, &smaxrow, &smaxcol))
return NULL;
Py_BEGIN_ALLOW_THREADS
rtn = prefresh(self->win,
pminrow, pmincol, sminrow,
smincol, smaxrow, smaxcol);
Py_END_ALLOW_THREADS
return PyCursesCheckERR(rtn, "prefresh");
default:
PyErr_SetString(PyCursesError,
"refresh() for a pad requires 6 arguments");
return NULL;
}
} else {
if (!PyArg_ParseTuple(args, ":refresh"))
return NULL;
Py_BEGIN_ALLOW_THREADS
rtn = wrefresh(self->win);
Py_END_ALLOW_THREADS
return PyCursesCheckERR(rtn, "prefresh");
}
}
static PyObject *
PyCursesWindow_SetScrollRegion(PyCursesWindowObject *self, PyObject *args)
{
int x, y;
if (!PyArg_ParseTuple(args,"ii;top, bottom",&y,&x))
return NULL;
return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
}
static PyObject *
PyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args)
{
WINDOW *win;
int nlines, ncols, begin_y, begin_x;
nlines = 0;
ncols = 0;
switch (PyTuple_Size(args)) {
case 2:
if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x))
return NULL;
break;
case 4:
if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
&nlines,&ncols,&begin_y,&begin_x))
return NULL;
break;
default:
PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments");
return NULL;
}
/* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */
#ifdef WINDOW_HAS_FLAGS
if (self->win->_flags & _ISPAD)
win = subpad(self->win, nlines, ncols, begin_y, begin_x);
else
#endif
win = subwin(self->win, nlines, ncols, begin_y, begin_x);
if (win == NULL) {
PyErr_SetString(PyCursesError, catchall_NULL);
return NULL;
}
return (PyObject *)PyCursesWindow_New(win);
}
static PyObject *
PyCursesWindow_Scroll(PyCursesWindowObject *self, PyObject *args)
{
int nlines;
switch(PyTuple_Size(args)) {
case 0:
return PyCursesCheckERR(scroll(self->win), "scroll");
case 1:
if (!PyArg_ParseTuple(args, "i;nlines", &nlines))
return NULL;
return PyCursesCheckERR(wscrl(self->win, nlines), "scroll");
default:
PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments");
return NULL;
}
}
static PyObject *
PyCursesWindow_TouchLine(PyCursesWindowObject *self, PyObject *args)
{
int st, cnt, val;
switch (PyTuple_Size(args)) {
case 2:
if (!PyArg_ParseTuple(args,"ii;start,count",&st,&cnt))
return NULL;
return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
case 3:
if (!PyArg_ParseTuple(args, "iii;start,count,val", &st, &cnt, &val))
return NULL;
return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline");
default:
PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments");
return NULL;
}
}
static PyObject *
PyCursesWindow_Vline(PyCursesWindowObject *self, PyObject *args)
{
PyObject *temp;
chtype ch;
int n, x, y, code = OK;
attr_t attr = A_NORMAL;
switch (PyTuple_Size(args)) {
case 2:
if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n))
return NULL;
break;
case 3:
if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &attr))
return NULL;
break;
case 4:
if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
return NULL;
code = wmove(self->win, y, x);
break;
case 5:
if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr",
&y, &x, &temp, &n, &attr))
return NULL;
code = wmove(self->win, y, x);
break;
default:
PyErr_SetString(PyExc_TypeError, "vline requires 2 to 5 arguments");
return NULL;
}
if (code != ERR) {
if (!PyCurses_ConvertToChtype(temp, &ch)) {
PyErr_SetString(PyExc_TypeError,
"argument 1 or 3 must be a ch or an int");
return NULL;
}
return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline");
} else
return PyCursesCheckERR(code, "wmove");
}
static PyMethodDef PyCursesWindow_Methods[] = {
{"addch", (PyCFunction)PyCursesWindow_AddCh, METH_VARARGS},
{"addnstr", (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS},
{"addstr", (PyCFunction)PyCursesWindow_AddStr, METH_VARARGS},
{"attroff", (PyCFunction)PyCursesWindow_wattroff, METH_VARARGS},
{"attron", (PyCFunction)PyCursesWindow_wattron, METH_VARARGS},
{"attrset", (PyCFunction)PyCursesWindow_wattrset, METH_VARARGS},
{"bkgd", (PyCFunction)PyCursesWindow_Bkgd, METH_VARARGS},
{"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet, METH_VARARGS},
{"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS},
{"box", (PyCFunction)PyCursesWindow_Box, METH_VARARGS},
{"clear", (PyCFunction)PyCursesWindow_wclear, METH_NOARGS},
{"clearok", (PyCFunction)PyCursesWindow_clearok, METH_VARARGS},
{"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS},
{"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS},
{"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS},
{"delch", (PyCFunction)PyCursesWindow_DelCh, METH_VARARGS},
{"deleteln", (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS},
{"derwin", (PyCFunction)PyCursesWindow_DerWin, METH_VARARGS},
{"echochar", (PyCFunction)PyCursesWindow_EchoChar, METH_VARARGS},
#ifdef NCURSES_MOUSE_VERSION
{"enclose", (PyCFunction)PyCursesWindow_Enclose, METH_VARARGS},
#endif
{"erase", (PyCFunction)PyCursesWindow_werase, METH_NOARGS},
{"getbegyx", (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS},
{"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS},
{"getch", (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS},
{"getkey", (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS},
{"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS},
{"getparyx", (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS},
{"getstr", (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS},
{"getyx", (PyCFunction)PyCursesWindow_getyx, METH_NOARGS},
{"hline", (PyCFunction)PyCursesWindow_Hline, METH_VARARGS},
{"idcok", (PyCFunction)PyCursesWindow_idcok, METH_VARARGS},
{"idlok", (PyCFunction)PyCursesWindow_idlok, METH_VARARGS},
{"immedok", (PyCFunction)PyCursesWindow_immedok, METH_VARARGS},
{"inch", (PyCFunction)PyCursesWindow_InCh, METH_VARARGS},
{"insch", (PyCFunction)PyCursesWindow_InsCh, METH_VARARGS},
{"insdelln", (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS},
{"insertln", (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS},
{"insnstr", (PyCFunction)PyCursesWindow_InsNStr, METH_VARARGS},
{"insstr", (PyCFunction)PyCursesWindow_InsStr, METH_VARARGS},
{"instr", (PyCFunction)PyCursesWindow_InStr, METH_VARARGS},
{"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched, METH_VARARGS},
{"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS},
{"keypad", (PyCFunction)PyCursesWindow_keypad, METH_VARARGS},
{"leaveok", (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS},
{"move", (PyCFunction)PyCursesWindow_wmove, METH_VARARGS},
{"mvderwin", (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS},
{"mvwin", (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS},
{"nodelay", (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS},
{"notimeout", (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS},
{"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS},
/* Backward compatibility alias -- remove in Python 2.3 */
{"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS},
{"overlay", (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS},
{"overwrite", (PyCFunction)PyCursesWindow_Overwrite,
METH_VARARGS},
{"putwin", (PyCFunction)PyCursesWindow_PutWin, METH_VARARGS},
{"redrawln", (PyCFunction)PyCursesWindow_RedrawLine},
{"redrawwin", (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS},
{"refresh", (PyCFunction)PyCursesWindow_Refresh, METH_VARARGS},
#ifndef STRICT_SYSV_CURSES
{"resize", (PyCFunction)PyCursesWindow_wresize, METH_VARARGS},
#endif
{"scroll", (PyCFunction)PyCursesWindow_Scroll, METH_VARARGS},
{"scrollok", (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS},
{"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion, METH_VARARGS},
{"standend", (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS},
{"standout", (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS},
{"subpad", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS},
{"subwin", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS},
{"syncdown", (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS},
{"syncok", (PyCFunction)PyCursesWindow_syncok, METH_VARARGS},
{"syncup", (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS},
{"timeout", (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS},
{"touchline", (PyCFunction)PyCursesWindow_TouchLine, METH_VARARGS},
{"touchwin", (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS},
{"untouchwin", (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS},
{"vline", (PyCFunction)PyCursesWindow_Vline, METH_VARARGS},
{NULL, NULL} /* sentinel */
};
static PyObject *
PyCursesWindow_GetAttr(PyCursesWindowObject *self, char *name)
{
return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name);
}
/* -------------------------------------------------------*/
PyTypeObject PyCursesWindow_Type = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"_curses.curses window", /*tp_name*/
sizeof(PyCursesWindowObject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
0, /*tp_print*/
(getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/
(setattrfunc)0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
};
/*********************************************************************
Global Functions
**********************************************************************/
NoArgNoReturnFunction(beep)
NoArgNoReturnFunction(def_prog_mode)
NoArgNoReturnFunction(def_shell_mode)
NoArgNoReturnFunction(doupdate)
NoArgNoReturnFunction(endwin)
NoArgNoReturnFunction(flash)
NoArgNoReturnFunction(nocbreak)
NoArgNoReturnFunction(noecho)
NoArgNoReturnFunction(nonl)
NoArgNoReturnFunction(noraw)
NoArgNoReturnFunction(reset_prog_mode)
NoArgNoReturnFunction(reset_shell_mode)
NoArgNoReturnFunction(resetty)
NoArgNoReturnFunction(savetty)
NoArgOrFlagNoReturnFunction(cbreak)
NoArgOrFlagNoReturnFunction(echo)
NoArgOrFlagNoReturnFunction(nl)
NoArgOrFlagNoReturnFunction(raw)
NoArgReturnIntFunction(baudrate)
NoArgReturnIntFunction(termattrs)
NoArgReturnStringFunction(termname)
NoArgReturnStringFunction(longname)
NoArgTrueFalseFunction(can_change_color)
NoArgTrueFalseFunction(has_colors)
NoArgTrueFalseFunction(has_ic)
NoArgTrueFalseFunction(has_il)
NoArgTrueFalseFunction(isendwin)
NoArgNoReturnVoidFunction(filter)
NoArgNoReturnVoidFunction(flushinp)
NoArgNoReturnVoidFunction(noqiflush)
static PyObject *
PyCurses_Color_Content(PyObject *self, PyObject *args)
{
short color,r,g,b;
PyCursesInitialised
PyCursesInitialisedColor
if (!PyArg_ParseTuple(args, "h:color_content", &color)) return NULL;
if (color_content(color, &r, &g, &b) != ERR)
return Py_BuildValue("(iii)", r, g, b);
else {
PyErr_SetString(PyCursesError,
"Argument 1 was out of range. Check value of COLORS.");
return NULL;
}
}
static PyObject *
PyCurses_color_pair(PyObject *self, PyObject *args)
{
int n;
PyCursesInitialised
PyCursesInitialisedColor
if (!PyArg_ParseTuple(args, "i:color_pair", &n)) return NULL;
return PyInt_FromLong((long) (n << 8));
}
static PyObject *
PyCurses_Curs_Set(PyObject *self, PyObject *args)
{
int vis,erg;
PyCursesInitialised
if (!PyArg_ParseTuple(args, "i:curs_set", &vis)) return NULL;
erg = curs_set(vis);
if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");
return PyInt_FromLong((long) erg);
}
static PyObject *
PyCurses_Delay_Output(PyObject *self, PyObject *args)
{
int ms;
PyCursesInitialised
if (!PyArg_ParseTuple(args, "i:delay_output", &ms)) return NULL;
return PyCursesCheckERR(delay_output(ms), "delay_output");
}
static PyObject *
PyCurses_EraseChar(PyObject *self)
{
char ch;
PyCursesInitialised
ch = erasechar();
return PyString_FromStringAndSize(&ch, 1);
}
static PyObject *
PyCurses_getsyx(PyObject *self)
{
int x,y;
PyCursesInitialised
getsyx(y, x);
return Py_BuildValue("(ii)", y, x);
}
#ifdef NCURSES_MOUSE_VERSION
static PyObject *
PyCurses_GetMouse(PyObject *self)
{
int rtn;
MEVENT event;
PyCursesInitialised
rtn = getmouse( &event );
if (rtn == ERR) {
PyErr_SetString(PyCursesError, "getmouse() returned ERR");
return NULL;
}
return Py_BuildValue("(hiiil)",
(short)event.id,
event.x, event.y, event.z,
(long) event.bstate);
}
static PyObject *
PyCurses_UngetMouse(PyObject *self, PyObject *args)
{
MEVENT event;
PyCursesInitialised
if (!PyArg_ParseTuple(args, "hiiil",
&event.id,
&event.x, &event.y, &event.z,
(int *) &event.bstate))
return NULL;
return PyCursesCheckERR(ungetmouse(&event), "ungetmouse");
}
#endif
static PyObject *
PyCurses_GetWin(PyCursesWindowObject *self, PyObject *temp)
{
WINDOW *win;
PyCursesInitialised
if (!PyFile_Check(temp)) {
PyErr_SetString(PyExc_TypeError, "argument must be a file object");
return NULL;
}
win = getwin(PyFile_AsFile(temp));
if (win == NULL) {
PyErr_SetString(PyCursesError, catchall_NULL);
return NULL;
}
return PyCursesWindow_New(win);
}
static PyObject *
PyCurses_HalfDelay(PyObject *self, PyObject *args)
{
unsigned char tenths;
PyCursesInitialised
if (!PyArg_ParseTuple(args, "b:halfdelay", &tenths)) return NULL;
return PyCursesCheckERR(halfdelay(tenths), "halfdelay");
}
#ifndef STRICT_SYSV_CURSES
/* No has_key! */
static PyObject * PyCurses_has_key(PyObject *self, PyObject *args)
{
int ch;
PyCursesInitialised
if (!PyArg_ParseTuple(args,"i",&ch)) return NULL;
if (has_key(ch) == FALSE) {
Py_INCREF(Py_False);
return Py_False;
}
Py_INCREF(Py_True);
return Py_True;
}
#endif /* STRICT_SYSV_CURSES */
static PyObject *
PyCurses_Init_Color(PyObject *self, PyObject *args)
{
short color, r, g, b;
PyCursesInitialised
PyCursesInitialisedColor
switch(PyTuple_Size(args)) {
case 4:
if (!PyArg_ParseTuple(args, "hhhh;color,r,g,b", &color, &r, &g, &b)) return NULL;
break;
default:
PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments");
return NULL;
}
return PyCursesCheckERR(init_color(color, r, g, b), "init_color");
}
static PyObject *
PyCurses_Init_Pair(PyObject *self, PyObject *args)
{
short pair, f, b;
PyCursesInitialised
PyCursesInitialisedColor
if (PyTuple_Size(args) != 3) {
PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments");
return NULL;
}
if (!PyArg_ParseTuple(args, "hhh;pair, f, b", &pair, &f, &b)) return NULL;
return PyCursesCheckERR(init_pair(pair, f, b), "init_pair");
}
static PyObject *ModDict;
static PyObject *
PyCurses_InitScr(PyObject *self)
{
WINDOW *win;
if (initialised == TRUE) {
wrefresh(stdscr);
return (PyObject *)PyCursesWindow_New(stdscr);
}
win = initscr();
if (win == NULL) {
PyErr_SetString(PyCursesError, catchall_NULL);
return NULL;
}
initialised = initialised_setupterm = TRUE;
/* This was moved from initcurses() because it core dumped on SGI,
where they're not defined until you've called initscr() */
#define SetDictInt(string,ch) \
do { \
PyObject *o = PyInt_FromLong((long) (ch)); \
if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \
Py_DECREF(o); \
} \
} while (0)
/* Here are some graphic symbols you can use */
SetDictInt("ACS_ULCORNER", (ACS_ULCORNER));
SetDictInt("ACS_LLCORNER", (ACS_LLCORNER));
SetDictInt("ACS_URCORNER", (ACS_URCORNER));
SetDictInt("ACS_LRCORNER", (ACS_LRCORNER));
SetDictInt("ACS_LTEE", (ACS_LTEE));
SetDictInt("ACS_RTEE", (ACS_RTEE));
SetDictInt("ACS_BTEE", (ACS_BTEE));
SetDictInt("ACS_TTEE", (ACS_TTEE));
SetDictInt("ACS_HLINE", (ACS_HLINE));
SetDictInt("ACS_VLINE", (ACS_VLINE));
SetDictInt("ACS_PLUS", (ACS_PLUS));
#if !defined(__hpux) || defined(HAVE_NCURSES_H)
/* On HP/UX 11, these are of type cchar_t, which is not an
integral type. If this is a problem on more platforms, a
configure test should be added to determine whether ACS_S1
is of integral type. */
SetDictInt("ACS_S1", (ACS_S1));
SetDictInt("ACS_S9", (ACS_S9));
SetDictInt("ACS_DIAMOND", (ACS_DIAMOND));
SetDictInt("ACS_CKBOARD", (ACS_CKBOARD));
SetDictInt("ACS_DEGREE", (ACS_DEGREE));
SetDictInt("ACS_PLMINUS", (ACS_PLMINUS));
SetDictInt("ACS_BULLET", (ACS_BULLET));
SetDictInt("ACS_LARROW", (ACS_LARROW));
SetDictInt("ACS_RARROW", (ACS_RARROW));
SetDictInt("ACS_DARROW", (ACS_DARROW));
SetDictInt("ACS_UARROW", (ACS_UARROW));
SetDictInt("ACS_BOARD", (ACS_BOARD));
SetDictInt("ACS_LANTERN", (ACS_LANTERN));
SetDictInt("ACS_BLOCK", (ACS_BLOCK));
#endif
SetDictInt("ACS_BSSB", (ACS_ULCORNER));
SetDictInt("ACS_SSBB", (ACS_LLCORNER));
SetDictInt("ACS_BBSS", (ACS_URCORNER));
SetDictInt("ACS_SBBS", (ACS_LRCORNER));
SetDictInt("ACS_SBSS", (ACS_RTEE));
SetDictInt("ACS_SSSB", (ACS_LTEE));
SetDictInt("ACS_SSBS", (ACS_BTEE));
SetDictInt("ACS_BSSS", (ACS_TTEE));
SetDictInt("ACS_BSBS", (ACS_HLINE));
SetDictInt("ACS_SBSB", (ACS_VLINE));
SetDictInt("ACS_SSSS", (ACS_PLUS));
/* The following are never available with strict SYSV curses */
#ifdef ACS_S3
SetDictInt("ACS_S3", (ACS_S3));
#endif
#ifdef ACS_S7
SetDictInt("ACS_S7", (ACS_S7));
#endif
#ifdef ACS_LEQUAL
SetDictInt("ACS_LEQUAL", (ACS_LEQUAL));
#endif
#ifdef ACS_GEQUAL
SetDictInt("ACS_GEQUAL", (ACS_GEQUAL));
#endif
#ifdef ACS_PI
SetDictInt("ACS_PI", (ACS_PI));
#endif
#ifdef ACS_NEQUAL
SetDictInt("ACS_NEQUAL", (ACS_NEQUAL));
#endif
#ifdef ACS_STERLING
SetDictInt("ACS_STERLING", (ACS_STERLING));
#endif
SetDictInt("LINES", LINES);
SetDictInt("COLS", COLS);
return (PyObject *)PyCursesWindow_New(win);
}
static PyObject *
PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds)
{
int fd = -1;
int err;
char* termstr = NULL;
static char *kwlist[] = {"term", "fd", NULL};
if (!PyArg_ParseTupleAndKeywords(
args, keywds, "|zi:setupterm", kwlist, &termstr, &fd)) {
return NULL;
}
if (fd == -1) {
PyObject* sys_stdout;
sys_stdout = PySys_GetObject("stdout");
if (sys_stdout == NULL) {
PyErr_SetString(
PyCursesError,
"lost sys.stdout");
return NULL;
}
fd = PyObject_AsFileDescriptor(sys_stdout);
if (fd == -1) {
return NULL;
}
}
if (setupterm(termstr,fd,&err) == ERR) {
char* s = "setupterm: unknown error";
if (err == 0) {
s = "setupterm: could not find terminal";
} else if (err == -1) {
s = "setupterm: could not find terminfo database";
}
PyErr_SetString(PyCursesError,s);
return NULL;
}
initialised_setupterm = TRUE;
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
PyCurses_IntrFlush(PyObject *self, PyObject *args)
{
int ch;
PyCursesInitialised
switch(PyTuple_Size(args)) {
case 1:
if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL;
break;
default:
PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument");
return NULL;
}
return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
}
#ifdef HAVE_CURSES_IS_TERM_RESIZED
static PyObject *
PyCurses_Is_Term_Resized(PyObject *self, PyObject *args)
{
int lines;
int columns;
int result;
PyCursesInitialised
if (!PyArg_ParseTuple(args,"ii:is_term_resized", &lines, &columns))
return NULL;
result = is_term_resized(lines, columns);
if (result == TRUE) {
Py_INCREF(Py_True);
return Py_True;
} else {
Py_INCREF(Py_False);
return Py_False;
}
}
#endif /* HAVE_CURSES_IS_TERM_RESIZED */
#if !defined(__NetBSD__)
static PyObject *
PyCurses_KeyName(PyObject *self, PyObject *args)
{
const char *knp;
int ch;
PyCursesInitialised
if (!PyArg_ParseTuple(args,"i",&ch)) return NULL;
if (ch < 0) {
PyErr_SetString(PyExc_ValueError, "invalid key number");
return NULL;
}
knp = keyname(ch);
return PyString_FromString((knp == NULL) ? "" : (char *)knp);
}
#endif
static PyObject *
PyCurses_KillChar(PyObject *self)
{
char ch;
ch = killchar();
return PyString_FromStringAndSize(&ch, 1);
}
static PyObject *
PyCurses_Meta(PyObject *self, PyObject *args)
{
int ch;
PyCursesInitialised
switch(PyTuple_Size(args)) {
case 1:
if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL;
break;
default:
PyErr_SetString(PyExc_TypeError, "meta requires 1 argument");
return NULL;
}
return PyCursesCheckERR(meta(stdscr, ch), "meta");
}
#ifdef NCURSES_MOUSE_VERSION
static PyObject *
PyCurses_MouseInterval(PyObject *self, PyObject *args)
{
int interval;
PyCursesInitialised
if (!PyArg_ParseTuple(args,"i;interval",&interval))
return NULL;
return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");
}
static PyObject *
PyCurses_MouseMask(PyObject *self, PyObject *args)
{
int newmask;
mmask_t oldmask, availmask;
PyCursesInitialised
if (!PyArg_ParseTuple(args,"i;mousemask",&newmask))
return NULL;
availmask = mousemask(newmask, &oldmask);
return Py_BuildValue("(ll)", (long)availmask, (long)oldmask);
}
#endif
static PyObject *
PyCurses_Napms(PyObject *self, PyObject *args)
{
int ms;
PyCursesInitialised
if (!PyArg_ParseTuple(args, "i;ms", &ms)) return NULL;
return Py_BuildValue("i", napms(ms));
}
static PyObject *
PyCurses_NewPad(PyObject *self, PyObject *args)
{
WINDOW *win;
int nlines, ncols;
PyCursesInitialised
if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) return NULL;
win = newpad(nlines, ncols);
if (win == NULL) {
PyErr_SetString(PyCursesError, catchall_NULL);
return NULL;
}
return (PyObject *)PyCursesWindow_New(win);
}
static PyObject *
PyCurses_NewWindow(PyObject *self, PyObject *args)
{
WINDOW *win;
int nlines, ncols, begin_y=0, begin_x=0;
PyCursesInitialised
switch (PyTuple_Size(args)) {
case 2:
if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols))
return NULL;
break;
case 4:
if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
&nlines,&ncols,&begin_y,&begin_x))
return NULL;
break;
default:
PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
return NULL;
}
win = newwin(nlines,ncols,begin_y,begin_x);
if (win == NULL) {
PyErr_SetString(PyCursesError, catchall_NULL);
return NULL;
}
return (PyObject *)PyCursesWindow_New(win);
}
static PyObject *
PyCurses_Pair_Content(PyObject *self, PyObject *args)
{
short pair,f,b;
PyCursesInitialised
PyCursesInitialisedColor
switch(PyTuple_Size(args)) {
case 1:
if (!PyArg_ParseTuple(args, "h;pair", &pair)) return NULL;
break;
default:
PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument");
return NULL;
}
if (pair_content(pair, &f, &b)==ERR) {
PyErr_SetString(PyCursesError,
"Argument 1 was out of range. (1..COLOR_PAIRS-1)");
return NULL;
}
return Py_BuildValue("(ii)", f, b);
}
static PyObject *
PyCurses_pair_number(PyObject *self, PyObject *args)
{
int n;
PyCursesInitialised
PyCursesInitialisedColor
switch(PyTuple_Size(args)) {
case 1:
if (!PyArg_ParseTuple(args, "i;pairvalue", &n)) return NULL;
break;
default:
PyErr_SetString(PyExc_TypeError,
"pair_number requires 1 argument");
return NULL;
}
return PyInt_FromLong((long) ((n & A_COLOR) >> 8));
}
static PyObject *
PyCurses_Putp(PyObject *self, PyObject *args)
{
char *str;
if (!PyArg_ParseTuple(args,"s;str", &str)) return NULL;
return PyCursesCheckERR(putp(str), "putp");
}
static PyObject *
PyCurses_QiFlush(PyObject *self, PyObject *args)
{
int flag = 0;
PyCursesInitialised
switch(PyTuple_Size(args)) {
case 0:
qiflush();
Py_INCREF(Py_None);
return Py_None;
case 1:
if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL;
if (flag) qiflush();
else noqiflush();
Py_INCREF(Py_None);
return Py_None;
default:
PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments");
return NULL;
}
}
#ifdef HAVE_CURSES_RESIZETERM
static PyObject *
PyCurses_ResizeTerm(PyObject *self, PyObject *args)
{
int lines;
int columns;
PyCursesInitialised
if (!PyArg_ParseTuple(args,"ii:resizeterm", &lines, &columns))
return NULL;
return PyCursesCheckERR(resizeterm(lines, columns), "resizeterm");
}
#endif
#ifdef HAVE_CURSES_RESIZE_TERM
static PyObject *
PyCurses_Resize_Term(PyObject *self, PyObject *args)
{
int lines;
int columns;
PyCursesInitialised
if (!PyArg_ParseTuple(args,"ii:resize_term", &lines, &columns))
return NULL;
return PyCursesCheckERR(resize_term(lines, columns), "resize_term");
}
#endif /* HAVE_CURSES_RESIZE_TERM */
static PyObject *
PyCurses_setsyx(PyObject *self, PyObject *args)
{
int y,x;
PyCursesInitialised
if (PyTuple_Size(args)!=2) {
PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments");
return NULL;
}
if (!PyArg_ParseTuple(args, "ii;y, x", &y, &x)) return NULL;
setsyx(y,x);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
PyCurses_Start_Color(PyObject *self)
{
int code;
PyObject *c, *cp;
PyCursesInitialised
code = start_color();
if (code != ERR) {
initialisedcolors = TRUE;
c = PyInt_FromLong((long) COLORS);
PyDict_SetItemString(ModDict, "COLORS", c);
Py_DECREF(c);
cp = PyInt_FromLong((long) COLOR_PAIRS);
PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp);
Py_DECREF(cp);
Py_INCREF(Py_None);
return Py_None;
} else {
PyErr_SetString(PyCursesError, "start_color() returned ERR");
return NULL;
}
}
static PyObject *
PyCurses_tigetflag(PyObject *self, PyObject *args)
{
char *capname;
PyCursesSetupTermCalled;
if (!PyArg_ParseTuple(args, "z", &capname))
return NULL;
return PyInt_FromLong( (long) tigetflag( capname ) );
}
static PyObject *
PyCurses_tigetnum(PyObject *self, PyObject *args)
{
char *capname;
PyCursesSetupTermCalled;
if (!PyArg_ParseTuple(args, "z", &capname))
return NULL;
return PyInt_FromLong( (long) tigetnum( capname ) );
}
static PyObject *
PyCurses_tigetstr(PyObject *self, PyObject *args)
{
char *capname;
PyCursesSetupTermCalled;
if (!PyArg_ParseTuple(args, "z", &capname))
return NULL;
capname = tigetstr( capname );
if (capname == 0 || capname == (char*) -1) {
Py_INCREF(Py_None);
return Py_None;
}
return PyString_FromString( capname );
}
static PyObject *
PyCurses_tparm(PyObject *self, PyObject *args)
{
char* fmt;
char* result = NULL;
int i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0,i9=0;
PyCursesSetupTermCalled;
if (!PyArg_ParseTuple(args, "s|iiiiiiiii:tparm",
&fmt, &i1, &i2, &i3, &i4,
&i5, &i6, &i7, &i8, &i9)) {
return NULL;
}
result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9);
return PyString_FromString(result);
}
static PyObject *
PyCurses_TypeAhead(PyObject *self, PyObject *args)
{
int fd;
PyCursesInitialised
if (!PyArg_ParseTuple(args,"i;fd",&fd)) return NULL;
return PyCursesCheckERR(typeahead( fd ), "typeahead");
}
static PyObject *
PyCurses_UnCtrl(PyObject *self, PyObject *args)
{
PyObject *temp;
chtype ch;
PyCursesInitialised
if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
if (PyInt_Check(temp))
ch = (chtype) PyInt_AsLong(temp);
else if (PyString_Check(temp))
ch = (chtype) *PyString_AsString(temp);
else {
PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
return NULL;
}
return PyString_FromString(unctrl(ch));
}
static PyObject *
PyCurses_UngetCh(PyObject *self, PyObject *args)
{
PyObject *temp;
int ch;
PyCursesInitialised
if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
if (PyInt_Check(temp))
ch = (int) PyInt_AsLong(temp);
else if (PyString_Check(temp))
ch = (int) *PyString_AsString(temp);
else {
PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int");
return NULL;
}
return PyCursesCheckERR(ungetch(ch), "ungetch");
}
static PyObject *
PyCurses_Use_Env(PyObject *self, PyObject *args)
{
int flag;
PyCursesInitialised
switch(PyTuple_Size(args)) {
case 1:
if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&flag))
return NULL;
break;
default:
PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument");
return NULL;
}
use_env(flag);
Py_INCREF(Py_None);
return Py_None;
}
#ifndef STRICT_SYSV_CURSES
static PyObject *
PyCurses_Use_Default_Colors(PyObject *self)
{
int code;
PyCursesInitialised
PyCursesInitialisedColor
code = use_default_colors();
if (code != ERR) {
Py_INCREF(Py_None);
return Py_None;
} else {
PyErr_SetString(PyCursesError, "use_default_colors() returned ERR");
return NULL;
}
}
#endif /* STRICT_SYSV_CURSES */
/* List of functions defined in the module */
static PyMethodDef PyCurses_methods[] = {
{"baudrate", (PyCFunction)PyCurses_baudrate, METH_NOARGS},
{"beep", (PyCFunction)PyCurses_beep, METH_NOARGS},
{"can_change_color", (PyCFunction)PyCurses_can_change_color, METH_NOARGS},
{"cbreak", (PyCFunction)PyCurses_cbreak, METH_VARARGS},
{"color_content", (PyCFunction)PyCurses_Color_Content, METH_VARARGS},
{"color_pair", (PyCFunction)PyCurses_color_pair, METH_VARARGS},
{"curs_set", (PyCFunction)PyCurses_Curs_Set, METH_VARARGS},
{"def_prog_mode", (PyCFunction)PyCurses_def_prog_mode, METH_NOARGS},
{"def_shell_mode", (PyCFunction)PyCurses_def_shell_mode, METH_NOARGS},
{"delay_output", (PyCFunction)PyCurses_Delay_Output, METH_VARARGS},
{"doupdate", (PyCFunction)PyCurses_doupdate, METH_NOARGS},
{"echo", (PyCFunction)PyCurses_echo, METH_VARARGS},
{"endwin", (PyCFunction)PyCurses_endwin, METH_NOARGS},
{"erasechar", (PyCFunction)PyCurses_EraseChar, METH_NOARGS},
{"filter", (PyCFunction)PyCurses_filter, METH_NOARGS},
{"flash", (PyCFunction)PyCurses_flash, METH_NOARGS},
{"flushinp", (PyCFunction)PyCurses_flushinp, METH_NOARGS},
#ifdef NCURSES_MOUSE_VERSION
{"getmouse", (PyCFunction)PyCurses_GetMouse, METH_NOARGS},
{"ungetmouse", (PyCFunction)PyCurses_UngetMouse, METH_VARARGS},
#endif
{"getsyx", (PyCFunction)PyCurses_getsyx, METH_NOARGS},
{"getwin", (PyCFunction)PyCurses_GetWin, METH_O},
{"has_colors", (PyCFunction)PyCurses_has_colors, METH_NOARGS},
{"has_ic", (PyCFunction)PyCurses_has_ic, METH_NOARGS},
{"has_il", (PyCFunction)PyCurses_has_il, METH_NOARGS},
#ifndef STRICT_SYSV_CURSES
{"has_key", (PyCFunction)PyCurses_has_key, METH_VARARGS},
#endif
{"halfdelay", (PyCFunction)PyCurses_HalfDelay, METH_VARARGS},
{"init_color", (PyCFunction)PyCurses_Init_Color, METH_VARARGS},
{"init_pair", (PyCFunction)PyCurses_Init_Pair, METH_VARARGS},
{"initscr", (PyCFunction)PyCurses_InitScr, METH_NOARGS},
{"intrflush", (PyCFunction)PyCurses_IntrFlush, METH_VARARGS},
{"isendwin", (PyCFunction)PyCurses_isendwin, METH_NOARGS},
#ifdef HAVE_CURSES_IS_TERM_RESIZED
{"is_term_resized", (PyCFunction)PyCurses_Is_Term_Resized, METH_VARARGS},
#endif
#if !defined(__NetBSD__)
{"keyname", (PyCFunction)PyCurses_KeyName, METH_VARARGS},
#endif
{"killchar", (PyCFunction)PyCurses_KillChar, METH_NOARGS},
{"longname", (PyCFunction)PyCurses_longname, METH_NOARGS},
{"meta", (PyCFunction)PyCurses_Meta, METH_VARARGS},
#ifdef NCURSES_MOUSE_VERSION
{"mouseinterval", (PyCFunction)PyCurses_MouseInterval, METH_VARARGS},
{"mousemask", (PyCFunction)PyCurses_MouseMask, METH_VARARGS},
#endif
{"napms", (PyCFunction)PyCurses_Napms, METH_VARARGS},
{"newpad", (PyCFunction)PyCurses_NewPad, METH_VARARGS},
{"newwin", (PyCFunction)PyCurses_NewWindow, METH_VARARGS},
{"nl", (PyCFunction)PyCurses_nl, METH_VARARGS},
{"nocbreak", (PyCFunction)PyCurses_nocbreak, METH_NOARGS},
{"noecho", (PyCFunction)PyCurses_noecho, METH_NOARGS},
{"nonl", (PyCFunction)PyCurses_nonl, METH_NOARGS},
{"noqiflush", (PyCFunction)PyCurses_noqiflush, METH_NOARGS},
{"noraw", (PyCFunction)PyCurses_noraw, METH_NOARGS},
{"pair_content", (PyCFunction)PyCurses_Pair_Content, METH_VARARGS},
{"pair_number", (PyCFunction)PyCurses_pair_number, METH_VARARGS},
{"putp", (PyCFunction)PyCurses_Putp, METH_VARARGS},
{"qiflush", (PyCFunction)PyCurses_QiFlush, METH_VARARGS},
{"raw", (PyCFunction)PyCurses_raw, METH_VARARGS},
{"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode, METH_NOARGS},
{"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode, METH_NOARGS},
{"resetty", (PyCFunction)PyCurses_resetty, METH_NOARGS},
#ifdef HAVE_CURSES_RESIZETERM
{"resizeterm", (PyCFunction)PyCurses_ResizeTerm, METH_VARARGS},
#endif
#ifdef HAVE_CURSES_RESIZE_TERM
{"resize_term", (PyCFunction)PyCurses_Resize_Term, METH_VARARGS},
#endif
{"savetty", (PyCFunction)PyCurses_savetty, METH_NOARGS},
{"setsyx", (PyCFunction)PyCurses_setsyx, METH_VARARGS},
{"setupterm", (PyCFunction)PyCurses_setupterm,
METH_VARARGS|METH_KEYWORDS},
{"start_color", (PyCFunction)PyCurses_Start_Color, METH_NOARGS},
{"termattrs", (PyCFunction)PyCurses_termattrs, METH_NOARGS},
{"termname", (PyCFunction)PyCurses_termname, METH_NOARGS},
{"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS},
{"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS},
{"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS},
{"tparm", (PyCFunction)PyCurses_tparm, METH_VARARGS},
{"typeahead", (PyCFunction)PyCurses_TypeAhead, METH_VARARGS},
{"unctrl", (PyCFunction)PyCurses_UnCtrl, METH_VARARGS},
{"ungetch", (PyCFunction)PyCurses_UngetCh, METH_VARARGS},
{"use_env", (PyCFunction)PyCurses_Use_Env, METH_VARARGS},
#ifndef STRICT_SYSV_CURSES
{"use_default_colors", (PyCFunction)PyCurses_Use_Default_Colors, METH_NOARGS},
#endif
{NULL, NULL} /* sentinel */
};
/* Initialization function for the module */
PyMODINIT_FUNC
init_curses(void)
{
PyObject *m, *d, *v, *c_api_object;
static void *PyCurses_API[PyCurses_API_pointers];
/* Initialize object type */
PyCursesWindow_Type.ob_type = &PyType_Type;
/* Initialize the C API pointer array */
PyCurses_API[0] = (void *)&PyCursesWindow_Type;
PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled;
PyCurses_API[2] = (void *)func_PyCursesInitialised;
PyCurses_API[3] = (void *)func_PyCursesInitialisedColor;
/* Create the module and add the functions */
m = Py_InitModule("_curses", PyCurses_methods);
if (m == NULL)
return;
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
if (d == NULL)
return;
ModDict = d; /* For PyCurses_InitScr to use later */
/* Add a CObject for the C API */
c_api_object = PyCObject_FromVoidPtr((void *)PyCurses_API, NULL);
PyDict_SetItemString(d, "_C_API", c_api_object);
Py_DECREF(c_api_object);
/* For exception curses.error */
PyCursesError = PyErr_NewException("_curses.error", NULL, NULL);
PyDict_SetItemString(d, "error", PyCursesError);
/* Make the version available */
v = PyString_FromString(PyCursesVersion);
PyDict_SetItemString(d, "version", v);
PyDict_SetItemString(d, "__version__", v);
Py_DECREF(v);
SetDictInt("ERR", ERR);
SetDictInt("OK", OK);
/* Here are some attributes you can add to chars to print */
SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES);
SetDictInt("A_NORMAL", A_NORMAL);
SetDictInt("A_STANDOUT", A_STANDOUT);
SetDictInt("A_UNDERLINE", A_UNDERLINE);
SetDictInt("A_REVERSE", A_REVERSE);
SetDictInt("A_BLINK", A_BLINK);
SetDictInt("A_DIM", A_DIM);
SetDictInt("A_BOLD", A_BOLD);
SetDictInt("A_ALTCHARSET", A_ALTCHARSET);
#if !defined(__NetBSD__)
SetDictInt("A_INVIS", A_INVIS);
#endif
SetDictInt("A_PROTECT", A_PROTECT);
SetDictInt("A_CHARTEXT", A_CHARTEXT);
SetDictInt("A_COLOR", A_COLOR);
/* The following are never available with strict SYSV curses */
#ifdef A_HORIZONTAL
SetDictInt("A_HORIZONTAL", A_HORIZONTAL);
#endif
#ifdef A_LEFT
SetDictInt("A_LEFT", A_LEFT);
#endif
#ifdef A_LOW
SetDictInt("A_LOW", A_LOW);
#endif
#ifdef A_RIGHT
SetDictInt("A_RIGHT", A_RIGHT);
#endif
#ifdef A_TOP
SetDictInt("A_TOP", A_TOP);
#endif
#ifdef A_VERTICAL
SetDictInt("A_VERTICAL", A_VERTICAL);
#endif
SetDictInt("COLOR_BLACK", COLOR_BLACK);
SetDictInt("COLOR_RED", COLOR_RED);
SetDictInt("COLOR_GREEN", COLOR_GREEN);
SetDictInt("COLOR_YELLOW", COLOR_YELLOW);
SetDictInt("COLOR_BLUE", COLOR_BLUE);
SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA);
SetDictInt("COLOR_CYAN", COLOR_CYAN);
SetDictInt("COLOR_WHITE", COLOR_WHITE);
#ifdef NCURSES_MOUSE_VERSION
/* Mouse-related constants */
SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED);
SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED);
SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED);
SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED);
SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED);
SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED);
SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED);
SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED);
SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED);
SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED);
SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED);
SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED);
SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED);
SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED);
SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED);
SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED);
SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED);
SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED);
SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED);
SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED);
SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT);
SetDictInt("BUTTON_CTRL", BUTTON_CTRL);
SetDictInt("BUTTON_ALT", BUTTON_ALT);
SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS);
SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION);
#endif
/* Now set everything up for KEY_ variables */
{
int key;
char *key_n;
char *key_n2;
#if !defined(__NetBSD__)
for (key=KEY_MIN;key < KEY_MAX; key++) {
key_n = (char *)keyname(key);
if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
continue;
if (strncmp(key_n,"KEY_F(",6)==0) {
char *p1, *p2;
key_n2 = malloc(strlen(key_n)+1);
if (!key_n2) {
PyErr_NoMemory();
break;
}
p1 = key_n;
p2 = key_n2;
while (*p1) {
if (*p1 != '(' && *p1 != ')') {
*p2 = *p1;
p2++;
}
p1++;
}
*p2 = (char)0;
} else
key_n2 = key_n;
SetDictInt(key_n2,key);
if (key_n2 != key_n)
free(key_n2);
}
#endif
SetDictInt("KEY_MIN", KEY_MIN);
SetDictInt("KEY_MAX", KEY_MAX);
}
}