예제 #1
0
bool cPluginSatip::SetupParse(const char *nameP, const char *valueP)
{
  debug1("%s", __PRETTY_FUNCTION__);
  // Parse your own setup parameters and store their values.
  if (!strcasecmp(nameP, "OperatingMode"))
     SatipConfig.SetOperatingMode(atoi(valueP));
  else if (!strcasecmp(nameP, "EnableCIExtension"))
     SatipConfig.SetCIExtension(atoi(valueP));
  else if (!strcasecmp(nameP, "CICAM")) {
     int Cicams[MAX_CICAM_COUNT];
     for (unsigned int i = 0; i < ELEMENTS(Cicams); ++i)
         Cicams[i] = 0;
     unsigned int CicamsCount = ParseCicams(valueP, Cicams);
     for (unsigned int i = 0; i < CicamsCount; ++i)
         SatipConfig.SetCICAM(i, Cicams[i]);
     }
  else if (!strcasecmp(nameP, "EnableEITScan"))
     SatipConfig.SetEITScan(atoi(valueP));
  else if (!strcasecmp(nameP, "DisabledSources")) {
     int DisabledSources[MAX_DISABLED_SOURCES_COUNT];
     for (unsigned int i = 0; i < ELEMENTS(DisabledSources); ++i)
         DisabledSources[i] = cSource::stNone;
     unsigned int DisabledSourcesCount = ParseSources(valueP, DisabledSources);
     for (unsigned int i = 0; i < DisabledSourcesCount; ++i)
         SatipConfig.SetDisabledSources(i, DisabledSources[i]);
     }
  else if (!strcasecmp(nameP, "DisabledFilters")) {
     int DisabledFilters[SECTION_FILTER_TABLE_SIZE];
     for (unsigned int i = 0; i < ELEMENTS(DisabledFilters); ++i)
         DisabledFilters[i] = -1;
     unsigned int DisabledFiltersCount = ParseFilters(valueP, DisabledFilters);
     for (unsigned int i = 0; i < DisabledFiltersCount; ++i)
         SatipConfig.SetDisabledFilters(i, DisabledFilters[i]);
     }
  else if (!strcasecmp(nameP, "TransportMode"))
     SatipConfig.SetTransportMode(atoi(valueP));
  else
     return false;
  return true;
}
예제 #2
0
파일: fex.cpp 프로젝트: Flawe/fex
void main(int argc, const char* argv[])
{
	if (argc == 1)
	{
		ShowHelp();
		return;
	}

	// parse arguments
	int i;
	for (i = 1; i < argc - 1; ++i)
	{
		if (argv[i][0] != '-' || strlen(argv[i]) != 2)
		{
			ShowHelp();
			return;
		}

		switch (argv[i][1])
		{
		case 'e':
			i++;
			ParseFilters(argv[i]);
			break;
		case 'd':
			i++;
			AddDirectory(argv[i]);
			break;
		case 'r':
			recursive = true;
			break;
		case 'c':
			cache = true;
			break;
		case 'C':
			recache = true;
			break;
		}
	}

	if (filters.size() == 0)
	{
		printf("fex: no file extensions specified\n");
		return;
	}

	if (folders.size() == 0)
	{
		printf("fex: no directories specified\n");
		return;
	}

	if (i == argc)
	{
		printf("fex: no search pattern specified\n");
		return;
	}

	//LARGE_INTEGER start1, stop1, start2, stop2;
	//QueryPerformanceCounter(&start1);

	// build our data
	BuildPackage();

	//QueryPerformanceCounter(&stop1);

	if (megaBuffer)
	{
		//QueryPerformanceCounter(&start2);

		RE2 mainSearch(argv[argc - 1]);
		RE2 newLineSearch("\n");

		re2::StringPiece newLineString;
		re2::StringPiece megaString(megaBuffer, megaBufferSize);
		int num = 0;
		int lastFound = 0;
		const char* lastNewLine = NULL;
		int lastNumNewLines = 0;
		while (RE2::FindAndConsume(&megaString, mainSearch))
		{
			// identify which file the search hit was in
			for (unsigned int i = lastFound; i < numBufferFiles; ++i)
			{
				if (megaString.data() <= megaBuffer + bufferFiles[i].ptrOffset)
				{
					// do a regexp search to find all newlines for this file up to the point of the hit
					// if previous search had a hit on the same file, use the cached numNewLines and ptr so
					// we don't have to search through entire file again
					const char* beg = NULL;
					int numNewLines = 0;
					if (i == lastFound && lastNewLine != NULL)
					{
						beg = lastNewLine;
						numNewLines += lastNumNewLines;
					}
					else
					{
						beg = i == 0 ? megaBuffer : megaBuffer + bufferFiles[i - 1].ptrOffset;
					}

					const char* end = megaString.data();
					newLineString.set(beg, end - beg);
					
					int lastConsumed = 0;
					int consumed = 0;
					while (consumed = RE2::FindAndConsume(&newLineString, newLineSearch))
					{
						lastConsumed = consumed;
						numNewLines++;
					}
					lastNumNewLines = numNewLines;
					lastNewLine = newLineString.data();

					// copy DISPLAY_LINE_LENGTH characters to a separate buffer so we can use it as a marker for the match
					// break on newline
					for (int c = 0; c < DISPLAY_LINE_LENGTH; ++c)
					{
						if (lastNewLine[c] != '\n')
						{
							displayLine[c] = lastNewLine[c];
						}
						else
						{
							displayLine[c] = '\0';
							break;
						}
					}
					printf("%s:%d:%s\n", bufferFiles[i].name, numNewLines + 1, displayLine);
					lastFound = i;
					break;
				}
			}
			num++;
		}

		//QueryPerformanceCounter(&stop2);
		//printf("fex: data accumulation done in: %.2f seconds, %d files searched\n", (stop1.QuadPart - start1.QuadPart) / 1000000.f, numBufferFiles);
		//printf("fex: regexp match done in: %.2f seconds, found %d instances\n", (stop2.QuadPart - start2.QuadPart) / 1000000.f, num);
	}

	CleanUp();
}