/* This callback function catches the data passed by libcurl and sends it back as a scheme string */ static size_t write_callback (void *ptr, size_t size, size_t nmemb, void *userdata) { size_t length1, length2; SCM data1, data2; struct scm_flag *sf; sf = (struct scm_flag *) userdata; data1 = sf->scm; #if SCM_MAJOR_VERSION == 2 if (sf->flag) length1 = scm_c_bytevector_length (data1); else length1 = scm_c_string_length (data1); #else length1 = scm_c_string_length (data1); #endif length2 = size * nmemb; /* printf ("In write_callback\n"); */ #if SCM_MAJOR_VERSION == 2 if (sf->flag) { data2 = scm_c_make_bytevector (length1 + length2); memcpy (SCM_BYTEVECTOR_CONTENTS (data2), SCM_BYTEVECTOR_CONTENTS (data1), length1); memcpy (SCM_BYTEVECTOR_CONTENTS (data2) + length1, ptr, length2); } else { data2 = scm_c_make_string (length1 + length2, SCM_MAKE_CHAR('\0')); for (size_t i = 0; i < length1; i ++) { scm_c_string_set_x (data2, i, scm_c_string_ref (data1, i)); } for (size_t i = 0; i < length2; i ++) { scm_c_string_set_x (data2, i + length1, SCM_MAKE_CHAR (((char *)ptr)[i])); } } #else data2 = scm_c_make_string (length1 + length2, SCM_MAKE_CHAR('\0')); memcpy (SCM_STRING_CHARS (data2), SCM_STRING_CHARS (data1), length1); memcpy (SCM_STRING_CHARS (data2) + length1, ptr, length2); #endif sf->scm = data2; return length2; }
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); }
/*! \brief Exports the keymap in scheme to a GLib GArray. * \par Function Description * This function converts the list of key sequence/action pairs * returned by the scheme function \c dump-current-keymap into an * array of C structures. * * The returned value must be freed by caller. * * \return A GArray with keymap data. */ GArray* g_keys_dump_keymap (void) { SCM dump_proc = scm_c_lookup ("dump-current-keymap"); SCM scm_ret; GArray *ret = NULL; struct keyseq_action_t { gchar *keyseq, *action; }; dump_proc = scm_variable_ref (dump_proc); g_return_val_if_fail (SCM_NFALSEP (scm_procedure_p (dump_proc)), NULL); scm_ret = scm_call_0 (dump_proc); g_return_val_if_fail (SCM_CONSP (scm_ret), NULL); ret = g_array_sized_new (FALSE, FALSE, sizeof (struct keyseq_action_t), (guint)scm_ilength (scm_ret)); for (; scm_ret != SCM_EOL; scm_ret = SCM_CDR (scm_ret)) { SCM scm_keymap_entry = SCM_CAR (scm_ret); struct keyseq_action_t keymap_entry; g_return_val_if_fail (SCM_CONSP (scm_keymap_entry) && scm_is_symbol (SCM_CAR (scm_keymap_entry)) && scm_is_string (SCM_CDR (scm_keymap_entry)), ret); keymap_entry.action = g_strdup (SCM_SYMBOL_CHARS (SCM_CAR (scm_keymap_entry))); keymap_entry.keyseq = g_strdup (SCM_STRING_CHARS (SCM_CDR (scm_keymap_entry))); ret = g_array_append_val (ret, keymap_entry); } return ret; }
/*! \todo Finish function documentation!!! * \brief * \par Function Description * */ SCM g_rc_paper_sizes(SCM scm_papername, SCM scm_width, SCM scm_height) #define FUNC_NAME "paper-sizes" { int width; int height; char *papername; SCM ret; SCM_ASSERT (scm_is_string (scm_papername), scm_papername, SCM_ARG1, FUNC_NAME); SCM_ASSERT (SCM_NIMP (scm_width) && SCM_REALP (scm_width), scm_width, SCM_ARG2, FUNC_NAME); SCM_ASSERT (SCM_NIMP (scm_height) && SCM_REALP (scm_height), scm_height, SCM_ARG3, FUNC_NAME); papername = SCM_STRING_CHARS (scm_papername); width = (int) (SCM_NUM2DOUBLE (0, scm_width) * MILS_PER_INCH); height = (int) (SCM_NUM2DOUBLE (0, scm_height) * MILS_PER_INCH); if (!s_papersizes_uniq(papername)) { ret = SCM_BOOL_F; } else { s_papersizes_add_entry(papername, width, height); ret = SCM_BOOL_T; } return ret; }
/*! \brief read the configuration string list for the component dialog * \par Function Description * This function reads the string list from the component-dialog-attributes * configuration parameter and converts the list into a GList. * The GList is stored in the global default_component_select_attrlist variable. */ SCM g_rc_component_dialog_attributes(SCM stringlist) { int length, i; GList *list=NULL; gchar *attr; SCM_ASSERT(scm_list_p(stringlist), stringlist, SCM_ARG1, "scm_is_list failed"); length = scm_ilength(stringlist); /* If the command is called multiple times, remove the old list before recreating it */ g_list_foreach(default_component_select_attrlist, (GFunc)g_free, NULL); g_list_free(default_component_select_attrlist); /* convert the scm list into a GList */ for (i=0; i < length; i++) { SCM_ASSERT(scm_is_string(scm_list_ref(stringlist, scm_from_int(i))), scm_list_ref(stringlist, scm_from_int(i)), SCM_ARG1, "list element is not a string"); attr = g_strdup(SCM_STRING_CHARS(scm_list_ref(stringlist, scm_from_int(i)))); list = g_list_prepend(list, attr); } default_component_select_attrlist = g_list_reverse(list); return SCM_BOOL_T; }
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); }
/*! \todo Finish function documentation!!! * \brief * \par Function Description * */ SCM g_rc_add_menu(SCM menu_name, SCM menu_items) { SCM_ASSERT (scm_is_string (menu_name), menu_name, SCM_ARG1, "add-menu"); SCM_ASSERT (SCM_NIMP (menu_items) && SCM_CONSP (menu_items), menu_items, SCM_ARG2, "add-menu"); s_menu_add_entry(SCM_STRING_CHARS (menu_name), menu_items); return SCM_BOOL_T; }
/*! \brief Test the version of gattrib and gEDA/gaf * * \param version Version being tested * \returns false if incorrect version, true if OK */ SCM g_rc_gattrib_version(SCM version) { SCM_ASSERT (scm_is_string (version), version, SCM_ARG1, "gattrib-version"); if (g_strcasecmp (SCM_STRING_CHARS (version), PACKAGE_DATE_VERSION) != 0) { fprintf(stderr, "You are running gEDA/gaf version [%s%s.%s],\n", PREPEND_VERSION_STRING, PACKAGE_DOTTED_VERSION, PACKAGE_DATE_VERSION); fprintf(stderr, "but you have a version [%s] gattribrc file.\n", SCM_STRING_CHARS (version)); fprintf(stderr, "Please be sure that you have the latest rc file.\n"); return SCM_BOOL_F; } return SCM_BOOL_T; }
/* 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); }
/*! \todo Finish function documentation!!! * \brief * \par Function Description * */ SCM g_rc_gschem_version(SCM version) { SCM ret; SCM_ASSERT (scm_is_string (version), version, SCM_ARG1, "gschem-version"); if (g_strcasecmp (SCM_STRING_CHARS (version), DATE_VERSION) != 0) { fprintf(stderr, "You are running gEDA/gaf version [%s%s.%s],\n", PREPEND_VERSION_STRING, DOTTED_VERSION, DATE_VERSION); fprintf(stderr, "but you have a version [%s] gschemrc file:\n[%s]\n", SCM_STRING_CHARS (version), rc_filename); fprintf(stderr, "Please be sure that you have the latest rc file.\n"); ret = SCM_BOOL_F; } else { ret = SCM_BOOL_T; } return ret; }
// Does not include the template object in the string representation. static PyObject * pyscm_PySCM_str(pyscm_PySCMObject *self) { if (0 == self->ob_scm_index) { return(PyString_FromString("<no SCM association>")); } 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"); } SCM sstr = scm_object_to_string(SCM_CADR(shandle),scm_variable_ref(scm_c_lookup("write"))); PyObject *pstr = PyString_FromStringAndSize(SCM_STRING_CHARS(sstr),SCM_STRING_LENGTH(sstr)); return(pstr); // possibly NULL. }
/*! \todo Finish function documentation!!! * \brief * \par Function Description * */ SCM g_rc_print_command(SCM scm_command) #define FUNC_NAME "print-command" { char *command; SCM_ASSERT (scm_is_string (scm_command), scm_command, SCM_ARG1, FUNC_NAME); command = SCM_STRING_CHARS (scm_command); g_free (default_print_command); default_print_command = g_strdup (command); return SCM_BOOL_T; }
/* 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); } #if 0 /* No longer needed, but the netlist_mode variable is still used */ SCM g_set_netlist_mode(SCM mode) { char *string; string = SCM_STRING_CHARS (mode); if (strcmp(string, "gEDA") == 0) { netlist_mode = gEDA; } else if (strcmp(string, "SPICE") == 0) { netlist_mode = SPICE; } else if (strcmp(string, "TANGO") == 0) { netlist_mode = TANGO; } #if DEBUG printf("netlist_mode: %s %d\n", string, netlist_mode); #endif return (scm_from_int (0)); }
/*! \todo Finish function documentation!!! * \brief * \par Function Description * */ SCM g_rc_attribute_name(SCM scm_path) { char *path; SCM ret; SCM_ASSERT (scm_is_string (scm_path), scm_path, SCM_ARG1, "attribute-name"); path = SCM_STRING_CHARS (scm_path); /* not unique? */ if (!s_attrib_uniq(path)) { ret = SCM_BOOL_F; } else { s_attrib_add_entry (path); ret = SCM_BOOL_T; } return ret; }
/* 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); }
/* 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); }
/* scm_pin is the value associated with the pinnumber= attribute and uref */ SCM g_get_attribute_by_pinnumber(SCM scm_uref, SCM scm_pin, SCM scm_wanted_attrib) { SCM scm_return_value; NETLIST *nl_current; OBJECT *pin_object; char *uref; char *pin; char *wanted_attrib; char *return_value = NULL; int done = FALSE; SCM_ASSERT(scm_is_string (scm_uref), scm_uref, SCM_ARG1, "gnetlist:get-pin-attribute"); SCM_ASSERT(scm_is_string (scm_pin), scm_pin, SCM_ARG2, "gnetlist:get-pin-attribute"); SCM_ASSERT(scm_is_string (scm_wanted_attrib), scm_wanted_attrib, SCM_ARG3, "gnetlist:get-pin-attribute"); uref = SCM_STRING_CHARS (scm_uref); pin = SCM_STRING_CHARS (scm_pin); 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 && !done) { if (nl_current->component_uref) { if (strcmp(nl_current->component_uref, uref) == 0) { pin_object = o_complex_return_pin_object(nl_current->object_ptr, pin); if (pin_object) { /* only look for the first occurance of wanted_attrib */ return_value = o_attrib_search_attrib_name(pin_object->attribs, wanted_attrib, 0); #if DEBUG if (return_value) { printf("GOT IT: %s\n", return_value); } #endif } else if (strcmp("pintype", wanted_attrib) == 0) { if (nl_current->cpins) { CPINLIST *pinobject = s_cpinlist_search_pin(nl_current->cpins, pin); if (pinobject) { return_value="pwr"; #if DEBUG printf("Supplied pintype 'pwr' for artificial pin '%s' of '%s'\n", pin, uref); #endif } } } } } 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); }
/* with that pinseq pin and component */ SCM g_get_attribute_by_pinseq(SCM scm_uref, SCM scm_pinseq, SCM scm_wanted_attrib) { SCM scm_return_value; NETLIST *nl_current; char *uref; char *pinseq; char *wanted_attrib; char *pinseq_attrib; char *return_value = NULL; OBJECT *o_text_object; OBJECT *o_pin_object; SCM_ASSERT(scm_is_string (scm_uref), scm_uref, SCM_ARG1, "gnetlist:get-pin-number-seq"); SCM_ASSERT(scm_is_string (scm_pinseq), scm_pinseq, SCM_ARG2, "gnetlist:get-pin-number-seq"); SCM_ASSERT(scm_is_string (scm_wanted_attrib), scm_wanted_attrib, SCM_ARG3, "gnetlist:get-pin-attribute-seq"); uref = SCM_STRING_CHARS (scm_uref); pinseq = SCM_STRING_CHARS (scm_pinseq); wanted_attrib = SCM_STRING_CHARS (scm_wanted_attrib); pinseq_attrib = g_strconcat ("pinseq=", pinseq, NULL); #if DEBUG printf("gnetlist:g_netlist.c:g_get_attribute_by_pinseq -- \n"); printf(" wanted uref = %s\n", uref); printf(" wanted_pin_seq = %s\n", pinseq); printf(" wanted_attrib = %s\n", wanted_attrib); #endif /* 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 */ /* This checks for attributes attached to this component */ /* at schematic level */ o_text_object = o_attrib_search_string_single(nl_current->object_ptr, pinseq_attrib); if (o_text_object && o_text_object->attached_to) { o_pin_object = o_text_object->attached_to; if (o_pin_object) { return_value = o_attrib_search_name_single(o_pin_object, wanted_attrib, NULL); if (return_value) { break; } } } else { #if DEBUG printf("gnetlist:g_netlist.c:g_get_attribute_by_pinseq -- "); printf("can't find pinseq at schematic level\n"); #endif } /* now search inside the symbol */ /* This checks for attributes attached at the symbol level */ o_text_object = o_attrib_search_string_list(nl_current->object_ptr-> complex->prim_objs, pinseq_attrib); if (o_text_object && o_text_object->attached_to) { o_pin_object = o_text_object->attached_to; if (o_pin_object) { return_value = o_attrib_search_name_single(o_pin_object, wanted_attrib, NULL); if (return_value) { break; } } } /* Don't break until we search the whole netlist to handle slotted */ /* parts. 4.28.2007 -- SDB. */ } } nl_current = nl_current->next; } if (return_value) { scm_return_value = scm_makfrom0str (return_value); } else { scm_return_value = scm_makfrom0str ("unknown"); } #if DEBUG printf("gnetlist:g_netlist.c:g_get_attribute_by_pinseq -- "); printf("return_value: %s\n", return_value); #endif g_free(pinseq_attrib); return (scm_return_value); }
/* * Sets several text properties of the given <B>attribute smob</B>: - <B>coloridx</B>: The index of the text color, or -1 to keep previous color. - <B>size</B>: Size (numeric) of the text, or -1 to keep the previous size. - <B>alignment</B>: String with the alignment of the text. Possible values are: * "" : Keep the previous alignment. * "Lower Left" * "Middle Left" * "Upper Left" * "Lower Middle" * "Middle Middle" * "Upper Middle" * "Lower Right" * "Middle Right" * "Upper Right" - <B>rotation</B>: Angle of the text, or -1 to keep previous angle. - <B>x</B>, <B>y</B>: Coords of the text. */ SCM g_set_attrib_text_properties(SCM attrib_smob, SCM scm_coloridx, SCM scm_size, SCM scm_alignment, SCM scm_rotation, SCM scm_x, SCM scm_y) { struct st_attrib_smob *attribute = (struct st_attrib_smob *)SCM_CDR(attrib_smob); OBJECT *object; GSCHEM_TOPLEVEL *w_current = global_window_current; TOPLEVEL *toplevel = w_current->toplevel; int color = -1; int size = -1; char *alignment_string; int alignment = -2; int rotation = 0; int x = -1, y = -1; SCM_ASSERT (scm_is_integer(scm_coloridx), scm_coloridx, SCM_ARG2, "set-attribute-text-properties!"); SCM_ASSERT ( scm_is_integer(scm_size), scm_size, SCM_ARG3, "set-attribute-text-properties!"); SCM_ASSERT (scm_is_string(scm_alignment), scm_alignment, SCM_ARG4, "set-attribute-text-properties!"); SCM_ASSERT ( scm_is_integer(scm_rotation), scm_rotation, SCM_ARG5, "set-attribute-text-properties!"); SCM_ASSERT ( scm_is_integer(scm_x), scm_x, SCM_ARG6, "set-attribute-text-properties!"); SCM_ASSERT ( scm_is_integer(scm_y), scm_y, SCM_ARG7, "set-attribute-text-properties!"); color = scm_to_int(scm_coloridx); SCM_ASSERT (!(color < -1 || color >= MAX_COLORS), scm_coloridx, SCM_ARG2, "set-attribute-text-properties!"); size = scm_to_int(scm_size); rotation = scm_to_int(scm_rotation); x = scm_to_int(scm_x); y = scm_to_int(scm_y); alignment_string = SCM_STRING_CHARS(scm_alignment); if (strlen(alignment_string) == 0) { alignment = -1; } if (strcmp(alignment_string, "Lower Left") == 0) { alignment = 0; } if (strcmp(alignment_string, "Middle Left") == 0) { alignment = 1; } if (strcmp(alignment_string, "Upper Left") == 0) { alignment = 2; } if (strcmp(alignment_string, "Lower Middle") == 0) { alignment = 3; } if (strcmp(alignment_string, "Middle Middle") == 0) { alignment = 4; } if (strcmp(alignment_string, "Upper Middle") == 0) { alignment = 5; } if (strcmp(alignment_string, "Lower Right") == 0) { alignment = 6; } if (strcmp(alignment_string, "Middle Right") == 0) { alignment = 7; } if (strcmp(alignment_string, "Upper Right") == 0) { alignment = 8; } if (alignment == -2) { /* Bad specified */ SCM_ASSERT (scm_is_string(scm_alignment), scm_alignment, SCM_ARG4, "set-attribute-text-properties!"); } if (attribute && attribute->attribute) { object = attribute->attribute; if (object && object->text) { o_invalidate (w_current, object); if (x != -1) { object->text->x = x; } if (y != -1) { object->text->y = y; } if (size != -1) { object->text->size = size; } if (alignment != -1) { object->text->alignment = alignment; } if (rotation != -1) { object->text->angle = rotation; } o_text_recreate(toplevel, object); if (!toplevel->DONT_REDRAW) { o_invalidate (w_current, object); } } } return SCM_BOOL_T; }
/* (netname (uref pin) (uref pin) ... ) */ SCM g_get_nets(SCM scm_uref, SCM scm_pin) { SCM outerlist = SCM_EOL; SCM pinslist = SCM_EOL; SCM pairlist = SCM_EOL; NETLIST *nl_current = NULL; CPINLIST *pl_current = NULL; NET *n_current; char *wanted_uref = NULL; char *wanted_pin = NULL; char *net_name = NULL; char *pin; char *uref; SCM_ASSERT(scm_is_string (scm_uref), scm_uref, SCM_ARG1, "gnetlist:get-nets"); SCM_ASSERT(scm_is_string (scm_pin), scm_pin, SCM_ARG2, "gnetlist:get-nets"); wanted_uref = SCM_STRING_CHARS (scm_uref); wanted_pin = SCM_STRING_CHARS (scm_pin); 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, wanted_uref) == 0) { pl_current = nl_current->cpins; while (pl_current != NULL) { if (pl_current->pin_number) { if (strcmp(pl_current->pin_number, wanted_pin) == 0) { n_current = pl_current->nets; if (pl_current->net_name) { net_name = pl_current->net_name; } while (n_current != NULL) { if (n_current->connected_to) { pairlist = SCM_EOL; pin = (char *) g_malloc(sizeof(char) * strlen (n_current-> connected_to)); uref = (char *) g_malloc(sizeof(char) * strlen(n_current-> connected_to)); sscanf(n_current->connected_to, "%s %s", uref, pin); pairlist = scm_list_n (scm_makfrom0str (uref), scm_makfrom0str (pin), SCM_UNDEFINED); pinslist = scm_cons (pairlist, pinslist); g_free(uref); g_free(pin); } n_current = n_current->next; } } } pl_current = pl_current->next; } } } nl_current = nl_current->next; } if (net_name != NULL) { outerlist = scm_cons (scm_makfrom0str (net_name), pinslist); } else { outerlist = scm_cons (scm_makfrom0str ("ERROR_INVALID_PIN"), outerlist); fprintf(stderr, "Invalid wanted_pin passed to get-nets [%s]\n", wanted_pin); } return (outerlist); }
/*! \brief Add a component to the page. * \par Function Description * Adds a component <B>scm_comp_name</B> to the schematic, at * position (<B>scm_x</B>, <B>scm_y</B>), with some properties set by * the parameters: * \param [in] scm_x Coordinate X of the symbol. * \param [in] scm_y Coordinate Y of the symbol. * \param [in] angle Angle of rotation of the symbol. * \param [in] selectable True if the symbol is selectable, false otherwise. * \param [in] mirror True if the symbol is mirrored, false otherwise. * If scm_comp_name is a scheme empty list, SCM_BOOL_F, or an empty * string (""), then g_add_component returns SCM_BOOL_F without writing * to the log. * \return TRUE if the component was added, FALSE otherwise. * */ SCM g_add_component(SCM page_smob, SCM scm_comp_name, SCM scm_x, SCM scm_y, SCM scm_angle, SCM scm_selectable, SCM scm_mirror) { TOPLEVEL *toplevel; PAGE *page; gboolean selectable, mirror; gchar *comp_name; int x, y, angle; OBJECT *new_obj; const CLibSymbol *clib; /* Return if scm_comp_name is NULL (an empty list) or scheme's FALSE */ if (SCM_NULLP(scm_comp_name) || (SCM_BOOLP(scm_comp_name) && !(SCM_NFALSEP(scm_comp_name))) ) { return SCM_BOOL_F; } /* Get toplevel and the page */ SCM_ASSERT (g_get_data_from_page_smob (page_smob, &toplevel, &page), page_smob, SCM_ARG1, "add-component-at-xy"); /* Check the arguments */ SCM_ASSERT (scm_is_string(scm_comp_name), scm_comp_name, SCM_ARG2, "add-component-at-xy"); SCM_ASSERT ( scm_is_integer(scm_x), scm_x, SCM_ARG3, "add-component-at-xy"); SCM_ASSERT ( scm_is_integer(scm_y), scm_y, SCM_ARG4, "add-component-at-xy"); SCM_ASSERT ( scm_is_integer(scm_angle), scm_angle, SCM_ARG5, "add-component-at-xy"); SCM_ASSERT ( scm_boolean_p(scm_selectable), scm_selectable, SCM_ARG6, "add-component-at-xy"); SCM_ASSERT ( scm_boolean_p(scm_mirror), scm_mirror, SCM_ARG7, "add-component-at-xy"); /* Get the parameters */ comp_name = SCM_STRING_CHARS(scm_comp_name); x = scm_to_int(scm_y); y = scm_to_int(scm_y); angle = scm_to_int(scm_angle); selectable = SCM_NFALSEP(scm_selectable); mirror = SCM_NFALSEP(scm_mirror); SCM_ASSERT (comp_name, scm_comp_name, SCM_ARG2, "add-component-at-xy"); if (strcmp(comp_name, "") == 0) { return SCM_BOOL_F; } clib = s_clib_get_symbol_by_name (comp_name); new_obj = o_complex_new (toplevel, 'C', DEFAULT_COLOR, x, y, angle, mirror, clib, comp_name, selectable); s_page_append_list (page, o_complex_promote_attribs (toplevel, new_obj)); s_page_append (page, new_obj); /* * For now, do not redraw the newly added complex, since this might cause * flicker if you are zoom/panning right after this function executes */ #if 0 /* Now the new component should be added to the object's list and drawn in the screen */ o_invalidate (toplevel, new_object); #endif return SCM_BOOL_T; }
/* 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; }
/* * Adds an attribute <B>scm_attrib_name</B> with value <B>scm_attrib_value</B> to the given <B>object</B>. The attribute has the visibility <B>scm_vis</B> and show <B>scm_show</B> flags. The possible values are: - <B>scm_vis</B>: scheme boolean. Visible (TRUE) or hidden (FALSE). - <B>scm_show</B>: a list containing what to show: "name", "value", or both. The return value is always TRUE. */ SCM g_add_attrib(SCM object, SCM scm_attrib_name, SCM scm_attrib_value, SCM scm_vis, SCM scm_show) { GSCHEM_TOPLEVEL *w_current=global_window_current; TOPLEVEL *toplevel = w_current->toplevel; OBJECT *o_current=NULL; gboolean vis; int show=0; gchar *attrib_name=NULL; gchar *attrib_value=NULL; gchar *value=NULL; int i; gchar *newtext=NULL; SCM_ASSERT (scm_is_string(scm_attrib_name), scm_attrib_name, SCM_ARG2, "add-attribute-to-object"); SCM_ASSERT (scm_is_string(scm_attrib_value), scm_attrib_value, SCM_ARG3, "add-attribute-to-object"); SCM_ASSERT (scm_boolean_p(scm_vis), scm_vis, SCM_ARG4, "add-attribute-to-object"); SCM_ASSERT (scm_list_p(scm_show), scm_show, SCM_ARG5, "add-attribute-to-object"); /* Get toplevel and o_current */ SCM_ASSERT (g_get_data_from_object_smob (object, &toplevel, &o_current), object, SCM_ARG1, "add-attribute-to-object"); /* Get parameters */ attrib_name = SCM_STRING_CHARS(scm_attrib_name); attrib_value = SCM_STRING_CHARS(scm_attrib_value); vis = SCM_NFALSEP(scm_vis); for (i=0; i<=scm_to_int(scm_length(scm_show))-1; i++) { /* Check every element in the list. It should be a string! */ SCM_ASSERT(scm_list_ref(scm_show, scm_from_int(i)), scm_show, SCM_ARG5, "add-attribute-to-object"); SCM_ASSERT(scm_is_string(scm_list_ref(scm_show, scm_from_int(i))), scm_show, SCM_ARG5, "add-attribute-to-object"); value = SCM_STRING_CHARS(scm_list_ref(scm_show, scm_from_int(i))); SCM_ASSERT(value, scm_show, SCM_ARG5, "add-attribute-to-object"); /* Only "name" or "value" strings are allowed */ SCM_ASSERT(!((strcasecmp(value, "name") != 0) && (strcasecmp(value, "value") != 0) ), scm_show, SCM_ARG5, "add-attribute-to-object"); /* show = 1 => show value; show = 2 => show name; show = 3 => show both */ if (strcasecmp(value, "value") == 0) { show |= 1; } else if (strcasecmp(value, "name") == 0) { show |= 2; } } /* Show name and value (show = 3) => show=0 for gschem */ if (show == 3) { show = 0; } newtext = g_strdup_printf("%s=%s", attrib_name, attrib_value); o_attrib_add_attrib (w_current, newtext, vis, show, o_current); g_free(newtext); return SCM_BOOL_T; }
/* given a net name, return all connections */ SCM g_get_all_connections(SCM scm_netname) { SCM list = SCM_EOL; SCM x = SCM_EOL; SCM is_member = SCM_EOL; SCM connlist = SCM_EOL; SCM pairlist = SCM_EOL; NETLIST *nl_current; CPINLIST *pl_current; NET *n_current; char *wanted_net_name; char *net_name; char *pin; char *uref; SCM_ASSERT(scm_is_string(scm_netname), scm_netname, SCM_ARG1, "gnetlist:get-all-connections"); wanted_net_name = SCM_STRING_CHARS (scm_netname); if (wanted_net_name == NULL) { return list; } 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 (strcmp(net_name, wanted_net_name) == 0) { /* add the net name to the list */ #if DEBUG printf("found net: `%s'\n", net_name); #endif n_current = pl_current->nets; while (n_current != NULL) { if (n_current->connected_to) { pairlist = SCM_EOL; pin = (char *) g_malloc(sizeof(char) * strlen(n_current-> connected_to)); uref = (char *) g_malloc(sizeof(char) * strlen(n_current-> connected_to)); sscanf(n_current->connected_to, "%s %s", uref, pin); pairlist = scm_list_n (scm_makfrom0str (uref), scm_makfrom0str (pin), SCM_UNDEFINED); x = pairlist; is_member = scm_member(x, connlist); if (is_member == SCM_BOOL_F) { connlist = scm_cons (pairlist, connlist); } g_free(uref); g_free(pin); } n_current = n_current->next; } } } pl_current = pl_current->next; } nl_current = nl_current->next; } return connlist; }
/*! \brief Get the object bounds of the given object, excluding the object * types or the attributes given as parameters. * \par Function Description * Get the object bounds without considering the attributes in * scm_exclude_attribs, neither the object types included in * scm_exclude_object_type * \param [in] object_smob The object we want to know the bounds of. * \param [in] exclude_attrib_list A list with the attribute names we don't * want to include when calculing the bounds. * \param [in] exclude_obj_type_list A list with the object types we don't * want to include when calculing the bounds. * The object types are those used in (OBJECT *)->type converted into strings. * \return a list of the bounds of the <B>object smob</B>. * The list has the format: ( (left right) (top bottom) ) * WARNING: top and bottom are mis-named in world-coords, * top is the smallest "y" value, and bottom is the largest. * Be careful! This doesn't correspond to what you'd expect, * nor to the coordinate system who's origin is the bottom, left of the page. */ SCM g_get_object_bounds (SCM object_smob, SCM scm_exclude_attribs, SCM scm_exclude_object_type) { TOPLEVEL *toplevel=NULL; OBJECT *object=NULL; int left=0, right=0, bottom=0, top=0; SCM returned = SCM_EOL; SCM vertical = SCM_EOL; SCM horizontal = SCM_EOL; GList *exclude_attrib_list = NULL, *exclude_obj_type_list = NULL; gboolean exclude_all_attribs = FALSE; int i; SCM_ASSERT (scm_list_p(scm_exclude_attribs), scm_exclude_attribs, SCM_ARG2, "get-object-bounds"); SCM_ASSERT (scm_list_p(scm_exclude_object_type), scm_exclude_object_type, SCM_ARG3, "get-object-bounds"); /* Build the exclude attrib list */ for (i=0; i <= scm_to_int(scm_length(scm_exclude_attribs))-1; i++) { SCM_ASSERT (scm_is_string(scm_list_ref(scm_exclude_attribs, scm_from_int(i))), scm_exclude_attribs, SCM_ARG2, "get-object-bounds"); exclude_attrib_list = g_list_append(exclude_attrib_list, SCM_STRING_CHARS(scm_list_ref(scm_exclude_attribs, scm_from_int(i)))); } /* Build the exclude object type list */ for (i=0; i <= scm_to_int(scm_length(scm_exclude_object_type))-1; i++) { SCM_ASSERT (scm_is_string(scm_list_ref(scm_exclude_object_type, scm_from_int(i))), scm_exclude_object_type, SCM_ARG3, "get-object-bounds"); exclude_obj_type_list = g_list_append(exclude_obj_type_list, SCM_STRING_CHARS(scm_list_ref(scm_exclude_object_type, scm_from_int(i)))); } /* Get toplevel and o_current. */ g_get_data_from_object_smob (object_smob, &toplevel, &object); SCM_ASSERT (toplevel && object, object_smob, SCM_ARG1, "get-object-bounds"); if (g_list_find_custom(exclude_attrib_list, "all", (GCompareFunc) &strcmp)) exclude_all_attribs = TRUE; custom_world_get_single_object_bounds (toplevel, object, &left, &top, &right, &bottom, exclude_attrib_list, exclude_obj_type_list); /* Free the exclude attrib_list. Don't free the nodes!! */ g_list_free(exclude_attrib_list); /* Free the exclude attrib_list. Don't free the nodes!! */ g_list_free(exclude_obj_type_list); horizontal = scm_cons (scm_from_int(left), scm_from_int(right)); vertical = scm_cons (scm_from_int(top), scm_from_int(bottom)); returned = scm_cons (horizontal, vertical); return (returned); }