/*
 * XXX - the routine pointed to by "print_line_fcn_p" doesn't get handed lines,
 * it gets handed bufferfuls.  That's fine for "follow_write_raw()"
 * and "follow_add_to_gtk_text()", but, as "follow_print_text()" calls
 * the "print_line()" routine from "print.c", and as that routine might
 * genuinely expect to be handed a line (if, for example, it's using
 * some OS or desktop environment's printing API, and that API expects
 * to be handed lines), "follow_print_text()" should probably accumulate
 * lines in a buffer and hand them "print_line()".  (If there's a
 * complete line in a buffer - i.e., there's nothing of the line in
 * the previous buffer or the next buffer - it can just hand that to
 * "print_line()" after filtering out non-printables, as an
 * optimization.)
 *
 * This might or might not be the reason why C arrays display
 * correctly but get extra blank lines very other line when printed.
 */
frs_return_t
FollowStreamDialog::readFollowStream()
{
    guint32 global_client_pos = 0, global_server_pos = 0;
    guint32 *global_pos;
    gboolean skip;
    GList* cur;
    frs_return_t frs_return;
    follow_record_t *follow_record;
    QElapsedTimer elapsed_timer;

    elapsed_timer.start();

    for (cur = follow_info_.payload; cur; cur = g_list_next(cur)) {
        if (dialogClosed()) break;

        follow_record = (follow_record_t *)cur->data;
        skip = FALSE;
        if (!follow_record->is_server) {
            global_pos = &global_client_pos;
            if(follow_info_.show_stream == FROM_SERVER) {
                skip = TRUE;
            }
        } else {
            global_pos = &global_server_pos;
            if (follow_info_.show_stream == FROM_CLIENT) {
                skip = TRUE;
            }
        }

        QByteArray buffer;
        if (!skip) {
            // We want a deep copy.
            buffer.clear();
            buffer.append((const char *) follow_record->data->data,
                                     follow_record->data->len);
            frs_return = showBuffer(
                        buffer.data(),
                        follow_record->data->len,
                        follow_record->is_server,
                        follow_record->packet_num,
                        global_pos);
            if(frs_return == FRS_PRINT_ERROR)
                return frs_return;
            if (elapsed_timer.elapsed() > info_update_freq_) {
                fillHintLabel(ui->teStreamContent->textCursor().position());
                wsApp->processEvents();
                elapsed_timer.start();
            }
        }
    }

    return FRS_OK;
}
/*
 * XXX - the routine pointed to by "print_line_fcn_p" doesn't get handed lines,
 * it gets handed bufferfuls.  That's fine for "follow_write_raw()"
 * and "follow_add_to_gtk_text()", but, as "follow_print_text()" calls
 * the "print_line()" routine from "print.c", and as that routine might
 * genuinely expect to be handed a line (if, for example, it's using
 * some OS or desktop environment's printing API, and that API expects
 * to be handed lines), "follow_print_text()" should probably accumulate
 * lines in a buffer and hand them "print_line()".  (If there's a
 * complete line in a buffer - i.e., there's nothing of the line in
 * the previous buffer or the next buffer - it can just hand that to
 * "print_line()" after filtering out non-printables, as an
 * optimization.)
 *
 * This might or might not be the reason why C arrays display
 * correctly but get extra blank lines very other line when printed.
 */
frs_return_t
FollowStreamDialog::readUdpStream()
{
    guint32 global_client_pos = 0, global_server_pos = 0;
    guint32 *global_pos;
    gboolean skip;
    GList* cur;
    frs_return_t frs_return;
    follow_record_t *follow_record;
    char *buffer;

    for (cur = follow_info_.payload; cur; cur = g_list_next(cur)) {
        follow_record = (follow_record_t *)cur->data;
        skip = FALSE;
        if (!follow_record->is_server) {
            global_pos = &global_client_pos;
            if(follow_info_.show_stream == FROM_SERVER) {
                skip = TRUE;
            }
        } else {
            global_pos = &global_server_pos;
            if (follow_info_.show_stream == FROM_CLIENT) {
                skip = TRUE;
            }
        }

        if (!skip) {
            buffer = (char *)g_memdup(follow_record->data->data,
                                      follow_record->data->len);

            frs_return = showBuffer(
                        buffer,
                        follow_record->data->len,
                        follow_record->is_server,
                        follow_record->packet_num,
                        global_pos);
            g_free(buffer);
            if(frs_return == FRS_PRINT_ERROR)
                return frs_return;
        }
    }

    return FRS_OK;
}
Example #3
0
File: menu.c Project: lkjcalc/nTxt
int menu(void* scrbuf, const char* menuentries[])
{
    int selecteditem = 1;
    int lastitem;

    int blockarrow = 0;
    int inputpause = INPUTPAUSE;

    while (1) {
        sleep(10); //results in around 63 fps

        lastitem = dispMenu(scrbuf, 0, 0, menuentries, selecteditem);
        showBuffer(scrbuf);

        //closing menu:
        if (isKeyPressed(KEY_NSPIRE_ESC) || on_key_pressed())
            return 0;

        //choosing an option:
        if (isKeyPressed(KEY_NSPIRE_ENTER))
            return selecteditem;

        //navigating:
        if (isKeyPressed(KEY_NSPIRE_UP) && (blockarrow != 0x1 || inputpause <= 0)) {
            inputpause = INPUTPAUSE;
            blockarrow = 0x1;
            selecteditem--;
            if (selecteditem == 0)
                selecteditem = lastitem;
        }
        else if (isKeyPressed(KEY_NSPIRE_DOWN) && (blockarrow != 0x2 || inputpause <= 0)) {
            inputpause = INPUTPAUSE;
            blockarrow = 0x2;
            selecteditem++;
            if (selecteditem > lastitem)
                selecteditem = 1;
        }

        if (!isKeyPressed(KEY_NSPIRE_UP) && !isKeyPressed(KEY_NSPIRE_DOWN))
            blockarrow = 0;
        else
            inputpause--;
    }
}
/*
 * XXX - the routine pointed to by "print_line_fcn_p" doesn't get handed lines,
 * it gets handed bufferfuls.  That's fine for "follow_write_raw()"
 * and "follow_add_to_gtk_text()", but, as "follow_print_text()" calls
 * the "print_line()" routine from "print.c", and as that routine might
 * genuinely expect to be handed a line (if, for example, it's using
 * some OS or desktop environment's printing API, and that API expects
 * to be handed lines), "follow_print_text()" should probably accumulate
 * lines in a buffer and hand them "print_line()".  (If there's a
 * complete line in a buffer - i.e., there's nothing of the line in
 * the previous buffer or the next buffer - it can just hand that to
 * "print_line()" after filtering out non-printables, as an
 * optimization.)
 *
 * This might or might not be the reason why C arrays display
 * correctly but get extra blank lines very other line when printed.
 */
frs_return_t
FollowStreamDialog::readSslStream()
{
    guint32      global_client_pos = 0, global_server_pos = 0;
    guint32 *    global_pos;
    GList *      cur;
    frs_return_t frs_return;

    for (cur = follow_info_.payload; cur; cur = g_list_next(cur)) {
        SslDecryptedRecord * rec = (SslDecryptedRecord*) cur->data;
        gboolean             include_rec = FALSE;

        if (rec->is_from_server) {
            global_pos = &global_server_pos;
            include_rec = (follow_info_.show_stream == BOTH_HOSTS) ||
                    (follow_info_.show_stream == FROM_SERVER);
        } else {
            global_pos = &global_client_pos;
            include_rec = (follow_info_.show_stream == BOTH_HOSTS) ||
                    (follow_info_.show_stream == FROM_CLIENT);
        }

        if (include_rec) {
            size_t nchars = rec->data.data_len;
            gchar *buffer = (gchar *)g_memdup(rec->data.data, (guint) nchars);

            frs_return = showBuffer(buffer, nchars,
                                     rec->is_from_server, rec->packet_num, global_pos);
            g_free(buffer);
            if (frs_return == FRS_PRINT_ERROR)
                return frs_return;
        }
    }

    return FRS_OK;
}
Example #5
0
int
beSlave(int ppiFD, UINT16 bufX, UINT16 bufY, int dims)
{
	int	retval;
	int	done = 0;
	int	bytes_read;
	CfgTable	*table;


	gRows = bufX;
	gCols = bufY;
	realloc_image();
	if ( gImage == NULL ){
		return(-1);
	}

	printf("Setting up slave...to read %d bytes", gImageSize);


	if ( dims == DIM2D ){
		table = ppiSlaveTable2D;
		/* 2D configuration */
		retval = ioctl( ppiFD, CMD_PPI_NUMLINES, bufY  );
		if(retval){
			perror("ppi ioctl error");
			return(-1);
		}
		retval = ioctl( ppiFD, CMD_PPI_LINELEN, bufX );
		if(retval){
			perror("ppi ioctl error");
			return(-1);
		}
	}
	else {
		/* 1D configuration */
		table = ppiSlaveTable1D;
		retval = ioctl( ppiFD, CMD_PPI_XFR_TYPE, CFG_PPI_XFR_TYPE_NO_SYNC );
		if(retval){
			perror("ppi ioctl error");
			return(-1);
		}
		retval = ioctl( ppiFD, CMD_PPI_PORT_CFG, CFG_PPI_PORT_CFG_SYNC1 );
		if(retval){
			perror("ppi ioctl error");
			return(-1);
		}
	}
	config_device( ppiFD, table );

	/* show configuration */
	ioctl( ppiFD, CMD_PPI_GET_ALLCONFIG, 0);

	printf("Slave set up complete...following output is received from master...\n");

	// read image from PPI 
	// print out what is received
	while (!done) {
		bytes_read = read( ppiFD, (char *)gImage, gImageSize );
		if ( (*gImage & 0x07FF) == 0x06ad )
			done = 1;
		else{
			showBuffer( (UINT16 *)gImage, bufX, bufY, 0x0FFF );
		}
	}
	return(0);
}
Example #6
0
int
beMaster(int ppiFD, UINT16 bufX, UINT16 bufY, int dims)
{
	int	retval;
	UINT16	value = 0;
	int done = 0;
	char	buf[128];
	CfgTable	*table;

	printf("Setting up master...");
#ifdef DEBUG
	ioctl( ppiFD, CMD_PPI_GET_ALLCONFIG, 0);
#endif

	gRows = bufX;
	gCols = bufY;
	gImage = realloc_image();
	if ( gImage == NULL ){
		return(-1);
	}

	/* fill in common values */
	if ( dims == DIM2D ){
		table = ppiMasterTable2D;
		/* 2D configuration */
		retval = ioctl( ppiFD, CMD_PPI_NUMLINES, bufY  );
		if(retval){
			perror("ppi ioctl error");
			return(-1);
		}
		retval = ioctl( ppiFD, CMD_PPI_LINELEN, bufX );
		if(retval){
			perror("ppi ioctl error");
			return(-1);
		}
	}
	else {
		/* 1D configuration */
		table = ppiMasterTable1D;
	}

	config_device( ppiFD, table );
	printf("Master set up complete...further input is transmited to slave\n");
#ifdef DEBUG
	ioctl( ppiFD, CMD_PPI_GET_ALLCONFIG, 0);
#endif

	while ( !done )
	{
		printf("Enter fill pattern [CcQqRrTtVvHh?]:  ");

		if ( fgets( buf, sizeof(buf), stdin ) == NULL ){
			done = 1;
			break;
		}
		switch( buf[0] ) {
			case 'q':
			case 'Q':
				done = 1;
				value = 0xdead;
				gPatternID = 'q';
				break;

			case 'v':
			case 'V':
				gPatternID = 'v';
				printf("\nEnter fill value: ");
				if ( fgets( buf, sizeof(buf), stdin ) == NULL ){
					done = 1;
					break;
				}
				if ( sscanf(buf, "%hx", &value) != 1 ){
					printf("\nError reading value...retry\n");
					continue;
				}
				break;

			case 'h':
			case 'H':
			case '?':
				printf("\nColumn, Row, Sequential, Tile, Value, Help?, Quit\n");
				continue;
				break;

			default:
				gPatternID = buf[0];
		}
				
		fillBuffer( (UINT16 *)gImage, bufX, bufY, gPatternID, value );
		showBuffer( (UINT16 *)gImage, bufX, bufY, 0x0FFF );

		retval = write( ppiFD, gImage, gImageSize );
		if ( retval != gImageSize ){
			perror("ppi write error");
			done = 1;
		}
	}

	printf("Done \n");

	return(0);
}
/*
 * XXX - the routine pointed to by "print_line_fcn_p" doesn't get handed lines,
 * it gets handed bufferfuls.  That's fine for "follow_write_raw()"
 * and "follow_add_to_gtk_text()", but, as "follow_print_text()" calls
 * the "print_line()" routine from "print.c", and as that routine might
 * genuinely expect to be handed a line (if, for example, it's using
 * some OS or desktop environment's printing API, and that API expects
 * to be handed lines), "follow_print_text()" should probably accumulate
 * lines in a buffer and hand them "print_line()".  (If there's a
 * complete line in a buffer - i.e., there's nothing of the line in
 * the previous buffer or the next buffer - it can just hand that to
 * "print_line()" after filtering out non-printables, as an
 * optimization.)
 *
 * This might or might not be the reason why C arrays display
 * correctly but get extra blank lines very other line when printed.
 */
frs_return_t
FollowStreamDialog::readTcpStream()
{
    FILE *data_out_fp;
    tcp_stream_chunk    sc;
    size_t              bcount;
    size_t              bytes_read;
    int                 iplen;
    guint8              client_addr[MAX_IPADDR_LEN];
    guint16             client_port = 0;
    gboolean            is_server;
    guint32             global_client_pos = 0, global_server_pos = 0;
    guint32             *global_pos;
    gboolean            skip;
    char                buffer[FLT_BUF_SIZE+1]; /* +1 to fix ws bug 1043 */
    size_t              nchars;
    frs_return_t        frs_return;

    iplen = (follow_info_.is_ipv6) ? 16 : 4;

    data_out_fp = ws_fopen(data_out_filename_.toUtf8().constData(), "rb");
    if (data_out_fp == NULL) {
        QMessageBox::critical(this, "Error",
                      "Could not open temporary file %1: %2", data_out_filename_,
                      g_strerror(errno));
        return FRS_OPEN_ERROR;
    }

    while ((nchars=fread(&sc, 1, sizeof(sc), data_out_fp))) {
        if (nchars != sizeof(sc)) {
            QMessageBox::critical(this, "Error",
                          QString(tr("Short read from temporary file %1: expected %2, got %3"))
                          .arg(data_out_filename_)
                          .arg(sizeof(sc))
                          .arg(nchars));
            fclose(data_out_fp);
            data_out_fp = NULL;
            return FRS_READ_ERROR;
        }
        if (client_port == 0) {
            memcpy(client_addr, sc.src_addr, iplen);
            client_port = sc.src_port;
        }
        skip = FALSE;
        if (memcmp(client_addr, sc.src_addr, iplen) == 0 &&
                client_port == sc.src_port) {
            is_server = FALSE;
            global_pos = &global_client_pos;
            if (follow_info_.show_stream == FROM_SERVER) {
                skip = TRUE;
            }
        } else {
            is_server = TRUE;
            global_pos = &global_server_pos;
            if (follow_info_.show_stream == FROM_CLIENT) {
                skip = TRUE;
            }
        }

        bytes_read = 0;
        while (bytes_read < sc.dlen) {
            bcount = ((sc.dlen-bytes_read) < FLT_BUF_SIZE) ? (sc.dlen-bytes_read) : FLT_BUF_SIZE;
            nchars = fread(buffer, 1, bcount, data_out_fp);
            if (nchars == 0)
                break;
            /* XXX - if we don't get "bcount" bytes, is that an error? */
            bytes_read += nchars;

            if (!skip)
            {
                frs_return = showBuffer(buffer,
                                         nchars, is_server, sc.packet_num, global_pos);
                if(frs_return == FRS_PRINT_ERROR) {
                    fclose(data_out_fp);
                    data_out_fp = NULL;
                    return frs_return;
                }

            }
        }
    }

    if (ferror(data_out_fp)) {
        QMessageBox::critical(this, tr("Error reading temporary file"),
                           QString("%1: %2").arg(data_out_filename_).arg(g_strerror(errno)));
        fclose(data_out_fp);
        data_out_fp = NULL;
        return FRS_READ_ERROR;
    }

    fclose(data_out_fp);
    data_out_fp = NULL;
    return FRS_OK;
}
Example #8
0
int filebrowser(void* scrbuf, char* file, char* title)
{
    char currentdir[FILENAME_MAX + 1];
    char* filenames[1024];
    char filenameinput[FILENAME_MAX + 1] = "";
    char blockc = '\0';
    int focus_filenameinput = 1;
    int num_files;
    int filescroll = 0;
    int fileselected = 0;
    int i;
    int inputpause = 0;
    if (get_last_doc(currentdir) != 0) {
        getcwd(currentdir, FILENAME_MAX + 1);
    }
    else {
        *(strrchr(currentdir, '/') + 1) = '\0';
    }

    num_files = get_filenames(currentdir, filenames);
    if (num_files == -1)
        return 1;

    wait_no_key_pressed();
    while (1) {
        //disp:
        clearScreen(scrbuf);
        filledRect(scrbuf, 0, TITLE_Y, SCREEN_WIDTH, TITLE_HEIGHT, 0);
        dispStringColor(scrbuf, 4, (TITLE_HEIGHT - CHAR_HEIGHT) / 2, title, WHITE_COLOR, 0);
        dispHorizLine(scrbuf, 0, DIR_Y + DIR_HEIGHT - 1, 320, 0);
        dispString(scrbuf, 4, DIR_Y + (DIR_HEIGHT - CHAR_HEIGHT) / 2, currentdir);
        dispHorizLine(scrbuf, 0, FILENAMEINPUT_Y, 320, 0);
        dispString(scrbuf, 4, FILENAMEINPUT_Y + (FILENAMEINPUT_HEIGHT - CHAR_HEIGHT) / 2, "Filename:");
        dispString(scrbuf, 4 + 10 * CHAR_WIDTH, FILENAMEINPUT_Y + (FILENAMEINPUT_HEIGHT - CHAR_HEIGHT) / 2, filenameinput);
        if (focus_filenameinput)//if cursor is in the file name input field, disp an underline to show it
            putChar(scrbuf, 4 + (10 + strlen(filenameinput)) * CHAR_WIDTH, FILENAMEINPUT_Y + (FILENAMEINPUT_HEIGHT - CHAR_HEIGHT) / 2, '_');
        for (i = filescroll; i < filescroll + FILES_SHOWN && i < num_files; i++) {
            //disp file symbol
            if (is_dir(filenames[i]) && strcmp(filenames[i], ".") && strcmp(filenames[i], ".."))
                putChar(scrbuf, CHAR_WIDTH * 2, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, '\\');
            //disp filename, filesize and selection
            if (i != fileselected || focus_filenameinput) {
                dispString(scrbuf, CHAR_WIDTH * 3, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, filenames[i]);
                if (!is_dir(filenames[i])) {
                    char size[16];
                    get_filesize(filenames[i], size);
                    dispString(scrbuf, FILENAME_WIDTH, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, size);
                }
            }
            else {
                filledRect(scrbuf, CHAR_WIDTH * 3, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT - 1, SCREEN_WIDTH - CHAR_WIDTH * 4, CHAR_HEIGHT + 2, MENU_SELECTION_COLOR);
                dispStringColor(scrbuf, CHAR_WIDTH * 3, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, filenames[i], WHITE_COLOR, MENU_SELECTION_COLOR);
                if (!is_dir(filenames[i])) {
                    char size[16];
                    get_filesize(filenames[i], size);
                    dispStringColor(scrbuf, FILENAME_WIDTH, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, size, WHITE_COLOR, MENU_SELECTION_COLOR);
                }
            }
        }
        showBuffer(scrbuf);


        //input
        if (!any_key_pressed())
            inputpause = 0;
        else
            inputpause--;

        if (isKeyPressed(KEY_NSPIRE_ESC))
            break;
        if (isKeyPressed(KEY_NSPIRE_TAB)) {
            focus_filenameinput = !focus_filenameinput;
            wait_no_key_pressed();
        }

        if (!focus_filenameinput) {
            if (isKeyPressed(KEY_NSPIRE_ENTER) && (blockc != '\n' || inputpause <= 0)) {
                inputpause = INPUTPAUSE;
                blockc = '\n';
                if (is_dir(filenames[fileselected])) {
                    chdir(filenames[fileselected]);
                    filescroll = 0;
                    fileselected = 0;
                    free_filenames(filenames);
                    getcwd(currentdir, FILENAME_MAX + 1);
                    num_files = get_filenames(currentdir, filenames);
                }
                else {
                    strcpy(file, currentdir);
                    strcat(file, filenames[fileselected]);
                    free_filenames(filenames);
                    printf("%s\n", file);
                    return 0;
                }
            }
            else if (isKeyPressed(KEY_NSPIRE_UP) && (blockc != 0x1 || inputpause <= 0)) {
                inputpause = INPUTPAUSE;
                blockc = 0x1;
                fileselected--;
                if (fileselected < 0) {
                    fileselected = num_files - 1;
                    filescroll = num_files - FILES_SHOWN;
                    if (filescroll < 0)
                        filescroll = 0;
                }
                else if (fileselected - filescroll < 0)
                    filescroll--;
                strcpy(filenameinput, filenames[fileselected]);
            }
            else if (isKeyPressed(KEY_NSPIRE_DOWN) && (blockc != 0x2 || inputpause <= 0)) {
                inputpause = INPUTPAUSE;
                blockc = 0x2;
                fileselected++;
                if (fileselected >= num_files) {
                    fileselected = 0;
                    filescroll = 0;
                }
                else if (fileselected - filescroll >= FILES_SHOWN)
                    ++filescroll;
                strcpy(filenameinput, filenames[fileselected]);
            }
        }
        else { //focus_filenameinput
            char c = readc();
            if (c == blockc && inputpause > 0)
                continue;
            if (c != '\0' && c != '\t' && c != '\n') {
                inputpause = INPUTPAUSE;
                blockc = c;
                if (c == '\b') {
                    if (filenameinput[0] != '\0')
                        filenameinput[strlen(filenameinput) - 1] = '\0';
                }
                else {
                    filenameinput[strlen(filenameinput)] = c;
                    filenameinput[strlen(filenameinput) + 1] = '\0';
                }
            }
            if (isKeyPressed(KEY_NSPIRE_UP) || isKeyPressed(KEY_NSPIRE_TAB)) {
                inputpause = INPUTPAUSE;
                focus_filenameinput = 0;
            }
            if (isKeyPressed(KEY_NSPIRE_ENTER)) {
                strcpy(file, currentdir);
                strcat(file, filenameinput);
                free_filenames(filenames);
                printf("%s\n", file);
                return 0;
            }
        }
        sleep(10);
    }

    free_filenames(filenames);
    return 1;
}