Skip to content

Commit

Permalink
Simplify use of signed vs unsigned.
Browse files Browse the repository at this point in the history
Fixes various compiler warnings. Unsigned chars are now restricted
to the UTF-8 and PatternMatcher functions.
  • Loading branch information
hishamhm committed Nov 13, 2014
1 parent 6c7f5b3 commit 691a747
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 70 deletions.
2 changes: 1 addition & 1 deletion Field.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int Field_run(Field* this, bool setCursor, bool* handled, bool* code) {
Display_move(this->y, this->x + this->labelLen + 2 + this->cursor);
Display_attrset(A_REVERSE);
if (this->cursor < Text_chars(curr->text)) {
const unsigned char* ch = Text_stringAt(curr->text, this->cursor);
const char* ch = Text_stringAt(curr->text, this->cursor);
Display_writeAtn(this->y, x + this->cursor, ch, UTF8_bytes(*ch));
} else {
Display_writeAtn(this->y, x + this->cursor, " ", 1);
Expand Down
8 changes: 4 additions & 4 deletions Highlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct ReadHighlightFileArgs_ {
};
struct MatchArgs_ {
const unsigned char* buffer;
const char* buffer;
int* attrs;
GraphNode* rules;
GraphNode* follows;
Expand Down Expand Up @@ -349,15 +349,15 @@ HighlightContext* Highlight_addContext(Highlight* this, char* open, char* close,
#define PAINT(_args, _here, _attr) do { _args->attrs[_args->attrsAt++] = _attr; _here = UTF8_forward(_here, 1); } while(0)

static inline void Highlight_tryMatch(Highlight* this, MatchArgs* args, bool paintUnmatched) {
const unsigned char* here = args->buffer;
const char* here = args->buffer;
intptr_t intColor;
bool eager;
intptr_t matchlen = args->match(args->rules, args->buffer, &intColor, &eager);
Color color = (Color) intColor;
assert(color >= 0 && color < Colors);
if (matchlen && (eager || ( !(isword(here[matchlen-1]) && isword(here[matchlen]))))) {
int attr = CRT_colors[color];
const unsigned char* nextStop = here + matchlen;
const char* nextStop = here + matchlen;
while (here < nextStop) {
PAINT(args, here, attr);
}
Expand Down Expand Up @@ -385,7 +385,7 @@ static inline void Highlight_tryMatch(Highlight* this, MatchArgs* args, bool pai
args->buffer = here;
}

void Highlight_setAttrs(Highlight* this, const unsigned char* buffer, int* attrs, int len, int y) {
void Highlight_setAttrs(Highlight* this, const char* buffer, int* attrs, int len, int y) {
MatchArgs args = {
.buffer = buffer,
.attrs = attrs,
Expand Down
22 changes: 11 additions & 11 deletions Line.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ void Line_display(Object* cast, RichString* str) {

Highlight_setAttrs(hl, this->text.data, hlAttrs, this->text.bytes, y + 1);

const unsigned char* start = Text_toString(this->text);
const char* start = Text_toString(this->text);
int attrIdx = 0;

for (const unsigned char* curr = start; *curr; ) {
for (const char* curr = start; *curr; ) {
int inIdx = curr - start;
if (*curr == '\t') {
int tabSize = tabWidth - (outIdx % tabWidth);
Expand Down Expand Up @@ -216,26 +216,26 @@ int Line_breakAt(Line* this, int at, bool doIndent) {
void Line_joinNext(Line* this) {
assert(this->super.next);
Line* next = (Line*) this->super.next;
Text_strcat(&(this->text), next->text);
(void) Text_strcat(&(this->text), next->text);
ListItem_remove((ListItem*) next);
}

static int lineToBufferFromTo(StringBuffer* str, Line* l, int xFrom, int xTo) {
static void lineToBufferFromTo(StringBuffer* str, Line* l, int xFrom, int xTo) {
const char* from = Text_stringAt(l->text, xFrom);
const char* to = Text_stringAt(l->text, xTo);
StringBuffer_addN(str, from, to - from);
}

static int lineToBufferFrom(StringBuffer* str, Line* l, int xFrom) {
const unsigned char* from = Text_stringAt(l->text, xFrom);
static void lineToBufferFrom(StringBuffer* str, Line* l, int xFrom) {
const char* from = Text_stringAt(l->text, xFrom);
StringBuffer_addN(str, from, Text_toString(l->text) + Text_bytes(l->text) - from);
}

static int lineToBufferTo(StringBuffer* str, Line* l, int xTo) {
static void lineToBufferTo(StringBuffer* str, Line* l, int xTo) {
StringBuffer_addN(str, Text_toString(l->text), Text_bytesUntil(l->text, xTo));
}

static int lineToBuffer(StringBuffer* str, Line* l) {
static void lineToBuffer(StringBuffer* str, Line* l) {
StringBuffer_addN(str, Text_toString(l->text), Text_bytes(l->text));
}

Expand Down Expand Up @@ -340,7 +340,7 @@ int* Line_unindent(Line* this, int lines, int indentSpaces) {
bool Line_insertBlock(Line* this, int x, Text block, int* newX, int* newY) {
// newY must contain the current value of y on input
int blockBytes = Text_bytes(block);
unsigned char* nl = memchr(block.data, '\n', block.bytes);
char* nl = memchr(block.data, '\n', block.bytes);
Line* at = this;
bool multiline = (nl);
if (!multiline) {
Expand All @@ -351,11 +351,11 @@ bool Line_insertBlock(Line* this, int x, Text block, int* newX, int* newY) {
Line_breakAt(this, x, 0);
Line* last = (Line*) this->super.next;
Text_insertString(&(this->text), x, block.data, lineLen);
unsigned char* walk = ++nl;
char* walk = ++nl;
(*newY)++;
while ( (nl = memchr(walk, '\n', blockBytes - (walk - block.data) )) ) {
lineLen = nl - walk;
char* text = malloc(lineLen+1);
char* text = (char*) malloc(lineLen+1);
text[lineLen] = '\0';
memcpy(text, walk, lineLen);
Line* newLine = Line_new(this->super.list, Text_new(text), this->context);
Expand Down
4 changes: 2 additions & 2 deletions Object.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ void Object_delete(Object* this) {
}

void Object_display(Object* this, RichString* out) {
unsigned char objAddress[50];
sprintf((char*)objAddress, "O:%p C:%p", (void*) this, (void*) this->class);
char objAddress[50];
sprintf(objAddress, "O:%p C:%p", (void*) this, (void*) this->class);
RichString_write(out, 0, objAddress);
}

Expand Down
11 changes: 7 additions & 4 deletions PatternMatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/*{
typedef int(*Method_PatternMatcher_match)(GraphNode*, const unsigned char*, intptr_t*, bool*);
typedef int(*Method_PatternMatcher_match)(GraphNode*, const char*, intptr_t*, bool*);
struct GraphNode_ {
unsigned char min;
Expand Down Expand Up @@ -181,7 +181,8 @@ void PatternMatcher_add(PatternMatcher* this, unsigned char* pattern, intptr_t v
}
}

bool PatternMatcher_partialMatch(GraphNode* node, unsigned char* input, int inputLen, char* rest, int restLen) {
bool PatternMatcher_partialMatch(GraphNode* node, const char* sinput, int inputLen, char* rest, int restLen) {
const unsigned char* input = (const unsigned char*) sinput;
int i = 0;
while (i < inputLen) {
node = GraphNode_follow(node, input[i]);
Expand All @@ -203,7 +204,8 @@ bool PatternMatcher_partialMatch(GraphNode* node, unsigned char* input, int inpu
return false;
}

int PatternMatcher_match(GraphNode* node, const unsigned char* input, intptr_t* value, bool* eager) {
int PatternMatcher_match(GraphNode* node, const char* sinput, intptr_t* value, bool* eager) {
const unsigned char* input = (const unsigned char*) sinput;
int i = 0;
int match = 0;
*value = 0;
Expand All @@ -221,7 +223,8 @@ int PatternMatcher_match(GraphNode* node, const unsigned char* input, intptr_t*
return match;
}

int PatternMatcher_match_toLower(GraphNode* node, const unsigned char* input, intptr_t* value, bool* eager) {
int PatternMatcher_match_toLower(GraphNode* node, const char* sinput, intptr_t* value, bool* eager) {
const unsigned char* input = (const unsigned char*) sinput;
int i = 0;
int match = 0;
*value = 0;
Expand Down
4 changes: 2 additions & 2 deletions Script.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static int Script_Buffer___newindex(lua_State* L) {
luaL_checkstring(L, 3);
size_t len;
const char* text = lua_tolstring(L, 3, &len);
Buffer_setLine(buffer, y, Text_new((unsigned char*)text));
Buffer_setLine(buffer, y, Text_new((char*) text));
}
return 0;
}
Expand Down Expand Up @@ -377,7 +377,7 @@ void Script_highlightFile(Highlight* this, const char* fileName) {
this->hasScript = callFunction(this->L, "highlight_file", fileName);
}

void Script_highlightLine(Highlight* this, const unsigned char* buffer, int* attrs, int len, int y) {
void Script_highlightLine(Highlight* this, const char* buffer, int* attrs, int len, int y) {
lua_State* L = this->L;
if (!this->hasScript)
return;
Expand Down
10 changes: 5 additions & 5 deletions TabManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void TabManager_resize(TabManager* this, int w, int h) {
this->redrawBar = true;
}

int TabManager_find(TabManager* this, const char* name) {
int TabManager_find(TabManager* this, char* name) {
int items = Vector_size(this->items);
for (int i = 0; i < items; i++) {
TabPage* page = (TabPage*) Vector_get(this->items, i);
Expand Down Expand Up @@ -340,7 +340,7 @@ char* TabManager_getPageName(TabManager* this, int i) {
}
}

void TabManager_load(TabManager* this, const char* fileName, int limit) {
void TabManager_load(TabManager* this, char* fileName, int limit) {
FILE* fd = Files_openHome("r", fileName, NULL);
if (fd) {
char line[4097];
Expand All @@ -350,8 +350,8 @@ void TabManager_load(TabManager* this, const char* fileName, int limit) {
char* enter = strrchr(line, '\n');
if (enter) *enter = '\0';
if (*line == '\0') continue;
if (TabManager_find(this, line) == -1 && access(line, F_OK) == 0) {
TabManager_add(this, line, NULL);
if (TabManager_find(this, (char*) line) == -1 && access(line, F_OK) == 0) {
TabManager_add(this, (char*) line, NULL);
limit--;
if (!limit) break;
}
Expand All @@ -361,7 +361,7 @@ void TabManager_load(TabManager* this, const char* fileName, int limit) {
}
}

void TabManager_save(TabManager* this, const char* fileName) {
void TabManager_save(TabManager* this, char* fileName) {
FILE* fd = Files_openHome("w", fileName, NULL);
if (fd) {
int items = Vector_size(this->items);
Expand Down
Loading

0 comments on commit 691a747

Please sign in to comment.