summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrés <andmarti@gmail.com>2021-05-12 18:37:37 -0300
committerAndrés <andmarti@gmail.com>2021-05-12 18:37:37 -0300
commit85a10e0179d651c3b5a15da6f09a7c12afa2bc74 (patch)
tree5cf8ab8fb0f639da3c40b818d0a64d2b9cd4ee9c
parent204e524a0c797e10b03864b3a13b8f0e296c6800 (diff)
Removed tabs and white spaces
-rw-r--r--src/cmds.c616
-rw-r--r--src/tui.c38
2 files changed, 358 insertions, 296 deletions
diff --git a/src/cmds.c b/src/cmds.c
index 8a4919f..92dbc92 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -101,6 +101,7 @@ void mark_ent_as_deleted(register struct ent * p, int delete) {
return;
}
+
/**
* \brief TODO Write brief description
*
@@ -127,6 +128,7 @@ void flush_saved() {
return;
}
+
/**
* \brief TODO Write brief description
*
@@ -149,6 +151,7 @@ void sync_refs() {
return;
}
+
/**
* \brief TODO Write brief description
*
@@ -202,6 +205,7 @@ void syncref(register struct enode * e) {
return;
}
+
/**
* \brief TODO Write brief description
*
@@ -254,6 +258,7 @@ void deletecol(int col, int mult) {
return;
}
+
/**
* \brief TODO Write a brief description
*
@@ -326,6 +331,7 @@ void int_deletecol(int col, int mult) {
return;
}
+
/**
* \brief TODO Write a brief description
*
@@ -423,6 +429,7 @@ void copyent(register struct ent * n, register struct ent * p, int dr, int dc, i
return;
}
+
/**
* \brief TODO Write brief description
* \return NUM; STR; etc.
@@ -460,6 +467,7 @@ int etype(register struct enode *e) {
return -1;
}
+
/**
* \brief TODO Write a brief function description
* \details ignorelock is used when sorting so that locked cells
@@ -523,6 +531,7 @@ void erase_area(int sr, int sc, int er, int ec, int ignorelock, int mark_as_dele
return;
}
+
/**
* \brief TODO Write a brief function description
* \details Function to copy an expression. It returns the copy.
@@ -638,6 +647,7 @@ struct enode * copye(register struct enode *e, int Rdelta, int Cdelta, int r1, i
return ret;
}
+
/**
* \brief dorowformat()
* \details: apply a row format in lines(size) to a row (r)
@@ -655,6 +665,7 @@ void dorowformat(int r, unsigned char size) {
return;
}
+
/**
* \brief TODO Write brief function description
* \details Note: Modified 9/17/90 THA to handle more formats.
@@ -702,6 +713,7 @@ void doformat(int c1, int c2, int w, int p, int r) {
}
+
/**
* \brief TODO Document formatcol)
* \param[in] c
@@ -755,6 +767,7 @@ void formatcol(int c) {
return;
}
+
/**
* \brief TODO Document insert_row()
* \details Insert a single rox. It will be inserted before currow.
@@ -797,6 +810,7 @@ void insert_row(int after) {
return;
}
+
/**
* \brief Insert new column
* \details Insert a cingle column. The column will be inserted
@@ -856,6 +870,7 @@ void insert_col(int after) {
return;
}
+
/**
* \brief Delete a row
* \param[in] row
@@ -904,6 +919,7 @@ void deleterow(int row, int mult) {
return;
}
+
/**
* \brief Delete a row
* \details Delete a row - internal function
@@ -955,6 +971,7 @@ void int_deleterow(int row, int mult) {
return;
}
+
/**
* \brief Document ljustify()
* \param[in] sr
@@ -990,6 +1007,7 @@ void ljustify(int sr, int sc, int er, int ec) {
return;
}
+
/**
* \brief TODO Document rjustify()
* \param[in] sr
@@ -1025,8 +1043,9 @@ void rjustify(int sr, int sc, int er, int ec) {
return;
}
+
/**
- * \brief TODO Cocument center()
+ * \brief TODO Document center()
* \param[in] sr
* \param[in] sc
* \param[in] er
@@ -1060,6 +1079,7 @@ void center(int sr, int sc, int er, int ec) {
return;
}
+
/**
* @brief TODO Document chg_mode
* \param[in] strcmd
@@ -1099,6 +1119,7 @@ void chg_mode(char strcmd){
return;
}
+
/**
* \brief Delete selected cells
* \details Delete selected cell or range of cells.
@@ -1155,6 +1176,7 @@ void del_selected_cells() {
return;
}
+
/**
* \brief Enter cell content on a cell
* \details Enter cell content on a cell.
@@ -1171,6 +1193,7 @@ void enter_cell_content(int r, int c, char * submode, wchar_t * content) {
if (get_conf_int("autocalc") && ! loading) EvalRange(r, c, r, c);
}
+
/**
* @brief Send command to interpreter
* \details Send command to interpreter
@@ -1197,6 +1220,7 @@ void send_to_interp(wchar_t * oper) {
return;
}
+
/**
* \brief Return a pointer to a cell's [struct ent *]
* Return a pointer to a cell's [struct ent *], creating if needed
@@ -1229,6 +1253,7 @@ struct ent * lookat(int row, int col) {
return (*pp);
}
+
/**
* \brief Blank an ent
* \param[in] p
@@ -1252,6 +1277,7 @@ void cleanent(struct ent * p) {
return;
}
+
/**
* \brief Free memory of an ent and its contents
* \param[in] v
@@ -1279,6 +1305,7 @@ void clearent(struct ent * v) {
return;
}
+
/**
* \brief Moves curcol back one displayed column
* \param[in] arg
@@ -1304,6 +1331,7 @@ struct ent * back_col(int arg) {
return lookat(currow, c);
}
+
/**
* \brief Moves curcol forward one displayed column
* \param[in] arg
@@ -1331,6 +1359,7 @@ struct ent * forw_col(int arg) {
return lookat(currow, c);
}
+
/**
* \brief Move currow forward one displayed row
* \param[in] arg
@@ -1354,6 +1383,7 @@ struct ent * forw_row(int arg) {
return lookat(r, curcol);
}
+
/**
* \brief Moves currow backward on displayed row
* \return lookat
@@ -1373,61 +1403,62 @@ struct ent * back_row(int arg) {
return lookat(r, curcol);
}
+
/**
* \brief Document scroll_down()
* \param[in] n
* \return none
*/
-void scroll_down(int n)
-{
- while (n--) {
- int last, currow_orig = currow;
- /* find last mobile row */
- calc_mobile_rows(&last);
- /* move to next non-hidden non-frozen row */
- do {
- lookat(++last, curcol);
- if (last >= maxrows)
- return;
- } while (row_hidden[last] || row_frozen[last]);
- /* this will adjust offscr_sc_rows */
- currow = last;
- calc_mobile_rows(NULL);
- /* restore currow */
- currow = currow_orig;
- if (currow < offscr_sc_rows)
- currow = offscr_sc_rows;
- unselect_ranges();
- }
+void scroll_down(int n) {
+ while (n--) {
+ int last, currow_orig = currow;
+ /* find last mobile row */
+ calc_mobile_rows(&last);
+ /* move to next non-hidden non-frozen row */
+ do {
+ lookat(++last, curcol);
+ if (last >= maxrows)
+ return;
+ } while (row_hidden[last] || row_frozen[last]);
+ /* this will adjust offscr_sc_rows */
+ currow = last;
+ calc_mobile_rows(NULL);
+ /* restore currow */
+ currow = currow_orig;
+ if (currow < offscr_sc_rows)
+ currow = offscr_sc_rows;
+ unselect_ranges();
+ }
}
+
/**
* @brief Document scroll_up()
* \param[in] n
* \return none
*/
-void scroll_up(int n)
-{
- while (n--) {
- int first, last, currow_orig = currow;
- /* move to previous non-hidden non-frozen row */
- first = offscr_sc_rows;
- do {
- if (--first < 0)
- return;
- } while (row_hidden[first] || row_frozen[first]);
- offscr_sc_rows = first;
- /* find corresponding last mobile row */
- currow = first;
- calc_mobile_rows(&last);
- /* restore/adjust currow */
- currow = currow_orig;
- if (currow > last)
- currow = last;
- unselect_ranges();
- }
+void scroll_up(int n) {
+ while (n--) {
+ int first, last, currow_orig = currow;
+ /* move to previous non-hidden non-frozen row */
+ first = offscr_sc_rows;
+ do {
+ if (--first < 0)
+ return;
+ } while (row_hidden[first] || row_frozen[first]);
+ offscr_sc_rows = first;
+ /* find corresponding last mobile row */
+ currow = first;
+ calc_mobile_rows(&last);
+ /* restore/adjust currow */
+ currow = currow_orig;
+ if (currow > last)
+ currow = last;
+ unselect_ranges();
+ }
}
+
/**
* \brief TODO Document go_home()
* \return lookat
@@ -1436,58 +1467,59 @@ struct ent * go_home() {
return lookat(0, 0);
}
+
/**
* \brief vert_top() - for command H in normal mode
* \return lookat
*/
-struct ent * vert_top()
-{
- int r = offscr_sc_rows;
- while (row_hidden[r] || row_frozen[r]) r++;
- return lookat(r, curcol);
+struct ent * vert_top() {
+ int r = offscr_sc_rows;
+ while (row_hidden[r] || row_frozen[r]) r++;
+ return lookat(r, curcol);
}
+
/**
* \brief vert_bottom() - for command L in normal mode
* \return lookat
*/
-struct ent * vert_bottom()
-{
- int last;
- calc_mobile_rows(&last);
- return lookat(last, curcol);
+struct ent * vert_bottom() {
+ int last;
+ calc_mobile_rows(&last);
+ return lookat(last, curcol);
}
+
/**
* \brief vert_middle() - for command M in normal mode
* \return lookat
*/
-struct ent * vert_middle()
-{
- int i;
- int midscreen_pos = (LINES - RESROW - RESCOLHEADER - 1)/2;
- int curr_pos = 0;
- int mobile_rows = calc_mobile_rows(NULL);
-
- for (i = 0; i < maxrows; i++) {
- if (row_hidden[i])
- continue;
- if (! row_frozen[i]) {
- if (i < offscr_sc_rows)
- continue;
- if (--mobile_rows < 0)
- continue;
- }
+struct ent * vert_middle() {
+ int i;
+ int midscreen_pos = (LINES - RESROW - RESCOLHEADER - 1)/2;
+ int curr_pos = 0;
+ int mobile_rows = calc_mobile_rows(NULL);
+
+ for (i = 0; i < maxrows; i++) {
+ if (row_hidden[i])
+ continue;
+ if (! row_frozen[i]) {
+ if (i < offscr_sc_rows)
+ continue;
+ if (--mobile_rows < 0)
+ continue;
+ }
- /* compare middle of current row against middle of screen */
- if (curr_pos + (row_format[i] - 1)/2 >= midscreen_pos)
- return lookat(i, curcol);
+ /* compare middle of current row against middle of screen */
+ if (curr_pos + (row_format[i] - 1)/2 >= midscreen_pos)
+ return lookat(i, curcol);
- curr_pos += row_format[i];
- }
- return NULL;
+ curr_pos += row_format[i];
+ }
+ return NULL;
}
+
/**
* \brief go_end(): go to last valid cell of grid
* \return lookat; NULL otherwise
@@ -1512,6 +1544,7 @@ struct ent * go_end() {
return NULL;
}
+
/**
* \brief TODO Document tick()
* \details if ticks a cell, returns struct ent *
@@ -1540,32 +1573,32 @@ struct ent * tick(char ch) {
return NULL;
}
+
/**
* \brief TODO Document scroll_right()
* \param[in] n
* \return none
*/
-void scroll_right(int n)
-{
- while (n--) {
- int last, curcol_orig = curcol;
- /* find last mobile column */
- calc_mobile_cols(&last);
- /* move to next non-hidden non-frozen column */
- do {
- lookat(currow, ++last);
- if (last >= maxcols)
- return;
- } while (col_hidden[last] || col_frozen[last]);
- /* this will adjust offscr_sc_cols */
- curcol = last;
- calc_mobile_cols(NULL);
- /* restore curcol */
- curcol = curcol_orig;
- if (curcol < offscr_sc_cols)
- curcol = offscr_sc_cols;
- unselect_ranges();
- }
+void scroll_right(int n) {
+ while (n--) {
+ int last, curcol_orig = curcol;
+ /* find last mobile column */
+ calc_mobile_cols(&last);
+ /* move to next non-hidden non-frozen column */
+ do {
+ lookat(currow, ++last);
+ if (last >= maxcols)
+ return;
+ } while (col_hidden[last] || col_frozen[last]);
+ /* this will adjust offscr_sc_cols */
+ curcol = last;
+ calc_mobile_cols(NULL);
+ /* restore curcol */
+ curcol = curcol_orig;
+ if (curcol < offscr_sc_cols)
+ curcol = offscr_sc_cols;
+ unselect_ranges();
+ }
}
/**
@@ -1573,28 +1606,28 @@ void scroll_right(int n)
* \param[in] n
* \return none
*/
-void scroll_left(int n)
-{
- while (n--) {
- int first, last, curcol_orig = curcol;
- /* move to previous non-hidden non-frozen column */
- first = offscr_sc_cols;
- do {
- if (--first < 0)
- return;
- } while (col_hidden[first] || col_frozen[first]);
- offscr_sc_cols = first;
- /* find corresponding last mobile column */
- curcol = first;
- calc_mobile_cols(&last);
- /* restore/adjust curcol */
- curcol = curcol_orig;
- if (curcol > last)
- curcol = last;
- unselect_ranges();
- }
+void scroll_left(int n) {
+ while (n--) {
+ int first, last, curcol_orig = curcol;
+ /* move to previous non-hidden non-frozen column */
+ first = offscr_sc_cols;
+ do {
+ if (--first < 0)
+ return;
+ } while (col_hidden[first] || col_frozen[first]);
+ offscr_sc_cols = first;
+ /* find corresponding last mobile column */
+ curcol = first;
+ calc_mobile_cols(&last);
+ /* restore/adjust curcol */
+ curcol = curcol_orig;
+ if (curcol > last)
+ curcol = last;
+ unselect_ranges();
+ }
}
+
/**
* \brief TODO Document left_limit()
*
@@ -1606,6 +1639,7 @@ struct ent * left_limit() {
return lookat(currow, c);
}
+
/**
* \brief right_limit()
* \details get the last valid cell to the right
@@ -1619,6 +1653,7 @@ struct ent * right_limit(int row) {
return lookat(row, c);
}
+
/**
* \brief TODO Document goto_top()
*
@@ -1630,6 +1665,7 @@ struct ent * goto_top() {
return lookat(r, curcol);
}
+
/**
* \brief TODO Document goto_bottom()
*
@@ -1643,6 +1679,7 @@ struct ent * goto_bottom() {
return lookat(r, curcol);
}
+
/**
* \brief TODO Document goto_last_col()
* traverse the table and see which is the max column that has content
@@ -1664,6 +1701,7 @@ struct ent * goto_last_col() {
return lookat(rf, mc);
}
+
/**
* @brief TODO Document go_forward()
*
@@ -1689,6 +1727,7 @@ struct ent * go_forward() {
return lookat(r_ori, c_ori);
}
+
/**
* \brief TODO Document go_bol()
*
@@ -1698,6 +1737,7 @@ struct ent * go_bol() {
return lookat(currow, offscr_sc_cols);
}
+
/**
* \brief TODO Document go_eol()
* \return none
@@ -1708,36 +1748,37 @@ struct ent * go_eol() {
return lookat(currow, last_col);
}
+
/**
* \brief TODO Document horiz_middle()
* \return lookat; NULL otherwise
*/
-struct ent * horiz_middle()
-{
- int i;
- int midscreen_pos = (COLS - rescol - 1)/2;
- int curr_pos = 0;
- int mobile_cols = calc_mobile_cols(NULL);
-
- for (i = 0; i < maxcols; i++) {
- if (col_hidden[i])
- continue;
- if (! col_frozen[i]) {
- if (i < offscr_sc_cols)
- continue;
- if (--mobile_cols < 0)
- continue;
- }
+struct ent * horiz_middle() {
+ int i;
+ int midscreen_pos = (COLS - rescol - 1)/2;
+ int curr_pos = 0;
+ int mobile_cols = calc_mobile_cols(NULL);
+
+ for (i = 0; i < maxcols; i++) {
+ if (col_hidden[i])
+ continue;
+ if (! col_frozen[i]) {
+ if (i < offscr_sc_cols)
+ continue;
+ if (--mobile_cols < 0)
+ continue;
+ }
- /* compare middle of current col against middle of screen */
- if (curr_pos + (fwidth[i] - 1)/2 >= midscreen_pos)
- return lookat(currow, i);
+ /* compare middle of current col against middle of screen */
+ if (curr_pos + (fwidth[i] - 1)/2 >= midscreen_pos)
+ return lookat(currow, i);
- curr_pos += fwidth[i];
- }
- return NULL;
+ curr_pos += fwidth[i];
+ }
+ return NULL;
}
+
/**
* \brief TODO Document go_backward()
*
@@ -1763,6 +1804,7 @@ struct ent * go_backward() {
return lookat(r_ori, c_ori);
}
+
/**
* \brief TODO Document auto_justify()
*
@@ -1823,6 +1865,7 @@ void auto_justify(int ci, int cf, int min) {
return;
}
+
/**
* \brief Delete a cell expression and turn into constant
*
@@ -1905,6 +1948,7 @@ void valueize_area(int sr, int sc, int er, int ec) {
return;
}
+
/**
* \brief TODO Document select_inner_range()
* \param[in] vir_tlrow
@@ -1951,6 +1995,7 @@ void select_inner_range(int * vir_tlrow, int * vir_tlcol, int * vir_brrow, int *
return;
}
+
/**
* \brief Check if cell is locked
*
@@ -1965,6 +2010,7 @@ int locked_cell(int r, int c) {
return 0;
}
+
/**
* \brief Check if area contains locked cells
*
@@ -1988,6 +2034,7 @@ int any_locked_cells(int r1, int c1, int r2, int c2) {
return 0;
}
+
/**
* \brief sum special command
* \return none
@@ -2026,6 +2073,7 @@ int fsum() {
return 0;
}
+
/**
* \brief fcopy special command
* \param[in] action
@@ -2139,6 +2187,7 @@ int fcopy(char * action) {
return 0;
}
+
/**
* \brief Add padding to cells
*
@@ -2185,6 +2234,7 @@ int pad(int n, int r1, int c1, int r2, int c2) {
return 0;
}
+
/**
* \brief fix_row_hidden
* \details fix hidden rows after undoing ir dr etc..
@@ -2208,6 +2258,7 @@ void fix_row_hidden(int deltar, int ri, int rf) {
return;
}
+
/**
* \brief fix_col_hidden
* \details fix hidden cols after undoing ic dc etc..
@@ -2231,6 +2282,7 @@ void fix_col_hidden(int deltac, int ci, int cf) {
return;
}
+
/**
* \brief fix_row_frozen
* \details fix frozen rows after undoing ir dr etc..
@@ -2254,6 +2306,7 @@ void fix_row_frozen(int deltar, int ri, int rf) {
return;
}
+
/**
* \brief fix_col_frozen
* \details fix frozen cols after undoing ic dc etc..
@@ -2277,6 +2330,7 @@ void fix_col_frozen(int deltac, int ci, int cf) {
return;
}
+
/**
* \brief Compute number of mobile (unfrozen) rows to fit on screen
*
@@ -2292,78 +2346,77 @@ void fix_col_frozen(int deltac, int ci, int cf) {
*
* \return Number of mobile rows displayable on the screen
*/
-int calc_mobile_rows(int *last_p)
-{
- int i, row_space, mobile_rows, last;
-
- /*
- * Compute the number of frozen rows and the space they need.
- * Eventually this should be added/subtracted when individual rows
- * are frozen/unfrozen/enlarged/reduced/deleted and not recomputed
- * every time here... or at least have a global flag indicating that
- * nothing has changed and that this loop can be skipped.
- */
- nb_frozen_rows = 0;
- nb_frozen_screenrows = 0;
- for (i = 0; i < maxrows; i++) {
- if (row_hidden[i])
- continue;
- if (row_frozen[i]) {
- nb_frozen_rows++;
- nb_frozen_screenrows += row_format[i];
- }
- }
-
- /* Adjust display start if currow is above it */
- if (currow < offscr_sc_rows)
- offscr_sc_rows = currow;
-
- /* Determine the space available for mobile rows. */
- row_space = LINES - RESROW - RESCOLHEADER - nb_frozen_screenrows;
-
- /*
- * Find how many visible mobile rows can fit in there
- * and remember which one is the last to fit.
- */
- mobile_rows = 0;
- last = offscr_sc_rows;
- for (i = offscr_sc_rows; i < maxrows; i++) {
- if (row_hidden[i])
- continue;
- if (row_frozen[i])
- continue;
- if (row_format[i] > row_space)
- break;
- row_space -= row_format[i];
- mobile_rows++;
- last = i;
- }
-
- /*
- * If currow is beyond the last row here then we must start over,
- * moving backward this time, to properly position start of display.
- */
- if (last < currow) {
- row_space = LINES - RESROW - RESCOLHEADER - nb_frozen_screenrows;
- mobile_rows = 0;
- last = currow;
- for (i = currow; i >= 0; i--) {
- if (row_hidden[i])
- continue;
- if (row_frozen[i])
- continue;
- if (row_format[i] > row_space)
- break;
- row_space -= row_format[i];
- mobile_rows++;
- last = i;
- }
- offscr_sc_rows = last;
- }
-
- if (last_p)
- *last_p = last;
- return mobile_rows;
+int calc_mobile_rows(int *last_p) {
+ int i, row_space, mobile_rows, last;
+
+ /*
+ * Compute the number of frozen rows and the space they need.
+ * Eventually this should be added/subtracted when individual rows
+ * are frozen/unfrozen/enlarged/reduced/deleted and not recomputed
+ * every time here... or at least have a global flag indicating that
+ * nothing has changed and that this loop can be skipped.
+ */
+ nb_frozen_rows = 0;
+ nb_frozen_screenrows = 0;
+ for (i = 0; i < maxrows; i++) {
+ if (row_hidden[i])
+ continue;
+ if (row_frozen[i]) {
+ nb_frozen_rows++;
+ nb_frozen_screenrows += row_format[i];
+ }
+ }
+
+ /* Adjust display start if currow is above it */
+ if (currow < offscr_sc_rows)
+ offscr_sc_rows = currow;
+
+ /* Determine the space available for mobile rows. */
+ row_space = LINES - RESROW - RESCOLHEADER - nb_frozen_screenrows;
+
+ /*
+ * Find how many visible mobile rows can fit in there
+ * and remember which one is the last to fit.
+ */
+ mobile_rows = 0;
+ last = offscr_sc_rows;
+ for (i = offscr_sc_rows; i < maxrows; i++) {
+ if (row_hidden[i])
+ continue;
+ if (row_frozen[i])
+ continue;
+ if (row_format[i] > row_space)
+ break;
+ row_space -= row_format[i];
+ mobile_rows++;
+ last = i;
+ }
+
+ /*
+ * If currow is beyond the last row here then we must start over,
+ * moving backward this time, to properly position start of display.
+ */
+ if (last < currow) {
+ row_space = LINES - RESROW - RESCOLHEADER - nb_frozen_screenrows;
+ mobile_rows = 0;
+ last = currow;
+ for (i = currow; i >= 0; i--) {
+ if (row_hidden[i])
+ continue;
+ if (row_frozen[i])
+ continue;
+ if (row_format[i] > row_space)
+ break;
+ row_space -= row_format[i];
+ mobile_rows++;
+ last = i;
+ }
+ offscr_sc_rows = last;
+ }
+
+ if (last_p)
+ *last_p = last;
+ return mobile_rows;
}
/**
@@ -2381,80 +2434,80 @@ int calc_mobile_rows(int *last_p)
*
* \return Number of mobile columns displayable on the screen
*/
-int calc_mobile_cols(int *last_p)
-{
- int i, col_space, mobile_cols, last;
-
- /*
- * Compute the number of frozen columns and the space they need.
- * Eventually this should be added/subtracted when individual
- * columns are frozen/unfrozen/enlarged/reduced/deleted and not
- * recomputed every time here... or at least have a flag indicating
- * that nothing has changed and that this loop may be skipped.
- */
- nb_frozen_cols = 0;
- nb_frozen_screencols = 0;
- for (i = 0; i < maxcols; i++) {
- if (row_frozen[i])
- continue;
- if (col_frozen[i]) {
- nb_frozen_cols++;
- nb_frozen_screencols += fwidth[i];
- }
- }
-
- /* Adjust display start if curcol is left of it */
- if (curcol < offscr_sc_cols)
- offscr_sc_cols = curcol;
-
- /* Determine the space available for mobile columns. */
- col_space = COLS - rescol - nb_frozen_screencols;
-
- /*
- * Find how many visible mobile columns can fit in there
- * and remember which one is the last to fit.
- */
- mobile_cols = 0;
- last = offscr_sc_cols;
- for (i = offscr_sc_cols; i < maxcols; i++) {
- if (col_hidden[i])
- continue;
- if (col_frozen[i])
- continue;
- if (fwidth[i] > col_space)
- break;
- col_space -= fwidth[i];
- mobile_cols++;
- last = i;
- }
-
- /*
- * If curcol is beyond the last column here then we start over,
- * moving backward this time, to properly position start of display.
- */
- if (last < curcol) {
- col_space = COLS - rescol - nb_frozen_screencols;
- mobile_cols = 0;
- last = curcol;
- for (i = curcol; i >= 0; i--) {
- if (col_hidden[i])
- continue;
- if (col_frozen[i])
- continue;
- if (fwidth[i] > col_space)
- break;
- col_space -= fwidth[i];
- mobile_cols++;
- last = i;
- }
- offscr_sc_cols = last;
- }
-
- if (last_p)
- *last_p = last;
- return mobile_cols;
+int calc_mobile_cols(int *last_p) {
+ int i, col_space, mobile_cols, last;
+
+ /*
+ * Compute the number of frozen columns and the space they need.
+ * Eventually this should be added/subtracted when individual
+ * columns are frozen/unfrozen/enlarged/reduced/deleted and not
+ * recomputed every time here... or at least have a flag indicating
+ * that nothing has changed and that this loop may be skipped.
+ */
+ nb_frozen_cols = 0;
+ nb_frozen_screencols = 0;
+ for (i = 0; i < maxcols; i++) {
+ if (row_frozen[i])
+ continue;
+ if (col_frozen[i]) {
+ nb_frozen_cols++;
+ nb_frozen_screencols += fwidth[i];
+ }
+ }
+
+ /* Adjust display start if curcol is left of it */
+ if (curcol < offscr_sc_cols)
+ offscr_sc_cols = curcol;
+
+ /* Determine the space available for mobile columns. */
+ col_space = COLS - rescol - nb_frozen_screencols;
+
+ /*
+ * Find how many visible mobile columns can fit in there
+ * and remember which one is the last to fit.
+ */
+ mobile_cols = 0;
+ last = offscr_sc_cols;
+ for (i = offscr_sc_cols; i < maxcols; i++) {
+ if (col_hidden[i])
+ continue;
+ if (col_frozen[i])
+ continue;
+ if (fwidth[i] > col_space)
+ break;
+ col_space -= fwidth[i];
+ mobile_cols++;
+ last = i;
+ }
+
+ /*
+ * If curcol is beyond the last column here then we start over,
+ * moving backward this time, to properly position start of display.
+ */
+ if (last < curcol) {
+ col_space = COLS - rescol - nb_frozen_screencols;
+ mobile_cols = 0;
+ last = curcol;
+ for (i = curcol; i >= 0; i--) {
+ if (col_hidden[i])
+ continue;
+ if (col_frozen[i])
+ continue;
+ if (fwidth[i] > col_space)
+ break;
+ col_space -= fwidth[i];
+ mobile_cols++;
+ last = i;
+ }
+ offscr_sc_cols = last;
+ }
+
+ if (last_p)
+ *last_p = last;
+ return mobile_cols;
}
+
/**
* \brief pad_and_align
*
@@ -2571,6 +2624,7 @@ void pad_and_align (char * str_value, char * numeric_value, int col_width, int a
return;
}
+
/**
* \brief Check if the buffer content is a valid command
*
diff --git a/src/tui.c b/src/tui.c
index f635b09..79142da 100644
--- a/src/tui.c
+++ b/src/tui.c
@@ -300,7 +300,6 @@ void ui_sc_msg(char * s, int type, ...) {
*
* \return none
*/
-
void ui_do_welcome() {
char * msg_title = "SC-IM - SpreadSheet Calculator Improvised";
char * msg_by = "An SC fork by Andrés Martinelli";
@@ -374,6 +373,7 @@ void ui_do_welcome() {
return;
}
+
/**
* \brief Refreshes screen grid
*
@@ -385,7 +385,6 @@ void ui_do_welcome() {
*
* \return none
*/
-
void ui_update(int header) {
if (loading) return;
if (cmd_multiplier > 1) return;
@@ -458,7 +457,6 @@ void ui_update(int header) {
*
* \return none
*/
-
void ui_handle_cursor() {
switch (curmode) {
case COMMAND_MODE:
@@ -477,6 +475,7 @@ void ui_handle_cursor() {
return;
}
+
/**
* \brief Print string with alignment
*
@@ -493,19 +492,18 @@ void ui_handle_cursor() {
*
* \return none
*/
-
void ui_write_j(WINDOW * win, const char * word, const unsigned int row, const unsigned int justif) {
(justif == 0) ? (wmove(win, row, 0) && wclrtoeol(win)) : wmove(win, row, COLS - strlen(word));
wprintw(win, "%s", word);
return;
}
+
/**
* \brief Print multiplier and pending operator to the status bar
*
* \return none
*/
-
void ui_print_mult_pend() {
if (curmode != NORMAL_MODE && curmode != VISUAL_MODE && curmode != EDIT_MODE) return;
@@ -543,12 +541,12 @@ void ui_print_mult_pend() {
}
}
+
/**
* \brief Show first and second row (header). Handle cursor position.
*
* \return none
*/
-
void ui_show_header() {
//ui_clr_header(0);
ui_clr_header(1);
@@ -580,6 +578,7 @@ void ui_show_header() {
return;
}
+
/**
* \brief ui_clr_header
* \details clr a line
@@ -617,7 +616,6 @@ void ui_clr_header(int i) {
*
* \return none
*/
-
void ui_print_mode() {
unsigned int row = 0; // Print mode in first row
char strm[PATHLEN+22] = "";
@@ -672,6 +670,7 @@ void ui_print_mode() {
return;
}
+
/**
* \brief Show sc_row headings: 0, 1, 2...
*
@@ -680,7 +679,6 @@ void ui_print_mode() {
*
* \return none
*/
-
void ui_show_sc_row_headings(WINDOW * win, int nb_mobile_rows) {
#ifdef USECOLORS
if (has_colors()) ui_set_ucolor(win, &ucolors[HEADINGS], DEFAULT_COLOR);
@@ -727,6 +725,7 @@ void ui_show_sc_row_headings(WINDOW * win, int nb_mobile_rows) {
}
}
+
/**
* \brief Show sc_col headings: A, B, C...
*
@@ -735,7 +734,6 @@ void ui_show_sc_row_headings(WINDOW * win, int nb_mobile_rows) {
*
* \return none
*/
-
void ui_show_sc_col_headings(WINDOW * win, int nb_mobile_cols) {
int i;
srange * s = get_selected_range();
@@ -791,6 +789,7 @@ void ui_show_sc_col_headings(WINDOW * win, int nb_mobile_cols) {
}
}
+
/**
* \brief Show the content of the cell
*
@@ -800,7 +799,6 @@ void ui_show_sc_col_headings(WINDOW * win, int nb_mobile_cols) {
*
* \return none
*/
-
void ui_show_content(WINDOW * win, int nb_mobile_rows, int nb_mobile_cols) {
int row, col;
@@ -1047,6 +1045,7 @@ void ui_show_content(WINDOW * win, int nb_mobile_rows, int nb_mobile_cols) {
}
}
+
/**
* \brief Add details of an ent to a char*
*
@@ -1096,6 +1095,7 @@ void ui_add_cell_detail(char * d, struct ent * p1) {
}
}
+
/**
* \brief Draw cell content detail in header
* \return none
@@ -1162,6 +1162,7 @@ void ui_show_celldetails() {
wrefresh(input_win);
}
+
/**
* \brief Error routine for yacc (gram.y)
*
@@ -1176,6 +1177,7 @@ void yyerror(char * err) {
return;
}
+
/**
* \brief Create a string that represents the formatted value of the cell
*
@@ -1188,7 +1190,6 @@ void yyerror(char * err) {
* \return 1 if format of number - (numbers with format) - puede harber label.
* \return -1 if there is no format in the cell
*/
-
int ui_get_formated_value(struct ent ** p, int col, char * value) {
//char * cfmt = (*p)->format ? (*p)->format : NULL;
char * cfmt = (*p)->format ? (*p)->format : (realfmt[col] >= 0 && realfmt[col] < COLFORMATS && colformat[realfmt[col]] != NULL) ? colformat[realfmt[col]] : NULL;
@@ -1210,6 +1211,7 @@ int ui_get_formated_value(struct ent ** p, int col, char * value) {
}
}
+
/**
* \brief Shows text in child process
*
@@ -1218,7 +1220,6 @@ int ui_get_formated_value(struct ent ** p, int col, char * value) {
*
* \param[in] val
*/
-
void ui_show_text(char * val) {
int pid;
char px[MAXCMD];
@@ -1248,7 +1249,6 @@ void ui_show_text(char * val