void save_value(int number, char *value, struct Value *valuePtr, int len) {
    if (valuePtr->number == 0) {
        valuePtr->number = number;
        valuePtr->value = (char *) malloc(sizeof(char) * (len-4));
        strcpy(valuePtr->value, value);

        valuePtr->left = NULL;
        valuePtr->right = NULL;
        return;
    }

    if (number < valuePtr->number) {
        if (valuePtr->left == NULL) {
            valuePtr->left = malloc(sizeof(struct Value));
            valuePtr->left->number = 0;
        }
        save_value(number, value, valuePtr->left, len);
    }
    else if (number > valuePtr->number) {
        if (valuePtr->right == NULL) {
            valuePtr->right = malloc(sizeof(struct Value));
            valuePtr->right->number = 0;
        }
        save_value(number, value, valuePtr->right, len);
    }
}
Exemple #2
0
void group_warning(void)
{
boolean w= false;
int i= in_open;
base_ptr= input_ptr;
input_stack[base_ptr]= cur_input;
while((grp_stack[i]==cur_boundary)&&(i> 0)){



if(tracing_nesting_par> 0){
while((input_stack[base_ptr].state_field==token_list)||
(input_stack[base_ptr].index_field> i))
decr(base_ptr);
if(input_stack[base_ptr].name_field> 17)
w= true;
}

grp_stack[i]= save_value(save_ptr);
decr(i);
}
if(w){
tprint_nl("Warning: end of ");
print_group(true);
tprint(" of a different file");
print_ln();
if(tracing_nesting_par> 1)
show_context();
if(history==spotless)
history= warning_issued;
}
}
Exemple #3
0
//static int ahbm_read_proc(char *page, char **start, off_t off,
//		int count, int *eof, void *data)
static int ahbm_show(struct seq_file *m, void *v)
{
	int i = 0, len = 0;
	int ignore_time = (sum/period)-rate;
	struct saved_value *vbuf;

	vbuf = vmalloc(sizeof(struct saved_value) * period);
	if(!vbuf) {
		seq_printf(m,"//period = %d\nsum = %dms\nrate = %dms",period,sum,rate);
		seq_printf(m,"malloc err.\n");
		return len;
	}

	//cpm_clear_bit(11,CPM_CLKGR);
	cpm_clear_bit(4,CPM_CLKGR);
	while(i<period) {
		outl(0x0,DDR_MC);
		outl(0x0,DDR_RESULT_1);
		outl(0x0,DDR_RESULT_2);
		outl(0x0,DDR_RESULT_3);
		outl(0x0,DDR_RESULT_4);
		outl(0x1,DDR_MC);

		ahbm_restart(CIM);
		ahbm_restart(AHB0);
		ahbm_restart(GPU);
		ahbm_restart(LCD);
		ahbm_restart(XXX);
		ahbm_restart(AHB2);

		msleep(rate);

		outl(0x0,DDR_MC);

		ahbm_stop(CIM);
		ahbm_stop(AHB0);
		ahbm_stop(GPU);
		ahbm_stop(LCD);
		ahbm_stop(XXX);
		ahbm_stop(AHB2);

		save_value(&vbuf[i]);

		msleep(ignore_time);
		i++;
	}
	cpm_set_bit(4,CPM_CLKGR);

	seq_printf(m,"//period=%d sum=%dms rate = %dms\n",period,sum,rate);

	i=0;
	while(i<period) {
		print_value(m,&vbuf[i]);
		seq_printf(m,"SAMPLE_FINISH:%d\n",i);
		i++;
	}

	vfree(vbuf);
	return 0;
}
Exemple #4
0
static dav_error *
db_store(dav_db *db,
         const dav_prop_name *name,
         const apr_xml_elem *elem,
         dav_namespace_map *mapping)
{
  const svn_string_t *const *old_propval_p;
  const svn_string_t *old_propval;
  const svn_string_t *propval;
  svn_boolean_t absent;
  apr_pool_t *pool = db->p;
  dav_error *derr;

  /* SVN sends property values as a big blob of bytes. Thus, there should be
     no child elements of the property-name element. That also means that
     the entire contents of the blob is located in elem->first_cdata. The
     dav_xml_get_cdata() will figure it all out for us, but (normally) it
     should be awfully fast and not need to copy any data. */

  propval = svn_string_create
    (dav_xml_get_cdata(elem, pool, 0 /* strip_white */), pool);

  derr = decode_property_value(&propval, &absent, propval, elem, pool);
  if (derr)
    return derr;

  if (absent && ! elem->first_child)
    /* ### better error check */
    return dav_svn__new_error(pool, HTTP_INTERNAL_SERVER_ERROR, 0,
                              apr_psprintf(pool,
                                           "'%s' cannot be specified on the "
                                           "value without specifying an "
                                           "expectation",
                                           SVN_DAV__OLD_VALUE__ABSENT));

  /* ### namespace check? */
  if (elem->first_child && !strcmp(elem->first_child->name, SVN_DAV__OLD_VALUE))
    {
      const char *propname;

      get_repos_propname(db, name, &propname);

      /* Parse OLD_PROPVAL. */
      old_propval = svn_string_create(dav_xml_get_cdata(elem->first_child, pool,
                                                        0 /* strip_white */),
                                      pool);
      derr = decode_property_value(&old_propval, &absent,
                                   old_propval, elem->first_child, pool);
      if (derr)
        return derr;

      old_propval_p = (const svn_string_t *const *) &old_propval;
    }
  else
    old_propval_p = NULL;


  return save_value(db, name, old_propval_p, propval);
}
Exemple #5
0
static void save_value_above(RDArsrc *incrsrc,RDArsrc *mtnrsrc)
{
	int x;

	if(FINDRSCGETINT(mtnrsrc,"TABLE VALUES",&x)) return;
	makespacevaluelist(x);
	save_value(incrsrc,mtnrsrc);
}
Exemple #6
0
static void save_value_below(RDArsrc *incrsrc,RDArsrc *mtnrsrc)
{
	int x;

	if(FINDRSCGETINT(mtnrsrc,"TABLE VALUES",&x)) return;
	makespacevaluelist(++x);
	FINDRSCSETINT(mtnrsrc,"TABLE VALUES",x);
	updatersrc(mtnrsrc,"TABLE VALUES");
	save_value(incrsrc,mtnrsrc);
}
Exemple #7
0
/*
  save a parameter
 */
void AP_Tuning_Plane::save_value(uint8_t parm)
{
    switch(parm) {
    // special handling of dual-parameters
    case TUNING_RATE_ROLL_PI:
        save_value(TUNING_RATE_ROLL_P);
        save_value(TUNING_RATE_ROLL_I);
        break;
    case TUNING_RATE_PITCH_PI:
        save_value(TUNING_RATE_PITCH_P);
        save_value(TUNING_RATE_PITCH_I);
        break;
    default:
        AP_Float *f = get_param_pointer(parm);
        if (f != nullptr) {
            f->save();
        }
        break;
    }
}
Exemple #8
0
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;
}
int main() {
    FILE *file_template = fopen("template.in", "r");
    FILE *file_values = fopen("values.in", "r");

    char *line = NULL;
    size_t len = 0;
    ssize_t read;

    if (file_values == NULL) {
        printf("Can't open template.in file!");
        return 0;
    }

    if (file_values == NULL) {
        printf("Can't open values.in file!");
        return 0;
    }

    while ((read = getline(&line, &len, file_values)) != -1) {
       if (line[0] == '-') {
           /* Regenerate enviroment and create last document */
           create_document(file_template);
           prepare_environment();

           /* Set document number */
           strcpy(document_number, get_value(line, len));
       } else {
           /* Save current template value on binary tree */
           save_value(get_number(line), get_value(line, len), firstValue, len);
       }
    }

    /* Create last document */
    create_document(file_template);
    free_memory(firstValue);

    if (line) {
        free(line);
    }

    fclose(file_template);
    fclose(file_values);

    return 0;
}
Exemple #10
0
extern struct value_t *cequ(int nargs, struct value_t **env, ...) {
	int ret_type = 0;
	struct value_t *ret;
	va_list ap;
	va_start(ap, env);
	struct value_t *v = va_arg(ap, struct value_t *);
	struct value_t *v2 = va_arg(ap, struct value_t *);
	va_end(ap);

	// only makes sense for integers and bools currently
	switch(v->type_tag) {
	case 1:
		if (v->int_val == v2->int_val) {
			ret = save_value(1.0, 2);
		} else {
			ret = save_value(0.0, 2);
		}
		break;
	case 2:
		if (!v->bool_val == !v2->bool_val) {
			ret = save_value(1.0, 2);
		} else {
			ret = save_value(0.0, 2);
		}
		break;
	case 4:
		if (v->array_len == v2->array_len) {
			ret = save_value(1.0, 2);
		} else {
			ret = save_value(0.0, 2);
		}
		break;
	case 3:
		if (v->array_len == v2->array_len && memcmp(v->array_val, v2->array_val, sizeof(char)*v->array_len) == 0) {
			ret = save_value(1.0, 2);
		} else {
			ret = save_value(0.0, 2);
		}
		break;
	}
	return ret;
}
Exemple #11
0
void file_warning(void)
{
halfword p= save_ptr;
int l= cur_level;
int c= cur_group;
int i;
save_ptr= cur_boundary;
while(grp_stack[in_open]!=save_ptr){
decr(cur_level);
tprint_nl("Warning: end of file when ");
print_group(true);
tprint(" is incomplete");
cur_group= save_level(save_ptr);
save_ptr= save_value(save_ptr);
}
save_ptr= p;
cur_level= (quarterword)l;
cur_group= (group_code)c;
p= cond_ptr;
l= if_limit;
c= cur_if;
i= if_line;
while(if_stack[in_open]!=cond_ptr){
tprint_nl("Warning: end of file when ");
print_cmd_chr(if_test_cmd,cur_if);
if(if_limit==fi_code)
tprint_esc("else");
print_if_line(if_line);
tprint(" is incomplete");
if_line= if_line_field(cond_ptr);
cur_if= if_limit_subtype(cond_ptr);
if_limit= if_limit_type(cond_ptr);
cond_ptr= vlink(cond_ptr);
}
cond_ptr= p;
if_limit= l;
cur_if= c;
if_line= i;
print_ln();
if(tracing_nesting_par> 1)
show_context();
if(history==spotless)
history= warning_issued;
}
Exemple #12
0
int save_YMrecord(char **pname)
{
        char static name[256] ;
        int fil ;
        int r,i, nb,dummy ;
        static int YMfiles_saved = 0 ;

        YMfiles_saved++ ;
        sprintf(name,"%s\\YM_%03d.BIN",startdir,YMfiles_saved) ;
        *pname = &name ;

        remove(name) ;
        fil = open(name,O_CREAT|O_BINARY|O_RDWR,0) ;
        if (fil==0) return FALSE ;

        nb = ym_pos_end-ym_pos_start ;

//        nb = YMbuffer_ptr/14 ;

#ifdef YM5

        write(fil,"YM5!",4) ;           // format
        write(fil,"LeOnArD!",8) ;       // id
        save_value(fil,nb,4) ;          // number of VBL
        save_value(fil,1,4) ;           // song Attributes: interleaved
        save_value(fil,0,2) ;            // nb digidrums
//       save_value(fil,2000000,4) ;   // 2000000Hz => ST
        save_value(fil,1000000,4) ;     // 1000000Hz => CPC
        save_value(fil,50,2) ;          // 50KHz
        save_value(fil,ym_pos_loop-ym_pos_start,4) ; // VBL Loop
        dummy=0 ;
        write(fil,&dummy,2) ;           // Size extra data
        write(fil,&dummy,1) ;           // NTS song name
        write(fil,&dummy,1) ;           // NTS name author
        write(fil,pcstid,sizeof(pcstid)) ;
#else
        write(fil,"YM3!",4) ;
#endif
/*        for (i=0;i<nb;i++) {
                YMbuffer[i*14+1] &= 0x0f ;
                YMbuffer[i*14+3] &= 0x0f ;
                YMbuffer[i*14+5] &= 0x0f ;
                YMbuffer[i*14+6] &= 0x1f ;
                YMbuffer[i*14+7] &= 0x3f ;
                YMbuffer[i*14+8] &= 0x1f ;
                YMbuffer[i*14+9] &= 0x1f ;
                YMbuffer[i*14+10] &= 0x1f ;
                if (YMbuffer[i*14+13] != 0xff)
                        YMbuffer[i*14+13] &= 0xf ;
        }
*/
        for (r=0;r<14;r++) {
                for (i=0;i<nb;i++)
                        YMlinear[i] = YMbuffer[(i+ym_pos_start)*14+r] ;
                write(fil,YMlinear,nb) ;
        }

#ifdef YM5
        for (i=0;i<nb;i++)
                YMlinear[i] = 0 ;
        write(fil,YMlinear,nb) ;
        write(fil,YMlinear,nb) ;

        write(fil,"End!",4) ;
#endif
        close(fil) ;
        return TRUE ;
}
Exemple #13
0
/* Returns 0 on success, non-zero on failure */
static int save_table(
    lua_State * L,
    luabins_SaveBuffer * sb,
    int index,
    int nesting
  )
{
  int result = LUABINS_ESUCCESS;
  int header_pos = 0;
  int total_size = 0;

  if (nesting > LUABINS_MAXTABLENESTING)
  {
    return LUABINS_ETOODEEP;
  }

  /* TODO: Hauling stack for key and value removal
     may get too heavy for larger tables. Think out a better way.
  */

  header_pos = lbsSB_length(sb);
  result = lbs_writeTableHeader(sb, 0, 0);

  result = lbsSB_grow(sb, LUABINS_LINT + LUABINS_LINT);
  if (result == LUABINS_ESUCCESS)
  {
    lua_checkstack(L, 2); /* Key and value */
    lua_pushnil(L); /* key for lua_next() */
  }

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

    /* Save key. */
    result = save_value(L, sb, key_pos, nesting);

    /* Save value. */
    if (result == LUABINS_ESUCCESS)
    {
      result = save_value(L, sb, value_pos, nesting);
    }

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

  if (result == LUABINS_ESUCCESS)
  {
    /*
      Note that if array has holes, lua_objlen() may report
      larger than actual array size. So we need to adjust.

      TODO: Note inelegant downsize from size_t to int.
            Handle integer overflow here.
    */
    int array_size = luabins_min(total_size, (int)lua_objlen(L, index));
    int hash_size = luabins_max(0, total_size - array_size);

    result = lbs_writeTableHeaderAt(sb, header_pos, array_size, hash_size);
  }

  return result;
}
Exemple #14
0
/* 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;
}
Exemple #15
0
int luabins_save(lua_State * L, int index_from, int index_to)
{
  unsigned char num_to_save = 0;
  int index = index_from;
  int base = lua_gettop(L);
  luabins_SaveBuffer sb;

  /*
  * TODO: If lua_error() would happen below, would leak the buffer.
  */

  if (index_to - index_from > LUABINS_MAXTUPLE)
  {
    lua_pushliteral(L, "can't save that many items");
    return LUABINS_EFAILURE;
  }

  /* Allowing to call luabins_save(L, 1, lua_gettop(L))
     from C function, called from Lua with no arguments
     (when lua_gettop() would return 0)
  */
  if (index_to < index_from)
  {
    index_from = 0;
    index_to = 0;
    num_to_save = 0;
  }
  else
  {
    if (
        index_from < 0 || index_from > base ||
        index_to < 0 || index_to > base
      )
    {
      lua_pushliteral(L, "can't save: inexistant indices");
      return LUABINS_EFAILURE;
    }

    num_to_save = index_to - index_from + 1;
  }

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

  lbs_writeTupleSize(&sb, num_to_save);
  for ( ; index <= index_to; ++index)
  {
    int result = 0;

    result = save_value(L, &sb, index, 0);
    if (result != LUABINS_ESUCCESS)
    {
      switch (result)
      {
      case LUABINS_EBADTYPE:
        lua_pushliteral(L, "can't save: unsupported type detected");
        break;

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

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

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

      lbsSB_destroy(&sb);

      return result;
    }
  }

  {
    size_t len = 0UL;
    const unsigned char * buf = lbsSB_buffer(&sb, &len);
    lua_pushlstring(L, (const char *)buf, len);
    lbsSB_destroy(&sb);
  }

  return LUABINS_ESUCCESS;
}
Exemple #16
0
static void test_ExitCode(void)
{
    static const char* AeDebug="Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug";
    static const char* WineDbg="Software\\Wine\\WineDbg";
    char test_exe[MAX_PATH];
    DWORD ret;
    HKEY hkey;
    DWORD disposition;
    reg_save_value auto_value;
    reg_save_value debugger_value;

    GetModuleFileNameA(GetModuleHandle(NULL), test_exe, sizeof(test_exe));
    if (GetFileAttributes(test_exe) == INVALID_FILE_ATTRIBUTES)
        strcat(test_exe, ".so");
    if (GetFileAttributesA(test_exe) == INVALID_FILE_ATTRIBUTES)
    {
        ok(0, "could not find the test executable '%s'\n", test_exe);
        return;
    }

    ret=RegCreateKeyExA(HKEY_LOCAL_MACHINE, AeDebug, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &disposition);
    if (ret == ERROR_SUCCESS)
    {
        save_value(hkey, "auto", &auto_value);
        save_value(hkey, "debugger", &debugger_value);
        trace("HKLM\\%s\\debugger is set to '%s'\n", AeDebug, debugger_value.data);
    }
    else if (ret == ERROR_ACCESS_DENIED)
    {
        skip("not enough privileges to change the debugger\n");
        return;
    }
    else if (ret != ERROR_FILE_NOT_FOUND)
    {
        ok(0, "could not open the AeDebug key: %d\n", ret);
        return;
    }

    if (debugger_value.data && debugger_value.type == REG_SZ &&
        strstr((char*)debugger_value.data, "winedbg --auto"))
    {
        HKEY hkeyWinedbg;
        ret=RegCreateKeyA(HKEY_CURRENT_USER, WineDbg, &hkeyWinedbg);
        if (ret == ERROR_SUCCESS)
        {
            static DWORD zero;
            reg_save_value crash_dlg_value;
            save_value(hkeyWinedbg, "ShowCrashDialog", &crash_dlg_value);
            RegSetValueExA(hkeyWinedbg, "ShowCrashDialog", 0, REG_DWORD, (BYTE *)&zero, sizeof(DWORD));
            crash_and_winedbg(hkey, test_exe);
            restore_value(hkeyWinedbg, &crash_dlg_value);
            RegCloseKey(hkeyWinedbg);
        }
        else
            ok(0, "Couldn't access WineDbg Key - error %u\n", ret);
    }

    if (winetest_interactive)
        /* Since the debugging process never sets the debug event, it isn't recognized
           as a valid debugger and, after the debugger exits, Windows will show a dialog box
           asking the user what to do */
        crash_and_debug(hkey, test_exe, "dbg,none");
    else
        skip("\"none\" debugger test needs user interaction\n");
    if (disposition == REG_CREATED_NEW_KEY)
        win_skip("'dbg,event,order' test doesn't finish on Win9x/WinMe\n");
    else
        crash_and_debug(hkey, test_exe, "dbg,event,order");
    crash_and_debug(hkey, test_exe, "dbg,attach,event,code2");
    if (pDebugSetProcessKillOnExit)
        crash_and_debug(hkey, test_exe, "dbg,attach,event,nokill");
    else
        win_skip("DebugSetProcessKillOnExit is not available\n");
    if (pDebugActiveProcessStop)
        crash_and_debug(hkey, test_exe, "dbg,attach,event,detach");
    else
        win_skip("DebugActiveProcessStop is not available\n");

    if (disposition == REG_CREATED_NEW_KEY)
    {
        RegCloseKey(hkey);
        RegDeleteKeyA(HKEY_LOCAL_MACHINE, AeDebug);
    }
    else
    {
        restore_value(hkey, &auto_value);
        restore_value(hkey, &debugger_value);
        RegCloseKey(hkey);
    }
}
Exemple #17
0
void save_value_list (FILE *f, value_list vl)
{ int ix;
  save_int (f, vl -> size);
  for (ix = 0; ix < vl -> size; ix++)
    save_value (f, vl -> array[ix]);
};