diff options
author | mongo <andmarti@gmail.com> | 2017-12-01 10:11:48 -0300 |
---|---|---|
committer | mongo <andmarti@gmail.com> | 2017-12-01 10:11:48 -0300 |
commit | 87242d8a8e4fdbd621f7dafcec5c17b4a95624b4 (patch) | |
tree | a162c9f306c75a80b3b936dd36dded0200429842 | |
parent | 6c3967ed314cf625f7edf2ae48bb7911edca4ae3 (diff) |
Work on issue 213
-rw-r--r-- | src/cmds.c | 2 | ||||
-rw-r--r-- | src/conf.c | 2 | ||||
-rw-r--r-- | src/dep_graph.c | 84 | ||||
-rw-r--r-- | src/file.c | 1 | ||||
-rw-r--r-- | src/interp.c | 2 | ||||
-rw-r--r-- | src/main.c | 31 |
6 files changed, 106 insertions, 16 deletions
@@ -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; } @@ -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); } } } @@ -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 @@ -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 |