[hackers] [dvtm] Status bar aesthetic patch

2015-07-17 Thread Ross Mohn
Hi,

I like to to use my own characters at the beginning and end of the
status bar message. Previously I've edited dvtm.c directly, but it's
better to have this configurable in config.h so that eveeryone can
choose their own.

Thanks -Ross

diff --git a/config.def.h b/config.def.h
index e25d83c..32a2a1e 100644
--- a/config.def.h
+++ b/config.def.h
@@ -30,6 +30,9 @@ static Color colors[] = {
 #define URGENT_ATTR NORMAL_ATTR
 /* curses attributes for the status bar */
 #define BAR_ATTR(COLOR(BLUE) | A_NORMAL)
+/* characters for beginning and end of status bar message */
+#define BAR_BEGIN   '['
+#define BAR_END ']'
 /* status bar (command line option -s) position */
 #define BAR_POS BAR_TOP /* BAR_BOTTOM, BAR_OFF */
 /* whether status bar should be hidden if only one client exists */
diff --git a/dvtm.c b/dvtm.c
index dbacb39..7170f3b 100644
--- a/dvtm.c
+++ b/dvtm.c
@@ -348,7 +348,7 @@ drawbar(void) {
 	(void)y;
 	int maxwidth = screen.w - x - 2;
 
-	addch('[');
+	addch(BAR_BEGIN);
 	attrset(BAR_ATTR);
 
 	wchar_t wbuf[sizeof bar.text];
@@ -370,7 +370,7 @@ drawbar(void) {
 	}
 
 	attrset(TAG_NORMAL);
-	mvaddch(bar.y, screen.w - 1, ']');
+	mvaddch(bar.y, screen.w - 1, BAR_END);
 	attrset(NORMAL_ATTR);
 	move(sy, sx);
 	wnoutrefresh(stdscr);


[hackers] [scc] fix missing ; || Hiltjo Posthuma

2015-07-17 Thread git
commit f00413b6a611d855fc398604c10a5b8c0afa596b
Author: Hiltjo Posthuma hil...@codemadness.org
AuthorDate: Fri Jul 17 20:29:58 2015 +0200
Commit: Roberto E. Vargas Caballero k...@shike2.com
CommitDate: Fri Jul 17 20:58:50 2015 +0200

fix missing ;

diff --git a/cc1/cpp.c b/cc1/cpp.c
index 3e10e2e..4df8244 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -447,7 +447,7 @@ ifclause(int isdef)
 
if (cppctx == NR_COND-1)
error(too much nesting levels of conditional inclusion);
-   n = cppctx++
+   n = cppctx++;
if (yytoken != IDEN) {
error(no macro name given in #%s directive,
  (isdef) ? ifdef : ifndef);



Re: [hackers] [scc][patch] fix build + some whitespace fixes

2015-07-17 Thread Eric Pruitt
On Fri, Jul 17, 2015 at 08:33:12PM +0200, Hiltjo Posthuma wrote:
 patch 1: whitespace fixes
 patch 2: make fp of type FILE * and use needed includes
 patch 3: fix missing ;

You forgot the attachments.

Eric



Re: [hackers] [scc][patch] fix build + some whitespace fixes

2015-07-17 Thread Hiltjo Posthuma
On Fri, Jul 17, 2015 at 8:34 PM, Eric Pruitt eric.pru...@gmail.com wrote:

 You forgot the attachments.

Lol, sorry, again:

patch 1: whitespace fixes
patch 2: make fp of type FILE * and use needed includes
patch 3: fix missing ;
From fdcb684addcb71b6067b6668bd0e723277e22544 Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma hil...@codemadness.org
Date: Fri, 17 Jul 2015 20:28:56 +0200
Subject: [PATCH 1/3] whitespace fixes

---
 cc1/cc1.h |  1 -
 cc1/cpp.c | 26 +-
 2 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 7095cf2..6a9d9aa 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -13,7 +13,6 @@ typedef struct caselist Caselist;
 typedef struct node Node;
 typedef struct input Input;
 
-
 struct type {
unsigned char op;   /* type builder operator */
unsigned char ns;
diff --git a/cc1/cpp.c b/cc1/cpp.c
index 534585a..3e10e2e 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -59,17 +59,17 @@ icpp(void)
 static void
 nextcpp(void)
 {
-next();
-if (yytoken == EOFTOK)
+   next();
+   if (yytoken == EOFTOK)
error(unterminated argument list invoking macro \%s\,
-  macroname);
-if (yylen + 1  arglen)
-error(argument overflow invoking macro \%s\,
-  macroname);
-memcpy(argp, yytext, yylen);
-argp += yylen;
-*argp++ = ' ';
-arglen -= yylen + 1;
+ macroname);
+   if (yylen + 1  arglen)
+   error(argument overflow invoking macro \%s\,
+ macroname);
+   memcpy(argp, yytext, yylen);
+   argp += yylen;
+   *argp++ = ' ';
+   arglen -= yylen + 1;
 }
 
 static void
@@ -171,7 +171,7 @@ copymacro(char *bp, char *s, size_t bufsiz, char *arglist[])
s += 2;
}
}
-*bp = '\0';
+   *bp = '\0';
 
return;
 
@@ -201,8 +201,8 @@ expand(char *begin, Symbol *sym)
macroname = sym-name;
if (!parsepars(arguments, arglist, atoi(s)))
return 0;
-for (n = 0; n  atoi(s); ++n)
-fprintf(stderr, PAR%d:%s\n, n, arglist[n]);
+   for (n = 0; n  atoi(s); ++n)
+   fprintf(stderr, PAR%d:%s\n, n, arglist[n]);
 
copymacro(buffer, s+3, INPUTSIZ-1, arglist);
 
-- 
2.3.0

From 88eb60a95be178120f204bc80d6a011cece4522b Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma hil...@codemadness.org
Date: Fri, 17 Jul 2015 20:29:28 +0200
Subject: [PATCH 2/3] make fp of type FILE * and use needed includes

---
 cc1/cc1.h| 2 +-
 cc1/decl.c   | 1 +
 cc1/symbol.c | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 6a9d9aa..5a18e21 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -73,7 +73,7 @@ struct yystype {
 
 struct input {
char *fname;
-   void *fp;
+   FILE *fp;
char *line, *begin, *p;
struct input *next;
unsigned short nline;
diff --git a/cc1/decl.c b/cc1/decl.c
index 9d6ff98..ded6ee4 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -1,6 +1,7 @@
 
 #include inttypes.h
 #include setjmp.h
+#include stdio.h
 #include string.h
 
 #include ../inc/sizes.h
diff --git a/cc1/symbol.c b/cc1/symbol.c
index 57eb7ac..c869cd6 100644
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -1,5 +1,6 @@
 
 #include inttypes.h
+#include stdio.h
 #include stdlib.h
 #include string.h
 
-- 
2.3.0

From a81a19be94c21fffa5b92aeb6bd484f50f5e62c0 Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma hil...@codemadness.org
Date: Fri, 17 Jul 2015 20:29:58 +0200
Subject: [PATCH 3/3] fix missing ;

---
 cc1/cpp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cc1/cpp.c b/cc1/cpp.c
index 3e10e2e..4df8244 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -447,7 +447,7 @@ ifclause(int isdef)
 
if (cppctx == NR_COND-1)
error(too much nesting levels of conditional inclusion);
-   n = cppctx++
+   n = cppctx++;
if (yytoken != IDEN) {
error(no macro name given in #%s directive,
  (isdef) ? ifdef : ifndef);
-- 
2.3.0



[hackers] [scc] Discard symbol in undef() || Roberto E. Vargas Caballero

2015-07-17 Thread git
commit dbb2ca15669b9542a46f2232ce74c3f95afd2902
Author: Roberto E. Vargas Caballero k...@shike2.com
AuthorDate: Sat Jul 18 00:06:34 2015 +0200
Commit: Roberto E. Vargas Caballero k...@shike2.com
CommitDate: Sat Jul 18 07:22:29 2015 +0200

Discard symbol in undef()

Once that the symbol is undefined, then we have to pass
to the next symbol, which should be EOF.

diff --git a/cc1/cpp.c b/cc1/cpp.c
index 30a3b20..3eecc54 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -512,6 +512,7 @@ undef(void)
}
sym = lookup(NS_CPP);
sym-flags = ~ISDEFINED;
+   next();
 }
 
 bool



[hackers] [scc] Fix cut/paste in macro expansion || Roberto E. Vargas Caballero

2015-07-17 Thread git
commit 36f259ae86ef2ab10ef3beeb6bcda9cdec68acfd
Author: Roberto E. Vargas Caballero k...@shike2.com
AuthorDate: Sat Jul 18 00:04:03 2015 +0200
Commit: Roberto E. Vargas Caballero k...@shike2.com
CommitDate: Sat Jul 18 07:22:29 2015 +0200

Fix cut/paste in macro expansion

The replacement of the macro invocation by the macro expansion
was wrong, mainly because we must know left length, rigth length,
expansion length and invocation length, but we were using only
one length.

diff --git a/cc1/cpp.c b/cc1/cpp.c
index b904e5a..30a3b20 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -182,22 +182,22 @@ expansion_too_long:
 bool
 expand(char *begin, Symbol *sym)
 {
-   size_t len;
+   size_t total, elen, rlen, llen, ilen;
int n, r;
char *s = sym-u.s;
char *arglist[NR_MACROARG], arguments[INPUTSIZ], buffer[BUFSIZE];
 
-   fprintf(stderr, macro '%s':%s\n, sym-name, sym-u.s);
if (sym == symfile) {
sprintf(buffer, \%s\, input-fname);
goto print_subs;
}
if (sym == symline) {
-   r = snprintf(buffer, sizeof(buffer), %s, input-line);
+   r = snprintf(buffer, sizeof(buffer), %d, input-nline);
if(r == -1 || (size_t)r = sizeof(buffer)) {
error(expansion of macro \%s\ is too long, 
sym-name);
return 0;
}
+   fprintf(stderr, Expansion of line '%s'\n, buffer);
goto print_subs;
}
 
@@ -211,17 +211,22 @@ expand(char *begin, Symbol *sym)
 
 print_subs:
fprintf(stderr, macro '%s' expanded to :'%s'\n, macroname, buffer);
-   len = strlen(buffer);
+   elen = strlen(buffer);/* expansion lentgh */
+   rlen = strlen(input-p);  /* rigth length */
+   llen = begin - input-line;   /* left length */
+   ilen = input-p - begin;  /* invocation length */
+   total = llen + elen + rlen;
 
-   if (begin - input-line + len = LINESIZ-1)
+   if (total = LINESIZ)
error(macro expansion too long);
 
/* cut macro invocation */
-   memmove(begin, input-p, input-p - begin);
+   memmove(begin, begin + ilen, rlen);
 
/* paste macro expansion */
-   memmove(begin + len, begin, len);
-   memcpy(begin, buffer, len);
+   memmove(begin + elen, begin, rlen);
+   memcpy(begin, buffer, elen);
+   input-line[total] = '\0';
 
input-p = input-begin = begin;
 



[hackers] [scc] Add #endif clauses || Roberto E. Vargas Caballero

2015-07-17 Thread git
commit 660288e9ac9bb504280b5051a3e1d83bce617765
Author: Roberto E. Vargas Caballero k...@shike2.com
AuthorDate: Fri Jul 17 22:55:00 2015 +0200
Commit: Roberto E. Vargas Caballero k...@shike2.com
CommitDate: Fri Jul 17 23:14:53 2015 +0200

Add #endif clauses

I forgot it in the rewriting ^^.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 518ed6a..1f1d7f4 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -202,6 +202,7 @@ enum tokens {
IFDEF,
IFNDEF,
UNDEF,
+   ENDIF,
EOFTOK
 };
 
diff --git a/cc1/cpp.c b/cc1/cpp.c
index a81b5cc..b66c45b 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -477,6 +477,15 @@ ifndef(void)
 }
 
 static void
+endif(void)
+{
+   if (cppctx == 0)
+   error(#endif without #if);
+   if (!ifstatus[--cppctx])
+   --cppoff;
+}
+
+static void
 elseclause(void)
 {
if (cppctx == 0)
@@ -513,6 +522,7 @@ cpp(void)
{IFDEF, ifdef},
{IFNDEF, ifndef},
{ELSE, elseclause},
+   {ENDIF, endif},
{UNDEF, undef},
{PRAGMA, pragma},
{ERROR, usererr},
diff --git a/cc1/symbol.c b/cc1/symbol.c
index c869cd6..01d8053 100644
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -235,6 +235,7 @@ ikeywords(void)
{ifdef, IFDEF, IFDEF},
{else, ELSE, ELSE},
{ifndef, IFNDEF, IFNDEF},
+   {endif, ENDIF, ENDIF},
{undef, UNDEF, UNDEF},
{pragma, PRAGMA, PRAGMA},
{error, ERROR, ERROR}



[hackers] [scc] Disable macro expansions in cpp clausules || Roberto E. Vargas Caballero

2015-07-17 Thread git
commit e21b9b0779b6daa0e082d059ce6a179f4b454bef
Author: Roberto E. Vargas Caballero k...@shike2.com
AuthorDate: Fri Jul 17 22:56:38 2015 +0200
Commit: Roberto E. Vargas Caballero k...@shike2.com
CommitDate: Fri Jul 17 23:14:53 2015 +0200

Disable macro expansions in cpp clausules

It is mandatory by the standard, and it is needed
beause in other case you can have recursion problems

diff --git a/cc1/cpp.c b/cc1/cpp.c
index b66c45b..b904e5a 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -532,6 +532,8 @@ cpp(void)
if (*input-p != '#')
return 0;
++input-p;
+
+   disexpand = 1;
lexmode = CPPMODE;
setnamespace(NS_CPPCLAUSES);
next();
@@ -544,6 +546,8 @@ cpp(void)
 
if (yytoken != EOFTOK  !cppoff)
error(trailing characters after preprocessor directive);
+   disexpand = 0;
lexmode = CCMODE;
+
return 1;
 }



[hackers] [scc] getdefs: remove statement with no effect || Hiltjo Posthuma

2015-07-17 Thread git
commit fb52401a1d119fd02590755c6fd5173ac65210b2
Author: Hiltjo Posthuma hil...@codemadness.org
AuthorDate: Fri Jul 17 21:31:41 2015 +0200
Commit: Hiltjo Posthuma hil...@codemadness.org
CommitDate: Fri Jul 17 22:34:35 2015 +0200

getdefs: remove statement with no effect

diff --git a/cc1/cpp.c b/cc1/cpp.c
index 5264274..e8894f0 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -296,10 +296,8 @@ getdefs(Symbol *args[NR_MACROARG], int nargs, char *bp, 
size_t bufsiz)
memcpy(bp, yytext, len);
bp += len;
bufsiz -= len;
-   if ((prevc = yytoken) != '#') {
-   bufsiz;
+   if ((prevc = yytoken) != '#')
*bp++ = ' ';
-   }
next();
}
*bp = '\0';



[hackers] [scc] getpars: return -1 on error || Hiltjo Posthuma

2015-07-17 Thread git
commit dbefc1b5cb50c4925d56f7cfbd1c12e4c5214e94
Author: Hiltjo Posthuma hil...@codemadness.org
AuthorDate: Fri Jul 17 21:11:07 2015 +0200
Commit: Hiltjo Posthuma hil...@codemadness.org
CommitDate: Fri Jul 17 22:34:35 2015 +0200

getpars: return -1 on error

diff --git a/cc1/cpp.c b/cc1/cpp.c
index 43a6d64..5264274 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -261,6 +261,7 @@ getpars(Symbol *args[NR_MACROARG])
 popctx_and_error:
popctx();
error(err);
+   return -1;
 }
 
 static void