Пример #1
0
tuple<Token::Value, unsigned int, unsigned int> Token::fromIdentifierOrKeyword(string const& _literal)
{
	auto positionM = find_if(_literal.begin(), _literal.end(), ::isdigit);
	if (positionM != _literal.end())
	{
		string baseType(_literal.begin(), positionM);
		auto positionX = find_if_not(positionM, _literal.end(), ::isdigit);
		int m = parseSize(positionM, positionX);
		Token::Value keyword = keywordByName(baseType);
		if (keyword == Token::Bytes)
		{
			if (0 < m && m <= 32 && positionX == _literal.end())
				return make_tuple(Token::BytesM, m, 0);
		}
		else if (keyword == Token::UInt || keyword == Token::Int)
		{
			if (0 < m && m <= 256 && m % 8 == 0 && positionX == _literal.end())
			{
				if (keyword == Token::UInt)
					return make_tuple(Token::UIntM, m, 0);
				else
					return make_tuple(Token::IntM, m, 0);
			}
		}
		else if (keyword == Token::UFixed || keyword == Token::Fixed)
		{
			if (
				positionM < positionX &&
				positionX < _literal.end() &&
				*positionX == 'x' &&
				all_of(positionX + 1, _literal.end(), ::isdigit)
			) {
				int n = parseSize(positionX + 1, _literal.end());
				if (
					0 <= m && m <= 256 &&
					8 <= n && n <= 256 &&
					m + n > 0 &&
					m + n <= 256 &&
					m % 8 == 0 &&
					n % 8 == 0
				) {
					if (keyword == Token::UFixed)
						return make_tuple(Token::UFixedMxN, m, n);
					else
						return make_tuple(Token::FixedMxN, m, n);
				}
			}	
		}
		return make_tuple(Token::Identifier, 0, 0);
	}

	return make_tuple(keywordByName(_literal), 0, 0);
}
Пример #2
0
int	sizeArg(t_game *game, char **av, bool mode)
{
  (void)mode;
  if (my_strlen(av[0]) <= 11 || parseSize(av[0], game))
    return (1);
  return (0);
}
Пример #3
0
int main(int argc, char** argv) {

  if (argc != 3) {
    std::cerr << "Usage: " << argv[0] << "<file name> <file size in {KB,MB,GB}>\n";
    return -1;
  }

  std::random_device rd;
  std::mt19937_64 gen(rd());
  std::uniform_int_distribution<char> dis;

  std::ofstream file(argv[1]);

  auto left = parseSize(argv[2]);

  while(left) {
    char generated = dis(gen);
    if (std::isgraph(generated)) {
      file << generated;
      left--;
    }
  }

  return 0;
}
Пример #4
0
static bool parse_PB(B& in, S& solver, bool abort_on_error)
{
    try{
        parseSize(in, solver);
        parseGoal(in, solver);
        return parseConstrs(in, solver);
    }catch (cchar* msg){
        if (abort_on_error){
            reportf("PARSE ERROR! [line %d] %s\n", in.line, msg);
            xfree(msg);
            if (opt_satlive && !opt_try)
                printf("s UNKNOWN\n");
            exit(opt_try ? 5 : 0);
        }else
            throw msg;
    }

}
Пример #5
0
int main(int argc, char **argv)
#endif
{
    int ret;
    char *ptr;
    struct net_config net_config;
    struct disk_config disk_config;
    struct stat_config stat_config;
    int c;
    int doWarn=0;
    char *ifName=NULL;

#ifdef LOSSTEST
    int seedSet = 0;
    int printSeed = 0;
#endif

#ifdef SIG_UNBLOCK
    atexit(signalForward);
#endif

    disk_config.fileName=NULL;
    disk_config.pipeName=NULL;
    disk_config.flags = 0;

    net_config.portBase = 9000;
    net_config.ttl = 1;
    net_config.flags = 0;
    net_config.mcastRdv = NULL;
    net_config.exitWait = 500;
    net_config.startTimeout = 0;
    net_config.receiveTimeout = 0;

    stat_config.statPeriod = DEFLT_STAT_PERIOD;
    stat_config.printUncompressedPos = -1;
    stat_config.noProgress = 0;

#ifdef WINDOWS
    /* windows is basically unusable with its default buffer size of 8k...*/
    net_config.requestedBufSize = 1024*1024;
#else
    net_config.requestedBufSize = 0;
#endif

    ptr = strrchr(argv[0], '/');
    if(!ptr)
	ptr = argv[0];
    else
	ptr++;
    
    net_config.net_if = NULL;
    if (strcmp(ptr, "init") == 0) {
	doWarn = 1;
	disk_config.pipeName = strdup("/bin/gzip -dc");
	disk_config.fileName = "/dev/hda";
    }
    while( (c=getopt_l(argc, argv, "b:f:p:P:i:l:M:s:t:w:x:z:dkLnyZ")) != EOF ) {
	switch(c) {
	    case 'f':
		disk_config.fileName=optarg;
		break;
	    case 'i':
		ifName=optarg;
		break;
	    case 'p':
		disk_config.pipeName=optarg;
		break;
	    case 'P':
		net_config.portBase = atoi(optarg);
		break;
	    case 'l':
		udpc_log = fopen(optarg, "a");
		break;
	    case 0x701:
		stat_config.noProgress = 1;
		break;
	    case 't': /* ttl */
		net_config.ttl = atoi(optarg);
		break;
	    case 'M':
		net_config.mcastRdv = strdup(optarg);
		break;

#ifdef BB_FEATURE_UDPCAST_FEC
	    case 'L':
		    fec_license();
		    break;
#endif

#ifdef LOSSTEST
	    case 0x601:
		setWriteLoss(optarg);
		break;
	    case 0x602:
		setReadLoss(optarg);
		break;
	    case 0x603:
		seedSet=1;
		srandom(strtoul(optarg,0,0));
		break;
	    case 0x604:
		printSeed=1;
		break;
	    case 0x605:
		setReadSwap(optarg);
		break;
#endif
	    case 'd': /* passive */
		net_config.flags|=FLAG_PASSIVE;
		break;
	    case 'n': /* nosync */
		disk_config.flags|=FLAG_NOSYNC;
		break;
	    case 'y': /* sync */
		disk_config.flags|=FLAG_SYNC;
		break;
	    case 'b': /* rcvbuf */
		net_config.requestedBufSize=parseSize(optarg);
		break;
	    case 'k': /* nokbd */
		net_config.flags |= FLAG_NOKBD;
		break;

	    case 'w': /* exit-wait */
		net_config.exitWait = atoi(optarg);
		break;

	    case 's': /* start-timeout */
		net_config.startTimeout = atoi(optarg);		
		break;

	    case 0x801: /* receive-timeout */
		net_config.receiveTimeout = atoi(optarg);
		break;

	    case 'z':
		stat_config.statPeriod = atoi(optarg) * 1000;
		break;
	    case 'x':
		stat_config.printUncompressedPos = atoi(optarg);
		break;

	    case 'Z':
		net_config.flags |= FLAG_IGNORE_LOST_DATA;
		break;

	    case '?':
#ifndef NO_BB
	        bb_show_usage();
#else
		usage(argv[0]);
#endif
	}
    }

    fprintf(stderr, "Udp-receiver %s\n", version);

#ifdef LOSSTEST
    if(!seedSet)
	srandomTime(printSeed);
#endif

    signal(SIGINT, intHandler);
#ifdef USE_SYSLOG
    openlog((const char *)"udpcast", LOG_NDELAY|LOG_PID, LOG_SYSLOG);
#endif
    
    ret= startReceiver(doWarn, &disk_config, &net_config, &stat_config, ifName);
    if(ret < 0) {
      fprintf(stderr, "Receiver error\n");
    }
    return ret;
}
Пример #6
0
QSize XMLParseBase::parseSize(QDomElement &element, bool normalize)
{
    return parseSize(getFirstText(element), normalize);
}
Пример #7
0
KdmItem::KdmItem(QObject *parent, const QDomNode &node)
    : QObject(parent)
    , boxManager(0)
    , fixedManager(0)
    , myWidget(0)
    , m_showTypeInvert(false)
    , m_minScrWidth(0)
    , m_minScrHeight(0)
    , m_visible(true)
    , m_shown(true)
{
    QDomNode showNode = node.namedItem("show");
    if (!showNode.isNull()) {
        QDomElement sel = showNode.toElement();

        QString modes = sel.attribute("modes");
        if (!modes.isNull() &&
            (modes == "nowhere" ||
             (modes != "everywhere" &&
              !modes.split(",", QString::SkipEmptyParts).contains("console"))))
        {
            m_visible = false;
            return;
        }

        m_showType = sel.attribute("type");
        if (!m_showType.isNull()) {
            if (m_showType[0] == '!') {
                m_showType.remove(0, 1);
                m_showTypeInvert = true;
            }
            if (!m_showType.startsWith("plugin-") &&
                themer()->typeVisible(m_showType) == m_showTypeInvert)
            {
                m_visible = false;
                return;
            }
        }

        m_minScrWidth = sel.attribute("min-screen-width").toInt();
        m_minScrHeight = sel.attribute("min-screen-height").toInt();
    }

    // Set default layout for every item
    currentManager = MNone;
    geom.pos.x.type = geom.pos.y.type =
        geom.size.x.type = geom.size.y.type = DTnone;
    geom.minSize.x.type = geom.minSize.y.type =
        geom.maxSize.x.type = geom.maxSize.y.type = DTpixel;
    geom.minSize.x.val = geom.minSize.y.val = 0;
    geom.maxSize.x.val = geom.maxSize.y.val = 1000000;
    geom.anchor = "nw";
    geom.expand = 0;

    // Set defaults for derived item's properties
    state = Snormal;

    KdmItem *parentItem = qobject_cast<KdmItem *>(parent);
    if (!parentItem)
        style.frame = false, style.guistyle = 0;
    else
        style = parentItem->style;

    // Read the mandatory Pos tag. Other tags such as normal, prelighted,
    // etc.. are read under specific implementations.
    QDomNodeList childList = node.childNodes();
    for (int nod = 0; nod < childList.count(); nod++) {
        QDomNode child = childList.item(nod);
        QDomElement el = child.toElement();
        QString tagName = el.tagName();

        if (tagName == "pos") {
            parseSize(el.attribute("x", QString()), geom.pos.x);
            parseSize(el.attribute("y", QString()), geom.pos.y);
            parseSize(el.attribute("width", QString()), geom.size.x);
            parseSize(el.attribute("height", QString()), geom.size.y);
            parseSize(el.attribute("min-width", QString()), geom.minSize.x);
            parseSize(el.attribute("min-height", QString()), geom.minSize.y);
            parseSize(el.attribute("max-width", QString()), geom.maxSize.x);
            parseSize(el.attribute("max-height", QString()), geom.maxSize.y);
            geom.anchor = el.attribute("anchor", "nw");
            geom.expand = toBool(el.attribute("expand", "false"));
        } else if (tagName == "buddy") {
            buddy = el.attribute("idref", "");
        } else if (tagName == "style") {
            parseStyle(el, style);
        }
    }

    if (!style.font.present)
        parseFont("Sans 14", style.font);

    QDomElement el = node.toElement();
    setObjectName(el.attribute("id", QString::number((ulong)this, 16)));
    isButton = toBool(el.attribute("button", "false"));
    isBackground = toBool(el.attribute("background", "false"));
    QString screen = el.attribute("screen", isBackground ? "all" : "greeter");
    paintOnScreen =
        screen == "greeter" ? ScrGreeter :
        screen == "other" ? ScrOther : ScrAll;

    if (!parentItem)
        // The "toplevel" node (the screen) is really just like a fixed node
        setFixedLayout();
    else
        // Tell 'parent' to add 'me' to its children
        parentItem->addChildItem(this);
}
Пример #8
0
static retCode setStackSize(char *option, logical enable, void *cl) {
  initStackSize = parseSize(option);
  return Ok;
}
Пример #9
0
static retCode setHeapSize(char *option, logical enable, void *cl) {
  initHeapSize = parseSize(option);
  if (initHeapSize == 0)
    return Error;
  return Ok;
}
Пример #10
0
bool DSO::addCustomFile(const QString &fileName)
{
  m_lastCustomError = "";

  SkFile file(fileName);

  if (!file.open(SkFile::ReadOnly | SkFile::Text))
  {
    m_lastCustomError = tr("File not found!");
    return false;
  }

  QString code;

  do
  {
    if (file.atEnd())
    {
      break;
    }
    QString line = file.readLine();

    if (line.simplified() == "*DATA")
    {
      break;
    }

    code += line;
  } while (true);

  QScriptEngine engine;

  scriptNewTypes.clear();

  engine.globalObject().setProperty("AUTHOR", "");
  engine.globalObject().setProperty("EPOCH", 2000);
  engine.globalObject().setProperty("DESCRIPTION", "");

  engine.globalObject().setProperty("POINT_SOURCE", 0);
  engine.globalObject().setProperty("CIRCLE", 1);
  engine.globalObject().setProperty("CROSS", 2);
  engine.globalObject().setProperty("RECTANGLE", 3);

  QScriptValue fun = engine.newFunction(DEFINE_CUSTOM_OBJECT, 3);
  engine.globalObject().setProperty("DEFINE_CUSTOM_OBJECT", fun);

  QScriptValue result = engine.evaluate(code);
  if (engine.hasUncaughtException())
  {
    int line = engine.uncaughtExceptionLineNumber();
    m_lastCustomError = QString("uncaught exception at line ") + line + " : " + result.toString();
    return false;
  }

  QString author;
  QString description;
  double epoch;

  int nameOffset = 0; // TODO: dat globalne

  QScriptValueIterator it(engine.globalObject());
  while (it.hasNext())
  {
    it.next();

    if (it.name() == "AUTHOR")
    {
      author = it.value().toString();
    }
    else
    if (it.name() == "DESCRIPTION")
    {
      description = it.value().toString();
    }
    else
    if (it.name() == "EPOCH")
    {
      epoch = it.value().toNumber();
    }
  }

  do
  {
    if (file.atEnd())
    {
      break;
    }
    QString line = file.readLine().simplified();

    if (line.startsWith("//"))
    {
      continue;
    }

    if (line.size() == 0)
    {
      continue;
    }

    QStringList list = line.split("|");

    //qDebug() << line << list.count();

    if (list.count() != 10)
    {
      m_lastCustomError = "Invalid record";
      return false;
    }

    QString type = list[0].simplified();
    QString name1 = list[1].simplified();
    QString name2 = list[2].simplified();
    double ra = parseRA(list[3]);
    double dec = parseDec(list[4]);
    double sizeA = parseSize(list[5]);
    double sizeB = parseSize(list[6]);
    double mag = list[7].simplified().toDouble();
    double pa = list[8].simplified().toDouble();
    QString cls = list[9].simplified();

    dso_t dso;

    if (qIsNaN(ra) || qIsNaN(dec))
    {
      m_lastCustomError = "Invalid RA/Dec value";
      return false;
    }

    m_namesMap[USER_OFFSET + nameOffset].append(name1);
    m_namesMap[USER_OFFSET + nameOffset].append(name2);
    nameOffset++;

    dso.cataloque = 0; // TODO: dodelat
    dso.galType = 0; // TODO: dodelat
    dso.mag = SkMath::isNear(mag, 0) ?  NO_DSO_MAG : (short)(mag * 100.);
    dso.nameOffs = USER_OFFSET + nameOffset;
    dso.pa = pa; //TODO: bez PA
    dso.rd.ra = SkMath::toRad(ra);
    dso.rd.dec = SkMath::toRad(dec); //TODO:epoch
    dso.shape = NO_DSO_SHAPE;
    dso.sx = sizeA;
    dso.sy = sizeB;
    dso.type = DSOT_CUSTOM_FLAG; // TODO: user types

    qDebug() << line;
    qDebug() << type << name1 << name2 << ra << dec << sizeA << sizeB << mag << pa << cls;
  } while (true);

  return true;
}
/*
 * Process program's flags.
 */
static
int
options(char** argv, int argc)
{
	int i;
	unsigned int j;
	size_t sz;
	userProperty* prop;

	for (i = 1; i < argc; i++) {
		if (argv[i][0] != '-') {
			break;
		}

		if (strcmp(argv[i], "-help") == 0) {
			usage();
			exit(EXIT_SUCCESS);
		}
		else if (strcmp(argv[i], "-version") == 0) {
			printShortVersion();
			exit(EXIT_SUCCESS);
		}
		else if (strcmp(argv[i], "-fullversion") == 0) {
			printFullVersion();
			exit(EXIT_SUCCESS);
		}
#if defined(__ia64__)
		else if (strcmp(argv[i], "-ia32") == 0) {
			i++;
			/* FIXME: skip, case handled by the calle script */
		}
#endif
		else if (strcmp(argv[i], "-classpath") == 0
			 || strcmp(argv[i], "-cp") == 0) {

			i++;
			if (argv[i] == 0) {
				fprintf(stderr, 
				    "Error: No path found for %s option.\n",
				    argv[i - 1]);
				exit(EXIT_FAILURE);
			}

			/* set the new classpath */
			vmargs.classpath = strdup(argv[i]);
		}
		else if (strcmp(argv[i], "-addclasspath") == 0) {
			char	*newcpath;
			unsigned int      cpathlength;

			i++;
			if (argv[i] == 0) {
				fprintf(stderr, 
				    "Error: No path found for %s option.\n",
				    argv[i - 1]);
				exit(EXIT_FAILURE);
			}

			cpathlength = ((vmargs.classpath != NULL) ? strlen(vmargs.classpath) : 0)
				+ strlen(path_separator)
				+ strlen(argv[i])
				+ 1;

			/* Get longer buffer FIXME:  free the old one */
			if ((newcpath = malloc(cpathlength)) == NULL) {
				fprintf(stderr,  _("Error: out of memory.\n"));
				exit(EXIT_FAILURE);
			}

			/* Construct new classpath */
			if( vmargs.classpath != 0 )
			  	strcpy(newcpath, vmargs.classpath);
			else
				newcpath[0] = '\0';
			strcat(newcpath, path_separator);
			strcat(newcpath, argv[i]);

			/* set the new classpath */
			vmargs.classpath = newcpath;
		}
#ifdef KAFFE_X_AWT_INCLUDED
                /* Extra option to use kaffe's Xlib AWT backend.
                 */
                else if (strncmp(argv[i], "-Xkaffe-xlib-awt", (j=16)) == 0) {
			prop = setKaffeAWT("kaffe.awt.nativelib=xawt");
                }
#endif
#ifdef KAFFE_QT_AWT_INCLUDED
                /* Extra option to use kaffe's Qt/Embedded AWT backend.
                 */
                else if (strncmp(argv[i], "-Xkaffe-qt-awt", (j=15)) == 0) {
                        prop = setKaffeAWT("kaffe.awt.nativelib=qtawt");
                }
#endif
#ifdef KAFFE_NANOX_AWT_INCLUDED
		/* Extra option to use kaffe's Nano-X AWT backend.
		 */
		else if (strncmp(argv[i], "-Xkaffe-nanox-awt", (j=17)) == 0) {
			prop = setKaffeAWT("kaffe.awt.nativelib=nanoxawt");
		}
#endif
#if defined(USE_GMP)
		/* Extra option to use gmp for native, fast bignums.
		 * Only available with binreloc, since binreloc is used to
		 * find the gmpjavamath.jar file.
		 */
                else if (strncmp(argv[i], "-Xnative-big-math", (j=17)) == 0) {
                        char    *newbootcpath;
                        unsigned int      bootcpathlength;
			const char *prefix =
#if defined(ENABLE_BINRELOC)
				LIBDIR
#else /* !defined(ENABLE_BINRELOC) */
				DEFAULT_KAFFEHOME
#endif /* defined(ENABLE_BINRELOC) */
				;

 			const char *suffix = file_separator "gmpjavamath.jar";

                        bootcpathlength = strlen(prefix)
				+ strlen(suffix)
				+ strlen(path_separator)
                                + ((vmargs.bootClasspath != NULL) ?
                                        strlen(vmargs.bootClasspath) : 0)
                                + 1;

                        /* Get longer buffer FIXME:  free the old one */
                        if ((newbootcpath = malloc(bootcpathlength)) == NULL) {
                                fprintf(stderr,  _("Error: out of memory.\n"));
                                exit(EXIT_FAILURE);
                        }

                        /* Construct new boot classpath */
                        strcpy(newbootcpath, prefix);
			strcat(newbootcpath, suffix);
                        strcat(newbootcpath, path_separator);
                        if( vmargs.bootClasspath != 0 )
                                strcat(newbootcpath, vmargs.bootClasspath);

                        /* set the new boot classpath */
                        vmargs.bootClasspath = newbootcpath;
                }
#endif /* defined(USE_GMP) */
		else if (strncmp(argv[i], "-Xbootclasspath/p:", (j=18)) == 0) {
			char	*newbootcpath;
			unsigned int      bootcpathlength;

			bootcpathlength = strlen(&argv[i][j])
				+ strlen(path_separator)
				+ ((vmargs.bootClasspath != NULL) ?
					strlen(vmargs.bootClasspath) : 0)
				+ 1;

			/* Get longer buffer FIXME:  free the old one */
			if ((newbootcpath = malloc(bootcpathlength)) == NULL) {
				fprintf(stderr,  _("Error: out of memory.\n"));
				exit(EXIT_FAILURE);
			}

			/* Construct new boot classpath */
			strcpy(newbootcpath, &argv[i][j]);
			strcat(newbootcpath, path_separator);
			if( vmargs.bootClasspath != 0 )
			  	strcat(newbootcpath, vmargs.bootClasspath);

			/* set the new boot classpath */
			vmargs.bootClasspath = newbootcpath;
		}
		else if (strncmp(argv[i], "-Xbootclasspath/a:", (j=18)) == 0) {
			char	*newbootcpath;
			unsigned int      bootcpathlength;

			bootcpathlength = strlen(&argv[i][j])
				+ strlen(path_separator)
				+ ((vmargs.bootClasspath != NULL) ?
					strlen(vmargs.bootClasspath) : 0)
				+ 1;

			/* Get longer buffer FIXME:  free the old one */
			if ((newbootcpath = malloc(bootcpathlength)) == NULL) {
				fprintf(stderr,  _("Error: out of memory.\n"));
				exit(EXIT_FAILURE);
			}

			/* Construct new boot classpath */
			if( vmargs.bootClasspath != 0 ) {
			  	strcpy(newbootcpath, vmargs.bootClasspath);
				strcat(newbootcpath, path_separator);
			}
			strcat(newbootcpath, &argv[i][j]);

			/* set the new boot classpath */
			vmargs.bootClasspath = newbootcpath;
		}
		else if (strncmp(argv[i], "-Xbootclasspath:", (j=16)) == 0) {
			char	*newbootcpath;
			unsigned int      bootcpathlength;

			bootcpathlength = strlen(&argv[i][j]) + 1;

			/* Get longer buffer FIXME:  free the old one */
			if ((newbootcpath = malloc(bootcpathlength)) == NULL) {
				fprintf(stderr,  _("Error: out of memory.\n"));
				exit(EXIT_FAILURE);
			}

			/* Construct new boot classpath */
			strcpy(newbootcpath, &argv[i][j]);

			/* set the new boot classpath */
			vmargs.bootClasspath = newbootcpath;
		}
		else if ((strncmp(argv[i], "-ss", (j=3)) == 0) 
			 || (strncmp(argv[i], "-Xss", (j=4)) == 0)) {
			if (argv[i][j] == 0) {
				i++;
				if (argv[i] == 0) {
					fprintf(stderr, _("Error: No stack size found for -ss option.\n"));
					exit(EXIT_FAILURE);
				}
				sz = parseSize(argv[i]);
			} else {
				sz = parseSize(&argv[i][j]);
			}
			if (sz < THREADSTACKSIZE) {
				fprintf(stderr,  _("Warning: Attempt to set stack size smaller than %d - ignored.\n"), THREADSTACKSIZE);
			}
			else {
				vmargs.nativeStackSize = sz;
			}
		}
		else if ((strncmp(argv[i], "-mx", (j=3)) == 0)
			 || (strncmp(argv[i], "-Xmx", (j=4)) == 0)) {
			if (argv[i][j] == 0) {
				i++;
				if (argv[i] == 0) {
					fprintf(stderr,  _("Error: No heap size found for -mx option.\n"));
					exit(EXIT_FAILURE);
				}
				if (strcmp(argv[i], "unlimited") == 0)
					vmargs.maxHeapSize = UNLIMITED_HEAP;
				else
					vmargs.maxHeapSize = parseSize(argv[i]);
			} else {
				if (strcmp(&argv[i][j], "unlimited") == 0)
					vmargs.maxHeapSize = UNLIMITED_HEAP;
				else
					vmargs.maxHeapSize = parseSize(&argv[i][j]);
			}
		}
		else if ((strncmp(argv[i], "-ms", (j=3)) == 0)
			 || (strncmp(argv[i], "-Xms", (j=4)) == 0)) {
			if (argv[i][j] == 0) {
				i++;
				if (argv[i] == 0) {
					fprintf(stderr,  _("Error: No heap size found for -ms option.\n"));
					exit(EXIT_FAILURE);
				}
				vmargs.minHeapSize = parseSize(argv[i]);
			} else {
				vmargs.minHeapSize = parseSize(&argv[i][j]);
			}
		}
		else if (strncmp(argv[i], "-as", 3) == 0) {
			if (argv[i][3] == 0) {
				i++;
				if (argv[i] == 0) {
					fprintf(stderr,  _("Error: No heap size found for -as option.\n"));
					exit(EXIT_FAILURE);
				}
				vmargs.allocHeapSize = parseSize(argv[i]);
			} else {
				vmargs.allocHeapSize = parseSize(&argv[i][3]);
			}
		}
		else if (strcmp(argv[i], "-verify") == 0) {
			vmargs.verifyMode = 3;
		}
		else if (strcmp(argv[i], "-verifyremote") == 0) {
			vmargs.verifyMode = 2;
		}
		else if (strcmp(argv[i], "-noverify") == 0) {
			vmargs.verifyMode = 0;
		}
		else if (strcmp(argv[i], "-verbosegc") == 0) {
			vmargs.enableVerboseGC = 1;
		}
		else if (strcmp(argv[i], "-noclassgc") == 0) {
			vmargs.enableClassGC = 0;
		}
		else if (strcmp(argv[i], "-verbosejit") == 0) {
			vmargs.enableVerboseJIT = 1;
		}
		else if (strcmp(argv[i], "-verbosemem") == 0) {
			vmargs.enableVerboseGC = 2;
		}
		else if (strcmp(argv[i], "-verbosecall") == 0) {
			vmargs.enableVerboseCall = 1;
		}
		else if (strcmp(argv[i], "-verbose") == 0 || strcmp(argv[i], "-v") == 0) {
			vmargs.enableVerboseClassloading = 1;
		}
                else if (strcmp(argv[i], "-jar") == 0) {
			char	*newcpath;
			unsigned int      cpathlength;

			cpathlength = strlen(argv[i+1]) + 
				strlen(path_separator) +
				((vmargs.classpath!=NULL) ? strlen(vmargs.classpath) : 0) +
				1;

			newcpath = (char *)malloc (cpathlength);
			if (newcpath == NULL) {
				fprintf(stderr,  _("Error: out of memory.\n"));
				exit(EXIT_FAILURE);
			}

			strcpy (newcpath, argv[i+1]);

			if (vmargs.classpath != NULL) {
				strcat (newcpath, path_separator);
				strcat (newcpath, vmargs.classpath);
				free ((void*)vmargs.classpath);
			}

			/* set the new classpath */
			vmargs.classpath = newcpath;

                        isJar = 1;
                }
		else if (strncmp(argv[i], "-Xrun", 5) == 0) {
		  char *argPos;
		  char *libName;
		  int libnameLen;

		  argPos = strchr(argv[i], ':');
		  if (argPos != NULL)
		    {
		      libnameLen = argPos - &argv[i][5];
		      vmargs.profilerArguments = strdup(argPos+1);
		    }
		  else
		    libnameLen = strlen(argv[i]) - 1;

		  libName = malloc(libnameLen+4);
		  strcpy(libName, "lib");
		  strncat(libName, &argv[i][5], libnameLen);

		  vmargs.profilerLibname = libName;
		}
#if defined(KAFFE_PROFILER)
		else if (strcmp(argv[i], "-prof") == 0) {
			profFlag = 1;
			vmargs.enableClassGC = 0;
		}
#endif
#if defined(KAFFE_XPROFILER)
		else if (strcmp(argv[i], "-Xxprof") == 0) {
			xProfFlag = 1;
			vmargs.enableClassGC = 0;
		}
		else if (strcmp(argv[i], "-Xxprof_syms") == 0) {
			i++;
			if (argv[i] == 0) {
				fprintf(stderr, 
					_("Error: -Xxprof_syms option requires "
					"a file name.\n"));
			}
			else if( !profileSymbolFile(argv[i]) )
			{
				fprintf(stderr, 
					_("Unable to create profiler symbol "
					"file %s.\n"),
					argv[i]);
			}
		}
		else if (strcmp(argv[i], "-Xxprof_gmon") == 0) {
			i++;
			if (argv[i] == 0) {
				fprintf(stderr, 
					_("Error: -Xxprof_gmon option requires "
					"a file name.\n"));
			}
			else if (!profileGmonFile(argv[i]))
			{
				fprintf(stderr, 
					_("Unable to create gmon file %s.\n"),
					argv[i]);
			}
		}
#endif
#if defined(KAFFE_XDEBUGGING)
		else if (strcmp(argv[i], "-Xxdebug") == 0) {
			/* Use a default name */
			machine_debug_filename = "xdb.as";
		}
		else if (strcmp(argv[i], "-Xxdebug_file") == 0) {
			i++;
			if (argv[i] == 0) {
				fprintf(stderr, 
					_("Error: -Xxdebug_file option requires "
					"a file name.\n"));
			}
			else
			{
				machine_debug_filename = argv[i];
			}
		}
#endif
#if defined(KAFFE_FEEDBACK)
		else if (strcmp(argv[i], "-Xfeedback") == 0) {
			i++;
			if (argv[i] == 0) {
				fprintf(stderr, 
					_("Error: -Xfeedback option requires a "
					"file name.\n"));
			}
			else
			{
				feedback_filename = argv[i];
			}
		}
#endif
		else if (strcmp(argv[i], "-nodeadlock") == 0) {
			KaffeVM_setDeadlockDetection(0);
		}
#if defined(KAFFE_STATS)
                else if (strcmp(argv[i], "-vmstats") == 0) {
			extern void statsSetMaskStr(char *);
                        i++;
                        if (argv[i] == 0) { /* forgot second arg */
                                fprintf(stderr, 
					_("Error: -vmstats option requires a "
					"second arg.\n"));
                                exit(EXIT_FAILURE);
                        }
                        statsSetMaskStr(argv[i]);
                }
#endif
#if defined(KAFFE_VMDEBUG)
                else if (strcmp(argv[i], "-vmdebug") == 0) {
                        i++;
                        if (argv[i] == 0) { /* forgot second arg */
                                fprintf(stderr, 
					_("Error: -vmdebug option requires a "
					"debug flag. Use `list' for a list.\n"));
                                exit(EXIT_FAILURE);
                        }
                        if (!dbgSetMaskStr(argv[i]))
				exit(EXIT_FAILURE);
                }
#endif
                else if (strcmp(argv[i], "-debug-fd") == 0) {
			char *end;
                        i++;
                        if (argv[i] == 0) { /* forgot second arg */
                                fprintf(stderr, 
					_("Error: -debug-fd an open descriptor.\n"));
                                exit(EXIT_FAILURE);
                        }
			dbgSetDprintfFD(strtol(argv[i], &end, 10));
			if (end != 0 && *end != '\0') {
				fprintf(stderr,
					_("Error: -debug-fd requires an integer.\n"));
				exit(EXIT_FAILURE);
			}
                }
		else if (argv[i][1] ==  'D') {
			/* Set a property */
			char *propStr = strdup(&argv[i][2]);

			prop = setUserProperty(propStr);
		}
		else if (argv[i][1] == 'X') {
			fprintf(stderr, 
				_("Error: Unrecognized JVM specific option "
				"`%s'.\n"),
				argv[i]);
		}
		/* The following options are not supported and will be
		 * ignored for compatibility purposes.
		 */
		else if (strcmp(argv[i], "-noasyncgc") == 0 ||
		   strcmp(argv[i], "-cs") == 0 ||
		   strcmp(argv[i], "-checksource")) {
		}
		else if (strcmp(argv[i], "-oss") == 0) {
			i++;
		}
		else {
			fprintf(stderr,  _("Unknown flag: %s\n"), argv[i]);
		}
	}

	/* Return first no-flag argument */
	return (i);
}
Пример #12
0
	bool Pipeline::loadSetup(TiXmlElement *xml)
	{
		// Load textures
		for (TiXmlElement *element = xml->FirstChildElement("Texture");
		     element != 0;
		     element = element->NextSiblingElement("Texture"))
		{
			// Get texture name
			const char *name = element->Attribute("name");
			if (!name)
			{
				getManager()->getLog()->error("%s: Texture name missing.",
				                              getName().c_str());
				continue;
			}
			// Get texture format
			const char *formatstr = element->Attribute("format");
			TextureFormat::List format = TextureFormat::RGBA8;
			if (formatstr)
			{
				format = TextureFormat::fromString(formatstr);
				if (format == TextureFormat::Invalid)
				{
					getManager()->getLog()->error("%s: Invalid texture format \"%s\".",
					                              getName().c_str(),
					                              formatstr);
					continue;
				}
			}
			TargetTextureInfo texture;
			texture.name = name;
			parseSize(element, texture.relsize, texture.abssize);
			// Create texture resource
			unsigned int texturesize[2];
			texturesize[0] = (unsigned int)(texture.relsize[0] * targetsize[0])
			               + texture.abssize[0];
			texturesize[1] = (unsigned int)(texture.relsize[1] * targetsize[1])
			               + texture.abssize[1];
			Texture::Ptr texres = getManager()->createResource<Texture>("Texture");
			texres->set2D(texturesize[0], texturesize[1], format);
			texres->setMipmapsEnabled(false);
			// TODO: Configurable filtering
			texres->setFiltering(TextureFiltering::Nearest);
			texture.texture = texres;
			// Add the texture to the texture list
			targettextures.push_back(texture);
		}
		// Load frame buffer resources
		for (TiXmlElement *element = xml->FirstChildElement("FrameBuffer");
		     element != 0;
		     element = element->NextSiblingElement("FrameBuffer"))
		{
			// Get texture name
			const char *name = element->Attribute("name");
			if (!name)
			{
				getManager()->getLog()->error("%s: Texture name missing.",
				                              getName().c_str());
				continue;
			}
			FrameBufferInfo fb;
			fb.name = name;
			parseSize(element, fb.relsize, fb.abssize);
			// Get depthbuffer
			bool depthbuffer = false;
			const char *depthbufferstr = element->Attribute("depthbuffer");
			if (depthbufferstr && !strcmp(depthbufferstr, "true"))
			{
				depthbuffer = true;
			}
			// Create framebuffer
			fb.fb = getManager()->createResource<FrameBuffer>("FrameBuffer");
			unsigned int fbsize[2];
			fbsize[0] = (unsigned int)(fb.relsize[0] * targetsize[0])
			          + fb.abssize[0];
			fbsize[1] = (unsigned int)(fb.relsize[1] * targetsize[1])
			          + fb.abssize[1];
			fb.fb->setSize(fbsize[0], fbsize[1], depthbuffer);
			framebuffers.push_back(fb);
		}
		// Load render targets
		for (TiXmlElement *element = xml->FirstChildElement("RenderTarget");
		     element != 0;
		     element = element->NextSiblingElement("RenderTarget"))
		{
			// Get target name
			const char *name = element->Attribute("name");
			if (!name)
			{
				getManager()->getLog()->error("%s: RenderTarget name missing.",
				                              getName().c_str());
				continue;
			}
			// Get framebuffer
			const char *fbname = element->Attribute("framebuffer");
			if (!fbname)
			{
				getManager()->getLog()->error("%s: RenderTarget framebuffer name missing.",
				                              getName().c_str());
				continue;
			}
			FrameBuffer::Ptr fb = getFrameBuffer(fbname);
			if (!fb)
			{
				getManager()->getLog()->error("%s: RenderTarget framebuffer not found.",
				                              getName().c_str());
				continue;
			}
			// Create render target
			RenderTargetInfo target;
			target.target = getManager()->createResource<RenderTarget>("RenderTarget");
			target.name = name;
			target.target->setFrameBuffer(fb);
			// Depth buffer
			TiXmlElement *depthbufferelem = element->FirstChildElement("DepthBuffer");
			if (depthbufferelem)
			{
				const char *texname = depthbufferelem->Attribute("texture");
				if (!texname)
				{
					getManager()->getLog()->error("%s: DepthBuffer texture missing.",
					                              getName().c_str());
					continue;
				}
				Texture::Ptr texture = getTargetTexture(texname);
				if (!texture)
				{
					getManager()->getLog()->error("%s: DepthBuffer texture not found.",
					                              getName().c_str());
					continue;
				}
				target.target->setDepthBuffer(texture);
			}
			// Color buffers
			for (TiXmlElement *colorbufferelem = element->FirstChildElement("ColorBuffer");
			     colorbufferelem != 0;
			     colorbufferelem = colorbufferelem->NextSiblingElement("ColorBuffer"))
			{
				const char *texname = colorbufferelem->Attribute("texture");
				if (!texname)
				{
					getManager()->getLog()->error("%s: ColorBuffer texture missing.",
					                              getName().c_str());
					continue;
				}
				Texture::Ptr texture = getTargetTexture(texname);
				if (!texture)
				{
					getManager()->getLog()->error("%s: ColorBuffer texture not found.",
					                              getName().c_str());
					continue;
				}
				target.target->addColorBuffer(texture);
			}
			rendertargets.push_back(target);
		}
		return true;
	}