示例#1
0
文件: main.cpp 项目: zh99998/qqbot
static bool same_group(std::string id1, std::string id2)
{
	std::vector< std::string > g1 = find_group(id1);
	if (g1.empty())
		return false;
	return in_group(g1, id2);
}
示例#2
0
void cast_energy_drain( byte level, struct char_data *ch, char *arg, int type,
  struct char_data *victim, struct obj_data *tar_obj )
{
  switch (type) {
    case SPELL_TYPE_SPELL:
			spell_energy_drain(level, ch, victim, 0);
			break;
    case SPELL_TYPE_POTION:
         spell_energy_drain(level, ch, ch, 0);
         break;
    case SPELL_TYPE_SCROLL:
         if(victim)
       		spell_energy_drain(level, ch, victim, 0);
         else if(!tar_obj)
            spell_energy_drain(level, ch, ch, 0);
         break;
    case SPELL_TYPE_WAND:
         if(victim)
       	       	spell_energy_drain(level, ch, victim, 0);
         break;
    case SPELL_TYPE_STAFF:
         for (victim = real_roomp(ch->in_room)->people ;
              victim ; victim = victim->next_in_room )
            if (!in_group(ch,victim))
               if (victim != ch)
                  spell_energy_drain(level, ch, victim, 0);
         break;
    default : 
         log_msg("Serious screw-up in energy drain!");
         break;
	}
}
示例#3
0
void cast_cause_critic(byte level, struct char_data *ch, char *arg, int type,
  struct char_data *victim, struct obj_data *tar_obj )
{
	switch (type) {
    case SPELL_TYPE_SPELL:
         spell_cause_critical(level, ch, victim, 0);
         break;
    case SPELL_TYPE_SCROLL:
	 if (!victim)
	   victim = ch;
	 spell_cause_critical(level,ch,victim,0);
	 break;
    case SPELL_TYPE_WAND:
       	 if (!victim) victim = ch;
	 spell_cause_critical(level,ch,victim,0);
	 break;
    case SPELL_TYPE_POTION:
       	 if (!victim) victim = ch;
         spell_cause_critical(level, ch, victim, 0);
         break;
    case SPELL_TYPE_STAFF:
         for (victim = real_roomp(ch->in_room)->people ;
              victim ; victim = victim->next_in_room )
            if (!in_group(ch,victim))
               spell_cause_critical(level, ch, victim, 0);
         break;
    default : 
         log_msg("Serious screw-up in cause critical!");
         break;

  }
}
示例#4
0
文件: spells1.c 项目: frasten/openleu
void cast_cause_serious( byte level, struct char_data *ch, const char *arg, int type,
                         struct char_data *victim, struct obj_data *tar_obj )
{
  switch (type) 
  {
  case SPELL_TYPE_SPELL:
    spell_cause_serious(level, ch, victim, 0);
    break;
  case SPELL_TYPE_POTION:
    spell_cause_serious(level, ch, ch, 0);
    break;
  case SPELL_TYPE_WAND:
    if (tar_obj) return;
      if (!victim) victim = ch;
        spell_cause_serious(level, ch, victim, 0);
    break;
  case SPELL_TYPE_STAFF:
    for( victim = real_roomp(ch->in_room)->people ;
         victim ; victim = victim->next_in_room )
      if (!in_group(ch,victim))
        spell_cause_serious(level, ch, victim, 0);
    break;
  default : 
    mudlog( LOG_SYSERR, "Serious screw-up in cause serious wounds!");
    break;
  }
}
示例#5
0
文件: main.cpp 项目: zh99998/qqbot
/*
 * 查找同组的其他聊天室和qq群.
 */
static std::vector<std::string> & find_group(std::string id)
{
	static std::vector<std::string> empty;
	BOOST_FOREACH(std::vector<std::string> & g ,  channelgroups)
	{
		if (in_group(g, id))
			return g;
	}
	return empty;
}
示例#6
0
int
is_executable(struct stat *sb)
{
    if (g_uid == 0)
        return 1;
    if (sb->st_mode & S_IXOTH)
        return 1;
    if ((sb->st_mode & S_IXUSR) && sb->st_uid == g_uid)
        return 1;
    if ((sb->st_mode & S_IXGRP) && in_group(sb->st_gid))
        return 1;
    return 0;
}
示例#7
0
int
is_readable(struct stat *sb)
{
    /* although root can read from anything, it doesn't help us to show that here.
    if (g_uid == 0)
        return 1;
     */
    if (sb->st_mode & S_IROTH)
        return 1;
    if ((sb->st_mode & S_IRUSR) && sb->st_uid == g_uid)
        return 1;
    if ((sb->st_mode & S_IRGRP) && in_group(sb->st_gid))
        return 1;
    return 0;
}
示例#8
0
int
is_writable(struct stat *sb)
{
    /* although root can write to anything, it doesn't help us to show that here.
    if (g_uid == 0)
        return 1;
     */
    if (sb->st_mode & S_IWOTH)
        return 1;
    if ((sb->st_mode & S_IWUSR) && sb->st_uid == g_uid)
        return 1;
    if ((sb->st_mode & S_IWGRP) && in_group(sb->st_gid))
        return 1;
    return 0;
}
示例#9
0
文件: spells1.c 项目: frasten/openleu
void cast_call_lightning( byte level, struct char_data *ch, const char *arg, int type,
                          struct char_data *victim, struct obj_data *tar_obj )
{
  extern struct weather_data weather_info;

  switch (type) 
  {
  case SPELL_TYPE_SPELL:
    if( OUTSIDE( ch ) && weather_info.sky >= SKY_RAINING )
    {
      spell_call_lightning(level, ch, victim, 0);
    } 
    else 
    {
      send_to_char( "You fail to call upon the lightning from the sky!\n\r", 
                    ch);
    }
    break;
  case SPELL_TYPE_POTION:
    if (OUTSIDE(ch) && (weather_info.sky>=SKY_RAINING)) 
    {
      spell_call_lightning(level, ch, ch, 0);
    }
    break;
  case SPELL_TYPE_SCROLL:
    if (OUTSIDE(ch) && (weather_info.sky>=SKY_RAINING)) 
    {
      if(victim) 
        spell_call_lightning(level, ch, victim, 0);
      else if(!tar_obj) 
        spell_call_lightning(level, ch, ch, 0);
    }
    break;
  case SPELL_TYPE_STAFF:
    if (OUTSIDE(ch) && (weather_info.sky>=SKY_RAINING)) 
    {
      for( victim = real_roomp(ch->in_room)->people ;
           victim ; victim = victim->next_in_room )
        if (!in_group(victim,ch))
          spell_call_lightning(level, ch, victim, 0);
    }
    break;
  default : 
    mudlog( LOG_SYSERR, "Serious screw-up in call lightning!");
    break;
  }
}
示例#10
0
static int condition_test_group(Condition *c) {
        gid_t id;
        int r;

        assert(c);
        assert(c->parameter);
        assert(c->type == CONDITION_GROUP);

        r = parse_gid(c->parameter, &id);
        if (r >= 0)
                return in_gid(id);

        /* Avoid any NSS lookups if we are PID1 */
        if (getpid_cached() == 1)
                return streq(c->parameter, "root");

        return in_group(c->parameter) > 0;
}
示例#11
0
文件: perms.c 项目: ardeujho/3-move
PUBLIC int in_group(OBJECT what, VECTOR group) {
  int i;

  if (group == NULL)
    return 0;

  for (i = 0; i < group->_.length; i++) {
    OBJ x = AT(group, i);

    if (x == (OBJ) what)
      return 1;

    if (VECTORP(x))
      if (in_group(what, (VECTOR) x))
	return 1;
  }

  return 0;
}
示例#12
0
文件: dosmode.c 项目: AllardJ/Tomato
/*******************************************************************
Wrapper around dos_utime that possibly allows DOS semantics rather
than POSIX.
*******************************************************************/
int file_utime(connection_struct *conn, char *fname, struct utimbuf *times)
{
  extern struct current_user current_user;
  SMB_STRUCT_STAT sb;
  int ret = -1;

  errno = 0;

  if(dos_utime(fname, times) == 0)
    return 0;

  if((errno != EPERM) && (errno != EACCES))
    return -1;

  if(!lp_dos_filetimes(SNUM(conn)))
    return -1;

  /* We have permission (given by the Samba admin) to
     break POSIX semantics and allow a user to change
     the time on a file they don't own but can write to
     (as DOS does).
   */

  if(dos_stat(fname,&sb) != 0)
    return -1;

  /* Check if we have write access. */
  if (CAN_WRITE(conn)) {
	  if (((sb.st_mode & S_IWOTH) ||
	       conn->admin_user ||
	       ((sb.st_mode & S_IWUSR) && current_user.uid==sb.st_uid) ||
	       ((sb.st_mode & S_IWGRP) &&
		in_group(sb.st_gid,current_user.gid,
			 current_user.ngroups,current_user.groups)))) {
		  /* We are allowed to become root and change the filetime. */
		  become_root(False);
		  ret = dos_utime(fname, times);
		  unbecome_root(False);
	  }
  }

  return ret;
}
示例#13
0
void cast_harm( byte level, struct char_data *ch, char *arg, int type,
  struct char_data *victim, struct obj_data *tar_obj )
{
	switch (type) {
    case SPELL_TYPE_SPELL:
         spell_harm(level, ch, victim, 0);
         break;
    case SPELL_TYPE_POTION:
         spell_harm(level, ch, ch, 0);
         break;
    case SPELL_TYPE_STAFF:
         for (victim = real_roomp(ch->in_room)->people ;
              victim ; victim = victim->next_in_room )
            if (!in_group(ch,victim))
               spell_harm(level, ch, victim, 0);
         break;
    default : 
         log_msg("Serious screw-up in harm!");
         break;

  }
}
示例#14
0
文件: bedup.c 项目: tcheneau/burp
static int iterate_over_clients(struct config *conf, strlist_t **grouplist, int gcount, const char *ext, unsigned int maxlinks)
{
	int ret=0;
	DIR *dirp=NULL;
	struct dirent *dirinfo=NULL;

	signal(SIGABRT, &sighandler);
	signal(SIGTERM, &sighandler);
	signal(SIGINT, &sighandler);

	if(!(dirp=opendir(conf->clientconfdir)))
	{
		logp("Could not opendir '%s': %s\n",
			conf->clientconfdir, strerror(errno));
		return 0;
	}
	while((dirinfo=readdir(dirp)))
	{
		char *lockfile=NULL;
		char *lockfilebase=NULL;
		if(!strcmp(dirinfo->d_name, ".")
		  || !strcmp(dirinfo->d_name, "..")
		  || looks_like_vim_tmpfile(dirinfo->d_name)
		  || !is_regular_file(conf->clientconfdir, dirinfo->d_name))
			continue;

		if(gcount)
		{
			int ig=0;
			if((ig=in_group(conf->clientconfdir,
				dirinfo->d_name, grouplist, gcount, conf))<0)
			{
				ret=-1;
				break;
			}
			if(!ig) continue;
		}

		if(!(lockfilebase=prepend(conf->client_lockdir,
			dirinfo->d_name, "/"))
		 || !(lockfile=prepend(lockfilebase,
			BEDUP_LOCKFILE_NAME, "/")))
		{
			if(lockfilebase) free(lockfilebase);
			if(lockfile) free(lockfile);
			ret=-1;
			break;
		}
		free(lockfilebase);

		if(get_lock(lockfile))
		{
			logp("Could not get %s\n", lockfile);
			free(lockfile);
			continue;
		}

		// Remember that we got that lock.
		if(strlist_add(&locklist, &lockcount, lockfile, 1))
		{
			free(lockfile);
			lockcount=0;
			break;
		}

		logp("Got %s\n", lockfile);

		if(process_dir(conf->directory, dirinfo->d_name,
			ext, maxlinks, 1 /* burp mode */, 0 /* level */))
		{
			ret=-1;
			break;
		}

		ccount++;
	}
	closedir(dirp);

	remove_locks();

	return ret;
}
示例#15
0
/*
 * NOTE: the "groups" string will be modified in place by strtok()
 */
void
obtain_user_info(const char *user, const char *groups)
{
    struct passwd *pw;
    int i;
    uid_t uid = -1;

    /* no user specified? use the current uid. */
    if (!user) {
        uid = getuid();
        pw = getpwuid(uid);
    }
    else {
        /* try to resolve the pw struct from the user string */
        pw = getpwnam(user);

        /* if it fails, try to treat it as a number */
        if (!pw) {
            char *endptr = (char *)user;

            /* try by id as well */
            uid = strtol(user, &endptr, 0);
            if (uid == ULONG_MAX || *endptr != '\0') {
                fprintf(stderr, "[!] Invalid user id: %s!\n", user);
                exit(1);
            }

            pw = getpwuid(uid);
        }
    }
    if (!pw) {
        fprintf(stderr, "[!] Unable to find uid %lu, trying anyway...\n", (unsigned long)uid);
        g_uid = uid;
        g_ngroups = 0;
    }
    else
        g_uid = pw->pw_uid;

    /* find out what groups the current or specified user is in */
    if (!user) {
        int num = getgroups(0, g_groups);
        if (num > g_ngroups) {
            fprintf(stderr, "[!] Too many groups!\n");
            exit(1);
        }
        if ((g_ngroups = getgroups(g_ngroups, g_groups)) == -1) {
            perror("[!] Unable to getgroups");
            exit(1);
        }

        /* make sure our gid is in the groups */
        if (!in_group(pw->pw_gid))
            add_group(pw->pw_gid);
    }
    else if (pw) {
        /* since we are passing the max, we shouldn't have an issue with failed return */
        getgrouplist(pw->pw_name, pw->pw_gid, g_groups, &g_ngroups);
    }
    /* else we have no way of knowing, the user doesn't exist =) */

    /* append any extra groups */
    if (groups) {
        char *grnam = strtok((char *)groups, ",");

        while (grnam) {
            struct group *pg = getgrnam(grnam);
            gid_t gid;

            if (!pg) {
                char *endptr = grnam;

                gid = strtoul(grnam, &endptr, 0);
                /* a bad number indicates a probably mistake */
                if (gid == ULONG_MAX || *endptr != '\0') {
                    fprintf(stderr, "[!] Unknown/invalid group: %s\n", grnam);
                    exit(1);
                }

                /* try again */
                pg = getgrgid(gid);
            }

            if (!pg) {
                /* this is just a warning, add the number and keep processing others */
                fprintf(stderr, "[!] Unable to find gid %s, trying anyway...\n", grnam);
                if (!in_group(gid))
                    add_group(gid);
            }
            else if (!in_group(pg->gr_gid))
                add_group(pg->gr_gid);

            /* process the next group name. */
            grnam = strtok(NULL, ",");
        }
    }

    /* print what we found :) */
    if (pw)
        printf("[*] uid=%u(%s), groups=", pw->pw_uid, pw->pw_name);
    else
        printf("[*] uid=%u(?), groups=", g_uid);

    for (i = 0; i < g_ngroups; i++) {
        struct group *pg = getgrgid(g_groups[i]);

        if (pg)
            printf("%u(%s)", pg->gr_gid, pg->gr_name);
        else
            printf("%u(?)", g_groups[i]);
        if (i != g_ngroups - 1)
            printf(",");
    }
    printf("\n");
}
示例#16
0
 void on_setup(Executor& exec) const
 {
     //I can only enable this if the current process supports breakaways.
     if (in_group() && break_away_enabled(nullptr))
         exec.creation_flags  |= boost::detail::winapi::CREATE_BREAKAWAY_FROM_JOB_;
 }
示例#17
0
文件: bedup.c 项目: kaptk2/burp
static int iterate_over_clients(struct conf **globalcs,
	struct strlist *grouplist, const char *ext, unsigned int maxlinks)
{
	int ret=0;
	DIR *dirp=NULL;
	struct conf **cconfs=NULL;
	struct dirent *dirinfo=NULL;
	const char *globalclientconfdir=get_string(globalcs[OPT_CLIENTCONFDIR]);

	signal(SIGABRT, &sighandler);
	signal(SIGTERM, &sighandler);
	signal(SIGINT, &sighandler);

	if(!(cconfs=confs_alloc())) return -1;
	if(confs_init(cconfs)) return -1;

	if(!(dirp=opendir(globalclientconfdir)))
	{
		logp("Could not opendir '%s': %s\n",
			globalclientconfdir, strerror(errno));
		return 0;
	}
	while((dirinfo=readdir(dirp)))
	{
		char *lockfile=NULL;
		char *lockfilebase=NULL;
		char *client_lockdir=NULL;
		struct lock *lock=NULL;

		if(dirinfo->d_ino==0
		// looks_like...() also avoids '.' and '..'.
		  || looks_like_tmp_or_hidden_file(dirinfo->d_name)
		  || !is_regular_file(globalclientconfdir, dirinfo->d_name))
			continue;

		confs_free_content(cconfs);
		if(confs_init(cconfs)) return -1;

		if(set_string(cconfs[OPT_CNAME], dirinfo->d_name))
			return -1;

		if(conf_load_clientconfdir(globalcs, cconfs))
		{
			logp("could not load config for client %s\n",
				dirinfo->d_name);
			return 0;
		}

		if(grouplist)
		{
			const char *dedup_group=
				get_string(cconfs[OPT_DEDUP_GROUP]);
			if(!dedup_group
			  || !in_group(grouplist, dedup_group))
				continue;
		}

		if(!(client_lockdir=get_string(cconfs[OPT_CLIENT_LOCKDIR])))
			client_lockdir=get_string(cconfs[OPT_DIRECTORY]);

		if(!(lockfilebase=prepend(client_lockdir,
			dirinfo->d_name, "/"))
		 || !(lockfile=prepend(lockfilebase,
			BEDUP_LOCKFILE_NAME, "/")))
		{
			free_w(&lockfilebase);
			free_w(&lockfile);
			ret=-1;
			break;
		}
		free_w(&lockfilebase);

		if(!(lock=lock_alloc_and_init(lockfile)))
		{
			ret=-1;
			break;
		}
		lock_get(lock);
		free_w(&lockfile);

		if(lock->status!=GET_LOCK_GOT)
		{
			logp("Could not get %s\n", lock->path);
			continue;
		}
		logp("Got %s\n", lock->path);

		// Remember that we got that lock.
		lock_add_to_list(&locklist, lock);

		if(process_dir(get_string(cconfs[OPT_DIRECTORY]),
			dirinfo->d_name,
			ext, maxlinks, 1 /* burp mode */, 0 /* level */))
		{
			ret=-1;
			break;
		}

		ccount++;
	}
	closedir(dirp);

	locks_release_and_free(&locklist);

	confs_free(&cconfs);

	return ret;
}
示例#18
0
    void visit(verbly::token& it)
    {
      switch (it.get_type())
      {
        case verbly::token::type::utterance:
        {
          for (auto& tkn : it)
          {
            if (!tkn.is_complete())
            {
              visit(tkn);
              
              break;
            }
          }
          
          break;
        }
        
        case verbly::token::type::fillin:
        {
          switch (it.get_fillin_type())
          {
            case verbly::token::fillin_type::participle_phrase:
            { 
              for (;;)
              {
                verbly::verb v = database.verbs().has_frames().random().limit(1).run().front();
                auto frames = v.frames().run();
                std::vector<verbly::frame> filtered;
                std::remove_copy_if(std::begin(frames), std::end(frames), std::back_inserter(filtered), [] (verbly::frame& f) {
                  if (f.parts().size() < 2)
                  {
                    return true;
                  }
                
                  if (f.parts()[0].get_type() != verbly::frame::part::type::noun_phrase)
                  {
                    return true;
                  }
                
                  if (f.parts()[0].get_role() != "Agent")
                  {
                    return true;
                  }
                
                  if (f.parts()[1].get_type() != verbly::frame::part::type::verb)
                  {
                    return true;
                  }
                
                  return false;
                });
                
                if (filtered.empty())
                {
                  continue;
                }
                
                verbly::frame fr = filtered[rand() % filtered.size()];
                verbly::token utter;
                for (auto part : fr.parts())
                {
                  switch (part.get_type())
                  {
                    case verbly::frame::part::type::noun_phrase:
                    {
                      if (part.get_role() == "Agent")
                      {
                        continue;
                      }
                      
                      if (part.get_synrestrs().count("adjp") == 1)
                      {
                        utter << verbly::token{verbly::token::fillin_type::adjective_phrase};
                        
                        continue;
                      } else if ((part.get_synrestrs().count("be_sc_ing") == 1)
                        || (part.get_synrestrs().count("ac_ing") == 1)
                        || (part.get_synrestrs().count("sc_ing") == 1)
                        || (part.get_synrestrs().count("np_omit_ing") == 1)
                        || (part.get_synrestrs().count("oc_ing") == 1))
                      {
                        utter << verbly::token{verbly::token::fillin_type::participle_phrase};
                        
                        continue;
                      } else if ((part.get_synrestrs().count("poss_ing") == 1)
                        || (part.get_synrestrs().count("possing") == 1)
                        || (part.get_synrestrs().count("pos_ing") == 1))
                      {
                        utter << verbly::token{"their"};
                        utter << verbly::token{verbly::token::fillin_type::participle_phrase};
                        
                        continue;
                      } else if (part.get_synrestrs().count("genitive") == 1)
                      {
                        utter << verbly::token{"their"};
                        
                        continue;
                      } else if (part.get_synrestrs().count("adv_loc") == 1)
                      {
                        if (rand() % 2 == 0)
                        {
                          utter << verbly::token{"here"};
                        } else {
                          utter << verbly::token{"there"};
                        }
                        
                        continue;
                      } else if (part.get_synrestrs().count("refl") == 1)
                      {
                        utter << verbly::token{"themselves"};
                        
                        continue;
                      } else if ((part.get_synrestrs().count("sc_to_inf") == 1)
                        || (part.get_synrestrs().count("ac_to_inf") == 1)
                        || (part.get_synrestrs().count("vc_to_inf") == 1)
                        || (part.get_synrestrs().count("rs_to_inf") == 1)
                        || (part.get_synrestrs().count("oc_to_inf") == 1))
                      {
                        utter << verbly::token{verbly::token::fillin_type::infinitive_phrase};
                        
                        continue;
                      } else if (part.get_synrestrs().count("oc_bare_inf") == 1)
                      {
                        verbly::token tkn{verbly::token::fillin_type::infinitive_phrase};
                        tkn.set_extra(1);
                        
                        utter << tkn;
                        
                        continue;
                      }
                      
                      auto selrestrs = fr.roles()[part.get_role()];
                      auto query = database.nouns().limit(1).random().is_not_proper().full_hyponym_of(parse_selrestrs(selrestrs));
                      verbly::noun n = query.run().front();
                      if ((rand() % 2 == 0) && (part.get_synrestrs().count("definite") == 0))
                      {
                        utter << verbly::token{"the"};
                      } else {
                        if (n.starts_with_vowel_sound())
                        {
                          utter << verbly::token{"an"};
                        } else {
                          utter << verbly::token{"a"};
                        }
                      }
                      
                      if (part.get_synrestrs().count("plural") == 1)
                      {
                        utter << verbly::token{n, verbly::token::noun_inflection::plural};
                      } else {
                        utter << verbly::token{n};
                      }
                      
                      if (part.get_synrestrs().count("acc_ing") == 1)
                      {
                        utter << verbly::token{verbly::token::fillin_type::participle_phrase};
                      }
                    
                      break;
                    }
                  
                    case verbly::frame::part::type::verb:
                    {
                      utter << verbly::token{v, verbly::token::verb_inflection::ing_form};
                    
                      break;
                    }
                  
                    case verbly::frame::part::type::literal_preposition:
                    {
                      utter << verbly::token{part.get_choices()[rand() % part.get_choices().size()]};
                    
                      break;
                    }
                    
                    case verbly::frame::part::type::selection_preposition:
                    {
                      auto query = database.prepositions();
                      for (auto preprestr : part.get_preprestrs())
                      {
                        query.in_group(preprestr);
                      }
                      utter << verbly::token{query.random().limit(1).run().front()};
                      
                      break;
                    }
                  
                    case verbly::frame::part::type::adjective:
                    {
                      utter << verbly::token{verbly::token::fillin_type::adjective_phrase};
                    
                      break;
                    }
                  
                    case verbly::frame::part::type::adverb:
                    {
                      utter << verbly::token{verbly::token::fillin_type::adverb_phrase};
                    
                      break;
                    }
                  
                    case verbly::frame::part::type::literal:
                    {
                      utter << verbly::token{part.get_literal()};
                    
                      break;
                    }
                  }
                }
              
                it = utter;
  
                break;
              }
              
              break;
            }
            
            case verbly::token::fillin_type::adjective_phrase:
            {
              verbly::token phrase;
              
              if (rand() % 4 == 0)
              {
                phrase << verbly::token{verbly::token::fillin_type::adverb_phrase};
              }
              
              if (rand() % 2 == 0)
              {
                phrase << verbly::token{verbly::token::fillin_type::participle_phrase};
              } else {
                phrase << verbly::token{database.adjectives().random().limit(1).run().front()};
              }
              
              it = phrase;
              
              break;
            }
            
            case verbly::token::fillin_type::adverb_phrase:
            {
              it = verbly::token{database.adverbs().random().limit(1).run().front()};
              
              break;
            }
            
            case verbly::token::fillin_type::infinitive_phrase:
            {
              verbly::token utter;
              if (it.get_extra() != 1)
              {
                utter << verbly::token{"to"};
              }
              
              utter << verbly::token{database.verbs().random().limit(1).run().front()};
              
              it = utter;
              
              break;
            }

            default:
            {
              it = verbly::token{"*the reality of the situation*"};
  
              break;
            }
          }
          
          break;
        }
      }
    }
示例#19
0
文件: journalctl.c 项目: adsr/systemd
int main(int argc, char *argv[]) {
        int r;
        sd_journal *j = NULL;
        unsigned line = 0;
        bool need_seek = false;
        sd_id128_t previous_boot_id;
        bool previous_boot_id_valid = false;
        bool have_pager;

        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r <= 0)
                goto finish;

        if (arg_new_id128) {
                r = generate_new_id128();
                goto finish;
        }

#ifdef HAVE_ACL
        if (!arg_quiet && geteuid() != 0 && in_group("adm") <= 0)
                log_warning("Showing user generated messages only. Users in the group 'adm' can see all messages. Pass -q to turn this message off.");
#endif

        if (arg_directory)
                r = sd_journal_open_directory(&j, arg_directory, 0);
        else
                r = sd_journal_open(&j, arg_local ? SD_JOURNAL_LOCAL_ONLY : 0);

        if (r < 0) {
                log_error("Failed to open journal: %s", strerror(-r));
                goto finish;
        }

        if (arg_print_header) {
                journal_print_header(j);
                r = 0;
                goto finish;
        }

        r = add_this_boot(j);
        if (r < 0)
                goto finish;

        r = add_matches(j, argv + optind);
        if (r < 0)
                goto finish;

        if (!arg_quiet) {
                usec_t start, end;
                char start_buf[FORMAT_TIMESTAMP_MAX], end_buf[FORMAT_TIMESTAMP_MAX];

                r = sd_journal_get_cutoff_realtime_usec(j, &start, &end);
                if (r < 0) {
                        log_error("Failed to get cutoff: %s", strerror(-r));
                        goto finish;
                }

                if (r > 0) {
                        if (arg_follow)
                                printf("Logs begin at %s.\n", format_timestamp(start_buf, sizeof(start_buf), start));
                        else
                                printf("Logs begin at %s, end at %s.\n",
                                       format_timestamp(start_buf, sizeof(start_buf), start),
                                       format_timestamp(end_buf, sizeof(end_buf), end));
                }
        }

        if (arg_lines >= 0) {
                r = sd_journal_seek_tail(j);
                if (r < 0) {
                        log_error("Failed to seek to tail: %s", strerror(-r));
                        goto finish;
                }

                r = sd_journal_previous_skip(j, arg_lines);
        } else {
                r = sd_journal_seek_head(j);
                if (r < 0) {
                        log_error("Failed to seek to head: %s", strerror(-r));
                        goto finish;
                }

                r = sd_journal_next(j);
        }

        if (r < 0) {
                log_error("Failed to iterate through journal: %s", strerror(-r));
                goto finish;
        }

        have_pager = !arg_no_pager && !arg_follow;
        if (have_pager) {
                columns();
                pager_open();
        }

        if (arg_output == OUTPUT_JSON) {
                fputc('[', stdout);
                fflush(stdout);
        }

        for (;;) {
                for (;;) {
                        sd_id128_t boot_id;
                        int flags = (arg_show_all*OUTPUT_SHOW_ALL |
                                     have_pager*OUTPUT_FULL_WIDTH);

                        if (need_seek) {
                                r = sd_journal_next(j);
                                if (r < 0) {
                                        log_error("Failed to iterate through journal: %s", strerror(-r));
                                        goto finish;
                                }
                        }

                        if (r == 0)
                                break;

                        r = sd_journal_get_monotonic_usec(j, NULL, &boot_id);
                        if (r >= 0) {
                                if (previous_boot_id_valid &&
                                    !sd_id128_equal(boot_id, previous_boot_id))
                                        printf(ANSI_HIGHLIGHT_ON "----- Reboot -----" ANSI_HIGHLIGHT_OFF "\n");

                                previous_boot_id = boot_id;
                                previous_boot_id_valid = true;
                        }

                        line ++;

                        r = output_journal(j, arg_output, line, 0, flags);
                        if (r < 0)
                                goto finish;

                        need_seek = true;
                }

                if (!arg_follow)
                        break;

                r = sd_journal_wait(j, (uint64_t) -1);
                if (r < 0) {
                        log_error("Couldn't wait for log event: %s", strerror(-r));
                        goto finish;
                }
        }

        if (arg_output == OUTPUT_JSON)
                fputs("\n]\n", stdout);

finish:
        if (j)
                sd_journal_close(j);

        pager_close();

        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}