Ejemplo n.º 1
0
//função insere uma aresta
void grafoD_insereAresta(GrafoD gd, char *vID1,  char *vID2, char *leftCEP, char *rightCEP, double size, double speed, char* nome){

    VerticeV *V1, *aux;
    Grafo *GD;

    GD = (Grafo *) gd;

    aux = calloc(1, sizeof(VerticeV));
    aux->id = calloc(strlen(vID1)+2, sizeof(char));
    strcpy(aux->id, vID1);
    V1 = (VerticeV *) get_hashtable(GD->ID, aux);
    freeVerticeV(aux);

    ArestaP *atual;
    if(V1->aresta == NULL){
        V1->aresta = calloc(1, sizeof(ArestaP));
        atual = V1->aresta;
    }else{
        atual = V1->aresta;
        while(atual->next != NULL){
            atual = atual->next;
        }
        atual->next = calloc(1, sizeof(ArestaP));
        atual = atual->next;
    }

    atual->v1 = V1;
    
    aux = calloc(1, sizeof(VerticeV));
    aux->id = calloc(strlen(vID2)+2, sizeof(char));
    strcpy(aux->id, vID2);
    atual->v2 = (VerticeV *) get_hashtable(GD->ID, aux);
    freeVerticeV(aux);

    atual->disable = 0;
    atual->nome = calloc(strlen(nome)+2, sizeof(char));
    strcpy(atual->nome, nome);
    atual->cepR = calloc(strlen(rightCEP)+2,sizeof(char));
    strcpy(atual->cepR, rightCEP);
    atual->cepL = calloc(strlen(leftCEP)+2,sizeof(char));
    strcpy(atual->cepL, leftCEP);
    atual->tam = size;
    atual->speed = speed;
    atual->next = NULL;


    insert_hashtable(GD->left, atual);
    insert_hashtable(GD->right, atual);

}
Ejemplo n.º 2
0
char const *
strget(char const *s)
{
	poolelem e, *ep;

	if (strpool == NULL)
		strpool = new_hashtable(&poolinfo);

	e.str = s;

	if (!find_hashtable(strpool, (hashelt *)&e))
		insert_hashtable(strpool, (hashelt *)&e);

	ep = (poolelem *)cur_hashtable(strpool);
	ep->ref++;
	return ep->str;
}
Ejemplo n.º 3
0
//cria e insere vertice
void *grafoD_criar(GrafoD gd, char *id, double x, double y){

    Grafo *gr;
    gr = (Grafo*)gd;

    VerticeV *grafo;
    grafo= calloc(1, sizeof(VerticeV));
    grafo->id = calloc(strlen(id)+2, sizeof(char));
    strcpy(grafo->id,id);
    grafo->disable = 0;
    grafo->x = x;
    grafo->y = y;
    grafo->aresta = NULL;

    KDT_insert(gr->vertices, grafo);
    insert_hashtable(gr->ID, grafo);

    return (void *) gd;
}
Ejemplo n.º 4
0
/*
 * Tests to see if the given directory has already been visited.
 */
static int
already_visited(char *mandir, char *dir, int count_visit)
{
	struct stat st;

	if (stat(dir, &st) < 0) {
		if (mandir != NULL)
			warn("%s/%s", mandir, dir);
		else
			warn("%s", dir);
		exit_code = 1;
		return 1;
	}
	if (find_hashtable(visited, st.st_ino, st.st_dev) != NULL) {
		if (mandir != NULL)
			warnx("already visited %s/%s", mandir, dir);
		else
			warnx("already visited %s", dir);
		return 1;
	}
	if (count_visit)
		insert_hashtable(visited, st.st_ino, st.st_dev, "");
	return 0;
}
Ejemplo n.º 5
0
/*
 * Processes a single man page source by using nroff to create
 * the preformatted cat page.
 */
static void
process_page(char *mandir, char *src, char *cat, enum Ziptype zipped)
{
	int src_test, cat_test;
	time_t src_mtime, cat_mtime;
	char cmd[MAXPATHLEN];
	dev_t src_dev;
	ino_t src_ino;
	const char *link_name;

	src_test = test_path(src, &src_mtime);
	if (!(src_test & (TEST_FILE|TEST_READABLE))) {
		if (!(src_test & TEST_DIR)) {
			warnx("%s/%s: unreadable", mandir, src);
			exit_code = 1;
			if (rm_junk && is_symlink(src))
				junk(mandir, src, "bogus symlink");
		}
		return;
	}
	src_dev = test_st.st_dev;
	src_ino = test_st.st_ino;
	cat_test = test_path(cat, &cat_mtime);
	if (cat_test & (TEST_FILE|TEST_READABLE)) {
		if (!force && cat_mtime >= src_mtime) {
			if (verbose) {
				fprintf(stderr, "\t%s/%s: up to date\n",
				    mandir, src);
			}
			return;
		}
	}
	/*
	 * Is the man page a link to one we've already processed?
	 */
	if ((link_name = find_hashtable(links, src_ino, src_dev)) != NULL) {
		if (verbose || pretend) {
			fprintf(stderr, "%slink %s -> %s\n",
			    verbose ? "\t" : "", cat, link_name);
		}
		if (!pretend)
			link(link_name, cat);
		return;
	}
	insert_hashtable(links, src_ino, src_dev, strdup(cat));
	if (verbose || pretend) {
		fprintf(stderr, "%sformat %s -> %s\n",
		    verbose ? "\t" : "", src, cat);
		if (pretend)
			return;
	}
	snprintf(tmp_file, sizeof tmp_file, "%s.tmp", cat);
	snprintf(cmd, sizeof cmd,
	    "%scat %s | tbl | nroff -c -T%s -man | %s > %s.tmp",
	    zipped == BZIP ? BZ2CAT_CMD : zipped == GZIP ? GZCAT_CMD : "",
	    src, nroff_device,
	    zipped == BZIP ? BZ2_CMD : zipped == GZIP ? GZ_CMD : "cat",
	    cat);
	if (system(cmd) != 0)
		err(1, "formatting pipeline");
	if (rename(tmp_file, cat) < 0)
		warn("%s", cat);
	tmp_file[0] = '\0';
}