Beispiel #1
0
 // Decodes your encoded data to tree.
 TreeNode* deserialize(string data) {
     vector<string> vec;
     string tmp; for (auto x : data) {
         if (x == '|') {
             vec.push_back(tmp);
             tmp = "";
         } else {
             tmp += x;
         }
     }
     int vsize=vec.size(); TreeNode dummy(0);
     queue<TreeNode*> q; q.push(&dummy);
     for (int i=0; i < vsize; ) {
         TreeNode *ptr = q.front(); q.pop();
         if (ptr) {
             tmp = vec[i++];
             if (tmp != "null") {
                 int val = str2num(tmp);
                 ptr->left = new TreeNode(val);
                 q.push(ptr->left);
             }
             tmp = vec[i++];
             if (tmp != "null") {
                 int val = str2num(tmp);
                 ptr->right = new TreeNode(val);
                 q.push(ptr->right);
             }
         }
     }
     return dummy.right;
 }
Beispiel #2
0
/* read sp3 header -----------------------------------------------------------*/
static int readsp3h(FILE *fp, gtime_t *time, char *type, int *sats,
                    double *bfact, char *tsys)
{
    int i,j,k=0,ns=0,sys,prn;
    char buff[1024];
    
    trace(3,"readsp3h:\n");
    
    for (i=0;i<22;i++) {
        if (!fgets(buff,sizeof(buff),fp)) break;
        
        if (i==0) {
            *type=buff[2];
            if (str2time(buff,3,28,time)) return 0;
        }
        else if (2<=i&&i<=6) {
            if (i==2) {
                ns=(int)str2num(buff,4,2);
            }
            for (j=0;j<17&&k<ns;j++) {
                sys=code2sys(buff[9+3*j]);
                prn=(int)str2num(buff,10+3*j,2);
                if (k<MAXSAT) sats[k++]=satno(sys,prn);
            }
        }
        else if (i==12) {
            strncpy(tsys,buff+9,3); tsys[3]='\0';
        }
        else if (i==14) {
            bfact[0]=str2num(buff, 3,10);
            bfact[1]=str2num(buff,14,12);
        }
    }
    return ns;
}
Beispiel #3
0
/* read ionex dcb aux data ----------------------------------------------------*/
static void readionexdcb(FILE *fp, double *dcb, double *rms)
{
    int i,sat;
    char buff[1024],id[32],*label;
    
    trace(3,"readionexdcb:\n");
    
    for (i=0;i<MAXSAT;i++) dcb[i]=rms[i]=0.0;
    
    while (fgets(buff,sizeof(buff),fp)) {
        if (strlen(buff)<60) continue;
        label=buff+60;
        
        if (strstr(label,"PRN / BIAS / RMS")==label) {
            
            strncpy(id,buff+3,3); id[3]='\0';
            
            if (!(sat=satid2no(id))) {
                trace(2,"ionex invalid satellite: %s\n",id);
                continue;
            }
            dcb[sat-1]=str2num(buff, 6,10);
            rms[sat-1]=str2num(buff,16,10);
        }
        else if (strstr(label,"END OF AUX DATA")==label) break;
    }
}
Beispiel #4
0
/*!
\brief fills an integer array with tokens extracted from a string
\author Xanathar
\return int the number of number read from the string
\param str the string
\param array the array
\param maxsize the size of array
\param defval -1 -> the default value for uninitialized items
\param base the base for number conversion
\deprecated This is part of the old XSS stuff.
*/
int fillIntArray(char* str, int *array, int maxsize, int defval, int base)
{
	int i=0;
	char tmp[1048];
	char *mem;

	if (strlen(str) > 1024) {
		mem = new char[strlen(str)+5];
	} else mem = tmp;  //xan -> we avoid dyna-alloc for strs < 1K
	strcpy(tmp, str);

	char *s;
	char *delimiter = " ";

	if (base != baseInArray) for (i = 0; i < maxsize; i++) array[i] = defval;

	i = 0;

	s = strtok(tmp,delimiter);

	while ((s!=NULL)&&(i < maxsize)) {
		if (base == baseInArray) {
			array[i] = str2num(s, array[i]);
			i++;
		}
		else {
			array[i++] = str2num(s, base);
		}
		s = strtok(NULL, delimiter);
	}

	if (mem != tmp) safedeletearray(mem);
	return i;
}
Beispiel #5
0
// read station position data -----------------------------------------------
void __fastcall TPlot::ReadStaPos(const char *file, const char *sta,
                                  double *rr)
{
    FILE *fp;
    char buff[256],code[256],name[256];
    double pos[3];
    int sinex=0;
    
    if (!(fp=fopen(file,"r"))) return;
    
    while (fgets(buff,sizeof(buff),fp)) {
        if (strstr(buff,"%=SNX")==buff) sinex=1;
        if (buff[0]=='%'||buff[1]=='#') continue;
        if (sinex) {
            if (strlen(buff)<68||strncmp(buff+14,sta,4)) continue;
            if (!strncmp(buff+7,"STAX",4)) rr[0]=str2num(buff,47,21);
            if (!strncmp(buff+7,"STAY",4)) rr[1]=str2num(buff,47,21);
            if (!strncmp(buff+7,"STAZ",4)) {
                rr[2]=str2num(buff,47,21);
                break;
            }
        }
        else {
            if (sscanf(buff,"%lf %lf %lf %s",pos,pos+1,pos+2,code)<4) continue;
            if (strcmp(code,sta)) continue;
            pos[0]*=D2R;
            pos[1]*=D2R;
            pos2ecef(pos,rr);
            break;
        }
    }
	fclose(fp);
}
void loadfishing()
{
	unsigned long loopexit=0;
	do
	{
		readw2();
		if(!(strcmp((char*)script1,"BASE_FISHING_TIME"))) fishing_data.basetime=str2num(script2);
		else if(!(strcmp((char*)script1,"RANDOM_FISHING_TIME"))) fishing_data.randomtime=str2num(script2);
	}
	while ( (strcmp((char*)script1, "}")) && (++loopexit < MAXLOOPS) );
}
void loadhunger() // by Magius(CHE)
{
	unsigned long loopexit=0;
	do
	{
		readw2();
		if(!(strcmp((char*)script1,"HUNGERRATE"))) server_data.hungerrate=str2num(script2);
		else if(!(strcmp((char*)script1,"HUNGER_DAMAGE"))) server_data.hungerdamage=str2num(script2);
		else if(!(strcmp((char*)script1,"HUNGER_DAMAGE_RATE"))) server_data.hungerdamagerate=str2num(script2);
	}
	while ( (strcmp((char*)script1, "}")) && (++loopexit < MAXLOOPS) );
}
void loadregenerate() // by Magius(CHE)
{
	unsigned long loopexit=0;
	do
	{
		readw2();
		if(!(strcmp((char*)script1,"HITPOINTS_REGENRATE"))) server_data.hitpointrate=str2num(script2);
		else if(!(strcmp((char*)script1,"STAMINA_REGENRATE"))) server_data.staminarate=str2num(script2);
		else if(!(strcmp((char*)script1,"MANA_REGENRATE"))) server_data.manarate=str2num(script2);
		else if(!(strcmp((char*)script1,"ARMOR_AFFECT_MANA_REGEN"))) server_data.armoraffectmana=str2num(script2);
	}
	while ( (strcmp((char*)script1, "}")) && (++loopexit < MAXLOOPS) );
}
Beispiel #9
0
QList<XCursorThemeFX::tAnimSeq> XCursorThemeFX::parseScript (const QString &script, quint32 maxFrame) {
    QList<tAnimSeq> res;
    QString scp = script;
    scp.replace("\r", "\n");
    QStringList scpL = scp.split('\n', QString::SkipEmptyParts);
    foreach (QString s, scpL) {
        s = s.simplified();
        //qDebug() << s;
        QStringList fld = s.split(',', QString::SkipEmptyParts); //BUG!BUG!BUG!
        if (fld.size() != 2) {
            qDebug() << "script error:" << s;
            qWarning() << "script error:" << s;
            continue;
        }
        // frame[s]
        int hyph = fld[0].indexOf('-');
        tAnimSeq a;
        if (hyph == -1) {
            // just a number
            if (!str2num(fld[0], a.from)) {
                qDebug() << "script error (frame):" << s;
                qWarning() << "script error (frame):" << s;
                continue;
            }
            a.from = qMax(qMin(maxFrame, a.from), (quint32)1)-1;
            a.to = a.from;
        } else {
            // a..b
            if (!str2num(fld[0].left(hyph), a.from)) {
                qDebug() << "script error (frame from):" << s;
                qWarning() << "script error (frame from):" << s;
                continue;
            }
            a.from = qMax(qMin(maxFrame, a.from), (quint32)1)-1;
            if (!str2num(fld[0].mid(hyph+1), a.to)) {
                qDebug() << "script error (frame to):" << s;
                qWarning() << "script error (frame to):" << s;
                continue;
            }
            a.to = qMax(qMin(maxFrame, a.to), (quint32)1)-1;
        }
        // delay
        if (!str2num(fld[1], a.delay)) {
            qDebug() << "script error (delay):" << s;
            qWarning() << "script error (delay):" << s;
            continue;
        }
        if (a.delay < 10) a.delay = 10;
        qDebug() << "from" << a.from << "to" << a.to << "delay" << a.delay;
        res << a;
    }
Beispiel #10
0
string BinOpValue::getValue(){
	string a=this->a->getValue();
	string b=this->b->getValue();
	if(!op.compare("+")){
	try{
		double x=str2num(a);
		double y=str2num(b);
		return num2str(x+y);
	}catch(string &tx){
		return a+b;
	}//end try
	}else if(!op.compare("-")){
		TRY_NUM(-);
	}else if(!op.compare("*")){
void loadbegging()
{
	unsigned long loopexit=0;
	do
	{
		readw2();

		if(!(strcmp((char*)script1,"BEGGING_TIME"))) begging_data.timer=str2num(script2);
		else if(!(strcmp((char*)script1,"BEGGING_RANGE"))) begging_data.range=str2num(script2);
		else if(!(strcmp((char*)script1,"BEGGING_TEXT0"))) strcpy(begging_data.text[0],(char*)script2);
		else if(!(strcmp((char*)script1,"BEGGING_TEXT1"))) strcpy(begging_data.text[1],(char*)script2);
		else if(!(strcmp((char*)script1,"BEGGING_TEXT2"))) strcpy(begging_data.text[2],(char*)script2);
	}
	while ( (strcmp((char*)script1, "}")) && (++loopexit < MAXLOOPS) );
}
Beispiel #12
0
cable* cable::factory(const char* s)
{
    cable* cbl = NULL;
    int argc;
    char** argv = NULL;
    int addr;

    if (*s == 0)
        return NULL;

    parse_cmdline_args(s, &argc, &argv);

    if (argc == 0)
        return NULL;

    if (stricmp(argv[0], "xil3") == 0) {
        if (argc == 1)
            addr = 0x378;
        else {
            if (str2num(argv[1], &addr))
                goto cleanup;
        }
        
        cbl = new parport((unsigned int)addr);
    }
    else if (stricmp(argv[0], "dusb") == 0)
        cbl = new digilent;
    else if (stricmp(argv[0],"znuhtag") == 0) {
	    int num=0;
	    if(argc > 1)
		    str2num(argv[1], &num);
	cbl = new znuhtag(num);
    }
    else if (stricmp(argv[0],"amontec") == 0) {
	    int speed = 0;
	    if (argc > 1)
		    str2num(argv[1], &speed);
	cbl = new amontec(speed);
    }
    else {
        msgf(STR_INVALID_CABLE_DEF);
        return NULL;
    }

cleanup:

    return cbl;
}
Beispiel #13
0
int t_extract( char * in, float * temp )
{
	char re[] = "^(-?[0-9]+\\.?[0-9]*) *([cCfF])$";
	size_t nmatch = 3;
	regmatch_t pmatch[ nmatch ];
	char * temp_type, * temp_val;
	int value;

	if( rematch( in, re, nmatch, pmatch ) )
	{
		temp_val = substring( in, pmatch[ 1 ].rm_so, pmatch[ 1 ].rm_eo - 1 ); // In order to free up at the end.
		*temp = ( float )str2num( temp_val );

		temp_type = substring( in, pmatch[ 2 ].rm_so, pmatch[ 2 ].rm_eo - 1 );
		if( *temp_type == 'c' || *temp_type == 'C' )
			value = CELS;
		if( *temp_type == 'f' || *temp_type == 'F' )
			value = FAHR;
	}
	else
	{
		fprintf( stderr, "t_extract: Bad temperature entry.\n" );
		exit( 1 );
	}

	free( temp_type );
	free( temp_val );

	return value;
}
Beispiel #14
0
int cmd_erase(int argc, const char** argv)
{
	cable* cbl = NULL;
	int index;
	chip* dev;
	const char* param;

	// Position
	param = cmdline_get_non_opt(argc, argv, 0);
	if (param == NULL || str2num(param, &index) || index <= 0)
	{
        msgf(STR_INVALID_PARAMETERS);
		return 0;
    }
    
    cbl = open_cable(1);
    if (cbl == NULL)
        return 0;
	
    dev = select_device_in_chain(index - 1);
    if (dev == NULL)
        return -1;

	msgf(STR_ERASING, index, dev->name.c_str());
	
	if (dev->erase(cbl) == 0)
		msgf(STR_SUCCESS_COMPLETED);

	close_cable(cbl);

    return 0;
}
Beispiel #15
0
/* read dcb parameters file --------------------------------------------------*/
static int readdcbf(const char *file, nav_t *nav)
{
    FILE *fp;
    double cbias;
    int sat,type=0;
    char buff[256];
    
    trace(3,"readdcbf: file=%s\n",file);
    
    if (!(fp=fopen(file,"r"))) {
        trace(2,"dcb parameters file open error: %s\n",file);
        return 0;
    }
    while (fgets(buff,sizeof(buff),fp)) {
        
        if      (strstr(buff,"DIFFERENTIAL (P1-P2) CODE BIASES")) type=1;
        else if (strstr(buff,"DIFFERENTIAL (P1-C1) CODE BIASES")) type=2;
        else if (strstr(buff,"DIFFERENTIAL (P2-C2) CODE BIASES")) type=3;
        
        if (!type) continue;
        
        if (!(sat=satid2no(buff))||(cbias=str2num(buff,26,9))==0.0) continue;
        
        nav->cbias[sat-1][type-1]=cbias*1E-9*CLIGHT; /* ns -> m */
    }
    fclose(fp);
    
    return 1;
}
Beispiel #16
0
int cmd_idcode(int argc, const char** argv)
{
	cable* cbl;
    chip* dev;
	int index;
	const char* param;

	// Position
	param = cmdline_get_non_opt(argc, argv, 0);
	if (param == NULL || str2num(param, &index) || index <= 0)
	{
        msgf(STR_INVALID_PARAMETERS);
		return 0;
    }

	cbl = open_cable(1);
    if (cbl == NULL)
        return 0;

    dev = select_device_in_chain(index - 1);
    if (dev)
        msgf(STR_DEVICE_IDCODE, index, dev->id);
	    
	close_cable(cbl);
	
    return 0;
}
    int calculate(string s) {
        stack<int> vals;
        stack<char> ops;
        string num = "";

        for (int i = 0; i < s.length(); i++) {
            if (s[i] == '*' || s[i] == '/') {
                while (ops.size() && (ops.top() == '*' || ops.top() == '/'))
                    calculateHelper(vals, ops);
                ops.push(s[i]);
            } else if (s[i] == '+' || s[i] == '-') {
                while (ops.size() && (ops.top() == '-' || ops.top() == '*' || ops.top() == '/'))
                    calculateHelper(vals, ops);
                ops.push(s[i]);
            } else if (s[i] >= '0' && s[i] <= '9') {
                num = num + s[i];
                if(i == s.length() - 1 || s[i + 1] < '0' || s[i + 1] > '9') {
                    vals.push(str2num(num)); 
                    num = "";
                }
            }
        }
        
        while (ops.size())
            calculateHelper(vals, ops);
        return vals.top();
    }
Beispiel #18
0
static SQInteger default_delegate_tointeger(HSQUIRRELVM v)
{
    SQObjectPtr &o=stack_get(v,1);
    switch(type(o)) {
    case OT_STRING: {
        SQObjectPtr res;
        if(str2num(_stringval(o),res)) {
            v->Push(SQObjectPtr(tointeger(res)));
            break;
        }
    }
    return sq_throwerror(v, _SC("cannot convert the string"));
    break;
    case OT_INTEGER:
    case OT_FLOAT:
        v->Push(SQObjectPtr(tointeger(o)));
        break;
    case OT_BOOL:
        v->Push(SQObjectPtr(_integer(o)?(SQInteger)1:(SQInteger)0));
        break;
    default:
        v->Push(_null_);
        break;
    }
    return 1;
}
Beispiel #19
0
bool cCharStuff::cBankerAI::Withdraw(int c, P_CHAR pBanker, const string& comm)
{
	P_CHAR pc_currchar = currchar[c];
	int beginoffset ;
	int endoffset ;
	string value2 ;
	int value=0 ;
	if ((beginoffset=comm.find_first_of("0123456789")) != string::npos)
	{
		if ((endoffset=comm.find_first_not_of("0123456789",beginoffset))== string::npos)
			endoffset = comm.length();
		value2= comm.substr(beginoffset,endoffset-beginoffset);
		value = str2num(value2) ;
	}
	else 
		value = 0 ;
	if (pc_currchar->CountBankGold() >= value)
	{
		int goldcount = value;
		addgold(c, goldcount);
		goldsfx(c, goldcount);
		DeleBankItem(pc_currchar, 0x0EED, 0, goldcount);
		sprintf(temp, "%s here is your withdraw of %i.", pc_currchar->name.c_str(), goldcount);
		npctalk(c, pBanker, temp, 1);
		return true;
	}
	else
		sprintf(temp, "%s you have insufficent funds!", pc_currchar->name.c_str());
	npctalk(c, pBanker, temp, 1);
	return true;
}
 /**
  * @param tokens The Reverse Polish Notation
  * @return the value
  */
 int evalRPN(vector<string>& tokens) {
     // Write your code here
     if(tokens.size() == 0)
         return 0;
     stack<int> s;
     for(auto &t : tokens){
         if(t == "+" || t == "-" || t == "*" || t == "/"){
             int a = s.top();
             s.pop();
             int b = s.top();
             s.pop();
             if(t == "+")
                 s.push(b + a);
             if(t == "-")
                 s.push(b - a);
             if(t == "*")
                 s.push(b * a);
             if(t == "/")
                 s.push(b / a);
         }else{
             s.push(str2num(t));
         }
     }
     return s.top();
 }
Beispiel #21
0
unsigned int handleConstants(char line[])
{
	
	char temp[3];

	if(line[0] == 'C')
		return line[2];


	else if(line[0] == 'X')
	{
		temp[0]=line[2];
		temp[1]=line[3];
		temp[2]='\0';
		return str2num(temp,16);

	}

	else
	{
		int j = strlen(line)-1;
		unsigned int objCode= 0;
		int i = 0;
		while(i<=j)
			objCode += char2num(line[i++]) * pow(10,j--);


	}

}
Beispiel #22
0
P_ITEM cCharStuff::AddRandomLoot(P_ITEM pBackpack, char * lootlist)
{
	char sect[512];
	int i,j, storeval,loopexit=0;
	P_ITEM retitem = NULL;
	storeval=-1;
	i=0; j=0;

	sprintf(sect, "LOOTLIST %s", lootlist);
	
	Script *pScpBase=i_scripts[npc_script];
	Script *pScp=pScpBase->Select(sect,custom_npc_script);
	if (!pScp) return NULL;

	loopexit=0;
	do
	{
		pScp->NextLine();
		if (script1[0]!='}')
		{
			i++; // Count number of entries on list.
		}
	} while ( (script1[0]!='}') && (++loopexit < MAXLOOPS) );
	pScp->Close();

	if(i>0)
	{
		i=rand()%(i);
		pScp=pScpBase->Select(sect,custom_npc_script);

		loopexit=0;
		do
		{
			pScp->NextLine();
			if (script1[0]!='}')
			{
				if(j==i)
				{
					storeval=str2num(script1);	//script1 = ITEM#

					scpMark m=pScp->Suspend();
					retitem = Targ->AddMenuTarget(-1, 0, storeval);
					pScp->Resume(m);

					if(retitem!=NULL)
					{
						retitem->pos.x=50+(rand()%80);
						retitem->pos.y=50+(rand()%80);
						retitem->pos.z=9;
						retitem->SetContSerial(pBackpack->serial);
					}
					break;;    
				}
				else j++;
			}
		}	while ( (script1[0]!='}') && (++loopexit < MAXLOOPS) );
		pScp->Close();
	}
	return retitem;
}
Beispiel #23
0
/*** s: socket ***/
int cCharStuff::getRandomNPC(char * npclist)
{
	//This function gets the random npc number from the list and recalls
	//addrespawnnpc passing the new number
	char sect[512];
	unsigned int uiTempList[100];
	int i=0,k=0;
	sprintf(sect, "NPCLIST %s", npclist);

	Script *pScpBase=i_scripts[npc_script];
	Script *pScp=pScpBase->Select(sect,custom_npc_script);
	if (!pScp) return 0;

	unsigned long loopexit=0;
	do
	{
		pScp->NextLine();
		if (script1[0]!='}')
		{
			uiTempList[i]=str2num(script1);
			i++;
		}
	}
	while ( (script1[0]!='}') && (++loopexit < MAXLOOPS));
	pScp->Close();

	if(i>0)
	{
		i=rand()%(i);
		k=uiTempList[i];
	}
	return k;
}
void loadrepsys() //Repsys
{
	unsigned long loopexit=0;
	do
	{
		readw2();
		if(!(strcmp((char*)script1,"MURDER_DECAY"))) repsys.murderdecay=str2num(script2);
		else if(!(strcmp((char*)script1,"MAXKILLS"))) repsys.maxkills=str2num(script2);
		else if(!(strcmp((char*)script1,"CRIMINAL_TIME"))) repsys.crimtime=str2num(script2);
	}
	while ( (strcmp((char*)script1, "}")) && (++loopexit < MAXLOOPS) );

	if (!repsys.murderdecay) repsys.murderdecay=420;
	if (!repsys.maxkills) repsys.maxkills=4;
	if (!repsys.crimtime) repsys.crimtime=120;
}
Beispiel #25
0
static int csv_read_record(TABDCA *dca, struct csv *csv)
{     /* read next record from csv data file */
      int k, ret = 0;
      xassert(csv->mode == 'R');
      if (setjmp(csv->jump))
      {  ret = 1;
         goto done;
      }
      /* read dummy RECNO field */
      if (csv->ref[0] > 0)
#if 0 /* 01/VI-2010 */
         mpl_tab_set_num(dca, csv->ref[0], csv->count-1);
#else
         mpl_tab_set_num(dca, csv->ref[0], csv->count-csv->nskip-1);
#endif
      /* read fields */
      for (k = 1; k <= csv->nf; k++)
      {  read_field(csv);
         if (csv->what == CSV_EOF)
         {  /* end-of-file reached */
            xassert(k == 1);
            ret = -1;
            goto done;
         }
         else if (csv->what == CSV_EOR)
         {  /* end-of-record reached */
            int lack = csv->nf - k + 1;
            if (lack == 1)
               xprintf("%s:%d: one field missing\n", csv->fname,
                  csv->count);
            else
               xprintf("%s:%d: %d fields missing\n", csv->fname,
                  csv->count, lack);
            longjmp(csv->jump, 0);
         }
         else if (csv->what == CSV_NUM)
         {  /* floating-point number */
            if (csv->ref[k] > 0)
            {  double num;
               xassert(str2num(csv->field, &num) == 0);
               mpl_tab_set_num(dca, csv->ref[k], num);
            }
         }
         else if (csv->what == CSV_STR)
         {  /* character string */
            if (csv->ref[k] > 0)
               mpl_tab_set_str(dca, csv->ref[k], csv->field);
         }
         else
            xassert(csv != csv);
      }
      /* now there must be NL */
      read_field(csv);
      xassert(csv->what != CSV_EOF);
      if (csv->what != CSV_EOR)
      {  xprintf("%s:%d: too many fields\n", csv->fname, csv->count);
         longjmp(csv->jump, 0);
      }
done: return ret;
}
Beispiel #26
0
uint Aligner::checkBeginGreedy(const string& read, pair<kmer, uint>& overlap, vector<uNumber>& path, uint errors){
	if(overlap.second==0){path.push_back(0);return 0;}
	string readLeft(read.substr(0,overlap.second)),unitig;
	auto rangeUnitigs(getEnd(overlap.first));
	uint minMiss(errors+1),indiceMinMiss(0);
	bool ended(false);
	int offset(0);
	kmer nextOverlap(0);

	for(uint i(0); i<rangeUnitigs.size(); ++i){
		unitig=(rangeUnitigs[i].first);
		if(unitig.size()-k+1>=readLeft.size()){
			uint miss(missmatchNumber(unitig.substr(unitig.size()-readLeft.size()-k+1,readLeft.size()),readLeft, errors));
			// if(miss==0){
			// 	path.push_back(unitig.size()-readLeft.size()-k+1);
			// 	path.push_back(rangeUnitigs[i].second);
			// 	return 0;
			// }
			if(miss<minMiss){
				minMiss=miss;
				indiceMinMiss=i;
				ended=true;
				offset=unitig.size()-readLeft.size()-k+1;
			}
		}else{
			uint miss(missmatchNumber(unitig.substr(0,unitig.size()-k+1), readLeft.substr(readLeft.size()+k-1-unitig.size()), errors));
			// if(miss==0){
			// 	minMiss+=mapOnLeftEndGreedy(read, path, {nextOverlap,overlap.second-(nextUnitig.size()-k+1)},errors);
			// 	if(minMiss<=errors){
			// 		path.push_back(rangeUnitigs[indiceMinMiss].second);
			// 		sucessML++;
			// 	}
			// }
			if(miss<minMiss){
				kmer overlapNum(str2num(unitig.substr(0,k-1)));
				if(miss<minMiss){
					ended=false;
					minMiss=miss;
					indiceMinMiss=i;
					nextOverlap=overlapNum;
				}
			}

		}
	}

	if(minMiss<=errors){
		if(ended){
			path.push_back(offset);
			path.push_back(rangeUnitigs[indiceMinMiss].second);
			return minMiss;
		}
		minMiss+=mapOnLeftEndGreedy(read, path, {nextOverlap,overlap.second-(rangeUnitigs[indiceMinMiss].first.size()-k+1)},errors-minMiss);
		if(minMiss<=errors){
			path.push_back(rangeUnitigs[indiceMinMiss].second);
			sucessML++;
		}
	}
	return minMiss;
}
Beispiel #27
0
errInfo newWork(const std::wstring &name, const std::wstring &info, work **ret)
{
	dataBuf buf;
	CURL *handle = curl_easy_init();
	std::string postField = "field=work&operation=add&name=" + encode(name) + "&info=" + encode(toSingleLine(info));
	std::unique_ptr<char[]> errBuf = std::make_unique<char[]>(2048);
	CURLcode success;
	curl_easy_setopt(handle, CURLOPT_URL, scriptURL);
	curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, errBuf.get());
	curl_easy_setopt(handle, CURLOPT_POSTFIELDS, postField.c_str());
	curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_data);
	curl_easy_setopt(handle, CURLOPT_WRITEDATA, &buf);
	success = curl_easy_perform(handle);
	if (success != CURLcode::CURLE_OK)
	{
		curl_easy_cleanup(handle);
		std::string err(errBuf.get());
		return errInfo("E:network:" + err);
	}
	curl_easy_cleanup(handle);
	
	size_t newID;
	if (str2num(buf, newID) != 0)
		return errInfo(std::string("E:Server side error:") + buf);
	*ret = new work(newID, name, info);
	workList.emplace(newID, *ret);

	return errInfo();
}
Beispiel #28
0
int cmd_read(int argc, const char** argv)
{
	u8* data = NULL;
	cable* cbl;
	const char* param;
	chip* dev;
	int index, length;
	program_file* f = NULL;

	// Position
	param = cmdline_get_non_opt(argc, argv, 0);
	if (param == NULL || str2num(param, &index) || index <= 0)
	{
        msgf(STR_INVALID_PARAMETERS);
		return 0;
    }

	// File name
	param = cmdline_get_non_opt(argc, argv, 1);
	if (param == NULL)
	{
        msgf(STR_INVALID_PARAMETERS);
		return 0;
    }

    cbl = open_cable(1);
    if (cbl == NULL)
        goto cleanup;
	
    dev = select_device_in_chain(index - 1);
    if (dev == NULL)
        goto cleanup;

    msgf(STR_READING, index, dev->name.c_str());
	length = dev->readback(cbl, &data);
	if (length <= 0 || data == NULL)
		goto cleanup;

    f = create_program_file(dev, argc, argv);
	if (f == NULL)
		goto cleanup;

	if (f->save(param, data, length))
		goto cleanup;

	msgf(STR_SUCCESS_COMPLETED);
    
cleanup:

	close_cable(cbl);

	if (data)
        free(data);

    if (f)
        delete f;
    
    return 0;
}
uint Aligner::mapOnRightEndGreedy(const string &read, vector<uNumber>& path, const pair<kmer, uint>& overlap , uint errors){
	// cout<<"moreg"<<endl;
	string unitig,readLeft(read.substr(overlap.second)),nextUnitig;
	// auto rangeUnitigs(getBeginOpti(overlap.first,path.back()));
	auto rangeUnitigs(getBegin(overlap.first));
	uint miniMiss(errors+1), miniMissIndice(9);
	bool ended(false);
	// int offset(0);
	kmer nextOverlap(0);
	// cout<<"go"<<endl;
	// for(uint i(0); i<rangeUnitigs2.size(); ++i){
	// 	cout<<(rangeUnitigs2[i].first)<<endl;
	// }
	// cout<<"true"<<endl;
	for(uint i(0); i<rangeUnitigs.size(); ++i){
		unitig=(rangeUnitigs[i].first);
		// bool stop(false);
		// if(rangeUnitigs[i].first!=rangeUnitigs2[i].first){
		// 	cout<<read<<endl;
		// 	cout<<"lol2"<<endl;
		// 	cout<<rangeUnitigs[i].first<<endl<<rangeUnitigs2[i].first<<endl;
		// 	cout<<rangeUnitigs[i].second<<" "<<rangeUnitigs2[i].second<<endl;
		// 	stop=true;
		// }
		// if(stop){cin.get();}
		// cout<<unitig<<endl;
		// cout<<rangeUnitigs[i].first<<endl;
		//case the rest of the read is too small
		if(readLeft.size()<=unitig.size()){
			uint miss(missmatchNumber(unitig.substr(0,readLeft.size()), readLeft, errors));
			if(miss<miniMiss){
				miniMiss=miss;
				miniMissIndice=i;
				ended=true;
				// offset=unitig.size()-readLeft.size()-k+1;
			}
		}else{
			//case the read is big enough we want to recover a true overlap
			uint miss(missmatchNumber(unitig, read.substr(overlap.second,unitig.size()), errors));
			if(miss<miniMiss){
				if(miss<miniMiss){
					kmer overlapNum(str2num(unitig.substr(unitig.size()-k+1,k-1)));
					miniMiss=miss;
					miniMissIndice=i;
					nextUnitig=unitig;
					nextOverlap=overlapNum;
				}
			}
		}
	}
	// cout<<"end"<<endl;
	if(miniMiss<=errors){
		path.push_back(rangeUnitigs[miniMissIndice].second);
		if (ended){return miniMiss;}
		miniMiss+=mapOnRightEndGreedy(read , path, {nextOverlap,overlap.second+(nextUnitig.size()-k+1)}, errors-miniMiss);
	}
	return miniMiss;
}
Beispiel #30
0
int getRangedValue( std::string str )
{
	int	lovalue ,
		hivalue ,
		retcode = 0;

	gettokennum( str, 0);
	lovalue=str2num(gettokenstr);
	gettokennum( str, 1);
	hivalue=str2num(gettokenstr);

	if (hivalue) {
		retcode = RandomNum(lovalue, hivalue);
	} else {
		retcode = lovalue;
	}
	return retcode;
}