Exemplo n.º 1
0
struct pkg_format_node *
pkg_format_parse(const char *fmt, struct dpkg_error *err)
{
	struct pkg_format_node *head;
	struct pkg_format_node *cur;
	const char *fmtend;

	head = cur = NULL;

	while (*fmt) {
		if (cur)
			cur = cur->next = pkg_format_node_new();
		else
			head = cur = pkg_format_node_new();

		if (fmt[0] == '$' && fmt[1] == '{') {
			fmtend = strchr(fmt, '}');
			if (!fmtend) {
				dpkg_put_error(err, _("missing closing brace"));
				pkg_format_free(head);
				return NULL;
			}

			if (!parsefield(cur, fmt + 2, fmtend - 1, err)) {
				pkg_format_free(head);
				return NULL;
			}
			fmt = fmtend + 1;
		} else {
			fmtend = fmt;
			do {
				fmtend += 1;
				fmtend = strchr(fmtend, '$');
			} while (fmtend && fmtend[1] != '{');

			if (!fmtend)
				fmtend = fmt + strlen(fmt);

			if (!parsestring(cur, fmt, fmtend - 1, err)) {
				pkg_format_free(head);
				return NULL;
			}
			fmt = fmtend;
		}
	}

	if (!head)
		dpkg_put_error(err, _("may not be empty string"));

	return head;
}
Exemplo n.º 2
0
struct lstitem *
parseformat(const char *fmt)
{
	struct lstitem *head;
	struct lstitem *cur;
	const char *fmtend;

	head = cur = NULL;

	while (*fmt) {
		if (cur)
			cur = cur->next = alloclstitem();
		else
			head = cur = alloclstitem();

		if (fmt[0] == '$' && fmt[1] == '{') {
			fmtend = strchr(fmt, '}');
			if (!fmtend) {
				fprintf(stderr,
				      _("Closing brace missing in format\n"));
				freeformat(head);
				return NULL;
			}

			if (!parsefield(cur, fmt + 2, fmtend - 1)) {
				freeformat(head);
				return NULL;
			}
			fmt = fmtend + 1;
		} else {
			fmtend = fmt;
			do {
				fmtend += 1;
				fmtend = strchr(fmtend, '$');
			} while (fmtend && fmtend[1] != '{');

			if (!fmtend)
				fmtend = fmt + strlen(fmt);

			if (!parsestring(cur, fmt, fmtend - 1)) {
				freeformat(head);
				return NULL;
			}
			fmt = fmtend;
		}
	}

	return head;
}
Exemplo n.º 3
0
/*
 * Scan mail header.
 */
void scanheader (FILE *fd)
{
	register char *p;
	register c;

	freeheader ();
	for (;;) {
		/* get line from file */
		p = gethline (fd);

		/* end of header */
		if (! p)
			break;

		/* handle multiline header fields */
		c = getc (fd);
		while (c == ' ' || c == '\t') {
			register char *s, *p2, *np;
			int len;

			p2 = gethline (fd);
			if (! p2)
				break;
			for (s=p2; *s==' ' || *s=='\t'; ++s);
			len = strlen (p) + strlen (s) + 1;
			if (len < 511) {
				np = malloc ((unsigned) len + 1);
				if (! np) {
					error ("out of memory");
					quit ();
				}
				strcpy (np, p);
				strcat (np, " ");
				strcat (np, s);
				free (p);
				p = np;
			}
			free (p2);
			c = getc (fd);
		}
		ungetc (c, fd);

		parsefield (p);

		free (p);
	}
}
Exemplo n.º 4
0
checkindecl(gk_word *Gkword)
{
	int rval;
	int hits = 0;
	int nstems = 0;
	int i;
	int sawstems = 0;
	char *keys;
	char keybuf[LONGSTRING];
	char workword[MAXWORDSIZE];
	char * parsefield();
	char stemkeys[LONGSTRING];
	char tmpword[MAXWORDSIZE];
	register char * sp;
	
/*
	keybuf = (char *)malloc((size_t)LONGSTRING);
	workword = (char *)malloc((size_t)MAXWORDSIZE);
*/
	if( (prntflags_of(Gkword) & VERBS_ONLY ) ) return(0);
	Xstrncpy(tmpword,workword_of(Gkword),MAXWORDSIZE);

	keys = keybuf;
	rval = chckindecl(tmpword,keys);
/*
printf("rval %d workword [%s] keys [%s]\n", rval, workword, keys );
*/
	if( ! rval ) {
		goto finish;
	}
	while(*keys) {	
	sp = keys;
		
/*
		sp = parsefield(sp,tmpword,':');
*/
		sp = parsefield(sp,workword,':',MAXWORDSIZE);
		if( ! workword[0] ) Xstrncpy(workword,tmpword,MAXWORDSIZE);

/*
		if( tmpword[0] ) set_workword(Gkword,tmpword);
*/
		sp = parsefield(sp,lemma_of(Gkword),':',MAXWORDSIZE);
		sp = parsefield(sp,stemkeys,' ',LONGSTRING);
		subchar(stemkeys,':',' ');

/*	
		Xstrncpy(workword,workword_of(Gkword),MAXWORDSIZE);
*/
		set_stem(Gkword,workword );
		hits += IndeclWorks(Gkword,stemkeys);
		while(*keys && ! isspace(*keys) ) keys++;
		while(isspace(*keys)) keys++;

	}
	finish:

/*
		xFree(keybuf,"keybuf");
		xFree(workword,"workword");
		keybuf = workword = NULL;
*/

	return(hits);
}