Просмотр исходного кода

introduce uchar, ushort & uint typedefs

Oswald Buddenhagen 10 лет назад
Родитель
Сommit
42cedc8f81
8 измененных файлов с 54 добавлено и 50 удалено
  1. 5 1
      src/common.h
  2. 2 2
      src/config.c
  3. 4 4
      src/driver.h
  4. 19 19
      src/drv_imap.c
  5. 7 7
      src/drv_maildir.c
  6. 8 8
      src/sync.c
  7. 1 1
      src/sync.h
  8. 8 8
      src/util.c

+ 5 - 1
src/common.h

@@ -29,6 +29,10 @@
 #include <stdarg.h>
 #include <stdio.h>
 
+typedef unsigned char uchar;
+typedef unsigned short ushort;
+typedef unsigned int uint;
+
 #define as(ar) (sizeof(ar)/sizeof(ar[0]))
 
 #define __stringify(x) #x
@@ -119,7 +123,7 @@ int map_name( const char *arg, char **result, int reserve, const char *in, const
 void sort_ints( int *arr, int len );
 
 void arc4_init( void );
-unsigned char arc4_getbyte( void );
+uchar arc4_getbyte( void );
 
 int bucketsForSize( int size );
 

+ 2 - 2
src/config.c

@@ -45,7 +45,7 @@ get_arg( conffile_t *cfile, int required, int *comment )
 
 	p = cfile->rest;
 	assert( p );
-	while ((c = *p) && isspace( (unsigned char) c ))
+	while ((c = *p) && isspace( (uchar)c ))
 		p++;
 	if (!c || c == '#') {
 		if (comment)
@@ -65,7 +65,7 @@ get_arg( conffile_t *cfile, int required, int *comment )
 				escaped = 1;
 			else if (c == '"')
 				quoted ^= 1;
-			else if (!quoted && isspace( (unsigned char) c ))
+			else if (!quoted && isspace( (uchar)c ))
 				break;
 			else
 				*t++ = c;

+ 4 - 4
src/driver.h

@@ -35,7 +35,7 @@ typedef struct store_conf {
 	const char *flat_delim;
 	const char *map_inbox;
 	const char *trash;
-	unsigned max_size; /* off_t is overkill */
+	uint max_size; /* off_t is overkill */
 	char trash_remote_new, trash_only_new;
 } store_conf_t;
 
@@ -62,7 +62,7 @@ typedef struct message {
 	/* string_list_t *keywords; */
 	size_t size; /* zero implies "not fetched" */
 	int uid;
-	unsigned char flags, status;
+	uchar flags, status;
 	char tuid[TUIDL];
 } message_t;
 
@@ -90,7 +90,7 @@ typedef struct store {
 	message_t *msgs; /* own */
 	int uidvalidity;
 	int uidnext; /* from SELECT responses */
-	unsigned opts; /* maybe preset? */
+	uint opts; /* maybe preset? */
 	/* note that the following do _not_ reflect stats from msgs, but mailbox totals */
 	int count; /* # of messages */
 	int recent; /* # of recent messages - don't trust this beyond the initial read */
@@ -109,7 +109,7 @@ typedef struct {
 	char *data;
 	int len;
 	time_t date;
-	unsigned char flags;
+	uchar flags;
 } msg_data_t;
 
 #define DRV_OK          0

+ 19 - 19
src/drv_imap.c

@@ -100,11 +100,11 @@ typedef struct imap_store {
 	int ref_count;
 	/* trash folder's existence is not confirmed yet */
 	enum { TrashUnknown, TrashChecking, TrashKnown } trashnc;
-	unsigned got_namespace:1;
+	uint got_namespace:1;
 	char *delimiter; /* hierarchy delimiter */
 	list_t *ns_personal, *ns_other, *ns_shared; /* NAMESPACE info */
 	message_t **msgapp; /* FETCH results */
-	unsigned caps; /* CAPABILITY results */
+	uint caps; /* CAPABILITY results */
 	string_list_t *auth_mechs;
 	parse_list_state_t parse_list_sts;
 	/* command queue */
@@ -591,7 +591,7 @@ next_arg( char **ps )
 	s = *ps;
 	if (!s)
 		return 0;
-	while (isspace( (unsigned char)*s ))
+	while (isspace( (uchar)*s ))
 		s++;
 	if (!*s) {
 		*ps = 0;
@@ -613,7 +613,7 @@ next_arg( char **ps )
 	} else {
 		ret = s;
 		while ((c = *s)) {
-			if (isspace( (unsigned char)c )) {
+			if (isspace( (uchar)c )) {
 				*s++ = 0;
 				break;
 			}
@@ -684,7 +684,7 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts )
 	if (!s)
 		return LIST_BAD;
 	for (;;) {
-		while (isspace( (unsigned char)*s ))
+		while (isspace( (uchar)*s ))
 			s++;
 		if (sts->level && *s == ')') {
 			s++;
@@ -751,7 +751,7 @@ parse_imap_list( imap_store_t *ctx, char **sp, parse_list_state_t *sts )
 		} else {
 			/* atom */
 			p = s;
-			for (; *s && !isspace( (unsigned char)*s ); s++)
+			for (; *s && !isspace( (uchar)*s ); s++)
 				if (sts->level && *s == ')')
 					break;
 			cur->len = s - p;
@@ -876,7 +876,7 @@ parse_fetch_rsp( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED )
 	msg_data_t *msgdata;
 	struct imap_cmd *cmdp;
 	int uid = 0, mask = 0, status = 0, size = 0;
-	unsigned i;
+	uint i;
 	time_t date = 0;
 
 	if (!is_list( list )) {
@@ -1000,7 +1000,7 @@ static void
 parse_capability( imap_store_t *ctx, char *cmd )
 {
 	char *arg;
-	unsigned i;
+	uint i;
 
 	free_string_list( ctx->auth_mechs );
 	ctx->auth_mechs = 0;
@@ -1052,7 +1052,7 @@ parse_response_code( imap_store_t *ctx, struct imap_cmd *cmd, char *s )
 		/* RFC2060 says that these messages MUST be displayed
 		 * to the user
 		 */
-		for (; isspace( (unsigned char)*p ); p++);
+		for (; isspace( (uchar)*p ); p++);
 		error( "*** IMAP ALERT *** %s\n", p );
 	} else if (cmd && !strcmp( "APPENDUID", arg )) {
 		if (!(arg = next_arg( &s )) ||
@@ -1743,8 +1743,8 @@ process_sasl_interact( sasl_interact_t *interact, imap_server_conf_t *srvc )
 }
 
 static int
-process_sasl_step( imap_store_t *ctx, int rc, const char *in, unsigned in_len,
-                   sasl_interact_t *interact, const char **out, unsigned *out_len )
+process_sasl_step( imap_store_t *ctx, int rc, const char *in, uint in_len,
+                   sasl_interact_t *interact, const char **out, uint *out_len )
 {
 	imap_server_conf_t *srvc = ((imap_store_conf_t *)ctx->gen.conf)->server;
 
@@ -1765,11 +1765,11 @@ process_sasl_step( imap_store_t *ctx, int rc, const char *in, unsigned in_len,
 }
 
 static int
-decode_sasl_data( const char *prompt, char **in, unsigned *in_len )
+decode_sasl_data( const char *prompt, char **in, uint *in_len )
 {
 	if (prompt) {
 		int rc;
-		unsigned prompt_len = strlen( prompt );
+		uint prompt_len = strlen( prompt );
 		/* We're decoding, the output will be shorter than prompt_len. */
 		*in = nfmalloc( prompt_len );
 		rc = sasl_decode64( prompt, prompt_len, *in, prompt_len, in_len );
@@ -1786,10 +1786,10 @@ decode_sasl_data( const char *prompt, char **in, unsigned *in_len )
 }
 
 static int
-encode_sasl_data( const char *out, unsigned out_len, char **enc, unsigned *enc_len )
+encode_sasl_data( const char *out, uint out_len, char **enc, uint *enc_len )
 {
 	int rc;
-	unsigned enc_len_max = ((out_len + 2) / 3) * 4 + 1;
+	uint enc_len_max = ((out_len + 2) / 3) * 4 + 1;
 	*enc = nfmalloc( enc_len_max );
 	rc = sasl_encode64( out, out_len, *enc, enc_len_max, enc_len );
 	if (rc != SASL_OK) {
@@ -1804,7 +1804,7 @@ static int
 do_sasl_auth( imap_store_t *ctx, struct imap_cmd *cmdp ATTR_UNUSED, const char *prompt )
 {
 	int rc, ret;
-	unsigned in_len, out_len, enc_len;
+	uint in_len, out_len, enc_len;
 	const char *out;
 	char *in, *enc;
 	sasl_interact_t *interact = NULL;
@@ -1851,7 +1851,7 @@ done_sasl_auth( imap_store_t *ctx, struct imap_cmd *cmd ATTR_UNUSED, int respons
 	if (response == RESP_OK && ctx->sasl_cont) {
 		sasl_interact_t *interact = NULL;
 		const char *out;
-		unsigned out_len;
+		uint out_len;
 		int rc = sasl_client_step( ctx->sasl, NULL, 0, &interact, &out, &out_len );
 		if (process_sasl_step( ctx, rc, NULL, 0, interact, &out, &out_len ) < 0)
 			warn( "Warning: SASL reported failure despite successful IMAP authentication. Ignoring...\n" );
@@ -1904,7 +1904,7 @@ imap_open_store_authenticate2( imap_store_t *ctx )
 #ifdef HAVE_LIBSASL
 	if (saslend != saslmechs) {
 		int rc;
-		unsigned out_len = 0;
+		uint out_len = 0;
 		char *enc = NULL;
 		const char *gotmech = NULL, *out = NULL;
 		sasl_interact_t *interact = NULL;
@@ -2198,7 +2198,7 @@ static int
 imap_make_flags( int flags, char *buf )
 {
 	const char *s;
-	unsigned i, d;
+	uint i, d;
 
 	for (i = d = 0; i < as(Flags); i++)
 		if (flags & (1 << i)) {

+ 7 - 7
src/drv_maildir.c

@@ -85,12 +85,12 @@ static int MaildirCount;
 
 static const char Flags[] = { 'D', 'F', 'R', 'S', 'T' };
 
-static unsigned char
+static uchar
 maildir_parse_flags( const char *info_prefix, const char *base )
 {
 	const char *s;
-	unsigned i;
-	unsigned char flags;
+	uint i;
+	uchar flags;
 
 	flags = 0;
 	if ((s = strstr( base, info_prefix )))
@@ -312,7 +312,7 @@ static const char *subdirs[] = { "cur", "new", "tmp" };
 typedef struct {
 	char *base;
 	int size;
-	unsigned uid:31, recent:1;
+	uint uid:31, recent:1;
 	char tuid[TUIDL];
 } msg_t;
 
@@ -835,7 +835,7 @@ maildir_scan( maildir_store_t *ctx, msglist_t *msglist )
 				}
 				entry->uid = uid;
 				if ((u = strstr( entry->base, ",U=" )))
-					for (ru = u + 3; isdigit( (unsigned char)*ru ); ru++);
+					for (ru = u + 3; isdigit( (uchar)*ru ); ru++);
 				else
 					u = ru = strchr( entry->base, conf->info_delimiter );
 				fnl = (u ?
@@ -1187,7 +1187,7 @@ maildir_fetch_msg( store_t *gctx, message_t *gmsg, msg_data_t *data,
 static int
 maildir_make_flags( char info_delimiter, int flags, char *buf )
 {
-	unsigned i, d;
+	uint i, d;
 
 	buf[0] = info_delimiter;
 	buf[1] = '2';
@@ -1309,7 +1309,7 @@ maildir_set_flags( store_t *gctx, message_t *gmsg, int uid ATTR_UNUSED, int add,
 	maildir_store_t *ctx = (maildir_store_t *)gctx;
 	maildir_message_t *msg = (maildir_message_t *)gmsg;
 	char *s, *p;
-	unsigned i;
+	uint i;
 	int j, ret, ol, fl, bbl, bl, tl;
 	char buf[_POSIX_PATH_MAX], nbuf[_POSIX_PATH_MAX];
 

+ 8 - 8
src/sync.c

@@ -75,7 +75,7 @@ static const char Flags[] = { 'D', 'F', 'R', 'S', 'T' };
 static int
 parse_flags( const char *buf )
 {
-	unsigned flags, i, d;
+	uint flags, i, d;
 
 	for (flags = i = d = 0; i < as(Flags); i++)
 		if (buf[d] == Flags[i]) {
@@ -88,7 +88,7 @@ parse_flags( const char *buf )
 static int
 make_flags( int flags, char *buf )
 {
-	unsigned i, d;
+	uint i, d;
 
 	for (i = d = 0; i < as(Flags); i++)
 		if (flags & (1 << i))
@@ -105,14 +105,14 @@ make_flags( int flags, char *buf )
 #define S_NEXPIRE      (1<<6)  /* temporary: new expiration state */
 #define S_DELETE       (1<<7)  /* ephemeral: flags propagation is a deletion */
 
-#define mvBit(in,ib,ob) ((unsigned char)(((unsigned)in) * (ob) / (ib)))
+#define mvBit(in,ib,ob) ((uchar)(((uint)in) * (ob) / (ib)))
 
 typedef struct sync_rec {
 	struct sync_rec *next;
 	/* string_list_t *keywords; */
 	int uid[2]; /* -2 = pending (use tuid), -1 = skipped (too big), 0 = expired */
 	message_t *msg[2];
-	unsigned char status, flags, aflags[2], dflags[2];
+	uchar status, flags, aflags[2], dflags[2];
 	char tuid[TUIDL];
 } sync_rec_t;
 
@@ -1126,7 +1126,7 @@ box_loaded( int sts, void *aux )
 	flag_vars_t *fv;
 	int uid, no[2], del[2], alive, todel, t1, t2;
 	int sflags, nflags, aflags, dflags, nex;
-	unsigned hashsz, idx;
+	uint hashsz, idx;
 	char fbuf[16]; /* enlarge when support for keywords is added */
 
 	if (check_ret( sts, aux ))
@@ -1147,7 +1147,7 @@ box_loaded( int sts, void *aux )
 		if (srec->status & S_DEAD)
 			continue;
 		uid = srec->uid[t];
-		idx = (unsigned)((unsigned)uid * 1103515245U) % hashsz;
+		idx = (uint)((uint)uid * 1103515245U) % hashsz;
 		while (srecmap[idx].uid)
 			if (++idx == hashsz)
 				idx = 0;
@@ -1162,7 +1162,7 @@ box_loaded( int sts, void *aux )
 			make_flags( tmsg->flags, fbuf );
 			printf( svars->ctx[t]->opts & OPEN_SIZE ? "  message %5d, %-4s, %6lu: " : "  message %5d, %-4s: ", uid, fbuf, tmsg->size );
 		}
-		idx = (unsigned)((unsigned)uid * 1103515245U) % hashsz;
+		idx = (uint)((uint)uid * 1103515245U) % hashsz;
 		while (srecmap[idx].uid) {
 			if (srecmap[idx].uid == uid) {
 				srec = srecmap[idx].srec;
@@ -1403,7 +1403,7 @@ box_loaded( int sts, void *aux )
 			}
 		}
 		debug( "%d excess messages remain\n", todel );
-		if (svars->chan->expire_unread < 0 && (unsigned)alive * 2 > svars->chan->max_messages) {
+		if (svars->chan->expire_unread < 0 && (uint)alive * 2 > svars->chan->max_messages) {
 			error( "%s: %d unread messages in excess of MaxMessages (%d).\n"
 			       "Please set ExpireUnread to decide outcome. Skipping mailbox.\n",
 			       svars->orig_name[S], alive, svars->chan->max_messages );

+ 1 - 1
src/sync.h

@@ -50,7 +50,7 @@ typedef struct channel_conf {
 	char *sync_state;
 	string_list_t *patterns;
 	int ops[2];
-	unsigned max_messages; /* for slave only */
+	uint max_messages; /* for slave only */
 	signed char expire_unread;
 	char use_internal_date;
 } channel_conf_t;

+ 8 - 8
src/util.c

@@ -138,7 +138,7 @@ sys_error( const char *msg, ... )
 
 	flushn();
 	va_start( va, msg );
-	if ((unsigned)vsnprintf( buf, sizeof(buf), msg, va ) >= sizeof(buf))
+	if ((uint)vsnprintf( buf, sizeof(buf), msg, va ) >= sizeof(buf))
 		oob();
 	va_end( va );
 	perror( buf );
@@ -311,7 +311,7 @@ nfsnprintf( char *buf, int blen, const char *fmt, ... )
 	va_list va;
 
 	va_start( va, fmt );
-	if (blen <= 0 || (unsigned)(ret = vsnprintf( buf, blen, fmt, va )) >= (unsigned)blen)
+	if (blen <= 0 || (uint)(ret = vsnprintf( buf, blen, fmt, va )) >= (uint)blen)
 		oob();
 	va_end( va );
 	return ret;
@@ -518,14 +518,14 @@ sort_ints( int *arr, int len )
 
 
 static struct {
-	unsigned char i, j, s[256];
+	uchar i, j, s[256];
 } rs;
 
 void
 arc4_init( void )
 {
 	int i, fd;
-	unsigned char j, si, dat[128];
+	uchar j, si, dat[128];
 
 	if ((fd = open( "/dev/urandom", O_RDONLY )) < 0 && (fd = open( "/dev/random", O_RDONLY )) < 0) {
 		error( "Fatal: no random number source available.\n" );
@@ -551,10 +551,10 @@ arc4_init( void )
 		arc4_getbyte();
 }
 
-unsigned char
+uchar
 arc4_getbyte( void )
 {
-	unsigned char si, sj;
+	uchar si, sj;
 
 	rs.i++;
 	si = rs.s[rs.i];
@@ -565,7 +565,7 @@ arc4_getbyte( void )
 	return rs.s[(si + sj) & 0xff];
 }
 
-static const unsigned char prime_deltas[] = {
+static const uchar prime_deltas[] = {
     0,  0,  1,  3,  1,  5,  3,  3,  1,  9,  7,  5,  3, 17, 27,  3,
     1, 29,  3, 21,  7, 17, 15,  9, 43, 35, 15,  0,  0,  0,  0,  0
 };
@@ -665,7 +665,7 @@ del_fd( int fd )
 }
 
 #define shifted_bit(in, from, to) \
-	(((unsigned)(in) & from) \
+	(((uint)(in) & from) \
 		/ (from > to ? from / to : 1) \
 		* (to > from ? to / from : 1))