Exemplo n.º 1
0
/**
 * Read Access Point Configuration Name
 * @return 0 on success or... -1
 */
int _readHotspotConfig(void)
{
	// Open Configuration File
	int fd = sceIoOpen("ms0:/seplugins/hotspot.txt", PSP_O_RDONLY, 0777);
	
	// Opened Configuration File
	if(fd >= 0)
	{
		// Line Buffer
		char line[128];
		
		// Read Line
		_readLine(fd, line, sizeof(line));
		
		// Find Hotspot Configuration
		_hotspot = _findHotspotConfigId(line);
		
		// Found Hotspot
		if(_hotspot != -1) printk("Selected Hotspot: %s\n", line);
		
		// No Hotspot found
		else printk("Couldn't find Hotspot: %s\n", line);
		
		// Close Configuration File
		sceIoClose(fd);
		
		// Return Success
		if(_hotspot >= 0) return 0;
	}
	
	// Generic Error
	return -1;
}
Exemplo n.º 2
0
void lemur::file::SortMergeTextFiles::_doSingleFileMergesort(std::string &inputFile, std::string &outputFile, std::vector<std::string> &chunkList, int chunkRecordSize) {
  // our in-memory chunks
  std::vector<std::string> inMemoryChunk;
  inMemoryChunk.reserve(chunkRecordSize);

  int currentChunkRecord=0;

  // clear the input buffer
  _inputBuffer.clear();

  FILE* _in;
  _in = fopen( inputFile.c_str(), "rb" );

  if( !_in ) {
    LEMUR_THROW( LEMUR_IO_ERROR, "Couldn't open file " + inputFile + "." );
  }

  // reset the buffer size
  //  setvbuf(_in, NULL, _IOFBF, 65536);
  setvbuf(_in, NULL, _IOFBF, 5*1024*1024);
  std::vector<std::string> outputChunks;

  int countInputRecords=0;

  char* thisLine;
  size_t lineLength;

  while (_readLine(_in,  thisLine, lineLength, _inputBuffer)) {
    if (currentChunkRecord==chunkRecordSize) {
      chunkList.push_back(_flushChunks(outputFile, &inMemoryChunk, chunkList.size()));
      inMemoryChunk.clear();
      currentChunkRecord=0;
    }

    // straight fill-up the buffer
    if ((lineLength > 0) && (thisLine)) {
      inMemoryChunk.push_back(std::string(thisLine));

      // increment our counters
      ++currentChunkRecord;
      ++countInputRecords;
    }
  }

  if (currentChunkRecord > 0) {
    chunkList.push_back(_flushChunks(outputFile, &inMemoryChunk, chunkList.size()));
  }

  // close the input file, we're done with it
  fclose(_in);

  // now, merge sort the chunks
  // _doFinalMergesortFiles(outputChunks, outputFile);
}
Exemplo n.º 3
0
bool indri::parse::WARCRecord::readHeader() {
  // skip over empty lines until content-length has been found
  // to accomodate the slightly malformed clueweb warcs.
  // Consume the first WARC record (type warcinfo)
  // should verify the WARC-Type is warcinfo
  // if not, it's a partial file or broken... bleah.
  // read until the WARC-Record-ID line.
  // parse the urn:uri value for the file unique identifier (ugly)
  // read until the Content-Length line.
  // parse the length (atoi)
  // read until an empty line
  // read length bytes into record

  char* beginLine;
  size_t lineLength;  
  std::string line;
  std::string key, value;
  bool result;
  bool empty = false;
  _buffer.clear();
  do {
    result = _readLine( beginLine, lineLength );
    if (! result) break;
    line.assign(beginLine, lineLength);
    // gather the unmolested header string
    header += line;
    // strip the newline (CRLF or LF)
    line = trim_right(line, "\r\n");
    empty = line.size() == 0;
    if (! empty) {
      split(line, key, value);
      value = trim_left(value);
      // classify and add to metadata
      if (key == WARCTYPE) {
        warcType.assign(value);
      } else if (key == WARCRECORDID) {
        // trim '<urn:uuid:' from front, '>' from back
        uuid.assign(value.substr(10, value.size() - 11));
      } else if (key == CONTENTLENGTH) {
        contentLength = atoi(value.c_str());
      } else if (key == WARCTARGETURI) {
        targetURI.assign(value);
      } else if (key == WARCTRECID) {
        trecID.assign(value);
      } else {
        // stuff it in the hash table
        metadata.insert(key, value);
      }
    }
  } while (result && (!contentLength || !empty)) ;
  return contentLength != 0;
}
Exemplo n.º 4
0
ButtonSet::BUTTON BluetoothInterface::scanButtons()
{
    while (_readLine())
    {
        // one-char commands
        if (strlen(_command) == 1)
        {
            char* found = strchr(BUTTONS_RELEASED, _command[0]);
            if (found)
            {
                return (BUTTON)((found - BUTTONS_RELEASED) + 1);
            }
        }
    }

    return BUTTON_NONE;
}
Exemplo n.º 5
0
/**
 * Read Server IP
 * @return IP != 0 on success or... 0
 */
const char * _readServerConfig(void)
{
	// Line Buffer
	static char line[128];

	// Open Configuration File
	int fd = sceIoOpen("ms0:/seplugins/server.txt", PSP_O_RDONLY, 0777);
	
	// Opened Configuration File
	if(fd >= 0)
	{
		// Read Line
		_readLine(fd, line, sizeof(line));
		
		// Close Configuration File
		sceIoClose(fd);
		
		// Return IP (String)
		return line;
	}
	
	// Generic Error
	return NULL;
}
Exemplo n.º 6
0
static float *pmFReadPDBFrameFull(FILE* stream,PMAtomDesc** atominfo,size_t *atoms)
{
	size_t i=0;
	char linebuffer[128];

	float *coords=0, *c;
	PMAtomDesc *info=0, *a;

	size_t alloc = ALLOCPAGESIZE;

	//check if size is known
	if(*atoms)
		alloc = *atoms;

	while(fgets(linebuffer,128,stream)){
	        //fprintf(stderr,"%i[%i]\n",i,(i%alloc));
		//only atom lines
		if(!strncmp(linebuffer,"ATOM",4) || !strncmp(linebuffer,"HETATM",6)){
			//test line
	        if(strlen(linebuffer)<54)break; // underfull line

	        //allocate more memory
	        if(!(i%alloc)){
	        	c = (float*)realloc(coords,(i/alloc+1)*alloc*3*sizeof(float));
			if(!c){
				WARN("Failed to allocate coordinates array");	
				free(coords);
				free(info);
				return 0;
			}
			else coords = (float*) c;
	        	a = (PMAtomDesc*) realloc(info,(i/alloc+1)*alloc*sizeof(PMAtomDesc));
			if(!c){
				WARN("Failed to allocate info array");	
				free(coords);
				free(info);
				return 0;
			}
			else info = (PMAtomDesc *) a;

			c=&coords[i*3];
			a=&info[i];
		        //fprintf(stderr,">>>>>>%p<<<<<<<\n",coords);
	        }


	        //reading
	        _readLine(linebuffer,a++,c);
	        c+=3;
	        i++;
	    }
		//any line with end stops reading ENDMDL and END
	    else if(!strncmp(linebuffer,"END",3))
	    	break;
	}
	if (*atoms) { //test if size matches
		if(*atoms != i) {
			free(info);
			free(coords);
			return 0;
		}
	}
	else {
		*atoms=i;
	    coords = (float*)   realloc(coords,i*3*sizeof(float));
	    info   = (PMAtomDesc*) realloc(info,i*sizeof(PMAtomDesc));
	}
	*atominfo = info;
	return coords;
}