Esempio n. 1
0
void ParseAsync(const Nan::FunctionCallbackInfo<Value> &args) {
  Isolate *isolate = args.GetIsolate();
  int args_length = args.Length();

  if (args_length < 2) {
    isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
    return;
  }

  Local<Value> input = args[0];
  if (!ValidateInput(input, isolate)) {
    return;
  }
  if (!args[1]->IsFunction()) {
    isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Second parameter must be a callback")));
    return;
  }

  Nan::Callback *callback = new Nan::Callback(args[1].As<Function>());
  anitomyJs::Worker *worker = new anitomyJs::Worker(callback);

  if (args_length >= 3) {
    Local<Value> options = args[2];
    if (!ValidateOptions(options, isolate) ||
        !worker->GetAnitomy()->SetOptions(options->ToObject(isolate->GetCurrentContext()).ToLocalChecked(), isolate)) {
      return;
    }
  }

  worker->GetAnitomy()->SetInput(input, isolate);
  Nan::AsyncQueueWorker(worker);
  args.GetReturnValue().Set(Nan::Undefined());
}
Esempio n. 2
0
void ParseSync(const Nan::FunctionCallbackInfo<Value> &args) {
  Isolate *isolate = args.GetIsolate();
  int args_length = args.Length();

  if (args_length < 1) {
    isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
    return;
  }

  Local<Value> input = args[0];
  if (!ValidateInput(input, isolate)) {
    return;
  }

  anitomyJs::AnitomyJs anitomy;
  if (args_length >= 2) {
    Local<Value> options = args[1];
    if (!ValidateOptions(options, isolate) ||
        !anitomy.SetOptions(options->ToObject(isolate->GetCurrentContext()).ToLocalChecked(), isolate)) {
      return;
    }
  }

  anitomy.SetInput(input, isolate);
  anitomy.Parse();

  args.GetReturnValue().Set(anitomy.ParsedResult(isolate));
}
Esempio n. 3
0
bool Engine::ValidateOptions(anime::Episode& episode, int anime_id,
                             const MatchOptions& match_options,
                             bool redirect) const {
    auto anime_item = AnimeDatabase.FindItem(anime_id);

    if (!anime_item)
        return false;

    return ValidateOptions(episode, *anime_item, match_options, redirect);
}
Esempio n. 4
0
int main(int argc, char** argv)
{
	int ret = EXIT_SUCCESS;

	// Setup default error handling strategy.
	// ...

	// Setup the default log stream.
	Log logger;
	LogSetDefault(&logger);

	// Setup the command line handling.
	AnyOption options;

	// Use this to active debug mode.
	options.setFlag("debug", 'd');

	options.setVerbose();
	options.autoUsagePrint(true);

	// Process the command line arguments.
	options.processCommandArgs(argc, argv);

	String file;
	ret = ValidateOptions(options, file);

	if( ret != EXIT_SUCCESS )
	{
		options.printUsage();
		return ret;
	}

	Runtime runtime;
	runtime.init();
	runtime.shutdown();

	return ret;
}
Esempio n. 5
0
int main (int argc, char *argv[]) {
	int c;
	unsigned long hostaddr;
	FILE *cmdfile;
	char *cmdline = NULL;
	char *cmdtok = NULL;
	char *filename = NULL;
	char line[MAXLEN];
	char tmpcmd[MAXLEN];
	debug=0;verbose=0;errpause=0;skiperr=0;allocpty=0;envfl=0;
	timeout=5;
	enable_trace=0;
	tracelvl=0;
	errfile=NULL;
	envfilenm=NULL;
	appname = basename(argv[0]);
	while ((c = getopt (argc, argv, "dhpvP :c:f:t:s:e:T:")) != -1) {
		switch (c) {
			case 'c':
				cmdline = optarg;
				break;
				
			case 'd':
				debug++;
				break;
				
			case 'f':
				filename = optarg;
				break;
				
			case 'h':
				PrintUsage();
				break;
				
			case 'p':
				errpause++;
				break;
				
			case 'P':
				allocpty++;
				break;
				
			case 'e':
				envfl++;
				envfilenm = optarg;
				break;
				
			case 's':
				skiperr++;
				errfile = optarg;
				break;
				
			case 't':
				timeout = (int) strtol(optarg, (char **)NULL, 10);
				break;
				
			case 'T':
				enable_trace++;
				tracelvl = (int) strtol(optarg, (char **)NULL, 10);
				break;
				
			case 'v':
				verbose++;
				break;
				
			case '?':
				PrintUsage();
				break;
		}
	}
	
	ValidateOptions(cmdline,filename);
	
	if ((argc - optind) == 1) {
		hostaddr = GetHostInfo((char *)argv[optind]);
	} else {
        fprintf(stderr, "Hostname or IP is required\n\n");
        PrintUsage();
	}
	
	/* Get Username from effecive user id running the program */
	GetUserInfo();
	
	/* Initialize the Session */
	InitSession(hostaddr);
	
	if (cmdline != NULL) {
		RunCommand(cmdline);
	} else {
		if ((cmdfile = fopen(filename, "r")) == 0) {
			fprintf(stderr, "Could not open file %s:%s\n",
					filename ,strerror(errno));
			exit(-1);
		}
		
		strcpy(tmpcmd,"");
		while (fgets(line, sizeof(line), cmdfile) != NULL) {
			cmdtok = strdup(line);
			if (CheckLine(trim(cmdtok))) {
				sprintf(tmpcmd,"%s%s",tmpcmd,cmdtok);
			} else {
				if ( strcmp(tmpcmd,"") != 0 ) {
					sprintf(tmpcmd,"%s%s",tmpcmd,cmdtok);
					free(cmdtok);
					cmdtok = strdup(tmpcmd);
				}
				if (strlen(cmdtok) > 1 && SkipComments(cmdtok) ) {
					RunCommand(cmdtok);
				}
				strcpy(tmpcmd,"");
			}
			free(cmdtok);
		}
		if (strcmp(tmpcmd,"") != 0) {
			RunCommand(tmpcmd);
			strcpy(tmpcmd,"");
		}
	}
	CleanupSession(session,username);
	return 0;
}