Exemple #1
0
void ConsoleAddText(char *text)
{
	int l, size;
	DrawConsole = true;

	SendMessage(HEdit1, WM_SETREDRAW, 0, 0);
	SendMessage(HEdit1, EM_SETREADONLY, 0, 0);

	//  set the carriage in the end of the text
	l = SendMessage(HEdit1, WM_GETTEXTLENGTH, 0, 0);

	size = l + strlen(text) + strchrn(text, '\n');
	if (HEdit1_size <= size)
	{
		SendMessage(HEdit1, WM_GETTEXT, HEdit1_size, (LPARAM)HEdit1_buf);
		SendMessage(HEdit1, WM_SETTEXT, 0, (LPARAM)(HEdit1_buf + size + 1 - HEdit1_size));
		l = SendMessage(HEdit1, WM_GETTEXTLENGTH, 0, 0);
	}

	SendMessage(HEdit1, EM_SETSEL, l, l);

	while (*text)
		SendMessage(HEdit1, WM_CHAR, *text++, 1);
	SendMessage(HEdit1, EM_SETREADONLY, 1, 0);
	SendMessage(HEdit1, WM_SETREDRAW, 1, 0);
}
Exemple #2
0
void onPacket(char* payload, uint16_t len
    , BSPConsoleReplyFn replyFn, void* replyParam) {
#   define COMMAND_BUFFER_SIZE 256
	static char commandBuffer[COMMAND_BUFFER_SIZE];
	static char* bufferPtr = commandBuffer;
#   define REPLY_BUFFER_SIZE 1024
	char reply[REPLY_BUFFER_SIZE];

    if((bufferPtr + len) >= (commandBuffer + COMMAND_BUFFER_SIZE)) {
		/* Too big; can't handle it */
		sprintf(reply, "Command length > maximum allowed %d\n"
				, COMMAND_BUFFER_SIZE);
        replyFn(reply, REPLY_BUFFER_SIZE, replyParam);
	} else { /* Buffer away the command */
    	char* found = strchrn(payload, ';', len);
		if(!found) { /* Command continues in later packet */
			strncpy(bufferPtr, payload, len);
			bufferPtr += len;
		} else {
            /* Command end received; form a whole command WITHOUT
                command end; Continue from last partial string */
			strncpy(bufferPtr, payload, found - payload);

            /* Terminating NULL at the end of the complete command */
            commandBuffer[(bufferPtr-commandBuffer) + (found-payload)] = 0;

            sprintf(reply, "Received signal: %s\n", commandBuffer);
            replyFn(reply, REPLY_BUFFER_SIZE, replyParam);

            if(!onCommandline(commandBuffer)) {
            	sprintf(reply, "Invalid signal.\n%s", USAGE);
                replyFn(reply, REPLY_BUFFER_SIZE, replyParam);
            }
            replyFn(PROMPT, REPLY_BUFFER_SIZE, replyParam);

			bufferPtr = commandBuffer;   /* Restore the temp pointer to head */
			
			if(len > (++found - payload)) { /* Copy remainder */
                uint16_t remain;
                remain = len - (found - payload);
                strncpy(bufferPtr, found, remain);
                bufferPtr += remain;
            }
		}
    }
}
Exemple #3
0
/* Read keys using MMAP to speed things up */
std::vector<Keypoint> ReadKeysMMAP(FILE *fp) 
{    
    int i, j, num, len, val, n;

    std::vector<Keypoint> kps;

    struct stat sb;

    /* Stat the file */
    if (fstat(fileno(fp), &sb) < 0) {
	printf("[ReadKeysMMAP] Error: could not stat file\n");
	return kps;
    }

    char *file = (char *)mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, 
			      fileno(fp), 0);

    char *file_start = file;

    char string_buf[1024];
    char *str = string_buf;

    /* Find the first '\n' */
    char *newline = strchr(file, '\n');
    int pos = (int) (newline - file);
	
    memcpy(str, file, pos);
    str[pos] = 0;

    if (sscanf(str, "%d %d%n", &num, &len, &n) != 2) {
	printf("[ReadKeysMMAP] Invalid keypoint file beginning.");
	return kps;
    }

#ifdef KEY_LIMIT
    num = MIN(num, 65536); // we'll store at most 65536 features per
                           // image
#endif /* KEY_LIMIT */

    file += (pos + 1);

    if (len != 128) {
	printf("[ReadKeysMMAP] Keypoint descriptor length invalid "
	       "(should be 128).");
	return kps;
    }

    for (i = 0; i < num; i++) {
	str = string_buf;

	/* Allocate memory for the keypoint. */
	unsigned char *d = new unsigned char[len];
	float x, y, scale, ori;

	/* Find the first '\n' */
	newline = strchr(file, '\n');
	pos = (int) (newline - file);
	
	memcpy(str, file, pos);
	str[pos] = 0;

	if (sscanf(str, "%f %f %f %f%n", &y, &x, &scale, &ori, &n) != 4) {
	    printf("[ReadKeysMMAP] Invalid keypoint file format.");
	    return kps;
	}

	file += (pos + 1);

	/* Find the next seven '\n's */
	str = string_buf;

	char *seventh_newline = strchrn(file, '\n', 7);
	pos = (int) (seventh_newline - file);

	memcpy(str, file, pos);
	str[pos] = 0;

	for (j = 0; j < len; j++) {
	    if (sscanf(str, "%d%n", &val, &n) != 1 || val < 0 || val > 255) {
		printf("[ReadKeysMMAP] Invalid keypoint file value.");
		return kps;
	    }
	    d[j] = (unsigned char) val;
	    str += n;
	}

	file += (pos + 1);

        if (desc)
            kps.Add(Keypoint(x, y, d));
        else
            kps.Add(Keypoint(x, y));
    }

    /* Unmap */
    if (munmap(file_start, sb.st_size) < 0) {
	printf("[ReadKeysMMAP] Error: could not unmap memory\n");
	return kps;
    }

    return kps;    
}