Esempio n. 1
0
File: svm.c Progetto: shouya/svm
int sm_newline(SM_ARGS) {
    int _ti_result = 0;

    switch (*state) {
    case S_NOP:
        break;
    case S_INST_NAME: /* execute simple instruction, such as ret */
        *state = S_NOP;
        name[*name_len] = '\0';
        /* execinst(_inst_name, 0, NULL, infile); */
        _ti_result = trans_inst(name, 0, NULL, &out_bin[*pos]);
        if (_ti_result == FAILURE) {
            fprintf(stderr, "error while parsing argument, line: %d\n", line);
            return FAILURE;
        } else {
            *pos += _ti_result;
        }
        /* always reserve a BUF_SIZE space to new instructions */
        reset_name(name, name_len);
        break;
    case S_INST_ARG:
        *state = S_NOP;
        argv[*argc - 1][*argv_len] = '\0';
        _ti_result = trans_inst(name, *argc, argv, &out_bin[*pos]);
        if (_ti_result == FAILURE) {
            fprintf(stderr, "error while parsing argument, line: %d\n", line);
            return FAILURE;
        } else {
            *pos += _ti_result;
        }
        reset_name(name, name_len);
        reset_argument(argc, argv, argv_len);
        break;
    case S_COMMENT:
        *state = S_NOP;
        break;
    case S_INST_ARG_BEG:
        *state = S_NOP;
        if (*argc > 0) { /* such as [mov eax,\n] */
            fprintf(stderr, "syntax error at line %d\n", line);
            return FAILURE;
        }
        /* such as [nop \n] */
        _ti_result = trans_inst(name, 0, NULL, &out_bin[*pos]);
        if (_ti_result == FAILURE) {
            fprintf(stderr, "error while parsing argument, line: %d\n", line);
            return FAILURE;
        } else {
            *pos += _ti_result;
        }
        /*execinst(_inst_name, 0, NULL, infile);*/
        reset_name(name, name_len);
        break;
    }
    return SUCCESS;
}
Esempio n. 2
0
File: svm.c Progetto: shouya/svm
int sm_semicolon(SM_ARGS) {
    int _ti_result;
    switch (*state) {
    case S_NOP:
        *state = S_COMMENT;
        break;
    case S_INST_NAME: /* [nop; some comments] */
        *state = S_COMMENT;
        name[*name_len] = '\0';
        _ti_result = trans_inst(name, 0, NULL, &out_bin[*pos]);
        if (_ti_result == FAILURE) {
            fprintf(stderr, "error while parsing argument, line: %d\n", line);
            return FAILURE;
        } else {
            *pos += _ti_result;
        }
        reset_name(name, name_len);
        break;
    case S_INST_ARG:
        *state = S_COMMENT;
        argv[*argc - 1][*argv_len] = '\0';
        _ti_result = trans_inst(name, *argc, argv, &out_bin[*pos]);
        if (_ti_result == FAILURE) {
            fprintf(stderr, "error while parsing argument, line: %d\n", line);
            return FAILURE;
        } else {
            *pos += _ti_result;
        }
        reset_name(name, name_len);
        reset_argument(argc, argv, argv_len);
        break;
    case S_COMMENT:
        break;
    case S_INST_ARG_BEG:
        *state = S_COMMENT;
        if (*argc > 0) { /* such as [mov eax,;] */
            fprintf(stderr, "syntax error at line %d\n", line);
            return FAILURE;
        }
        /* such as [nop ;] */
        _ti_result = trans_inst(name, 0, NULL, &out_bin[*pos]);
        if (_ti_result == FAILURE) {
            fprintf(stderr, "error while parsing argument, line: %d\n", line);
            return FAILURE;
        } else {
            *pos += _ti_result;
        }
        reset_name(name, name_len);
        break;
    }
    return SUCCESS;
}
Esempio n. 3
0
static void
window_name_changed (WnckWindow      *window,
                     WnckApplication *app)
{
  if (window == app->priv->name_window)
    {
      reset_name (app);
      update_name (app);
    }
}
Esempio n. 4
0
File: svm.c Progetto: shouya/svm
int sm_colon(SM_ARGS) {
    switch (*state) {
    case S_INST_NAME:
        *state = S_NOP;
        reset_name(name, name_len);
        break;
    case S_INST_ARG:
    case S_INST_ARG_BEG:
    case S_NOP:
        fprintf(stderr, "syntax error at line %d\n", line);
        return FAILURE;
    case S_COMMENT:
        break;
    }
    return SUCCESS;
}
Esempio n. 5
0
void
_wnck_application_remove_window (WnckApplication *app,
                                 WnckWindow      *window)
{
  g_return_if_fail (WNCK_IS_APPLICATION (app));
  g_return_if_fail (WNCK_IS_WINDOW (window));
  g_return_if_fail (wnck_window_get_application (window) == app);
  
  app->priv->windows = g_list_remove (app->priv->windows, window);
  _wnck_window_set_application (window, NULL);

  g_signal_handlers_disconnect_by_func (G_OBJECT (window),
                                        window_name_changed, app);
  
  /* emits signals, so do it last */
  reset_name (app);
  update_name (app);

  /* see if we're using icon from a window */
  if (app->priv->icon == NULL ||
      app->priv->mini_icon == NULL)
    emit_icon_changed (app);
}
Esempio n. 6
0
void
_wnck_application_add_window (WnckApplication *app,
                              WnckWindow      *window)
{
  g_return_if_fail (WNCK_IS_APPLICATION (app));
  g_return_if_fail (WNCK_IS_WINDOW (window));
  g_return_if_fail (wnck_window_get_application (window) == NULL);
  
  app->priv->windows = g_list_prepend (app->priv->windows, window);  
  _wnck_window_set_application (window, app);

  g_signal_connect (G_OBJECT (window), "name_changed",
                    G_CALLBACK (window_name_changed), app);
  
  /* emits signals, so do it last */
  reset_name (app);
  update_name (app);

  /* see if we're using icon from a window */
  if (app->priv->icon == NULL ||
      app->priv->mini_icon == NULL)
    emit_icon_changed (app);
}
Esempio n. 7
0
File: init.c Progetto: medivhc/rtems
rtems_task Init(
  rtems_task_argument argument
)
{
  name = malloc(40);
  puts( "\n\n*** TEST ASSOC ROUTINES - 1 ***" );

  puts( "Init - get local by name -- OK" );
  local = rtems_assoc_local_by_name( assoc_table, "zero" );
  rtems_test_assert( local == 1 );

  puts( "Init - get local by name -- expect 0" );
  local = rtems_assoc_local_by_name( assoc_table, "four" );
  rtems_test_assert( local == 0 );

  puts( "Init - get local by remote bitfield -- OK" );
  local = rtems_assoc_local_by_remote_bitfield( assoc_table, 1 );
  rtems_test_assert( local == 8 );

  puts( "Init - get local by remote bitfield -- expect 0" );
  local = rtems_assoc_local_by_remote_bitfield( assoc_table, 0 );
  rtems_test_assert( local == 0 );

  puts( "Init - get local by remote -- OK" );
  local = rtems_assoc_local_by_remote( assoc_table, 1 );
  rtems_test_assert( local == 8 );

  puts( "Init - get local by remote -- expect 0" );
  local = rtems_assoc_local_by_remote( assoc_table, 0 );
  rtems_test_assert( local == 0 );

  reset_name();
  puts( "Init - get name by local bitfield -- OK" );
  name = rtems_assoc_name_by_local_bitfield( assoc_table, 1, name );
  rtems_test_assert ( !strcmp( name, "zero" ) );

  reset_name();
  puts( "Init - get name by local bitfield -- OK" );
  name = rtems_assoc_name_by_local_bitfield( assoc_table, 3, name );
  rtems_test_assert ( !strcmp( name, "zero one" ) );

  reset_name();
  puts( "Init - get name by local bitfield -- expect\"\"" );
  name = rtems_assoc_name_by_local_bitfield( assoc_table, 0, name );
  rtems_test_assert ( !strcmp( name, "" ) );
  
  reset_name();
  puts( "Init - get name by local -- OK" );
  rtems_test_assert( !strcmp( rtems_assoc_name_by_local( assoc_table, 1 ), 
			      "zero" ) );
  
  reset_name();
  puts( "Init - get name by local -- using bad value" );
  puts( rtems_assoc_name_by_local( assoc_table, 0 ) );

  reset_name();
  puts( "Init - get name by remote bitfield -- OK" );
  name = 
    rtems_assoc_name_by_remote_bitfield( assoc_table, 1, name );
  rtems_test_assert ( !strcmp( name, "three" ) );

  reset_name();
  puts( "Init - get name by remote bitfield -- OK" );
  name = 
    rtems_assoc_name_by_remote_bitfield( assoc_table, 3, name );
  rtems_test_assert ( !strcmp( name, "three two" ) );

  reset_name();
  puts( "Init - get name by remote bitfield -- expect\"\"" );
  name = 
    rtems_assoc_name_by_remote_bitfield( assoc_table, 0, name );
  rtems_test_assert ( !strcmp( name, "" ) );
  
  reset_name();
  puts( "Init - get name by remote -- OK" );
  rtems_test_assert( !strcmp( rtems_assoc_name_by_remote( assoc_table, 1 ),
			      "three" ) );
  
  reset_name();
  puts( "Init - get name by remote -- using bad value" );
  puts( rtems_assoc_name_by_remote( assoc_table, 0 ) );

  puts( "Init - get ptr by local -- OK" );
  assoc_item = rtems_assoc_ptr_by_local( assoc_table, 1 );
  rtems_test_assert( assoc_item == assoc_table );

  puts( "Init - get ptr by local -- expect NULL" );
  assoc_item = rtems_assoc_ptr_by_local( assoc_table, 0 );
  rtems_test_assert( assoc_item == 0 );

  puts( "Init - get ptr by remote -- OK" );
  assoc_item = rtems_assoc_ptr_by_remote( assoc_table, 8 );
  rtems_test_assert( assoc_item == assoc_table );

  puts( "Init - get ptr by remote -- expect NULL" );
  assoc_item = rtems_assoc_ptr_by_remote( assoc_table, 0 );
  rtems_test_assert( assoc_item == 0 );

  puts( "Init - get ptr by name -- OK" );
  assoc_item = rtems_assoc_ptr_by_name( assoc_table, "zero" );
  rtems_test_assert( assoc_item == assoc_table );

  puts( "Init - get ptr by name -- expect NULL" );
  assoc_item = rtems_assoc_ptr_by_name( assoc_table, "six" );
  rtems_test_assert( assoc_item == 0 );

  puts( "Init - get remote by local bitfield -- OK" );
  remote = rtems_assoc_remote_by_local_bitfield( assoc_table, 1 );
  rtems_test_assert( remote == 8 );

  puts( "Init - get remote by local bitfield -- expect 0" );
  remote = rtems_assoc_remote_by_local_bitfield( assoc_table, 0 );
  rtems_test_assert( remote == 0 );

  puts( "Init - get remote by local -- OK" );
  remote = rtems_assoc_remote_by_local( assoc_table, 1 );
  rtems_test_assert( remote == 8 );

  puts( "Init - get remote by local -- expect 0" );
  remote = rtems_assoc_remote_by_local( assoc_table, 0 );
  rtems_test_assert( remote == 0 );

  puts( "Init - get remote by name -- OK" );
  remote = rtems_assoc_remote_by_name( assoc_table, "zero" );
  rtems_test_assert( remote == 8 );

  puts( "Init - get remote by name -- expect 0" );
  remote = rtems_assoc_remote_by_name( assoc_table, "six" );
  rtems_test_assert( remote == 0 );

  puts( "Init - get ptr by name -- expect (default)" );
  assoc_item = rtems_assoc_ptr_by_name( assoc_table_default, "six" );
  rtems_test_assert( assoc_item == assoc_table_default );

  puts( "Init - get ptr by local -- expect (default)" );
  assoc_item = rtems_assoc_ptr_by_local( assoc_table_default, 0 );
  rtems_test_assert( assoc_item == assoc_table_default );

  puts( "Init - get ptr by remote -- expect (default)" );
  assoc_item = rtems_assoc_ptr_by_remote( assoc_table_default, 0 );
  rtems_test_assert( assoc_item == assoc_table_default );

  puts( "Init - get ptr by name -- expect NULL" );
  assoc_item = rtems_assoc_ptr_by_name( assoc_table_null, "six" );
  rtems_test_assert( assoc_item == 0 );

  puts( "Init - get ptr by local -- expect NULL" );
  assoc_item = rtems_assoc_ptr_by_local( assoc_table_null, 0 );
  rtems_test_assert( assoc_item == 0 );

  puts( "Init - get ptr by remote -- expect NULL" );
  assoc_item = rtems_assoc_ptr_by_remote( assoc_table_null, 0 );
  rtems_test_assert( assoc_item == 0 );

  free( name );

  puts( "*** END OF TEST ASSOC ROUTINES - 1 ***" );

  rtems_test_exit(0);
}