Пример #1
0
/**
 *  iowarrior_read
 */
static ssize_t iowarrior_read(struct file *file, char __user *buffer,
			      size_t count, loff_t *ppos)
{
	struct iowarrior *dev;
	int read_idx;
	int offset;

	dev = file->private_data;

	/* verify that the device wasn't unplugged */
	if (dev == NULL || !dev->present)
		return -ENODEV;

	dbg("%s - minor %d, count = %zd", __func__, dev->minor, count);

	/* read count must be packet size (+ time stamp) */
	if ((count != dev->report_size)
	    && (count != (dev->report_size + 1)))
		return -EINVAL;

	/* repeat until no buffer overrun in callback handler occur */
	do {
		atomic_set(&dev->overflow_flag, 0);
		if ((read_idx = read_index(dev)) == -1) {
			/* queue emty */
			if (file->f_flags & O_NONBLOCK)
				return -EAGAIN;
			else {
				//next line will return when there is either new data, or the device is unplugged
				int r = wait_event_interruptible(dev->read_wait,
								 (!dev->present
								  || (read_idx =
								      read_index
								      (dev)) !=
								  -1));
				if (r) {
					//we were interrupted by a signal
					return -ERESTART;
				}
				if (!dev->present) {
					//The device was unplugged
					return -ENODEV;
				}
				if (read_idx == -1) {
					// Can this happen ???
					return 0;
				}
			}
		}

		offset = read_idx * (dev->report_size + 1);
		if (copy_to_user(buffer, dev->read_queue + offset, count)) {
			return -EFAULT;
		}
	} while (atomic_read(&dev->overflow_flag));

	read_idx = ++read_idx == MAX_INTERRUPT_BUFFER ? 0 : read_idx;
	atomic_set(&dev->read_idx, read_idx);
	return count;
}
Пример #2
0
static ssize_t iowarrior_read(struct file *file, char __user *buffer,
			      size_t count, loff_t *ppos)
{
	struct iowarrior *dev;
	int read_idx;
	int offset;

	dev = file->private_data;

	/*                                         */
	if (dev == NULL || !dev->present)
		return -ENODEV;

	dbg("%s - minor %d, count = %zd", __func__, dev->minor, count);

	/*                                               */
	if ((count != dev->report_size)
	    && (count != (dev->report_size + 1)))
		return -EINVAL;

	/*                                                          */
	do {
		atomic_set(&dev->overflow_flag, 0);
		if ((read_idx = read_index(dev)) == -1) {
			/*            */
			if (file->f_flags & O_NONBLOCK)
				return -EAGAIN;
			else {
				//                                                                               
				int r = wait_event_interruptible(dev->read_wait,
								 (!dev->present
								  || (read_idx =
								      read_index
								      (dev)) !=
								  -1));
				if (r) {
					//                               
					return -ERESTART;
				}
				if (!dev->present) {
					//                        
					return -ENODEV;
				}
				if (read_idx == -1) {
					//                    
					return 0;
				}
			}
		}

		offset = read_idx * (dev->report_size + 1);
		if (copy_to_user(buffer, dev->read_queue + offset, count)) {
			return -EFAULT;
		}
	} while (atomic_read(&dev->overflow_flag));

	read_idx = ++read_idx == MAX_INTERRUPT_BUFFER ? 0 : read_idx;
	atomic_set(&dev->read_idx, read_idx);
	return count;
}
Пример #3
0
bool CommandRenumber::run() {
    if (!m_index_directory.empty()) {
        m_vout << "Reading index files...\n";
        read_index(osmium::item_type::node, "nodes");
        read_index(osmium::item_type::way, "ways");
        read_index(osmium::item_type::relation, "relations");

        m_vout << "  Nodes     index contains " << index(osmium::item_type::node).size()     << " items\n";
        m_vout << "  Ways      index contains " << index(osmium::item_type::way).size()      << " items\n";
        m_vout << "  Relations index contains " << index(osmium::item_type::relation).size() << " items\n";
    }

    m_vout << "First pass through input file (reading relations)...\n";
    osmium::io::Reader reader_pass1(m_input_file, osmium::osm_entity_bits::relation);

    osmium::io::Header header = reader_pass1.header();
    header.set("generator", m_generator);
    header.set("xml_josm_upload", "false");
    for (const auto& h : m_output_headers) {
        header.set(h);
    }
    osmium::io::Writer writer(m_output_file, header, m_output_overwrite);

    osmium::io::InputIterator<osmium::io::Reader, osmium::Relation> it { reader_pass1 };
    osmium::io::InputIterator<osmium::io::Reader, osmium::Relation> end {};

    for (; it != end; ++it) {
        lookup(osmium::item_type::relation, it->id());
    }

    reader_pass1.close();

    m_vout << "Second pass through input file...\n";
    osmium::io::Reader reader_pass2(m_input_file);
    while (osmium::memory::Buffer buffer = reader_pass2.read()) {
        renumber(buffer);
        writer(std::move(buffer));
    }
    reader_pass2.close();

    writer.close();

    if (!m_index_directory.empty()) {
        m_vout << "Writing index files...\n";
        write_index(osmium::item_type::node, "nodes");
        write_index(osmium::item_type::way, "ways");
        write_index(osmium::item_type::relation, "relations");
    }

    m_vout << "Done.\n";

    return true;
}
Пример #4
0
static void read_field(FILE *f, const save_field_t *field, void *base)
{
    void *p = (byte *)base + field->ofs;
    int i;

    switch (field->type) {
    case F_BYTE:
        read_data(p, field->size, f);
        break;
    case F_SHORT:
        for (i = 0; i < field->size; i++) {
            ((short *)p)[i] = read_short(f);
        }
        break;
    case F_INT:
        for (i = 0; i < field->size; i++) {
            ((int *)p)[i] = read_int(f);
        }
        break;
    case F_FLOAT:
        for (i = 0; i < field->size; i++) {
            ((float *)p)[i] = read_float(f);
        }
        break;
    case F_VECTOR:
        read_vector(f, (vec_t *)p);
        break;

    case F_LSTRING:
        *(char **)p = read_string(f);
        break;
    case F_ZSTRING:
        read_zstring(f, (char *)p, field->size);
        break;

    case F_EDICT:
        *(edict_t **)p = read_index(f, sizeof(edict_t), g_edicts, game.maxentities - 1);
        break;
    case F_CLIENT:
        *(gclient_t **)p = read_index(f, sizeof(gclient_t), game.clients, game.maxclients - 1);
        break;
    case F_ITEM:
        *(gitem_t **)p = read_index(f, sizeof(gitem_t), itemlist, game.num_items - 1);
        break;

    case F_POINTER:
        *(void **)p = read_pointer(f, field->size);
        break;

    default:
        gi.error("%s: unknown field type", __func__);
    }
}
Пример #5
0
polygon_connection_attribute_array *read_connection_attribute_array(char *filename,short print) {
	/*!
	 *
	 * \author Emanuele Cordano
	 * \author May 2008
	 *
	 *\param (char*) - name of filename
	 *\param (short) -
	 *
	 *\brief It creates and reads a polygonvector from the following options:
	 */
	polygon_connection_attribute_array *pca;
	FILE *fd;
	long j,n_po;

	fd=t_fopen(filename,"r");
	n_po=(long)read_index(fd,no_PRINT);
	pca=new_connection_attributes(n_po);

	for (j=pca->nl;j<=pca->nh;j++) {
		pca->element[j]=read_connections(fd,print);

	//	if (pca->element[j]->index!=j) printf ("Error in read_connection_attributes (polygon %ld) inconstancy: %ld %ld \n",j,j,pca->element[j]->index);
	}

	t_fclose(fd);
	if (print==1) printf("Function read_connection_attributes (number of polygons %ld) was successfully executed!!",pca->nh);

	return pca;

}
Пример #6
0
int read_index_preload(struct index_state *index, const char **pathspec)
{
	int retval = read_index(index);

	preload_index(index, pathspec);
	return retval;
}
Пример #7
0
LONGMATRIX_VECTOR *read_fine_indices(char *filename,short print) {
	/*!
	 * \author Emanuele Cordano
	 * date May 2009
	 *
	 * \param (char*) - name of filename
	 *\param (short) -
	 */
	LONGMATRIX_VECTOR *lm;
	FILE *fd;
	long j,n_po;
	fd=t_fopen(filename,"r");

	n_po=(long)read_index(fd,no_PRINT);
	lm=new_longmatrix_vector(n_po);

	for (j=lm->nl;j<=lm->nh;j++) {
		if (print==1) printf("Function read_fine_indices element %ld of %ld is being defined \n",j,lm->nh);
		lm->element[j]=read_longmatrix(fd,"a",no_PRINT);
		if (print==1) printf("Function read_fine_indices element %ld of %ld is read [%ld,%ld] f.e. %ld \n",j,lm->nh,lm->element[j]->nrh,lm->element[j]->nrh,lm->element[j]->element[1][1]);
		if (!lm->element[j]) t_error("lm->element[j] in read_fine_indices was not defined");

	//		if (polygons->element[j]->index!=j) printf ("Error in read_polygonvector (polygon %ld) inconstancy: %ld %ld \n",j,j,polygons->element[j]->index);
	}

	t_fclose(fd);

	if (print==1) printf("Function read_fine_indices was successfully executed! \n");

	return lm;
}
Пример #8
0
void globalbsa::init()
{

  file_size = utils::size(global_bsa_stream);

  read_number_of_index_entries();
  read_index();
}
Пример #9
0
 T read()
 {
     T result;
     assert(0 < mSize);
     const int16_t index = read_index(0);
     result = mBuffer[index];
     mSize--;
     return result;
 }
Пример #10
0
AST_expr* readASTExpr(BufferedReader* reader) {
    uint8_t type = reader->readByte();
    if (VERBOSITY("parsing") >= 2)
        printf("type = %d\n", type);
    if (type == 0)
        return NULL;

    uint8_t checkbyte = reader->readByte();
    assert(checkbyte == 0xae);

    switch (type) {
        case AST_TYPE::Attribute:
            return read_attribute(reader);
        case AST_TYPE::BinOp:
            return read_binop(reader);
        case AST_TYPE::BoolOp:
            return read_boolop(reader);
        case AST_TYPE::Call:
            return read_call(reader);
        case AST_TYPE::Compare:
            return read_compare(reader);
        case AST_TYPE::Dict:
            return read_dict(reader);
        case AST_TYPE::DictComp:
            return read_dictcomp(reader);
        case AST_TYPE::IfExp:
            return read_ifexp(reader);
        case AST_TYPE::Index:
            return read_index(reader);
        case AST_TYPE::Lambda:
            return read_lambda(reader);
        case AST_TYPE::List:
            return read_list(reader);
        case AST_TYPE::ListComp:
            return read_listcomp(reader);
        case AST_TYPE::Name:
            return read_name(reader);
        case AST_TYPE::Num:
            return read_num(reader);
        case AST_TYPE::Repr:
            return read_repr(reader);
        case AST_TYPE::Slice:
            return read_slice(reader);
        case AST_TYPE::Str:
            return read_str(reader);
        case AST_TYPE::Subscript:
            return read_subscript(reader);
        case AST_TYPE::Tuple:
            return read_tuple(reader);
        case AST_TYPE::UnaryOp:
            return read_unaryop(reader);
        default:
            fprintf(stderr, "Unknown expr node type (parser.cpp:" STRINGIFY(__LINE__) "): %d\n", type);
            abort();
            break;
    }
}
Пример #11
0
LINEVECTOR *read_linevector (char *filename, short print) {
	/*!
	 * \author Emanuele Cordano
	 * \date May 2009
	 *
	 *\param filename (char *) - name of the file where to read line_information
	 *\param print (short)
	 *
	 *
	 *\brief It creates and reads a linevector from the following options:
	 *\brief index{1}
	 *  FILE CONTAINIG NECESSARY INFORMATION FOR LINES
			x    y    line_index    lenght2d    x_P1    y_P1    x_P2   y_P2

			1: double matrix lines information  {55550,8}
	 */

	FILE *fd;
	DOUBLEMATRIX *ldata;
	LINEVECTOR *lines;
	POINT *P1,*P2;
	long index,j,ja;

	int ix=1; /*! x coordinate of the middle point */
	int iy=ix+1; /*! y coordinate of the midddele point */
	int iline_index=iy+1; /*! iline_index of the line */
	int ilength2d=iline_index+1; /*! lenght of the line */
	int iP1_x=ilength2d+1; /*! P1 x coordinate */
	int iP1_y=iP1_x+1; /*! P1 y coordinate */
	int iP2_x=iP1_y+1; /*! P2 x coordinate */
	int iP2_y=iP2_x+1; /*! P2 y coordinate */
	int indata=iP2_y; /* number of data */

	fd=t_fopen(filename,"r");
	index=(long)read_index(fd,no_PRINT);
	ldata=read_doublematrix(fd,"a",no_PRINT);
	if (ldata->nch!=indata) printf("Warning in read_linevector: inconstancy on number of columns (data) : %ld %d \n",ldata->nch,indata);
	//if (ldata->nrh!=index)  printf("Error in read_linevector: inconstancy on number of lines : %ld %ld",ldata->nrh,index);
	lines=new_linevector(ldata->nrh);
	for (j=lines->nl;j<=lines->nh;j++) {
		ja=(long)ldata->element[j][iline_index];
		if (j!=ja) printf("Error in read_linevector (line %ld of %ld): inconstancy on line index : %ld %ld \n",j,lines->nh,j,ja);
		P1=new_point(j-1,ldata->element[j][iP1_x],ldata->element[j][iP1_y],NULL_ELEVATION);
		P2=new_point(j,ldata->element[j][iP2_x],ldata->element[j][iP2_y],NULL_ELEVATION);
		lines->element[j]=new_line_from_points(j,P1,P2);
		free_point(P1);
		free_point(P2);

	}

	free_doublematrix(ldata);
	if (print==1) printf("Function read_linevector (number of lines %ld) was successfully executed!! \n",lines->nh);

	return lines;

}
Пример #12
0
// read a variable and push in onto the stack. this returns 1 if a "normal"
// variable was read, or 0 if an end-table or end-function marker was read (in which case
// nothing is pushed onto the stack).
static int read_variable( Transport *tpt, lua_State *L )
{
  struct exception e;
  uint8_t type = transport_read_uint8_t( tpt );

  switch( type )
  {
    case RPC_NIL:
      lua_pushnil( L );
      break;

    case RPC_BOOLEAN:
      lua_pushboolean( L, transport_read_uint8_t( tpt ) );
      break;

    case RPC_NUMBER:
      lua_pushnumber( L, transport_read_number( tpt ) );
      break;

    case RPC_STRING:
    {
      uint32_t len = transport_read_uint32_t( tpt );
      char *s = ( char * )alloca( len + 1 );
      transport_read_string( tpt, s, len );
      s[ len ] = 0;
      lua_pushlstring( L, s, len );
      break;
    }

    case RPC_TABLE:
      read_table( tpt, L );
      break;

    case RPC_TABLE_END:
      return 0;

    case RPC_FUNCTION:
      read_function( tpt, L );
      break;
    
    case RPC_FUNCTION_END:
      return 0;

    case RPC_REMOTE:
      read_index( tpt, L );
      break;

    default:
      e.errnum = type;
      e.type = fatal;
      Throw( e );
  }
  return 1;
}
Пример #13
0
 void buffer::ensure_writeable_bytes(std::size_t size) {
     SNOW_LOG_DEBUG << "size " << size;
     if(writeable_bytes() >= size) {
         SNOW_LOG_DEBUG << "courent size enough, return direct";
         return;
     }
     if (m_size - readable_bytes() < size) {
         SNOW_LOG_DEBUG << "create a now buffer size " << m_write_index + size;
         std::unique_ptr<char[]> new_buffer(new char[m_write_index + size]);
         SNOW_LOG_DEBUG << "read index " << read_index() << " write index " << write_index();
         std::copy(read_index(), write_index(), new_buffer.get());
         m_buffer.swap(new_buffer);
         m_size = m_write_index + size;
     }
     std::size_t readable = readable_bytes();
     m_read_index         = 0;
     m_write_index        = m_read_index + readable;
     SNOW_LOG_DEBUG << "total size " << m_size << " readable bytes " << m_write_index - m_read_index << " writeable bytes " << m_size - m_write_index;
     assert(writeable_bytes() >= size);
 }
Пример #14
0
LONGBIN *read_line_indices(char *filename,short print) {
	/*
	 *
	 * \author Emanuele Cordano
	 * date May 2009
	 *
	 * \param (char*) - name of filename
	 *\param (short) -
	 *
	 */
	LONGVECTOR **lv;
	LONGBIN *lb;
	LONGVECTOR *vi;
	FILE *fd;
	long j,n_l,c;
	fd=t_fopen(filename,"r");

	n_l=(long)read_index(fd,print);
//	printf("n_l=%ld",n_l);

	lv=(LONGVECTOR **)malloc((size_t)(n_l*sizeof(LONGVECTOR *)));
//	stop_execution();
	for (j=0;j<=n_l-1;j++) {
		lv[j]=read_longarray(fd,print);
	}
	vi=new_longvector(n_l);
	for (j=vi->nl;j<=vi->nh;j++) {
		vi->element[j]=lv[j-1]->nh;
	}
	lb=new_longbin(vi);
	for (j=lb->index->nl;j<=lb->index->nh;j++) {
		for(c=1;c<=lb->index->element[j];c++) {
			lb->element[j][c]=lv[j-1]->element[c];
		}
	}

	free_longvector(vi);
	for (j=0;j<=n_l-1;j++) {
			free_longvector(lv[j]);
	}
	free(lv);
	t_fclose(fd);

	if (print==1) printf("Function read_line_indices was successfully executed! \n");




	return lb;


}
Пример #15
0
int folder_entity_get_property(struct folder_entity *entity, const char *name,
		char **value)
{
	int ret = 0;
	struct rs_node *property_node;
	struct folder_property *property;
	bool is_array_access;
	unsigned index;

	if (entity == NULL || ut_string_is_invalid(name) || value == NULL)
		return -EINVAL;

	property_node = rs_dll_find_match(&entity->folder->properties,
			folder_property_match_str_array_name, name);
	if (property_node == NULL) {
		ULOGE("property \"%s\" not found for folder %s", name,
				entity->folder->name);
		return -ESRCH;
	}
	property = to_property(property_node);
	is_array_access = name[strlen(name) - 1] == ']';
	if (is_array_access && !folder_property_is_array(property)) {
		ULOGE("non-array property accessed as an array one");
		return -EINVAL;
	}


	if (is_array_access) {
		index = read_index(name);
		if (index == UINT_MAX)
			return -EINVAL;
		ret = property->geti(property, entity, index, value);
		if (ret < 0) {
			ULOGE("property->geti: %s", strerror(-ret));
			return ret;
		}
		if (*value == NULL) {
			*value = strdup("nil");
			if (*value == NULL)
				return -errno;
		}
	} else {
		ret = property_get(property, entity, value);
		if (ret < 0) {
			ULOGE("property_get: %s", strerror(-ret));
			return ret;
		}
	}

	return *value == NULL ? -errno : 0;
}
Пример #16
0
static void read_thread_noindex(void) {
	bool empty = true;
	lzma_check check = LZMA_CHECK_NONE;
	while (read_header(&check)) {
		empty = false;
		while (read_block(false, check, 0))
			; // pass
		read_index();
		read_footer();
	}
	if (empty)
		die("Empty input");
	pipeline_stop();
}
Пример #17
0
uint32_t
num_cpus()
{
	cpu_set_t os_cpus_online;

	if (read_list("/sys/devices/system/cpu/online", &os_cpus_online) !=
			FILE_RES_OK) {
		fprintf(stdout, "ERROR: couldn't read list of online CPUs\n");
		return 0;
	}

	uint16_t n_cpus = 0;
	uint16_t n_os_cpus;

	for (n_os_cpus = 0; n_os_cpus < CPU_SETSIZE; n_os_cpus++) {
		char path[1000];

		snprintf(path, sizeof(path),
				"/sys/devices/system/cpu/cpu%hu/topology/physical_package_id",
				n_os_cpus);

		uint16_t i_os_package;
		file_res res = read_index(path, &i_os_package);

		if (res == FILE_RES_NOT_FOUND) {
			break; // we've processed all available CPUs - done
		}

		if (res != FILE_RES_OK) {
			fprintf(stdout, "ERROR: reading OS package index from %s\n", path);
			return 0;
		}

		// Only consider CPUs that are actually in use.
		if (CPU_ISSET(n_os_cpus, &os_cpus_online)) {
			n_cpus++;
		}
	}

	if (n_os_cpus == CPU_SETSIZE) {
		fprintf(stdout, "ERROR: too many CPUs\n");
		return 0;
	}

	fprintf(stdout, "detected %" PRIu32 " CPUs\n\n", n_cpus);

	return n_cpus;
}
Пример #18
0
void show_area_tots(char *areap) {
    int i,idx;
    unsigned int  bullcnt, holdcnt, trafcnt;
    long bullsz, holdsz, trafsz, totsz;
    struct indexhdr hdr;
    struct mailindex ind;
    char buf[FILE_PATH_SIZE], *cp;
#define BM_HOLD 8
  
    sprintf(buf,"%s/%s", Mailspool, areap);
    if ((cp=strrchr(areap,'.')) != NULL) *cp='\0';
    if((idx = open(buf,READBINARY)) != -1) {
        if(read_header(idx,&hdr) == -1)
            hdr.msgs = 0;

        memset(&ind,0,sizeof(ind));

        bullcnt = holdcnt = trafcnt = 0U;
        bullsz = holdsz = trafsz = totsz = 0L;
	for(i=1;i<=hdr.msgs;i++) {
            default_index("",&ind);
            if(read_index(idx,&ind) == -1) {
                puts("* index read err *");
                break;
            }
            totsz += ind.size;
            if (ind.type == 'B') {bullsz += ind.size; bullcnt++;}
            if (ind.type == 'T') {trafsz += ind.size; trafcnt++;}
            if (ind.status & BM_HOLD) {holdsz += ind.size; holdcnt++;}
	}
        printf("%-27s%6u %5ldK ",areap,hdr.msgs, (totsz+1023)/1024);
        allsz += totsz;
        
        if (hdr.msgs) {
            allmsgcnt += hdr.msgs;
            if (bullcnt) printf("%6u %5ldK", bullcnt, (bullsz+1023)/1024);
            else printf("%12s", " ");
            if (trafcnt) printf("%6u %5ldK", trafcnt, (trafsz+1023)/1024);
            else printf("%12s", " ");
            if (holdcnt) printf("%6u %5ldK", holdcnt, (holdsz+1023)/1024);
            /*else printf("%12s", " ");*/
        }
        printf("\n");
        default_index("",&ind);
        close(idx);
    }
}
Пример #19
0
 const T* read_ptr(int16_t* count)
 {
     const T* result = nullptr;
     int16_t clamped_count = std::min<int16_t>(*count, size());
     if (0 < clamped_count)
     {
         int16_t readIndex = read_index(0);
         assert(0 <= readIndex);
         assert(readIndex < max_size());
         result = &(mBuffer[readIndex]);
         clamped_count = std::min<int16_t>(clamped_count, max_size() - readIndex);
         mSize -= clamped_count;
         assert(0 <= mSize); 
     }
     *count = clamped_count;
     return result;
 }
Пример #20
0
void CommandRenumber::show_index(const std::string& type) {
    auto t = osmium::item_type::undefined;

    if (type == "n" || type == "node") {
        t = osmium::item_type::node;
    } else if (type == "w" || type == "way") {
        t = osmium::item_type::way;
    } else if (type == "r" || type == "relation") {
        t = osmium::item_type::relation;
    } else {
        throw argument_error{"Invalid value for --show-index option. Allowed are 'node', 'way', or 'relation'"};
    }

    read_start_ids_file();
    read_index(t);
    m_id_map(t).print(m_id_map(t).start_id());
}
Пример #21
0
int LookForBid(char *file) {
/* scan index associated with <file> for a msg containing bid Bid2Find */

    struct indexhdr hdr;
    struct mailindex ind;
    char buf[FILE_PATH_SIZE], *cp;
    int idx,i,bidlen, serr = 0;

    dirformat(file);
    sprintf(buf,"%s/%s.ind",Mailspool,file);
    if((idx = open(buf,READBINARY)) == -1) {
        printf("Can not read index file %s\n",buf);
        return -1;
    }
  
    memset(&ind,0,sizeof(ind));
    default_index("",&ind);
    bidlen=strlen(Bid2Find);
  
    /* Read the index file header */
    if (read_header(idx,&hdr) == 0)
	{
		for(i=1;i<=hdr.msgs;i++)
		{
        	if (read_index(idx,&ind) == -1)
			{
        		serr = 1;
				break;
			}
        	if(strnicmp(ind.messageid,Bid2Find,bidlen) == 0) {
            	if (*(ind.messageid+bidlen) == '@')
                	printf("Bid %s found in msg #%d of area %s\n", Bid2Find, i, file);
        	}
        	/* Done with this index, clear it */
        	default_index("",&ind);
    	}
	}
    else serr = 1;

	if (serr)
		printf("Error reading index of %s\n", file);

    close(idx);
    return 0;
}
Пример #22
0
void show_index(char *name, int msgidflag) {
    int i,idx;
    char *cp;
    struct indexhdr hdr;
    struct mailindex ind;
    char buf[129];
  
    if((cp=strchr(name,'.')) != NULL)
        *cp = '\0';
    sprintf(buf,"%s/%s.ind",Mailspool,name);
    if((idx = open(buf,READBINARY)) == -1) {
        printf("Index file '%s' not found!\n",buf);
        return;
    }
  
    if(read_header(idx,&hdr) == -1){
        printf("Can not read header from index file '%s'\n",buf);
        close(idx);
        return;
    }
  
    if (!msgidflag)
        printf("%s has %d message%s:\n\n",buf,hdr.msgs,(hdr.msgs == 1 ? "" : "s"));
  
    memset(&ind,0,sizeof(ind));
  
    for(i=1;i<=hdr.msgs;i++) {
        if (!msgidflag) printf("Message %d\n",i);
        default_index("",&ind);
        if(read_index(idx,&ind) == -1) {
            puts("Can not read index!");
            break;
        }
        if (msgidflag) {
            if (ind.msgid > highest_msgid) highest_msgid = ind.msgid;
        }
        else print_index(&ind);
    }
    default_index("",&ind);
    close(idx);
  
}
Пример #23
0
 void read(int16_t* count, T* data)
 {
     int16_t clamped_count = std::min<int16_t>(*count, size());
     int16_t readIndex = read_index(0);
     assert(0 <= readIndex);
     assert(readIndex < max_size());
     int16_t max_seq_read = std::min<int16_t>(clamped_count, max_size() - readIndex);
     if (clamped_count <= max_seq_read)
     {
         memcpy(data, &(mBuffer[readIndex]), clamped_count * sizeof(T));
     }
     else
     {
         memcpy(data, &(mBuffer[readIndex]), max_seq_read * sizeof(T));
         memcpy(data + max_seq_read, &(mBuffer[0]), (clamped_count - max_seq_read) * sizeof(T));
     }
     mSize -= clamped_count;
     assert(0 <= mSize);
     *count = clamped_count;
 }
Пример #24
0
static unsigned iowarrior_poll(struct file *file, poll_table * wait)
{
	struct iowarrior *dev = file->private_data;
	unsigned int mask = 0;

	if (!dev->present)
		return POLLERR | POLLHUP;

	poll_wait(file, &dev->read_wait, wait);
	poll_wait(file, &dev->write_wait, wait);

	if (!dev->present)
		return POLLERR | POLLHUP;

	if (read_index(dev) != -1)
		mask |= POLLIN | POLLRDNORM;

	if (atomic_read(&dev->write_busy) < MAX_WRITES_IN_FLIGHT)
		mask |= POLLOUT | POLLWRNORM;
	return mask;
}
Пример #25
0
int
main(int argc, char *argv[])
{
	WT_CONNECTION *conn;
	WT_SESSION *session;

	home = example_setup(argc, argv);

	error_check(
	    wiredtiger_open(home, NULL, "create,cache_size=500M", &conn));
	add_extractor(conn);
	error_check(conn->open_session(conn, NULL, NULL, &session));

	setup_table(session);
	read_index(session);
	remove_items(session);

	error_check(conn->close(conn, NULL));

	return (EXIT_SUCCESS);
}
Пример #26
0
int sj_index_load(char *filename, SJ_IndexContext *sj_ic)
{
    ByteIOContext pb;
    register_protocol(&file_protocol);

    if (url_fopen(&pb, filename, URL_RDONLY) < 0) {
        // file could not be open
        return -1;
    }
    sj_ic->size = url_fsize(&pb) - HEADER_SIZE;
    sj_ic->index_num = (sj_ic->size / INDEX_SIZE);
    sj_ic->indexes = av_malloc(sj_ic->index_num * sizeof(Index));

    int64_t magic = get_le64(&pb);
    if (magic != 0x534A2D494E444558LL) {
        // not an index file
        url_fclose(&pb);
        return -2;
    }
    sj_ic->version = get_byte(&pb);
    sj_ic->start_pts = get_le64(&pb);
    sj_ic->start_dts = get_le64(&pb);
    sj_ic->start_timecode.frames = get_byte(&pb);
    sj_ic->start_timecode.seconds = get_byte(&pb);
    sj_ic->start_timecode.minutes = get_byte(&pb);
    sj_ic->start_timecode.hours = get_byte(&pb);

    if (!sj_ic->index_num) {
        // empty index
        url_fclose(&pb);
        return -4;
    }

    for(int i = 0; i < sj_ic->index_num; i++) {
        read_index(&sj_ic->indexes[i], &pb);
    }
    url_fclose(&pb);
    return 0;
}
Пример #27
0
int main(void)
{
    WORD idx;
    struct user_info *user;
    char line[32];

    UART_DATA = 0x21;
    
    GPIO_SET2   = DRIVE_RESET | C64_RESET;

	memset(&mountfile, 0 ,sizeof(mountfile));

    // no cart
    CART_MODE = 0x00;

    GPIO_CLEAR2 = C64_RESET;
    
    wait2sec();

    // read index
    init_freeze();
    screen_initialized = 1;
    // now we can use the console :)

    // initialize timer IRQ for keyboard scan
    IRQ_TIMER    = 3906; // 50 Hz
    
    if(!iec_test()) {
        printf("IEC cable seems faulty.\n");
        while(1);
    }

/*
    {
        WORD w;
        BYTE b;
        BYTE *mem = (BYTE *)MAP1_ADDR;
        DWORD addr = 0x1400000;
		MAPPER_MAP1 = (addr >> 13);

		w = (addr & 0x1FFF);
		for(b=0;b<32;b++) {
			if((b & 7)==0) {
				printf("\n%07lx: ", addr + (DWORD)b);
                if((w + b) >= 0x2000) {
                    MAPPER_MAP1 = MAPPER_MAP1 + 1;
                    w -= 0x2000;
                }
            }
			printf("%02x ", mem[w + b]);
		}
		printf("\n");
    }

    ethernet_test();
    while(1)
        ;
*/

    // read index
    idx = read_index();
    if(idx == 0xFFFF) {
        idx = 0;
        printf("Couldn't read index file.\n");
    }


/*
    {
        BYTE b;
        
        // dump content of first 144 bytes of one_wire rom
        onewire_reset();
        onewire_sendbyte(0xCC); // skip rom
        onewire_sendbyte(0xF0); // read memory
        onewire_sendbyte(0); // starting address
        onewire_sendbyte(0);
        
        for(b=0;b<144;b++) {
            if((b % 16)==0) {
                printf("\n0%02x: ", b);
            }
            printf("%02x ", onewire_getbyte());
        } printf("\n");
    }
    printf("!Enter your name:\n");
    read(0, line, 32);    
    printf("Your name is: %s.\n", line);
*/
    
    // get user name
    user = get_user(idx);

    printf("The unit should be a %s version.\n", user->type);
    if(!test_sdram()) {
        if(user->type[0] != 'b') {
            printf("SDRAM test failed...\n Are you sure you got a plus version?\nStop.\n");
            while(1);
        }
    } else {
        printf("SDRAM is ok!\n");
        if(user->type[0] == 'b') {
            printf(" User requested a basic version...\n Are you sure you want to continue?\n");
//            scanf("%s", line);
            read(0, line, 32);
//    		uart_read_buffer(line, 32);
    		if(line[0] != 'y') {
    		    printf("Stop.\n");
    		    while(1);
    		}
        }
    }
    
    if(user->type[0] == 'e') { // ethernet version
        if(!ethernet_test()) {
            printf("Ethernet failed.\n");
            while(1);
        }
    }

    if(!flash_roms()) {
        printf("Flashing ROMS Failed.\n");
        while(1);
    }

    if(!personalize(user)) {
        printf("PERSONALIZING FAILED... STOPPED!!\n");
        while(1);
    }
        
    // store where we left off
    if(!write_index(idx+1)) {
        printf("WARNING!! Writing index failed.\n");
    }
    
    printf("Programming cart successful...\n");

    // Init 1541 to enable sound for testing
    copy_page(0x0836, ROM1541_ADDR);
    copy_page(0x0837, ROM1541_ADDR+1);
    GPIO_CLEAR2 = DRIVE_RESET;

    while(1);
}
Пример #28
0
int Asset::read(FileXML *file, 
	int expand_relative)
{
	int result = 0;

// Check for relative path.
	if(expand_relative)
	{
		char new_path[BCTEXTLEN];
		char asset_directory[BCTEXTLEN];
		char input_directory[BCTEXTLEN];
		FileSystem fs;

		strcpy(new_path, path);
		fs.set_current_dir("");

		fs.extract_dir(asset_directory, path);

// No path in asset.
// Take path of XML file.
		if(!asset_directory[0])
		{
			fs.extract_dir(input_directory, file->filename);

// Input file has a path
			if(input_directory[0])
			{
				fs.join_names(path, input_directory, new_path);
			}
		}
	}


	while(!result)
	{
		result = file->read_tag();
		if(!result)
		{
			if(file->tag.title_is("/ASSET"))
			{
				result = 1;
			}
			else
			if(file->tag.title_is("AUDIO"))
			{
				read_audio(file);
			}
			else
			if(file->tag.title_is("AUDIO_OMIT"))
			{
				read_audio(file);
			}
			else
			if(file->tag.title_is("FORMAT"))
			{
				char *string = file->tag.get_property("TYPE");
				format = File::strtoformat(string);
				use_header = 
					file->tag.get_property("USE_HEADER", use_header);
			}
			else
			if(file->tag.title_is("FOLDER"))
			{
				char *string = file->tag.get_property("NUMBER");
				if(string)
					awindow_folder = atoi(string);
				else
					awindow_folder = AWindowGUI::folder_number(file->read_text());
			}
			else
			if(file->tag.title_is("VIDEO"))
			{
				read_video(file);
			}
			else
			if(file->tag.title_is("VIDEO_OMIT"))
			{
				read_video(file);
			}
			else
			if(file->tag.title_is("INDEX"))
			{
				read_index(file);
			}
		}
	}

//printf("Asset::read 2\n");
	return 0;
}
Пример #29
0
int folder_entity_set_property(struct folder_entity *entity, const char *name,
		const char *value)
{
	int ret;
	unsigned index;
	bool is_array_access;
	struct rs_node *property_node;
	struct folder_property *property;
	wordexp_t __attribute__((cleanup(wordfree)))we = {0};

	if (entity == NULL || ut_string_is_invalid(name) ||
			ut_string_is_invalid(value))
		return -EINVAL;

	property_node = rs_dll_find_match(&entity->folder->properties,
			folder_property_match_str_array_name, name);
	if (property_node == NULL) {
		ULOGE("property \"%s\" not found for folder %s", name,
				entity->folder->name);
		return -ESRCH;
	}
	property = to_property(property_node);
	is_array_access = name[strlen(name) - 1] == ']';
	if (is_array_access && !folder_property_is_array(property)) {
		ULOGE("non-array property accessed as an array one");
		return -EINVAL;
	}

	if (is_array_access) {
		if (property->seti == NULL) {
			ULOGE("property %s.%s[] is read-only",
					entity->folder->name, name);
			return -EPERM;
		}
		index = read_index(name);
		if (index == UINT_MAX)
			return -EINVAL;
		ret = property->seti(property, entity, index, value);
		if (ret < 0) {
			ULOGE("property->seti: %s", strerror(-ret));
			return ret;
		}
	} else {
		if (folder_property_is_array(property)) {
			if (property->seti == NULL) {
				ULOGE("property %s.%s[] is read-only",
						entity->folder->name, name);
				return -EPERM;
			}
			ret = wordexp(value, &we, 0);
			if (ret != 0) {
				ULOGE("wordexp error %d", ret);
				return ret == WRDE_NOSPACE ? ENOMEM : EINVAL;
			}

			for (index = 0; index < we.we_wordc; index++) {
				ret = property->seti(property, entity, index,
						we.we_wordv[index]);
				if (ret < 0) {
					ULOGE("property->seti: %s",
							strerror(-ret));
					return ret;
				}
			}
			ret = property->seti(property, entity, index, "nil");
			if (ret < 0) {
				ULOGE("property->seti: %s", strerror(-ret));
				return ret;
			}
		} else {
			if (property->set == NULL) {
				ULOGE("property %s.%s is read-only",
						entity->folder->name, name);
				return -EPERM;
			}
			ret = property->set(property, entity, value);
			if (ret < 0) {
				ULOGE("property->set: %s", strerror(-ret));
				return ret;
			}
		}
	}

	return 0;
}
Пример #30
0
int read_one_obj(
                 FILE *fp,
                 Polygon *poly,
                 Surface *surface)
{
    char b[MWS];
    int flag_material = 0;
    int flag_point = 0;
    int flag_index = 0;

    /* initialize surface */
    surface->diff[0] = 1.0;
    surface->diff[1] = 1.0;
    surface->diff[2] = 1.0;
    surface->spec[0] = 0.0;
    surface->spec[1] = 0.0;
    surface->spec[2] = 0.0;
    surface->ambi = 0.0;
    surface->shine = 0.2;

    if ( getword(fp,b,MWS) <= 0) return 0;

    poly->vtx_num = 0;
    poly->idx_num = 0;

    while (flag_material==0 || flag_point==0 || flag_index==0) {
        if      (strindex(b,"Material")>=0) {
            getword(fp,b,MWS);
            flag_material = 1;
        }
        else if (strindex(b,"point")>=0) {
            fprintf(stderr,"Counting... [point]\n");
            poly->vtx_num = count_point(fp, b);
            flag_point = 1;
        }
        else if (strindex(b,"coordIndex")>=0) {
            fprintf(stderr,"Counting... [coordIndex]\n");
            poly->idx_num = count_index(fp, b);
            flag_index = 1;
        }
        else if (getword(fp,b,MWS) <= 0) return 0;
    }

    flag_material = 0;
    flag_point = 0;
    flag_index = 0;

    fseek(fp, 0, SEEK_SET);
    poly->vtx = (double *)malloc(sizeof(double)*3*poly->vtx_num);
    poly->idx = (int *)malloc(sizeof(int)*3*poly->idx_num);
    while (flag_material==0 || flag_point==0 || flag_index==0) {
        if      (strindex(b,"Material")>=0) {
            fprintf(stderr,"Reading... [Material]\n");
            read_material(fp,surface,b);
            flag_material = 1;
        }
        else if (strindex(b,"point")>=0) {
            fprintf(stderr,"Reading... [point]\n");
            read_point(fp,poly,b);
            flag_point = 1;
        }
        else if (strindex(b,"coordIndex")>=0) {
            fprintf(stderr,"Reading... [coordIndex]\n");
            read_index(fp,poly,b);
            flag_index = 1;
        }
        else if (getword(fp,b,MWS) <= 0) return 0;
    }

    return 1;
}