[Tutor] Can you tell me if this C or python please

Bob Gailer bgailer at alum.rpi.edu
Sat Mar 3 00:11:02 CET 2007


Lance Haig wrote:
> Bob Gailer wrote:
>> Lance Haig wrote:
>>> Hi,
>>>
>>> I am helping on an OS project called bongo-project and I am trying 
>>> to debug a script that is used for migration. When I run the file I 
>>> get an error. I have traced it down to a file called libs.c.
>>>
>>> I know that the file looks like a c file but I am confused by some 
>>> of the code in it. I would appreciate it if someone could look at 
>>> the file for me and tell me if it is c so I can pass it back to the 
>>> c guys and ask them.
>>>   
>> OK. Show us the file (if not too big as body text).
>>
> sorry I should have attached it
That is C. It looks like it is written to be called from a Python program.

Clues that it is C rather than python:
  # compiler directives (e.g. #include)
  Variable declarations e.g. static ..., extern ...
  Use of {} to group statements
  Use of ; to terminate statements
  Use of /* */ to enclose comments
>
> /**************************************************************************** 
>
> *
> * Copyright (c) 2006 Novell, Inc.
> * All Rights Reserved.
> *
> * This program is free software; you can redistribute it and/or
> * modify it under the terms of version 2.1 of the GNU Lesser General 
> Public
> * License as published by the Free Software Foundation.
> *
> * 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 Lesser General Public License for more details.
> *
> * You should have received a copy of the GNU Lesser General Public 
> License
> * along with this program; if not, contact Novell, Inc.
> *
> * To contact Novell about this file by physical or electronic mail,
> * you may find current contact information at www.novell.com
> *
> ****************************************************************************/ 
>
>
> #include <Python.h>
> #include "libs.h"
> #include "pybongo.h"
> #include <bongo-config.h>
> #include <xpl.h>
> #include <mdb.h>
> #include <connio.h>
> #include <memmgr.h>
> #include <msgapi.h>
> #include <nmlib.h>
> #include <streamio.h>
> #include <bongojson.h>
>
> #ifdef __cplusplus
> extern "C" {
> #endif
>
> static PyMethodDef ModuleMethods[] = { {NULL} };
>
> /* Pull in the methods from the bindings */
> extern PyMethodDef CalCmdMethods[];
> extern EnumItemDef CalCmdEnums[];
> extern PyMethodDef CalMethods[];
> extern PyMethodDef MdbMethods[];
> extern EnumItemDef MdbEnums[];
> extern PyMethodDef MsgApiMethods[];
> extern EnumItemDef MsgApiEnums[];
> extern PyMethodDef StreamIOMethods[];
> extern PyMethodDef BongoJsonMethods[];
> extern PyMethodDef BongoUtilMethods[];
>
>
> PyMODINIT_FUNC
> initlibs()
> {
>    MDBHandle directoryHandle=NULL;
>    char dbfdir[PATH_MAX];
>
>    /* Initialize the various bongo libraries */
>    if (!MemoryManagerOpen((unsigned char*)"pybongo")) {
>        PyErr_SetString(PyExc_ImportError,
>                        "bongo.libs error: MemoryManagerOpen() failed");
>        return;
>    }
>
>    if (!ConnStartup(DEFAULT_CONNECTION_TIMEOUT, TRUE)) {
>        PyErr_SetString(PyExc_ImportError,
>                        "bongo.libs error: ConnStartup() failed");
>        return;
>    }
>
>    directoryHandle = MsgInit();
>    if (!directoryHandle) {
>        PyErr_SetString(PyExc_ImportError,
>                        "bongo.libs error: MsgInit() failed");
>        return;
>    }
>
>    MsgGetDBFDir(dbfdir);
>
>    if (!BongoCalInit(dbfdir)) {
>        PyErr_SetString(PyExc_ImportError,
>                        "bongo.libs error: BongoCalInit() failed");
>        return;
>    }
>
>    if (!NMAPInitialize(directoryHandle)) {
>        PyErr_SetString(PyExc_ImportError,
>                        "bongo.libs error: NMAPInitialize() failed");
>        return;
>    }
>
>    if (!StreamioInit()) {
>        PyErr_SetString(PyExc_ImportError,
>                        "bongo.libs error: StreamioInit() failed");
>        return;
>    }
>
>    if (!BongoJsonPreInit()) {
>        PyErr_SetString(PyExc_ImportError,
>                        "bongo.libs error: BongoJsonPreInit() failed");
>        return;
>    }
>      /* Create the libs module */
>    PyObject *module = Py_InitModule("libs", ModuleMethods);
>
>    /* Add the Bongo libs */
>    AddLibrary(module, "cal", CalMethods, NULL);
>    AddLibrary(module, "calcmd", CalCmdMethods, CalCmdEnums);
>    AddLibrary(module, "mdb", MdbMethods, MdbEnums);
>    AddLibrary(module, "msgapi", MsgApiMethods, MsgApiEnums);
>    AddLibrary(module, "streamio", StreamIOMethods, NULL);
>    AddLibrary(module, "bongojson", BongoJsonMethods, NULL);
>    AddLibrary(module, "bongoutil", BongoUtilMethods, NULL);
>
>    BongoJsonPostInit(module);
>    BongoCalPostInit(module);
> }
>
> #ifdef __cplusplus
> }
> #endif
>


-- 
Bob Gailer
510-978-4454



More information about the Tutor mailing list