コード例 #1
0
ファイル: ps_vareas.c プロジェクト: AsherBond/MondocosmOS
/* create paths for area and islands */
static int plot_area(struct Map_info *P_map, int area, double shift)
{
    struct line_pnts *Points;
    int j, ret, ni, island;

    /* allocate memory for coordinates */
    Points = Vect_new_line_struct();

    /* plot areas */
    if (0 > (ret = Vect_get_area_points(P_map, area, Points))) {
	if (ret == -1)
	    G_warning(_("Read error in vector map"));
	return 0;
    }
    construct_path(Points, shift, WHOLE_PATH);

    /* plot islands */
    ni = Vect_get_area_num_isles(P_map, area);
    for (j = 0; j < ni; j++) {
	island = Vect_get_area_isle(P_map, area, j);
	if (0 > (ret = Vect_get_isle_points(P_map, island, Points))) {
	    if (ret == -1)
		G_warning(_("Read error in vector map"));
	    return -1;
	}
	construct_path(Points, shift, WHOLE_PATH);
    }
    return 1;
}
コード例 #2
0
int main(int argc, char* argv[]) {
	int style = STYLE_SH;

	if (argc > 2) usage();
	
	// default to csh style, if $SHELL ends with "csh".
	char* shell = getenv("SHELL");
	if (shell) {
		char* str = strstr(shell, "csh");
		if (str) style = STYLE_CSH;
	}
	
	if (argc == 2 && strcmp(argv[1], "-c") == 0) style = STYLE_CSH;
	if (argc == 2 && strcmp(argv[1], "-s") == 0) style = STYLE_SH;

	char* path = construct_path("PATH", "/etc/paths", "/etc/paths.d");
	char* manpath = NULL;

	// only adjust manpath if already set
	int do_manpath = (getenv("MANPATH") != NULL);
	if (do_manpath) {
		manpath = construct_path("MANPATH", "/etc/manpaths", "/etc/manpaths.d");
	}

	if (style == STYLE_CSH) {
		printf("setenv PATH \"%s\";\n", path);
		if (do_manpath) printf("setenv MANPATH \"%s\";\n", manpath);
	} else {
		printf("PATH=\"%s\"; export PATH;\n", path);
		if (do_manpath) printf("MANPATH=\"%s\"; export MANPATH;\n", manpath);
	}

	return 0;
}
コード例 #3
0
ファイル: epk.c プロジェクト: bkerler/epk2extract
void handle_extracted_image_file(char *filename, char *target_dir,
		const char *pak_type_name) {
	if (is_squashfs(filename)) {
		char unsquashed[100] = "";
		construct_path(unsquashed, target_dir, pak_type_name, NULL);
		printf("unsquashfs %s to directory %s\n", filename, unsquashed);
		rmrf(unsquashed);
		unsquashfs(filename, unsquashed);
	}
	if (check_lzo_header(filename)) {
		char unpacked[100] = "";
		construct_path(unpacked, target_dir, pak_type_name, ".unpacked");
		printf("decompressing %s with modified LZO algorithm to %s\n",
				filename, unpacked);
		if (lzo_unpack((const char*) filename, (const char*) unpacked) != 0) {
			printf("sorry. decompression failed. aborting now.\n");
			exit(1);
		}
		if (is_cramfs_image(unpacked)) {
			char uncram[100] = "";
			construct_path(uncram, target_dir, pak_type_name, NULL);
			printf("uncramfs %s to directory %s\n", unpacked, uncram);
			rmrf(uncram);
			uncramfs(uncram, unpacked);
		}
	}
	if (is_uboot_image(filename)) {
		char deimaged[100] = "";
		construct_path(deimaged, target_dir, pak_type_name, ".deimaged");
		printf("extracting u-boot image %s to %s\n", filename, deimaged);
		extract_uboot_image(filename, deimaged);
		handle_extracted_image_file(deimaged, target_dir, pak_type_name);
	}

}
コード例 #4
0
inline 
void
DijkstraPathfinder::process_one_open_node()
{
  if (open_nodes.empty())
    {
      state = NO_PATH_AVAILABLE;
      return;
    }
  else
    {
      Node& cnode = *open_nodes.top();
      open_nodes.pop();

      assert(cnode.visited == 0);
      cnode.visited = 1;
      
      // Goal reached
      if (int(cnode.x) == end.x && int(cnode.y) == end.y)
        {
          construct_path();
          state = PATH_FOUND;
          return;
        }
     
      make_neighbors_open(cnode);
    }
}
コード例 #5
0
ファイル: mode-extract.c プロジェクト: agrif/libvaht
static int extract_archive(struct vt_options* opt, vaht_archive* archive, char* out)
{
    uint16_t resource_types_count = vaht_archive_get_resource_types(archive);
    unsigned int t;
    for (t = 0; t < resource_types_count; t++)
    {
        const char* type = vaht_archive_get_resource_type(archive, t);
        
        /* check if we pass the type filter */
        if (opt->filter_type != NULL && strcmp(opt->filter_type, type) != 0)
        {
            /* we have failed the type filter! */
            continue;
        }

        /* if we're converting, but there's no extension for this type,
         * skip it
         */
        if (opt->convert && get_ext(opt, type) == NULL)
            continue;
        
        char* newdir = path_join(out, type);
        if (create_directory(opt, newdir))
        {
            free(newdir);
            return 1;
        }
        
        free(newdir);
        
        vaht_resource** resources = vaht_resources_open(archive, type);
        
        unsigned int r;
        for (r = 0; resources[r] != NULL; r++)
        {
            /* check if we pass the id filter */
            if (opt->filter_id != -1 && opt->filter_id != vaht_resource_id(resources[r]))
            {
                /* we failed the resource id filter! */
                continue;
            }
            
            char* ext = get_ext(opt, type);
            char* path = construct_path(resources[r], out, ext);
            
            if (write_resource(opt, resources[r], path))
            {
                vaht_resources_close(resources);
                free(path);
                return 1;
            }
            
            free(path);
        }
        
        vaht_resources_close(resources);
    }
    
    return 0;
}
コード例 #6
0
void day::load_day(const food_manager & man, const boost::filesystem::path & folder, const boost::gregorian::date & date) {
	clear();
	auto p = construct_path(folder, date);
	if(!boost::filesystem::exists(p)) {
		log_debug() << "No foods for " << date << " saved." << std::endl;
		return;
	}

	if(!boost::filesystem::is_regular_file(p)) {
		log_error() << "The file " << p << " should be a regular file." << std::endl;
		return;
	}

	std::ifstream ifs(p.c_str());
	boost::archive::text_iarchive ia(ifs);

	size_t n; ia >> n;

	for(size_t i = 0; i < n; ++i) {
		size_t m; ia >> m;
		foods.push_back({});
		for(size_t j = 0; j < m; ++j) {
			std::string identifier; ia >> identifier;

			foods.back().push_back(man.getItem(identifier));
		}
	}
}
コード例 #7
0
ファイル: main.cpp プロジェクト: KGE-INC/VirtualDub
void copy_file(const std::string& dstfile, const std::string& srcfile) {
	printf("copying: %s -> %s\n", srcfile.c_str(), dstfile.c_str());

	FILE *fs = fopen(srcfile.c_str(), "rb");

	if (!fs)
		error("couldn't open source file \"%s\"", srcfile.c_str());

	std::string filename(g_outputDir);

	if (!filename.empty()) {
		char c = filename[filename.size()-1];
		if (c != '/' && c != '\\')
			filename += '/';
	}

	filename += dstfile;

	construct_path(filename);

	FILE *fd = fopen(filename.c_str(), "wb");
	if (!fd)
		error("couldn't create \"%s\"", filename.c_str());

	fseek(fs, 0, SEEK_END);
	std::vector<char> data(ftell(fs));
	fseek(fs, 0, SEEK_SET);
	if (1 != fread(&data.front(), data.size(), 1, fs))
		error("couldn't read from \"%s\"", srcfile.c_str());
	fclose(fs);

	if (1 != fwrite(&data.front(), data.size(), 1, fd) || fclose(fd))
		error("couldn't write to \"%s\"", dstfile.c_str());
}
コード例 #8
0
// -------------------------------------------------------------------------
double GraphDefinition::construct_path(long ed_id, long v_pos) {
    if (parent[ed_id].ed_ind[v_pos] == -1) {
        path_element_tt pelement;
        GraphEdgeInfo* cur_edge = m_vecEdgeVector[ed_id];
        if (v_pos == 0) {
            pelement.vertex_id = cur_edge->m_lStartNode;
            pelement.cost = cur_edge->m_dCost;
        } else {
            pelement.vertex_id = cur_edge->m_lEndNode;
            pelement.cost = cur_edge->m_dReverseCost;
        }
        pelement.edge_id = cur_edge->m_lEdgeID;

        m_vecPath.push_back(pelement);
        return pelement.cost;
    }
    double ret = construct_path(parent[ed_id].ed_ind[v_pos],
        parent[ed_id].v_pos[v_pos]);
    path_element_tt pelement;
    GraphEdgeInfo* cur_edge = m_vecEdgeVector[ed_id];
    if (v_pos == 0) {
        pelement.vertex_id = cur_edge->m_lStartNode;
        pelement.cost = m_dCost[ed_id].endCost - ret;  // cur_edge.m_dCost;
        ret = m_dCost[ed_id].endCost;
    } else {
        pelement.vertex_id = cur_edge->m_lEndNode;
        pelement.cost = m_dCost[ed_id].startCost - ret;
        ret = m_dCost[ed_id].startCost;
    }
    pelement.edge_id = cur_edge->m_lEdgeID;

    m_vecPath.push_back(pelement);

    return ret;
}
コード例 #9
0
ファイル: cpp.c プロジェクト: rui314/8cc-old
static File *open_header(CppContext *ctx, String *name, List *paths) {
    for (int i = 0; i < LIST_LEN(paths); i++) {
        String *path = construct_path((String *)LIST_REF(paths, i), name);
        FILE *stream = fopen(STRING_BODY(path), "r");
        if (!stream)
            continue;
        return make_file(stream, STRING_BODY(path));
    }
    error_cpp_ctx(ctx, "Cannot find header: '%s'", STRING_BODY(name));
}
コード例 #10
0
Path
Pgr_trspHandler::process_trsp(
        size_t edge_count) {
    pgassert(m_path.start_id() == m_start_vertex);
    pgassert(m_path.end_id() == m_end_vertex);
    pgassert(m_parent.empty());

    m_parent.resize(edge_count + 1);
    m_dCost.resize(edge_count + 1);

    initialize_que();

    current_node = m_start_vertex;

    pgassert(m_path.start_id() == m_start_vertex);

    auto cur_edge = dijkstra_exploration();

    pgassert(m_path.start_id() == m_start_vertex);
    if (current_node != m_end_vertex) {
        Path result(m_start_vertex, m_end_vertex);
        return result.renumber_vertices(m_min_id);;
    }

    pgassert(m_path.start_id() == m_start_vertex);

    if (current_node == cur_edge.startNode()) {
        construct_path(cur_edge.idx(), C_EDGE);
    } else {
        construct_path(cur_edge.idx(), RC_EDGE);
    }

    Path_t pelement;
    pelement.node = m_end_vertex;
    pelement.edge = -1;
    pelement.cost = 0.0;
    m_path.push_back(pelement);

    m_path.Path::recalculate_agg_cost();
    return m_path.renumber_vertices(m_min_id);
}
コード例 #11
0
void day::save_day(const boost::filesystem::path & folder) {
	std::ofstream ofs(construct_path(folder, date).c_str());
	boost::archive::text_oarchive oa(ofs);

	size_t s = foods.size(); // TODO: really??!?
	oa << s;
	for(const auto & l : foods) {
		s = l.size();
		oa << s;
		for(const auto & f : l)
			oa << f.getIdentifier();
	}
}
コード例 #12
0
ファイル: revision.c プロジェクト: SayCV/geda-gaf
static PyObject *Revision_get_object_data(
	Revision *self, PyObject *args, PyObject *kwds)
{
	PyObject *ob_arg = NULL;
	static char *kwlist[] = { "ob", NULL };

	if (!PyArg_ParseTupleAndKeywords(
		    args, kwds, "O!:Revision.get_object_data", kwlist,
		    &ObjectType, &ob_arg))
		return NULL;

	xorn_object_t ob = ((Object *)ob_arg)->ob;
	xorn_obtype_t type = xorn_get_object_type(self->rev, ob);

	switch (type) {
	case xorn_obtype_none:
		PyErr_SetNone(PyExc_KeyError);
		return NULL;
	case xornsch_obtype_arc:
		return construct_arc(xornsch_get_arc_data(self->rev, ob));
	case xornsch_obtype_box:
		return construct_box(xornsch_get_box_data(self->rev, ob));
	case xornsch_obtype_circle:
		return construct_circle(
			xornsch_get_circle_data(self->rev, ob));
	case xornsch_obtype_component:
		return construct_component(
			xornsch_get_component_data(self->rev, ob));
	case xornsch_obtype_line:
		return construct_line(xornsch_get_line_data(self->rev, ob));
	case xornsch_obtype_net:
		return construct_net(xornsch_get_net_data(self->rev, ob));
	case xornsch_obtype_path:
		return construct_path(xornsch_get_path_data(self->rev, ob));
	case xornsch_obtype_picture:
		return construct_picture(
			xornsch_get_picture_data(self->rev, ob));
	case xornsch_obtype_text:
		return construct_text(xornsch_get_text_data(self->rev, ob));
	}

	char buf[BUFSIZ];
	snprintf(buf, BUFSIZ, "Object type not supported (%d)", type);
	PyErr_SetString(PyExc_ValueError, buf);
	return NULL;
}
コード例 #13
0
// -------------------------------------------------------------------------
double Pgr_trspHandler::construct_path(int64_t ed_id, Position pos) {
    pgassert(pos != ILLEGAL);

    if (m_parent[ed_id].isIllegal(pos)) {
        Path_t pelement;
        auto cur_edge = &m_edges[ed_id];
        if (pos == RC_EDGE) {
            pelement.node = cur_edge->startNode();
            pelement.cost = cur_edge->cost();
        } else {
            pelement.node = cur_edge->endNode();
            pelement.cost = cur_edge->r_cost();
        }
        pelement.edge = cur_edge->edgeID();

        m_path.push_back(pelement);
        pgassert(m_path.start_id() == m_start_vertex);
        return pelement.cost;
    }

    double ret = construct_path(m_parent[ed_id].e_idx[pos],
        m_parent[ed_id].v_pos[pos]);
    Path_t pelement;
    auto cur_edge = &m_edges[ed_id];
    if (pos == RC_EDGE) {
        pelement.node = cur_edge->startNode();
        pelement.cost = m_dCost[ed_id].endCost - ret;
        ret = m_dCost[ed_id].endCost;
    } else {
        pelement.node = cur_edge->endNode();
        pelement.cost = m_dCost[ed_id].startCost - ret;
        ret = m_dCost[ed_id].startCost;
    }
    pelement.edge = cur_edge->edgeID();

    m_path.push_back(pelement);

    return ret;
}
コード例 #14
0
ファイル: GraphDefinition.cpp プロジェクト: dapotts/pgrouting
// -------------------------------------------------------------------------
int GraphDefinition:: my_dijkstra(edge_t *edges, unsigned int edge_count, int start_vertex, int end_vertex, bool directed, bool has_reverse_cost,
                path_element_t **path, int *path_count, char **err_msg)
{
    if(!m_bIsGraphConstructed)
    {
        init();
        construct_graph(edges, edge_count, has_reverse_cost, directed);
        m_bIsGraphConstructed = true;
    }
    
    std::priority_queue<PDP, std::vector<PDP>, std::greater<PDP> > que;
    parent = new PARENT_PATH[edge_count + 1];
    m_dCost = new CostHolder[edge_count + 1];
    m_vecPath.clear();

    unsigned int i;
    for(i = 0; i <= edge_count; i++)
    {
        m_dCost[i].startCost = 1e15;
        m_dCost[i].endCost = 1e15;
    }
    
    if(m_mapNodeId2Edge.find(start_vertex) == m_mapNodeId2Edge.end())
    {
        *err_msg = (char *)"Source Not Found";
        deleteall();
        return -1;
    }

    if(m_mapNodeId2Edge.find(end_vertex) == m_mapNodeId2Edge.end())
    {
        *err_msg = (char *)"Destination Not Found";
        deleteall();
        return -1;
    }

    LongVector vecsource = m_mapNodeId2Edge[start_vertex];
    GraphEdgeInfo* cur_edge = NULL;

    for(i = 0; i < vecsource.size(); i++)
    {
        cur_edge = m_vecEdgeVector[vecsource[i]];
        if(cur_edge->m_lStartNode == start_vertex)
        {
            if(cur_edge->m_dCost >= 0.0)
            {
                m_dCost[cur_edge->m_lEdgeIndex].endCost= cur_edge->m_dCost;
                parent[cur_edge->m_lEdgeIndex].v_pos[0] = -1;
                parent[cur_edge->m_lEdgeIndex].ed_ind[0] = -1;
                que.push(std::make_pair(cur_edge->m_dCost, std::make_pair(cur_edge->m_lEdgeIndex, true)));
            }
        }
        else
        {
            if(cur_edge->m_dReverseCost >= 0.0)
            {
                m_dCost[cur_edge->m_lEdgeIndex].startCost = cur_edge->m_dReverseCost;
                parent[cur_edge->m_lEdgeIndex].v_pos[1] = -1;
                parent[cur_edge->m_lEdgeIndex].ed_ind[1] = -1;
                que.push(std::make_pair(cur_edge->m_dReverseCost, std::make_pair(cur_edge->m_lEdgeIndex, false)));
            }
        }
    }
    //parent[start_vertex].v_id = -1;
    //parent[start_vertex].ed_id = -1;
    //m_dCost[start_vertex] = 0.0;

    // int new_node;
    int cur_node = -1;

    while(!que.empty())
    {
        PDP cur_pos = que.top();
        que.pop();
        int cured_index = cur_pos.second.first;
        cur_edge = m_vecEdgeVector[cured_index];
        //GraphEdgeInfo* new_edge;

        if(cur_pos.second.second)      // explore edges connected to end node
        {
            cur_node = cur_edge->m_lEndNode;
            if(cur_edge->m_dCost < 0.0)
                continue;
            if(cur_node == end_vertex)
                break;
            explore(cur_node, *cur_edge, true, cur_edge->m_vecEndConnedtedEdge, que);
        }
        else        // explore edges connected to start node
        {
            cur_node = cur_edge->m_lStartNode;
            if(cur_edge->m_dReverseCost < 0.0)
                continue;
            if(cur_node == end_vertex)
                break;
            explore(cur_node, *cur_edge, false, cur_edge->m_vecStartConnectedEdge, que);
        }
    }
    if(cur_node != end_vertex)
    {
        if(m_lStartEdgeId == m_lEndEdgeId)
        {
            if(get_single_cost(1000.0, path, path_count))
            {
                return 0;
            }
        }
        *err_msg = (char *)"Path Not Found";
        deleteall();
        return -1;
    }
    else
    {
        double total_cost;
        if(cur_node == cur_edge->m_lStartNode)
        {
            total_cost = m_dCost[cur_edge->m_lEdgeIndex].startCost;
            construct_path(cur_edge->m_lEdgeIndex, 1);
        }
        else
        {
            total_cost = m_dCost[cur_edge->m_lEdgeIndex].endCost;
            construct_path(cur_edge->m_lEdgeIndex, 0);
        }
        path_element_t pelement;
        pelement.vertex_id = end_vertex;
        pelement.edge_id = -1;
        pelement.cost = 0.0;
        m_vecPath.push_back(pelement);

        if(m_lStartEdgeId == m_lEndEdgeId)
        {
            if(get_single_cost(total_cost, path, path_count))
            {
                return 0;
            }
        }
        
        *path = (path_element_t *) malloc(sizeof(path_element_t) * (m_vecPath.size() + 1));
        *path_count = m_vecPath.size();

        for(int i = 0; i < *path_count; i++)
        {
            (*path)[i].vertex_id = m_vecPath[i].vertex_id;
            (*path)[i].edge_id = m_vecPath[i].edge_id;
            (*path)[i].cost = m_vecPath[i].cost;
        }
        if(isStartVirtual)
        {
            (*path)[0].vertex_id = -1;
            (*path)[0].edge_id = m_lStartEdgeId;
        }
        if(isEndVirtual)
        {
            *path_count = *path_count - 1;
            (*path)[*path_count - 1].edge_id = m_lEndEdgeId;
        }
    }
    deleteall();
    return 0;
}
コード例 #15
0
ファイル: GraphDefinition.cpp プロジェクト: dapotts/pgrouting
// -------------------------------------------------------------------------
int GraphDefinition::my_dijkstra(int start_vertex, int end_vertex, unsigned int edge_count, char **err_msg)
{
    if(!m_bIsGraphConstructed)
    {
    *err_msg = (char *)"Graph not Ready!";
    return -1;
    }
    unsigned int i;
    for(i = 0; i <= edge_count; i++)
    {
    m_dCost[i].startCost = 1e15;
    m_dCost[i].endCost = 1e15;
    }

    if(m_mapNodeId2Edge.find(start_vertex) == m_mapNodeId2Edge.end())
    {
    *err_msg = (char *)"Source Not Found";
    deleteall();
    return -1;
    }

    if(m_mapNodeId2Edge.find(end_vertex) == m_mapNodeId2Edge.end())
    {
    *err_msg = (char *)"Destination Not Found";
    deleteall();
    return -1;
    }

    std::priority_queue<PDP, std::vector<PDP>, std::greater<PDP> > que;
    LongVector vecsource = m_mapNodeId2Edge[start_vertex];
    GraphEdgeInfo* cur_edge = NULL;

    for(i = 0; i < vecsource.size(); i++)
    {
    cur_edge = m_vecEdgeVector[vecsource[i]];
    if(cur_edge->m_lStartNode == start_vertex)
    {
        if(cur_edge->m_dCost >= 0.0)
        {
        m_dCost[cur_edge->m_lEdgeIndex].endCost= cur_edge->m_dCost;
        parent[cur_edge->m_lEdgeIndex].v_pos[0] = -1;
        parent[cur_edge->m_lEdgeIndex].ed_ind[0] = -1;
        que.push(std::make_pair(cur_edge->m_dCost, std::make_pair(cur_edge->m_lEdgeIndex, true)));
        }
    }
    else
    {
        if(cur_edge->m_dReverseCost >= 0.0)
        {
        m_dCost[cur_edge->m_lEdgeIndex].startCost = cur_edge->m_dReverseCost;
        parent[cur_edge->m_lEdgeIndex].v_pos[1] = -1;
        parent[cur_edge->m_lEdgeIndex].ed_ind[1] = -1;
        que.push(std::make_pair(cur_edge->m_dReverseCost, std::make_pair(cur_edge->m_lEdgeIndex, false)));
        }
    }
    }
    
    // int new_node;
    int cur_node = -1;

    while(!que.empty())
    {
    PDP cur_pos = que.top();
    que.pop();
    int cured_index = cur_pos.second.first;
    cur_edge = m_vecEdgeVector[cured_index];
    //GraphEdgeInfo* new_edge;

    if(cur_pos.second.second)      // explore edges connected to end node
    {
        cur_node = cur_edge->m_lEndNode;
        if(cur_edge->m_dCost < 0.0)
        continue;
        if(cur_node == end_vertex)
        break;
        explore(cur_node, *cur_edge, true, cur_edge->m_vecEndConnedtedEdge, que);
    }
    else        // explore edges connected to start node
    {
        cur_node = cur_edge->m_lStartNode;
        if(cur_edge->m_dReverseCost < 0.0)
        continue;
        if(cur_node == end_vertex)
        break;
        explore(cur_node, *cur_edge, false, cur_edge->m_vecStartConnectedEdge, que);
    }
    }
    if(cur_node != end_vertex)
    {
    *err_msg = (char *)"Path Not Found";
    deleteall();
    return -1;
    }
    else
    {
    // double total_cost;  //set but not used
    if(cur_node == cur_edge->m_lStartNode)
    {
        // total_cost = m_dCost[cur_edge->m_lEdgeIndex].startCost;
        construct_path(cur_edge->m_lEdgeIndex, 1);
    }
    else
    {
        // total_cost = m_dCost[cur_edge->m_lEdgeIndex].endCost;
        construct_path(cur_edge->m_lEdgeIndex, 0);
    }
    path_element_t pelement;
    pelement.vertex_id = end_vertex;
    pelement.edge_id = -1;
    pelement.cost = 0.0;
    m_vecPath.push_back(pelement);
    }
    return 0;
}
コード例 #16
0
ファイル: tldr.c プロジェクト: gabrielPeart/tldr-cpp-client
int
print_tldrpage(char const* input)
{
    int islinux;
    int isdarwin;
    char* output;
    char* platform;
    char url[1024];
    struct utsname sys;

    int homelen;
    char* homedir;
    int tldrlen;
    char* tldrdir = "/.tldr/tldr-master/pages/";
    char directory[1024];
    struct stat sb;

    uname(&sys);
    islinux = strcmp(sys.sysname, "Linux") == 0;
    isdarwin = strcmp(sys.sysname, "Darwin") == 0;

    if (islinux) { platform = "linux"; }
    else if (isdarwin) { platform = "osx"; }
    else { platform = "common"; }

    if ((homedir = getenv("HOME")) == NULL)
    {
        homedir = getpwuid(getuid())->pw_dir;
    }

    homelen = strlen(homedir);
    tldrlen = strlen(tldrdir);
    memcpy(directory, homedir, homelen);
    memcpy(directory + homelen, tldrdir, tldrlen);
    directory[homelen + tldrlen] = '\0';

    if (stat(directory, &sb) == 0 && S_ISDIR(sb.st_mode))
    {
        construct_path(url, 1024, homedir, input, platform);
        if (stat(url, &sb) == 0 && S_ISREG(sb.st_mode))
        {
            if (!get_file_content(url, &output, 0))
            {
                parse_tldrpage(output);
                free(output);
                return 0;
            }
        }
        else
        {
            construct_path(url, 1024, homedir, input, "common");
            if (stat(url, &sb) == 0 && S_ISREG(sb.st_mode))
            {
                if (!get_file_content(url, &output, 0))
                {
                    parse_tldrpage(output);
                    free(output);
                    return 0;
                }
            }
        }
    }

    construct_url(url, 1024, input, platform);
    download_content(url, &output, 0);
    if (output == NULL)
    {
        construct_url(url, 1024, input, "common");
        download_content(url, &output, 0);
        if (output == NULL) { return 1; }
    }

    parse_tldrpage(output);

    free(output);
    return 0;
}