コード例 #1
0
ファイル: pvs.c プロジェクト: jff/mathspad
static void handle_pvs_err(unsigned char *buffer)
{
  /* buffer contains "file&dir&message&error&place" */
  if (fields(buffer)==5) {
    int sl,sc;
    char fullname[1024];
    char errormessage[10000];
    int errpos=0;
    FILE *f;
    if (pvs_open_pvs_files) {
      strcpy(fullname,field[1]);
      strcat(fullname,field[0]);
      strcat(fullname,".pvs");
      sscanf(field[4], "%i %i", &sl, &sc);
      open_temporary_file(fullname, fullname, 1, sl);
    }
    sprintf((char*)errormessage, "Error in '%s' on line %i, column %i.\n"
	    "%s\n"
	    "\n", field[0], sl, sc, field[2]);
    errpos=strlen(errormessage);
    f=fopen(field[3],"r");
    if (f) {
      int t;
      t=fread(errormessage+errpos, 1, 10000-errpos-1, f);
      errormessage[errpos+t]=0;
      fclose(f);
    }
    message(MP_CLICKREMARK, LocaletoUstr((unsigned char*)errormessage));
    unlink(field[3]);
  }
}
コード例 #2
0
ファイル: pvs.c プロジェクト: jff/mathspad
static void handle_pvs_buf(unsigned char *buffer)
{
  /* buffer contains "bufname&file&display&read_only" */
  int nf = fields(buffer);
  /* PVS version 2.1 used 4 fields, PVS version 2.2 uses 5 fields */
  if ((nf==4 || nf==5) && field[1]!=NILstr) {
    if (pvs_open_pvs_files) {
      open_temporary_file(field[0], field[1], field[2]!=NILstr,0);
    }
    unlink(field[1]);
  }
}
コード例 #3
0
ファイル: pvs.c プロジェクト: jff/mathspad
static void handle_pvs_loc(unsigned char *buffer)
{
  /* buffer contains "dir&file&place" */
  if (fields(buffer)==3 && pvs_open_pvs_files) {
    int sl,sc,el,ec;
    char filename[1024];
    if (field[0]!=NILstr) {
      strcpy(filename, field[0]);
    } else {
      filename[0]=0;
    }
    strcat(filename,field[1]);
    parse_position(field[2],sl,sc,el,ec);
    open_temporary_file(filename, filename, 0,sl);
  }
}
コード例 #4
0
ファイル: groups.c プロジェクト: cran/rcqp
Group *
ComputeGroupExternally(Group *group)
{
  int i;
  int size = group->my_corpus->size;
  int cutoff_freq = group->cutoff_frequency;

  char temporary_name[TEMP_FILENAME_BUFSIZE];
  FILE *fd;
  FILE *pipe;
  char sort_call[CL_MAX_LINE_LENGTH];

  /* ---------------------------------------------------------------------- */

  if ((fd = open_temporary_file(temporary_name)) == NULL) {
    perror("Error while opening temporary file");
    cqpmessage(Warning, "Can't open temporary file");
    return group;
  }

  for (i = 0; i < size; i++) {
    fprintf(fd, "%d %d\n", get_group_id(group, i, 0), get_group_id(group, i, 1)); /* (source ID, target ID) */
  }
  fclose(fd);

  /* construct sort call */
  sprintf(sort_call, ExternalGroupingCommand, temporary_name);
  if (GROUP_DEBUG)
   Rprintf( "Running grouping sort: \n\t%s\n",
            sort_call);
  if ((pipe = popen(sort_call, "r")) == NULL) {
    perror("Failure opening grouping pipe");
    cqpmessage(Warning, "Can't open grouping pipe:\n%s\n"
               "Disable external grouping by\n"
               "  set UseExternalGrouping off;", 
               sort_call);
  }
  else {
    int freq, p1, p2, tokens;
#define GROUP_REALLOC 16

    while ((tokens = fscanf(pipe, "%d%d%d", &freq, &p1, &p2)) == 3) {
      if (freq > cutoff_freq) {
        if ((group->nr_cells % GROUP_REALLOC) == 0) {
          if (group->count_cells == NULL) {
            group->count_cells = 
              (ID_Count_Mapping *)cl_malloc(GROUP_REALLOC *
                                         sizeof(ID_Count_Mapping));
          }
          else {
            group->count_cells = 
              (ID_Count_Mapping *)cl_realloc(group->count_cells,
                                          (group->nr_cells + GROUP_REALLOC) *
                                          sizeof(ID_Count_Mapping));
          }
          assert(group->count_cells);
        }

        group->count_cells[group->nr_cells].s = p1;
        group->count_cells[group->nr_cells].t = p2;
        group->count_cells[group->nr_cells].freq = freq;

        group->nr_cells = group->nr_cells + 1;
      }
    }

    if (tokens != EOF) {
     Rprintf( "Warning: could not reach EOF of temporary file!\n");
    }

    pclose(pipe);
  }

  if (GROUP_DEBUG) {
   Rprintf( "Keeping temporary file %s -- delete manually\n",
            temporary_name);
  }
  else if (unlink(temporary_name) != 0) {
    perror(temporary_name);
   Rprintf( "Can't remove temporary file %s -- \n\tI will continue, "
            "but you should remove that file.\n", temporary_name);
  }
  
  return group;
}
コード例 #5
0
int32_t
ppb_url_loader_follow_redirect(PP_Resource loader, struct PP_CompletionCallback callback)
{
    struct pp_url_loader_s *ul = pp_resource_acquire(loader, PP_RESOURCE_URL_LOADER);
    if (!ul) {
        trace_error("%s, bad resource\n", __func__);
        return PP_ERROR_BADRESOURCE;
    }
    char *new_url = nullsafe_strdup(ul->redirect_url);

    free_and_nullify(ul, url);
    free_and_nullify(ul, redirect_url);
    free_and_nullify(ul, status_line);
    free_and_nullify(ul, headers);
    free_and_nullify(ul, request_headers);

    if (ul->fd >= 0) {
        close(ul->fd);
        ul->fd = -1;
    }

    // abort further handling of the NPStream
    if (ul->np_stream) {
        ul->np_stream->pdata = NULL;
        ul->np_stream = NULL;
    }

    ul->fd = open_temporary_file();
    ul->url = new_url;
    ul->read_pos = 0;
    ul->method = PP_METHOD_GET;
    ul->ccb = callback;

    struct url_loader_open_param_s *p = g_slice_alloc(sizeof(*p));
    p->url =                ul->url;
    p->loader =             loader;
    p->instance_id =        ul->instance->id;
    p->method =             ul->method;
    p->request_headers =    ul->request_headers;
    p->custom_referrer_url = ul->custom_referrer_url;
    p->custom_content_transfer_encoding =  ul->custom_content_transfer_encoding;
    p->custom_user_agent =  ul->custom_user_agent;
    p->target =             NULL;
    p->post_len =           0;
    p->post_data =          NULL;
    p->m_loop =             ppb_message_loop_get_current();
    p->depth =              ppb_message_loop_get_depth(p->m_loop) + 1;

    ppb_message_loop_post_work(p->m_loop, PP_MakeCCB(_url_loader_open_comt, p), 0);
    ppb_message_loop_run_nested(p->m_loop);

    pp_resource_release(loader);

    int retval = p->retval;
    g_slice_free1(sizeof(*p), p);

    if (retval != NPERR_NO_ERROR)
        return PP_ERROR_FAILED;

    if (callback.func == NULL) {
        int done = 0;
        while (!done) {
            ul = pp_resource_acquire(loader, PP_RESOURCE_URL_LOADER);
            if (ul) {
                done = ul->finished_loading;
                pp_resource_release(loader);
            } else {
                break;
            }
            printf("waitin'\n");
            usleep(10000);
        }
        return PP_OK;
    }

    return PP_OK_COMPLETIONPENDING;
}
コード例 #6
0
int32_t
ppb_url_loader_open_target(PP_Resource loader, PP_Resource request_info,
                           struct PP_CompletionCallback callback, const char *target)
{
    struct pp_url_loader_s *ul = pp_resource_acquire(loader, PP_RESOURCE_URL_LOADER);
    if (!ul) {
        trace_error("%s, bad resource\n", __func__);
        return PP_ERROR_BADRESOURCE;
    }
    struct pp_url_request_info_s *ri = pp_resource_acquire(request_info,
                                                           PP_RESOURCE_URL_REQUEST_INFO);
    if (!ri) {
        trace_error("%s, bad resource\n", __func__);
        pp_resource_release(loader);
        return PP_ERROR_BADRESOURCE;
    }
    struct PP_Var full_url;

    if (ri->is_immediate_javascript) {
        full_url = ppb_var_var_from_utf8_z(ri->url);
    } else {
        struct PP_Var rel_url = ppb_var_var_from_utf8_z(ri->url);
        full_url = ppb_url_util_dev_resolve_relative_to_document(ul->instance->id, rel_url, NULL);
        ppb_var_release(rel_url);
    }

    ul->url =              nullsafe_strdup(ppb_var_var_to_utf8(full_url, NULL));
    ul->method =           ri->method;
    ul->read_pos =         0;
    ul->request_headers =  nullsafe_strdup(ri->headers);
    ul->follow_redirects = ri->follow_redirects;
    ul->stream_to_file =   ri->stream_to_file;

    ul->record_download_progress =         ri->record_download_progress;
    ul->record_upload_progress =           ri->record_upload_progress;
    ul->custom_referrer_url =              nullsafe_strdup(ri->custom_referrer_url);
    ul->allow_cross_origin_requests =      ri->allow_cross_origin_requests;
    ul->allow_credentials =                ri->allow_credentials;
    ul->custom_content_transfer_encoding = nullsafe_strdup(ri->custom_content_transfer_encoding);
    ul->custom_user_agent =                nullsafe_strdup(ri->custom_user_agent);
    ul->target =                           nullsafe_strdup(target);

#define TRIM_NEWLINE(s)     s = trim_nl(s)

    TRIM_NEWLINE(ul->request_headers);
    TRIM_NEWLINE(ul->custom_referrer_url);
    TRIM_NEWLINE(ul->custom_content_transfer_encoding);
    TRIM_NEWLINE(ul->custom_user_agent);

    ul->post_len = ri->post_len;
    if (ri->post_len > 0) {
        ul->post_data = malloc(ri->post_len);
        memcpy(ul->post_data, ri->post_data, ri->post_len);
    }

    ul->fd = open_temporary_file();
    ul->ccb = callback;

    ppb_var_release(full_url);
    pp_resource_release(request_info);

    struct url_loader_open_param_s *p = g_slice_alloc(sizeof(*p));
    p->url =                ul->url;
    p->loader =             loader;
    p->instance_id =        ul->instance->id;
    p->method =             ul->method;
    p->request_headers =    ul->request_headers;
    p->custom_referrer_url = ul->custom_referrer_url;
    p->custom_content_transfer_encoding = ul->custom_content_transfer_encoding;
    p->custom_user_agent =  ul->custom_user_agent;
    p->target =         ul->target;
    p->post_len =       ul->post_len;
    p->post_data =      ul->post_data;
    p->m_loop =         ppb_message_loop_get_current();
    p->depth =          ppb_message_loop_get_depth(p->m_loop) + 1;

    ppb_core_add_ref_resource(loader);  // add ref to ensure data in ul remain accessible
    pp_resource_release(loader);

    ppb_message_loop_post_work(p->m_loop, PP_MakeCCB(_url_loader_open_comt, p), 0);
    ppb_message_loop_run_nested(p->m_loop);
    ppb_core_release_resource(loader);
    
    int retval = p->retval;
    g_slice_free1(sizeof(*p), p);

    if (retval != NPERR_NO_ERROR)
        return PP_ERROR_FAILED;

    if (callback.func == NULL) {
        int done = 0;
        while (!done) {
            ul = pp_resource_acquire(loader, PP_RESOURCE_URL_LOADER);
            if (ul) {
                done = ul->finished_loading;
                pp_resource_release(loader);
            } else {
                break;
            }
            printf("waitin'\n");
            usleep(10000);
        }
        return PP_OK;
    }

    return PP_OK_COMPLETIONPENDING;
}
コード例 #7
0
ファイル: plugin-proxy.c プロジェクト: DavidMercier/gwyddion
/**
 * file_plugin_proxy_load:
 * @filename. A file name to load.
 * @mode: Run mode.
 * @error: Return location for a #GError (or %NULL).
 * @name: Plug-in name (i.e. file-loading function) to run.
 *
 * The plug-in proxy itself, runs file-loading plug-in @name to load @filename.
 *
 * Returns: A newly created data container with the contents of @filename,
 *          or %NULL if it fails.
 **/
static GwyContainer*
file_plugin_proxy_load(const gchar *filename,
                       GwyRunType mode,
                       GError **error,
                       const gchar *name)
{
    FilePluginInfo *info;
    GwyContainer *data = NULL;
    GObject *dfield;
    gchar *tmpname = NULL, *buffer = NULL;
    GError *err = NULL;
    gint exit_status;
    gsize size = 0;
    FILE *fh;
    gchar *args[] = { NULL, NULL, NULL, NULL, NULL };
    gboolean ok;

    gwy_debug("called as %s with file `%s'", name, filename);
    if (mode != GWY_RUN_INTERACTIVE) {
        g_set_error(error, GWY_MODULE_FILE_ERROR,
                    GWY_MODULE_FILE_ERROR_INTERACTIVE,
                    _("Plugin-proxy must be run as interactive."));
        return NULL;
    }
    if (!(info = file_find_plugin(name, GWY_FILE_OPERATION_LOAD))) {
        g_set_error(error, GWY_MODULE_FILE_ERROR,
                    GWY_MODULE_FILE_ERROR_UNIMPLEMENTED,
                    _("Plug-in `%s' does not implement file loading."), name);
        return NULL;
    }
    if (!(fh = open_temporary_file(&tmpname, error)))
        return NULL;

    args[0] = info->file;
    args[1] = g_strdup(gwy_enum_to_string(GWY_FILE_OPERATION_LOAD,
                                          file_op_names, -1));
    args[2] = tmpname;
    args[3] = decode_glib_encoded_filename(filename);
    gwy_debug("%s %s %s %s", args[0], args[1], args[2], args[3]);
    ok = g_spawn_sync(NULL, args, NULL, 0, NULL, NULL,
                      NULL, NULL, &exit_status, &err);
    if (ok) {
        ok = g_file_get_contents(tmpname, &buffer, &size, &err);
        if (!ok) {
            g_set_error(error, GWY_MODULE_FILE_ERROR, GWY_MODULE_FILE_ERROR_IO,
                        _("Cannot read temporary file: %s."), err->message);
            g_clear_error(&err);
        }
    }
    else {
        g_set_error(error, GWY_MODULE_FILE_ERROR,
                    GWY_MODULE_FILE_ERROR_SPECIFIC,
                    _("Cannot execute plug-in `%s': %s."), name, err->message);
        g_clear_error(&err);
    }
    g_unlink(tmpname);
    fclose(fh);
    gwy_debug("ok = %d, exit_status = %d, err = %p", ok, exit_status, err);
    if (ok && exit_status) {
        g_set_error(error, GWY_MODULE_FILE_ERROR,
                    GWY_MODULE_FILE_ERROR_SPECIFIC,
                    _("Plug-in `%s' returned non-zero exit status: %d."),
                    name, exit_status);
        ok = FALSE;
    }
    if (ok) {
        data = text_dump_import(buffer, size, error);
        if (!data)
            ok = FALSE;
    }
    if (ok
        && (!gwy_container_gis_object_by_name(data, "/0/data", &dfield)
            || !GWY_IS_DATA_FIELD(dfield))) {
        g_set_error(error, GWY_MODULE_FILE_ERROR, GWY_MODULE_FILE_ERROR_DATA,
                    _("Plug-in `%s' did not return any meaningful data."),
                    name);
        gwy_object_unref(data);
    }
    g_free(args[1]);
    g_free(args[3]);
    g_free(buffer);
    g_free(tmpname);

    return data;
}