int main(void) { int count = IN_COUNT; initbuffer(); /* if(maxbits < INIT_BITS) maxbits = INIT_BITS; */ /* * With our setting, maxbits = 16, INIT_BITS = 9 */ /* if (maxbits > BITS) maxbits = BITS; */ maxbits = BITS; maxmaxcode = 1 << maxbits; InCnt = count; apsim_InCnt = IN_COUNT + 3; InBuff = (unsigned char *) orig_text_buffer; OutBuff = (unsigned char *) comp_text_buffer; compress(); #ifdef PRINT_RESULTS int i; for (i = 0; i < HSIZE; i++) { printf("compress: htab[%d] = %lu\n", i, htabof(i)); } #endif if(htabof(2) != 10485922) return (1); return (0); }
int main() { int count = IN_COUNT; initbuffer(); /* if(maxbits < INIT_BITS) maxbits = INIT_BITS; */ /* * With our setting, maxbits = 16, INIT_BITS = 9 */ /* if (maxbits > BITS) maxbits = BITS; */ maxbits = BITS; maxmaxcode = 1 << maxbits; InCnt = count; apsim_InCnt = IN_COUNT + 3; InBuff = (unsigned char *) orig_text_buffer; OutBuff = (unsigned char *) comp_text_buffer; compress(); return 0; }
void create_buffers(int num) { int i, j; /* Should never happen */ if (num < 0) return; if (cfsh_num_buffers == 0) { if (num != 0) { printf("create_buffers: Creating buffers for the first time!\n"); size_buffer_array(num); printf("create_buffers: initting all %i buffers with %i default length\n", num, DEFAULT_BUFFER_SIZE); for (i = 0; i < num; i++) initbuffer(i); } else { printf("create_buffers: no buffers exist; none created, none cleared\n"); } } else if (cfsh_num_buffers > num) { printf("create_buffers: buffers %i to %i will be discarded\n", num, cfsh_num_buffers); for (i = num; i < cfsh_num_buffers; i++) destroybuffer(i); printf("create_buffers: reducing array size by %i\n", cfsh_num_buffers - num); size_buffer_array(num); } else { j = cfsh_num_buffers; /* We must find the value now as it will change */ printf("create_buffers: expanding array size by %i\n", num - cfsh_num_buffers); size_buffer_array(num); printf("create_buffers: initting %i new buffers with %i default length\n", num - j, DEFAULT_BUFFER_SIZE); for (i = j; i < num; i++) initbuffer(i); } }
//------------------------------------------------------------------------------- void initializations(void) { initreferences(); initmatrices(); initbuffer(); initScrambler(); initTwindleMatrix(); initwindow(); initfilter(); }
int main () { tp_buffer *bp = (tp_buffer*)malloc(sizeof(tp_buffer)*PAGES); bp = initbuffer(); char *nomeTabela=(char *)malloc(sizeof(char)*TAMANHO_NOME_TABELA); char *nomeCampo=(char *)malloc(sizeof(char)*TAMANHO_NOME_CAMPO); char *inserir=(char *)malloc(sizeof(char)*1); char tipoCampo; table *tabela = (table *)malloc(sizeof(table)*1); int fimCampos = 0, numTabelas, tamanhoCampo, i; printf("Digite o numero de tabelas a serem inseridas!\n"); scanf("%i",&numTabelas); for(i = 0; i < numTabelas; i++){ printf("Digite o nome da tabela!\n"); scanf("%s",nomeTabela); tabela = iniciaTabela(nomeTabela); while(fimCampos == 0){ printf("Digite o Nome do campo!\n"); scanf("%s",nomeCampo); fflush(stdin); printf("Digite o Tipo do campo!\n"); scanf("%c",&tipoCampo); fflush(stdin); printf("Digite o Tamanho do campo!\n"); scanf("%d",&tamanhoCampo); tabela = adicionaCampo(tabela, nomeCampo, tipoCampo, tamanhoCampo); printf("Deseja inserir um novo campo? (Y/N)\n"); scanf("%s",inserir); if(!strcmp(inserir,"N")){ fimCampos = 1; finalizaTabela(tabela); } } } printf("Digite o nome da tabela!\n"); scanf("%s",nomeTabela); //printf("%d",i); return 0; }
int iniciaAtributos(struct fs_objects *objeto, tp_table **tabela, tp_buffer **bufferpoll, char *nomeT){ *objeto = leObjeto(nomeT); *tabela = leSchema(*objeto); *bufferpoll = initbuffer(); if(*tabela == ERRO_ABRIR_ESQUEMA) { return ERRO_DE_PARAMETRO; } if(*bufferpoll == ERRO_DE_ALOCACAO) return ERRO_DE_PARAMETRO; return SUCCESS; }
int main( void ) { int count = IN_COUNT; long fcode; code_int i = 0; int c; code_int ent; int ix = 0; initbuffer(); maxbits = BITS; maxmaxcode = 1 << maxbits; InCnt = count; apsim_InCnt = IN_COUNT + 3; InBuff = (unsigned char *)orig_text_buffer; OutBuff = (unsigned char *)comp_text_buffer; ent = getbyte (); _Pragma("loopbound min 6 max 6") while ( ix++ < 6 ) { int apsim_bound111 = 0; if( InCnt > 0 && (apsim_InCnt-- > 0)) { InCnt--; c = (unsigned int)*InBuff++; } else { c = -1; } in_count++; fcode = (long) (((long) c << maxbits) + ent); ent = c; } return 0; }
int main(){ //union FILE *arq, *arq2; //Ponteiros para arquivos int valor_reg, tam_registro, pos_inicial_regis; pos_inicial_regis = valor_reg = tam_registro = 0; tp_buffer *bufferpoll = (tp_buffer*)malloc(sizeof(tp_buffer)*PAGES); initbuffer(bufferpoll); arq = fopen("file/meta.dat", "r"); if(arq == NULL){ printf("Read Error\n"); return 0; } fread(&valor_reg, sizeof(int), 1, arq); tp_table *s = (tp_table*)malloc(sizeof(tp_table)*valor_reg); //Aloca um vetor com o numero de colunas da tupla tam_registro = load_metadata(arq, s, valor_reg); fclose(arq); arq2 = fopen("file/data.dat", "r"); if(arq2 == NULL){ printf("Read Error\n"); return 0; } load_data(arq2, bufferpoll, tam_registro); fclose(arq2); //para imprimir //printbufferpoll(bufferpoll, s, 0, valor_reg); //Parametros são: buffer, estrutura dos meta dados, página a ser impressa e quantos campos tem a "tabela" cabecalho(s, valor_reg); pos_inicial_regis = 1 * tam_registro; drawline(bufferpoll, s, valor_reg, &pos_inicial_regis, 0); // (buffer, meta, numero de campos, posicao inicial, pagina) printf("\n"); free(s); free(bufferpoll); return 0; }
int main(void) { int count; initglobalvars(); count = 50; initbuffer(); maxbits = 16; maxmaxcode = 1 << maxbits; InCnt = count; apsim_InCnt = 50 + 3; InBuff = (unsigned char *) orig_text_buffer; OutBuff = (unsigned char *) comp_text_buffer; compress(); return (0); }
int excluirTabela(char *nomeTabela) { struct fs_objects objeto, objeto1; tp_table *esquema, *esquema1; int x,erro, i, j, k, l, qtTable; char str[20]; char dat[5] = ".dat"; memset(str, '\0', 20); if (!verificaNomeTabela(nomeTabela)) { printf("ERROR: table \"%s\" does not exist.\n", nomeTabela); return ERRO_NOME_TABELA; } strcpylower(str, nomeTabela); strcat(str, dat); //Concatena e junta o nome com .dat abreTabela(nomeTabela, &objeto, &esquema); qtTable = quantidadeTabelas(); char **tupla = (char **)malloc(sizeof(char **)*qtTable); memset(tupla, 0, qtTable); for (i=0; i < qtTable; i++) { tupla[i] = (char *)malloc(sizeof(char)*TAMANHO_NOME_TABELA); memset(tupla[i], '\0', TAMANHO_NOME_TABELA); } tp_table *tab2 = (tp_table *)malloc(sizeof(struct tp_table)); tab2 = procuraAtributoFK(objeto); //retorna o tipo de chave que e cada campo FILE *dicionario; char directory[LEN_DB_NAME*2]; memset(directory, '\0', LEN_DB_NAME*2); strcpy(directory, connected.db_directory); strcat(directory, "fs_object.dat"); if((dicionario = fopen(directory,"a+b")) == NULL) return ERRO_ABRIR_ARQUIVO; k=0; while(fgetc (dicionario) != EOF){ fseek(dicionario, -1, 1); //coloca o nome de todas as tabelas em tupla fread(tupla[k], sizeof(char), TAMANHO_NOME_TABELA , dicionario); k++; fseek(dicionario, 28, 1); } fclose(dicionario); for(i = 0; i < objeto.qtdCampos; i++){ if(tab2[i].chave == PK){ for(j=0; j<qtTable; j++) { //se tiver chave primaria verifica se ela e chave if(objcmp(tupla[j], nomeTabela) != 0) { //estrangeira em outra tabela abreTabela(tupla[j], &objeto1, &esquema1); tp_table *tab3 = (tp_table *)malloc(sizeof(struct tp_table)); tab3 = procuraAtributoFK(objeto1); for(l=0; l<objeto1.qtdCampos; l++) { if(tab3[l].chave == FK) { //verifica se a outra tabela possui chave estrangeira. se sim, verifica se e da tabela anterior. if(objcmp(nomeTabela, tab3[l].tabelaApt) == 0) { printf("ERROR: cannot drop table \"%s\" because other objects depend on it.\n", nomeTabela); return ERRO_CHAVE_ESTRANGEIRA; } } } free(tab3); } } } } free(tab2); tp_buffer *bufferpoll = initbuffer(); if(bufferpoll == ERRO_DE_ALOCACAO){ printf("ERROR: no memory available to allocate buffer.\n"); return ERRO_LEITURA_DADOS; } erro = SUCCESS; for(x = 0; erro == SUCCESS; x++) erro = colocaTuplaBuffer(bufferpoll, x, esquema, objeto); if(procuraSchemaArquivo(objeto) != 0) { free(bufferpoll); return ERRO_REMOVER_ARQUIVO_SCHEMA; } if(procuraObjectArquivo(nomeTabela) != 0) { free(bufferpoll); return ERRO_REMOVER_ARQUIVO_OBJECT; } strcpy(directory, connected.db_directory); strcat(directory, str); remove(directory); free(bufferpoll); printf("DROP TABLE\n"); return SUCCESS; }
static void imminit() { initbuffer(bigvbo, ARRAY_BUFFER, immbuffersize); initbuffer(bigibo, ELEMENT_ARRAY_BUFFER, immbuffersize); memset(immattribs, 0, sizeof(immattribs)); }
int campo_existe_na_tabela(char tabela[],char campo[]){ int erro; struct fs_objects objeto = leObjeto(tabela); tp_table *esquema = leSchema(objeto); if(esquema == ERRO_ABRIR_ESQUEMA){ printf("Erro ao criar o esquema.\n"); return 0; } tp_buffer *bufferpoll = initbuffer(); if(bufferpoll == ERRO_DE_ALOCACAO){ printf("Erro ao alocar memória para o buffer.\n"); return 0; } erro = colocaTuplaBuffer(bufferpoll, 0, esquema, objeto); if(erro != SUCCESS){ printf("Erro %d: na função colocaTuplaBuffer().\n", erro); return 0; } erro = colocaTuplaBuffer(bufferpoll, 1, esquema, objeto); if(erro != SUCCESS){ printf("Erro %d: na função colocaTuplaBuffer().\n", erro); return 0; } erro = colocaTuplaBuffer(bufferpoll, 2, esquema, objeto); if(erro != SUCCESS){ printf("Erro %d: na função colocaTuplaBuffer().\n", erro); return 0; } column *pagina = getPage(bufferpoll, esquema, objeto, 0); if(pagina == ERRO_PARAMETRO){ printf("Erro, na função getPage(), problemas no parametro.\n"); return 0; } // Auxiliar dos dados da tupla buscada int j, y = 0; for(j=0; j < objeto.qtdCampos*bufferpoll[0].nrec; j++){ if(strcmp(pagina[j].nomeCampo,tabela) == 0){ for(y=j;y<j+objeto.qtdCampos;y++){ if (strcmp (pagina[y].nomeCampo, campo) == 0) return 1; // Encontrou a coluna(campo), retorna 1 } } } return 0; // Nao encontrou a coluna, retorna 0 }
void imprimeAll(char nomeTabela[]) { int j,erro, x, p, cont=0; struct fs_objects objeto; if(!verificaNomeTabela(nomeTabela)){ printf("\nERROR: relation \"%s\" was not found.\n\n\n", nomeTabela); return; } objeto = leObjeto(nomeTabela); tp_table *esquema = leSchema(objeto); if(esquema == ERRO_ABRIR_ESQUEMA){ printf("ERROR: schema cannot be created.\n"); free(esquema); return; } tp_buffer *bufferpoll = initbuffer(); if(bufferpoll == ERRO_DE_ALOCACAO){ free(bufferpoll); free(esquema); printf("ERROR: no memory available to allocate buffer.\n"); return; } erro = SUCCESS; for(x = 0; erro == SUCCESS; x++) erro = colocaTuplaBuffer(bufferpoll, x, esquema, objeto); int ntuples = --x; p = 0; while(x){ column *pagina = getPage(bufferpoll, esquema, objeto, p); if(pagina == ERRO_PARAMETRO){ printf("ERROR: could not open the table.\n"); free(bufferpoll); free(esquema); return; } if(!cont) { for(j=0; j < objeto.qtdCampos; j++){ if(pagina[j].tipoCampo == 'S') printf(" %-20s ", pagina[j].nomeCampo); else printf(" %-10s ", pagina[j].nomeCampo); if(j<objeto.qtdCampos-1) printf("|"); } printf("\n"); for(j=0; j < objeto.qtdCampos; j++){ printf("%s",(pagina[j].tipoCampo == 'S')? "----------------------": "------------"); if(j<objeto.qtdCampos-1) printf("+"); } printf("\n"); } cont++; for(j=0; j < objeto.qtdCampos*bufferpoll[p].nrec; j++){ if(pagina[j].tipoCampo == 'S') printf(" %-20s ", pagina[j].valorCampo); else if(pagina[j].tipoCampo == 'I'){ int *n = (int *)&pagina[j].valorCampo[0]; printf(" %-10d ", *n); } else if(pagina[j].tipoCampo == 'C'){ printf(" %-10c ", pagina[j].valorCampo[0]); } else if(pagina[j].tipoCampo == 'D'){ double *n = (double *)&pagina[j].valorCampo[0]; printf(" %-10f ", *n); } if(j>=1 && ((j+1)%objeto.qtdCampos)==0) printf("\n"); else printf("|"); } x-=bufferpoll[p++].nrec; } printf("\n(%d %s)\n\n",ntuples,(1>=ntuples)?"row": "rows"); free(bufferpoll); free(esquema); }
// read a Differential Data Stream unsigned char *readDDSfile(const char *filename,size_t *bytes) { int version=1; unsigned int skip,strip; unsigned char *data = 0; unsigned char *ptr = 0; unsigned int cnt,cnt1,cnt2; int bits,act; if ((DDS_file=fopen(filename,"rb"))==NULL) return(NULL); for (cnt=0; DDS_ID[cnt]!='\0'; cnt++) if (fgetc(DDS_file)!=DDS_ID[cnt]) { fclose(DDS_file); version=0; break; } if (version==0) { if ((DDS_file=fopen(filename,"rb"))==NULL) return(NULL); for (cnt=0; DDS_ID2[cnt]!='\0'; cnt++) if (fgetc(DDS_file)!=DDS_ID2[cnt]) { fclose(DDS_file); return(NULL); } version=2; } initbuffer(); skip=readbits(DDS_file,2)+1; strip=readbits(DDS_file,16)+1; data=NULL; cnt=act=0; while ((cnt1=readbits(DDS_file,DDS_RL))!=0) { bits=DDS_decode(readbits(DDS_file,3)); for (cnt2=0; cnt2<cnt1; cnt2++) { if (cnt<=strip) act+=readbits(DDS_file,bits)-(1<<bits)/2; else act+=*(ptr-strip)-*(ptr-strip-1)+readbits(DDS_file,bits)-(1<<bits)/2; while (act<0) act+=256; while (act>255) act-=256; if (cnt%DDS_BLOCKSIZE==0) { if (data==NULL) {if ((data=(unsigned char *)malloc(DDS_BLOCKSIZE))==NULL) ERRORMSG();} else if ((data=(unsigned char *)realloc(data,cnt+DDS_BLOCKSIZE))==NULL) ERRORMSG(); ptr=&data[cnt]; } *ptr++=act; cnt++; } } fclose(DDS_file); if (cnt==0) return(NULL); if ((data=(unsigned char *)realloc(data,cnt))==NULL) ERRORMSG(); if (version==1) interleave(data,cnt,skip); else interleave(data,cnt,skip,DDS_INTERLEAVE); *bytes=cnt; return(data); }
// write a Differential Data Stream void writeDDSfile(const char *filename,unsigned char *data,size_t bytes,unsigned int skip,unsigned int strip,int nofree) { int version=1; unsigned char *ptr1,*ptr2; int pre1,pre2, act1,act2, tmp1,tmp2; unsigned int cnt,cnt1,cnt2; int bits,bits1,bits2; if (bytes<1) ERRORMSG(); if (bytes>DDS_INTERLEAVE) version=2; if (skip<1 || skip>4) skip=1; if (strip<1 || strip>65536) strip=1; if ((DDS_file=fopen(filename,"wb"))==NULL) ERRORMSG(); fprintf(DDS_file,"%s",(version==1)?DDS_ID:DDS_ID2); deinterleave(data,bytes,skip,DDS_INTERLEAVE); initbuffer(); writebits(DDS_file,skip-1,2); writebits(DDS_file,strip++-1,16); ptr1=ptr2=data; pre1=pre2=0; cnt=cnt1=cnt2=0; bits=bits1=bits2=0; while (cnt++<bytes) { tmp1=*ptr1++; if (cnt<=strip) act1=tmp1-pre1; else act1=tmp1-pre1-*(ptr1-strip)+*(ptr1-strip-1); pre1=tmp1; while (act1<-128) act1+=256; while (act1>127) act1-=256; if (act1<=0) for (bits=0; (1<<bits)/2<-act1; bits++) ; else for (bits=0; (1<<bits)/2<=act1; bits++) ; bits=DDS_decode(DDS_code(bits)); if (cnt1==0) { cnt1++; bits1=bits; continue; } if (cnt1<(1<<DDS_RL)-1 && bits==bits1) { cnt1++; continue; } if (cnt1+cnt2<(1<<DDS_RL) && (cnt1+cnt2)*max(bits1,bits2)<cnt1*bits1+cnt2*bits2+DDS_RL+3) { cnt2+=cnt1; if (bits1>bits2) bits2=bits1; } else { writebits(DDS_file,cnt2,DDS_RL); writebits(DDS_file,DDS_code(bits2),3); while (cnt2-->0) { tmp2=*ptr2++; if (ptr2-strip<=data) act2=tmp2-pre2; else act2=tmp2-pre2-*(ptr2-strip)+*(ptr2-strip-1); pre2=tmp2; while (act2<-128) act2+=256; while (act2>127) act2-=256; writebits(DDS_file,act2+(1<<bits2)/2,bits2); } cnt2=cnt1; bits2=bits1; } cnt1=1; bits1=bits; } if (cnt1+cnt2<(1<<DDS_RL) && (cnt1+cnt2)*max(bits1,bits2)<cnt1*bits1+cnt2*bits2+DDS_RL+3) { cnt2+=cnt1; if (bits1>bits2) bits2=bits1; } else { writebits(DDS_file,cnt2,DDS_RL); writebits(DDS_file,DDS_code(bits2),3); while (cnt2-->0) { tmp2=*ptr2++; if (ptr2-strip<=data) act2=tmp2-pre2; else act2=tmp2-pre2-*(ptr2-strip)+*(ptr2-strip-1); pre2=tmp2; while (act2<-128) act2+=256; while (act2>127) act2-=256; writebits(DDS_file,act2+(1<<bits2)/2,bits2); } cnt2=cnt1; bits2=bits1; } if (cnt2!=0) { writebits(DDS_file,cnt2,DDS_RL); writebits(DDS_file,DDS_code(bits2),3); while (cnt2-->0) { tmp2=*ptr2++; if (ptr2-strip<=data) act2=tmp2-pre2; else act2=tmp2-pre2-*(ptr2-strip)+*(ptr2-strip-1); pre2=tmp2; while (act2<-128) act2+=256; while (act2>127) act2-=256; writebits(DDS_file,act2+(1<<bits2)/2,bits2); } } flushbits(DDS_file); fclose(DDS_file); if (nofree==0) free(data); else interleave(data,bytes,skip,DDS_INTERLEAVE); }
void imprime(rc_select *GLOBAL_DATA_SELECT, rc_parser *GLOBAL_PARSER) { int j, f, k, l,erro, x, y, yy, p, q, cont=0, aux, podeImprimi; struct fs_objects objeto, objetoJ; if(!verificaNomeTabela(GLOBAL_DATA_SELECT->objName)){ printf("\nERROR: relation \"%s\" was not found.\n\n\n", GLOBAL_DATA_SELECT->objName); return; } objeto = leObjeto(GLOBAL_DATA_SELECT->objName); tp_table *esquema = leSchema(objeto); if(esquema == ERRO_ABRIR_ESQUEMA){ printf("ERROR: schema cannot be created.\n"); free(esquema); return; } tp_buffer *bufferpoll = initbuffer(); if(bufferpoll == ERRO_DE_ALOCACAO ){ free(bufferpoll); free(esquema); printf("ERROR: no memory available to allocate buffer.\n"); return; } erro = SUCCESS; for(x = 0; erro == SUCCESS; x++) erro = colocaTuplaBuffer(bufferpoll, x, esquema, objeto); if(GLOBAL_DATA_SELECT->join == NULL){ if(GLOBAL_DATA_SELECT->nColumn == 0){ printf("**\n"); int ntuples = --x; p = 0; while(x){ column *pagina = getPage(bufferpoll, esquema, objeto, p); if(pagina == ERRO_PARAMETRO){ printf("ERROR: could not open the table.\n"); free(bufferpoll); free(esquema); return; } if(!cont) { for(j=0; j < objeto.qtdCampos; j++){ if(pagina[j].tipoCampo == 'S') printf(" %-20s ", pagina[j].nomeCampo); else printf(" %-10s ", pagina[j].nomeCampo); if(j<objeto.qtdCampos-1) printf("|"); } printf("\n"); for(j=0; j < objeto.qtdCampos; j++){ printf("%s",(pagina[j].tipoCampo == 'S')? "----------------------": "------------"); if(j<objeto.qtdCampos-1) printf("+"); } printf("\n"); } cont++; podeImprimi = 0; aux =0; for(k = 0; k < bufferpoll[p].nrec; k++){ if(GLOBAL_DATA_SELECT->where != NULL){ for(j=0; j < objeto.qtdCampos && podeImprimi != 1; j++){ podeImprimi = verificaWhere(GLOBAL_DATA_SELECT, pagina, j + aux); } } if(podeImprimi == 0){ for(j=0; j < objeto.qtdCampos ; j++){ if(pagina[j + aux].tipoCampo == 'S') printf(" %-20s ", pagina[j + aux].valorCampo); else if(pagina[j + aux].tipoCampo == 'I'){ int *n = (int *)&pagina[j + aux].valorCampo[0]; printf(" %-10d ", *n); } else if(pagina[j + aux].tipoCampo == 'C'){ printf(" %-10c ", pagina[j + aux].valorCampo[0]); } else if(pagina[j + aux].tipoCampo == 'D'){ double *n = (double *)&pagina[j + aux].valorCampo[0]; printf(" %-10f ", *n); } if(objeto.qtdCampos==j+1) printf("\n"); else printf("|"); } }else { ntuples--; } podeImprimi = 0; aux += objeto.qtdCampos; } x-=bufferpoll[p++].nrec; } printf("\n(%d %s)\n\n",ntuples,(1>=ntuples)?"row": "rows"); }else{ int ntuples = --x; p = 0; while(x){ //aqui deve ser carregado as tuplas com as clasulas do where passar o rc select pra carregar a pagina //creio que seja a melhor forma pois ai só tera as tuplas das projeções e não precisa mexer drasticamente a função imprime, //pois para baixo é apenas printfs column *pagina = getPage(bufferpoll, esquema, objeto, p); if(pagina == ERRO_PARAMETRO){ printf("ERROR: could not open the table.\n"); free(bufferpoll); free(esquema); return; } int z; if(!cont) { for(j=0; j < GLOBAL_DATA_SELECT->nColumn ; j++){ for(z=0; z < objeto.qtdCampos; z++) { if(strcmp(GLOBAL_DATA_SELECT->columnName[j],pagina[z].nomeCampo)==0){ if(pagina[j].tipoCampo == 'S') printf(" %-20s ", pagina[z].nomeCampo); else printf(" %-10s ", pagina[z].nomeCampo); if(j< GLOBAL_DATA_SELECT->nColumn-1) printf("|"); } } } printf("\n"); for(j=0; j < GLOBAL_DATA_SELECT->nColumn ; j++){ printf("%s",(pagina[j].tipoCampo == 'S')? "----------------------": "------------"); if(j<GLOBAL_DATA_SELECT->nColumn-1) printf("+"); } printf("\n"); } cont++; podeImprimi = 0, aux = 0; for(k = 0; k < bufferpoll[p].nrec; k++){ if(GLOBAL_DATA_SELECT->where != NULL){ for(j=0; j < objeto.qtdCampos && podeImprimi != 1; j++){ podeImprimi = verificaWhere(GLOBAL_DATA_SELECT, pagina, j + aux); } } if(podeImprimi == 0){ for(z=0; z < GLOBAL_DATA_SELECT->nColumn ; z++){ for(j=0; j < objeto.qtdCampos ; j++){ if(strcmp(GLOBAL_DATA_SELECT->columnName[z],pagina[j].nomeCampo)==0){ if(pagina[j + aux].tipoCampo == 'S') printf(" %-20s ", pagina[j + aux].valorCampo); else if(pagina[j + aux].tipoCampo == 'I'){ int *n = (int *)&pagina[j + aux].valorCampo[0]; printf(" %-10d ", *n); } else if(pagina[j + aux].tipoCampo == 'C'){ printf(" %-10c ", pagina[j + aux].valorCampo[0]); } else if(pagina[j + aux].tipoCampo == 'D'){ double *n = (double *)&pagina[j + aux].valorCampo[0]; printf(" %-10f ", *n); } if(GLOBAL_DATA_SELECT->nColumn==(z+1)) printf("\n"); else printf("|"); } } } }else { ntuples--; } podeImprimi = 0; aux += objeto.qtdCampos; } x-=bufferpoll[p++].nrec; } printf("\n(%d %s)\n\n",ntuples,(1>=ntuples)?"row": "rows"); } }else{ if(!verificaNomeTabela(GLOBAL_DATA_SELECT->join->table)){ printf("\nERROR: relation \"%s\" was not found.\n\n\n", GLOBAL_DATA_SELECT->join->table); return; } objetoJ = leObjeto(GLOBAL_DATA_SELECT->join->table); tp_table *esquemaJ = leSchema(objetoJ); if(esquemaJ == ERRO_ABRIR_ESQUEMA){ printf("ERROR: schema cannot be created.\n"); free(esquemaJ); return; } tp_buffer *bufferpollJ = initbuffer(); if(bufferpollJ == ERRO_DE_ALOCACAO ){ free(bufferpollJ); free(esquemaJ); printf("ERROR: no memory available to allocate buffer.\n"); return; } erro = SUCCESS; for(y = 0; erro == SUCCESS; y++) erro = colocaTuplaBuffer(bufferpollJ, y, esquemaJ, objetoJ); int ntuples = --x; y--; p = 0; while(x){ printf("while join x\n"); column *pagina = getPage(bufferpoll, esquema, objeto, p); if(pagina == ERRO_PARAMETRO){ printf("ERROR: could not open the table.\n"); free(bufferpoll); free(esquema); return; } column *paginaJ = getPage(bufferpollJ, esquemaJ, objetoJ, p); if(paginaJ == ERRO_PARAMETRO){ printf("ERROR: could not open the table.\n"); free(bufferpollJ); free(esquemaJ); return; } int podeImprimi = 0; if(!cont) { for(j=0; j < objeto.qtdCampos; j++){ if(pagina[j].tipoCampo == 'S') printf(" %-20s ", pagina[j].nomeCampo); else printf(" %-10s ", pagina[j].nomeCampo); if(j < (objeto.qtdCampos + objetoJ.qtdCampos)-1) printf("|"); } for(l = 0; l < objetoJ.qtdCampos ; l++){ if(pagina[ l + j].tipoCampo == 'S') printf(" %-20s ", paginaJ[ l+ j].nomeCampo); else printf(" %-10s ", paginaJ[l + j].nomeCampo); if(j < (objeto.qtdCampos + objetoJ.qtdCampos) - 1) printf("|"); } printf("\n"); for(j=0; j < objeto.qtdCampos + objetoJ.qtdCampos; j++){ printf("%s",(pagina[j].tipoCampo == 'S')? "----------------------": "------------"); } printf("\n"); } cont++; for(k = 0; k < bufferpoll[p].nrec; k++){ yy = y; q = 0; aux = 0; podeImprimi = 0; while(yy){ printf("while join y%d\n", yy); column *paginaJ = getPage(bufferpollJ, esquemaJ, objetoJ, q); if(paginaJ == ERRO_PARAMETRO){ printf("ERROR: could not open the table.\n"); free(bufferpollJ); free(esquemaJ); return; } for(l = 0; l < bufferpollJ[q].nrec; l++){ for(j = 0; j < objeto.qtdCampos && podeImprimi != 1; j++){ for(f = 0; f < objetoJ.qtdCampos && podeImprimi != 1; f++){ printf("P %s = %s\n",pagina[j].valorCampo , paginaJ[f].valorCampo); if(strcmp( pagina[j].nomeCampo, paginaJ[f].nomeCampo) == 0){ printf("nome campo igual\n"); if((pagina[j].tipoCampo == 'S' || pagina[j].tipoCampo == 'C' ) && (paginaJ[f].tipoCampo == 'S' || paginaJ[f].tipoCampo == 'C' )){ printf(" campo char\n"); if(strcmp(pagina[j].valorCampo, paginaJ[f].valorCampo) != 0){ podeImprimi = 1; printf("nome igual\n");} }else if(pagina[j].tipoCampo == 'I' && paginaJ[f].tipoCampo == 'I' ){ int c = (int)pagina[j].valorCampo[0]; int s = (int)paginaJ[f].valorCampo[0]; printf("P3 %d = %d\n", c, s); printf("P %d = %d\n", j, f); if(c != s){ podeImprimi = 1; /*printf("P %d = %d\n", *c, *s);*/ } }else if(pagina[j].tipoCampo == 'D' && paginaJ[f].tipoCampo == 'D' ){ double c = atof(pagina[j].valorCampo); double s = atof(paginaJ[f].valorCampo); if(c != s) podeImprimi = 1; } } } if(podeImprimi == 0){ for(j=0; j < objeto.qtdCampos ; j++){ if(pagina[j + aux].tipoCampo == 'S') printf(" %-20s ", pagina[j + aux].valorCampo); else if(pagina[j + aux].tipoCampo == 'I'){ int *n = (int *)&pagina[j + aux].valorCampo[0]; printf(" %-10d ", *n); } else if(pagina[j + aux].tipoCampo == 'C'){ printf(" %-10c ", pagina[j + aux].valorCampo[0]); } else if(pagina[j + aux].tipoCampo == 'D'){ double *n = (double *)&pagina[j + aux].valorCampo[0]; printf(" %-10f ", *n); } if((objeto.qtdCampos+objetoJ.qtdCampos) != j + 1) printf("|"); } aux += objeto.qtdCampos; for(j = 0; j < objeto.qtdCampos ; j++){ if(paginaJ[j + aux].tipoCampo == 'S') printf(" %-20s ", paginaJ[j + aux].valorCampo); else if(paginaJ[j + aux].tipoCampo == 'I'){ int *n = (int *)&paginaJ[j + aux].valorCampo[0]; printf(" %-10d ", *n); } else if(paginaJ[j + aux].tipoCampo == 'C'){ printf(" %-10c ", paginaJ[j + aux].valorCampo[0]); } else if(paginaJ[j + aux].tipoCampo == 'D'){ double *n = (double *)&paginaJ[j + aux].valorCampo[0]; printf(" %-10f ", *n); } if((objeto.qtdCampos+objetoJ.qtdCampos)==j+1) printf("\n"); else printf("|"); } aux += objetoJ.qtdCampos; }else { ntuples--; } podeImprimi = 0; aux += objeto.qtdCampos; } } yy-=bufferpollJ[q++].nrec ; } yy = y; } x-=bufferpoll[p++].nrec ; } printf("\n(%d %s)\n\n",ntuples,(1>=ntuples)?"row": "rows"); } free(bufferpoll); free(esquema); }
int main (int argc, char *argv[]) { int err=0, len=0, i; struct sockaddr_in sa; int ssa = sizeof(struct sockaddr_in); char c; struct hostent *hp; if (argc != 3) { fprintf(stderr, "usage: client <own hostname> <remote hostname>\n"); exit(1); } signal(SIGTERM, closesock); signal(SIGINT, closesock); signal(SIGKILL, closesock); signal(SIGSTOP, closesock); initsem(); initbuffer(); s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (s<0) { Wait(&sem_dump); perror("socket"); Signal(&sem_dump); goto end; } hp = gethostbyname(argv[1]); if (hp != NULL) { memset((char *)&sa, sizeof(sa), 0); memcpy(&sa.sin_addr,hp->h_addr,hp->h_length); sa.sin_family = hp->h_addrtype; } else { sa.sin_family = AF_INET; sa.sin_addr.s_addr = inet_addr(argv[1]); } sa.sin_port = htons(7777); if (sa.sin_addr.s_addr == INADDR_NONE) { fprintf(stderr, "bad address\n"); exit(1); } err = bind (s, (caddr_t)&sa, ssa); if (err) { Wait(&sem_dump); perror("bind"); Signal(&sem_dump); goto end; } #if DEBUG val = 1; err = setsockopt (s, SOL_SOCKET, SO_DEBUG, &val, sizeof(val)); if (err) { Wait(&sem_dump); perror("setsockopt"); Signal(&sem_dump); goto end; } val = 4; err = getsockopt (s, SOL_SOCKET, SO_DEBUG, valbuf, &val); if (err) { Wait(&sem_dump); perror("getsockopt"); Signal(&sem_dump); goto end; } Wait(&sem_dump); if (*((int *)valbuf) == SO_DEBUG) fprintf(stderr,"socket option set to SO_DEBUG\n"); else fprintf(stderr,"failed to set socket option to SO_DEBUG\n"); Signal(&sem_dump); #endif #if OOBINLINE val = 1; err = setsockopt (s, SOL_SOCKET, SO_OOBINLINE, &val, sizeof(val)); if (err) { Wait(&sem_dump); perror("setsockopt"); Signal(&sem_dump); goto end; } val = 4; err = getsockopt (s, SOL_SOCKET, SO_OOBINLINE, valbuf, &val); if (err) { Wait(&sem_dump); perror("getsockopt"); Signal(&sem_dump); goto end; } Wait(&sem_dump); if (*((int *)valbuf) == SO_OOBINLINE) fprintf(stderr,"socket option set to SO_OOBINLINE\n"); else fprintf(stderr,"failed to set socket option to SO_OOBINLINE\n"); Signal(&sem_dump); #endif #if KEEPALIVE val = 1; err = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)); if (err) { Wait(&sem_dump); perror("setsockopt"); Signal(&sem_dump); goto end; } val = 4; err = getsockopt (s, SOL_SOCKET, SO_KEEPALIVE, valbuf, &val); if (err) { Wait(&sem_dump); perror("getsockopt"); Signal(&sem_dump); goto end; } Wait(&sem_dump); if (*((int *)valbuf) == SO_KEEPALIVE) fprintf(stderr,"socket option set to SO_KEEPALIVE\n"); else fprintf(stderr,"failed to set socket option to SO_KEEPALIVE\n"); Signal(&sem_dump); #endif /* val = 4; err = getsockopt (s, SOL_SOCKET, SO_RCVBUF, valbuf, &val); if (err) { Wait(&sem_dump); perror("getsockopt"); Signal(&sem_dump); goto end; } rcvbuf = MIN(rcvbuf, *((int *)valbuf)); Wait(&sem_dump); fprintf(stderr,"initial SO_RCVBUF: %d\n", rcvbuf); Signal(&sem_dump); */ #ifdef RCVBUF val = RCVBUF; err = setsockopt (s, SOL_SOCKET, SO_RCVBUF, &val, sizeof(val)); if (err) { Wait(&sem_dump); perror("setsockopt"); Signal(&sem_dump); goto end; } /* val = 4; err = getsockopt (s, SOL_SOCKET, SO_RCVBUF, valbuf, &val); if (err) { Wait(&sem_dump); perror("getsockopt"); Signal(&sem_dump); goto end; } rcvbuf = *((int *)valbuf); Wait(&sem_dump); fprintf(stderr,"now is SO_RCVBUF: %d\n", rcvbuf); Signal(&sem_dump); */ #endif /* val = 4; err = getsockopt (s, SOL_SOCKET, SO_SNDBUF, valbuf, &val); if (err) { Wait(&sem_dump); perror("getsockopt"); Signal(&sem_dump); goto end; } sndbuf = MIN(sndbuf, *((int *)valbuf)); Wait(&sem_dump); fprintf(stderr,"initial SO_SNDBUF: %d\n", sndbuf); Signal(&sem_dump); */ #ifdef SNDBUF val = SNDBUF; err = setsockopt (s, SOL_SOCKET, SO_SNDBUF, &val, sizeof(val)); if (err) { Wait(&sem_dump); perror("setsockopt"); Signal(&sem_dump); goto end; } /* val = 4; err = getsockopt (s, SOL_SOCKET, SO_SNDBUF, valbuf, &val); if (err) { Wait(&sem_dump); perror("getsockopt"); Signal(&sem_dump); goto end; } sndbuf = *((int *)valbuf); Wait(&sem_dump); fprintf(stderr,"now is SO_SNDBUF: %d\n", sndbuf); Signal(&sem_dump); */ #endif /* Wait(&sem_dump); fprintf(stderr,"Press return to continue ..."); fflush(stderr); while((c = getchar())!='\n'); Signal(&sem_dump); */ hp = gethostbyname(argv[2]); if (hp != NULL) { memset((char *)&sa, sizeof(sa), 0); memcpy(&sa.sin_addr,hp->h_addr,hp->h_length); sa.sin_family = hp->h_addrtype; } else { sa.sin_family = AF_INET; sa.sin_addr.s_addr = inet_addr(argv[2]); } sa.sin_port = htons(8000); if (sa.sin_addr.s_addr == INADDR_NONE) { fprintf(stderr, "bad address\n"); exit(1); } Wait(&sem_dump); fprintf(stderr,"connecting...\n"); fflush(stderr); Signal(&sem_dump); err = connect (s, (caddr_t)&sa, ssa); if (err) { Wait(&sem_dump); perror("connect"); Signal(&sem_dump); goto end; } { int on = 1; ioctl(s, FIONBIO, &on); } Wait(&sem_dump); fprintf(stderr,"connected!!!\n"); fflush(stderr); fprintf(stderr,"\nFork(monitor_process) == %d\n", Fork(2000,monitor_process, 4, s)); fprintf(stderr,"\nFork(receiver) == %d\n", Fork(8000,receiver, 4, s)); Signal(&sem_dump); { extern char *inet_ntoa(); static struct sockaddr_in local, peer; int ssa, err = 0; ssa = sizeof(struct sockaddr_in); err = getsockname(s, &local, &ssa); if (err) { Wait(&sem_dump); perror("getsockname"); Signal(&sem_dump); } ssa = sizeof(struct sockaddr_in); err = getpeername(s, &peer, &ssa); if (err) { Wait(&sem_dump); perror("getpeername"); Signal(&sem_dump); } Wait(&sem_dump); fprintf(stderr," addressfamily port# internetaddress\n"); fprintf(stderr,"local Socket: %d %d %s\n" , local.sin_family, ntohs(local.sin_port) , inet_ntoa(local.sin_addr.s_addr)); fprintf(stderr,"remote Socket: %d %d %s\n" , peer.sin_family, ntohs(peer.sin_port) , inet_ntoa(peer.sin_addr.s_addr)); fprintf(stderr,"\n"); Signal(&sem_dump); } forever { int len; /* len = MIN(BUFFER - snd_p, MAX(abs(_ldtimer(0)%sndbuf),12) ); */ len = sndbuf/2; /* err = send (s, &buffer[snd_p], len, 0); */ s1: err = send (s, buffer, len, 0); if (err < 0) { if (errno = EWOULDBLOCK) goto s1; Wait(&sem_dump); perror("send"); Signal(&sem_dump); goto end; } count_s += err; /* snd_p = ((snd_p + err) < BUFFER) ? (snd_p + err) : (snd_p + err - BUFFER); */ } end: Wait(&sem_dump); return(0); }