Exemplo n.º 1
0
void print_header(string tag, string type, int *dims)
{
    char buf[BUFLEN];  /* danger: buffer overflow */
    int *dp;
    
    if (xml)
      sprintf(buf,"<%s type=\"%s\" ",tag,find_name(type));
    else
      sprintf(buf, "%s %s", find_name(type), tag);
    (void) outstr(buf);
    if (dims != NULL) {				/* is this a plural item?   */
      if (xml) {
	sprintf(buf,"dim=\"");
        outstr(buf);
      }
      for (dp = dims; *dp != 0; dp++) {	/*   loop over dimensions   */
	sprintf(buf, "[%d]", *dp);		/*     format a dimension   */
	(void) outstr(buf);                 /*     and print it out     */
      }
      if (xml) {
	sprintf(buf,"\"");
        outstr(buf);
      }
    }
    if (xml) {
      sprintf(buf,">");
      outstr(buf);
    }
    
}
Exemplo n.º 2
0
int find_name(char *pchName,stack_t *pResult) {
	int iRC = EXIT_FAILURE;
	if (0 == pchName[0]) {
		return (EXIT_SUCCESS);
	}
	if ( exists1(pchName[0]) ) {
		push(pResult,pchName[0]);
		iRC = find_name(((char *)&pchName[1]),pResult);	
	} 
	// Edge case, it could find something with one char which
	// is a dead end, so we have to try to double chars
	// so continue on. However, if it finds one and it is the 
	// last char we stop.
	if (iRC == EXIT_SUCCESS && (0 == pchName[1])) {
		return iRC;
	}
	// Edge case, if we don't have two chars left, we must
	// stop looking.
	if (0 == pchName[1]) {
		pop(pResult);	// Toss the last success
		return EXIT_FAILURE;
	}
	if (exists2(pchName[0],pchName[1] )) {
		push(pResult,pchName[0]);
		push(pResult,pchName[1]+32);
		iRC = find_name(((char *)&pchName[2]),pResult);	
	}
	return iRC;
}
Exemplo n.º 3
0
static session *
find_session_from_nick (char *nick, server *serv)
{
	session *sess;
	GSList *list = sess_list;

	sess = find_dialog (serv, nick);
	if (sess)
		return sess;

	if (serv->front_session)
	{
		if (find_name (serv->front_session, nick))
			return serv->front_session;
	}

	if (current_sess && current_sess->server == serv)
	{
		if (find_name (current_sess, nick))
			return current_sess;
	}

	while (list)
	{
		sess = list->data;
		if (sess->server == serv)
		{
			if (find_name (sess, nick))
				return sess;
		}
		list = list->next;
	}
	return 0;
}
Exemplo n.º 4
0
static void
do_list(int all, u_int32_t type, char *name)
{
	rndstat_t rstat;
	rndstat_name_t rstat_name;
	int fd;
	int res;
	uint32_t i;
	u_int32_t start;

	fd = open(_PATH_URANDOM, O_RDONLY, 0644);
	if (fd < 0)
		err(1, "open");

	if (all == 0 && type == 0xff) {
		strncpy(rstat_name.name, name, sizeof(rstat_name.name));
		res = ioctl(fd, RNDGETSRCNAME, &rstat_name);
		if (res < 0)
			err(1, "ioctl(RNDGETSRCNAME)");
		printf(HEADER);
		printf("%-16s %10u %-4s %s\n",
		    rstat_name.source.name,
		    rstat_name.source.total,
		    find_name(rstat_name.source.type),
		    strflags(rstat_name.source.flags));
		close(fd);
		return;
	}

	/*
	 * Run through all the devices present in the system, and either
	 * print out ones that match, or print out all of them.
	 */
	printf(HEADER);
	start = 0;
	for (;;) {
		rstat.count = RND_MAXSTATCOUNT;
		rstat.start = start;
		res = ioctl(fd, RNDGETSRCNUM, &rstat);
		if (res < 0)
			err(1, "ioctl(RNDGETSRCNUM)");

		if (rstat.count == 0)
			break;

		for (i = 0; i < rstat.count; i++) {
			if (all != 0 ||
			    type == rstat.source[i].type)
				printf("%-16s %10u %-4s %s\n",
				    rstat.source[i].name,
				    rstat.source[i].total,
				    find_name(rstat.source[i].type),
				    strflags(rstat.source[i].flags));
		}
		start += rstat.count;
	}

	close(fd);
}
Exemplo n.º 5
0
/* match_this_proc() - find each instance of processor name "name" in 
 *                     the "procnames" array, starting with index "cur_proc"
 *                     and add the first "max_matches" into the "ranks"
 *                     array.  remove all instances of "name" from
 *                     "procnames".
 *
 * Parameters:
 * name - processor name to match
 * cur_proc - index into procnames[] at which to start matching
 * procnames - array of processor names
 * used_procnames - array of values indicating if a given procname has
 *                  been allocated or removed already
 * nr_procnames - length of procnames array
 * ranks - array of processor ranks
 * nr_ranks - length of ranks array
 * nr_ranks_allocated - number of ranks already filled in, or the next
 *                      entry to fill in (equivalent)
 *
 * Returns number of ranks filled in (allocated).
 */
static int match_this_proc(char *name,
			   int cur_proc,
			   int max_matches,
			   char *procnames[],
			   char used_procnames[],
			   int nr_procnames, 
			   int ranks[], 
			   int nr_ranks,
			   int nr_ranks_allocated)
{
    int ranks_remaining, nr_to_alloc, old_nr_allocated;

    old_nr_allocated = nr_ranks_allocated;

    /* calculate how many ranks we want to allocate */
    ranks_remaining = nr_ranks - nr_ranks_allocated;
    nr_to_alloc = (max_matches < ranks_remaining) ? 
	max_matches : ranks_remaining;

    while (nr_to_alloc > 0) {
	cur_proc = find_name(name, procnames, used_procnames, nr_procnames, 
			     cur_proc);
	if (cur_proc < 0) {
	    /* didn't find it */
	    return nr_ranks_allocated - old_nr_allocated;
	}

	/* need bounds checking on ranks */
#ifdef CB_CONFIG_LIST_DEBUG
	FPRINTF(stderr, "  assigning name %s (%d) to rank %d in mapping\n",
	       procnames[cur_proc], cur_proc, nr_ranks_allocated);
#endif

	ranks[nr_ranks_allocated] = cur_proc;
	nr_ranks_allocated++;
	used_procnames[cur_proc] = 1;
	    
	cur_proc++;
	nr_to_alloc--;
    }
	
    /* take all other instances of this host out of the list */
    while (cur_proc >= 0) {
	cur_proc = find_name(name, procnames, used_procnames, nr_procnames, 
		             cur_proc);
	if (cur_proc >= 0) {
#ifdef CB_CONFIG_LIST_DEBUG
	    FPRINTF(stderr, "  taking name %s (%d) out of procnames\n",
		   procnames[cur_proc], cur_proc);
#endif
	    used_procnames[cur_proc] = 1;
	    cur_proc++;
	}
    }
    return nr_ranks_allocated - old_nr_allocated;
}
Exemplo n.º 6
0
void find_name()
{
    Block block;
    block.compile("a = 1");
    block.compile("namespace ns { a = 2; b = 3; } ");

    test_equals(term_value(find_name(&block, "a")), "1");
    test_equals(term_value(find_name(&block, "ns:a")), "2");
    test_equals(term_value(find_name(&block, "ns:b")), "3");
}
Exemplo n.º 7
0
// CGeneralCRC message handlers
void CGeneralCRC::OnChangeName()
{
	CString strName;
	GetDlgItemText(IDC_CRC_NAME, strName);
	GetDlgItem(IDC_CRC_SAVE)->EnableWindow(!strName.IsEmpty() && find_name(strName) == -1);

	// Disable deletion since name changed (unless name change was caused by OnSelect)
	if (last_selected_ != find_name(strName))
		last_selected_ = -1;
	GetDlgItem(IDC_CRC_DELETE)->EnableWindow(last_selected_ >= last_predefined_);
}
Exemplo n.º 8
0
void non_required_module_is_not_visible()
{
    World* world = global_world();

    test_write_fake_file("module_a.ca", 1, "a = 1");
    test_write_fake_file("module_b.ca", 1, "b = 1");
    Block* module_a = load_module_file(world, temp_string("module_a"), "module_a.ca");
    Block* module_b = load_module_file(world, temp_string("module_b"), "module_b.ca");
    test_assert(find_name(module_a, "a") != NULL);
    test_assert(find_name(module_b, "a") == NULL);
}
Exemplo n.º 9
0
Block* find_function_local(Block* block, const char* name)
{
    caTerm* term = find_name(block, name, s_LookupFunction);
    if (term == NULL)
        return NULL;
    return nested_contents(term);
}
Exemplo n.º 10
0
Type* find_type(Block* block, const char* name)
{
    caTerm* term = find_name(block, name, s_LookupType);
    if (term == NULL)
        return NULL;
    return circa_type(circa_term_value(term));
}
Exemplo n.º 11
0
Arquivo: vasm.c Projeto: ezrec/vasm
symbol *find_symbol(char *name)
{
    hashdata data;
    if(!find_name(symhash,name,&data))
        return 0;
    return data.ptr;
}
Exemplo n.º 12
0
/*=export_func  optionEnumerationVal
 * what:  Convert from a string to an enumeration value
 * private:
 *
 * arg:   tOptions *,    pOpts,     the program options descriptor
 * arg:   tOptDesc *,    pOD,       enumeration option description
 * arg:   char const * const *,  paz_names, list of enumeration names
 * arg:   unsigned int,  name_ct,   number of names in list
 *
 * ret_type:  uintptr_t
 * ret_desc:  the enumeration value
 *
 * doc:   This converts the optArg.argString string from the option description
 *        into the index corresponding to an entry in the name list.
 *        This will match the generated enumeration value.
 *        Full matches are always accepted.  Partial matches are accepted
 *        if there is only one partial match.
=*/
uintptr_t
optionEnumerationVal(tOptions * pOpts, tOptDesc * pOD,
                     char const * const * paz_names, unsigned int name_ct)
{
    uintptr_t res = 0UL;

    /*
     *  IF the program option descriptor pointer is invalid,
     *  then it is some sort of special request.
     */
    switch ((uintptr_t)pOpts) {
    case (uintptr_t)OPTPROC_EMIT_USAGE:
        /*
         *  print the list of enumeration names.
         */
        enum_err(pOpts, pOD, paz_names, (int)name_ct);
        break;

    case (uintptr_t)OPTPROC_EMIT_SHELL:
    {
        unsigned int ix = (unsigned int)pOD->optArg.argEnum;
        /*
         *  print the name string.
         */
        if (ix >= name_ct)
            printf(INVALID_FMT, ix);
        else
            fputs(paz_names[ ix ], stdout);

        break;
    }

    case (uintptr_t)OPTPROC_RETURN_VALNAME:
    {
        unsigned int ix = (unsigned int)pOD->optArg.argEnum;
        /*
         *  Replace the enumeration value with the name string.
         */
        if (ix >= name_ct)
            return (uintptr_t)INVALID_STR;

        pOD->optArg.argString = paz_names[ix];
        break;
    }

    default:
        if ((pOD->fOptState & OPTST_RESET) != 0)
            break;

        res = find_name(pOD->optArg.argString, pOpts, pOD, paz_names, name_ct);

        if (pOD->fOptState & OPTST_ALLOC_ARG) {
            AGFREE(pOD->optArg.argString);
            pOD->fOptState &= ~OPTST_ALLOC_ARG;
            pOD->optArg.argString = NULL;
        }
    }

    return res;
}
Exemplo n.º 13
0
int add_dword(char *str)
{
	char *equals = NULL;
	struct EntryContainer *entry;

	equals = strchr(str, '=');
	if(equals == NULL)
	{
		fprintf(stderr, "Invalid option (no =)\n");
		return 0;
	}

	*equals++ = 0;

	if ((entry = find_name(str)))
	{
		entry->value = strtoul(equals, NULL, 0);
	}
	else
	{
		entry = find_free();
		if(entry == NULL)
		{
			fprintf(stderr, "Maximum options reached\n");
			return 0;
		}

		memset(entry, 0, sizeof(struct EntryContainer));
		entry->name = str;
		entry->type = PSF_TYPE_VAL;
		entry->value = strtoul(equals, NULL, 0);		
	}

	return 1;
}
Exemplo n.º 14
0
static void get_paren(
    char *buf,
    long *minp,
    long *maxp,
    int parent)
{
    int lth;

    get_must(0, buf);
    if (!strcmp(buf, size_w))
    {
        get_size(buf, minp, maxp, parent);
        // if (type == ASN_UTCTIME || type == ASN_GENTIME) *minp = *maxp = 0;
    }
    else
    {
        if (find_name(classname)->type != ASN_OBJ_ID &&
            (*buf == '_' || (*buf >= '0' && *buf <= '9') ||
             !strncmp(buf, min_w, 3)))
        {                       /* convert any upper bounds to numbers */
            get_min_max(buf, minp, maxp, parent);
            option |= ASN_RANGE_FLAG;
        }
        else
            for (; *buf != ')';
                 get_must(0, buf))
            {
                lth = strlen(buf);
                cat(&buf[lth++], " ");
                add_constraint(buf, lth);
            }
    }
}
Exemplo n.º 15
0
/* Create a drive quick and dirty. */
char *
create_drive(char *device)
{
	struct gv_drive *d;
	struct gctl_req *req;
	const char *errstr;
	char *drivename, *dname;
	int drives, i, flags, volumes, subdisks, plexes;

	flags = plexes = subdisks = volumes = 0;
	drives = 1;
	dname = NULL;

	drivename = find_drive();
	if (drivename == NULL)
		return (NULL);

	req = gctl_get_handle();
	gctl_ro_param(req, "class", -1, "VINUM");
	gctl_ro_param(req, "verb", -1, "create");
	d = gv_alloc_drive();
	if (d == NULL)
		err(1, "unable to allocate for gv_drive object");

	strlcpy(d->name, drivename, sizeof(d->name));
	copy_device(d, device);
	gctl_ro_param(req, "drive0", sizeof(*d), d);
	gctl_ro_param(req, "flags", sizeof(int), &flags);
	gctl_ro_param(req, "drives", sizeof(int), &drives);
	gctl_ro_param(req, "volumes", sizeof(int), &volumes);
	gctl_ro_param(req, "plexes", sizeof(int), &plexes);
	gctl_ro_param(req, "subdisks", sizeof(int), &subdisks);
	errstr = gctl_issue(req);
	if (errstr != NULL) {
		warnx("error creating drive: %s", errstr);
		gctl_free(req);
		return (NULL);
	} else {
		gctl_free(req);
		/* XXX: This is needed because we have to make sure the drives
		 * are created before we return. */
		/* Loop until it's in the config. */
		for (i = 0; i < 100000; i++) {
			dname = find_name("gvinumdrive", GV_TYPE_DRIVE,
			    GV_MAXDRIVENAME);
			/* If we got a different name, quit. */
			if (dname == NULL)
				continue;
			if (strcmp(dname, drivename)) {
				free(dname);
				return (drivename);
			}
			free(dname);
			dname = NULL;
			usleep(100000); /* Sleep for 0.1s */
		}
	}
	gctl_free(req);
	return (drivename);
}
Exemplo n.º 16
0
/* 
 * General routine for creating a volume. Mainly for use by concat, mirror,
 * raid5 and stripe commands.
 */
void
create_volume(int argc, char **argv, char *verb)
{
	struct gctl_req *req;
	const char *errstr;
	char buf[BUFSIZ], *drivename, *volname;
	int drives, flags, i;
	off_t stripesize;

	flags = 0;
	drives = 0;
	volname = NULL;
	stripesize = 262144;

	/* XXX: Should we check for argument length? */

	req = gctl_get_handle();
	gctl_ro_param(req, "class", -1, "VINUM");

	for (i = 1; i < argc; i++) {
		if (!strcmp(argv[i], "-f")) {
			flags |= GV_FLAG_F;
		} else if (!strcmp(argv[i], "-n")) {
			volname = argv[++i];
		} else if (!strcmp(argv[i], "-v")) {
			flags |= GV_FLAG_V;
		} else if (!strcmp(argv[i], "-s")) {
			flags |= GV_FLAG_S;
			if (!strcmp(verb, "raid5"))
				stripesize = gv_sizespec(argv[++i]);
		} else {
			/* Assume it's a drive. */
			snprintf(buf, sizeof(buf), "drive%d", drives++);

			/* First we create the drive. */
			drivename = create_drive(argv[i]); 
			if (drivename == NULL)
				goto bad;
			/* Then we add it to the request. */
			gctl_ro_param(req, buf, -1, drivename);
		}
	}

	gctl_ro_param(req, "stripesize", sizeof(off_t), &stripesize);

	/* Find a free volume name. */
	if (volname == NULL)
		volname = find_name("gvinumvolume", GV_TYPE_VOL, GV_MAXVOLNAME);

	/* Then we send a request to actually create the volumes. */
	gctl_ro_param(req, "verb", -1, verb);
	gctl_ro_param(req, "flags", sizeof(int), &flags); 
	gctl_ro_param(req, "drives", sizeof(int), &drives);
	gctl_ro_param(req, "name", -1, volname);
	errstr = gctl_issue(req);
	if (errstr != NULL)
		warnx("creating %s volume failed: %s", verb, errstr);
bad:
	gctl_free(req);
}
Exemplo n.º 17
0
t_file	*create_fake_list(char **av, int start, int ac)
{
	char	*dup;
	char	*name;
	t_file	*list2;

	list2 = NULL;
	while (start < ac)
	{
		dup = ft_strdup(av[start]);
		name = find_name(dup, av, start);
		if (!list2)
		{
			list2 = malloc(sizeof(t_file));
			ft_strncpy(list2->name, name, PATH_MAX);
			list2->path = ft_strsub(dup, 0, name - dup);
			list2->av_name = ft_strdup(av[start]);
			list2->next = NULL;
		}
		else
			add_list_with_name(list2, name, av[start], name - dup);
		start++;
		free(dup);
	}
	return (list2);
}
Exemplo n.º 18
0
SkDataTable* SkFontConfigInterfaceDirect::getFamilyNames() {
    SkAutoMutexAcquire ac(mutex_);

    FcPattern* pat = FcPatternCreate();
    SkAutoTCallVProc<FcPattern, FcPatternDestroy> autoDestroyPat(pat);
    if (NULL == pat) {
        return NULL;
    }

    FcObjectSet* os = FcObjectSetBuild(FC_FAMILY, (char *)0);
    SkAutoTCallVProc<FcObjectSet, FcObjectSetDestroy> autoDestroyOs(os);
    if (NULL == os) {
        return NULL;
    }

    FcFontSet* fs = FcFontList(NULL, pat, os);
    SkAutoTCallVProc<FcFontSet, FcFontSetDestroy> autoDestroyFs(fs);
    if (NULL == fs) {
        return NULL;
    }

    SkTDArray<const char*> names;
    SkTDArray<size_t> sizes;
    for (int i = 0; i < fs->nfont; ++i) {
        FcPattern* match = fs->fonts[i];
        const char* famName = get_name(match, FC_FAMILY);
        if (famName && !find_name(names, famName)) {
            *names.append() = famName;
            *sizes.append() = strlen(famName) + 1;
        }
    }

    return SkDataTable::NewCopyArrays((const void*const*)names.begin(),
                                      sizes.begin(), names.count());
}
Exemplo n.º 19
0
WORD name_ok(BYTE *name, WORD ok, WORD nilok)
{
	WORD	hit;

	if (name[0] == '@' || !name[0] || blank_name(name) )
	{
		if (nilok)
			return (TRUE);
		else
		{
			hndl_alert(1, string_addr(STNONAM));
			return (FALSE);
		}
	}
	else
	{
		hit = find_name(name);
		if (hit == NIL || hit == ok)
			return (TRUE);
		else
		{
			hndl_alert(1, string_addr(STNMDUP));
			return (FALSE);
		}
	}
}
Exemplo n.º 20
0
VOID unique_name(BYTE *name, BYTE *ptn, WORD n)
{
	do {
		sprintf(name, ptn, n);
		n++;
	} while (find_name(name) != NIL);
}
Exemplo n.º 21
0
/* flag the dll exports that link to an undefined symbol */
static void check_undefined_exports( DLLSPEC *spec )
{
    int i;

    for (i = 0; i < spec->nb_entry_points; i++)
    {
        ORDDEF *odp = &spec->entry_points[i];
        if (odp->type == TYPE_STUB || odp->type == TYPE_ABS || odp->type == TYPE_VARIABLE) continue;
        if (odp->flags & FLAG_FORWARD) continue;
        if (find_name( odp->link_name, &undef_symbols ))
        {
            switch(odp->type)
            {
            case TYPE_PASCAL:
            case TYPE_STDCALL:
            case TYPE_CDECL:
            case TYPE_VARARGS:
            case TYPE_THISCALL:
                if (link_ext_symbols)
                {
                    odp->flags |= FLAG_EXT_LINK;
                    add_name( &ext_link_imports, odp->link_name );
                }
                else error( "%s:%d: function '%s' not defined\n",
                                spec->src_name, odp->lineno, odp->link_name );
                break;
            default:
                error( "%s:%d: external symbol '%s' is not a function\n",
                       spec->src_name, odp->lineno, odp->link_name );
                break;
            }
        }
    }
}
Exemplo n.º 22
0
int main(void)
{
    int choice;
    if(file2mem() == FAIL){
        printf("信息文件读取出错\n");
        return 1;
    }
    while(1){
        print_choice();
        scanf("%d",&choice);
        switch(choice){
            case ADD:
                add_student();break;
            case DEL:
                delete_student();break;
            case CGE:
                change_student();break;
            case F_NAME:
                find_name();break;
            case F_NUM:
                find_number();break;
            case SORT:
                sort_score();break;
            case PRT:
                print_student();break;
            case EXIT:
                return 0;
        }
        getchar();
        printf("请按任意继续\n");
        getchar();
    }
    
}
Exemplo n.º 23
0
_extern void Cydia::elfHookFunction(const char *soname, const char *symbol, void *replace_func, void **old_func) {
    void *addr = NULL;
    if (find_name(getpid(), symbol, soname, (unsigned long *)&addr) < 0) {
        MSLog(MSLogLevelError, "Not found %s.", symbol);
        return;
    }
    Cydia::MSHookFunction(addr, replace_func, old_func);
}
Exemplo n.º 24
0
void SessionRep::init_style(const char* name, const PropertyData* props) {
    classname_ = name;
    name_ = find_name();
    style_ = new Style(*name_);
    Resource::ref(style_);
    style_->alias(classname_);
    props_ = props;
}
Exemplo n.º 25
0
T symbol_table<T>::find_symbol(const char* sym_name) const
{
  std::string find_name(sym_name);
  for( typename std::deque<std::pair<std::string,T> >::const_iterator it = symbols.begin(); it != symbols.end() ; it++ )
    if( it->first.compare(find_name) == 0)
      return it->second;
  return 0;
}
Exemplo n.º 26
0
int duplicate_name(const char *name) {
  int i;
  find_name(name, &i);
  if (i >= 0) {
    plintf("%s is a duplicate name\n", name);
    return (1);
  }
  return (0);
}
Exemplo n.º 27
0
static void said(int obj)
{
    char buf1[200];
    strncpy(buf1,buf + 8, sizeof(buf-8));
    buf1[8] = 0;
    
    printf(lang_says_format,find_name(obj));
    printf("%s\n", buf1);
}
Exemplo n.º 28
0
int find_lookup(char *name) {
  int index, com;
  find_name(name, &index);
  if (index == -1)
    return (-1);
  com = my_symb.elems[index].com;
  if (is_lookup(com))
    return (com % MAXTYPE);
  return (-1);
}
Exemplo n.º 29
0
void bug_with_lookup_type_and_qualified_name()
{
    // Bug repro. There was an issue where, when searching for a qualified name, we would
    // use the original lookup type on the prefix. (which is wrong).

    Block block;
    Block* module = create_block(&block, "module");
    Term* T = create_type(module, "T");

    test_assert(T == find_name(&block, "module:T", -1, sym_LookupType));
}
Exemplo n.º 30
0
int get_param_index(char *name) {
  int type, com;
  find_name(name, &type);
  if (type < 0)
    return (-1);
  com = my_symb.elems[type].com;
  if (is_ucon(com)) {
    return (com % MAXTYPE);
  }
  return (-1);
}