예제 #1
0
void switch_screens_command(scan_code_set3 scan_code, key_state state){ //switch screens if needed
	if(state == KEY_DOWN)
		return;
	
	scan_code_set3 key1 = (scan_code_set3)get_list_element(COMMAND_KEYS, 0);
	scan_code_set3 key2 = (scan_code_set3)get_list_element(COMMAND_KEYS, 1);
	if(!key1 || !key2)
		return;

	if((key1 == SCS3_LCTRL && key2 == SCS3_LALT) || (key2 == SCS3_LCTRL && key1 == SCS3_LALT)){
		switch(scan_code){
			case SCS3_1:
				switch_screen(0);
				break;
			case SCS3_2:
				switch_screen(1);
				break;
			case SCS3_3:
				switch_screen(2);
				break;
			case SCS3_4:
				switch_screen(3);
				break;
		}
	}
}
예제 #2
0
void print_char(scan_code_set3 scan_code, key_state state){ //print a char
	if(state == KEY_UP) //don't do anything on key release
		return;

	char s[2] = {0, 0};
	scan_code_set3 key1 = (scan_code_set3)get_list_element(COMMAND_KEYS, 0);
	switch(key1){
		case SCS3_LSHIFT:;
		case SCS3_RSHIFT:;
			char c = scancode_set3[scan_code];
			if(c > 0x60 && c < 0x7B)
				c -= 0x20;
			else if(c > 0x26 && c < 0x3E)
				c = SHIFT_ASCII[c-0x27];
			else if(c > 0x5A && c < 0x5E)
				c = SHIFT_ASCII[c-0x44];
			s[0] = c;
			set_vga_colors(WHITE, BLACK);
			print(s);
			break;
		case 0:;
			s[0] = scancode_set3[scan_code];
			set_vga_colors(WHITE, BLACK);
			print(s);
			break;
	}
	return;
}
예제 #3
0
void buffer_char(scan_code_set3 scan_code, key_state state){ //buffer a char if needed
	if(state == KEY_UP) //don't do anything on key release
		return;

	list_node *current_keyboard_buffer_node = keyboard_buffers->first;
	int screen_index = get_current_screen_index();
	while(current_keyboard_buffer_node){
		keyboard_buffer_descriptor *keyboard_buffer = (keyboard_buffer_descriptor *)current_keyboard_buffer_node->value;
		if(keyboard_buffer->screen_index == screen_index){
			scan_code_set3 key1 = (scan_code_set3)get_list_element(COMMAND_KEYS, 0);
			switch(key1){
				case SCS3_LSHIFT:;
				case SCS3_RSHIFT:;
					char c = scancode_set3[scan_code];
					if(c > 0x60 && c < 0x7B)
						c -= 0x20;
					else if(c > 0x26 && c < 0x3E)
						c = SHIFT_ASCII[c-0x27];
					else if(c > 0x5A && c < 0x5E)
						c = SHIFT_ASCII[c-0x44];
					keyboard_buffer->keyboard_buffer[keyboard_buffer->keyboard_buffer_index] = c;
					++keyboard_buffer->keyboard_buffer_index;
					break;
				case 0:;
					keyboard_buffer->keyboard_buffer[keyboard_buffer->keyboard_buffer_index] = scancode_set3[scan_code];
					++keyboard_buffer->keyboard_buffer_index;
					if(scancode_set3[scan_code] == '\n')
						keyboard_buffer->need_to_buffer = 0;
					break;
			}
		}

		current_keyboard_buffer_node = current_keyboard_buffer_node->next;
	}
}
예제 #4
0
/*==================================================
 * select_database -- open database (prompting if appropriate)
 * if fail, return FALSE, and possibly a message to display
 *  perrmsg - [OUT]  translated error message
 *================================================*/
BOOLEAN
select_database (STRING dbrequested, INT alteration, STRING * perrmsg)
{
	STRING dbdir = getlloptstr("LLDATABASES", ".");
	STRING dbused = 0;

	/* Get Database Name (Prompt or Command-Line) */
	if (!dbrequested || !dbrequested[0]) {
		char dbname[MAXPATHLEN];
		/* ask_for_db_filename returns static buffer, we save it below */
		if (!ask_for_db_filename(_(qSidldir), _(qSidldrp), dbdir, dbname, sizeof(dbname))
			|| !dbname[0]) {
			dbrequested = NULL;
			*perrmsg = _(qSiddbse);
			return FALSE;
		}
		dbrequested = strsave(dbname);
		if (eqstr(dbrequested, "?")) {
			INT n=0;
			LIST dblist=0, dbdesclist=0;
			strfree(&dbrequested);
			if ((n=get_dblist(dbdir, &dblist, &dbdesclist)) > 0) {
				INT i;
				i = choose_from_list(
					_("Choose database to open")
					, dbdesclist);
				if (i >= 0) {
					dbrequested = strsave(get_list_element(dblist, i+1, NULL));
				}
				release_dblist(dblist);
				release_dblist(dbdesclist);
			} else {
				*perrmsg = _("No databases found in database path");
				return FALSE;
			}
			if (!dbrequested) {
				*perrmsg = _(qSiddbse);
				return FALSE;
			}
		}
	}

	/* search for database */
	/* search for file in lifelines path */
	dbused = filepath(dbrequested, "r", dbdir, NULL, uu8);
	/* filepath returns alloc'd string */
	if (!dbused) dbused = strsave(dbrequested);

	if (!open_or_create_database(alteration, &dbused)) {
		return FALSE;
	}

	return TRUE;
}
예제 #5
0
size_t list_get_string(struct list_table* table, size_t lid, size_t pos)
{
	if(!table) return 0;

	struct list_descriptor* desc = find_descriptor(table, lid);

	if(!desc) return 0;

	void* value = get_list_element(desc, pos);
	return *((size_t*)value);
}
예제 #6
0
char list_get_char(struct list_table* table, size_t lid, size_t pos)
{
	if(!table) return '\0';

	struct list_descriptor* desc = find_descriptor(table, lid);

	if(!desc) return '\0';

	void* value = get_list_element(desc, pos);
	return *((char*)value);
}
예제 #7
0
bool list_back_bool(struct list_table* table, size_t lid)
{
	if(!table) return 0;

	struct list_descriptor* desc = find_descriptor(table, lid);

	if(!desc) return 0;

	void* value = get_list_element(desc, desc->list_size - 1);
	return *((bool*)value);
}
예제 #8
0
float list_front_float(struct list_table* table, size_t lid)
{
	if(!table) return 0;

	struct list_descriptor* desc = find_descriptor(table, lid);

	if(!desc) return 0;

	void* value = get_list_element(desc, 0);
	return *((float*)value);
}
예제 #9
0
파일: ezw.c 프로젝트: kk821521286/kangkai
/*
 * Performs one subordinate pass.
 */
void subordinate_pass(element_type threshold)
{
	list_type d;    //定义一颗零树
	int i;
	char found;
	if (threshold>0) 
	{
		for (i=0; i<list_length; i++) 
		{
			d = get_list_element(i,&found);
			if (found==1) 
			{
				if ((d.x&threshold)!=0)
					output_code(ONE);
				else 
					output_code(ZERO);
			}
		}
	}
}
예제 #10
0
void debugger_story_has_been_loaded()
{
  size_t index, len;
  uint32_t *element;
  char prefix_string[] = { FIZMO_COMMAND_PREFIX, 0 };
  int flags;

  //add_breakpoint(0x200d0);
  story_has_been_loaded = true;

  if (pcs != NULL)
  {
    len = get_list_size(pcs);
    breakpoints = create_list();
    for (index=0; index<len; index++)
    {
      element = (uint32_t*)get_list_element(pcs, index);
      // TODO: Verify breakpoints.
      add_list_element(breakpoints, z_mem + *element);
      free(element);
    }
    delete_list(pcs);
    pcs = NULL;
  }

  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0) 
    exit(-1);
  bzero((char *) &serv_addr, sizeof(struct sockaddr_in));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(DEBUGGER_PORT);
  inet_pton(AF_INET, DEBUGGER_IP_ADDRESS, &serv_addr.sin_addr.s_addr);
  if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) 
    exit(-1);
  listen(sockfd,5);
  clilen = sizeof(cli_addr);

  streams_latin1_output("\nPlease connect to ");
  streams_latin1_output(DEBUGGER_IP_ADDRESS);
  sprintf(buffer, ":%d", DEBUGGER_PORT);
  streams_latin1_output(buffer);
  streams_latin1_output(" to start.\n");

  while (newsockfd < 0) 
  {
    if ((newsockfd = accept(sockfd, 
          (struct sockaddr *) &cli_addr, 
          &clilen)) >= 0)
      break;
    if (errno != EINTR) 
    {
      perror("accept");
      exit(-1);
    }
  }

  flags = fcntl(newsockfd, F_GETFL, 0);
  fcntl(newsockfd, F_SETFL, flags | O_NONBLOCK);

  debugger_output(newsockfd, "\nFizmo debugger, libfizmo version ");
  debugger_output(newsockfd, LIBFIZMO_VERSION);
  debugger_output(newsockfd, ".\n");
  debugger_output(newsockfd, "Enter \"");
  debugger_output(newsockfd, prefix_string);
  debugger_output(newsockfd, "debug\" as story input to start debugging.\n\n");
}
예제 #11
0
gsl_matrix* pca(gsl_matrix* feature_matrix, gsl_vector* means, float sig_limit) {

    // subtract means of columns
    for (unsigned int j = 0; j < feature_matrix->size2; j++) {
        gsl_vector_view vv = gsl_matrix_column(feature_matrix,j);
        gsl_vector* v = &vv.vector;
        gsl_vector_set(means, j, getVectorMean(v));
        gsl_vector_add_constant(v, (-1.0) * gsl_vector_get(means,j));
    }

    // initialise matrix
    SEXP m;
    double* matrix;
    PROTECT(m = allocMatrix(REALSXP, feature_matrix->size1, feature_matrix->size2));
    matrix = REAL(m);
    for (unsigned int i = 0; i < feature_matrix->size1; i++) {
        for (unsigned int j = 0; j < feature_matrix->size2; j++) {
            matrix[i+(feature_matrix->size1)*j] = gsl_matrix_get( feature_matrix, i, j);
        }
    }

    // do principal components analysis, using R
    //fprintf(stderr, "PCA\n"); fflush(stdout);
    SEXP pca;
    PROTECT(pca = R_exec("prcomp", m));							//R_exec("print", pca);
    SEXP summary;
    PROTECT(summary = R_exec("summary", pca));						//R_exec("print", summary);


    // get proportion of variance
    SEXP ev;
    PROTECT(ev = get_list_element(pca,(char*)"sdev"));						//R_exec("print",ev);
    unsigned int dim = length(ev);									//printf("dim: %i\n", dim);

    float sum_var = 0.0;
    float c_ev = 0.0;
    for (unsigned int i = 0; i < dim; i++) {
        c_ev = (REAL(ev)[i]) * (REAL(ev)[i]);
        sum_var += c_ev;
    }

    float cum_var = 0.0;
    unsigned int sig_cnt = 0;
    for (unsigned int i = 0; i < dim; i++) {
        c_ev = (REAL(ev)[i]) * (REAL(ev)[i]);
        cum_var += c_ev;							 	//printf("ev%i: %.7g\n", i, REAL(ev)[i]);
        sig_cnt++;
        if ((cum_var/sum_var) > sig_limit) break;
    }

    //fprintf(stderr, "Cumulative variance of %g reached by using %i eigen vector(s).\n" , (cum_var/sum_var), sig_cnt);

    // get loads (eigenvectors)
    SEXP loads;
    PROTECT(loads = get_list_element(pca, (char*)"rotation"));					//R_exec("print", loads);
    gsl_matrix* rot = gsl_matrix_alloc(dim, sig_cnt);
    for (unsigned int i = 0; i < dim; i++) {
        for (unsigned int j = 0; j < sig_cnt; j++) {
            gsl_matrix_set(rot, i, j, REAL(loads)[i+dim*j]);			//printf("%g \n", REAL(loads)[i+dim*j]);
        }
    }

    // de-initialise R
    UNPROTECT(4);
    end_R();
    return(rot);
}