bool isMatch(string s, string p) {
     return isMatch(s.c_str(), p.c_str());
 }
示例#2
0
文件: regex.c 项目: Sasasu/leetcode
int main(int argc, char *argv[])
{
	char s[] = {"bbab"};
	char p[] = {"b*a*"};
	printf("%d\n", isMatch(s, p));
}
示例#3
0
bool FileFind::FindNext(String &name)
{
#ifdef WIN32
  while ( mInternalFind->bFound )
  {
    mInternalFind->bFound = FindNextFileA(mInternalFind->hFindNext, &mInternalFind->finddata);
    if ( (mInternalFind->finddata.cFileName[0] != '.') && !(mInternalFind->finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
    {


      //gOutput->Display("DIRECTORY ENTRY: %s\n",mInternalFind->finddata.cFileName);

      name = mInternalFind->finddata.cFileName;


  		strlwr((char*)name.c_str());

      if ( mWildCard )
      {
        if ( isMatch(mWildCard,name.c_str()) ) return true;
      }
      else
        return true;
    }
  }
  FindClose(mInternalFind->hFindNext);
#endif

#ifdef LINUX_GENERIC

  if ( mInternalFind->mDir )
  {
    while ( 1 )
    {

      struct direct *di = readdir( mInternalFind->mDir );

      if ( !di )
      {
        closedir( mInternalFind->mDir );
        mInternalFind->mDir = 0;
        return false;
      }

      //gOutput->Display("DIRECTORY ENTRY: %s\n",di->d_name);

      if ( strcmp(di->d_name,".") == 0 || strcmp(di->d_name,"..") == 0 )
      {
        // skip it!
      }
      else
      {
        name = di->d_name;
    		stringutils::strlwr((char*)name.c_str());
        if ( mWildCard )
        {
          if ( mWildCard->Match(name.c_str()) ) return true;
        }
        else
          return true;
      }
    }
  }
#endif

  return false; // finished search.
}
示例#4
0
void testIsMatch2(){
    bool res = isMatch("aba","*a");
    printf("Finished %d \n",res);
}
示例#5
0
文件: wav_lua.c 项目: mikecat/wav_lua
int main(int argc, char *argv[]) {
	FILE *fp;
	unsigned char header[44] = {};
	unsigned int channel_num;
	unsigned int sample_rate;
	unsigned int bit_per_sample;
	unsigned int block_size;
	unsigned int data_size;
	unsigned int sample_num;
	unsigned int sample;
	unsigned int channel;
	int i;
	int retnum;
	lua_State *s;
	if (argc < 4) {
		fprintf(stderr, "Usage: %s <input file> <output file> <script file> [parameters...]\n", argc > 0 ? argv[0] : "wav_lua");
		return 1;
	}
	if (argv[1][0] != '-' || argv[1][1] != '\0') {
		unsigned int header_size;
		fp = fopen(argv[1], "rb");
		if (fp == NULL) {
			fputs("input file open error\n", stderr);
			return 1;
		}
		if (fread(header, 1, 44, fp) != 44) {
			fputs("input file read error\n", stderr);
			fclose(fp);
			return 1;
		}
		channel_num = getData(&header[22], 2);
		sample_rate = getData(&header[24], 4);
		bit_per_sample = getData(&header[34], 2);
		block_size = getData(&header[32], 2);

		header_size = getData(&header[16], 4);
		if (header_size > 16) {
			if (fseek(fp, 20 + header_size, SEEK_SET)) {
				fputs("input file seek error\n", stderr);
				fclose(fp);
				return 1;
			}
			header[16] = 0x10; header[17] = 0; header[18] = 0; header[19] = 0;
			for (;;) {
				if (fread(&header[36], 1, 8, fp) != 8) {
					fputs("input file read error\n", stderr);
					fclose(fp);
					return 1;
				}
				if (isMatch(&header[36], "data", 4)) {
					break;
				} else {
					unsigned int chunk_size = getData(&header[40], 4);
					if (fseek(fp, chunk_size, SEEK_CUR)) {
						fputs("input file seek error\n", stderr);
						fclose(fp);
						return 1;
					}
				}
			}
		}

		data_size = getData(&header[40], 4);
		if (!isMatch(&header[0], "RIFF", 4) || !isMatch(&header[8], "WAVEfmt ", 8) || !isMatch(&header[36], "data", 4) ||
		getData(&header[20], 2) != 1 || getData(&header[28], 4) != channel_num * bit_per_sample / 8 * sample_rate ||
		block_size != channel_num * bit_per_sample / 8 || data_size % block_size != 0 ||
		(bit_per_sample != 8 && bit_per_sample != 16)) {
			fputs("unsupported input format\n", stderr);
			return 1;
		}
		sample_num = data_size / block_size;
		s = luaL_newstate();
		if (s == NULL) {
			fputs("failed to create Lua state\n", stderr);
			fclose(fp);
			return 1;
		}
		luaL_openlibs(s);
		if (luaL_dofile(s, argv[3])) {
			const char *str = luaL_checkstring(s, -1);
			fputs("failed to load Lua script\n", stderr);
			if (str != NULL) fputs(str, stderr);
			fclose(fp);
			lua_close(s);
			return 1;
		}

		if (lua_getglobal(s, "process") != LUA_TFUNCTION) {
			fputs("process is not a function\n", stderr);
			fclose(fp);
			lua_close(s);
			return 1;
		}

		lua_createtable(s, channel_num, 0);
		for (channel = 0; channel < channel_num; channel++) {
			lua_createtable(s, sample_num, 0);
		}
		for (sample = 1; sample <= sample_num; sample++) {
			for (channel = 0; channel < channel_num; channel++) {
				unsigned char data[2];
				double value = 0;
				if (fread(data, 1, bit_per_sample / 8, fp) != bit_per_sample / 8) {
					fputs("input read error\n", stderr);
					fclose(fp);
					lua_close(s);
					return 1;
				}
				if (bit_per_sample == 8) {
					value = (double)(data[0] - 128) / 128.0;
				} else if (bit_per_sample == 16) {
					unsigned int v = getData(data, 2);
					if (v & 0x8000) {
						value = (double)(-((int)(~v+1) & 0xffff)) / 32768.0;
					} else {
						value = (double)v / 32768.0;
					}
				}
				lua_pushnumber(s, value);
				lua_seti(s, -2 - channel, sample);
			}
		}
		fclose(fp);
		for (channel = 1; channel <= channel_num; channel++) {
			lua_seti(s, 2, channel);
		}
	} else {
		header[0] = 'R'; header[1] = 'I'; header[2] = 'F'; header[3] = 'F';
		header[8] = 'W'; header[9] = 'A'; header[10] = 'V'; header[11] = 'E';
		header[12] = 'f'; header[13] = 'm'; header[14] = 't'; header[15] = ' ';
		header[16] = 0x10; header[17] = 0; header[18] = 0; header[19] = 0;
		header[20] = 1; header[21] = 0;
		header[36]= 'd'; header[37] = 'a'; header[38] = 't'; header[39] = 'a';

		channel_num = 0;
		sample_rate = 44100;
		bit_per_sample = 16;
		block_size = 0;
		data_size = 0;

		s = luaL_newstate();
		if (s == NULL) {
			fputs("failed to create Lua state\n", stderr);
			return 1;
		}
		luaL_openlibs(s);
		if (luaL_dofile(s, argv[3])) {
			const char *str = luaL_checkstring(s, -1);
			fputs("failed to load Lua script\n", stderr);
			if (str != NULL) fputs(str, stderr);
			lua_close(s);
			return 1;
		}

		if (lua_getglobal(s, "process") != LUA_TFUNCTION) {
			fputs("process is not a function\n", stderr);
			lua_close(s);
			return 1;
		}

		lua_createtable(s, channel_num, 0);
	}

	lua_pushinteger(s, sample_rate);

	lua_createtable(s, argc - 4, 0);
	for (i = 0; i < argc - 4; i++) {
		lua_pushstring(s, argv[i + 4]);
		lua_seti(s, -2, i + 1);
	}

	if (lua_pcall(s, 3, LUA_MULTRET, 0) != LUA_OK) {
		const char *str = luaL_checkstring(s, -1);
		fputs("error in executing Lua script\n", stderr);
		if (str != NULL) fputs(str, stderr);
		lua_close(s);
		return 1;
	}

	if (argv[2][0] != '-' || argv[2][1] != '\0') {
		retnum = lua_gettop(s);
		if (retnum > 3) {
			fputs("too many return data from Lua script\n", stderr);
			lua_close(s);
			return 1;
		} else if (retnum > 0 && !lua_isnil(s, 1)) {
			if (!lua_istable(s, 1)) {
				fputs("the first return data is neither a table nor nil\n", stderr);
				lua_close(s);
				return 1;
			}
			if (retnum >= 2) {
				if (lua_isinteger(s, 2)) {
					sample_rate = luaL_checkinteger(s, 2);
				} else {
					fputs("the second return data is not an integer\n", stderr);
					lua_close(s);
					return 1;
				}
			}
			if (retnum >= 3) {
				if (lua_isinteger(s, 3)) {
					bit_per_sample = luaL_checkinteger(s, 3);
				} else {
					fputs("the third return data is not an integer\n", stderr);
					lua_close(s);
					return 1;
				}
			}
		}
		if (retnum > 1) lua_pop(s, retnum - 1);
		channel_num = luaL_len(s, 1);
		if (channel_num > 0) {
			if (bit_per_sample != 8 && bit_per_sample != 16) {
				fputs("unsupported output bit per sample\n", stderr);
				lua_close(s);
				return 1;
			}
			for (channel = 1; channel <= channel_num; channel++) {
				lua_geti(s, 1, channel);
				if (channel == 1) {
					sample_num = luaL_len(s, -1);
				} else if (sample_num != luaL_len(s, -1)) {
					fputs("the number of samples mismatch\n", stderr);
					lua_close(s);
					return 1;
				}
			}
			setData(&header[4], channel_num * bit_per_sample / 8 * sample_num + 36, 4);
			setData(&header[22], channel_num, 2);
			setData(&header[24], sample_rate, 4);
			setData(&header[28], channel_num * bit_per_sample / 8 * sample_rate, 4);
			setData(&header[32], channel_num * bit_per_sample / 8, 2);
			setData(&header[34], bit_per_sample, 2);
			setData(&header[40], channel_num * bit_per_sample / 8 * sample_num, 4);
			for (sample = 1; sample <= sample_num; sample++) {
				for (channel = 1; channel <= channel_num; channel++) {
					lua_geti(s, channel + 1, sample);
					if (!lua_isnumber(s, -1)) {
						fputs("some of the data is invalid\n", stderr);
						lua_close(s);
						return 1;
					}
					lua_pop(s, 1);
				}
			}
			fp = fopen(argv[2], "wb");
			if (fp == NULL) {
				fputs("output file open error\n", stderr);
				lua_close(s);
				return 1;
			}
			if (fwrite(header, 1, 44, fp) != 44) {
				fputs("output file write error\n", stderr);
				fclose(fp);
				lua_close(s);
				return 1;
			}
			for (sample = 1; sample <= sample_num; sample++) {
				for (channel = 1; channel <= channel_num; channel++) {
					double value;
					unsigned char data[2];
					int v;
					lua_geti(s, channel + 1, sample);
					value = luaL_checknumber(s, -1);
					if (value < -1.0) value = -1.0;
					if (value > 1.0) value = 1.0;
					lua_pop(s, 1);
					if (bit_per_sample == 8) {
						v = (int)(value * 128 + 128);
						if (v < 0) v = 0;
						if (v > 255) v = 255;
						data[0] = (unsigned char)v;
						if (fwrite(data, 1, 1, fp) != 1) {
							fputs("output file write error\n", stderr);
							fclose(fp);
							lua_close(s);
							return 1;
						}
					} else if (bit_per_sample == 16) {
						v = (int)(value * 32768);
						if (v < -32768) v = -32768;
						if (v > 32767) v = 32767;
						setData(data, v, 2);
						if (fwrite(data, 1, 2, fp) != 2) {
							fputs("output file write error\n", stderr);
							fclose(fp);
							lua_close(s);
							return 1;
						}
					}
				}
			}
			fclose(fp);
		}

		lua_pop(s, channel_num + 1);
	} else {
		lua_pop(s, lua_gettop(s));
	}
	lua_close(s);
	return 0;
}
示例#6
0
Status ModifierPull::prepare(mb::Element root, StringData matchedField, ExecInfo* execInfo) {
    _preparedState.reset(new PreparedState(root.getDocument()));

    // If we have a $-positional field, it is time to bind it to an actual field part.
    if (_posDollar) {
        if (matchedField.empty()) {
            return Status(ErrorCodes::BadValue,
                          str::stream() << "The positional operator did not find the match "
                                           "needed from the query. Unexpanded update: "
                                        << _fieldRef.dottedField());
        }
        _fieldRef.setPart(_posDollar, matchedField);
    }

    // Locate the field name in 'root'.
    Status status = pathsupport::findLongestPrefix(
        _fieldRef, root, &_preparedState->idxFound, &_preparedState->elemFound);

    // FindLongestPrefix may say the path does not exist at all, which is fine here, or
    // that the path was not viable or otherwise wrong, in which case, the mod cannot
    // proceed.
    if (status.code() == ErrorCodes::NonExistentPath) {
        _preparedState->elemFound = root.getDocument().end();
    } else if (!status.isOK()) {
        return status;
    }

    // We register interest in the field name. The driver needs this info to sort out if
    // there is any conflict among mods.
    execInfo->fieldRef[0] = &_fieldRef;

    if (!_preparedState->elemFound.ok() || _preparedState->idxFound < (_fieldRef.numParts() - 1)) {
        // If no target element exists, then there is nothing to do here.
        _preparedState->noOp = execInfo->noOp = true;
        return Status::OK();
    }

    // This operation only applies to arrays
    if (_preparedState->elemFound.getType() != mongo::Array)
        return Status(ErrorCodes::BadValue, "Cannot apply $pull to a non-array value");

    // If the array is empty, there is nothing to pull, so this is a noop.
    if (!_preparedState->elemFound.hasChildren()) {
        _preparedState->noOp = execInfo->noOp = true;
        return Status::OK();
    }

    // Walk the values in the array
    mb::Element cursor = _preparedState->elemFound.leftChild();
    while (cursor.ok()) {
        if (isMatch(cursor))
            _preparedState->elementsToRemove.push_back(cursor);
        cursor = cursor.rightSibling();
    }

    // If we didn't find any elements to add, then this is a no-op, and therefore in place.
    if (_preparedState->elementsToRemove.empty()) {
        _preparedState->noOp = execInfo->noOp = true;
    }

    return Status::OK();
}
#include "../src/RegularMatching.hpp"
#include "external/single_include/catch.hpp"


TEST_CASE("RegularMatching","[isMatch]") {
  REQUIRE(isMatch("123", "123") == true);
  //REQUIRE(isMatch("123", "*") == true); p[0] can't be '*'
  REQUIRE(isMatch("", "") == true);
  //REQUIRE(isMatch("abcd", "d*") == true);
  REQUIRE(isMatch("abcd", "d*") == false);
}
 bool isMatch(string s, string p) {
     n = s.size(), m = p.size();
     return isMatch(s, p, 0, 0);
 }
//--------------------------------------------------------------
void LayerTransform::processOscCommand(const string& command, const ofxOscMessage& m) {
    
    if(isMatch(command,"position") || isMatch(command,"p")) {
        if(validateOscSignature("([if][if]?[if]?)|([s][if])", m)) {
            if(m.getArgType(0) == OFXOSC_TYPE_STRING) {
                char c = tolower(getArgAsStringUnchecked(m,0)[0]);
                
                if(c == 'x') {
                    setPositionX(getArgAsFloatUnchecked(m,1));
                } else if(c == 'y') {
                    setPositionY(getArgAsFloatUnchecked(m,1));
                } else if(c == 'z') {
                    setPositionZ(getArgAsFloatUnchecked(m,1));
                } else if(c == 'n') {
                    setPositionNormalized(getArgAsBoolUnchecked(m,1));
                } else {
                    ofLogError("LayerTransform") << "invalid arg type: " << c << " " << command << ".";
                }
                
            } else {
                setPositionX(getArgAsFloatUnchecked(m,0));
                if(m.getNumArgs() > 1) {
                    setPositionY(getArgAsFloatUnchecked(m,1));
                    if(m.getNumArgs() > 2) {
                        setPositionZ(getArgAsFloatUnchecked(m,2));
                    }
                }
            }
        }
        
    } else if(isMatch(command,"anchorpoint") || isMatch(command,"a")) {

        if(validateOscSignature("([if][if]?[if]?)|([s][if])", m)) {
            if(m.getArgType(0) == OFXOSC_TYPE_STRING) {
                
                char c = tolower(getArgAsStringUnchecked(m,0)[0]);
                
                if(c == 'x') {
                    setAnchorPointX(getArgAsFloatUnchecked(m,1));
                } else if(c == 'y') {
                    setAnchorPointY(getArgAsFloatUnchecked(m,1));
                } else if(c == 'z') {
                    setAnchorPointZ(getArgAsFloatUnchecked(m,1));
                } else if(c == 'n') {
                    setAnchorPointNormalized(getArgAsBoolUnchecked(m,1));
                } else {
                    ofLog(OF_LOG_ERROR, "LayerTransform: invalid arg type: " + ofToString(c) + " " + command);
                }
                
                
            } else {
                
                setAnchorPointX(getArgAsFloatUnchecked(m,0));
                if(m.getNumArgs() > 1) {
                    setAnchorPointY(getArgAsFloatUnchecked(m,1));
                    if(m.getNumArgs() > 2) {
                        setAnchorPointZ(getArgAsFloatUnchecked(m,2));
                    }
                }
            }
        }
        
    } else if(isMatch(command,"rotate") || isMatch(command,"r")) {
        if(validateOscSignature("([if][if]?[if]?)|([s][if][if]?[if]?)", m)) {
            
            if(m.getArgType(0) == OFXOSC_TYPE_STRING) {
                
                char c = tolower(getArgAsStringUnchecked(m,0)[0]);

                if(c == 'x') {
                    setRotationX(getArgAsFloatUnchecked(m,1));
                } else if(c == 'y') {
                    setRotationY(getArgAsFloatUnchecked(m,1));
                } else if(c == 'z') {
                    setRotationZ(getArgAsFloatUnchecked(m,1));
                } else if(c == 'd') {
                    setRotation(getArgsAsPoint(m, 1));
                } else if(c == 'n') {
                    setRotationNormalized(getArgAsBoolUnchecked(m,1));
                } else {
                    ofLog(OF_LOG_ERROR, "LayerTransform: invalid arg type: " + ofToString(c) + " " + command);
                }
                
                
            } else {
                setRotationX(getArgAsFloatUnchecked(m,0));
                if(m.getNumArgs() > 1) {
                    setRotationY(getArgAsFloatUnchecked(m,1));
                    if(m.getNumArgs() > 2) {
                        setRotationZ(getArgAsFloatUnchecked(m,2));
                    }
                }
            }
        }
    } else if(isMatch(command,"scale") || isMatch(command,"s")) {
        if(validateOscSignature("([f][f]?[f]?)|([s][f])", m)) {
            if(m.getArgType(0) == OFXOSC_TYPE_STRING) {
                
                char  c = tolower(getArgAsStringUnchecked(m,0)[0]);
                float val = getArgAsFloatUnchecked(m,1);
                
                if(c == 'x') {
                    setScaleX(val);
                } else if(c == 'y') {
                    setScaleY(val);
                } else if(c == 'z') {
                    setScaleZ(val);
                } else {
                    ofLog(OF_LOG_ERROR, "LayerTransform: invalid arg type: " + ofToString(c) + " " + command);
                }
                
            } else {
                setScaleX(getArgAsFloatUnchecked(m,0));
                if(m.getNumArgs() > 1) {
                    setScaleY(getArgAsFloatUnchecked(m,1));
                    if(m.getNumArgs() > 2) {
                        setScaleZ(getArgAsFloatUnchecked(m,2));
                    }
                }
            }
        }
        
    } else if(isMatch(command,"opacity") || isMatch(command,"o")) {
        if(validateOscSignature("[if]", m)) {
            setOpacity(getArgAsFloatUnchecked(m,0));
        }
    } else if(isMatch(command,"opacityn") || isMatch(command,"on")) {
        if(validateOscSignature("[if]", m)) {
            setOpacityNormalized(getArgAsFloatUnchecked(m,0));
        }
    } else if(isMatch(command,"size") || isMatch(command, "sz")) {
        if(validateOscSignature("[if][if]", m)) {
            setSize(getArgAsFloatUnchecked(m,0),getArgAsFloatUnchecked(m,1));
        }
    } else if(isMatch(command,"width") || isMatch(command, "w")) {
        if(validateOscSignature("[if]", m)) {
            setWidth(getArgAsFloatUnchecked(m,0));
        }
    } else if(isMatch(command,"height") || isMatch(command, "h")) {
        if(validateOscSignature("[if]", m)) {
            setHeight(getArgAsFloatUnchecked(m,0));
        }
    }
    
}
void
NDalgorithm::forward(char    *A,   int32 Alen,
                     char    *T,   int32 Tlen,
                     int32   &A_End,
                     int32   &T_End,
                     bool    &Match_To_End) {

  assert (Alen <= Tlen);

  int32  Best_d      = 0;
  int32  Best_e      = 0;
  int32  Best_row    = 0;
  int32  Best_score  = 0;


  int32  Row = 0;
  int32  Dst = 0;
  int32  Err = 0;
  int32  Sco = 0;

  int32  fromd = 0;

  //  Skip ahead over matches.  The original used to also skip if either sequence was N.
  while ((Row < Alen) && (isMatch(A[Row], T[Row]))) {
    Sco += matchScore(A[Row], T[Row]);
    Row++;
  }

  if (Edit_Array_Lazy[0] == NULL)
    allocateMoreEditSpace();

  Edit_Array_Lazy[0][0].row    = Row;
  Edit_Array_Lazy[0][0].dist   = Dst;
  Edit_Array_Lazy[0][0].errs   = 0;
  Edit_Array_Lazy[0][0].score  = Sco;
  Edit_Array_Lazy[0][0].fromd  = INT32_MAX;

  // Exact match?

  if (Row == Alen) {
    A_End        = Alen;
    T_End        = Alen;
    Match_To_End = true;

    Right_Score       = Sco;
    Right_Delta_Len   = 0;

    return;
  }

  int32  Left  = 0;
  int32  Right = 0;

  int32  Max_Score         = PEDMINSCORE;
  int32  Max_Score_Len     = 0;
  int32  Max_Score_Best_d  = 0;
  int32  Max_Score_Best_e  = 0;

  for (int32 ei=1; ei <= Edit_Space_Max; ei++) {
    if (Edit_Array_Lazy[ei] == NULL)
      if (allocateMoreEditSpace() == false) {
        //  FAIL
        return;
      }

    Left  = MAX (Left  - 1, -ei);
    Right = MIN (Right + 1,  ei);

    //fprintf(stderr, "FORWARD ei=%d Left=%d Right=%d\n", ei, Left, Right);

    Edit_Array_Lazy[ei-1][Left  - 1].init();
    Edit_Array_Lazy[ei-1][Left     ].init();
    //  Of note, [0][0] on the first iteration is not reset here.
    Edit_Array_Lazy[ei-1][Right    ].init();
    Edit_Array_Lazy[ei-1][Right + 1].init();

    for (int32 d = Left;  d <= Right;  d++) {

      //  A mismatch.
      {
        int32  aPos         =  (1 + Edit_Array_Lazy[ei-1][d].row)     - 1;  //  -1 because we need to compare the base we are at,
        int32  tPos         =  (1 + Edit_Array_Lazy[ei-1][d].row) + d - 1;  //  not the base we will be at after the mismatch

        Row   = 1 + Edit_Array_Lazy[ei-1][d].row;
        Dst   =     Edit_Array_Lazy[ei-1][d].dist  + 1;
        Err   =     Edit_Array_Lazy[ei-1][d].errs  + 1;
        fromd =     d;

        //  If positive, we have a pointer into valid sequence.  If not, this mismatch
        //  doesn't make sense, and the row/score are set to bogus values.

        if ((aPos >= 0) && (tPos >= 0)) {
          assert (aPos <= Alen);
          assert( tPos <= Tlen);

          assert(A[aPos] != T[tPos]);

          Sco = Edit_Array_Lazy[ei-1][d].score + mismatchScore(A[aPos], T[tPos]);

        } else {
          Sco = PEDMINSCORE;
        }
      }

      //  Insert a gap in A.  Check the other sequence to see if this is a zero-cost gap.  Note
      //  agreement with future value of Row and what is used in isMatch() below.

      {
        int32  tPos    = 0 + Edit_Array_Lazy[ei-1][d-1].row + d;

        //assert(tPos >= 0);
        //assert(tPos < Tlen);

        if ((tPos >= 0) && (tPos <= Tlen)) {
          int32  gapCost = isFreeGap( T[tPos] ) ? PEDFREEGAP : PEDGAP;

          //if (gapCost == 0)
          //  fprintf(stderr, "NDalgorithm::forward()--  free A gap for aPos=%d tPos=%d t=%c/%d\n", tPos - d, tPos, T[tPos], T[tPos]);

          if (Edit_Array_Lazy[ei-1][d-1].score + gapCost > Sco) {
            Row   =     Edit_Array_Lazy[ei-1][d-1].row;
            Dst   =     Edit_Array_Lazy[ei-1][d-1].dist  + (gapCost == PEDFREEGAP) ? 0 : 0;
            Err   =     Edit_Array_Lazy[ei-1][d-1].errs  + (gapCost == PEDFREEGAP) ? 0 : 0;
            Sco   =     Edit_Array_Lazy[ei-1][d-1].score +  gapCost;
            fromd =     d-1;
          }
        }
      }

      //  Insert a gap in T.
      //  Testcase test-st-ts shows this works.

      {
        int32  aPos    = 1 + Edit_Array_Lazy[ei-1][d+1].row;

        //assert(aPos >= 0);
        //assert(aPos < Tlen);

        if ((aPos >= 0) && (aPos <= Alen)) {
          int32  gapCost = isFreeGap( A[aPos] ) ? 0 : PEDGAP;

          //if (gapCost == 0)
          //  fprintf(stderr, "NDalgorithm::forward()--  free T gap for aPos=%d tPos=%d a=%c/%d\n", aPos, aPos + d, A[aPos], A[aPos]);

          if (Edit_Array_Lazy[ei-1][d+1].score + gapCost > Sco) {
            Row   = 1 + Edit_Array_Lazy[ei-1][d+1].row;
            Dst   =     Edit_Array_Lazy[ei-1][d+1].dist  + (gapCost == PEDFREEGAP) ? 0 : 1;
            Err   =     Edit_Array_Lazy[ei-1][d+1].errs  + (gapCost == PEDFREEGAP) ? 0 : 1;
            Sco   =     Edit_Array_Lazy[ei-1][d+1].score +  gapCost;
            fromd =     d+1;
          }
        }
      }

      //  If A or B is N, that isn't a mismatch.
      //  If A is lowercase and T is uppercase, it's a match.
      //  If A is lowercase and T doesn't match, ignore the cost of the gap in B

      while ((Row < Alen) && (Row + d < Tlen) && (isMatch(A[Row], T[Row + d]))) {
        Sco += matchScore(A[Row], T[Row + d]);
        Row += 1;
        Dst += 1;
        Err += 0;
      }

      Edit_Array_Lazy[ei][d].row   = Row;
      Edit_Array_Lazy[ei][d].dist  = Dst;
      Edit_Array_Lazy[ei][d].errs  = Err;
      Edit_Array_Lazy[ei][d].score = Sco;
      Edit_Array_Lazy[ei][d].fromd = fromd;

      //fprintf(stderr, "SET ei=%d d=%d -- row=%d dist=%d errs=%d score=%d fromd=%d\n", ei, d, Row, Dst, Err, Sco, fromd);

      if (Row == Alen || Row + d == Tlen) {
        A_End = Row;           // One past last align position
        T_End = Row + d;

        Set_Right_Delta(ei, d);

        Match_To_End = true;

        return;  //return(ei);
      }
    }  //  Over all diagonals.

    //  Reset the band
    //
    //  The .dist used to be .row.

    while  ((Left <= Right) && (Left < 0) && (Edit_Array_Lazy[ei][Left].dist < Edit_Match_Limit[ Edit_Array_Lazy[ei][Left].errs ]))
      Left++;

    if (Left >= 0)
      while  ((Left <= Right) && (Edit_Array_Lazy[ei][Left].dist + Left < Edit_Match_Limit[ Edit_Array_Lazy[ei][Left].errs ]))
        Left++;

    if (Left > Right)
      break;

    while  ((Right > 0) && (Edit_Array_Lazy[ei][Right].dist + Right < Edit_Match_Limit[ Edit_Array_Lazy[ei][Right].errs ]))
      Right--;

    if (Right <= 0)
      while  (Edit_Array_Lazy[ei][Right].dist < Edit_Match_Limit[ Edit_Array_Lazy[ei][Right].errs ])
        Right--;

    assert (Left <= Right);

    for (int32 d = Left;  d <= Right;  d++)
      if (Edit_Array_Lazy[ei][d].score > Best_score) {
        Best_d      = d;
        Best_e      = ei;
        Best_row    = Edit_Array_Lazy[ei][d].row;
        Best_score  = Edit_Array_Lazy[ei][d].score;
      }

    if (Best_score > Max_Score) {
      Max_Score_Best_d = Best_d;
      Max_Score_Best_e = Best_e;
      Max_Score        = Best_score;
      Max_Score_Len    = Best_row;
    }
  }  //  Over all possible number of errors

  //fprintf(stderr, "NDalgorithm::forward()- iterated over all errors, return best found\n");

  A_End = Max_Score_Len;
  T_End = Max_Score_Len + Max_Score_Best_d;

  Set_Right_Delta(Max_Score_Best_e, Max_Score_Best_d);

  Match_To_End = false;

  return;  //return(Max_Score_Best_e);
}
 bool isMatch(string s, string p) {
     const char *str = s.data();
     const char *ptr = p.data();
     return isMatch(str, ptr);
 }
示例#12
0
void handle_backup_req(int sd, char* clientIP){
	char buf[BUFSIZE+100];
	char log_buf[STR_MAX];
	char user[STR_MAX];
	char filename[STR_MAX];
	char filepath[STR_MAX];
	char backup_dir_path[STR_MAX];
	char day[4];
	char date[12];
	char subject[STR_MAX];
	char cmd[STR_MAX];
	int response, len, fid;
	FILE* fp;
	int nsize, fsize, fsize2, fpsize, fpsize2;
	const int endQ = -1;
	int Q, tlen, tresp, i;
	tlen = 0; Q = -1;

	logger(SVR, "BACKUP REQUEST START");

	read(sd, &len, sizeof(len));
	len = ntohl(len);//
	read(sd, user, len);
	
	response = isMatch(user, clientIP);
	tresp = htonl(response);//
	write(sd, &tresp, sizeof(tresp));

	if(response){
		//get file
		read(sd, &len, sizeof(len));
		len = ntohl(len);//
		read(sd, day, len);

		read(sd, &len, sizeof(len));
		len = ntohl(len); //
		read(sd, date, len);

		check_create_dir(backup_dir_path);
		sprintf(backup_dir_path, "%s/%s", BACKUP_DIR, user);
		check_create_dir(backup_dir_path);
		sprintf(backup_dir_path, "%s/%s", backup_dir_path, day);
		check_create_dir(backup_dir_path);
		sprintf(log_buf, "Set Backup directory : %s", backup_dir_path);
		logger(SVR, log_buf);
		
		//check and create directory
		
		while(TRUE){
			read(sd, &len, sizeof(len));
			len = ntohl(len);//
			if(len == endQ) break;
			read(sd, filename, len);
#if DEBUE
			printf("%d %d filename : %s\n", len, endQ, filename);		
#endif
			sprintf(log_buf, "Get filename from %s[%s] : %s\n", user, clientIP, filename);
			logger(SVR, log_buf);

			sprintf(filepath, "%s/%s", backup_dir_path, filename);
			
			fp = fopen(filepath, "wb");

			if((len = recv(sd, &fsize2, sizeof(fsize), 0)) < 0){
				perror("recv");
				exit(1);
			}

			fsize = ntohl(fsize2);
			i = 0;
			nsize = 0;
			printf("file size : %d\n", fsize);
			
			while(nsize < fsize){
				//recv(sd, &fpsize2, sizeof(fpsize2), 0);
				//fpsize = ntohl(fpsize2);
				//printf("fpsize : %d\n", fpsize);
		
				if((len = recv(sd, buf, 4048, 0)) <= 0){
					perror("recv");
					exit(1);
				}
				nsize += len;
				printf("file size = %d, seq = %d, now_size = %d, recv_size = %d\n", fsize, i++, nsize, len);

				if(nsize <= fsize)	fwrite(buf, 1, len, fp);
				else						fwrite(buf, 1, len - sizeof(int), fp);
			}
			
			/*((char*)Q)[0] = buf[len-sizeof(int)];
			((char*)Q)[1] = buf[len-sizeof(int)+1];
			((char*)Q)[2] = buf[len-sizeof(int)+2];
			((char*)Q)[3] = buf[len-sizeof(int)+3];*/
			memcpy((char*)&Q, &buf[len-4], sizeof(Q));
			printf("Q is  %d\n", Q);
			//printf("%d %d %d %d\n", buf[len-4], buf[len-3], buf[len-2], buf[len-1]);
			
			//printf("%d\n", Q);
			fclose(fp);

			//if(Q == endQ) break;
			//recv(sd, &Q, sizeof(Q), 0);
			//Q = ntohl(Q);
			//printf("%d\n", Q);
			//exit(1);
			/*
			if( (fid = open(filepath, O_CREAT | O_WRONLY | O_TRUNC, 0755)) < 0 ){
				sprintf(log_buf, "file open fail : %s", filepath);
				logger(ERR, log_buf);
				exit(1);
			}
			
			i = 0;
			while(TRUE){
				while((tlen = recv(sd, &len, sizeof(len), 0)) != sizeof(tlen)){
					perror("recv");
					//exit(1);
				}
				printf("%d %d %d\n", i++, len, ntohl(len));
				tlen = ntohl(len);

				if(tlen == endQ) break;

				while((len = recv(sd, buf, tlen, 0)) != tlen){
					printf("%d %d\n", len, tlen);
					perror("recv2");
					exit(1);
				}
				if(write(fid, buf, len) < 0){
					perror("write");
					exit(1);
				}

			}

			
			i = 0;
			while(TRUE){
				if(read(sd, &len, sizeof(len)) < 0){
					perror("read");
					exit(1);
				}
				printf("%d %d %d\n", i++, len, ntohl(len));
				len = ntohl(len);//
#if DEBUG
				//printf("len %d %d\n", len, endQ);
#endif
				if(len == endQ) break;

				if((len = read(sd, buf, len)) < 0){
					perror("read2");
					exit(1);
				}
				if(write(fid, buf, len) < 0){
					perror("write");
					exit(1);
				}
			}
		
			if(fid) close(fid);
			sprintf(log_buf, "file[%s] is uploaded.", filepath);
			logger(SVR, log_buf);*/
		}
		/*	
			sprintf(log_buf, "Call: HTMLgen %s %s", user, date);
			logger(SVR, log_buf);

			sprintf(cmd, "./HTMLgen %s %s", user, date);
#if DEBUG
			printf("%s\n", cmd);
#endif	
			system(cmd);

			sprintf(cmd, "./mail_sender %s %s %s", user, clientIP, date);
			system(cmd);

			sprintf(subject, "The backup of %s is finish.", user);
			sprintf(cmd, "mail -s \"$(echo -e \"%s\\nContent-Type: text/html\")\" %s < %s", subject, MAIL_RCPT, MAIL_PATH); 

			system(cmd);
		}*/
	}

	logger(SVR, "BACKUP REQUEST END");
	if(sd) close(sd);
	exit(1);

}
示例#13
0
//@see Design-page 9
void handle_recovery_req(int sd, char* clientIP){
	char buf[RBUFMAX];
	char log_buf[STR_MAX];
	char user[STR_MAX];
	char filename[STR_MAX];
	char filepath[STR_MAX];
	char backup_dir_path[STR_MAX];
	char day[4];
	char date[12];
	char date_list[8][12];
	unsigned int d_list_idx;
	unsigned int i;
	//char cmd[STR_MAX];
	int response, len, fid;
	const int endQ = -1;
	int Q, tlen, tresp;

	tlen = 0;
	logger(SVR, "RECOVERY REQUEST START");
	
	read(sd, &len, sizeof(len));
	len = ntohl(len);//
	read(sd, user, len);
	
	response = isMatch(user, clientIP);
	tresp = htonl(response);//
	write(sd, &tresp, sizeof(tresp));//

	sprintf(backup_dir_path, "%s/%s", BACKUP_DIR, user);
	logger(SVR, "set path");

	if(response){
		//get file
		read(sd, &len, sizeof(len));
		len = ntohl(len);//
		read(sd, date, len);
		printf("%d %s\n", len, date);
		
		d_list_idx = 0;
		d_list_idx = getDateList(date, date_list);
		
		for(i = 0; i <= d_list_idx; i++){
			getWeekDay(date_list[i], day);
			sprintf(filename, "%s.tgz", date_list[i]);
			sprintf(filepath, "%s/%s/%s", backup_dir_path, day, filename);
			
			if( (fid = open(filepath, O_RDONLY)) < 0){
				sprintf(log_buf, "There is no File : %s\n", filepath);
				logger(SVR, log_buf);
				continue;
			}

			//transmit file if it exist

			len = strlen(filename) + 1;
			tlen = htonl(len);//
#if DEBUG
			printf("%d %d %s\n", len, tlen, filename);
#endif
			write(sd, &tlen, sizeof(tlen));
			write(sd, filename, len);

			while( (len = read(fid, buf, sizeof(buf))) > 0 ){
#if DEBUG
				printf("%d %d %d\n", len, htonl(len), sizeof(buf));
#endif
				tlen = htonl(len);//
				write(sd, &tlen, sizeof(tlen));
				write(sd, buf, len);
			}

			printf("%d %d\n", endQ, htonl(endQ));
			Q = htonl(endQ);
			write(sd, &Q, sizeof(Q));

			if(fid) close(fid);

		}
		Q = htonl(endQ);
		write(sd, &Q, sizeof(Q));		
	}
	
	logger(SVR, "RECOVERY REQUEST END");
	if(sd) close(sd);
	exit(1);

}
int main() {
    char* s1="aa";
    char* s2="aa";
    printf(isMatch(s1,s2));
}
示例#15
0
void U2AssemblyReadIterator::skip() {
    while(hasNext() && !isMatch() && !isDeletion()) {
        skipInsertion();
        skipPaddingAndHardClip();
    }
}
示例#16
0
//--------------------------------------------------------------
void PlayerAsset::processOscCommand(const string& command, const ofxOscMessage& m) {
    
    if(isMatch(command,"load")) {
        if(validateOscSignature("s", m)) {
            string assetAlias = getArgAsStringUnchecked(m, 0);
            
            if(hasAssetManager()) {
                BaseMediaAsset* asset = getAssetManager()->getAsset(assetAlias);
                
                if(asset != NULL) {
                    if(asset->isPlayable()) {
                        PlayableAsset* playableAsset = dynamic_cast<PlayableAsset*>(asset);
                        if(playableAsset != NULL) {
                            load(playableAsset);
                        } else {
                            ofLogError("PlayerAsset") << assetAlias << " could not be cast to a playable asset.";
                        }
                        
                    } else {
                        ofLogError("PlayerAsset") << assetAlias << " is not a playable asset.";
                    }
                } else {
                    ofLogError("PlayerAsset") << "no asset called " << assetAlias << " exists.";
                }
            }
            
            
            
        }
    } else if(isMatch(command,"start")) {
        player->start();
    } else if(isMatch(command,"stop")) {
        player->stop();
    } else if(isMatch(command,"pause")) {
        if(validateOscSignature("[sfi]", m)) {
            player->setPaused(getArgAsBoolUnchecked(m,0));
        }
    } else if(isMatch(command,"loopmode")) {
        if(validateOscSignature("s", m)) {
            string loopMode = getArgAsStringUnchecked(m,0);
            if(isMatch(loopMode,"NONE")) {
                player->setLoopType(OF_LOOP_NONE);
            } else if(isMatch(loopMode,"LOOP")) {
                player->setLoopType(OF_LOOP_NORMAL);
            } else if(isMatch(loopMode,"PALINDROME")) {
                player->setLoopType(OF_LOOP_PALINDROME);
            } else {
                ofLog(OF_LOG_WARNING, "FrameBufferPlayer: Unknown loop mode: " + loopMode);
            }
        }
    } else if(isMatch(command,"looppoints")) {
        if(validateOscSignature("[fi][fi]", m)) {
            player->setLoopPoints(getArgAsFloatUnchecked(m,0),getArgAsFloatUnchecked(m,1));
        }
    } else if(isMatch(command,"looppointstart")) {
        if(validateOscSignature("[fi]", m)) {
            player->setLoopPointStart(getArgAsFloatUnchecked(m,0));
        }
    } else if(isMatch(command,"looppointend")) {
        if(validateOscSignature("[fi]", m)) {
            player->setLoopPointStart(getArgAsFloatUnchecked(m,0));
        }
    } else if(isMatch(command,"looppointsn")) {
        if(validateOscSignature("[fi][fi]", m)) {
            player->setLoopPointsNorm(getArgAsFloatUnchecked(m,0),getArgAsFloatUnchecked(m,1));
        }
    } else if(isMatch(command,"looppointstartn")) {
        if(validateOscSignature("[fi]", m)) {
            player->setLoopPointStartNorm(getArgAsFloatUnchecked(m,0));
        }
    } else if(isMatch(command,"looppointendn")) {
        if(validateOscSignature("[fi]", m)) {
            player->setLoopPointStartNorm(getArgAsFloatUnchecked(m,0));
        }
    } else if(isMatch(command,"frame")) {
        if(validateOscSignature("[fi]", m)) {
            player->setFrame(getArgAsFloatUnchecked(m,0));
        }
    } else if(isMatch(command,"framen")) {
        if(validateOscSignature("[fi]", m)) {
            player->setFrameNorm(getArgAsFloatUnchecked(m,0));
        }
    } else if(isMatch(command,"speed")) {
        if(validateOscSignature("[fi]", m)) {
            player->setSpeed(getArgAsFloatUnchecked(m,0));
        }
    } else if(isMatch(command,"dump")) {
        dump();
    } else {
        // unknown command
    }
}
示例#17
0
文件: Realign.cpp 项目: Brainiarc7/TS
bool Realigner::computeSWalignment(vector<CigarOp>& CigarData, vector<MDelement>& MD_data,
                       unsigned int& start_pos_update) {

  string dummy_string;
  
  // Compute boundaries for tubed alignment around previously found alignment
  if (!ComputeTubedAlignmentBoundaries())
    return false;

  // Path ordering creates left aligned InDels
  vector<int> insertion_path_ordering(3);
  vector<int> deletion_path_ordering(3);
  insertion_path_ordering[0] = FROM_I;
  insertion_path_ordering[1] = FROM_MATCH;
  insertion_path_ordering[2] = FROM_MISM;
  deletion_path_ordering[0] = FROM_D;
  deletion_path_ordering[1] = FROM_MATCH;
  deletion_path_ordering[2] = FROM_MISM;

  // --- Compute first row  and column of the matrix
  // First row: moving horizontally for insertions
  if (!soft_clip_left_) {
    DP_matrix[0][1].best_path_direction = FROM_I;
    DP_matrix[0][1].best_score = kGapOpen;
    DP_matrix[0][1].scores[FROM_I] = kGapOpen;
    DP_matrix[0][1].scores[FROM_NOWHERE] = kNotApplicable;
    for (unsigned int q_idx=2; q_idx<q_limit_plus_[0]; q_idx++) {
      DP_matrix[0][q_idx].in_directions[FROM_I] = FROM_I;
      DP_matrix[0][q_idx].scores[FROM_NOWHERE] = kNotApplicable;
      DP_matrix[0][q_idx].scores[FROM_I] = DP_matrix[0][q_idx-1].best_score + kGapExtend;
      DP_matrix[0][q_idx].best_path_direction = FROM_I;
      DP_matrix[0][q_idx].best_score = DP_matrix[0][q_idx-1].best_score + kGapExtend;
    }
  }

  if (!start_anywhere_in_ref_) {
    // First column: moving vertically for deletions
    DP_matrix[1][0].best_path_direction = FROM_D;
    DP_matrix[1][0].best_score = kGapOpen;
    DP_matrix[1][0].scores[FROM_D] = kGapOpen;
    DP_matrix[1][0].scores[FROM_NOWHERE] = kNotApplicable;
    unsigned int t = 2;
    while (t < q_limit_minus_.size() and q_limit_minus_[t] == 0) {
      DP_matrix[t][0].in_directions[FROM_D] = FROM_D;
      DP_matrix[t][0].scores[FROM_NOWHERE] = kNotApplicable;
      DP_matrix[t][0].scores[FROM_D] = DP_matrix[t-1][0].best_score + kGapExtend;
      DP_matrix[t][0].best_path_direction = FROM_D;
      DP_matrix[t][0].best_score = DP_matrix[t-1][0].best_score + kGapExtend;
      t++;
    }
  }

  // ------ Main alignment loop ------
  vector<int>   temp_scores(FROM_NOWHERE);
  vector<int>   highest_score_cell(2, 0);

  for (unsigned int t_idx=1; t_idx<t_seq_.size()+1; t_idx++) {

    for (unsigned int q_idx=q_limit_minus_[t_idx]; q_idx<q_limit_plus_[t_idx]; q_idx++) {

      if (q_idx == 0)
        continue;

      // Scoring for Match; Mismatch / Insertion / Deletion;
      DP_matrix[t_idx][q_idx].scores.assign(FROM_NOWHERE+1, kNotApplicable);
      DP_matrix[t_idx][q_idx].in_directions.assign(FROM_NOWHERE, FROM_NOWHERE);
      if (soft_clip_left_)
        DP_matrix[t_idx][q_idx].scores[FROM_NOWHERE] = 0;

      // 1) - Match / Mismatch Score
      DP_matrix[t_idx][q_idx].is_match = isMatch(q_seq_[q_idx-1], t_seq_[t_idx-1]);
      if (DP_matrix[t_idx][q_idx].is_match) {
        DP_matrix[t_idx][q_idx].in_directions[FROM_MATCH] = DP_matrix[t_idx-1][q_idx-1].best_path_direction;
        DP_matrix[t_idx][q_idx].scores[FROM_MATCH] = DP_matrix[t_idx-1][q_idx-1].best_score + kMatchScore;
      } else {
        DP_matrix[t_idx][q_idx].in_directions[FROM_MISM] = DP_matrix[t_idx-1][q_idx-1].best_path_direction;
        DP_matrix[t_idx][q_idx].scores[FROM_MISM] = DP_matrix[t_idx-1][q_idx-1].best_score + kMismatchScore;
      }

      // 2) - Insertion Score
      temp_scores.assign(FROM_NOWHERE, kNotApplicable);
      temp_scores[FROM_MATCH] = DP_matrix[t_idx][q_idx-1].scores[FROM_MATCH] + kGapOpen;
      temp_scores[FROM_I] = DP_matrix[t_idx][q_idx-1].scores[FROM_I] + kGapExtend;
      temp_scores[FROM_MISM] = DP_matrix[t_idx][q_idx-1].scores[FROM_MISM] + kGapOpen;
      DP_matrix[t_idx][q_idx].scores[FROM_I] = kNotApplicable;
      DP_matrix[t_idx][q_idx].in_directions[FROM_I] = FROM_NOWHERE;
      for (int i=0; i<(int)insertion_path_ordering.size(); i++) {
        if (temp_scores[insertion_path_ordering[i]] > DP_matrix[t_idx][q_idx].scores[FROM_I]) {
          DP_matrix[t_idx][q_idx].scores[FROM_I] = temp_scores[insertion_path_ordering[i]];
          DP_matrix[t_idx][q_idx].in_directions[FROM_I] = insertion_path_ordering[i];
        }
      }

      // 3) - Deletion Score
      temp_scores.assign(FROM_NOWHERE, kNotApplicable);
      temp_scores[FROM_MATCH] = DP_matrix[t_idx-1][q_idx].scores[FROM_MATCH] + kGapOpen;
      temp_scores[FROM_D] = DP_matrix[t_idx-1][q_idx].scores[FROM_D] + kGapExtend;
      temp_scores[FROM_MISM] = DP_matrix[t_idx-1][q_idx].scores[FROM_MISM] + kGapOpen;
      DP_matrix[t_idx][q_idx].scores[FROM_D] = kNotApplicable;
      DP_matrix[t_idx][q_idx].in_directions[FROM_D] = FROM_NOWHERE;
      for (int i=0; i<(int)deletion_path_ordering.size(); i++) {
        if (temp_scores[deletion_path_ordering[i]] > DP_matrix[t_idx][q_idx].scores[FROM_D]) {
          DP_matrix[t_idx][q_idx].scores[FROM_D] = temp_scores[deletion_path_ordering[i]];
          DP_matrix[t_idx][q_idx].in_directions[FROM_D] = deletion_path_ordering[i];
        }
      }

      // Choose best move for this cell
      DP_matrix[t_idx][q_idx].best_score = kNotApplicable-1;
      DP_matrix[t_idx][q_idx].best_path_direction = FROM_NOWHERE;
      for (unsigned int iMove=0; iMove<DP_matrix[t_idx][q_idx].scores.size(); iMove++) {
        if (DP_matrix[t_idx][q_idx].scores[iMove] > DP_matrix[t_idx][q_idx].best_score) {
          DP_matrix[t_idx][q_idx].best_score = DP_matrix[t_idx][q_idx].scores[iMove];
          DP_matrix[t_idx][q_idx].best_path_direction = iMove;
        }
      }

      // Clipping settings determine where we search for the best scoring cell to stop aligning
      bool valid_t_idx = stop_anywhere_in_ref_ or (t_idx == t_seq_.size());
      bool valid_q_idx = soft_clip_right_ or (q_idx == q_seq_.size());
      bool investigate_highscore = valid_t_idx and valid_q_idx;

      if (investigate_highscore and DP_matrix[t_idx][q_idx].best_score
               > DP_matrix[highest_score_cell[0]][highest_score_cell[1]].best_score) {
        highest_score_cell[0] = t_idx;
        highest_score_cell[1] = q_idx;
      }

    }
  }
  // ------- end alignment matrix loop ------

  // Force full string alignment if desired, no matter what the score is.
  if (!stop_anywhere_in_ref_ and !soft_clip_right_) {
    highest_score_cell[0] = t_seq_.size();
    highest_score_cell[1] = q_seq_.size();
  }

  // Backtrack alignment in dynamic programming matrix, generate cigar string / MD tag
  backtrackAlignment(highest_score_cell[0], highest_score_cell[1], CigarData, MD_data, start_pos_update);
  return true;
}
 String ComplexExplanation::getSummary()
 {
     return StringUtils::toString(getValue()) + L" = " + (isMatch() ? L"(MATCH) " : L"(NON-MATCH) ") + getDescription();
 }
示例#19
0
文件: s2.cpp 项目: lzl124631x/code
 bool isMatch(string s, string p) {
     return isMatch(s, 0, p, 0);
 }
示例#20
0
int generatePicture(HumdrumFile& infile, Array<PixelRow>& picture, int
      style) {

   Array<char> marks;
   getMarkChars(marks, infile);
   PixelColor matchcolor(255,255,255);

   infile.analyzeRhythm("4");
   int min = infile.getMinTimeBase();
   double totaldur = infile.getTotalDuration();
   
   int columns = (int)(totaldur * min / 4.0 + 0.5) + 5;
   if (columns > 50000) {
      cout << "Error: picture will be too big to generate" << endl;
      exit(1);
   }
   int factor = (int)(maxwidth / columns);
   if (factor <= 0) {
      factor = 1;
   }
   if (factor > maxfactor) {
      factor = maxfactor;
   }

   // set picture to black first.  Black regions will be filled in
   // with the background later.
   picture.setSize(128);
   int i, j, k;
   PixelColor backcolor(bgcolor);
   for (i=0; i<picture.getSize(); i++) {
      picture[i].setSize(columns * factor);
      for (j=0; j<picture[i].getSize(); j++) {
         picture[i][j] = backcolor;
         // picture[i][j].setRed(0);
         // picture[i][j].setGreen(0);
         // picture[i][j].setBlue(0);
      }
   }

   // examine metric levels for metric coloration
   Array<int>rhylev;
   infile.analyzeMetricLevel(rhylev);
   for (i=0; i<rhylev.getSize(); i++) {
      // reverse sign so that long notes are positive.
      rhylev[i] = -rhylev[i];
   }
   
   PixelColor color;
   int minpitch = 128;
   int maxpitch = -1;
   int pitch = 0;
   double duration = 0;
   double start = 0;
   char buffer[1024] = {0};
   for (i=0; i<infile.getNumLines(); i++) {
      if (debugQ) {
         cout << "Processing input line " << i + 1 << '\t' << infile[i] << endl;
      }
      if (infile[i].isData()) {
         start = infile[i].getAbsBeat();
         for (j=0; j<infile[i].getFieldCount(); j++) {
            if (strcmp(infile[i].getExInterp(j), "**kern") != 0) {
               continue;
            }
            // duration = Convert::kernToDuration(infile[i][j]);
            duration = infile.getTiedDuration(i, j);
            color = makeColor(infile, i, j, style, rhylev, 
                  infile[i].getPrimaryTrack(j));
            for (k=0; k<infile[i].getTokenCount(j); k++) {
               infile[i].getToken(buffer, j, k);
               if (strchr(buffer, '_') != NULL) {
                  continue;
               }
               if (strchr(buffer, ']') != NULL) {
                  continue;
               }

               pitch = Convert::kernToMidiNoteNumber(buffer);
               if (pitch < 0) {
                  // ignore rests
                  continue;
               }
               if (pitch < minpitch) {
                  minpitch = pitch;
               }
               if (pitch > maxpitch) {
                  maxpitch = pitch;
               }
               if (isMatch(marks, buffer)) {
                  placeNote(picture, pitch, start, duration, min, 
                        color, factor, 1);
               } else {
                  placeNote(picture, pitch, start, duration, min, 
                        color, factor, 0);
               }
            }
         }
      }

   }

   gmaxpitch = maxpitch;
   gminpitch = minpitch;
   return factor;
}
示例#21
0
PRIVATE void processRSSList(auto_handle *session, CURL *curl_session, const simple_list items, const rss_feed * feed) {
  simple_list current_item = items;
  HTTPResponse *torrent = NULL;
  char fname[MAXPATHLEN];
  char *download_folder = NULL;
  char *feedID = NULL;
  char *download_url = NULL;

  if(!curl_session && !session) {
    printf("curl_session == NULL && session == NULL\n");
    abort();
  }

  if(feed != NULL) {
    feedID = feed->id;
  }

  while(current_item && current_item->data) {
    feed_item item = (feed_item)current_item->data;

    if(isMatch(session->filters, item->name, feedID, &download_folder)) {
      if(!session->match_only) {
         if(has_been_downloaded(session->downloads, item)) {
            dbg_printf(P_INFO, "Duplicate torrent: %s", item->name);
         } else {
            int8_t result = -1;
            dbg_printft(P_MSG, "[%s] Found new download: %s (%s)", feedID, item->name, item->url);
            if(isMagnetURI(item->url)) {
               result = addMagnetToTM(session, item->url, download_folder);
            } else {
               // It's a torrent file
               // Rewrite torrent URL, if necessary
               if((feed != NULL) && (feed->url_pattern != NULL) && (feed->url_replace != NULL)) {
                  download_url = rewriteURL(item->url, feed->url_pattern, feed->url_replace);
               }

               torrent = downloadTorrent(curl_session, download_url != NULL ? download_url : item->url);
               if(torrent) {
                  get_filename(fname, torrent->content_filename, item->url, session->torrent_folder);

                  /* add torrent to Transmission */
                  result = addTorrentToTM(session, torrent->data, torrent->size, fname, download_folder);
                  HTTPResponse_free(torrent);
               }

               am_free(download_url);
            }

            // process result
            if( result >= 0) {  //result == 0 -> duplicate torrent
               if(result > 0) { //torrent was added
                  if(session->prowl_key_valid) {
                     prowl_sendNotification(PROWL_NEW_DOWNLOAD, session->prowl_key, item->name);
                  }

                  if(session->toasty_key) {
                     toasty_sendNotification(PROWL_NEW_DOWNLOAD, session->toasty_key, item->name);
                  }

                  if(session->pushalot_key) {
                     pushalot_sendNotification(PUSHALOT_NEW_DOWNLOAD, session->pushalot_key, item->name);
                  }
                  
                  if(session->pushover_key) {
                     pushover_sendNotification(PUSHOVER_NEW_DOWNLOAD, session->pushover_key, item->name);
                  }
               }

               /* add url to bucket list */
               result = addToBucket(item->guid != NULL ? item->guid : item->url, &session->downloads, session->max_bucket_items);
               if (result == 0) {
                  session->bucket_changed = 1;
                  save_state(session->statefile, session->downloads);
               }
            } else {  //an error occurred
               if(session->prowl_key_valid) {
                  prowl_sendNotification(PROWL_DOWNLOAD_FAILED, session->prowl_key, item->name);
               }

               if(session->toasty_key) {
                  toasty_sendNotification(PROWL_DOWNLOAD_FAILED, session->toasty_key, item->name);
               }

               if(session->pushalot_key) {
                  pushalot_sendNotification(PUSHALOT_DOWNLOAD_FAILED, session->pushalot_key, item->name);
               }
               
               if(session->pushover_key) {
                  pushover_sendNotification(PUSHOVER_DOWNLOAD_FAILED, session->pushover_key, item->name);
               }
            }
         }
      } else {
         dbg_printft(P_MSG, "[%s] Match: %s (%s)", feedID, item->name, item->url);
      }
    }

    current_item = current_item->next;
  }
}
示例#22
0
int main(int argc, char **argv)
{
	printf("%d\n", isMatch(argv[1], argv[2]));
	return(0);
}
示例#23
0
文件: Wildcard2.c 项目: unasm/utils
int main(int argc, const char *argv[])
{

	//printf("%d\n", isMatch("aab", "c*a*b"));
	printf("%d\n", isMatch("ab", "*ab") == true);
	printf("%d\n", isMatch("ab", "a*b") == true);
	printf("%d\n", isMatch("aa", "") == false);
	printf("%d\n", isMatch("aa", "a") == false);
	printf("%d\n", isMatch("aa", "aa") == true);
	printf("%d\n", isMatch("abefcdgiescdfimde", "ab*cd?i*de") == true);// true expect
	printf("%d\n", isMatch("aaab", "b**") == false);
	printf("%d\n", isMatch("aa", "*?") == true);
	printf("%d\n", isMatch("aa", "*a") == true);

	printf("%d\n", isMatch("aa", "?*") == true);
	printf("%d\n", isMatch("aab", "c*a*b") == false);
	printf("%d\n", isMatch("aa", "a?") == true );
	printf("%d\n", isMatch("aa", "a*") == true);
	printf("%d\n", isMatch("abbaabbbbababaababababbabbbaaaabbbbaaabbbabaabbbbbabbbbabbabbaaabaaaabbbbbbaaabbabbbbababbbaaabbabbabb", "***b**a*a*b***b*a*b*bbb**baa*bba**b**bb***b*a*aab*a**") == true);// true expect
	return 0;
}