示例#1
0
SCM g_get_package_attribute(SCM scm_uref, SCM scm_wanted_attrib)
{
    SCM scm_return_value;
    NETLIST *nl_current;
    char *uref;
    char *wanted_attrib;
    char *return_value = NULL;

    SCM_ASSERT(scm_is_string (scm_uref),
	       scm_uref, SCM_ARG1, "gnetlist:get-package-attribute");

    SCM_ASSERT(scm_is_string (scm_wanted_attrib),
	       scm_wanted_attrib, SCM_ARG2, "gnetlist:get-package-attribute");

    uref          = SCM_STRING_CHARS (scm_uref);
    wanted_attrib = SCM_STRING_CHARS (scm_wanted_attrib);

    /* here is where you make it multi page aware */
    nl_current = netlist_head;

    /* search for the first instance */
    /* through the entire list */
    while (nl_current != NULL) {

	if (nl_current->component_uref) {
	    if (strcmp(nl_current->component_uref, uref) == 0) {

		/* first search outside the symbol */
		return_value =
		    o_attrib_search_name_single(nl_current->object_ptr,
						wanted_attrib, NULL);

		if (return_value) {
		    break;
		}

		/* now search inside the symbol */
		return_value =
		    o_attrib_search_name(nl_current->object_ptr->
					 complex->prim_objs, wanted_attrib,
					 0);

		break;
	    }
	}
	nl_current = nl_current->next;
    }

    if (return_value) {
      scm_return_value = scm_makfrom0str (return_value);
    } else {
      scm_return_value = scm_makfrom0str ("unknown");
    }

    return (scm_return_value);
}
示例#2
0
文件: pyscm.c 项目: tddpirate/pyguile
static PyObject *
pyscm_PySCM_call(pyscm_PySCMObject *self, PyObject *args, PyObject *kwargs)
{
  /* Return the result of calling self with argument args */

  SCM shandle = scm_hashv_get_handle(pyscm_registration_hash,scm_long2num(self->ob_scm_index));
  if (SCM_BOOLP(shandle) && SCM_EQ_P(SCM_BOOL_F,shandle)) {
    Py_FatalError("PySCM object lost its associated SCM object");  // NOT COVERED BY TESTS
  }
  // Now:
  // SCM_CADR(shandle) is the SCM object itself
  // SCM_CDDR(shandle) is the stemplate.
  if (pyguile_verbosity_test(PYGUILE_VERBOSE_PYSCM)) {
    scm_simple_format(scm_current_output_port(),scm_makfrom0str("# pyscm_PySCM_call: calling ~S with args=~S and keywords=~S; stemplate=~S\n"),scm_list_4(SCM_CADR(shandle),verbosity_repr(args),verbosity_repr(kwargs),SCM_CDDR(shandle)));
  }

  SCM sapply_func = GET_APPLY_FUNC(SCM_CDDR(shandle));
  if (SCM_EQ_P(SCM_EOL,sapply_func)) {
    if (pyguile_verbosity_test(PYGUILE_VERBOSE_PYSCM)) {
      scm_simple_format(scm_current_output_port(),scm_makfrom0str("# pyscm_PySCM_call: raising exceptions.TypeError due to \"PySCM wraps a non-callable SCM\"\n"),SCM_EOL);
    }
    PyErr_SetString(PyExc_TypeError, "PySCM wraps a non-callable SCM");
    return(NULL);
  }

  // Process arguments.
  SCM sargs_template = GET_P2G_POSITIONAL_ARGS_TEMPLATE(SCM_CDDR(shandle));
  SCM skwargs_template = GET_P2G_KEYWORD_ARGS_TEMPLATE(SCM_CDDR(shandle));
  /*if (logical_xor(SCM_EQ_P(SCM_EOL,sargs_template),(NULL==args))
    || logical_xor(SCM_EQ_P(SCM_EOL,skwargs_template),(NULL==kwargs)))*/
  // The following allows template to exist without actual arguments.
  if ((SCM_EQ_P(SCM_EOL,sargs_template) && (NULL != args))
      || (SCM_EQ_P(SCM_EOL,skwargs_template) && (NULL != kwargs))) {
    if (pyguile_verbosity_test(PYGUILE_VERBOSE_PYSCM)) {
      scm_simple_format(scm_current_output_port(),scm_makfrom0str("# pyscm_PySCM_call: raising exceptions.TypeError due to \"wrapped SCM does not take some of the provided arguments\"\n"),SCM_EOL);
    }
    PyErr_SetString(PyExc_TypeError, "wrapped SCM does not take some of the provided arguments");
    return(NULL);
  }

  SCM sargs = SCM_EQ_P(SCM_EOL,sargs_template) || (NULL == args)
    ? SCM_EOL : p2g_apply(args,sargs_template);
  SCM skwargs = SCM_EQ_P(SCM_EOL,skwargs_template) || (NULL == kwargs)
    ? SCM_EOL : p2g_apply(kwargs,skwargs_template);

  SCM sresult = scm_apply(sapply_func,scm_list_2(SCM_CADR(shandle),scm_list_2(sargs,skwargs)),SCM_EOL);
  SCM sresult_template = GET_G2P_RESULT_TEMPLATE(SCM_CDDR(shandle));
  if (SCM_EQ_P(SCM_EOL,sresult_template)) {
    Py_RETURN_NONE;
  }
  else {
    return(g2p_apply(sresult,sresult_template));
  }
}
示例#3
0
/* Given a uref, Return a list of pairs, each pair contains the name
 * of the pin, and the name of the net connected to that pin.  
 */
SCM g_get_pins_nets(SCM scm_uref)
{
    SCM pinslist = SCM_EOL;
    SCM pairlist = SCM_EOL;
    NETLIST *nl_current = NULL;
    CPINLIST *pl_current = NULL;

    char *wanted_uref = NULL;
    char *net_name = NULL;
    char *pin = NULL;

    SCM_ASSERT(scm_is_string (scm_uref),
	       scm_uref, SCM_ARG1, "gnetlist:get-pins-nets");

    wanted_uref = SCM_STRING_CHARS (scm_uref);

    /* search for the any instances */
    /* through the entire list */
    for (nl_current = netlist_head; nl_current != NULL;
	 nl_current = nl_current->next) {

	/* is there a uref? */
	if (nl_current->component_uref) {
	    /* is it the one we want ? */
	    if (strcmp(nl_current->component_uref, wanted_uref) == 0) {

		for (pl_current = nl_current->cpins; pl_current != NULL;
		     pl_current = pl_current->next) {
		    /* is there a valid pin number and a valid name ? */
		    if (pl_current->pin_number) {
			if (pl_current->net_name) {
			    /* yes, add it to the list */
			    pin = pl_current->pin_number;
			    net_name = pl_current->net_name;

			    pairlist = scm_cons (scm_makfrom0str (pin),
                                     scm_makfrom0str (net_name));
			    pinslist = scm_cons (pairlist, pinslist);
			}

		    }
		}
	    }
	}
    }

    pinslist = scm_reverse (pinslist);	/* pins are in reverse order on the way 
					 * out 
					 */
    return (pinslist);
}
示例#4
0
文件: plugin.c 项目: UIKit0/gnumeric
G_MODULE_EXPORT void
go_plugin_init (GOPlugin *p, GOCmdContext *cc)
{
	char *name, *dir;

	*ret_error = NULL;

	 scm_init_guile ();

	/* Initialize just in case. */
	eval_pos = NULL;

	init_value_type ();

	scm_c_define_gsubr ("gnumeric-funcall", 2, 0, 0, scm_gnumeric_funcall);
	scm_c_define_gsubr ("register-function", 5, 0, 0, scm_register_function);

	dir = gnm_sys_data_dir ("guile");
	name = g_strconcat (dir, "gnumeric_startup.scm", NULL);
	scm_apply (scm_c_eval_string ("(lambda (filename)"
				  "  (if (access? filename R_OK)"
				  "    (load filename)"
				  "    (display (string-append \"could not read Guile plug-in init file\" filename \"\n\"))))"),
		  scm_cons (scm_makfrom0str (name), SCM_EOL),
		  SCM_EOL);
	g_free (name);
	g_free (dir);
	/* Don't try to deactivate the plugin */
	gnm_plugin_use_ref (PLUGIN);
}
示例#5
0
/* this function will only return a unique list of packages */
SCM g_get_packages(SCM level)
{
    SCM list = SCM_EOL;
    GHashTable *ht;

    NETLIST *nl_current = NULL;

    SCM_ASSERT(scm_is_string (level), level, SCM_ARG1, "gnetlist:get-pins");

    /* build a hash table */
    ht = g_hash_table_new (g_str_hash, g_str_equal);
    for (nl_current = netlist_head; nl_current != NULL;
         nl_current = nl_current->next) {
      if (nl_current->component_uref != NULL) {
        /* add component_uref in the hash table */
        /* uniqueness of component_uref is guaranteed by the hashtable */

        if (g_hash_table_lookup (ht, nl_current->component_uref) == NULL) {
          g_hash_table_insert (ht, nl_current->component_uref,
                                   nl_current->component_uref);
          list = scm_cons (scm_makfrom0str (nl_current->component_uref), list);
        }
      }
    }
    g_hash_table_destroy (ht);

    return list;
}
示例#6
0
文件: pyscm.c 项目: tddpirate/pyguile
static int
pyscm_PySCM_setattr(pyscm_PySCMObject *self, char *name, PyObject *v)
{
  /* Set attribute 'name' to value 'v'. v==NULL means delete */
  if (pyguile_verbosity_test(PYGUILE_VERBOSE_PYSCM)) {
    scm_simple_format(scm_current_output_port(),scm_makfrom0str("# pyscm_PySCM_setattr: trying to set attribute=~S from pobj=~S to value ~S\n"),scm_list_3(scm_makfrom0str(name),verbosity_repr((PyObject *)self),verbosity_repr(v)));
  }
  SCM sobj_keyword;
  SCM sattr_vector = retrieve_sattr_vector(self,name,&sobj_keyword);
  if (SCM_UNBNDP(sattr_vector)) {
    // Attribute error exception was raised by retrieve_sattr_vector().
    return(-1);
  }

  SCM ssetattr_func = GET_H_SETATTR_FUNC(sattr_vector);
  if (SCM_EQ_P(SCM_EOL,ssetattr_func)) {
    PyErr_SetString(PyExc_AttributeError, name);
    return(-1);
  }

  if (NULL != v) {
    SCM sval = p2g_apply(v,
			 GET_H_P2G_SETATTR_TEMPLATE(sattr_vector));
    scm_append_x(scm_list_2(sobj_keyword,sval));
  }

  SCM sresult = scm_apply(ssetattr_func,sobj_keyword,SCM_EOL);
  return(SCM_EQ_P(SCM_BOOL_F,sresult) ? (-1) : 0);
}
示例#7
0
SCM g_get_pins(SCM uref)
{
    SCM list = SCM_EOL;
    NETLIST *nl_current;
    CPINLIST *pl_current;

    SCM_ASSERT(scm_is_string (uref), uref, SCM_ARG1, "gnetlist:get-pins");

    /* here is where you make it multi page aware */
    nl_current = netlist_head;

    /* search for the first instance */
    /* through the entire list */
    while (nl_current != NULL) {

	if (nl_current->component_uref) {
	    if (strcmp(nl_current->component_uref, SCM_STRING_CHARS (uref)) == 0) {

		pl_current = nl_current->cpins;
		while (pl_current != NULL) {
		    if (pl_current->pin_number) {
              list = scm_cons (scm_makfrom0str (pl_current->pin_number),
                               list);
		    }
		    pl_current = pl_current->next;
		}
	    }
	}
	nl_current = nl_current->next;
    }

    return (list);
}
示例#8
0
/* -------------------------------------------------------------------- *
 * This fcn returns the command line with which gnetlist was invoked.
 * It is used to write the first line of a SPICE file when netlisting 
 * to SPICE.
 * SDB -- 8.22.2004.
 * -------------------------------------------------------------------- */
SCM g_get_command_line()
{
     SCM commandline;

     commandline = scm_makfrom0str (command_line);

     return (commandline);
}
示例#9
0
static void
gnc_plugin_business_reload_module (const gchar *name)
{
    SCM file_scm;

    file_scm = scm_makfrom0str (name);
    scm_call_1(scm_c_eval_string("gnc:reload-module"), file_scm);
}
示例#10
0
文件: pyscm.c 项目: tddpirate/pyguile
static long
pyscm_PySCM_hash(pyscm_PySCMObject *self)
{
  /* Return a hash of self (or -1) */
  if (pyguile_verbosity_test(PYGUILE_VERBOSE_PYSCM)) {
    scm_simple_format(scm_current_output_port(),scm_makfrom0str("# pyscm_PySCM_hash: hash is ~S\n"),scm_list_1(scm_long2num(self->ob_scm_index)));
  }
  return(self->ob_scm_index);
}
示例#11
0
文件: pyscm.c 项目: tddpirate/pyguile
// Unwrap a pyscm_PySCMObject instance and get from it the original
// SCM object.  If the object is not a pyscm_PySCMObject or does not
// wrap a SCM object, raise an error.
SCM
unwrap_pyscm_object(PyObject *pobj)
{
  if (pyguile_verbosity_test(PYGUILE_VERBOSE_PYSCM)) {
    scm_simple_format(scm_current_output_port(),scm_makfrom0str("# unwrap_pyscm_object: trying to unwrap pobj=~S\n"),scm_list_1(verbosity_repr(pobj)));
  }

  if (!PySCMObject_Check(pobj)) {
    Py_FatalError("Trying to pyscm-unwrap a non-PySCM");
  }
  SCM shandle = scm_hashv_get_handle(pyscm_registration_hash,scm_long2num(((pyscm_PySCMObject *)pobj)->ob_scm_index));
  return(SCM_CADR(shandle));
}
示例#12
0
文件: pyscm.c 项目: tddpirate/pyguile
static PyObject *
pyscm_PySCM_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
  pyscm_PySCMObject *self;
  if (pyguile_verbosity_test(PYGUILE_VERBOSE_GC_PYSCM)) {
    scm_simple_format(scm_current_output_port(),scm_makfrom0str("# pyscm_PySCM_new: was called\n"),SCM_EOL);
  }
  self = (pyscm_PySCMObject *)type->tp_alloc(type,0);
  if (NULL != self) {
    self->ob_scm_index = 0;
  }
  return((PyObject *)self);
}
示例#13
0
/* still highly temp and doesn't work right */
SCM g_get_toplevel_attribute(SCM scm_wanted_attrib)
{
    char *wanted_attrib;
    char *return_value;
    SCM scm_return_value;

    SCM_ASSERT(scm_is_string (scm_wanted_attrib),
	       scm_wanted_attrib, SCM_ARG1, "gnetlist:get-toplevel-attribute");

    wanted_attrib = SCM_STRING_CHARS (scm_wanted_attrib);

    return_value = o_attrib_search_toplevel_all(project_current->pages,
						wanted_attrib);

    if (return_value) {
      scm_return_value = scm_makfrom0str (return_value);
      g_free(return_value);
    } else {
      scm_return_value = scm_makfrom0str ("not found");
    }

    return (scm_return_value);
}
示例#14
0
文件: pyscm.c 项目: tddpirate/pyguile
static void
pyscm_PySCM_dealloc(pyscm_PySCMObject *self)
{
  if (pyguile_verbosity_test(PYGUILE_VERBOSE_GC_PYSCM)) {
    scm_simple_format(scm_current_output_port(),scm_makfrom0str("# pyscm_PySCM_dealloc: deallocating PySCMObject with hash ~S\n"),scm_list_1(scm_long2num(self->ob_scm_index)));
  }
  if (0 != self->ob_scm_index) {
    // Unregister the associated SCM from the hash table.
    SCM shashkey = scm_long2num(self->ob_scm_index);
    scm_hashv_remove_x(pyscm_registration_hash,shashkey);
    // If ob_scm_index is zero, no SCM was associated yet with
    // this PySCM instance.
  }
  self->ob_type->tp_free((PyObject*)self);
}
示例#15
0
/********************************************************************\
 * gnc_trans_scm_set_description                                    *
 *   set the description of a scheme transaction.                   *
 *                                                                  *
 * Args: trans_scm   - the scheme transaction                       *
 *       description - the description to set                       *
 * Returns: Nothing                                                 *
\********************************************************************/
void
gnc_trans_scm_set_description(SCM trans_scm, const char *description)
{
    SCM arg;

    initialize_scm_functions();

    if (!gnc_is_trans_scm(trans_scm))
        return;
    if (description == NULL)
        return;

    arg = scm_makfrom0str(description);

    scm_call_2(setters.trans_scm_description, trans_scm, arg);
}
示例#16
0
/********************************************************************\
 * gnc_split_scm_set_action                                         *
 *   set the action of a scheme representation of a split.          *
 *                                                                  *
 * Args: split_scm - the scheme split                               *
 *       action    - the action to set                              *
 * Returns: Nothing                                                 *
\********************************************************************/
void
gnc_split_scm_set_action(SCM split_scm, const char *action)
{
    SCM arg;

    initialize_scm_functions();

    if (!gnc_is_split_scm(split_scm))
        return;
    if (action == NULL)
        return;

    arg = scm_makfrom0str(action);

    scm_call_2(setters.split_scm_action, split_scm, arg);
}
示例#17
0
/********************************************************************\
 * gnc_split_scm_set_memo                                           *
 *   set the memo of a scheme representation of a split.            *
 *                                                                  *
 * Args: split_scm - the scheme split                               *
 *       memo      - the memo to set                                *
 * Returns: Nothing                                                 *
\********************************************************************/
void
gnc_split_scm_set_memo(SCM split_scm, const char *memo)
{
    SCM arg;

    initialize_scm_functions();

    if (!gnc_is_split_scm(split_scm))
        return;
    if (memo == NULL)
        return;

    arg = scm_makfrom0str(memo);

    scm_call_2(setters.split_scm_memo, split_scm, arg);
}
示例#18
0
/********************************************************************\
 * gnc_trans_scm_set_notes                                          *
 *   set the notes of a scheme transaction.                         *
 *                                                                  *
 * Args: trans_scm - the scheme transaction                         *
 *       notes     - the notes to set                               *
 * Returns: Nothing                                                 *
\********************************************************************/
void
gnc_trans_scm_set_notes(SCM trans_scm, const char *notes)
{
    SCM arg;

    initialize_scm_functions();

    if (!gnc_is_trans_scm(trans_scm))
        return;
    if (notes == NULL)
        return;

    arg = scm_makfrom0str(notes);

    scm_call_2(setters.trans_scm_notes, trans_scm, arg);
}
示例#19
0
/* 
   This function returns certain calling flags to the calling guile prog. 
   The calling flags are returned to Guile as a list of option/value pairs [e.g. 
   ((verbose_mode #t) (interactive_mode #f) . . . ) ]
   It is used primarily to enable refdes sorting during netlisting via 
   the -s flag.  Note that this prog is not very flexible -- the allowed 
   calling flags are hard coded into the function.  At some point this 
   should be fixed . . . 
   9.1.2003 -- SDB 
 
   8.2.2005 -- Carlos Nieves Onega
   Different modes are now included in the backend_params list, as well as
   the backend parameters given from the command line. Since the function 
   calling-flag? in scheme/gnetlist.scm returns false if the calling flag was
   not found, it's only necessary to include the flags being true.
*/
SCM g_get_calling_flags()
{
    SCM arglist = SCM_EOL;

    GSList *aux;
  
    aux = backend_params;
    while (aux != NULL) {
      arglist = scm_cons (scm_list_n (scm_makfrom0str (aux->data),
				      SCM_BOOL (TRUE),
				      SCM_UNDEFINED), 
			  arglist);
      aux = aux->next;
    }
    
    return (arglist);
}
示例#20
0
static void
test_query (Query *q, SCM val2str)
{
    SCM scm_q;
    SCM str_q;
    SCM args = SCM_EOL;

    scm_q = gnc_query2scm (q);
    args = scm_cons (scm_q, SCM_EOL);
    str_q = scm_apply (val2str, args, SCM_EOL);

    args = scm_cons (scm_makfrom0str ("'"), scm_cons (str_q, SCM_EOL));
    str_q = scm_string_append (args);

    scm_display (str_q, SCM_UNDEFINED);
    scm_newline (SCM_UNDEFINED);
    scm_newline (SCM_UNDEFINED);
}
示例#21
0
/* this function will only return a non unique list of packages */
SCM g_get_non_unique_packages(SCM level)
{
    SCM list = SCM_EOL;

    NETLIST *nl_current = NULL;

    SCM_ASSERT(scm_is_string (level), level, SCM_ARG1, "gnetlist:get-pins");

    for (nl_current = netlist_head; nl_current != NULL;
         nl_current = nl_current->next) {
      if (nl_current->component_uref != NULL) {
        list = scm_cons (scm_makfrom0str (nl_current->component_uref),
                         list);
      }
    }
    
    return list;
}
示例#22
0
SCM g_get_all_unique_nets(SCM scm_level)
{

    SCM list = SCM_EOL;
    SCM x = SCM_EOL;
    NETLIST *nl_current;
    CPINLIST *pl_current;
    char *net_name;

    SCM_ASSERT(scm_is_string (scm_level), scm_level, SCM_ARG1, 
	       "gnetlist:get-all-unique-nets");

    nl_current = netlist_head;

    /* walk through the list of components, and through the list
     * of individual pins on each, adding net names to the list
     * being careful to ignore duplicates, and unconnected pins 
     */
    while (nl_current != NULL) {
	pl_current = nl_current->cpins;
	while (pl_current != NULL) {
	    if (pl_current->net_name) {

		net_name = pl_current->net_name;
		/* filter off unconnected pins */
		if (strncmp(net_name, "unconnected_pin", 15) != 0) {
		    /* add the net name to the list */
		    /*printf("Got net: `%s'\n",net_name); */

		    x = scm_makfrom0str (net_name);
		    if (scm_member(x, list) == SCM_BOOL_F) {
              list = scm_cons (x, list);
		    }
		}
	    }
	    pl_current = pl_current->next;
	}
	nl_current = nl_current->next;
    }

    return list;
}
示例#23
0
文件: session.c 项目: ChrisX34/stuff
SCM scgi_session_var (SCM name)
{
  /* todo: remove gh_scm2newstr when Guile 1.8 is released */
  char *n;
  char *retval;

  if (SCM_SYMBOLP(name))
    {
      n = gh_symbol2newstr (name, NULL);
    }
  else
    {
      n = gh_scm2newstr (name, NULL);
    }

  retval = cgi_session_var (n);

  free (n);

  return scm_makfrom0str (retval);
}
示例#24
0
/********************************************************************\
 * gnc_split_scm_set_account                                        *
 *   set the account of a scheme representation of a split.         *
 *                                                                  *
 * Args: split_scm - the scheme split                               *
 *       account   - the account to set                             *
 * Returns: Nothing                                                 *
\********************************************************************/
void
gnc_split_scm_set_account(SCM split_scm, Account *account)
{
    const char *guid_string;
    SCM arg;

    initialize_scm_functions();

    if (!gnc_is_split_scm(split_scm))
        return;
    if (account == NULL)
        return;

    guid_string = guid_to_string(xaccAccountGetGUID(account));
    if (guid_string == NULL)
        return;

    arg = scm_makfrom0str(guid_string);

    scm_call_2(setters.split_scm_account_guid, split_scm, arg);
}
示例#25
0
文件: pyscm.c 项目: tddpirate/pyguile
// Create a pyscm_PySCMObject instance, which wraps sobj and associates
// with it with template for data conversions when python accesses data
// and functions/methods associated with sobj.
PyObject *
wrap_scm(SCM sobj,SCM stemplate)
{
  if (pyguile_verbosity_test(PYGUILE_VERBOSE_PYSCM)) {
    scm_simple_format(scm_current_output_port(),scm_makfrom0str("# wrap_scm: was called to wrap ~S\n"),scm_list_1(sobj));
  }
  pyscm_PySCMObject *pwrapper = PyObject_New(pyscm_PySCMObject,&pyscm_PySCMType);
  if (NULL == pwrapper) {
    scm_memory_error("wrap_scm");  // NOT COVERED BY TESTS
  }
  //PyObject_Init(pwrapper,&pyscm_PySCMType);  // Is it needed or does PyObject_New() take care of it?
  //if (NULL == pwrapper) {
  //  scm_misc_error("wrap_scm","could not wrap object ~S with PySCM when using conversion template ~S",
  //		   scm_list_2(sobj,stemplate));
  //}
  else {
    SCM sconsed = scm_cons(sobj,stemplate);
    SCM shashkey = scm_long2num(++pyscm_registration_index);
    scm_hashv_create_handle_x(pyscm_registration_hash,shashkey,sconsed);
    pwrapper->ob_scm_index = pyscm_registration_index;
    return((PyObject *)pwrapper);
  }
}
示例#26
0
文件: pyscm.c 项目: tddpirate/pyguile
static PyObject *
pyscm_PySCM_getattr(pyscm_PySCMObject *self, char *name)
{
  if (pyguile_verbosity_test(PYGUILE_VERBOSE_PYSCM)) {
    scm_simple_format(scm_current_output_port(),scm_makfrom0str("# pyscm_PySCM_getattr: trying to get attribute=~S from pobj=~S\n"),scm_list_2(scm_makfrom0str(name),verbosity_repr((PyObject *)self)));
  }
  SCM sobj_keyword;
  SCM sattr_vector = retrieve_sattr_vector(self,name,&sobj_keyword);
  if (SCM_UNBNDP(sattr_vector)) {
    // Attribute error exception was raised by retrieve_sattr_vector().
    return(NULL);
  }

  SCM sgetattr_func = GET_H_GETATTR_FUNC(sattr_vector);
  if (SCM_EQ_P(SCM_EOL,sgetattr_func)) {
    PyErr_SetString(PyExc_AttributeError, name);
    return(NULL);
  }
  SCM stemplate = GET_H_G2P_GETATTR_TEMPLATE(sattr_vector);

  SCM sresult = scm_apply(sgetattr_func,sobj_keyword,SCM_EOL);
  return(g2p_apply(sresult,stemplate));
}
void
GameSession::init()
{
  loops = 0;
  deltas = 0.0;

  start_time = CL_System::get_time ();
  frames = 0;

  collision_mgr       = new CollisionManager();
  buildingtypemanager = new BuildingTypeManager();

  // Load helper functions
  // FIXME: These functions need a better place
  scm_c_primitive_load(path_manager.complete("feuerkraft.scm").c_str());
  scm_c_primitive_load(path_manager.complete("input.scm").c_str());
  
  // Deserialize the game world
  {
    std::cout << "<<<<<<<<<<<<< Parsing map <<<<<<<<<<<<<" << std::endl;
    SCM fdes = scm_open_file (scm_makfrom0str(filename.c_str()), 
                              scm_makfrom0str("r"));
    SCM lst = scm_read (fdes);
    scm_close (fdes);

    // unstable Testing stuff
    //OutputWorldBuilder builder;
    //SexprWorldReader(lst, &builder).run();

    // Now we create the real world
    world = new GameWorld(lst);
    std::cout << ">>>>>>>>>>>>> Parsing map >>>>>>>>>>>>>" << std::endl;
  }
  // End: Test of parsing code

  // The all mighty soldier that the player controlls
  Soldier* soldier = new Soldier(AList());
  soldier->set_position(FloatVector2d (500, 1100));

  {
    Soldier* soldier = new Soldier(AList());
    soldier->set_position(FloatVector2d (1400, 1500));
    SoldierAI* ai = new SoldierAI(soldier);
    world->add(soldier);
    AIManager::instance()->add(ai);
  }

  {
    Soldier* soldier = new Soldier(AList());
    soldier->set_position(FloatVector2d (1300, 1600));
    SoldierAI* ai = new SoldierAI(soldier);
    world->add(soldier);
    AIManager::instance()->add(ai);
  }

  world->add(new RobotTank(660, 1245, 0, 100.0f));
  world->add(new Helicopter(AList()
                            .set_float("x-pos", 600)
                            .set_float("y-pos", 1245)
                            .set_int("type", 0)));
  world->add(new Helicopter(AList()
                            .set_float("x-pos", 600)
                            .set_float("y-pos", 1445)
                            .set_int("type", 1)));
  world->add(new Helicopter(AList()
                            .set_float("x-pos", 660)
                            .set_float("y-pos", 1645)
                            .set_int("type", 2)));

  world->add(new Tank(FloatVector2d (650, 1245), 5, "feuerkraft/tank", "feuerkraft/turret", "feuerkraft/fire2"));
  world->add(new Tank(FloatVector2d (750, 1245), 5, "feuerkraft/tank", "feuerkraft/turret", "feuerkraft/fire2"));
  world->add(new Tank(FloatVector2d (850, 1245), 5, "feuerkraft/tank", "feuerkraft/turret", "feuerkraft/fire2"));

  {
    Tank* tank = new Tank(FloatVector2d (450, 1245), 5, "feuerkraft/tank", "feuerkraft/turret", "feuerkraft/fire2");
    world->add(tank);
    AIManager::instance()->add(new VehicleRoboAI(tank));
  }

  {
    Tank* tank = new Tank(FloatVector2d (0, 1245), 5, "feuerkraft/tank2", "feuerkraft/turret", "feuerkraft/fire2");
    world->add(tank);
    AIManager::instance()->add(new VehicleRoboAI(tank));
  }

  {
    Tank* tank = new Tank(FloatVector2d (-100, 1245), 5, "feuerkraft/tank", "feuerkraft/turret2", "feuerkraft/fire2");
    world->add(tank);
    AIManager::instance()->add(new VehicleRoboAI(tank));
  }

  {
    Tank* tank = new Tank(FloatVector2d (560, 1245), 5, "feuerkraft/tank2", "feuerkraft/turret2", "feuerkraft/fire2");
    world->add(tank);
    VehiclePathAI* ai = new VehiclePathAI(tank);

    ai->drive_to(FloatVector2d(200, 200));
    ai->drive_to(FloatVector2d(500, 200));
    ai->drive_to(FloatVector2d(500, 500));
    ai->drive_to(FloatVector2d(1500, 500));
    ai->drive_to(FloatVector2d(1500, 300));

    AIManager::instance()->add(ai);
  }

  world->add(new Background (resources->get_sprite("feuerkraft/sand"), -10.0f));
  world->add(soldier);

  player = new Player(soldier);
  view   = new View(0, 0, CL_Display::get_width(), CL_Display::get_height(), new PlayerViewUpdater(player));
  DisplayManager::init();
}
示例#28
0
文件: gwave.c 项目: krichter722/gwave
GdkGC *bg_gdk_gc;

char *pg_color_name  = "grey30" ;  /* panel graticule */
GdkColor pg_gdk_color;
GdkGC *pg_gdk_gc;

char *hl_color_name  = "white" ;  /* panel highlight: select-outline */
GdkColor hl_gdk_color;
GdkGC *hl_gdk_gc;

GdkColormap *win_colormap; /* colormap for main waveform window */


/* variables accessible from both C and guile */

SCM_VARIABLE_INIT(scm_gwave_version, "gwave-version-string",  scm_makfrom0str(VERSION));
/*,
"This variable is initialized to contain the version string for gwave, as"
"set in configure.in."); */

SCM_VARIABLE_INIT(scm_gwave_datadir, "gwave-datadir",  scm_makfrom0str(DATADIR));
/*"This variable is initialized to contain the compiled-in pathname to"
"the installed data directory, typicaly PREFIX/share, as set by configure."
"It is used by the startup code as a default location for finding gwave's"
"guile modules.");*/

SCM_VARIABLE_INIT(scm_gwave_bingwave, "gwave-bin-gwave-path", scm_makfrom0str(BINGWAVE));
/*,
"This variable is initialized to contain the compiled-in pathname to"
"the installed gwave executable, typicaly PREFIX/bin/gwave, as set by configure."
"It is used by the procedures that write out gwave configuration-restoring"
示例#29
0
/* given a net name, an attribute, and a wanted attribute, return all 
   the given attribute of all the graphical objects connected to that 
   net name */
SCM g_graphical_objs_in_net_with_attrib_get_attrib (SCM scm_netname, SCM scm_has_attribute, SCM scm_wanted_attribute)
{

    SCM list = SCM_EOL;
    NETLIST *nl_current;
    CPINLIST *pl_current;
    char *wanted_net_name;
    char *wanted_attrib;
    char *has_attrib;
    char *net_name;
    char *attrib_value=NULL;
    char *has_attrib_value = NULL;
    char *has_attrib_name = NULL;

    SCM_ASSERT(scm_is_string (scm_netname), scm_netname, SCM_ARG1, 
	       "gnetlist:get-attr-of-conn-graph-objs-with-attr");

    SCM_ASSERT(scm_is_string (scm_wanted_attribute),
	       scm_wanted_attribute, SCM_ARG2, 
	       "gnetlist:get-attr-of-conn-graph-objs-with-attr");

    SCM_ASSERT(scm_is_string (scm_has_attribute),
	       scm_has_attribute, SCM_ARG3, 
	       "gnetlist:get-attr-of-conn-graph-objs-with-attr");

    wanted_net_name = SCM_STRING_CHARS (scm_netname);
    wanted_attrib = SCM_STRING_CHARS (scm_wanted_attribute);
    has_attrib = SCM_STRING_CHARS (scm_has_attribute);
    
    if (wanted_net_name == NULL) {
	return list;
    }


    nl_current = graphical_netlist_head;
    
    /* walk through the list of components, and through the list
     * of individual pins on each, adding net names to the list
     * being careful to ignore duplicates, and unconnected pins 
     */
    while (nl_current != NULL) {
	pl_current = nl_current->cpins;
	while (pl_current != NULL) {
	    if (pl_current->net_name) {
		net_name = pl_current->net_name;
		if (strcmp(net_name, wanted_net_name) == 0) {

		  if (o_attrib_get_name_value (has_attrib, &has_attrib_name,
					       &has_attrib_value) != 0) {
		    attrib_value = 
		      o_attrib_search_name_single(nl_current->object_ptr,
						  has_attrib_name, NULL);
		    
		    if ( ((has_attrib_value == NULL) && (attrib_value == NULL)) ||
			 ((has_attrib_value != NULL) && (attrib_value != NULL) &&
			  (strcmp(attrib_value, has_attrib_value) == 0)) ) {
		      g_free (attrib_value);
		      attrib_value = o_attrib_search_name_single(nl_current->object_ptr,
								 wanted_attrib, NULL);
		      if (attrib_value) {
			list = scm_cons (scm_makfrom0str (attrib_value), list);
		      }
		      g_free (attrib_value);
		    }
		    g_free (has_attrib_name);
		    g_free (has_attrib_value);
		  }
		}
	    }
	    pl_current = pl_current->next;
	}
	nl_current = nl_current->next;
    }

    return list;
}
示例#30
0
/* in the form: (1 2 3 4). Repeated slots are NOT returned */
SCM g_get_unique_slots(SCM scm_uref)
{
    NETLIST *nl_current;
    char *uref;
    gchar *slot = NULL;
    char *slot_tmp = NULL;
    SCM slots_list = SCM_EOL;
    SCM slot_number;


    SCM_ASSERT(scm_is_string (scm_uref),
	       scm_uref, SCM_ARG1, "gnetlist:get-unique-slots-used-of-package");

    uref = SCM_STRING_CHARS (scm_uref);
    
    /* here is where you make it multi page aware */
    nl_current = netlist_head;

    /* search for the first instance */
    /* through the entire list */
    while (nl_current != NULL) {

	if (nl_current->component_uref) {
	    if (strcmp(nl_current->component_uref, uref) == 0) {

		/* first search outside the symbol */
		slot_tmp =
		    o_attrib_search_name_single(nl_current->object_ptr,
						"slot", NULL);

		if (!slot_tmp) {
		/* if not found, search inside the symbol */
		slot_tmp =
		    o_attrib_search_name(nl_current->object_ptr->
					 complex->prim_objs, "slot",
					 0);
		}
		/* When a package has no slot attribute, then assume it's slot number 1 */
		if (!slot_tmp) {
		  slot_tmp=g_strdup("1");
		}
		slot = g_strconcat ("#d", slot_tmp, NULL);
		slot_number = scm_string_to_number(scm_makfrom0str (slot),
                                           scm_from_int(10));
		g_free (slot);
		if (slot_number != SCM_BOOL_F) {
		  if (scm_member(slot_number, slots_list) ==  SCM_BOOL_F) {
		    slots_list = scm_cons (slot_number, slots_list);
		  }
		}
		else 
		  fprintf(stderr, "Uref %s: Bad slot number: %s.\n", uref, slot_tmp);
		g_free (slot_tmp);
	    }
	}
	nl_current = nl_current->next;
    }

    slots_list = scm_sort_list_x(slots_list,
                                 SCM_VARIABLE_REF (scm_c_module_lookup (
                                   scm_current_module (), "<")));
    return (slots_list);
}