Ejemplo n.º 1
0
/*
 * read a key value pair and add it to tree
 */
static void
read_key_value(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree)
{
  proto_tree *new_tree;
  proto_tree *new_tree_bck;
  proto_item *ti, *parent_ti;

  gbl_have_symbol = FALSE;

  parent_ti =
    proto_tree_add_item(etch_tree, hf_etch_keyvalue, tvb, *offset, 1,
                        ENC_NA);
  new_tree_bck = new_tree =
    proto_item_add_subtree(parent_ti, ett_etch_keyvalue);

  ti = proto_tree_add_item(new_tree, hf_etch_keyname, tvb, *offset, 0,
                           ENC_NA);
  new_tree = proto_item_add_subtree(ti, ett_etch_key);
  read_value(offset, tvb, new_tree, hf_etch_value);

  /* append the symbol of the key */
  if(gbl_have_symbol == TRUE){
    proto_item_append_text(parent_ti, " (");
    proto_item_append_text(parent_ti, "%s", wmem_strbuf_get_str(gbl_symbol_buffer));
    proto_item_append_text(parent_ti, ")");
  }

  ti = proto_tree_add_item(new_tree_bck, hf_etch_valuename, tvb, *offset,
                           0, ENC_NA);
  new_tree = proto_item_add_subtree(ti, ett_etch_value);
  read_value(offset, tvb, new_tree, hf_etch_value);
}
Ejemplo n.º 2
0
/*
 * read a struct and add it to tree
 */
static void
read_struct(unsigned int *offset, tvbuff_t *tvb, proto_tree *etch_tree,
            int add_type_field)
{
  proto_item *ti;
  proto_tree *new_tree;
  int         length;
  int         i;

  ti = proto_tree_add_item(etch_tree, hf_etch_struct, tvb, *offset,
                           tvb_captured_length(tvb) - *offset, ENC_NA);
  new_tree = proto_item_add_subtree(ti, ett_etch_struct);

  if (add_type_field) {
    read_type(offset, tvb, new_tree);
  }
  /* struct type as hash */
  read_value(offset, tvb, new_tree, hf_etch_value);

  /* struct length */
  length = read_value(offset, tvb, new_tree, hf_etch_length);

  for (i = 0; i < length; i++) {
    read_key_value(offset, tvb, new_tree);
  }

  /* termination */
  read_type(offset, tvb, new_tree);
}
void Eurotherm2000Series::get_setpoint_limits(double& min, double& max) const {
  std::string answer;
  read_value("LS",answer);
  min=strtod(answer.c_str(),NULL);
  read_value("HS",answer);
  max=strtod(answer.c_str(),NULL);  
}
Ejemplo n.º 4
0
struct menuinfo reset_type(FILE *cfgfile, struct menuinfo stats_menu, int vehicle)
{
// function loads the options for that type of plane

    char vehicle_str[15];       // for storing the vehicle heading (in the cfg file)
    char vehicle_number_str[3]; // for temporarily storing the vehicle number

// open the config file
    cfgfile = fopen("dogfight.cfg", "r");

// generate the vehicle heading required
    strcpy(vehicle_str, "vehicle ");
    fixed_str(vehicle_number_str, vehicle, 2);
    strcat(vehicle_str, vehicle_number_str);

    stats_menu.optionval[0] = read_value(cfgfile, '@', vehicle_str, "vehicle");
    stats_menu.optionval[1] = read_value(cfgfile, '@', vehicle_str, "turn_speed");
    stats_menu.optionval[2] = read_value(cfgfile, '@', vehicle_str, "acceleration");
    stats_menu.optionval[3] = read_value(cfgfile, '@', vehicle_str, "min_speed");
    stats_menu.optionval[4] = read_value(cfgfile, '@', vehicle_str, "max_speed");
    stats_menu.optionval[5] = read_value(cfgfile, '@', vehicle_str, "num_of_shots");
    stats_menu.optionval[6] = read_value(cfgfile, '@', vehicle_str, "shot_life");
    stats_menu.optionval[7] = read_value(cfgfile, '@', vehicle_str, "shot_lag");
    stats_menu.optionval[8] = read_value(cfgfile, '@', vehicle_str, "shot_base_speed");
    stats_menu.optionval[9] = read_value(cfgfile, '@', vehicle_str, "laser_length");

    fclose(cfgfile);

    return(stats_menu);
}
Ejemplo n.º 5
0
Archivo: array.c Proyecto: em-mo/TDDD56
struct array*
array_read(char * filename)
{
  int i;
  FILE * h;
  int num;
  value value;
  struct array * res;

  h = fopen(filename, "r");
  i = read_value(h, &num);
  assert(i > 0);
  
  res = array_alloc(num);

  num = 1;
  for (i = 0; i < res->capacity && num > 0; i++)
    {
      num = read_value(h, &value);
      array_put(res, value);
    }

  fclose(h);

  return res;
}
Ejemplo n.º 6
0
static mrb_value
read_object(MarshalContext *ctx)
{
	mrb_state *mrb = ctx->mrb;
	mrb_value class_path = read_value(ctx);

	struct RClass *klass =
		mrb_class_from_path(mrb, class_path);

	mrb_value obj = mrb_obj_value(mrb_obj_alloc(mrb, MRB_TT_OBJECT, klass));

	ctx->objects.add(obj);

	int iv_count = read_fixnum(ctx);
	int i;

	for (i = 0; i < iv_count; ++i)
	{
		mrb_value iv_name = read_value(ctx);
		mrb_value iv_value = read_value(ctx);

		mrb_obj_iv_set(mrb, mrb_obj_ptr(obj),
		               mrb_symbol(iv_name), iv_value);
	}

	return obj;
}
static char *check_device(const char *name)
{
	char path[PATH_MAX];
	int busnum, devnum, vendor, product;

	busnum = read_value(name, "busnum", "%d");
	if (busnum < 0)
		return NULL;

	devnum = read_value(name, "devnum", "%d");
	if (devnum < 0)
		return NULL;

	snprintf(path, sizeof(path), "/dev/bus/usb/%03u/%03u", busnum, devnum);

	vendor = read_value(name, "idVendor", "%04x");
	if (vendor < 0)
		return NULL;

	product = read_value(name, "idProduct", "%04x");
	if (product < 0)
		return NULL;

	if (vendor != 0x0a12 || product != 0x0001)
		return NULL;

	return strdup(path);
}
Ejemplo n.º 8
0
static bool_t MouseXYZ(GMouse* m, GMouseReading* pdr)
{
	(void)m;

	// No buttons
	pdr->buttons = 0;
	pdr->z = 0;
	
	if (getpin_pressed(m)) {
		pdr->z = 1;						// Set to Z_MAX as we are pressed

		aquire_bus(m);
		
		read_value(m, CMD_X);				// Dummy read - disable PenIRQ
		pdr->x = read_value(m, CMD_X);		// Read X-Value

		read_value(m, CMD_Y);				// Dummy read - disable PenIRQ
		pdr->y = read_value(m, CMD_Y);		// Read Y-Value

		read_value(m, CMD_ENABLE_IRQ);		// Enable IRQ

		release_bus(m);
	}
	return TRUE;
}
Ejemplo n.º 9
0
void	exec_opc(t_proc_list **lst, t_proc_list **exec_proc, t_vm *vm)
{
	if (vm->cycles != 0 && vm->cycles == (*lst)->proc->wex)
	{
		if (ft_codage_erase(vm->mem, (*lst)->proc) ||
			ft_param_erase(vm->mem, (*lst)->proc))
		{
			if ((*lst)->proc->opc == 1 || (*lst)->proc->opc == 9 ||
				(*lst)->proc->opc == 12 || (*lst)->proc->opc == 15)
				(*lst)->proc->codage = read_value(vm->mem,
												(*lst)->proc->prevpc + 1, 1);
			else
				(*lst)->proc->codage = read_value(vm->mem,
												(*lst)->proc->prevpc + 2, 1);
			reset_param(&((*lst)->proc->par_list));
			(*lst)->proc->exec = 1;
			(*lst)->proc->pc = (*lst)->proc->prevpc;
			get_opc(lst, vm);
		}
		ft_exec(lst, exec_proc, vm);
		(*lst)->proc->exec = 1;
		reset_param(&((*lst)->proc->par_list));
		(*lst)->proc->opc = 0;
		(*lst)->proc->wex = 0;
		(*lst)->proc->codage = 0;
	}
}
Ejemplo n.º 10
0
int main( int argc, char** argv )
{
    // Parse args and read values
    const Args args = parse(argc,argv);
    const int current = read_value("actual_brightness");
    const int max = read_value("max_brightness");

    int newval = current;

    switch (args.mode)
    {
        case PRINT:
            std::cout<<current<<" / "<<max<<std::endl;
            break;

        case PLUS:
        case MINUS: // args.value is negtive in this case.
            newval = clamp(current + args.value, 0, max);
            write_value("brightness", newval);
            break;
        case ABSOLUTE:
            newval = clamp(args.value, 0, max);
            write_value("brightness", newval);
            break;

        case ERROR:
            print_usage();
            break;
    }

    // Return 0 if everything went fine, and 1 if not.
    return args.mode == ERROR;
}
Ejemplo n.º 11
0
static void sk_write(const int argc, char *argv[])
{
	unsigned char slave_address, reg_address, i;
	unsigned short count;
	char buf[MAX_BUFF_SIZE] = { 0 };
	unsigned char val;
	unsigned char instance = atoi(argv[1]);

	/* Write command */
	if (argc > 5) {
		if (read_value(argv[3], &slave_address))
			printf("\nSlave Adress 0x%02x\n", slave_address);

		if (read_value(argv[4], &reg_address))
			printf("Reg Adress 0x%02x\n", reg_address);

		count = 1;
		for (i = 5; i < argc; i++) {
			if (read_value(argv[i], &val)) {
				buf[count++] = val;
				printf("0x%02x ", val);
			}
		}
		buf[0] = reg_address;

		/* Register Adress */
		i2c_RDWR(instance, slave_address, 0, 0, count, buf);

		printf("\n");
	} else {
		usage();
	}

}
Ejemplo n.º 12
0
int get_backlight (char* buf, char* color) {
    char val[200];
    char status[4];
    char *status_icon;
    char *ptr;
    char bl_path[45 + 10];
    char bl_bright[55 + 17];

    sprintf(bl_path, "/sys/class/backlight/%s_backlight", BACKLIGHT_TYPE);

    sprintf(bl_bright, "%s/%s", bl_path, "max_brightness");
    read_value(bl_bright, val);
    int max_level = strtol(val, &ptr, 10);

    sprintf(bl_bright, "%s/%s", bl_path, "actual_brightness");
    read_value(bl_bright, val);
    int lvl = strtol(val, &ptr, 10);

    float per =  ((float) lvl) / ((float) max_level);
    int percent = (int) (per * 100);

    status_icon = "";

    sprintf(buf, "%%{F%s}%%{B%s}%s%%{F%s}%%{B%s} %s %d", COLOR_BG_BACK, color, SEP_LEFT, COLOR_FG_BACK, COLOR_BG_BACK, status_icon, percent);
    return 1;
}
Ejemplo n.º 13
0
void msg_parser(char *msg_req_buffer, char *msg_resp_buffer, uint32_t *msg_len)
{
    msg_req_t         * req;
    msg_val_t           ret_msg_val;
    /* Store req and resp buffers into global context
     * to work for current message */
    g_msg_parser_ctxt->msg_req_buffer   = msg_req_buffer;
    g_msg_parser_ctxt->msg_resp_buffer  = msg_resp_buffer;
    g_msg_parser_ctxt->msg_len          = msg_len;
#if 0
    {
        uint16_t i;
        printf("Bytes : ");
        for (i=0; i<sizeof(msg_req_t); i++) {
            printf("%x ,", (uint8_t)msg_req_buffer[i]);
        }
        printf("\n");
    }
#endif
    req = (msg_req_t *) msg_req_buffer;
    if (req->req_type==KEEP_ALIVE_REQ) {
        msg_parser_resp(req->handle, req->req_type, STATUS_OK);
    } else {
        ret_msg_val = -1;
        switch (req->req_type) {
            case BYTE_READ_REQ:
                    ret_msg_val = read_value(req->addr, 1);   
                    break;
            case BYTE_WRITE_REQ:
                    write_value(req->addr, req->value, 1);   
                    break;
            case HALF_WORD_READ_REQ:
                    ret_msg_val = read_value(req->addr, 2);   
                    break;
            case HALF_WORD_WRITE_REQ:
                    write_value(req->addr, req->value, 2);   
                    break;
            case WORD_READ_REQ:
                    ret_msg_val = read_value(req->addr, 4);   
                    break;
            case WORD_WRITE_REQ:
                    write_value(req->addr, req->value, 4);   
                    break;
            default:
                assert(0, ASSERT_FATAL);
        }
        msg_parser_resp(req->handle, req->req_type, STATUS_OK,
                req->addr, ret_msg_val);
    }
#if 0
    {
        uint16_t i;
        printf("Bytes : ");
        for (i=0; i<sizeof(msg_resp_t); i++) {
            printf("%x ,", (uint8_t)msg_resp_buffer[i]);
        }
        printf("\n");
    }
#endif
}
Ejemplo n.º 14
0
void evaluate_formula (int *queue, int *queue_length, struct pcp_vars *pcp)
{
   register int *y = y_address;

   register int lastg = pcp->lastg;
   register int i;
   int nmr_entries;
   int *weight;
   int total;
   int nmr;

   total = 6 * lastg + 6;
   if (is_space_exhausted (total, pcp))
      return;

   /* fudge the value of submlg because of possible call to power */
   pcp->submlg -= total;

   read_value (TRUE, "Input number of components of formula: ",
	       &nmr_entries, 1);

   weight = allocate_vector (nmr_entries, 1, FALSE);
   first = allocate_vector (nmr_entries + 1, 0, FALSE);
   last = allocate_vector (nmr_entries + 1, 0, FALSE);
   list = allocate_vector (nmr_entries + 1, 0, FALSE);

   printf ("Input weight of each component of formula: ");
   for (i = 1; i < nmr_entries; ++i) {
      read_value (FALSE, "", &weight[i], 1);
   }
   read_value (TRUE, "", &weight[i], 1);

   read_value (TRUE, "Input power of individual component: ",
	       &power_of_entry, 1);
   
   read_value (TRUE, "Input power of word: ", &exponent, 1);
   
   for (i = 1; i <= nmr_entries; ++i) {
      first[i] = y[pcp->clend + weight[i] - 1] + 1;
      last[i] = y[pcp->clend + weight[i]];
   }
      
   /* generate the list of words; evaluate each, echelonise it 
      and build up the queue of redundant generators */
   nmr = 0;
   loop (queue, queue_length, nmr_entries, list, &nmr, 
	 first[nmr_entries], last[nmr_entries], pcp);

   /* reset value of submlg */
   pcp->submlg += total;
 
   free_vector (weight, 1);
   free_vector (first, 0);
   free_vector (last, 0);
   free_vector (list, 0);
}
Ejemplo n.º 15
0
int get_battery(char* buf) {
    char val[200];
    char status[4];
    char *status_icon;
    char *ptr;
    char bat_path_full[40];
    char bat_path_now[40];
    char bat_path_status[40];
    char *bat_path_base = "/sys/class/power_supply/BAT0";
    char bat_type_name[7];
    char bat_path_buf[50];
    sprintf(bat_path_buf, "%s/status", bat_path_base);

    if(file_exists("/sys/class/power_supply/BAT0/energy_full") == 1) {
        strcpy(bat_type_name, "energy");
    } else {
        strcpy(bat_type_name, "charge");
    }

    sprintf(bat_path_full, "%s/%s_full", bat_path_base, bat_type_name);
    sprintf(bat_path_now, "%s/%s_now", bat_path_base, bat_type_name);
    sprintf(bat_path_status, "%s/status", bat_path_base);

    read_value(bat_path_full, val);
    if(DEBUG) fprintf(stderr, "%s = %s\n", bat_path_full, val);

    int max_level = strtol(val, &ptr, 10) / 10000;
    read_value(bat_path_now, val);
    if(DEBUG) fprintf(stderr, "%s = %s\n", bat_path_now, val);

    int lvl = strtol(val, &ptr, 10) / 10000;
    float per =  ((float) lvl) / ((float) max_level);
    int percent = (int) (per * 100);

    read_value(bat_path_status, val);
    for (int i=0; i < 3; i++) {
        status[i] = val[i];
    }
    status[3] = '\0';
    if (status[0] == 'C') {
        status_icon = "";
    } else {
        status_icon = "";
        if (percent < 80) {
            status_icon = "";
        } else if (percent < 50) {
            status_icon = "";
        } else if (percent < 30) {
            status_icon = "";
        }
    }

    sprintf(buf, "%%{F%s}%%{B%s}%s%%{F%s}%%{B%s} %s %d%%", COLOR_BG_BAT, COLOR_BG_BACK, SEP_LEFT, COLOR_FG_BAT, COLOR_BG_BAT,status_icon, percent);
    return 1;
}
Ejemplo n.º 16
0
void unpack_block(FILE *f, scan_desc_t *scan_desc, uint32_t index, 
		  int32_t T[_BSIZE])
{
	printdecod("Start unpack_block #%u (index = %u)\n",calls_count,index);
	assert(feof(f) == 0);
	huff_table_t *DC = scan_desc->table[0][index];
	huff_table_t *AC = scan_desc->table[1][index];
	if (DC == NULL || AC == NULL) {
		printf("\n** ERREUR: Table de Huffman absente **\n");
	}
	assert(DC != NULL);
	assert(AC != NULL);
	/* decodage du coefficient DC */
	uint8_t magnitude = read_symbol(f,scan_desc,DC);
	int32_t offset = read_value(f,scan_desc,magnitude);
	T[0] = scan_desc->pred[index] + offset;
	scan_desc->pred[index] = T[0];
	/* decodage des coefficients AC */
	uint8_t symbol;
	uint8_t nb_zero;
	uint32_t i = 1;
	while (i < 64) {
		symbol = read_symbol(f,scan_desc,AC);
		if (symbol == 0xf0) {        /* ZRL */
			for (uint32_t j = 0; j < 16; j++) {
				T[i] = 0;
				i++;
			}	
		} else if (symbol == 0x00) { /* EOB */
			while (i < 64) {
				T[i] = 0;
				i++;
			}
		} else {                     /* symbole normal */
			magnitude = symbol % 16;
			nb_zero = symbol >> 4;
			printdecod("=> sym: %u   mag: %u  nb_zero: %u\n",symbol,
			   magnitude,nb_zero);
			for (uint32_t j = 0; j < nb_zero; j++) {
				T[i] = 0;
				i++;
			}
			T[i] = read_value(f,scan_desc,magnitude);
			i++;
		}
	}
	printdecod("\n");
	printblock(T);
	calls_count++;
}
Ejemplo n.º 17
0
void get_meminfo(meminfo_t *meminfo)
{
	char buffer[BUFSIZ];

	if (read_file("/proc/meminfo", buffer, sizeof (buffer)) != -1) {
		meminfo->total = read_value(buffer, "MemTotal:");
		meminfo->free = read_value(buffer, "MemFree:");
		meminfo->shared = read_value(buffer, "MemShared:");
		meminfo->buffers = read_value(buffer, "Buffers:");
		meminfo->cached = read_value(buffer, "Cached:");
	} else {
		memset(meminfo, 0, sizeof (meminfo_t));
	}
}
Ejemplo n.º 18
0
void process_ce_data(int col, char *input, char *output)
{
	int i;
	struct istruct data;

	double d =
	    read_value("device.inp", 0, 12) + read_value("device.inp", 0, 39);
	double area =
	    read_value("device.inp", 0, 21) * read_value("device.inp", 0, 23);

	double cap = read_value("blom_bulk.inp", 0, 84) * epsilon0 * area / d;
	double capq = 0.0;

	double dt = 0.0;

	int x = 0;

	FILE *out = fopen(output, "w");

	for (x = 0; x < col; x++) {
		printf("loading.... %d\n", x);
		inter_load_by_col(&data, input, x);

		double tot = 0.0;

		for (i = 1; i < data.len - 1; i++) {
			//if ((data.x[i]>1e-6)&&(data.x[i]<1e-5))
			{
				dt = (data.x[i + 1] - data.x[i - 1]) / 2.0;
				tot += data.data[i] * dt;
			}
		}

		capq = (data.x[0] * cap) / Q;	//charge on capasitor
		capq /= area;
		capq /= d;

		tot /= area;
		tot /= d;
		tot /= Q;

		fprintf(out, "%e %e\n", data.data[0], tot - capq);
		inter_free(&data);
	}
//getchar();

	fclose(out);

}
Ejemplo n.º 19
0
static int read_line(Vector v){
  char op[4];
  char s[10];
  struct Inst inst;
  int res = scanf("%s %s", op, s);
  if(res == EOF) return 0;
  inst.op_code = read_opcode(op);
  inst.x = read_value(s);
  if(inst.op_code == cpy || inst.op_code == jnz){
    scanf("%s", s);
    inst.y = read_value(s);
  }
  Vector_push(v, &inst);
  return 1;
}
Ejemplo n.º 20
0
Value *
read_list(Globals *g)
{
   Value *list;
   Value **tail;
   Value *v;

   tail = &list;
   while (g->buflen > 0) {
      if (NULL == (v = read_value(g))) {
	 switch (PEEK_CHAR(g)) {

	  case ')':
	    if (tail != NULL) {		/* if no last cdr yet, use nil */
	       *tail = NULL;
	    }
	    NEXT_CHAR(g);
	    return list;
	    break;

	  case '.':			/* set last cdr explicitly */
	    NEXT_CHAR(g);
	    *tail = read_value(g);
	    if (*tail == NULL) {
	       /* badly formed input ??? */
	       ABORT(g, 13);
	    }
	    tail = NULL;
	    break;

	  default:
	    /* badly formed input ??? */
	    ABORT(g, 13);
	    break;
	 }
      }
      else {			/* read a value, add it to the list */
	 if (NULL == tail) {
	    /* two values after a . in a list.  very bad! ??? */
	    ABORT(g, 13);
	 }
	 *tail = ALLOC_VALUE();
	 (*tail)->tag = cons;
	 (*tail)->value.cons.car = v;
	 tail = &(*tail)->value.cons.cdr;
      }
   }
}
Ejemplo n.º 21
0
    static void read_value_internal(const std::shared_ptr<type_t>& type, const symbols_t& symbols, reflectable& reflectable)
    {
        // read sub-type values
        if (VAL* base_type_index = get_base_type_index_opt(*type).get())
        {
            VAL& base_type = get_type(*base_type_index);
            read_value_internal(base_type, symbols, reflectable);
        }

        // read current type values
        VAL& field_vector = get_field_vector(*type);
        VAR symbols_iter = std::begin(symbols);
        VAL symbols_end = std::end(symbols);
        for (VAL& field_kvp : field_vector)
        {
            if (symbols_iter != symbols_end)
            {
                VAL& field = field_kvp.second;
                VAL& field_symbol = *symbols_iter;
                VAL& field_type_index = get_type_index(*field);
                VAL& field_type_descriptor = get_type_descriptor(field_type_index);
                VAL& field_ptr = static_cast<char*>(static_cast<void*>(&reflectable)) + get_value_offset(*field);
                read_value(*field_type_descriptor, field_symbol, field_ptr);
                ++symbols_iter;
            }
        }
    }
Ejemplo n.º 22
0
double sensor_read_pressure() {

  int fd = sys_open(SYSTEM_PRESSURE_0_PATH, SYSTEM_FLAG_READ);

  // no need to close sensor
  return read_value(fd);
}
Ejemplo n.º 23
0
double sensor_read_solar() {

  int fd = sys_open(SYSTEM_SOLAR_0_PATH, SYSTEM_FLAG_READ);

  // no need to close sensor
  return read_value(fd);
}
Ejemplo n.º 24
0
KSensorStatus htu21d_setup(void)
{
    KSensorStatus ret;
    KI2CConf conf = {
        .addressing_mode = K_ADDRESSINGMODE_7BIT,
        .role = K_MASTER,
        .clock_speed = 100000
    };
    k_i2c_init(I2C_BUS, &conf);

    /* reset sensor */
    ret = htu21d_reset();
    return ret;
}

KSensorStatus htu21d_read_temperature(float * temp)
{
    KSensorStatus ret = SENSOR_ERROR;
    int raw;
    if (temp != NULL)
    {
        if ((ret = read_value(READ_TEMP_CMD, &raw)) == SENSOR_OK)
        {
            *temp = raw;
            *temp *= 175.72;
            *temp /= 65536;
            *temp -= 46.85;
        }
    }
    return ret;
}
Ejemplo n.º 25
0
Archivo: xml.c Proyecto: esneider/xml
static enum STATE read_xml ( FILE* file, struct xml_element* elem, bool root ) {

	enum STATE state;

	while ( true ) {

		skip_space( file );

		char c = fgetc( file );
		if ( c == EOF ) return root ? OK : PARSE_ERROR;
		ungetc( c, file );

		if ( c == '<' ) {

			struct xml_element* son = calloc( 1, sizeof( struct xml_element ) );
			if ( !son ) return MEMORY_ERROR;

			son->father = elem;
			son->next = elem->son;
			son->status = IS_ELEMENT_STATUS;

			state = read_tag( file, son );
			switch ( state ) {

				case OPEN_TAG:

					if ( son->next ) son->next->prev = son;
					elem->son = son;

					if ( ( state = read_xml ( file, son, false ) ) != OK )
						return state;
					break;

				case CLOSE_TAG:

					free( son );
					return OK;

				case ISOLATED_TAG:

					if ( son->next ) son->next->prev = son;
					elem->son = son;
					break;

				case OTHER_TAG:

					free( son );
					break;

				default:
					if ( son->next ) son->next->prev = son;
					elem->son = son;
					return state;
			}
		} else {
			state = read_value( file, elem );
			if ( state != OK ) return state;
		}
	}
}
Ejemplo n.º 26
0
int read_packet(int id)
{
  int ret = read_header(id);
  
  /*
   * Since we are reading with no timeout,
   * a positive value indicates that the header is complete.
   */
  if(ret > 0)
  {
    ret = read_value(id);

    /*
     * Since we are reading with no timeout,
     * a non-negative value indicates that the value is complete.
     */
    if(ret >= 0)
    {
      ret = adapter_process_packet(id, serials[id].data);

      serials[id].bread = 0;
    }
  }
  
  return ret;
}
Ejemplo n.º 27
0
int
add_elements(struct ds_context *ctx)
{
	PMEMobjpool *pop;
	int errors = 0;
	int i;
	int key_len;
	int val_len;
	unsigned char *key;
	unsigned char *value;

	if (ctx == NULL) {
		errors++;
	} else if (ctx->pop == NULL) {
		errors++;
	}

	if (!errors) {
		pop = ctx->pop;

		for (i = 0; i < ctx->insertions; i++) {
			key = NULL;
			value = NULL;
			key_len = read_key(&key);
			val_len = read_value(&value);
			art_insert(pop, key, key_len, value, val_len);
			if (key != NULL)
				free(key);
			if (value != NULL)
				free(value);
		}
	}

	return errors;
}
Ejemplo n.º 28
0
struct t_command* read_command( FILE* f )
{
  char *name = NULL;
  int value = 0;
  char *value_str = NULL;
  struct t_command *command = malloc( sizeof(struct t_command) );

  name = read_name( f );
  command->name = name;

  // printf("\nNome: '%s'\n", name);

  read_equal( f );

  value = read_value( f );
  if ( value == -1 ) {
	  /* Value is a string */
	  value_str = read_string( f );
	  // printf("Stringa('%s')\n", value_str );
    command->value_str = value_str;
    command->type = STRING;
  } else {
	  // printf("Value: %u\n", value );
    command->value_num = value;
    command->type = NUMERIC;
  }

  return command;
}
Ejemplo n.º 29
0
 bool read_value(int8_t& value)
 {
     uint8_t v;
     bool ok = read_value(v);
     value = (int8_t)v;
     return ok;
 }
Ejemplo n.º 30
0
//int main ( int argc, char *argv[] )
int read_prof ( char *name, int subint, double *profile, int nphase, int npol, int nchan)
{  
	double value[nphase*npol*nchan];
	double scl[npol*nchan];
	double offs[npol*nchan];

	read_value (name, subint, value, nphase, nchan, npol);
	read_offs (name, subint, offs, nchan, npol);
	read_scl (name, subint, scl, nchan, npol);

	int i,j,h;
    for (i = 0; i < npol; i++)                             // print the results
    //for (i = 0; i < nchan; i++)                             // print the results
	{
		for (h = 0; h < nchan; h++)                             // print the results
		//for (h = 0; h < npol; h++)                             // print the results
		{
			for (j = 0; j < nphase; j++)                             // print the results
			{
				//profile[i*nchan*nphase+h*nphase+j] = value[i*nchan*nphase+h*nphase+j];
				profile[i*nchan*nphase+h*nphase+j] = value[i*nchan*nphase+h*nphase+j]*scl[i*nchan+h] + offs[i*nchan+h];
				//profile[i*npol*nphase+h*nphase+j] = value[i*npol*nphase+h*nphase+j]*scl[i*npol+h] + offs[i*npol+h];
				//profile[i*nphase+j] = value[i*nphase+j];
				//printf("%d %lf \n", i, profile[i]);
			}
		}
	}

    return 0;
}