Exemplo n.º 1
0
static int parse_names(char **string,int *n_names,char **names)
{
  int i;
  
  *n_names=0;
  while ((isalnum_star((*string)[0]) || ((*string)[0]==' '))) {
    if (isalnum_star((*string)[0])) {
      if (*n_names >= MAXNAMES) 
	gmx_fatal(FARGS,"To many names: %d\n",*n_names+1);
      i=0;
      while (isalnum_star((*string)[i])) {
	names[*n_names][i]=(*string)[i];
	i++;
	if (i > NAME_LEN) {
	  printf("Name is too long, the maximum is %d characters\n",NAME_LEN);
	  return 0;
	}
      }
      names[*n_names][i]='\0';
      if (!bCase)
	upstring(names[*n_names]);
      *string += i;
      (*n_names)++;
    }
    else
      (*string)++;
  }  

  return *n_names;
}
Exemplo n.º 2
0
int find_group(char s[], int ngrps, char **grpname)
{
  int aa, i, n;
  char string[STRLEN];
  gmx_bool bMultiple;
  
  bMultiple = FALSE;
  n = strlen(s);
  aa=NOTSET;
  /* first look for whole name match */
  if (aa==NOTSET)
    for(i=0; i<ngrps; i++)
      if (gmx_strcasecmp_min(s,grpname[i])==0) {
	if(aa!=NOTSET)
	  bMultiple = TRUE;
	aa=i;
      }
  /* second look for first string match */
  if (aa==NOTSET)
    for(i=0; i<ngrps; i++)
      if (gmx_strncasecmp_min(s,grpname[i],n)==0) {
	if(aa!=NOTSET)
	  bMultiple = TRUE;
	aa=i;
      }
  /* last look for arbitrary substring match */
  if (aa==NOTSET) {
    upstring(s);
    minstring(s);
    for(i=0; i<ngrps; i++) {
      strcpy(string, grpname[i]);
      upstring(string);
      minstring(string);
      if (strstr(string,s)!=NULL) {
	if(aa!=NOTSET)
	  bMultiple = TRUE;
	aa=i;
      }
    }
  }
  if (bMultiple) {
    printf("Error: Multiple groups '%s' selected\n", s);
    aa=NOTSET;
  }
  return aa;
}
Exemplo n.º 3
0
static void add_prop(aprop_t *ap,gmx_residuetype_t restype,
		     char *resnm,char *atomnm,
		     real p,int line) 
{
  int  i,j;
  gmx_bool bExact;
  
  j = get_prop_index(ap,restype,resnm,atomnm,&bExact);
  
  if (!bExact) {
    if (ap->nprop >= ap->maxprop) {
      ap->maxprop += 10;
      srenew(ap->resnm,ap->maxprop);
      srenew(ap->atomnm,ap->maxprop);
      srenew(ap->value,ap->maxprop);
      srenew(ap->bAvail,ap->maxprop);
      for(i=ap->nprop; (i<ap->maxprop); i++) {
	ap->atomnm[i] = NULL;
	ap->resnm[i]  = NULL;
	ap->value[i]  = 0;
	ap->bAvail[i] = FALSE;
      }
    }
    upstring(atomnm);
    upstring(resnm);
    ap->atomnm[ap->nprop] = strdup(atomnm);
    ap->resnm[ap->nprop]  = strdup(resnm);
    j = ap->nprop;
    ap->nprop++;
  }
  if (ap->bAvail[j]) {
    if (ap->value[j] == p)
      fprintf(stderr,"Warning double identical entries for %s %s %g on line %d in file %s\n",
	      resnm,atomnm,p,line,ap->db);
    else {
      fprintf(stderr,"Warning double different entries %s %s %g and %g on line %d in file %s\n"
	      "Using last entry (%g)\n",
	      resnm,atomnm,p,ap->value[j],line,ap->db,p);
      ap->value[j] = p;
    }
  }
  else {
    ap->bAvail[j] = TRUE;
    ap->value[j]  = p;
  }
}
Exemplo n.º 4
0
void do_view(const output_env_t oenv, const char *fn, const char *opts)
{
    char        buf[STRLEN], env[STRLEN];
    const char *cmd;
    int         ftp, n;

    if (output_env_get_view(oenv) && fn)
    {
        if (getenv("DISPLAY") == NULL)
        {
            fprintf(stderr, "Can not view %s, no DISPLAY environment variable.\n", fn);
        }
        else
        {
            ftp = fn2ftp(fn);
            sprintf(env, "GMX_VIEW_%s", ftp2ext(ftp));
            upstring(env);
            switch (ftp)
            {
                case efXVG:
                    if (!(cmd = getenv(env)) )
                    {
                        if (getenv("GMX_USE_XMGR") )
                        {
                            cmd = "xmgr";
                        }
                        else
                        {
                            cmd = "xmgrace";
                        }
                    }
                    break;
                default:
                    if ( (n = can_view(ftp)) )
                    {
                        if (!(cmd = getenv(env)) )
                        {
                            cmd = view_program[n];
                        }
                    }
                    else
                    {
                        fprintf(stderr, "Don't know how to view file %s", fn);
                        return;
                    }
            }
            if (strlen(cmd) )
            {
                sprintf(buf, "%s %s %s &", cmd, opts ? opts : "", fn);
                fprintf(stderr, "Executing '%s'\n", buf);
                if (0 != system(buf) )
                {
                    gmx_fatal(FARGS, "Failed executing command: %s", buf);
                }
            }
        }
    }
}
Exemplo n.º 5
0
gmx_bool gmx_atomprop_query(gmx_atomprop_t aps,
			int eprop,const char *resnm,const char *atomnm,
			real *value)
{
  gmx_atomprop *ap = (gmx_atomprop*) aps;
  size_t i;
  int  j;
#define MAXQ 32
  char atomname[MAXQ],resname[MAXQ];
  gmx_bool bExact;

  set_prop(aps,eprop);
  if ((strlen(atomnm) > MAXQ-1) || (strlen(resnm) > MAXQ-1)) {
    if (debug)
      fprintf(debug,"WARNING: will only compare first %d characters\n",
	      MAXQ-1);
  }
  if (isdigit(atomnm[0])) {
    /* put digit after atomname */
    for (i=1; (i<min(MAXQ-1,strlen(atomnm))); i++)
      atomname[i-1] = atomnm[i];
    atomname[i-1] = atomnm[0];
    atomname[i]   = '\0';
  } 
  else { 
    strncpy(atomname,atomnm,MAXQ-1);
  }
  upstring(atomname);
  strncpy(resname,resnm,MAXQ-1);
  upstring(resname);
  
  j = get_prop_index(&(ap->prop[eprop]),ap->restype,resname,
		     atomname,&bExact);
  
  if (j >= 0) {
    *value = ap->prop[eprop].value[j];
    return TRUE;
  }
  else {
    *value = ap->prop[eprop].def;
    return FALSE;
  }
}
Exemplo n.º 6
0
/* Print CPU information */
int print_cpuinfo(void)
{
	char soc_name[10];

	strncpy(soc_name, CONFIG_SYS_SOC, 10);
	upstring(soc_name);
	puts(soc_name);
	puts("\n");

	/* TBD: Add printf of major/minor rev info, stepping, etc. */
	return 0;
}
Exemplo n.º 7
0
void do_view(char *fn, char *opts)
{
#define N_EXT 3
  char buf[STRLEN], env[20], ext[N_EXT], *cmd, *defopts=NULL;
  int ftp, n;
  char *disp;


  if (bDoView() && fn) {
#ifdef SPEC_CPU
    disp = NULL;
#else
    disp = getenv("DISPLAY");
#endif
    if (disp == NULL) {
      fprintf(stderr,"Can not view %s, no DISPLAY environment variable.\n",fn);
    } else {
      ftp=fn2ftp(fn);
      strncpy(ext, ftp2ext(ftp), N_EXT);
      upstring(ext);
      sprintf(env, "GMX_VIEW_%s", ext);
      if ( (n=can_view(ftp)) ) {
#ifdef SPEC_CPU
	cmd = NULL;
#else
	cmd = getenv(env);
#endif
	if ( ! cmd )
	  cmd=view_program[n];
      } else {
	fprintf(stderr,"Don't know how to view file %s",fn);
	return;
      }
      /* Add command line option -nxy for xmgrace */
      if (ftp == efXVG && strcmp(cmd,"xmgrace") == 0)
	defopts = "-nxy";
      if ( strlen(cmd) ) {
	sprintf(buf,"%s %s%s%s%s%s &",
		cmd,
		opts ? opts : "",opts ? " " : "",
		defopts ? defopts : "",defopts ? " " : "",
		fn);
	fprintf(stderr,"Executing '%s'\n",buf);
	system(buf);
      }
    }
  }
}
Exemplo n.º 8
0
        /* {{{ MySQL_ArtResultSet::findColumn() -I- */
        uint32_t
        MySQL_ArtResultSet::findColumn(const sql::SQLString& columnLabel) const
        {
            CPP_ENTER("MySQL_ArtResultSet::columnLabel");
            checkValid();

            boost::scoped_array< char > upstring(sql::mysql::util::utf8_strup(columnLabel.c_str(), 0));

            FieldNameIndexMap::const_iterator iter = field_name_to_index_map.find(upstring.get());

            if (iter == field_name_to_index_map.end()) {
                return 0;
            }
            /* findColumn returns 1-based indexes */
            return iter->second + 1;
        }
Exemplo n.º 9
0
void do_view(const output_env_t oenv,const char *fn, const char *opts)
{
  char buf[STRLEN], env[STRLEN];
  const char *cmd;
  int ftp, n;
  
  if (output_env_get_view(oenv) && fn) {
    if (getenv("DISPLAY") == NULL) {
      fprintf(stderr,"Can not view %s, no DISPLAY environment variable.\n",fn);
    } else {
      ftp=fn2ftp(fn);
      sprintf(env, "GMX_VIEW_%s", ftp2ext(ftp));
      upstring(env);
      switch(ftp) {
      case efXVG:
	if ( ! (cmd=getenv(env)) ) {
	  if ( getenv("XMGR") )
	    cmd="xmgr";
	  else
	    cmd="xmgrace";
	}
	break;
      default:
      if ( (n=can_view(ftp)) ) {
	if ( ! (cmd=getenv(env)) )
	  cmd=view_program[n];
      } else {
	fprintf(stderr,"Don't know how to view file %s",fn);
	return;
      }
      }
      if ( strlen(cmd) ) {
	sprintf(buf,"%s %s %s &",cmd,opts ? opts : "",fn);
	fprintf(stderr,"Executing '%s'\n",buf);
#ifdef GMX_NO_SYSTEM
        printf("Warning-- No calls to system(3) supported on this platform.");
        printf("Warning-- Skipping execution of 'system(\"%s\")'.", buf);
#else
	if( 0 != system(buf) )
	{
	  gmx_fatal(FARGS,"Failed executing command: %s",buf);
	}
#endif
      }
    }
  }
}
Exemplo n.º 10
0
        /* {{{ MySQL_ArtResultSet::MySQL_ArtResultSet() -I- */
        MySQL_ArtResultSet::MySQL_ArtResultSet(const StringList& fn, rset_t* const rs, boost::shared_ptr< MySQL_DebugLogger > & l)
            : num_fields(static_cast<int>(fn.size())), rset(rs), current_record(rset->begin()),
              started(false), field_index_to_name_map(new sql::SQLString[num_fields]),
              num_rows(rset->size()), row_position(0), is_closed(false), logger(l)
        {
            CPP_ENTER("MySQL_ArtResultSet::MySQL_ArtResultSet");
            CPP_INFO_FMT("metadata.size=%d resultset.size=%d", fn.size(), rset->size());

            //	field_index_to_name_map = new sql::SQLString[num_fields];

            unsigned int idx = 0;
            for (StringList::const_iterator it = fn.begin(), e = fn.end(); it != e; ++it, ++idx) {
                boost::scoped_array< char > upstring(sql::mysql::util::utf8_strup(it->c_str(), 0));
                field_name_to_index_map[sql::SQLString(upstring.get())] = idx;
                field_index_to_name_map[idx] = upstring.get();
            }

            meta.reset(new MySQL_ArtResultSetMetaData(this, logger));
        }
Exemplo n.º 11
0
void do_addhelp(CHAR_DATA *ch, char *argument)
{
	MYSQL *conn;
	char buf[MSL*3], title[MSL], skill[MSL], arg[MSL], *ttitle;
	char *escape, *escape2;
	int minlevel;
	if(!str_cmp(argument,""))
	{
		send_to_char("Syntax: addhelp edit\n\r",ch);
		send_to_char("Syntax: addhelp 'help title' 'skill required' minimumlevel\n\r",ch);
		send_to_char("Example: addhelp 'HELP NEW FORMAT' 'none' 0\n\r",ch);
		send_to_char("Any words in the title will be keywords, case insensitive, that the help command searches for.\n\r",ch);
		send_to_char("The skill required is the name of a skill you must have at 1% or greater to view the help.\n\r",ch);
		send_to_char("It should only be used for cabal power helpfiles and other semi-secret helpfiles and should be 'none' otherwise.\n\r",ch);
		send_to_char("Minimum level is the minimum level required to view this helpfile, and should have a 0 if it's not\n\r",ch);
		send_to_char("an immortal or level dependant helpfile.\n\r",ch);
		send_to_char("Addhelp edit will allow you to change and add the actual text of your helpfile, and must be done first.\n\r",ch);
		return;
	}
	if(!str_cmp(argument, "edit"))
		return enter_text(ch, addhelp_end_fun);
	if(!ch->pcdata->entered_text || ch->pcdata->entered_text[0] == '\0' || !str_cmp(ch->pcdata->entered_text, ""))
		return send_to_char("You haven't specified the contents of your helpfile.\n\r",ch);
	conn = open_conn();
        if(!conn)
                return send_to_char("Error opening help database.\n\r",ch);
	argument = one_argument(argument,title);
	argument = one_argument(argument,skill);
	argument = one_argument(argument,arg);
	ttitle = palloc_string(upstring(title));
	minlevel = atoi(arg);
	escape = (char *)escape_string(ttitle);
	escape2 = (char *)escape_string(ch->pcdata->entered_text);
	sprintf(buf,"INSERT INTO helpfiles VALUES(NULL, \"%s\", \"%s\", %d, \"%s\")",
		escape, skill, minlevel, escape2);
	mysql_query(conn, buf);
	sprintf(buf,"Help file added:\n\rTitle: %s\n\rSkill Required: %s\n\rMinimum Level: %d\n\rHelp Text: %s\n\r",
			ttitle, skill, minlevel, ch->pcdata->entered_text);
	send_to_char(buf,ch);
	do_disc(conn);
}
Exemplo n.º 12
0
/*! \brief Support handling restarts
 *
 * \todo Clean this up (next patch)
 *
 * Read just the simulation 'generation' and with bTryToAppendFiles check files.
 * This is is needed at the beginning of mdrun,
 * to be able to rename the logfile correctly.
 * When file appending is requested, checks which output files are present,
 * and returns TRUE/FALSE in bDoAppendFiles if all or none are present.
 * If only some output files are present, give a fatal error.
 * When bDoAppendFiles is TRUE upon return, bAddPart will tell whether the simulation part
 * needs to be added to the output file name.
 *
 * This routine cannot print tons of data, since it is called before
 * the log file is opened. */
static void
read_checkpoint_data(const char *filename, int *simulation_part,
                     t_commrec *cr,
                     gmx_bool bTryToAppendFiles,
                     int nfile, const t_filenm fnm[],
                     const char *part_suffix,
                     gmx_bool *bAddPart,
                     gmx_bool *bDoAppendFiles)
{
    t_fileio            *fp;
    int                  nfiles;
    gmx_file_position_t *outputfiles;
    int                  nexist, f;
    char                *fn, suf_up[STRLEN];

    *bDoAppendFiles = FALSE;

    if (SIMMASTER(cr))
    {
        if (!gmx_fexist(filename) || (!(fp = gmx_fio_open(filename, "r")) ))
        {
            *simulation_part = 0;
        }
        else
        {
            read_checkpoint_simulation_part_and_filenames(fp,
                                                          simulation_part,
                                                          &nfiles,
                                                          &outputfiles);

            if (bTryToAppendFiles)
            {
                nexist = 0;
                for (f = 0; f < nfiles; f++)
                {
                    if (exist_output_file(outputfiles[f].filename, nfile, fnm))
                    {
                        nexist++;
                    }
                }
                if (nexist == nfiles)
                {
                    *bDoAppendFiles = bTryToAppendFiles;
                }
                else if (nexist > 0)
                {
                    fprintf(stderr,
                            "Output file appending has been requested,\n"
                            "but some output files listed in the checkpoint file %s\n"
                            "are not present or are named differently by the current program:\n",
                            filename);
                    fprintf(stderr, "output files present:");
                    for (f = 0; f < nfiles; f++)
                    {
                        if (exist_output_file(outputfiles[f].filename,
                                              nfile, fnm))
                        {
                            fprintf(stderr, " %s", outputfiles[f].filename);
                        }
                    }
                    fprintf(stderr, "\n");
                    fprintf(stderr, "output files not present or named differently:");
                    for (f = 0; f < nfiles; f++)
                    {
                        if (!exist_output_file(outputfiles[f].filename,
                                               nfile, fnm))
                        {
                            fprintf(stderr, " %s", outputfiles[f].filename);
                        }
                    }
                    fprintf(stderr, "\n");

                    gmx_fatal(FARGS, "File appending requested, but %d of the %d output files are not present or are named differently", nfiles-nexist, nfiles);
                }
            }

            if (*bDoAppendFiles)
            {
                if (nfiles == 0)
                {
                    gmx_fatal(FARGS, "File appending requested, but no output file information is stored in the checkpoint file");
                }
                fn = outputfiles[0].filename;
                if (strlen(fn) < 4 ||
                    gmx_strcasecmp(fn+strlen(fn)-4, ftp2ext(efLOG)) == 0)
                {
                    gmx_fatal(FARGS, "File appending requested, but the log file is not the first file listed in the checkpoint file");
                }
                /* Set bAddPart to whether the suffix string '.part' is present
                 * in the log file name.
                 */
                strcpy(suf_up, part_suffix);
                upstring(suf_up);
                *bAddPart = (strstr(fn, part_suffix) != NULL ||
                             strstr(fn, suf_up) != NULL);
            }

            sfree(outputfiles);
        }
    }
    if (PAR(cr))
    {
        gmx_bcast(sizeof(*simulation_part), simulation_part, cr);

        if (*simulation_part > 0 && bTryToAppendFiles)
        {
            gmx_bcast(sizeof(*bDoAppendFiles), bDoAppendFiles, cr);
            gmx_bcast(sizeof(*bAddPart), bAddPart, cr);
        }
    }
}