您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ strsep函数代码示例

51自学网 2021-06-03 08:32:13
  C++
这篇教程C++ strsep函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中strsep函数的典型用法代码示例。如果您正苦于以下问题:C++ strsep函数的具体用法?C++ strsep怎么用?C++ strsep使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了strsep函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: pkg_perform

intpkg_perform(const char *pkg){	char   *cp;	FILE   *pkg_in;	package_t plist;	const char *full_pkg, *suffix;	char *allocated_pkg;	int retval;	/* Break the package name into base and desired suffix (if any) */	if ((cp = strrchr(pkg, '.')) != NULL) {		if ((allocated_pkg = malloc(cp - pkg + 1)) == NULL)			err(2, "malloc failed");		memcpy(allocated_pkg, pkg, cp - pkg);		allocated_pkg[cp - pkg] = '/0';		suffix = cp + 1;		full_pkg = pkg;		pkg = allocated_pkg;	} else {		allocated_pkg = NULL;		full_pkg = pkg;		suffix = "tgz";	}	/* Preliminary setup */	sanity_check();	if (Verbose && !PlistOnly)		printf("Creating package %s/n", pkg);	get_dash_string(&Comment);	get_dash_string(&Desc);	if (IS_STDIN(Contents))		pkg_in = stdin;	else {		pkg_in = fopen(Contents, "r");		if (!pkg_in)			errx(2, "unable to open contents file '%s' for input", Contents);	}	plist.head = plist.tail = NULL;	/* If a SrcDir override is set, add it now */	if (SrcDir) {		if (Verbose && !PlistOnly)			printf("Using SrcDir value of %s/n", (realprefix) ? realprefix : SrcDir);		add_plist(&plist, PLIST_SRC, SrcDir);	}	/* Stick the dependencies, if any, at the top */	if (Pkgdeps)		register_depends(&plist, Pkgdeps, 0);	/*	 * Put the build dependencies after the dependencies.	 * This works due to the evaluation order in pkg_add.	 */	if (BuildPkgdeps)		register_depends(&plist, BuildPkgdeps, 1);	/* Put the conflicts directly after the dependencies, if any */	if (Pkgcfl) {		if (Verbose && !PlistOnly)			printf("Registering conflicts:");		while (Pkgcfl) {			cp = strsep(&Pkgcfl, " /t/n");			if (*cp) {				add_plist(&plist, PLIST_PKGCFL, cp);				if (Verbose && !PlistOnly)					printf(" %s", cp);			}		}		if (Verbose && !PlistOnly)			printf("./n");	}	/* Slurp in the packing list */	read_plist(&plist, pkg_in);	if (pkg_in != stdin)		fclose(pkg_in);	/* Prefix should override the packing list */	if (Prefix) {		delete_plist(&plist, FALSE, PLIST_CWD, NULL);		add_plist_top(&plist, PLIST_CWD, Prefix);	}	/*         * Run down the list and see if we've named it, if not stick in a name         * at the top.         */	if (find_plist(&plist, PLIST_NAME) == NULL) {		add_plist_top(&plist, PLIST_NAME, basename_of(pkg));	}	/* Make first "real contents" pass over it */	check_list(&plist, basename_of(pkg));	/*         * We're just here for to dump out a revised plist for the FreeBSD ports         * hack.  It's not a real create in progress.         *///.........这里部分代码省略.........
开发者ID:vocho,项目名称:qnxpkgsrcmirror,代码行数:101,


示例2: parse_prime

static intparse_prime(int linenum, char *line, struct dhgroup *dhg){	char *cp, *arg;	char *strsize, *gen, *prime;	const char *errstr = NULL;	long long n;	dhg->p = dhg->g = NULL;	cp = line;	if ((arg = strdelim(&cp)) == NULL)		return 0;	/* Ignore leading whitespace */	if (*arg == '/0')		arg = strdelim(&cp);	if (!arg || !*arg || *arg == '#')		return 0;	/* time */	if (cp == NULL || *arg == '/0')		goto truncated;	arg = strsep(&cp, " "); /* type */	if (cp == NULL || *arg == '/0')		goto truncated;	/* Ensure this is a safe prime */	n = strtonum(arg, 0, 5, &errstr);	if (errstr != NULL || n != MODULI_TYPE_SAFE) {		error("moduli:%d: type is not %d", linenum, MODULI_TYPE_SAFE);		goto fail;	}	arg = strsep(&cp, " "); /* tests */	if (cp == NULL || *arg == '/0')		goto truncated;	/* Ensure prime has been tested and is not composite */	n = strtonum(arg, 0, 0x1f, &errstr);	if (errstr != NULL ||	    (n & MODULI_TESTS_COMPOSITE) || !(n & ~MODULI_TESTS_COMPOSITE)) {		error("moduli:%d: invalid moduli tests flag", linenum);		goto fail;	}	arg = strsep(&cp, " "); /* tries */	if (cp == NULL || *arg == '/0')		goto truncated;	n = strtonum(arg, 0, 1<<30, &errstr);	if (errstr != NULL || n == 0) {		error("moduli:%d: invalid primality trial count", linenum);		goto fail;	}	strsize = strsep(&cp, " "); /* size */	if (cp == NULL || *strsize == '/0' ||	    (dhg->size = (int)strtonum(strsize, 0, 64*1024, &errstr)) == 0 ||	    errstr) {		error("moduli:%d: invalid prime length", linenum);		goto fail;	}	/* The whole group is one bit larger */	dhg->size++;	gen = strsep(&cp, " "); /* gen */	if (cp == NULL || *gen == '/0')		goto truncated;	prime = strsep(&cp, " "); /* prime */	if (cp != NULL || *prime == '/0') { truncated:		error("moduli:%d: truncated", linenum);		goto fail;	}	if ((dhg->g = BN_new()) == NULL ||	    (dhg->p = BN_new()) == NULL) {		error("parse_prime: BN_new failed");		goto fail;	}	if (BN_hex2bn(&dhg->g, gen) == 0) {		error("moduli:%d: could not parse generator value", linenum);		goto fail;	}	if (BN_hex2bn(&dhg->p, prime) == 0) {		error("moduli:%d: could not parse prime value", linenum);		goto fail;	}	if (BN_num_bits(dhg->p) != dhg->size) {		error("moduli:%d: prime has wrong size: actual %d listed %d",		    linenum, BN_num_bits(dhg->p), dhg->size - 1);		goto fail;	}	if (BN_cmp(dhg->g, BN_value_one()) <= 0) {		error("moduli:%d: generator is invalid", linenum);		goto fail;	}	return 1; fail:	BN_clear_free(dhg->g);	BN_clear_free(dhg->p);	dhg->g = dhg->p = NULL;	return 0;}
开发者ID:ozaki-r,项目名称:netbsd-src,代码行数:97,


示例3: doit

//.........这里部分代码省略.........				/* Skip to end of program[pid]: and trailing space */		bp = strchr(bp, ':');		bp += 2;		if (strncmp(bp, L1, strlen(L1)) == 0) {		  /*fprintf(stdout,"Hit L1: ");*/			bp += strlen(L1);		}		else if (strncmp(bp, L2, strlen(L2)) == 0) {		  /*fprintf(stdout,"Hit L2: ");*/			bp += strlen(L2);		}		else if (strncmp(bp, L3, strlen(L3)) == 0) {		  /*fprintf(stdout,"Hit L3: ");*/			bp += strlen(L3);		}		else if (strncmp(bp, L4, strlen(L4)) == 0) {		  /*fprintf(stdout,"Hit L4: ");*/			bp += strlen(L4);		}		else if (strncmp(bp, L5, strlen(L5)) == 0) {		  /*fprintf(stdout,"Hit L5: ");*/			bp += strlen(L5);		}		else if (strncmp(bp, L6, strlen(L6)) == 0) {		  /*fprintf(stdout,"Hit L6: ");*/			bp += strlen(L6);		}		else {			continue;		}		/*		 * The login name is the next token.		 */		if (! (user = strsep(&bp, " ")))			continue;		/*fprintf(stdout,"%s on %s/n",user,node);*/		/* We do not care about ROOT logins. */		if (strcasecmp(user, "ROOT") == 0)			continue;		dbres = mydb_query("select uid_idx from users where uid='%s' "				   "and status!='archived' and status!='nonlocal'",				   1, user);		if (!dbres) {			syslog(LOG_ERR, "DB error getting user %s", user);			continue;		}		if (!mysql_num_rows(dbres)) {			syslog(LOG_INFO, "No DB record for user %s", user);			mysql_free_result(dbres);			continue;		}		dbrow = mysql_fetch_row(dbres);		strncpy(uid_idx, dbrow[0], sizeof(uid_idx));		mysql_free_result(dbres);		/*		 * Safety first. 		 */		mydb_escape_string(tmp, uid_idx, strlen(uid_idx));		strcpy(uid_idx, tmp);		mydb_escape_string(tmp, node, strlen(node));		strcpy(node, tmp);		if (mydb_update("replace into uidnodelastlogin "				"(uid, uid_idx, node_id, date, time) "				"values ('%s', '%s', '%s', "				"        FROM_UNIXTIME(%ld, '%%Y-%%m-%%d'), "				"        FROM_UNIXTIME(%ld, '%%T')) ",				user, uid_idx, node, ll_time, ll_time) == 0)			break;		if (strncmp(node, opshostname, strlen(node)) == 0 ||		    strncmp(node, "ops", strlen(node)) == 0) {			if (mydb_update("replace into userslastlogin "					"(uid, uid_idx, date, time) "					"values ('%s', '%s', "					"  FROM_UNIXTIME(%ld, '%%Y-%%m-%%d'), "					"  FROM_UNIXTIME(%ld, '%%T')) ",					user, uid_idx, ll_time, ll_time) == 0)				break;		}		else {			if (mydb_update("replace into nodeuidlastlogin "					"(node_id, uid_idx, uid, date, time) "					"values ('%s', '%s', '%s', "					"  FROM_UNIXTIME(%ld, '%%Y-%%m-%%d'), "					"  FROM_UNIXTIME(%ld, '%%T')) ",					node, uid_idx, user, ll_time, ll_time) == 0)				break;		}	}	return 0;}
开发者ID:senseisimple,项目名称:emulab-stable,代码行数:101,


示例4: parse_setup_cpu_list

static int parse_setup_cpu_list(void){	struct thread_data *td;	char *str0, *str;	int t;	if (!g->p.cpu_list_str)		return 0;	dprintf("g->p.nr_tasks: %d/n", g->p.nr_tasks);	str0 = str = strdup(g->p.cpu_list_str);	t = 0;	BUG_ON(!str);	tprintf("# binding tasks to CPUs:/n");	tprintf("#  ");	while (true) {		int bind_cpu, bind_cpu_0, bind_cpu_1;		char *tok, *tok_end, *tok_step, *tok_len, *tok_mul;		int bind_len;		int step;		int mul;		tok = strsep(&str, ",");		if (!tok)			break;		tok_end = strstr(tok, "-");		dprintf("/ntoken: {%s}, end: {%s}/n", tok, tok_end);		if (!tok_end) {			/* Single CPU specified: */			bind_cpu_0 = bind_cpu_1 = atol(tok);		} else {			/* CPU range specified (for example: "5-11"): */			bind_cpu_0 = atol(tok);			bind_cpu_1 = atol(tok_end + 1);		}		step = 1;		tok_step = strstr(tok, "#");		if (tok_step) {			step = atol(tok_step + 1);			BUG_ON(step <= 0 || step >= g->p.nr_cpus);		}		/*		 * Mask length.		 * Eg: "--cpus 8_4-16#4" means: '--cpus 8_4,12_4,16_4',		 * where the _4 means the next 4 CPUs are allowed.		 */		bind_len = 1;		tok_len = strstr(tok, "_");		if (tok_len) {			bind_len = atol(tok_len + 1);			BUG_ON(bind_len <= 0 || bind_len > g->p.nr_cpus);		}		/* Multiplicator shortcut, "0x8" is a shortcut for: "0,0,0,0,0,0,0,0" */		mul = 1;		tok_mul = strstr(tok, "x");		if (tok_mul) {			mul = atol(tok_mul + 1);			BUG_ON(mul <= 0);		}		dprintf("CPUs: %d_%d-%d#%dx%d/n", bind_cpu_0, bind_len, bind_cpu_1, step, mul);		if (bind_cpu_0 >= g->p.nr_cpus || bind_cpu_1 >= g->p.nr_cpus) {			printf("/nTest not applicable, system has only %d CPUs./n", g->p.nr_cpus);			return -1;		}		BUG_ON(bind_cpu_0 < 0 || bind_cpu_1 < 0);		BUG_ON(bind_cpu_0 > bind_cpu_1);		for (bind_cpu = bind_cpu_0; bind_cpu <= bind_cpu_1; bind_cpu += step) {			int i;			for (i = 0; i < mul; i++) {				int cpu;				if (t >= g->p.nr_tasks) {					printf("/n# NOTE: ignoring bind CPUs starting at CPU#%d/n #", bind_cpu);					goto out;				}				td = g->threads + t;				if (t)					tprintf(",");				if (bind_len > 1) {					tprintf("%2d/%d", bind_cpu, bind_len);				} else {					tprintf("%2d", bind_cpu);				}				CPU_ZERO(&td->bind_cpumask);//.........这里部分代码省略.........
开发者ID:spacex,项目名称:kernel-centos7,代码行数:101,


示例5: main

intmain(int ac, char **av){	int ch;	int res;	char *sched = NULL;	char *cpustr = NULL;	char *sched_cpustr = NULL;	char *p = NULL;	cpumask_t cpumask;	int cpuid;	pid_t pid = getpid();  /* See usched_set(2) - BUGS */	CPUMASK_ASSZERO(cpumask);	while ((ch = getopt(ac, av, "d")) != -1) {		switch (ch) {		case 'd':			DebugOpt = 1;			break;		default:			usage();			/* NOTREACHED */		}	}	ac -= optind;	av += optind;	if (ac < 2) {		usage();		/* NOTREACHED */	}	sched_cpustr = strdup(av[0]);	sched = strsep(&sched_cpustr, ":");	if (strcmp(sched, "default") == 0)		fprintf(stderr, "Ignoring scheduler == /"default/": not implemented/n");	cpustr = strsep(&sched_cpustr, "");	if (strlen(sched) == 0 && cpustr == NULL) {		usage();		/* NOTREACHED */	}	/*	 * XXX needs expanded support for > 64 cpus	 */	if (cpustr != NULL) {		uint64_t v;		v = (uint64_t)strtoull(cpustr, NULL, 0);		for (cpuid = 0; cpuid < (int)sizeof(v) * 8; ++cpuid) {			if (v & (1LU << cpuid))				CPUMASK_ORBIT(cpumask, cpuid);		}	}	if (strlen(sched) != 0) {		if (DebugOpt)			fprintf(stderr, "DEBUG: USCHED_SET_SCHEDULER: scheduler: %s/n", sched);		res = usched_set(pid, USCHED_SET_SCHEDULER, sched, strlen(sched));		if (res != 0) {			asprintf(&p, "usched_set(%d, USCHED_SET_SCHEDULER, /"%s/", %d)",				pid, sched, (int)strlen(sched));			perror(p);			exit(1);		}	}	if (CPUMASK_TESTNZERO(cpumask)) {		for (cpuid = 0; cpuid < (int)sizeof(cpumask) * 8; ++cpuid) {			if (CPUMASK_TESTBIT(cpumask, cpuid))				break;		}		if (DebugOpt) {			fprintf(stderr, "DEBUG: USCHED_SET_CPU: cpuid: %d/n",				cpuid);		}		res = usched_set(pid, USCHED_SET_CPU, &cpuid, sizeof(int));		if (res != 0) {			asprintf(&p, "usched_set(%d, USCHED_SET_CPU, &%d, %d)",				pid, cpuid, (int)sizeof(int));			perror(p);			exit(1);		}		CPUMASK_NANDBIT(cpumask, cpuid);		while (CPUMASK_TESTNZERO(cpumask)) {			++cpuid;			if (CPUMASK_TESTBIT(cpumask, cpuid) == 0)				continue;			CPUMASK_NANDBIT(cpumask, cpuid);			if (DebugOpt) {				fprintf(stderr,					"DEBUG: USCHED_ADD_CPU: cpuid: %d/n",					cpuid);			}			res = usched_set(pid, USCHED_ADD_CPU, &cpuid, sizeof(int));			if (res != 0) {				asprintf(&p, "usched_set(%d, USCHED_ADD_CPU, &%d, %d)",					pid, cpuid, (int)sizeof(int));				perror(p);				exit(1);			}//.........这里部分代码省略.........
开发者ID:kusumi,项目名称:DragonFlyBSD,代码行数:101,


示例6: ind_load_module

/* * Load module stuff */static int ind_load_module(void){	struct ast_config *cfg;	struct ast_variable *v;	char *cxt;	char *c;	struct tone_zone *tones;	const char *country = NULL;	/* that the following cast is needed, is yuk! */	/* yup, checked it out. It is NOT written to. */	cfg = ast_config_load((char *)config);	if (!cfg)		return -1;	/* Use existing config to populate the Indication table */	cxt = ast_category_browse(cfg, NULL);	while(cxt) {		/* All categories but "general" are considered countries */		if (!strcasecmp(cxt, "general")) {			cxt = ast_category_browse(cfg, cxt);			continue;		}				if (!(tones = ast_calloc(1, sizeof(*tones)))) {			ast_config_destroy(cfg);			return -1;		}		ast_copy_string(tones->country,cxt,sizeof(tones->country));		v = ast_variable_browse(cfg, cxt);		while(v) {			if (!strcasecmp(v->name, "description")) {				ast_copy_string(tones->description, v->value, sizeof(tones->description));			} else if ((!strcasecmp(v->name,"ringcadence"))||(!strcasecmp(v->name,"ringcadance"))) {				char *ring,*rings = ast_strdupa(v->value);				c = rings;				ring = strsep(&c,",");				while (ring) {					int *tmp, val;					if (!isdigit(ring[0]) || (val=atoi(ring))==-1) {						ast_log(LOG_WARNING,"Invalid ringcadence given '%s' at line %d./n",ring,v->lineno);						ring = strsep(&c,",");						continue;					}										if (!(tmp = ast_realloc(tones->ringcadence, (tones->nrringcadence + 1) * sizeof(int)))) {						ast_config_destroy(cfg);						return -1;					}					tones->ringcadence = tmp;					tmp[tones->nrringcadence] = val;					tones->nrringcadence++;					/* next item */					ring = strsep(&c,",");				}			} else if (!strcasecmp(v->name,"alias")) {				char *countries = ast_strdupa(v->value);				c = countries;				country = strsep(&c,",");				while (country) {					struct tone_zone* azone;					if (!(azone = ast_calloc(1, sizeof(*azone)))) {						ast_config_destroy(cfg);						return -1;					}					ast_copy_string(azone->country, country, sizeof(azone->country));					ast_copy_string(azone->alias, cxt, sizeof(azone->alias));					if (ast_register_indication_country(azone)) {						ast_log(LOG_WARNING, "Unable to register indication alias at line %d./n",v->lineno);						free(tones);					}					/* next item */					country = strsep(&c,",");				}			} else {				/* add tone to country */				struct tone_zone_sound *ps,*ts;				for (ps=NULL,ts=tones->tones; ts; ps=ts, ts=ts->next) {					if (strcasecmp(v->name,ts->name)==0) {						/* already there */						ast_log(LOG_NOTICE,"Duplicate entry '%s', skipped./n",v->name);						goto out;					}				}				/* not there, add it to the back */								if (!(ts = ast_malloc(sizeof(*ts)))) {					ast_config_destroy(cfg);					return -1;				}				ts->next = NULL;				ts->name = strdup(v->name);				ts->data = strdup(v->value);				if (ps)					ps->next = ts;				else					tones->tones = ts;			}out:			v = v->next;//.........这里部分代码省略.........
开发者ID:sipwise,项目名称:asterisk,代码行数:101,


示例7: join

/* *Join a chat room */void join(packet *pkt, int fd) {   int i = 0;   char *args[16];   char *tmp = pkt->buf;   packet ret;   // Split command args   args[i] = strsep(&tmp, " /t");   while ((i < sizeof(args) - 1) && (args[i] != '/0')) {      args[++i] = strsep(&tmp, " /t");   }   if (i > 1 && validRoomname(args[0], fd)) {      // check if room exists      printf("Checking if room exists . . ./n");      if (Rget_ID(&room_list, args[0], rooms_mutex) == -1) {         // create if it does not exist         createRoom(&room_list, numRooms, args[0], rooms_mutex);      }      RprintList(&room_list, rooms_mutex);      printf("Receiving room node for requested room./n");      Room *newRoom = Rget_roomFNAME(&room_list, args[0], rooms_mutex);      int currRoomNum = atoi(args[1]);      // Should check if current room exists      printf("Receiving room node for users current room./n");      Room *currentRoom = Rget_roomFID(&room_list, currRoomNum, rooms_mutex);//pkt->options);      printf("Getting user node from current room user list./n");      if(currentRoom == NULL) {         printf("Could not remove user: current room is NULL/n");      }      else {         User *currUser = get_user(&(currentRoom->user_list), pkt->username, currentRoom->user_list_mutex);         printf("Removing user from his current rooms user list/n");         removeUser(&(currentRoom->user_list), currUser, currentRoom->user_list_mutex);         printf("User removed from current room/n");                  //Create node to add user to other room list.         Node *new_node = (Node *)malloc(sizeof(Node));         new_node->data = currUser;         currUser->roomID = newRoom->ID;         printf("Inserting user into new rooms user list/n");         insertUser(&(newRoom->user_list), currUser, newRoom->user_list_mutex);         RprintList(&room_list, rooms_mutex);         ret.options = JOINSUC;         strcpy(ret.realname, SERVER_NAME);         strcpy(ret.username, SERVER_NAME);         ret.timestamp = time(NULL);         sprintf(ret.buf, "%s %d", args[0], newRoom->ID);         send(fd, (void *)&ret, sizeof(packet), MSG_NOSIGNAL);         memset(&ret, 0, sizeof(ret));         ret.options = currRoomNum;         strcpy(ret.realname, SERVER_NAME);         strcpy(ret.username, SERVER_NAME);         strncpy(ret.buf, currUser->real_name, sizeof(currUser->real_name));         strcat(ret.buf, " has left the room.");         ret.timestamp = time(NULL);         send_message(&ret, -1);         memset(&ret, 0, sizeof(ret));         ret.options = newRoom->ID;         strcpy(ret.realname, SERVER_NAME);         strcpy(ret.username, SERVER_NAME);         strncpy(ret.buf, currUser->real_name, sizeof(currUser->real_name));         strcat(ret.buf, " has joined the room.");         ret.timestamp = time(NULL);         send_message(&ret, -1);      }   }   else {      printf("Problem in join./n");      sendError("We were unable to put you in that room, sorry.", fd);   }}
开发者ID:mgeitz,项目名称:tbdchat,代码行数:79,


示例8: read_config

struct if_options *read_config(const char *file,    const char *ifname, const char *ssid, const char *profile){	struct if_options *ifo;	FILE *f;	char *line, *option, *p, *platform;	int skip = 0, have_profile = 0;	struct utsname utn;	/* Seed our default options */	ifo = xzalloc(sizeof(*ifo));	ifo->options |= DHCPCD_GATEWAY | DHCPCD_DAEMONISE | DHCPCD_LINK;	ifo->options |= DHCPCD_ARP | DHCPCD_IPV4LL;	ifo->options |= DHCPCD_IPV6RS | DHCPCD_IPV6RA_REQRDNSS;	ifo->timeout = DEFAULT_TIMEOUT;	ifo->reboot = DEFAULT_REBOOT;	ifo->metric = -1;	strlcpy(ifo->script, SCRIPT, sizeof(ifo->script));	gethostname(ifo->hostname, HOSTNAME_MAX_LEN);	/* Ensure that the hostname is NULL terminated */	ifo->hostname[HOSTNAME_MAX_LEN] = '/0';	if (strcmp(ifo->hostname, "(none)") == 0 ||	    strcmp(ifo->hostname, "localhost") == 0)		ifo->hostname[0] = '/0';	platform = hardware_platform();#ifndef ANDROID	if (uname(&utn) == 0)		ifo->vendorclassid[0] = snprintf((char *)ifo->vendorclassid + 1,		    VENDORCLASSID_MAX_LEN,	            "%s-%s:%s-%s:%s%s%s", PACKAGE, VERSION,		    utn.sysname, utn.release, utn.machine,		    platform ? ":" : "", platform ? platform : "");	else#endif		ifo->vendorclassid[0] = snprintf((char *)ifo->vendorclassid + 1,		    VENDORCLASSID_MAX_LEN, "%s-%s", PACKAGE, VERSION);	/* Parse our options file */	f = fopen(file ? file : CONFIG, "r");	if (f == NULL) {		if (file != NULL)			syslog(LOG_ERR, "fopen `%s': %m", file);		return ifo;	}	while ((line = get_line(f))) {		option = strsep(&line, " /t");		/* Trim trailing whitespace */		if (line && *line) {			p = line + strlen(line) - 1;			while (p != line &&			    (*p == ' ' || *p == '/t') &&			    *(p - 1) != '//')				*p-- = '/0';		}		/* Start of an interface block, skip if not ours */		if (strcmp(option, "interface") == 0) {			if (ifname && line && strcmp(line, ifname) == 0)				skip = 0;			else				skip = 1;			continue;		}		/* Start of an ssid block, skip if not ours */		if (strcmp(option, "ssid") == 0) {			if (ssid && line && strcmp(line, ssid) == 0)				skip = 0;			else				skip = 1;			continue;		}		/* Start of a profile block, skip if not ours */		if (strcmp(option, "profile") == 0) {			if (profile && line && strcmp(line, profile) == 0) {				skip = 0;				have_profile = 1;			} else				skip = 1;			continue;		}		if (skip)			continue;		parse_config_line(ifo, option, line);	}	fclose(f);	if (profile && !have_profile) {		free_options(ifo);		errno = ENOENT;		ifo = NULL;	}	/* Terminate the encapsulated options */	if (ifo && ifo->vendor[0] && !(ifo->options & DHCPCD_VENDORRAW)) {		ifo->vendor[0]++;		ifo->vendor[ifo->vendor[0]] = DHO_END;	}	return ifo;//.........这里部分代码省略.........
开发者ID:0omega,项目名称:platform_external_dhcpcd,代码行数:101,


示例9: get_clients_from_parent

/* @internal * @brief During gateway restart, connects to the parent process via the internal socket * Downloads from it the active client list */void get_clients_from_parent(void) {	int sock;	struct sockaddr_un	sa_un;	s_config * config = NULL;	char linebuffer[MAX_BUF];	int len = 0;	char *running1 = NULL;	char *running2 = NULL;	char *token1 = NULL;	char *token2 = NULL;	char onechar;	char *command = NULL;	char *key = NULL;	char *value = NULL;	t_client * client = NULL;	t_client * lastclient = NULL;	config = config_get_config();	debug(LOG_INFO, "Connecting to parent to download clients");	/* Connect to socket */	sock = socket(AF_UNIX, SOCK_STREAM, 0);	memset(&sa_un, 0, sizeof(sa_un));	sa_un.sun_family = AF_UNIX;	strncpy(sa_un.sun_path, config->internal_sock, (sizeof(sa_un.sun_path) - 1));	if (connect(sock, (struct sockaddr *)&sa_un, strlen(sa_un.sun_path) + sizeof(sa_un.sun_family))) {		debug(LOG_ERR, "Failed to connect to parent (%s) - client list not downloaded", strerror(errno));		return;	}	debug(LOG_INFO, "Connected to parent.  Downloading clients");	LOCK_CLIENT_LIST();	command = NULL;	memset(linebuffer, 0, sizeof(linebuffer));	len = 0;	client = NULL;	/* Get line by line */	while (read(sock, &onechar, 1) == 1) {		if (onechar == '/n') {			/* End of line */			onechar = '/0';		}		linebuffer[len++] = onechar;		if (!onechar) {			/* We have a complete entry in linebuffer - parse it */			debug(LOG_DEBUG, "Received from parent: [%s]", linebuffer);			running1 = linebuffer;			while ((token1 = strsep(&running1, "|")) != NULL) {				if (!command) {					/* The first token is the command */					command = token1;				}				else {				/* Token1 has something like "foo=bar" */					running2 = token1;					key = value = NULL;					while ((token2 = strsep(&running2, "=")) != NULL) {						if (!key) {							key = token2;						}						else if (!value) {							value = token2;						}					}				}				if (strcmp(command, "CLIENT") == 0) {					/* This line has info about a client in the client list */					if (!client) {						/* Create a new client struct */						client = safe_malloc(sizeof(t_client));						memset(client, 0, sizeof(t_client));					}				}				if (key && value) {					if (strcmp(command, "CLIENT") == 0) {						/* Assign the key into the appropriate slot in the connection structure */						if (strcmp(key, "ip") == 0) {							client->ip = safe_strdup(value);						}						else if (strcmp(key, "mac") == 0) {							client->mac = safe_strdup(value);						}						else if (strcmp(key, "token") == 0) {							client->token = safe_strdup(value);						}						else if (strcmp(key, "fw_connection_state") == 0) {							client->fw_connection_state = atoi(value);						}						else if (strcmp(key, "fd") == 0) {//.........这里部分代码省略.........
开发者ID:ashleyhunt,项目名称:wifidog-oauth,代码行数:101,


示例10: parse_string

万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。