Exemplo n.º 1
0
int		main(void)
{
	t_salle	*h;
	t_init	all;
	char	*ptr;
	t_allp	*all_path;
	t_stap	st;

	if (get_next_line(0, &ptr) <= 0)
		return (0);
	all.nb_f = ((int)ft_strlen(ptr) <= 13) ? ft_atol(ptr) : -1;
	free(ptr);
	if (!(h = init_map(&all)) || all.nb_f <= 0 || all.nb_f >= 2147483648)
		exit_error("Error\n");
	h = reverse_lst(h);
	st.start = find_flag(h, "start");
	st.stop = find_flag(h, "end");
	st.nb_room = salle_len(h);
	all_path = NULL;
	if (!search_all_path(st, &all_path, &h))
		exit_error("Error\n");
	reinit_nb_hall(&all_path);
	verif_bouchon(&all_path);
	tri_path(&all_path);
	affiche(all);
	pass_fourmis(h, all_path, all.nb_f, all.color);
	return (0);
}
Exemplo n.º 2
0
Arquivo: rules.c Projeto: caomw/grass
static void add_rule(struct context *ctx, int type, const char *data)
{
    char **tokens;
    int ntokens;
    void **opts;
    int i;

    tokens = G_tokenize(data, ",");
    ntokens = G_number_of_tokens(tokens);
    opts = G_malloc(ntokens * sizeof(void *));

    for (i = 0; i < ntokens; i++) {
	char buf[256];
	char *name;

	strcpy(buf, tokens[i]);
	name = G_chop(buf);
	opts[i] = (name[0] == '-')
	    ? find_flag(ctx, name[1])
	    : find_option(ctx, name);
    }

    G_free_tokens(tokens);

    G__option_rule(type, ntokens, opts);
}
Exemplo n.º 3
0
bool Globals::bool_value(char* name, bool& value) {
  PRODUCT_CONST JVMFlag* result = find_flag(name);
  if (result == NULL || !result->is_bool()) {
    return false;
  }
  value = result->get_bool();
  return true;
}
Exemplo n.º 4
0
bool Globals::int_value_put(char* name, int value) {
  PRODUCT_CONST JVMFlag* result = find_flag(name);
  if (result == NULL || !result->is_int()) {
    return false;
  }
  result->set_int(value);
  return true;
}
Exemplo n.º 5
0
void flag_set( dbref target, dbref player, char *flag, int key ) {
    FLAGENT *fp;

    int negate, result;

    /*
     * Trim spaces, and handle the negation character
     */

    negate = 0;
    while( *flag && isspace( *flag ) ) {
        flag++;
    }
    if( *flag == '!' ) {
        negate = 1;
        flag++;
    }
    while( *flag && isspace( *flag ) ) {
        flag++;
    }

    /*
     * Make sure a flag name was specified
     */

    if( *flag == '\0' ) {
        if( negate ) {
            notify( player, "You must specify a flag to clear." );
        } else {
            notify( player, "You must specify a flag to set." );
        }
        return;
    }
    fp = find_flag( target, flag );
    if( fp == NULL ) {
        notify( player, "I don't understand that flag." );
        return;
    }
    /*
     * Invoke the flag handler, and print feedback
     */

    result = fp->handler( target, player, fp->flagvalue,
                          fp->flagflag, negate );
    if( !result ) {
        notify( player, NOPERM_MESSAGE );
    } else if( !( key & SET_QUIET ) && !Quiet( player ) ) {
        notify( player, ( negate ? "Cleared." : "Set." ) );
        s_Modified( target );
    }
    return;
}
Exemplo n.º 6
0
int cf_flag_access( int *vp, char *str, long extra, dbref player, char *cmd ) {
    char *fstr, *permstr, *tokst;

    FLAGENT *fp;

    fstr = strtok_r( str, " \t=,", &tokst );
    permstr = strtok_r( NULL, " \t=,", &tokst );

    if( !fstr || !*fstr || !permstr || !*permstr ) {
        return -1;
    }
    if( ( fp = find_flag( GOD, fstr ) ) == NULL ) {
        cf_log_notfound( player, cmd, "No such flag", fstr );
        return -1;
    }
    /*
     * Don't change the handlers on special things.
     */

    if( ( fp->handler != fh_any ) &&
            ( fp->handler != fh_wizroy ) &&
            ( fp->handler != fh_wiz ) &&
            ( fp->handler != fh_god ) &&
            ( fp->handler != fh_restrict_player ) &&
            ( fp->handler != fh_privileged ) ) {

        log_write( LOG_CONFIGMODS, "CFG", "PERM", "Cannot change access for flag: %s", fp->flagname );
        return -1;
    }
    if( !strcmp( permstr, ( char * ) "any" ) ) {
        fp->handler = fh_any;
    } else if( !strcmp( permstr, ( char * ) "royalty" ) ) {
        fp->handler = fh_wizroy;
    } else if( !strcmp( permstr, ( char * ) "wizard" ) ) {
        fp->handler = fh_wiz;
    } else if( !strcmp( permstr, ( char * ) "god" ) ) {
        fp->handler = fh_god;
    } else if( !strcmp( permstr, ( char * ) "restrict_player" ) ) {
        fp->handler = fh_restrict_player;
    } else if( !strcmp( permstr, ( char * ) "privileged" ) ) {
        fp->handler = fh_privileged;
    } else {
        cf_log_notfound( player, cmd, "Flag access", permstr );
        return -1;
    }
    return 0;
}
Exemplo n.º 7
0
int has_flag( dbref player, dbref it, char *flagname ) {
    FLAGENT *fp;

    FLAG fv;

    fp = find_flag( it, flagname );
    if( fp == NULL ) {	/* find_flag() uppercases the string */
        if( !strcmp( flagname, "PLAYER" ) ) {
            return isPlayer( it );
        }
        if( !strcmp( flagname, "THING" ) ) {
            return isThing( it );
        }
        if( !strcmp( flagname, "ROOM" ) ) {
            return isRoom( it );
        }
        if( !strcmp( flagname, "EXIT" ) ) {
            return isExit( it );
        }
        return 0;
    }
    if( fp->flagflag & FLAG_WORD3 ) {
        fv = Flags3( it );
    } else if( fp->flagflag & FLAG_WORD2 ) {
        fv = Flags2( it );
    } else {
        fv = Flags( it );
    }

    if( fv & fp->flagvalue ) {
        if( ( fp->listperm & CA_WIZARD ) && !Wizard( player ) ) {
            return 0;
        }
        if( ( fp->listperm & CA_GOD ) && !God( player ) ) {
            return 0;
        }
        /*
         * don't show CONNECT on dark wizards to mortals
         */
        if( isPlayer( it ) && isConnFlag( fp ) &&
                Can_Hide( it ) && Hidden( it ) && !See_Hidden( player ) ) {
            return 0;
        }
        return 1;
    }
    return 0;
}
Exemplo n.º 8
0
bool Globals::bool_value_put(char* name, bool value) {
  PRODUCT_CONST JVMFlag* result = find_flag(name);
  if (result == NULL) {
    return false;
  } else {
    GUARANTEE(result->is_bool() || result->is_int(), 
              "only int and bool types are allowed");
    if (sizeof(bool) == sizeof(int)) {
      result->set_int((int)value);
    } else if (result->is_bool()) {
      result->set_bool(value);
    } else if (result->is_int()) {
      result->set_int((int)value);
    }
    return true;
  }
}
Exemplo n.º 9
0
bool has_flag(dbref player, dbref it, const UTF8 *flagname)
{
    FLAGNAMEENT *fp = find_flag(flagname);
    if (!fp)
    {
        return false;
    }
    FLAGBITENT *fbe = fp->fbe;

    if (  (  fp->bPositive
          && (db[it].fs.word[fbe->flagflag] & fbe->flagvalue))
       || (  !fp->bPositive
          && (db[it].fs.word[fbe->flagflag] & fbe->flagvalue) == 0))
    {
        if (  (  (fbe->listperm & CA_STAFF)
              && !Staff(player))
           || (  (fbe->listperm & CA_ADMIN)
              && !WizRoy(player))
           || (  (fbe->listperm & CA_WIZARD)
              && !Wizard(player))
           || (  (fbe->listperm & CA_GOD)
              && !God(player)))
        {
            return false;
        }

        // Don't show CONNECT on dark wizards to mortals
        //
        if (  isPlayer(it)
           && (fbe->flagvalue == CONNECTED)
           && (fbe->flagflag == FLAG_WORD2)
           && Hidden(it)
           && !See_Hidden(player))
        {
            return false;
        }
        return true;
    }
    return false;
}
Exemplo n.º 10
0
int
main(int argc, char **argv)
{
	int		opt_s = 0,
			opt_c = 0;
	unsigned int	flags = 0, oflags;
	char *		module = NULL;
	int		c;

	cdename = malloc(strlen(basename(argv[0])));
	if (cdename == NULL) {
	  fprintf(stderr, "failed in malloc\n");
	  exit(1);
        }
	strcpy(cdename, basename(argv[0]));

	if (!strcmp(cdename, "nfsdebug")) {
	  module = "nfs";
	}
	else if (!strcmp(cdename, "nfsddebug")) {
	  module = "nfsd";
	}

	while ((c = getopt(argc, argv, "chm:sv")) != EOF) {
		switch (c) {
		case 'c':
			opt_c = 1;
			break;
		case 'h':
			usage(0, module); /* usage does not return */
			break;
		case 'm':
			module = optarg;
			break;
		case 's':
			opt_s = 1;
			break;
		case 'v':
			verbose++;
			break;
		default:
		        fprintf(stderr, "%s: unknown option -%c\n", cdename, optopt);
			usage(1, module);
		}
	}

	if (opt_c + opt_s > 1) {
		fprintf(stderr, "You can use at most one of -c and -s\n");
		usage(1, module);
	}

	if (!module) {
		fprintf(stderr, "%s: no module name specified.\n", cdename);
		usage(1, module);
	}

	if (strcmp(module, "nfsd") &&
	    strcmp(module, "nfs") &&
	    strcmp(module, "nlm") &&
	    strcmp(module, "rpc")) {
	        fprintf(stderr, "%s: unknown module: %s\n", cdename, module);
		usage(1, module);
	}

	if (argc == optind) {
		flags = ~(unsigned int) 0;
	} else {
		for (; optind < argc; optind++)
			flags |= find_flag(&module, argv[optind]);
		if (flags && !opt_c)
			opt_s = 1;
	}

	oflags = get_flags(module);

	if (opt_c) {
		oflags = set_flags(module, oflags & ~flags);
	} else if (opt_s) {
		oflags = set_flags(module, oflags | flags);
	}
	print_flags(stdout, module, oflags, 0);
	if (verbose) {
	        fprintf(stdout, "\nModule     Valid flags\n");
	        print_flags(stdout, module, ~(unsigned int) 0, 1);
	}

	return 0;
}
Exemplo n.º 11
0
// ---------------------------------------------------------------------------
// flag_set: Set or clear a specified flag on an object.
//
void flag_set(dbref target, dbref player, UTF8 *flag, int key)
{
    bool bDone = false;

    do
    {
        // Trim spaces, and handle the negation character.
        //
        while (mux_isspace(*flag))
        {
            flag++;
        }

        bool bNegate = false;
        if (*flag == '!')
        {
            bNegate = true;
            do
            {
                flag++;
            } while (mux_isspace(*flag));
        }

        // Beginning of flag name is now 'flag'.
        //
        UTF8 *nflag = flag;
        while (  *nflag != '\0'
              && !mux_isspace(*nflag))
        {
            nflag++;
        }

        if (*nflag == '\0')
        {
            bDone = true;
        }
        else
        {
            *nflag = '\0';
        }

        // Make sure a flag name was specified.
        //
        if (*flag == '\0')
        {
            if (bNegate)
            {
                notify(player, T("You must specify a flag to clear."));
            }
            else
            {
                notify(player, T("You must specify a flag to set."));
            }
        }
        else
        {
            FLAGNAMEENT *fp = find_flag(flag);
            if (!fp)
            {
                notify(player, T("I do not understand that flag."));
            }
            else
            {
                FLAGBITENT *fbe = fp->fbe;

                bool bClearSet = bNegate;
                if (!fp->bPositive)
                {
                    bNegate = !bNegate;
                }

                // Invoke the flag handler, and print feedback.
                //
                if (!fbe->handler(target, player, fbe->flagvalue, fbe->flagflag, bNegate))
                {
                    notify(player, NOPERM_MESSAGE);
                }
                else if (!(key & SET_QUIET) && !Quiet(player))
                {
                    notify(player, (bClearSet ? T("Cleared.") : T("Set.")));
                }
            }
        }
        flag = nflag + 1;

    } while (!bDone);
}
Exemplo n.º 12
0
void gazetteer_style_t::process_tags(osmium::OSMObject const &o)
{
    clear();

    char const *postcode = nullptr;
    char const *country = nullptr;
    char const *place = nullptr;
    flag_t place_flag;
    bool address_point = false;
    bool interpolation = false;
    bool admin_boundary = false;
    bool postcode_fallback = false;

    for (auto const &item : o.tags()) {
        char const *k = item.key();
        char const *v = item.value();

        if (strcmp(k, "admin_level") == 0) {
            m_admin_level = atoi(v);
            if (m_admin_level <= 0 || m_admin_level > MAX_ADMINLEVEL)
                m_admin_level = MAX_ADMINLEVEL;
            continue;
        }

        if (m_any_operator_matches && strcmp(k, "operator") == 0) {
            m_operator = v;
        }

        flag_t flag = find_flag(k, v);

        if (flag == 0) {
            continue;
        }

        if (flag & SF_MAIN) {
            if (strcmp(k, "place") == 0) {
                place = v;
                place_flag = flag;
            } else {
                m_main.emplace_back(k, v, flag);
                if ((flag & SF_BOUNDARY) && strcmp(v, "administrative") == 0) {
                    admin_boundary = true;
                }
            }
        }

        if (flag & (SF_NAME | SF_REF)) {
            m_names.emplace_back(k, v);
            if (flag & SF_NAME) {
                m_is_named = true;
            }
        }

        if (flag & SF_ADDRESS) {
            char const *addr_key;
            if (strncmp(k, "addr:", 5) == 0) {
                addr_key = k + 5;
            } else if (strncmp(k, "is_in:", 6) == 0) {
                addr_key = k + 6;
            } else {
                addr_key = k;
            }

            if (strcmp(addr_key, "postcode") == 0) {
                if (!postcode) {
                    postcode = v;
                }
            } else if (strcmp(addr_key, "country") == 0) {
                if (!country && strlen(v) == 2) {
                    country = v;
                }
            } else {
                bool first = std::none_of(
                    m_address.begin(), m_address.end(), [&](ptag_t const &t) {
                        return strcmp(t.first, addr_key) == 0;
                    });
                if (first) {
                    m_address.emplace_back(addr_key, v);
                }
            }
        }

        if (flag & SF_ADDRESS_POINT) {
            address_point = true;
            m_is_named = true;
        }

        if ((flag & SF_POSTCODE) && !postcode) {
            postcode = v;
            if (flag & SF_MAIN_FALLBACK) {
                postcode_fallback = true;
            }
        }

        if ((flag & SF_COUNTRY) && !country && std::strlen(v) == 2) {
            country = v;
        }

        if (flag & SF_EXTRA) {
            m_extra.emplace_back(k, v);
        }

        if (flag & SF_INTERPOLATION) {
            m_main.emplace_back("place", "houses", SF_MAIN);
            interpolation = true;
        }
    }

    if (postcode) {
        m_address.emplace_back("postcode", postcode);
    }
    if (country) {
        m_address.emplace_back("country", country);
    }
    if (place) {
        if (interpolation || (admin_boundary &&
                              strncmp(place, "isl", 3) != 0)) // island or islet
            m_extra.emplace_back("place", place);
        else
            m_main.emplace_back("place", place, place_flag);
    }
    if (address_point) {
        m_main.emplace_back("place", "house", SF_MAIN | SF_MAIN_FALLBACK);
    } else if (postcode_fallback && postcode) {
        m_main.emplace_back("place", "postcode", SF_MAIN | SF_MAIN_FALLBACK);
    }
}