Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cellcolor output incorrect #187

Closed
charlespax opened this issue Jul 19, 2017 · 6 comments
Closed

cellcolor output incorrect #187

charlespax opened this issue Jul 19, 2017 · 6 comments

Comments

@charlespax
Copy link
Contributor

charlespax commented Jul 19, 2017

Open a spreadsheet. Type :cellcolor A0:Z0 "bold=1. You will see that line A is in bold white text. Save file. Exit scim. Reopen the file. You will not see any bold text on line A.

If you look at the .sc file in a text editor, you will find the following line within the .sc file.
cellcolor A0:Z0 "fg=WHITE bg=ÿ?TE bold=1"

You can edit the .sc file to read ``cellcolor A0:Z0 "fg=WHITE bg=BLACK bold=1"` and then the colors will work correctly.

I am running Bash on Windows, Ubuntu version. uname -a gives Linux DESKTOP-7Q4DUMC 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 x86_64 x86_64 x86_64 GNU/Linux. Using commit 973e899 from 2017-07-05.

@andmarti1424
Copy link
Owner

This is very strange. Will try to reproduce it.

@charlespax
Copy link
Contributor Author

charlespax commented Jul 20, 2017

I think I found the location of the issue, but I'm not sure of the actual cause. Check out the diff below.

Here is my test.sc file:

# This data file was generated by SC-IM.
# You almost certainly shouldn't edit it.

leftstring A0 = "Cell A1"
leftstring B0 = "Cell A2"
leftstring C0 = "Cell A3"
leftstring A1 = "Row 1"
let B1 = 24
let C1 = 12
leftstring A2 = "Row 2"
let B2 = 21
let C2 = 40
goto C2

Opening this file and executing cellcolor a0:z0 "bold=1" gives a saved file of:

# This data file was generated by SC-IM.
# You almost certainly shouldn't edit it.

leftstring A0 = "Cell A1"
leftstring B0 = "Cell A2"
leftstring C0 = "Cell A3"
leftstring A1 = "Row 1"
let B1 = 24
let C1 = 12
leftstring A2 = "Row 2"
let B2 = 21
let C2 = 40
cellcolor A0:Z0 "fg=WHITE bg=ÿ?TE bold=1"
goto C2

Note that executing cat test.sc will not show ÿ as that is a non-printable EOF character.

I then apply this diff:

diff --git a/src/file.c b/src/file.c
index 7cc2332..daf9e4c 100644
--- a/src/file.c
+++ b/src/file.c
@@ -295,7 +295,7 @@ void write_fd(register FILE *f, int r0, int c0, int rn, int cn) {
                     decompile(e, 0);
                     uppercase(line);
                     del_char(line, 0);
-                    sprintf(strcolor + strlen(strcolor), " bg=%s", &line[0]);
+                    sprintf(strcolor + strlen(strcolor), " bg=problem-->%s", &line[0]);
                     free(e);

                     if ((*pp)->ucolor->bold)      sprintf(strcolor + strlen(strcolor), " bold=1");

If I recompile sc-im and do the same procedure on the original test.sc file I get:

# This data file was generated by SC-IM.
# You almost certainly shouldn't edit it.

leftstring A0 = "Cell A1"
leftstring B0 = "Cell A2"
leftstring C0 = "Cell A3"
leftstring A1 = "Row 1"
let B1 = 24
let C1 = 12
leftstring A2 = "Row 2"
let B2 = 21
let C2 = 40
cellcolor A0:Z0 "fg=WHITE bg=problem-->ÿ?TE bold=1"
goto C2

Maybe there is some sort of type issue when int value of the color is decompiled. Specifically, it looks like &line[0] on line 298 of file.c is outputting incorrectly.

@andmarti1424
Copy link
Owner

Are you using gcc?

@andmarti1424
Copy link
Owner

If not, could you please try building it with another compiler?

@charlespax
Copy link
Contributor Author

I believe I've been using gcc. I compiled again using make CC=gcc explicitly and get the same results.

I followed the instructions on the Debian install walk through. Here is a diff of my Makefile against what is in the master branch:

diff --git a/src/Makefile b/src/Makefile
index bc65db0..82b3ea5 100755
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,8 +1,8 @@
 # Specify the name of the resulting executable file
-name = scim
+name = sim

 # The base directory where everything should be installed.
-prefix  = /usr/local
+prefix  = /usr/local/stow/sc-im

 EXDIR   = $(prefix)/bin
 HELPDIR = $(prefix)/share/$(name)
@@ -13,10 +13,10 @@ MANDIR  = $(prefix)/share/man/man1

 # Change these to your liking or use `make CC=gcc` etc
 #CC   = cc
-#YACC = bison -y
+YACC = bison -y
 #SED  = sed

-LDLIBS += -lm
+LDLIBS += -lm -lncursesw -lzip -lxml2

 CFLAGS += -Wall -g
 CFLAGS += -DNCURSES
@@ -26,7 +26,7 @@ CFLAGS += -DHELP_PATH=\"$(HELPDIR)\"
 CFLAGS += -DLIBDIR=\"$(LIBDIR)\"

 # Sets default pager, e.g. 'less' or 'more'
-CFLAGS += -DDFLT_PAGER=\"less\"
+CFLAGS += -DDFLT_PAGER=\"pager\"
 # Sets default editor. Its use in case EDITOR env variable is not set
 CFLAGS += -DDFLT_EDITOR=\"vim\"
 # Comment out to disable color support
@@ -74,8 +74,8 @@ endif

 # NOTE: libxlsxwriter is required for xlsx file export support
 ifneq (,$(wildcard /usr/include/xlsxwriter.h))
-  CFLAGS += -DXLSX_EXPORT
-  LDLIBS += -lxlsxwriter
+#  CFLAGS += -DXLSX_EXPORT
+#  LDLIBS += -lxlsxwriter
 endif

 # Check for gnuplot existance

@charlespax
Copy link
Contributor Author

charlespax commented Jul 20, 2017

I dug a little deeper.

This diff fixes the issue:

diff --git a/src/color.c b/src/color.c
index cbd34e7..3ce5e52 100644
--- a/src/color.c
+++ b/src/color.c
@@ -260,7 +260,7 @@ void color_cell(int r, int c, int rf, int cf, char * str) {
             if (n->ucolor == NULL) {
                 n->ucolor = (struct ucolor *) malloc(sizeof(struct ucolor));
                 n->ucolor->fg = WHITE;
-                n->ucolor->bg = DEFAULT_COLOR;
+                n->ucolor->bg = BLACK;
                 n->ucolor->bold = 0;
                 n->ucolor->dim = 0;
                 n->ucolor->reverse = 0;

This gives cellcolor A0:Z0 "fg=WHITE" bg=BLACK bold=1"

I think the issue is that the background (bg) color is set as DEFAULT_COLOR, which is -1 in tui.h line 8: c#define DEFAULT_COLOR -1. We don't see this happening with the foreground color (fg) because it is set to WHITE.

To check, I applied this diff:

diff --git a/src/color.c b/src/color.c
index cbd34e7..b98a5fe 100644
--- a/src/color.c
+++ b/src/color.c
@@ -259,8 +259,8 @@ void color_cell(int r, int c, int rf, int cf, char * str) {
             n = lookat(i, j);
             if (n->ucolor == NULL) {
                 n->ucolor = (struct ucolor *) malloc(sizeof(struct ucolor));
-                n->ucolor->fg = WHITE;
-                n->ucolor->bg = DEFAULT_COLOR;
+                n->ucolor->fg = DEFAULT_COLOR;
+                n->ucolor->bg = BLACK;
                 n->ucolor->bold = 0;
                 n->ucolor->dim = 0;
                 n->ucolor->reverse = 0;

Then I get the following result in test.sc: cellcolor A0:Z0 "fg=ÿ?TSTRING B0 = "BBB" bg=BLACK bold=1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants