Beispiel #1
0
void load_fonts(const char *filename,fontchar **fontmap,uint8_t **widthmap)
{

	*fontmap  = (fontchar *) malloc(sizeof(fontchar)*65536);
	*widthmap = (uint8_t  *) malloc(sizeof(uint8_t)*(65536/8));

	fontmap_size  = sizeof(fontchar)*65536;
	widthmap_size = sizeof(uint8_t)*(65536/8);

	for(size_t n=0; n<65536; n++) for(int i=0; i<32; i++) (*fontmap)[n].data[i] = 0;
	for(size_t n=0; n<(sizeof(uint8_t)*(65536/8)); n++) (*widthmap)[n] = 0;

	FILE *mfile = fopen(filename,"r");

	for(int n=0; !feof(mfile); n++)
	{
		char *line = (char *) malloc(50);
		size_t size = 50;
		int r = getline(&line,&size,mfile);

		int width = load_line(line,&(*fontmap)[n]);
		set_widthmap(*widthmap,n,width);
		free(line);
	}
}
Beispiel #2
0
bool Patch::load(const char * filename, unsigned int checksum,
    unsigned int length)
{
    FILE *hFile;
    if((hFile = fopen(filename, "rb")) == 0) return false;

    while(true)
    {
        char buffer[PATCH_LINE_MAX];
        fgets(buffer, PATCH_LINE_MAX, hFile);

        if(feof(hFile)) break;

        char *pToken = &buffer[strspn(buffer, " \t\n\r")];

        if(*pToken++ != '\"') continue;

        char *strName = pToken;

        if((pToken = strchr(pToken, '\"')) == 0) continue;

        *pToken++ = 0;

        unsigned int currentChecksum;
        unsigned int currentLength;

        if(sscanf(pToken, "%x %x", &currentChecksum, &currentLength) != 2) continue;

        if((currentChecksum != checksum) || (currentLength != length)) continue;

        if((pToken = strchr(pToken, ':')) == 0) continue;

        if(!load_line(pToken + 1)) continue;

        strcpy(m_name, strName);

        fclose(hFile);
        return true;
    }

    fclose(hFile);

    return false;
}
Beispiel #3
0
int GBDTData::load_file(const char* path) {
    std::ifstream stream(path);
    if (!stream) {
        LOG(WARNING) << "fail to open " << path;
        return 1;
    }
    _m_data.clear();

    char* local_buffer = new char[GBDT_MAX_BUFF_LEN];
    stream.rdbuf()->pubsetbuf(local_buffer, GBDT_MAX_BUFF_LEN);

    std::string line;
    while(std::getline(stream, line)) {
        load_line(line.c_str());
    }
    
    DLOG(INFO) << "load file finished, size: " << _m_data.size();
    delete[] local_buffer;

    return 0;
}
Beispiel #4
0
Config *load_config(const char *filename)
{
    Config *config;
    
    FILE *f = fopen(filename, "rt");
    if (!f)
        return NULL;
    
    config = malloc(sizeof(Config));
    config->item_list = NULL;
    
    while (!feof(f))
    {
        char buf[BUFFER_SIZE];
        if (!fgets(buf, sizeof(buf), f))
             break;
        
        load_line(buf, config);
    }
    
    fclose(f);
    
    return config;
}
Beispiel #5
0
load_file (char *filename, bool initial)
{
  char *line;
  gfc_linebuf *b;
  gfc_file *f;
  FILE *input;
  int len, line_len;

  for (f = current_file; f; f = f->up)
    if (strcmp (filename, f->filename) == 0)
      {
	gfc_error_now ("File '%s' is being included recursively", filename);
	return FAILURE;
      }

  if (initial)
    {
      input = gfc_open_file (filename);
      if (input == NULL)
	{
	  gfc_error_now ("Can't open file '%s'", filename);
	  return FAILURE;
	}
    }
  else
    {
      input = gfc_open_included_file (filename, false);
      if (input == NULL)
	{
	  gfc_error_now ("Can't open included file '%s'", filename);
	  return FAILURE;
	}
    }

  /* Load the file.  */

  f = get_file (filename, initial ? LC_RENAME : LC_ENTER);
  f->up = current_file;
  current_file = f;
  current_file->line = 1;
  line = NULL;
  line_len = 0;

  for (;;) 
    {
      int trunc = load_line (input, &line, &line_len);

      len = strlen (line);
      if (feof (input) && len == 0)
	break;

      /* There are three things this line can be: a line of Fortran
	 source, an include line or a C preprocessor directive.  */

      if (line[0] == '#')
	{
	  preprocessor_line (line);
	  continue;
	}

      if (include_line (line))
	{
	  current_file->line++;
	  continue;
	}

      /* Add line.  */

      b = gfc_getmem (gfc_linebuf_header_size + len + 1);

#ifdef USE_MAPPED_LOCATION
      b->location
	= linemap_line_start (&line_table, current_file->line++, 120);
#else
      b->linenum = current_file->line++;
#endif
      b->file = current_file;
      b->truncated = trunc;
      strcpy (b->line, line);

      if (line_head == NULL)
	line_head = b;
      else
	line_tail->next = b;

      line_tail = b;
    }

  /* Release the line buffer allocated in load_line.  */
  gfc_free (line);

  fclose (input);

  current_file = current_file->up;
#ifdef USE_MAPPED_LOCATION
  linemap_add (&line_table, LC_LEAVE, 0, NULL, 0);
#endif
  return SUCCESS;
}
Beispiel #6
0
bool data_file::load(void)
{  
  DATA_FILE_SECTION *p_current = NULL;
  bool in_comment = FALSE;
  
  char line[MAX_TOKEN_LEN];
  while(load_line(line)) {
    LINE_TYPE type = line_type_get(line);
    
    /*
     * Skip comments in input file
     */
    if(type == LINE_COMMENT_START) {
      in_comment = TRUE;
      continue;
    }
    else if(type == LINE_COMMENT_STOP) {
      in_comment = FALSE;
      continue;
    } else if(in_comment) {
      continue;
    }
    
    switch(type) {
      case LINE_NONE:
      case LINE_COMMENT:
      case LINE_COMMENT_START:
      case LINE_COMMENT_STOP:
        break;
      // Create and load whole section
      case LINE_SECTION_START:
        p_current = section_new();
        p_current->load();
        break;
      case LINE_SECTION_ITEM:
        // Should not be here
        break;
      case LINE_SECTION_STOP:
        // Should not be here
        break;
      case LINE_SECTION_INCLUDE:
        {
          // Load sub-file
          char value[MAX_TOKEN_LEN];
          if(tokenize_line_command(line, NULL, value)) {
            DATA_FILE file;
            if(!file.load(value, FALSE)) {
              char local_file[MAX_FILENAME];
              return_path(current_dir, value, local_file, MAX_FILENAME);
              if(!file.load(local_file, FALSE)) {
                return(FALSE);
              }
            }
            
            import(&file);
          }
        }
        break;
    }
  }  
  return(TRUE);
}