summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormongo <andmarti@gmail.com>2017-12-01 10:11:48 -0300
committermongo <andmarti@gmail.com>2017-12-01 10:11:48 -0300
commit87242d8a8e4fdbd621f7dafcec5c17b4a95624b4 (patch)
treea162c9f306c75a80b3b936dd36dded0200429842
parent6c3967ed314cf625f7edf2ae48bb7911edca4ae3 (diff)
Work on issue 213
-rw-r--r--src/cmds.c2
-rw-r--r--src/conf.c2
-rw-r--r--src/dep_graph.c84
-rw-r--r--src/file.c1
-rw-r--r--src/interp.c2
-rw-r--r--src/main.c31
6 files changed, 106 insertions, 16 deletions
diff --git a/src/cmds.c b/src/cmds.c
index ff99310..60bbb0a 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -1224,7 +1224,7 @@ void send_to_interp(wchar_t * oper) {
linelim = 0;
yyparse();
- if (atoi(get_conf_value("autocalc")) && ! loading) EvalAll();
+ //if (atoi(get_conf_value("autocalc")) && ! loading) EvalAll();
return;
}
diff --git a/src/conf.c b/src/conf.c
index 1312700..1d89a9d 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -66,7 +66,7 @@
void store_default_config_values() {
put(user_conf_d, "half_page_scroll", "0");
put(user_conf_d, "autocalc", "1");
- put(user_conf_d, "numeric", "1");
+ put(user_conf_d, "numeric", "0");
put(user_conf_d, "nocurses", "0");
put(user_conf_d, "newline_action", "j");
put(user_conf_d, "external_functions", "0");
diff --git a/src/dep_graph.c b/src/dep_graph.c
index 3b90a68..cc30814 100644
--- a/src/dep_graph.c
+++ b/src/dep_graph.c
@@ -102,7 +102,7 @@ graphADT GraphCreate() {
}
/**
- * \brief Undefined function
+ * \brief Undefined function
*
* This adds the vertex sorted in the list and not at the end. Given a row and
* column to insert as a new vertex, this function will create a new vertex
@@ -242,7 +242,7 @@ void markAllVerticesNotVisited () {
/**
- * \brief Prints vertexes
+ * \brief Prints vertexes
*
* \return none
*/
@@ -263,12 +263,12 @@ void print_vertexs() {
strcpy(msg, "Content of graph:\n");
while (temp != NULL) {
- sprintf(det + strlen(det), "%d %d\n", temp->ent->row, temp->ent->col);
+ sprintf(det + strlen(det), "vertex: %d %d v:%d\n", temp->ent->row, temp->ent->col, temp->visited);
etemp = temp->edges;
/* check not overflow msg size. if so, just realloc. */
if (strlen(det) + strlen(msg) > msg_size) {
- sc_debug("realloc"),
+ //sc_debug("realloc"),
msg_size += BUFFERSIZE;
msg = (char *) realloc(msg, msg_size);
}
@@ -290,7 +290,7 @@ void print_vertexs() {
}
etemp = temp->back_edges;
while (etemp != NULL) {
- sprintf(det + strlen(det), "edges that depend on that ent: \\-> %d %d\n", etemp->connectsTo->ent->row, etemp->connectsTo->ent->col);
+ sprintf(det + strlen(det), "(back_edges) edges that depend on that ent: \\-> %d %d\n", etemp->connectsTo->ent->row, etemp->connectsTo->ent->col);
etemp = etemp->next;
/* check not overflow msg size. if so, just realloc. */
@@ -477,8 +477,8 @@ void destroy_graph(graphADT graph) {
/**
- * \brief TODO Document rebuild_graph()
- *
+ * \brief Document rebuild_graph()
+ * \details Rebuild entire graph and eval from top left to bottom right.
* \return none
*/
@@ -497,19 +497,79 @@ void rebuild_graph() {
/**
- * \brief Eval vertexs of graph
- *
+ * \brief Document All_vertexs_of_edges_visited
+ * \details Used in EvalBottomUp
+ * \return int
+ */
+int All_vertexs_of_edges_visited(struct edgeTag * e) {
+ struct edgeTag * edges = e;
+ while (edges != NULL) {
+ //sc_debug("1 r:%d c:%d visited:%d", edges->connectsTo->ent->row, edges->connectsTo->ent->col, edges->connectsTo->visited);
+ if (! edges->connectsTo->visited) return 0;
+ edges = edges->next;
+ }
+ return 1;
+}
+
+
+/**
+ * \brief TODO Document EvalBottomUp
* \return none
*/
+void EvalBottomUp() {
+ struct ent * p;
+ vertexT * temp = graph->vertices;
+
+ if (temp == NULL) return;
+ markAllVerticesNotVisited();
+ int evaluated = 0;
+
+ while (temp != NULL) {
+ if (! temp->visited && (p = *ATBL(tbl, temp->ent->row, temp->ent->col)) && ! p->expr) {
+ //FIXME: min y max no figuran en p->expr?
+ evaluated = 1;
+ temp->visited = 1;
+ //sc_debug("1valuating: %d %d", temp->ent->row, temp->ent->col);
+ } else if (! temp->visited && (temp->edges == NULL || All_vertexs_of_edges_visited(temp->edges)) ) {
+
+ if ((p = *ATBL(tbl, temp->ent->row, temp->ent->col)) && p->expr) {
+ //sc_debug("evaluating: %d %d", temp->ent->row, temp->ent->col);
+ EvalJustOneVertex(p, temp->ent->row, temp->ent->col, 1);
+ evaluated = 1;
+ temp->visited = 1;
+ } else {
+ //sc_debug("problem");
+ }
+ }
+
+ temp = temp->next;
+
+ /*
+ if (temp == NULL && evaluated) { //end of cycle. if evaluated a vertex in this loop, loop again
+ //sc_debug("recycle");
+ evaluated = 0;
+ temp = graph->vertices;
+ } else if (temp == NULL) return;*/
+ }
+ //sc_debug("fin eval");
+}
+
+
+/**
+ * \brief Eval vertexs of graph
+ * \return none
+ */
void EvalAll() {
EvalAllVertexs();
+ //EvalBottomUp();
return;
}
+
/**
* \brief TODO Document EvalAllVertexs
- *
+ * \details Eval all vertexs of graph in the order that they were added
* \return none
*/
@@ -520,7 +580,7 @@ void EvalAllVertexs() {
vertexT * temp = graph->vertices;
//int i = 0;
while (temp != NULL) {
- //sc_info("%d %d %d", temp->ent->row, temp->ent->col, i++);
+ //sc_debug("%d %d %d", temp->ent->row, temp->ent->col, i++);
if ((p = *ATBL(tbl, temp->ent->row, temp->ent->col)) && p->expr)
EvalJustOneVertex(p, temp->ent->row, temp->ent->col, 1);
temp = temp->next;
@@ -579,7 +639,7 @@ void EvalJustOneVertex(register struct ent * p, int i, int j, int rebuild_graph)
p->v = v;
p->flags |= is_changed | is_valid;
if (( p->trigger ) && ((p->trigger->flag & TRG_WRITE) == TRG_WRITE))
- do_trigger(p,TRG_WRITE);
+ do_trigger(p, TRG_WRITE);
}
}
}
diff --git a/src/file.c b/src/file.c
index 4c11b5e..9b5a020 100644
--- a/src/file.c
+++ b/src/file.c
@@ -724,6 +724,7 @@ int readfile(char * fname, int eraseflg) {
loading = 0;
linelim = -1;
+ //EvalAll(); // FIXME: see why this double EvalAll is neccesary to remedy #193
if (eraseflg) {
//(void) strcpy(curfile, save);
cellassign = 0;
diff --git a/src/interp.c b/src/interp.c
index 1351ebe..7bbd97c 100644
--- a/src/interp.c
+++ b/src/interp.c
@@ -961,7 +961,7 @@ double dolmin(struct ent * e, struct enode * ep) {
/**
* \brief TODO Document eval()
*
- * \param[in] end
+ * \param[in] ent
* \param[in] e
*
* \return none
diff --git a/src/main.c b/src/main.c
index 19e5fec..cd6bbf6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -40,7 +40,7 @@
* \author Andrés Martinelli <andmarti@gmail.com>
* \date 2017-07-18
* \brief The main file of sc-im
- *
+ *
* \details This is the main file for sc-im.
*
* \see Homepage: https://github.com/andmarti1424/sc-im
@@ -589,6 +589,8 @@ void signals() {
void sig_term();
void nopipe();
void winchg();
+ void sig_tstp();
+ void sig_cont();
signal(SIGINT, sig_int);
signal(SIGABRT, sig_abrt);
@@ -598,6 +600,8 @@ void signals() {
signal(SIGWINCH, winchg);
//(void) signal(SIGBUS, doquit);
//(void) signal(SIGFPE, doquit);
+ signal(SIGTSTP, sig_tstp);
+ signal(SIGCONT, sig_cont);
return;
}
@@ -617,6 +621,31 @@ void nopipe() {
}
/**
+ * \brief Handles the SIGTSTP signal
+ *
+ * \return none
+ */
+
+void sig_tstp() {
+ sc_debug("Got SIGTSTP.");
+ signal(SIGTSTP, SIG_DFL); /* set handler to default */
+ kill(getpid(), SIGTSTP); /* call the default handler */
+}
+
+
+/**
+ * \brief Handles the SIGCONT signal
+ *
+ * \return none
+ */
+
+void sig_cont() {
+ signal(SIGTSTP, sig_tstp); /* set handler back to this */
+ winchg();
+ sc_debug("Got SIGCONT.");
+}
+
+/**
* \brief Handles the SIGINT signal
*
* \return none