diff options
author | andmarti1424 <andmarti@gmail.com> | 2017-04-09 14:47:46 -0300 |
---|---|---|
committer | andmarti1424 <andmarti@gmail.com> | 2017-04-09 14:47:46 -0300 |
commit | 320bae7558476c896f1379e3513087baeae7300c (patch) | |
tree | 059e881a8c7e2cb2e41ade6237b296b05856e19f | |
parent | 7c65aa0806aaa8e0e8c4a181a81f5f350b829ca4 (diff) |
Arrenged comments
-rw-r--r-- | files/gui_example/.tui.c.swp | bin | 20480 -> 0 bytes | |||
-rw-r--r-- | src/cmds.c | 124 | ||||
-rw-r--r-- | src/dep_graph.c | 86 | ||||
-rw-r--r-- | src/gram.y | 10 | ||||
-rw-r--r-- | src/tui.c | 5 | ||||
-rw-r--r-- | src/undo.c | 141 |
6 files changed, 199 insertions, 167 deletions
diff --git a/files/gui_example/.tui.c.swp b/files/gui_example/.tui.c.swp Binary files differdeleted file mode 100644 index 473d9a0..0000000 --- a/files/gui_example/.tui.c.swp +++ /dev/null @@ -32,11 +32,13 @@ int offscr_sc_rows = 0, offscr_sc_cols = 0; int center_hidden_cols = 0; int center_hidden_rows = 0; -// mark_ent_as_deleted -// This structure is used to keep ent structs around before they -// are actualy deleted (memory freed) to allow the sync_refs routine a chance to fix the -// variable references. -// if delete flag is set, is_deleted flag of an ent is set +/* + * mark_ent_as_deleted + * This structure is used to keep ent structs around before they + * are actualy deleted (memory freed) to allow the sync_refs routine a chance to fix the + * variable references. + * if delete flag is set, is_deleted flag of an ent is set + */ void mark_ent_as_deleted(register struct ent * p, int delete) { if (p == NULL) return; if (delete) p->flags |= is_deleted; @@ -47,10 +49,12 @@ void mark_ent_as_deleted(register struct ent * p, int delete) { return; } -// flush_saved: iterates throw freeents (ents marked as deleted) -// calls clearent for freeing ents contents memory -// and free ent pointer. this function should always be called -// at exit. this is mandatory, just in case we want to UNDO any changes. +/* + * flush_saved: iterates throw freeents (ents marked as deleted) + * calls clearent for freeing ents contents memory + * and free ent pointer. this function should always be called + * at exit. this is mandatory, just in case we want to UNDO any changes. + */ void flush_saved() { register struct ent * p; register struct ent * q; @@ -66,12 +70,14 @@ void flush_saved() { return; } -// sync_refs and syncref are used to REMOVE references to -// deleted struct ents. -// Note that the deleted structure must still -// be hanging around before the call, but not referenced -// by an entry in tbl. -// IMPROVE: Shouldn't traverse the whole table. +/* + * sync_refs and syncref are used to REMOVE references to + * deleted struct ents. + * Note that the deleted structure must still + * be hanging around before the call, but not referenced + * by an entry in tbl. + * IMPROVE: Shouldn't traverse the whole table. + */ void sync_refs() { int i, j; register struct ent * p; @@ -163,8 +169,10 @@ void deletecol(int col, int mult) { return; } -// Delete a column - internal function -// parameters: col = col to delete, multi = cmds multiplier.(commonly 1) +/* + * Delete a column - internal function + * parameters: col = col to delete, multi = cmds multiplier.(commonly 1) + */ void int_deletecol(int col, int mult) { register struct ent ** pp; int r, c, i; @@ -357,11 +365,13 @@ void erase_area(int sr, int sc, int er, int ec, int ignorelock, int mark_as_dele sc = 0; checkbounds(&er, &ec); - // mark the ent as deleted - // Do a lookat() for the upper left and lower right cells of the range - // being erased to make sure they are included in the delete buffer so - // that pulling cells always works correctly even if the cells at one - // or more edges of the range are all empty. + /* + * mark the ent as deleted + * Do a lookat() for the upper left and lower right cells of the range + * being erased to make sure they are included in the delete buffer so + * that pulling cells always works correctly even if the cells at one + * or more edges of the range are all empty. + */ (void) lookat(sr, sc); (void) lookat(er, ec); for (r = sr; r <= er; r++) { @@ -389,7 +399,8 @@ void erase_area(int sr, int sc, int er, int ec, int ignorelock, int mark_as_dele return; } -/* function to copy an expression. it returns the copy. +/* + * function to copy an expression. it returns the copy. * special = 1 means transpose * special = 2 means copy from spreadsheet to undo struct */ @@ -585,8 +596,10 @@ void formatcol(int c) { return; } -// Insert a single row. It will be inserted before currow -// if after is 0; after if it is 1. +/* + * Insert a single row. It will be inserted before currow + * if after is 0; after if it is 1. + */ void insert_row(int after) { int r, c; struct ent ** tmprow, ** pp, ** qq; @@ -619,9 +632,11 @@ void insert_row(int after) { return; } -// Insert a single col. The col will be inserted -// BEFORE CURCOL if after is 0; -// AFTER CURCOL if it is 1. +/* + * Insert a single col. The col will be inserted + * BEFORE CURCOL if after is 0; + * AFTER CURCOL if it is 1. + */ void insert_col(int after) { int r, c; register struct ent ** pp, ** qq; @@ -712,8 +727,10 @@ void deleterow(int row, int mult) { return; } -// Delete a row - internal function -// parameters: row = row to delete, multi = cmds multiplier.(commonly 1) +/* + * Delete a row - internal function + * parameters: row = row to delete, multi = cmds multiplier.(commonly 1) + */ void int_deleterow(int row, int mult) { register struct ent ** pp; int r, c; @@ -854,8 +871,10 @@ void chg_mode(char strcmd){ } -// del selected cells -// can be a single cell or a range +/* + * del selected cells + * can be a single cell or a range + */ void del_selected_cells() { int tlrow = currow; int tlcol = curcol; @@ -921,8 +940,9 @@ void del_selected_cells() { return; } -/* Enter cell content on a cell. - Covers commands LET, LABEL, LEFTSTRING and RIGHTSTRING +/* + * Enter cell content on a cell. + * Covers commands LET, LABEL, LEFTSTRING and RIGHTSTRING */ void enter_cell_content(int r, int c, char * submode, wchar_t * content) { // TODO - ADD PADDING INTELLIGENCE HERE ?? @@ -930,8 +950,10 @@ void enter_cell_content(int r, int c, char * submode, wchar_t * content) { send_to_interp(interp_line); } -// Send command to interpreter -// wide_char version +/* + * Send command to interpreter + * wide_char version + */ void send_to_interp(wchar_t * oper) { if (atoi(get_conf_value("nocurses"))) { int pos = -1; @@ -1238,8 +1260,10 @@ struct ent * go_end() { return NULL; } -// if ticks a cell, returns struct ent * -// if ticks a range, return struct ent * to top left cell +/* + * if ticks a cell, returns struct ent * + * if ticks a range, return struct ent * to top left cell + */ struct ent * tick(char ch) { int r, c; struct mark * m = get_mark(ch); @@ -1683,8 +1707,10 @@ int fcopy() { return 0; } -// add padd to cells! -// this sets n to padding of a range +/* + * add padd to cells! + * this sets n to padding of a range + */ int pad(int n, int r1, int c1, int r2, int c2) { int r, c; struct ent * p ; @@ -1730,8 +1756,10 @@ int pad(int n, int r1, int c1, int r2, int c2) { return 0; } -// Calculate number of hidden columns in the left -// q are the number of columns that are before offscr_sc_cols that are shown because they are frozen. +/* + * Calculate number of hidden columns in the left + * q are the number of columns that are before offscr_sc_cols that are shown because they are frozen. + */ int calc_offscr_sc_cols() { int q = 0, i, cols = 0, col = 0; int freeze = freeze_ranges && (freeze_ranges->type == 'c' || freeze_ranges->type == 'a') ? 1 : 0; @@ -1958,11 +1986,13 @@ void pad_and_align (char * str_value, char * numeric_value, int col_width, int a return; } -// Check if the buffer content is a valid command -// res = 0 or NO_CMD : buf has no command -// res = 1 or EDITION_CMD : buf has a command -// res = 2 or MOVEMENT_CMD : buf has a movement command or a command that do not -// change cell content, and should not be considered by the '.' command +/* + * Check if the buffer content is a valid command + * res = 0 or NO_CMD : buf has no command + * res = 1 or EDITION_CMD : buf has a command + * res = 2 or MOVEMENT_CMD : buf has a movement command or a command that do not + * change cell content, and should not be considered by the '.' command + */ int is_single_command (struct block * buf, long timeout) { if (buf->value == L'\0') return NO_CMD; int res = NO_CMD; diff --git a/src/dep_graph.c b/src/dep_graph.c index 9438e98..809bd27 100644 --- a/src/dep_graph.c +++ b/src/dep_graph.c @@ -1,3 +1,18 @@ +/* + * This file contains all functions used for maintaining a dependence graph + * that keeps track of all the cells that depends on each other. + * this is done in a two way relationship. + * + * A vertex represents an ent and has in "edges", links to other vertex's(ents) which the first vertex depends on. + * + * The other relationship is "back_edges". This is a pointer to other vertex's and + * there you will keep linked all the vertex's that use the first vertex in their formulas. + * In other words, you will keep track of all the vertex's that depends on the first vertex. + * + * NOTE: an orphan vertex represents an ent that has an enode thats need to be evaluated, + * but do not depend in another cell. + */ + #include <stdio.h> #include <stdlib.h> #include <setjmp.h> @@ -14,20 +29,6 @@ extern jmp_buf fpe_save; extern int cellerror; /* is there an error in this cell */ - -/****************************************************************************** - * This file contains all functions used for maintaining a dependence graph - * that keeps track of all the cells that depends on each other. - * this is done in a two way relationship. - * - * A vertex represents an ent and has in "edges", links to other vertex's(ents) which the first vertex depends on. - * - * The other relationship is "back_edges". This is a pointer to other vertex's and - * there you will keep linked all the vertex's that use the first vertex in their formulas. - * In other words, you will keep track of all the vertex's that depends on the first vertex. - * - * NOTE: an orphan vertex represents an ent that has an enode thats need to be evaluated, but do not depend in another cell. - *******************************************************************************/ #define CREATE_NEW(type) (type *) malloc(sizeof(type)) #define APPEND_TO_LINKLIST(firstNode, newNode, tempNode) \ @@ -42,11 +43,6 @@ extern int cellerror; /* is there an error in this cell */ tempNode->next = newNode; \ } -/* LINKS: - * https://www.cs.bu.edu/teaching/c/graph/linked/ - * https://github.com/Chetan496/cpp-algortihms/blob/master/graph.c - */ - graphADT graph; /* Creates an empty graph, with no vertices. Allocate memory from the heap */ @@ -56,7 +52,8 @@ graphADT GraphCreate() { return emptyGraph; } -/* this adds the vertex sorted in the list +/* + * this adds the vertex sorted in the list * and not at the end * given a row & col to insert as a new vertex, this function will create a new vertex with those values * and add it order in the list! @@ -98,7 +95,8 @@ vertexT * GraphAddVertex(graphADT graph , struct ent * ent) { } -/* This looks for a vertex representing a specific ent in a sorted list +/* + * This looks for a vertex representing a specific ent in a sorted list * we search for a vertex in graph and return it if found. * if not found and create flag, we add the vertex (malloc it) and return it * else if not found, it returns NULL @@ -111,14 +109,18 @@ vertexT * getVertex(graphADT graph, struct ent * ent, int create) { temp = temp->next; } - // if we get to here, there is not vertex representing ent - // we add it if create is set to true! + /* + * if we get to here, there is not vertex representing ent + * we add it if create is set to true! + */ return create ? GraphAddVertex(graph, ent) : NULL; } -/* This function adds a edge in our graph from the vertex "from" to the vertex "to" */ -// should add edges ordered in list ? +/* + * This function adds a edge in our graph from the vertex "from" to the vertex "to" + * should add edges ordered in list ? + */ void GraphAddEdge(vertexT * from, vertexT * to) { if (from == NULL || to == NULL) { sc_info("Error while adding edge: either of the vertices do not exist") ; @@ -225,7 +227,8 @@ void print_vertexs() { } -/* this function frees the memory of vertex's edges. +/* + * this function frees the memory of vertex's edges. * this also frees the vertex itself, but only if it has no back_dependences. * the only parameter is an ent pointer. */ @@ -287,10 +290,12 @@ void destroy_vertex(struct ent * ent) { } -// for each edge in edges, we look for the reference to the vertex we are deleting and we erase it! -// v_cur is the reference -// if back_reference is set, the delete is done over the back_edges list -// if not, it is done over edges list. +/* + * for each edge in edges, we look for the reference to the vertex we are deleting and we erase it! + * v_cur is the reference + * if back_reference is set, the delete is done over the back_edges list + * if not, it is done over edges list. + */ void delete_reference(vertexT * v_cur, vertexT * vc, int back_reference) { if (v_cur == NULL || vc == NULL) return; // sc_debug("we follow %d %d", vc->ent->row, vc->ent->col); @@ -441,11 +446,11 @@ void EvalJustOneVertex(register struct ent * p, int i, int j, int rebuild_graph) -/********************************************************************************** +/* * the folowing functions and variables are used for ent_that_depends_on function. * the last is used to get the list of ents that depends on an specific ent * the result is saved in a list of ents. - **********************************************************************************/ + */ struct ent_ptr * deps = NULL; int dep_size = 0; @@ -467,9 +472,11 @@ void ents_that_depends_on (struct ent * ent) { return; } -// This method returns if a vertex called dest is reachable from the vertex called src -// (if back_dep is set to false). -// if back_dep is set to true, the relationship is evaluated in the opposite way. +/* + * This method returns if a vertex called dest is reachable from the vertex called src + * (if back_dep is set to false). + * if back_dep is set to true, the relationship is evaluated in the opposite way. + */ int GraphIsReachable(vertexT * src, vertexT * dest, int back_dep) { if (src == dest) { return 1; @@ -496,8 +503,10 @@ int GraphIsReachable(vertexT * src, vertexT * dest, int back_dep) { return 0; } -// this checks dependency of a range of ents -// keep the ents in "deps" lists +/* + * this checks dependency of a range of ents + * keep the ents in "deps" lists + */ void ents_that_depends_on_range (int r1, int c1, int r2, int c2) { if (graph == NULL) return; @@ -518,6 +527,3 @@ void ents_that_depends_on_range (int r1, int c1, int r2, int c2) { } return; } -/*******************************************************************/ - - @@ -64,11 +64,11 @@ int yylex(); %token <sval> PLUGIN /* - * When adding new commands, make sure that any commands that may take - * COL as an argument precede S_FORMAT in the %token list. All other - * commands must come after S_FORMAT. This is necessary so that range - * names can be less than three letters without being parsed as column - * names. + * When adding new commands, make sure that any commands that may take + * COL as an argument precede S_FORMAT in the %token list. All other + * commands must come after S_FORMAT. This is necessary so that range + * names can be less than three letters without being parsed as column + * names. */ %token S_SHOW @@ -38,9 +38,8 @@ * * ANYONE WHO WANTS TO PORT THIS TO ANOTHER UI, WOULD JUST NEED TO REIMPLEMENT THIS FILE * AND HELP() IN HELP.C - */ - -/* + * + * * if not working with ncurses, you should also have to define LINES and COLS macros in Xui.h as well. * see ui example inside /files folder */ @@ -1,77 +1,74 @@ #ifdef UNDO /* ----------------------------------------------------------------------------------------- -UNDO and REDO features works with an 'undo' struct list. -Which contains: - p_ant: pointer to 'undo' struct. If NULL, this node is the first change - for the session. - struct ent * added: 'ent' elements added by the change - struct ent * removed: 'ent' elements removed by the change - struct ent * aux_ents: 'ent' elements that needs to be around, but out of tbl. - these are used to update formulas correctly, upon shift/deletion of ents. - struct undo_range_shift * range_shift: range shifted by change - row_hidded: integers list (int *) hidden rows on screen - row_showed: integers list (int *) visible rows on screen - col_hidded: integers list (int *) hidden columns on screen - col_showed: integers list (int *) visible columns on screen - NOTE: the first position of the lists contains (number of elements - 1) in the list - struct undo_cols_format * cols_format: list of 'undo_col_info' elements used for - undoing / redoing changes in columns format (fwidth, precision y realfmt) - p_sig: pointer to 'undo' struct, If NULL, this node is the last change in - the session. - -Follows one level UNDO/REDO scheme. A change (C1) is made, then an UNDO operation, and -another change (C2). From there later changes are removed. -Scheme: - -+ C1 -> + -> UNDO - -^ \ -|_ | - \---------------/ -| -| -| - \-> C2 --> + ... - -undo_shift_range struct contains: - int delta_rows: delta rows for the range shift - int delta_cols: delta columns for the range shift - int tlrow: Upper left row defining the range of the shift - (As if a cell range shift is made) - int tlcol: Upper left column defining the range of the shift - (As if a cell range shift is made) - int brrow: Lower right row defining the range of the shift - (As if a cell range shift is made) - int brcol: Lower right column defining the range of the shift - (As if a cell range shift is made) - -Implemented actions for UNDO/REDO: -1. Remove content from cell or range -2. Input content into a cell -3. Edit a cell -4. Change alginment of range or cell -5. Paste range or cell -6. Shift range or cell with sh, sj, sk, sl -7. Insert row or column -8. Delete row or column -9. Paste row or column -10. Hide/show rows and columns -11. Sort of a range -12. Change in the format of a range or cell -13. '-' and '+' commands in normal mode -14. Lock and unlock of cells -15. datefmt command -16. Change in format of a column as a result of the 'f' command -17. Change in format of a column as a result of auto_jus -18. Change format of columns as a result of ic dc -19. fill command -20. unformat - -NOT implemented: -1. undo of freeze / unfreeze command - ----------------------------------------------------------------------------------------- -*/ + * UNDO and REDO features works with an 'undo' struct list. + * Which contains: + * p_ant: pointer to 'undo' struct. If NULL, this node is the first change + * for the session. + * struct ent * added: 'ent' elements added by the change + * struct ent * removed: 'ent' elements removed by the change + * struct ent * aux_ents: 'ent' elements that needs to be around, but out of tbl. + * these are used to update formulas correctly, upon shift/deletion of ents. + * struct undo_range_shift * range_shift: range shifted by change + * row_hidded: integers list (int *) hidden rows on screen + * row_showed: integers list (int *) visible rows on screen + * col_hidded: integers list (int *) hidden columns on screen + * col_showed: integers list (int *) visible columns on screen + * NOTE: the first position of the lists contains (number of elements - 1) in the list + * struct undo_cols_format * cols_format: list of 'undo_col_info' elements used for + * undoing / redoing changes in columns format (fwidth, precision y realfmt) + * p_sig: pointer to 'undo' struct, If NULL, this node is the last change in + * the session. + * + * Follows one level UNDO/REDO scheme. A change (C1) is made, then an UNDO operation, and + * another change (C2). From there later changes are removed. + * Scheme: + * + * + C1 -> + -> UNDO - + * ^ \ + * |_ | + * \---------------/ + * | + * | + * | + * \-> C2 --> + ... + * + * undo_shift_range struct contains: + * int delta_rows: delta rows for the range shift + * int delta_cols: delta columns for the range shift + * int tlrow: Upper left row defining the range of the shift + * (As if a cell range shift is made) + * int tlcol: Upper left column defining the range of the shift + * (As if a cell range shift is made) + * int brrow: Lower right row defining the range of the shift + * (As if a cell range shift is made) + * int brcol: Lower right column defining the range of the shift + * (As if a cell range shift is made) + * + * Implemented actions for UNDO/REDO: + * 1. Remove content from cell or range + * 2. Input content into a cell + * 3. Edit a cell + * 4. Change alginment of range or cell + * 5. Paste range or cell + * 6. Shift range or cell with sh, sj, sk, sl + * 7. Insert row or column + * 8. Delete row or column + * 9. Paste row or column + * 10. Hide/show rows and columns + * 11. Sort of a range + * 12. Change in the format of a range or cell + * 13. '-' and '+' commands in normal mode + * 14. Lock and unlock of cells + * 15. datefmt command + * 16. Change in format of a column as a result of the 'f' command + * 17. Change in format of a column as a result of auto_jus + * 18. Change format of columns as a result of ic dc + * 19. fill command + * 20. unformat + * + * NOT implemented: + * 1. undo of freeze / unfreeze command + */ #include <stdlib.h> #include "undo.h" |