Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Aug 2, 2010
1 parent c7464db commit d48aebc
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 168 deletions.
166 changes: 83 additions & 83 deletions Buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,32 @@ struct FilePosition_ {

char* realpath(const char* path, char* resolved_path);

inline void Buffer_restorePosition(Buffer* this) {
char rpath[256];
realpath(this->fileName, rpath);

FILE* fd = Files_openHome("r", "filepos", NULL);
if (fd) {
int x, y;
char line[256];
while (!feof(fd)) {
fscanf(fd, "%d %d %255[^\n]\n", &x, &y, line);
if (strcmp(line, rpath) == 0) {

Line* line = (Line*) this->panel->items->head;
for (int i = 0; line && i <= y; i++) {
Line_display((Object*)line, NULL);
line = (Line*) line->super.next;
}

Buffer_goto(this, x, y);
break;
}
}
fclose(fd);
}
}

Buffer* Buffer_new(int x, int y, int w, int h, char* fileName, bool command) {
Buffer* this = (Buffer*) malloc(sizeof(Buffer));

Expand Down Expand Up @@ -162,32 +188,6 @@ Buffer* Buffer_new(int x, int y, int w, int h, char* fileName, bool command) {
return this;
}

inline void Buffer_restorePosition(Buffer* this) {
char rpath[256];
realpath(this->fileName, rpath);

FILE* fd = Files_openHome("r", "filepos", NULL);
if (fd) {
int x, y;
char line[256];
while (!feof(fd)) {
fscanf(fd, "%d %d %255[^\n]\n", &x, &y, line);
if (strcmp(line, rpath) == 0) {

Line* line = (Line*) this->panel->items->head;
for (int i = 0; line && i <= y; i++) {
Line_display((Object*)line, NULL);
line = (Line*) line->super.next;
}

Buffer_goto(this, x, y);
break;
}
}
fclose(fd);
}
}

inline void Buffer_storePosition(Buffer* this) {

char rpath[4097];
Expand Down Expand Up @@ -264,63 +264,6 @@ void Buffer_move(Buffer* this, int x) {
this->panel->needsRedraw = true;
}

void Buffer_draw(Buffer* this) {
Panel* p = this->panel;

if (this->wasSelecting && !this->selecting)
p->needsRedraw = true;

this->y = Panel_getSelectedIndex(p);
this->line = (Line*) Panel_getSelected(p);

Line_updateContext(this->line);

if (this->line->context != this->savedContext)
p->needsRedraw = true;
this->savedContext = this->line->context;

if (this->x > last_x(this))
this->x = last_x(this);

/* actual X position (expanding tabs, etc) */
int screenX = Line_widthUntil(this->line, this->x, this->tabWidth);

if (screenX - p->scrollH >= p->w) {
p->scrollH = screenX - p->w + 1;
p->needsRedraw = true;
} else if (screenX < p->scrollH) {
p->scrollH = screenX;
p->needsRedraw = true;
}

Buffer_highlightBracket(this);

p->cursorX = screenX - p->scrollH;
Panel_draw(p);

this->wasSelecting = this->selecting;
}

int Buffer_y(Buffer* this) {
return this->y;
}

char* Buffer_currentLine(Buffer* this) {
return this->line->text;
}

inline char* Buffer_getLine(Buffer* this, int i) {
Line* line = (Line*) Panel_get(this->panel, i);
if (line)
return line->text;
else
return NULL;
}

char* Buffer_previousLine(Buffer* this) {
return Buffer_getLine(this, this->y - 1);
}

static inline bool Buffer_matchBracket(char ch, char* oth, int* dir) {
switch (ch) {
case '(': *oth = ')'; *dir = 1; return true;
Expand Down Expand Up @@ -398,6 +341,63 @@ inline void Buffer_highlightBracket(Buffer* this) {
}
}

void Buffer_draw(Buffer* this) {
Panel* p = this->panel;

if (this->wasSelecting && !this->selecting)
p->needsRedraw = true;

this->y = Panel_getSelectedIndex(p);
this->line = (Line*) Panel_getSelected(p);

Line_updateContext(this->line);

if (this->line->context != this->savedContext)
p->needsRedraw = true;
this->savedContext = this->line->context;

if (this->x > last_x(this))
this->x = last_x(this);

/* actual X position (expanding tabs, etc) */
int screenX = Line_widthUntil(this->line, this->x, this->tabWidth);

if (screenX - p->scrollH >= p->w) {
p->scrollH = screenX - p->w + 1;
p->needsRedraw = true;
} else if (screenX < p->scrollH) {
p->scrollH = screenX;
p->needsRedraw = true;
}

Buffer_highlightBracket(this);

p->cursorX = screenX - p->scrollH;
Panel_draw(p);

this->wasSelecting = this->selecting;
}

int Buffer_y(Buffer* this) {
return this->y;
}

char* Buffer_currentLine(Buffer* this) {
return this->line->text;
}

inline char* Buffer_getLine(Buffer* this, int i) {
Line* line = (Line*) Panel_get(this->panel, i);
if (line)
return line->text;
else
return NULL;
}

char* Buffer_previousLine(Buffer* this) {
return Buffer_getLine(this, this->y - 1);
}

void Buffer_delete(Buffer* this) {
if (this->fileName) {
Buffer_storePosition(this);
Expand Down
62 changes: 16 additions & 46 deletions Highlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ static Color Highlight_translateColor(char* color) {
return NormalColor;
}

void Highlight_initScript(Highlight* this, const char* fileName) {
if (!this->hasScript)
return;
lua_getglobal(this->L, "highlight_file");
if (!lua_isfunction(this->L, -1))
return;
lua_pushstring(this->L, fileName);
int err = lua_pcall(this->L, 1, 0, 0);
// TODO ignore errors for now
lua_pop(this->L, lua_gettop(this->L));
}

Highlight* Highlight_new(const char* fileName, const char* firstLine, lua_State* L) {
Highlight* this = (Highlight*) malloc(sizeof(Highlight));
this->L = L;
Expand All @@ -101,50 +113,6 @@ void Highlight_delete(Highlight* this) {
free(this);
}

void Highlight_loadScript(Highlight* this, const char* scriptName) {
this->hasScript = false;
int dirEndsAt;
char* foundFile = Files_findFile("scripts/%s", scriptName, &dirEndsAt);
if (!foundFile) {
return;
}
char* foundDir = strdup(foundFile);
foundDir[dirEndsAt] = '\0';

lua_getglobal(this->L, "package");
lua_getfield(this->L, -1, "path");
int len;
const char* oldPackagePath = lua_tolstring(this->L, -1, &len);
len += strlen(foundDir) + 18; // ";scripts/?.lua\0"
char newPackagePath[len];
snprintf(newPackagePath, len-1, "%s;%sscripts/?.lua", oldPackagePath, foundDir);
lua_pop(this->L, 1);
lua_pushstring(this->L, newPackagePath);
lua_setfield(this->L, -2, "path");
free(foundDir);

int err = luaL_dofile(this->L, foundFile);
free(foundFile);
if (err != 0) {
mvprintw(0,0,"Error loading script %s", lua_tostring(this->L, -1));
getch();
return;
}
this->hasScript = true;
}

void Highlight_initScript(Highlight* this, const char* fileName) {
if (!this->hasScript)
return;
lua_getglobal(this->L, "highlight_file");
if (!lua_isfunction(this->L, -1))
return;
lua_pushstring(this->L, fileName);
int err = lua_pcall(this->L, 1, 0, 0);
// TODO ignore errors for now
lua_pop(this->L, lua_gettop(this->L));
}

bool Highlight_readHighlightFile(ReadHighlightFileArgs* args, char* name) {
Highlight* this = args->this;
const char* fileName = args->fileName;
Expand Down Expand Up @@ -261,8 +229,9 @@ bool Highlight_readHighlightFile(ReadHighlightFileArgs* args, char* name) {
} else if (String_eq(tokens[0], "insensitive") && ntokens == 1) {
this->toLower = true;
} else if (String_eq(tokens[0], "script") && ntokens == 2) {
Highlight_loadScript(this, tokens[1]);
this->hasScript = Script_load(this->L, tokens[1]);
} else {
clear();
mvprintw(0,0,"Error reading %s: line %d: %s", name, lineno, buffer);
getch();
success = false;
Expand All @@ -276,6 +245,7 @@ bool Highlight_readHighlightFile(ReadHighlightFileArgs* args, char* name) {
}
fclose(file);
if (contexts->size != 1) {
clear();
mvprintw(0,0,"Error reading %s: %d context%s still open", name, contexts->size - 1, contexts->size > 2 ? "s" : "");
getch();
success = false;
Expand Down Expand Up @@ -347,7 +317,7 @@ void Highlight_runLineThroughScript(Highlight* this, unsigned char* buffer, int*
return;
}
lua_pushstring(this->L, buffer);
lua_pushinteger(this->L, y + 1);
lua_pushinteger(this->L, y);
int err = lua_pcall(this->L, 2, 1, 0);
if (err == 0) {
if (lua_isstring(this->L, -1)) {
Expand Down
16 changes: 8 additions & 8 deletions List.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ ListItemClass ListItemType = {
}
};

inline void List_reset(List* this) {
this->head = NULL;
this->tail = NULL;
this->size = 0;
this->atPtr = NULL;
this->atCtr = 0;
}

List* List_new(ListItemClass* type, void* data) {
List* this = (List*) malloc(sizeof(List));
this->type = type;
Expand All @@ -48,14 +56,6 @@ List* List_new(ListItemClass* type, void* data) {
return this;
}

inline void List_reset(List* this) {
this->head = NULL;
this->tail = NULL;
this->size = 0;
this->atPtr = NULL;
this->atCtr = 0;
}

void List_resetIterator(List* this) {
assert(this->head);
this->atPtr = this->head;
Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ bin_PROGRAMS = dit

my_dit_C_sources = dit.c Buffer.c CRT.c Clipboard.c DebugMemory.c Field.c \
FileReader.c FunctionBar.c Hashtable.c Highlight.c Line.c List.c Object.c \
Panel.c PatternMatcher.c Pool.c RichString.c ScreenManager.c \
Panel.c PatternMatcher.c Pool.c RichString.c ScreenManager.c Script.c \
Stack.c String.c StringBuffer.c TabManager.c Undo.c Vector.c Files.c
BUILT_SOURCES = Prototypes.h Structures.h

Expand Down
46 changes: 23 additions & 23 deletions PatternMatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ void PatternMatcher_delete(PatternMatcher* this) {
free(this);
}

inline GraphNode* GraphNode_follow(GraphNode* this, unsigned char c) {
if (c < this->min || c > this->max) {
return NULL;
}
if (this->min == this->max) {
assert(c == this->min);
return this->u.simple;
} else {
int id = c - this->min;
int ptrid = this->u.l.links[id];
if (ptrid == 0)
return NULL;
assert(ptrid >= 1 && ptrid <= this->u.l.nptrs);
if (this->u.l.nptrs == 1) {
assert(this->u.l.p.single);
return this->u.l.p.single;
} else {
assert(this->u.l.p.list[ptrid - 1]);
return this->u.l.p.list[ptrid - 1];
}
}
}

void GraphNode_build(GraphNode* current, unsigned char* input, unsigned char* special, int value, char nodeType) {
#define SPECIAL(c) (*special && *input == c)
#define NEXT do { special++; input++; } while (0)
Expand Down Expand Up @@ -307,29 +330,6 @@ void GraphNode_delete(GraphNode* this, GraphNode* prev) {
free(this);
}

inline GraphNode* GraphNode_follow(GraphNode* this, unsigned char c) {
if (c < this->min || c > this->max) {
return NULL;
}
if (this->min == this->max) {
assert(c == this->min);
return this->u.simple;
} else {
int id = c - this->min;
int ptrid = this->u.l.links[id];
if (ptrid == 0)
return NULL;
assert(ptrid >= 1 && ptrid <= this->u.l.nptrs);
if (this->u.l.nptrs == 1) {
assert(this->u.l.p.single);
return this->u.l.p.single;
} else {
assert(this->u.l.p.list[ptrid - 1]);
return this->u.l.p.list[ptrid - 1];
}
}
}

void GraphNode_link(GraphNode* this, unsigned char* mask, GraphNode* next) {

// Find maskmin and maskmax
Expand Down
Loading

0 comments on commit d48aebc

Please sign in to comment.