コード例 #1
0
void print_col (struct arvore * tree) // imprime em labelled bracketing
{
    if (tree==NULL)
    {
        printf("[]");//para quando o no estiver vazio
        return;
    }
    printf("[%d",tree->chave);
    print_col (tree->esq);
    print_col (tree->dir);
    printf("]");
}
コード例 #2
0
ファイル: ft_select.c プロジェクト: dbaldy/ft_select
int					print_args(t_param *debut)
{
	int			col;
	t_param		*buf;
	int			nb_col;
	int			nb_row;

	buf = debut;
	col = 0;
	nb_col = get_nb_col(debut);
	nb_row = get_nb_row(debut, nb_col);
	if (nb_row >= get_height())
		return (-2);
	if (print_lines(nb_row) == -1)
		return (-1);
	while (col < nb_col)
	{
		if ((buf = print_col(buf, nb_row, col, get_nb_tab(debut))) == NULL)
			return (-2);
		if (buf->nb == 0)
			break ;
		if (move_cursor_up(nb_row, get_nb_tab(debut)) < 0)
			return (-1);
		col++;
	}
	return (0);
}
コード例 #3
0
ファイル: prin.c プロジェクト: GabrielPora/ft_select
void print_list(t_select sl)
{
	int k;

	put_command("cl", 0);
	while (sl.lc != NULL)
	{
		if (sl.enable & SEARCH)
			print_search(sl.lc, sl.fd_tty);
		else
			print_name(sl.lc, sl.fd_tty);
		k = 0;
		if (sl.lc->next && (sl.lc->next->row == sl.lc->row))
		{
			while (k < sl.sp[sl.lc->col] - sl.lc->len)
			{
				ft_putstr_fd(" ", sl.fd_tty);
				k++;
			}
			print_col(sl.fd_tty);
		}
		else
			ft_putstr_fd("\n", sl.fd_tty);
		sl.lc = sl.lc->next;
	}
}
コード例 #4
0
ファイル: apiSQLite3b.c プロジェクト: kentzo9/django_weblog
int main(int argc, char **argv)
{
	sqlite3 *db;
	sqlite3_stmt *plineInfo = 0;
	char *line = NULL;
	size_t len = 0;
	ssize_t read;

	//  char *zErrMsg = 0;
	int rc, i;

	if (argc < 2) {
		fprintf(stderr, "Usage: %s DATABASE < SQL-STATEMENT(S)\n",
			argv[0]);
		exit(1);
	}

	if (sqlite3_open(argv[1], &db) != SQLITE_OK) {
		fprintf(stderr, "Can't open database: \n");
		sqlite3_close(db);
		exit(1);
	}







	while ((read = getline(&line, &len, stdin)) != -1) {

		rc = sqlite3_prepare(db, line, -1, &plineInfo, 0);
		if (rc == SQLITE_OK && plineInfo != NULL ) {
			while ((rc =
				sqlite3_step(plineInfo)) == SQLITE_ROW) {
				//
				for (i = 0;
				     i < sqlite3_column_count(plineInfo);
				     ++i)
					print_col(plineInfo, i);

				printf("\n");

			}
			rc = sqlite3_finalize(plineInfo);
		}


		fprintf(stderr, "Total Changes %d\n",
			sqlite3_total_changes(db));
	}
	if (line) {
		free(line);
	}
	sqlite3_close(db);
	return 0;
}
コード例 #5
0
ファイル: eatblob.c プロジェクト: kentzo9/django_weblog
int main(int argc, char **argv)
{
	sqlite3 *db;
	sqlite3_stmt *plineInfo = 0;
	char *line = NULL;
	size_t len = 0;
	ssize_t mread;

	int fd, n;
	long buflen = 0, totread = 0;
	char *buf = NULL, *pbuf = NULL;

	//  char *zErrMsg = 0;
	int rc, i;

	if (argc < 3) {
		fprintf(stderr,
			"Usage: %s <DATABASE> <BINARYFILE> < sqlcommands \n\n"
			"Or, the following:\n\n"
			"  $%s test3.db test.png \n"

                        "   eatblob:0> create table blobtest (des varchar(80), b blob);\n"
                        "   eatblob:0> insert into blobtest (des,b) values ('A test file: test.png',?);\n"
                        "   eatblob:1> select * from blobtest;\n"
                        "    A test file: test.png\n"
                        "   eatblob:1>\n\n"
			" Note output.0.png will contain a copy of test.png\n\n"
			"Or, do everything on the command prompt:\n\n"
			" $ ./eatblob test3.db test.png \"create table blobtest (des varchar(80),b blob);\"\n"
			" $ ./eatblob test3.db test.png \"insert into blobtest (des,b) values ('A test file: test.png',?);\"\n"
                        "\n\n",
			argv[0], argv[0]);
		exit(1);
	}

	if (sqlite3_open(argv[1], &db) != SQLITE_OK) {
		fprintf(stderr, "Can't open database: \n");
		sqlite3_close(db);
		exit(1);
	}

	if ((fd = open(argv[2], O_RDWR | O_CREAT, 0600)) == -1) {
		fprintf(stderr, "Can't open data: %s\n", strerror(errno));
		return 1;
	}

	while (buflen - totread - 1 < 1024)
		buflen = addmem(&buf, buflen);
	pbuf = buf;
	totread = 0;
	while ((n = read(fd, pbuf, 1024)) > 0) {
		totread += n;
		pbuf[n] = '\0';	// This is for printing test
		while (buflen - totread - 1 < 1024)
			buflen = addmem(&buf, buflen);

		pbuf = &buf[totread];

	}
	close(fd);


	if (argc == 4) {
		rc = sqlite3_prepare(db, argv[3], -1, &plineInfo, 0);
		if (rc == SQLITE_OK && plineInfo != NULL) {
			//fprintf(stderr, "SQLITE_OK\n");
			sqlite3_bind_blob(plineInfo, 1, buf, totread,
					  free);
			while ((rc =
				sqlite3_step(plineInfo)) == SQLITE_ROW) {
				//
				for (i = 0;
				     i < sqlite3_column_count(plineInfo);
				     ++i)
					print_col(plineInfo, i);

				printf("\n");

			}
			rc = sqlite3_finalize(plineInfo);
		}
		fprintf(stderr, "eatblob:%d> ", sqlite3_total_changes(db));

	} else {
		fprintf(stderr, "eatblob:0> ");
		while ((mread = mygetline(&line, &len, stdin)) > 0) {
			rc = sqlite3_prepare(db, line, -1, &plineInfo, 0);
			if (rc == SQLITE_OK && plineInfo != NULL) {
				//fprintf(stderr, "SQLITE_OK\n");
				sqlite3_bind_blob(plineInfo, 1, buf,
						  totread, free);
				while ((rc =
					sqlite3_step(plineInfo)) ==
				       SQLITE_ROW) {
					//
					for (i = 0;
					     i <
					     sqlite3_column_count
					     (plineInfo); ++i)
						print_col(plineInfo, i);

					printf("\n");

				}
				rc = sqlite3_finalize(plineInfo);
			}
			fprintf(stderr, "eatblob:%d> ",
				sqlite3_total_changes(db));
		}		/* end of while */

	}

	if (line) {
		free(line);
	}
	sqlite3_close(db);
	return 0;
}
コード例 #6
0
ファイル: ls.c プロジェクト: Lihaoyang1992/CS631
void cook_multi_cols()
{
	int i = 0;
	FNODEP p;
	int col = 0;
	int row = 0;
	int count = cldlist_get_count();
	int *arr = (int *)calloc(count, sizeof(int));
	int *arr_copy = (int *)calloc(count, sizeof(int));
	int *name_reserve_arr = (int *)calloc(count, sizeof(int));
	//test for -c
	int *visit_order = (int *)calloc(count, sizeof(int));

	cldlist_reset_ptr();

	while((p = cldlist_get_next()) != NULL) {
		int len = strlen(p->ftsentryptr->fts_name);

		if (all_flags.iflag) {
			arr[i] += max_in_len + 1;
		}

		if (all_flags.sflag) {
			arr[i] += max_blk_len + 1;
		}

		arr[i] += len;

		if (all_flags.Fflag) {
			arr[i]++;
		}
		arr[i] += 2;

		arr_copy[i] = arr[i];

		name_reserve_arr[i] = len;

		i++;
	}

	qsort(arr, count, sizeof(int), compare_num);

	int min = count;
	int j;
	for (i = 0; i < count; ++i) {
		int w = 0;
		int overflow = 0;
		int gap = 0;

		for(j = i; j < count; ++j) {
			w += arr[j];
			if (w > win_width) {
				j--;
				overflow = 1;
				break;
			}
		}

		if (overflow) {
			gap = j-i+1;
			if (gap < min) {
				min = gap;
			}
		}
	}
	
	col = min;
	row = ceil((double)count/(double)col);
	col = ceil((double)count/(double)row);

	if (all_flags.Cflag) {
		for (i = 0; i < count; ++i) {
			int c = i/row; 
			int r = i%row;
			int index = r*col + c;
			visit_order[index] = i;
		}
	} else {
		for (i = 0; i < count; ++i) {
			visit_order[i] = i;
		}
	}

	int *col_width = (int *)calloc(col, sizeof(int));

	for (i = 0; i < row; ++i) {
		for (j = 0; j < col; ++j) {
			int index = i*col + j;
			if (index < count) {
				if (name_reserve_arr[visit_order[index]] > col_width[j]) {
					col_width[j] = name_reserve_arr[visit_order[index]];
				}
			}
		}
	}

	for (i = 0; i < row; ++i) {
		for (j = 0; j < col; ++j) {
			int index = i*col + j;
			if (index < count) {
				FNODEP fnode = cldlist_get(visit_order[index]);
				if (fnode != NULL) {
					print_col(fnode, col_width[j]);
				}
			}
		}
		putchar('\n');
	}
}
コード例 #7
0
int menu ()//funcao que imprime o menu e executa a opcao escolhida
{
    int i,j,n,a;
    printf("\nO que deseja fazer agora? Digite o numero com sua opcao:\n");
    printf("1. Adicionar novos numeros.\n2. Remover um numero.\n3. Buscar um numero.\n4. Imprimir a arvore.\n5. Sair\nOpcao: ");
    scanf("%d",&i);
    switch (i)//pula para a opcao escolhida.
    {
        case 1:
            {
                printf("Quantos numeros pretende entrar? ");
                scanf("%d",&n);
                while (n<1)
                {
                    printf("Entre com pelo menos um numero. Quantos valores deseja entrar? ");
                    scanf("%d",&n);
                }
                printf("Entre com os numeros:\n");
                for (j=0;j<n;j++)
                {
                    scanf("%d",&a);
                    adicionar (a);
                }
                printf("Numeros adicionados!\n");
                return 0;
            }
        case 2:
            {
                printf("Qual numero voce deseja remover? ");
                scanf("%d",&a);
                if (busca(root,a)==1)
                {
                    remover(a);
                    printf("Item removido!\n");
                    return 0;
                }
                else
                {
                    printf("O item nao pode ser removido pois nao se encontra na arvore.\n");
                    return 0;
                }
            }
        case 3:
            {
                printf("Qual numero deseja buscar? ");
                scanf("%d",&a);
                if (busca(root,a)==1)
                    printf("Numero encontrado! Ele ja esta na arvore.\n");
                else
                    printf("Numero nao encontrado.\n");
                return 0;
            }
        case 4://conta com um switch interno, para que se escolha como sera impressa a arvore
            {
               printf("Como voce deseja imprimi-los?\n1. Em ordem.\n2. Pre-ordem.\n3. Pos-ordem.\n4. Labelled bracketing.\nOpcao: ");
               scanf("%d",&j);
               switch (j)
               {
                   case 1:
                       {
                           print_in(root);
                           printf("\n");
                           return 0;
                       }
                   case 2:
                       {
                           print_pre(root);
                           printf("\n");
                           return 0;
                       }
                   case 3:
                       {
                           print_pos(root);
                           printf("\n");
                           return 0;
                       }
                   case 4:
                       {
                           print_col(root);
                           printf("\n");
                           return 0;
                       }
                   default:
                       {
                           printf("Ocorreu um erro. Tente novamente.\n");
                           return 0;
                       }
               }
            }
        case 5:
            return 1;
        default:
            {
            printf("Ocorreu um erro. Tente novamente.\n");
            return 0;
            }
    }
}