Exemplo n.º 1
0
/** Write a section to the output. */
static void write_section(t3_config_t *config, FILE *file, int indent) {
  while (config != NULL) {
    if (config->type == T3_CONFIG_PLIST) {
      write_plist(config, file, indent);
      config = config->next;
      continue;
    }

    write_indent(file, indent);
    fputs(config->name, file);
    switch (config->type) {
      case T3_CONFIG_BOOL:
      case T3_CONFIG_INT:
      case T3_CONFIG_NUMBER:
      case T3_CONFIG_STRING:
      case T3_CONFIG_LIST:
        fputs(" = ", file);
        write_value(config, file, indent);
        fputc('\n', file);
        break;
      case T3_CONFIG_SECTION:
        fputc(' ', file);
        write_value(config, file, indent);
        fputc('\n', file);
        break;
      default:
        /* This can only happen if the client screws up the list, which
           the interface does not allow by itself. */
        break;
    }
    config = config->next;
  }
}
Exemplo n.º 2
0
/*
 * jsonwr_log10num_value
 * Write a number that has been converted into log base 10
 * because it may be too small to represent.
 */
void jsonwr_log10num_value(JSONWR_T* jsonwr, double value, int prec) {
  double m, e;
  m = 0;
  e = 0;
  if (value > -HUGE_VAL && value < HUGE_VAL) { // normal value
    e = floor(value);
    m = pow(10.0, value - e);
    // check that rounding up won't cause a 9.9999 to go to a 10
    if (m + (.5 * pow(10,-prec)) >= 10) {
      m = 1;
      e += 1;
    }
    str_clear(jsonwr->value_buf);
    str_appendf(jsonwr->value_buf, "\"%.*fe%+04.0f\"", prec, m, e);
    write_value(jsonwr);
  } else if (value >= HUGE_VAL) { // infinity
    str_clear(jsonwr->value_buf);
    str_appendf(jsonwr->value_buf, "\"inf\"");
    write_value(jsonwr);
  } else { // negative infinity
    str_clear(jsonwr->value_buf);
    // note that m and e are both 0, but it is important that we pass them
    // and not constants because if I pass a 0 then it is of int type which
    // takes up less space on the stack then the format string is expecting
    str_appendf(jsonwr->value_buf, "\"%.*fe%+04.0f\"", prec, m, e);
    write_value(jsonwr);
  }
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
/*
 * jsonwr_log10num_value
 * Write a number that has been converted into log base 10
 * because it may be too small to represent.
 */
void jsonwr_log10num_value(JSONWR_T* jsonwr, double value, int prec) {
  double m, e;
  m = 0;
  e = 0;
  if (value > -HUGE_VAL && value < HUGE_VAL) { // normal value
    e = floor(value);
    m = exp10(value - e);
    // check that rounding up won't cause a 9.9999 to go to a 10
    if (m + (.5 * pow(10,-prec)) >= 10) {
      m = 1;
      e += 1;
    }
    str_clear(jsonwr->value_buf);
    str_appendf(jsonwr->value_buf, "\"%.*fe%+04.0f\"", prec, m, e);
    write_value(jsonwr);
  } else if (value >= HUGE_VAL) { // infinity
    str_clear(jsonwr->value_buf);
    str_appendf(jsonwr->value_buf, "\"inf\"");
    write_value(jsonwr);
  } else { // negative infinity
    str_clear(jsonwr->value_buf);
    str_appendf(jsonwr->value_buf, "\"%.*fe%+04.0f\"", prec, 0, 0);
    write_value(jsonwr);
  }
}
Exemplo n.º 5
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
}
Exemplo n.º 6
0
void write_vector(scanner& sc, writer& wr, const value_vector_type& vec) {
    bool wrap = vector_length(vec) > wr.wrap_length;

    wr.append("[ ");
    wr.indent();
    if (wrap) {
        wr.newline();
    }
    sc.expect('[');

    unsigned int vals_read = 0;
    while (!sc.peek_token().is_char(']')) {
        if (vals_read < vec.size()) {
            write_value(sc, wr, vec[vals_read]);
            vals_read++;
        } else {
            read_value(sc);
        }

        bool terminate = sc.peek_token().is_char(']') && vals_read == vec.size();
        if (!terminate) {
            if (wrap) {
                wr.newline();
            } else {
                wr.append(", ");
            }
        } else if (!wrap) {
            wr.append(" ");
        }
        sc.expect(',', true);
    }

    for (unsigned int i = vals_read; i < vec.size(); i++) {
        scanner dummy_scanner = make_scanner("0");
        write_value(dummy_scanner, wr, vec[i]);
        if (i < vec.size() - 1) {
            if (wrap) {
                wr.newline();
            } else {
                wr.append(", ");
            }
        } else if (!wrap) {
            wr.append(" ");
        }
    }

    wr.unindent();
    if (wrap) {
        wr.newline();
    }

    sc.expect(']');
    wr.append("]");
}
Exemplo n.º 7
0
Config *
config_create()
{
    Config *config = malloc(sizeof(Config));

    config->document_root = NULL;
    config->config_dir = NULL;

    write_value(&config->document_root, CONFIG_DEFAULT_DOCUMENT_ROOT, CONFIG_VALUE_MAX_LENGTH);
    write_value(&config->config_dir, CONFIG_DEFAULT_CONFIG_DIR, CONFIG_VALUE_MAX_LENGTH);

    config->port = CONFIG_DEFAULT_PORT;

    return config;
}
Exemplo n.º 8
0
 void write_value(const reflectable& source_reflectable, symbol& target_symbol)
 {
     VAL& type = get_type(source_reflectable);
     VAL& type_index = get_type_index(*type);
     VAL& type_descriptor = get_type_descriptor(type_index);
     write_value(*type_descriptor, static_cast<const void*>(&source_reflectable), target_symbol);
 }
Exemplo n.º 9
0
void binary_serializer::write_tuple(size_t size,
                                    const primitive_variant* values) {
    const primitive_variant* end = values + size;
    for ( ; values != end; ++values) {
        write_value(*values);
    }
}
Exemplo n.º 10
0
static int sendit(unsigned int timeout_ms)
{
    char value[TIMEOUT_STR_LEN]; /* large enough for millions of years */

    snprintf(value, sizeof(value), "%u", timeout_ms);
    return write_value(THE_DEVICE, value);
}
Exemplo n.º 11
0
void 
TextEdit::set_text(const char *_text)
{
  strncpy(value, _text, size);
  value[size] = 0;
  write_value();
}
Exemplo n.º 12
0
void sysfs_write(struct sysfs_def *def, int gpio, const char *attr, const char *value)
{
	static char path[PATH_MAX];
	snprintf(path, PATH_MAX, "/sys/class/%s/%s%d/%s", def->class, def->obj_prefix, gpio, attr);
	path[PATH_MAX-1] = '\0';

	write_value(path, value);
}
Exemplo n.º 13
0
/*
 * jsonwr_bool_value
 * Write a boolean value
 */
void jsonwr_bool_value(JSONWR_T* jsonwr, int value) {
  str_clear(jsonwr->value_buf);
  if (value) {
    str_append(jsonwr->value_buf, "true", 4);
  } else {
    str_append(jsonwr->value_buf, "false", 5);
  }
  write_value(jsonwr);
}
Exemplo n.º 14
0
void
config_set(Config *config, int attr, void *value)
{
    switch (attr) {
        case CONFIG_DOCUMENT_ROOT:
            write_value(&config->document_root, (char *)value, CONFIG_VALUE_MAX_LENGTH);
            break;
        case CONFIG_CONFIG_DIR:
            write_value(&config->config_dir, (char *)value, CONFIG_VALUE_MAX_LENGTH);
            break;
        case CONFIG_PORT:
            config->port = *(int *)value;
            break;
        default:
            // TODO: error
            break;
    }
}
Exemplo n.º 15
0
static pic_value
pic_write_display(pic_state *pic)
{
  pic_value v, port = pic_stdout(pic);

  pic_get_args(pic, "o|p", &v, &port);
  write_value(pic, v, port, DISPLAY_MODE, OP_WRITE);
  return pic_undef_value(pic);
}
Exemplo n.º 16
0
static pic_value
pic_write_write_shared(pic_state *pic)
{
  pic_value v, port = pic_stdout(pic);

  pic_get_args(pic, "o|p", &v, &port);
  write_value(pic, v, port, WRITE_MODE, OP_WRITE_SHARED);
  return pic_undef_value(pic);
}
Exemplo n.º 17
0
    virtual void write_usage(std::ostream &out) const {
      if (key != 0) {
	out << '-' << key;
	out << "/--" << long_name;
      }
      out << "\t" << description;
      out << " Value: ";
      write_value(out);
      out << std::endl;
    }
Exemplo n.º 18
0
int mount_and_add(const char *controller, const char *path, const char *prop, const char *value)
{
	char aux[1024], paux[1024], subdir[1024];

	if (mkdir(dirname, 0700) < 0 && errno != EEXIST) {
		pr_perror("Can't make dir");
		return -1;
	}

	sprintf(subdir, "%s/%s", dirname, controller);
	if (mkdir(subdir, 0700) < 0) {
		pr_perror("Can't make dir");
		return -1;
	}

	if (mount("none", subdir, "cgroup", 0, controller)) {
		pr_perror("Can't mount cgroups");
		goto err_rd;
	}

	sprintf(paux, "%s/%s", subdir, path);
	mkdir(paux, 0600);

	sprintf(paux, "%s/%s/%s", subdir, path, prop);
	if (write_value(paux, value) < 0)
		goto err_rs;

	sprintf(aux, "%d", getpid());
	sprintf(paux, "%s/%s/tasks", subdir, path);
	if (write_value(paux, aux) < 0)
		goto err_rs;

	sprintf(paux, "%s/%s/special_prop_check", subdir, path);
	mkdir(paux, 0600);

	return 0;
err_rs:
	umount(dirname);
err_rd:
	rmdir(dirname);
	return -1;
}
Exemplo n.º 19
0
void sysfs_unexport(struct sysfs_def *def, int gpio)
{
	static char path[PATH_MAX];
	snprintf(path, PATH_MAX, "/sys/class/%s/unexport", def->class);
	path[PATH_MAX-1] = '\0';

	static char buffer[15];
	sprintf(buffer, "%d", gpio);

	write_value(path, buffer);
}
Exemplo n.º 20
0
 void Argument_helper::Argument_target::write_usage(std::ostream &out) const {
   if (key != 0) {
     out << '-' << key;
     out << "/--" << long_name;
   }
   out << ' ' << arg_description;
   out << "\t" << description;
   out << " Value: ";
   write_value(out);
   out << std::endl;
 }
Exemplo n.º 21
0
  void
  Vcd_instrumenter::write_update(std::ostream& os,
      ir::Time const& t) {
    os << '#' << t.value(m_unit) << '\n';

    std::size_t ref_counter = 0;
    for(auto const& insp : m_inspected) {
      for(std::size_t i=0; i<insp->num_elements(); ++i)
        ref_counter = write_value(os, insp, i, ref_counter);
    }
  }
Exemplo n.º 22
0
static void write_array(io::stream& e, const void* object, const bsreq* req, int level) {
	if(level > 0 && req->count > 1)
		e << "(";
	for(unsigned index = 0; index < req->count; index++) {
		if(index > 0)
			e << ", ";
		write_value(e, req->ptr(object, index), req, level);
	}
	if(level > 0 && req->count > 1)
		e << ")";
}
Exemplo n.º 23
0
  void
  Vcd_instrumenter::write_dump_all(std::ostream& os) {
    os << "$dumpvars\n";

    std::size_t ref_counter = 0;
    for(auto const& insp : m_inspected) {
      for(std::size_t i=0; i<insp->num_elements(); ++i)
        ref_counter = write_value(os, insp, i, ref_counter);
    }

    os << "$end\n";
  }
Exemplo n.º 24
0
int main(){

	Buffer buffer;													// generate and init new buffer
	buffer.read_offset = 0;
	buffer.write_offset = 0;
	buffer.isEmpty = 1;
	buffer.isFull = 0;
	buffer.mutex = 0;

	int value = -1;

	write_value( 4, &buffer );										// write and read some numbers
	write_value( 8, &buffer );

	value = read_value( &buffer );

	write_value( 15, &buffer );

	value = read_value( &buffer );
	value = read_value( &buffer );

	write_value( 16, &buffer );
	write_value( 23, &buffer );
	write_value( 42, &buffer );

	value = read_value( &buffer );
	value = read_value( &buffer );
	value = read_value( &buffer );


	return value;
}
Exemplo n.º 25
0
    void DeckOutput::write( const T& value ) {
        if (default_count > 0) {
            write_sep( );

            os << default_count << "*";
            default_count = 0;
            row_count++;
        }

        write_sep( );
        write_value( value );
        row_count++;
    }
Exemplo n.º 26
0
static void		cut_env(t_all *all, char ***env_dup)
{
	char	*name;
	int		ret;

	ret = 0;
	name = get_name(all->ch_arg[2]);
	ret = name_search(ft_strdup(name), all);
	if (ret != -1)
	{
		write_value(env_dup, ret);
		ft_strdel(&name);
	}
}
Exemplo n.º 27
0
/** Write a list to the output. */
static void write_list(t3_config_t *config, FILE *file, int indent) {
  t3_bool first = t3_true;
  while (config != NULL) {
    if (first) {
      first = t3_false;
    } else {
      fputs(", ", file);
    }

    write_value(config, file, indent);

    config = config->next;
  }
}
Exemplo n.º 28
0
bool
acdb_write_value_at_address(unsigned long address, int value)
{
  const acdb_param *param = get_acdb_param();
  if (!param) {
    return false;
  }

  if (!write_value(param, address, value)) {
    return true;
  }

  return false;
}
Exemplo n.º 29
0
int main(void) {

	while (1) {

		refresh_inputs();

		if (isSchedulable_done()) {
			done();
		} else if (isSchedulable_write_value()) {
			int ports = 0;
			if (!FIFO_HAS_ROOM(decoder_parser_blkexp_OUT)(&fifo_o_decoder_parser_blkexp_OUT, 1)) {
				ports |= 0x01;
			}
			if (ports != 0) {
				continue;
			}
			write_value();
		} else if (isSchedulable_write_zero()) {
			int ports = 0;
			if (!FIFO_HAS_ROOM(decoder_parser_blkexp_OUT)(&fifo_o_decoder_parser_blkexp_OUT, 1)) {
				ports |= 0x01;
			}
			if (ports != 0) {
				continue;
			}
			write_zero();
		} else if ((decoder_parser_blkexp_RUN_tokens >= 1) && (decoder_parser_blkexp_VALUE_tokens >= 1) && (decoder_parser_blkexp_LAST_tokens >= 1) && isSchedulable_read_immediate()) {
			int ports = 0;
			if (!FIFO_HAS_ROOM(decoder_parser_blkexp_OUT)(&fifo_o_decoder_parser_blkexp_OUT, 1)) {
				ports |= 0x01;
			}
			if (ports != 0) {
				continue;
			}
			read_immediate();
		} else if ((decoder_parser_blkexp_RUN_tokens >= 1) && (decoder_parser_blkexp_VALUE_tokens >= 1) && (decoder_parser_blkexp_LAST_tokens >= 1) && isSchedulable_read_save()) {
			int ports = 0;
			if (!FIFO_HAS_ROOM(decoder_parser_blkexp_OUT)(&fifo_o_decoder_parser_blkexp_OUT, 1)) {
				ports |= 0x01;
			}
			if (ports != 0) {
				continue;
			}
			read_save();
		} else {
			continue;
		}
	}
}
Exemplo n.º 30
0
int main(int argc, char** argv)
{
    int concurrent;
    if (argc != 2) {
        puts("Give 1 for concurrent OpenCL kernel execution and 0 otherwise.");
        exit(0);
    }
    concurrent = atoi(argv[1]);
    init_device(concurrent);
    write_value();
    execute_device();
    read_value();

    return 0;
}