示例#1
0
SHAPE *shape_add (SHAPE_TYPE t, const char *color)
{
	SHAPE		*s;
	unsigned	i;
	char		buf [20];

	for (s = writers [t].instances; s; s = s->next)
		if (!astrcmp (s->color, color)) {
			printf ("Shape already exists!\r\n");
			return (NULL);
		}
	s = (SHAPE *) malloc (sizeof (SHAPE));
	if (!s) {
		printf ("Out of memory!");
		usage ();
	}
	strncpy (s->color, color, sizeof (s->color));
	s->c = tty_color_type (color);
	for (i = 0; i < strlen (color); i++)
		if (s->color [i] >= 'a' && s->color [i] <= 'z')
			s->color [i] -= 'a' - 'A';
	s->type = t;
	s->cur_x = rnd (MAX_X - MIN_X) + MIN_X;
	s->cur_y = rnd (MAX_Y - MIN_Y) + MIN_Y;
	s->delta_x = 1 + rnd (5);
	s->delta_y = 1 + rnd (5);
	s->size = 30;
	s->delay = 125;
	snprintf (buf, sizeof (buf), "P:%s(%s)", types_str [t], color);
	s->timer = DDS_Timer_create (buf);
	s->next = writers [t].instances;
	writers [t].instances = s;
	return (s);
}
示例#2
0
SHAPE_TYPE shape_type (const char *cp)
{
	SHAPE_TYPE	t;

	if (!astrcmp (cp, "square"))
		t = ST_SQUARE;
	else if (!astrcmp (cp, "circle"))
		t = ST_CIRCLE;
	else if (!astrcmp (cp, "triangle"))
		t = ST_TRIANGLE;
	else {
		t = ST_SQUARE;
		printf ("Invalid shape type (only circle, square or triangle allowed)!\r\n");
		usage ();
	}
	return (t);
}
示例#3
0
SDB_API int sdb_array_add_sorted(Sdb *s, const char *key, const char *val, ut32 cas) {
	int lstr, lval, i, j;
	const char *str_e, *str_lp, *str_p, *str = sdb_const_get_len (s, key, &lstr, 0);
	char *nstr, *nstr_p, **vals;
	const char null = '\0';
	if (!str || !*str) {
		str = &null;
		lstr = 0;
	}
	str_e = str + lstr;
	str_lp = str_p = str;
	if (!val || !*val) {
		return 1;
	}
	lval = strlen (val);
	vals = sdb_fmt_array (val);
	for (i = 0; vals[i]; i++) {
		/* empty */
	}
	if (i > 1) {
		qsort (vals, i, sizeof (ut64*), cstring_cmp);
	}
	nstr_p = nstr = malloc (lstr + lval + 3);
	if (!nstr) {
		return 1;
	}
	for (i = 0; vals[i]; i++) {
		while (str_p < str_e) {
			if (astrcmp (vals[i], str_p) < 0) {
				break;
			}
			sdb_const_anext (str_p, &str_p);
			if (!str_p) {
				str_p = str_e;
			}
		}
		memcpy (nstr_p, str_lp, str_p - str_lp);
		nstr_p += str_p - str_lp;
		if (str_p == str_e && str_lp != str_e) {
			*(nstr_p++) = SDB_RS;
		}
		str_lp = str_p;
		j = strlen (vals[i]);
		memcpy (nstr_p, vals[i], j);
		nstr_p += j;
		*(nstr_p++) = SDB_RS;
	}
	if (str_lp < str_e) {
		memcpy (nstr_p, str_lp, str_e - str_lp);
		nstr_p += str_e - str_lp;
		*(nstr_p) = '\0';
	} else {
		*(--nstr_p) = '\0';
	}
	sdb_set_owned (s, key, nstr, cas);
	free (vals);
	return 0;
}
示例#4
0
Color_t tty_color_type (const char *s)
{
	Color_t	c;

	for (c = TC_Black; c <= TC_White; c++)
		if (!astrcmp (tty_color_names [c], s))
			return (c);

	return (TC_Black);
}
示例#5
0
文件: main.c 项目: liuchuo/C-practice
int main(){
    int astrcmp(char *,char *);
    int m;
    char str1[20],str2[20];
    char *p1,*p2;
    printf("input two strings:\n");
    scanf("%s",str1);
    scanf("%s",str2);
    p1 = &str1[0];
    p2 = &str2[0];
    m = astrcmp(p1,p2);
    printf("result:%d\n",m);
    return 0;
}
示例#6
0
文件: array.c 项目: haoa193/radare2
// previously named del_str... pair with _add
SDB_API int sdb_array_remove(Sdb *s, const char *key, const char *val, ut32 cas) {
	const char *str = sdb_const_get (s, key, 0);
	const char *n, *p = str;
	int idx;
	if (p)
	for (idx=0; ; idx++) {
		if (!astrcmp (p, val))
			return sdb_array_delete (s, key, idx, cas);
		n = strchr (p, SDB_RS);
		if (!n) break;
		p = n+1;
	}
	return 0;
}
示例#7
0
文件: array.c 项目: haoa193/radare2
/* get array index of given value */
SDB_API int sdb_array_indexof(Sdb *s, const char *key, const char *val, ut32 cas) {
	const char *str = sdb_const_get (s, key, 0);
	const char *n, *p = str;
	int idx;
	for (idx=0; ; idx++) {
		if (!p) break;
		if (!astrcmp (p, val))
			return idx;
		n = strchr (p, SDB_RS);
		if (!n) break;
		p = n+1;
	}
	return -1;
}
示例#8
0
void
arginit(void)
{
	int verb;
	char *line;
	char word[Maxword+1], *cp;
	Filsys *fs;

	if(nvrcheck() == 0) {
		setconfig(conf.confdev);
		if (!conf.configfirst)
			return;
	}

	/* nvr was bad or invoker requested configuration step */
	setconfig(conf.confdev);
	for (;;) {
		print("config: ");
		if ((line = Brdline(&bin, '\n')) == nil)
			return;
		line[Blinelen(&bin)-1] = '\0';

		cp = getwrd(word, line);
		if (word[0] == '\0' || word[0] == '#')
			continue;
		if(strcmp(word, "end") == 0)
			return;
		if(strcmp(word, "halt") == 0)
			exit();
		if(strcmp(word, "queryjuke") == 0) {
			getwrd(word, cp);
			if(testconfig(word) == 0)
				querychanger(iconfig(word));
			continue;
		}

		if(strcmp(word, "allow") == 0) {
			wstatallow = 1;
			writeallow = 1;
			continue;
		}
		if(strcmp(word, "copyworm") == 0) {
			copyworm = 1;
			continue;
		}
		if(strcmp(word, "copydev") == 0) {
			cp = getwrd(word, cp);
			if(testconfig(word))
				continue;
			src = strdup(word);
			getwrd(word, cp);
			if(testconfig(word))
				continue;
			dest = strdup(word);
			copydev = 1;
			continue;
		}
		if(strcmp(word, "noauth") == 0) {
			noauth = !noauth;
			continue;
		}
		if(strcmp(word, "noattach") == 0) {
			noattach = !noattach;
			continue;
		}
		if(strcmp(word, "readonly") == 0) {
			readonly = 1;
			continue;
		}

		if(strcmp(word, "ream") == 0) {
			verb = FREAM;
			goto gfsname;
		}
		if(strcmp(word, "recover") == 0) {
			verb = FRECOVER;
			goto gfsname;
		}
		if(strcmp(word, "filsys") == 0) {
			verb = FEDIT;
			goto gfsname;
		}

		if(strcmp(word, "nvram") == 0) {
			getwrd(word, cp);
			if(testconfig(word))
				continue;
			/* if it fails, it will complain */
			nvrsetconfig(word);
			continue;
		}
		if(strcmp(word, "config") == 0) {
			getwrd(word, cp);
			if(!testconfig(word) && nvrsetconfig(word) == 0)
				f.newconf = 1;
			continue;
		}
		if(strcmp(word, "service") == 0) {
			getwrd(word, cp);
			strncpy(service, word, sizeof service);
			f.modconf = 1;
			continue;
		}
		if (strcmp(word, "resetparams") == 0) {
			resetparams++;
			continue;
		}

		/*
		 * continue to parse obsolete keywords so that old
		 * configurations can still work.
		 */
		if (strcmp(word, "ipauth") != 0 &&
		    astrcmp(word, "ip") != 0 &&
		    astrcmp(word, "ipgw") != 0 &&
		    astrcmp(word, "ipmask") != 0 &&
		    astrcmp(word, "ipsntp") != 0) {
			print("unknown config command\n");
			print("\ttype end to get out\n");
			continue;
		}

		getwrd(word, cp);
		f.modconf = 1;
		continue;

	gfsname:
		cp = getwrd(word, cp);
		for(fs=filsys; fs->name; fs++)
			if(strcmp(word, fs->name) == 0)
				break;
		if (fs->name == nil) {
			memset(fs, 0, sizeof *fs);
			fs->name = strdup(word);
		}
		switch(verb) {
		case FREAM:
			if(strcmp(fs->name, "main") == 0)
				wstatallow = 1;	/* only set, never reset */
			/* fallthrough */
		case FRECOVER:
			fs->flags |= verb;
			break;
		case FEDIT:
			f.modconf = 1;
			getwrd(word, cp);
			fs->flags |= verb;
			if(word[0] == 0)
				fs->conf = nil;
			else if(!testconfig(word))
				fs->conf = strdup(word);
			break;
		}
	}
}
示例#9
0
/*
 * continue to parse obsolete keywords so that old configurations can
 * still work.
 */
void
mergeconf(Iobuf *p)
{
	char word[Maxword+1];
	char *cp;
	Filsys *fs;
	Fspar *fsp;

	for (cp = p->iobuf; *cp != '\0'; cp++) {
		cp = getwrd(word, cp);
		if(word[0] == '\0')
			break;
		else if (word[0] == '#')
			while (*cp != '\n' && *cp != '\0')
				cp++;
		else if(strcmp(word, "service") == 0) {
			cp = getwrd(word, cp);
			if(service[0] == 0)
				strncpy(service, word, sizeof service);
		} else if(strcmp(word, "ipauth") == 0)	/* obsolete */
			cp = getwrd(word, cp);
		else if(astrcmp(word, "ip") == 0)	/* obsolete */
			cp = getwrd(word, cp);
		else if(astrcmp(word, "ipgw") == 0)	/* obsolete */
			cp = getwrd(word, cp);
		else if(astrcmp(word, "ipsntp") == 0)	/* obsolete */
			cp = getwrd(word, cp);
		else if(astrcmp(word, "ipmask") == 0)	/* obsolete */
			cp = getwrd(word, cp);
		else if(strcmp(word, "filsys") == 0) {
			cp = getwrd(word, cp);
			for(fs = filsys; fs < filsys + nelem(filsys) - 1 &&
			    fs->name; fs++)
				if(strcmp(fs->name, word) == 0)
					break;
			if (fs >= filsys + nelem(filsys) - 1)
				panic("out of filsys structures");
			if (fs->name && strcmp(fs->name, word) == 0 &&
			    fs->flags & FEDIT)
				cp = getwrd(word, cp);	/* swallow conf */
			else {
				fs->name = strdup(word);
				cp = getwrd(word, cp);
				if (word[0] == '\0')
					fs->conf = nil;
				else
					fs->conf = strdup(word);
			}
		} else if ((fsp = getpar(word)) != nil) {
			cp = getwrd(word, cp);
			if (!isascii(word[0]) || !isdigit(word[0]))
				print("bad %s value: %s", fsp->name, word);
			else
				fsp->declared = atol(word);
		} else {
			putbuf(p);
			panic("unknown keyword in config block: %s", word);
		}

		if(*cp != '\n') {
			putbuf(p);
			panic("syntax error in config block at `%s'", word);
		}
	}
}
示例#10
0
static inline int cstring_cmp(const void *a, const void *b) { 
	const char **va = (const char **)a;
	const char **vb = (const char **)b;
	return astrcmp (*va, *vb);
}