Exemplo n.º 1
0
char * match_routes(req_header * header){
	int i;
	for(i = 0; i < NUM_ROUTES; i++){
		if(!strcmp(routes[i].route, extract_path(header->path))){
			printf("Routing to %s\n", extract_path(header->path));
			char * content = handle_route(header, i);
			content = wrap_header(header, content);
			printf("%s\n", content);
			return content;
		}
	}
	//printf("did not find any matching routes...\n");
	return return404();
}
	void start_curl() {
		state = kDownloading;
		curl = curl_easy_init();
		//assert(direct_ip.size());
		std::string actual_url = redirect_url.size() ? redirect_url:url;
		char buf[1024];
		sprintf(buf,"%s://%s%s%s",
					extract_proto(actual_url).c_str(),
					direct_ip.c_str(),
					extract_port(actual_url).c_str(),
					extract_path(actual_url).c_str());
		curl_easy_setopt(curl, CURLOPT_URL, buf);
		sprintf(buf,"Host: %s%s",extract_host(actual_url).c_str(),extract_port(actual_url).c_str());
		headers = curl_slist_append(headers,buf);
		curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Request::GotData);
		curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)this);
		curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-airplay-agent/1.0");
		curl_easy_setopt(curl,CURLOPT_CONNECTTIMEOUT, 15);
		curl_easy_setopt(curl,CURLOPT_TIMEOUT, 30);
		curl_easy_setopt(curl,CURLOPT_NOPROGRESS, 0);
		curl_easy_setopt(curl,CURLOPT_FOLLOWLOCATION, 0);

		curl_easy_setopt(curl,CURLOPT_HEADERFUNCTION, Request::GotHeaderStatic);
		curl_easy_setopt(curl,CURLOPT_HEADERDATA, this);

		curl_easy_setopt(curl,CURLOPT_PROGRESSFUNCTION, Request::GotProgressStatic);
		curl_easy_setopt(curl,CURLOPT_PROGRESSDATA, (void *)this);
		//curl_easy_setopt(curl,CURLOPT_VERBOSE,1);
		if( curlsh )
			curl_easy_setopt(curl,CURLOPT_SHARE,curlsh);
		if( curlm )
			curl_multi_add_handle(curlm, curl);
	}
Exemplo n.º 3
0
HRESULT sdk_mesh::create(ID3D11Device* device, LPCTSTR file)
{
    HRESULT hr;

    sdk_mesh_.reset(new CDXUTSDKMesh);

    tstring path = extract_path(file);

	SDKMESH_CALLBACKS11 callbacks;
	callbacks.pCreateTextureFromFile = &dune::load_texture_cb;
	callbacks.pCreateVertexBuffer = nullptr;
	callbacks.pCreateIndexBuffer = nullptr;
	callbacks.pContext = reinterpret_cast<void*>(&path);

    V_RETURN(sdk_mesh_->Create(device, file, false, &callbacks));

    V_RETURN(cb_mesh_data_vs_.create(device));
    V_RETURN(cb_mesh_data_ps_.create(device));

    init_bb(sdk_mesh_->GetMeshBBoxCenter(0));

    for (UINT i = 0; i < sdk_mesh_->GetNumMeshes(); ++i)
    {
        update_bb(sdk_mesh_->GetMeshBBoxCenter(i) - sdk_mesh_->GetMeshBBoxExtents(i));
        update_bb(sdk_mesh_->GetMeshBBoxCenter(i) + sdk_mesh_->GetMeshBBoxExtents(i));
    }
        
    return S_OK;
}
Exemplo n.º 4
0
void composite_mesh::create_from_dir(ID3D11Device* device, const tstring& pattern)
{
    tstring absolute_pattern = make_absolute_path(pattern);
    tstring path = extract_path(tstring(absolute_pattern));

    std::vector<WIN32_FIND_DATA> files;

    WIN32_FIND_DATA data;

    HANDLE h = FindFirstFile(absolute_pattern.c_str(), &data);

    if (h != INVALID_HANDLE_VALUE)
    {
        files.push_back(data);

        while(FindNextFile(h, &data))
            files.push_back(data);
    }

    if (files.empty())
        throw exception(tstring(L"Couldn't find ") + pattern);

    for (auto i = files.begin(); i != files.end(); ++i)
    {
        tstring file = path + tstring(i->cFileName);
        create(device, file.c_str());
    }
}
Exemplo n.º 5
0
float		pathfinding(t_paths *path, t_map *map)
{
  t_paths	*start;
  int		end;
  int		i;
  int		*ke;

  end = 0;
  start = path;
  ke = init_ke(map, path);
  reinit_paths(path);
  path->visited = 1;
  path->visited_by = path->id;
  while (ke[0] && !end)
    {
      set_list_on_ke(&path, ke[0]);
      add_or_remove_from_ke(0, 0, ke);
      for (i = 0; path->neighboors[i] && !end; i++)
	if (!(path->neighboors[i])->visited)
	  {
	    add_or_remove_from_ke((path->neighboors[i])->id, 1, ke);
	    (path->neighboors[i])->visited = 1;
	    (path->neighboors[i])->visited_by = path->id;
	    if ((path->neighboors[i])->pos[0] == map->fortress_pos[0] && (path->neighboors[i])->pos[1] == map->fortress_pos[1])
	      end = 1;
	  }
    }
  return (extract_path(end, ke, path, start));
}
Exemplo n.º 6
0
 void ExtractorBase::extract (string const &content, string const &type, Object *object) const {
     namespace fs = boost::filesystem;
     fs::path path(fs::unique_path());
     WriteFile(path.native(), content);
     extract_path(path.native(), type, object);
     fs::remove(path);
 }
Exemplo n.º 7
0
 void ExtractorBase::extract_url (string const &url, string const &type, Object *object) const {
     namespace fs = boost::filesystem;
     fs::path path = fs::unique_path();
     int r = wget(url, path.native());
     if (r != 0) {
         throw ExternalError(url);
     }
     extract_path(path.native(), type, object);
     fs::remove(path);
 }
Exemplo n.º 8
0
static path_t* expand_pos(graphcut_workspace_t*w, posqueue_t*queue, node_t*pos, char reverse, unsigned char*mytree, unsigned char*othertree)
{
    graph_t*graph = w->graph;
    int dir;
    if((mytree[NR(pos)]&(IN_TREE|ACTIVE)) != (IN_TREE|ACTIVE)) {
	/* this node got deleted or marked inactive in the meantime. ignore it */
	DBG printf("node %d is deleted or inactive\n", NR(pos));
	return 0;
    }

    halfedge_t*e = pos->edges;
    for(;e;e=e->next) {
	node_t*newpos = e->fwd->node;
	weight_t weight = reverse?e->fwd->weight:e->weight;
	if(mytree[NR(newpos)]) continue; // already known

	if(weight) {
	    if(othertree[NR(newpos)]) {
		DBG printf("found connection: %d connects to %d\n", NR(pos), NR(newpos));
                posqueue_addpos(queue, pos); mytree[NR(pos)] |= ACTIVE; // re-add, this vertex might have other connections

		path_t*path;
		if(reverse) {
		    path = extract_path(w, othertree, mytree, newpos, pos, e->fwd);
		} else {
		    path = extract_path(w, mytree, othertree, pos, newpos, e);
		}
		return path;
	    } else {
		DBG printf("advance from %d to new pos %d\n", NR(pos), NR(newpos));
		w->back[NR(newpos)] = e->fwd;
		e->used = 1;
		posqueue_addpos(queue, newpos); mytree[NR(newpos)] |= ACTIVE|IN_TREE; // add
	    }
	}
    }
    /* if we can't expand this node anymore, it's now an inactive node */
    mytree[NR(pos)] &= ~ACTIVE;
    return 0;
}
static void output_combined_results
	(const struct Conv_Order_Data*const cod, const struct Integration_Test_Info*const int_test_info,
	 const int error_type, const struct Simulation*const sim)
{
	char error_ext[STRLEN_MIN];
	switch (error_type) {
		case ERROR_STANDARD: strcpy(error_ext,"standard"); break;
		case ERROR_FUNCTIONAL: strcpy(error_ext,"functional"); break;
		default: EXIT_ERROR("Unsupported: %d.\n",error_type); break;
	}

	const char*const output_path = extract_path(compute_error_input_name_root(int_test_info,error_type,false,sim));
	char output_name[STRLEN_MAX];
	sprintf(output_name,"%s%c%s%c%s%s",output_path,'/',"l2errs+convergence",'_',error_ext,".txt");

	const ptrdiff_t n_vars = cod->conv_orders->extents[2];

	FILE* file = fopen_create_dir(output_name); // closed

	fprintf(file,"n_vars %2td\n",n_vars);
	fprintf(file,"ml_max %2d\n",ML_MAX);
	fprintf(file,"p_max  %2d\n",P_MAX);

	struct Matrix_i tmp_i;
	struct Matrix_d tmp_d;

	fprintf(file,"\nCases Run\n");
	set_const_Matrix_from_Multiarray_i((struct const_Matrix_i*)&tmp_i,cod->cases_run,0);
	print_to_file_Matrix_i(file,&tmp_i);

	fprintf(file,"\nMesh Size\n");
	set_const_Matrix_from_Multiarray_d((struct const_Matrix_d*)&tmp_d,cod->h,0);
	print_to_file_Matrix_d(file,&tmp_d);

	fprintf(file,"\nL2 Errors\n\n");
	for (int i = 0; i < n_vars; ++i) {
		fprintf(file,"%s\n",cod->var_names[i]);
		set_const_Matrix_from_Multiarray_d((struct const_Matrix_d*)&tmp_d,cod->l2_err,(ptrdiff_t[]){i});
		print_to_file_Matrix_d(file,&tmp_d);
	}

	fprintf(file,"\nConvergence Orders\n\n");
	for (int i = 0; i < n_vars; ++i) {
		fprintf(file,"%s\n",cod->var_names[i]);
		set_const_Matrix_from_Multiarray_d((struct const_Matrix_d*)&tmp_d,cod->conv_orders,(ptrdiff_t[]){i});
		print_to_file_Matrix_d(file,&tmp_d);
	}

	fclose(file);
}
Exemplo n.º 10
0
static rc_t optionally_create_paths_in_output_filename( tool_ctx_t * tool_ctx )
{
    rc_t rc = 0;
    String path;
    if ( extract_path( tool_ctx -> output_filename, &path ) )
    {
        /* the output-filename contains a path... */
        if ( !dir_exists( tool_ctx -> dir, "%S", &path ) )
        {
            /* this path does not ( yet ) exist, create it... */
            rc = create_this_dir( tool_ctx -> dir, &path, true );
        }
    }
    return rc;
}
Exemplo n.º 11
0
char * match_routes(req_header * header){
	int i;
	int return_code = 200;
	for(i = 0; i < NUM_ROUTES; i++){

		if(!strcmp(routes[i].route, extract_path(header->path))){
			char * content = handle_route(header, i, &return_code);
			//if( == NULL){
			//	return return404();
			//}
			content = wrap_header(header, content);
			printf("%s", content);
			return content;
		}
	}
	return return404();
}
Exemplo n.º 12
0
//=======================================================================================
// DocLocator implementation
//=======================================================================================
DocLocator::DocLocator(const string& locator)
    : m_fullLocator(locator)
    , m_protocol(k_unknown)
    , m_innerProtocol(k_none)
    , m_fullpath("")
    , m_path("")
    , m_innerFullPath("")
    , m_innerFile("")
    , m_fValid(false)
{
    split_locator(locator);
    if (is_valid())
    {
        extract_file();
        extract_path();
    }
}
Exemplo n.º 13
0
int main(int argc, char **argv) {

	char path [255];
	char cap[255];
	char cua[255];

	strcpy(path, argv[1]);

	printf("El path es %s \n", path);

	if ( extract_path(path, cap, cua) ) {
		puts("Es un directori");
	} else {
		puts("Es un fitxer");
	}
	

	printf("El cap es: %s i la cua %s \n", cap, cua);


}
Exemplo n.º 14
0
int main(void)
{
  int m, w, i, j;
  int path[MAX_NODES], len;

  /* clear graph */
  for (i = 0; i < MAX_NODES; i++) {
    for (j = 0; j < MAX_NODES; j++) {
      graph[i][j] = DISCONNECT;
    }
  }

  /* read graph */
  scanf("%d %d %d", &i, &j, &w);
  while (!(i == -1 && j == -1)) {
    assert(0 <= i && i < MAX_NODES && 0 <= j && j < MAX_NODES);
    graph[i][j] = /*graph[j][i] =*/ w;
    scanf("%d %d %d", &i, &j, &w);
  }

  floyd();

  /* do queries */
  scanf("%d %d", &i, &j);
  while (!(i == -1 && j == -1)) {
    assert(0 <= i && i < MAX_NODES && 0 <= j && j < MAX_NODES);
    printf("%d %d: %d\n", i, j, dist[i][j]);
    len = extract_path(i, j, path);
    for (m = 0; m < len; m++) {
      if (m) {
	printf(" ");
      }
      printf("%d", path[m]);
    }
    printf("\n");
    scanf("%d %d", &i, &j);
  }

  return 0;
}
Exemplo n.º 15
0
FILE* fcFileOpener::try_open(const std::string &path, const std::string &name)
{
	std::string fullpath ( path + "/" + name );
	normalize_path( fullpath );

	FILE *fp = fopen(fullpath.c_str(), "r");
	if ( fp ) {
		_scannedfiles.insert( name );
		std::string p = extract_path(fullpath);

		for(size_t i=0; i<_excludePaths.size(); i++){
			size_t where = p.find(_excludePaths.at(i));
			if(where != std::string::npos && where == 0) {
				// the matched file is locatd inside an excluded directory
				fclose ( fp );
				return NULL;
			}
		}

		_matchedfiles.insert( fullpath );
		return fp;
	}
	return NULL;
}
Exemplo n.º 16
0
int revparse__ext(
	git_object **object_out,
	git_reference **reference_out,
	size_t *identifier_len_out,
	git_repository *repo,
	const char *spec)
{
	size_t pos = 0, identifier_len = 0;
	int error = -1, n;
	git_buf buf = GIT_BUF_INIT;

	git_reference *reference = NULL;
	git_object *base_rev = NULL;

	bool should_return_reference = true;

	assert(object_out && reference_out && repo && spec);

	*object_out = NULL;
	*reference_out = NULL;

	while (spec[pos]) {
		switch (spec[pos]) {
		case '^':
			should_return_reference = false;

			if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, false)) < 0)
				goto cleanup;

			if (spec[pos+1] == '{') {
				git_object *temp_object = NULL;

				if ((error = extract_curly_braces_content(&buf, spec, &pos)) < 0)
					goto cleanup;

				if ((error = handle_caret_curly_syntax(&temp_object, base_rev, git_buf_cstr(&buf))) < 0)
					goto cleanup;

				git_object_free(base_rev);
				base_rev = temp_object;
			} else {
				git_object *temp_object = NULL;

				if ((error = extract_how_many(&n, spec, &pos)) < 0)
					goto cleanup;

				if ((error = handle_caret_parent_syntax(&temp_object, base_rev, n)) < 0)
					goto cleanup;

				git_object_free(base_rev);
				base_rev = temp_object;
			}
			break;

		case '~':
		{
			git_object *temp_object = NULL;

			should_return_reference = false;

			if ((error = extract_how_many(&n, spec, &pos)) < 0)
				goto cleanup;

			if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, false)) < 0)
				goto cleanup;

			if ((error = handle_linear_syntax(&temp_object, base_rev, n)) < 0)
				goto cleanup;

			git_object_free(base_rev);
			base_rev = temp_object;
			break;
		}

		case ':':
		{
			git_object *temp_object = NULL;

			should_return_reference = false;

			if ((error = extract_path(&buf, spec, &pos)) < 0)
				goto cleanup;

			if (any_left_hand_identifier(base_rev, reference, identifier_len)) {
				if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, true)) < 0)
					goto cleanup;

				if ((error = handle_colon_syntax(&temp_object, base_rev, git_buf_cstr(&buf))) < 0)
					goto cleanup;
			} else {
				if (*git_buf_cstr(&buf) == '/') {
					if ((error = handle_grep_syntax(&temp_object, repo, NULL, git_buf_cstr(&buf) + 1)) < 0)
						goto cleanup;
				} else {

					/*
					 * TODO: support merge-stage path lookup (":2:Makefile")
					 * and plain index blob lookup (:i-am/a/blob)
					 */
					giterr_set(GITERR_INVALID, "unimplemented");
					error = GIT_ERROR;
					goto cleanup;
				}
			}

			git_object_free(base_rev);
			base_rev = temp_object;
			break;
		}

		case '@':
		{
			if (spec[pos+1] == '{') {
				git_object *temp_object = NULL;

				if ((error = extract_curly_braces_content(&buf, spec, &pos)) < 0)
					goto cleanup;

				if ((error = ensure_base_rev_is_not_known_yet(base_rev)) < 0)
					goto cleanup;

				if ((error = handle_at_syntax(&temp_object, &reference, spec, identifier_len, repo, git_buf_cstr(&buf))) < 0)
					goto cleanup;

				if (temp_object != NULL)
					base_rev = temp_object;
				break;
			} else {
				/* Fall through */
			}
		}

		default:
			if ((error = ensure_left_hand_identifier_is_not_known_yet(base_rev, reference)) < 0)
				goto cleanup;

			pos++;
			identifier_len++;
		}
	}

	if ((error = ensure_base_rev_loaded(&base_rev, &reference, spec, identifier_len, repo, false)) < 0)
		goto cleanup;

	if (!should_return_reference) {
		git_reference_free(reference);
		reference = NULL;
	}

	*object_out = base_rev;
	*reference_out = reference;
	*identifier_len_out = identifier_len;
	error = 0;

cleanup:
	if (error) {
		if (error == GIT_EINVALIDSPEC)
			giterr_set(GITERR_INVALID,
				"failed to parse revision specifier - Invalid pattern '%s'", spec);

		git_object_free(base_rev);
		git_reference_free(reference);
	}

	git_buf_free(&buf);
	return error;
}
void WorkspaceGenerator_MSVC8::generate_source_files(MSVC8_Project &vcproj, const Project &project)
{
	std::string chop_str = "Sources\\";
	std::string::size_type chop_length = chop_str.length();

	std::list<std::string>::iterator itCur, itNew;
	std::list<std::string> cur_path;
	std::vector<MSVC8_Filter *> filters;

	std::list<std::string>::const_iterator itFiles;
	for (itFiles = project.files.begin(); itFiles != project.files.end(); itFiles++)
	{
		std::string file = *itFiles;

		// cut off path to files:
		if (file.length() > chop_length && file.substr(0, chop_length) == chop_str)
		{
			file = file.substr(chop_length);
		}

		std::list<std::string> new_path = extract_path(file);

		itCur = cur_path.begin();
		itNew = new_path.begin();
		while (itCur != cur_path.end())
		{
			if (itNew == new_path.end() || *itCur != *itNew) // path is no longer identical
			{
				while (itCur != cur_path.end())
				{
					filters.pop_back();
					itCur++;
				}
				break;
			}

			itCur++;
			itNew++;
		}
		while (itNew != new_path.end())
		{
			std::string filter_name = *itNew;

			MSVC8_Filter *filter = new MSVC8_Filter;
			filter->name = filter_name;
			if (filters.empty())
				vcproj.files.push_back(filter);
			else
				filters.back()->files.push_back(filter);
			filters.push_back(filter);

			itNew++;
		}

		cur_path = new_path;

		MSVC8_File *vcfile = new MSVC8_File;
		vcfile->relative_path = "..\\" + chop_str + file;

		if (filters.empty())
			vcproj.files.push_back(vcfile);
		else
			filters.back()->files.push_back(vcfile);
	}

	for (itCur = cur_path.begin(); itCur != cur_path.end(); itCur++)
		filters.pop_back();
}
Exemplo n.º 18
0
int
main(int ac, char **av)
{
    int fmt = 0;
    int ret = 0;
    int ac_offset = 0;
    const char *in_fmt = NULL;
    const char *out_fmt = NULL;
    mime_model_t in_type = MIME_MODEL_UNKNOWN;
    mime_model_t out_type = MIME_MODEL_UNKNOWN;
    struct bu_vls in_format = BU_VLS_INIT_ZERO;
    struct bu_vls in_path = BU_VLS_INIT_ZERO;
    struct bu_vls out_format = BU_VLS_INIT_ZERO;
    struct bu_vls out_path = BU_VLS_INIT_ZERO;
    struct bu_vls log = BU_VLS_INIT_ZERO;
    struct bu_vls input_opts = BU_VLS_INIT_ZERO;
    struct bu_vls output_opts = BU_VLS_INIT_ZERO;

    ac-=(ac>0); av+=(ac>0); // skip program name argv[0] if present
    ac_offset = (ac > 2) ? 2 : 0;  // The last two argv entries must always be the input and output paths

    /* Handle anything else as options */
    option::Stats stats(TopUsage, ac - ac_offset, av);
    option::Option *options = (option::Option *)bu_calloc(stats.options_max, sizeof(option::Option), "options");
    option::Option *buffer= (option::Option *)bu_calloc(stats.buffer_max, sizeof(option::Option), "options");
    option::Parser parse(TopUsage, ac - ac_offset, av, options, buffer);

    /* Now that we've parsed them, start using them */
    if (options[HELP] || ac == 0) {
	if (options[HELP].arg) {
	    int help_type_int = bu_file_mime(options[HELP].arg, MIME_MODEL);
	    switch (help_type_int) {
		case MIME_MODEL_VND_FASTGEN:
		    option::printUsage(std::cout, Fast4Usage);
		    break;
		case MIME_MODEL_STL:
		    option::printUsage(std::cout, STLUsage);
		    break;
		default:
		    option::printUsage(std::cout, TopUsage);
		    break;
	    }
	} else {
	    option::printUsage(std::cout, TopUsage);
	    // TODO - figure out how to get this info from each plugin to construct this table
	    // on the fly...
	    bu_log("\nSupported formats:\n");
	    bu_log(" ------------------------------------------------------------\n");
	    bu_log(" | Extension  |          File Format      |  Input | Output |\n");
	    bu_log(" |----------------------------------------------------------|\n");
	    bu_log(" |    stl     |   STereoLithography       |   Yes  |   Yes  |\n");
	    bu_log(" |------------|---------------------------|--------|--------|\n");
	    bu_log(" |    obj     |   Wavefront Object        |   Yes  |   Yes  |\n");
	    bu_log(" |------------|---------------------------|--------|--------|\n");
	    bu_log(" |    step    |   STEP (AP203)            |   Yes  |   Yes  |\n");
	    bu_log(" |------------|---------------------------|--------|--------|\n");
	    bu_log(" |    iges    |   Initial Graphics        |   Yes  |   No   |\n");
	    bu_log(" |            |   Exchange Specification  |        |        |\n");
	    bu_log(" |----------------------------------------------------------|\n");
	}
	goto cleanup;
    }

    /* Any args that weren't top level args will get passed to the
     * format specific arg processing routines, after we use the known
     * top level options and the path inputs to determine what the file
     * types in question are.  Steps:
     *
     * 1.  Reassemble the unknown args into strings. */
    reassemble_argstr(&input_opts, &output_opts, options[UNKNOWN]);
    if (bu_vls_strlen(&input_opts) > 0) bu_log("Unknown options (input): %s\n", bu_vls_addr(&input_opts));
    if (bu_vls_strlen(&output_opts) > 0) bu_log("Unknown options (output): %s\n", bu_vls_addr(&output_opts));
    /*
     * 2.  Use bu_argv_from_string to create new
     * arrays to be fed to the format specific option parsers.*/

    /* TODO - determine whether we want to have a specific option prefix,
     * such as in- and out-, to identify an option as specific to the
     * input file format suboption parser only.  i.e.:
     *
     * --in-tol=1.0  -> --tol=1.0 to the input file's suboptions only
     * --out-tol=2.0 -> --tol=2.0 to the input file's suboptions only
     * --tol=1.5     -> --tol=1.5 to both input and output suboptions
     *
     *  consistent with top level --in-format and --out-format options
     *
     */

    /* See if we have input and output files specified */
    if (!extract_path(&in_path, av[ac-2])) {
	bu_vls_printf(&log, "Error: no input path identified: %s\n", av[ac-2]);
	ret = 1;
    }
    if (!extract_path(&out_path, av[ac-1])) {
	bu_vls_printf(&log, "Error: no output path identified: %s\n", av[ac-1]);
	ret = 1;
    }

    /* Make sure we have distinct input and output paths */
    if (bu_vls_strlen(&in_path) > 0 && BU_STR_EQUAL(bu_vls_addr(&in_path), bu_vls_addr(&out_path))) {
	bu_vls_printf(&log, "Error: identical path specified for both input and output: %s\n", bu_vls_addr(&out_path));
	ret = 1;
    }

    /* Find out what input file type we are dealing with */
    if (options[IN_FORMAT]) {
	in_fmt = options[IN_FORMAT].arg;
    } else {
	/* If we aren't overridden by an option, it's worth doing file
	 * introspection to see if the file contents identify the input
	 * type solidly, provided we have that capability.*/

	/* fake type introspection for testing: */
	//bu_vls_sprintf(&in_format, "step");
    }
    fmt = parse_model_string(&in_format, &log, in_fmt, av[ac-2]);
    in_type = (fmt < 0) ? MIME_MODEL_UNKNOWN : (mime_model_t)fmt;
    in_fmt = NULL;

    /* Identify output file type */
    if (options[OUT_FORMAT]) out_fmt = options[OUT_FORMAT].arg;
    fmt = parse_model_string(&out_format, &log, out_fmt, av[ac-1]);
    out_type = (fmt < 0) ? MIME_MODEL_UNKNOWN : (mime_model_t)fmt;
    out_fmt = NULL;

    /* If we get to this point without knowing both input and output types, we've got a problem */
    if (in_type == MIME_MODEL_UNKNOWN) {
	bu_vls_printf(&log, "Error: no format type identified for input path: %s\n", bu_vls_addr(&in_path));
	ret = 1;
    }
    if (out_type == MIME_MODEL_UNKNOWN) {
	bu_vls_printf(&log, "Error: no format type identified for output path: %s\n", bu_vls_addr(&out_path));
	ret = 1;
    }

    /* If everything isn't OK, we're done - report and clean up memory */
    if (ret == 1) goto cleanup;

    /* If we've gotten this far, we know enough to try to convert. Until we
     * hook in conversion calls to libgcv, print a summary of the option
     * parsing results for debugging. */
    in_fmt = bu_file_mime_str((int)in_type, MIME_MODEL);
    out_fmt = bu_file_mime_str((int)out_type, MIME_MODEL);
    bu_log("Input file format: %s\n", in_fmt);
    bu_log("Output file format: %s\n", out_fmt);
    bu_log("Input file path: %s\n", bu_vls_addr(&in_path));
    bu_log("Output file path: %s\n", bu_vls_addr(&out_path));

    switch (in_type) {
	case MIME_MODEL_VND_FASTGEN:
	    fast4_arg_process(bu_vls_addr(&input_opts));
	    break;
	case MIME_MODEL_STL:
	    stl_arg_process(bu_vls_addr(&input_opts));
	default:
	    break;
    }

    switch (out_type) {
	case MIME_MODEL_VND_FASTGEN:
	    fast4_arg_process(bu_vls_addr(&output_opts));
	    break;
	case MIME_MODEL_STL:
	    stl_arg_process(bu_vls_addr(&output_opts));
	default:
	    break;
    }



    /* Clean up */
cleanup:
    if (bu_vls_strlen(&log) > 0) bu_log("%s", bu_vls_addr(&log));
    if (in_fmt) bu_free((char *)in_fmt, "input format string");
    if (out_fmt) bu_free((char *)out_fmt, "output format string");
    bu_free(options, "free options");
    bu_free(buffer, "free buffer");
    bu_vls_free(&in_format);
    bu_vls_free(&in_path);
    bu_vls_free(&out_format);
    bu_vls_free(&out_path);
    bu_vls_free(&log);
    bu_vls_free(&input_opts);
    bu_vls_free(&output_opts);

    return ret;
}
Exemplo n.º 19
0
/* get_bitpath()
 * ====================================================================
 * Get the font path from the ASSIGN.SYS
 * If there is NO ASSIGN.SYS, we substitute C: or A: instead.
 *
 */
void
get_bitpath( void )
{
    int  i, sys_file;
    long j;
    int  error;
    char *fname;
    int  alen;

    olddma = Fgetdta();
    Fsetdta( &newdma );		/* Point to OUR buffer */

    strcpy( epath, "C:\\ASSIGN.SYS" );
    epath[0] = GetBaseDrive();

    bufptr     = 0L;
    BufferSize = 0L;

    error = Fsfirst( epath, 0 );	/* Normal file search for 1st file */
    if( error == 0 )
    {   /* found it! */
        bufptr = calloc( 1, newdma.d_length * 2L );
        if( bufptr )
        {
            BufferSize = newdma.d_length;

            if( (sys_file = Fopen( epath, 0 )) < 0)
            {
                Fsetdta( olddma );		/* Point to OLD buffer */
                if( bufptr )
                {
                    free( bufptr );
                    bufptr = 0L;
                }
                form_alert( 1, alert1 );
                return;
            }

            path_found = FALSE;
            do
            {
                i = 0;
                alen = (int)Fread( sys_file, BufferSize, bufptr );
                do
                {
                    if( !strncmp( &bufptr[i], "path", 4) ||
                            !strncmp( &bufptr[i], "PATH", 4) )
                    {
                        strcpy( epath, extract_path( &i, alen ) );
                        path_found = TRUE;
                        goto done;
                    }
                    else
                    {
                        while(( bufptr[i] != '\n' ) && ( i < alen )) {
                            ++i;    /* Skip to newline */
                        }
                        ++i;
                    }
                } while( i < alen );
            } while( alen == BufferSize );
done:
            Fclose( sys_file );

            if( bufptr )
            {
                free( bufptr );
                bufptr = 0L;
            }
            j = strlen( epath );
            if( epath[ j - 1 ] == '\\' )
                epath[ j - 1 ] = '\0';
        }
        else
            form_alert( 1, alert1 );
    }
    Fsetdta( olddma );		/* Point to OLD buffer */

    fname = &epath[0];
    fname = strupr( fname );
}
Exemplo n.º 20
0
int
parse_model_string(struct bu_vls *format, struct bu_vls *log, const char *opt, const char *input)
{
    int type_int = 0;
    mime_model_t type = MIME_MODEL_UNKNOWN;

    struct bu_vls format_cpy = BU_VLS_INIT_ZERO;
    struct bu_vls path = BU_VLS_INIT_ZERO;

    if (UNLIKELY(!input) || UNLIKELY(strlen(input) == 0)) return MIME_MODEL_UNKNOWN;

    /* If an external routine has specified a format string, that string will
     * override the file extension (but not an explicit option or format prefix.
     * Stash any local format string here for later processing.  The idea is
     * to allow some other routine (say, an introspection of a file looking for
     * some signature string) to override a file extension based type identification.
     * Such introspection is beyond the scope of this function, but should override
     * the file extension mechanism. */
    if (format) bu_vls_sprintf(&format_cpy, "%s", bu_vls_addr(format));

    /* If we have an explicit option, that overrides any other format specifiers */
    if (opt) {
	type_int = bu_file_mime(opt, MIME_MODEL);
	type = (type_int < 0) ? MIME_MODEL_UNKNOWN : (mime_model_t)type_int;
	if (type == MIME_MODEL_UNKNOWN) {
	    /* Have prefix, but doesn't result in a known format - that's an error */
	    if (log) bu_vls_printf(log, "Error: unknown model format \"%s\" specified as an option.\n", opt);
	    bu_vls_free(&format_cpy);
	    return -1;
	}
    }

    /* Try for a format prefix */
    if (extract_format_prefix(format, input)) {
	/* If we don't already have a valid type and we had a format prefix,
	 * find out if it maps to a valid type */
	if (type == MIME_MODEL_UNKNOWN && format) {
	    /* Yes - see if the prefix specifies a model format */
	    type_int = bu_file_mime(bu_vls_addr(format), MIME_MODEL);
	    type = (type_int < 0) ? MIME_MODEL_UNKNOWN : (mime_model_t)type_int;
	    if (type == MIME_MODEL_UNKNOWN) {
		/* Have prefix, but doesn't result in a known format - that's an error */
		if (log) bu_vls_printf(log, "Error: unknown model format \"%s\" specified as a format prefix.\n", bu_vls_addr(format));
		bu_vls_free(&format_cpy);
		return -1;
	    }
	}
    }

    /* If we don't already have a type and we were passed a format string, give it a try */
    if (type == MIME_MODEL_UNKNOWN && format && bu_vls_strlen(&format_cpy) > 0) {
	bu_vls_sprintf(format, "%s", bu_vls_addr(&format_cpy));
	type_int = bu_file_mime(bu_vls_addr(&format_cpy), MIME_MODEL);
	type = (type_int < 0) ? MIME_MODEL_UNKNOWN : (mime_model_t)type_int;
	if (type == MIME_MODEL_UNKNOWN) {
	    /* Have prefix, but doesn't result in a known format - that's an error */
	    if (log) bu_vls_printf(log, "Error: unknown model format \"%s\" passed to parse_model_string.\n", bu_vls_addr(format));
	    bu_vls_free(&format_cpy);
	    return -1;
	}
    }

    /* If we have no prefix or the prefix didn't map to a model type, try file extension */
    if (type == MIME_MODEL_UNKNOWN && extract_path(&path, input)) {
	if (bu_path_component(format, bu_vls_addr(&path), PATH_EXTENSION)) {
	    type_int = bu_file_mime(bu_vls_addr(format), MIME_MODEL);
	    type = (type_int < 0) ? MIME_MODEL_UNKNOWN : (mime_model_t)type_int;
	    if (type == MIME_MODEL_UNKNOWN) {
		/* Have file extension, but doesn't result in a known format - that's an error */
		if (log) bu_vls_printf(log, "Error: file extension \"%s\" does not map to a known model format.\n", bu_vls_addr(format));
		bu_vls_free(&format_cpy);
		bu_vls_free(&path);
		return -1;
	    }
	}
    }
    bu_vls_free(&path);
    bu_vls_free(&format_cpy);
    return (int)type;
}