Esempio n. 1
0
static void do_missed(int state, unsigned int input)
{
	char buf[32];
	sprintf(buf,"%d->%dA%dB", input, state/10, state%10);
	gtk_label_set_text(GTK_LABEL(label[current_times-1]), buf);
	reset_input();
}
Esempio n. 2
0
void serve_mouse_event(int x, int y) {
    if (click_room(x, y)) {
        // roomnames.target = get_clicked_roomname(x);
        // update_roomname_win();
        get_online();
        // query_history();
        // query_members();
        // update_chatroom();
    } else if (click_filepath(x, y)) {
        focus_on_target(filepath);
    } else if (click_upload(x, y)) {
        upload_file();
        reset_input();
    } else if (click_inputbox(x, y)) {
        focus_on_target(inputbox);
    } else if (user->download->exist_file) {
        if (click_download(x, y)) {
            wclear(room.console);
            waddstr(room.console, "downloading file...");
            wrefresh(room.console);
            user->download->exist_file = 0;

            init_download();
        } else if (click_cancel(x, y)) {
            wclear(room.console);
            wrefresh(room.console);
            user->download->exist_file = 0;
        }
    }
}
Esempio n. 3
0
Errcode init_input(void)
/* called on startup to initialize the mouse and other input */
{
Errcode err;
static char *idr_names[] = {mouse_idriver_name, 
							summa_idriver_name,
							vconfg.idr_name };
char idr_path[PATH_SIZE];
char *idr_name;

	idr_name = idr_names[vconfg.dev_type];
	make_resource_name(idr_name, idr_path);

	if((err = init_idriver(idr_path,vconfg.idr_modes,
						   vconfg.comm_port)) < Success)
	{
		init_idriver(key_idriver_name, vconfg.idr_modes, 0);
	}

	/* setup input to current icb.input_screen loaded by open_wscreen() */

	reset_input();
	enable_textboxes();

	if (err < Success)
	{
		softerr(err,"!%s","nomouse", idr_name );
	}
	return(0);
}
Esempio n. 4
0
HIDDEN void
convert_input(void)
{

    reset_input();

    while (get_next_record(fpin, 1, 1));
}
Esempio n. 5
0
static void restore_input(brl_t *brl)
{
    reset_input(brl);

    if (brl->saved != NULL) {
        insert_input(brl, brl->saved, strlen(brl->saved));
        brl_free(brl->saved);
        brl->saved = NULL;
    }
}
Esempio n. 6
0
void _tnl_reset_compile_input( GLcontext *ctx,
			    GLuint start,
			    GLuint beginstate,
			    GLuint savedbeginstate )
{
   struct immediate *IM = TNL_CURRENT_IM(ctx);

   reset_input( ctx, start, beginstate, savedbeginstate );
   IM->CopyStart = start;
   IM->LastPrimitive = IM->Start;
}
Esempio n. 7
0
static void
phase_one(void){
#line 1463 "ctangle.w"
phase= 1;
section_count= 0;
reset_input();
skip_limbo();
while(!input_has_ended)scan_section();
check_complete();
phase= 2;
}
Esempio n. 8
0
void reset_game()
{
	random_num = produce_a_random_number();
	current_times = 0;
	reset_guessed();
	reset_input();
	int i = 0;
	for(; i<8; i++)
		gtk_label_set_text(GTK_LABEL(label[i]), "");
	gtk_image_set_from_pixbuf(GTK_IMAGE(image), picture_buf[0]);
}       
Esempio n. 9
0
void
#line 350 "./cwebdir/ctang-w2c.ch"
 phase_one P1H(void){
#line 1463 "./cwebdir/ctangle.w"
phase= 1;
section_count= 0;
reset_input();
skip_limbo();
while(!input_has_ended)scan_section();
check_complete();
phase= 2;
}
Esempio n. 10
0
void midi_init(void) {
	uint32_t i = 0;

	for (i = 0 ; i < MIDI_RX_BUFFER_INDEX_ENTRIES ; i++) {
		midi_rx_buffer[i] = (uint8_t) 0;
	}

	midi_rx_buffer_index_head = (uint16_t) 0;
	midi_rx_buffer_index_tail = (uint16_t) 0;

	reset_input();

	midi_interface_f.init();
}
Esempio n. 11
0
static void do_bad_input(void)
{
	GtkWidget *dialog;
	gchar info[64];
	sprintf(info, "输入数字不完整!\n请输入4个数字");
	dialog = gtk_message_dialog_new(NULL, 
		 GTK_DIALOG_DESTROY_WITH_PARENT,
		 GTK_MESSAGE_ERROR,
		 GTK_BUTTONS_OK, info);
	gtk_window_set_icon(GTK_WINDOW(dialog), window_icon_buf);
	gtk_window_set_title(GTK_WINDOW(dialog), "输入有误");
	gtk_dialog_run(GTK_DIALOG(dialog));
	gtk_widget_destroy(dialog);
	reset_input();
}
Esempio n. 12
0
static void do_pro_duplicate(unsigned int input)
{
	GtkWidget *dialog;
	gchar info[64];
	sprintf(info, "你已经猜过%d了", input);
	dialog = gtk_message_dialog_new(NULL, 
		 GTK_DIALOG_DESTROY_WITH_PARENT,
		 GTK_MESSAGE_ERROR,
		 GTK_BUTTONS_OK, info);
	gtk_window_set_icon(GTK_WINDOW(dialog), window_icon_buf);
	gtk_window_set_title(GTK_WINDOW(dialog), "输入有误");
	gtk_dialog_run(GTK_DIALOG(dialog));
	gtk_widget_destroy(dialog);
	reset_input();
}
Esempio n. 13
0
void _tnl_reset_exec_input( GLcontext *ctx,
			    GLuint start,
			    GLuint beginstate,
			    GLuint savedbeginstate )
{
   TNLcontext *tnl = TNL_CONTEXT(ctx);
   struct immediate *IM = TNL_CURRENT_IM(ctx);

   reset_input( ctx, start, beginstate, savedbeginstate );

   IM->CopyStart = start - tnl->ExecCopyCount;

   IM->Primitive[IM->CopyStart] = ctx->Driver.CurrentExecPrimitive;
   if (tnl->ExecParity)
      IM->Primitive[IM->CopyStart] |= PRIM_PARITY;

   IM->LastPrimitive = IM->CopyStart;
}
Esempio n. 14
0
int brl_read_line(brl_t *brl, char *buf, size_t size)
{
    if (brl->ml == NULL && brl->ml_ops == NULL) {
        reset_input(brl);
        enable_rawmode(brl);
        brl_show_prompt(brl);
        redraw_prompt(brl);
        _brl_process_input(brl);

        if (brl->data > 0)
            snprintf(buf, size, "%s", brl->buf);
        else
            buf[0] = '\0';

        brl_hide_prompt(brl);
        restore_rawmode(brl);

        return brl->data;
    }
    else {
        errno = EINPROGRESS;
        return -1;
    }
}
Esempio n. 15
0
void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal )
{
    input_thread_t* pInput = (input_thread_t*) p_obj;

    assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );

    if( !getIntf()->p_sys->p_input )
    {
        msg_Dbg( getIntf(), "new input %p detected", pInput );

        getIntf()->p_sys->p_input = pInput;
        vlc_object_hold( pInput );

        // update global variables pertaining to this input
        update_current_input();

        // ensure the playtree is also updated
        // (highlights the new item to be played back)
        getPlaytreeVar().onUpdateCurrent( true );
    }

    switch( newVal.i_int )
    {
        case INPUT_EVENT_STATE:
        {
            int state = var_GetInteger( pInput, "state" );
            SET_BOOL( m_cVarStopped, false );
            SET_BOOL( m_cVarPlaying, state != PAUSE_S );
            SET_BOOL( m_cVarPaused, state == PAUSE_S );
            break;
        }

        case INPUT_EVENT_POSITION:
        {
            float pos = var_GetFloat( pInput, "position" );
            SET_STREAMTIME( m_cVarTime, pos, false );
            SET_BOOL( m_cVarSeekable, pos != 0.0 );
            break;
        }

        case INPUT_EVENT_RATE:
        {
            float rate = var_GetFloat( pInput, "rate" );
            char* buffer;
            if( asprintf( &buffer, "%.3g", rate ) != -1 )
            {
                SET_TEXT( m_cVarSpeed, UString( getIntf(), buffer ) );
                free( buffer );
            }
            break;
        }

        case INPUT_EVENT_ES:
        {
            // Do we have audio
            vlc_value_t audio_es;
            var_Change( pInput, "audio-es", VLC_VAR_CHOICESCOUNT,
                            &audio_es, NULL );
            SET_BOOL( m_cVarHasAudio, audio_es.i_int > 0 );
            break;
        }

        case INPUT_EVENT_VOUT:
        {
            vout_thread_t* pVout = input_GetVout( pInput );
            SET_BOOL( m_cVarHasVout, pVout != NULL );
            if( !pVout || pVout == m_pVout )
            {
                // end of input or vout reuse (nothing to do)
                if( pVout )
                    vlc_object_release( pVout );
                break;
            }
            if( m_pVout )
            {
                // remove previous Vout callbacks
                var_DelCallback( m_pVout, "mouse-moved",
                                 onGenericCallback, this );
                vlc_object_release( m_pVout );
                m_pVout = NULL;
            }

            // add new Vout callbackx
            var_AddCallback( pVout, "mouse-moved",
                             onGenericCallback, this );
            m_pVout = pVout;
            break;
        }

        case INPUT_EVENT_CHAPTER:
        {
            vlc_value_t chapters_count;
            var_Change( pInput, "chapter", VLC_VAR_CHOICESCOUNT,
                        &chapters_count, NULL );
            SET_BOOL( m_cVarDvdActive, chapters_count.i_int > 0 );
            break;
        }

        case INPUT_EVENT_RECORD:
            SET_BOOL( m_cVarRecording, var_GetBool( pInput, "record" ) );
            break;

        case INPUT_EVENT_DEAD:
            msg_Dbg( getIntf(), "end of input detected for %p", pInput );

            var_DelCallback( pInput, "intf-event", onGenericCallback2, this );
            var_DelCallback( pInput, "bit-rate", onGenericCallback, this );
            var_DelCallback( pInput, "sample-rate", onGenericCallback, this );
            var_DelCallback( pInput, "can-record" , onGenericCallback, this );
            vlc_object_release( pInput );
            getIntf()->p_sys->p_input = NULL;
            reset_input();
            break;

        default:
            break;
    }
}
Esempio n. 16
0
/**
 * @ingroup midi
 *
 */
static bool parse(void) {
	uint8_t serial_data;
    if (!raw_read(&serial_data)) {
        // No data available.
        return false;
	}

#if 0
    console_putc('|'); console_puthex(serial_data); console_putc('|');
    return false;
#endif

	if (pending_message_index == (uint8_t) 0) {
		// Start a new pending message
		pending_message[0] = serial_data;

		// Check for running status first
		if (is_channel_message(get_type_from_status_byte(running_status_rx))) {
			// Only these types allow Running Status
			// If the status byte is not received, prepend it
			// to the pending message
			if (serial_data < 0x80) {
				pending_message[0] = running_status_rx;
				pending_message[1] = serial_data;
				pending_message_index = (uint8_t) 1;
			}
			// Else: well, we received another status byte,
			// so the running status does not apply here.
			// It will be updated upon completion of this message.
		}

		switch (get_type_from_status_byte(pending_message[0])) {
		// 1 byte messages
		case MIDI_TYPES_START:
		case MIDI_TYPES_CONTINUE:
		case MIDI_TYPES_STOP:
		case MIDI_TYPES_CLOCK:
		case MIDI_TYPES_ACTIVE_SENSING:
		case MIDI_TYPES_SYSTEM_RESET:
		case MIDI_TYPES_TUNE_REQUEST:
			// Handle the message type directly here.
			midi_message.type = get_type_from_status_byte(pending_message[0]);
			midi_message.channel = (uint8_t) 0;
			midi_message.data1 = (uint8_t) 0;
			midi_message.data2 = (uint8_t) 0;
			midi_message.bytes_count = (uint8_t) 1;
			//midi_message.valid = true;
			// \fix Running Status broken when receiving Clock messages.
			// Do not reset all input attributes, Running Status must remain unchanged.
			//resetInput();
			// We still need to reset these
			pending_message_index = (uint8_t) 0;
			pending_message_expected_lenght = (uint8_t) 0;
			return true;
			break;
		// 2 bytes messages
		case MIDI_TYPES_PROGRAM_CHANGE:
		case MIDI_TYPES_AFTER_TOUCH_CHANNEL:
		case MIDI_TYPES_TIME_CODE_QUARTER_FRAME:
		case MIDI_TYPES_SONG_SELECT:
			pending_message_expected_lenght = (uint8_t) 2;
			break;
		// 3 bytes messages
		case MIDI_TYPES_NOTE_ON:
		case MIDI_TYPES_NOTE_OFF:
		case MIDI_TYPES_CONTROL_CHANGE:
		case MIDI_TYPES_PITCH_BEND:
		case MIDI_TYPES_AFTER_TOUCH_POLY:
		case MIDI_TYPES_SONG_POSITION:
			pending_message_expected_lenght = (uint8_t) 3;
			break;
		case MIDI_TYPES_SYSTEM_EXCLUSIVE:
			// The message can be any lenght
			// between 3 and MIDI_SYSTEM_EXCLUSIVE_INDEX_ENTRIES
			pending_message_expected_lenght = MIDI_SYSTEM_EXCLUSIVE_INDEX_ENTRIES;
			running_status_rx = MIDI_TYPES_INVALIDE_TYPE;
			midi_message.system_exclusive[0] = MIDI_TYPES_SYSTEM_EXCLUSIVE;
			break;
		case MIDI_TYPES_INVALIDE_TYPE:
		default:
			// This is obviously wrong. Let's get the hell out'a here.
			reset_input();
			return false;
			break;
		}

		if (pending_message_index >= (pending_message_expected_lenght - (uint8_t) 1)) {
			// Reception complete
			midi_message.type = get_type_from_status_byte(pending_message[0]);
			midi_message.channel = get_channel_from_status_byte(pending_message[0]);
			midi_message.data1 = pending_message[1];

			// Save data2 only if applicable
			if (pending_message_expected_lenght == (uint8_t) 3) {
				midi_message.data2 = pending_message[2];
				midi_message.bytes_count = (uint8_t) 3;
			} else {
				midi_message.data2 = (uint8_t) 0;
				midi_message.bytes_count = (uint8_t) 2;
			}
			pending_message_index = (uint8_t) 0;
			pending_message_expected_lenght = (uint8_t) 0;
			//midi_message.valid = true;
			return true;
		} else {
			// Waiting for more data
			pending_message_index++;
		}

		if (USE_1_BYTE_PARSING) {
			// Message is not complete.
			return false;
		} else {
			// Call the parser recursively
			// to parse the rest of the message.
			return parse();
		}
	} else {
		// First, test if this is a status byte
		if (serial_data >= 0x80) {
			// Reception of status bytes in the middle of an uncompleted message
			// are allowed only for interleaved Real Time message or EOX
			switch (serial_data) {
			case MIDI_TYPES_CLOCK:
			case MIDI_TYPES_START:
			case MIDI_TYPES_CONTINUE:
			case MIDI_TYPES_STOP:
			case MIDI_TYPES_ACTIVE_SENSING:
			case MIDI_TYPES_SYSTEM_RESET:
				// Here we will have to extract the one-byte message,
				// pass it to the structure for being read outside
				// the MIDI class, and recompose the message it was
				// interleaved into. Oh, and without killing the running status..
				// This is done by leaving the pending message as is,
				// it will be completed on next calls.
				midi_message.type = serial_data;
				midi_message.data1 = 0;
				midi_message.data2 = 0;
				midi_message.channel = 0;
				midi_message.bytes_count = (uint8_t) 1;
				//midi_message.valid = true;
				return true;

				break;
				// End of Exclusive
			case 0xF7:
				if (midi_message.system_exclusive[0]
						== MIDI_TYPES_SYSTEM_EXCLUSIVE) {
					// Store the last byte (EOX)
					midi_message.system_exclusive[pending_message_index++] = 0xF7;
					midi_message.type = MIDI_TYPES_SYSTEM_EXCLUSIVE;
					// Get length
					midi_message.data1 = pending_message_index & 0xFF; // LSB
					midi_message.data2 = pending_message_index >> 8;   // MSB
					midi_message.channel = 0;
					midi_message.bytes_count = (uint8_t) 3;
					//midi_message.valid = true;

					reset_input();
					return true;
				} else {
					// Well well well.. error.
					reset_input();
					return false;
				}
				break;
			default:
				break;
			}
		}
Esempio n. 17
0
static void process_input(brl_t *brl)
{
    unsigned char c;
    int           mapped, type, in, n, diff;
    char          out, *line, *hentry;

    while((n = read(brl->fd, &c, sizeof(c))) > 0) {
        if (brl->esc) {
            if (brl->seq_len < (int)sizeof(brl->seq))
                brl->seq[brl->seq_len++] = c;

            if (brl->seq_len == 2) {
                if (c != '[') {
                    mapped = map_esc_sequence(brl);
                    brl->esc = FALSE;
                }
                else
                    continue;
            }
            else {
                if (0x40 <= c && c <= 0x7e) {
                    mapped = map_ctrl_sequence(brl);
                    brl->esc = FALSE;
                }
                else {
                    if (brl->seq_len == (int)sizeof(brl->seq)) {
                        mapped = BRL_TYPE_INVALID;
                        brl->esc = FALSE;
                    }
                    else
                        continue;
                }
            }
        }
        else
            mapped = map_input(brl, c);

        type = BRL_INPUT_TYPE(mapped);
        in   = BRL_INPUT_DATA(mapped);

        switch (type) {
        case BRL_TYPE_SELF:
            out = (char)(in & 0xff);
            insert_input(brl, &out, 1);
            redraw_prompt(brl);
            break;

        case BRL_TYPE_COMMAND:
            switch (in) {
            case BRL_CMD_PREV_LINE:
                if (brl->h.srch == 0)
                    save_input(brl);
                hentry = ringbuf_search(&brl->h, -1, 0, (char *)brl->saved);
                debug(brl, "s:%d,'%s'", brl->h.srch,
                      brl->saved ? brl->saved : "-");
                if (hentry != NULL) {
                    reset_input(brl);
                    insert_input(brl, hentry, strlen(hentry));
                    redraw_prompt(brl);
                }
                else
                    bell(brl);
                break;

            case BRL_CMD_NEXT_LINE:
                hentry = ringbuf_search(&brl->h, +1, 0, (char *)brl->saved);
                debug(brl, "s:%d,'%s'", brl->h.srch,
                      brl->saved ? brl->saved : "-");
                if (hentry != NULL) {
                    if (hentry == brl->saved)
                        restore_input(brl);
                    else {
                        reset_input(brl);
                        insert_input(brl, hentry, strlen(hentry));
                    }
                    redraw_prompt(brl);
                }
                else
                    bell(brl);
                break;

            case BRL_CMD_BACKWARD:
                move_cursor(brl, -1);
                redraw_prompt(brl);
                break;
            case BRL_CMD_FORWARD:
                move_cursor(brl, +1);
                redraw_prompt(brl);
                break;

            case BRL_CMD_LINE_START:
                move_cursor(brl, -brl->offs);
                redraw_prompt(brl);
                break;
            case BRL_CMD_LINE_END:
                move_cursor(brl, brl->data - brl->offs);
                redraw_prompt(brl);
                break;

            case BRL_CMD_ERASE_BEFORE:
                erase_input(brl, -1);
                if (brl->offs < brl->data)
                    move_cursor(brl, -1);
                redraw_prompt(brl);
                break;
            case BRL_CMD_ERASE_AT:
                erase_input(brl, 1);
                redraw_prompt(brl);
                break;

            case BRL_CMD_ERASE_REST:
                save_yank(brl, brl->offs, brl->data);
                erase_input(brl, brl->data - brl->offs);
                redraw_prompt(brl);
                break;
            case BRL_CMD_ERASE_ALL:
                save_yank(brl, 0, brl->data);
                reset_input(brl);
                redraw_prompt(brl);
                break;
            case BRL_CMD_YANK:
                insert_input(brl, (char *)brl->yank, brl->yank_data);
                redraw_prompt(brl);
                break;

            case BRL_CMD_PREV_WORD:
                diff = input_delimiter(brl, -1);
                move_cursor(brl, diff);
                redraw_prompt(brl);
                break;

            case BRL_CMD_NEXT_WORD:
                diff = input_delimiter(brl, +1);
                move_cursor(brl, diff);
                redraw_prompt(brl);
                break;

            case BRL_CMD_REDRAW:
                redraw_prompt(brl);
                break;

            case BRL_CMD_ENTER:
                dprintf(brl->fd, "\n\r");
                if (brl->line_cb != NULL) {
                    line = alloca(brl->data + 1);
                    strncpy(line, (char *)brl->buf, brl->data);
                    line[brl->data] = '\0';
                    reset_input(brl);
                    restore_rawmode(brl);
                    brl->line_cb(brl, line, brl->user_data);
                    enable_rawmode(brl);
                    ringbuf_reset_search(&brl->h);
                    debug(brl, "");
                    redraw_prompt(brl);
                }
                else
                    return;
                break;

            default:
#if 0
                printf("editing command 0x%x\n\r", in);
#endif
                bell(brl);
            }
            break;

        case BRL_TYPE_CSEQ:
            brl->esc     = TRUE;
            brl->seq[0]  = c;
            brl->seq_len = 1;
            break;

        case BRL_TYPE_INVALID:
        default:
            bell(brl);
            break;
        }
    }
}
Esempio n. 18
0
int main() {
  check_offloading();

  int cpuExec = 0;
  #pragma omp target map(tofrom: cpuExec)
  {
    cpuExec = omp_is_initial_device();
  }
  int max_teams = 256;
  int gpu_threads = 256;
  int cpu_threads = 32;
  int max_threads = cpuExec ? cpu_threads : gpu_threads;

  a = (double *) malloc(MAX_N * sizeof(double));
  a_h = (double *) malloc(MAX_N * sizeof(double));
  b = (double *) malloc(MAX_N * sizeof(double));
  c = (double *) malloc(MAX_N * sizeof(double));

#pragma omp target enter data map(to:a[:MAX_N],b[:MAX_N],c[:MAX_N])

  for (int n = 32 ; n < MAX_N ; n+=5000) {
    int t = 0;
    reset_input(a, a_h, b, c);

#pragma omp target update to(a[:n],b[:n],c[:n])

    for (int ths = 1; ths <= 1024; ths *= 3) {
      for(int sch = 1 ; sch <= n ; sch *= 1200) {
        t+=4;
#pragma omp target
#pragma omp parallel
        {
          add_f1(a, b, c, n, sch);
          add_f2(a, b, c, n, sch);
          add_f3(a, b, c, n, sch);
          add_f4(a, b, c, n, sch);
        }
      }
    }

    // check results for each 'n'
    for (int times = 0 ; times < t ; times++)
      for (int i = 0; i < n; ++i)
        a_h[i] += b[i] + c[i];

#pragma omp target update from(a[:n])

    for (int i = 0; i < n; ++i) {
      if (a_h[i] != a[i]) {
        printf("Error at n = %d, i = %d: host = %lf, device = %lf\n", n, i, a_h[i], a[i]);
        return 1;
      }
    }
  } // loop 'n'
  printf("Succeeded\n");


  for (int n = 32 ; n < MAX_N ; n+=5000) {
    int t = 0;
    reset_input(a, a_h, b, c);

#pragma omp target update to(a[:n],b[:n],c[:n])

    for (int ths = 1; ths <= 1024; ths *= 3) {
      for(int sch = 1 ; sch <= n ; sch *= 1200) {
        t+=4;
#pragma omp target parallel num_threads(1024)
        {
          add_f1(a, b, c, n, sch);
          add_f2(a, b, c, n, sch);
          add_f3(a, b, c, n, sch);
          add_f4(a, b, c, n, sch);
        }
      }
    }

    // check results for each 'n'
    for (int times = 0 ; times < t ; times++)
      for (int i = 0; i < n; ++i)
        a_h[i] += b[i] + c[i];

#pragma omp target update from(a[:n])

    for (int i = 0; i < n; ++i) {
      if (a_h[i] != a[i]) {
        printf("Error at n = %d, i = %d: host = %lf, device = %lf\n", n, i, a_h[i], a[i]);
        return 1;
      }
    }
  } // loop 'n'
  printf("Succeeded\n");


  for (int n = 32 ; n < MAX_N ; n+=5000) {
    int t = 0;
    reset_input(a, a_h, b, c);

#pragma omp target update to(a[:n],b[:n],c[:n])

    for (int tms = 1 ; tms <= 256 ; tms *= 2) { // 8 times
      for (int ths = 32 ; ths <= 1024 ; ths *= 2) { // 6 times
        for(int sch = 1 ; sch <= n ; sch *= 1200) {
          t+=4;
#pragma omp target teams num_teams(tms) thread_limit(ths)
          {
            tadd_dpf1<double>(a, b, c, n, sch);
            add_dpf2(a, b, c, n, sch);
            add_dpf3(a, b, c, n, sch);
            add_dpf4(a, b, c, n, sch);
          }
        } // loop 'sch'
      } // loop 'ths'
    } // loop 'tms'

    // check results for each 'n'
    for (int times = 0 ; times < t ; times++)
      for (int i = 0; i < n; ++i)
        a_h[i] += b[i] + c[i];

#pragma omp target update from(a[:n])

    for (int i = 0; i < n; ++i) {
      if (a_h[i] != a[i]) {
        printf("Error at n = %d, i = %d: host = %lf, device = %lf\n", n, i, a_h[i], a[i]);
        return 1;
      }
    }
  } // loop 'n'
  printf("Succeeded\n");

#pragma omp target exit data map(release:a[:MAX_N],b[:MAX_N],c[:MAX_N])



  #define N (957*3)
  double Ad[N], Bd[N], Cd[N];

  #define INIT() { \
    INIT_LOOP(N, { \
      Ad[i] = 1 << 16; \
      Bd[i] = i << 16; \
      Cd[i] = -(i << 16); \
    }) \
  }

  INIT();

  double RESULT[256];
  int VALID[256];
  long long EXPECTED[7];
  EXPECTED[0] = 34; EXPECTED[1] = 2311; EXPECTED[2] = 4795;
  EXPECTED[3] = 7532; EXPECTED[4] = 10468; EXPECTED[5] = 12999;
  EXPECTED[6] = 15345;
  unsigned e = 0;
  for (int t = 2; t <= max_threads; t+=39) {
    long long OUT = 0;
    int num_threads = t;
    int num_tests = 0;
    #pragma omp target teams map(tofrom: OUT, num_tests) num_teams(1) thread_limit(max_threads)
    {
      #pragma omp parallel num_threads(num_threads)
      {
        for (int offset = 0; offset < 32; offset++) {
          for (int factor = 1; factor < 33; factor++) {
            kernel1(num_threads, RESULT, VALID, offset, factor,
                    N, Ad, Bd, Cd, &OUT, &num_tests);
          }
        }
      }
    }

    if (OUT + num_tests != EXPECTED[e++])
      printf ("Failed test with num_threads = %d, OUT + num_tests = %ld\n",
              t, OUT + num_tests);
    else
      printf ("Succeeded\n");
  }
  if (cpuExec) {
    DUMP_SUCCESS(6);
  }


  e = 0;
  for (int t = 2; t <= max_threads; t+=39) {
    long long OUT = 0;
    int num_threads = t;
    int num_tests = 0;
    #pragma omp target parallel map(tofrom: OUT, num_tests) num_threads(num_threads)
    {
        for (int offset = 0; offset < 32; offset++) {
          for (int factor = 1; factor < 33; factor++) {
            kernel1(num_threads, RESULT, VALID, offset, factor,
                    N, Ad, Bd, Cd, &OUT, &num_tests);
          }
        }
    }

    if (OUT + num_tests != EXPECTED[e++])
      printf ("Failed test with num_threads = %d, OUT + num_tests = %ld\n",
              t, OUT + num_tests);
    else
      printf ("Succeeded\n");
  }
  if (cpuExec) {
    DUMP_SUCCESS(6);
  }


  long long OUT = 0;
  int num_tests = 0;
  #pragma omp target map(tofrom: OUT, num_tests)
  {
    kernel1(1, RESULT, VALID, 0, 1,
            N, Ad, Bd, Cd, &OUT, &num_tests);
  }

  if (OUT + num_tests != 1)
    printf ("Failed test with OUT + num_tests = %ld\n",
            OUT + num_tests);
  else
    printf ("Succeeded\n");

  return 0;
}
Esempio n. 19
0
int main(int argc, char *argv[]) {

    if (argc != 2) {
        fprintf(stderr, "usage: %s [ip]\n", argv[0]);
        exit(1);
    }

    init_user();
    init_connection(argv[1]);
    signup_signin();

    init_curses();
    init_windows_attr();
    init_windows();
     
    // catch response from server
    pthread_t response_thd;
    if(pthread_create(&response_thd, NULL, response_handler, (void *)0))
        ERR_EXIT("Create response thread failed");

    get_online();

    while (1) {
        int c = wgetch(target->win);
        switch(c) {
            case '\t':
                target->text[target->len] = '\0';
                strcat(target->text, "    ");
                target->len += 4;
                target->y += 4;
                break;
            case KEY_BACKSPACE:
                if (target->y != 0) {
                    target->len--;
                    if (target->offset == 0)
                        mvwaddch(target->win, target->x,--target->y,' ');
                    else {
                        int i;
                        for (i = target->len + target->offset; i < target->len; i++) {
                            target->text[i] = target->text[i + 1];
                            mvwaddch(target->win, target->x, i, target->text[i]);
                        }
                        mvwaddch(target->win, target->x, i,' ');
                        target->y--;
                    }
                    wrefresh(target->win);
                }
                break;
            case 27: //esc
                close_client();
            case KEY_MOUSE:
                // waddstr(target->win, "clicked");
                if(getmouse(&event) == OK)
                    serve_mouse_event(event.y, event.x);
                break;
            case 13: //enter
                target->text[target->len] = '\0';
                if (strcmp(target->type, COMMENT) == 0) {
                    send_cmt();
                } else {
                    upload_file();
                }
                reset_input();
                break;
            case KEY_DOWN:
                break;
            case KEY_UP:
                break;
            case KEY_LEFT:
                if (target->len != 0) {
                    target->y--;
                    target->offset--;
                }
                break;
            case KEY_RIGHT:
                if (target->offset != 0) {
                    target->y++;
                    target->offset++;
                }
                break;
            default:
                mvwaddch(target->win, target->x, target->y, c);
                if (target->offset == 0) {
                    target->text[target->len++] = c;
                } else {
                    int i;
                    for (i = target->len; i > target->len + target->offset; i--)
                        target->text[i] = target->text[i - 1];
                    target->text[i] = c;
                    target->len++;
                    while (i++ < target->len - 1)
                        mvwaddch(target->win, target->x, i, target->text[i]);
                }
                wrefresh(target->win);
                // wprintw(target->win, "%d", c);
                target->y++;
                break;
        }
        wmove(target->win, target->x, target->y);
        wrefresh(target->win);
    }
    close_client();
}
Esempio n. 20
0
void compile()
{
char		line[1024];
int		token_type;
USE_ITEM	*ptr;
int		old_use_count;

	token_type = get_token();

	if (token_type != NAMES)
	    err_abort("File does not start with terminal names in column one");
	
	while (token_type != EOF)
	    token_type = do_entry(NULL);

	DEBUG0(2, "Starting handling of forward USE's\n");

	for (part2=0; part2<2; part2++) {
	    old_use_count = -1;
	    DEBUG(2, "\n\nPART %d\n\n", part2);
	    while (use_list.head != NULL  &&  old_use_count != use_count) {
		old_use_count = use_count;
		for (ptr = use_list.tail; ptr != NULL; ptr = ptr->bptr) {
		    fseek(stdin, ptr->offset, 0);
		    reset_input();
		    if ((token_type = get_token()) != NAMES)
			syserr_abort("Token after a seek not NAMES");
		    (void) do_entry(ptr);
		    if (complete)
			dequeue(ptr);
		}

		for (ptr = use_list.head; ptr != NULL; ptr = ptr->fptr) {
		    fseek(stdin, ptr->offset, 0);
		    reset_input();
		    if ((token_type = get_token()) != NAMES)
			syserr_abort("Token after a seek not NAMES");
		    (void) do_entry(ptr);
		    if (complete)
			dequeue(ptr);
		}
		
		DEBUG0(2, "Finished a pass through enqueued forward USE's\n");
	    }
	}

	if (use_list.head != NULL) {
	    fprintf(stderr, "\nError in following up use-links.  Either there is\n");
	    fprintf(stderr, "a loop in the links or they reference non-existant\n");
	    fprintf(stderr, "terminals.  The following is a list of the entries\n");
	    fprintf(stderr, "involved:\n\n");

	    for (ptr = use_list.head; ptr != NULL; ptr = ptr->fptr) {
		fseek(stdin, ptr->offset, 0);
		fgets(line, 1024, stdin);
		fprintf(stderr, "%s", line);
	    }

	    exit(1);
	}
}
Esempio n. 21
0
void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal )
{
    input_thread_t* pInput = (input_thread_t*) p_obj;

    assert( getIntf()->p_sys->p_input == NULL || getIntf()->p_sys->p_input == pInput );

    if( !getIntf()->p_sys->p_input )
    {
        msg_Dbg( getIntf(), "new input %p detected", pInput );

        getIntf()->p_sys->p_input = pInput;
        vlc_object_hold( pInput );
    }

    switch( newVal.i_int )
    {
        case INPUT_EVENT_STATE:
        {
            int state = var_GetInteger( pInput, "state" );
            SET_BOOL( m_cVarStopped, false );
            SET_BOOL( m_cVarPlaying, state != PAUSE_S );
            SET_BOOL( m_cVarPaused, state == PAUSE_S );
            break;
        }

        case INPUT_EVENT_POSITION:
        {
            float pos = var_GetFloat( pInput, "position" );
            SET_STREAMTIME( m_cVarTime, pos, false );
            SET_BOOL( m_cVarSeekable, pos != 0.0 );
            break;
        }

        case INPUT_EVENT_RATE:
        {
            float rate = var_GetFloat( pInput, "rate" );
            char* buffer;
            if( asprintf( &buffer, "%.3g", rate ) != -1 )
            {
                SET_TEXT( m_cVarSpeed, UString( getIntf(), buffer ) );
                free( buffer );
            }
            break;
        }

        case INPUT_EVENT_ES:
        {
            // Do we have audio
            vlc_value_t audio_es;
            var_Change( pInput, "audio-es", VLC_VAR_CHOICESCOUNT,
                            &audio_es, NULL );
            SET_BOOL( m_cVarHasAudio, audio_es.i_int > 0 );
            break;
        }

        case INPUT_EVENT_VOUT:
        {
            vout_thread_t* pVout = input_GetVout( pInput );
            SET_BOOL( m_cVarHasVout, pVout != NULL );
            if( !pVout || pVout == m_pVout )
            {
                // end of input or vout reuse (nothing to do)
                if( pVout )
                    vlc_object_release( pVout );
                break;
            }
            if( m_pVout )
            {
                // remove previous Vout callbacks
                var_DelCallback( m_pVout, "mouse-moved",
                                 onGenericCallback, this );
                vlc_object_release( m_pVout );
                m_pVout = NULL;
            }

            // add new Vout callbackx
            var_AddCallback( pVout, "mouse-moved",
                             onGenericCallback, this );
            m_pVout = pVout;
            break;
        }

        case INPUT_EVENT_AOUT:
        {
            audio_output_t* pAout = input_GetAout( pInput );

            // end of input or aout reuse (nothing to do)
            if( !pAout || pAout == m_pAout )
            {
                if( pAout )
                    vlc_object_release( pAout );
                break;
            }

            // remove previous Aout if any
            if( m_pAout )
            {
                var_DelCallback( m_pAout, "audio-filter",
                                 onGenericCallback, this );
                if( m_bEqualizer_started )
                {
                    var_DelCallback( m_pAout, "equalizer-bands",
                                     onEqBandsChange, this );
                    var_DelCallback( m_pAout, "equalizer-preamp",
                                     onEqPreampChange, this );
                }
                vlc_object_release( m_pAout );
                m_pAout = NULL;
                m_bEqualizer_started = false;
            }

            // New Aout (addCallbacks)
            var_AddCallback( pAout, "audio-filter", onGenericCallback, this );

            char *pFilters = var_GetNonEmptyString( pAout, "audio-filter" );
            bool b_equalizer = pFilters && strstr( pFilters, "equalizer" );
            free( pFilters );
            SET_BOOL( m_cVarEqualizer, b_equalizer );
            if( b_equalizer )
            {
                var_AddCallback( pAout, "equalizer-bands",
                              onEqBandsChange, this );
                var_AddCallback( pAout, "equalizer-preamp",
                              onEqPreampChange, this );
                m_bEqualizer_started = true;
            }
            m_pAout = pAout;
            break;
        }

        case INPUT_EVENT_CHAPTER:
        {
            vlc_value_t chapters_count;
            var_Change( pInput, "chapter", VLC_VAR_CHOICESCOUNT,
                        &chapters_count, NULL );
            SET_BOOL( m_cVarDvdActive, chapters_count.i_int > 0 );
            break;
        }

        case INPUT_EVENT_RECORD:
            SET_BOOL( m_cVarRecording, var_GetBool( pInput, "record" ) );
            break;

        case INPUT_EVENT_DEAD:
            msg_Dbg( getIntf(), "end of input detected for %p", pInput );

            var_DelCallback( pInput, "intf-event", onGenericCallback2, this );
            var_DelCallback( pInput, "bit-rate", onGenericCallback, this );
            var_DelCallback( pInput, "sample-rate", onGenericCallback, this );
            var_DelCallback( pInput, "can-record" , onGenericCallback, this );
            vlc_object_release( pInput );
            getIntf()->p_sys->p_input = NULL;
            reset_input();
            break;

        default:
            break;
    }
}
Esempio n. 22
0
int main(void) {
    io_init();
    uint8_t input[16];
    aes128_ctx_t ks, iks;


    printf("Build Date: %s\n", build_date);
    printf("Git:        %s\n\n", build_git_sha);
    printf("  Photon DA AES\n");
    printf("-----------------\n");
    printf("ROUNDS  = %lu\n", (unsigned long) ROUNDS);
    printf("DELAY   = %lu\n", (unsigned long) DELAY);
    printf("STARTUP = %lu\n", (unsigned long) STARTUP);
    printf("-----------------\n");
    printf("SBOX:  0x%.2X\n", (unsigned int) aes_sbox);
    printf("Input: 0x%.2X\n", (unsigned int) input);
    printf("Key:   0x%.2X\n", (unsigned int) key);
    printf("-----------------\n");
#if ROUNDS == 0
    uint16_t writes = eeprom_read_word(&write_cycles);
    uint8_t byte = eeprom_read_byte(&input_byte);
    printf("write_cycles = %u\n", writes);
    printf("input_byte = 0x%.2X\n", byte);
#endif
#ifdef PHOTON
    printf("Computing S-Box only!\n");
#endif
    printf("\n");

#if STARTUP > 0
    _delay_ms(STARTUP * 1000);
#endif

#ifdef VERBOSE
    printf("Printing AES Key:\n");
    print_128(key);
    printf("\n");
#endif

    // aes128_init(const void* key, aes128_ctx_t* ctx);
    aes128_init(key, &ks);

#ifdef VERBOSE
    printf("Printing AES SBOX:\n");
    uint16_t s = 0;
    for(s=0; s < 256; s++) {
        printf("%.2X", aes_sbox[s]);
        if((s + 1) % 16 == 0)
            printf("\n");
    }
    printf("\n");
#endif

#if ROUNDS > 0
    unsigned long round = 1;
    uint8_t i=0;
    unsigned long total_rounds = 256 * ROUNDS;
    while(round <= total_rounds) {
        reset_input(input, i);
#else
    reset_input(input, byte);
    memcpy(&init,&input,sizeof(uint8_t)*16);
    printf("Input:\n");
    print_128(input);
    printf("\n");
    while(1) {
        memcpy(&input,&init,sizeof(uint8_t)*16);
#endif
        memcpy(&iks,&ks,sizeof(aes128_ctx_t));

#ifdef VERBOSE
#if ROUNDS > 0
        printf("[%6ld]: Input:\n", round);
#else
        printf("Input:\n");
#endif
        print_128(input);
        printf("\n");
#endif

        // void aes128_enc(void* buffer, aes128_ctx_t* ctx);
        aes128_enc(input, &ks);

#ifdef VERBOSE
#if ROUNDS  > 0
        printf("[%6ld]: Result:\n", round);
#else
        printf("Result:\n");
#endif

        //Result gets written back to the input
        print_128(input);
        printf("\n");
#endif

#if ROUNDS > 0
        round++;
        if ( (round - 1) % ROUNDS == 0)
            i++;
#endif
#if DELAY > 0
        _delay_ms(DELAY);
#endif
    }
#if ROUNDS  > 0
    printf("Exiting... after round %li\n", round - 1);
#endif

    return(0);
}