Re: [hackers] [dmenu] Typofix, patches rebased

2016-01-11 Thread Eric Pruitt
Hi Klemens,

On Mon, Jan 11, 2016 at 05:29:47PM +, Klemens Nanni wrote:
> cc596365a (unbolify dmenu) "breaks" some of the patches provided at
> tools.suckless.org/dmenu/patches. Basically 's,bool,int' was all I had
> to do besides some offset correction. Since this is the first time I'm
> dealing with dmenu's source I do not guarantee anything, but it compiles
> fine, though. Making them apply without errors ontop of latest git was
> all I did, no changes in functionality or whatsoever.

The entire website is a Git repository (http://suckless.org/wiki). You
can clone it, update the patches then push the diffs which will
eventually be reviewed by someone with commit privileges on the live
repo.

Eric



Re: [hackers] [dmenu] Typofix, patches rebased

2016-01-11 Thread Hiltjo Posthuma
On Mon, Jan 11, 2016 at 6:29 PM, Klemens Nanni  wrote:
> Hey,
>

Hi!

> cc596365a (unbolify dmenu) "breaks" some of the patches provided at
> tools.suckless.org/dmenu/patches. Basically 's,bool,int' was all I had
> to do besides some offset correction. Since this is the first time I'm
> dealing with dmenu's source I do not guarantee anything, but it compiles
> fine, though. Making them apply without errors ontop of latest git was
> all I did, no changes in functionality or whatsoever.
>

Thanks, I'll apply the typofix later to upstream dmenu, you can push
the other patches to the wiki.
A small note: try to keep the code-style neat / consistent.

Kind regards,
Hiltjo



[hackers] [scc] Initialize all the flags of new created types || Roberto E. Vargas Caballero

2016-01-11 Thread git
commit 01d01a1a25cb16603479e6e0a7ae3dbc7c726686
Author: Roberto E. Vargas Caballero 
AuthorDate: Sun Jan 10 11:30:33 2016 +0100
Commit: Roberto E. Vargas Caballero 
CommitDate: Sun Jan 10 11:30:33 2016 +0100

Initialize all the flags of new created types

This change simplify the logic in mktype()

diff --git a/cc1/types.c b/cc1/types.c
index 0a23b9c..1607bd4 100644
--- a/cc1/types.c
+++ b/cc1/types.c
@@ -452,7 +452,9 @@ mktype(Type *tp, int op, TINT nelem, Type *pars[])
 
type.type = tp;
type.op = op;
+   type.defined = 0;
type.arith = 0;
+   type.sign = 0;
type.integer = 0;
type.printed = 0;
type.aggreg = 0;
@@ -465,7 +467,7 @@ mktype(Type *tp, int op, TINT nelem, Type *pars[])
switch (op) {
case ARY:
if (nelem == 0)
-   goto no_defined;
+   break;
/* PASSTROUGH */
case FTN:
case PTR:
@@ -475,14 +477,11 @@ mktype(Type *tp, int op, TINT nelem, Type *pars[])
type.printed = 1;
type.integer = 1;
type.arith = 1;
-   type.sign = 0;
type.n.rank = RANK_INT;
-   goto no_defined;
+   break;
case STRUCT:
case UNION:
type.aggreg = 1;
-   no_defined:
-   type.defined = 0;
break;
}
 



[hackers] [scc] Give non used warning in parameter of functions || Roberto E. Vargas Caballero

2016-01-11 Thread git
commit 9adea1257259dd445efff48073917cc5a6b3f230
Author: Roberto E. Vargas Caballero 
AuthorDate: Sun Jan 10 17:28:26 2016 +0100
Commit: Roberto E. Vargas Caballero 
CommitDate: Sun Jan 10 17:52:50 2016 +0100

Give non used warning in parameter of functions

This warning can be useful, and it is easy to remove it
using dummy assignations.

diff --git a/cc1/decl.c b/cc1/decl.c
index f900ac6..f5a43f1 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -140,7 +140,9 @@ parameter(struct decl *dcl)
Type *funtp = dcl->parent, *tp = dcl->type;
TINT n = funtp->n.elem;
char *name = sym->name;
+   int flags;
 
+   flags = 0;
switch (dcl->sclass) {
case STATIC:
case EXTERN:
@@ -148,10 +150,10 @@ parameter(struct decl *dcl)
errorp("bad storage class in function parameter");
break;
case REGISTER:
-   sym->flags |= ISREGISTER;
+   flags |= ISREGISTER;
break;
case NOSCLASS:
-   sym->flags |= ISAUTO;
+   flags |= ISAUTO;
break;
}
 
@@ -180,7 +182,7 @@ parameter(struct decl *dcl)
}
 
sym->type = tp;
-   sym->flags |= ISUSED;/* avoid non used warnings in prototypes */
+   sym->flags |= flags;
return sym;
 }
 
@@ -755,6 +757,27 @@ dodcl(int rep, Symbol *(*fun)(struct decl *), unsigned ns, 
Type *parent)
return sym;
 }
 
+static void
+prototype(Symbol *sym)
+{
+   int n;
+   Symbol **p;
+
+   emit(ODECL, sym);
+   /*
+* avoid non used warnings in prototypes
+*/
+   n = sym->type->n.elem;
+   for (p = sym->u.pars;  n-- > 0; ++p) {
+   if (*p == NULL)
+   continue;
+   (*p)->flags |= ISUSED;
+   }
+   free(sym->u.pars);
+   sym->u.pars = NULL;
+   popctx();
+}
+
 void
 decl(void)
 {
@@ -775,11 +798,7 @@ decl(void)
}
 
if (curctx != GLOBALCTX+1 || yytoken == ';') {
-   /* it is a prototype */
-   emit(ODECL, sym);
-   free(sym->u.pars);
-   sym->u.pars = NULL;
-   popctx();
+   prototype(sym);
expect(';');
return;
}
diff --git a/cc1/tests/test014.c b/cc1/tests/test014.c
index 7f4ab89..2fc66a5 100644
--- a/cc1/tests/test014.c
+++ b/cc1/tests/test014.c
@@ -42,6 +42,7 @@ test014.c:32: error: bad storage class in function parameter
 test014.c:33: error: invalid storage class for function 'func4'
 test014.c:34: error: invalid type specification
 test014.c:35: warning: 'f' defined but not used
+test014.c:35: warning: 'par' defined but not used
 test014.c:38: error: conflicting types for 'd'
 */
 



[hackers] [scc] Add support for k functions || Roberto E. Vargas Caballero

2016-01-11 Thread git
commit 2fae9d998da0050e988c600e6581a076441382ef
Author: Roberto E. Vargas Caballero 
AuthorDate: Mon Jan 11 10:10:40 2016 +0100
Commit: Roberto E. Vargas Caballero 
CommitDate: Mon Jan 11 10:10:40 2016 +0100

Add support for k functions

I know that this was the most expected feature of scc. You guys
can begin to work with scc after this commit.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 391b995..73a76fb 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -45,6 +45,7 @@ struct type {
bool integer : 1;   /* this type is INT or enum */
bool arith : 1; /* this type is INT, ENUM, FLOAT */
bool aggreg : 1;/* this type is struct or union */
+   bool k_r : 1;   /* This is a k function */
size_t size;/* sizeof the type */
size_t align;   /* align of the type */
Type *type; /* base type */
@@ -134,7 +135,8 @@ enum {
 enum {
FTN = 1,
PTR,
-   ARY
+   ARY,
+   KRFTN
 };
 
 /* namespaces */
diff --git a/cc1/code.c b/cc1/code.c
index 4d1441b..e62619f 100644
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -355,20 +355,15 @@ static void
 emitfun(unsigned op, void *arg)
 {
Symbol *sym = arg, **sp;
-   TINT n;
 
emitdcl(op, arg);
puts("\n{");
 
-   n = sym->type->n.elem;
-   for (sp = sym->u.pars; n-- > 0; ++sp) {
-   if ((sym = *sp) == NULL)
-   continue;
-   /* enable non used warnings in parameters */
-   sym->flags &= ~ISUSED;
-   emit(ODECL, sym);
-   }
+   for (sp = sym->u.pars; sp && *sp; ++sp)
+   emit(ODECL, *sp);
puts("\\");
+   free(sym->u.pars);
+   sym->u.pars = NULL;
 }
 
 static void
diff --git a/cc1/decl.c b/cc1/decl.c
index f5a43f1..2858c9d 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -52,6 +52,7 @@ push(struct declarators *dp, int op, ...)
case ARY:
p->nelem = va_arg(va, TINT);
break;
+   case KRFTN:
case FTN:
p->nelem = va_arg(va, TINT);
p->tpars = va_arg(va, Type **);
@@ -87,7 +88,7 @@ pop(struct declarators *dp, struct decl *dcl)
popctx();
dcl->pars = NULL;
}
-   if (p->op == FTN)
+   if (p->op == FTN || p->op == KRFTN)
dcl->pars = p->pars;
dcl->type = mktype(dcl->type, p->op, p->nelem, p->tpars);
return 1;
@@ -159,7 +160,7 @@ parameter(struct decl *dcl)
 
switch (tp->op) {
case VOID:
-   if (n != 0) {
+   if (n != 0 || funtp->k_r) {
errorp("incorrect void parameter");
return NULL;
}
@@ -175,13 +176,22 @@ parameter(struct decl *dcl)
return NULL;
}
if (!empty(sym, tp)) {
-   if ((sym = install(NS_IDEN, sym)) == NULL) {
+   Symbol *p = install(NS_IDEN, sym);
+   if (!p && !funtp->k_r) {
errorp("redefinition of parameter '%s'", name);
return NULL;
}
+   if (p && funtp->k_r) {
+   errorp("declaration for parameter ‘%s’ but no such 
parameter",
+  sym->name);
+   return NULL;
+   }
+   if (p)
+   sym = p;
}
 
sym->type = tp;
+   sym->flags &= ~(ISAUTO|ISREGISTER);
sym->flags |= flags;
return sym;
 }
@@ -192,66 +202,114 @@ static Symbol *dodcl(int rep,
  Type *type);
 
 static void
-fundcl(struct declarators *dp)
+krfun(Type *tp, Type *types[], Symbol *syms[], int *ntypes, int *nsyms)
 {
-   Type type, *types[NR_FUNPARAM], *tp;
-   Symbol *syms[NR_FUNPARAM], *sym;
-   TINT size;
-   Symbol *pars;
-   int toomany = 0, toovoid = 0;
-
-   pushctx();
-   expect('(');
-   type.n.elem = 0;
+   int n = 0;
+   Symbol *sym;
+   int toomany = 0;
 
-   if (yytoken == ')') {
-   ++type.n.elem;
-   syms[0] = NULL;
-   types[0] = ellipsistype;
-   goto end_params;
+   if (yytoken != ')') {
+   do {
+   sym = yylval.sym;
+   expect(IDEN);
+   sym->type = inttype;
+   sym->flags |= ISAUTO;
+   if ((sym = install(NS_IDEN, sym)) == NULL) {
+   errorp("redefinition of parameter '%s'",
+  sym->name);
+   continue;
+   }
+   if (n < NR_FUNPARAM) {
+   ++n;
+   *syms++ = sym;
+   continue;
+  

[hackers] [scc] Add warning about empty parameter declarations || Roberto E. Vargas Caballero

2016-01-11 Thread git
commit 401f843e3fd7dd3399a30d79b1a35f1340909dbe
Author: Roberto E. Vargas Caballero 
AuthorDate: Sun Jan 10 15:50:52 2016 +0100
Commit: Roberto E. Vargas Caballero 
CommitDate: Sun Jan 10 15:50:52 2016 +0100

Add warning about empty parameter declarations

This is an extension of scc over c99, where we allow to have empty
declarations in parameters but it is a good idea tt give a
warning to the user in this case.

diff --git a/cc1/decl.c b/cc1/decl.c
index 7b7ff2d..7f2e96f 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -116,6 +116,23 @@ arydcl(struct declarators *dp)
push(dp, ARY, n);
 }
 
+static int
+empty(Symbol *sym, Type *tp)
+{
+   if (!sym->name) {
+   sym->type = tp;
+   switch (tp->op) {
+   default:
+   warn("empty declaration");
+   case STRUCT:
+   case UNION:
+   case ENUM:
+   return 1;
+   }
+   }
+   return 0;
+}
+
 static Symbol *
 parameter(struct decl *dcl)
 {
@@ -124,8 +141,6 @@ parameter(struct decl *dcl)
TINT n = funtp->n.elem;
char *name = sym->name;
 
-   sym->type = tp;
-
switch (dcl->sclass) {
case STATIC:
case EXTERN:
@@ -157,16 +172,15 @@ parameter(struct decl *dcl)
errorp("incorrect function type for a function parameter");
return NULL;
}
-
-   if (name) {
+   if (!empty(sym, tp)) {
if ((sym = install(NS_IDEN, sym)) == NULL) {
errorp("redefinition of parameter '%s'", name);
return NULL;
}
}
+
sym->type = tp;
sym->flags |= ISUSED;/* avoid non used warnings in prototypes */
-
return sym;
 }
 
@@ -535,23 +549,6 @@ type(struct decl *dcl)
return sym;
 }
 
-static int
-empty(Symbol *sym, Type *tp)
-{
-   if (!sym->name) {
-   sym->type = tp;
-   switch (tp->op) {
-   default:
-   warn("empty declaration");
-   case STRUCT:
-   case UNION:
-   case ENUM:
-   return 1;
-   }
-   }
-   return 0;
-}
-
 static Symbol *
 field(struct decl *dcl)
 {



[hackers] [scc] Remove indentation level in decl() || Roberto E. Vargas Caballero

2016-01-11 Thread git
commit 40f728bbc37cdce07a2dd000dfa81c0dfe0b307a
Author: Roberto E. Vargas Caballero 
AuthorDate: Sun Jan 10 16:53:14 2016 +0100
Commit: Roberto E. Vargas Caballero 
CommitDate: Sun Jan 10 16:53:14 2016 +0100

Remove indentation level in decl()

diff --git a/cc1/decl.c b/cc1/decl.c
index 7f2e96f..f900ac6 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -769,42 +769,37 @@ decl(void)
 * but due to parameter context, we have to check
 * against GLOBALCTX+1
 */
-   if (sym->type->op == FTN) {
-   if (curctx != GLOBALCTX+1)
-   goto prototype;
+   if (sym->type->op != FTN) {
+   expect(';');
+   return;
+   }
 
-   switch (yytoken) {
-   case '{':
-   case TYPEIDEN:
-   case TYPE:
-   case TQUALIFIER:
-   case SCLASS:
-   if (sym->flags & ISTYPEDEF)
-   errorp("function definition declared 
'typedef'");
-   if (sym->flags & ISDEFINED)
-   errorp("redefinition of '%s'", sym->name);
-   if (sym->flags & ISEXTERN) {
-   sym->flags &= ~ISEXTERN;
-   sym->flags |= ISGLOBAL;
-   }
-   sym->flags |= ISDEFINED;
-   sym->flags &= ~ISEMITTED;
-   curfun = sym;
-   emit(OFUN, sym);
-   free(sym->u.pars);
-   compound(NULL, NULL, NULL);
-   emit(OEFUN, NULL);
-   curfun = NULL;
-   return;
-   default:
-   prototype:
-   emit(ODECL, sym);
-   free(sym->u.pars);
-   sym->u.pars = NULL;
-   popctx();
-   }
+   if (curctx != GLOBALCTX+1 || yytoken == ';') {
+   /* it is a prototype */
+   emit(ODECL, sym);
+   free(sym->u.pars);
+   sym->u.pars = NULL;
+   popctx();
+   expect(';');
+   return;
}
-   expect(';');
+
+   if (sym->flags & ISTYPEDEF)
+   errorp("function definition declared 'typedef'");
+   if (sym->flags & ISDEFINED)
+   errorp("redefinition of '%s'", sym->name);
+   if (sym->flags & ISEXTERN) {
+   sym->flags &= ~ISEXTERN;
+   sym->flags |= ISGLOBAL;
+   }
+   sym->flags |= ISDEFINED;
+   sym->flags &= ~ISEMITTED;
+   curfun = sym;
+   emit(OFUN, sym);
+   free(sym->u.pars);
+   compound(NULL, NULL, NULL);
+   emit(OEFUN, NULL);
+   curfun = NULL;
 }
 
 static void



[hackers] [scc] Mark as integer type size_t || Roberto E. Vargas Caballero

2016-01-11 Thread git
commit 04896c0cb0b29caaad3976bba16428610be15a48
Author: Roberto E. Vargas Caballero 
AuthorDate: Mon Jan 11 10:11:24 2016 +0100
Commit: Roberto E. Vargas Caballero 
CommitDate: Mon Jan 11 10:11:24 2016 +0100

Mark as integer type size_t

diff --git a/cc1/types.c b/cc1/types.c
index b213407..9966ba6 100644
--- a/cc1/types.c
+++ b/cc1/types.c
@@ -270,6 +270,7 @@ static Type types[] = {
.letter = L_UINT,
.defined = 1,
.size = 2,
+   .integer = 1,
.arith = 1,
.align = 1,
.n.rank = RANK_UINT,



[hackers] [dmenu] Typofix, patches rebased

2016-01-11 Thread Klemens Nanni
Hey,

cc596365a (unbolify dmenu) "breaks" some of the patches provided at
tools.suckless.org/dmenu/patches. Basically 's,bool,int' was all I had
to do besides some offset correction. Since this is the first time I'm
dealing with dmenu's source I do not guarantee anything, but it compiles
fine, though. Making them apply without errors ontop of latest git was
all I did, no changes in functionality or whatsoever.

Best Regards,
Klemens
>From 367f55b3fc31c23fdc0d534a04e3563938a58977 Mon Sep 17 00:00:00 2001
From: Klemens Nanni 
Date: Mon, 11 Jan 2016 13:26:37 +0100
Subject: [PATCH 1/3] Typofix

---
 config.def.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/config.def.h b/config.def.h
index 8db1dda..dcffd38 100644
--- a/config.def.h
+++ b/config.def.h
@@ -6,7 +6,7 @@ static int topbar = 1;  /* -b  option; if 0, dmenu appears a
 static const char *fonts[] = {
 	"monospace:size=10"
 };
-static const char *prompt  = NULL;  /* -p  option; prompt to the elft of input field */
+static const char *prompt  = NULL;  /* -p  option; prompt to the left of input field */
 static const char *normbgcolor = "#22"; /* -nb option; normal background */
 static const char *normfgcolor = "#bb"; /* -nf option; normal foreground */
 static const char *selbgcolor  = "#005577"; /* -sb option; selected background   */
-- 
2.6.2




diff --git a/dmenu.c b/dmenu.c
index 4f22ffe..c2fc3ee 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -33,6 +33,7 @@ struct item {
 	char *text;
 	struct item *left, *right;
 	int out;
+	int distance;
 };
 
 static char text[BUFSIZ] = "";
@@ -254,6 +255,86 @@ match(void)
 	calcoffsets();
 }
 
+int
+compare_distance(const void *a, const void *b)
+{
+	struct item *da = *(struct item **) a;
+	struct item *db = *(struct item **) b;
+
+	if (!db)
+		return 1;
+	if (!da)
+		return -1;
+
+	return da->distance - db->distance;
+}
+
+void
+fuzzymatch(void)
+{
+	/* bang - we have so much memory */
+	struct item *it;
+	struct item **fuzzymatches = NULL;
+	char c;
+	int number_of_matches = 0, i, pidx, sidx, eidx;
+	int text_len = strlen(text), itext_len;
+
+	matches = matchend = NULL;
+
+	/* walk through all items */
+	for (it = items; it && it->text; it++) {
+		if (text_len) {
+			itext_len = strlen(it->text);
+			pidx = 0;
+			sidx = eidx = -1;
+			/* walk through item text */
+			for (i = 0; i < itext_len && (c = it->text[i]); i++) {
+/* fuzzy match pattern */
+if (text[pidx] == c) {
+	if(sidx == -1)
+		sidx = i;
+	pidx++;
+	if (pidx == text_len) {
+		eidx = i;
+		break;
+	}
+}
+			}
+			/* build list of matches */
+			if (eidx != -1) {
+/* compute distance */
+/* factor in 30% of sidx and distance between eidx and total
+ * text length .. let's see how it works */
+it->distance = eidx - sidx + (itext_len - eidx + sidx) / 3;
+appenditem(it, , );
+number_of_matches++;
+			}
+		} else {
+			appenditem(it, , );
+		}
+	}
+
+	if (number_of_matches) {
+		/* initialize array with matches */
+		if (!(fuzzymatches = realloc(fuzzymatches, number_of_matches * sizeof(struct item*
+			die("cannot realloc %u bytes:", number_of_matches * sizeof(struct item*));
+		for (i = 0, it = matches; it && i < number_of_matches; i++, it = it->right) {
+			fuzzymatches[i] = it;
+		}
+		/* sort matches according to distance */
+		qsort(fuzzymatches, number_of_matches, sizeof(struct item*), compare_distance);
+		/* rebuild list of matches */
+		matches = matchend = NULL;
+		for (i = 0, it = fuzzymatches[i];  i < number_of_matches && it && \
+it->text; i++, it = fuzzymatches[i]) {
+			appenditem(it, , );
+		}
+		free(fuzzymatches);
+	}
+	curr = sel = matches;
+	calcoffsets();
+}
+
 static void
 insert(const char *str, ssize_t n)
 {
@@ -264,7 +345,7 @@ insert(const char *str, ssize_t n)
 	if (n > 0)
 		memcpy([cursor], str, n);
 	cursor += n;
-	match();
+	fuzzymatch();
 }
 
 static size_t
@@ -309,7 +390,7 @@ keypress(XKeyEvent *ev)
 
 		case XK_k: /* delete right */
 			text[cursor] = '\0';
-			match();
+			fuzzymatch();
 			break;
 		case XK_u: /* delete left */
 			insert(NULL, 0 - cursor);
@@ -443,7 +524,7 @@ keypress(XKeyEvent *ev)
 		strncpy(text, sel->text, sizeof text - 1);
 		text[sizeof text - 1] = '\0';
 		cursor = strlen(text);
-		match();
+		fuzzymatch();
 		break;
 	}
 	drawmenu();
@@ -585,7 +666,7 @@ setup(void)
 	}
 	promptw = (prompt && *prompt) ? TEXTW(prompt) : 0;
 	inputw = MIN(inputw, mw/3);
-	match();
+	fuzzymatch();
 
 	/* create menu window */
 	swa.override_redirect = True;



diff --git a/dmenu.c b/dmenu.c
index e0c2f80..ef25442 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -487,6 +487,7 @@ readstdin(void)
 	}
 	if (items)
 		items[i].text = NULL;
+	if (i == 1 && items[0].text[0] == '\0') items = realloc(items, 0);
 	inputw = maxstr ? TEXTW(maxstr) : 0;
 	lines = MIN(lines, i);
 }



diff --git a/config.def.h b/config.def.h
index 8db1dda..f941d84 

[hackers] [sbase] Fix rematch() || Roberto E. Vargas Caballero

2016-01-11 Thread git
commit 54ad6d512bdd9b15553d9e1bd8be5c33e4561535
Author: Roberto E. Vargas Caballero 
AuthorDate: Thu Jan 7 11:37:56 2016 +0100
Commit: sin 
CommitDate: Mon Jan 11 15:37:58 2016 +

Fix rematch()

Rematch() was incremnenting the last match always, even in the
cases when it was not matching anything. This patch detects
this situation and it updates it only when there is a match.

diff --git a/ed.c b/ed.c
index e98acda..0fc07b1 100644
--- a/ed.c
+++ b/ed.c
@@ -404,8 +404,13 @@ match(int num)
 static int
 rematch(int num)
 {
-   lastmatch += matchs[0].rm_eo;
-   return !regexec(pattern, lastmatch, 10, matchs, 0);
+   regoff_t off = matchs[0].rm_eo;
+
+   if (!regexec(pattern, lastmatch + off, 10, matchs, 0)) {
+   lastmatch += off;
+   return 1;
+   }
+   return 0;
 }
 
 static int



[hackers] [sbase] Handle explicitly the case of line 0 || Roberto E. Vargas Caballero

2016-01-11 Thread git
commit 78fd6ff239f4b2fd626a1484e61dfa0ba3a8bdfa
Author: Roberto E. Vargas Caballero 
AuthorDate: Wed Jan 6 22:04:29 2016 +0100
Commit: sin 
CommitDate: Mon Jan 11 15:37:58 2016 +

Handle explicitly the case of line 0

Line 0 is a special line added to allow operations with
empty buffers, and we have to ensure that it is not going
to match any regular expression. The code was written in
a way that this case was handle implicitily, but this
solution was working only for the first file loaded in
ed, while the second file loaded in ed got a line with
a dirty seek field. This solution check explicitily
against invalid lines passed to makeline(), which
allows to simplify the common case.

diff --git a/ed.c b/ed.c
index 0b03fd1..e98acda 100644
--- a/ed.c
+++ b/ed.c
@@ -167,20 +167,20 @@ makeline(char *s, int *off)
}
lp = zero + lastidx;
 
-   while ((c = *s) && *s != '\n')
-   ++s;
-   if (c == '\n')
-   ++s;
-   len = s - begin;
+   if (!s) {
+   lp->seek = -1;
+   len = 0;
+   } else {
+   while ((c = *s++) != '\n')
+   /* nothing */;
+   len = s - begin;
+   if ((lp->seek = lseek(scratch, 0, SEEK_END)) < 0 ||
+   write(scratch, begin, len) < 0) {
+   error("input/output error");
+   }
+   }
if (off)
*off = len;
-
-   if (len > 0)
-   if ((lp->seek = lseek(scratch, 0, SEEK_END)) < 0 ||
-   write(scratch, begin, len) < 0) {
-   error("input/output error");
-   }
-
++lastidx;
return lp - zero;
 }
@@ -208,8 +208,11 @@ gettxt(int line)
char *p;
 
lp = zero + getindex(line);
-   off = lp->seek;
sizetxt = 0;
+   off = lp->seek;
+
+   if (off == (off_t) -1)
+   return text = addchar('\0', text, , );
 
 repeat:
if (!csize || off < lasto || off - lasto >= csize) {
@@ -339,7 +342,7 @@ setscratch()
error("scratch filename too long");
if ((scratch = mkstemp(tmpname)) < 0)
error("failed to create scratch file");
-   if ((k = makeline("", NULL)))
+   if ((k = makeline(NULL, NULL)))
error("input/output error in scratch file");
relink(k, k, k, k);
clearundo();



[hackers] [sbase] Stop matching when lastmatch points to '\n' || Roberto E. Vargas Caballero

2016-01-11 Thread git
commit cf868c8eeb45f47063cc5d30b04b552e7dd5a7c4
Author: Roberto E. Vargas Caballero 
AuthorDate: Thu Jan 7 12:34:40 2016 +0100
Commit: sin 
CommitDate: Mon Jan 11 15:37:58 2016 +

Stop matching when lastmatch points to '\n'

This situation happens with something like s/$/test/,
where rm_so == rm_eo == 0. Without this check, ed
keeps looping forever.

diff --git a/ed.c b/ed.c
index 67ffdb8..4a872ed 100644
--- a/ed.c
+++ b/ed.c
@@ -1005,7 +1005,7 @@ subline(int num, int nth)
static size_t siz, cap;
 
i = changed = siz = 0;
-   for (m = match(num); m; m = rematch(num)) {
+   for (m = match(num); m && *lastmatch != '\n'; m = rematch(num)) {
addpre(, , );
changed |= addsub(, , , nth, ++i);
}



[hackers] [sbase] ed: Remove useless newlines || sin

2016-01-11 Thread git
commit 0fb1c6fd60d6f9dfa0e4f86fc821bfe75f9b476d
Author: sin 
AuthorDate: Fri Jan 8 10:27:07 2016 +
Commit: sin 
CommitDate: Mon Jan 11 15:37:58 2016 +

ed: Remove useless newlines

diff --git a/ed.c b/ed.c
index 686d2aa..0b03fd1 100644
--- a/ed.c
+++ b/ed.c
@@ -64,8 +64,6 @@ static char *lastmatch;
 static struct undo udata;
 static int newcmd;
 
-
-
 static void
 discard(void)
 {



Re: [hackers] [dmenu] Typofix, patches rebased

2016-01-11 Thread Klemens Nanni
dmenu-git-20161101-instant.patch contains a typo at line 23,
's,next,text' fixes it.

Klemens Nanni:
> Hey, > > cc596365a (unbolify dmenu) "breaks" some of the patches provided at
> tools.suckless.org/dmenu/patches. Basically 's,bool,int' was all I had
> to do besides some offset correction. Since this is the first time I'm
> dealing with dmenu's source I do not guarantee anything, but it
compiles > fine, though. Making them apply without errors ontop of
latest git was > all I did, no changes in functionality or whatsoever. >
> Best Regards, > Klemens

-- 
Encrypt your messages using GNUPG if you can - nobody likes snoopers!
For more detailed information, look at the FSF's Email Self-Defense
Guide under https://emailselfdefense.fsf.org
My Key ID: 0x38ECD8BD | fingerprint: A5B8 05BF E06E 61AD 8399  0CDC 46B3
F9ED 38EC D8BD