示例#1
0
int main(int argc, char** argv, char** envp) {
	int rand_number;
	int cont=1;
	while(cont) {
		rand_number=rand()%100;
		// printf("rand_number is %d\n",rand_number);
		int guess=-1;
		while(guess!=rand_number) {
			printf("what is your guess ? ");
			CHECK_INT(scanf("%d", &guess), EOF);
			if(guess<rand_number) {
				printf("guess higher...\n");
			}
			if(guess>rand_number) {
				printf("guess lower...\n");
			}
			if(guess==rand_number) {
				printf("RIGHT!!!\n");
			}
		}
		printf("want to play more ? ");
		CHECK_INT(scanf("%d", &cont), EOF);
	}
	return EXIT_SUCCESS;
}
示例#2
0
  SExpr* SPrimScope::tryTypeCheck() {
    // for inlined prims, try to see if primitive will always fail
    if (!InlinePrimitives) return NULL;
    
    bool fail = false;
    switch (pd->type()) {
     case NotReallyAPrimitive:
     case InternalPrimitive:
      fatal("cannot call an internal primitive from Self code");
      return NULL;
     case IntComparisonPrimitive:
     case IntArithmeticPrimitive:
      // must have two smis
      fail = CHECK_INT(receiver) || CHECK_INT(args->last());
      break;

     case FloatArithmeticPrimitive:
     case FloatComparisonPrimitive:
      // must have two floats
      fail = CHECK_FLOAT(receiver) || CHECK_FLOAT(args->last());
      break;
      
     case AtPrimitive:
     case AtPutPrimitive:
      // must have array rcvr and smi arg
      fail = TYPECHECK(receiver, is_objVector()) || CHECK_INT(args->last());
      break;
     case SizePrimitive:
      // must have array rcvr
      fail = TYPECHECK(receiver, is_objVector());
      break;

     case ByteAtPutPrimitive:
      // stored value must be 0..255; for now, test only for integer
      fail = CHECK_INT(args->nth(0));
      // fall through
     case ByteAtPrimitive:
      // must have array rcvr and smi arg
      fail |= TYPECHECK(receiver, is_byteVector()) || CHECK_INT(args->last());
      break;
     case ByteSizePrimitive:
      // must have array rcvr
      fail = TYPECHECK(receiver, is_byteVector());
      break;

     default:
      return NULL;          
    }
    
    if (fail) {
      // primitive will always fail
      ConstPReg* error = new_ConstPReg(_sender, VMString[BADTYPEERROR]);
      Node* dummy;
      MergeNode* mdummy = NULL;
      return genPrimFailure(NULL, error, dummy, mdummy, resultPR, false);
    } else {
      return NULL;
    }
  }
void add_entry(phone_entry* phonebook, const int size) {
	int entry=find_empty_cell(phonebook, size);
	printf("give me the name for the new entry: ");
	CHECK_INT(scanf("%s", phonebook[entry].name), 1);
	printf("give me the phone for the new entry: ");
	CHECK_INT(scanf("%s", phonebook[entry].phone), 1);
	phonebook[entry].used=1;
}
示例#4
0
void zob_client_connect(struct zob_client * p_client, struct zob_string * p_sock_name)
{
	char * p_raw_sock_name  = NULL;
	zob_string_get(p_sock_name, &p_raw_sock_name);

	strcpy(p_client->remote_addr.sun_path, p_raw_sock_name);

	p_client->socket_fd = socket(AF_UNIX, SOCK_STREAM, 0);
	CHECK_INT(p_client->socket_fd);

	CHECK_INT(connect(p_client->socket_fd
				, (struct sockaddr *) &p_client->remote_addr, sizeof p_client->remote_addr));
}
示例#5
0
void zob_client_send(struct zob_client * p_client, int in_fd)
{
	int reading_count = read(in_fd, &p_client->buffer, DB_BUFFER_SIZE);
	CHECK_INT(reading_count);

	if(0 == reading_count)
		return;

	int writting_count = write(p_client->socket_fd, &p_client->buffer, reading_count);
	CHECK_INT(writting_count);

	if(reading_count != writting_count)
		zob_app_error(gp_app, "IO mismatch", __FILE__, __LINE__);
}
示例#6
0
void zob_client_recv(struct zob_client * p_client)
{
	int reading_count = read(p_client->socket_fd, &p_client->buffer, DB_BUFFER_SIZE);
	CHECK_INT(reading_count);
	p_client->buffer[reading_count] = '\0';
	printf("%s\n", p_client->buffer);
	if(p_client->buffer != strstr(p_client->buffer, "Ok"))
		zob_app_error(gp_app, "No ack", __FILE__, __LINE__);
}
示例#7
0
int main(int argc, char *argv[])
{
  struct _var var1,var2;

  printf("Testing var.h\n");

  var_set_int(&var1, 1000);
  CHECK(var1, 1000, 1000);

  var_set_float(&var1, 99.32);
  CHECK(var1, 99, 99.32);

  var_set_int(&var1, 0x0122223333);
  CHECK_INT(var1, 0x22223333, 0x122223333);

  var_set_int(&var1, 0xffffffffffffffff);
  CHECK_INT(var1, 0xffffffff, 0xffffffffffffffff);

  var_set_int(&var1, 0x0fffffffffffffff);
  CHECK_INT(var1, 0xffffffff, 0x0fffffffffffffff);

  TEST_OP(add, int, -10, 20, 10, 10);
  TEST_OP(add, int, 10, 20, 30, 30);
  TEST_OP(sub, int, -10, 20, -30, -30);
  TEST_OP(sub, int, 10, 20, -10, -10);
  TEST_OP(mul, int, 10, 20, 200, 200);
  TEST_OP(div, int, 10, 20, 0, 0);
  TEST_OP(div, int, 20, -10, -2, -2);
  TEST_OP(add, float, -10.1, 20, 9, 9.9);
  TEST_OP(add, float, -10, 20.2, 10, 10.2);
  TEST_OP(sub, float, -10, 20.2, -30, -30.2);
  TEST_OP(mul, float, -10, 20.2, -202, -202);
  TEST_OP(mul, float, 8, 20.2, 161, 161.60);
  TEST_OP(div, float, 2.56, 8, 0, 0.32);
  TEST_OP(div, float, 32.8, 4, 8, 8.2);

  TEST_OP_INT(add, int, 0xffffffff, 1, 0, 0x100000000);

  if (errors != 0) { printf("var.h ... FAILED.\n"); return -1; }

  printf("var.h ... PASSED.\n");

  return 0;
}
示例#8
0
static void
test_write_vint_read_impl ( CuTest* tc, apr_status_t (*read) (lcn_index_input_t *, unsigned int*), lcn_index_input_t *in )
{
    unsigned int result;

    CHECK_INT( 1 );
    CHECK_INT( 10);
    CHECK_INT( 100);
    CHECK_INT( 1000);
    CHECK_INT( 10000);
    CHECK_INT( 100000);
    CHECK_INT( 1000000);
    CHECK_INT( 10000000);
    CHECK_INT( 100000000);
}
void delete_entry(phone_entry* phonebook, const int size) {
	char name[256];
	printf("give me a name to delete: ");
	CHECK_INT(scanf("%s", name), 1);
	int entry=find_cell_by_name(phonebook, size, name);
	if(entry==-1) {
		fprintf(stderr, "you moron! give me a name in the book\n");
	} else {
		phonebook[entry].used=0;
	}
}
void find_entry(phone_entry* phonebook, const int size) {
	char name[256];
	printf("give me a name to find: ");
	CHECK_INT(scanf("%s", name), 1);
	int entry=find_cell_by_name(phonebook, size, name);
	if(entry==-1) {
		fprintf(stderr, "you moron! there is no one by that name\n");
	} else {
		printf("the phone for %s is %s\n", name, phonebook[entry].phone);
	}
}
示例#11
0
int main(int argc, char** argv, char** envp) {
	int num;
	CHECK_INT(scanf("%d", &num), 1);
	int i=0;
	while(num/2>0) {
		i++;
		num/=2;
	}
	printf("number of times divided is %d\n", i);
	return EXIT_SUCCESS;
}
示例#12
0
//-----------------------------------------------------------------------------
int testSelectionMode(ctkFileDialog* fileDialog)
{
  fileDialog->setSelectionMode(QAbstractItemView::ExtendedSelection);
  CHECK_INT(fileDialog->selectionMode(), static_cast<int>(QAbstractItemView::ExtendedSelection));

  // Due to limitation of QFileDialog API, calling setFileMode resets
  // the selection mode.

  fileDialog->setSelectionMode(QAbstractItemView::ExtendedSelection);
  fileDialog->setFileMode(QFileDialog::Directory);
  CHECK_INT(fileDialog->selectionMode(), static_cast<int>(QAbstractItemView::SingleSelection));

  fileDialog->setSelectionMode(QAbstractItemView::ExtendedSelection);
  fileDialog->setFileMode(QFileDialog::DirectoryOnly);
  CHECK_INT(fileDialog->selectionMode(), static_cast<int>(QAbstractItemView::SingleSelection));

  fileDialog->setSelectionMode(QAbstractItemView::ExtendedSelection);
  fileDialog->setFileMode(QFileDialog::ExistingFile);
  CHECK_INT(fileDialog->selectionMode(), static_cast<int>(QAbstractItemView::SingleSelection));

  fileDialog->setSelectionMode(QAbstractItemView::ExtendedSelection);
  fileDialog->setFileMode(QFileDialog::ExistingFiles);
  CHECK_INT(fileDialog->selectionMode(), static_cast<int>(QAbstractItemView::ExtendedSelection));

  fileDialog->setSelectionMode(QAbstractItemView::ExtendedSelection);
  fileDialog->setFileMode(QFileDialog::AnyFile);
  CHECK_INT(fileDialog->selectionMode(), static_cast<int>(QAbstractItemView::SingleSelection));

  return EXIT_SUCCESS;
}
int show_menu() {
	int result;
	do {
		printf("here is your menu....\n");
		printf("1) add an entry (name and phone)\n");
		printf("2) delete an entry (by name)\n");
		printf("3) find an entry (by name)\n");
		printf("4) print the phonebook\n");
		printf("5) exit\n");
		CHECK_INT(scanf("%d", &result), 1);
	} while(result<1 || result>5);
	return result;
}
示例#14
0
文件: rand.c 项目: Shareed2k/linuxapi
int main(int argc, char** argv, char** envp) {
	int seed;
	int i;
	printf("give me a seed: ");
	CHECK_INT(scanf("%d", &seed), 1);
	// no error code for srand
	srand(seed);
	for(i=0; i<10; i++) {
		// no error code for rand
		printf("rand gave me %d\n", rand());
	}
	return EXIT_SUCCESS;
}
示例#15
0
void compare_proto_info(struct proto_info const *const info, struct proto_info const *const expected)
{
    CHECK_INT(info->head_len, expected->head_len);
    CHECK_INT(info->payload, expected->payload);
}
示例#16
0
/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    : _mpc5125_update_int_mask_table
* Returned Value   : none
* Comments         :
*    Updates interrupt mask table. This table is going to be used by 
*    mpc5125_external_isr to handle nested interrupts
*
*END*------------------------------------------------------------------------*/
static void _mpc5125_update_int_mask_table
   (
      void
   )
{
   MPC5125_IPIC_STRUCT_PTR              ipic_ptr = MPC5125_IPIC_ADDR();
   uint_32                              sicfg;
   uint_32                              num, index, oldindex;
   uchar                                sysaspread = 0, sysbspread = 0, syscspread = 0, sysdspread = 0;
   uchar                                mixaspread = 0, mixbspread = 0;

  
   sicfg = ipic_ptr->SICFR;
   
   /* Get the Priority scheme */
   sysaspread = (sicfg & MPC5125_IPIC_SICFR_IPSA_SPREAD) ? 1 : 0;
   sysbspread = (sicfg & MPC5125_IPIC_SICFR_IPSB_SPREAD) ? 1 : 0;
   syscspread = (sicfg & MPC5125_IPIC_SICFR_IPSC_SPREAD) ? 1 : 0;
   sysdspread = (sicfg & MPC5125_IPIC_SICFR_IPSD_SPREAD) ? 1 : 0;
   mixaspread = (sicfg & MPC5125_IPIC_SICFR_MPSA_SPREAD) ? 1 : 0;
   mixbspread = (sicfg & MPC5125_IPIC_SICFR_MPSB_SPREAD) ? 1 : 0;

   _mem_zero(mpc5125_int_mask_table, sizeof(mpc5125_int_mask_table));

   /* Interrupts masks are created in priority order */
   /* The order depends on each groups Priority scheme */
   /* It is dynamic, so the masks may need to be rebuilt often */

   /* Except for the user specified Highest Priority Int, the source at MIXA0 is the highest priority int */
   /* Who is number 2 depends on the combination of group priority schemes. */
   
   /* This code determines the priority order and builds a masking table. */
   /* For each priority level it determines the interrupt source and vector (index) */
   /* copies the higher priorities 3 register mask and appends that sources mask bit to its mask */
   
    _GET_MIXA0_NUM(num);                       /* find our source */
    _GET_MIXA_GROUP_INDEX(num,index);          /* establish our vector */          

   /* Find the next highest level and so on */
   
   if(!mixaspread) {
      CHECK_INT(MIXA,1);
      CHECK_INT(MIXA,2);
      CHECK_INT(MIXA,3);
   }
   
   CHECK_INT_IF(mixbspread,MIXB,0);

   if(!sysbspread) {
      CHECK_INT(SYSB,0);
      CHECK_INT(SYSB,1);
      CHECK_INT(SYSB,2);
      CHECK_INT(SYSB,3);
   } 

   CHECK_INT_IF(mixaspread,MIXA,1);

   if(!sysbspread) {
      CHECK_INT(SYSB,4);
      CHECK_INT(SYSB,5);
      CHECK_INT(SYSB,6);
      CHECK_INT(SYSB,7);
   }
      
   if(mixbspread) {
      CHECK_INT(MIXB,1);
   } else {
      CHECK_INT(MIXB,0);
      CHECK_INT(MIXB,1);
      CHECK_INT(MIXB,2);
      CHECK_INT(MIXB,3);
   } 
   
   if(!sysaspread) {
      CHECK_INT(SYSA,0);
      CHECK_INT(SYSA,1);
      CHECK_INT(SYSA,2);
      CHECK_INT(SYSA,3);
   } 
   
   CHECK_INT_IF(mixaspread,MIXA,2);
   
   if(!sysaspread) {
      CHECK_INT(SYSA,4);
      CHECK_INT(SYSA,5);
      CHECK_INT(SYSA,6);
      CHECK_INT(SYSA,7);
   } 

   if(!mixaspread) {
      CHECK_INT(MIXA,4);
      CHECK_INT(MIXA,5);
      CHECK_INT(MIXA,6);
      CHECK_INT(MIXA,7);
   } 
    
   CHECK_INT_IF(mixbspread,MIXB,2);

    if(!syscspread) {
      CHECK_INT(SYSC,0);
      CHECK_INT(SYSC,1);
      CHECK_INT(SYSC,2);
      CHECK_INT(SYSC,3);
    } 

   CHECK_INT_IF(mixaspread,MIXA,3);
   
   if(!syscspread) {
      CHECK_INT(SYSC,4);
      CHECK_INT(SYSC,5);
      CHECK_INT(SYSC,6);
      CHECK_INT(SYSC,7);
    } 
   
   if(mixbspread) {
      CHECK_INT(MIXB,3);
   } else {
      CHECK_INT(MIXB,4);
      CHECK_INT(MIXB,5);
      CHECK_INT(MIXB,6);
      CHECK_INT(MIXB,7);
   } 
   
   if(!sysdspread) {
      CHECK_INT(SYSD,0);
      CHECK_INT(SYSD,1);
      CHECK_INT(SYSD,2);
      CHECK_INT(SYSD,3);
   } 
   
   CHECK_INT_IF(mixaspread,MIXA,4);

   if(!sysdspread) {
      CHECK_INT(SYSD,4);
      CHECK_INT(SYSD,5);
      CHECK_INT(SYSD,6);
      CHECK_INT(SYSD,7);
   } 

   CHECK_INT_IF(mixbspread,MIXB,4);
   CHECK_INT_ID(MPC5125_INT_ID_GPT2);
   CHECK_INT_IF(sysbspread,SYSB,1);
   CHECK_INT_IF(sysaspread,SYSA,1);
   CHECK_INT_ID(MPC5125_INT_ID_GPT3);
   CHECK_INT_IF(syscspread,SYSC,1);
   CHECK_INT_IF(sysdspread,SYSD,0);
   CHECK_INT_ID(MPC5125_INT_ID_GPT4);
   CHECK_INT_IF(mixaspread,MIXA,5);
   CHECK_INT_ID(MPC5125_INT_ID_GPT5);
   CHECK_INT_IF(sysbspread,SYSB,1);
   CHECK_INT_IF(sysaspread,SYSA,1);
   CHECK_INT_ID(MPC5125_INT_ID_GPT6);
   CHECK_INT_IF(syscspread,SYSC,1);
   CHECK_INT_IF(sysdspread,SYSD,1);
   CHECK_INT_ID(MPC5125_INT_ID_GPT7);
   CHECK_INT_IF(mixbspread,MIXB,5);
   CHECK_INT_ID(MPC5125_INT_ID_GPIO1);
   CHECK_INT_IF(sysbspread,SYSB,2);
   CHECK_INT_IF(sysaspread,SYSA,2);
   CHECK_INT_ID(MPC5125_INT_ID_RTC_SEC);
   CHECK_INT_IF(syscspread,SYSC,2);
   CHECK_INT_IF(sysdspread,SYSD,2);
   CHECK_INT_ID(MPC5125_INT_ID_RTC_ALARM);
   CHECK_INT_IF(mixaspread,MIXA,6);
   CHECK_INT_ID(MPC5125_INT_ID_DDR);
   CHECK_INT_IF(sysbspread,SYSB,3);
   CHECK_INT_IF(sysaspread,SYSA,3);
   CHECK_INT_ID(MPC5125_INT_ID_SBA);
   CHECK_INT_IF(syscspread,SYSC,3);
   CHECK_INT_IF(sysdspread,SYSD,3);
   CHECK_INT_ID(MPC5125_INT_ID_PMC);
   CHECK_INT_IF(mixbspread,MIXB,6);
   CHECK_INT_ID(MPC5125_INT_ID_USB2OTG1_WKUP);
   CHECK_INT_IF(sysbspread,SYSB,4);
   CHECK_INT_IF(sysaspread,SYSA,4);
   CHECK_INT_ID(MPC5125_INT_ID_USB2OTG2_WKUP);
   CHECK_INT_IF(syscspread,SYSC,4);
   CHECK_INT_IF(sysdspread,SYSD,4);
   CHECK_INT_ID(MPC5125_INT_ID_GPIO2);
   CHECK_INT_IF(mixaspread,MIXA,7);
   CHECK_INT_ID(MPC5125_INT_ID_TEMP_105C);
   CHECK_INT_IF(sysbspread,SYSB,5);
   CHECK_INT_IF(sysaspread,SYSA,5);
   CHECK_INT_ID(MPC5125_INT_ID_IIM);
   CHECK_INT_IF(syscspread,SYSC,5);
   CHECK_INT_IF(sysdspread,SYSD,5);
   CHECK_INT_ID(MPC5125_INT_ID_PRIOMON);
   CHECK_INT_IF(mixbspread,MIXB,7);
   CHECK_INT_ID(MPC5125_INT_ID_MSCAN3);
   CHECK_INT_IF(sysbspread,SYSB,6);
   CHECK_INT_IF(sysaspread,SYSA,6);
   CHECK_INT_ID(MPC5125_INT_ID_MSCAN4);
   CHECK_INT_IF(syscspread,SYSC,6);
   CHECK_INT_IF(sysdspread,SYSD,6);
   CHECK_INT_ID(MPC5125_INT_ID_GPT12);
   CHECK_INT_ID(MPC5125_INT_ID_GPT13);
   CHECK_INT_IF(sysbspread,SYSB,7);
   CHECK_INT_IF(sysaspread,SYSA,7);
   CHECK_INT_ID(MPC5125_INT_ID_GPT14);
   CHECK_INT_IF(syscspread,SYSC,7);
   CHECK_INT_IF(sysdspread,SYSD,7);
   CHECK_INT_ID(MPC5125_INT_ID_GPT15);
   
} 
示例#17
0
文件: enumBuckets.cpp 项目: 8l/rose
/*
  The main entry to LSH package. Depending on the command line
  parameters, the function computes the R-NN data structure optimal
  parameters and/or construct the R-NN data structure and runs the
  queries on the data structure.
 */
int main(int argc, char *argv[]){

  FAILIF(0 != regcomp(&preg[ENUM_PPROP_FILE], "FILE:([^,]+)", REG_EXTENDED));
  FAILIF(0 != regcomp(&preg[ENUM_PPROP_LINE], "LINE:([0-9]+)", REG_EXTENDED));
  FAILIF(0 != regcomp(&preg[ENUM_PPROP_OFFSET], "OFFSET:([0-9]+)", REG_EXTENDED));
  FAILIF(0 != regcomp(&preg[ENUM_PPROP_NODE_KIND], "NODE_KIND:([0-9]+)", REG_EXTENDED));
  FAILIF(0 != regcomp(&preg[ENUM_PPROP_NUM_NODE], "NUM_NODE:([0-9]+)", REG_EXTENDED));
  FAILIF(0 != regcomp(&preg[ENUM_PPROP_NUM_DECL], "NUM_DECL:([0-9]+)", REG_EXTENDED));
  FAILIF(0 != regcomp(&preg[ENUM_PPROP_NUM_STMT], "NUM_STMT:([0-9]+)", REG_EXTENDED));
  FAILIF(0 != regcomp(&preg[ENUM_PPROP_NUM_EXPR], "NUM_EXPR:([0-9]+)", REG_EXTENDED));
  FAILIF(0 != regcomp(&preg[ENUM_PPROP_TBID], "TBID:([-]?[0-9]+)", REG_EXTENDED));
  FAILIF(0 != regcomp(&preg[ENUM_PPROP_TEID], "TEID:([-]?[0-9]+)", REG_EXTENDED));
  FAILIF(0 != regcomp(&preg[ENUM_PPROP_nVARs], "VARs:\\{[^}]*\\}([0-9]+)", REG_EXTENDED));
  FAILIF(0 != regcomp(&preg[ENUM_PPROP_CONTEXT_KIND], "CONTEXT_KIND:([0-9]+)", REG_EXTENDED));
  FAILIF(0 != regcomp(&preg[ENUM_PPROP_NEIGHBOR_KIND], "NEIGHBOR_KIND:([0-9]+)", REG_EXTENDED));
  FAILIF(0 != regcomp(&preg[ENUM_PPROP_OIDs], "OIDs:\\{[^}]*\\}([0-9]+)", REG_EXTENDED)); // TODO, pair-wise comparision of Vars.

  //initializeLSHGlobal();
  availableTotalMemory = 800000000;

  // Parse part of the command-line parameters.
  bool computeParameters = false;
  char *paramsFile = NULL;

  // Parameters for filtering:
  bool no_filtering = false, bug_detecting = true;
  int upperBound = 0, lowerBound = 2;
  int minNumNodes = 0, min_nVars = 0;
  int max_num_diff_vars = 16;
  float max_num_diff_nVars_diff = 0.5, max_nVars_diff = 0.35;
  bool interfiles = false;
  int min_lines = 0;

  for (int opt; (opt = getopt(argc, argv, "ABl:v:V:e:E:a:m:N:d:p:P:R:M:cFf:b:t:")) != -1; ) {
    // Needed: -p -f -R
    switch (opt) {
    case 'A': 
      fprintf(stderr, "Warning: output all clones. Takes more time...\n");
      no_filtering = true; break;
    case 'B':
      fprintf(stderr, "Warning: no filtering for bugs now.\n");
      bug_detecting = false; break;
    case 'l': min_lines = atoi(optarg); break;
    case 'v': min_nVars = atoi(optarg); break;
    case 'V': max_num_diff_vars = atoi(optarg); break;
    case 'e': max_num_diff_nVars_diff = atof(optarg); break;
    case 'E': max_nVars_diff = atof(optarg); break;
    case 'm': minNumNodes = atoi(optarg); break;
    case 'b': lowerBound = atoi(optarg); break;
    case 't': upperBound = atoi(optarg); break;
    case 'N': nPoints = atol(optarg); break;
    case 'd': pointsDimension = atol(optarg); break;
    case 'p': paramsFile = optarg; break;
    case 'P': successProbability = atof(optarg); break;
    case 'M': availableTotalMemory = atol(optarg); break;
    case 'a': prefetch = atol(optarg); break;
    case 'c':
      fprintf(stderr, "Warning: will compute parameters\n");
      computeParameters = true;
      break;
    case 'F':
      fprintf(stderr, "Warning: inter-file clone detection. Takes more time...\n");
      interfiles = true; break;
    case 'R':
      nRadii = 1;
      FAILIF(NULL == (listOfRadii = (RealT*)MALLOC(nRadii * sizeof(RealT))));
      FAILIF(NULL == (memRatiosForNNStructs = (RealT*)MALLOC(nRadii * sizeof(RealT))));
      listOfRadii[0] = strtod(optarg, NULL);
      memRatiosForNNStructs[0] = 1;
      break;
    case 'f':
      readDataSetFromFile2(optarg);
      DPRINTF("Allocated memory (after reading data set): %ld\n", totalAllocatedMemory);
      break;
    default:
      fprintf(stderr, "Unknown option: -%c\n", opt);
      usage(1, argv[0]);
    }
  }
  
  if (optind < argc) {
    fprintf(stderr, "There are unprocessed parameters left\n");
    usage(1, argv[0]);
  }

  CHECK_INT(availableTotalMemory);
  CHECK_INT(nPoints);
  CHECK_INT(pointsDimension);
  CHECK_INT(nRadii);

  if (nPoints > MAX_N_POINTS) {
    printf("Error: the structure supports at most %ld points (%ld were specified).\n", MAX_N_POINTS, nPoints);
    fprintf(ERROR_OUTPUT, "Error: the structure supports at most %ld points (%ld were specified).\n", MAX_N_POINTS, nPoints);
    exit(1);
  }

  if (computeParameters == false)
    computeParameters = readParamsFile(paramsFile);

  if (computeParameters) {
    IntT nSampleQueries = N_SAMPLE_QUERY_POINTS;
    PPointT sampleQueries[nSampleQueries];
    IntT sampleQBoundaryIndeces[nSampleQueries];
    
    // Choose several data set points for the sample query points.
    for(IntT i = 0; i < nSampleQueries; i++){
      sampleQueries[i] = dataSetPoints[genRandomInt(0, nPoints - 1)];
    }

    // Compute the array sampleQBoundaryIndeces that specifies how to
    // segregate the sample query points according to their distance
    // to NN.
    sortQueryPointsByRadii(pointsDimension,
			   nSampleQueries,
			   sampleQueries,
			   nPoints,
			   dataSetPoints,
			   nRadii,
			   listOfRadii,
			   sampleQBoundaryIndeces);


    // Compute the R-NN DS parameters
    // if a parameter file is given, output them to that file, and continue
    // otherwise, output them to stdout, and exit

    FILE *fd;
    if (paramsFile == NULL) {
      fd = stdout;
    } else {
      fd = fopen(paramsFile, "wt");
      if (fd == NULL) {
	fprintf(stderr, "Unable to write to parameter file %s\n", paramsFile);
	exit(1);
      }
    }

    fprintf(fd, "%ld\n", nRadii);
    transformMemRatios();
    for(IntT i = 0; i < nRadii; i++) {
      // which sample queries to use
      IntT segregatedQStart = (i == 0) ? 0 : sampleQBoundaryIndeces[i - 1];
      IntT segregatedQNumber = nSampleQueries - segregatedQStart;
      if (segregatedQNumber == 0) {
	// XXX: not the right answer
	segregatedQNumber = nSampleQueries;
	segregatedQStart = 0;
      }
      ASSERT(segregatedQStart < nSampleQueries);
      ASSERT(segregatedQStart >= 0);
      ASSERT(segregatedQStart + segregatedQNumber <= nSampleQueries);
      ASSERT(segregatedQNumber >= 0);
      RNNParametersT optParameters = computeOptimalParameters(listOfRadii[i],
							      successProbability,
							      nPoints,
							      pointsDimension,
							      dataSetPoints,
							      segregatedQNumber,
							      sampleQueries + segregatedQStart,
							      (UnsT)((availableTotalMemory - totalAllocatedMemory) * memRatiosForNNStructs[i]));
      printRNNParameters(fd, optParameters);
    }
    if (fd == stdout) {
      exit(0);
    } else {
      fclose(fd);
      ASSERT(readParamsFile(paramsFile) == false);
    }
  }

  // output vector clusters according to the filtering parameters.
  printf("========================= Structure built =========================\n");
  printf("nPoints = %ld, Dimension = %ld\n", nPoints, pointsDimension);
  printf("no_filtering (0/1) = %d, inter-file (0/1) = %d, prefetch = %ld\n", no_filtering, interfiles, prefetch);
  printf("*** Filtering Parameters for individual vectors ***\n");
  printf("minNumNodes = %d, min_nVars = %d, min_lines = %d\n", minNumNodes, min_nVars, min_lines);
  printf("*** Filtering Parameters for clusters ***\n");
  printf("lowerBound = %d, upperBound = %d\n", lowerBound, upperBound);
  printf("Max num of different nVars = %d, Max diff among different nVars = %g, \nMax diff among the num of different nVars = %g\n", max_num_diff_vars, max_nVars_diff, max_num_diff_nVars_diff);


  IntT resultSize = nPoints;
  PPointT *result = (PPointT*)MALLOC(resultSize * sizeof(*result));
  PPointT queryPoint;
  FAILIF(NULL == (queryPoint = (PPointT)MALLOC(sizeof(PointT))));
  FAILIF(NULL == (queryPoint->coordinates = (RealT*)MALLOC(pointsDimension * sizeof(RealT))));

  TimeVarT meanQueryTime = 0;
  IntT nQueries = 0;
  bool seen[nPoints];
  IntT nBuckets = 0, nBucketedPoints = 0;

  memset(seen, 0, nPoints * sizeof(bool));
  for(IntT i = 0; i < nPoints; nQueries++, i++) {

    // find the next unseen point
    while (i < nPoints && seen[i]) i++;
    if (i >= nPoints) break;
    queryPoint = dataSetPoints[i];

    // get the near neighbors.
    IntT nNNs = 0;
    for(IntT r = 0; r < nRadii; r++) { // nRadii is always 1 so far.
      nNNs = getRNearNeighbors(nnStructs[r], queryPoint, result, resultSize);
      //printf("Total time for R-NN query at radius %0.6lf (radius no. %ld):\t%0.6lf\n", (double)(listOfRadii[r]), r, timeRNNQuery);
      meanQueryTime += timeRNNQuery;

      //printf("\nQuery point %ld: found %ld NNs at distance %0.6lf (radius no. %ld). NNs are:\n",
      //       i, nNNs, (double)(listOfRadii[r]), r);

      // sort by filename, then number of variables, then line number
      qsort(result, nNNs, sizeof(*result), comparePoints);

      // The result array may contain the queryPoint, so do not output it in the following.

      PPointT *cur = result, *end = result + nNNs;

      if ( ! no_filtering ) { // Filter out certain vectors and clusters.
	while (cur < end)  {	// Shall we discard the rest results
				// and start over for a new point? Not
				// now for the sake of
				// performance...TODO
	  ASSERT(*cur != NULL);
	
	  // Look for the first un-filtered point for the next bucket.
	  while ( cur < end ) {
	    if ( pointIsNotFiltered(cur) ) {
	      break;
	    }
	    seen[(*cur)->index] = true;
	    cur++;
	  }
	  if ( cur >= end )
	    break;

	  bool worthy = false;
	  int sizeBucket = 1; // 1 means the first un-filtered point
	  PPointT *begin = cur;
	  seen[(*begin)->index] = true;
	  cur++;
	  while ( cur < end &&
		  // look for the next point outside the current file
		  // if interfiles is false; that point is the end of
		  // current bucket (assume vectors in a bucket are
		  // sorted by their filenames already).
		  ( interfiles || strcmp((*begin)->filename, (*cur)->filename)==0 ) ) {
	    if ( pointIsNotFiltered(cur) ) {
	      // prepare for filtering
	      sizeBucket++;

	      // the first heuristics for bugs AFTER filtering:
	      worthy = worthy || (*begin)->prop[ENUM_PPROP_nVARs-1] != (*cur)->prop[ENUM_PPROP_nVARs-1];

	      // the second heuristics for bugs AFTER filtering:
	      worthy = worthy || inconsistentIDchanges((*begin)->oids, (*cur)->oids); // TODO
	    }
	    seen[(*cur)->index] = true;
	    cur++;
	  }
	
	  // output the bucket if:
	  //   - there are >= 2 different points
	  //   - there are <= upperBound (default 0) && >= lowerBound (default 2) points
	  //   - there are >= 2 different numbers of variables
	  // and update nBuckets and nBucketedPoints consequently
	  if (sizeBucket >= lowerBound && (upperBound < lowerBound || sizeBucket <= upperBound) && ( bug_detecting ? worthy : true ) ) {
	    nBuckets++;
	    printf("\n");
	    for (PPointT *p = begin; p < cur; p++)  {
	      ASSERT(*p != NULL);
	      if ( pointIsNotFiltered(p) ) {
		nBucketedPoints++;
	      
		// compute the distance to the query point (maybe useless)
		RealT distance = 0.;
		for (IntT i = 0; i < pointsDimension; i++) {
		  RealT t = (*p)->coordinates[i] - queryPoint->coordinates[i];
		  // L1 distance
// 		  distance += (t >= 0) ? t : -t;
		  // Pi--L2 distance, LSH uses L2 by default, we should output L2 distance here. 
		  distance += t*t;
		}
		// L1 distance
// 		printf("%09d\tdist:%0.1lf", (*p)->index, distance);
		// L2 distance
		printf("%09d\tdist:%0.1lf", (*p)->index, sqrt(distance));
		printf("\tFILE %s LINE:%d:%d NODE_KIND:%d nVARs:%d NUM_NODE:%d TBID:%d TEID:%d\n",
		       (*p)->filename, (*p)->prop[ENUM_PPROP_LINE-1], (*p)->prop[ENUM_PPROP_OFFSET-1],
		       (*p)->prop[ENUM_PPROP_NODE_KIND-1], (*p)->prop[ENUM_PPROP_nVARs-1],
		       (*p)->prop[ENUM_PPROP_NUM_NODE-1], (*p)->prop[ENUM_PPROP_TBID-1], (*p)->prop[ENUM_PPROP_TEID-1]);
		//CR_ASSERT(distance(pointsDimension, queryPoint, *p) <= listOfRadii[r]);
		//DPRINTF("Distance: %lf\n", distance(pointsDimension, queryPoint, result[j]));
		//printRealVector("NN: ", pointsDimension, result[j]->coordinates);
	      }
	    }
	  } // end of enumeration of a bucket
	}	// end of !no_filtering
      }
      else {
	if ( nNNs>=lowerBound ) { // filter out non-clones anyway
	  nBuckets++;
	  printf("\n");
	  for (PPointT *p = cur; p < end; p++)  {
	    ASSERT(*p != NULL);
	    nBucketedPoints++;
	    seen[(*p)->index] = true;
  
	    // compute the distance to the query point (maybe useless)
	    RealT distance = 0.;
	    for (IntT i = 0; i < pointsDimension; i++) {
	      RealT t = (*p)->coordinates[i] - queryPoint->coordinates[i];
	      // L1 distance
// 	      distance += (t >= 0) ? t : -t;
	      // Pi--L2 distance, LSH uses L2 by default, we should output L2 distance here. 
	      distance += t*t;
	    }

	    // L1 distance
// 	    printf("%09d\tdist:%0.1lf", (*p)->index, distance);
	    // L2 distance
	    printf("%09d\tdist:%0.1lf", (*p)->index, sqrt(distance));
	    printf("\tFILE %s LINE:%d:%d NODE_KIND:%d nVARs:%d NUM_NODE:%d TBID:%d TEID:%d\n",
		   (*p)->filename, (*p)->prop[ENUM_PPROP_LINE-1], (*p)->prop[ENUM_PPROP_OFFSET-1],
		   (*p)->prop[ENUM_PPROP_NODE_KIND-1], (*p)->prop[ENUM_PPROP_nVARs-1],
		   (*p)->prop[ENUM_PPROP_NUM_NODE-1], (*p)->prop[ENUM_PPROP_TBID-1], (*p)->prop[ENUM_PPROP_TEID-1]);
	    //CR_ASSERT(distance(pointsDimension, queryPoint, *p) <= listOfRadii[r]);
	    //DPRINTF("Distance: %lf\n", distance(pointsDimension, queryPoint, result[j]));
	    //printRealVector("NN: ", pointsDimension, result[j]->coordinates);
	  } // end of enumeration of a bucket
	} // end of nNNs>=lowerBound
      }	// end of no_filtering and  exploration of NNs
    } // for (...nRadii...)
  }

  // Simple statistics and finish
  if (nQueries > 0) {
    meanQueryTime = meanQueryTime / nQueries;
    printf("\n%ld queries, Mean query time: %0.6lf\n", nQueries, (double)meanQueryTime);
    printf("%ld buckets, %ld points (out of %ld, %.2f %%) in them\n",
	   nBuckets, nBucketedPoints, nPoints, 100*(float)nBucketedPoints/(float)nPoints);
  } else {
    printf("No query\n");
  }

  //freePRNearNeighborStruct(nnStruct);

  return 0;
}
示例#18
0
long int get_number() {
	long int ret;
	CHECK_INT(scanf("%ld", &ret), 1);
	return ret;
}
示例#19
0
  EXTERNAL_PROPERTY_LIST_LOOP(list, keyword, value, search_plist)
    {
      /* Host */
      if (EQ (keyword, Qhost))
        {
          CHECK_STRING (value);
          ldap_host = alloca (XSTRING_LENGTH (value) + 1);
          strcpy (ldap_host, (char *)XSTRING_DATA (value));
        }
      /* Filter */
      else if (EQ (keyword, Qfilter))
        {
          CHECK_STRING (value);
          ldap_filter = alloca (XSTRING_LENGTH (value) + 1);
          strcpy (ldap_filter, (char *)XSTRING_DATA (value));
        }
      /* Attributes */
      else if (EQ (keyword, Qattributes))
        {
          if (! NILP (value))
            {
              Lisp_Object attr_left = value;
              struct gcpro ngcpro1;

              NGCPRO1 (attr_left);
              CHECK_CONS (value);

              ldap_attributes = alloca ((XINT (Flength (value)) + 1)*sizeof (char *));

              for (i=0; !NILP (attr_left); i++) {
                CHECK_STRING (XCAR (attr_left));
                ldap_attributes[i] = alloca (XSTRING_LENGTH (XCAR (attr_left)) + 1);
                strcpy(ldap_attributes[i],
                       (char *)(XSTRING_DATA( XCAR (attr_left))));
                attr_left = XCDR (attr_left);
              }
              ldap_attributes[i] = NULL;
              NUNGCPRO;
            }
        }
      /* Attributes Only */
      else if (EQ (keyword, Qattrsonly))
        {
          CHECK_SYMBOL (value);
          ldap_attrsonly = NILP (value) ? 0 : 1;
        }
      /* Base */
      else if (EQ (keyword, Qbase))
        {
          if (!NILP (value))
            {
              CHECK_STRING (value);
              ldap_base = alloca (XSTRING_LENGTH (value) + 1);
              strcpy (ldap_base, (char *)XSTRING_DATA (value));
            }
        }
      /* Scope */
      else if (EQ (keyword, Qscope))
        {
          CHECK_SYMBOL (value);

          if (EQ (value, Qbase))
            ldap_scope = LDAP_SCOPE_BASE;
          else if (EQ (value, Qonelevel))
            ldap_scope = LDAP_SCOPE_ONELEVEL;
          else if (EQ (value, Qsubtree))
            ldap_scope = LDAP_SCOPE_SUBTREE;
          else
            signal_simple_error ("Invalid scope", value);
        }
      /* Authentication method */
      else if (EQ (keyword, Qauth))
        {
          CHECK_SYMBOL (value);

          if (EQ (value, Qsimple))
            ldap_auth = LDAP_AUTH_SIMPLE;
#ifdef LDAP_AUTH_KRBV41
          else if (EQ (value, Qkrbv41))
            ldap_auth = LDAP_AUTH_KRBV41;
#endif
#ifdef LDAP_AUTH_KRBV42
          else if (EQ (value, Qkrbv42))
            ldap_auth = LDAP_AUTH_KRBV42;
#endif
          else
            signal_simple_error ("Invalid authentication method", value);
        }
      /* Bind DN */
      else if (EQ (keyword, Qbinddn))
        {
          if (!NILP (value))
            {
              CHECK_STRING (value);
              ldap_binddn = alloca (XSTRING_LENGTH (value) + 1);
              strcpy (ldap_binddn, (char *)XSTRING_DATA (value));
            }
        }
      /* Password */
      else if (EQ (keyword, Qpasswd))
        {
          if (!NILP (value))
            {
              CHECK_STRING (value);
              ldap_passwd = alloca (XSTRING_LENGTH (value) + 1);
              strcpy (ldap_passwd, (char *)XSTRING_DATA (value));
            }
        }
      /* Deref */
      else if (EQ (keyword, Qderef))
        {
          CHECK_SYMBOL (value);
          if (EQ (value, Qnever))
            ldap_deref = LDAP_DEREF_NEVER;
          else if (EQ (value, Qsearch))
            ldap_deref = LDAP_DEREF_SEARCHING;
          else if (EQ (value, Qfind))
            ldap_deref = LDAP_DEREF_FINDING;
          else if (EQ (value, Qalways))
            ldap_deref = LDAP_DEREF_ALWAYS;
          else
            signal_simple_error ("Invalid deref value", value);
        }
      /* Timelimit */
      else if (EQ (keyword, Qtimelimit))
        {
          if (!NILP (value))
            {
              CHECK_INT (value);
              ldap_timelimit = XINT (value);
            }
        }
      /* Sizelimit */
      else if (EQ (keyword, Qsizelimit))
        {
          if (!NILP (value))
            {
              CHECK_INT (value);
              ldap_sizelimit = XINT (value);
            }
        }
    }