コード例 #1
0
ファイル: bml.cpp プロジェクト: jperrot/MeMoPlayer
    void parseTable () {
        fgetc (m_fp); // B
        fgetc (m_fp); // M
        fgetc (m_fp); // L
        fgetc (m_fp); // 1

        m_nbTags = decodeSize ();
        m_tags = new char * [m_nbTags];
        for (int i = 0; i < m_nbTags; i++) {
            m_tags[i] = decodeString ();
        }
    }
コード例 #2
0
ファイル: bml.cpp プロジェクト: jperrot/MeMoPlayer
 XmlNode * parseNode () {
     int type = fgetc (m_fp);
     if (type == 3) {
         char * data = decodeString ();
         return new XmlNode (data, CDATA);
     } else if (type > 0) {
         int index = decodeSize ();
         XmlNode * n = new XmlNode (m_tags[index], type == 1 ? OPEN_TAG : SELF_TAG);
         // parse attribute
         int attrIdx = decodeSize (); // index of first attibute
         while (attrIdx != 0) {
             char * value = decodeString ();
             n->addAttribute (new XmlAttribute (m_tags[attrIdx-1], value));
             attrIdx = decodeSize (); // index of next attibute
         }
         XmlNode * child = parseNode ();
         while (child != NULL) {
             n->addChild (child);
             child = parseNode ();
         }
         return n;
     } 
     return NULL;
 }
コード例 #3
0
ファイル: ICOImageDecoder.cpp プロジェクト: mirror/chromium
size_t ICOImageDecoder::decodeFrameCount() {
  decodeSize();

  // If decodeSize() fails, return the existing number of frames.  This way
  // if we get halfway through the image before decoding fails, we won't
  // suddenly start reporting that the image has zero frames.
  if (failed())
    return m_frameBufferCache.size();

  // If the file is incomplete, return the length of the sequence of completely
  // received frames.  We don't do this when the file is fully received, since
  // some ICOs have entries whose claimed offset + size extends past the end of
  // the file, and we still want to display these if they don't trigger decoding
  // failures elsewhere.
  if (!isAllDataReceived()) {
    for (size_t i = 0; i < m_dirEntries.size(); ++i) {
      const IconDirectoryEntry& dirEntry = m_dirEntries[i];
      if ((dirEntry.m_imageOffset + dirEntry.m_byteSize) > m_data->size())
        return i;
    }
  }
  return m_dirEntries.size();
}
コード例 #4
0
ファイル: CJForm.c プロジェクト: doolse/wingsos
static HTMLTable *JFormDoTable(DOMElement *table, HTMLForms *forms)
{
	DOMElement *row,*cell;
	uint nrows;
	HTMLTable *Tab;
	HTMLRow *HRow;
	uint rows=0;
	uint maxcol=0;
	uint colup;
	Tab = calloc(sizeof(HTMLTable), 1);
	forms->FirstTable = addQueueB(forms->FirstTable, forms->FirstTable, Tab);
	Tab->Name = XMLgetAttr(table, "name");
	for (row=table->Elements; row; row = XMLnextElem(row))
	{
		colup=0;
		HRow = calloc(sizeof(HTMLRow), 1);
		Tab->FirstRow = addQueueB(Tab->FirstRow, Tab->FirstRow, HRow);
		HRow->Height = decodeSize(XMLgetAttr(row, "height"));
		for (cell=row->Elements; cell; cell = XMLnextElem(cell))
		{
			int colspan;
			int rowspan;
			HTMLCell *Cell;

			Cell = calloc(sizeof(HTMLCell), 1);
			Tab->FirstCell = addQueueB(Tab->FirstCell, Tab->FirstCell, Cell);
			colspan = atoi(XMLgetAttr(cell, "colspan"));
			rowspan = atoi(XMLgetAttr(cell, "rowspan"));
			if (!colspan)
				colspan++;
			if (!rowspan)
				rowspan++;
			Cell->Width = decodeSize(XMLgetAttr(cell, "width"));
			Cell->Value = ((DOMNode *)cell)->Value;
			Cell->Name = "";
			Cell->Hints.MinX = -1;
			Cell->Hints.MinY = -1;
			Cell->Hints.PrefX = -1;
			Cell->Hints.PrefY = -1;
			Cell->Hints.MaxY = -1;
			Cell->Hints.MaxY = -1;
			if (cell->Elements)
			{
				DOMElement *inp = cell->Elements;
				char *type;
				int ctype=0;

				if (!strcmp(((DOMNode *)inp)->Name, "table"))
				{
					ctype = WT_INNER;
					Cell->Inner = JFormDoTable(inp, forms);
				}
				else 
				{
					Cell->Name = XMLgetAttr(inp, "name");
					Cell->Hints.MinX = decodeFillWidth(XMLgetAttr(inp, "minx"));
					Cell->Hints.MinY = decodeFillWidth(XMLgetAttr(inp, "miny"));
					Cell->Hints.PrefX = decodeFillWidth(XMLgetAttr(inp, "prefx"));
					Cell->Hints.PrefY = decodeFillWidth(XMLgetAttr(inp, "prefy"));
					Cell->Hints.MaxY = decodeFillWidth(XMLgetAttr(inp, "maxx"));
					Cell->Hints.MaxY = decodeFillWidth(XMLgetAttr(inp, "maxy"));
					if (!strcmp(((DOMNode *)inp)->Name, "fill"))
					{
						ctype = WT_FILLER;
					}
					else
					{
						type = XMLgetAttr(inp, "type");
						Cell->Value = XMLgetAttr(inp, "value");
						if (!strcmp(type, "text"))
							ctype = WT_TEXT;
						else
						if (!strcmp(type, "button"))
							ctype = WT_BUTTON;
						else
						if (!strcmp(type, "textarea"))
							ctype = WT_TEXTAREA;
						else
						if (!strcmp(type, "custom"))
							ctype = WT_CUSTOM;

					}
				}
				Cell->Type = ctype;
			}
			Cell->TabLay[0] = colup;
			Cell->TabLay[1] = rows;
			Cell->TabLay[2] = colspan;
			Cell->TabLay[3] = rowspan;
			Cell->TabLay[4] = decodeAlign(XMLgetAttr(cell, "align"));
			colup++;
		}
		if (colup > maxcol)
			maxcol = colup;
		rows++;
	}
	Tab->Rows = rows;
	Tab->Cols = maxcol;
	return Tab;
}
コード例 #5
0
ファイル: main.cpp プロジェクト: x1nixmzeng/z3-tools
int main( int argc, char** argv )
{
	printf(
		"z3ResourceExtractor-wip\n" \
		"Reversing the decompression method\n\n"
	);
	
	#ifdef IGNORE_USAGE_OPTION
	if( true )
	#else
	if( argc == 2 )
	#endif
	{
		#ifdef IGNORE_USAGE_OPTION
		HANDLE fcHandle = filecmds::fcOpenRead( "fileindex_dec_stage1.dat" );
		#else
		HANDLE fcHandle = filecmds::fcOpenRead( argv[1] );
		#endif

		if( !( fcHandle == INVALID_HANDLE_VALUE ) )
		{
			char *dBuffer;
			unsigned int dBufferLen;

			dBufferLen = filecmds::fcGetSize( fcHandle );

			dBuffer = filecmds::fcAllocate( dBufferLen );
			filecmds::fcReadFile( fcHandle, dBuffer, dBufferLen );
			filecmds::fcCloseFile( fcHandle );


			unsigned char *pdata;

			pdata = (unsigned char *)dBuffer;

			unsigned int a,b;

			if( decodeSize( pdata, a, b ) )
			{
				printf( "GOT SIZE: %u (%u bytes)\n", a, b );
			}

			pdata += b;

			unsigned char *buffer = new unsigned char[a];
			unsigned int bufOffset = 0;

			printf("Uncompressed: %u bytes\n", a );

			unsigned int i = b;

			// #jit streaming
			fcHandle = filecmds::fcOpenWrite("dump.dat", true);

			while( i < dBufferLen )
			{
				unsigned int oldi = bufOffset;


				printf("Next instruction: %02X - ", *pdata );

				decodeInstruction( pdata, b, buffer, bufOffset );
		
				filecmds::fcWriteFile( fcHandle, (char *)buffer+oldi, bufOffset-oldi );

				pdata += b;
				i += b;
				printf("%u bytes!  (%u/%u)\n", b, i, dBufferLen );
			}

			delete dBuffer;

			filecmds::fcCloseFile( fcHandle );


			delete buffer;
		}

		printf("Done!\n\n");
	}
	else
		printf("Usage: %%s <half_dumped_filelist.msf>\n\n");
	
	return 0;
}
コード例 #6
0
ファイル: RtsFlags.c プロジェクト: altaic/ghc
void
setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
{
    rtsBool error = rtsFalse;
    I_ mode;
    I_ arg, total_arg;

    setProgName (argv);
    total_arg = *argc;
    arg = 1;

    *argc = 1;
    *rts_argc = 0;

    // process arguments from the ghc_rts_opts global variable first.
    // (arguments from the GHCRTS environment variable and the command
    // line override these).
    {
	if (ghc_rts_opts != NULL) {
	    splitRtsFlags(ghc_rts_opts, rts_argc, rts_argv);
	}
    }

    // process arguments from the GHCRTS environment variable next
    // (arguments from the command line override these).
    {
	char *ghc_rts = getenv("GHCRTS");

	if (ghc_rts != NULL) {
            if (rtsOptsEnabled != rtsOptsNone) {
                splitRtsFlags(ghc_rts, rts_argc, rts_argv);
            }
            else {
                errorBelch("Warning: Ignoring GHCRTS variable as RTS options are disabled.\n         Link with -rtsopts to enable them.");
                // We don't actually exit, just warn
            }
	}
    }

    // Split arguments (argv) into PGM (argv) and RTS (rts_argv) parts
    //   argv[0] must be PGM argument -- leave in argv

    for (mode = PGM; arg < total_arg; arg++) {
	// The '--RTS' argument disables all future +RTS ... -RTS processing.
	if (strequal("--RTS", argv[arg])) {
	    arg++;
	    break;
	}
	// The '--' argument is passed through to the program, but
	// disables all further +RTS ... -RTS processing.
	else if (strequal("--", argv[arg])) {
	    break;
	}
	else if (strequal("+RTS", argv[arg])) {
            if (rtsOptsEnabled != rtsOptsNone) {
                mode = RTS;
            }
            else {
                errorBelch("RTS options are disabled. Link with -rtsopts to enable them.");
                stg_exit(EXIT_FAILURE);
            }
	}
	else if (strequal("-RTS", argv[arg])) {
	    mode = PGM;
	}
	else if (mode == RTS && *rts_argc < MAX_RTS_ARGS-1) {
            rts_argv[(*rts_argc)++] = argv[arg];
        }
        else if (mode == PGM) {
	    argv[(*argc)++] = argv[arg];
	}
	else {
	  barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
	}
    }
    // process remaining program arguments
    for (; arg < total_arg; arg++) {
	argv[(*argc)++] = argv[arg];
    }
    argv[*argc] = (char *) 0;
    rts_argv[*rts_argc] = (char *) 0;

    // Process RTS (rts_argv) part: mainly to determine statsfile
    for (arg = 0; arg < *rts_argc; arg++) {
	if (rts_argv[arg][0] != '-') {
	    fflush(stdout);
	    errorBelch("unexpected RTS argument: %s", rts_argv[arg]);
	    error = rtsTrue;

        } else {

            switch(rts_argv[arg][1]) {
            case '-':
                if (strequal("info", &rts_argv[arg][2])) {
                    printRtsInfo();
                    stg_exit(0);
                }
                break;
            default:
                break;
            }

            if (rtsOptsEnabled != rtsOptsAll)
            {
                errorBelch("Most RTS options are disabled. Link with -rtsopts to enable them.");
                stg_exit(EXIT_FAILURE);
            }

            switch(rts_argv[arg][1]) {

	      /* process: general args, then PROFILING-only ones, then
		 CONCURRENT-only, TICKY-only (same order as defined in
		 RtsFlags.lh); within those groups, mostly in
		 case-insensitive alphabetical order.  Final group is
		 x*, which allows for more options.
	      */

#ifdef TICKY_TICKY
# define TICKY_BUILD_ONLY(x) x
#else
# define TICKY_BUILD_ONLY(x) \
errorBelch("the flag %s requires the program to be built with -ticky", rts_argv[arg]); \
error = rtsTrue;
#endif

#ifdef PROFILING
# define PROFILING_BUILD_ONLY(x)   x
#else
# define PROFILING_BUILD_ONLY(x) \
errorBelch("the flag %s requires the program to be built with -prof", rts_argv[arg]); \
error = rtsTrue;
#endif

#ifdef TRACING
# define TRACING_BUILD_ONLY(x)   x
#else
# define TRACING_BUILD_ONLY(x) \
errorBelch("the flag %s requires the program to be built with -eventlog or -debug", rts_argv[arg]); \
error = rtsTrue;
#endif

#ifdef THREADED_RTS
# define THREADED_BUILD_ONLY(x)      x
#else
# define THREADED_BUILD_ONLY(x) \
errorBelch("the flag %s requires the program to be built with -threaded", rts_argv[arg]); \
error = rtsTrue;
#endif

#ifdef DEBUG
# define DEBUG_BUILD_ONLY(x) x
#else
# define DEBUG_BUILD_ONLY(x) \
errorBelch("the flag %s requires the program to be built with -debug", rts_argv[arg]); \
error = rtsTrue;
#endif

	      /* =========== GENERAL ========================== */
	      case '?':
		error = rtsTrue;
		break;

              /* This isn't going to allow us to keep related options
                 together as we add more --* flags. We really need a
                 proper options parser. */
	      case '-':
                  if (strequal("install-signal-handlers=yes",
                               &rts_argv[arg][2])) {
                      RtsFlags.MiscFlags.install_signal_handlers = rtsTrue;
                  }
                  else if (strequal("install-signal-handlers=no",
                               &rts_argv[arg][2])) {
                      RtsFlags.MiscFlags.install_signal_handlers = rtsFalse;
                  }
                  else if (strequal("machine-readable",
                               &rts_argv[arg][2])) {
                      RtsFlags.MiscFlags.machineReadable = rtsTrue;
                  }
                  else if (strequal("info",
                               &rts_argv[arg][2])) {
                      printRtsInfo();
                      stg_exit(0);
                  }
                  else {
		      errorBelch("unknown RTS option: %s",rts_argv[arg]);
		      error = rtsTrue;
                  }
		  break;
	      case 'A':
                  RtsFlags.GcFlags.minAllocAreaSize
                      = decodeSize(rts_argv[arg], 2, BLOCK_SIZE, HS_INT_MAX)
                           / BLOCK_SIZE;
                  break;

#ifdef USE_PAPI
	      case 'a':
		switch(rts_argv[arg][2]) {
		case '1':
		  RtsFlags.PapiFlags.eventType = PAPI_FLAG_CACHE_L1;
		  break;
		case '2':
		  RtsFlags.PapiFlags.eventType = PAPI_FLAG_CACHE_L2;
		  break;
		case 'b':
		  RtsFlags.PapiFlags.eventType = PAPI_FLAG_BRANCH;
		  break;
		case 's':
		  RtsFlags.PapiFlags.eventType = PAPI_FLAG_STALLS;
		  break;
		case 'e':
		  RtsFlags.PapiFlags.eventType = PAPI_FLAG_CB_EVENTS;
		  break;
                case '+':
                case '#':
                  if (RtsFlags.PapiFlags.numUserEvents >= MAX_PAPI_USER_EVENTS) {
                      errorBelch("maximum number of PAPI events reached");
                      stg_exit(EXIT_FAILURE);
                  }
                  nat eventNum  = RtsFlags.PapiFlags.numUserEvents++;
                  char kind     = rts_argv[arg][2];
                  nat eventKind = kind == '+' ? PAPI_PRESET_EVENT_KIND : PAPI_NATIVE_EVENT_KIND;

                  RtsFlags.PapiFlags.userEvents[eventNum] = rts_argv[arg] + 3;
                  RtsFlags.PapiFlags.eventType = PAPI_USER_EVENTS;
                  RtsFlags.PapiFlags.userEventsKind[eventNum] = eventKind;
                  break;
		default:
		  bad_option( rts_argv[arg] );
		}
		break;
#endif

	      case 'B':
		RtsFlags.GcFlags.ringBell = rtsTrue;
		break;

	      case 'c':
		  if (rts_argv[arg][2] != '\0') {
		      RtsFlags.GcFlags.compactThreshold =
			  atof(rts_argv[arg]+2);
		  } else {
		      RtsFlags.GcFlags.compact = rtsTrue;
		  }
		  break;

              case 'w':
		RtsFlags.GcFlags.sweep = rtsTrue;
		break;

	      case 'F':
	        RtsFlags.GcFlags.oldGenFactor = atof(rts_argv[arg]+2);
	      
		if (RtsFlags.GcFlags.oldGenFactor < 0)
		  bad_option( rts_argv[arg] );
		break;
	      
	      case 'D':
              DEBUG_BUILD_ONLY(
	      { 
		  char *c;

		  for (c  = rts_argv[arg] + 2; *c != '\0'; c++) {
		      switch (*c) {
		      case 's':
			  RtsFlags.DebugFlags.scheduler = rtsTrue;
			  break;
		      case 'i':
			  RtsFlags.DebugFlags.interpreter = rtsTrue;
			  break;
		      case 'w':
			  RtsFlags.DebugFlags.weak = rtsTrue;
			  break;
		      case 'G':
			  RtsFlags.DebugFlags.gccafs = rtsTrue;
			  break;
		      case 'g':
			  RtsFlags.DebugFlags.gc = rtsTrue;
			  break;
		      case 'b':
			  RtsFlags.DebugFlags.block_alloc = rtsTrue;
			  break;
		      case 'S':
			  RtsFlags.DebugFlags.sanity = rtsTrue;
			  break;
		      case 't':
			  RtsFlags.DebugFlags.stable = rtsTrue;
			  break;
		      case 'p':
			  RtsFlags.DebugFlags.prof = rtsTrue;
			  break;
		      case 'l':
			  RtsFlags.DebugFlags.linker = rtsTrue;
			  break;
		      case 'a':
			  RtsFlags.DebugFlags.apply = rtsTrue;
			  break;
		      case 'm':
			  RtsFlags.DebugFlags.stm = rtsTrue;
			  break;
		      case 'z':
			  RtsFlags.DebugFlags.squeeze = rtsTrue;
			  break;
		      case 'c':
			  RtsFlags.DebugFlags.hpc = rtsTrue;
			  break;
		      case 'r':
			  RtsFlags.DebugFlags.sparks = rtsTrue;
			  break;
		      default:
			  bad_option( rts_argv[arg] );
		      }
		  }
                  // -Dx also turns on -v.  Use -l to direct trace
                  // events to the .eventlog file instead.
                  RtsFlags.TraceFlags.tracing = TRACE_STDERR;
	      })
              break;

	      case 'K':
                  RtsFlags.GcFlags.maxStkSize =
                      decodeSize(rts_argv[arg], 2, sizeof(W_), HS_WORD_MAX) / sizeof(W_);
                  break;

	      case 'k':
		switch(rts_argv[arg][2]) {
                case 'c':
                  RtsFlags.GcFlags.stkChunkSize =
                      decodeSize(rts_argv[arg], 3, sizeof(W_), HS_WORD_MAX) / sizeof(W_);
                  break;
                case 'b':
                  RtsFlags.GcFlags.stkChunkBufferSize =
                      decodeSize(rts_argv[arg], 3, sizeof(W_), HS_WORD_MAX) / sizeof(W_);
                  break;
                case 'i':
                  RtsFlags.GcFlags.initialStkSize =
                      decodeSize(rts_argv[arg], 3, sizeof(W_), HS_WORD_MAX) / sizeof(W_);
                  break;
                default:
                  RtsFlags.GcFlags.initialStkSize =
                      decodeSize(rts_argv[arg], 2, sizeof(W_), HS_WORD_MAX) / sizeof(W_);
                  break;
                }
                break;

              case 'M':
                  RtsFlags.GcFlags.maxHeapSize =
                      decodeSize(rts_argv[arg], 2, BLOCK_SIZE, HS_WORD_MAX) / BLOCK_SIZE;
                  /* user give size in *bytes* but "maxHeapSize" is in *blocks* */
                  break;

	      case 'm':
                  RtsFlags.GcFlags.pcFreeHeap = atof(rts_argv[arg]+2);

                  if (RtsFlags.GcFlags.pcFreeHeap < 0 ||
                      RtsFlags.GcFlags.pcFreeHeap > 100)
                      bad_option( rts_argv[arg] );
                  break;

	      case 'G':
                  RtsFlags.GcFlags.generations =
                      decodeSize(rts_argv[arg], 2, 1, HS_INT_MAX);
                  break;

	      case 'H':
                  if (rts_argv[arg][2] == '\0') {
                      RtsFlags.GcFlags.heapSizeSuggestionAuto = rtsTrue;
                  } else {
                      RtsFlags.GcFlags.heapSizeSuggestion =
                          (nat)(decodeSize(rts_argv[arg], 2, BLOCK_SIZE, HS_WORD_MAX) / BLOCK_SIZE);
                  }
                  break;

#ifdef RTS_GTK_FRONTPANEL
	      case 'f':
		  RtsFlags.GcFlags.frontpanel = rtsTrue;
		  break;
#endif

    	      case 'I':	/* idle GC delay */
		if (rts_argv[arg][2] == '\0') {
		  /* use default */
		} else {
		    I_ cst; /* tmp */

		    /* Convert to millisecs */
		    cst = (I_) ((atof(rts_argv[arg]+2) * 1000));
		    RtsFlags.GcFlags.idleGCDelayTime = cst;
		}
		break;

	      case 'S':
		  RtsFlags.GcFlags.giveStats = VERBOSE_GC_STATS;
		  goto stats;

	      case 's':
		  RtsFlags.GcFlags.giveStats = SUMMARY_GC_STATS;
		  goto stats;

	      case 't':
		  RtsFlags.GcFlags.giveStats = ONELINE_GC_STATS;
		  goto stats;

	    stats:
		{ 
		    int r;
		    r = open_stats_file(arg, *argc, argv,
					*rts_argc, rts_argv, NULL,
					&RtsFlags.GcFlags.statsFile);
		    if (r == -1) { error = rtsTrue; }
		}
                break;

	      case 'Z':
		RtsFlags.GcFlags.squeezeUpdFrames = rtsFalse;
		break;

	      /* =========== PROFILING ========================== */

	      case 'P': /* detailed cost centre profiling (time/alloc) */
	      case 'p': /* cost centre profiling (time/alloc) */
		PROFILING_BUILD_ONLY(
		switch (rts_argv[arg][2]) {
		  case 'x':
		    RtsFlags.CcFlags.doCostCentres = COST_CENTRES_XML;
		    break;
		  case 'a':
		    RtsFlags.CcFlags.doCostCentres = COST_CENTRES_ALL;
		    break;
		  default:
		      if (rts_argv[arg][1] == 'P') {
			  RtsFlags.CcFlags.doCostCentres =
			      COST_CENTRES_VERBOSE;
		      } else {
			  RtsFlags.CcFlags.doCostCentres =
			      COST_CENTRES_SUMMARY;
		      }
		      break;
		}
		) break;

	      case 'R':
		  PROFILING_BUILD_ONLY(
		      RtsFlags.ProfFlags.maxRetainerSetSize = atof(rts_argv[arg]+2);
  	          ) break;
	      case 'L':
		  PROFILING_BUILD_ONLY(
		      RtsFlags.ProfFlags.ccsLength = atof(rts_argv[arg]+2);
                      if(RtsFlags.ProfFlags.ccsLength <= 0) {
			bad_option(rts_argv[arg]);
                      }
		  ) break;