Beispiel #1
0
static int csv_read_record(TABDCA *dca, struct csv *csv)
{     /* read next record from csv data file */
      int k, ret = 0;
      xassert(csv->mode == 'R');
      if (setjmp(csv->jump))
      {  ret = 1;
         goto done;
      }
      /* read dummy RECNO field */
      if (csv->ref[0] > 0)
#if 0 /* 01/VI-2010 */
         mpl_tab_set_num(dca, csv->ref[0], csv->count-1);
#else
         mpl_tab_set_num(dca, csv->ref[0], csv->count-csv->nskip-1);
#endif
      /* read fields */
      for (k = 1; k <= csv->nf; k++)
      {  read_field(csv);
         if (csv->what == CSV_EOF)
         {  /* end-of-file reached */
            xassert(k == 1);
            ret = -1;
            goto done;
         }
         else if (csv->what == CSV_EOR)
         {  /* end-of-record reached */
            int lack = csv->nf - k + 1;
            if (lack == 1)
               xprintf("%s:%d: one field missing\n", csv->fname,
                  csv->count);
            else
               xprintf("%s:%d: %d fields missing\n", csv->fname,
                  csv->count, lack);
            longjmp(csv->jump, 0);
         }
         else if (csv->what == CSV_NUM)
         {  /* floating-point number */
            if (csv->ref[k] > 0)
            {  double num;
               xassert(str2num(csv->field, &num) == 0);
               mpl_tab_set_num(dca, csv->ref[k], num);
            }
         }
         else if (csv->what == CSV_STR)
         {  /* character string */
            if (csv->ref[k] > 0)
               mpl_tab_set_str(dca, csv->ref[k], csv->field);
         }
         else
            xassert(csv != csv);
      }
      /* now there must be NL */
      read_field(csv);
      xassert(csv->what != CSV_EOF);
      if (csv->what != CSV_EOR)
      {  xprintf("%s:%d: too many fields\n", csv->fname, csv->count);
         longjmp(csv->jump, 0);
      }
done: return ret;
}
Beispiel #2
0
static int read_pwd(FILE *stream, char *buf, size_t buflen, struct passwd *pwd) {
	int res;
	char *p = buf;
	size_t llen = buflen;

	if (0 != (res = read_field(stream, &p, &llen, &pwd->pw_name, ':'))) {
		return res;
	}

	if (0 != (res = read_field(stream, &p, &llen, &pwd->pw_passwd, ':'))) {
		return res;
	}

	if (0 != (res = read_int_field(stream, "%hd", &pwd->pw_uid, ':'))) {
		return res;
	}

	if (0 != (res = read_int_field(stream, "%hd", &pwd->pw_gid, ':'))) {
		return res;
	}

	if (0 != (res = read_field(stream, &p, &llen, &pwd->pw_gecos, ':'))) {
		return res;
	}

	if (0 != (res = read_field(stream, &p, &llen, &pwd->pw_dir, ':'))) {
		return res;
	}

	if (0 != (res = read_field(stream, &p, &llen, &pwd->pw_shell, '\n'))) {
		return res;
	}

	return 0;
}
Beispiel #3
0
int fgetgrent_r(FILE *fp, struct group *gbuf, char *tbuf,
		size_t buflen, struct group **gbufp) {
	int res;
	char *buf = tbuf;
	size_t buf_len = buflen;
	char *ch, **pmem;

	*gbufp = NULL;

	if (0 != (res = read_field(fp, &buf, &buf_len, &gbuf->gr_name, ':'))) {
		return res;
	}

	if (0 != (res = read_field(fp, &buf, &buf_len, &gbuf->gr_passwd, ':'))) {
		return res;
	}

	if (0 != (res = read_int_field(fp, "%hd", &gbuf->gr_gid, ':'))) {
		return res;
	}

	if (0 != (res = read_field(fp, &buf, &buf_len, &ch, '\n'))) {
		return res;
	}

	gbuf->gr_mem = pmem = (char **)binalign_bound((uintptr_t)buf, sizeof(void *));
	buf_len -= (uintptr_t)pmem - (uintptr_t)buf;

	*pmem = ch;

	while (NULL != (ch = strchr(ch, ','))) {

		if (buf_len < sizeof(char *)) {
			return -ERANGE;
		}

		buf_len -= sizeof(char *);

		*ch++ = '\0';

		*(++pmem) = ch;

	}

	if (buf_len < sizeof(char *)) {
		return -ERANGE;
	}
	*(++pmem) = NULL;

	*gbufp = gbuf;

	return 0;
}
Beispiel #4
0
Abonent* parse_abonent(TCHAR** pos, TCHAR* max_pos)
{
    DWORD id;
    TCHAR phone_no[256];
    TCHAR family_name[256];
    TCHAR name[256];
    TCHAR middle_name[256];
    TCHAR street[256];
    TCHAR house[256];
    TCHAR building[256];
    TCHAR flat[256];
    TCHAR tmp[256];

    get_next_el(pos, tmp, max_pos);
    id = _ttoi(tmp);

    read_field(phone_no);
    read_field(family_name);
    read_field(name);
    read_field(middle_name);
    read_field(street);
    read_field(house);
    read_field(building);
    read_field(flat);

    skip_delimiters(pos, max_pos);
    (*pos)++;

    Abonent* abonent = create_abonent(id, phone_no, family_name, name,
                                      middle_name, street, house, building, flat);
    return abonent;
}
Beispiel #5
0
krb5_error_code
krb5_ktsrvint_read_entry(krb5_context context, krb5_keytab id, krb5_keytab_entry *ret_entry)
{
    FILE *fp;
    char name[SNAME_SZ], instance[INST_SZ], realm[REALM_SZ];
    unsigned char key[8];
    int vno;
    krb5_error_code kerror;

    /* Read in an entry from the srvtab file. */
    fp = KTFILEP(id);
    kerror = read_field(fp, name, sizeof(name));
    if (kerror != 0)
	return kerror;
    kerror = read_field(fp, instance, sizeof(instance));
    if (kerror != 0)
	return kerror;
    kerror = read_field(fp, realm, sizeof(realm));
    if (kerror != 0)
	return kerror;
    vno = getc(fp);
    if (vno == EOF)
	return KRB5_KT_END;
    if (fread(key, 1, sizeof(key), fp) != sizeof(key))
	return KRB5_KT_END;

    /* Fill in ret_entry with the data we read.  Everything maps well
     * except for the timestamp, which we don't have a value for.  For
     * now we just set it to 0. */
    memset(ret_entry, 0, sizeof(*ret_entry));
    ret_entry->magic = KV5M_KEYTAB_ENTRY;
    kerror = krb5_425_conv_principal(context, name, instance, realm,
				     &ret_entry->principal);
    if (kerror != 0)
	return kerror;
    ret_entry->vno = vno;
    ret_entry->timestamp = 0;
    ret_entry->key.enctype = ENCTYPE_DES_CBC_CRC;
    ret_entry->key.magic = KV5M_KEYBLOCK;
    ret_entry->key.length = sizeof(key);
    ret_entry->key.contents = malloc(sizeof(key));
    if (!ret_entry->key.contents) {
	krb5_free_principal(context, ret_entry->principal);
	return ENOMEM;
    }
    memcpy(ret_entry->key.contents, key, sizeof(key));

    return 0;
}
Beispiel #6
0
void main(int argc, char *argv[]){
    void error_print();

    double R, F, x_shift, y_shift;

    /* Processing the command line argument  */
    if (argc<2 || argc >5){
        error_print(argv[0]);
        exit(1);
    }
    /* reading the data from a command line */
    sscanf(argv[1],"%le",&R);
    sscanf(argv[2],"%le",&F);
    x_shift=y_shift=0.;
    if(argc == 4) sscanf(argv[3],"%le",&y_shift);
    if(argc == 5) {
        sscanf(argv[3],"%le",&y_shift);
        sscanf(argv[4],"%le",&x_shift);
    }
    read_field();

    if (field.double1 != 0.) {
        fprintf(stderr,"tor_ens can not be applied in spherical\
 coordinates,\nuse CONVERT first\n");
        exit(1);
    }
Beispiel #7
0
static int read_parameters(struct parameters *params)
{
	char *data, *name, *val;
	char *buff = malloc(3 * N);
	data = buff;
	name = data + N;
	val = name + N;

	FILE *fp = fopen("setup", "r");
	
	if (fp == NULL)
		return 1;

	while (read_block(fp, name, data, N, N)) {
		if (!strcmp(name, "parameters")) {
			while ((data = read_field(data, name, val)))
				set_parameter_value(params, name, val);
			break;
		}
		data = buff;
	}
	free(buff);
	fclose(fp);
	return 0;
}
Beispiel #8
0
static void read_fields( FILE *f, const save_field_t *fields, void *base ) {
    const save_field_t *field;

    for( field = fields; field->type; field++ ) {
        read_field( f, field, base );
    }
}
Beispiel #9
0
//-----------------------------------------------------------------------------
bool datareader_c::read_joint( model_ptr owner, xml_element_ptr top, std::string key ) {
  xml_attribute_ptr attribute = top->attribute( "id" );
  if( !attribute ) return false;

  std::string name = attribute->get_value();
  xml_element_ptr element;
  std::string tag;

  joint_ptr joint = joint_ptr( new joint_c() );
  component_ptr component = boost::dynamic_pointer_cast<component_c>( joint );

  if( key != "" )
    key += "::";
  key += name;
  joint->id = name;

  for( unsigned i = 0; i < top->elements(); i++ ) {
    element = top->element( i );
    tag = element->get_name();
    if( tag == "Field" ) {
      read_field( component, element, key );
    }
  }

  owner->insert( joint );

  return true;
}
Beispiel #10
0
classfile* read_classfile(FILE* f){
    classfile* c = malloc(sizeof(classfile));
    memcheck(c);
    c->magic = read32(f);
    c->minor_version = read16(f);
    c->major_version = read16(f);
    c->constant_pool_count = read16(f);
    c->constant_pool = malloc(sizeof(void*) * (c->constant_pool_count - 1));
    for(int i = 0; i < (c->constant_pool_count - 1); i++){
	c->constant_pool[i] = read_constant(i, f);
//	print_constant(c->constant_pool[i], stderr);
    }
    c->access_flags = read16(f);
    c->this_class = read16(f);
    c->super_class = read16(f);
    c->interfaces_count = read16(f);
    if(c->interfaces_count > 0){
	c->interfaces = malloc(sizeof(short) * c->interfaces_count);
	memcheck(c->interfaces);
	for(int i = 0; i < (c->interfaces_count); i++){
	    c->interfaces[i] = read16(f);
	}
    }
    c->fields_count = read16(f);
    if(c->fields_count > 0){
	c->fields = malloc(sizeof(void*) * c->fields_count);
	memcheck(c->fields);
	//have to read in the fields
	for(int i = 0; i < (c->fields_count); i++){
	    c->fields[i] = read_field(f);
	}
    } else
	c->fields = NULL;
    c->methods_count = read16(f);
    if(c->methods_count > 0){
	c->methods = malloc(sizeof(void*) * c->methods_count);
	memcheck(c->methods);
	for(int i = 0; i < (c->methods_count); i++){
	    c->methods[i] = read_method(c, f);
	}
    } else 
	c->methods = NULL;
    c->attributes_count = read16(f);
    if(c->attributes_count > 0){
	c->attributes = malloc(sizeof(void*) * c->attributes_count);
	memcheck(c->attributes);
	for(int i = 0; i < c->attributes_count; i++){
	    c->attributes[i] = read_attribute(f);
	}
    } else 
	c->attributes = NULL;

    int last = getc(f);
    assert(last == EOF);
    return c;
}
static int is_supply_enabled(struct regulator_dev *rdev)
{
	const struct supply_info *info;
	struct tps6524x *hw;

	hw	= rdev_get_drvdata(rdev);
	info	= &supply_info[rdev_get_id(rdev)];

	return read_field(hw, &info->enable);
}
Beispiel #12
0
struct spwd *fgetspent(FILE *file) {
	int res;
	char *buf = spwd_buf;
	size_t buf_len = SHADOW_NAME_BUF_LEN + SHADOW_PSWD_BUF_LEN;

	if (0 != (res = read_field(file, &buf, &buf_len, &spwd.sp_namp, ':'))) {
		return NULL;
	}

	if (0 != (res = read_field(file, &buf, &buf_len, &spwd.sp_pwdp, ':'))) {
		return NULL;
	}

	if (0 != (res = read_int_field(file, "%ld", &spwd.sp_lstchg, ':'))) {
		return NULL;
	}

	if (0 != (res = read_int_field(file, "%ld", &spwd.sp_min, ':'))) {
		return NULL;
	}

	if (0 != (res = read_int_field(file, "%ld", &spwd.sp_max, ':'))) {
		return NULL;
	}

	if (0 != (res = read_int_field(file, "%ld", &spwd.sp_warn, ':'))) {
		return NULL;
	}

	if (0 != (res = read_int_field(file, "%ld", &spwd.sp_inact, ':'))) {
		return NULL;
	}

	if (0 != (res = read_int_field(file, "%ld", &spwd.sp_expire, ':'))) {
		return NULL;
	}

	if (0 != (res = read_int_field(file, "%ld", &spwd.sp_flag, '\n'))) {
		return NULL;
	}

	return &spwd;
}
    csv_reader_iterator & operator++()
    {
        switch (status) {
            case PENULTIMATE:
                status = END;
                return *this;
            case END:
                throw new std::logic_error("Trying to advance invalid iterator");
            case VALID: ;
        }

        wchar_t buffer[BUFFER_SIZE];
        int buffer_size = -1;
        int i = 0;

        load_saved_buffer(buffer, buffer_size);
        current_line.fields.clear();
        skip_newlines(buffer, buffer_size, i);
        if (i == buffer_size && input_stream_p->eof()) {
            status = END;
            return *this;
        }

        // add a column of the csv line in each iteration
        while (true) {
            field_buffer_p->str(L"");
            read_field(buffer, buffer_size, i);

            if (i == buffer_size && input_stream_p->eof()) {
                break;
            }

            fill_buffer_if_empty(buffer, buffer_size, i);

            // end of csv line, were done :)
            if (L'\n' == buffer[i]) {
                break;
            }
            // another column, just continue the loop
            if (delimiter == buffer[i]) {
                i += 1;
                continue;
            }
            throw std::logic_error("Unexpected character encountered");
        }

        skip_newlines(buffer, buffer_size, i);
        if (input_stream_p->eof() && i == buffer_size) {
            input_stream_p = wistream_pt();
            status = PENULTIMATE;
        }
        save_buffer(buffer, buffer_size, i);

        return *this;
    }
Beispiel #14
0
static ContextAddress find_module(Context * ctx, ELF_File * exe_file, ELF_File * module,
                                  ContextAddress r_map, ContextAddress r_brk) {
#if ENABLE_Symbols
    Symbol * sym = NULL;
    int i = 0, n = 0;
    Symbol ** children = NULL;
    ContextAddress link = r_map;
    Symbol * sym_l_addr = NULL;
    Symbol * sym_l_next = NULL;
    Symbol * sym_l_tls_modid = NULL;
    if (find_symbol_by_name(ctx, STACK_NO_FRAME, r_brk, "link_map", &sym) < 0)
        str_exception(errno, "Cannot find loader symbol: link_map");
    if (get_symbol_children(sym, &children, &n) < 0) exception(errno);
    for (i = 0; i < n; i++) {
        char * name = NULL;
        if (get_symbol_name(children[i], &name) < 0) exception(errno);
        if (name == NULL) continue;
        if (strcmp(name, "l_map_start") == 0) sym_l_addr = children[i];
        else if (strcmp(name, "l_next") == 0) sym_l_next = children[i];
        else if (strcmp(name, "l_tls_modid") == 0) sym_l_tls_modid = children[i];
    }
    if (sym_l_addr == NULL || sym_l_next == NULL || sym_l_tls_modid == NULL)
        str_exception(ERR_OTHER, "Invalid 'link_map' fields");
    while (link != 0) {
        ContextAddress l_tls_modid = 0;
        read_field(ctx, sym_l_tls_modid, link, &l_tls_modid);
        if (l_tls_modid != 0) {
            ContextAddress l_addr = 0;
            ELF_File * link_file = NULL;
            read_field(ctx, sym_l_addr, link, &l_addr);
            elf_map_to_link_time_address(ctx, l_addr, 0, &link_file, NULL);
            if (link_file != NULL) {
                if (link_file == module) return l_tls_modid;
                if (get_dwarf_file(link_file) == module) return l_tls_modid;
            }
        }
        read_field(ctx, sym_l_next, link, &link);
    }
#endif
    return 0;
}
Beispiel #15
0
int get_defpswd(struct passwd *passwd, char *buf, size_t buf_len) {
	FILE *passwdf;
	char *temp;
	int res = 0;

	if (NULL == (passwdf = fopen(ADDUSER_FILE, "r"))) {
		return errno;
	}

	while (read_field(passwdf, &buf, &buf_len, &temp, '=') != EOF) {
		if(0 == strcmp(temp, "GROUP")) {
			if (0 != read_int_field(passwdf, "%hd", &passwd->pw_gid, '\n')) {
				res = -1;
				goto out;
			}
			continue;
		}

		if(0 == strcmp(temp, "HOME")) {
			if (0 != read_field(passwdf, &buf, &buf_len,
					&passwd->pw_dir, '\n')) {
				res = -1;
				goto out;
			}
			continue;
		}

		if(0 == strcmp(temp, "SHELL")) {
			if (0 != read_field(passwdf, &buf, &buf_len,
					&passwd->pw_shell, '\n')) {
				res = -1;
				goto out;
			}
			continue;
		}
	}

out:
	fclose(passwdf);
	return res;
}
Beispiel #16
0
unsigned read_field_num(char *base, char *name)
{
	unsigned num;
	char *val = read_field(base, name);
	int n = sscanf(val, "%u", &num);
	free(val);
	if (n != 1) { 
		Eprintf("Cannot parse number in sysfs field %s/%s\n", base,name);
		return 0;
	}
	return num;
}
Beispiel #17
0
unsigned read_field_map(char *base, char *name, struct map *map)
{
	char *val = read_field(base, name);

	for (; map->name; map++) {
		if (!strcmp(val, map->name))
			break;
	}
	free(val);
	if (map->name)
		return map->value;
	Eprintf("sysfs field %s/%s has unknown string value `%s'\n", base, name, val);
	return -1;
}
Beispiel #18
0
void CSVReader::read_line(const std::string& s, int l_idx){
	std::vector<std::string> fields;
	boost::split( fields, s, boost::is_any_of(mDivider));
	int f_idx=0;
	fields.erase(remove(fields.begin(), fields.end(), ""),fields.end());
	int numfields=fields.size();

	foreach(std::string& s, fields){
		boost::trim(s);
		if(l_idx==0 && mReadHeader){
			read_header(s, l_idx, f_idx, numfields);
		}else{
			read_field(s, l_idx, f_idx, numfields);
		}
		f_idx++;
	}
Beispiel #19
0
void main(int argc, char *argv[]) {
    void error_print();

    int i,j;
    double gain, i_sat, base, ss, intensity, dx,dx2;
    long ik1;



    /* Processing the command line argument  */

    if (argc != 4) {
        error_print(argv[0]);
        exit(1);
    }
    /* reading the data from a command line */
    sscanf(argv[1],"%le", &gain);
    sscanf(argv[2],"%le",&base);
    sscanf(argv[3],"%le",&i_sat);

    read_field();
    dx =field.size/(field.number);
    dx2 = dx*dx;


    ik1=0;
    for (i=1; i<=field.number ; i++) {
        for (j=1; j<=field.number ; j++) {
            intensity=(field.real[ik1]*field.real[ik1]+\
                       field.imaginary[ik1]*field.imaginary[ik1]);


            ss=exp(base*(gain/(1.+(intensity/i_sat))));

            field.real[ik1] *= ss;
            field.imaginary[ik1] *= ss;
            ik1++;
        }

    }
    write_field();


}
Beispiel #20
0
bool tpafile::load(pal::string_t path)
{
	// Check if the file exists, if not, there is nothing to add
	if (!pal::file_exists(path))
	{
		return true;
	}

	// Open the file
	pal::ifstream_t file(path);
	if (!file.good())
	{
		// Failed to open the file!
		return false;
	}

	// Read lines from the file
	while (true)
	{
		std::string line;
		std::getline(file, line);
		auto line_palstr = pal::to_palstring(line);
		if (file.eof())
		{
			break;
		}

		auto offset = 0;

		tpaentry_t entry;

		// Read fields
		if (!(read_field(line_palstr, offset, entry.library_type))) return false;
		if (!(read_field(line_palstr, offset, entry.library_name))) return false;
		if (!(read_field(line_palstr, offset, entry.library_version))) return false;
		if (!(read_field(line_palstr, offset, entry.library_hash))) return false;
		if (!(read_field(line_palstr, offset, entry.asset_type))) return false;
		if (!(read_field(line_palstr, offset, entry.asset_name))) return false;
		if (!(read_field(line_palstr, offset, entry.relative_path))) return false;

		m_entries.push_back(entry);
	}

	return true;
}
Beispiel #21
0
Datei: load.c Projekt: gplv2/rlib
struct rlib_report_lines * read_line(gchar **ptr) {
	struct rlib_report_lines *rl = g_malloc(sizeof(struct rlib_report_lines));
	gint32 *type;
	gpointer pointer = NULL;
	struct rlib_element *current;
	
	rl->xml_bgcolor.xml = (xmlChar *)read_xml_str(ptr);
	rl->xml_color.xml = (xmlChar *)read_xml_str(ptr);
	rl->xml_font_size.xml = (xmlChar *)read_xml_str(ptr);
	rl->xml_suppress.xml = (xmlChar *)read_xml_str(ptr);
	rl->e = NULL;

	type = (gint32 *)*ptr;
	if(*type == RLIB_FILE_LINE) {
		*ptr += sizeof(gint32);
		while(1) {
			type = (gint32 *)*ptr;
			if(*type == RLIB_FILE_LINE)
				break;
			if(*type == RLIB_ELEMENT_FIELD)
				pointer = read_field(ptr);
			if(*type == RLIB_ELEMENT_LITERAL)
				pointer = read_text(ptr);
			if(*type == RLIB_ELEMENT_FIELD || *type == RLIB_ELEMENT_LITERAL) {
				if(rl->e == NULL) {
					rl->e = g_malloc(sizeof(struct rlib_element));
					current = rl->e;
				} else {
					struct rlib_element *e;
					for(e=rl->e;e->next != NULL;e=e->next);
					e->next = g_malloc(sizeof(struct rlib_element));
					current = e->next;
				}
				current->data = pointer;
				current->type = *type;
				current->next = NULL;
			}
		}
		*ptr += sizeof(gint32);
	}
	return rl;
}
static int get_voltage_sel(struct regulator_dev *rdev)
{
	const struct supply_info *info;
	struct tps6524x *hw;
	int ret;

	hw	= rdev_get_drvdata(rdev);
	info	= &supply_info[rdev_get_id(rdev)];

	if (info->flags & FIXED_VOLTAGE)
		return info->fixed_voltage;

	ret = read_field(hw, &info->voltage);
	if (ret < 0)
		return ret;
	if (WARN_ON(ret >= info->n_voltages))
		return -EIO;

	return ret;
}
static int get_voltage_sel(struct regulator_dev *rdev)
{
	const struct supply_info *info;
	struct tps6524x *hw;
	int ret;

	hw	= rdev_get_drvdata(rdev);
	info	= &supply_info[rdev_get_id(rdev)];

	if (rdev->desc->n_voltages == 1)
		return 0;

	ret = read_field(hw, &info->voltage);
	if (ret < 0)
		return ret;
	if (WARN_ON(ret >= info->n_voltages))
		return -EIO;

	return ret;
}
static int get_current_limit(struct regulator_dev *rdev)
{
	const struct supply_info *info;
	struct tps6524x *hw;
	int ret;

	hw	= rdev_get_drvdata(rdev);
	info	= &supply_info[rdev_get_id(rdev)];

	if (info->flags & FIXED_ILIMSEL)
		return info->fixed_ilimsel;

	ret = read_field(hw, &info->ilimsel);
	if (ret < 0)
		return ret;
	if (WARN_ON(ret >= info->n_ilimsels))
		return -EIO;

	return info->ilimsels[ret];
}
Beispiel #25
0
//-----------------------------------------------------------------------------
bool datareader_c::read( solution_ptr& solution, std::string scenario_id, xml_element_ptr top ) {
  if( !buffer_line() ) return false;
  //print_cells();

  solution = solution_ptr( new solution_c( solution_c::MODEL ) );
  solution->scenario_id = scenario_id;
  component_ptr component = boost::dynamic_pointer_cast<solution_c>( solution );

  xml_element_ptr element;
  std::string key, tag;

  for( unsigned i = 0; i < top->elements(); i++ ) {
    element = top->element( i );
    tag = element->get_name();
    if( tag == "Field" ) {
      read_field( component, element );
    } else if( tag == "Model" ) {
      read_model( component, element );
    }
  }

  return true;
}
Beispiel #26
0
//-----------------------------------------------------------------------------
bool datareader_c::read( trial_ptr& trial, std::string scenario_id, xml_element_ptr top ) {
  if( !buffer_line() ) return false;
  //print_cells();

  trial = trial_ptr( new trial_c() );
  trial->scenario_id = scenario_id;
  component_ptr component = boost::dynamic_pointer_cast<trial_c>( trial );

  xml_element_ptr element;
  std::string key, name;

  for( unsigned i = 0; i < top->elements(); i++ ) {
    element = top->element( i );
    name = element->get_name();
    if( name == "Field" ) {
      read_field( component, element );
    } else if( name == "Model" ) {
      read_model( component, element );
    }
  }

  return true;
}
Beispiel #27
0
static struct csv *csv_open_file(TABDCA *dca, int mode)
{     /* open csv data file */
      struct csv *csv;
      /* create control structure */
      csv = xmalloc(sizeof(struct csv));
      csv->mode = mode;
      csv->fname = NULL;
      csv->fp = NULL;
      if (setjmp(csv->jump)) goto fail;
      csv->count = 0;
      csv->c = '\n';
      csv->what = 0;
      csv->field[0] = '\0';
      csv->nf = 0;
      /* try to open the csv data file */
      if (mpl_tab_num_args(dca) < 2)
      {  xprintf("csv_driver: file name not specified\n");
         longjmp(csv->jump, 0);
      }
      csv->fname = xmalloc(strlen(mpl_tab_get_arg(dca, 2))+1);
      strcpy(csv->fname, mpl_tab_get_arg(dca, 2));
      if (mode == 'R')
      {  /* open the file for reading */
         int k;
         csv->fp = fopen(csv->fname, "r");
         if (csv->fp == NULL)
         {  xprintf("csv_driver: unable to open %s - %s\n",
               csv->fname, strerror(errno));
            longjmp(csv->jump, 0);
         }
#if 1 /* 01/VI-2010 */
         csv->nskip = 0;
#endif
         /* skip fake new-line */
         read_field(csv);
         xassert(csv->what == CSV_EOR);
         /* read field names */
         xassert(csv->nf == 0);
         for (;;)
         {  read_field(csv);
            if (csv->what == CSV_EOR)
               break;
            if (csv->what != CSV_STR)
            {  xprintf("%s:%d: invalid field name\n", csv->fname,
                  csv->count);
               longjmp(csv->jump, 0);
            }
            if (csv->nf == CSV_FIELD_MAX)
            {  xprintf("%s:%d: too many fields\n", csv->fname,
                  csv->count);
               longjmp(csv->jump, 0);
            }
            csv->nf++;
            /* find corresponding field in the table statement */
            for (k = mpl_tab_num_flds(dca); k >= 1; k--)
            {  if (strcmp(mpl_tab_get_name(dca, k), csv->field) == 0)
                  break;
            }
            csv->ref[csv->nf] = k;
         }
         /* find dummy RECNO field in the table statement */
         for (k = mpl_tab_num_flds(dca); k >= 1; k--)
            if (strcmp(mpl_tab_get_name(dca, k), "RECNO") == 0) break;
         csv->ref[0] = k;
      }
      else if (mode == 'W')
      {  /* open the file for writing */
         int k, nf;
         csv->fp = fopen(csv->fname, "w");
         if (csv->fp == NULL)
         {  xprintf("csv_driver: unable to create %s - %s\n",
               csv->fname, strerror(errno));
            longjmp(csv->jump, 0);
         }
         /* write field names */
         nf = mpl_tab_num_flds(dca);
         for (k = 1; k <= nf; k++)
            fprintf(csv->fp, "%s%c", mpl_tab_get_name(dca, k),
               k < nf ? ',' : '\n');
         csv->count++;
      }
      else
         xassert(mode != mode);
      /* the file has been open */
      return csv;
fail: /* the file cannot be open */
      if (csv->fname != NULL) xfree(csv->fname);
      if (csv->fp != NULL) fclose(csv->fp);
      xfree(csv);
      return NULL;
}
Beispiel #28
0
static int check_account(const char *service
			 , const char *tty, const char *user)
{
     int from=0,to=0,fd=-1;
     char *buffer=NULL;
     int count=0;
     TIME here_and_now;
     int retval=PAM_SUCCESS;

     here_and_now = time_now();                     /* find current time */
     do {
	  boolean good=TRUE,intime;

	  /* here we get the service name field */

	  fd = read_field(fd,&buffer,&from,&to);

	  if (!buffer || !buffer[0]) {
	       /* empty line .. ? */
	       continue;
	  }
	  ++count;

	  good = logic_field(service, buffer, count, is_same);
	  D(("with service: %s", good ? "passes":"fails" ));

	  /* here we get the terminal name field */

	  fd = read_field(fd,&buffer,&from,&to);
	  if (!buffer || !buffer[0]) {
	       _log_err(PAM_TIME_CONF "; no tty entry #%d", count);
	       continue;
	  }
	  good &= logic_field(tty, buffer, count, is_same);
	  D(("with tty: %s", good ? "passes":"fails" ));

	  /* here we get the username field */

	  fd = read_field(fd,&buffer,&from,&to);
	  if (!buffer || !buffer[0]) {
	       _log_err(PAM_TIME_CONF "; no user entry #%d", count);
	       continue;
	  }
	  good &= logic_field(user, buffer, count, is_same);
	  D(("with user: %s", good ? "passes":"fails" ));

	  /* here we get the time field */

	  fd = read_field(fd,&buffer,&from,&to);
	  if (!buffer || !buffer[0]) {
	       _log_err(PAM_TIME_CONF "; no time entry #%d", count);
	       continue;
	  }

	  intime = logic_field(&here_and_now, buffer, count, check_time);
	  D(("with time: %s", intime ? "passes":"fails" ));

	  fd = read_field(fd,&buffer,&from,&to);
	  if (buffer && buffer[0]) {
	       _log_err(PAM_TIME_CONF "; poorly terminated rule #%d", count);
	       continue;
	  }

	  if (good && !intime) {
	       /*
		* for security parse whole file..  also need to ensure
		* that the buffer is free()'d and the file is closed.
		*/
	       retval = PAM_PERM_DENIED;
	  } else {
	       D(("rule passed"));
	  }
     } while (buffer);

     return retval;
}
Beispiel #29
0
int bit_file::load(const char* name)
{
    FILE *f;
    int rc = -1;
    u8 field;

    if (data || length)
        // Call clear() first
        return -1;
    
    f = fopen(name, "rb");
    if (f == NULL)
	{
		msgf(STR_UNABLE_TO_OPEN_FILE);
	    return -1;
	}
	
    // Skip header
    fseek(f, 13, SEEK_SET);
    
    // Read fields
    while(!feof(f))
    {
        if (fread(&field, 1, 1, f) != 1)
            goto cleanup;
        
        switch (field)
        {
        case 'a': // NCD File Name
        case 'b': // Part Name
        case 'c': // Creation Date
        case 'd': // Creation Time
            if (read_field(f, NULL, 0) != 0)
			{
				msgf(STR_INVALID_FILE_FORMAT);
				goto cleanup;
			}
            break;

        case 'e': // Data
            if (alloc_read_data(f) != 0)
			{
				msgf(STR_INVALID_FILE_FORMAT);
				goto cleanup;
			}
            rc = 0;
            goto cleanup;
            break;

        default:
			msgf(STR_INVALID_FILE_FORMAT);
            goto cleanup;
        }
    }

cleanup:

	if (rc)
		clear();

    if (f)
        fclose(f);

    return rc;
}
Beispiel #30
0
int main(int argc, char **argv)
{
  if (argc < 3) {
    fprintf(stderr, "Usage: {xml file} {output dir}\n");
    exit(1);
  }
  
  fid = readFile("", argv[1]);

  fid_p = fid;
  
  char *reference_field = read_field("reference");
  
  char *refdoc = readFile("p:/pan10/", reference_field);
  int refdoc_len = strlen(refdoc);
  
  plagsrc **refdoc_src = malloc(refdoc_len * sizeof(plagsrc *));
  
  for (int i = 0; i < refdoc_len; i++) {
    refdoc_src[i] = NULL;
  }
  
  for (;;) {
   
    char *Fthis_offset = read_field("this_offset");
    if (Fthis_offset == NULL) break;
    char *Fthis_length = read_field("this_length");
    char *Fsource_reference = read_field("source_reference");
    char *Fsource_offset = read_field("source_offset");
    char *Fsource_length = read_field("source_length");
        
    plagsrc *P = malloc(sizeof(plagsrc));
    P->begin = atoi(Fthis_offset);
    P->length = atoi(Fthis_length);
    P->src_begin = atoi(Fsource_offset);
    P->src_length = atoi(Fsource_length);
    strcpy(P->docname, Fsource_reference);
    P->source_num = sources_n;
    
    const char *hex = "0123456789abcdef";
    P->col[0] = hex[((rand()) % 10)+5];
    P->col[1] = hex[((rand()) % 10)+5];
    P->col[2] = hex[((rand()) % 10)+5];
    P->col[3] = '\0';
        
    free(Fthis_offset);
    free(Fthis_length);
    free(Fsource_reference);
    free(Fsource_offset);
    free(Fsource_length);
        
    for (int i = P->begin; i < P->begin + P->length; i++) {
      refdoc_src[i] = P;
    }
        
    if (sources_n >= MAX_SOURCES) {
      fprintf(stderr, "TOO MANY SOURCES\n");
      exit(1);
    }
    sources[sources_n++] = P;
    
    char *fd_before = readFile_sub("p:/pan10/", P->docname, 0, P->src_begin);
    char *fd_mid = readFile_sub("p:/pan10/", P->docname, P->src_begin, P->src_begin + P->src_length);
    char *fd_after = readFile_sub("p:/pan10/", P->docname, P->src_begin + P->src_length, INT_MAX);
    char fdname[1024];
        
    sprintf(fdname, "%s/%d.html", argv[2], P->source_num);
    FILE *fp = fopen(fdname, "w");
    fprintf(fp, "<html>");
    fprintf(fp, "<head><title>%s</title></head>", P->docname);
    fprintf(fp, "<body>");
    fprintf(fp, "<pre>");
    //fprintf(stderr, "writing %d %d %d\n", strlen(fd), P->src_begin, P->src_length);
    fprintf(fp, "<span>%s</span>", fd_before);
    fprintf(fp, "<a id=\"entry\">");
    fprintf(fp, "<span style=\"background-color:#%s;\">%s</span>", P->col, fd_mid);     
    fprintf(fp, "<span>%s</span>", fd_after);
    fprintf(fp, "</pre>");
    fprintf(fp, "</body>");
    fprintf(fp, "</html>");
    fclose(fp);
    
    free(fd_before);
    free(fd_mid);
    free(fd_after);
  }
  
  
  char fdname[1024];
      
  sprintf(fdname, "%s/index.html", argv[2]);
  FILE *fp = fopen(fdname, "w");
  plagsrc *curplg = NULL;
  fprintf(fp, "<html>");
  fprintf(fp, "<body>");
  fprintf(fp, "<pre>");
  fprintf(fp, "<span>");
  for (int i = 0; i < refdoc_len; i++) {
    if (curplg != refdoc_src[i]) {
      if (curplg != NULL) fprintf(fp, "</a>");
      fprintf(fp, "</span>");
      
      curplg = refdoc_src[i];
      if (curplg) {
        fprintf(fp, "<span style=\"background-color:#%s;\">", curplg->col);
        fprintf(fp, "<a href=\"%d.html#entry\">", curplg->source_num);
      } else {
        fprintf(fp, "<span>");
      }
    }
    fputc(refdoc[i], fp);
  }
  if (curplg != NULL) fprintf(fp, "</a>");
  fprintf(fp, "</span>");
  fprintf(fp, "</pre>");
  fprintf(fp, "</body>");
  fprintf(fp, "</html>");
  fclose(fp);
    
  return 0;
}