Example #1
0
File: help.c Project: pexip/os-dpkg
int maintainer_script_alternative(struct pkginfo *pkg,
                                  const char *scriptname, const char *desc,
                                  const char *cidir, char *cidirrest,
                                  const char *ifok, const char *iffallback) {
  struct command cmd;
  const char *oldscriptpath;
  struct stat stab;
  char buf[100];

  oldscriptpath = pkgadminfile(pkg, &pkg->installed, scriptname);
  sprintf(buf, _("old %s script"), desc);

  command_init(&cmd, oldscriptpath, buf);
  command_add_args(&cmd, scriptname, ifok,
                   versiondescribe(&pkg->available.version, vdew_nonambig),
                   NULL);

  if (stat(oldscriptpath,&stab)) {
    if (errno == ENOENT) {
      debug(dbg_scripts,"maintainer_script_alternative nonexistent %s `%s'",
            scriptname,oldscriptpath);
      command_destroy(&cmd);
      return 0;
    }
    warning(_("unable to stat %s '%.250s': %s"),
            cmd.name, oldscriptpath, strerror(errno));
  } else {
    if (!do_script(pkg, &pkg->installed, &cmd, &stab, PROCWARN)) {
      command_destroy(&cmd);
      post_script_tasks();
      return 1;
    }
  }
  fprintf(stderr, _("dpkg - trying script from the new package instead ...\n"));

  strcpy(cidirrest,scriptname);
  sprintf(buf, _("new %s script"), desc);

  command_destroy(&cmd);
  command_init(&cmd, cidir, buf);
  command_add_args(&cmd, scriptname, iffallback,
                   versiondescribe(&pkg->installed.version, vdew_nonambig),
                   NULL);

  if (stat(cidir,&stab)) {
    command_destroy(&cmd);
    if (errno == ENOENT)
      ohshit(_("there is no script in the new version of the package - giving up"));
    else
      ohshite(_("unable to stat %s `%.250s'"),buf,cidir);
  }

  do_script(pkg, &pkg->available, &cmd, &stab, 0);
  fprintf(stderr, _("dpkg: ... it looks like that went OK.\n"));

  command_destroy(&cmd);
  post_script_tasks();

  return 1;
}
Example #2
0
File: help.c Project: pexip/os-dpkg
int
maintainer_script_new(struct pkginfo *pkg,
                      const char *scriptname, const char *desc,
                      const char *cidir, char *cidirrest, ...)
{
  struct command cmd;
  struct stat stab;
  va_list args;
  char buf[100];

  strcpy(cidirrest, scriptname);
  sprintf(buf, _("new %s script"), desc);

  va_start(args, cidirrest);
  command_init(&cmd, cidir, buf);
  command_add_arg(&cmd, scriptname);
  command_add_argv(&cmd, args);
  va_end(args);

  if (stat(cidir,&stab)) {
    command_destroy(&cmd);
    if (errno == ENOENT) {
      debug(dbg_scripts,"maintainer_script_new nonexistent %s `%s'",scriptname,cidir);
      return 0;
    }
    ohshite(_("unable to stat %s `%.250s'"), buf, cidir);
  }
  do_script(pkg, &pkg->available, &cmd, &stab, 0);

  command_destroy(&cmd);
  post_script_tasks();

  return 1;
}
Example #3
0
File: help.c Project: pexip/os-dpkg
static int
vmaintainer_script_installed(struct pkginfo *pkg, const char *scriptname,
                             const char *desc, va_list args)
{
  struct command cmd;
  const char *scriptpath;
  struct stat stab;
  char buf[100];

  scriptpath = pkgadminfile(pkg, &pkg->installed, scriptname);
  sprintf(buf, _("installed %s script"), desc);

  command_init(&cmd, scriptpath, buf);
  command_add_arg(&cmd, scriptname);
  command_add_argv(&cmd, args);

  if (stat(scriptpath,&stab)) {
    command_destroy(&cmd);
    if (errno == ENOENT) {
      debug(dbg_scripts, "vmaintainer_script_installed nonexistent %s",
            scriptname);
      return 0;
    }
    ohshite(_("unable to stat %s `%.250s'"), buf, scriptpath);
  }
  do_script(pkg, &pkg->installed, &cmd, &stab, 0);

  command_destroy(&cmd);

  return 1;
}
Example #4
0
/* FUNCTION: call_script_ctx()
 *
 * Execute commands from a script file.
 *   - A new GIO struct is pushed onto the GIO stack.
 *   - The input stream is set to the script file
 *   - The output stream is "null" of echo_out is FALSE.
 *   - Commands are parsed and executed until EOF is reached.
 *
 * PARAM1: CLI_CTX            current CLI context
 * PARAM2: void *             script name or memory address
 * PARAM3: int                input type: file or memory
 * PARAM4: bool_t             TRUE = echo commands to output stream
 * PARAM5: bool_t             FALSE = suppress command output
 * PARAM6: bool_t             TRUE = abort script on first error
 *
 * RETURN: int                0 or error code
 */
int
call_script_ctx(CLI_CTX ctx, void *cmdset, int type,
                bool_t echo_in, bool_t echo_out, bool_t halt)
{
   GIO   *gio = ctx->gio;
   VFILE *fd; 
   int   rtn;

   switch (type)
   {
   case CMDSFROMFILE:
      if ((fd = vfopen((char *)cmdset, "r")) == (VFILE *)NULL)
      {
/*       gio_printf(gio, "file not found: %s\n", cmdset); */
         return (ENP_NOFILE);
      }
      else
      {
         /* input = file */
         if ((rtn = GIO_PUSH_FILE(&ctx->gio, fd, GIO_RD)) != GIO_DONE)
         {
            vfclose(fd);
            return (rtn);
         }
         gio = ctx->gio;      /* update gio descriptor */

         /* if echo_out == FALSE, redirect output to "null" */
         if (!echo_out)
         {
            GIO_NULL(gio, GIO_WR);
         }

         /* set the GIO_F_ECHO flag if we are echoing commands */
         if (echo_in)
            gio->flags |= GIO_F_ECHO;
         else
            gio->flags &= ~GIO_F_ECHO;

         rtn = do_script(ctx, halt);

         vfclose(fd);         /* close the file */
         gio_pop(&ctx->gio);  /* destroy the script context */
      }   
      break;  
   
   case CMDSFROMMEM:
      /* not yet implemented */

   default:
      dtrap();                /* unknown script type */
      rtn = CLI_ERR_FATAL;
      break;
   }

   return (rtn);
}
Example #5
0
int PulleyDispatcher::do_script(const Values& values, Object& response)
{
	auto& log = SteamWorks::Logging::getLogger("steamworks.pulley");

	std::string filename = _get_parameter(values, "filename");
	if (filename.empty())
	{
		log.warnStream() << "No filename given.";
		return 0;
	}
	if (d->count_followers())
	{
		log.warnStream() << "Can't read script file after connecting to server.";
		return 0;
	}

	log.debugStream() << "Reading script from '" << filename << '\'';
	auto r = do_script(filename.c_str());

	if (r)
	{
		// Still return 0, because we want the pulley to continue.
		// TODO: error reporting through @p response
		return 0;
	}

	std::string base = _get_parameter(values, "base");
	bool autofollow = false;
	auto a = values.get("autofollow");
	if (!a.is<picojson::null>())
	{
		autofollow = a.is<bool>() && a.get<bool>();
	}

	if (autofollow && base.empty())
	{
		log.warnStream() << "Pulleyscript autoload is on, but no base is set.";
	}
	else if (autofollow)
	{
		auto synclist = d->m_parser->find_subscriptions();
		log.debugStream() << "Pulleyscript adding " << std::distance(synclist.cbegin(), synclist.cend()) << " subscriptions.";
		for (auto filter : synclist)
		{
			d->add_follower(base, filter, response);
		}

		d->m_parser->find_backends();
	}
	else
	{
		log.debugStream() << "Pulleyscript loaded, no autofollow.";
	}

	return 0;
}
Example #6
0
int PulleyDispatcher::exec(const std::string& verb, const Values& values, Object& response)
{
	if (verb == "connect") return do_connect(values, response);
	else if (verb == "stop") return do_stop(values);
	else if (verb == "serverinfo") return do_serverinfo(values, response);
	else if (verb == "follow") return do_follow(values, response);
	else if (verb == "unfollow") return do_unfollow(values, response);
	else if (verb == "dump_dit") return do_dump_dit(values, response);
	else if (verb == "resync") return do_resync(values, response);
	else if (verb == "script") return do_script(values, response);
	return -1;
}
Example #7
0
int main()
{
	lua_State *L = lua_open();
	luaopen_base( L );
	
	do_script( L, "test_coro.lua" );

	/* for testing purpose only */
	while( gTimerHandlers.size() != 0 )
	{
		DWORD now = GetTickCount();
		for( TimerHandlerList::iterator it = gTimerHandlers.begin(); it != gTimerHandlers.end(); )
		{
			TimerHandler *h = *it;
			if( h->_start + h->_delay <= now )
			{
				h->_fn( L );
				free( h );
				it = gTimerHandlers.erase( it );
				continue;
			}

			++ it;
		}

		Sleep( 1 );
	}

	/* clear */
	struct deletor
	{
		void operator()( TimerHandler *h )
		{
			free( h );
		}
	};
	std::for_each( gTimerHandlers.begin(), gTimerHandlers.end(), deletor() );

	lua_close( L );
	return 0;
}
Example #8
0
void Control::interpretator(string line)
{

  /*** Transforms to lower case ***/
  //transform(line.begin(), line.end(), line.begin(),::tolower);

  /*** check for commentation ***/
  string checkComment(line,0,1);
  if(checkComment == "#" || line.size()<2)
    return;

  /*** replaces '{' and '}' with ' { ' and ' } ' ***/
  for(unsigned int i=0; i<line.size(); i++)
    {
      if(string(line,i,1) =="{")
	{
	  line.replace(i, 1, string(" { "),0,3);
	  i++;
	}
      else if(string(line,i,1)=="}")
	{
	  line.replace(i, 1, string(" } "),0,3);
	  i++;
	}
    }  

  /*** break command into words ***/
  vector<string> words;
  words.clear();
  char temp[300];
  istringstream stream(line.c_str());
  while(stream>>temp)
    words.push_back(removeWhite(string(temp)));

  /*** check for lines with only white space ***/
  if(words.size() < 1)
    return;
  /*
  printf("Control has the words:\n");
  for(int i=0;i<words.size();i++)
    printf("'%s' ",words[i].c_str());
  printf("\n");
  */
  
  try
    {
      string com = words.at(0);

      if(com == "load")
	{
	if(words.size() > 2)
	  load(words.at(1), words.at(2));
	else
	  {
	    char no[6];
	    sprintf(no, "%d", soups.size());	 
	    load(words.at(1), string("AutoSoup") + string(no));
	  }
	}
      else if(com == "loadtosoup")
	{
	  if(words.size() > 3)
	    loadToSoup(atoi(words.at(1).c_str()), words.at(2), words.at(3));
	  else
	    {
	      char no[6];
	      sprintf(no, "%d", soups.size());	 
	      load(words.at(1), string("AutoSoup") + string(no));
	    }
	}
      else if(com == "stat")
	stat();
      else if(com == "list")
	list();
      else if(com == "clear")
	clear();
      else if(com == "task")
	doTask(words);
      else if(com == "script")
	do_script(words);
      else if(com == "exit")
	return;
      else
	printf("Don't understand the command '%s'!\n",words.at(0).c_str());
    }
  catch (...)
    {
      printf("The command %s caused a critical error!\n",line.c_str());
    }


}
Example #9
0
int main() {
	int lineno = 0;
	char buf[MAX_LINE]; // input buffer

	printf("// this code was automatically generated by proccmds.awk\n");
	printf("#include \"librcp.h\"\n");
	printf("#include <sys/types.h>\n");
	printf("#include <sys/stat.h>\n");
	printf("#include <unistd.h>\n");
	printf("\n");
	printf("int module_initialize_commands(CliNode *head) {\n");
	printf("\tCliNode *node;\n");
	printf("\tCliMode mode = CLIMODE_ALL;\n");
	
	while (fgets(buf, MAX_LINE, stdin) != NULL) {
		lineno++;
		
		char *start = buf;
		while (*start == ' ' || *start == '\t' || *start == '\n')
			start++;

		// empty lines
		if (*start == '\0')
			continue;
		
		// comments
		if (*start == '#')
			continue;
		
		// more comments
		char *ptr = strchr(start, '#');
		if (ptr != NULL)
			*ptr = '\0';
		
		// strip end of string
		ptr = start + strlen(start);
		ptr--;
		while (*ptr == ' ' || *ptr == '\t' || *ptr == '\n')
			ptr--;
		ptr++;
		*ptr = '\0';
		
		// dispatch
		if (strncmp(start, "M:", 2) == 0)
			do_mode(start + 2, lineno);
		else if (strncmp(start, "C:", 2) == 0)
			do_command(start + 2, lineno);
		else if (strncmp(start, "Q:", 2) == 0)
			do_question(start + 2, lineno);
		else if (strncmp(start, "H:", 2) == 0)
			do_help(start + 2, lineno);
		else if (strncmp(start, "S:", 2) == 0)
			do_script(start + 2, lineno);
		else {
			printf("Error: invalid line %d - %s\n", lineno, start);
			return 1;
		}
	}

	printf("\n\treturn 0;\n");
	printf("}\n");
	
	return 0;
}