summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroman65536 <roman65536@yahoo.com>2017-03-18 11:25:10 +0100
committerroman65536 <roman65536@yahoo.com>2017-03-18 11:25:10 +0100
commite2c245f206cc4728759bce4245d85d9c17b154c2 (patch)
treeba1194f465e3b82138582c63d0c7471b3fd17e74
parent3eb558daaf5d09c6c31ed1c736f09331eea2b2f1 (diff)
parentcefe73bab1dc159ec96205862a107cf40508b816 (diff)
Merge branch 'freeze' of https://github.com/andmarti1424/sc-im into freeze
-rw-r--r--src/Makefile2
-rw-r--r--src/cmds_command.c4
-rw-r--r--src/cmds_command.h2
-rw-r--r--src/cmds_insert.c90
-rw-r--r--src/cmds_insert.h6
-rw-r--r--src/cmds_normal.c16
-rw-r--r--src/history.c19
-rw-r--r--src/history.h4
-rw-r--r--src/input.c5
-rw-r--r--src/input.h5
-rw-r--r--src/interp.c30
-rw-r--r--src/lua.c115
-rw-r--r--src/main.c44
-rw-r--r--src/trigger.c17
14 files changed, 230 insertions, 129 deletions
diff --git a/src/Makefile b/src/Makefile
index fe0b4bd..903565d 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -42,6 +42,8 @@ CFLAGS += -DDFLT_PAGER=\"less\"
CFLAGS += -DUSECOLORS
# Command history file, relative to home directory. Comment out to disable commandline history
CFLAGS += -DHISTORY_FILE=\".$(name)info\"
+# Input mode history. Same as previous, but for insert mode commands
+#CFLAGS += -DINS_HISTORY_FILE=\".$(name)info\"
# Comment out to disable undo/redo support
CFLAGS += -DUNDO
# Maximum number of rows in spreadsheet. Up to 1048576
diff --git a/src/cmds_command.c b/src/cmds_command.c
index 30e364a..eed95c5 100644
--- a/src/cmds_command.c
+++ b/src/cmds_command.c
@@ -781,7 +781,7 @@ void do_commandmode(struct block * sb) {
modflg = 0;
update(TRUE);
}
- } else {
+ } else {
sc_error("COMMAND NOT FOUND !");
}
@@ -796,7 +796,7 @@ void do_commandmode(struct block * sb) {
#endif
chg_mode('.');
- inputline[0]='\0';
+ inputline[0]=L'\0';
set_comp(0); // unmark tab completion
update(TRUE);
}
diff --git a/src/cmds_command.h b/src/cmds_command.h
index 390b061..f7d1b3b 100644
--- a/src/cmds_command.h
+++ b/src/cmds_command.h
@@ -1,4 +1,6 @@
+#ifdef HISTORY_FILE
#include "history.h"
+#endif
#include "buffer.h"
extern int shall_quit;
diff --git a/src/cmds_insert.c b/src/cmds_insert.c
index a038c2d..77f5737 100644
--- a/src/cmds_insert.c
+++ b/src/cmds_insert.c
@@ -11,6 +11,10 @@
#include "cmds_visual.h"
#include "conf.h"
+#ifdef INS_HISTORY_FILE
+char ori_insert_edit_submode;
+#endif
+
void do_insertmode(struct block * sb) {
if (sb->value == ctl('v') ) { // VISUAL SUBMODE
@@ -35,6 +39,41 @@ void do_insertmode(struct block * sb) {
show_header(input_win);
}
+#ifdef INS_HISTORY_FILE
+ } else if (sb->value == OKEY_UP || sb->value == ctl('p') || // UP
+ sb->value == OKEY_DOWN || sb->value == ctl('n')) { // DOWN
+
+ int delta = 0;
+ if (sb->value == OKEY_UP || sb->value == ctl('p')) { // up
+ if (insert_history->len <= - insert_history->pos + 1) return;
+ delta = -1;
+ }
+ if (sb->value == OKEY_DOWN || sb->value == ctl('n')) { // down
+ if ( - insert_history->pos == 0) return;
+ delta = 1;
+ }
+ insert_history->pos += delta;
+
+ wchar_t word [COLS];
+ wcscpy(word, get_line_from_history(insert_history, insert_history->pos));
+ if (insert_history->pos == 0)
+ insert_edit_submode = ori_insert_edit_submode;
+ else {
+ insert_edit_submode = word[0];
+ del_wchar(word, 0);
+ }
+ wcscpy(inputline, word);
+ inputline_pos = wcswidth(inputline, real_inputline_pos);
+
+ chg_mode(insert_edit_submode);
+ clr_header(input_win, 0);
+ print_mode(input_win);
+ wrefresh(input_win);
+ show_header(input_win);
+
+ return;
+#endif
+
} else if (sb->value == OKEY_BS || sb->value == OKEY_BS2) { // BS
if ( ! wcslen(inputline) || ! real_inputline_pos ) return;
@@ -43,11 +82,19 @@ void do_insertmode(struct block * sb) {
del_wchar(inputline, real_inputline_pos);
inputline_pos -= l;
show_header(input_win);
+#ifdef INS_HISTORY_FILE
+ if (insert_history->pos == 0)
+ del_wchar(get_line_from_history(insert_history, insert_history->pos), real_inputline_pos); // Clean history
+#endif
} else if (sb->value == OKEY_DEL) { // DEL
int max = wcswidth(inputline, wcslen(inputline));
if (inputline_pos > max) return;
del_wchar(inputline, real_inputline_pos);
+#ifdef INS_HISTORY_FILE
+ if (insert_history->pos == 0)
+ del_wchar(get_line_from_history(insert_history, insert_history->pos), real_inputline_pos); // Clean history
+#endif
show_header(input_win);
} else if (sb->value == OKEY_TAB) { // TAB
@@ -83,6 +130,19 @@ void do_insertmode(struct block * sb) {
enter_cell_content(currow, curcol, ope, content);
+#ifdef INS_HISTORY_FILE
+ // if exists in history an item with same text to the command typed
+ // (counting from the second position) it is moved to the beginning of list.
+ // (first element in list means last command executed)
+ del_item_from_history(insert_history, 0);
+ wchar_t copy[BUFFERSIZE];
+
+ swprintf(copy, BUFFERSIZE, L"%c%ls", insert_edit_submode, inputline);
+ int moved = move_item_from_history_by_str(insert_history, copy, -1);
+ if (! moved) add(insert_history, copy);
+ insert_history->pos = 0;
+#endif
+
inputline[0] = L'\0';
inputline_pos = 0;
real_inputline_pos = 0;
@@ -101,6 +161,7 @@ void do_insertmode(struct block * sb) {
update(TRUE);
return;
+
} else if (sb->value == OKEY_HOME) { // HOME
real_inputline_pos = 0;
inputline_pos = wcswidth(inputline, real_inputline_pos);
@@ -118,20 +179,33 @@ void do_insertmode(struct block * sb) {
//DEBUG sc_info("2: %d %lc", sb->value, sb->value);
ins_in_line(sb->value);
show_header(input_win);
+#ifdef INS_HISTORY_FILE
+ if (insert_history->pos == 0) { // Only if editing the new command
+ wchar_t * sl = get_line_from_history(insert_history, 0);
+ add_wchar(sl, sb->value, real_inputline_pos-1); // Insert into history
+ }
+#endif
- } else if (sb->value == ctl('r') && get_bufsize(sb) == 2 && // C-r
- (sb->pnext->value - ('a' - 1) < 1 || sb->pnext->value > 26)) {
- char cline [BUFFERSIZE];
+ } else if (sb->value == ctl('r') && get_bufsize(sb) == 2 && // C-r // FIXME ???
+ (sb->pnext->value - (L'a' - 1) < 1 || sb->pnext->value > 26)) {
+ wchar_t cline [BUFFERSIZE];
int i, r = get_mark(sb->pnext->value)->row;
if (r != -1) {
- sprintf(cline, "%s%d", coltoa(get_mark(sb->pnext->value)->col), r);
+ swprintf(cline, BUFFERSIZE, L"%s%d", coltoa(get_mark(sb->pnext->value)->col), r);
} else {
- sprintf(cline, "%s%d:", coltoa(get_mark(sb->pnext->value)->rng->tlcol), get_mark(sb->pnext->value)->rng->tlrow);
- sprintf(cline + strlen(cline), "%s%d", coltoa(get_mark(sb->pnext->value)->rng->brcol), get_mark(sb->pnext->value)->rng->brrow);
+ swprintf(cline, BUFFERSIZE, L"%s%d:", coltoa(get_mark(sb->pnext->value)->rng->tlcol), get_mark(sb->pnext->value)->rng->tlrow);
+ swprintf(cline + wcslen(cline), BUFFERSIZE, L"%s%d", coltoa(get_mark(sb->pnext->value)->rng->brcol), get_mark(sb->pnext->value)->rng->brrow);
}
- for(i = 0; i < strlen(cline); i++) ins_in_line(cline[i]);
- show_header(input_win);
+ for(i = 0; i < wcslen(cline); i++) ins_in_line(cline[i]);
+#ifdef INS_HISTORY_FILE
+ if (commandline_history->pos == 0) { // Only if editing the new command
+ wchar_t * sl = get_line_from_history(commandline_history, 0);
+ wcscat(sl, cline); // Insert into history
+ }
+#endif
+ show_header(input_win);
+ return;
}
return;
}
diff --git a/src/cmds_insert.h b/src/cmds_insert.h
index bbcd7ce..7e5e7b8 100644
--- a/src/cmds_insert.h
+++ b/src/cmds_insert.h
@@ -1,3 +1,9 @@
#include "input.h"
+#ifdef INS_HISTORY_FILE
+#include "history.h"
+extern struct history * insert_history;
+#endif
+
void do_insertmode(struct block * sb);
+
diff --git a/src/cmds_normal.c b/src/cmds_normal.c
index 8916931..1c36c0d 100644
--- a/src/cmds_normal.c
+++ b/src/cmds_normal.c
@@ -22,13 +22,19 @@
#include "dep_graph.h"
extern graphADT graph;
extern char valores;
-
-
extern int cmd_multiplier;
-extern struct history * commandline_history;
extern void start_visualmode(int tlrow, int tlcol, int brrow, int brcol);
wchar_t interp_line[BUFFERSIZE];
+#ifdef HISTORY_FILE
+extern struct history * commandline_history;
+#endif
+
+#ifdef INS_HISTORY_FILE
+extern struct history * insert_history;
+extern char ori_insert_edit_submode;
+#endif
+
void do_normalmode(struct block * buf) {
int bs = get_bufsize(buf);
struct ent * e;
@@ -418,6 +424,10 @@ void do_normalmode(struct block * buf) {
if (locked_cell(currow, curcol)) return;
insert_edit_submode = buf->value;
chg_mode(insert_edit_submode);
+#ifdef INS_HISTORY_FILE
+ ori_insert_edit_submode = buf->value;
+ add(insert_history, L"");
+#endif
clr_header(input_win, 0);
print_mode(input_win);
wrefresh(input_win);
diff --git a/src/history.c b/src/history.c
index 552d2f4..24a73d6 100644
--- a/src/history.c
+++ b/src/history.c
@@ -59,7 +59,7 @@ void destroy_history(struct history * h) {
return;
}
-void load_history(struct history * h) {
+void load_history(struct history * h, wchar_t mode) {
char infofile[PATHLEN];
wchar_t linea[FBUFLEN];
int c;
@@ -78,9 +78,11 @@ void load_history(struct history * h) {
int s = wcslen(linea)-1;
del_range_wchars(linea, s, s);
- if (linea[0] == L':') {
+ if (linea[0] == mode && mode == L':') {
del_range_wchars(linea, 0, 0);
add(h, linea);
+ } else if (mode != L':' && (linea[0] == L'=' || linea[0] == L'<' || linea[0] == L'>' || linea[0] == L'\\')) {
+ add(h, linea);
}
}
fclose(f);
@@ -92,8 +94,7 @@ void load_history(struct history * h) {
// Save history to file
// returns 0 on success, -1 otherwise
-int save_history(struct history * h) {
- if (h->mode != ':' ) return -1;
+int save_history(struct history * h, char * mode) {
char infofile [PATHLEN];
char * home;
FILE * f;
@@ -103,8 +104,8 @@ int save_history(struct history * h) {
if ((home = getenv("HOME"))) {
sprintf(infofile, "%s/", home);
strcat(infofile, HISTORY_FILE);
- f = fopen(infofile, "w");
- if (f == NULL) return -1;
+ f = fopen(infofile, mode);
+ if (f == NULL) return 0;
// Go to the end
for (i=1; i < h->len; i++) {
@@ -112,14 +113,14 @@ int save_history(struct history * h) {
}
// Traverse list back to front, so the history is saved in chronological order
for (i=0; i < h->len; i++) {
- fwprintf(f, L":");
+ if (! strcmp(mode, "w")) fwprintf(f, L":"); // mode 'w' means we are saving the command mode history
fwprintf(f, L"%ls\n", nl->line);
nl = nl->pant;
}
fclose(f);
- return 0;
+ return 1;
}
- return -1;
+ return 0;
}
// Remove history element
diff --git a/src/history.h b/src/history.h
index 3d75016..ed31132 100644
--- a/src/history.h
+++ b/src/history.h
@@ -13,8 +13,8 @@ struct hlist {
struct history * create_history(char mode);
void destroy_history(struct history * h);
-void load_history();
-int save_history(struct history * h);
+void load_history(struct history * h, wchar_t mode);
+int save_history(struct history * h, char * mode);
void del_item_from_history(struct history * h, int pos);
int move_item_from_history_by_str(struct history * h, wchar_t * item, int pos);
void add(struct history * h, wchar_t * line);
diff --git a/src/input.c b/src/input.c
index b2a974e..a475207 100644
--- a/src/input.c
+++ b/src/input.c
@@ -148,6 +148,11 @@ void break_waitcmd_loop(struct block * buffer) {
commandline_history->pos = 0;
set_comp(0);
#endif
+ } else if (curmode == INSERT_MODE) {
+#ifdef INS_HISTORY_FILE
+ del_item_from_history(insert_history, 0);
+ insert_history->pos = 0;
+#endif
} else if (curmode == VISUAL_MODE) {
exit_visualmode();
}
diff --git a/src/input.h b/src/input.h
index 83e62cf..346afae 100644
--- a/src/input.h
+++ b/src/input.h
@@ -6,7 +6,12 @@ extern int multiplier; // Multipl
extern int command_pending; // Command pending
extern WINDOW * input_win;
extern struct block * lastcmd_buffer;
+#ifdef HISTORY_FILE
extern struct history * commandline_history;
+#endif
+#ifdef INS_HISTORY_FILE
+extern struct history * insert_history;
+#endif
void fix_timeout(struct timeval * start_tv); // Handle timeout of stdin
void handle_input(struct block * buffer);
diff --git a/src/interp.c b/src/interp.c
index dca521a..cc5b8a8 100644
--- a/src/interp.c
+++ b/src/interp.c
@@ -8,22 +8,22 @@
*/
#include <sys/types.h>
-
-#ifdef IEEE_MATH
-#include <ieeefp.h>
-#endif
-
#include <math.h>
#include <signal.h>
#include <setjmp.h>
#include <ctype.h>
#include <errno.h>
-
#include <time.h>
#include <string.h>
-
#include <stdlib.h>
#include <ncurses.h>
+#include <unistd.h>
+#include <regex.h>
+
+#ifdef IEEE_MATH
+#include <ieeefp.h>
+#endif
+
#include "sc.h"
#include "macros.h"
#include "color.h"
@@ -35,12 +35,9 @@
#include "lex.h" // for atocol
#include "interp.h"
#include "utils/string.h"
-#include <unistd.h>
-#include <regex.h>
+#include "trigger.h"
-#include "trigger.h"
#ifdef XLUA
-//void do_trigger( struct ent *p , int rw);
#include "lua.h"
#endif
@@ -1896,6 +1893,7 @@ void unlock_cells(struct ent * v1, struct ent * v2) {
/* set the numeric part of a cell */
void let(struct ent * v, struct enode * e) {
+
if (locked_cell(v->row, v->col)) return;
#ifdef UNDO
@@ -1916,6 +1914,7 @@ void let(struct ent * v, struct enode * e) {
double val;
+ short already_eval = FALSE;
unsigned isconstant = constant(e);
if (v->row == currow && v->col == curcol)
cellassign = 1;
@@ -1931,6 +1930,7 @@ void let(struct ent * v, struct enode * e) {
} else {
cellerror = CELLOK;
val = eval(v, e); // JUST NUMERIC VALUE
+ already_eval = TRUE;
}
if (v->cellerror != cellerror) {
v->flags |= is_changed;
@@ -1960,7 +1960,7 @@ void let(struct ent * v, struct enode * e) {
v->expr = (struct enode *) 0;
}
efree(e);
- } else if (! exprerr) {
+ } else if (! exprerr && ! already_eval) {
efree(v->expr);
v->expr = e;
@@ -2014,6 +2014,8 @@ void slet(struct ent * v, struct enode * se, int flushdir) {
char * p;
if (v->row == currow && v->col == curcol) cellassign = 1;
exprerr = 0;
+ short already_eval = FALSE;
+
(void) signal(SIGFPE, eval_fpe);
if (setjmp(fpe_save)) {
sc_error ("Floating point exception in cell %s", v_name(v->row, v->col));
@@ -2040,7 +2042,7 @@ void slet(struct ent * v, struct enode * se, int flushdir) {
v->expr = (struct enode *) 0;
v->flags &= ~is_strexpr;
}
- } else {
+ } else if ( ! already_eval ) {
if (p) free(p); // ADDED for 2267 leak!
efree(v->expr);
@@ -2049,7 +2051,7 @@ void slet(struct ent * v, struct enode * se, int flushdir) {
p = seval(v, se); // ADDED - here we store the cell dependences in a graph
if (p) scxfree(p); // ADDED
- v->flags |= (is_changed|is_strexpr);
+ v->flags |= (is_changed | is_strexpr);
if (flushdir < 0) v->flags |= is_leftflush;
if (flushdir == 0)
diff --git a/src/lua.c b/src/lua.c
index f784ef3..8c88cf4 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -28,7 +28,6 @@
#include "screen.h"
#include "conf.h"
-
extern FILE * fdoutput;
extern WINDOW * input_win;
@@ -131,7 +130,6 @@ static int l_sc (lua_State *L) {
return 0;
}
-
static int l_colrow2a(lua_State *L) {
int c, r;
char buf[16];
@@ -143,7 +141,6 @@ static int l_colrow2a(lua_State *L) {
return 1;
}
-
static int l_colrow(lua_State *L) {
char buf[16];
char *val;
@@ -218,7 +215,9 @@ char * query(char * initial_msg) {
wtimeout(input_win, TIMEOUT_CURSES);
wmove(input_win, 0,0);
wclrtoeol(input_win);
-
+ wmove(input_win, 1,0);
+ wclrtoeol(input_win);
+ wrefresh(input_win);
return hline;
}
@@ -244,8 +243,6 @@ LC_NUMBER2(curcol,curcol)
LC_NUMBER2(maxcols,maxcols)
LC_NUMBER2(maxrows,maxrows)
-
-
static const luaL_reg sclib[] = {
{ "lgetnum", l_getnum },
{ "lsetnum", l_setnum },
@@ -262,27 +259,24 @@ static const luaL_reg sclib[] = {
{NULL,NULL}
};
-
-
void doLuainit() {
- char buffer[PATHLEN];
- char buffer1[PATHLEN];
-
- L = luaL_newstate(); /* Create Lua state variable */
- luaL_openlibs(L); /* Load Lua libraries */
+ char buffer[PATHLEN];
+ char buffer1[PATHLEN];
+
+ L = luaL_newstate(); /* Create Lua state variable */
+ luaL_openlibs(L); /* Load Lua libraries */
sprintf(buffer,"lua/init.lua");
- if(plugin_exists(buffer,strlen(buffer),buffer1))
- {
- if (luaL_loadfile(L, buffer1)) { /* Load but don't run the Lua script */
- fprintf(stderr, "\nWarning :\n Couldn't load init.lua: %s\n\n", lua_tostring(L,-1));
- return;
- }
- if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
- fprintf(stderr, "\nFATAL ERROR:\n Couldn't initialized Lua: %s\n\n", lua_tostring(L,-1));
- }
- luaL_register(L, "sc", sclib); /* Load SC specific LUA commands after init.lua exec*/
-
+ if(plugin_exists(buffer,strlen(buffer),buffer1)) {
+ if (luaL_loadfile(L, buffer1)) { /* Load but don't run the Lua script */
+ fprintf(stderr, "\nWarning :\n Couldn't load init.lua: %s\n\n", lua_tostring(L,-1));
+ return;
+ }
+ if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
+ fprintf(stderr, "\nFATAL ERROR:\n Couldn't initialized Lua: %s\n\n", lua_tostring(L,-1));
+ }
+ luaL_register(L, "sc", sclib); /* Load SC specific LUA commands after init.lua exec*/
+
return;
}
@@ -298,31 +292,30 @@ char * doLUA( struct enode * se) {
cmd = seval(NULL, se->e.o.left);
sprintf(buffer,"lua/%s",cmd);
- if(plugin_exists(buffer,strlen(buffer),buffer1))
- {
- if (luaL_loadfile(L, buffer1)) /* Load but don't run the Lua script */
- bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
+ if(plugin_exists(buffer,strlen(buffer),buffer1)) {
+ if (luaL_loadfile(L, buffer1)) /* Load but don't run the Lua script */
+ bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
- if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
- bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
+ if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
+ bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
- /* Tell what function to run */
- // lua_getglobal(L, "tellme");
- }
+ /* Tell what function to run */
+ // lua_getglobal(L, "tellme");
+ }
+ if (cmd != NULL) free(cmd);
return 0;
}
-
void doLuaTriger() {
- if (luaL_loadfile(L, "trigger.lua")) /* Load but don't run the Lua script */
- return;
- //bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
+ if (luaL_loadfile(L, "trigger.lua")) /* Load but don't run the Lua script */
+ return;
+ //bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
- if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
- bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
+ if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
+ bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
- lua_getglobal(L, "trigger"); /* Tell what function to run */
+ lua_getglobal(L, "trigger"); /* Tell what function to run */
//sc_debug("In C, calling Lua");
if (lua_pcall(L, 0, 0, 0)) /* Run the function */
@@ -360,32 +353,30 @@ void doLuaTrigger_cell(struct ent *p, int flags) {
struct trigger *trigger = p->trigger;
char buffer[PATHLEN];
char buffer1[PATHLEN];
-
+
row = p->row;
col = p->col;
sprintf(buffer,"lua/%s",trigger->file);
- if(plugin_exists(buffer,strlen(buffer),buffer1))
- {
- if (luaL_loadfile(L, buffer1)) /* Load but don't run the Lua script */
- return;
- //bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
-
-
- if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
- bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
-
- lua_getglobal(L, trigger->function); /* Tell what function to run */
-
- lua_pushinteger(L,col);
- lua_pushinteger(L,row);
- lua_pushinteger(L, flags);
- //sc_debug("In C, calling Lua");
- if (lua_pcall(L, 3, 0, 0)) /* Run the function */
- bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
- //sc_debug("Back in C again");
- }
-
+ if(plugin_exists(buffer,strlen(buffer),buffer1)) {
+ if (luaL_loadfile(L, buffer1)) /* Load but don't run the Lua script */
+ return;
+ //bail(L, "luaL_loadfile() failed"); /* Error out if file can't be read */
+
+
+ if (lua_pcall(L, 0, 0, 0)) /* PRIMING RUN. FORGET THIS AND YOU'RE TOAST */
+ bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
+
+ lua_getglobal(L, trigger->function); /* Tell what function to run */
+
+ lua_pushinteger(L,col);
+ lua_pushinteger(L,row);
+ lua_pushinteger(L, flags);
+ //sc_debug("In C, calling Lua");
+ if (lua_pcall(L, 3, 0, 0)) /* Run the function */
+ bail(L, "lua_pcall() failed"); /* Error out if Lua file has an error */
+ //sc_debug("Back in C again");
+ }
return;
}
#endif
diff --git a/src/main.c b/src/main.c
index 7c50ad9..ce8457d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -8,7 +8,10 @@
#include <locale.h>
#include <wchar.h>
#include <wordexp.h>
+
+#ifndef __APPLE__
#include <stropts.h> // for ioctl
+#endif
#include "main.h"
#include "shift.h"
@@ -83,6 +86,7 @@ struct block * lastcmd_buffer;
struct dictionary * user_conf_d;
struct dictionary * predefined_conf_d;
struct history * commandline_history;
+struct history * insert_history;
void read_stdin();
/*********************************************************************
@@ -105,12 +109,16 @@ int main (int argc, char ** argv) {
store_default_config_values();
// create command line history structure
-#ifdef HISTORY_FILE
if (! atoi(get_conf_value("nocurses"))) {
+#ifdef HISTORY_FILE
commandline_history = (struct history *) create_history(':');
- load_history(commandline_history);
- }
+ load_history(commandline_history, ':');
#endif
+#ifdef INS_HISTORY_FILE
+ insert_history = (struct history *) create_history('=');
+ load_history(insert_history, '=');
+#endif
+ }
// create basic structures that will depend on the loaded file
create_structures();
@@ -128,12 +136,12 @@ int main (int argc, char ** argv) {
#ifdef USECOLORS
//if (has_colors() && get_d_colors_param() == NULL) {
if (get_d_colors_param() == NULL) {
- start_default_ucolors();
- // in case we decide to change colors
- // this creates a dictionary and stores in it
- // the relationship between macros and the keys values
- // that are defined in .sc files
- set_colors_param_dict();
+ start_default_ucolors();
+ // in case we decide to change colors
+ // this creates a dictionary and stores in it
+ // the relationship between macros and the keys values
+ // that are defined in .sc files
+ set_colors_param_dict();
}
#endif
@@ -193,7 +201,8 @@ int main (int argc, char ** argv) {
}
// handle input from keyboard
- buffer = (struct block *) create_buf(); // TODO: this should only take place if curses ui
+ if (! atoi(get_conf_value("nocurses")))
+ buffer = (struct block *) create_buf(); // this should only take place if curses ui
wchar_t nocurses_buffer[BUFFERSIZE];
@@ -221,12 +230,6 @@ int main (int argc, char ** argv) {
END OF MAIN LOOP
*********************************************************************/
-
-
-
-
-
-
extern graphADT graph;
void create_structures() {
@@ -280,7 +283,6 @@ void read_stdin() {
perror(NULL);
exit(-1);
}
-
//sc_debug("finish reading");
}
@@ -325,11 +327,13 @@ int exit_app(int status) {
// free history
#ifdef HISTORY_FILE
- if (! atoi(get_conf_value("nocurses")) && save_history(commandline_history) != 0 ) {
- sc_error("Cannot save command line history");
- }
+ if (! save_history(commandline_history, "w")) sc_error("Could not save commandline history");
if (commandline_history != NULL) destroy_history(commandline_history);
#endif
+#ifdef INS_HISTORY_FILE
+ if (! save_history(insert_history, "a")) sc_error("Could not save input mode history");
+ if (insert_history != NULL) destroy_history(insert_history);
+#endif
// erase structures
delete_structures();
diff --git a/src/trigger.c b/src/trigger.c
index df3dde6..dbd1403 100644
--- a/src/trigger.c
+++ b/src/trigger.c
@@ -83,13 +83,13 @@ void set_trigger(int r, int c, int rf, int cf, char * str) {
#endif
if (strcmp(get(d,"type"), "C")== 0) {
char * error;
- char buffer[PATHLEN];
- char buffer1[PATHLEN];
- tmp|=TRG_C;
- sprintf(buffer,"module/%s",n->trigger->file);
-
- if(plugin_exists(buffer,strlen(buffer),buffer1))
- n->trigger->handle=dlopen(buffer1,RTLD_LAZY);
+ char buffer[PATHLEN];
+ char buffer1[PATHLEN];
+ tmp |= TRG_C;
+ sprintf(buffer,"module/%s",n->trigger->file);
+
+ if(plugin_exists(buffer,strlen(buffer),buffer1))
+ n->trigger->handle=dlopen(buffer1,RTLD_LAZY);
if(!n->trigger->handle) {
fputs (dlerror(), stderr);
exit(1);
@@ -161,8 +161,7 @@ void do_C_Trigger_cell(struct ent * p, int rw) {
-int plugin_exists(char *name, int len, char *path)
-{
+int plugin_exists(char *name, int len, char *path) {
FILE *fp;
static char *HomeDir;