Plan 9 from Bell Labs’s /usr/web/sources/contrib/quanstro/root/sys/src/cmd/upas/common/flags.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include "common.h"

static uchar flagtab[] = {
	'a',	Fanswered,
	'D',	Fdeleted,
	'd',	Fdraft,
	'f',	Fflagged,
	'r',	Frecent,
	's',	Fseen,
	'S',	Fstored,
};

char*
flagbuf(char *buf, int flags)
{
	char *p, c;
	int i;

	p = buf;
	for(i = 0; i < nelem(flagtab); i += 2){
		c = '-';
		if(flags & flagtab[i+1])
			c = flagtab[i];
		*p++ = c;
	}
	*p = 0;
	return buf;
}

int
buftoflags(char *p)
{
	uchar flags;
	int i;

	flags = 0;
	for(i = 0; i < nelem(flagtab); i += 2)
		if(p[i>>1] == flagtab[i])
			flags |= flagtab[i + 1];
	return flags;
}

char*
txflags(char *p, uchar *flags)
{
	uchar neg, f, c, i;

	for(;;){
		neg = 0;
		if((c = *p++) == '-'){
			neg = 1;
			c = *p++;
		}
		if(c == 0)
			return nil;
		for(i = 0;; i += 2){
			if(i == nelem(flagtab))
				return "bad flag";
			if(c == flagtab[i]){
				f = flagtab[i+1];
				break;
			}
		}
		if(neg)
			*flags &= ~f;
		else
			*flags |= f;
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].