Ejemplo n.º 1
0
void help_init(void)
{
gint n;
gchar *filename, *line, *topic;
gpointer scan;
GString *buffer;

/* hash table with topic label as the key */
sysenv.manual = g_hash_table_new(g_str_hash, g_str_equal);

/* open the manual file for scanning */
filename = g_build_filename(sysenv.gdis_path, MANUAL_FILE, NULL);
printf("scanning: %s\n", filename);
scan = scan_new(filename);
g_free(filename);
if (!scan)
  {
  help_topic_new(NULL, NULL);
  return;
  }

/* process the manual file */
topic=NULL;
buffer = g_string_new(NULL);
line = scan_get_line(scan);
while (!scan_complete(scan))
  {
  if (g_ascii_strncasecmp(line, "%topic ", 7) == 0)
    {
/* add any old data */
    if (topic && buffer->len)
      {
      help_topic_new(topic, buffer->str);
      buffer = g_string_set_size(buffer, 0);
      g_free(topic);
      }
/* remove trailing <cr> */
    n = strlen(&line[7]);
    topic = g_strndup(&line[7], n-1);
    }
  else
    {
/* append everything that's not a topic to the current buffer */
    if (topic)
      g_string_append(buffer, line);
    }

  line = scan_get_line(scan);
  }

/* done - add the last topic found */
if (topic)
  help_topic_new(topic, buffer->str);

g_string_free(buffer, TRUE);
g_free(topic);

scan_free(scan);
}
Ejemplo n.º 2
0
static void
Scan_dealloc(Scan* self)
{        
    scan_free(&self->scan);
    
    free(self->lidar_mm);
    
    Py_TYPE(self)->tp_free((PyObject*)self);
}
Ejemplo n.º 3
0
/**
 * shrink_dpa_allocation - for each dimm in region free n bytes for label_id
 * @nd_region: the set of dimms to reclaim @n bytes from
 * @label_id: unique identifier for the namespace consuming this dpa range
 * @n: number of bytes per-dimm to release
 *
 * Assumes resources are ordered.  Starting from the end try to
 * adjust_resource() the allocation to @n, but if @n is larger than the
 * allocation delete it and find the 'new' last allocation in the label
 * set.
 */
static int shrink_dpa_allocation(struct nd_region *nd_region,
		struct nd_label_id *label_id, resource_size_t n)
{
	int i;

	for (i = 0; i < nd_region->ndr_mappings; i++) {
		struct nd_mapping *nd_mapping = &nd_region->mapping[i];
		int rc;

		rc = scan_free(nd_region, nd_mapping, label_id, n);
		if (rc)
			return rc;
	}

	return 0;
}
Ejemplo n.º 4
0
int main(int argc, char **argv) {
    struct scan_ctx *scan;
    struct scan_chunk_data chunk_data[2];
    struct analyze_ctx *analyze;
    int fd, result;

    analyze = analyze_open(argv[2], argv[1]);
    if (!analyze) {
	perror("analyze_init");
	return EXIT_FAILURE;
    }

    scan = scan_init();
    if (!scan) {
	perror("scan_init");
	return EXIT_FAILURE;
    }

    fd = open(argv[1], O_RDWR);
    if (fd < 0) {
	perror("open");
	return EXIT_FAILURE;
    }
    scan_set_fd(scan, fd);
    scan_set_aio(scan);

    if (!scan_begin(scan))
	return EXIT_FAILURE;
    do {
	result = scan_read_chunk(scan, chunk_data);
	if (result & SCAN_CHUNK_FOUND)
	    store_chunk(analyze, chunk_data);
	else {
	    fputs("Scan error\n", stderr);
	    return EXIT_FAILURE;
	}
    } while (!(result & SCAN_CHUNK_LAST));
    analyze_close(analyze);
    scan_free(scan);

    return EXIT_SUCCESS;
}
Ejemplo n.º 5
0
gint read_aims(gchar *filename, struct model_pak *model)
{
gint i, num_tokens;
gchar **buff;
gpointer scan;
struct core_pak *core;

g_assert(model != NULL);

scan = scan_new(filename);
if (!scan) return(1);

while (!scan_complete(scan)) {

  buff = scan_get_tokens(scan, &num_tokens);

/* 
   for debugging purposes 
   produces a compiler warning about an
	implicit declaration of function 'g_printf'
   though this is a valid glib function since 2.2
	http://library.gnome.org/devel/glib/2.18/glib-String-Utility-Functions.html#g-printf
*/
/*
  for (i=0; i<num_tokens; i++) {
	g_printf(" %s ", buff[i]);
  }
  printf("\n");
*/

  if (!buff) break;

  /* read cell vectors */
  if ( g_strrstr(*buff, "lattice_vector") != NULL ) {
     for (i=0 ; i<3 ; i++) {
         if (num_tokens >= 3) {
            model->latmat[i] = str_to_float(*(buff+1));
            model->latmat[i+3] = str_to_float(*(buff+2));
            model->latmat[i+6] = str_to_float(*(buff+3));
         }
         else { 
            gui_text_show(ERROR, "error reading AIMS lattice vectors \n"); 
            return(2);
         }
         g_strfreev(buff);
         buff = scan_get_tokens(scan, &num_tokens);
     }
     model->periodic = 3;
     model->construct_pbc = TRUE;
  }

  /* read coordinates */
  if ( g_strrstr(*buff, "atom") != NULL ) {
     if ( ( num_tokens >= 4 ) && ( elem_symbol_test(*(buff+4)) ) ) {
        core = new_core(*(buff+4), model);
        core->x[0] = str_to_float(*(buff+1));
        core->x[1] = str_to_float(*(buff+2));
        core->x[2] = str_to_float(*(buff+3));
        model->cores = g_slist_prepend(model->cores, core);
     }
     else {
        gui_text_show(ERROR, "error reading AIMS lattice vectors \n"); 
        return(2);
     }
  }

  g_strfreev(buff);
}

/* done reading */
scan_free(scan);

/* model setup */
g_free(model->filename);
model->filename = g_strdup(filename);

g_free(model->basename);
model->basename = g_path_get_basename(filename);

model->fractional = FALSE;
model_prep(model);

return(0);
}
Ejemplo n.º 6
0
// no coords - just control data for the run
// coords - .pdb file
// topology - .frx file
gint reaxmd_input_import(gpointer import)
{
gint *symbols, num_symbols, unknown;
gchar *line, *fullname_model;
gchar *filename, *filepath;
gpointer scan, config;
GString *unparsed;
struct reaxmd_pak *reaxmd;
struct model_pak *model;
FILE *fp;

scan = scan_new(import_fullpath(import));
if (!scan)
  return(1);

/* populate symbol table */
reaxmd_symbols_init(scan);

config = config_new(REAXMD, NULL);
reaxmd = config_data(config);

unparsed = g_string_new(NULL);

while (!scan_complete(scan))
  {
  symbols = scan_get_symbols(scan, &num_symbols);
  if (num_symbols)
    {
    unknown = FALSE;
/* process first recognized symbol */
    switch (symbols[0])
      {
      case REAXMD_NSTEPS:
        reaxmd->total_steps = parse_nth_token_dup(1, scan_cur_line(scan));
        break;

      case REAXMD_TIMESTEP:
      case REAXMD_TEMPERATURE:
      case REAXMD_THERMOSTAT:
      case REAXMD_BAROSTAT:
      case REAXMD_CUTOFF:
      case REAXMD_UPDATE:
      case REAXMD_NWRITE:
      case REAXMD_GRID:
        break;

      case REAXMD_PLUMED_FILE:
        filename = parse_nth_token_dup(1, scan_cur_line(scan));
        filepath = g_build_filename(import_path(import), filename, NULL);
//printf("Looking for: %s\n", filepath);
        if (g_file_test(filepath, G_FILE_TEST_EXISTS))
          project_job_file_append(NULL, filepath, sysenv.workspace);
        else
          gui_text_show(ERROR, "REAXMD plumed file was not found!\n"); 
        g_free(filename);
        g_free(filepath);
        break;

      default:
        unknown = TRUE;
      }
    g_free(symbols);
    }
  else
    unknown=TRUE;

  if (unknown)
    {
    line = scan_cur_line(scan);
    if (line)
      g_string_append(unparsed, line);
    }
  }

config_unparsed_set(g_string_free(unparsed, FALSE), config);
/* CURRENT - free this, until we add a GUI */
//import_object_add(IMPORT_CONFIG, config, import);
config_free(config);

/* done irx parse */
scan_free(scan);

/* NEW - attempt to load reference coordinates */
fullname_model = parse_extension_set(import_fullpath(import), "pdb");
fp = fopen(fullname_model, "rt");
if (fp)
  {
  model = model_new();
  read_pdb_block(fp, model);
  fclose(fp);
  import_object_add(IMPORT_MODEL, model, import);
  }
else
  {
  gui_text_show(WARNING, "Failed to open reference PDB model for ReaxMD.\n");
  }
g_free(fullname_model);

/* init */
import_init(import);

return(0);
}
Ejemplo n.º 7
0
gint nwchem_input_import(gpointer import)
{
gint *symbols, num_symbols, num_tokens, value;
gchar *line, **buff;
gpointer scan, config;
GString *unparsed;
struct model_pak *model=NULL; // CURRENT - will break if more than one in a file
struct nwchem_pak *nwchem;

scan = scan_new(import_fullpath(import));
if (!scan)
  return(1);

/* populate symbol table */
nwchem_scan_symbols_init(scan);

config = config_new(NWCHEM, NULL);
nwchem = config_data(config);

unparsed = g_string_new(NULL);

while (!scan_complete(scan))
  {
  symbols = scan_get_symbols(scan, &num_symbols);

  if (num_symbols)
    {
/* process first recognized symbol */
    value = symbols[0];
    switch (value)
      {
      case NWCHEM_START:
/* TODO - could this serve as title? */
        nwchem->start = parse_strip(scan_cur_line(scan));
        break;

      case NWCHEM_BASIS:
// TODO - don't want to use this for predefined basis sets
        read_nwchem_basis_library(scan, config);
        break;

      case NWCHEM_CHARGE:
        line = scan_cur_line(scan);
        buff = tokenize(line, &num_tokens);
        if (num_tokens > 1)
          nwchem->charge = g_strdup(buff[1]);
        g_strfreev(buff);
        break;

      case NWCHEM_GEOMETRY:
        if (!model)
          {
          model = model_new();
          import_object_add(IMPORT_MODEL, model, import);
          }
        read_nwchem_geometry(scan, model);
        break;

      case NWCHEM_SYSTEM:
        if (!model)
          {
          model = model_new();
          import_object_add(IMPORT_MODEL, model, import);
          }
        read_nwchem_system(scan, model);
        break;

      case NWCHEM_TASK:
        read_nwchem_task(scan, config, symbols, num_symbols);
        break;

      default:
/* add lines that have recognized symbols (but no special trigger) to unparsed */
/* this'll happen for symbols that occur in multiple locations (eg dft) */
        line = scan_cur_line(scan);
        if (line)
          g_string_append(unparsed, line);
      }

    g_free(symbols);
    }
  else
    {
/* add non-NULL lines to unparsed list */
    line = scan_cur_line(scan);
    if (line)
      g_string_append(unparsed, line);
    }
  }

config_unparsed_set(g_string_free(unparsed, FALSE), config);
import_object_add(IMPORT_CONFIG, config, import);

scan_free(scan);

import_init(import);

return(0);
}
Ejemplo n.º 8
0
/* Scan file FILENAME for tokens. Upon success, return zero and set TOKEN
 * to point to a NULL-terminated array of scan_tokens, i.e. the token id
 * of the last token is 0. Return non-zero otherwise. */
int
scan_file(const char* filename, struct scan_token** token)
{
	struct misc_file_buffer file;
	struct scan_token* array;
	struct scan_token* buffer;
	int pos;
	int size;
	int current;
	int rc;
	int line;

	rc = misc_get_file_buffer(filename, &file);
	if (rc)
		return rc;
	size = INITIAL_ARRAY_LENGTH;
	pos = 0;
	array = (struct scan_token*) misc_malloc(size *
						 sizeof(struct scan_token));
	if (array == NULL) {
		misc_free_file_buffer(&file);
		return -1;
	}
	memset(array, 0, size * sizeof(struct scan_token));
	line = 1;
	while ((size_t) file.pos < file.length) {
		skip_blanks(&file);
		current = misc_get_char(&file, 0);
		switch (current) {
		case '[':
			file.pos++;
			rc = scan_section_heading(&file, &array[pos++], line);
			break;
		case ':':
			file.pos++;
			rc = scan_menu_heading(&file, &array[pos++], line);
			break;
		case '#':
			file.pos++;
			skip_line(&file);
			rc = 0;
			break;
		case '\n':
			file.pos++;
			rc = 0;
			break;
		case EOF:
			rc = 0;
			break;
		default:
			if (search_line_for(&file, '=')) {
				if (isdigit(current))
					rc = scan_number_assignment(
						&file, &array[pos++], line);
				else
					rc = scan_keyword_assignment(
						&file, &array[pos++], line);
			} else {
				rc = scan_keyword_only_statement(&file,
							&array[pos++], line);
			}
		}
		if (rc)
			break;
		line++;
		/* Enlarge array if there is only one position left */
		if (pos + 1 >= size) {
			size *= 2;
			buffer = (struct scan_token *)
					misc_malloc(size *
						    sizeof(struct scan_token));
			if (buffer == NULL) {
				rc = -1;
				break;
			}
			memset(buffer, 0, size * sizeof(struct scan_token));
			memcpy(buffer, array, pos*sizeof(struct scan_token));
			free(array);
			array = buffer;
		}
	}
	misc_free_file_buffer(&file);
	if (rc)
		scan_free(array);
	else
		*token = array;
	return rc;
}
Ejemplo n.º 9
0
struct scan_token *
scan_build_automenu(struct scan_token* scan)
{
	char* entry[BOOT_MENU_ENTRIES];
	int num_entries;
	int default_entry;
	char* db_keyword[SCAN_KEYWORD_NUM];
	int db_line[SCAN_KEYWORD_NUM];
	char* sec_keyword[SCAN_KEYWORD_NUM];
	int sec_line[SCAN_KEYWORD_NUM];
	int num_targets;
	int num_sections;
	size_t size;
	struct scan_token* new_scan;
	int i;
	int i_new;
	char* name;
	char* default_name;
	int pos;

	/* Find defaultboot */
	i = scan_find_section(scan, DEFAULTBOOT_SECTION,
			      scan_id_section_heading, 0);
	/* Get defaultboot data */
	if (scan_get_section_keywords(scan, &i, DEFAULTBOOT_SECTION, db_keyword,
				      db_line, NULL, NULL))
		return NULL;
	default_name = db_keyword[(int) scan_keyword_default];
	num_targets = scan_count_target_keywords(db_keyword);
	/* Get size of scan array and number of sections */
	num_sections = 0;
	for (i = 0; scan[i].id != scan_id_empty; i++) {
		if (scan[i].id == scan_id_section_heading)
			num_sections++;
	}
	size = /* old scan array + delimiter */     i + 1 +
	       /* defaultboot heading  */           1 +
	       /* defaultmenu */                    1 +
	       /* menu heading  */                  1 +
	       /* keyword default,prompt,timeout */ 3 +
	       /* target keywords*/                 num_targets +
	       /* missing target definitions */     num_sections * num_targets +
	       /* number assigment  */              num_sections;
	size *= sizeof(struct scan_token);
	new_scan = misc_malloc(size);
	if (!new_scan)
		return NULL;
	memset(new_scan, 0, size);
	/* Fill new array */
	i = 0;
	i_new = 0;
	num_entries = 0;
	default_entry = -1;
	memset(entry, 0, sizeof(entry));
	while (scan[i].id != scan_id_empty) {
		switch (scan[i].id) {
		case scan_id_menu_heading:
			name = scan[i].content.menu.name;
			/* Abort if automenu name is already in use */
			if (strcmp(name, SCAN_AUTOMENU_NAME) == 0) {
				error_reason("Cannot build automenu: menu name "
					     "'%s' already used",
					     SCAN_AUTOMENU_NAME);
				goto err;
			}
			/* Menu sections are copied without changes */
			if (scan_copy_section(scan, new_scan, &i, &i_new))
				goto err;
			break;
		case scan_id_section_heading:
			name = scan[i].content.section.name;
			/* Do not copy old defaultboot section */
			if (strcmp(name, DEFAULTBOOT_SECTION) == 0) {
				scan_skip_section(scan, &i);
				break;
			}
			/* Get section data but do not advance index */
			pos = i;
			if (scan_get_section_keywords(scan, &pos, name,
						      sec_keyword, sec_line,
						      NULL, NULL))
				goto err;
			/* Copy section contents and advance index */
			if (scan_copy_section(scan, new_scan, &i, &i_new))
				goto err;
			/* Stop here for non-IPL sections. */
			if (scan_get_section_type(sec_keyword) != section_ipl)
				break;
			/* Is there enough room for another section? */
			if (num_entries == BOOT_MENU_ENTRIES) {
				error_reason("Cannot build automenu: too many "
					     "IPL sections defined (max %d)",
					     BOOT_MENU_ENTRIES);
				goto err;
			}
			/* Determine if this is the default entry */
			if (default_name && strcmp(default_name, name) == 0)
				default_entry = num_entries;
			entry[num_entries++] = name;
			/* Add missing target parameters if necessary */
			if (scan_count_target_keywords(sec_keyword) > 0)
				break;
			if (scan_append_target_keywords(new_scan, &i_new,
							db_keyword))
				goto err;
			break;
		default:
			/* Rule 1 */
			error_reason("Line %d: %s not allowed outside of "
				     "section", scan[i].line,
				     scan_id_name(scan[i].id));
			goto err;
		}
	}
	if (num_entries == 0) {
		error_reason("Cannot build automenu: no IPL entries available");
		goto err;
	}

	/* Append new defaultboot and automenu sections */
	/* [defaultboot] */
	if (scan_append_section_heading(new_scan, &i_new, DEFAULTBOOT_SECTION))
		goto err;
	/* defaultmenu=zipl-automatic-menu */
	if (scan_append_keyword_assignment(new_scan, &i_new,
				scan_keyword_defaultmenu, SCAN_AUTOMENU_NAME))
		goto err;
	/* :zipl-automatic-menu */
	if (scan_append_menu_heading(new_scan, &i_new, SCAN_AUTOMENU_NAME))
		goto err;
	/* default= */
	if (default_entry >= 0) {
		char str[20];

		snprintf(str, sizeof(str), "%d", default_entry + 1);
		if (scan_append_keyword_assignment(new_scan, &i_new,
						   scan_keyword_default, str))
			goto err;
	}
	/* prompt= */
	i = (int) scan_keyword_prompt;
	if (db_keyword[i]) {
		if (scan_append_keyword_assignment(new_scan, &i_new,
						   scan_keyword_prompt,
						   db_keyword[i]))
			goto err;
	}
	/* timeout= */
	i = (int) scan_keyword_timeout;
	if (db_keyword[i]) {
		if (scan_append_keyword_assignment(new_scan, &i_new,
						   scan_keyword_timeout,
						   db_keyword[i]))
			goto err;
	}
	/* target= */
	/* targetbase= */
	/* targetgeometry= */
	/* targetblocksize= */
	/* targetoffset= */
	if (scan_append_target_keywords(new_scan, &i_new, db_keyword))
		goto err;
	/* <num>=<section name>*/
	for (i = 0; i < num_entries; i++) {
		if (scan_append_number_assignment(new_scan, &i_new, i + 1,
						  entry[i]))
			goto err;
	}

	return new_scan;

err:
	scan_free(new_scan);
	return NULL;
}
Ejemplo n.º 10
0
gint read_rietica(gchar *filename, struct model_pak *model)
{
gint i, phases=0, skip, num_tokens;
gchar **buff, *line;
float x, y, z;
gpointer scan;
GSList *list;
struct core_pak *core;

/* checks */
g_assert(model != NULL);
scan = scan_new(filename);
if (!scan)
  return(1);

/* FIXME - stop the previous file routines setting this */
model->id = -1;

while (!scan_complete(scan))
  {
  buff = scan_get_tokens(scan, &num_tokens);
  
/* search for structure start */
  if (num_tokens)
    {
    if (g_ascii_strncasecmp(*buff, "***", 3) == 0)
      {
      if (phases)
        model = model_new();
      phases++;

/* structure name - omit the 1st and last tokens (ie "***") */
      if (num_tokens > 1)
        {
        g_free(*(buff+num_tokens-1));
        *(buff+num_tokens-1) = NULL;
        g_free(model->basename);
        model->basename = g_strjoinv(" ", buff+1);
        }

/* parse spacegroup */
      line = scan_get_line(scan);
      line = scan_get_line(scan);
      model->sginfo.spacename = g_strstrip(g_strdup(line));
      model->sginfo.spacenum = -1;

/* parse a structure */
      skip = 0;
      while (!scan_complete(scan))
        {
        g_strfreev(buff);
        buff = scan_get_tokens(scan, &num_tokens);

        if (num_tokens)
          {
          if (elem_symbol_test(*buff))
            {
/* new core */
/*
            if (num_tokens > 6)
*/
              {
              core = new_core(*buff, model);
              model->cores = g_slist_prepend(model->cores, core);

/* formatted output can result in -ve signs "joining" tokens */
              line = scan_cur_line(scan);
/* no doubt some fortran programmer thought this was a clever format */
              sscanf(line, "%*16c%8f%8f%8f", &x, &y, &z);
              VEC3SET(core->x, x, y, z);

/*
printf("> %s", line);
P3VEC(" - ", core->x);
              core->x[0] = str_to_float(*(buff+2));
              core->x[1] = str_to_float(*(buff+3));
              core->x[2] = str_to_float(*(buff+4));
              core->sof = str_to_float(*(buff+6));
*/

              skip = 0;
              }
            }
          else
            skip++;
          }

/* 4 lines after the last core - parse cell info and terminate structure */
        if (skip == 4)
          {
          if (num_tokens > 5)
            {
            for (i=6 ; i-- ; )
              model->pbc[i] = str_to_float(*(buff+i));
            model->pbc[3] *= D2R;
            model->pbc[4] *= D2R;
            model->pbc[5] *= D2R;
            }
          break;
          }
        }
      }
    }
  g_strfreev(buff);
  }

/* setup all new structures */
for (list=sysenv.mal ; list ; list=g_slist_next(list))
  {
  model = list->data;

  if (model->id == -1)
    {
    model->id = RIETICA;
    model->periodic = 3;
    model->fractional = TRUE;
    strcpy(model->filename, filename);
    model->cores = g_slist_reverse(model->cores);
    model_prep(model);
    }
  }

scan_free(scan);

return(0);
}