1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-20 16:22:38 -05:00

Clean up splint warnings:

- Inconsistencies between defines.h and estruct.h.
- Review scope of termio local variables.
- Type mismatch in utf8.
This commit is contained in:
Renaud 2015-02-16 13:41:59 +08:00
parent e2be62323b
commit 4b2c50f6d2
4 changed files with 45 additions and 25 deletions

View File

@ -43,7 +43,7 @@ ifeq ($(uname_S),Darwin)
DEFINES=-DAUTOCONF -DPOSIX -DSYSV -D_DARWIN_C_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_XOPEN_SOURCE=600
endif
ifeq ($(uname_S),CYGWIN)
DEFINES=-DAUTOCONF -DCYGWIN -DPROGRAM=$(PROGRAM)
DEFINES=-DAUTOCONF -DCYGWIN -DSYSV -DPROGRAM=$(PROGRAM)
LIBS=-lcurses
endif
ifeq ($(uname_S),MINGW32)
@ -86,6 +86,9 @@ lint: ${SRC}
lint ${LFLAGS} ${SRC} >lintout
cat lintout
splint:
splint $(DEFINES) $(SRC) -booltype boolean -booltrue TRUE -boolfalse FALSE +posixlib
errs:
@rm -f makeout
make $(PROGRAM) >makeout

View File

@ -1,3 +1,9 @@
/* defines.h -- */
#ifndef __DEFINES_H__
#define __DEFINES_H__
/* Must define one of
VMS | V7 | USG | BSD | MSDOS
*/
@ -18,3 +24,7 @@
if smaller font or portrait orientation limit to 400x150 */
#define MAXCOL 400
#define MAXROW 150
#endif
/* end of defines.h */

View File

@ -20,7 +20,6 @@
#include "utf8.h"
/* rfi */
#include <unistd.h>
#include <sys/ioctl.h>
@ -58,12 +57,12 @@ int nxtchar = -1; /* character held from type ahead */
#include <signal.h>
#include <termio.h>
#include <fcntl.h>
int kbdflgs; /* saved keyboard fd flags */
int kbdpoll; /* in O_NDELAY mode */
int kbdqp; /* there is a char in kbdq */
char kbdq; /* char we've already read */
struct termio otermio; /* original terminal characteristics */
struct termio ntermio; /* charactoristics to use inside */
static int kbdflgs ; /* saved keyboard fd flags */
static int kbdpoll ; /* in O_NDELAY mode */
static int kbdqp ; /* there is a char in kbdq */
static char kbdq ; /* char we've already read */
static struct termio otermio ; /* original terminal characteristics */
static struct termio ntermio ; /* characteristics to use inside */
#if XONXOFF
#define XXMASK 0016000
#endif

42
utf8.c
View File

@ -1,3 +1,5 @@
/* utf8.c -- implements utf8.h, converts between unicode and UTF-8 */
#include "utf8.h"
#include <assert.h>
@ -18,8 +20,8 @@
unsigned utf8_to_unicode(char *line, unsigned index, unsigned len, unicode_t *res)
{
unicode_t value ;
unsigned char c = line[index];
unsigned bytes, mask, i;
unsigned c = line[ index] & 0xFFU ;
unsigned bytes, mask, i;
*res = c;
@ -36,12 +38,12 @@ unsigned utf8_to_unicode(char *line, unsigned index, unsigned len, unicode_t *re
/* Ok, it's 11xxxxxx, do a stupid decode */
mask = 0x20;
bytes = 2;
while (c & mask) {
while( (c & mask) != 0) {
bytes++;
mask >>= 1;
}
/* bytes is in range [2..4] */
/* bytes is in range [2..4] as c was in range [C2..F4] */
len -= index;
if (bytes > len)
return 1;
@ -51,7 +53,7 @@ unsigned utf8_to_unicode(char *line, unsigned index, unsigned len, unicode_t *re
/* Ok, do the bytes */
line += index;
for (i = 1; i < bytes; i++) {
c = line[i];
c = line[i] & 0xFFU ;
if ((c & 0xc0) != 0x80)
return 1;
value = (value << 6) | (c & 0x3f);
@ -85,7 +87,7 @@ static void reverse_string(char *begin, char *end)
* overlong utf-8 sequences.
*/
unsigned unicode_to_utf8( unicode_t c, char *utf8) {
int bytes = 1 ;
unsigned bytes = 1 ;
assert( c <= 0x10FFFF) ;
@ -94,18 +96,24 @@ unsigned unicode_to_utf8( unicode_t c, char *utf8) {
c &= 0xFF ;
#endif
*utf8 = c ;
if (c > 0x7f) {
int prefix = 0x40;
char *p = utf8;
if( c <= 0x7f)
*utf8 = (char) c ;
else {
unsigned prefix = 0x40 ;
char *p = utf8 ;
do {
*p++ = 0x80 + (c & 0x3f);
bytes++;
prefix >>= 1;
c >>= 6;
*p++ = (char) (0x80 + (c & 0x3f)) ;
bytes++ ;
prefix >>= 1 ;
c >>= 6 ;
} while( c >= prefix) ;
*p = c - 2*prefix;
reverse_string(utf8, p);
*p = (char) (c - 2 * prefix) ;
reverse_string( utf8, p) ;
}
return bytes;
return bytes ;
}
/* end of utf8.c */