예제 #1
0
파일: ocl.c 프로젝트: nasa/QuIP
static void ocl_info(QSP_ARG_DECL  Compute_Platform *cpp)
{
	int s;

	sprintf(MSG_STR,"Vendor:  %s",OCLPF_VENDOR(cpp));
	prt_msg(MSG_STR);
	sprintf(MSG_STR,"Version:  %s",OCLPF_VERSION(cpp));
	prt_msg(MSG_STR);
	sprintf(MSG_STR,"Profile:  %s",OCLPF_PROFILE(cpp));
	prt_msg(MSG_STR);

	// The extensions can be long...
	s = (int) strlen(OCLPF_EXTENSIONS(cpp))+strlen(EXTENSIONS_PREFIX)+2;
	if( s > sb_size(QS_SCRATCH) )
		enlarge_buffer( QS_SCRATCH, s );
	sprintf(sb_buffer(QS_SCRATCH),"%s%s\n",EXTENSIONS_PREFIX,OCLPF_EXTENSIONS(cpp));
	prt_msg(sb_buffer(QS_SCRATCH));
}
예제 #2
0
파일: save.c 프로젝트: fantao963/lua-amf
int luaamf_save(lua_State * L)
{
  int result = LUAAMF_EFAILURE;
  luaamf_SaveBuffer sb;

  {
    void * alloc_ud = NULL;
    lua_Alloc alloc_fn = lua_getallocf(L, &alloc_ud);
    sb_init(&sb, alloc_fn, alloc_ud);
  }

  result = save_value(&sb, L, 1, 1);

  if (result != LUAAMF_ESUCCESS)
  {
    switch (result)
    {
    case LUAAMF_EBADTYPE:
      lua_pushliteral(L, "can't save: unsupported type detected");
      break;

    case LUAAMF_ETOODEEP:
      lua_pushliteral(L, "can't save: nesting is too deep");
      break;

    case LUAAMF_ETOOLONG:
      lua_pushliteral(L, "can't save: not enough memory");
      break;

    default: /* Should not happen */
      lua_pushliteral(L, "save failed");
      break;
    }

    sb_destroy(&sb);
    return result;
  }
  {
    size_t len = 0UL;
    const unsigned char * buf = sb_buffer(&sb, &len);
    lua_pushlstring(L, (const char *)buf, len);
    sb_destroy(&sb);
  }

  return LUAAMF_ESUCCESS;
}
예제 #3
0
파일: save.c 프로젝트: fantao963/lua-amf
/* Returns 0 on success, non-zero on failure */
static int save_table(
    lua_State * L,
    luaamf_SaveBuffer * sb,
    int index
  )
{
  luaamf_SaveBuffer numeric;
  luaamf_SaveBuffer associative;
  int result = LUAAMF_ESUCCESS;
  int numeric_index = 1;
  int key_value_pairs_number = 0;

  {
    void * alloc_ud = NULL;
    lua_Alloc alloc_fn = lua_getallocf(L, &alloc_ud);
    sb_init(&numeric, alloc_fn, alloc_ud);
    sb_init(&associative, alloc_fn, alloc_ud);
  }

  lua_pushnil(L);
  while (result == LUAAMF_ESUCCESS && lua_next(L, index) != 0)
  {
    int value_pos = lua_gettop(L);  /* We need absolute values */
    int key_pos = value_pos - 1;

    if(lua_type(L, key_pos) == LUA_TNUMBER && lua_tonumber(L, key_pos) == (float)numeric_index)
    {
      /* Save enumerated value. */
      result = save_value(&numeric, L, value_pos, 1);
      numeric_index++;
    }
    else
    {
      /* Save associative key. */
      result = save_value(&associative, L, key_pos, 0);

      /* Save associative value. */
      if (result == LUAAMF_ESUCCESS)
      {
        result = save_value(&associative, L, value_pos, 1);
        key_value_pairs_number++;
      }
    }

    if (result == LUAAMF_ESUCCESS)
    {
      /* Remove value from stack, leave key for the next iteration. */
      lua_pop(L, 1);
    }
    else
    {
      return result;
    }
  }

  /* write serilization here */
  sb_writechar(sb, LUAAMF_ARRAY);
  encode_int(sb, 2 * key_value_pairs_number + 1);
  sb_write(sb, sb_buffer(&associative, &(associative.buf_size)), associative.buf_size);
  sb_writechar(sb, 0x001);
  sb_write(sb, sb_buffer(&numeric, &(numeric.buf_size)), numeric.buf_size);
  result = LUAAMF_ESUCCESS;

  sb_destroy(&numeric);
  sb_destroy(&associative);
  return result;
}