コード例 #1
0
ファイル: gfec.c プロジェクト: kleopatra999/gnucash-2
/* We assume that data is actually a char**. The way we return results
 * from this function is to malloc a fresh string, and store it in
 * this pointer. It is the caller's responsibility to do something
 * smart with this freshly allocated storage. the caller can determine
 * whether there was an error by initializing the char* passed in to
 * NULL. If there is an error, the char string will not be NULL on
 * return. */
static SCM
gfec_catcher(void *data, SCM tag, SCM throw_args)
{
    SCM func;
    SCM result;
    const char *msg = NULL;

    func = scm_c_eval_string("gnc:error->string");
    if (scm_is_procedure(func))
    {
        result = scm_call_2(func, tag, throw_args);
        if (scm_is_string(result))
        {
            char * str;

            scm_dynwind_begin (0); 
            str = scm_to_locale_string (result);
            msg = g_strdup (str);
            scm_dynwind_free (str); 
            scm_dynwind_end (); 
        }
    }

    if (msg == NULL)
    {
        msg = "Error running guile function.";
    }

    *(char**)data = strdup(msg);

    return SCM_UNDEFINED;
}
コード例 #2
0
ファイル: extensions.c プロジェクト: AtomicKity/guile
static void
load_extension (SCM lib, SCM init)
{
  extension_t *head;

  scm_i_pthread_mutex_lock (&ext_lock);
  head = registered_extensions;
  scm_i_pthread_mutex_unlock (&ext_lock);

  /* Search the registry. */
  if (head != NULL)
    {
      extension_t *ext;
      char *clib, *cinit;
      int found = 0;

      scm_dynwind_begin (0);

      clib = scm_to_locale_string (lib);
      scm_dynwind_free (clib);
      cinit = scm_to_locale_string (init);
      scm_dynwind_free (cinit);

      for (ext = head; ext; ext = ext->next)
	if ((ext->lib == NULL || !strcmp (ext->lib, clib))
	    && !strcmp (ext->init, cinit))
	  {
	    ext->func (ext->data);
            found = 1;
	    break;
	  }

      scm_dynwind_end ();

      if (found)
        return;
    }

  /* Dynamically link the library. */
#if HAVE_MODULES
  scm_dynamic_call (init, scm_dynamic_link (lib));
#else
  scm_misc_error ("load-extension",
                  "extension ~S:~S not registered and dynamic-link disabled",
                  scm_list_2 (init, lib));
#endif
}
コード例 #3
0
ファイル: scheme.c プロジェクト: nizmic/nwm
static SCM scm_nwm_log(SCM msg)
{
    scm_dynwind_begin(0);
    char *c_msg = scm_to_locale_string(msg);
    scm_dynwind_free(c_msg);
    fprintf(stderr, "%s\n", c_msg);
    scm_dynwind_end();
    return SCM_UNSPECIFIED;
}
コード例 #4
0
static SCM
gdbscm_open_memory (SCM rest)
{
  const SCM keywords[] = {
    mode_keyword, start_keyword, size_keyword, SCM_BOOL_F
  };
  char *mode = NULL;
  CORE_ADDR start = 0;
  CORE_ADDR end;
  int mode_arg_pos = -1, start_arg_pos = -1, size_arg_pos = -1;
  ULONGEST size;
  SCM port;
  long mode_bits;

  gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, keywords, "#sUU", rest,
			      &mode_arg_pos, &mode,
			      &start_arg_pos, &start,
			      &size_arg_pos, &size);

  scm_dynwind_begin ((scm_t_dynwind_flags) 0);

  if (mode == NULL)
    mode = xstrdup ("r");
  scm_dynwind_free (mode);

  if (size_arg_pos > 0)
    {
      /* For now be strict about start+size overflowing.  If it becomes
	 a nuisance we can relax things later.  */
      if (start + size < start)
	{
	  gdbscm_out_of_range_error (FUNC_NAME, 0,
				scm_list_2 (gdbscm_scm_from_ulongest (start),
					    gdbscm_scm_from_ulongest (size)),
				     _("start+size overflows"));
	}
      end = start + size;
    }
  else
    end = ~(CORE_ADDR) 0;

  mode_bits = ioscm_parse_mode_bits (FUNC_NAME, mode);

  port = ioscm_open_port (memory_port_desc, mode_bits);

  ioscm_init_memory_port (port, start, end);

  scm_dynwind_end ();

  /* TODO: Set the file name as "memory-start-end"?  */
  return port;
}
コード例 #5
0
ファイル: g_rc.c プロジェクト: bert/geda-gaf
/*! \brief Verify the version of the RC file under evaluation.
 *  \par Function Description
 *
 *  Implements the Scheme function "gschem-version". Tests the version
 *  string in the argument against the version of the application
 *  itself.
 *
 *  \param [in] scm_version Scheme object containing RC file version string
 *
 *  \returns #t if the version of the RC file matches the application,
 *           else #f.
 */
SCM g_rc_gschem_version(SCM scm_version)
{
    SCM ret;
    char *version;
    SCM rc_filename;
    char *sourcefile;

    SCM_ASSERT (scm_is_string (scm_version), scm_version,
                SCM_ARG1, "gschem-version");

    scm_dynwind_begin (0);
    version = scm_to_utf8_string (scm_version);
    scm_dynwind_free (version);

    if (g_utf8_collate (g_utf8_casefold (version,-1),
                        g_utf8_casefold (PACKAGE_DATE_VERSION,-1)) != 0) {
        sourcefile = NULL;
        rc_filename = g_rc_rc_filename ();
        if (rc_filename == SCM_BOOL_F) {
            rc_filename = scm_from_utf8_string ("unknown");
        }
        sourcefile = scm_to_utf8_string (rc_filename);
        scm_dynwind_free (sourcefile);
        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] gschemrc file:\n[%s]\n"),
                version, sourcefile);
        fprintf(stderr,
                _("Please be sure that you have the latest rc file.\n"));
        ret = SCM_BOOL_F;
    } else {
        ret = SCM_BOOL_T;
    }
    scm_dynwind_end();
    return ret;
}
コード例 #6
0
ファイル: ffmpeg.c プロジェクト: wedesoft/aiscm
SCM make_ffmpeg_input(SCM scm_file_name, SCM scm_debug)
{
  SCM retval;
  struct ffmpeg_t *self;
  scm_dynwind_begin(0);
  const char *file_name = scm_to_locale_string(scm_file_name);
  scm_dynwind_free(file_name);
  self = (struct ffmpeg_t *)scm_gc_calloc(sizeof(struct ffmpeg_t), "ffmpeg");
  self->video_stream_idx = -1;
  self->audio_stream_idx = -1;
  SCM_NEWSMOB(retval, ffmpeg_tag, self);

  int err;
  err = avformat_open_input(&self->fmt_ctx, file_name, NULL, NULL);
  if (err < 0) {
    ffmpeg_destroy(retval);
    scm_misc_error("make-ffmpeg-input", "Error opening file '~a': ~a", scm_list_2(scm_file_name, get_error_text(err)));
  };

  err = avformat_find_stream_info(self->fmt_ctx, NULL);
  if (err < 0) {
    ffmpeg_destroy(retval);
    scm_misc_error("make-ffmpeg-input", "No stream information in file '~a': ~a", scm_list_2(scm_file_name, get_error_text(err)));
  };

  // TODO: only open desired streams
  // Open video stream
  self->video_stream_idx = av_find_best_stream(self->fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
  if (self->video_stream_idx >= 0)
    self->video_codec_ctx = open_decoder(retval, scm_file_name, video_stream(self), "video");

  // Open audio stream
  self->audio_stream_idx = av_find_best_stream(self->fmt_ctx, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0);
  if (self->audio_stream_idx >= 0)
    self->audio_codec_ctx = open_decoder(retval, scm_file_name, audio_stream(self), "audio");

  // Print debug information
  if (scm_is_true(scm_debug)) av_dump_format(self->fmt_ctx, 0, file_name, 0);

  // Allocate input frames
  self->video_target_frame = allocate_frame(retval);
  self->audio_target_frame = allocate_frame(retval);

  // Initialise data packet
  av_init_packet(&self->pkt);
  self->pkt.data = NULL;
  self->pkt.size = 0;

  scm_dynwind_end();
  return retval;
}
コード例 #7
0
ファイル: guile-util.c プロジェクト: kleopatra999/gnucash-2
gchar *gnc_scm_to_locale_string(SCM scm_string)
{
    gchar* s;
    char * str;

    scm_dynwind_begin (0); 
    str = scm_to_locale_string(scm_string);

    /* prevent memory leaks in scm_to_locale_string() per guile manual; see 'http://www.gnu.org/software/guile/manual/html_node/Dynamic-Wind.html#Dynamic-Wind' */
    s = g_strdup(str);
    scm_dynwind_free (str); 
    scm_dynwind_end (); 
    return s;
}
コード例 #8
0
ファイル: path_fix.c プロジェクト: NalaGinrut/ragnarok
SCM scm_mmr_path_fix(SCM target)
#define FUNC_NAME "path-fix"
{
  char *path = NULL;
  char *fixed = NULL; // fixed path
  char *tmp = NULL;
  int path_len = 0;
  int bi = 0;
  int pi = 0;
  SCM ret;
  
  SCM_VALIDATE_STRING(1 ,target);

  scm_dynwind_begin(0);
  
  path = scm_to_locale_string(target);
  scm_dynwind_free(path);

  if(!strstr(path ,"/.."))
    {
      // no relative path
      ret = target;
      goto end;
    }

  path_len = strlen(path);
  path_len = path_len>MAX_PATH_LEN? MAX_PATH_LEN : path_len;
  fixed = (char *)malloc(path_len+1);
  fixed[0] = '\n'; // sentinal

  while(get_dir(path ,fixed+1 ,&pi ,&bi))
    {}

  /* NOTE: The result won't contain '/' at the end,
   * because we'll append *path '/' filename* finally.
   */

  tmp = fix_prefix(fixed+1);
  ret = scm_from_locale_string(tmp);

  free(fixed);
  fixed = NULL;
  tmp = NULL;

 end:
  scm_dynwind_end();
  return ret;
}
コード例 #9
0
ファイル: scheme.c プロジェクト: nizmic/nwm
static SCM scm_bind_key(SCM mod_mask, SCM key, SCM proc)
{
    xcb_keysym_t keysym;
    if (scm_is_true(scm_number_p(key)))
        keysym = scm_to_uint32(key);
    else if (scm_is_true(scm_string_p(key))) {
        scm_dynwind_begin(0);
        char *c_key = scm_to_locale_string(key);
        scm_dynwind_free(c_key);
        keysym = get_keysym(c_key);
        scm_dynwind_end();
    }
    else
        return SCM_UNSPECIFIED;
    bind_key(scm_to_uint16(mod_mask), keysym, proc);
    return SCM_UNSPECIFIED;
}
コード例 #10
0
ファイル: g_rc.c プロジェクト: igutekunst/geda-gaf
/*! \brief
 *  \par Function Description
 *
 *  \param [in] path 
 *  \param [in] name Optional descriptive name for library directory.
 *  \return SCM_BOOL_T on success, SCM_BOOL_F otherwise.
 */
SCM g_rc_component_library(SCM path, SCM name)
{
  gchar *string;
  char *temp;
  char *namestr = NULL;

  SCM_ASSERT (scm_is_string (path), path,
              SCM_ARG1, "component-library");

  scm_dynwind_begin (0);
  if (name != SCM_UNDEFINED) {
    SCM_ASSERT (scm_is_string (name), name,
		SCM_ARG2, "component-library");
    namestr = scm_to_utf8_string (name);
    scm_dynwind_free(namestr);
  }

  /* take care of any shell variables */
  temp = scm_to_utf8_string (path);
  string = s_expand_env_variables (temp);
  scm_dynwind_unwind_handler (g_free, string, SCM_F_WIND_EXPLICITLY);
  free (temp);

  /* invalid path? */
  if (!g_file_test (string, G_FILE_TEST_IS_DIR)) {
    fprintf(stderr,
            "Invalid path [%s] passed to component-library\n",
            string);
    scm_dynwind_end();
    return SCM_BOOL_F;
  }

  if (g_path_is_absolute (string)) {
    s_clib_add_directory (string, namestr);
  } else {
    gchar *cwd = g_get_current_dir ();
    gchar *temp;
    temp = g_build_filename (cwd, string, NULL);
    s_clib_add_directory (temp, namestr);
    g_free(temp);
    g_free(cwd);
  }

  scm_dynwind_end();
  return SCM_BOOL_T;
}
コード例 #11
0
SCM scm_mmr_create_this_path(SCM path ,SCM mode)
#define FUNC_NAME "create-this-path"
{
  char *p = NULL;
  char *b = NULL;
  char *buf = NULL;
  SCM ret = SCM_BOOL_F;
  int m = 0777;
  int len = 0;
  int n = 0;
  
  SCM_VALIDATE_STRING(1 ,path);

  if(!SCM_UNBNDP(mode))
    {
      SCM_VALIDATE_NUMBER(2 ,mode);
      m = scm_to_int(mode);
    }

  scm_dynwind_begin(0);
  
  p = scm_to_locale_string(path);
  scm_dynwind_free(p);
  
  len = strlen(p);
  buf = (char*)malloc(len+1); // Don't forget +1 for '\0'
  n = get_path_levels(p ,len);
  
  while(n >= 0)
    {
      int l = 0;
      b = get_parent_path(p ,&n ,len);
      l = b-p;
      memcpy(buf ,b ,l);
      buf[l+1] = '\0';
      do_create(buf ,len);
    }

  free(buf);
  buf = NULL;

  scm_dynwind_end();
  
  return ret; 
}
コード例 #12
0
ファイル: scheme.c プロジェクト: nizmic/nwm
static SCM scm_launch_program(SCM prog)
{
    scm_dynwind_begin(0);
    char *c_path = scm_to_locale_string(scm_car(prog));
    scm_dynwind_free(c_path);
    fprintf(stderr, "launching program %s\n", c_path);
    pid_t pid = fork();
    if (pid == 0) {
      if (scm_is_false(scm_execlp(scm_car(prog), prog))) {
            perror("execl failed");
            exit(2);
        }
    }
    else {
        fprintf(stderr, "launched %s as pid %d\n", c_path, pid);
    }
    scm_dynwind_end();
    return SCM_UNSPECIFIED;
}
コード例 #13
0
ファイル: check_perms.c プロジェクト: NalaGinrut/ragnarok
SCM scm_mmr_check_file_perms(SCM target ,SCM perms)
#define FUNC_NAME "check-file-perms"
{
  int p = 0;
  char *filename = NULL;
  SCM ret = SCM_BOOL_F;
  struct stat sb;
  int mode = 0;
  int pa = 0 ,pu = 0 ,pr = 0;
    
  SCM_VALIDATE_STRING(1 ,target);
  SCM_VALIDATE_NUMBER(2 ,perms);

  scm_dynwind_begin(0);
  errno = 0;

  p = scm_to_int(perms);
  filename = scm_to_locale_string(target);
  scm_dynwind_free(filename);
  
  if(stat(filename ,&sb))
    {
      goto end;
    }

  mode = sb.st_mode;
  pa = PERMS_A & p;
  pu = PERMS_U & p;
  pr = PERMS_R & p;
  
  if((pa == (mode & pa)) ||
     (pu == (mode & pu)) ||
     (pr == (mode & pr)))
    {
      ret = SCM_BOOL_T;
    }
  
 end:
  scm_dynwind_end();
  return ret;
}
コード例 #14
0
/************************************************************
 *               Style Sheet Selection Dialog               *
 ************************************************************/
static void
gnc_style_sheet_select_dialog_add_one(StyleSheetDialog * ss,
                                      SCM sheet_info,
                                      gboolean select)
{
    SCM get_name, scm_name;
    const gchar *c_name;
    char * str;
    GtkTreeSelection *selection;
    GtkTreeIter iter;

    get_name = scm_c_eval_string("gnc:html-style-sheet-name");
    scm_name = scm_call_1(get_name, sheet_info);
    scm_dynwind_begin (0); 
    str = scm_to_locale_string (scm_name);
    c_name = g_strdup (str);
    scm_dynwind_free (str); 
    scm_dynwind_end (); 
    if (!c_name)
        return;

    /* add the column name */
    scm_gc_protect_object(sheet_info);
    gtk_list_store_append (ss->list_store, &iter);
    gtk_list_store_set (ss->list_store, &iter,
                        /* Translate the displayed name */
                        COLUMN_NAME, _(c_name),
                        COLUMN_STYLESHEET, sheet_info,
                        -1);
    /* The translation of the name fortunately doesn't affect the
     * lookup because that is done through the sheet_info argument. */

    if (select)
    {
        selection = gtk_tree_view_get_selection (ss->list_view);
        gtk_tree_selection_select_iter (selection, &iter);
    }
}
コード例 #15
0
ファイル: g_netlist.c プロジェクト: blueantst/geda-gaf
/*  (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");

  scm_dynwind_begin (0);

  wanted_uref = scm_to_utf8_string (scm_uref);
  scm_dynwind_free (wanted_uref);

  wanted_pin = scm_to_utf8_string (scm_pin);
  scm_dynwind_free (wanted_pin);

  nl_current = netlist_head;

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

    if (!nl_current->component_uref) continue;
    if (strcmp (nl_current->component_uref, wanted_uref) != 0) continue;

    for (pl_current = nl_current->cpins;
         pl_current != NULL;
         pl_current = pl_current->next) {

      if (!pl_current->pin_number) continue;
      if (strcmp(pl_current->pin_number, wanted_pin) != 0) continue;

      if (pl_current->net_name) {
        net_name = pl_current->net_name;
      }

      for (n_current = pl_current->nets;
           n_current != NULL;
           n_current = n_current->next) {

        if (!n_current->connected_to) continue;

        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_from_utf8_string (uref),
                               scm_from_utf8_string (pin),
                               SCM_UNDEFINED);

        pinslist = scm_cons (pairlist, pinslist);

        g_free(uref);
        g_free(pin);
      }
    }
  }

  if (net_name != NULL) {
    outerlist = scm_cons (scm_from_utf8_string (net_name), pinslist);
  } else {
    outerlist = scm_cons (scm_from_utf8_string ("ERROR_INVALID_PIN"),
                          outerlist);
    fprintf(stderr, _("Invalid refdes ('%s') and pin ('%s') passed to get-nets\n"),
            wanted_uref, wanted_pin);
  }

  scm_dynwind_end ();

  return (outerlist);
}
コード例 #16
0
static SCM
gnc_style_sheet_new (StyleSheetDialog * ssd)
{
    SCM              make_ss   = scm_c_eval_string("gnc:make-html-style-sheet");
    SCM              templates = scm_c_eval_string("(gnc:get-html-templates)");
    SCM              t_name = scm_c_eval_string("gnc:html-style-sheet-template-name");
    SCM              new_ss = SCM_BOOL_F;
    GtkWidget        * template_combo;
    GtkTreeModel     * template_model;
    GtkWidget        * name_entry;
    gint             dialog_retval;
    GList *template_names = NULL;

    /* get the new name for the style sheet */
    GladeXML *xml = gnc_glade_xml_new ("report.glade",
                                       "New Style Sheet Dialog");
    GtkWidget * dlg = glade_xml_get_widget (xml, "New Style Sheet Dialog");
    template_combo = glade_xml_get_widget (xml, "template_combobox");
    name_entry     = glade_xml_get_widget (xml, "name_entry");

    g_assert(ssd);

    /* Erase the initial dummy entry. */
    template_model = gtk_combo_box_get_model(GTK_COMBO_BOX(template_combo));
    gtk_list_store_clear(GTK_LIST_STORE(template_model));

    /* put in the list of style sheet type names */
    for (; !scm_is_null(templates); templates = SCM_CDR(templates))
    {
        char * str;
        const char* orig_name;

        SCM t = SCM_CAR(templates);
        scm_dynwind_begin (0); 
        str = scm_to_locale_string (scm_call_1(t_name, t));
        orig_name = g_strdup (str);
        scm_dynwind_free (str); 
        scm_dynwind_end (); 

        /* Store the untranslated names for lookup later */
        template_names = g_list_prepend (template_names, (gpointer)orig_name);

        /* The displayed name should be translated */
        gtk_combo_box_prepend_text(GTK_COMBO_BOX(template_combo),
                                   _(orig_name));
    }
    gtk_combo_box_set_active(GTK_COMBO_BOX(template_combo), 0);

    /* get the name */
    gtk_window_set_transient_for (GTK_WINDOW(dlg), GTK_WINDOW(ssd->toplevel));
    dialog_retval = gtk_dialog_run(GTK_DIALOG(dlg));

    if (dialog_retval == GTK_RESPONSE_OK)
    {
        gint choice = gtk_combo_box_get_active (GTK_COMBO_BOX(template_combo));
        const char *template_str = g_list_nth_data (template_names, choice);
        const char *name_str     = gtk_entry_get_text(GTK_ENTRY(name_entry));
        if (name_str && strlen(name_str) == 0)
        {
            /* If the name is empty, we display an error dialog but
             * refuse to create the new style sheet. */
            gnc_error_dialog (ssd->toplevel, "%s", _("You must provide a name for the new style sheet."));
            name_str = NULL;
        }
        if (template_str && name_str)
        {
            new_ss = scm_call_2(make_ss,
                                scm_makfrom0str(template_str),
                                scm_makfrom0str(name_str));
        }
    }

    g_list_free (template_names);
    gtk_widget_destroy(dlg);
    return(new_ss);
}
コード例 #17
0
static void
update_display_lists(gnc_column_view_edit * view)
{
    SCM   get_names = scm_c_eval_string("gnc:all-report-template-names");
    SCM   template_menu_name = scm_c_eval_string("gnc:report-template-menu-name/report-guid");
    SCM   report_menu_name = scm_c_eval_string("gnc:report-menu-name");
    SCM   names = scm_call_0(get_names);
    SCM   contents =
        gnc_option_db_lookup_option(view->odb, "__general", "report-list",
                                    SCM_BOOL_F);
    SCM   this_report;
    SCM   selection;
    const gchar *name;
    int   row, i, id;
    GtkListStore *store;
    GtkTreeIter iter;
    GtkTreePath *path;
    GtkTreeSelection *tree_selection;


    /* Update the list of available reports (left selection box). */
    row = view->available_selected;

    if (scm_is_list(view->available_list) && !scm_is_null (view->available_list))
    {
        row = MIN (row, scm_ilength (view->available_list) - 1);
        selection = scm_list_ref (view->available_list, scm_int2num (row));
    }
    else
    {
        selection = SCM_UNDEFINED;
    }

    scm_gc_unprotect_object(view->available_list);
    view->available_list = names;
    scm_gc_protect_object(view->available_list);

    store = GTK_LIST_STORE(gtk_tree_view_get_model(view->available));
    gtk_list_store_clear(store);

    if (scm_is_list(names))
    {
        for (i = 0; !scm_is_null(names); names = SCM_CDR(names), i++)
        {
            char * str;

            if (scm_is_equal (SCM_CAR(names), selection))
                row = i;
            scm_dynwind_begin (0); 
            str = scm_to_locale_string (scm_call_2(template_menu_name, SCM_CAR(names),
                                          SCM_BOOL_F));
            name = _(g_strdup (str));
            scm_dynwind_free (str); 
            scm_dynwind_end (); 
            gtk_list_store_append(store, &iter);
            gtk_list_store_set(store, &iter,
                               AVAILABLE_COL_NAME, name,
                               AVAILABLE_COL_ROW, i,
                               -1);
        }

    }

    tree_selection = gtk_tree_view_get_selection(view->available);
    path = gtk_tree_path_new_from_indices(row, -1);
    gtk_tree_selection_select_path(tree_selection, path);
    gtk_tree_path_free(path);


    /* Update the list of selected reports (right selection box). */
    row = view->contents_selected;

    if (scm_is_list(view->contents_list) && !scm_is_null (view->contents_list))
    {
        row = MIN (row, scm_ilength (view->contents_list) - 1);
        selection = scm_list_ref (view->contents_list, scm_int2num (row));
    }
    else
    {
        selection = SCM_UNDEFINED;
    }

    scm_gc_unprotect_object(view->contents_list);
    view->contents_list = contents;
    scm_gc_protect_object(view->contents_list);

    store = GTK_LIST_STORE(gtk_tree_view_get_model(view->contents));
    gtk_list_store_clear(store);
    if (scm_is_list(contents))
    {
        for (i = 0; !scm_is_null(contents); contents = SCM_CDR(contents), i++)
        {
            char * str;

            if (scm_is_equal (SCM_CAR(contents), selection))
                row = i;

            id = scm_num2int(SCM_CAAR(contents), SCM_ARG1, G_STRFUNC);
            this_report = gnc_report_find(id);
            scm_dynwind_begin (0); 
            str = scm_to_locale_string (scm_call_1(report_menu_name, this_report));
            name = _(g_strdup (str));
            scm_dynwind_free (str); 
            scm_dynwind_end (); 

            gtk_list_store_append(store, &iter);
            gtk_list_store_set
            (store, &iter,
             CONTENTS_COL_NAME, name,
             CONTENTS_COL_ROW, i,
             CONTENTS_COL_REPORT_COLS, scm_num2int(SCM_CADR(SCM_CAR(contents)),
                                                   SCM_ARG1, G_STRFUNC),
             CONTENTS_COL_REPORT_ROWS, scm_num2int(SCM_CADDR(SCM_CAR(contents)),
                                                   SCM_ARG1, G_STRFUNC),
             -1);
        }
    }

    tree_selection = gtk_tree_view_get_selection(view->contents);
    path = gtk_tree_path_new_from_indices(row, -1);
    gtk_tree_selection_select_path(tree_selection, path);
    //  gtk_tree_view_scroll_to_cell(view->contents, path, NULL, TRUE, 0.5, 0.0);
    gtk_tree_path_free(path);
}
コード例 #18
0
ファイル: scandir.c プロジェクト: NalaGinrut/ragnarok
  /* This scandir is a shrink version of the glibc version.
   * I believe we don't need versionsort or any other sort in the ragnarok.
   */
SCM scm_mmr_scandir(SCM dir, SCM filter)
#define FUNC_NAME "scandir"
{
    struct dirent_or_dirent64 **rdent;
    int has_filter = 0;
    int n = 0 ,i = 0;
    char *tmp_ptr = NULL;
    SCM flag;
    SCM ret = SCM_EOL;
    SCM *prev;
    SCM str;

    SCM_VALIDATE_STRING(1, dir);

    if(!SCM_UNBNDP(filter))
	{
	    SCM_ASSERT(scm_is_true(scm_procedure_p(filter)),
		       filter ,SCM_ARG2 ,FUNC_NAME);
	    has_filter = 1;
	}

    scm_dynwind_begin(0);
    errno = 0;

    tmp_ptr = scm_to_locale_string(dir);
    scm_dynwind_free(tmp_ptr);

    n = scandir_or_scandir64(tmp_ptr,
			     &rdent, NULL,
			     alphasort_or_alphasort64);

    if(has_filter)
	{
	    for(prev = &ret;i<n;i++)
		{
		    str = rdent[i]?
			scm_from_locale_stringn(rdent[i]->d_name ,NAMLEN(rdent[i]))
			:
			SCM_EOF_VAL;
		    flag = scm_call_1(filter ,str);
		    free(rdent[i]);

		    if(scm_is_true(flag))
			{
			    *prev = scm_cons(str ,SCM_EOL);
			    prev = SCM_CDRLOC(*prev);
			}
		}
	}
    else
	{
	    for(prev = &ret;i<n;i++)
		{
		    str = rdent[i]?
			scm_from_locale_stringn(rdent[i]->d_name ,NAMLEN(rdent[i]))
			:
			SCM_EOF_VAL;
		    *prev = scm_cons(str ,SCM_EOL);
		    prev = SCM_CDRLOC(*prev);
		    free(rdent[i]);
		}
	}

    if(errno != 0)
	SCM_SYSERROR;

    scm_dynwind_end();

    free(rdent);
    
    return ret;
}
コード例 #19
0
/* returns g_malloc'd path */
static void
gnc_extension_path (SCM extension, char **fullpath)
{
    SCM path;
    gchar **strings;
    gint i;
    gint num_strings;

    initialize_getters();

    path = gnc_guile_call1_to_list(getters.path, extension);
    if ((path == SCM_UNDEFINED) || scm_is_null(path))
    {
        *fullpath = g_strdup("");
        return;
    }

    num_strings = scm_ilength(path) + 2;
    strings = g_new0(gchar *, num_strings);
    strings[0] = "/menubar";

    i = 1;
    while (!scm_is_null(path))
    {
        SCM item;

        item = SCM_CAR(path);
        path = SCM_CDR(path);

        if (scm_is_string(item))
        {
            char* s;

            scm_dynwind_begin (0); 
            s = scm_to_locale_string(item);

            if (i == 1)
            {

                strings[i] = g_strdup(s);
            }
            else
            {
                strings[i] = g_strdup(gettext(s));
            }
            scm_dynwind_free (s); 
            scm_dynwind_end (); 
        }
        else
        {
            g_free(strings);

            PERR("not a string");

            *fullpath = g_strdup("");
            return;
        }

        i++;
    }

    *fullpath = g_strjoinv("/", strings);

    for (i = 1; i < num_strings; i++)
    {
        if (strings[i] != NULL)
        {
            g_free(strings[i]);
        }
    }

    g_free(strings);
}
コード例 #20
0
ファイル: g_netlist.c プロジェクト: blueantst/geda-gaf
/* 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:graphical-objs-in-net-with-attrib-get-attrib");

    SCM_ASSERT(scm_is_string (scm_wanted_attribute),
	       scm_wanted_attribute, SCM_ARG3, 
	       "gnetlist:graphical-objs-in-net-with-attrib-get-attrib");

    SCM_ASSERT(scm_is_string (scm_has_attribute),
	       scm_has_attribute, SCM_ARG2, 
	       "gnetlist:graphical-objs-in-net-with-attrib-get-attrib");

    scm_dynwind_begin (0);

    wanted_net_name = scm_to_utf8_string (scm_netname);
    if (wanted_net_name == NULL) {
	return list;
    }

    scm_dynwind_free (wanted_net_name);

    wanted_attrib = scm_to_utf8_string (scm_wanted_attribute);
    scm_dynwind_free (wanted_attrib);

    has_attrib = scm_to_utf8_string (scm_has_attribute);
    scm_dynwind_free (has_attrib);

    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_string_get_name_value (has_attrib, &has_attrib_name,
					       &has_attrib_value) != 0) {
		    attrib_value = 
		      o_attrib_search_object_attribs_by_name (nl_current->object_ptr,
		                                              has_attrib_name, 0);
		    
		    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_object_attribs_by_name (nl_current->object_ptr,
		                                                wanted_attrib, 0);
		      if (attrib_value) {
			list = scm_cons (scm_from_utf8_string (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;
    }

    scm_dynwind_end ();
    return list;
}
コード例 #21
0
ファイル: g_netlist.c プロジェクト: blueantst/geda-gaf
/* 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-attribute-by-pinnumber");

    SCM_ASSERT(scm_is_string (scm_pin),
	       scm_pin, SCM_ARG2, "gnetlist:get-attribute-by-pinnumber");

    SCM_ASSERT(scm_is_string (scm_wanted_attrib),
	       scm_wanted_attrib, SCM_ARG3, "gnetlist:get-attribute-by-pinnumber");

    scm_dynwind_begin (0);

    uref = scm_to_utf8_string (scm_uref);
    scm_dynwind_free (uref);

    pin = scm_to_utf8_string (scm_pin);
    scm_dynwind_free (pin);

    wanted_attrib = scm_to_utf8_string (scm_wanted_attrib);
    scm_dynwind_free (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_find_pin_by_attribute (nl_current->object_ptr,
		                                     "pinnumber", pin);

		if (pin_object) {

		    /* only look for the first occurance of wanted_attrib */
		    return_value =
		      o_attrib_search_object_attribs_by_name (pin_object,
		                                              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;
    }

    scm_dynwind_end ();

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

    return (scm_return_value);
}
コード例 #22
0
ファイル: g_netlist.c プロジェクト: blueantst/geda-gaf
/* 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 *return_value = NULL;
  OBJECT *o_pin_object;

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

  SCM_ASSERT(scm_is_string (scm_pinseq),
             scm_pinseq, SCM_ARG2, "gnetlist:get-attribute-by-pinseq");


  SCM_ASSERT(scm_is_string (scm_wanted_attrib),
             scm_wanted_attrib, SCM_ARG3, "gnetlist:get-attribute-by-pinseq");

  scm_dynwind_begin (0);

  uref = scm_to_utf8_string (scm_uref);
  scm_dynwind_free (uref);

  pinseq = scm_to_utf8_string (scm_pinseq);
  scm_dynwind_free (pinseq);

  wanted_attrib = scm_to_utf8_string (scm_wanted_attrib);
  scm_dynwind_free (wanted_attrib);

#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) {

        o_pin_object = o_complex_find_pin_by_attribute (nl_current->object_ptr,
                                                        "pinseq", pinseq);

        if (o_pin_object) {
          return_value =
            o_attrib_search_object_attribs_by_name (o_pin_object,
                                                    wanted_attrib, 0);
          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;
  }

  scm_dynwind_end ();

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

#if DEBUG
  printf("gnetlist:g_netlist.c:g_get_attribute_by_pinseq -- ");
  printf("return_value: %s\n", return_value);
#endif

  return (scm_return_value);
}
コード例 #23
0
ファイル: ffmpeg.c プロジェクト: wedesoft/aiscm
SCM make_ffmpeg_output(SCM scm_file_name,
                       SCM scm_format_name,
                       SCM scm_video_parameters,
                       SCM scm_have_video,
                       SCM scm_audio_parameters,
                       SCM scm_have_audio,
                       SCM scm_debug)
{
  SCM retval;
  struct ffmpeg_t *self;
  scm_dynwind_begin(0);
  const char *file_name = scm_to_locale_string(scm_file_name);
  scm_dynwind_free(file_name);
  self = (struct ffmpeg_t *)scm_gc_calloc(sizeof(struct ffmpeg_t), "ffmpeg");
  self->video_stream_idx = -1;
  self->audio_stream_idx = -1;
  SCM_NEWSMOB(retval, ffmpeg_tag, self);

  int err;
  const char *format_name = NULL;
  if (!scm_is_false(scm_format_name)) {
    format_name = scm_to_locale_string(scm_symbol_to_string(scm_format_name));
    scm_dynwind_free(format_name);
  };
#ifdef HAVE_AVFORMAT_ALLOC_OUTPUT_CONTEXT2
  err = avformat_alloc_output_context2(&self->fmt_ctx, NULL, format_name, file_name);
  if (!self->fmt_ctx) {
    ffmpeg_destroy(retval);
    scm_misc_error("make-ffmpeg-output", "Error initializing output format for file '~a': ~a",
                   scm_list_2(scm_file_name, get_error_text(err)));
  };
#else
  AVOutputFormat *format;
  if (format_name)
    format = av_guess_format(format_name, NULL, NULL);
  else
    format = av_guess_format(NULL, file_name, NULL);
  if (!format) {
    ffmpeg_destroy(retval);
    scm_misc_error("make-ffmpeg-output", "Unable to determine file format for file '~a'",
                   scm_list_1(scm_file_name));
  };
  self->fmt_ctx = avformat_alloc_context();
  if (!self->fmt_ctx) {
    ffmpeg_destroy(retval);
    scm_misc_error("make-ffmpeg-output", "Error initializing output format for file '~a'",
                   scm_list_1(scm_file_name));
  };
  self->fmt_ctx->oformat = format;
  strncpy(self->fmt_ctx->filename, file_name, sizeof(self->fmt_ctx->filename));
#endif

  char have_video = scm_is_true(scm_have_video);
  if (have_video) {
    // Open codec and video stream
    enum AVCodecID video_codec_id = self->fmt_ctx->oformat->video_codec;
    AVCodec *video_encoder = find_encoder(retval, video_codec_id, "video");
    AVStream *video_stream = open_output_stream(retval, video_encoder, &self->video_stream_idx, "video", scm_file_name);

    // Get video parameters
    SCM scm_shape          = scm_car(scm_video_parameters);
    SCM scm_frame_rate     = scm_cadr(scm_video_parameters);
    SCM scm_video_bit_rate = scm_caddr(scm_video_parameters);
    SCM scm_aspect_ratio   = scm_cadddr(scm_video_parameters);

    // Configure the output video codec
    self->video_codec_ctx =
      configure_output_video_codec(video_stream, video_codec_id, scm_video_bit_rate, scm_shape, scm_frame_rate, scm_aspect_ratio);

    // Some formats want stream headers to be separate.
    if (self->fmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
        self->video_codec_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;

    // Open output video codec
    open_codec(retval, self->video_codec_ctx, video_encoder, "video", scm_file_name);

    // Allocate frame
    self->video_target_frame = allocate_output_video_frame(retval, self->video_codec_ctx);
  };

  char have_audio = scm_is_true(scm_have_audio);
  if (have_audio) {
    // Open audio codec and stream
    enum AVCodecID audio_codec_id = self->fmt_ctx->oformat->audio_codec;
    AVCodec *audio_encoder = find_encoder(retval, audio_codec_id, "audio");
    AVStream *audio_stream = open_output_stream(retval, audio_encoder, &self->audio_stream_idx, "audio", scm_file_name);

    // Get audio parameters
    SCM scm_select_rate    = scm_car(scm_audio_parameters);
    SCM scm_channels       = scm_cadr(scm_audio_parameters);
    SCM scm_audio_bit_rate = scm_caddr(scm_audio_parameters);
    SCM scm_select_format  = scm_cadddr(scm_audio_parameters);

    // Configure the output audio codec
    self->audio_codec_ctx =
      configure_output_audio_codec(retval, audio_stream, audio_codec_id,
                                   scm_select_rate, scm_channels, scm_audio_bit_rate, scm_select_format);

    // Some formats want stream headers to be separate.
    if (self->fmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
        self->audio_codec_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;

    // Open output audio codec
    open_codec(retval, self->audio_codec_ctx, audio_encoder, "audio", scm_file_name);

    // Allocate audio frame
    self->audio_target_frame =
      allocate_output_audio_frame(retval, self->audio_codec_ctx, self->audio_codec_ctx->sample_fmt);
    self->audio_packed_frame =
      allocate_output_audio_frame(retval, self->audio_codec_ctx, av_get_packed_sample_fmt(self->audio_codec_ctx->sample_fmt));

    // Initialise audio buffer
    ringbuffer_init(&self->audio_buffer, 1024);
  };

  if (scm_is_true(scm_debug)) av_dump_format(self->fmt_ctx, 0, file_name, 1);

  // Open the output file if needed
  if (!(self->fmt_ctx->oformat->flags & AVFMT_NOFILE)) {
    int err = avio_open(&self->fmt_ctx->pb, file_name, AVIO_FLAG_WRITE);
    if (err < 0) {
      ffmpeg_destroy(retval);
      scm_misc_error("make-ffmpeg-output", "Could not open '~a': ~a",
                     scm_list_2(scm_file_name, get_error_text(err)));
    }
    self->output_file = 1;
  }

  // Write video file header
  err = avformat_write_header(self->fmt_ctx, NULL);
  if (err < 0) {
    ffmpeg_destroy(retval);
    scm_misc_error("make-ffmpeg-output", "Error writing header of video '~a': ~a",
                   scm_list_2(scm_file_name, get_error_text(err)));
  };
  self->header_written = 1;

  scm_dynwind_end();
  return retval;
}