コード例 #1
0
ファイル: output-pstoedit.c プロジェクト: awesome/autotrace
/* This output routine uses two temporary files to keep the
   both the command line syntax of autotrace and the 
   pstoedit API. 

   shape -> bo file(tmpfile_name_p2e) 
   -> specified formatted file(tmpfile_name_pstoedit) 
   -> file */
static int
output_pstoedit_writer (FILE* file, gchar* name,
			int llx, int lly, int urx, int ury, 
			at_output_opts_type * opts,
			at_spline_list_array_type shape,
			at_msg_func msg_func, 
			gpointer msg_data,
			gpointer user_data)
{
  at_spline_writer *  p2e_writer = NULL;
  char  tmpfile_name_p2e[] = TMPDIR "at-bo-" "XXXXXX";
  char  tmpfile_name_pstoedit[] = TMPDIR "at-fo-" "XXXXXX";
  const gchar* symbolicname = (const gchar*)user_data;
  FILE * tmpfile;
  int result = 0;
  int c;

  int argc;
#define CMD_INDEX         0
#define SYMBOLICNAME_FLAG_INDEX 1
#define SYMBOLICNAME_VAL_INDEX  2
#define BO_FLAG_INDEX     3
#define INPUT_INDEX       4
#define OUTPUT_INDEX      5
  const char * argv[]  = {"pstoedit", "-f", 0, "-bo", 0, 0};

  argc = sizeof(argv) / sizeof(char *);

  tmpfile = make_temporary_file(tmpfile_name_p2e, "w");
  if (NULL == tmpfile)
    {
      result = -1;
      goto remove_tmp_p2e;
    }

  /* 
   * shape -> bo file 
   */
  p2e_writer = at_output_get_handler_by_suffix ("p2e");
  at_splines_write (p2e_writer, 
		    tmpfile, 
		    tmpfile_name_p2e,
		    opts, 
		    &shape, 
		    msg_func,
		    msg_data);
		    
  fclose(tmpfile);

  tmpfile = make_temporary_file(tmpfile_name_pstoedit, "r");
  if (NULL == tmpfile)
    {
      result = -1;
      goto remove_tmp_pstoedit;
    }

  /*
   * bo file -> specified formatted file 
   */
  argv[SYMBOLICNAME_VAL_INDEX] = symbolicname;
  argv[INPUT_INDEX]      = tmpfile_name_p2e;
  argv[OUTPUT_INDEX]     = tmpfile_name_pstoedit;
  pstoedit_plainC(argc, argv, NULL);

  /*
   * specified formatted file(tmpfile_name_pstoedit) -> file  
   */
  /* fseek(tmpfile, 0, SEEK_SET); */
  while (EOF != (c = fgetc(tmpfile)))
    fputc(c, file);
  fclose(tmpfile);
  
 remove_tmp_pstoedit:
  remove_temporary_file(tmpfile_name_pstoedit);
 remove_tmp_p2e:
  remove_temporary_file(tmpfile_name_p2e);
  return result;
}
コード例 #2
0
ファイル: output-pstoedit.c プロジェクト: FrancescBagur/Ccalc
/* This output routine uses two temporary files to keep the
   both the command line syntax of autotrace and the 
   pstoedit API. 

   shape -> bo file(tmpfile_name_p2e) 
   -> specified formatted file(tmpfile_name_pstoedit) 
   -> file */
static int
output_pstoedit_writer (const at_string suffix,
			FILE* file, at_string name,
			int llx, int lly, int urx, int ury, 
			at_output_opts_type * opts,
			at_spline_list_array_type shape,
			at_msg_func msg_func, 
			at_address msg_data)
{
  char  tmpfile_name_p2e[] = TMPDIR "at-bo-" "XXXXXX";
  char  tmpfile_name_pstoedit[] = TMPDIR "at-fo-" "XXXXXX";
  char * symbolicname;
  FILE * tmpfile;
  int result = 0;
  int c;

  int argc;
#define CMD_INDEX         0
#define SYMBOLICNAME_FLAG_INDEX 1
#define SYMBOLICNAME_VAL_INDEX  2
#define BO_FLAG_INDEX     3
#define INPUT_INDEX       4
#define OUTPUT_INDEX      5
  char * argv[]  = {"pstoedit", "-f", 0, "-bo", 0, 0};

  argc = sizeof(argv) / sizeof(char *);

  if (false == pstoedit_suffix_table_lookup_shallow(suffix))
    {
      if (msg_func) 
	msg_func ("Suffix for pstoedit backend driver is wrong", 
		  AT_MSG_WARNING, msg_data);
      return -1;
    }

  symbolicname = get_symbolicname(suffix);
  if (!symbolicname)
    {
      if (msg_func) 
	msg_func ("Symbolicname for pstoedit backend driver is wrong", 
		  AT_MSG_WARNING, msg_data);
      return -1;
    }
  
  tmpfile = make_temporary_file(tmpfile_name_p2e, "w");
  if (NULL == tmpfile)
    {
      result = -1;
      goto remove_tmp_p2e;
    }

  /* 
   * shape -> bo file 
   */
  output_p2e_writer(tmpfile, tmpfile_name_p2e,
		    llx, lly, urx, ury, opts,
		    shape, msg_func, msg_data);
  fclose(tmpfile);

  tmpfile = make_temporary_file(tmpfile_name_pstoedit, "r");
  if (NULL == tmpfile)
    {
      result = -1;
      goto remove_tmp_pstoedit;
    }

  /*
   * bo file -> specified formatted file 
   */
  argv[SYMBOLICNAME_VAL_INDEX] = symbolicname;
  argv[INPUT_INDEX]      = tmpfile_name_p2e;
  argv[OUTPUT_INDEX]     = tmpfile_name_pstoedit;
  pstoedit_plainC(argc, argv, NULL);

  /*
   * specified formatted file(tmpfile_name_pstoedit) -> file  
   */
  /* fseek(tmpfile, 0, SEEK_SET); */
  while (EOF != (c = fgetc(tmpfile)))
    fputc(c, file);
  fclose(tmpfile);
  
 remove_tmp_pstoedit:
  remove_temporary_file(tmpfile_name_pstoedit);
 remove_tmp_p2e:
  remove_temporary_file(tmpfile_name_p2e);
  free(symbolicname);
  return result;
}