コード例 #1
0
IMPLEMENT_FUNCTION(httprequest, request)
{
	// free previous HTTP object (if any)
	httprequest_object* hro = get_httprequest_object_(interpr_, this_);
	httprequest_freeResponse_(hro, true);

	// get the callback
	if( argc_ < 2 )
		SEE_error_throw(interpr_, interpr_->Error, "too few parameters");
	if( argc_ > 3 )
		SEE_error_throw(interpr_, interpr_->Error, "too many parameters");
	SEE_object* callback  = ARG_CALLBACK(argc_-1);
	if( callback == NULL )
		SEE_error_throw(interpr_, interpr_->TypeError, "no callback given");

	// get the post buffer (if any)
	wxString postBuffer;
	if( argc_ > 2 )
		postBuffer = ARG_STRING(1);

	// set object persistent, remember the callback (always the last parameter)
	hro->m_see->AddPersistentObject((SEE_object*)hro, SJ_PERSISTENT_OTHER, NULL, httprequest_unexpected_unpersistent_);
	hro->m_persistentCallback = callback;

	// create a new HTTP object
	hro->m_sjHttp = new SjHttp();
	hro->m_sjHttpEvtHandler = new SjHttpEvtHandler(hro);

	hro->m_sjHttp->Init(hro->m_sjHttpEvtHandler, IDO_SEESOCKET);
	hro->m_sjHttp->OpenFile(ARG_STRING(0), &wxConvUTF8, hro->m_requestHeader, postBuffer);

	RETURN_UNDEFINED;
}
コード例 #2
0
IMPLEMENT_FUNCTION(httprequest, setRequestHeader)
{
	httprequest_object* hro = get_httprequest_object_(interpr_, this_);

	if( hro->m_requestHeader == NULL )
		hro->m_requestHeader = new SjSSHash();

	if( argc_ == 0 )
		hro->m_requestHeader->Clear();
	else
		hro->m_requestHeader->Insert(ARG_STRING(0), ARG_STRING(1));

	RETURN_UNDEFINED;
}
コード例 #3
0
ファイル: lint.cpp プロジェクト: lamyongxian/warzone2100
static QScriptValue js_makeComponentAvailable(QScriptContext *context, QScriptEngine *engine)
{
	ARG_COUNT_EXACT(2);
	ARG_STRING(0);
	ARG_PLAYER(1);
	return QScriptValue();
}
コード例 #4
0
ファイル: lint.cpp プロジェクト: Iluvalar/warzone2100
static QScriptValue js_isStructureAvailable(QScriptContext *context, QScriptEngine *engine)
{
	ARG_COUNT_EXACT(2);
	ARG_STRING(0);
	ARG_PLAYER(1);
	return QScriptValue(true);
}
コード例 #5
0
ファイル: lint.cpp プロジェクト: Iluvalar/warzone2100
/* Build a droid template in the specified factory */
static QScriptValue js_buildDroid(QScriptContext *context, QScriptEngine *)
{
	ARG_COUNT_EXACT(2);
	ARG_STRING(0);
	ARG_STRUCT(1);
	return QScriptValue(true);
}
コード例 #6
0
ファイル: lint.cpp プロジェクト: lamyongxian/warzone2100
static QScriptValue js_chat(QScriptContext *context, QScriptEngine *)
{
	ARG_COUNT_EXACT(2);
	ARG_PLAYER(0);
	ARG_STRING(1);
	return QScriptValue(true);
}
コード例 #7
0
ファイル: lint.cpp プロジェクト: lamyongxian/warzone2100
static QScriptValue js_isStructureAvailable(QScriptContext *context, QScriptEngine *engine)
{
	ARG_COUNT_VAR(1, 2);
	ARG_STRING(0);
	if (context->argumentCount() > 1) ARG_PLAYER(1);
	return QScriptValue(true);
}
コード例 #8
0
IMPLEMENT_FUNCTION(httprequest, getResponseHeader)
{
	httprequest_object* hro = get_httprequest_object_(interpr_, this_);
	wxString ret;
	if( hro->m_sjHttp )
		ret = hro->m_sjHttp->GetHttpResponseHeader(ARG_STRING(0));
	RETURN_STRING(ret);
}
コード例 #9
0
ファイル: lint.cpp プロジェクト: lamyongxian/warzone2100
static QScriptValue js_bind(QScriptContext *context, QScriptEngine *engine)
{
	ARG_COUNT_VAR(2, 3);
	ARG_STRING(0);
	ARG_OBJ(1);
	// TBD implement it for testing
	return QScriptValue();
}
コード例 #10
0
ファイル: lint.cpp プロジェクト: lamyongxian/warzone2100
static QScriptValue js_enableStructure(QScriptContext *context, QScriptEngine *engine)
{
	ARG_COUNT_VAR(1, 2);
	ARG_STRING(0);
	if (context->argumentCount() > 1)
	{
		ARG_PLAYER(1);
	}
	return QScriptValue();
}
コード例 #11
0
ファイル: lint.cpp プロジェクト: lamyongxian/warzone2100
static QScriptValue js_completeResearch(QScriptContext *context, QScriptEngine *engine)
{
	ARG_COUNT_VAR(1, 2);
	ARG_STRING(0);
	if (context->argumentCount() > 1)
	{
		ARG_PLAYER(1);
	}
	return QScriptValue();
}
コード例 #12
0
ファイル: lint.cpp プロジェクト: lamyongxian/warzone2100
static QScriptValue js_setStructureLimits(QScriptContext *context, QScriptEngine *engine)
{
	ARG_COUNT_VAR(2, 3);
	ARG_STRING(0);
	ARG_NUMBER(1);
	if (context->argumentCount() > 2)
	{
		ARG_PLAYER(2);
	}
	return QScriptValue();
}
コード例 #13
0
ファイル: lint.cpp プロジェクト: lamyongxian/warzone2100
static QScriptValue js_playSound(QScriptContext *context, QScriptEngine *engine)
{
	ARG_COUNT_VAR(1, 4);
	ARG_STRING(0);
	if (context->argumentCount() != 1)
	{
		SCRIPT_ASSERT(context, context->argumentCount() == 4, "Arguments must be either 1 or 4");
		ARG_NUMBER(1);
		ARG_NUMBER(2);
		ARG_NUMBER(3);
	}
	return QScriptValue();
}
コード例 #14
0
ファイル: lint.cpp プロジェクト: lamyongxian/warzone2100
/// Special scripting function that registers a object-specific timer event. Note: Functions must be passed
/// quoted, otherwise they will be inlined!
static QScriptValue js_queue(QScriptContext *context, QScriptEngine *engine)
{
	ARG_COUNT_VAR(1, 3);
	ARG_STRING(0);
	if (context->argumentCount() > 1) ARG_NUMBER(1);
	if (context->argumentCount() == 3) ARG_OBJ(2);
	QString funcName = context->argument(0).toString();
	// TODO - check that a function by that name exists
	// TODO - object argument
	int player = engine->globalObject().property("me").toInt32();
	timerNode node(engine, funcName, player);
	timers.push_back(node);
	return QScriptValue();
}
コード例 #15
0
ファイル: lint.cpp プロジェクト: Iluvalar/warzone2100
static QScriptValue js_enumStruct(QScriptContext *context, QScriptEngine *engine)
{
	ARG_COUNT_VAR(0, 3);
	switch (context->argumentCount())
	{
	default:
	case 3: ARG_PLAYER(2); // fall-through
	case 2: ARG_STRING(1); // fall-through
	case 1: ARG_PLAYER(0); break;
	}
	QScriptValue result = engine->newArray(3);
	for (int i = 0; i < 3; i++)
	{
		result.setProperty(i, convStructure(engine));
	}
	return result;
}
コード例 #16
0
ファイル: dispatch.c プロジェクト: armandofox/glomop
/*
 *  HTTP headers looked OK, and we were able to determine what type of
 *  distiller was needed, so go ahead and do the distillation, returning
 *  the results to the client.  If distillation fails, return the
 *  original content and headers to the client.
 *
 *  ARGS:
 *    i:  URL (BUG::shouldn't be needed - it's currently used to
 *      determine distiller type for "aggregator" virtual-site URLs )
 *    i: input to distiller (from previous "pipestage" or from server)
 *    o: output from distiller
 *    o: distiller type descriptor
 *    i: argument list for distiller
 *
 *  RETURNS:  Distiller status for the distillation
 *  REENTRANT: yes
 *  SIDE EFFECTS:
 *    If distillation succeeds, fills in new headers (for return to client)
 *      in DistillerOutput structure
 *  ASSUMTPIONS:
 *    None
 */
static DistillerStatus
do_distillation(const char *url,
                DistillerInput *dinp, DistillerOutput *doutp,
                C_DistillerType *dtype,
                ArgumentList *al)
{
  DistillerStatus result = distFatalError;
  Argument *arg;
  const char *whichuser = "******";
  const char *mime;
  int mime_len;

  /*
   *  HTTP headers look OK.  Extract the MIME type, figure out what
   *  distiller to use, and dispatch to it.
   */

  if ((arg = getArgumentFromIdInList(al, FRONT_USERID))) {
    whichuser = ARG_STRING(*arg);
  }

  /*
   *  If this is the set-prefs page, be sure the user's args get munged into it
   * REMOVED by fox since it interferes with the "mini-httpd" worker (miniserver.pl):
   * this routing is now enforced by X-Route instead
   */
  if (0 && strcasecmp(url, fe_set_prefs_url) == 0) {
    SET_DISTILLER_TYPE(*dtype, "transend/text/html");
  } else {
    set_distiller_type(&dinp->metadata,
                       (const char *)url, 
                       whichuser, dtype);
  }
  
  if ((mime = get_header_value(&dinp->metadata,
                               "content-type",
                               &mime_len, NULL, NULL)) != NULL) {
    strncpy(dinp->mimeType, mime, MIN(mime_len,MAX_MIMETYPE-1));
    dinp->mimeType[MIN(mime_len,MAX_MIMETYPE-1)] = '\0';
  } else {
    strcpy(dinp->mimeType, "text/html");
  }
  result = Distill(dtype, al->arg, al->nargs, dinp, doutp);
  return result;
}
コード例 #17
0
ファイル: lint.cpp プロジェクト: lamyongxian/warzone2100
static QScriptValue js_removeTimer(QScriptContext *context, QScriptEngine *)
{
	ARG_COUNT_EXACT(1);
	ARG_STRING(0);
	QString function = context->argument(0).toString();
	int i, size = timers.size();
	for (i = 0; i < size; ++i)
	{
		timerNode node = timers.at(i);
		if (node.function == function)
		{
			return QScriptValue();
		}
	}
	QString warnName = function.left(15) + "...";
	SCRIPT_ASSERT(context, false, "Did not find timer %s to remove", warnName.toUtf8().constData());
	return QScriptValue();
}
コード例 #18
0
ファイル: lint.cpp プロジェクト: lamyongxian/warzone2100
static QScriptValue js_include(QScriptContext *context, QScriptEngine *engine)
{
	ARG_COUNT_EXACT(1);
	ARG_STRING(0);
	// TODO -- implement this somehow -- not sure how to handle paths here
#if 0
	QString path = context->argument(0).toString();
	UDWORD size;
	char *bytes = NULL;
	if (!loadFile(path.toAscii().constData(), &bytes, &size))
	{
		debug(LOG_ERROR, "Failed to read include file \"%s\"", path.toAscii().constData());
		return false;
	}
	QString source = QString::fromAscii(bytes, size);
	free(bytes);
	QScriptSyntaxCheckResult syntax = QScriptEngine::checkSyntax(source);
	if (syntax.state() != QScriptSyntaxCheckResult::Valid)
	{
		debug(LOG_ERROR, "Syntax error in include %s line %d: %s", 
		      path.toAscii().constData(), syntax.errorLineNumber(), syntax.errorMessage().toAscii().constData());
		return false;
	}
	context->setActivationObject(engine->globalObject());
	context->setThisObject(engine->globalObject());
	QScriptValue result = engine->evaluate(source, path);
	if (engine->hasUncaughtException())
	{
		int line = engine->uncaughtExceptionLineNumber();
		debug(LOG_ERROR, "Uncaught exception at line %d, include file %s: %s",
		      line, path.toAscii().constData(), result.toString().toAscii().constData());
		return false;
	}
#endif
	return QScriptValue();
}
コード例 #19
0
ファイル: lint.cpp プロジェクト: lamyongxian/warzone2100
static QScriptValue js_translate(QScriptContext *context, QScriptEngine *engine)
{
	ARG_COUNT_EXACT(1);
	ARG_STRING(0);
	return QScriptValue(context->argument(0));
}
コード例 #20
0
ファイル: obj_Database.cpp プロジェクト: boh1996/silverjuke
IMPLEMENT_FUNCTION(database, openQuery)
{
	database_object* dbo = toDatabase(interpr_, this_);
	RETURN_BOOL( dbo->sql->Query(ARG_STRING(0)) );
}
コード例 #21
0
ファイル: lint.cpp プロジェクト: lamyongxian/warzone2100
static QScriptValue js_loadLevel(QScriptContext *context, QScriptEngine *)
{
	ARG_COUNT_EXACT(1);
	ARG_STRING(0);
	return QScriptValue();
}
コード例 #22
0
ファイル: lint.cpp プロジェクト: lamyongxian/warzone2100
static QScriptValue js_enableTemplate(QScriptContext *context, QScriptEngine *engine)
{
	ARG_COUNT_EXACT(1);
	ARG_STRING(0);
	return QScriptValue();
}
コード例 #23
0
ファイル: obj_Player.cpp プロジェクト: antonivich/Silverjuke
IMPLEMENT_FUNCTION(player, addAtPos)
{
	g_mainFrame->Enqueue(ARG_STRING(1), ARG_POS,
	                     false/*verified?*/, ARG_BOOL(2)/*autoplay?*/, false/*uiChecks?*/);
	RETURN_UNDEFINED;
}
コード例 #24
0
ファイル: test_main.c プロジェクト: armandofox/glomop
int
main(int argc, char *argv[])
{
  DistillerStatus st;
  UINT32 len;
  Argument args[12];
  int nargs = 0;
  int i;
  char *k;
  FILE *f;
  char nextfile[255];
  DistillerInput in;
  DistillerOutput out;
  C_DistillerType distType;

  sprintf(distType.string, "test " INPUT_MIME_TYPE);
  
  if ((argc < 2) || (argc >= 2  &&  strncmp(argv[1], "-h", 2) == 0)) {
    usage();
    exit(1);
  }

  if ((f = fopen(argv[1], "r")) == NULL) {
    fprintf(stderr, "Can't open input file %s\n", argv[1]);
    exit(1);
  }


  for (i=2; i<argc-1; i += 2, nargs++) {
    SET_ARG_ID(args[nargs], strtoul(&argv[i][1], (char**)NULL, 0));
    switch (argv[i][0]) {
    case 'i':
      SET_ARG_INT(args[nargs], strtol(argv[i+1], (char**)NULL, 0));
      fprintf(stderr, "Arg id %lu is %ld\n", ARG_ID(args[nargs]),
              ARG_INT(args[nargs]));
      break;
    case 'f':
      SET_ARG_DOUBLE(args[nargs], strtod(argv[i+1], (char**)NULL));
      fprintf(stderr, "Arg id %lu is %f\n", ARG_ID(args[nargs]),
              (float)ARG_DOUBLE(args[nargs]));
      break;
    case 's':
    default:
      SET_ARG_STRING(args[nargs], argv[i+1]);
      fprintf(stderr, "Arg id %lu is \"%s\"\n", ARG_ID(args[nargs]),
              ARG_STRING(args[nargs]));
    }
  }

  if ((st = DistillerInit(distType, 0, NULL)) != distOk) {
    fprintf(stderr, "DistillerInit failed: error %d\n", (int)st);
    exit(1);
  }

  SetMimeType(&in, INPUT_MIME_TYPE);
  while (fgets(nextfile, 254, f) != NULL) {
    char nextfile2[255];
    int fd;
    int count;
    int ii;
      
    nextfile[strlen(nextfile)-1] = 0;
    fd = open(nextfile, O_RDONLY);
    if (fd == -1) {
      fprintf(stderr, "Can't read %s, skipping\n", nextfile);
      continue;
    }
    for (len = 0;
         (count = read(fd, (void*)(buf+len), (sizeof(buf)-len))) > 0;
         len += count)
      ;
          
    fprintf(stderr, "Read %lu bytes from %s\n", len, nextfile);
    SetData(&in, (void *)buf);
    SetDataLength(&in, len);
    SetMetadata(&in, NULL);
    SetMetadataLength(&in, 0);

    for (ii= 0; ii<REPEAT_COUNT; ii++) {

      fprintf(stderr,"Calling distiller main\n");
      st = DistillerMain(args,nargs,&in,&out);
      if (st != distOk) {
        fprintf(stderr, "DistillerMain failed: error %d\n", (int)st);
      }
      close(fd);
      strcpy(nextfile2, argv[argc-1]);
      if (nextfile2[strlen(nextfile2)-1] != '/')
        strcat(nextfile2,"/");
      k = strrchr(nextfile, '/');
      if (k)
        strcat(nextfile2, k+1);
      else
        strcat(nextfile2, nextfile);
      strcat(nextfile2, ".OUT");
      fd = open(nextfile2, O_CREAT | O_WRONLY | O_TRUNC, 0666);
      if (fd == -1) {
        fprintf(stderr, "Can't write %s, using stdout\n", nextfile2);
        fd = fileno(stdout);
      }
      len = write(fd, (const void *)DataPtr(&out), (size_t)(DataLength(&out)));
      if (fd != fileno(stdout))
        close(fd);
      fprintf(stderr, "Wrote %lu of %lu bytes to %s\n", len, DataLength(&out), nextfile2);
      if (out.data.freeMe == gm_True) 
        DistillerFree(DataPtr(&out));
      if (out.metadata.freeMe == gm_True)
        DistillerFree(MetadataPtr(&out));
    }
  }
  return(1);
}
コード例 #25
0
ファイル: obj_Database.cpp プロジェクト: boh1996/silverjuke
IMPLEMENT_FUNCTION(database, construct)
{
	RETURN_OBJECT( HOST_DATA->Database_new(ARG_STRING(0)) );
}
コード例 #26
0
ファイル: host-text.c プロジェクト: RamchandraApte/rebol
*/	REBINT Text_Gob(void *richtext, REBSER *block)
/*
**		Handles all commands for the TEXT dialect as specified
**		in the system/dialects/text object.
**
**		This function calls the REBOL_Dialect interpreter to
**		parse the dialect and build and return the command number
**		(the index offset in the text object above) and a block
**		of arguments. (For now, just a REBOL block, but this could
**		be changed to isolate it from changes in REBOL's internals).
**
**		Each arg will be of the specified datatype (given in the
**		dialect) or NONE when no argument of that type was given
**		and this code must determine the proper default value.
**
**		If the cmd result is zero, then it is either the end of
**		the block, or an error has occurred. If the error value
**		is non-zero, then it was an error.
**
***********************************************************************/
{
	REBCNT index = 0;
	REBINT cmd;
	REBSER *args = 0;
	REBVAL *arg;
	REBCNT nargs;

	//font object conversion related values
	REBFNT* font;
	REBVAL* val;
	REBPAR  offset;
	REBPAR  space;

	//para object conversion related values
	REBPRA* para;
	REBPAR  origin;
	REBPAR  margin;
	REBPAR  indent;
	REBPAR  scroll;

	do {
		cmd = Reb_Dialect(DIALECTS_TEXT, block, &index, &args);

		if (cmd == 0) return 0;
		if (cmd < 0) {
//			Reb_Print("ERROR: %d, Index %d", -cmd, index);
			return -((REBINT)index+1);
		}
//		else
//			Reb_Print("TEXT: Cmd %d, Index %d, Args %m", cmd, index, args);

		arg = BLK_HEAD(args);
		nargs = SERIES_TAIL(args);
//		Reb_Print("Number of args: %d", nargs);

		switch (cmd) {

		case TW_TYPE_SPEC:

			if (IS_STRING(arg)) {
				rt_text(richtext, ARG_STRING(0), index);
			} else if (IS_TUPLE(arg)) {
				rt_color(richtext, ARG_TUPLE(0));
			}
			break;
		case TW_ANTI_ALIAS:
			rt_anti_alias(richtext, ARG_OPT_LOGIC(0));
			break;

		case TW_SCROLL:
			rt_scroll(richtext, ARG_PAIR(0));
			break;

		case TW_BOLD:
		case TW_B:
			rt_bold(richtext, ARG_OPT_LOGIC(0));
			break;

		case TW_ITALIC:
		case TW_I:
			rt_italic(richtext, ARG_OPT_LOGIC(0));
			break;

		case TW_UNDERLINE:
		case TW_U:
			rt_underline(richtext, ARG_OPT_LOGIC(0));
			break;
		case TW_CENTER:
			rt_center(richtext);
			break;
		case TW_LEFT:
			rt_left(richtext);
			break;
		case TW_RIGHT:
			rt_right(richtext);
			break;
		case TW_FONT:

		if (!IS_OBJECT(arg)) break;

		font = (REBFNT*)rt_get_font(richtext);

		val = BLK_HEAD(ARG_OBJECT(0))+1;

		if (IS_STRING(val)) {
			font->name = VAL_STRING(val);
		}

//		Reb_Print("font/name: %s", font->name);

		val++;

		if (IS_BLOCK(val)) {
			REBSER* styles = VAL_SERIES(val);
			REBVAL* slot = BLK_HEAD(styles);
			REBCNT len = SERIES_TAIL(styles) ,i;

			for (i = 0;i<len;i++){
				if (IS_WORD(slot+i)){
					set_font_styles(font, slot+i);
				}
			}

		} else if (IS_WORD(val)) {
			set_font_styles(font, val);
		}

		val++;
		if (IS_INTEGER(val)) {
			font->size = VAL_INT32(val);
		}

//		Reb_Print("font/size: %d", font->size);

		val++;
		if ((IS_TUPLE(val)) || (IS_NONE(val))) {
			COPY_MEM(font->color,VAL_TUPLE(val), 4);
		}

//		Reb_Print("font/color: %d.%d.%d.%d", font->color[0],font->color[1],font->color[2],font->color[3]);

		val++;
		if ((IS_PAIR(val)) || (IS_NONE(val))) {
			offset = VAL_PAIR(val);
			font->offset_x = offset.x;
			font->offset_y = offset.y;
		}

//		Reb_Print("font/offset: %dx%d", offset.x,offset.y);

		val++;
		if ((IS_PAIR(val)) || (IS_NONE(val))) {
			space = VAL_PAIR(val);
			font->space_x = space.x;
			font->space_y = space.y;
		}

//		Reb_Print("font/space: %dx%d", space.x, space.y);


		val++;

		font->shadow_x = 0;
		font->shadow_y = 0;

		if (IS_BLOCK(val)) {
			REBSER* ser = VAL_SERIES(val);
			REBVAL* slot = BLK_HEAD(ser);
			REBCNT len = SERIES_TAIL(ser) ,i;

			for (i = 0;i<len;i++){
				if (IS_PAIR(slot)) {
					REBPAR shadow = VAL_PAIR(slot);
					font->shadow_x = shadow.x;
					font->shadow_y = shadow.y;
				} else if (IS_TUPLE(slot)) {
					COPY_MEM(font->shadow_color,VAL_TUPLE(slot), 4);
				} else if (IS_INTEGER(slot)) {
					font->shadow_blur = VAL_INT32(slot);
				}
				slot++;
			}
		} else if (IS_PAIR(val)) {
			REBPAR shadow = VAL_PAIR(val);
			font->shadow_x = shadow.x;
			font->shadow_y = shadow.y;
		}

			rt_font(richtext, font);
			break;

		case TW_PARA:
			if (!IS_OBJECT(arg)) break;

			para = (REBPRA*)rt_get_para(richtext);

			val = BLK_HEAD(ARG_OBJECT(0))+1;


			if (IS_PAIR(val)) {
				origin = VAL_PAIR(val);
				para->origin_x = origin.x;
				para->origin_y = origin.y;
			}

//			Reb_Print("para/origin: %dx%d", origin.x, origin.y);

			val++;
			if (IS_PAIR(val)) {
				margin = VAL_PAIR(val);
				para->margin_x = margin.x;
				para->margin_y = margin.y;
			}

//			Reb_Print("para/margin: %dx%d", margin.x, margin.y);

			val++;
			if (IS_PAIR(val)) {
				indent = VAL_PAIR(val);
				para->indent_x = indent.x;
				para->indent_y = indent.y;
			}

//			Reb_Print("para/indent: %dx%d", indent.x, indent.y);

			val++;
			if (IS_INTEGER(val)) {
				para->tabs = VAL_INT32(val);
			}

//			Reb_Print("para/tabs: %d", para->tabs);

			val++;
			if (IS_LOGIC(val)) {
				para->wrap = VAL_LOGIC(val);
			}

//			Reb_Print("para/wrap?: %d", para->wrap);

			val++;
			if (IS_PAIR(val)) {
				scroll = VAL_PAIR(val);
				para->scroll_x = scroll.x;
				para->scroll_y = scroll.y;
			}
//			Reb_Print("para/scroll: %dx%d", scroll.x, scroll.y);

			val++;

			if (IS_WORD(val)) {
				REBINT result = Reb_Find_Word(VAL_WORD_SYM(val), Symbol_Ids, 0);
				switch (result){
					case SW_RIGHT:
					case SW_LEFT:
					case SW_CENTER:
						para->align = result;
						break;
					default:
						para->align = SW_LEFT;
						break;
				}

			}

			val++;

			if (IS_WORD(val)) {
				REBINT result = Reb_Find_Word(VAL_WORD_SYM(val), Symbol_Ids, 0);
				switch (result){
					case SW_TOP:
					case SW_BOTTOM:
					case SW_MIDDLE:
						para->valign = result;
						break;
					default:
						para->valign = SW_TOP;
						break;
				}
			}

			rt_para(richtext, para);
			break;

		case TW_SIZE:
			rt_font_size(richtext, ARG_INTEGER(0));
			break;

		case TW_SHADOW:
			rt_shadow(richtext, &ARG_PAIR(0), ARG_TUPLE(1), ARG_INTEGER(2));
			break;

		case TW_DROP:
			rt_drop(richtext, ARG_OPT_INTEGER(0));
			break;

		case TW_NEWLINE:
		case TW_NL:
			rt_newline(richtext, index);
			break;
		case TW_CARET:
			{
				REBPAR caret = {0,0};
				REBPAR highlightStart = {0,0};
				REBPAR highlightEnd = {0,0};
				REBVAL *slot;
				if (!IS_OBJECT(arg)) break;

				val = BLK_HEAD(ARG_OBJECT(0))+1;
				if (IS_BLOCK(val)) {
					slot = BLK_HEAD(VAL_SERIES(val));
					if (SERIES_TAIL(VAL_SERIES(val)) == 2 && IS_BLOCK(slot) && IS_STRING(slot+1)){
						caret.x = 1 + slot->data.series.index;
						caret.y = 1 + (slot+1)->data.series.index;;
						//Reb_Print("caret %d, %d", caret.x, caret.y);
					}
				}
				val++;
				if (IS_BLOCK(val)) {
					slot = BLK_HEAD(VAL_SERIES(val));
					if (SERIES_TAIL(VAL_SERIES(val)) == 2 && IS_BLOCK(slot) && IS_STRING(slot+1)){
						highlightStart.x = 1 + slot->data.series.index;
						highlightStart.y = 1 + (slot+1)->data.series.index;;
						//Reb_Print("highlight-start %d, %d", highlightStart.x, highlightStart.y);
					}
				}
				val++;
				if (IS_BLOCK(val)) {
					slot = BLK_HEAD(VAL_SERIES(val));
					if (SERIES_TAIL(VAL_SERIES(val)) == 2 && IS_BLOCK(slot) && IS_STRING(slot+1)){
						highlightEnd.x = 1 + slot->data.series.index;
						highlightEnd.y = 1 + (slot+1)->data.series.index;;
						//Reb_Print("highlight-End %d, %d", highlightEnd.x, highlightEnd.y);
					}
				}

				rt_caret(richtext, &caret, &highlightStart,&highlightEnd);
			}
			break;
		}
	} while (TRUE);
}
コード例 #27
0
ファイル: lint.cpp プロジェクト: lamyongxian/warzone2100
static QScriptValue js_addFeature(QScriptContext *context, QScriptEngine *engine)
{
	ARG_STRING(2);
	return QScriptValue(convFeature(engine));
}
コード例 #28
0
ファイル: test_main.c プロジェクト: armandofox/glomop
int
main(int argc, char *argv[])
{
    DistillerStatus st;
    UINT32 len;
    Argument args[12];
    int nargs = 0;
    gm_Bool bool;
    int i;
    char *k;
    FILE *f;
    char nextfile[255];
    DistillerInput in;
    DistillerOutput out;
    C_DistillerType distType;

    sprintf(distType.string, "test image/gif");

    if ((argc < 2) || (argc >= 2  &&  strncmp(argv[1], "-h", 2) == 0)) {
        usage();
        exit(1);
    }

    if ((f = fopen(argv[1], "r")) == NULL) {
        fprintf(stderr, "Can't open input file %s\n", argv[1]);
        exit(1);
    }


    for (i=2; i<argc-1; i += 2, nargs++) {
        SET_ARG_ID(args[nargs], strtoul(argv[i], (char**)NULL, 0));
        if (isdigit(*argv[i+1])) {
            SET_ARG_INT(args[nargs], strtol(argv[i+1], (char**)NULL, 0));
            fprintf(stderr, "Arg id %lu is %ld\n", ARG_ID(args[nargs]),
                    ARG_INT(args[nargs]));
        } else {
            SET_ARG_STRING(args[nargs], argv[i+1]);
            fprintf(stderr, "Arg id %lu is \"%s\"\n", ARG_ID(args[nargs]),
                    ARG_STRING(args[nargs]));
        }
    }

    if ((st = DistillerInit(distType)) != distOk) {
        fprintf(stderr, "DistillerInit failed: error %d\n", (int)st);
        exit(1);
    }

    strcpy(in.mimeType, "image/gif");
    while (fgets(nextfile, 254, f) != NULL) {
        char nextfile2[255];
        int fd;
        int count;

        nextfile[strlen(nextfile)-1] = 0;
        fd = open(nextfile, O_RDONLY);
        if (fd == -1) {
            fprintf(stderr, "Can't read %s, skipping\n", nextfile);
            continue;
        }
        for (len = 0;
                (count = read(fd, (void*)(buf+len), (sizeof(buf)-len))) > 0;
                len += count)
            ;

        fprintf(stderr, "Read %lu bytes from %s\n", len, nextfile);
        in.data = (void *)buf;
        in.length = len;
        fprintf(stderr,"Calling distiller main\n");
        st = DistillerMain(args,nargs,&in,&out,&bool);
        if (st != distOk) {
            fprintf(stderr, "DistillerMain failed: error %d\n", (int)st);
        }
        close(fd);
        strcpy(nextfile2, argv[argc-1]);
        if (nextfile2[strlen(nextfile2)-1] != '/')
            strcat(nextfile2,"/");
        k = strrchr(nextfile, '/');
        if (k)
            strcat(nextfile2, k+1);
        else
            strcat(nextfile2, nextfile);
        strcat(nextfile2, ".OUT");
        fd = open(nextfile2, O_CREAT | O_WRONLY | O_TRUNC, 0666);
        if (fd == -1) {
            fprintf(stderr, "Can't write %s, using stdout\n", nextfile2);
            fd = fileno(stdout);
        }
        len = write(fd, (const void *)out.data, (size_t)out.length);
        if (fd != fileno(stdout))
            close(fd);
        fprintf(stderr, "Wrote %lu of %lu bytes to %s\n", len, out.length, nextfile2);
        if (bool)
            DistillerFree(out.data);
    }
}
コード例 #29
0
ファイル: dd_digest.c プロジェクト: pagxir/deadshot
int main(int argc, char * argv[])
{
        int i;
        int read_write_error;
        int input_stat[2] = {0};
        int output_stat[2] = {0};

        int flags = 0;
        int count = -1;
        int skip = 0, seek = 0;
        int bs = -1, ibs = 4096, obs = 4096;
        int buffer_size = 0;
        int count_read, count_write;
        time_t time_start, time_finish, time_use;

        const char * input_path = "-";
        const char * output_path = "-";
        const char * input_device = NULL;
        const char * output_device = NULL;

        struct io_base *input_handle, *output_handle;
        char * buffer_read, * buffer_write, * buffer_alloc;

        for (i = 1; i < argc; i++) {
                char * argline = argv[i];
                char * optvalue = getoptvalue(argv[i]);

                ARG_INT(&ibs, 1, "ibs=");
                ARG_INT(&obs, 2, "obs=");
                ARG_INT(&bs, (1 | 2), "bs=");
                ARG_INT(&seek, 4, "seek=");
                ARG_INT(&skip, 8, "skip=");
                ARG_INT(&count, 16, "count=");
                ARG_STRING(&input_path, 32, "if=");
                ARG_STRING(&output_path, 64, "of=");
                ARG_STRING(&input_device, 128, "kin=");
                ARG_STRING(&output_device, 256, "kout=");

                fprintf(stderr, "unkown operand %s", argline);
                exit(-1);
        }

        if (bs != -1) {
                ibs = bs;
                obs = bs;
        }

        valid_size("invalid input block size", ibs);
        valid_size("invalid output block size", obs);

        input_handle = open_file(input_path, GENERIC_READ);
        valid_handle("invalid input handle", input_handle);

        output_handle = open_file(output_path, GENERIC_WRITE);
        valid_handle("invalid output handle", output_handle);

        buffer_size = (ibs < obs? obs: ibs) * 2;
        buffer_alloc = (char *)malloc(buffer_size);
        valid_buffer("alloc buffer fail", buffer_alloc);

        if (seek > 0) {
				off_t posnew = seek * (off_t)(obs);
				off_t poscur = io_lseek(output_handle, posnew, SEEK_CUR);
                valid_size("seek output file fail", posnew == poscur);
        }

        if (skip > 0) {
				off_t posnew = skip * (off_t)(ibs);
				off_t poscur = io_lseek(output_handle, posnew, SEEK_CUR);
                valid_size("skip input file fail", posnew == poscur);
        }

        read_write_error = 0;
        count_read = count_write = 0;
        buffer_read = buffer_write = buffer_alloc;

        time_start = time(NULL);
        while (read_write_error == 0) {
                size_t transfer = 0;

                while (buffer_read < buffer_alloc + obs) {
                        if (!io_read(input_handle, buffer_read, ibs, &transfer)) {
                                read_write_error = 2;
                                break;
                        }

                        if (transfer == 0) {
                                read_write_error = 1;
                                break;
                        }

                        buffer_read += transfer;
                        count_read += transfer;

                        input_stat[transfer == ibs]++;
                        if (input_stat[0] + input_stat[1] == count) {
                                read_write_error = 1;
                                break;
                        }
                }

                while (buffer_write + obs <= buffer_read) {
                        if (!io_write(output_handle, buffer_write, obs, &transfer)) {
                                read_write_error = 2;
                                break;
                        }

                        if (transfer == 0) {
                                read_write_error = 2;
                                break;
                        }

                        output_stat[transfer == obs]++;
                        buffer_write += transfer;
                        count_write += transfer;
                }

                memmove(buffer_alloc, buffer_write, count_read - count_write);
                buffer_read = buffer_alloc + (count_read - count_write);
                buffer_write = buffer_alloc;
        }

        while (read_write_error == 1 &&
                        count_write < count_read) {
                size_t transfer = (count_read - count_write);

                valid_size("internal error", transfer < obs);
                if (io_write(output_handle, buffer_write, transfer, &transfer)) {
                        output_stat[transfer == obs]++;
                        buffer_write += transfer;
                        count_write += transfer;
                        continue;
                }

                if (io_write(output_handle, buffer_write, obs, &transfer)) {
                        output_stat[transfer == obs]++;
                        buffer_write += transfer;
                        count_write += transfer;
                        continue;
                }
           
                read_write_error = 3;
                break;
        }
        time_finish = time(NULL);

        io_close(output_handle);
        io_close(input_handle);
        free(buffer_alloc);

        time_use = time_finish > time_start? time_finish - time_start: 1;
        fprintf(stderr, "%d+%d records in\n", input_stat[1], input_stat[0]);
        fprintf(stderr, "%d+%d records out\n", output_stat[1], output_stat[0]);
        fprintf(stderr, "%d bytes transferred in %ld secs (%ld bytes/sec)\n",
                        count_read, time_use, count_read / time_use);
        return 0;
}