Example #1
0
Stringc Stringc::get_line(int iline)
{
   int i = 0;
   int il = 0;
   int istart = 0;
   int iend = 0;

// Find the start and end location of the desired iline'th line.

   while ( i < num_chars && il <= iline)
      {

//    Step through spaces

      while ( i< num_chars && (char_array[i] == '\n')) i++;

//    Step through a line and save its start and end location if it
//    is the desired iline.

      if ( i < num_chars )
         {
         if ( il == iline) istart = i;
         while ( i < num_chars && char_array[i] != '\n' ) 
            {
            if ( il == iline) iend = i;
            i++;
            }
         il++;
         }
      }

// Extract the line string from the character array if iline exists.

   if ( iline < il && iline >= 0)
      {
      int line_size = iend-istart+1;
      Stringc sline(line_size);
      for ( i=0; i<line_size; i++)
         {
         sline[i] = char_array[istart+i];
         }
      sline[line_size] = '\0';
      return sline;
      }
   else
      {
      cout << "\nError in Stringc::get_line routine.\n";
      if ( iline < 0 ) 
         cout << "   Negative line index does not make sense.\n";
      else
         cout << "   Line index is greater than the number of lines.\n";
      cout << "   Returning an empty string as line\n";
      Stringc sline(1);
      sline[0] = '\0';
      return sline;
      }
}
Example #2
0
std::vector<calibRecord> getVectorCalibTableFromFile(const char* filename)
{
  std::vector<calibRecord> mycalibTable;
  
  std::ifstream myfile(filename);
  std::string line;
  if (myfile.is_open())
  {
    mycalibTable.clear();
    while (getline(myfile,line))
    {
      calibRecord calib;
      std::stringstream sline(line);
      sline >> calib.idx
      >> calib.ix
      >> calib.iy
      >> calib.iz
      >> calib.c
      >> calib.cerr
      >> calib.fixed
      >> calib.nfits ;
      mycalibTable.push_back(calib);
    }
    myfile.close();
  }
 vector<string> fullJustify(vector<string> &words, int L) {
     vector<string> vret;
     
     const int n = words.size();
     int i = 0;
     while (i < n)
     {
         // expand line
         int len = words[i].size();  // get first word
         int j = i + 1;
         while ((j < n) && ((len + words[j].size() + j-i) <= L) )  // cur len + next word + spaces(at least one)
             len += words[j++].size();   // add one word;
         
         // connect words for a line
         bool isLastLine = (j == n);   // special case
         bool isOneWord = (j-i == 1);
         
         int avrg = (isLastLine || isOneWord) ? 1 : (L-len) / (j-i-1);  // avrg spaces for a interval
         int extra = (isLastLine || isOneWord) ? 0 : (L-len) % (j-i-1); // extra spaces, will be assigned on the right
         
         string sline(words[i]);
         for (int k = i + 1; k < j; ++k)
         {
             sline.append((extra > 0) ? avrg+1 : avrg, ' ');  // spaces: avrg + extra(1)
             sline.append(words[k]);
             --extra;
         }
         sline.append(L - sline.size(), ' ');   // left spaces for left-justified
         
         vret.push_back(sline);  // save sline
         
         i = j;   // caution: move one!!!
     }
     return vret;
 }
Example #4
0
bool
CMap::on_load(std::string filename) {
  tile_list.clear();

  std::ifstream input_file(filename.c_str());

  if (!input_file.is_open())
    return false;

  for (int y = 0; y < MAP_HEIGHT; ++y) {
    std::string line;
    getline(input_file, line);
    std::stringstream sline(line);
    for (int x = 0; x < MAP_WIDTH; ++x) {
      CTile tmp_tile;

      std::string token;
      getline(sline, token, ' ');
      std::stringstream ss(token);
      ss >> tmp_tile.tile_id;
      ss.seekg(ss.tellg() + (long)1);
      ss >> tmp_tile.type_id;

      tile_list.push_back(tmp_tile);
    }
  }
  input_file.close();

  return true;
}
Example #5
0
//______________________________________________________________________________
void ReadIntegers(const char* filename, std::vector<int>& integers)
{
  /// Read integers from filename, where integers are either
  /// separated by "," or by return carriage
  ifstream in(gSystem->ExpandPathName(filename));
  int i;

  char line[10000];

  in.getline(line,10000,'\n');

  TString sline(line);

  if (sline.Contains(","))
  {
    TObjArray* a = sline.Tokenize(",");
    TIter next(a);
    TObjString* s;
    while ( ( s = static_cast<TObjString*>(next()) ) )
    {
      integers.push_back(s->String().Atoi());
    }
  }
  else
  {
    integers.push_back(sline.Atoi());

    while ( in >> i )
    {
      integers.push_back(i);
    }
  }

  std::sort(integers.begin(),integers.end());
}
Example #6
0
TimeIntegrator::TimeIntegrator(Eigen::VectorXd &napp, std::ifstream &dyn_id, double &mass)
{
    _napp = napp;

    std::string line;
    if (dyn_id.is_open())
    {
        std::vector<double> F_std, T_std;
        while (dyn_id.good())
        {
            while(std::getline(dyn_id,line,'\n'))
            {
                // Ignore blank lines in the begining of the file (if any)
                if(line.empty()) continue;
                // Trim white space from the beginning of the string
                line.erase(line.begin(), std::find_if(line.begin(), line.end(), std::not1(std::ptr_fun<int, int>(isspace))));
                // If line starts with /, //, #, * and %, ignore it
                if(line[0] == '#' || line[0]=='/' || line[0]=='%' || line[0]=='*') continue;

                // Read data
                // Note: automatically rules out strings and does not convert them. No need for checking
                std::vector<double> inputs;
                std::istringstream sline(line);
                std::copy( std::istream_iterator<double>(sline),std::istream_iterator<double>(),std::back_inserter(inputs));

                // Build Piezoelectric Matrix
                if (inputs.size()==2)
                {
                    T_std.push_back(inputs[0]);
                    F_std.push_back(inputs[1]);
                }
            }
        }
        // Determine nstep, dt, F1
        // Map F1 using temp
        Eigen::Map<Eigen::VectorXd> Acc_temp(F_std.data(),F_std.size());
        F1=Acc_temp*mass; // accecelaration into mass
        _nstep = T_std.size();
        for (unsigned int i=0; i<T_std.size(); ++i)
        {
            if (T_std[i+1]>T_std[i])
            {
                _dt = T_std[i+1]-T_std[i];
                break;
            }
            else
            {
                // Turn this off for GUI mode
//                throw std::invalid_argument("Could not determine time-step size");
            }
        }
    }
    else
    {
        // Turn this off for GUI mode
//        throw std::invalid_argument("Could not open the file!");
    }
}
Example #7
0
void renderscore(Sprite *d) {
	IString lag;
	IString name;
	std::sprintf(lag, "%d", d->plag);
	std::sprintf(name, "(%s)", d->name);
	scorelines.emplace_back(sline());
	std::sprintf(scorelines.back().s, "%d\t%s\t%d\t%s\t%s", d->frags,
			d->state == CS_LAGGED ? "LAG" : lag, d->ping, d->team,
			d->state == CS_DEAD ? name : d->name);
	menumanual(0, scorelines.size() - 1, scorelines.back().s);
}
Example #8
0
/*
 * read synatag/paradigmatic value from file
 * return map {fromTerm, toTerm, sim}
 * on condition that sim >= threshold
 */
map< string, map<string, double> > readSim(vector<string> &terms, string fin, char fromORto, double threshold, char delim)
{
    // input file
    ifstream filein(fin.c_str());
    if (!filein)
    {
        cout << "Error: can't open " << fin << endl;
        exit (-1);
    }
    if (fromORto!='f' && fromORto!='t')
    {
        cout << "Warning: invalid input in fromORto (f/t)! Use defaulted value f" << endl;
        fromORto = 'f';
    }

    map< string, map<string, double> > synFrom;  // {from, to, syntag}
    map< string, map<string, double> > synTo;    // {to, from, syntag}
    map< string, map<string, double> > score;
    
    // read data from file {from, to syntag}
    string line, fromTerm, toTerm, token;
    double syntag;
    cout << "reading file " << fin << endl;
    while (getline(filein, line))
    {
        stringstream sline(line.c_str());
        getline(sline, fromTerm, delim);
        getline(sline, toTerm, delim);
        getline(sline, token, delim);
        syntag = std::stod(token);
        if (syntag < threshold)
            continue;
        if (fromORto == 'f')
        {
            synFrom[fromTerm][toTerm] = syntag;
            if (find(terms.begin(), terms.end(), fromTerm) == terms.end())
                terms.push_back(fromTerm);
        }
        else
        {
            synTo[toTerm][fromTerm] = syntag;
            if (find(terms.begin(), terms.end(), toTerm) == terms.end())
                terms.push_back(toTerm);
        }
    }
    cout << "loading done!" << endl;
    filein.close();
    if (fromORto == 'f') return synFrom;
    else return synTo;
}
Example #9
0
void getfield(std::ifstream &infile, std::map <std::string, std::string> &var)
{
    std::string line, vname, value;
    while (getline(infile, line))
    {
        if (line.empty()) continue;
        trimline(line);
        if (line[0] == '#' || line[0] == '!' || line[0] == '/' || line[0] == '%') continue;
        std::istringstream sline(line);
        getline(sline, vname, '=');
        getline(sline, value, '=');
        trimline(vname);
        trimline(value);
        var[vname] = value.c_str();
    }
}
Example #10
0
// get term names from input file
vector<string> getTerms(string filename)
{
    vector<string> terms;
    ifstream file(filename.c_str());
    if (!file)
    {
        cout << "Error: can't open " << filename << endl;
        exit(-1);
    }
    string line, fid;
    while (getline(file, line))
    {
        stringstream sline(line);
        getline(sline, fid, '\t');
        terms.push_back(fid);
    }
    file.close();
    return terms;
}
Example #11
0
std::vector<icrecord> getVectorICTableFromFile(const char* filename)
{
  std::vector<icrecord> ictable;
  std::ifstream myfile(filename);
  std::string line;
  if (myfile.is_open())
  {
    ictable.clear();
    while (getline(myfile,line))
    {
      icrecord calib;
      std::stringstream sline(line);
      sline >> calib.ix
             >> calib.iy
             >> calib.iz
             >> calib.c
             >> calib.cerr;
      ictable.push_back(calib);
    }
    myfile.close();
  }
Example #12
0
File: main.c Project: sisoftrg/qico
RETSIGTYPE sigerr(int sig)
{
	signal(sig,SIG_DFL);
	aso_done();
	write_log("got SIG%s signal",sigs[sig]);
	if(cfgs(CFG_PIDFILE))if(getpid()==islocked(ccs))lunlink(ccs);
	IFPerl(perl_done(1));
	log_done();
	tty_close();
	qqreset();sline("");title("");
	cls_close(ssock);
	cls_shutd(lins_sock);
	cls_shutd(uis_sock);
	switch(sig) {
	    case SIGSEGV:
	    case SIGFPE:
	    case SIGBUS:
	    case SIGABRT:
		abort();
	    default:
		exit(1);
	}
}
Example #13
0
static int hydra(int mode,int hmod,int rh1)
{
	flist_t *l;
	int rc=XFER_OK,ticskip=0;
	sline("Hydra-%dk session",hmod*2);
	hydra_init(HOPT_XONXOFF|HOPT_TELENET,mode,hmod,cfgi(CFG_HRXWIN),cfgi(CFG_HTXWIN));
	for(l=fl;l;l=l->next)
		if(l->sendas) {
			if(l->type==IS_REQ||!rh1) {
				rc=hydra_file(l->tosend,l->sendas);
				if(rc==XFER_ABORT)break;
				if(rc==XFER_OK||rc==XFER_SKIP)flexecute(l);
			}
		} else if(!rh1)flexecute(l);
	if(rc==XFER_ABORT) {
		hydra_deinit();
		return 1;
	}
	rc=hydra_file(NULL,NULL);
	for(l=fl;l;l=l->next)
		if(l->sendas) {
			rc=cfgi(CFG_AUTOTICSKIP)?ticskip:0;ticskip=0;
			if(!rc||!istic(l->tosend))rc=hydra_file(l->tosend,l->sendas);
			    else write_log("tic file '%s' auto%sed",l->tosend,rc==XFER_SKIP?"skipp":"suspend");
			if(rc==XFER_ABORT)break;
			if(rc==XFER_OK||rc==XFER_SKIP)flexecute(l);
			if(rc==XFER_SKIP||rc==XFER_SUSPEND)ticskip=rc;
		} else flexecute(l);
	if(rc==XFER_ABORT) {
		hydra_deinit();
		return 1;
	}
	rc=hydra_file(NULL,NULL);
	hydra_deinit();
	return(rc==XFER_ABORT);
}
Example #14
0
ConfigUtil::ConfigUtil(const char *path)
{
	int i;
	for (i = 0; i < sizeof(DEFAULT_SETTING) / sizeof(DEFAULT_SETTING[0]); i++)
	{
        string key(DEFAULT_SETTING[i].key);
        string val(DEFAULT_SETTING[i].val);
        items.insert(pair<string, string>(key, val));
	}
	
	ifstream ifs(path);
	if (ifs.good())
	{
		char line[1024];
		char key[1024];
		char val[1024];
		while (!ifs.eof())
		{
			ifs.getline(line, sizeof(line));
			if (line[0] == '[')
			{
				continue;
			}
			for (i = 0; line[i]; i++)
			{
				if (line[i] == ';' || line[i] == '#')
				{
					line[i] = 0;
					break;
				}
			}
			for (i--; i >= 0; i--)
			{
				if (line[i] == ' ' || line[i] == '\t')
				{
					line[i] = 0;
				}
				else
				{
					break;
				}
			}
			if (!line[0])
			{
				continue;
			}

			string sline(line);
			istringstream issline(sline);
			
			issline.getline(key, sizeof(key), ':');
			string skey(key);
			if (skey.length() == 0)
			{
				continue;
			}
			
			issline.getline(val, sizeof(val), ':');
			string sval(val);
			if (sval.length() == 0)
			{
				//continue;
			}
			
			items.erase(skey);
			items.insert(pair<string, string>(skey, sval));
		}
	}
	ifs.close();
}
void AtomInformations::loadFile(std::string fileName)
{
  std::ifstream file(fileName, std::ifstream::in);
  if (!file.is_open()) {
    std::ostringstream oss;
    oss << "Impossible to open " << fileName << " to load atom informations.";
    throw oss.str();
  }

  // On vide la map.
  m_atomInfos.clear();

  // Le fichier est ouvert.
  std::string line;
  // On ignore la première ligne puisqu'elle contient les noms des
  // colonnes.
  if (!std::getline(file, line)) {
    std::ostringstream oss;
    oss << "File " << fileName << "is empty.";
    throw oss.str();
  }

  // On boucle jusqu'à la fin du fichier.
  while (file.good()) {
    std::getline(file, line);
    std::stringstream sline(line);

    // On lit le symbol chimique.
    std::string symbol;
    if (!std::getline(sline, symbol, ',')) {
      break;
    }

    // Le tableau pour les colonnes.
    std::vector<std::string> columns;
    std::string value;
    // On boucle sur toutes les colonnes.
    for (int i = 0; i < AtomInformations::COLUMN_NUMBER; ++i) {
      if (!std::getline(sline, value, ',')) {
        // Pas de valeur dans la colonne.
        std::ostringstream oss;
        oss << "No value in " << fileName << ", column " << i + 2 << ".";
        throw oss.str();
      }
      if (value == "") {
        // Chaine vide dans la colonne.
        std::ostringstream oss;
        oss << "Empty value in " << fileName << ", column " << i + 2 << ".";
        throw oss.str();
      }
      columns.push_back(value);
    }
    // On ajoute l'association symbol-colonnes à la map.
    m_atomInfos.insert(std::pair<std::string, std::vector<std::string>>(symbol, columns));
  }

  if (m_atomInfos.empty()) {
        // Fichier ne contenant aucune donnée.
        std::ostringstream oss;
        oss << "File " << fileName << "is empty.";
        throw oss.str();
  }
}
Example #16
0
void TextEdit::updateScreenLines(const char *begin, const char *end)
{
  g_assert(begin);
  g_assert(end);

  int realw;
  if (!area || (realw = area->getmaxx()) <= 1)
    return;

  ScreenLines::iterator b, i;
  b = std::lower_bound(screen_lines.begin(), screen_lines.end(), begin,
      TextEdit::CmpScreenLineEnd());
  if (b != screen_lines.begin()) {
    /*
     *  Initial      Correct final
     * situation      situation
     * ---------      ---------
     * |aaaa   |  ->  |aaaa b |
     * |bcdddd |      |cdddd  |
     *
     * User inserts a space in front of the 'c' character. The 'b' string can
     * be moved on the previous line thus one more extra line before has to be
     * recalculated to handle the situation correctly.
     */
    b--;
  }
  i = b;

  ScreenLines new_screen_lines;

  const char *p = b->start;
  if (i == screen_lines.begin())
    p = getTextStart();

  while (p < bufend) {
    const char *s = p;
    size_t length;
    // lower max width by one to make a room for the cursor
    p = getScreenLine(p, realw - 1, &length);
    ScreenLine sline(s, p, length);
    new_screen_lines.push_back(sline);
    while (i != screen_lines.end() && (i->end <= end || i->start < s
          || i->end < p))
      i++;
    if (i != screen_lines.end() && sline == *i) {
      /* Screen lines are same thus it isn't necessary to recalculate more
       * screen lines. */
      break;
    }
  }
  if (i != screen_lines.end())
    i++;

  /*
  g_debug("UpdateScreenLines(), new_lines=%d, old_lines=%d",
      new_screen_lines.size(), i - b);
  */

  // replace old screen lines with new screen lines
  ScreenLines::iterator j;
  for (j = new_screen_lines.begin(); j != new_screen_lines.end() && b != i;
      j++, b++)
    *b = *j;

  if (j != new_screen_lines.end()) {
    // b == i
    screen_lines.insert(b, j, new_screen_lines.end());
  }
  else {
    // b != i
    screen_lines.erase(b, i);
  }
}
Example #17
0
int32 map_config_read(const int8* cfgName)
{
    int8 line[1024], w1[1024], w2[1024];
    FILE* fp;

    fp = fopen(cfgName, "r");
    if (fp == nullptr)
    {
        ShowError("Map configuration file not found at: %s\n", cfgName);
        return 1;
    }

    while (fgets(line, sizeof(line), fp))
    {
        int8* ptr;

        if (line[0] == '#')
        {
            continue;
        }
        if (sscanf(line, "%[^:]: %[^\t\r\n]", w1, w2) < 2)
        {
            continue;
        }

        //Strip trailing spaces
        ptr = w2 + strlen(w2);
        while (--ptr >= w2 && *ptr == ' ');
        ptr++;
        *ptr = '\0';

        if (strcmpi(w1, "timestamp_format") == 0)
        {
            strncpy(timestamp_format, w2, 20);
        }
        else if (strcmpi(w1, "stdout_with_ansisequence") == 0)
        {
            stdout_with_ansisequence = config_switch(w2);
        }
        else if (strcmpi(w1, "console_silent") == 0)
        {
            ShowInfo("Console Silent Setting: %d", atoi(w2));
            msg_silent = atoi(w2);
        }
        else if (strcmpi(w1, "map_port") == 0)
        {
            map_config.usMapPort = (atoi(w2));
        }
        else if (strcmp(w1, "buff_maxsize") == 0)
        {
            map_config.buffer_size = atoi(w2);
        }
        else if (strcmp(w1, "max_time_lastupdate") == 0)
        {
            map_config.max_time_lastupdate = atoi(w2);
        }
        else if (strcmp(w1, "vanadiel_time_offset") == 0)
        {
            map_config.vanadiel_time_offset = atoi(w2);
        }
        else if (strcmp(w1, "lightluggage_block") == 0)
        {
            map_config.lightluggage_block = atoi(w2);
        }
        else if (strcmp(w1, "exp_rate") == 0)
        {
            map_config.exp_rate = atof(w2);
        }
        else if (strcmp(w1, "exp_loss_rate") == 0)
        {
            map_config.exp_loss_rate = atof(w2);
        }
        else if (strcmp(w1, "exp_party_gap_penalties") == 0)
        {
            map_config.exp_party_gap_penalties = atof(w2);
        }
        else if (strcmp(w1, "fov_party_gap_penalties") == 0)
        {
            map_config.fov_party_gap_penalties = atof(w2);
        }
        else if (strcmp(w1, "fov_allow_alliance") == 0)
        {
            map_config.fov_allow_alliance = atof(w2);
        }
        else if (strcmp(w1, "mob_tp_multiplier") == 0)
        {
            map_config.mob_tp_multiplier = atof(w2);
        }
        else if (strcmp(w1, "player_tp_multiplier") == 0)
        {
            map_config.player_tp_multiplier = atof(w2);
        }
        else if (strcmp(w1, "nm_hp_multiplier") == 0)
        {
            map_config.nm_hp_multiplier = atof(w2);
        }
        else if (strcmp(w1, "mob_hp_multiplier") == 0)
        {
            map_config.mob_hp_multiplier = atof(w2);
        }
        else if (strcmp(w1, "player_hp_multiplier") == 0)
        {
            map_config.player_hp_multiplier = atof(w2);
        }
        else if (strcmp(w1, "nm_mp_multiplier") == 0)
        {
            map_config.nm_mp_multiplier = atof(w2);
        }
        else if (strcmp(w1, "mob_mp_multiplier") == 0)
        {
            map_config.mob_mp_multiplier = atof(w2);
        }
        else if (strcmp(w1, "player_mp_multiplier") == 0)
        {
            map_config.player_mp_multiplier = atof(w2);
        }
        else if (strcmp(w1, "sj_mp_divisor") == 0)
        {
            map_config.sj_mp_divisor = atof(w2);
        }
        else if (strcmp(w1, "nm_stat_multiplier") == 0)
        {
            map_config.nm_stat_multiplier = atof(w2);
        }
        else if (strcmp(w1, "mob_stat_multiplier") == 0)
        {
            map_config.mob_stat_multiplier = atof(w2);
        }
        else if (strcmp(w1, "player_stat_multiplier") == 0)
        {
            map_config.player_stat_multiplier = atof(w2);
        }
        else if (strcmp(w1, "drop_rate_multiplier") == 0)
        {
            map_config.drop_rate_multiplier = atof(w2);
        }
        else if (strcmp(w1, "all_mobs_gil_bonus") == 0)
        {
            map_config.all_mobs_gil_bonus = atoi(w2);
        }
        else if (strcmp(w1, "max_gil_bonus") == 0)
        {
            map_config.max_gil_bonus = atoi(w2);
        }
        else if (strcmp(w1, "exp_retain") == 0)
        {
            map_config.exp_retain = dsp_cap(atof(w2), 0.0f, 1.0f);
        }
        else if (strcmp(w1, "exp_loss_level") == 0)
        {
            map_config.exp_loss_level = atoi(w2);
        }
        else if (strcmp(w1, "level_sync_enable") == 0)
        {
            map_config.level_sync_enable = atoi(w2);
        }
        else if (strcmp(w1, "all_jobs_widescan") == 0)
        {
            map_config.all_jobs_widescan = atoi(w2);
        }
        else if (strcmp(w1, "speed_mod") == 0)
        {
            map_config.speed_mod = atoi(w2);
        }
        else if (strcmp(w1, "mob_speed_mod") == 0)
        {
            map_config.mob_speed_mod = atoi(w2);
        }
        else if (strcmp(w1, "skillup_chance_multiplier") == 0)
        {
            map_config.skillup_chance_multiplier = atof(w2);
        }
        else if (strcmp(w1, "craft_chance_multiplier") == 0)
        {
            map_config.craft_chance_multiplier = atof(w2);
        }
        else if (strcmp(w1, "skillup_amount_multiplier") == 0)
        {
            map_config.skillup_amount_multiplier = atof(w2);
        }
        else if (strcmp(w1, "craft_amount_multiplier") == 0)
        {
            map_config.craft_amount_multiplier = atof(w2);
        }
        else if (strcmp(w1, "craft_day_matters") == 0)
        {
            map_config.craft_day_matters = atof(w2);
        }
        else if (strcmp(w1, "craft_moonphase_matters") == 0)
        {
            map_config.craft_moonphase_matters = atof(w2);
        }
        else if (strcmp(w1, "craft_direction_matters") == 0)
        {
            map_config.craft_direction_matters = atof(w2);
        }
        else if (strcmp(w1, "mysql_host") == 0)
        {
            map_config.mysql_host = aStrdup(w2);
        }
        else if (strcmp(w1, "mysql_login") == 0)
        {
            map_config.mysql_login = aStrdup(w2);
        }
        else if (strcmp(w1, "mysql_password") == 0)
        {
            map_config.mysql_password = aStrdup(w2);
        }
        else if (strcmp(w1, "mysql_port") == 0)
        {
            map_config.mysql_port = atoi(w2);
        }
        else if (strcmp(w1, "mysql_database") == 0)
        {
            map_config.mysql_database = aStrdup(w2);
        }
        else if (strcmpi(w1, "import") == 0)
        {
            map_config_read(w2);
        }
        else if (strcmpi(w1, "newstyle_skillups") == 0)
        {
            map_config.newstyle_skillups = atoi(w2);
        }
        else if (strcmp(w1, "Battle_cap_tweak") == 0)
        {
            map_config.Battle_cap_tweak = atoi(w2);
        }
        else if (strcmp(w1, "CoP_Battle_cap") == 0)
        {
            map_config.CoP_Battle_cap = atoi(w2);
        }
        else if (strcmp(w1, "max_merit_points") == 0)
        {
            map_config.max_merit_points = atoi(w2);
        }
        else if (strcmp(w1, "yell_cooldown") == 0)
        {
            map_config.yell_cooldown = atoi(w2);
        }
        else if (strcmp(w1, "audit_chat") == 0)
        {
            map_config.audit_chat = atoi(w2);
        }
        else if (strcmp(w1, "audit_say") == 0)
        {
            map_config.audit_say = atoi(w2);
        }
        else if (strcmp(w1, "audit_shout") == 0)
        {
            map_config.audit_shout = atoi(w2);
        }
        else if (strcmp(w1, "audit_tell") == 0)
        {
            map_config.audit_tell = atoi(w2);
        }
        else if (strcmp(w1, "audit_yell") == 0)
        {
            map_config.audit_yell = atoi(w2);
        }
        else if (strcmp(w1, "audit_linkshell") == 0)
        {
            map_config.audit_linkshell = atoi(w2);
        }
        else if (strcmp(w1, "audit_party") == 0)
        {
            map_config.audit_party = atoi(w2);
        }
        else if (strcmp(w1, "msg_server_port") == 0)
        {
            map_config.msg_server_port = atoi(w2);
        }
        else if (strcmp(w1, "msg_server_ip") == 0)
        {
            map_config.msg_server_ip = aStrdup(w2);
        }
        else
        {
            ShowWarning(CL_YELLOW"Unknown setting '%s' in file %s\n" CL_RESET, w1, cfgName);
        }
    }

    fclose(fp);

    // Load the English server message..
    fp = fopen("./conf/server_message.conf", "rb");
    if (fp == nullptr)
    {
        ShowError("Could not read English server message from: ./conf/server_message.conf\n");
        return 1;
    }

    while (fgets(line, sizeof(line), fp))
    {
        string_t sline(line);
        map_config.server_message += sline;
    }

    fclose(fp);

    // Load the French server message..
    fp = fopen("./conf/server_message_fr.conf", "rb");
    if (fp == nullptr)
    {
        ShowError("Could not read English server message from: ./conf/server_message_fr.conf\n");
        return 1;
    }

    while (fgets(line, sizeof(line), fp))
    {
        string_t sline(line);
        map_config.server_message_fr += sline;
    }

    fclose(fp);

    // Ensure both messages have nullptr terminates..
    if (map_config.server_message.at(map_config.server_message.length() - 1) != 0x00)
    {
        map_config.server_message += (char)0x00;
    }
    if (map_config.server_message_fr.at(map_config.server_message_fr.length() - 1) != 0x00)
    {
        map_config.server_message_fr += (char)0x00;
    }

    return 0;
}
Example #18
0
File: main.c Project: sisoftrg/qico
static void answer_mode(int type)
{
	int rc, spd;char *cs;
	struct sockaddr_in sa;
	socklen_t ss=sizeof(sa);
	sts_t sts;
	if(cfgs(CFG_ROOTDIR)&&ccs[0])chdir(ccs);
	rnode=xcalloc(1,sizeof(ninfo_t));
	is_ip=!isatty(0);
	xstrcpy(ip_id,"ipline",10);
	rnode->tty=xstrdup(is_ip?(bink?"binkp":"tcpip"):basename(ttyname(0)));
	rnode->options|=O_INB;
	if(!log_init(cfgs(CFG_LOG),rnode->tty)) {
		printf("can't open log %s!\n",ccs);
		exit(S_FAILURE);
	}
	signal(SIGINT,SIG_IGN);
	signal(SIGTERM,sigerr);
	signal(SIGSEGV,sigerr);
	signal(SIGFPE,sigerr);
	signal(SIGPIPE,SIG_IGN);
	IFPerl(perl_init(cfgs(CFG_PERLFILE),0));
	log_callback=NULL;xsend_cb=NULL;
	ssock=cls_conn(CLS_LINE,cfgs(CFG_SERVER),NULL);
	if(ssock<0)write_log("can't connect to server: %s",strerror(errno));
	    else log_callback=vlogs;

	rc=aso_init(cfgs(CFG_ASOOUTBOUND),cfgs(CFG_BSOOUTBOUND),cfgs(CFG_QSTOUTBOUND),cfgal(CFG_ADDRESS)->addr.z);
	if(!rc) {
		write_log("No outbound defined");
		stopit(S_FAILURE);
	}

	write_log("answering incoming call");vidle();
	if(is_ip&&!getpeername(0,(struct sockaddr*)&sa,&ss)) {
		write_log("remote is %s",inet_ntoa(sa.sin_addr));
		spd=TCP_SPEED;
	} else {
		cs=getenv("CONNECT");spd=cs?atoi(cs):0;
		xfree(connstr);connstr=xstrdup(cs);
		if(cs&&spd)write_log("*** CONNECT %s",cs);
		    else {
			write_log("*** CONNECT Unknown");
			spd=DEFAULT_SPEED;
		}
	}
	if((cs=getenv("CALLER_ID"))&&strcasecmp(cs,"none")&&strlen(cs)>3)write_log("caller-id: %s",cs);
	tty_setattr(0);
	tty_local(0);
	rc=session(0,type,NULL,spd);
	tty_local(1);
	if(!is_ip) {
		hangup();
		stat_collect();
	}
	tty_cooked();
	if((S_OK==(rc&S_MASK))&&cfgi(CFG_HOLDONSUCCESS)) {
		log_done();
		log_init(cfgs(CFG_MASTERLOG),NULL);
		aso_getstatus(&rnode->addrs->addr, &sts);
		sts.flags|=(Q_WAITA|Q_WAITR|Q_WAITX);
		sts.htime=MAX(t_set(cci*60),sts.htime);
		write_log("calls to %s delayed for %d min after successful incoming session",
				ftnaddrtoa(&rnode->addrs->addr),cci);
		aso_setstatus(&rnode->addrs->addr,&sts);
		log_done();
		log_init(cfgs(CFG_LOG),rnode->tty);
	}
	title("Waiting...");
	vidle();sline("");
	aso_done();
	stopit(rc);
}
Example #19
0
int cone::cone_fit(region &reg, double **list_x, double *list_y, double **norm, int no, int xspan, int yspan,double *param, double *chisq)

{
    double pt[3], pt_norm[3];
    double  acone[3];

    int ind[9];         // indices of  extreme points

    sline input_norms[9];
    sline output_axis;
    sline *r_axis=&output_axis;
    int   axnum=1;

    int i, index, k;

    if (chisq) chisq = chisq;    // to prevent stupid compiler warnings.

    double *q= (double *) dvector(1,3);  /* cone coord sys origin */


// Numerical recipe vars

    double **list, *F, *sig;
    double  *b = dvector(1,PARAM_SIZE);
    double  *n = dvector(1,3);
    int *lista;
    double alamda, newchisq, oldchisq;


    double  **covar = (double **) dmatrix(1,PARAM_SIZE,1,PARAM_SIZE),
              **alpha = (double **) dmatrix(1,PARAM_SIZE,1,PARAM_SIZE);


    list = (double **) dmatrix(1,no,1,3);
    F = (double *) dvector(1,no);
    sig = (double *) dvector(1,no);


    pplane projection_plane(reg,ind);           // fills ind with indices of extremes

    if ( param[1] == RIDICULOUS_NUMBER )
    {   /* NEW REGION SO CONSTRUCT INITIAL ESTIMATES */


        // Guess AXIS of CONE

        //  Take 5 pts at 4 corners and center of region and compute sline of normals

        // top left normal

        pt[0] =  list_x[ind[0]][1];
        pt[1] = list_x[ind[0]][2];
        pt[2] = list_y[ind[0]];

        for (i=0; i<3; ++i)
            pt_norm[i] = norm[ind[0]][i+1];

        input_norms[0] = sline(pt, pt_norm,0);

        // top right normal

        // changed by Bojan Kverh 25.2.1998

        index = ind[2];    // xspan+1;

        pt[0] =  list_x[index][1];
        pt[1] = list_x[index][2];
        pt[2] = list_y[index];

        for (i=0; i<3; ++i)
            pt_norm[i] = norm[index][i+1];


        input_norms[1] = sline(pt, pt_norm,0);

        // middle normal

        index = ind[4];

        pt[0] =  list_x[index][1];
        pt[1] = list_x[index][2];
        pt[2] = list_y[index];

        for (i=0; i<3; ++i)
            pt_norm[i] = norm[index][i+1];

        input_norms[2] = sline(pt, pt_norm,0);

        // bottom left normal

        // changed by Bojan Kverh 25.2.1998

        index = ind[6];

        pt[0] =  list_x[index][1];
        pt[1] = list_x[index][2];
        pt[2] = list_y[index];

        for (i=0; i<3; ++i)
            pt_norm[i] = norm[index][i+1];

        input_norms[3] = sline(pt, pt_norm,0);

        // bottom right normal

        index = ind[8];

        pt[0] =  list_x[index][1];
        pt[1] = list_x[index][2];
        pt[2 ] = list_y[index];

        for (i=0; i<3; ++i)
            pt_norm[i] = norm[index][i+1];

        input_norms[4] = sline(pt, pt_norm,0);

        index = guess_axes(input_norms,5,
                           &r_axis, &axnum,
                           1.5,
                           NULL,
                           10,
                           1000.0,
                           0.001,
                           0.0005,
                           1,
                           NULL,
                           0.5,
                           NULL);

        output_axis.direction(acone);

// index = 1;
// acone[0] = acone[2] = 0.0;
//  acone[1] = 1.0;

        if ( (index == 0) || ( fabs(modsq(acone-1) - 0.999999) > 0.001 ))
        {   // we have no axis
            std::cout << "ERROR: Cannot Guess Axis for this Cone\n" << "index = " << index << "\n";
            std::cout << "acone[0] =" << acone[0]  << " acone[1] =" << acone[1]  << " acone[2] =" << acone[2] << "\n";
            std::cout << "modsq = " << modsq(acone-1) << "\n";
            return(0);

        }

        // printf("%d:%f %f %f\n",index,acone[0],acone[1],acone[2]);


        // compute  initial estimates

        // make n normal at first point

        n[1] = -norm[1][1];
        n[2] = -norm[1][2];
        n[3] = -norm[1][3];

// make rho = 1

        b[1] = 1.0;

        // Make origin of cone coordinate system a point 1 "unit" off
        //      1st cone point along normal at the point

        q[1] = list_x[1][1] -  b[1]* n[1];
        q[2] = list_x[1][2] -  b[1]* n[2];
        q[3] = list_y[1] -  b[1]* n[3];

        /*
        // Added by Bojan Kverh 26.2.1998
        // Estimation of cone axis
        // As this will be done only at the beginning,
        // the axis is very similar to the one of the cylinder

        vector3D v1,v2,v3,ax;
        double dnorm;
        int npts = 0;

        index = 1 + rand() % no;

        ax.el(0) = 0.0;
        ax.el(1) = 0.0;
        ax.el(2) = 0.0;

        for (i = 1; i <= no; i++)
        { index = 1 + rand() % no;  // random number
          v1.el(0) = norm[index][1];
          v1.el(1) = norm[index][2];
          v1.el(2) = norm[index][3];
          v2.el(0) = norm[i][1];
          v2.el(1) = norm[i][2];
          v2.el(2) = norm[i][3];
          v3 = v1.outer(v2);
          dnorm = v3.norm();
          if (dnorm > 0.1)
        { v3.normalize();
                 npts++;
                 // if (ax.inner(v3) < 0.0) v3.multiply_col(0,-1);
                 ax += v3;
          }
        }

             acone[0] = ax.el(0) / npts;
             acone[1] = ax.el(1) / npts;
             acone[2] = ax.el(2) / npts;

             // End Added by Bojan Kverh 26.2.1998
             */


        // compute estimates of angles

        // phi = atan2(n[2]/n[1]);

        b[2] = atan2(n[2],n[1]);


        // theta = acos(n[3])

        b[3] = acos(n[3]);


        // sigma = atan2(acone[2]/acone[1]);  but in NORAML C ARREAY INDEX!!

        b[4] = atan2(acone[1],acone[0]);


        // tau = acos(n[3]) but in NORAML C ARREAY INDEX!!

        b[5] = acos(acone[2]);


        //  To Estimate k  --- use ralph`s curvature estimation.
        //    SInce COne one curvature should be zero or close to it.
        //   Choose no zero curvature value as estimate.

        rcad_SurfaceData pnts[9];
        int              inds[9];

        // make firts pnts[0] entry centre point

        // Pt ordering     	1 2 3
        //		4 0 8
        //		7 6 5

        xspan = yspan = (int)sqrt(no);

        index =  ind[4];

        pnts[0].p[0] = list_x[index][1];
        pnts[0].p[1] = list_x[index][2];
        pnts[0].p[2] = list_y[index];


        // top left point


        index = ind[0];

        pnts[1].p[0] =  list_x[index][1];
        pnts[1].p[1] = list_x[index][2];
        pnts[1].p[2] = list_y[index];

        // top middle point


        index = ind[1];

        pnts[2].p[0] =  list_x[index][1];
        pnts[2].p[1] = list_x[index][2];
        pnts[2].p[2] = list_y[index];

        // top right point


        index = ind[2];

        pnts[3].p[0] =  list_x[index][1];
        pnts[3].p[1] = list_x[index][2];
        pnts[3].p[2] = list_y[index];

        // middle left point


        index = ind[3];

        pnts[4].p[0] =  list_x[index][1];
        pnts[4].p[1] = list_x[index][2];
        pnts[4].p[2] = list_y[index];

        // middle right point


        index =  ind[5];

        pnts[8].p[0] =  list_x[index][1];
        pnts[8].p[1] = list_x[index][2];
        pnts[8].p[2] = list_y[index];

        // bottom left point

        index = ind[6];

        pnts[7].p[0] =  list_x[index][1];
        pnts[7].p[1] = list_x[index][2];
        pnts[7].p[2] = list_y[index];

        // bottom middle point

        index = ind[7];

        pnts[6].p[0] =  list_x[index][1];
        pnts[6].p[1] = list_x[index][2];
        pnts[6].p[2] = list_y[index];


// bottom right point

        index = ind[8];

        pnts[5].p[0] =  list_x[index][1];
        pnts[5].p[1] = list_x[index][2];
        pnts[5].p[2] = list_y[index];

        for (i=0; i<9; ++i)
            inds[i] = i;


        // make n normal at centre point
        index = ind[4];

        double normal[3];
        double dir1[3];
        double dir2[3];


        normal[0] = norm[index][1];
        normal[1] = norm[index][2];
        normal[2] = norm[index][3];


        double k1,k2;
        int error;

        error=rcad_circurv(9,inds,pnts[0].p, normal, pnts, &k1, &k2, dir1, dir2);

        //std::printf("Circurv: %d k1: %lf k2: %lf\n", error, k1, k2);

        // find largest k1 or k2 and set this  as estimate for cone's k


        if ( fabs(k1) > fabs(k2) )
            b[6] = -k1;
        else
            b[6] = -k2;

    }
    else

    {   /* copy current fit parameters to b and q */

        b[1] = param[1];
        b[2] = param[2];
        b[3] = param[3];
        b[4] = param[4];
        b[5] = param[5];
        b[6] = param[6];

        q[1] = param[11];
        q[2] = param[12];
        q[3] = param[13];


    }

    for(i=1; i<=no; i++) {
        /* set NR variables */
        F[i] = 0.0;
        sig[i] = 1.0;



        /* translate points to now coord system */

        list[i][1] = list_x[i][1] - q[1];
        list[i][2] = list_x[i][2] - q[2];
        list[i][3]=  list_y[i] - q[3];


    }


    lista = (int *) ivector(1,PARAM_SIZE);

    lista[1] = 1;
    lista[2] = 2;
    lista[3] = 3;
    lista[4] = 4;
    lista[5] = 5;
    lista[6] = 6;

    alamda = -1.0;
    newchisq = oldchisq = 1.0;

    //printf("Initial Cone Estimates: %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f\n", b[1],b[2],b[3],b[4],b[5], b[6]);

    // non-linear least squares estimate cone NOW at last


    o_mrqmin(list, F, sig, no,b,PARAM_SIZE, lista,PARAM_SIZE, covar, alpha, &newchisq,&alamda,  conedx);

    k= 0;

    while (  k++ < 25 )
    {   /* iterate until no better error or max of 25 steps */
        oldchisq = newchisq;
        o_mrqmin(list, F, sig, no,b,PARAM_SIZE, lista,PARAM_SIZE, covar, alpha, &newchisq,&alamda,conedx);


    }

    alamda = 0.0;
    o_mrqmin(list, F, sig, no,b,PARAM_SIZE, lista,PARAM_SIZE, covar, alpha, &newchisq,&alamda,conedx);

    // added by Bojan Kverh 21.5.98.
    // modify the axis if necessary

    vector3D axis, n2, flag;
    double pi = 3.1415926535;

    axis.el(0) = cos(b[4])*sin(b[5]);
    axis.el(1) = sin(b[4])*sin(b[5]);
    axis.el(2) = cos(b[5]);
    n2.el(0) = cos(b[2])*sin(b[3]);
    n2.el(1) = sin(b[2])*sin(b[3]);
    n2.el(2) = cos(b[3]);

    if (b[6] * n2.inner(axis) > 0.0)
    {   /* if (b[4] > 0) b[4] -= pi;
          else b[4] += pi; */
        if (b[5] > 0) b[5] -= pi;
        else b[5] += pi;
    }

    param[1] = b[1];
    param[2] = b[2];
    param[3] = b[3];
    param[4] =  b[4];
    param[5] = b[5];
    param[6] = b[6];

    param[11] = q[1];
    param[12] = q[2];
    param[13] = q[3];





    // tidy up nr memory allocs


    free_dvector(b,1,PARAM_SIZE);
    free_dvector(n,1,3);
    free_dmatrix(list,1,no,1,3);
    free_dmatrix(covar,1,PARAM_SIZE,1,PARAM_SIZE);
    free_dmatrix(alpha,1,PARAM_SIZE,1,PARAM_SIZE);

    free_ivector(lista,1,PARAM_SIZE);
    free_dvector(F,1,no);
    free_dvector(sig,1,no );

    free_dvector(q,1,3);

    return(1);
}