Ejemplo n.º 1
0
static
void send_data()
{
  int data_size = 0;
  static unsigned temperature;

  temperature = 21;
  clear_buffer(outputBuffer);
  clear_buffer(payload_buf);
  generate_payload(payload_buf,temperature);

  if(init_buffer(COAP_DATA_BUFF_SIZE)){
    coap_packet_t* request =\
    (coap_packet_t*)allocate_buffer(sizeof(coap_packet_t));
    init_packet(request);
    coap_set_method(request, COAP_POST);
    request->tid = xact_id++;
    request->type = MESSAGE_TYPE_CON;
    coap_set_header_uri(request,service_uri);
    coap_set_option(request, Option_Type_Uri_Host,
      sizeof(char)*strlen(server_ip), (uint8_t*)server_ip);
    coap_set_option(request, Option_Type_Proxy_Uri,
    sizeof(char)*strlen(proxy_uri), (uint8_t*)proxy_uri);
    coap_set_payload(request,(uint8_t*)payload_buf,
    sizeof(char)*strlen(payload_buf));
    data_size = serialize_packet(request, (uint8_t*)outputBuffer);

    PRINTF("Now sending request to base station [");
    PRINTF(&client_conn->ripaddr);
    PRINTF("]:%u/%s\n",REMOTE_PORT,service_uri);
    uip_udp_packet_send(client_conn, outputBuffer, data_size);
    delete_buffer();
  }
}
Ejemplo n.º 2
0
void init(void)
{
	for(uint8_t i = 0; i < matrix_xyz_len; i++) {
		vars.xyz[i] = (xyz_t){
			.x = randint(0, LEDS_X),
			.y = randint(0, LEDS_Y),
			.z = randint(0, LEDS_Z)
		};
	}

	clear_buffer();
}
void effect(void)
{
	clear_buffer();

	for(uint8_t i = 0; i < matrix_xyz_len; i++) {
		xyz_t xyz = vars.xyz[i];

		for(uint8_t j = 0; j < 3; j++) {
			if(xyz.z + j < LEDS_Z) {
				set_led(xyz.x, xyz.y, xyz.z + j, MAX_INTENSITY);
			}
		}

		uint8_t z = xyz.z;

		z++;

		if(z >= LEDS_Z) z = 0;

		vars.xyz[i].z = z;
	}
}
Ejemplo n.º 3
0
DWORD request_custom_command(Remote *remote, Packet *packet)
{
	Packet * response = packet_create_response(packet);
	Tlv argTlv             = {0};
	DWORD index            = 0;
	vector<wstring> args;

	LPCSTR func = packet_get_tlv_value_string(packet, TLV_TYPE_MIMIKATZ_FUNCTION);
	dprintf("Function: %s", packet_get_tlv_value_string(packet, TLV_TYPE_MIMIKATZ_FUNCTION));
	wstring function = s2ws(func);

	while( packet_enum_tlv( packet, index++, TLV_TYPE_MIMIKATZ_ARGUMENT, &argTlv ) == ERROR_SUCCESS )
	{
		dprintf("Arg: %s", (PCHAR)argTlv.buffer);
		args.push_back(s2ws((PCHAR)argTlv.buffer));
	}

	clear_buffer();

	initialize_mimikatz();
	myMimiKatz->doCommandeLocale(&function, &args);

	wchar_t* output = convert_wstring_to_wchar_t(oss.str());
	
	clear_buffer();

	packet_add_tlv_raw(response, TLV_TYPE_MIMIKATZ_RESULT, output, (DWORD)(wcslen(output)*sizeof(wchar_t)));
	packet_transmit_response(ERROR_SUCCESS, remote, response);

	return ERROR_SUCCESS;	
}
Ejemplo n.º 4
0
int main(int argc, char **argv){
	FILE *fpa;
	FILE *fpb;
	char ba[BUF_SIZE];
	char bb[BUF_SIZE];
	int a;
	int b;
	int num_match=0;
	int total=0;
	fpa = fopen(argv[1], "r");
	fpb = fopen(argv[2], "r");
	clear_buffer(ba);
	clear_buffer(bb);
	while(fgets(ba, sizeof(ba), fpa)){
		if(fgets(bb, sizeof(bb), fpb)){
		}
		else{
			break;
		}
		a = atoi(ba);
		b = atoi(bb);
		if(a == b){
			num_match++;
		}
		total++;
		clear_buffer(ba);
		clear_buffer(bb);
	}
	printf("%f\n", (double)num_match/(double)total);
	return EXIT_SUCCESS;
}
Ejemplo n.º 5
0
/**
* Przetwarza otrzymaną odpowiedź serwera.
*/
void process_respond(int* auth){
  if(! *auth){ // Autoryzuje do skutku
    my_usr_id = msg->user_id;
    if(my_usr_id != -1){
      *auth = 1;
      strcpy(user_type, msg->message);
      printf("Zalogowano jako: %s\n",msg->message);
    }else{
      printf("SERVER: %s \n", msg->message);
    }
    clear_buffer();
    return;
  }
  switch (msg->command_type) {
    case -1:  // Błąd
      printf("Problem z przetworzeniem żądania!\nSERVER: %s\n", msg->message);
      break;
    case 0:
    case 2 ... 14:
      printf("SERVER: %s\n",msg->message);
      if(msg->is_complete == 0)
        printf("\n");
      break;
    default:  //jakieś inne bugi
      printf("Wystapil problem z żądaniem lub żądanie nieobsugiwane! \n");
      break;
  }
  clear_buffer();
}
Ejemplo n.º 6
0
int main(int argc, char const *argv[]) {
    coordinate cityA, cityB;
    
    char units;
    printf("Choose units of distance \'k\' for kilometes \'m\' for miles\n>>> ");
    scanf("%c", &units);
    clear_buffer();
    while(!check(units, "km")) {
        printf("Enter \'k\' or \'m\'\n>>> ");
        scanf("%c", &units);
        clear_buffer();
    }

    printf("Enter a coordinates (latitude and longitude) of first city\n>>> ");
    scanf("%lf %lf", &cityA.latitude, &cityA.longitude);
    printf("Enter a coordinates of second city\n>>> ");
    scanf("%lf %lf", &cityB.latitude, &cityB.longitude);
    
    double distance = get_distance(cityA, cityB);
    if (units == 'm')
        distance = (1.0 / 1.609344) * distance;
    printf("\nDistance between this cities: %.3f %s.\n", distance,
           (units == 'k')? "kilometes": "miles");
   
    return 0;
}
Ejemplo n.º 7
0
void init(void)
{
	for(uint8_t i = 0; i < starfield_xyz_len; i++) {
		vars.xyz[i] = (xyz_t){
			.x = randint(0, LEDS_X),
			.y = randint(0, LEDS_Y),
			.z = randint(0, LEDS_Z)
		};
	}

	clear_buffer();
}
void effect(void)
{
	clear_buffer();

	for(uint8_t i = 0; i < starfield_xyz_len; i++) {
		xyz_t xyz = vars.xyz[i];

		set_led(xyz.x, xyz.y, xyz.z, MAX_INTENSITY);

		uint8_t y = xyz.y;

		y++;

		if(y >= LEDS_Y) y = 0;

		vars.xyz[i].y = y;
	}
}
Ejemplo n.º 8
0
/*
	Extract Meta information from video using ffprobe.
*/
void extract_meta(char const *video_path, int *width, int *height, int *fcount, float *fps)
{
	FILE *pipe_fp;
	char readbuf[80]; //todo: magic number, not good
	char fcount_probe_cmmd[1024] = "ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 ";
	char fps_probe_cmmd[1024] = "ffprobe -v error -select_streams v:0 -show_entries stream=avg_frame_rate -of default=noprint_wrappers=1:nokey=1 ";
	char y_probe_cmmd[1024] = "ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height ";
	char x_probe_cmmd[1024] = "ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=width ";

	/*
	Extract frame count information from video.
	*/

	pipe_to_buffer(pipe_fp, readbuf, fcount_probe_cmmd, video_path);

	if(sscanf(readbuf, "%d", fcount) != 1) {
		// printf("Frame Count could not be read.\n");
	}
	printf("Frame Count: %d\n", *fcount);
	clear_buffer(readbuf);


	/*
	Extract fps information from video.
	*/
	pipe_to_buffer(pipe_fp, readbuf, fps_probe_cmmd, video_path);

	int _n, _d; //must extract 
	if(sscanf(readbuf, "%d/%d", &_n, &_d) != 1) {
		// printf("FPScould not be read.\n");
	}

	float _f = ((float) _n / (float) _d);
	memcpy(fps, &_f, sizeof(float));

	printf("FPS (%d/%d) : %f\n", _n, _d, *fps);
	clear_buffer(readbuf);

	/*
	Extract height information from video.
	*/
	pipe_to_buffer(pipe_fp, readbuf, y_probe_cmmd, video_path);

	if(sscanf(readbuf, "streams_stream_0_height=%d", height) != 1) {
		// printf("FPScould not be read.\n");
	}
	printf("Height: %d\n", *height);
	clear_buffer(readbuf);

	/*
	Extract width information from video.
	*/
	pipe_to_buffer(pipe_fp, readbuf, x_probe_cmmd, video_path);
	
	if(sscanf(readbuf, "streams_stream_0_width=%d", width) != 1) {
		// printf("FPScould not be read.\n");
	}
	printf("Width: %d\n", *width);
	clear_buffer(readbuf);
}
Ejemplo n.º 9
0
void mapcache_create(uint32 mapnum)
{
	buffer_t buffer;
	uint32 x = 0, y = 0;

	clear_buffer(&buffer);

	add_opcode(&buffer, SMAPDATA);
	add_buffer(&buffer, &mapnum, SIZE32);
	add_string(&buffer, map(mapnum)->name );
	add_buffer(&buffer, &map(mapnum)->moral,SIZE8);
	add_buffer(&buffer, &map(mapnum)->music,SIZE8);
	add_buffer(&buffer, &map(mapnum)->left,SIZE16);
	add_buffer(&buffer, &map(mapnum)->right,SIZE16);
	add_buffer(&buffer, &map(mapnum)->up,SIZE16);
	add_buffer(&buffer, &map(mapnum)->down,SIZE16);
	add_buffer(&buffer, &map(mapnum)->shop,SIZE16);
	add_buffer(&buffer, &map(mapnum)->bootmap,SIZE32);
	add_buffer(&buffer, &map(mapnum)->bootx,SIZE8);
	add_buffer(&buffer, &map(mapnum)->booty,SIZE8);
	add_buffer(&buffer, &map(mapnum)->revision,SIZE32);

	for( x = 0; x < MAX_MAP_NPCS; x++)
		add_buffer(&buffer, &map(mapnum)->npc[x].num,SIZE16);

	for(x = 0; x < MAX_MAPX; x++){
		for(y = 0; y < MAX_MAPY; y++){
			add_buffer(&buffer,&map(mapnum)->tile[GETXY(x,y)].type, SIZE8);
			add_buffer(&buffer,&map(mapnum)->tile[GETXY(x,y)].data1, SIZE16);
			add_buffer(&buffer,&map(mapnum)->tile[GETXY(x,y)].data2, SIZE16);
			add_buffer(&buffer,&map(mapnum)->tile[GETXY(x,y)].data3, SIZE16);
			add_buffer(&buffer,&map(mapnum)->tile[GETXY(x,y)].ground.y, SIZE8);
			add_buffer(&buffer,&map(mapnum)->tile[GETXY(x,y)].ground.x, SIZE8);
			add_buffer(&buffer,&map(mapnum)->tile[GETXY(x,y)].ground.tileset, SIZE8);
			add_buffer(&buffer,&map(mapnum)->tile[GETXY(x,y)].mask.y, SIZE8);
			add_buffer(&buffer,&map(mapnum)->tile[GETXY(x,y)].mask.x, SIZE8);
			add_buffer(&buffer,&map(mapnum)->tile[GETXY(x,y)].mask.tileset, SIZE8);
			add_buffer(&buffer,&map(mapnum)->tile[GETXY(x,y)].anim.y, SIZE8);
			add_buffer(&buffer,&map(mapnum)->tile[GETXY(x,y)].anim.x, SIZE8);
			add_buffer(&buffer,&map(mapnum)->tile[GETXY(x,y)].anim.tileset, SIZE8);
			add_buffer(&buffer,&map(mapnum)->tile[GETXY(x,y)].fringe.y, SIZE8);
			add_buffer(&buffer,&map(mapnum)->tile[GETXY(x,y)].fringe.x, SIZE8);
			add_buffer(&buffer,&map(mapnum)->tile[GETXY(x,y)].fringe.tileset, SIZE8);
		}
	}

	clear_buffer(&map_array_cache[mapnum]);
	map_array_cache[mapnum] = buffer;
}
Ejemplo n.º 10
0
token scanner_get_str_bracket()
{
    WCHAR in_char, c;

    clear_buffer();
    if (m_file_in_ptr == 0) return TOKEN_EOF;
    if (src_eof()) return TOKEN_EOF;

    while (((in_char=src_getc())!=0)) {
        if (isspace(in_char))
            continue;
        else if (in_char == 0x0d)
            continue;            
        else if (in_char == 0x0a)
            continue;            
        else if (in_char != ']') {
            buffer_char(in_char);
            for (c=src_getc(); 
                c!=',' && c!='\t' && c!='\n' && c != ']'; 
                c=src_getc()) {
                if (c==0) break;
                buffer_char(c);
            }
            src_ungetc(c);
            return TOKEN_STRING;
        }    
    }
    
    return TOKEN_EOF;
}
Ejemplo n.º 11
0
int show_vocab(vocab_t *listavocab, int cat, bool imprime) {

int resultados = 0;
	
	
print_buffer_new_line();
if (listavocab) {
	
	listavocab = go_to_cat(listavocab,cat);
	listavocab = listavocab->psiguiente;

	resultados = 0;
	if (listavocab) {
		clear_buffer();
		while (listavocab && !listavocab->pcat) {
			resultados++;
			if (imprime) {
				show_vocab_item(listavocab,resultados);
			}

			listavocab = listavocab->psiguiente;					
  	}    	
	}

}

upgrade_buffer(false);

return resultados;
}
Ejemplo n.º 12
0
void send_map(void)
{
	buffer_t buffer;
	uint32 x = 0;

	clear_buffer(&buffer);

	add_opcode(&buffer, CMAPDATA);
	add_string(&buffer, map()->name );
	add_buffer(&buffer, &map()->moral,SIZE8);
	add_buffer(&buffer, &map()->music,SIZE8);
	add_buffer(&buffer, &map()->left,SIZE16);
	add_buffer(&buffer, &map()->right,SIZE16);
	add_buffer(&buffer, &map()->up,SIZE16);
	add_buffer(&buffer, &map()->down,SIZE16);
	add_buffer(&buffer, &map()->shop,SIZE16);
	add_buffer(&buffer, &map()->bootmap,SIZE32);
	add_buffer(&buffer, &map()->bootx,SIZE8);
	add_buffer(&buffer, &map()->booty,SIZE8);

	for( x = 0; x < MAX_MAP_NPCS; x++){
		add_buffer(&buffer, &map()->npc[x].num,SIZE16);
	}

	add_buffer(&buffer, map()->tile,(MAX_MAPX * MAX_MAPY) * sizeof(tile_t));

	send_data(&buffer);
}
Ejemplo n.º 13
0
/**
* cast_spell(void)
*
* @brief
* @param void
* @return void
*/
void cast_spell(void)
{
	buffer_t buffer;

	//Check for subscript out of range
	if(!tempdata()->spell_selected || tempdata()->spell_selected >= MAX_PLAYER_SPELLS)
		return;

	//Check if player has enough MP
	if(player(myindex())->spells[tempdata()->spell_selected]){
		if(player(myindex())->vitals[VITAL_MP] < spell(player(myindex())->spells[tempdata()->spell_selected])->mpreq){
			//	Call AddText("Not enough MP to cast " & Trim$(Spell(SpellSelected).Name) & ".", 12)
			return;
		}
		if(gettickcount() > player(myindex())->attacktimer + 1){
			if(player(myindex())->moving == 0){
				clear_buffer(&buffer);
				add_opcode(&buffer,CCAST);
				add_buffer(&buffer,&tempdata()->spell_selected, SIZE16);
				socketsend(&buffer);
				player(myindex())->attacking = TRUE;
				player(myindex())->attacktimer = gettickcount();
				tempdata()->castedspell = TRUE;
			}
			else{
				//Call AddText("Cannot cast while walking!", 12)
			}
		}
	}
	else{
		//Call AddText("No spell here.", 12)
	}
}
Ejemplo n.º 14
0
void Renderer::fillBuffers()
{
	cellGcmSetSurface(&deferredLight[0]);
	cellGcmSetDitherEnable(CELL_GCM_FALSE);
	clear_buffer();
	this->SetCurrentShader(*sceneVert, *sceneFrag);
	cellGcmSetDepthTestEnable(CELL_GCM_TRUE);
	cellGcmSetCullFaceEnable(CELL_GCM_TRUE);
	cellGcmSetBlendEnable(CELL_GCM_TRUE);
	cellGcmSetDepthFunc(CELL_GCM_LESS);

	cellGcmSetColorMaskMrt(CELL_GCM_COLOR_MASK_MRT1_A |
						   CELL_GCM_COLOR_MASK_MRT1_R |
						   CELL_GCM_COLOR_MASK_MRT1_G |
						   CELL_GCM_COLOR_MASK_MRT1_B);



	projMatrix = Matrix4::perspective(0.7853982, screen_ratio, 1.0f, 10000.0f);	//CHANGED TO THIS!!
	//projMatrix = Matrix4::orthographic(-0.5,0.5,-0.5,0.5,-1,1);
	viewMatrix = camera->BuildViewMatrix();
	modelMatrix = Matrix4::identity();
	currentVert->UpdateShaderMatrices(modelMatrix, viewMatrix, projMatrix);

	DrawNode(root);
	cellGcmSetDitherEnable(CELL_GCM_TRUE);

	cellGcmSetColorMaskMrt(0);
	//SetTextureSampler(currentFrag->GetParameter("texture"), height->GetMesh()->GetDefaultTexture());
	//height->GetMesh()->Draw(*sceneVert, *sceneFrag);
}
Ejemplo n.º 15
0
int main() {
    vga_fd = open("/dev/vga", O_RDONLY);
    ioctl(vga_fd, SETVGAMODE, (void*)vga_mode_320x200x256); 

    int fd = open("/dev/mouse", O_RDONLY);
    mousestate_t data;

    int ballX = WIDTH/2 - BALL_SIZE / 2;
    int ballY = HEIGHT/2 - BALL_SIZE /2;
    int velX = 10;
    int velY = 10;

    char color = 1;

    while (1) {
	clear_buffer(buffer);

	// read mouse position
	read(fd, &data, sizeof(data));
	data.y = 199 - data.y;
	data.x = data.x * WIDTH / 320;
	data.y = data.y * HEIGHT / 200;

	// draw ball and racket
	moveBall(&ballX,&ballY,&velX,&velY,data.y);
	drawBall(ballX,ballY,color);
	drawRacket(data.y,color);
	ioctl(vga_fd, FLUSHVGA, buffer);
	
	usleep(10000);
    }
    return 0;
}
Ejemplo n.º 16
0
// Pop up the Idle screen
void idle_screen(void)
{
	clear_buffer();
	LCD_Display_Text(121,(prog_uchar*)Verdana14,40,12); // "Press"
	LCD_Display_Text(122,(prog_uchar*)Verdana14,24,32); // "for status"
	write_buffer();
};
Ejemplo n.º 17
0
	/*************************************************************
	 * make_lookup_keyword:
	 *************************************************************/
struct cmd_struct  *make_lookup_keyword( /* Return: addr of cmd_struct	*/
    struct cduKeyword  keywordList[]	/* <r> keyword list		*/
   )
   {
    int   i;
    int   icnt;
    struct cmd_struct  *cmd;
    struct cduKeyword  *key;

		/*=====================================================
		 * Check size of keywordList[] ...
		 *====================================================*/
    for (icnt=0,key=keywordList ; key->keyA_name ; icnt++,key++)
        ;

    cmd = malloc((icnt+1)*sizeof(struct cmd_struct));
    if (!cmd)
       {
        fprintf(stderr,"*EXIT* Out of space!\n");
        exit(0);
       }
    clear_buffer(cmd,(icnt+1)*sizeof(struct cmd_struct));
    cmd[0].cmdA_string = (void *)(icnt+1);

		/*======================================================
		 * Initialize cmd[] table ...
		 *=====================================================*/
    for (i=1,key=keywordList ; i<=icnt ; i++,key++)
       {
        cmd[i].cmdL_id = i;
        cmd[i].cmdA_string = key->keyA_name;
       }
    return(cmd);
   }
Ejemplo n.º 18
0
/**
 * Ask for 20 numbers in a loop. When 20 valid numbers are entered, calculate
 * the average and report out the largest, smallest and average numbers.
 *
 * Control the loop by controlling the counter alone, letting the loop worry
 * about itself.
 */
int main()
{
  int i = 1, quantity = 20;
  double number = 0, running_sum = 0, largest_number = 0, smallest_number = 0;

  print_greeting(quantity);

  for (i = 1; i <= quantity; i += 1)
  {
    printf("Enter number %d: ", i);

    if (scanf("%lf", &number))
    {
      running_sum += number;
      smallest_number = compute_smallest_number(number, smallest_number, i);
      largest_number = compute_largest_number(number, largest_number);
    }
    else
    {
      printf("Please only enter numbers! Let's try again...\n");
      i -= 1;
      number = 0.00;
    }

    clear_buffer();
  }

  print_statistics(running_sum, quantity, smallest_number, largest_number);

  return 0;
}
Ejemplo n.º 19
0
char get_char(void)
{
	// Variables
	int success = 0;
	char cont, invalid;

	printf("\nWould you like to recalculate your budget? (Y/N): ");
	do
	{
		invalid = ' '; // Prevents infinite loop
		scanf("%c%c", &cont, &invalid);

		cont = toupper(cont);

		// Checks if cont is a Y or N or if invalid is a newline character
		if (cont != 'Y' && cont != 'N' || invalid != '\n')
		{
			printf("Error! Please enter Y to recalculate or N to not recalculate: ");

			// If not a newline character clear the buffer
			if (invalid != '\n')
			{
				clear_buffer();
			}
		}
		else // Success
		{
			success = 1;
		}		
	} while (success == 0);

	return cont;
}
Ejemplo n.º 20
0
void update_student_ID(int student_id[], char name[], int *num)
{
	int i, id;
	do 
	{
		i = 0;

		printf("\n>>>Student ID: ");
		scanf("%d", &id);

		while(student_id[i] != id && i++ < (*num));

		if (i <= (*num))
		{
			printf("ERROR: %d has been used already!\n", id);
		}

	} while (i <= (*num));

	student_id[(*num)++] = id;

	clear_buffer();
	printf(">>>Name: ");
	gets(name);
}
Ejemplo n.º 21
0
Archivo: prefs.c Proyecto: vigna/ne
static void load_virt_ext(char *vname) {
	/* Our find_regexp() is geared to work on buffers rather than streams, so we'll create a
	   stand-alone buffer. This also buys us proper handling of encodings. */
	buffer * vb = alloc_buffer(NULL);
	if (vb == NULL) return;
	clear_buffer(vb);
	vb->opt.auto_prefs = 0;
	vb->opt.do_undo = 0;
	vb->opt.case_search = 0;
	if (load_file_in_buffer(vb, vname) != OK) return;

	bool skip_first = false;
	vb->find_string = "^\\s*(\\w+)\\s+([0-9]+i?)\\s+(.+[^ \\t])\\s*$|^\\.([^ \\t/]+)\\s*$";
	vb->find_string_changed = 1;

	if ((virt_ext = realloc(virt_ext, (num_virt_ext + vb->num_lines) * sizeof *virt_ext))
			&& (extra_ext = realloc(extra_ext, (num_extra_exts + vb->num_lines) * sizeof *extra_ext))) {
		while (find_regexp(vb, NULL, skip_first, false) == OK) {
			skip_first = true;
			if (nth_regex_substring_nonempty(vb->cur_line_desc, 1)) {
				char * const ext          = nth_regex_substring(vb->cur_line_desc, 1);
				char * const max_line_str = nth_regex_substring(vb->cur_line_desc, 2);
				char * const regex        = nth_regex_substring(vb->cur_line_desc, 3);
				if (!ext || !max_line_str || !regex) break;

				errno = 0;
				char *endptr;
				int64_t max_line = strtoll(max_line_str, &endptr, 0);
				if (max_line < 1 || errno) max_line = INT64_MAX;

				int i;
				for(i = 0; i < num_virt_ext; i++)
					if (strcmp(virt_ext[i].ext, ext) == 0) {
						free(virt_ext[i].ext);
						free(virt_ext[i].regex);
						break;
					}

				virt_ext[i].ext = ext;
				virt_ext[i].max_line = max_line;
				virt_ext[i].regex = regex;
				virt_ext[i].case_sensitive = *endptr != 'i';
				free(max_line_str);
				if (i == num_virt_ext) num_virt_ext++;
			}
			else {
				char * const ext = nth_regex_substring(vb->cur_line_desc, 4);
				if (! ext) break;
				int i;
				for(i = 0; i < num_extra_exts; i++)
					if (strcmp(extra_ext[i], ext) == 0) break;
				if (i == num_extra_exts) extra_ext[num_extra_exts++] = ext;
				else free(ext);
			}
		}
	}

	vb->find_string = NULL; /* Or free_buffer() would free() it. */
	free_buffer(vb);
}
Ejemplo n.º 22
0
double get_double(void)
{
	// Variables
	int success = 0;
	double number = 0;
	char invalid;	

	do 
	{
		invalid = ' '; // Prevents infinite loop
		scanf("%lf%c", &number, &invalid);

		if (invalid != '\n') // Not a newline character
		{
			printf("Error! Please enter a number: ");
			clear_buffer();
		}		
		else if (number < 0) // Negative number
		{
			printf("Error! Please enter a positive number: ");
		}
		else // Success
		{
			success = 1;
		}		
	} while (success == 0);

	return number;
}
Ejemplo n.º 23
0
void effect(void)
{
	// TODO use real kernels instead of loops!
	
	clear_buffer();

	for (uint8_t x=0; x<8; x++) {
		for (uint8_t y=0; y<8; y++) {
			srand(3*(x*LEDS_Y+y));
			set_led(x,y,((ticks >> 3)+rand()) & 7, MAX_INTENSITY >> 3);
		}
	}

	const uint8_t water = ((ticks >> 7) % 7) + 1;
	const uint8_t surface = ticks & 127;

	for (uint8_t z=0; z<water; z++) {
		for (uint8_t x=0; x<8; x++) {
			for (uint8_t y=0; y<8; y++) {
				set_led(x,y,7-z, MAX_INTENSITY);
			}
		}
	}

	for (uint8_t x=0; x<8; x++) {
		for (uint8_t y=0; y<8; y++) {
			set_led(x,y,8-water, weber_fechner(surface << 1));
		}
	}
}
Ejemplo n.º 24
0
	  int TCP_RECEIVEOBJ::start_watching(void)
	  {
	  	if (sock)
		{
			clear_buffer();
  		    sprintf(writebuf,"watch %d\n",streamnum);
			if (SDLNet_TCP_Send(sock, writebuf, strlen(writebuf))==strlen(writebuf))
			{
				read_tcp(watchbuf, 6);
				if (!strcmp(watchbuf,"200 OK"))
				{
				   watching=TRUE;
				   cout << "start watching.\n";
				   packetcount=0;bufstart=0; bufend=0;
				   QueryPerformanceCounter((_LARGE_INTEGER *)&timestamp);
				   return(200);
				}
			}
			SDLNet_TCP_Close(sock);
		    sock=0;
		}
		watching=FALSE;
/*		if (hDlg==ghWndToolbox)
		{
			close_toolbox();
			actobject=this;
			make_dialog();
		}*/
		return(0);
	  }
Ejemplo n.º 25
0
	  void TCP_RECEIVEOBJ::reset(void)
	  {
      /*
		int x;
	  		  for (x=0;x<MAX_CONNECTS;x++)
		  {
			  out[x].from_port=-1;
			  out[x].to_port=-1;
			  out[x].to_object=-1;
		  }
		  for (x=0;x<MAX_PORTS;x++)
		  {
			  out_ports[x].out_name[0]=0;
			  strcpy(out_ports[x].out_dim,"none");
			  strcpy(out_ports[x].out_desc,"none");
		      out_ports[x].out_min=-1.0f;
		      out_ports[x].out_max=1.0f;
		  }
		  outports=0;
		  inports=0;
		  height=50;
*/
		  if (sock)
		  {
			clear_buffer();
			strcpy(writebuf,"close\n");
			SDLNet_TCP_Send(sock, writebuf, strlen(writebuf));
			SDLNet_TCP_Close(sock);
			sock=0;
			cout << "closed.\n";
		  } 
		  streamnum=-1;
		  watching=false;

	  }
Ejemplo n.º 26
0
int set_raw_string(buffer_t *buffer, char* str)
{
	size_t len = strlen(str)+1;
	clear_buffer(buffer);
	if(add_buffer(buffer, str, len)) return 1;
	return 0;
}
Ejemplo n.º 27
0
Archivo: input.c Proyecto: dmt4/ne
static void init_history(void) {
	if (!history_buff){
		history_buff = alloc_buffer(NULL);
		if (history_buff) {
			const char * const history_filename = tilde_expand("~/.ne/.history");
			clear_buffer(history_buff);
			history_buff->opt.do_undo = 0;
			history_buff->opt.auto_prefs = 0;
			load_file_in_buffer(history_buff, history_filename);
			/* The history buffer is agnostic. The actual encoding of each line is detected dynamically. */
			history_buff->encoding = ENC_8_BIT;
			change_filename(history_buff, str_dup(history_filename));
			assert_buffer(history_buff);

			/* This should be never necessary with new histories, as all lines will
				be terminated by a life feed, but it is kept for backward
				compatibility. */

			move_to_bof(history_buff);
			if (history_buff->cur_line_desc->line && history_buff->cur_line_desc->line_len) {
				insert_stream(history_buff,
								  history_buff->cur_line_desc,
								  history_buff->cur_line,
								  history_buff->cur_line_desc->line_len,
								  "", 1);
			}
		}
	}
	if (history_buff) {
		move_to_bof(history_buff);
		move_to_sol(history_buff);
	}
}
Ejemplo n.º 28
0
void 
MapDrawHelper::buffer_render_start() 
{
  if (!m_buffer_drawn) {
    clear_buffer();
    m_buffer_drawn = true;
  }
}
Ejemplo n.º 29
0
handler_t  recv_data(void * e, void * s) {
    char buff[1024];
    int32_t len = 0;
    int32_t offset = 0;
    socket_t * st = (socket_t *)s;
    connection * ct = st->ct;
    if (st->status == ISWRITE) {
        while (1) {
            memset(buff, 0, sizeof(buff));
            len = recv(st->fd, buff, sizeof(buff) - 1, 0);
            if (len == 0) {
                break; //木有数据了
            }else if (len == -1) {
                //出错了
            }else {
                while (len > 0) {
                // printf("len = %d\n",len);
                // printf("get_buffer_remaining(ct->packet) = %d\n",get_buffer_remaining(ct->packet));
                if (buffer_has_remaining(ct->packet)) {
                    int32_t remaining = get_buffer_remaining(ct->packet);
                    if (remaining >= len) {
                        put_buffers_len(ct->packet, buff, offset, len);
                        if (buffer_has_remaining(ct->packet) == false) {
                            flip_buffer(ct->packet);
                            read_all_packet(ct);
                            clear_buffer(ct->packet);
                        }
                        offset = 0;
                        len = 0;
                    }
                    else {
                        put_buffers_len(ct->packet, buff, offset, remaining);
                        flip_buffer(ct->packet);
                        read_all_packet(ct);
                        clear_buffer(ct->packet);
                        offset += remaining;
                        len -= remaining;
                        }
                    }
                }
            }
        }
    }
    return HANDLER_GO_ON;
}
Ejemplo n.º 30
0
void
piglit_init(int argc, char **argv)
{
	bool pass = true;
	GLuint buffer;
	int i;
	unsigned offset, size;
	char *cpu = malloc(SIZE);

	if (!cpu)
		piglit_report_result(PIGLIT_FAIL);

	for (i = 1; i < argc; i++)
		if (!strcmp(argv[i], "-debug"))
			debug = true;

	piglit_require_extension("GL_ARB_clear_buffer_object");
	glGenBuffers(1, &buffer);
	glBindBuffer(GL_ARRAY_BUFFER, buffer);
	glBufferData(GL_ARRAY_BUFFER, SIZE, NULL, GL_STREAM_READ);

	clear_buffer(0, 0, SIZE, 0, cpu);

	srand(6487216);
	for (i = 1; i <= 200; i++) {
		offset = rand() % SIZE;
		size = 1 + (rand() % (SIZE - offset));

		clear_buffer(i, offset, size, rand(), cpu);
	}

	/* and some small unaligned copies within one dword */
	for (; i < 230; i++) {
		offset = (rand() % (SIZE/4)) * 4 + 1 + (rand() % 2);
		size = 1;

		clear_buffer(i, offset, size, rand(), cpu);
	}

	pass = piglit_check_gl_error(GL_NO_ERROR) &&
	       check_array_buffer_data(SIZE, cpu);
	glDeleteBuffers(1, &buffer);
	free(cpu);
	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}