;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; LUSH Lisp Universal Shell
;;;   Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
;;; Includes parts of TL3:
;;;   Copyright (C) 1987-1999 Leon Bottou and Neuristique.
;;; Includes selected parts of SN3.2:
;;;   Copyright (C) 1991-2001 AT&T Corp.
;;;
;;; Includes information derived from the GSL (Gnu Scientific Library)
;;;   header files which are copyrighted and distributed under the GPL
;;;   by their respective authors.
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(libload "python/python-config")


#? *** aux_arg

;; dummy function that adds Python C header files in C file
(eval `(de dummy_aux_arg () ,python-cpheader-cmd ()))

#? * (dummy_aux_arg)
#? * (pyarg_parsetuple_prepare <n> <s>)
#? * (pyarg_parsetuple_one <o> <s>)
#? * (pyarg_parsetuple_two <o> <s>)
#? * (pyarg_parsetuple_three <o> <s>)
#? * (pyarg_parsetuple_four <o> <s>)

;; ********************************************************


(de PyArg_ParseTuple_prepare ( n s )
    ((-int-) n)
    ((-str-) s)
    (let ((a (gptr ())))
      #{ {
      int i;
      $a = malloc($n * sizeof(void *));
      for(i=0; i<$n; i++)
      {
	  switch(*((char*)$s->data + i))
	  {
	  case 'b':  *((void **)$a+i) = malloc(sizeof(char)); break;
	  case 'h':  *((void **)$a+i) = malloc(sizeof(short)); break;
	  case 'i':  *((void **)$a+i) = malloc(sizeof(int)); break;
	  case 'l':  *((void **)$a+i) = malloc(sizeof(long)); break;
	  case 'c':  *((void **)$a+i) = malloc(sizeof(char)); break;
	  case 'f':  *((void **)$a+i) = malloc(sizeof(float)); break;
	  case 'd':  *((void **)$a+i) = malloc(sizeof(double)); break;
	  case 's':  *((void **)$a+i) = malloc(sizeof(char *)); break;
	  case 'z':  *((void **)$a+i) = malloc(sizeof(char *)); break;
	  case '#':  *((void **)$a+i) = malloc(sizeof(int)); break;
	  default: break;
	  }
      }
      } #}
      a))

(de PyArg_ParseTuple_one (o s)
    ((-gptr- "PyObject *") o)
    ((-str-) s)
    (let ((a (gptr ())))
    #{  $a = C_pyarg_parsetuple_prepare(($s->size -1), $s);
    PyArg_ParseTuple($o,$s->data,$a);
    #}
    a))


(de PyArg_ParseTuple_two (o s)
    ((-gptr- "PyObject *") o)
    ((-str-) s)
    (let ((a (gptr ())))
    #{  $a = C_pyarg_parsetuple_prepare($s->size, $s);
    PyArg_ParseTuple($o,$s->data,$a,($a+1));
    #}
    a))

(de PyArg_ParseTuple_three (o s)
    ((-gptr- "PyObject *") o)
    ((-str-) s)
    (let ((a (gptr ())))
    #{  $a = C_pyarg_parsetuple_prepare($s->size, $s);
    PyArg_ParseTuple($o,$s->data,$a,($a+1),($a+2));
    #}
    a))

(de PyArg_ParseTuple_four (o s)
    ((-gptr- "PyObject *") o)
    ((-str-) s)
    (let ((a (gptr ())))
    #{  $a = C_pyarg_parsetuple_prepare($s->size, $s);
    PyArg_ParseTuple($o,$s->data,$a,($a+1),($a+2),($a+3));
    #}
    a))


;; ********************************************************

(dhc-make () 
  dummy_aux_arg
  pyarg_parsetuple_prepare
  pyarg_parsetuple_one
  pyarg_parsetuple_two
  pyarg_parsetuple_three
  pyarg_parsetuple_four
)
