Ejemplo n.º 1
0
static int helloworld_handler(request_rec* r) {
    if ( !r->handler || strcmp(r->handler, "helloworld") ) {
        return DECLINED ;   /* none of our business */
        }
    if ( r->method_number != M_GET ) {
        return HTTP_METHOD_NOT_ALLOWED ;  /* Reject other methods */
        }
    ap_set_content_type(r, "text/html;charset=ascii") ;
    ap_rputs(
        "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n", r) ;
    ap_rputs(
        "<html><head><title>Apache HelloWorld Module</title></head>", r) ;
    ap_rputs("<body><h1>Hello World!</h1>", r) ;
    ap_rputs("<p>This is the Apache HelloWorld module!</p>", r) ;

    /* Print the headers and env */
    /* Note that the response headers and environment may be empty at
     * this point.  The CGI environment is an overhead we dispense
     * with in a module, unless another module that requires it
     * (e.g. mod_rewrite) has set it up.
     */
    printtable(r, r->headers_in, "Request Headers", "Header", "Value") ;
    printtable(r, r->headers_out, "Response Headers", "Header", "Value") ;
    printtable(r, r->subprocess_env, "Environment", "Variable", "Value") ;

    ap_rputs("</body></html>", r) ;
    return OK ;
    }
Ejemplo n.º 2
0
int main(int argc, char*argv[]){
  uint32_t i;
  uint32_t result;
  uint32_t out;
  int k=0;
  int del = 0;
  int table[128];

  i=0;
  while(i<128){
    table[i]=0;
    i++;
  }

  k=0;
  i = (127 << 23) + (0 << 14);
  while(k < 16384*1024){
    result=fsqrt_s(i);
    out = fsqrt(i,0);
    del = out - result;
    table[del+64] = table[del+64]+1;
    k++;
    i++;
  }
      
  printtable(table);
  return 0;

}
Ejemplo n.º 3
0
std::ostream& operator<<(std::ostream& os, Unit x){
  os << "Unit(" << ind << iendl 
     << x->name;
  os << iendl << "PARENTS";
  printtable(os, x->parents, x->parentCount);
  os << iendl << "GLOBALS";
  printtable(os, x->globals, x->globalCount);
  os << iendl << "CONSTRUCTORS";
  printtable(os, x->constructors, x->constructorCount);
  os << iendl << "NATIVEFUNCS";
  printtable(os, x->nativeFuncs, x->nativeFuncCount);
  os << iendl << "NATIVEPREDS";
  printtable(os, x->nativePreds, x->nativePredCount);
  os << iendl << "DENOTATIONS";
  printtable(os, x->denotations, x->denotationCount);
  os << iendl << "initSchemaIndex=" << x->initSchemaIndex;
  os << iendl << "SCHEMAS";
  printtable(os, x->schemas, x->schemaCount);
  os << iendl << "CODE";
  int step = 0;
  while (step < x->codeSize){
    os << iendl;
    printNext(os, x->code, step);
  }
  os << unind << ")" << iendl;
  return os;
}
Ejemplo n.º 4
0
/* dump out a Paragraph in the desired manner
 */
static Paragraph*
display(Paragraph *p, MMIOT *f)
{
    if ( !p ) return 0;
    
    switch ( p->typ ) {
    case STYLE:
    case WHITESPACE:
	break;

    case HTML:
	printhtml(p->text, f);
	break;
	
    case CODE:
	printcode(p->text, f);
	break;
	
    case QUOTE:
	htmlify(p->down, p->ident ? "div" : "blockquote", p->ident, f);
	break;
	
    case UL:
    case OL:
    case AL:
	listdisplay(p->typ, p->down, f);
	break;

#if DL_TAG_EXTENSION
    case DL:
	definitionlist(p->down, f);
	break;
#endif

    case HR:
	Qstring("<hr />", f);
	break;

    case HDR:
	printheader(p, f);
	break;

    case TABLE:
	printtable(p, f);
	break;

    case SOURCE:
	htmlify(p->down, 0, 0, f);
	break;
	
    default:
	printblock(p, f);
	break;
    }
    return p->next;
}
Ejemplo n.º 5
0
int main(int argc, char*argv[]){
  uint32_t i,j;
  uint32_t result;
  uint32_t out;
  int k=0;
  int del = 0;
  int table[128];

  i=0;
  while(i<128){
    table[i]=0;
    i++;
  }
  //j=9;
  //while(j<1024){
  j=0;
  k=0;
  i = (127 << 23) + (j << 13);
  while(k < 8192*1024){
    result=finv_s(i);
    out = finv(i,0);
    del = out - result;
    table[del+64] = table[del+64]+1;
    k++;
    i++;
  }
  /*if(table[69]){
   i=0;
  while(i<128){
    table[i]=0;
    i++;
  }
    k=0;
  i = (127 << 23) + (j << 13);
  while(k < 8192){
    result=finv_s(i);
    out = finv(i,0);
    del = out - result;
    table[del+64] = table[del+64]+1;
    k++;
    i++;
  }
   printf("offset=%d\n",j);
   printtable(table);
   return 1;
   }
  j++; 
  }*/
  printtable(table);
  return 0;

}
Ejemplo n.º 6
0
static K printq(K x)
{
    K result;
    
    if (xt < 0) result = printatom(x);
    else if ((xt >= 0) && (xt < 20)) result = printlist(x);
    else if (xt == 98) result = printtable(x);
    else if (xt == 99) result = printdict(x);
    else result = krr((S)"notimplemented");
    
    printf("\n");
    return result;
}
Ejemplo n.º 7
0
Archivo: rand.c Proyecto: erikg/rand
   /**
    * scramble function, for io_pipes and files (not parm).
    * @param method The method type, as defined in the enum.
    * @return Void Nothing.
    * @author Erik Greenwald <*****@*****.**>
    * @remarks Thanks to Dr Eric Shade for helping out.
    */
void
scramble (char method, FILE * io_pipes[2])
{
    char **table = NULL;
    int size = 0;

    if (method == LINE || method == WORD)
    {
	struct ll *ptr = NULL;

	   /*** make linked list     ***/
	if (method == LINE)
	    ptr = readlines (io_pipes, &size);
	if (method == WORD)
	    ptr = readwords (io_pipes, &size);

	   /*** make table from list ***/

	if (size == 0)
	    return;

	table = (char **)malloc (size * sizeof (void *));
	if (table == NULL)
	{
	    printf ("%s", NOMEM);
	    return;
	}

	list_to_table (ptr, table, size);

	   /*** delete the linked list and clean up ***/
	freelist (ptr);
    }

    /*
     * shuffle it  (thanks to Dr Shade)
     */
    shuffle (table, size);

   /*** print it   ***/

    printtable (table, size, io_pipes[1]);

    freetable (table, size);
    free (table);
    return;
}
Ejemplo n.º 8
0
static int dist_generate(int argc, char *argv[])
{
	FILE *fp;
	double mu, sigma, rho;

	if (argc == 1) {
		if (!(fp = fopen(argv[0], "r")))
			error(-1, errno, "Failed to open file: %s", argv[0]);
	}
	else
		fp = stdin;

	short *inverse = dist_make(fp, &mu, &sigma, &rho);
	if (!inverse)
		error(-1, 0, "Failed to generate distribution");

	printtable(inverse, TABLESIZE);

	return 0;
}
Ejemplo n.º 9
0
int
main(int argc, char **argv)
{
	FILE *fp;
	double *x;
	double mu, sigma, rho;
	int limit;
	int *table;
	short *inverse;
	int total;

	if (argc > 1) {
		if (!(fp = fopen(argv[1], "r"))) {
			perror(argv[1]);
			exit(1);
		}
	} else {
		fp = stdin;
	}
	x = readdoubles(fp, &limit);
	if (limit <= 0) {
		fprintf(stderr, "Nothing much read!\n");
		exit(2);
	}
	arraystats(x, limit, &mu, &sigma, &rho);
#ifdef DEBUG
	fprintf(stderr, "%d values, mu %10.4f, sigma %10.4f, rho %10.4f\n",
		limit, mu, sigma, rho);
#endif

	table = makedist(x, limit, mu, sigma);
	free((void *) x);
	cumulativedist(table, DISTTABLESIZE, &total);
	inverse = inverttable(table, TABLESIZE, DISTTABLESIZE, total);
	interpolatetable(inverse, TABLESIZE);
	printtable(inverse, TABLESIZE);
	return 0;
}
Ejemplo n.º 10
0
int main(void)
{
   list *head, *tail, *current;

   int mode = 0;

   head = tail = current = NULL;
   while (1)
   {
      puts("[1] 테이블 생성");
      puts("[2] 테이블 입력");
      puts("[3] 테이블 삭제");
      puts("[4] 데이터 삭제");
      puts("[5] 출력");
      puts("[6] 검색");
      puts("[7] 저장");
      puts("[8] 로드");
      puts("[0] 종료");
      scanf("%d%*c", &mode);
      if (mode == 1)
      {
         current = makelist();
         putlist(&head, &tail, current);
      }
      else if (mode == 2)
      {
         simpleinput(head);
      }
      else if (mode == 3)
      {
         deltable(&head, &tail);
      }
      else if (mode == 4)
      {
         killvar(head);
      }
      else if (mode == 5)
      {
         printtable(head);
      }
      else if (mode == 6)
      {
         search(head);
      }
      else if (mode == 7)
      {
         save(head);
      }
      else if (mode == 8)
      {
         head = tail = current = NULL;
         load(&head, &tail);
      }
      else if (mode == 0)
      {
         exit(1);
      }
      else
      {
         continue;
      }
   }
}
Ejemplo n.º 11
0
extern void
flushout (struct table *p)

{
  char *name;
  FILE *outfile;
  struct llist *lptr;
  int i,j;
  char *newvar1,*newvar2;
  int printed;

  name = getfilename(p->procname);

#ifdef DEBUG
  printf("\n\n name: %s\n",name);
  printf("entry: \n");
  printtable(p);
#endif


  outfile = fopen(name,"w");
  if (outfile == NULL) {
	fprintf(stderr,"ERROR: unable to open %s\n",name);
	exit(1);
  }


/* print includes
 */
  for (lptr = p->includs; lptr != NULL; lptr= lptr->nextl)
	  fprintf(outfile,"#include %s\n",lptr->entry);
  
/* print proc name
 */
  fprintf(outfile,"\n%s",p->procname);


/* print parameters in proc line 
 */
  for (i = 0; i< p->declnum; i++){
        fprintf(outfile," x%d",i);
	if (i !=  p->declnum-1)
		fprintf(outfile,",");
  }
  fprintf(outfile,")\n");

/* print var declarations
 */
  i = 0;
  for (lptr = p->decls; lptr != NULL; lptr= lptr->nextl){
	printed = FALSE;
	for (j=0; lptr->entry[j] != '\0'; j++){
		if (lptr->entry[j] == '[') {
			printed = TRUE;
			newvar1 = (char *) calloc(1,40);
			strncpy(newvar1,lptr->entry,j);
			newvar2 = (char *) calloc(1,40);
			strcpy(newvar2,&(lptr->entry[j]));
		   	fprintf(outfile,"%s x%d %s;\n",newvar1,i++,newvar2);
		}
	}
			
	   if (!printed) fprintf(outfile,"%s x%d;\n",lptr->entry,i++);
  }

/* print body
 */
  
  fprintf(outfile,"{\n");

 /* use procn, set by getfilename as system name called
 */
  fprintf(outfile,"\nreturn(%s(",procn);

  for (i=0; i< p->declnum; i++){
        fprintf(outfile," x%d",i);
	if (i !=  p->declnum-1)
		fprintf(outfile,",");
  }
  fprintf(outfile,"));\n}\n");


  if (fclose(outfile) != 0)
	perror(name);
}
Ejemplo n.º 12
0
Archivo: test.c Proyecto: cpu2015g6/FPU
int main(int argc, char*argv[]){
  int failed=0;
  uint32_t i;
  uint32_t result;
  uint32_t out;
  int aaa[1024];
  int k=0;
  int m=0;
  int del = 0;
  int table[128];

  if(argc < 4){
   printf("few args!!\n");
   return 1;
  }

  i=0;
  while(i<128){
    table[i]=0;
    i++;
  }
  int offset = atoi(argv[1]);
  int offset_term = atoi(argv[2]);
  i=(127<<23) + (offset << 13);

  int j=0 - (atoi(argv[3]));
  int dist=1000;
  int best=0;

  while(offset < offset_term){

    dist=1000;
    j=0 - (atoi(argv[3]));

    while(j < atoi(argv[3]) + 1){

      k=0;
      i=(127<<23) + (offset << 13);

      while(k < 8192*1024){
	result=finv_s(i);
	out = finv(i,j);
	del = out - result;
	/*if(del > 4 || del < -4){
	  printf("offset: %d\n",offset);
	  printf("del: %d\n",del);
	  printbin(i);
	  printbin(out);
	  printbin(result);
	  return 0;
	  }*/
	table[del+64] = table[del+64]+1;
	k++;
	i++;
      }
      
      printtable(table);
      return 1;
      

      if(distri(table) < dist){
	best = j;
	dist = distri(table);
      }

      m=0;
      while(m<128){
	table[m]=0;
	m++;
      }
      
      j++;
    }
    
    k=0;
    i=(127<<23) + (offset << 13);
     while(k < 8192){
	result=finv_s(i);
	out = finv(i,best);
	del = out - result;
	table[del+64] = table[del+64]+1;
	k++;
	i++;
      }

     //print23bin(ctou(dummy[offset]));
     //printtable(table);
     //printf("%d\n",lub(table));
     aaa[offset] = 0 - ((lub(table)+glb(table)) /2);
     /*m=0;
     while(m<128){
       table[m]=0;
       m++;
     }*/
    
     if(dist < 10){
       fprintf(stderr,"clear: offset=%d,dist=%d,exp=%d,best=%d,glb=%d,lub=%d\n",offset,dist,aaa[offset],best,glb(table),lub(table));
    }else{
       fprintf(stderr,"FAILED...: offset=%d,dist=%d,exp=%d,best=%d,glb=%d,lub=%d\n",offset,dist,aaa[offset],best,glb(table),lub(table));
      failed++;
      }
    fprintf(stderr,"sinchoku...%d/%d\n",offset-atoi(argv[1]),atoi(argv[2])-atoi(argv[1]));
    incdecprint2(dummy2,best,offset);

      m=0;
      while(m<128){
	table[m]=0;
	m++;
      }

      offset++;
  }
  offset=atoi(argv[1]);
  while(offset < atoi(argv[2])){
    incdecprint(dummy,aaa[offset],offset);
    offset++;
  }

	//printf("best case: %d dist: %d\n",best,dist);
  fprintf(stderr,"failed cases: %d/%d\n",failed,atoi(argv[2])-atoi(argv[1]));
  
  return 0;
}
Ejemplo n.º 13
0
/* dump out a Paragraph in the desired manner
 */
static Paragraph*
display(Paragraph *p, MMIOT *f, int easyNewLine)
{
    if ( !p ) return 0;

    switch ( p->typ ) {
    case STYLE:
    case WHITESPACE:
	break;

    case HTML:
	printhtml(p->text, f);
	break;
	
    case CODE:
	printcode(p->text, f);
	break;
	
    case QUOTE:
    if (p->down) {
        p->down->easyNewline = p->easyNewline;
    }
	htmlify(p->down, p->ident ? "div" : "blockquote", p->ident, f);
	break;
	
    case UL:
    case OL:
    case AL:
	listdisplay(p->typ, p->down, f);
	break;

    case DL:
	definitionlist(p->down, f);
	break;

    case HR:
	Qstring("<hr />", f);
	break;

    case HDR:
	printheader(p, f);
	break;

    case TABLE:
	printtable(p, f);
	break;

    case SOURCE:
    if (p->down) {
        p->down->easyNewline = p->easyNewline;
    }
	htmlify(p->down, 0, 0, f);
	break;
	
    default:
	printblock(p, f, easyNewLine);
	break;
    }
    // MK HACK, copy easyNewLine
    Paragraph *pNext = p->next;
    if (pNext) {
        pNext->easyNewline = p->easyNewline;
    }
    return pNext;
}
Ejemplo n.º 14
0
int
main (void) 
{
    initRecordManager(NULL);
    int in;
    int cl = 0;
    while(cl == 0){
        printf("What to do:\n1.Add new table\n2.insert\n3.update\n4.delete\n5.scan\n6.print table\n7.close\n");
        in=0;
        scanf("%d",&in);
        RM_TableData *table;
        Record *result,*r;
        Value *value,*v;
        int i,j;
        switch(in)
        {
            case 0:
                printf("invalid input\n");
                break;
            case 1:
                printf("\nAdding new table:\n");
                printf("Table name: ");
                char tbn[50];
                scanf("%s",tbn);
                char* tbnp = (char *) malloc(sizeof(char)*sizeof(tbn));
                memcpy(tbnp,tbn,sizeof(tbn));
                printf("number of attributes: ");
                int nat = 0;
                scanf("%d",&nat);
                printf("number of keys: ");
                int nk = 0;
                scanf("%d",&nk);
                Schema *sch;
                char **names = (char **) malloc(sizeof(char*) * nat);
                DataType* dt = (DataType *) malloc(sizeof(DataType) * nat);
                int* sizes = (int *) malloc(sizeof(int) * nat);
                int* keys = (int *) malloc(sizeof(int) * nk);
                int kptr = 0;
                for(i=0;i<nat;i++){
                    printf("Attribute %d name:  ", i+1);
                    char buf[100];
                    scanf("%s", buf);
                    char* tmp = (char *) malloc(sizeof(char)*sizeof(buf));
                    memcpy(tmp,buf,sizeof(buf));
                    names[i] = tmp;
                    printf("Attribute %d datatype: [I/S/F/B]: ", i+1);
                    char dtp;
                    scanf(" %c", &dtp);
                    //printf("\ndtp = %c", dtp);
                    switch(dtp)
                    {
                        case 'I':
                            dt[i] = DT_INT;
                            sizes[i] = 0;
                            break;
                        case 'S':
                            dt[i] = DT_STRING;
                            printf("Attribute %d length:  ", i+1);
                            scanf("%d",&sizes[i]);
                            printf("length is: %d\n", sizes[i]);
                            break;
                        case 'F':
                            dt[i] = DT_FLOAT;
                            sizes[i] = 0;
                            break;
                        case 'B':
                            dt[i] = DT_BOOL;
                            sizes[i] = 0;
                            break;
                            
                    }
                    printf("Is Attribute %d a key?: [Y/N] ", i+1);
                    char isk;
                    scanf(" %c", &isk);
                    if(isk == 'Y'){
                        keys[kptr] = i;
                        kptr++;
                    }
                    //printf("schema add: %s,%d,%c\n",names[i],sizes[i],isk);
                }
                sch = createSchema(nat,names,dt,sizes,nk,keys);
                createTable(tbnp,sch);
                break;
            case 2:
                printf("Insert record\n");
                printf("table name: ");
                char buf2[100];
                scanf("%s", buf2);
                char* tmp2 = (char *) malloc(sizeof(char)*sizeof(buf2));
                memcpy(tmp2,buf2,sizeof(buf2));
                table = (RM_TableData *) malloc(sizeof(RM_TableData));
                openTable(table, tmp2);
                createRecord(&result, table->schema);
               for(i=0;i<table->schema->numAttr;i++){
                    if(table->schema->dataTypes[i] == DT_INT)
                    {
                        printf("intput int attr[%d/%d] value -- %s: ", i+1,table->schema->numAttr,table->schema->attrNames[i]);
                        int intt = 0;
                        scanf("%d",&intt);
                        //printf("\n%d is %d\n", i, intt);
                        MAKE_VALUE(value,DT_INT,intt);
                        setAttr(result, table->schema, i, value);
                        freeVal(value);
                    } else if (table->schema->dataTypes[i] == DT_STRING)
                    {
                        printf("intput string attr[%d/%d] value -- %s: ", i+1,table->schema->numAttr,table->schema->attrNames[i]);
                        char instrbuf[100];
                        scanf("%s",instrbuf);
                        char* instr = (char *) malloc(sizeof(char)*sizeof(instrbuf));
                        memcpy(instr,instrbuf,sizeof(instrbuf));
                        MAKE_STRING_VALUE(value,instr);
                        setAttr(result, table->schema, i, value);
                        freeVal(value);
                    } else if (table->schema->dataTypes[i] == DT_FLOAT)
                    {
                        printf("intput float attr[%d/%d] value -- %s: ", i+1,table->schema->numAttr,table->schema->attrNames[i]);
                        float infl;
                        scanf("%fl",&infl);
                        MAKE_VALUE(value,DT_FLOAT,infl);
                        setAttr(result, table->schema, i, value);
                        freeVal(value);
                    } else if (table->schema->dataTypes[i] == DT_BOOL)
                    {
                        printf("intput boolean attr[%d/%d] value -- %s [T/F]: ", i+1,table->schema->numAttr,table->schema->attrNames[i]);
                        char inbl;
                        scanf(" %c",&inbl);
                        if(inbl == 'T'){
                            MAKE_VALUE(value,DT_BOOL,true);
                        }
                        else if (inbl == 'F'){
                            MAKE_VALUE(value,DT_BOOL,false);
                        }
                        setAttr(result, table->schema, i, value);
                        freeVal(value);
                    }
                    if(i==table->schema->numAttr-1){
                        printf("\n");
                    }
                }
                insertRecord(table,result);
                
                break;
            case 3:
                printf("update record\n");
                printf("table name: ");
                char buf3[100];
                scanf("%s", buf3);
                char* tmp3 = (char *) malloc(sizeof(char)*sizeof(buf3));
                memcpy(tmp3,buf3,sizeof(buf3));
                table = (RM_TableData *) malloc(sizeof(RM_TableData));
                openTable(table, tmp3);
                createRecord(&result, table->schema);
                
                r = (Record *) malloc(sizeof(Record));
                RM_ScanHandle *sc = (RM_ScanHandle *) malloc(sizeof(RM_ScanHandle));
                startScan(table, sc, NULL);
                
                printf("Select record to update: \n");
                j=0;
                int rids[100][2];
                while(next(sc, r) == RC_OK){
                    printf("(%d)   ",j+1);
                    rids[j][0] = r->id.page;
                    rids[j][1] = r->id.slot;
                    for(i=0;i<table->schema->numAttr;i++){
                        if(table->schema->dataTypes[i] == DT_INT)
                        {
                            getAttr(r,table->schema,i,&v);
                            printf("%-15d",v->v.intV);
                        } else if(table->schema->dataTypes[i] == DT_STRING)
                        {
                            getAttr(r,table->schema,i,&v);
                            printf("%-15s",v->v.stringV);
                        } else if(table->schema->dataTypes[i] == DT_FLOAT)
                        {
                            getAttr(r,table->schema,i,&v);
                            printf("%-15fl",v->v.floatV);
                        } else if(table->schema->dataTypes[i] == DT_BOOL)
                        {
                            getAttr(r,table->schema,i,&v);
                            printf("%-15s",v->v.boolV ? "true" : "false");
                        }
                    }
                    printf("\n");
                    j++;
                }
                
                int sele;
                scanf("%d", &sele);
                sele--;
                if(sele >= 0 && sele < j+1){
                    createRecord(&result, table->schema);
                    for(i=0;i<table->schema->numAttr;i++){
                        if(table->schema->dataTypes[i] == DT_INT)
                        {
                            printf("intput int attr[%d/%d] value -- %s: ", i+1,table->schema->numAttr,table->schema->attrNames[i]);
                            int intt = 0;
                            scanf("%d",&intt);
                            //printf("\n%d is %d\n", i, intt);
                            MAKE_VALUE(value,DT_INT,intt);
                            setAttr(result, table->schema, i, value);
                            freeVal(value);
                        } else if (table->schema->dataTypes[i] == DT_STRING)
                        {
                            printf("intput string attr[%d/%d] value -- %s: ", i+1,table->schema->numAttr,table->schema->attrNames[i]);
                            char instrbuf[100];
                            scanf("%s",instrbuf);
                            char* instr = (char *) malloc(sizeof(char)*sizeof(instrbuf));
                            memcpy(instr,instrbuf,sizeof(instrbuf));
                            MAKE_STRING_VALUE(value,instr);
                            setAttr(result, table->schema, i, value);
                            freeVal(value);
                        } else if (table->schema->dataTypes[i] == DT_FLOAT)
                        {
                            printf("intput float attr[%d/%d] value -- %s: ", i+1,table->schema->numAttr,table->schema->attrNames[i]);
                            float infl;
                            scanf("%fl",&infl);
                            MAKE_VALUE(value,DT_FLOAT,infl);
                            setAttr(result, table->schema, i, value);
                            freeVal(value);
                        } else if (table->schema->dataTypes[i] == DT_BOOL)
                        {
                            printf("intput boolean attr[%d/%d] value -- %s [T/F]: ", i+1,table->schema->numAttr,table->schema->attrNames[i]);
                            char inbl;
                            scanf(" %c",&inbl);
                            if(inbl == 'T'){
                                MAKE_VALUE(value,DT_BOOL,true);
                            }
                            else if (inbl == 'F'){
                                MAKE_VALUE(value,DT_BOOL,false);
                            }
                            setAttr(result, table->schema, i, value);
                            freeVal(value);
                        }
                        if(i==table->schema->numAttr-1){
                            printf("\n");
                        }
                    }
                    result->id.page = rids[sele][0];
                    result->id.slot = rids[sele][1];
                    updateRecord(table,result);
                }
                break;
            case 4:
                printf("delete record\n");
                printf("table name: ");
                char buf4[100];
                scanf("%s", buf4);
                char* tmp4 = (char *) malloc(sizeof(char)*sizeof(buf3));
                memcpy(tmp4,buf4,sizeof(buf4));
                table = (RM_TableData *) malloc(sizeof(RM_TableData));
                openTable(table, tmp4);
                createRecord(&result, table->schema);
                
                r = (Record *) malloc(sizeof(Record));
                RM_ScanHandle *sc2 = (RM_ScanHandle *) malloc(sizeof(RM_ScanHandle));
                startScan(table, sc2, NULL);
                
                printf("Select record to delete: \n");
                j=0;
                int rids2[100][2];
                while(next(sc2, r) == RC_OK){
                    printf("(%d)   ",j+1);
                    rids2[j][0] = r->id.page;
                    rids2[j][1] = r->id.slot;
                    for(i=0;i<table->schema->numAttr;i++){
                        if(table->schema->dataTypes[i] == DT_INT)
                        {
                            getAttr(r,table->schema,i,&v);
                            printf("%-15d",v->v.intV);
                        } else if(table->schema->dataTypes[i] == DT_STRING)
                        {
                            getAttr(r,table->schema,i,&v);
                            printf("%-15s",v->v.stringV);
                        } else if(table->schema->dataTypes[i] == DT_FLOAT)
                        {
                            getAttr(r,table->schema,i,&v);
                            printf("%-15fl",v->v.floatV);
                        } else if(table->schema->dataTypes[i] == DT_BOOL)
                        {
                            getAttr(r,table->schema,i,&v);
                            printf("%-15s",v->v.boolV ? "true" : "false");
                        }
                    }
                    printf("\n");
                    j++;
                }
                
                int sele2;
                scanf("%d", &sele2);
                sele2--;
                if(sele2 >= 0 && sele2 < j+1){
                    RID rid;
                    rid.page = rids[sele2][0];
                    rid.slot = rids[sele2][1];
                    deleteRecord(table,rid);
                }
                break;
            case 5:
                printf("scan\n");
                break;
            case 6:
                printf("table name: ");
                char buf[100];
                scanf("%s", buf);
                char* tmp = (char *) malloc(sizeof(char)*sizeof(buf));
                memcpy(tmp,buf,sizeof(buf));
                printtable(buf);
                break;
            case 7:
                cl = 1;
                break;
            default:
                printf("invalid input\n");
                break;
        }
    }
}
Ejemplo n.º 15
0
int main()
{

	table *tbl;
	char *word;
	int size = 53;
	char compmethod = '1';

	printf("Testing all of table (EEE!!)'s methods!!\n\n");
	printf("Creating tbl, adding stuff, searching for stuff.\n");

	tbl = createtable(size);

	word = "hoi";
	printf("Adding word %s\n",word);
	addtable(tbl, size, word, compmethod);

	printtable(tbl, size);

	word = "boi";
	printf("Adding word %s\n",word);
	addtable(tbl, size, word, compmethod);

	printtable(tbl, size);

	word = "owijf";
	printf("Adding word %s\n",word);
	addtable(tbl, size, word, compmethod);

	printtable(tbl, size);

/*

	llist *listt;
	char *word;
	int line;

	printf("Testing all of llist's methods!!\n\n");
	printf("Creating llist listt.  Adding stuff to it.\n");

	listt = createllist();

	word = "hoi";
	line = 11;

	printf("Adding misspelled word %s at line %d\n",word,line);
	addllist(listt, word, line);

	printlist(listt);

	word = "zuh";
	line = 11;

	printf("Adding misspelled word %s at line %d\n",word,line);
	addllist(listt, word, line);

	printlist(listt);


	word = "ajia";
	line = 12;

	printf("Adding misspelled word %s at line %d\n",word,line);
	addllist(listt, word, line);

	printlist(listt);

	word = "hoi";
	line = 15;

	printf("Adding misspelled word %s at line %d\n",word,line);
	addllist(listt, word, line);

	printlist(listt);




	char* buffer = "a wefe";
	int size = 53;
	char compmethod = '2';
	int shash;

	printf("Testing all of hash's methods!!\n\n");
	printf("Using string %s, size %d, compmethod %c\n",buffer,size,compmethod);

	shash = hash( buffer, size, compmethod );

	printf("Result of hashing: %d\n",shash);
*/
	return 0;

}
Ejemplo n.º 16
0
int
main (int argc, char *argv[])
{
  ptr<locationtable> locs = New refcounted<locationtable> (10);

  Configurator::only ().set_int ("chord.max_vnodes", 1024);
  
  chord_node n;
  ptr<location> l;

  n.r.hostname = "192.168.0.1";
  n.r.port = 11977;
  n.vnode_num = 0;
  n.age = 0;
  n.x = make_chordID (n.r.hostname, n.r.port, n.vnode_num);
  n.coords.setsize (Coord::NCOORD + Coord::USING_HT);
  warnx << "base insert... ";
  l = locs->insert (n);
  assert (l);

  assert (locs->size () == 1);
  assert (locs->usablenodes() == 1);
  assert (locs->cached (l->id ()));
  assert (!locs->pinned (l->id ()));
  warnx << "ok\n";

  warnx << "setting dead... ";
  l->set_alive (false);
  assert (locs->usablenodes () == 0);
  warnx << "ok\n";

  warnx << "flushing... ";
  locs->flush ();
  assert (locs->size () == 0);
  warnx << "ok\n";

  warnx << "reinsert... ";
  locs->insert (l);
  assert (locs->size () == 1);
  assert (locs->usablenodes () == 0);
  assert (locs->cached (l->id ()));
  assert (locs->lookup (l->id ()) == l);
  warnx << "ok\n";

  warnx << "back to life... ";
  l->set_alive (true);
  assert (locs->usablenodes () == 1);

  warnx << "pinning sole node... ";
  locs->pin (n.x, 0); 
  warnx << "ok\n";
  warnx << "verifying pinned... ";
  assert (locs->pinned (l->id ()));
  warnx << "ok\n";
  warnx << "attempting flush of pin node... ";
  locs->flush ();
  assert (locs->cached (l->id ()));
  assert (locs->lookup (l->id ()) == l);
  assert (locs->size () == 1);
  warnx << "failed as expected.\n";

  warnx << "pinning a successor and attempting flush... ";
  locs->pin (n.x, 1);
  locs->flush ();
  assert (locs->cached (l->id ()));
  warnx << "ok\n";

  warnx << "resetting locationtable... ";
  locs = New refcounted<locationtable> (10);
  warnx << "ok\n";

  locs->insert (l);
  warnx << "pinning self, pred and succlist... ";
  locs->pin (n.x, 0);
  locs->pin (n.x, -1);
  locs->pin (n.x, 16);
  warnx << " ok\n";

  warnx << "flushing... ";
  locs->flush ();
  assert (locs->cached (l->id ()));
  warnx << "ok\n";

  warnx << "testing with 2 nodes... ";
  n.vnode_num = 1;
  n.x = make_chordID (n.r.hostname, n.r.port, n.vnode_num);
  l = locs->insert (n);
  assert (locs->size () == 2);
  assert (locs->pinned (n.x));
  locs->flush ();
  assert (locs->size () == 2);
  warnx << "ok\n";

  warnx << "pinning new self, pred and succlist and then flushing... ";
  locs->pin (n.x, 0);
  locs->pin (n.x, -1);
  locs->pin (n.x, 16);
  locs->flush ();
  assert (locs->cached (l->id ()));
  assert (locs->size () == 2);
  warnx << "ok\n";

  warnx << "inserting 10 nodes... ";
  for (unsigned int i = 0; i < 10; i++) {
    n.r.hostname = "192.168.1.1";
    n.r.port = 1000 + i;
    n.vnode_num = i;
    n.x = make_chordID (n.r.hostname, n.r.port, i);
    l = locs->insert (n);
    assert (l);
    assert (l->alive ());
    assert (locs->size () == 2 + i + 1);
    assert (locs->usablenodes () == 2 + i + 1);
  }
  warnx << "ok\n";

  warnx << "testing duplicate insert... ";
  ptr<location> w = locs->insert (n);
  assert (l == w);
  assert (locs->size () == 12);
  assert (locs->usablenodes () == 12);
  warnx << "ok\n";

  printtable (locs, "insert", "");
}