Re: audio(9) manual page

2014-06-24 Thread Alexander Polakov
* Jason McIntyre j...@kerhand.co.uk [140625 00:41]:
 On Tue, Jun 24, 2014 at 09:13:47AM +0200, Alexandre Ratchov wrote:
  I see what you mean. As the manual describes the interface between
  two layers we may need to be more precise about who calls who.
  Wouldn't the following be less ambigous?
  
  When the hardware is ready to accept more samples the driver shall
  call the
  .Fa intr
  function with the argument
  .Fa intrarg .
  
 
 the use of will is perfectly fine here - it's basically a conditional
 sentence structure.
 
 shall sounds awful. it sounds formal, dated, and like a document
 produced by posix. please don;t make this change.
 
 what is simpler, i think, and easier for most folks to understand, is
 using a present tense:
 
   When the hardware is ready to accept more samples,
   the driver calls the
   .Fa intr
   function with the argument
   .Fa intrarg .
   
 it's all a matter of taste, i suppose, but present tense structure does
 seem to be easier to read for non-native speakers (in my experience).

I agree, this one looks even better.



audio(9) manual page

2014-06-23 Thread Alexander Polakov
So I have been trying to write a new audio driver (for Xonar DS if
anyone interested) and therefore reading audio(9).

I was confused for a while by the use of will here. I think it's not
clear enough that these functions should be called by the driver code.

I'm not a native speaker, so may be it's just my lack of familiarity with
english idioms. Sorry for the noise if that's the case.

Index: audio.9
===
RCS file: /cvs/src/share/man/man9/audio.9,v
retrieving revision 1.23
diff -u -r1.23 audio.9
--- audio.9 21 Jan 2014 03:15:46 -  1.23
+++ audio.9 23 Jun 2014 19:42:42 -
@@ -284,7 +284,7 @@
 has been initiated (normally with DMA).
 When the hardware is ready to accept more samples the function
 .Fa intr
-will be called with the argument
+shall be called with the argument
 .Fa intrarg .
 Calling
 .Fa intr
@@ -302,7 +302,7 @@
 has been initiated (normally with DMA).
 When the hardware is ready to deliver more samples the function
 .Fa intr
-will be called with the argument
+shall be called with the argument
 .Fa intrarg .
 Calling
 .Fa intr
@@ -437,7 +437,7 @@
 .Fa blksize
 sized block, the function
 .Fa intr
-will be called with the argument
+shall be called with the argument
 .Fa intrarg
 (typically from the audio hardware interrupt service routine).
 Once started, the transfer may be stopped using
@@ -459,7 +459,7 @@
 .Fa blksize
 sized block, the function
 .Fa intr
-will be called with the argument
+shall be called with the argument
 .Fa intrarg
 (typically from the audio hardware interrupt service routine).
 Once started, the transfer may be stopped using



Re: Reduce IPI traffic from signals

2013-04-19 Thread Alexander Polakov
Hello?

I've been running with this diff since July without any issues (i386 
amd64).

* Alexander Polakov p...@sdf.org [121213 18:34]:
 This diff reduces IPI traffic for a case when process A is sending
 a lot of signals to process B running on a different CPU. userret()
 delivers all process signals at once, so there is no need to send
 an interrupt for every signal.
 
 The problem was noticed by rtorrent 0.9.2 users, which does exactly
 this, which led to process/system hangs and slowness.
 
 Tested and known to help on amd64 by me and dcoppa@.
 
 Index: amd64/amd64/machdep.c
 ===
 RCS file: /cvs/src/sys/arch/amd64/amd64/machdep.c,v
 retrieving revision 1.155
 diff -u -r1.155 machdep.c
 --- amd64/amd64/machdep.c 4 Jun 2012 15:19:47 -   1.155
 +++ amd64/amd64/machdep.c 23 Jul 2012 13:49:40 -
 @@ -690,8 +690,10 @@
  void
  signotify(struct proc *p)
  {
 - aston(p);
 - cpu_unidle(p-p_cpu);
 + if (!isastset(p)) {
 + aston(p);
 + cpu_unidle(p-p_cpu);
 + }
  }
  
  #ifdef MULTIPROCESSOR
 Index: amd64/include/cpu.h
 ===
 RCS file: /cvs/src/sys/arch/amd64/include/cpu.h,v
 retrieving revision 1.73
 diff -u -r1.73 cpu.h
 --- amd64/include/cpu.h   17 Apr 2012 16:02:33 -  1.73
 +++ amd64/include/cpu.h   23 Jul 2012 13:49:40 -
 @@ -213,6 +213,7 @@
  #endif
  
  #define aston(p) ((p)-p_md.md_astpending = 1)
 +#define isastset(p)  ((p)-p_md.md_astpending == 1)
  
  #define curpcb   curcpu()-ci_curpcb
  
 Index: hppa/hppa/machdep.c
 ===
 RCS file: /cvs/src/sys/arch/hppa/hppa/machdep.c,v
 retrieving revision 1.206
 diff -u -r1.206 machdep.c
 --- hppa/hppa/machdep.c   21 Jun 2012 00:56:59 -  1.206
 +++ hppa/hppa/machdep.c   23 Jul 2012 13:49:40 -
 @@ -1399,8 +1399,10 @@
  void
  signotify(struct proc *p)
  {
 - setsoftast(p);
 - cpu_unidle(p-p_cpu);
 + if (!isastset(p)) {
 + setsoftast(p);
 + cpu_unidle(p-p_cpu);
 + }
  }
  
  /*
 Index: hppa/include/intr.h
 ===
 RCS file: /cvs/src/sys/arch/hppa/include/intr.h,v
 retrieving revision 1.37
 diff -u -r1.37 intr.h
 --- hppa/include/intr.h   14 Jan 2011 13:20:06 -  1.37
 +++ hppa/include/intr.h   23 Jul 2012 13:49:40 -
 @@ -157,7 +157,8 @@
  int   hppa_ipi_broadcast(u_long);
  #endif
  
 -#define  setsoftast(p)   (p-p_md.md_astpending = 1)
 +#define  setsoftast(p)   ((p)-p_md.md_astpending = 1)
 +#define  isastset(p) ((p)-p_md.md_astpending == 1)
  
  void *softintr_establish(int, void (*)(void *), void *);
  void  softintr_disestablish(void *);
 Index: i386/i386/machdep.c
 ===
 RCS file: /cvs/src/sys/arch/i386/i386/machdep.c,v
 retrieving revision 1.510
 diff -u -r1.510 machdep.c
 --- i386/i386/machdep.c   23 May 2012 08:23:43 -  1.510
 +++ i386/i386/machdep.c   23 Jul 2012 13:49:40 -
 @@ -2420,8 +2420,10 @@
  void
  signotify(struct proc *p)
  {
 - aston(p);
 - cpu_unidle(p-p_cpu);
 + if (!isastset(p)) {
 + aston(p);
 + cpu_unidle(p-p_cpu);
 + }
  }
  
  #ifdef MULTIPROCESSOR
 Index: i386/include/cpu.h
 ===
 RCS file: /cvs/src/sys/arch/i386/include/cpu.h,v
 retrieving revision 1.122
 diff -u -r1.122 cpu.h
 --- i386/include/cpu.h27 Mar 2012 06:44:01 -  1.122
 +++ i386/include/cpu.h23 Jul 2012 13:49:41 -
 @@ -226,6 +226,7 @@
  #endif
  
  #define aston(p) ((p)-p_md.md_astpending = 1)
 +#define isastset(p)  ((p)-p_md.md_astpending == 1)
  
  #define curpcb   curcpu()-ci_curpcb
  
 Index: m88k/include/cpu.h
 ===
 RCS file: /cvs/src/sys/arch/m88k/include/cpu.h,v
 retrieving revision 1.54
 diff -u -r1.54 cpu.h
 --- m88k/include/cpu.h25 Oct 2011 18:38:06 -  1.54
 +++ m88k/include/cpu.h23 Jul 2012 13:49:41 -
 @@ -256,6 +256,7 @@
   (((struct cpu_info *)(framep)-tf.tf_cpu)-ci_intrdepth  1)
  
  #define  aston(p)((p)-p_md.md_astpending = 1)
 +#define  isastset(p) ((p)-p_md.md_astpending == 1)
  
  /*
   * This is used during profiling to integrate system time.
 Index: m88k/m88k/m88k_machdep.c
 ===
 RCS file: /cvs/src/sys/arch/m88k/m88k/m88k_machdep.c,v
 retrieving revision 1.52
 diff -u -r1.52 m88k_machdep.c
 --- m88k/m88k/m88k_machdep.c  23 Mar 2012 15:51:26 -  1.52
 +++ m88k/m88k/m88k_machdep.c  23 Jul 2012 13:49:41 -
 @@ -314,8 +314,10 @@
  void
  signotify(struct proc *p)
  {
 - aston(p

softraid(4) about boot support

2013-03-11 Thread Alexander Polakov
It seems like this is not true any more. Right?

Index: softraid.4
===
RCS file: /cvs/src/share/man/man4/softraid.4,v
retrieving revision 1.30
diff -u -p -u -r1.30 softraid.4
--- softraid.4  14 Aug 2012 01:08:19 -  1.30
+++ softraid.4  11 Mar 2013 21:25:39 -
@@ -178,8 +178,6 @@ This is due to the scrub functionality n
 .Pp
 Currently there is no automated mechanism to recover from failed disks.
 .Pp
-There is no boot support at this time for any disciplines.
-.Pp
 Sparc hardware needs to use fstype
 .Dq 4.2BSD
 instead of

-- 
Alexander Polakov | plhk.ru



Re: vga diff for testing

2013-03-04 Thread Alexander Polakov
 at pciide0 channel 0 drive 0
scsibus0 at atapiscsi0: 2 targets
cd0 at scsibus0 targ 0 lun 0: HL-DT-ST, RW/DVD GCC-4247N, 1.01 ATAPI 5/cdrom 
removable
cd0(pciide0:0:0): using PIO mode 4, Ultra-DMA mode 2
pciide0: channel 1 ignored (disabled)
ahci0 at pci0 dev 31 function 2 Intel 82801GBM AHCI rev 0x02: msi, AHCI 1.1
scsibus1 at ahci0: 32 targets
sd0 at scsibus1 targ 0 lun 0: ATA, ST96812AS, 7.01 SCSI3 0/direct fixed 
t10.ATA_ST96812AS_5PJ3YAQN
sd0: 57231MB, 512 bytes/sector, 117210240 sectors
ichiic0 at pci0 dev 31 function 3 Intel 82801GB SMBus rev 0x02: apic 1 int 23
iic0 at ichiic0
usb1 at uhci0: USB revision 1.0
uhub1 at usb1 Intel UHCI root hub rev 1.00/1.00 addr 1
usb2 at uhci1: USB revision 1.0
uhub2 at usb2 Intel UHCI root hub rev 1.00/1.00 addr 1
usb3 at uhci2: USB revision 1.0
uhub3 at usb3 Intel UHCI root hub rev 1.00/1.00 addr 1
usb4 at uhci3: USB revision 1.0
uhub4 at usb4 Intel UHCI root hub rev 1.00/1.00 addr 1
isa0 at ichpcib0
isadma0 at isa0
pckbc0 at isa0 port 0x60/5
pckbd0 at pckbc0 (kbd slot)
pckbc0: using irq 1 for kbd slot
wskbd0 at pckbd0: console keyboard, using wsdisplay0
pms0 at pckbc0 (aux slot)
pckbc0: using irq 12 for aux slot
wsmouse0 at pms0 mux 0
wsmouse1 at pms0 mux 0
pms0: Synaptics touchpad, firmware 6.2
pcppi0 at isa0 port 0x61
spkr0 at pcppi0
aps0 at isa0 port 0x1600/31
npx0 at isa0 port 0xf0/16: reported by CPUID; using exception 16
mtrr: Pentium Pro MTRR support
ugen0 at uhub4 port 2 STMicroelectronics Biometric Coprocessor rev 1.00/0.01 
addr 2
vscsi0 at root
scsibus2 at vscsi0: 256 targets
softraid0 at root
scsibus3 at softraid0: 256 targets
root on sd0a (2c203a71c0f29eb5.a) swap on sd0b dump on sd0b
sd1 at scsibus3 targ 1 lun 0: OPENBSD, SR CRYPTO, 005 SCSI2 0/direct fixed
sd1: 37785MB, 512 bytes/sector, 77384592 sectors

-- 
Alexander Polakov | plhk.ru



uhub: retry attaching device

2013-01-20 Thread Alexander Polakov
So I have got this device:
 addr 2: File-backed Storage Gadget, Linux 2.6.24.2-Boeye with s3c-udc

The problem is that when I connect it to PC, it asks for confirmation
and I have to press button on the device. I guess uhub exploration code
timeouts while I'm doing that and gives me uhub0: device problem,
disabling port 5. With diff attached it works reliably:

umass0 at uhub0 port 5 configuration 1 interface 0 Linux 2.6.24.2-Boeye with 
s3c-udc File-backed Storage Gadget rev 2.00/3.22 addr 2
umass0: using SCSI over Bulk-Only
scsibus4 at umass0: 2 targets, initiator 0
sd2 at scsibus4 targ 1 lun 0: Linux, File-Stor Gadget, 0322 SCSI2 0/direct 
removable serial.00850600372041756775
sd2: 1885MB, 512 bytes/sector, 3862393 sectors

Index: uhub.c
===
RCS file: /cvs/src/sys/dev/usb/uhub.c,v
retrieving revision 1.59
diff -u -p -u -r1.59 uhub.c
--- uhub.c  29 Sep 2011 11:18:01 -  1.59
+++ uhub.c  20 Jan 2013 23:33:57 -
@@ -349,6 +349,7 @@ uhub_explore(usbd_device_handle dev)
int speed;
int port;
int change, status, reconnect;
+   int i;
 
DPRINTFN(10, (uhub_explore dev=%p addr=%d\n, dev, dev-address));
 
@@ -486,10 +487,14 @@ uhub_explore(usbd_device_handle dev)
speed = USB_SPEED_LOW;
else
speed = USB_SPEED_FULL;
-   /* Get device info and set its address. */
-   err = usbd_new_device(sc-sc_dev, dev-bus,
- dev-depth + 1, speed, port, up);
-   /* XXX retry a few times? */
+   for (i = 0; i  3; i++) {
+   /* Get device info and set its address. */
+   err = usbd_new_device(sc-sc_dev, dev-bus,
+ dev-depth + 1, speed, port, up);
+   usbd_delay_ms(dev, 100);
+   if (!err)
+   break;
+   }
if (err) {
DPRINTFN(-1,(uhub_explore: usbd_new_device failed, 
 error=%s\n, usbd_errstr(err)));

-- 
Alexander Polakov | plhk.ru



[cwm] tab completion

2012-11-06 Thread Alexander Polakov
);
+   if (TAILQ_EMPTY(resultq))
+   search_match_path(menuq, resultq, search);
 }
 
 static int

-- 
Alexander Polakov | plhk.ru



Re: [cwm] tab completion

2012-11-06 Thread Alexander Polakov
* Alexander Polakov p...@sdf.org [121107 02:20]:
 I think this one is ready for wider testing.
 
 How to use: hit tab in exec menu to complete the command (start
 with / if you want something not in $PATH).  When you're ready,
 hit tab again.  This will open file menu, which can be used to
 complete file argument.
 
 Completion works for other menus as well.

Oops, sorry, I sent the wrong diff (previous revision).

Index: calmwm.h
===
RCS file: /cvs/xenocara/app/cwm/calmwm.h,v
retrieving revision 1.155
diff -u -p -u -r1.155 calmwm.h
--- calmwm.h31 Oct 2012 22:06:24 -  1.155
+++ calmwm.h7 Nov 2012 01:06:13 -
@@ -73,6 +73,10 @@
 #define CWM_RCYCLE 0x0002
 #define CWM_INGROUP0x0004
 
+/* menu */
+#define CWM_MENU_DUMMY 0x0001
+#define CWM_MENU_FILE  0x0002
+
 #define KBTOGROUP(X) ((X) - 1)
 
 union arg {
@@ -260,7 +264,7 @@ TAILQ_HEAD(cmd_q, cmd);
 struct menu {
TAILQ_ENTRY(menu)entry;
TAILQ_ENTRY(menu)resultentry;
-#define MENU_MAXENTRY   50
+#define MENU_MAXENTRY   200
char text[MENU_MAXENTRY + 1];
char print[MENU_MAXENTRY + 1];
void*ctx;
@@ -354,6 +358,10 @@ voidgroup_update_names(struct 
screen
 voidsearch_match_client(struct menu_q *, struct menu_q *,
 char *);
 voidsearch_match_exec(struct menu_q *, struct menu_q *,
+char *);
+voidsearch_match_exec_path(struct menu_q *, struct menu_q 
*,
+char *);
+voidsearch_match_path_any(struct menu_q *, struct menu_q *,
 char *);
 voidsearch_match_text(struct menu_q *, struct menu_q *,
 char *);
Index: kbfunc.c
===
RCS file: /cvs/xenocara/app/cwm/kbfunc.c,v
retrieving revision 1.64
diff -u -p -u -r1.64 kbfunc.c
--- kbfunc.c31 Oct 2012 19:30:19 -  1.64
+++ kbfunc.c7 Nov 2012 01:06:13 -
@@ -298,8 +298,9 @@ kbfunc_exec(struct client_ctx *cc, union
}
xfree(path);
 
-   if ((mi = menu_filter(sc, menuq, label, NULL, 1,
-   search_match_exec, NULL)) != NULL) {
+   if ((mi = menu_filter(sc, menuq, label, NULL,
+   CWM_MENU_DUMMY | CWM_MENU_FILE,
+   search_match_exec_path, NULL)) != NULL) {
if (mi-text[0] == '\0')
goto out;
switch (cmd) {
@@ -376,7 +377,7 @@ kbfunc_ssh(struct client_ctx *cc, union 
xfree(lbuf);
(void)fclose(fp);
 
-   if ((mi = menu_filter(sc, menuq, ssh, NULL, 1,
+   if ((mi = menu_filter(sc, menuq, ssh, NULL, CWM_MENU_DUMMY,
search_match_exec, NULL)) != NULL) {
if (mi-text[0] == '\0')
goto out;
@@ -403,7 +404,7 @@ kbfunc_client_label(struct client_ctx *c
TAILQ_INIT(menuq);
 
/* dummy is set, so this will always return */
-   mi = menu_filter(cc-sc, menuq, label, cc-label, 1,
+   mi = menu_filter(cc-sc, menuq, label, cc-label, CWM_MENU_DUMMY,
search_match_text, NULL);
 
if (!mi-abort) {
Index: menu.c
===
RCS file: /cvs/xenocara/app/cwm/menu.c,v
retrieving revision 1.41
diff -u -p -u -r1.41 menu.c
--- menu.c  31 Oct 2012 19:30:19 -  1.41
+++ menu.c  7 Nov 2012 01:06:13 -
@@ -28,6 +28,7 @@
 #include string.h
 #include stdio.h
 #include unistd.h
+#include ctype.h
 
 #include calmwm.h
 
@@ -37,10 +38,11 @@
 enum ctltype {
CTL_NONE = -1,
CTL_ERASEONE = 0, CTL_WIPE, CTL_UP, CTL_DOWN, CTL_RETURN,
-   CTL_ABORT, CTL_ALL
+   CTL_TAB, CTL_ABORT, CTL_ALL
 };
 
 struct menu_ctx {
+   struct screen_ctx   *sc;
char searchstr[MENU_MAXENTRY + 1];
char dispstr[MENU_MAXENTRY*2 + 1];
char promptstr[MENU_MAXENTRY + 1];
@@ -54,6 +56,7 @@ struct menu_ctx {
int  height;
int  width;
int  num;
+   int  flags;
int  x;
int  y;
void (*match)(struct menu_q *, struct menu_q *, char *);
@@ -93,7 +96,7 @@ menu_init(struct screen_ctx *sc)
 
 struct menu *
 menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt,
-char *initial, int dummy,
+char *initial, int flags, 
 void (*match)(struct menu_q *, struct menu_q *, char *),
 void (*print)(struct menu *, int))
 {
@@ -114,6 +117,8 @@ menu_filter(struct screen_ctx *sc, struc
xsave = mc.x;
ysave = mc.y;
 
+   mc.sc

Re: cwm reload support

2012-10-31 Thread Alexander Polakov
;
-   client_draw_border(cc);
-   }
 }
 
 static struct {
@@ -148,7 +120,7 @@ static struct {
{ CM-equal,   vmaximize },
{ CMS-equal,  hmaximize },
{ CMS-f,  freeze },
-   { CMS-r,  reload },
+   { CMS-r,  restart },
{ CMS-q,  quit },
{ M-h,moveleft },
{ M-j,movedown },
@@ -375,7 +347,7 @@ static struct {
{ vmaximize, kbfunc_client_vmaximize, KBFLAG_NEEDCLIENT, {0} },
{ hmaximize, kbfunc_client_hmaximize, KBFLAG_NEEDCLIENT, {0} },
{ freeze, kbfunc_client_freeze, KBFLAG_NEEDCLIENT, {0} },
-   { reload, kbfunc_reload, 0, {0} },
+   { restart, kbfunc_restart, 0, {0} },
{ quit, kbfunc_quit_wm, 0, {0} },
{ exec, kbfunc_exec, 0, {.i = CWM_EXEC_PROGRAM} },
{ exec_wm, kbfunc_exec, 0, {.i = CWM_EXEC_WM} },
Index: cwm.1
===
RCS file: /cvs/xenocara/app/cwm/cwm.1,v
retrieving revision 1.47
diff -u -p -u -r1.47 cwm.1
--- cwm.1   9 May 2012 18:37:39 -   1.47
+++ cwm.1   31 Oct 2012 16:38:30 -
@@ -116,7 +116,8 @@ dialog; allows you to switch from
 .Nm
 to another window manager without restarting the X server.
 .It Ic CMS-r
-Reload configuration.
+Restart the running
+.Xr cwm 1 .
 .It Ic CMS-q
 Quit
 .Nm .
Index: cwmrc.5
===
RCS file: /cvs/xenocara/app/cwm/cwmrc.5,v
retrieving revision 1.44
diff -u -p -u -r1.44 cwmrc.5
--- cwmrc.5 28 Oct 2012 20:13:02 -  1.44
+++ cwmrc.5 31 Oct 2012 16:38:30 -
@@ -269,8 +269,9 @@ mousebind M-3   window_resize
 .Ed
 .Sh BIND COMMAND LIST
 .Bl -tag -width 18n -compact
-.It reload
-Reload configuration.
+.It restart
+Restart the running
+.Xr cwm 1 .
 .It quit
 Quit
 .Xr cwm 1 .
Index: font.c
===
RCS file: /cvs/xenocara/app/cwm/font.c,v
retrieving revision 1.17
diff -u -p -u -r1.17 font.c
--- font.c  8 Sep 2011 12:35:33 -   1.17
+++ font.c  31 Oct 2012 16:38:30 -
@@ -51,16 +51,11 @@ font_height(struct screen_ctx *sc)
 void
 font_init(struct screen_ctx *sc, const char *color)
 {
-   if (sc-xftdraw)
-   XftDrawDestroy(sc-xftdraw);
sc-xftdraw = XftDrawCreate(X_Dpy, sc-rootwin,
DefaultVisual(X_Dpy, sc-which), DefaultColormap(X_Dpy, sc-which));
if (sc-xftdraw == NULL)
errx(1, XftDrawCreate);
 
-   if (sc-xftcolor.pixel)
-   XftColorFree(X_Dpy, DefaultVisual(X_Dpy, sc-which),
-   DefaultColormap(X_Dpy, sc-which), sc-xftcolor);
if (!XftColorAllocName(X_Dpy, DefaultVisual(X_Dpy, sc-which),
DefaultColormap(X_Dpy, sc-which), color, sc-xftcolor))
errx(1, XftColorAllocName);
Index: kbfunc.c
===
RCS file: /cvs/xenocara/app/cwm/kbfunc.c,v
retrieving revision 1.63
diff -u -p -u -r1.63 kbfunc.c
--- kbfunc.c9 Sep 2012 19:47:47 -   1.63
+++ kbfunc.c31 Oct 2012 16:38:30 -
@@ -35,6 +35,7 @@
 #define KNOWN_HOSTS.ssh/known_hosts
 #define HASH_MARKER|1|
 
+extern char**saved_argv;
 extern sig_atomic_txev_quit;
 
 void
@@ -490,7 +491,8 @@ kbfunc_quit_wm(struct client_ctx *cc, un
 }
 
 void
-kbfunc_reload(struct client_ctx *cc, union arg *arg)
+kbfunc_restart(struct client_ctx *cc, union arg *arg)
 {
-   conf_reload(Conf);
+   (void)setsid();
+   (void)execvp(saved_argv[0], saved_argv);
 }
Index: menu.c
===
RCS file: /cvs/xenocara/app/cwm/menu.c,v
retrieving revision 1.40
diff -u -p -u -r1.40 menu.c
--- menu.c  23 Oct 2012 16:13:59 -  1.40
+++ menu.c  31 Oct 2012 16:38:30 -
@@ -77,8 +77,6 @@ menu_init(struct screen_ctx *sc)
 {
XGCValuesgv;
 
-   if (sc-menuwin)
-   XDestroyWindow(X_Dpy, sc-menuwin);
sc-menuwin = XCreateSimpleWindow(X_Dpy, sc-rootwin, 0, 0, 1, 1,
Conf.bwidth,
sc-color[CWM_COLOR_FG_MENU].pixel,
@@ -89,8 +87,6 @@ menu_init(struct screen_ctx *sc)
gv.background = sc-color[CWM_COLOR_BG_MENU].pixel;
gv.function = GXxor;
 
-   if (sc-gc)
-   XFreeGC(X_Dpy, sc-gc);
sc-gc = XCreateGC(X_Dpy, sc-menuwin,
GCForeground|GCBackground|GCFunction, gv);
 }
Index: xutil.c
===
RCS file: /cvs/xenocara/app/cwm/xutil.c,v
retrieving revision 1.45
diff -u -p -u -r1.45 xutil.c
--- xutil.c 13 Jul 2012 17:01:05 -  1.45
+++ xutil.c 31 Oct 2012 16:38:30 -
@@ -429,9 +429,3 @@ xu_getcolor(struct screen_ctx *sc, char 
 
return (color.pixel);
 }
-
-void
-xu_freecolor(struct screen_ctx *sc, unsigned long pixel)
-{
-   XFreeColors(X_Dpy, DefaultColormap(X_Dpy, sc-which), pixel, 1, 0L);
-}
-- 
Alexander

Re: cwm reload support

2012-10-30 Thread Alexander Polakov
* Okan Demirmen o...@demirmen.com [121030 04:10]:
 will anyone miss reload support?  one can always re-exec cwm, or any
 other wm for a matter of fact.

I don't know the keybinding for it. It's useless :-)

-- 
Alexander Polakov | plhk.ru



Re: cwm reload support

2012-10-30 Thread Alexander Polakov
* Alexander Polakov p...@sdf.org [121030 14:40]:
 * Okan Demirmen o...@demirmen.com [121030 04:10]:
  will anyone miss reload support?  one can always re-exec cwm, or any
  other wm for a matter of fact.
 
 I don't know the keybinding for it. It's useless :-)

It seems people do really use that. How about this diff?
In short: do u_exec(cwm) in conf_reload(). This should probably be
u_exec(somewhere-argv0-is-saved).

Index: calmwm.h
===
RCS file: /cvs/xenocara/app/cwm/calmwm.h,v
retrieving revision 1.153
diff -u -p -u -r1.153 calmwm.h
--- calmwm.h9 Sep 2012 19:47:47 -   1.153
+++ calmwm.h30 Oct 2012 14:24:13 -
@@ -397,7 +397,7 @@ void kbfunc_lock(struct client_ctx 
*,
 voidkbfunc_menu_search(struct client_ctx *, union arg *);
 voidkbfunc_moveresize(struct client_ctx *, union arg *);
 voidkbfunc_quit_wm(struct client_ctx *, union arg *);
-voidkbfunc_reload(struct client_ctx *, union arg *);
+voidkbfunc_reload(struct client_ctx *, union arg *);
 voidkbfunc_ssh(struct client_ctx *, union arg *);
 voidkbfunc_term(struct client_ctx *, union arg *);
 
@@ -431,7 +431,6 @@ void conf_grab(struct conf *, 
struct 
 voidconf_grab_mouse(struct client_ctx *);
 voidconf_init(struct conf *);
 voidconf_mousebind(struct conf *, char *, char *);
-voidconf_reload(struct conf *);
 voidconf_setup(struct conf *, const char *);
 voidconf_ungrab(struct conf *, struct keybinding *);
 
@@ -449,7 +448,6 @@ void xev_loop(void);
 voidxu_btn_grab(Window, int, u_int);
 voidxu_btn_ungrab(Window, int, u_int);
 voidxu_configure(struct client_ctx *);
-voidxu_freecolor(struct screen_ctx *, unsigned long);
 voidxu_getatoms(void);
 unsigned long   xu_getcolor(struct screen_ctx *, char *);
 int xu_getprop(Window, Atom, Atom, long, u_char **);
Index: conf.c
===
RCS file: /cvs/xenocara/app/cwm/conf.c,v
retrieving revision 1.100
diff -u -p -u -r1.100 conf.c
--- conf.c  29 Oct 2012 19:46:03 -  1.100
+++ conf.c  30 Oct 2012 14:24:13 -
@@ -81,36 +81,8 @@ conf_color(struct conf *c, struct screen
 {
int  i;
 
-   for (i = 0; i  CWM_COLOR_MAX; i++) {
-   xu_freecolor(sc, sc-color[i].pixel);
+   for (i = 0; i  CWM_COLOR_MAX; i++)
sc-color[i].pixel = xu_getcolor(sc, c-color[i].name);
-   }
-}
-
-void
-conf_reload(struct conf *c)
-{
-   struct screen_ctx   *sc;
-   struct client_ctx   *cc;
-
-   if (parse_config(c-conf_path, c) == -1) {
-   warnx(config file %s has errors, not reloading, c-conf_path);
-   return;
-   }
-
-   TAILQ_FOREACH(sc, Screenq, entry) {
-   conf_gap(c, sc);
-   conf_color(c, sc);
-   conf_font(c, sc);
-   menu_init(sc);
-   }
-   TAILQ_FOREACH(cc, Clientq, entry) {
-   conf_client(cc);
-   /* XXX Does not take hmax/vmax into account. */
-   if ((cc-flags  CLIENT_MAXFLAGS) == CLIENT_MAXIMIZED)
-   cc-bwidth = 0;
-   client_draw_border(cc);
-   }
 }
 
 static struct {
@@ -148,7 +120,7 @@ static struct {
{ CM-equal,   vmaximize },
{ CMS-equal,  hmaximize },
{ CMS-f,  freeze },
-   { CMS-r,  reload },
+   { CMS-r,  reload },
{ CMS-q,  quit },
{ M-h,moveleft },
{ M-j,movedown },
Index: cwm.1
===
RCS file: /cvs/xenocara/app/cwm/cwm.1,v
retrieving revision 1.47
diff -u -p -u -r1.47 cwm.1
--- cwm.1   9 May 2012 18:37:39 -   1.47
+++ cwm.1   30 Oct 2012 14:24:13 -
@@ -115,8 +115,6 @@ Spawn
 dialog; allows you to switch from
 .Nm
 to another window manager without restarting the X server.
-.It Ic CMS-r
-Reload configuration.
 .It Ic CMS-q
 Quit
 .Nm .
Index: cwmrc.5
===
RCS file: /cvs/xenocara/app/cwm/cwmrc.5,v
retrieving revision 1.44
diff -u -p -u -r1.44 cwmrc.5
--- cwmrc.5 28 Oct 2012 20:13:02 -  1.44
+++ cwmrc.5 30 Oct 2012 14:24:13 -
@@ -269,8 +269,6 @@ mousebind M-3   window_resize
 .Ed
 .Sh BIND COMMAND LIST
 .Bl -tag -width 18n -compact
-.It reload
-Reload configuration.
 .It quit
 Quit
 .Xr cwm 1 .
Index: font.c
===
RCS file: /cvs/xenocara/app/cwm/font.c,v
retrieving

[hppa64] mkboot fix

2012-09-28 Thread Alexander Polakov
This allows mkboot make bootable lif's.
mkboot compiled on amd64, tested with rp2470.

Index: mkboot.c
===
RCS file: /cvs/src/sys/arch/hppa64/stand/mkboot/mkboot.c,v
retrieving revision 1.2
diff -u -p -r1.2 mkboot.c
--- mkboot.c27 Oct 2009 23:59:34 -  1.2
+++ mkboot.c28 Sep 2012 13:32:53 -
@@ -117,10 +117,10 @@ main(int argc, char **argv)
bzero(buf, sizeof(buf));
/* clear possibly unused directory entries */
memset(lifd[1].dir_name, ' ', sizeof lifd[1].dir_name);
-   lifd[1].dir_type = -1;
+   lifd[1].dir_type = htobe16(-1);
lifd[1].dir_addr = 0;
lifd[1].dir_length = 0;
-   lifd[1].dir_flag = 0xFF;
+   lifd[1].dir_flag = htobe16(0xFF);
lifd[1].dir_implement = 0;
lifd[7] = lifd[6] = lifd[5] = lifd[4] = lifd[3] = lifd[2] = lifd[1];
 
@@ -131,7 +131,7 @@ main(int argc, char **argv)
lifv-vol_oct = htobe16(LIF_VOL_OCT);
lifv-vol_dirsize = htobe32(btolifs(LIF_DIRSIZE));
lifv-vol_version = htobe16(1);
-   lifv-vol_lastvol = lifv-vol_number =  htobe16(1);
+   lifv-vol_lastvol = lifv-vol_number = htobe32(1);
lifv-vol_length = LIF_FILESTART;
bcddate(to_file, lifv-vol_toc);
lifv-ipl_addr = htobe32(LIF_FILESTART);
@@ -211,12 +211,12 @@ putfile(from_file, to)
n = read(from, elf_header, sizeof (elf_header));
if (n != sizeof (elf_header))
err(1, %s: reading ELF header, from_file);
-   header_count = betoh32(elf_header.e_phnum);
+   header_count = betoh16(elf_header.e_phnum);
memory_needed = header_count * sizeof (*elf_segments);
elf_segments = malloc(memory_needed);
if (elf_segments == NULL)
err(1, malloc);
-   (void) lseek(from, betoh32(elf_header.e_phoff), SEEK_SET);
+   (void) lseek(from, betoh64(elf_header.e_phoff), SEEK_SET);
n = read(from, elf_segments, memory_needed);
if (n != memory_needed)
err(1, %s: reading ELF segments, from_file);
@@ -233,9 +233,10 @@ putfile(from_file, to)
}
if (elf_load_image_segment == -1)
errx(1, %s: no suitable ELF program segment, 
from_file);
-   entry = betoh32(elf_header.e_entry) +
-   betoh32(elf_segments[elf_load_image_segment].p_offset) -
-   betoh32(elf_segments[elf_load_image_segment].p_vaddr);
+   entry = betoh64(elf_header.e_entry) +
+   betoh64(elf_segments[elf_load_image_segment].p_offset) -
+   betoh64(elf_segments[elf_load_image_segment].p_vaddr);
+   printf(entry = 0x%lx\n, entry);
} else if (*(u_char *)ex == 0x1f  ((u_char *)ex)[1] == 0x8b) {
entry = 0;
} else

-- 
open source wizard



ksh: tab completion fix (again)

2012-09-26 Thread Alexander Polakov
I sent this diff in 2011 (?) with a bunch of other diffs.
It fixes tab completion for filenames containing special
characters like [], () and so.

This code affects interactive mode only, and I don't know a way
to do automated testing of this. Suggestions welcome.

Index: edit.c
===
RCS file: /cvs/src/bin/ksh/edit.c,v
retrieving revision 1.35
diff -u -r1.35 edit.c
--- edit.c  10 Sep 2012 01:25:30 -  1.35
+++ edit.c  26 Sep 2012 21:32:42 -
@@ -348,7 +348,7 @@
 {
char *toglob;
char **words;
-   int nwords, i, idx, escaping;
+   int nwords;
XPtrV w;
struct source *s, *sold;
 
@@ -357,20 +357,6 @@
 
toglob = add_glob(str, slen);
 
-   /* remove all escaping backward slashes */
-   escaping = 0;
-   for (i = 0, idx = 0; toglob[i]; i++) {
-   if (toglob[i] == '\\'  !escaping) {
-   escaping = 1;
-   continue;
-   }
-
-   toglob[idx] = toglob[i];
-   idx++;
-   if (escaping) escaping = 0;
-   }
-   toglob[idx] = '\0';
-
/*
 * Convert foo* (toglob) to an array of strings (words)
 */
@@ -378,7 +364,7 @@
s = pushs(SWSTR, ATEMP);
s-start = s-str = toglob;
source = s;
-   if (yylex(ONEWORD) != LWORD) {
+   if (yylex(ONEWORD|UNESCAPE) != LWORD) {
source = sold;
internal_errorf(0, fileglob: substitute error);
return 0;
@@ -394,15 +380,12 @@
if (nwords == 1) {
struct stat statb;
 
-   /* Check if globbing failed (returned glob pattern),
-* but be careful (E.g. toglob == ab* when the file
-* ab* exists is not an error).
-* Also, check for empty result - happens if we tried
-* to glob something which evaluated to an empty
-* string (e.g., $FOO when there is no FOO, etc).
+   /* Check if file exists, also, check for empty
+* result - happens if we tried to glob something
+* which evaluated to an empty string (e.g.,
+* $FOO when there is no FOO, etc).
 */
-   if ((strcmp(words[0], toglob) == 0 
-   stat(words[0], statb)  0) ||
+if ((lstat(words[0], statb)  0) ||
words[0][0] == '\0') {
x_free_words(nwords, words);
words = NULL;
Index: lex.c
===
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.45
diff -u -r1.45 lex.c
--- lex.c   9 Mar 2011 09:30:39 -   1.45
+++ lex.c   26 Sep 2012 21:32:43 -
@@ -299,6 +299,10 @@
}
/* FALLTHROUGH */
default:
+   if (cf  UNESCAPE) {
+   *wp++ = QCHAR, *wp++ = c;
+   break;
+   }
Xcheck(ws, wp);
if (c) { /* trailing \ is lost */
*wp++ = CHAR, *wp++ = '\\';
Index: lex.h
===
RCS file: /cvs/src/bin/ksh/lex.h,v
retrieving revision 1.11
diff -u -r1.11 lex.h
--- lex.h   29 May 2006 18:22:24 -  1.11
+++ lex.h   26 Sep 2012 21:32:43 -
@@ -113,6 +113,7 @@
 #define CMDWORD BIT(8) /* parsing simple command (alias related) */
 #define HEREDELIM BIT(9)   /* parsing ,- delimiter */
 #define HEREDOC BIT(10)/* parsing heredoc */
+#define UNESCAPE BIT(11)   /* remove backslashes */
 
 #defineHERES   10  /* max  in line */
 

-- 
open source wizard



Re: ThinkPad T60 x86emu panic on resume (w/patch)

2012-09-03 Thread Alexander Polakov
* Theo de Raadt dera...@cvs.openbsd.org [120903 00:13]:
  Index: vga_pci.c
  ===
  RCS file: /cvs/src/sys/dev/pci/vga_pci.c,v
  retrieving revision 1.68
  diff -u -r1.68 vga_pci.c
  --- vga_pci.c   22 Aug 2012 20:58:30 -  1.68
  +++ vga_pci.c   2 Sep 2012 17:42:09 -
  @@ -186,7 +186,13 @@
  {   0x, 0x, 0x, 0x }, 1, 0
  },
   
  -   {   /* All ATI video until further notice */
  +   {   
  +   {   PCI_VENDOR_ATI, PCI_PRODUCT_ATI_RADEON_X1400,
  +   0x, 0x },
  +   {   0x, 0x, 0x, 0x}, 0, 0
  +   },
  +
  +   {   /* Other ATI video until further notice */
  {   PCI_VENDOR_ATI, 0x,
  0x, 0x },
  {   0x, 0x, 0x, 0x}, 1, 0
 
 
 That's a great patch, because it doesn't find or fix the underlying
 issues.

Thanks.

 Then, when the next person -- who's video did need this -- finds out
 it no longer works, they can submit the inverse of your diff -- once
 again not undercovering the real issue.  Of course, now it is their
 problem, not yours, right?

No, he'll add a record above mine with his subproduct/subvendor ids.

 Your diff can be summarized as make it work for me, me, me, me.
 Awesome work.  You know how to fix it just for yourself and submit a
 self-serving patch, hoping we'll commit it without looked deeper, so
 truly you are now an open source wizard.

I don't hope you'll commit it as is. I hope you'll send some useful
comments and suggestions to improve the patch (not insults).

Now back to underlying issues: x86emu executes some code which causes
parity check NMI (bit 7 set in port 0x61) to be generated, which causes
drop to the debugger (I mistook it for a panic).

Btw, is it intended to not include isa.h in i386/trap.c? (removed in r.1.35).
Code wrapped in #if NISA  0 is thrown out by cpp now.



Sync i386 NMI trap code with amd64

2012-09-03 Thread Alexander Polakov
Include isa.h to avoid confusion while reading the code (code wrapped
into #if NISA  0 is thrown out by cpp atm).
No behaviour change, except for additional printf() before entering
the debugger (which I find helpful).
Ignore second chunk if you don't care about i386 and amd64 being the
same.

Btw, amd64/x86_nmi() reads ports which are called historic garbage by
i386/isa_nmi().

Index: trap.c
===
RCS file: /cvs/src/sys/arch/i386/i386/trap.c,v
retrieving revision 1.103
diff -u -r1.103 trap.c
--- trap.c  7 Aug 2012 05:16:53 -   1.103
+++ trap.c  3 Sep 2012 21:49:26 -
@@ -80,6 +80,7 @@
 #endif
 
 #include npx.h
+#include isa.h
 
 void trap(struct trapframe *);
 void syscall(struct trapframe *);
@@ -509,13 +510,12 @@
if (kdb_trap(type, 0, frame))
return;
 #endif
-   return;
 #endif /* DDB || KGDB */
/* machine/parity/power fail/kitchen sink faults */
-   if (isa_nmi() == 0)
-   return;
-   else
+   if (isa_nmi() != 0)
goto we_re_toast;
+   else
+   return;
 #endif
}



Re: ThinkPad T60 x86emu panic on resume (w/patch)

2012-09-02 Thread Alexander Polakov
With the diff below it resumes ok to X, but when I try to switch
to text console or do a shutdown, I get this panic:

/etc/rc.shutdown in progress...
/etc/rc.shutdown complete.
Stopped at  cpu_idle_cycle+0xf: ret
ddb{1} bt
No such command
ddb{1} trace
cpu_idle_cycle(d406ac00) at cpu_idle_cycle+0xf
Bad frame pointer: 0xf546ef5c
ddb{1} machine ddbcpu 0
Stopped at  Debugger+0x4:   popl%ebp
ddb{0} bt
No such command
ddb{0} trace
Debugger(d0b035e0,f54c2f08,0,14,6b) at Debugger+0x4
i386_ipi_handler(0,20,0,f54c0010,d0510010) at i386_ipi_handler+0x5f
Xintripi() at Xintripi+0x49
--- interrupt ---
kputchar(6b,14,0,1,0) at kputchar+0x1a
kprintf(d08f3d1a,14,0,0,f54c2ef8) at kprintf+0x254
db_printf(d08f3d1a,1b88d72e,b,d03db6c2,0) at db_printf+0x3e
kdbprinttrap(109,0,d9ddae24,1000,d0a47d44) at kdbprinttrap+0x1e
kdb_trap(109,0,f54c2fa8,3,ffee3bd) at kdb_trap+0x1fc
trap() at trap+0x2e7
--- trap (number 0) ---
0:
ddb{0} 

Index: vga_pci.c
===
RCS file: /cvs/src/sys/dev/pci/vga_pci.c,v
retrieving revision 1.68
diff -u -r1.68 vga_pci.c
--- vga_pci.c   22 Aug 2012 20:58:30 -  1.68
+++ vga_pci.c   2 Sep 2012 17:42:09 -
@@ -186,7 +186,13 @@
{   0x, 0x, 0x, 0x }, 1, 0
},
 
-   {   /* All ATI video until further notice */
+   {   
+   {   PCI_VENDOR_ATI, PCI_PRODUCT_ATI_RADEON_X1400,
+   0x, 0x },
+   {   0x, 0x, 0x, 0x}, 0, 0
+   },
+
+   {   /* Other ATI video until further notice */
{   PCI_VENDOR_ATI, 0x,
0x, 0x },
{   0x, 0x, 0x, 0x}, 1, 0

* Alexander Polakov p...@sdf.org [120902 21:40]:
 Suspending system...
 # Stopped at  x86emu_halt_sys+0x47f7: movl0x40(%edi),%ecx
 x86emu_halt_sys(d408804c,3,f5470d6c,d0725f1c,d4088000) at 
 x86emu_halt_sys+0x47f
 7
 x86emu_exec(d4088000,c000,3,d05b0887,0) at x86emu_exec+0x41
 vga_post_call(d4088000,c0,f5470dbc,f5470d8c,d4016400) at vga_post_call+0x6c
 vga_pci_activate(d4016400,3,f5470dbc,d05b2208,d3f29180) at 
 vga_pci_activate+0x9
 8
 config_activate_children(d3f29180,3,f5470dec,d05b019c,0) at 
 config_activate_chi
 ldren+0x45
 config_activate_children(d4016600,3,4,100107,f5470e1c) at 
 config_activate_child
 ren+0x45
 ppbactivate(d4016600,3,f5470e5c,d05b2208,d3f29380) at ppbactivate+0x345
 config_activate_children(d3f29380,3,f5470e8c,d0840914,c0) at 
 config_activate_ch
 ildren+0x45
 config_activate_children(d4015fc0,3,1,f5470ebc,0) at 
 config_activate_children+0
 x45
 acpi_resume(d4013c00,3,0,d409a560,d4013c00) at acpi_resume+0x134
 ddb{0} trace
 x86emu_halt_sys(d408804c,3,f5470d6c,d0725f1c,d4088000) at 
 x86emu_halt_sys+0x47f
 7
 x86emu_exec(d4088000,c000,3,d05b0887,0) at x86emu_exec+0x41
 vga_post_call(d4088000,c0,f5470dbc,f5470d8c,d4016400) at vga_post_call+0x6c
 vga_pci_activate(d4016400,3,f5470dbc,d05b2208,d3f29180) at 
 vga_pci_activate+0x9
 8
 config_activate_children(d3f29180,3,f5470dec,d05b019c,0) at 
 config_activate_chi
 ldren+0x45
 config_activate_children(d4016600,3,4,100107,f5470e1c) at 
 config_activate_child
 ren+0x45
 ppbactivate(d4016600,3,f5470e5c,d05b2208,d3f29380) at ppbactivate+0x345
 config_activate_children(d3f29380,3,f5470e8c,d0840914,c0) at 
 config_activate_ch
 ildren+0x45
 config_activate_children(d4015fc0,3,1,f5470ebc,0) at 
 config_activate_children+0
 x45
 acpi_resume(d4013c00,3,0,d409a560,d4013c00) at acpi_resume+0x134
 acpi_sleep_state(d4013c00,3,0,d0840d41,d409a560) at acpi_sleep_state+0x7a
 acpi_sleep_task(d4013c00,3,d9fd0744,1,d4013c00) at acpi_sleep_task+0x1a
 acpi_dotask(d4013c00,20,d09ccf9d,0,d03db6c2) at acpi_dotask+0x42
 acpi_thread(d3f27770) at acpi_thread+0x123
 Bad frame pointer: 0xd0bbbe28
 ddb{0} boot reboot
 cbb0: bad Vcc request. sock_ctrl 0xff88, sock_status 0x
 rebooting...



Re: [cwm] ssh menu: match on any part of input

2012-08-27 Thread Alexander Polakov
* Jonas Jonasson jonas.jonas...@safe-mail.net [120827 13:02]:
  I don't know about you guys, but:
  
  1) I can recall last octet of an IP address more often than the first,
  2) I have a lot of machines in the same /24 subnet.
 
 Why not use globbing?

Because it is slower to type and less convenient.

 I find search_match_text redundant since search_match_exec has support for
 globbing. You can do *x* to get the same behaviour as search_match_text x.
 With search_match_exec you can also list all alternatives (*).

Like Ctrl-A, right?
 
 Furthermore when it comes to searching in the menus in cwm, why not do case
 sensitive matching? Every user is used to the fact that case matters 
 everywhere
 else. It also allows for better filtering.

When I search for window, I don't care if it is Bla-blah ISO 13818.pdf or
bla-blah iso 13818.pdf and iso 138 is easier to type than *ISO 138*.



[cwm] ssh menu: match on any part of input

2012-08-24 Thread Alexander Polakov
I don't know about you guys, but:

1) I can recall last octet of an IP address more often than the first,
2) I have a lot of machines in the same /24 subnet.

diff --git a/kbfunc.c b/kbfunc.c
index 9bbf802..9f1fdb1 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -377,7 +377,7 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg)
(void)fclose(fp);
 
if ((mi = menu_filter(sc, menuq, ssh, NULL, 1, 0,
-   search_match_exec, NULL)) != NULL) {
+   search_match_text, NULL)) != NULL) {
if (mi-text[0] == '\0')
goto out;
l = snprintf(cmd, sizeof(cmd), %s -e ssh %s, Conf.termpath,



Re: pdksh wrong strips quotes in shell substs

2012-08-12 Thread Alexander Polakov
* Philip Guenther guent...@gmail.com [120812 18:50]:
 On Sun, 12 Aug 2012, Alexander Polakov wrote:
 Below is an expansion of your diff for tests/unclass2.t to cover the cases 
 discussed in this thread plus a couple others.
 
 
 As for how to get the fix to cover all those cases: the heredoc case can 
 be handled by changing the added test to
   if ((cf  HEREDOC) || state == SBRACE)
 
 ...but it needs to be something like
   if ((cf  HEREDOC) || (state == SBRACE  is_in_double_quotes))
 
 with is_in_double_quotes some magic to differentiate between the 
 ${foo+'bar'} and ${foo+'bar'} cases.  That presumably involves walking 
 up the statep list, but that has to stop when it hits a wrapping 
 command-expansion.  For example, the third new test in the diff below:
   echo $( echo ${foo:+'blah  $foo'})
 that should output
   blah  $foo

Ok, second attempt

Index: lex.c
===
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.45
diff -u -r1.45 lex.c
--- lex.c   9 Mar 2011 09:30:39 -   1.45
+++ lex.c   12 Aug 2012 19:13:12 -
@@ -113,7 +113,7 @@
 
   Again:
states[0].ls_state = -1;
-   states[0].ls_info.base = (Lex_state *) 0;
+   states[0].ls_info.base = (Lex_state *) NULL;
statep = states[1];
state_info.base = states;
state_info.end = states[STATE_BSIZE];
@@ -270,6 +270,10 @@
*wp++ = QCHAR, *wp++ = c;
break;
case '\'':
+   if ((cf  HEREDOC) || state == SBRACEQ) {
+   *wp++ = CHAR, *wp++ = c;
+   break;
+   }
*wp++ = OQUOTE;
ignore_backslash_newline++;
PUSH_STATE(SSQUOTE);
@@ -342,7 +346,10 @@
PUSH_STATE(STBRACE);
} else {
ungetsc(c);
-   PUSH_STATE(SBRACE);
+   if (state == SDQUOTE)
+   PUSH_STATE(SBRACEQ);
+   else
+   PUSH_STATE(SBRACE);
}
} else if (ctype(c, C_ALPHA)) {
*wp++ = OSUBST;
@@ -419,6 +426,10 @@
case SSQUOTE:
if (c == '\'') {
POP_STATE();
+   if (state == SBRACEQ) {
+   *wp++ = CHAR, *wp++ = c;
+   break;
+   }
*wp++ = CQUOTE;
ignore_backslash_newline--;
} else
@@ -525,6 +536,7 @@
*wp++ = c;
break;
 
+   case SBRACEQ:
case SBRACE:
/*{*/
if (c == '}') {
Index: lex.h
===
RCS file: /cvs/src/bin/ksh/lex.h,v
retrieving revision 1.11
diff -u -r1.11 lex.h
--- lex.h   29 May 2006 18:22:24 -  1.11
+++ lex.h   12 Aug 2012 19:13:12 -
@@ -51,19 +51,20 @@
 /*
  * states while lexing word
  */
-#defineSBASE   0   /* outside any lexical constructs */
-#defineSWORD   1   /* implicit quoting for substitute() */
-#defineSLETPAREN 2 /* inside (( )), implicit quoting */
-#defineSSQUOTE 3   /* inside '' */
-#defineSDQUOTE 4   /* inside  */
-#defineSBRACE  5   /* inside ${} */
-#defineSCSPAREN 6  /* inside $() */
-#defineSBQUOTE 7   /* inside `` */
-#defineSASPAREN 8  /* inside $(( )) */
-#define SHEREDELIM 9   /* parsing ,- delimiter */
-#define SHEREDQUOTE 10 /* parsing  in ,- delimiter */
-#define SPATTERN 11/* parsing *(...|...) pattern (*+?@!) */
-#define STBRACE 12 /* parsing ${..[#%]..} */
+#define SBASE  0   /* outside any lexical constructs */
+#define SWORD  1   /* implicit quoting for substitute() */
+#define SLETPAREN  2   /* inside (( )), implicit quoting */
+#define SSQUOTE3   /* inside '' */
+#define SDQUOTE4   /* inside  */
+#define SBRACE 5   /* inside ${} */
+#define SBRACEQ6   /* inside ${} */
+#define SCSPAREN   7   /* inside $() */
+#define SBQUOTE

Re: pdksh wrong strips quotes in shell substs

2012-08-11 Thread Alexander Polakov
* Philip Guenther guent...@gmail.com [120810 00:45]:
 On Thu, Aug 9, 2012 at 5:31 AM, Mark Kettenis mark.kette...@xs4all.nl wrote:
  Date: Thu, 9 Aug 2012 11:30:13 +0200
  From: Landry Breuil lan...@rhaalovely.net
 ...
  in the context of https://bugzilla.mozilla.org/show_bug.cgi?id=781461
  i've stumbled upon the following issue:
  (our pdksh)
 
  $FOO=1
  $cat EOF
   echo ${FOO:+'blah'aa}
   EOF
  echo blahaa
 
  bash-4.2# FOO=1
  bash-4.2# cat EOF
echo ${FOO:+'blah'aa}
   EOF
   echo 'blah'aa
 
  Apparently the ksh from solaris, hpux and debian don't strip the quotes
  in that usecase, and none of the other shells do (bash, dash, zsh...)
 
  So maybe it can be considered as a bug in our pdksh..
 
  I think it is.  POSIX says in 2.6.2 Parameter Expansion that:
 
...word shall be subjected to tilde expansion, parameter expansion,
command substitution, and arithmetic expansion.
 
  which suggests that quote removal isn't supposed to happen.
 
 I agree.  The bug applies to the simple double-quoted case too:
 
 $ foo=1
 $ echo ${foo:+'blah'}
 blah
 $
 
 The correct output there should include the single-quotes, ala:
 'blah'

Hi.

Nobody cares, so here's my attempt. I haven't run it though a
world/ports build because of slow hardware on my hands right now.

Index: lex.c
===
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.45
diff -u -r1.45 lex.c
--- lex.c   9 Mar 2011 09:30:39 -   1.45
+++ lex.c   11 Aug 2012 20:18:15 -
@@ -271,6 +271,8 @@
break;
case '\'':
*wp++ = OQUOTE;
+   if (state == SBRACE)
+   *wp++ = CHAR, *wp++ = c;
ignore_backslash_newline++;
PUSH_STATE(SSQUOTE);
break;
@@ -420,6 +422,8 @@
if (c == '\'') {
POP_STATE();
*wp++ = CQUOTE;
+   if (state == SBRACE)
+   *wp++ = CHAR, *wp++ = c;
ignore_backslash_newline--;
} else
*wp++ = QCHAR, *wp++ = c;
Index: tests/unclass2.t
===
RCS file: /cvs/src/bin/ksh/tests/unclass2.t,v
retrieving revision 1.2
diff -u -r1.2 unclass2.t
--- tests/unclass2.t25 Jun 1998 19:02:43 -  1.2
+++ tests/unclass2.t11 Aug 2012 20:18:19 -
@@ -161,3 +161,12 @@
XX
 ---
 
+name: single quotes in braces
+description:
+   Check that single quotes inside {} are not lost
+stdin:
+   foo=1
+   echo ${foo:+'blah'}
+expected-stdout:
+   'blah'
+---



ACPI WMI project, need help

2012-07-30 Thread Alexander Polakov
Hi,

I started working on porting ACPI WMI (WMI stands for Windows Management
Instrumentation, it's ACPI extension by Microsoft) driver from NetBSD hoping 
it will help me with my HP Compaq 6910p problem [1].

Currently, device attaches, and I can do some simple stuff, like dumping
its guids table (and attach dumb acpihp on top of it).

acpiwmi0 at acpi0: ACPI WMI Interface
acpiwmi0: {5FB7F034-2C63-45E9-BE91-3D44E2C707E4} oid 4141 count 01 flags 02
acpiwmi0: {95F24279-4D7B-4334-9387-ACCDC67EF61C} oid 0080 count 01 flags 08
acpiwmi0: {2B814318-4BE8-4707-9D84-A190A859B5D0} oid 00A0 count 01 flags 08
acpiwmi0: {05901221-D566-11D1-B2F0-00A0C9062910} oid 4241 count 01 flags 00
acpiwmi0: {1F4C91EB-DC5C-460B-951D-C7CB9B4B8D5E} oid 4142 count 01 flags 02
acpiwmi0: {2D114B49-2DFB-4130-B8FE-4A3C09E75133} oid 4342 count 35 flags 00
acpiwmi0: {988D08E3-68F4-4C35-AF3E-6A1B8106F83C} oid 4442 count 14 flags 00
acpiwmi0: {14EA9746-CE1F-4098-A0E0-7045CB4DA745} oid 4542 count 01 flags 00
acpiwmi0: {322F2028-0F84-4901-988E-015176049E2D} oid 4642 count 02 flags 00
acpiwmi0: {8232DE3D-663D-4327-A8F4-E293ADB9BF05} oid 4742 count 00 flags 00
acpiwmi0: {8F1F6436-9F42-42C8-BADC-0E9424F20C9A} oid 4842 count 00 flags 00
acpiwmi0: {8F1F6435-9F42-42C8-BADC-0E9424F20C9A} oid 4942 count 00 flags 00
acpihp0 at acpiwmi0: HP WMI mappings

What really bothers me here is acpi_wmi_init_ec() function, which claims
to install address space handler for the EC space.

Here it is:

static void
acpi_wmi_init_ec(struct acpi_wmi_softc *sc)
{
searching for EC device skipped

rv = AcpiInstallAddressSpaceHandler(sc-sc_node-ad_handle,
ACPI_ADR_SPACE_EC, acpi_wmi_ec_handler, NULL, sc);

if (ACPI_FAILURE(rv))
sc-sc_ecdev = NULL;
}

You can see code for AcpiInstallAddressSpaceHandler() here [2].

The handler itself looks like this:

/*
 * Handler for EC regions, which may be embedded in WMI.
 */
static int
acpi_wmi_ec_handler(uint32_t func, ACPI_PHYSICAL_ADDRESS addr,
uint32_t width, ACPI_INTEGER *val, void *setup, void *aux)
{
struct acpi_wmi_softc *sc = aux;

if (aux == NULL || val == NULL)
return AE_BAD_PARAMETER;

if (addr  0xFF || width % 8 != 0)
return AE_BAD_ADDRESS;

switch (func) {

case ACPI_READ:
(void)acpiec_bus_read(sc-sc_ecdev, addr, val, width);
break;

case ACPI_WRITE:
(void)acpiec_bus_write(sc-sc_ecdev, addr, *val, width);
break;

default:
return AE_BAD_PARAMETER;
}

return AE_OK;
}

My problem is that I can't find something similar in our ACPI stack.
NetBSD installs address space handler in their EC driver too, but
OpenBSD doesn't do this. Can I safely ignore this piece of code, or
is it crucial for properly operating the device?

Begging for a helping hand from ACPI guru.

[1] 
http://old.nabble.com/HP-6910p%3A-keyboard---touchpad-not-working-p34156209.html
[2] 
http://grok.x12.su/source/xref/netbsd/sys/external/intel-public/acpica/dist/events/evxfregn.c#130



Reduce IPI traffic from signals

2012-07-23 Thread Alexander Polakov
This diff reduces IPI traffic for a case when process A is sending
a lot of signals to process B running on a different CPU. userret()
delivers all process signals at once, so there is no need to send
an interrupt for every signal.

The problem was noticed by rtorrent 0.9.2 users, which does exactly
this, which led to process/system hangs and slowness.

Tested and known to help on amd64 by me and dcoppa@.

Index: amd64/amd64/machdep.c
===
RCS file: /cvs/src/sys/arch/amd64/amd64/machdep.c,v
retrieving revision 1.155
diff -u -r1.155 machdep.c
--- amd64/amd64/machdep.c   4 Jun 2012 15:19:47 -   1.155
+++ amd64/amd64/machdep.c   23 Jul 2012 13:49:40 -
@@ -690,8 +690,10 @@
 void
 signotify(struct proc *p)
 {
-   aston(p);
-   cpu_unidle(p-p_cpu);
+   if (!isastset(p)) {
+   aston(p);
+   cpu_unidle(p-p_cpu);
+   }
 }
 
 #ifdef MULTIPROCESSOR
Index: amd64/include/cpu.h
===
RCS file: /cvs/src/sys/arch/amd64/include/cpu.h,v
retrieving revision 1.73
diff -u -r1.73 cpu.h
--- amd64/include/cpu.h 17 Apr 2012 16:02:33 -  1.73
+++ amd64/include/cpu.h 23 Jul 2012 13:49:40 -
@@ -213,6 +213,7 @@
 #endif
 
 #define aston(p)   ((p)-p_md.md_astpending = 1)
+#define isastset(p)((p)-p_md.md_astpending == 1)
 
 #define curpcb curcpu()-ci_curpcb
 
Index: hppa/hppa/machdep.c
===
RCS file: /cvs/src/sys/arch/hppa/hppa/machdep.c,v
retrieving revision 1.206
diff -u -r1.206 machdep.c
--- hppa/hppa/machdep.c 21 Jun 2012 00:56:59 -  1.206
+++ hppa/hppa/machdep.c 23 Jul 2012 13:49:40 -
@@ -1399,8 +1399,10 @@
 void
 signotify(struct proc *p)
 {
-   setsoftast(p);
-   cpu_unidle(p-p_cpu);
+   if (!isastset(p)) {
+   setsoftast(p);
+   cpu_unidle(p-p_cpu);
+   }
 }
 
 /*
Index: hppa/include/intr.h
===
RCS file: /cvs/src/sys/arch/hppa/include/intr.h,v
retrieving revision 1.37
diff -u -r1.37 intr.h
--- hppa/include/intr.h 14 Jan 2011 13:20:06 -  1.37
+++ hppa/include/intr.h 23 Jul 2012 13:49:40 -
@@ -157,7 +157,8 @@
 int hppa_ipi_broadcast(u_long);
 #endif
 
-#definesetsoftast(p)   (p-p_md.md_astpending = 1)
+#definesetsoftast(p)   ((p)-p_md.md_astpending = 1)
+#defineisastset(p) ((p)-p_md.md_astpending == 1)
 
 void   *softintr_establish(int, void (*)(void *), void *);
 voidsoftintr_disestablish(void *);
Index: i386/i386/machdep.c
===
RCS file: /cvs/src/sys/arch/i386/i386/machdep.c,v
retrieving revision 1.510
diff -u -r1.510 machdep.c
--- i386/i386/machdep.c 23 May 2012 08:23:43 -  1.510
+++ i386/i386/machdep.c 23 Jul 2012 13:49:40 -
@@ -2420,8 +2420,10 @@
 void
 signotify(struct proc *p)
 {
-   aston(p);
-   cpu_unidle(p-p_cpu);
+   if (!isastset(p)) {
+   aston(p);
+   cpu_unidle(p-p_cpu);
+   }
 }
 
 #ifdef MULTIPROCESSOR
Index: i386/include/cpu.h
===
RCS file: /cvs/src/sys/arch/i386/include/cpu.h,v
retrieving revision 1.122
diff -u -r1.122 cpu.h
--- i386/include/cpu.h  27 Mar 2012 06:44:01 -  1.122
+++ i386/include/cpu.h  23 Jul 2012 13:49:41 -
@@ -226,6 +226,7 @@
 #endif
 
 #define aston(p)   ((p)-p_md.md_astpending = 1)
+#define isastset(p)((p)-p_md.md_astpending == 1)
 
 #define curpcb curcpu()-ci_curpcb
 
Index: m88k/include/cpu.h
===
RCS file: /cvs/src/sys/arch/m88k/include/cpu.h,v
retrieving revision 1.54
diff -u -r1.54 cpu.h
--- m88k/include/cpu.h  25 Oct 2011 18:38:06 -  1.54
+++ m88k/include/cpu.h  23 Jul 2012 13:49:41 -
@@ -256,6 +256,7 @@
(((struct cpu_info *)(framep)-tf.tf_cpu)-ci_intrdepth  1)
 
 #defineaston(p)((p)-p_md.md_astpending = 1)
+#defineisastset(p) ((p)-p_md.md_astpending == 1)
 
 /*
  * This is used during profiling to integrate system time.
Index: m88k/m88k/m88k_machdep.c
===
RCS file: /cvs/src/sys/arch/m88k/m88k/m88k_machdep.c,v
retrieving revision 1.52
diff -u -r1.52 m88k_machdep.c
--- m88k/m88k/m88k_machdep.c23 Mar 2012 15:51:26 -  1.52
+++ m88k/m88k/m88k_machdep.c23 Jul 2012 13:49:41 -
@@ -314,8 +314,10 @@
 void
 signotify(struct proc *p)
 {
-   aston(p);
-   cpu_unidle(p-p_cpu);
+   if (!isastset(p)) {
+   aston(p);
+   cpu_unidle(p-p_cpu);
+   }
 }
 
 #ifdef MULTIPROCESSOR
Index: macppc/macppc/machdep.c
===
RCS file: 

Re: cwm tiling

2012-06-09 Thread Alexander Polakov
* Tobias Ulmer tobi...@tmux.org [120609 11:32]:
 On Sun, Jun 03, 2012 at 09:07:13PM +0400, Alexander Polakov wrote:
  I'd like to start a discussion about adding tiling to cwm with
  these two diffs.
 
 How hard can it be to import spectrwm... You're reinventing the wheel
 here, badly.

No, I am not. I'm reimplementing the wheel.

-- 
Alexander Polakov | plhk.ru



Re: cwm tiling

2012-06-09 Thread Alexander Polakov
* Thomas Pfaff tpf...@tp76.info [120608 23:06]:
 On Fri, 8 Jun 2012 13:57:35 -0400
 Okan Demirmen o...@demirmen.com wrote:
 
  On Fri 2012.06.08 at 19:40 +0200, Thomas Pfaff wrote:
   On Sun, 3 Jun 2012 21:07:13 +0400
   Alexander Polakov p...@sdf.org wrote:
   
I'd like to start a discussion about adding tiling to cwm with
these two diffs.
   
   I don't want it ;-)
   
   If I wanted a tiling window manager I'd install one of the many
   already available.  Please keep cwm clean and simple, as it is.
  
  It's not being dropped as an idea at all.  Defaults will not change
  however.
  
 
 Doing this means more code (more now and definitely more to come),
 more documentation, more configuration options, more to learn, more
 more more.

It adds about hundred lines of code and one binding now. You are not
obliged to learn and use every possible keyboard binding, are you?

 I appreciate that the defaults would stay the same, but really,
 what is the point in doing this?  cwm can't be everything to
 everyone.

The point is: when you want tiling from time to time, it's impractical
to switch to a tiling window manager.

-- 
Alexander Polakov | plhk.ru



[cwm patch 2/6] Focus MRU client when doing group_only()

2012-04-08 Thread Alexander Polakov
diff --git a/calmwm.h b/calmwm.h
index b365983..9ac93b0 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -319,6 +319,7 @@ void client_map(struct client_ctx 
*);
 voidclient_maximize(struct client_ctx *);
 voidclient_move(struct client_ctx *);
 voidclient_mtf(struct client_ctx *);
+struct client_ctx  *client_mrusearch(struct screen_ctx *, struct group_ctx 
*);
 struct client_ctx  *client_new(Window, struct screen_ctx *, int);
 voidclient_ptrsave(struct client_ctx *);
 voidclient_ptrwarp(struct client_ctx *);
diff --git a/client.c b/client.c
index 2cb0b1e..a53ccb0 100644
--- a/client.c
+++ b/client.c
@@ -643,6 +643,32 @@ client_cycle(struct screen_ctx *sc, int flags)
client_ptrwarp(newcc);
 }
 
+struct client_ctx *
+client_mrusearch(struct screen_ctx *sc, struct group_ctx *gc) 
+{
+   int again = 1;
+   struct client_ctx *cc;
+
+   if (TAILQ_EMPTY(sc-mruq))
+   return NULL;
+
+   cc = TAILQ_FIRST(sc-mruq);
+   while (again) {
+   again = 0;
+
+   /* Only cycle visible and non-ignored windows. */
+   if ((cc-flags  (CLIENT_HIDDEN|CLIENT_IGNORE))
+cc-group != gc)
+   again = 1;
+   else
+   break;
+   cc = client_mrunext(cc);
+   if (cc == TAILQ_FIRST(sc-mruq))
+   return NULL;
+   }
+   return cc;
+}
+
 static struct client_ctx *
 client_mrunext(struct client_ctx *cc)
 {
diff --git a/group.c b/group.c
index f698cc7..f03e4a3 100644
--- a/group.c
+++ b/group.c
@@ -303,16 +303,22 @@ void
 group_only(struct screen_ctx *sc, int idx)
 {
int  i;
+   struct group_ctx*gc;
+   struct client_ctx   *cc;
 
if (idx  0 || idx = CALMWM_NGROUPS)
err(1, group_only: index out of range (%d), idx);
 
+   gc = sc-groups[idx];
+
for (i = 0; i  CALMWM_NGROUPS; i++) {
if (i == idx)
group_show(sc, sc-groups[i]);
else
group_hide(sc, sc-groups[i]);
}
+   if ((cc = client_mrusearch(sc, gc)) != NULL)
+   client_ptrwarp(cc);
 }
 
 /*
-- 
1.7.6



[cwm patch 1/6] Implement shell-like tab-completion for menus

2012-04-08 Thread Alexander Polakov
window/application menu: tab completes the word.
exec menu: tab completes the word, when at the end
of the word file menu appears.

diff --git a/calmwm.h b/calmwm.h
index 3aaac3e..b365983 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -257,7 +257,7 @@ TAILQ_HEAD(cmd_q, cmd);
 struct menu {
TAILQ_ENTRY(menu)entry;
TAILQ_ENTRY(menu)resultentry;
-#define MENU_MAXENTRY   50
+#define MENU_MAXENTRY   200
char text[MENU_MAXENTRY + 1];
char print[MENU_MAXENTRY + 1];
void*ctx;
@@ -354,6 +354,8 @@ void search_match_exec(struct 
menu_q *, struct menu_q *,
 char *);
 voidsearch_match_text(struct menu_q *, struct menu_q *,
 char *);
+voidsearch_match_path(struct menu_q *, struct menu_q *,
+char *);
 voidsearch_print_client(struct menu *, int);
 
 XineramaScreenInfo *screen_find_xinerama(struct screen_ctx *, int, int);
@@ -410,7 +412,7 @@ void mousefunc_window_raise(struct 
client_ctx *, void *);
 voidmousefunc_window_resize(struct client_ctx *, void *);
 
 struct menu*menu_filter(struct screen_ctx *, struct menu_q *,
-char *, char *, int,
+char *, char *, int, int,
 void (*)(struct menu_q *, struct menu_q *, char *),
 void (*)(struct menu *, int));
 voidmenu_init(struct screen_ctx *);
diff --git a/group.c b/group.c
index 17de904..f698cc7 100644
--- a/group.c
+++ b/group.c
@@ -395,7 +395,7 @@ group_menu(XButtonEvent *e)
if (TAILQ_EMPTY(menuq))
return;
 
-   mi = menu_filter(sc, menuq, NULL, NULL, 0, NULL, NULL);
+   mi = menu_filter(sc, menuq, NULL, NULL, 0, 0, NULL, NULL);
 
if (mi == NULL || mi-ctx == NULL)
goto cleanup;
diff --git a/kbfunc.c b/kbfunc.c
index a044a4c..224b9af 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -157,7 +157,7 @@ kbfunc_client_search(struct client_ctx *cc, union arg *arg)
TAILQ_INSERT_TAIL(menuq, mi, entry);
}
 
-   if ((mi = menu_filter(sc, menuq, window, NULL, 0,
+   if ((mi = menu_filter(sc, menuq, window, NULL, 0, 0,
search_match_client, search_print_client)) != NULL) {
cc = (struct client_ctx *)mi-ctx;
if (cc-flags  CLIENT_HIDDEN)
@@ -192,7 +192,7 @@ kbfunc_menu_search(struct client_ctx *cc, union arg *arg)
TAILQ_INSERT_TAIL(menuq, mi, entry);
}
 
-   if ((mi = menu_filter(sc, menuq, application, NULL, 0,
+   if ((mi = menu_filter(sc, menuq, application, NULL, 0, 0,
search_match_text, NULL)) != NULL)
u_spawn(((struct cmd *)mi-ctx)-image);
 
@@ -303,7 +303,7 @@ kbfunc_exec(struct client_ctx *cc, union arg *arg)
}
xfree(path);
 
-   if ((mi = menu_filter(sc, menuq, label, NULL, 1,
+   if ((mi = menu_filter(sc, menuq, label, NULL, 1, 1,
search_match_exec, NULL)) != NULL) {
if (mi-text[0] == '\0')
goto out;
@@ -383,7 +383,7 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg)
xfree(lbuf);
(void)fclose(fp);
 
-   if ((mi = menu_filter(sc, menuq, ssh, NULL, 1,
+   if ((mi = menu_filter(sc, menuq, ssh, NULL, 1, 0,
search_match_exec, NULL)) != NULL) {
if (mi-text[0] == '\0')
goto out;
@@ -410,7 +410,7 @@ kbfunc_client_label(struct client_ctx *cc, union arg *arg)
TAILQ_INIT(menuq);
 
/* dummy is set, so this will always return */
-   mi = menu_filter(cc-sc, menuq, label, cc-label, 1,
+   mi = menu_filter(cc-sc, menuq, label, cc-label, 1, 0,
search_match_text, NULL);
 
if (!mi-abort) {
diff --git a/menu.c b/menu.c
index 79b283d..c40b8ba 100644
--- a/menu.c
+++ b/menu.c
@@ -37,10 +37,11 @@
 enum ctltype {
CTL_NONE = -1,
CTL_ERASEONE = 0, CTL_WIPE, CTL_UP, CTL_DOWN, CTL_RETURN,
-   CTL_ABORT, CTL_ALL
+   CTL_TAB, CTL_ABORT, CTL_ALL
 };
 
 struct menu_ctx {
+   struct screen_ctx   *sc;
char searchstr[MENU_MAXENTRY + 1];
char dispstr[MENU_MAXENTRY*2 + 1];
char promptstr[MENU_MAXENTRY + 1];
@@ -53,6 +54,7 @@ struct menu_ctx {
int  entry;
int  width;
int  num;
+   int  filecomplete;
int  x;
int  y;
void (*match)(struct menu_q *, struct menu_q *, char *);
@@ -96,7 +98,7 @@ menu_init(struct screen_ctx *sc)
 
 struct menu *
 menu_filter(struct screen_ctx *sc, struct menu_q 

[cwm patch 4/6] Unmaximize window when moving it

2012-04-08 Thread Alexander Polakov
 every window manager around does this, i guess

diff --git a/client.c b/client.c
index 74bb2e2..1daa4c2 100644
--- a/client.c
+++ b/client.c
@@ -438,7 +438,11 @@ client_resize(struct client_ctx *cc)
 void
 client_move(struct client_ctx *cc)
 {
-   XMoveWindow(X_Dpy, cc-win, cc-geom.x, cc-geom.y);
+   int x = cc-geom.x;
+   int y = cc-geom.y;
+   if ((cc-flags  CLIENT_MAXFLAGS) == CLIENT_MAXIMIZED)
+   client_maximize(cc);
+   XMoveWindow(X_Dpy, cc-win, x, y);
xu_configure(cc);
 }
 
-- 
1.7.6



[cwm patch 6/6] Make raise on click work as expected

2012-04-08 Thread Alexander Polakov
 mousebind 1 window_raise

I wonder if it breaks something.

diff --git a/xevents.c b/xevents.c
index ad000f8..33bc185 100644
--- a/xevents.c
+++ b/xevents.c
@@ -261,6 +261,7 @@ xev_handle_buttonpress(XEvent *ee)
return;
 
(*mb-callback)(cc, e);
+   XAllowEvents(X_Dpy, ReplayPointer, CurrentTime);
 }
 
 static void
diff --git a/xutil.c b/xutil.c
index 859cf51..6432be8 100644
--- a/xutil.c
+++ b/xutil.c
@@ -59,7 +59,7 @@ xu_btn_grab(Window win, int mask, u_int btn)
int i;
for (i = 0; i  nitems(ign_mods); i++)
XGrabButton(X_Dpy, btn, (mask | ign_mods[i]), win,
-   False, BUTTONMASK, GrabModeAsync,
+   False, BUTTONMASK, GrabModeSync,
GrabModeSync, None, None);
 }
 
-- 
1.7.6



[cwm patch 5/6] Multibyte characters input for menus

2012-04-08 Thread Alexander Polakov
diff --git a/calmwm.c b/calmwm.c
index 7e0df51..2ebd685 100644
--- a/calmwm.c
+++ b/calmwm.c
@@ -25,6 +25,7 @@
 #include err.h
 #include errno.h
 #include getopt.h
+#include locale.h
 #include signal.h
 #include stdlib.h
 #include string.h
@@ -62,6 +63,9 @@ main(int argc, char **argv)
char*display_name = NULL;
int  ch;
 
+   setlocale(LC_CTYPE, );
+   mbtowc(NULL, NULL, MB_CUR_MAX);
+
while ((ch = getopt(argc, argv, c:d:)) != -1) {
switch (ch) {
case 'c':
diff --git a/menu.c b/menu.c
index c40b8ba..6b77f65 100644
--- a/menu.c
+++ b/menu.c
@@ -70,7 +70,7 @@ static voidmenu_draw(struct screen_ctx *, struct 
menu_ctx *,
 struct menu_q *, struct menu_q *);
 static int  menu_calc_entry(struct screen_ctx *, struct menu_ctx *,
 int, int);
-static int  menu_keycode(KeyCode, u_int, enum ctltype *,
+static int  menu_keycode(XKeyEvent *, enum ctltype *,
  char *);
 
 void
@@ -239,16 +239,22 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct 
menu_q *menuq,
 {
struct menu *mi;
enum ctltype ctl;
-   char chr, *fcp, *sp;
+   char chr[32], *fcp, *sp;
size_t   len;
+   int  clen, i;
+   wchar_t  wc;
 
-   if (menu_keycode(e-xkey.keycode, e-xkey.state, ctl, chr)  0)
+   if (menu_keycode(e-xkey, ctl, chr)  0)
return (NULL);
 
switch (ctl) {
case CTL_ERASEONE:
if ((len = strlen(mc-searchstr))  0) {
-   mc-searchstr[len - 1] = '\0';
+   clen = 1;
+   while (mbtowc(wc, mc-searchstr[len-clen], 
MB_CUR_MAX) == -1)
+   clen++;
+   for (i = 1; i = clen; i++)
+   mc-searchstr[len - i] = '\0';
mc-changed = 1;
}
break;
@@ -332,13 +338,9 @@ filecomplete:
break;
}
 
-   if (chr != '\0') {
-   char str[2];
-
-   str[0] = chr;
-   str[1] = '\0';
+   if (chr[0] != '\0') {
mc-changed = 1;
-   (void)strlcat(mc-searchstr, str, sizeof(mc-searchstr));
+   (void)strlcat(mc-searchstr, chr, sizeof(mc-searchstr));
}
 
mc-noresult = 0;
@@ -524,15 +526,16 @@ menu_calc_entry(struct screen_ctx *sc, struct menu_ctx 
*mc, int x, int y)
 }
 
 static int
-menu_keycode(KeyCode kc, u_int state, enum ctltype *ctl, char *chr)
+menu_keycode(XKeyEvent *ev, enum ctltype *ctl, char *chr)
 {
-   int  ks;
+   KeySym   ks;
+   u_intstate = ev-state;
 
*ctl = CTL_NONE;
-   *chr = '\0';
-
-   ks = XKeycodeToKeysym(X_Dpy, kc, (state  ShiftMask) ? 1 : 0);
+   chr[0] = '\0';
 
+   ks = XKeycodeToKeysym(X_Dpy, ev-keycode, (state  ShiftMask) ? 1 : 0);
+   
/* Look for control characters. */
switch (ks) {
case XK_BackSpace:
@@ -600,14 +603,8 @@ menu_keycode(KeyCode kc, u_int state, enum ctltype *ctl, 
char *chr)
if (*ctl != CTL_NONE)
return (0);
 
-   /*
-* For regular characters, only (part of, actually) Latin 1
-* for now.
-*/
-   if (ks  0x20 || ks  0x07e)
+   if (XLookupString(ev, chr, 32, ks, NULL)  0)
return (-1);
 
-   *chr = (char)ks;
-
return (0);
 }
-- 
1.7.6



[cwm patch 3/6] Better modifier suppression detection

2012-04-08 Thread Alexander Polakov
 The obvious solution: just check for every possible modifier.

diff --git a/calmwm.h b/calmwm.h
index 9ac93b0..2de9578 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -202,7 +202,7 @@ struct screen_ctx {
Window   menuwin;
struct color color[CWM_COLOR_MAX];
GC   gc;
-   int  altpersist;
+   int  cycling;
int  xmax;
int  ymax;
struct gap   gap;
@@ -306,6 +306,7 @@ __dead void  usage(void);
 voidclient_applysizehints(struct client_ctx *);
 struct client_ctx  *client_current(void);
 voidclient_cycle(struct screen_ctx *, int);
+voidclient_cycle_leave(struct screen_ctx *, struct 
client_ctx *);
 voidclient_delete(struct client_ctx *);
 voidclient_draw_border(struct client_ctx *);
 struct client_ctx  *client_find(Window);
diff --git a/client.c b/client.c
index a53ccb0..74bb2e2 100644
--- a/client.c
+++ b/client.c
@@ -228,7 +228,7 @@ client_setactive(struct client_ctx *cc, int fg)
 * If we're in the middle of alt-tabbing, don't change
 * the order please.
 */
-   if (!sc-altpersist)
+   if (!sc-cycling)
client_mtf(cc);
} else
client_leave(cc);
@@ -637,12 +637,23 @@ client_cycle(struct screen_ctx *sc, int flags)
}
}
 
-   /* reset when alt is released. XXX I hate this hack */
-   sc-altpersist = 1;
+   /* reset when modkey is released. XXX I hate this hack */
+   sc-cycling = 1;
client_ptrsave(oldcc);
client_ptrwarp(newcc);
 }
 
+void
+client_cycle_leave(struct screen_ctx *sc, struct client_ctx *cc) 
+{
+   sc-cycling = 0;
+
+   client_mtf(NULL);
+
+   if (cc != NULL)
+   group_sticky_toggle_exit(cc);
+}
+
 struct client_ctx *
 client_mrusearch(struct screen_ctx *sc, struct group_ctx *gc) 
 {
diff --git a/xevents.c b/xevents.c
index ce4378a..ad000f8 100644
--- a/xevents.c
+++ b/xevents.c
@@ -70,6 +70,9 @@ void  (*xev_handlers[LASTEvent])(XEvent *) = {
[MappingNotify] = xev_handle_mappingnotify,
 };
 
+static KeySym modkeys[] = { XK_Alt_L, XK_Alt_R, XK_Super_L, XK_Super_R,
+   XK_Control_L, XK_Control_R };
+
 static void
 xev_handle_maprequest(XEvent *ee)
 {
@@ -314,7 +317,7 @@ xev_handle_keypress(XEvent *ee)
 }
 
 /*
- * This is only used for the alt suppression detection.
+ * This is only used for the modifier suppression detection.
  */
 static void
 xev_handle_keyrelease(XEvent *ee)
@@ -322,26 +325,19 @@ xev_handle_keyrelease(XEvent *ee)
XKeyEvent   *e = ee-xkey;
struct screen_ctx   *sc;
struct client_ctx   *cc;
-   int  keysym;
+   int  i, keysym;
 
sc = screen_fromroot(e-root);
cc = client_current();
 
keysym = XKeycodeToKeysym(X_Dpy, e-keycode, 0);
-   if (keysym != XK_Alt_L  keysym != XK_Alt_R)
-   return;
-
-   sc-altpersist = 0;
-
-   /*
-* XXX - better interface... xevents should not know about
-* how/when to mtf.
-*/
-   client_mtf(NULL);
-
-   if (cc != NULL) {
-   group_sticky_toggle_exit(cc);
-   XUngrabKeyboard(X_Dpy, CurrentTime);
+   for (i = 0; i  sizeof(modkeys)/sizeof(modkeys[0]); i++) {
+   if (keysym == modkeys[i]) {
+   client_cycle_leave(sc, cc);
+   if (cc)
+   XUngrabKeyboard(X_Dpy, CurrentTime);
+   break;
+   }
}
 }
 
-- 
1.7.6



Re: [cwm patch 1/6] Implement shell-like tab-completion for menus

2012-04-08 Thread Alexander Polakov
* Stuart Henderson s...@spacehopper.org [120408 13:42]:
 On 2012/01/20 00:44, Alexander Polakov wrote:
  window/application menu: tab completes the word.
  exec menu: tab completes the word, when at the end
  of the word file menu appears.
 
 I like this quite a lot, but there is a bug in a directory with a
 lot of files, see http://junkpile.org/cwm-filelist.png
 

Here's an updated diff, tested on a directory with 5000 files.

diff --git a/calmwm.h b/calmwm.h
index 3aaac3e..b365983 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -257,7 +257,7 @@ TAILQ_HEAD(cmd_q, cmd);
 struct menu {
TAILQ_ENTRY(menu)entry;
TAILQ_ENTRY(menu)resultentry;
-#define MENU_MAXENTRY   50
+#define MENU_MAXENTRY   200
char text[MENU_MAXENTRY + 1];
char print[MENU_MAXENTRY + 1];
void*ctx;
@@ -354,6 +354,8 @@ void search_match_exec(struct 
menu_q *, struct menu_q *,
 char *);
 voidsearch_match_text(struct menu_q *, struct menu_q *,
 char *);
+voidsearch_match_path(struct menu_q *, struct menu_q *,
+char *);
 voidsearch_print_client(struct menu *, int);
 
 XineramaScreenInfo *screen_find_xinerama(struct screen_ctx *, int, int);
@@ -410,7 +412,7 @@ void mousefunc_window_raise(struct 
client_ctx *, void *);
 voidmousefunc_window_resize(struct client_ctx *, void *);
 
 struct menu*menu_filter(struct screen_ctx *, struct menu_q *,
-char *, char *, int,
+char *, char *, int, int,
 void (*)(struct menu_q *, struct menu_q *, char *),
 void (*)(struct menu *, int));
 voidmenu_init(struct screen_ctx *);
diff --git a/group.c b/group.c
index 17de904..f698cc7 100644
--- a/group.c
+++ b/group.c
@@ -395,7 +395,7 @@ group_menu(XButtonEvent *e)
if (TAILQ_EMPTY(menuq))
return;
 
-   mi = menu_filter(sc, menuq, NULL, NULL, 0, NULL, NULL);
+   mi = menu_filter(sc, menuq, NULL, NULL, 0, 0, NULL, NULL);
 
if (mi == NULL || mi-ctx == NULL)
goto cleanup;
diff --git a/kbfunc.c b/kbfunc.c
index a044a4c..224b9af 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -157,7 +157,7 @@ kbfunc_client_search(struct client_ctx *cc, union arg *arg)
TAILQ_INSERT_TAIL(menuq, mi, entry);
}
 
-   if ((mi = menu_filter(sc, menuq, window, NULL, 0,
+   if ((mi = menu_filter(sc, menuq, window, NULL, 0, 0,
search_match_client, search_print_client)) != NULL) {
cc = (struct client_ctx *)mi-ctx;
if (cc-flags  CLIENT_HIDDEN)
@@ -192,7 +192,7 @@ kbfunc_menu_search(struct client_ctx *cc, union arg *arg)
TAILQ_INSERT_TAIL(menuq, mi, entry);
}
 
-   if ((mi = menu_filter(sc, menuq, application, NULL, 0,
+   if ((mi = menu_filter(sc, menuq, application, NULL, 0, 0,
search_match_text, NULL)) != NULL)
u_spawn(((struct cmd *)mi-ctx)-image);
 
@@ -303,7 +303,7 @@ kbfunc_exec(struct client_ctx *cc, union arg *arg)
}
xfree(path);
 
-   if ((mi = menu_filter(sc, menuq, label, NULL, 1,
+   if ((mi = menu_filter(sc, menuq, label, NULL, 1, 1,
search_match_exec, NULL)) != NULL) {
if (mi-text[0] == '\0')
goto out;
@@ -383,7 +383,7 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg)
xfree(lbuf);
(void)fclose(fp);
 
-   if ((mi = menu_filter(sc, menuq, ssh, NULL, 1,
+   if ((mi = menu_filter(sc, menuq, ssh, NULL, 1, 0,
search_match_exec, NULL)) != NULL) {
if (mi-text[0] == '\0')
goto out;
@@ -410,7 +410,7 @@ kbfunc_client_label(struct client_ctx *cc, union arg *arg)
TAILQ_INIT(menuq);
 
/* dummy is set, so this will always return */
-   mi = menu_filter(cc-sc, menuq, label, cc-label, 1,
+   mi = menu_filter(cc-sc, menuq, label, cc-label, 1, 0,
search_match_text, NULL);
 
if (!mi-abort) {
diff --git a/menu.c b/menu.c
index 79b283d..746bf89 100644
--- a/menu.c
+++ b/menu.c
@@ -37,10 +37,11 @@
 enum ctltype {
CTL_NONE = -1,
CTL_ERASEONE = 0, CTL_WIPE, CTL_UP, CTL_DOWN, CTL_RETURN,
-   CTL_ABORT, CTL_ALL
+   CTL_TAB, CTL_ABORT, CTL_ALL
 };
 
 struct menu_ctx {
+   struct screen_ctx   *sc;
char searchstr[MENU_MAXENTRY + 1];
char dispstr[MENU_MAXENTRY*2 + 1];
char promptstr[MENU_MAXENTRY + 1];
@@ -53,6 +54,7 @@ struct menu_ctx {
int  entry;
int  width;
int  num

Re: [cwm patch 3/6] Better modifier suppression detection

2012-04-08 Thread Alexander Polakov
* Stuart Henderson s...@spacehopper.org [120408 13:43]:
 On 2012/01/20 00:15, Alexander Polakov wrote:
   The obvious solution: just check for every possible modifier.
 
 client.c: In function 'client_cycle':
 client.c:641: error: 'struct screen_ctx' has no member named 'altpersist'

It didn't apply cleanly without 2nd patch. This one should be fine:

Index: calmwm.h
===
RCS file: /cvs/xenocara/app/cwm/calmwm.h,v
retrieving revision 1.142
diff -u -p -u -r1.142 calmwm.h
--- calmwm.h13 Sep 2011 08:41:57 -  1.142
+++ calmwm.h8 Apr 2012 11:31:40 -
@@ -202,7 +202,7 @@ struct screen_ctx {
Window   menuwin;
struct color color[CWM_COLOR_MAX];
GC   gc;
-   int  altpersist;
+   int  cycling;
int  xmax;
int  ymax;
struct gap   gap;
@@ -306,6 +306,7 @@ __dead void  usage(void);
 voidclient_applysizehints(struct client_ctx *);
 struct client_ctx  *client_current(void);
 voidclient_cycle(struct screen_ctx *, int);
+voidclient_cycle_leave(struct screen_ctx *, struct 
client_ctx *);
 voidclient_delete(struct client_ctx *);
 voidclient_draw_border(struct client_ctx *);
 struct client_ctx  *client_find(Window);
Index: client.c
===
RCS file: /cvs/xenocara/app/cwm/client.c,v
retrieving revision 1.91
diff -u -p -u -r1.91 client.c
--- client.c13 Sep 2011 08:41:57 -  1.91
+++ client.c8 Apr 2012 11:31:41 -
@@ -228,7 +228,7 @@ client_setactive(struct client_ctx *cc, 
 * If we're in the middle of alt-tabbing, don't change
 * the order please.
 */
-   if (!sc-altpersist)
+   if (!sc-cycling)
client_mtf(cc);
} else
client_leave(cc);
@@ -637,10 +637,21 @@ client_cycle(struct screen_ctx *sc, int 
}
}
 
-   /* reset when alt is released. XXX I hate this hack */
-   sc-altpersist = 1;
+   /* reset when modkey is released. XXX I hate this hack */
+   sc-cycling = 1;
client_ptrsave(oldcc);
client_ptrwarp(newcc);
+}
+
+void
+client_cycle_leave(struct screen_ctx *sc, struct client_ctx *cc) 
+{
+   sc-cycling = 0;
+
+   client_mtf(NULL);
+   if (cc != NULL)
+   group_sticky_toggle_exit(cc);
+
 }
 
 static struct client_ctx *
Index: xevents.c
===
RCS file: /cvs/xenocara/app/cwm/xevents.c,v
retrieving revision 1.56
diff -u -p -u -r1.56 xevents.c
--- xevents.c   13 Sep 2011 08:41:57 -  1.56
+++ xevents.c   8 Apr 2012 11:31:42 -
@@ -70,6 +70,9 @@ void  (*xev_handlers[LASTEvent])(XEvent 
[MappingNotify] = xev_handle_mappingnotify,
 };
 
+static KeySym modkeys[] = { XK_Alt_L, XK_Alt_R, XK_Super_L, XK_Super_R,
+   XK_Control_L, XK_Control_R };
+
 static void
 xev_handle_maprequest(XEvent *ee)
 {
@@ -314,7 +317,7 @@ xev_handle_keypress(XEvent *ee)
 }
 
 /*
- * This is only used for the alt suppression detection.
+ * This is only used for the modifier suppression detection.
  */
 static void
 xev_handle_keyrelease(XEvent *ee)
@@ -322,26 +325,19 @@ xev_handle_keyrelease(XEvent *ee)
XKeyEvent   *e = ee-xkey;
struct screen_ctx   *sc;
struct client_ctx   *cc;
-   int  keysym;
+   int  i, keysym;
 
sc = screen_fromroot(e-root);
cc = client_current();
 
keysym = XKeycodeToKeysym(X_Dpy, e-keycode, 0);
-   if (keysym != XK_Alt_L  keysym != XK_Alt_R)
-   return;
-
-   sc-altpersist = 0;
-
-   /*
-* XXX - better interface... xevents should not know about
-* how/when to mtf.
-*/
-   client_mtf(NULL);
-
-   if (cc != NULL) {
-   group_sticky_toggle_exit(cc);
-   XUngrabKeyboard(X_Dpy, CurrentTime);
+   for (i = 0; i  sizeof(modkeys)/sizeof(modkeys[0]); i++) {
+   if (keysym == modkeys[i]) {
+   client_cycle_leave(sc, cc);
+   if (cc)
+   XUngrabKeyboard(X_Dpy, CurrentTime);
+   break;
+   }
}
 }
 

-- 
Alexander Polakov | plhk.ru



Re: [cwm patch 1/6] Implement shell-like tab-completion for menus

2012-04-08 Thread Alexander Polakov
* Ted Unangst t...@tedunangst.com [120408 18:06]:
 On Fri, Jan 20, 2012, Alexander Polakov wrote:
 
 I'm not sure how you got your clock so wrong, but I almost missed all
 your mails because they did not show up where I expected them.

My clock is fine, I sent the output of git format-patch to the list
(which proved to be the wrong thing to do) and the dates of the mails
are the dates when patches were committed to my local git tree.

Sorry for the inconvinience.

http://ompldr.org/vZGF2Mw
-- 
Alexander Polakov | plhk.ru



Re: diff: improving msdosfs write speed for large files

2012-04-05 Thread Alexander Polakov
* Mike Belopuhov m...@crypt.org.ru [120404 17:51]:
 i agree that this is a great find.  i don't really like the diff though.
 i see no point in introducing this macro.  what do others think?

Your diff looks better to me.

 Index: msdosfs/denode.h
 ===
 RCS file: /cvs/src/sys/msdosfs/denode.h,v
 retrieving revision 1.23
 diff -u -p -r1.23 denode.h
 --- msdosfs/denode.h  17 Jul 2010 19:27:07 -  1.23
 +++ msdosfs/denode.h  4 Apr 2012 12:20:23 -
 @@ -116,10 +116,11 @@ struct fatcache {
   * cache is probably pretty worthless if a file is opened by multiple
   * processes.
   */
 -#define  FC_SIZE 2   /* number of entries in the cache */
 +#define  FC_SIZE 3   /* number of entries in the cache */
  #define  FC_LASTMAP  0   /* entry the last call to pcbmap() 
 resolved
* to */
  #define  FC_LASTFC   1   /* entry for the last cluster in the 
 file */
 +#define  FC_OLASTFC  2   /* entry for the previous last cluster 
 */
  
  #define  FCE_EMPTY   0x  /* doesn't represent an actual 
 cluster # */
  
 Index: msdosfs/msdosfs_fat.c
 ===
 RCS file: /cvs/src/sys/msdosfs/msdosfs_fat.c,v
 retrieving revision 1.22
 diff -u -p -r1.22 msdosfs_fat.c
 --- msdosfs/msdosfs_fat.c 4 Jul 2011 04:30:41 -   1.22
 +++ msdosfs/msdosfs_fat.c 4 Apr 2012 12:20:26 -
 @@ -952,6 +952,13 @@ extendfile(struct denode *dep, uint32_t 
   return (error);
   }
  
 + /*
 +  * Preserve value for the last cluster before extending the file
 +  * to speed up further lookups.
 +  */
 + fc_setcache(dep, FC_OLASTFC, dep-de_fc[FC_LASTFC].fc_frcn,
 + dep-de_fc[FC_LASTFC].fc_fsrcn);
 +
   while (count  0) {
   /*
* Allocate a new cluster chain and cat onto the end of the

-- 
Alexander Polakov | plhk.ru



diff: improving msdosfs write speed for large files

2012-04-04 Thread Alexander Polakov
This is a diff from NetBSD pr.34583:
http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=34583

Quoting the author:

I noticed that when writing large file (hundreds of megabytes)
to an msdos disk, the writing speed to a file decreases with the
file length.
Since I have some experience with messydos filesystems (I wrote
MSH: for the Amiga) I took a look.
The obvious suspicion with operations that slow down with the
length of a file is an excessive traversal of the FAT cluster
chain. However, there is a cache that caches 2 positions: the
last cluster in the file, and the most recently looked up one.
Debugging info showed however that frequent full traversals were
still made. So, apparently when extending a file and after
updating the end cluster, the previous end is again needed.
Adding a 3rd entry in the cache, which keeps the end position
from just before extending a file.
This has the desired effect of keeping the write speed constant.
(What it is that needs that position I have not been able to
ascertain from the filesystem code; it doesn't seem to make
sense, actually, to read or write clusters before the original
EOF. I was hoping to find the place where the cache is trashed
and rewrite it to get the desired info from it beforehand, so
that the extra cache entry is again unneeded, but alas.)

While there, I changed 0 to NULL for two pointer arguments of
extendfile().

Index: sys/msdosfs/denode.h
===
RCS file: /cvs/src/sys/msdosfs/denode.h,v
retrieving revision 1.23
diff -u -p -u -r1.23 denode.h
--- sys/msdosfs/denode.h17 Jul 2010 19:27:07 -  1.23
+++ sys/msdosfs/denode.h1 Apr 2012 14:27:48 -
@@ -116,10 +116,11 @@ struct fatcache {
  * cache is probably pretty worthless if a file is opened by multiple
  * processes.
  */
-#defineFC_SIZE 2   /* number of entries in the cache */
+#defineFC_SIZE 3   /* number of entries in the cache */
 #defineFC_LASTMAP  0   /* entry the last call to pcbmap() 
resolved
 * to */
 #defineFC_LASTFC   1   /* entry for the last cluster in the 
file */
+#defineFC_NEXTTOLASTFC 2   /* entry for a close to the last 
cluster in the file */
 
 #defineFCE_EMPTY   0x  /* doesn't represent an actual 
cluster # */
 
@@ -130,6 +131,12 @@ struct fatcache {
(dep)-de_fc[slot].fc_frcn = frcn; \
(dep)-de_fc[slot].fc_fsrcn = fsrcn;
 
+#define fc_last_to_nexttolast(dep) \
+   do {  \
+   (dep)-de_fc[FC_NEXTTOLASTFC].fc_frcn = 
(dep)-de_fc[FC_LASTFC].fc_frcn; \
+   (dep)-de_fc[FC_NEXTTOLASTFC].fc_fsrcn = 
(dep)-de_fc[FC_LASTFC].fc_fsrcn; \
+   } while (0)
+
 /*
  * This is the in memory variant of a dos directory entry.  It is usually
  * contained within a vnode.
Index: sys/msdosfs/msdosfs_fat.c
===
RCS file: /cvs/src/sys/msdosfs/msdosfs_fat.c,v
retrieving revision 1.22
diff -u -p -u -r1.22 msdosfs_fat.c
--- sys/msdosfs/msdosfs_fat.c   4 Jul 2011 04:30:41 -   1.22
+++ sys/msdosfs/msdosfs_fat.c   1 Apr 2012 14:27:49 -
@@ -952,6 +952,8 @@ extendfile(struct denode *dep, uint32_t 
return (error);
}
 
+   fc_last_to_nexttolast(dep);
+
while (count  0) {
/*
 * Allocate a new cluster chain and cat onto the end of the
Index: sys/msdosfs/msdosfs_lookup.c
===
RCS file: /cvs/src/sys/msdosfs/msdosfs_lookup.c,v
retrieving revision 1.24
diff -u -p -u -r1.24 msdosfs_lookup.c
--- sys/msdosfs/msdosfs_lookup.c4 Jul 2011 04:30:41 -   1.24
+++ sys/msdosfs/msdosfs_lookup.c1 Apr 2012 14:27:49 -
@@ -620,8 +620,9 @@ createde(struct denode *dep, struct deno
diroffset = ddep-de_fndoffset + sizeof(struct direntry)
- ddep-de_FileSize;
dirclust = de_clcount(pmp, diroffset);
-   if ((error = extendfile(ddep, dirclust, 0, 0, DE_CLEAR)) != 0) {
-   (void)detrunc(ddep, ddep-de_FileSize, 0, NOCRED, NULL);
+   error = extendfile(ddep, dirclust, NULL, NULL, DE_CLEAR);
+   if (error) {
+   (void) detrunc(ddep, ddep-de_FileSize, 0, NOCRED, 
NULL);
return error;
}

tests:

w/o the patch:
 time cp huge.file /mnt/storage/
   4m5.87s real 0m0.04s user 0m17.56s system

w/the patch:
 time cp huge.file /mnt/storage/
   2m22.48s real 0m0.02s user 0m45.30s system

-- 
Alexander Polakov | plhk.ru



Re: diff: improving msdosfs write speed for large files

2012-04-04 Thread Alexander Polakov
* Alexander Hall alexan...@beard.se [120404 16:16]:
 Alexander Polakov polac...@gmail.com wrote:
 tests:
 
 w/o the patch:
  time cp huge.file /mnt/storage/
4m5.87s real 0m0.04s user 0m17.56s system
 
 w/the patch:
  time cp huge.file /mnt/storage/
2m22.48s real 0m0.02s user 0m45.30s system
 
 -- 
 Alexander Polakov | plhk.ru
 
 Just curious; how huge is that file?

$ ls -lah huge.file
 -rw-r--r--  1 estet  users   500M Apr  4 08:41 huge.file

-- 
Alexander Polakov | plhk.ru



Re: cwm: tab-completion

2012-01-22 Thread Alexander Polakov
* Alexander Polakov polac...@gmail.com [120120 01:11]:
 Sometimes I want to type something like xterm -e top in exec menu,
 and feel the need for tab completion.

And now a bigger thing on top of that. One can tab-complete command with
the first menu entry, once ready, just hit tab again and start typing
file path. It uses glob(3), so asterisks are allowed.

I think diff needs more work, posting now to get comments and check if
there's any interest in this.

Index: calmwm.h
===
RCS file: /cvs/xenocara/app/cwm/calmwm.h,v
retrieving revision 1.142
diff -u -p -r1.142 calmwm.h
--- calmwm.h13 Sep 2011 08:41:57 -  1.142
+++ calmwm.h22 Jan 2012 10:26:55 -
@@ -257,7 +257,7 @@ TAILQ_HEAD(cmd_q, cmd);
 struct menu {
TAILQ_ENTRY(menu)entry;
TAILQ_ENTRY(menu)resultentry;
-#define MENU_MAXENTRY   50
+#define MENU_MAXENTRY   200
char text[MENU_MAXENTRY + 1];
char print[MENU_MAXENTRY + 1];
void*ctx;
@@ -354,6 +354,8 @@ void search_match_exec(struct 
menu_q 
 char *);
 voidsearch_match_text(struct menu_q *, struct menu_q *,
 char *);
+voidsearch_match_path(struct menu_q *, struct menu_q *,
+char *);
 voidsearch_print_client(struct menu *, int);
 
 XineramaScreenInfo *screen_find_xinerama(struct screen_ctx *, int, int);
@@ -410,7 +412,7 @@ void mousefunc_window_raise(struct 
cl
 voidmousefunc_window_resize(struct client_ctx *, void *);
 
 struct menu*menu_filter(struct screen_ctx *, struct menu_q *,
-char *, char *, int,
+char *, char *, int, int,
 void (*)(struct menu_q *, struct menu_q *, char *),
 void (*)(struct menu *, int));
 voidmenu_init(struct screen_ctx *);
Index: group.c
===
RCS file: /cvs/xenocara/app/cwm/group.c,v
retrieving revision 1.55
diff -u -p -r1.55 group.c
--- group.c 29 Dec 2011 20:48:38 -  1.55
+++ group.c 22 Jan 2012 10:26:55 -
@@ -395,7 +395,7 @@ group_menu(XButtonEvent *e)
if (TAILQ_EMPTY(menuq))
return;
 
-   mi = menu_filter(sc, menuq, NULL, NULL, 0, NULL, NULL);
+   mi = menu_filter(sc, menuq, NULL, NULL, 0, 0, NULL, NULL);
 
if (mi == NULL || mi-ctx == NULL)
goto cleanup;
Index: kbfunc.c
===
RCS file: /cvs/xenocara/app/cwm/kbfunc.c,v
retrieving revision 1.58
diff -u -p -r1.58 kbfunc.c
--- kbfunc.c29 Aug 2011 09:09:45 -  1.58
+++ kbfunc.c22 Jan 2012 10:26:55 -
@@ -157,7 +157,7 @@ kbfunc_client_search(struct client_ctx *
TAILQ_INSERT_TAIL(menuq, mi, entry);
}
 
-   if ((mi = menu_filter(sc, menuq, window, NULL, 0,
+   if ((mi = menu_filter(sc, menuq, window, NULL, 0, 0,
search_match_client, search_print_client)) != NULL) {
cc = (struct client_ctx *)mi-ctx;
if (cc-flags  CLIENT_HIDDEN)
@@ -192,7 +192,7 @@ kbfunc_menu_search(struct client_ctx *cc
TAILQ_INSERT_TAIL(menuq, mi, entry);
}
 
-   if ((mi = menu_filter(sc, menuq, application, NULL, 0,
+   if ((mi = menu_filter(sc, menuq, application, NULL, 0, 0,
search_match_text, NULL)) != NULL)
u_spawn(((struct cmd *)mi-ctx)-image);
 
@@ -303,7 +303,7 @@ kbfunc_exec(struct client_ctx *cc, union
}
xfree(path);
 
-   if ((mi = menu_filter(sc, menuq, label, NULL, 1,
+   if ((mi = menu_filter(sc, menuq, label, NULL, 1, 1,
search_match_exec, NULL)) != NULL) {
if (mi-text[0] == '\0')
goto out;
@@ -383,7 +383,7 @@ kbfunc_ssh(struct client_ctx *cc, union 
xfree(lbuf);
(void)fclose(fp);
 
-   if ((mi = menu_filter(sc, menuq, ssh, NULL, 1,
+   if ((mi = menu_filter(sc, menuq, ssh, NULL, 1, 0,
search_match_exec, NULL)) != NULL) {
if (mi-text[0] == '\0')
goto out;
@@ -410,7 +410,7 @@ kbfunc_client_label(struct client_ctx *c
TAILQ_INIT(menuq);
 
/* dummy is set, so this will always return */
-   mi = menu_filter(cc-sc, menuq, label, cc-label, 1,
+   mi = menu_filter(cc-sc, menuq, label, cc-label, 1, 0,
search_match_text, NULL);
 
if (!mi-abort) {
Index: menu.c
===
RCS file: /cvs/xenocara/app/cwm/menu.c,v
retrieving revision 1.33
diff -u -p -r1.33 menu.c
--- menu.c  8 Sep 2011 12:00:50

cwm: tab-completion

2012-01-19 Thread Alexander Polakov
Sometimes I want to type something like xterm -e top in exec menu,
and feel the need for tab completion.

Not sure about the FALLTHROUGH thing, though.

Index: menu.c
===
RCS file: /cvs/xenocara/app/cwm/menu.c,v
retrieving revision 1.33
diff -u -p -u -r1.33 menu.c
--- menu.c  8 Sep 2011 12:00:50 -   1.33
+++ menu.c  19 Jan 2012 20:58:45 -
@@ -37,7 +37,7 @@
 enum ctltype {
CTL_NONE = -1,
CTL_ERASEONE = 0, CTL_WIPE, CTL_UP, CTL_DOWN, CTL_RETURN,
-   CTL_ABORT, CTL_ALL
+   CTL_TAB, CTL_ABORT, CTL_ALL
 };
 
 struct menu_ctx {
@@ -254,6 +254,14 @@ menu_handle_key(XEvent *e, struct menu_c
mc-searchstr[0] = '\0';
mc-changed = 1;
break;
+   case CTL_TAB:
+   if ((mi = TAILQ_FIRST(resultq)) != NULL) {
+   (void)strlcpy(mc-searchstr,
+   mi-text, sizeof(mc-searchstr));
+   mc-changed = 1;
+   break;
+   }
+   /* FALLTHROUGH */
case CTL_ALL:
mc-list = !mc-list;
break;
@@ -475,6 +483,9 @@ menu_keycode(KeyCode kc, u_int state, en
break;
case XK_Return:
*ctl = CTL_RETURN;
+   break;
+   case XK_Tab:
+   *ctl = CTL_TAB;
break;
case XK_Up:
*ctl = CTL_UP;

-- 
Alexander Polakov | plhk.ru



Re: Fix cwm cycle

2011-12-31 Thread Alexander Polakov
* Luis Henriques hen...@camandro.org [111230 02:21]:
 Hi,
 
 I have been using for a while a hack to fix cwm windows cycle (the traditional
 Alt-Tab).  The problem is that I modified the default key binding but the
 code actually expects Alt to be the modifier.  The result is that, in some
 situations (e.g., after moving to a new group), the window does not get
 keyboard input until I hit the Alt key.
 
 The code already uses some funny hack to handle this, but this hack does not
 work in my case (I'm using Mod4-Tab).  I'm attaching the patch that seems to
 sort this out, but I am not sure if there are any side effects (any x11 expert
 around?).

We should fix the hack, I guess. I see more than one way to do that.

1) dumb: check for Alt, Ctrl and Super(aka Mod4 aka Win) keys release

diff --git a/calmwm.h b/calmwm.h
index 3aaac3e..d03956b 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -202,7 +202,7 @@ struct screen_ctx {
Window   menuwin;
struct color color[CWM_COLOR_MAX];
GC   gc;
-   int  altpersist;
+   int  cycling;
int  xmax;
int  ymax;
struct gap   gap;
diff --git a/client.c b/client.c
index 428b258..531432d 100644
--- a/client.c
+++ b/client.c
@@ -229,7 +229,7 @@ client_setactive(struct client_ctx *cc, int fg)
 * If we're in the middle of alt-tabbing, don't change
 * the order please.
 */
-   if (!sc-altpersist)
+   if (!sc-cycling)
client_mtf(cc);
} else
client_leave(cc);
@@ -641,7 +641,7 @@ client_cycle(struct screen_ctx *sc, int flags)
}
 
/* reset when alt is released. XXX I hate this hack */
-   sc-altpersist = 1;
+   sc-cycling = 1;
client_ptrsave(oldcc);
client_ptrwarp(newcc);
 }
diff --git a/xevents.c b/xevents.c
index 2a3b49c..42feaa0 100644
--- a/xevents.c
+++ b/xevents.c
@@ -318,7 +318,7 @@ xev_handle_keypress(XEvent *ee)
 }
 
 /*
- * This is only used for the alt suppression detection.
+ * This is only used for the modifier suppression detection.
  */
 static void
 xev_handle_keyrelease(XEvent *ee)
@@ -332,10 +332,12 @@ xev_handle_keyrelease(XEvent *ee)
cc = client_current();
 
keysym = XKeycodeToKeysym(X_Dpy, e-keycode, 0);
-   if (keysym != XK_Alt_L  keysym != XK_Alt_R)
+   if ((keysym != XK_Alt_L  keysym != XK_Alt_R) 
+   (keysym != XK_Super_L  keysym != XK_Super_R) 
+   (keysym != XK_Control_L  keysym != XK_Control_R))
return;
 
-   sc-altpersist = 0;
+   sc-cycling = 0;
 
/*
 * XXX - better interface... xevents should not know about

2) a little bit smarter: we can extract keybinding search code from
handle_keypress(), search for cycle keybinding and check for their
modifier keys only (I can cook a diff by request).

3) something really smart

Or we can kill the idea of most recently used goes first.
 
-- 
Alexander Polakov | plhk.ru



cwm: group_movetogroup() fix

2011-12-28 Thread Alexander Polakov
Check if we're already in group. This fixes a problem with java
application reported by Thomas Jeunet (it sets WM_TRANSIENT_FOR hint
many times on the same window, which leads to group_movetogroup()
being called).

cvs server: Diffing .
Index: group.c
===
RCS file: /cvs/xenocara/app/cwm/group.c,v
retrieving revision 1.54
diff -u -p -r1.54 group.c
--- group.c 12 Oct 2011 15:43:50 -  1.54
+++ group.c 28 Dec 2011 10:42:16 -
@@ -222,11 +222,13 @@ group_movetogroup(struct client_ctx *cc,
err(1, group_movetogroup: index out of range (%d), idx);
 
gc = sc-groups[idx];
+   if (cc-group == gc)
+   return;
if (gc-hidden) {
client_hide(cc);
gc-nhidden++;
}
-   group_add(sc-groups[idx], cc);
+   group_add(gc, cc);
 }
 
 /*

-- 
Alexander Polakov | plhk.ru



cwm: WM_TRANSIENT_FOR hint support

2011-08-31 Thread Alexander Polakov
This diff moves dialogs, toolbars and such to the group of the main
application window.

Index: client.c
===
RCS file: /cvs/xenocara/app/cwm/client.c,v
retrieving revision 1.86
diff -u -p -r1.86 client.c
--- client.c14 Jul 2011 11:39:53 -  1.86
+++ client.c31 Aug 2011 14:13:41 -
@@ -58,9 +58,10 @@ client_find(Window win)
 struct client_ctx *
 client_new(Window win, struct screen_ctx *sc, int mapped)
 {
-   struct client_ctx   *cc;
+   struct client_ctx   *cc, *tc;
XWindowAttributeswattr;
XWMHints*wmhints;
+   Window   trans;
int  state;
 
if (win == None)
@@ -133,6 +134,10 @@ client_new(Window win, struct screen_ctx
 
if (mapped)
group_autogroup(cc);
+
+   if (XGetTransientForHint(X_Dpy, win, trans))
+   if ((tc = client_find(trans))  tc-group)
+   group_movetogroup(cc, tc-group-shortcut - 1);
 
return (cc);
 }
Index: xevents.c
===
RCS file: /cvs/xenocara/app/cwm/xevents.c,v
retrieving revision 1.55
diff -u -p -r1.55 xevents.c
--- xevents.c   22 Aug 2011 16:34:34 -  1.55
+++ xevents.c   31 Aug 2011 14:13:41 -
@@ -181,7 +181,8 @@ xev_handle_propertynotify(XEvent *ee)
 {
XPropertyEvent  *e = ee-xproperty;
struct screen_ctx   *sc;
-   struct client_ctx   *cc;
+   struct client_ctx   *cc, *tc;
+   Window  trans;
 
if ((cc = client_find(e-window)) != NULL) {
switch (e-atom) {
@@ -191,6 +192,10 @@ xev_handle_propertynotify(XEvent *ee)
case XA_WM_NAME:
client_setname(cc);
break;
+   case XA_WM_TRANSIENT_FOR:
+   if (XGetTransientForHint(X_Dpy, e-window, trans))
+   if ((tc = client_find(trans))  tc-group)
+   group_movetogroup(cc, tc-group-shortcut - 1);
default:
/* do nothing */
break;

-- 
Alexander Polakov | plhk.ru



softraid detach routine

2011-07-31 Thread Alexander Polakov
sr_detach() returns garbage if (sc-sc_scsibus == NULL).
Can this happen? I don't know. But it's better to be clear,
isn't it?

Index: softraid.c
===
RCS file: /cvs/src/sys/dev/softraid.c,v
retrieving revision 1.245
diff -u -p -r1.245 softraid.c
--- softraid.c  17 Jul 2011 22:46:48 -  1.245
+++ softraid.c  31 Jul 2011 15:57:24 -
@@ -1682,7 +1682,7 @@ int
 sr_detach(struct device *self, int flags)
 {
struct sr_softc *sc = (void *)self;
-   int rv;
+   int rv = 0;
 
DNPRINTF(SR_D_MISC, %s: sr_detach\n, DEVNAME(sc));
 

-- 
Alexander Polakov | plhk.ru



ksh: dead assignments found by LLVM analyzer

2011-07-30 Thread Alexander Polakov
Title says it all. It found some other bugs, but they're harder to
verify (and some of them don't look right at first look).

diff --git a/c_ksh.c b/c_ksh.c
index e653975..1cdf150 100644
--- a/c_ksh.c
+++ b/c_ksh.c
@@ -534,7 +534,7 @@ c_command(char **wp)
 int
 c_typeset(char **wp)
 {
-   struct block *l = e-loc;
+   struct block *l;
struct tbl *vp, **p;
Tflag fset = 0, fclr = 0;
int thing = 0, func = 0, local = 0;
diff --git a/emacs.c b/emacs.c
index 3b2d083..17145d5 100644
--- a/emacs.c
+++ b/emacs.c
@@ -1021,7 +1021,6 @@ x_redraw(int limit)
x_displen = xx_cols - 2;
}
xlp_valid = false;
-   cp = x_lastcp();
x_zots(xbp);
if (xbp != xbuf || xep  xlp)
limit = xx_cols;
diff --git a/eval.c b/eval.c
index 1918751..303a953 100644
--- a/eval.c
+++ b/eval.c
@@ -709,17 +709,14 @@ varsub(Expand *xp, char *sp, char *word,
/* Check for size of array */
if ((p=strchr(sp,'['))  (p[1]=='*'||p[1]=='@')  p[2]==']') {
int n = 0;
-   int max = 0;
 
vp = global(arrayname(sp));
if (vp-flag  (ISSET|ARRAY))
zero_ok = 1;
for (; vp; vp = vp-u.array)
-   if (vp-flag  ISSET) {
-   max = vp-index + 1;
+   if (vp-flag  ISSET)
n++;
-   }
-   c = n; /* ksh88/ksh93 go for number, not max index */
+   c = n;
} else if (c == '*' || c == '@')
c = e-loc-argc;
else {
diff --git a/io.c b/io.c
index ea2925c..0fb2f41 100644
--- a/io.c
+++ b/io.c
@@ -295,7 +295,7 @@ check_fd(char *name, int mode, const char **emsgp)
 
if (isdigit(name[0])  !name[1]) {
fd = name[0] - '0';
-   if ((fl = fcntl(fd = name[0] - '0', F_GETFL, 0))  0) {
+   if ((fl = fcntl(fd, F_GETFL, 0))  0) {
if (emsgp)
*emsgp = bad file descriptor;
return -1;
diff --git a/var.c b/var.c
index 77d3969..d3a0554 100644
--- a/var.c
+++ b/var.c
@@ -830,7 +830,7 @@ is_wdvarassign(const char *s)
 char **
 makenv(void)
 {
-   struct block *l = e-loc;
+   struct block *l;
XPtrV env;
struct tbl *vp, **vpp;
int i;

-- 
Alexander Polakov | plhk.ru



Re: Synaptics touchpad

2011-07-22 Thread Alexander Polakov
* Alexandr Shadchin alexandr.shadc...@gmail.com [110719 22:52]:
 Hi,
 
 Please test latest patch for support Synaptics touchpad
 (or http://koba.devio.us/distfiles/synaptics.v5.diff)
 Patch for snapshot from 18-Jul-2011 or newer.
 
 It seems everything regression eliminated.

Works fine here:

pms0 at pckbc0 (aux slot)
wsmouse0 at pms0 mux 0
wsmouse1 at pms0 mux 0
pms0: Synaptics touchpad, firmware 7.4
 
-- 
Alexander Polakov | plhk.ru



Re: cwm: menu border + typo

2011-07-14 Thread Alexander Polakov
* Alexander Polakov polac...@gmail.com [110714 15:24]:
 Adds a border around the menu window. I think it looks nicer with
 border.

I have more worthless cwm diffs, like:

- Add cycleingroup,rcycleingroup
  Cycle through clients belonging to the same group as active client.
- Redraw client borders *after* we reload colors.
- Add color group to set border color for each window group
- Put geometry window in the center of the window being resized
- Add color font to set menu font color
- Add color {menufg,menubg} to set menu colors

here: http://plhk.ru/trash/cwm/ 

-- 
Alexander Polakov | plhk.ru



Re: sdn allocation and umass(4)

2011-06-24 Thread Alexander Polakov
* Christopher Zimmermann madro...@zakweb.de [110624 21:24]:
 On 06/24/11 18:46, Joel Sing wrote:
  On Friday 24 June 2011, Benny Lofgren wrote:
  - More consistent sdn unit allocation (perhaps this is achievable
with DUID, I haven't had time to explore that yet)
  
  sd(4) unit allocation will always be inconsistent and unpredicatable 
  - DUIDs will let you avoid this entirely.
 
 
 By the way, is there a way to mount umass(4) devices without looking at
 dmesg for the number of the sdn device?
 

hotplugd(8)

-- 
Alexander Polakov | plhk.ru



misc. ksh diffs

2011-05-30 Thread Alexander Polakov
 */
+#define RMBKSLSH BIT(11)   /* remove backslashes */
 
 #defineHERES   10  /* max  in line */
 
-- 
1.7.5

[PATCH 7/7] ksh/vi: compensate for cursor move on command mode

 * move completion cursor one position right if the
   character is space
 * when we enter command mode, cursor is moved one
   position left, and the space on the end is lost.
   So we are trying to complete ls instead of file
   while having ls  and file.c when having file.c .
---
 vi.c |   15 ++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/vi.c b/vi.c
index 95d192c..0bac6be 100644
--- a/vi.c
+++ b/vi.c
@@ -1956,6 +1956,7 @@ complete_word(int command, int count, int flags)
int match_len;
int is_unique;
int is_command;
+   int pos;
 
/* Undo previous completion */
if (command == 0  expanded == COMPLETE  buf) {
@@ -1974,11 +1975,23 @@ complete_word(int command, int count, int flags)
buf = 0;
}
 
+   /* XXX: hack. When we enter command mode, the cursor is moved
+* one position left. This means that the space at the end is
+* eaten and file completion becomes command completion.
+* (see x_locate_word() for more on this)
+*/
+   pos = es-cursor;
+   if (command) {
+   pos += (isspace(es-cbuf[es-cursor]) ? 1 : 0);
+   if (pos  es-linelen)
+   pos = es-linelen;
+   }
+
/* XCF_FULLPATH for count 'cause the menu printed by print_expansions()
 * was done this way.
 */
nwords = x_cf_glob(XCF_COMMAND_FILE | (count ? XCF_FULLPATH : 0) | 
flags,
-   es-cbuf, es-linelen, es-cursor,
+   es-cbuf, es-linelen, pos,
start, end, words, is_command);
if (nwords == 0) {
vi_error();
-- 
1.7.5

-- 
Alexander Polakov | plhk.ru



cwm: utf-8 diff

2011-05-27 Thread Alexander Polakov
This diff works for me with some fonts (fixed, snap, even verdana),
but doesn't work with terminus (black squares instead of chars).

Index: app/cwm/calmwm.c
===
RCS file: /cvs/xenocara/app/cwm/calmwm.c,v
retrieving revision 1.54
diff -u -p -u -r1.54 calmwm.c
--- app/cwm/calmwm.c11 May 2011 13:53:51 -  1.54
+++ app/cwm/calmwm.c27 May 2011 12:35:51 -
@@ -30,6 +30,7 @@
 #include string.h
 #include stdio.h
 #include unistd.h
+#include locale.h
 
 #include calmwm.h
 
@@ -61,6 +62,8 @@ main(int argc, char **argv)
const char  *conf_file = NULL;
char*display_name = NULL;
int  ch;
+
+   setlocale(LC_CTYPE, );
 
while ((ch = getopt(argc, argv, c:d:)) != -1) {
switch (ch) {
Index: app/cwm/font.c
===
RCS file: /cvs/xenocara/app/cwm/font.c,v
retrieving revision 1.14
diff -u -p -u -r1.14 font.c
--- app/cwm/font.c  11 May 2011 13:53:51 -  1.14
+++ app/cwm/font.c  27 May 2011 12:35:51 -
@@ -66,7 +66,7 @@ font_width(struct screen_ctx *sc, const 
 {
XGlyphInfo   extents;
 
-   XftTextExtents8(X_Dpy, sc-font, (const XftChar8*)text,
+   XftTextExtentsUtf8(X_Dpy, sc-font, (unsigned char*)text,
len, extents);
 
return (extents.xOff);
@@ -77,9 +77,8 @@ font_draw(struct screen_ctx *sc, const c
 Drawable d, int x, int y)
 {
XftDrawChange(sc-xftdraw, d);
-   /* Really needs to be UTF8'd. */
-   XftDrawString8(sc-xftdraw, sc-xftcolor, sc-font, x, y,
-   (const FcChar8*)text, len);
+   XftDrawStringUtf8(sc-xftdraw, sc-xftcolor, sc-font, x, y,
+   (const unsigned char*)text, len);
 }
 
 XftFont *

-- 
Alexander Polakov | plhk.ru



script(1): read input from file

2011-05-19 Thread Alexander Polakov
Here's a diff to make script(1) read input from a file when -i flag is
used (and fallback to stdin when file is out of data).
Can be used to emulate user input for interactive programs.

(here we do tab completion)

[/tmp]% cat test 
ls mutt--- two tabs here
exit
[/tmp]% script -i test  /dev/null
[/tmp]% cat typescript 
Script started on Thu May 19 15:21:42 2011
ls mutt-
exit
[/tmp]% ls mutt-watashi-1000-24241-  
mutt-watashi-1000-24241-672795505315738224 -- tab completion
mutt-watashi-1000-24241-796843985399926878 -- in action 
[/tmp]% ls mutt-watashi-1000-24241-
ls: mutt-watashi-1000-24241-: No such file or directory
[/tmp]% exit

Script done on Thu May 19 15:21:42 2011

The manpage change is not very clean and descriptive, but well..

Index: usr.bin/script/script.1
===
RCS file: /cvs/src/usr.bin/script/script.1,v
retrieving revision 1.13
diff -u -p -u -r1.13 script.1
--- usr.bin/script/script.1 31 May 2007 19:20:15 -  1.13
+++ usr.bin/script/script.1 19 May 2011 11:09:37 -
@@ -38,7 +38,8 @@
 .Nd make typescript of terminal session
 .Sh SYNOPSIS
 .Nm script
-.Op Fl a
+.Op Fl ai
+.Op Ar infile
 .Op Ar file
 .Sh DESCRIPTION
 .Nm
@@ -65,6 +66,12 @@ Append the output to
 or
 .Pa typescript ,
 retaining the prior contents.
+.El
+.Pp
+.Bl -tag -width Ds
+.It Fl i
+Read commands from 
+.Ar infile .
 .El
 .Pp
 The script ends when the forked shell exits (a control-D
Index: usr.bin/script/script.c
===
RCS file: /cvs/src/usr.bin/script/script.c,v
retrieving revision 1.25
diff -u -p -u -r1.25 script.c
--- usr.bin/script/script.c 27 Oct 2009 23:59:43 -  1.25
+++ usr.bin/script/script.c 19 May 2011 11:09:37 -
@@ -104,16 +104,21 @@ main(int argc, char *argv[])
struct winsize win;
char ibuf[BUFSIZ];
ssize_t cc, off;
-   int aflg, ch;
+   int aflg, iflg, ch, ifd;
+   char *ifname;
 
-   aflg = 0;
-   while ((ch = getopt(argc, argv, a)) != -1)
+   aflg = iflg = 0;
+   while ((ch = getopt(argc, argv, ai:)) != -1)
switch(ch) {
case 'a':
aflg = 1;
break;
+   case 'i':
+   iflg = 1;
+   ifname = optarg;
+   break;
default:
-   fprintf(stderr, usage: %s [-a] [file]\n, __progname);
+   fprintf(stderr, usage: %s [-ai] [infile] [outfile]\n, 
__progname);
exit(1);
}
argc -= optind;
@@ -126,6 +131,8 @@ main(int argc, char *argv[])
 
if ((fscript = fopen(fname, aflg ? a : w)) == NULL)
err(1, %s, fname);
+   if (iflg  ((ifd = open(ifname, O_RDONLY)) == -1))
+   err(1, %s, ifname);
 
(void)tcgetattr(STDIN_FILENO, tt);
(void)ioctl(STDIN_FILENO, TIOCGWINSZ, win);
@@ -133,6 +140,8 @@ main(int argc, char *argv[])
err(1, openpty);
 
(void)printf(Script started, output file is %s\n, fname);
+   if (iflg)
+   (void)printf(Input file is %s\n, ifname);
rtt = tt;
cfmakeraw(rtt);
rtt.c_lflag = ~ECHO;
@@ -168,11 +177,16 @@ main(int argc, char *argv[])
while (1) {
if (dead)
break;
-   cc = read(STDIN_FILENO, ibuf, BUFSIZ);
+   cc = read(iflg ? ifd : STDIN_FILENO, ibuf, BUFSIZ);
if (cc == -1  errno == EINTR)
continue;
-   if (cc = 0)
+   if (cc = 0) {
+   if (iflg) {
+   iflg = 0;
+   continue;
+   }
break;
+   }
for (off = 0; off  cc; ) {
ssize_t n = write(master, ibuf + off, cc - off);
if (n == -1  errno != EAGAIN)
@@ -303,7 +317,6 @@ doshell(void)
 void
 fail(void)
 {
-
(void)kill(0, SIGTERM);
done(1);
 }
-- 
Alexander Polakov | plhk.ru



Re: Fan mode management in acpithinkpad(4)

2011-05-13 Thread Alexander Polakov
* Marco Peereboom sl...@peereboom.us [110512 17:59]:
 On Thu, May 12, 2011 at 03:32:56PM +0200, Christopher Zimmermann wrote:
  On 05/12/11 14:37, Vadim Zhukov wrote:
  Hello all.
  
  Here is a patch that allows for me to work on other things. :) Basically,
  it makes OS choose fan mode instead of firmware. Main feature here is
  enabling of disengadged mode when temperature goes critical, picking
  80C as a red line. Now I can fully load CPU on my X201i -
  say, make -j 4 - and it still works instead of being powering off by
  acpitz(4).
  
 
 User space will not be allowed to play.  I don't have a stinkpad so I
 can't test this but I do encourage people to play with this diff and
 report to the list.

My thinkpad is AMD-powered, so 60 degrees is *normal* for it. With this
diff the fan is always running at max speed, generating lots of noise.

-- 
Alexander Polakov | plhk.ru



Re: ksh completion

2011-05-10 Thread Alexander Polakov
* LEVAI Daniel l...@ecentrum.hu [110510 14:33]:
 On Tue, May 10, 2011 at 12:28:06 +0200, LEVAI Daniel wrote:
  On Tue, May 10, 2011 at 08:41:48 +0200, LEVAI Daniel wrote:
   On Mon, May 09, 2011 at 23:48:46 +0400, Alexander Polakov wrote:
* Alexander Polakov polac...@gmail.com [110502 18:19]:
 Do you mean something like this or I got it all wrong again and we
 have to wait another 15 years for someone to dig into this?

That diff was wrong, this one is likely less wrong.
   This is working fine for me.
  
  I've just found a usecase where it fails to complete a filename:
  
  $ touch 'aaa: bbb ccc'
  $ touch 'aaa: bbc ddd'
  $ ls -la aTAB
  $ ls -la aaa:\ bbTAB
  aaa: bbb ccc   aaa: bbc ddd
  $ ls -la aaa:\ bbcTAB
^^^ nothing happens
 Apperantly, adding ':' to ESCAPEDCHARS solves the problem. Do you think
 there is any sideeffect to this?

No, I don't think so. Let's just add it and find out in practice.

Index: bin/ksh/edit.c
===
RCS file: /cvs/src/bin/ksh/edit.c,v
retrieving revision 1.34
diff -u -r1.34 edit.c
--- bin/ksh/edit.c  20 May 2010 01:13:07 -  1.34
+++ bin/ksh/edit.c  10 May 2011 10:48:26 -
@@ -357,20 +357,6 @@
 
toglob = add_glob(str, slen);
 
-   /* remove all escaping backward slashes */
-   escaping = 0;
-   for (i = 0, idx = 0; toglob[i]; i++) {
-   if (toglob[i] == '\\'  !escaping) {
-   escaping = 1;
-   continue;
-   }
-
-   toglob[idx] = toglob[i];
-   idx++;
-   if (escaping) escaping = 0;
-   }
-   toglob[idx] = '\0';
-
/*
 * Convert foo* (toglob) to an array of strings (words)
 */
@@ -378,7 +364,7 @@
s = pushs(SWSTR, ATEMP);
s-start = s-str = toglob;
source = s;
-   if (yylex(ONEWORD) != LWORD) {
+   if (yylex(ONEWORD|RMBKSLSH) != LWORD) {
source = sold;
internal_errorf(0, fileglob: substitute error);
return 0;
@@ -394,6 +380,20 @@
if (nwords == 1) {
struct stat statb;
 
+   /* remove all escaping backward slashes (see below) */
+   escaping = 0;
+   for (i = 0, idx = 0; toglob[i]; i++) {
+   if (toglob[i] == '\\'  !escaping) {
+   escaping = 1;
+   continue;
+   }
+
+   toglob[idx] = toglob[i];
+   idx++;
+   if (escaping) escaping = 0;
+   }
+   toglob[idx] = '\0';
+
/* Check if globbing failed (returned glob pattern),
 * but be careful (E.g. toglob == ab* when the file
 * ab* exists is not an error).
@@ -821,7 +821,7 @@
int rval = 0;
 
for (add = 0, wlen = len; wlen - add  0; add++) {
-   if (strchr(\#$'()*;=?[\\]`{|}, s[add]) ||
+   if (strchr(ESCAPEDCHARS, s[add]) ||
strchr(ifs, s[add])) {
if (putbuf_func(s, add) != 0) {
rval = -1;
Index: bin/ksh/lex.c
===
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.45
diff -u -r1.45 lex.c
--- bin/ksh/lex.c   9 Mar 2011 09:30:39 -   1.45
+++ bin/ksh/lex.c   10 May 2011 10:48:26 -
@@ -299,6 +299,10 @@
}
/* FALLTHROUGH */
default:
+   if ((cf  RMBKSLSH)  strchr(  
ESCAPEDCHARS, c)) {
+   *wp++ = QCHAR, *wp++ = c;
+   break;
+   }
Xcheck(ws, wp);
if (c) { /* trailing \ is lost */
*wp++ = CHAR, *wp++ = '\\';
Index: bin/ksh/lex.h
===
RCS file: /cvs/src/bin/ksh/lex.h,v
retrieving revision 1.11
diff -u -r1.11 lex.h
--- bin/ksh/lex.h   29 May 2006 18:22:24 -  1.11
+++ bin/ksh/lex.h   10 May 2011 10:48:26 -
@@ -113,6 +113,7 @@
 #define CMDWORD BIT(8) /* parsing simple command (alias related) */
 #define HEREDELIM BIT(9)   /* parsing ,- delimiter */
 #define HEREDOC BIT(10)/* parsing heredoc */
+#define RMBKSLSH BIT(11)   /* remove backslashes */
 
 #defineHERES   10  /* max  in line */
 
Index: bin/ksh/sh.h
===
RCS file: /cvs/src/bin/ksh/sh.h,v
retrieving revision 1.30
diff -u -r1.30 sh.h
--- bin/ksh/sh.h4 Jan 2010 18:07:11 -

Re: ksh completion

2011-05-09 Thread Alexander Polakov
* Alexander Polakov polac...@gmail.com [110502 18:19]:
 Do you mean something like this or I got it all wrong again and we
 have to wait another 15 years for someone to dig into this?

That diff was wrong, this one is likely less wrong.

Index: bin/ksh/edit.c
===
RCS file: /cvs/src/bin/ksh/edit.c,v
retrieving revision 1.34
diff -u -r1.34 edit.c
--- bin/ksh/edit.c  20 May 2010 01:13:07 -  1.34
+++ bin/ksh/edit.c  9 May 2011 19:44:06 -
@@ -357,20 +357,6 @@
 
toglob = add_glob(str, slen);
 
-   /* remove all escaping backward slashes */
-   escaping = 0;
-   for (i = 0, idx = 0; toglob[i]; i++) {
-   if (toglob[i] == '\\'  !escaping) {
-   escaping = 1;
-   continue;
-   }
-
-   toglob[idx] = toglob[i];
-   idx++;
-   if (escaping) escaping = 0;
-   }
-   toglob[idx] = '\0';
-
/*
 * Convert foo* (toglob) to an array of strings (words)
 */
@@ -378,7 +364,7 @@
s = pushs(SWSTR, ATEMP);
s-start = s-str = toglob;
source = s;
-   if (yylex(ONEWORD) != LWORD) {
+   if (yylex(ONEWORD|RMBKSLSH) != LWORD) {
source = sold;
internal_errorf(0, fileglob: substitute error);
return 0;
@@ -394,6 +380,20 @@
if (nwords == 1) {
struct stat statb;
 
+   /* remove all escaping backward slashes (see below) */
+   escaping = 0;
+   for (i = 0, idx = 0; toglob[i]; i++) {
+   if (toglob[i] == '\\'  !escaping) {
+   escaping = 1;
+   continue;
+   }
+
+   toglob[idx] = toglob[i];
+   idx++;
+   if (escaping) escaping = 0;
+   }
+   toglob[idx] = '\0';
+
/* Check if globbing failed (returned glob pattern),
 * but be careful (E.g. toglob == ab* when the file
 * ab* exists is not an error).
@@ -821,7 +821,7 @@
int rval = 0;
 
for (add = 0, wlen = len; wlen - add  0; add++) {
-   if (strchr(\#$'()*;=?[\\]`{|}, s[add]) ||
+   if (strchr(ESCAPEDCHARS, s[add]) ||
strchr(ifs, s[add])) {
if (putbuf_func(s, add) != 0) {
rval = -1;
Index: bin/ksh/lex.c
===
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.45
diff -u -r1.45 lex.c
--- bin/ksh/lex.c   9 Mar 2011 09:30:39 -   1.45
+++ bin/ksh/lex.c   9 May 2011 19:44:07 -
@@ -299,6 +299,10 @@
}
/* FALLTHROUGH */
default:
+   if ((cf  RMBKSLSH)  strchr(  
ESCAPEDCHARS, c)) {
+   *wp++ = QCHAR, *wp++ = c;
+   break;
+   }
Xcheck(ws, wp);
if (c) { /* trailing \ is lost */
*wp++ = CHAR, *wp++ = '\\';
Index: bin/ksh/lex.h
===
RCS file: /cvs/src/bin/ksh/lex.h,v
retrieving revision 1.11
diff -u -r1.11 lex.h
--- bin/ksh/lex.h   29 May 2006 18:22:24 -  1.11
+++ bin/ksh/lex.h   9 May 2011 19:44:07 -
@@ -113,6 +113,7 @@
 #define CMDWORD BIT(8) /* parsing simple command (alias related) */
 #define HEREDELIM BIT(9)   /* parsing ,- delimiter */
 #define HEREDOC BIT(10)/* parsing heredoc */
+#define RMBKSLSH BIT(11)   /* remove backslashes */
 
 #defineHERES   10  /* max  in line */
 
Index: bin/ksh/sh.h
===
RCS file: /cvs/src/bin/ksh/sh.h,v
retrieving revision 1.30
diff -u -r1.30 sh.h
--- bin/ksh/sh.h4 Jan 2010 18:07:11 -   1.30
+++ bin/ksh/sh.h9 May 2011 19:44:07 -
@@ -398,6 +398,9 @@
 #define OBRACE '{'
 #define CBRACE '}'
 
+/* Characters to be escaped */
+#define ESCAPEDCHARS \#$'()*;=?[\\]`{|}
+
 /* Determine the location of the system (common) profile */
 #define KSH_SYSTEM_PROFILE /etc/profile
 

-- 
Alexander Polakov | plhk.ru



Re: ksh completion

2011-05-02 Thread Alexander Polakov
* Martynas Venckus marty...@venck.us [110410 05:17]:
  hi,
 
  (this is a re-post)
 
  make tab completion work for '=', '`', '[', ':', and '$' - pulled from
  mksh by Alexander Polakov (also posted to tech recently).
 
  closes pr 6006 too.
 
  comments/ok?
 
 The diff is a workaround and even wrong.  Ksh lexical analyzer
 itself has the ability to deal with escapes properly (see yylex).
 
 I believe we shouldn't remove backward slashes before passing it
 for analysis, this would fix all cases, including:
 
   $ touch aabbcc aa\*cc
   $ echo aa\*cctab
   aa*cc   aabbcc
   $ echo aa\*cc
   aa*cc


Do you mean something like this or I got it all wrong again and we
have to wait another 15 years for someone to dig into this?

Index: bin/ksh/edit.c
===
RCS file: /cvs/src/bin/ksh/edit.c,v
retrieving revision 1.34
diff -u -r1.34 edit.c
--- bin/ksh/edit.c  20 May 2010 01:13:07 -  1.34
+++ bin/ksh/edit.c  2 May 2011 14:10:47 -
@@ -357,20 +357,6 @@
 
toglob = add_glob(str, slen);
 
-   /* remove all escaping backward slashes */
-   escaping = 0;
-   for (i = 0, idx = 0; toglob[i]; i++) {
-   if (toglob[i] == '\\'  !escaping) {
-   escaping = 1;
-   continue;
-   }
-
-   toglob[idx] = toglob[i];
-   idx++;
-   if (escaping) escaping = 0;
-   }
-   toglob[idx] = '\0';
-
/*
 * Convert foo* (toglob) to an array of strings (words)
 */
@@ -393,6 +379,20 @@
;
if (nwords == 1) {
struct stat statb;
+
+   /* remove all escaping backward slashes (see below) */
+   escaping = 0;
+   for (i = 0, idx = 0; toglob[i]; i++) {
+   if (toglob[i] == '\\'  !escaping) {
+   escaping = 1;
+   continue;
+   }
+
+   toglob[idx] = toglob[i];
+   idx++;
+   if (escaping) escaping = 0;
+   }
+   toglob[idx] = '\0';
 
/* Check if globbing failed (returned glob pattern),
 * but be careful (E.g. toglob == ab* when the file
Index: bin/ksh/lex.c
===
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.45
diff -u -r1.45 lex.c
--- bin/ksh/lex.c   9 Mar 2011 09:30:39 -   1.45
+++ bin/ksh/lex.c   2 May 2011 14:10:47 -
@@ -287,24 +287,15 @@
switch (c) {
case '\\':
c = getsc();
-   switch (c) {
-   case '\\':
-   case '$': case '`':
+   if ((c == ''  ((cf  HEREDOC) == 0)) ||
+   strchr( 
\#$'()*;=?[\\]`{|}, c)) {
*wp++ = QCHAR, *wp++ = c;
break;
-   case '':
-   if ((cf  HEREDOC) == 0) {
-   *wp++ = QCHAR, *wp++ = c;
-   break;
-   }
-   /* FALLTHROUGH */
-   default:
-   Xcheck(ws, wp);
-   if (c) { /* trailing \ is lost */
-   *wp++ = CHAR, *wp++ = '\\';
-   *wp++ = CHAR, *wp++ = c;
-   }
-   break;
+   }
+   Xcheck(ws, wp);
+   if (c) { /* trailing \ is lost */
+   *wp++ = CHAR, *wp++ = '\\';
+   *wp++ = CHAR, *wp++ = c;
}
break;
case '$':

-- 
Alexander Polakov | plhk.ru



Re: ksh completion

2011-03-24 Thread Alexander Polakov
* Alexander Polakov polac...@gmail.com [110315 23:26]:
 * Federico G. Schwindt fg...@lodoss.net [110315 17:38]:
   I think I'm slightly confused as to you'd like fixed - do you mean that
   one shouldn't need to escape a '[' if it's the first character? (note
   that /bin/[ exists).  Else, can you clarify a bit more?  Thanks!
  
correct, shouldn't need to escape a '[' if it's teh first character.
i do know of [, but command and file completion are two different things. 
   see
  bash too.
 
 I don't want to be defensive, but hey, how is bash relevant? [ is treated as
 a globbing character, you know. Is it first character or not, ksh doesn't 
 care,
 it just tries to expand it.
 
 Oh well, you can try expanding it and then - if it failed - escape it and
 try again, like in the patch below. Bear in mind I didn't give it much 
 thought, because I have a feeling it's not a good idea.

And just for the archives, a patch that really works as advertised
(and using it for some time I feel like it *is* a good idea).

Index: bin/ksh/edit.c
===
RCS file: /cvs/src/bin/ksh/edit.c,v
retrieving revision 1.34
diff -u -r1.34 edit.c
--- bin/ksh/edit.c  20 May 2010 01:13:07 -  1.34
+++ bin/ksh/edit.c  21 Mar 2011 13:38:04 -
@@ -18,13 +18,14 @@
 #include libgen.h
 #include sys/stat.h
 
+#define ESCAPEDCHARS \#$'()*;=?[\\`{|}
 
 static void x_sigwinch(int);
 static volatile sig_atomic_t got_sigwinch;
 static void check_sigwinch(void);
 
-static int x_file_glob(int, const char *, int, char ***);
-static int x_command_glob(int, const char *, int, char ***);
+static int x_file_glob(int, const char *, int, char ***, int);
+static int x_command_glob(int, const char *, int, char ***, int);
 static int x_locate_word(const char *, int, int, int *, int *);
 
 
@@ -344,10 +345,11 @@
  * - returns number of matching strings
  */
 static int
-x_file_glob(int flags, const char *str, int slen, char ***wordsp)
+x_file_glob(int flags, const char *str, int slen, char ***wordsp, int 
canrecurse)
 {
char *toglob;
char **words;
+   char *estr;
int nwords, i, idx, escaping;
XPtrV w;
struct source *s, *sold;
@@ -365,6 +367,11 @@
continue;
}
 
+   /* specially escape escaped [ or $ or ` for globbing */
+   if (escaping  (toglob[i] == '[' ||
+   toglob[i] == '$' || toglob[i] == '`'))
+   toglob[idx++] = QCHAR;
+
toglob[idx] = toglob[i];
idx++;
if (escaping) escaping = 0;
@@ -378,7 +385,7 @@
s = pushs(SWSTR, ATEMP);
s-start = s-str = toglob;
source = s;
-   if (yylex(ONEWORD) != LWORD) {
+   if (yylex(ONEWORD|LQCHAR) != LWORD) {
source = sold;
internal_errorf(0, fileglob: substitute error);
return 0;
@@ -411,6 +418,21 @@
}
afree(toglob, ATEMP);
 
+   /* Globbing failed, do escaping and try again. */
+   if (!nwords  !words  canrecurse) {
+   estr = alloc(2 * slen + 1, ATEMP);
+   idx = 0;
+   for(i = 0; i  slen; i++) {
+   if (strchr(ESCAPEDCHARS, str[i]))
+   estr[idx++] = '\\';
+   estr[idx++] = str[i];
+   }
+   estr[idx] = '\0';
+   nwords = x_file_glob(flags, estr, idx, wordsp, !canrecurse);
+   afree(estr, ATEMP);
+   return nwords;
+   }
+
if (nwords) {
*wordsp = words;
} else if (words) {
@@ -443,7 +465,7 @@
 }
 
 static int
-x_command_glob(int flags, const char *str, int slen, char ***wordsp)
+x_command_glob(int flags, const char *str, int slen, char ***wordsp, int 
canrecurse)
 {
char *toglob;
char *pat;
@@ -607,7 +629,7 @@
return 0;
 
nwords = (is_command ? x_command_glob : x_file_glob)(flags,
-   buf + *startp, len, words);
+   buf + *startp, len, words, 1);
if (nwords == 0) {
*wordsp = (char **) 0;
return 0;
@@ -821,7 +843,7 @@
int rval = 0;
 
for (add = 0, wlen = len; wlen - add  0; add++) {
-   if (strchr(\#$'()*;=?[\\]`{|}, s[add]) ||
+   if (strchr(ESCAPEDCHARS, s[add]) ||
strchr(ifs, s[add])) {
if (putbuf_func(s, add) != 0) {
rval = -1;
Index: bin/ksh/lex.c
===
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.45
diff -u -r1.45 lex.c
--- bin/ksh/lex.c   9 Mar 2011 09:30:39 -   1.45
+++ bin/ksh/lex.c   21 Mar 2011 13:38:04 -
@@ -411,6 +411,13

Re: ksh completion

2011-03-15 Thread Alexander Polakov
* Federico G. Schwindt fg...@lodoss.net [110315 17:38]:
  I think I'm slightly confused as to you'd like fixed - do you mean that
  one shouldn't need to escape a '[' if it's the first character? (note
  that /bin/[ exists).  Else, can you clarify a bit more?  Thanks!
 
   correct, shouldn't need to escape a '[' if it's teh first character.
   i do know of [, but command and file completion are two different things.  
 see
 bash too.

I don't want to be defensive, but hey, how is bash relevant? [ is treated as
a globbing character, you know. Is it first character or not, ksh doesn't care,
it just tries to expand it.

Oh well, you can try expanding it and then - if it failed - escape it and
try again, like in the patch below. Bear in mind I didn't give it much 
thought, because I have a feeling it's not a good idea.

diff --git a/edit.c b/edit.c
index 4cff25b..eee8a5d 100644
--- a/edit.c
+++ b/edit.c
@@ -18,6 +18,7 @@
 #include libgen.h
 #include sys/stat.h
 
+#define ESCAPEDCHARS \#$'()*;=?[\\`{|}
 
 static void x_sigwinch(int);
 static volatile sig_atomic_t got_sigwinch;
@@ -348,6 +349,7 @@ x_file_glob(int flags, const char *str, int slen, char 
***wordsp)
 {
char *toglob;
char **words;
+   char *estr;
int nwords, i, idx, escaping;
XPtrV w;
struct source *s, *sold;
@@ -416,6 +418,21 @@ x_file_glob(int flags, const char *str, int slen, char 
***wordsp)
}
afree(toglob, ATEMP);
 
+   /* Globbing failed, do escaping and try again. */
+   if (!nwords  !words) {
+   estr = alloc(2 * slen + 1, ATEMP);
+   idx = 0;
+   for(i = 0; i  slen; i++) {
+   if (strchr(ESCAPEDCHARS, str[i]))
+   estr[idx++] = '\\';
+   estr[idx++] = str[i];
+   }
+   estr[idx] = '\0';
+   nwords = x_file_glob(flags, estr, idx, wordsp);
+   afree(estr, ATEMP);
+   return nwords;
+   }
+
if (nwords) {
*wordsp = words;
} else if (words) {
@@ -826,7 +843,7 @@ x_escape(const char *s, size_t len, int (*putbuf_func) 
(const char *, size_t))
int rval = 0;
 
for (add = 0, wlen = len; wlen - add  0; add++) {
-   if (strchr(\#$'()*;=?[\\`{|}, s[add]) ||
+   if (strchr(ESCAPEDCHARS, s[add]) ||
strchr(ifs, s[add])) {
if (putbuf_func(s, add) != 0) {
rval = -1;

-- 
Alexander Polakov | plhk.ru



thinkpad mute mic key

2011-03-13 Thread Alexander Polakov
 @@
 
 #include machine/apmvar.h
 
+#include audio.h
+#include wskbd.h
+
 #defineTHINKPAD_HKEY_VERSION   0x0100
 
 #defineTHINKPAD_CMOS_VOLUME_DOWN   0x00
@@ -59,6 +63,7 @@
 #defineTHINKPAD_BUTTON_VOLUME_DOWN 0x1016
 #defineTHINKPAD_BUTTON_VOLUME_MUTE 0x1017
 #defineTHINKPAD_BUTTON_THINKVANTAGE0x1018
+#defineTHINKPAD_BUTTON_MICROPHONE_MUTE 0x101b
 #defineTHINKPAD_BUTTON_FN_F11  0x100b
 #defineTHINKPAD_BUTTON_HIBERNATE   0x100c
 #defineTHINKPAD_LID_OPEN   0x5001
@@ -106,6 +111,10 @@
 voidthinkpad_sensor_attach(struct acpithinkpad_softc *sc);
 voidthinkpad_sensor_refresh(void *);
 
+#if NAUDIO  0  NWSKBD  0
+extern int wskbd_set_mixervolume(long dir, int out);
+#endif
+
 struct cfattach acpithinkpad_ca = {
sizeof(struct acpithinkpad_softc), thinkpad_match, thinkpad_attach
 };
@@ -311,6 +320,13 @@
break;
case THINKPAD_BUTTON_VOLUME_UP:
thinkpad_volume_up(sc);
+   handled = 1;
+   break;
+   case THINKPAD_BUTTON_MICROPHONE_MUTE:
+#if NAUDIO  0  NWSKBD  0
+   workq_add_task(NULL, 0, (workq_fn)wskbd_set_mixervolume,
+   (void *)(long)0, (void *)(int)0);
+#endif
handled = 1;
break;
case THINKPAD_BUTTON_THINKVANTAGE:
Index: sys/dev/wscons/wskbd.c
===
RCS file: /cvs/src/sys/dev/wscons/wskbd.c,v
retrieving revision 1.64
diff -u -r1.64 wskbd.c
--- sys/dev/wscons/wskbd.c  20 Nov 2010 20:52:11 -  1.64
+++ sys/dev/wscons/wskbd.c  13 Mar 2011 19:10:19 -
@@ -299,7 +299,7 @@
 void   wskbd_update_layout(struct wskbd_internal *, kbd_t);
 
 #if NAUDIO  0
-extern int wskbd_set_mixervolume(long dir);
+extern int wskbd_set_mixervolume(long dir, int out);
 #endif
 
 void
@@ -1650,15 +1650,15 @@
 #if NAUDIO  0
case KS_AudioMute:
workq_add_task(NULL, 0, (workq_fn)wskbd_set_mixervolume,
-   (void *)(long)0, NULL);
+   (void *)(long)0, (void *)(int)1);
break;
case KS_AudioLower:
workq_add_task(NULL, 0, (workq_fn)wskbd_set_mixervolume,
-   (void *)(long)-1, NULL);
+   (void *)(long)-1, (void*)(int)1);
break;
case KS_AudioRaise:
workq_add_task(NULL, 0, (workq_fn)wskbd_set_mixervolume,
-   (void *)(long)1, NULL);
+   (void *)(long)1, (void*)(int)1);
return (0);
 #endif
default:
-- 
Alexander Polakov | plhk.ru



ksh completion for [, :, $

2011-02-04 Thread Alexander Polakov
Hi there,

I sent this diff to bugs@ some time ago but haven't got any replies.
Probably tech@ is a better place for it.

The problem is known as bz#6006/user.

The fix is taken from mksh (rev.1.4 for [ and rev.1.184 for others).
It adds quoting character (QCHAR) when [, $, ` are prepended by \ to make
them be interpreted literally (like if they were enclosed in ' ').
It also adds : to the list of escaped characters.
Original commit message:

revision 1.184
date: 2009-10-30 00:57:36 +;  author: tg;  state: Exp;  lines: +10 -8;  
commitid: 1004AEA39BD3F10ECFA;
make tab completing filenames with ':' '=' '$' '`' work as well as
others (colon and equals sign need to be simply escaped, while dollar
sign and accent gravis need double escaping like opening square brak-
ket did back then); add = to C_QUOTE to simplify (doesn't break any-
thing) and sort these strings asciibetically while here


Index: bin/ksh/edit.c
===
RCS file: /cvs/src/bin/ksh/edit.c,v
retrieving revision 1.34
diff -u -r1.34 edit.c
--- bin/ksh/edit.c  20 May 2010 01:13:07 -  1.34
+++ bin/ksh/edit.c  4 Feb 2011 17:58:48 -
@@ -365,6 +365,11 @@
continue;
}
 
+   /* specially escape escaped [ or $ or ` for globbing */
+   if (escaping  (toglob[i] == '[' ||
+   toglob[i] == '$' || toglob[i] == '`'))
+   toglob[idx++] = QCHAR;
+
toglob[idx] = toglob[i];
idx++;
if (escaping) escaping = 0;
@@ -378,7 +383,7 @@
s = pushs(SWSTR, ATEMP);
s-start = s-str = toglob;
source = s;
-   if (yylex(ONEWORD) != LWORD) {
+   if (yylex(ONEWORD|LQCHAR) != LWORD) {
source = sold;
internal_errorf(0, fileglob: substitute error);
return 0;
@@ -821,7 +826,7 @@
int rval = 0;
 
for (add = 0, wlen = len; wlen - add  0; add++) {
-   if (strchr(\#$'()*;=?[\\]`{|}, s[add]) ||
+   if (strchr(\#$'()*:;=?[\\]`{|}, s[add]) ||
strchr(ifs, s[add])) {
if (putbuf_func(s, add) != 0) {
rval = -1;
Index: bin/ksh/lex.c
===
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.44
diff -u -r1.44 lex.c
--- bin/ksh/lex.c   3 Jul 2008 17:52:08 -   1.44
+++ bin/ksh/lex.c   4 Feb 2011 17:58:48 -
@@ -411,6 +411,13 @@
}
}
break;
+   case QCHAR:
+   if (cf  LQCHAR) {
+   *wp++ = QCHAR;
+   *wp++ = getsc();
+   break;
+   }
+   /* fallthrough */
default:
*wp++ = CHAR, *wp++ = c;
}
Index: bin/ksh/lex.h
===
RCS file: /cvs/src/bin/ksh/lex.h,v
retrieving revision 1.11
diff -u -r1.11 lex.h
--- bin/ksh/lex.h   29 May 2006 18:22:24 -  1.11
+++ bin/ksh/lex.h   4 Feb 2011 17:58:48 -
@@ -113,6 +113,7 @@
 #define CMDWORD BIT(8) /* parsing simple command (alias related) */
 #define HEREDELIM BIT(9)   /* parsing ,- delimiter */
 #define HEREDOC BIT(10)/* parsing heredoc */
+#define LQCHAR BIT(11) /* source string contains QCHAR */
 
 #defineHERES   10  /* max  in line */
 

-- 
Alexander Polakov | plhk.ru



less(1) typo

2011-02-03 Thread Alexander Polakov
There's no such thing like LC_TYPE, LC_CTYPE is actually checked
in charset.c.


Index: less.1
===
RCS file: /cvs/src/usr.bin/less/less.1,v
retrieving revision 1.20
diff -u -r1.20 less.1
--- less.1  28 Oct 2010 21:32:54 -  1.20
+++ less.1  3 Feb 2011 18:52:18 -
@@ -1297,7 +1297,7 @@
 .Pp
 If neither LESSCHARSET nor LESSCHARDEF is set,
 but the string UTF-8 is found in the
-.Ev LC_ALL , LC_TYPE
+.Ev LC_ALL , LC_CTYPE
 or
 .Ev LANG
 environment variables, then the default character set is utf-8.
-- 
Alexander Polakov | plhk.ru



Re: ls(1) multibyte support

2011-01-06 Thread Alexander Polakov
* Alexander Polakov polac...@gmail.com [110105 17:20]:
 Hi,
 
 here's an updated version.
 
 1) en_US.UTF-8.src updates from FreeBSD
 2) wcwidth() changed to use the same code as iswprint()
* maybe just use iswprint() itself?
 3) _RUNETYPE_SW0 changed to be !0 (and match FreeBSD). 0 value is used in
mklocale to perform additional checks required for MAPLOWER and
MAPUPPER, but not SWIDTHx.

  4) _RUNETYPE_SWM changed to make (r_RUNETYPE_SWM) == _RUNETYPE_SW0
  work


Index: lib/libc/locale/iswctype.c
===
RCS file: /OpenBSD/src/lib/libc/locale/iswctype.c,v
retrieving revision 1.1
diff -u -r1.1 iswctype.c
--- lib/libc/locale/iswctype.c  7 Aug 2005 10:16:23 -   1.1
+++ lib/libc/locale/iswctype.c  6 Jan 2011 16:24:20 -
@@ -170,7 +170,9 @@
 int
 wcwidth(wchar_t c)
 {
-return (((unsigned)__runetype_w(c)  _CTYPE_SWM)  _CTYPE_SWS);
+   if (__isctype_w((c), _CTYPE_R))
+   return (((unsigned)__runetype_w(c)  _CTYPE_SWM)  _CTYPE_SWS);
+   return -1;
 }
 
 wctrans_t
Index: lib/libc/locale/runetype.h
===
RCS file: /OpenBSD/src/lib/libc/locale/runetype.h,v
retrieving revision 1.5
diff -u -r1.5 runetype.h
--- lib/libc/locale/runetype.h  8 Oct 2007 08:17:15 -   1.5
+++ lib/libc/locale/runetype.h  6 Jan 2011 16:24:20 -
@@ -69,9 +69,9 @@
 #define_RUNETYPE_I 0x0008U /* Ideogram */
 #define_RUNETYPE_T 0x0010U /* Special */
 #define_RUNETYPE_Q 0x0020U /* Phonogram */
-#define_RUNETYPE_SWM   0xc000U/* Mask to get screen width data */
+#define_RUNETYPE_SWM   0xe000U /* Mask to get screen width 
data */
 #define_RUNETYPE_SWS   30  /* Bits to shift to get width */
-#define_RUNETYPE_SW0   0xU /* 0 width character */
+#define_RUNETYPE_SW0   0x2000U /* 0 width character */
 #define_RUNETYPE_SW1   0x4000U /* 1 width character */
 #define_RUNETYPE_SW2   0x8000U /* 2 width character */
 #define_RUNETYPE_SW3   0xc000U /* 3 width character */
Index: share/locale/ctype/en_US.UTF-8.src
===
RCS file: /OpenBSD/src/share/locale/ctype/en_US.UTF-8.src,v
retrieving revision 1.1
diff -u -r1.1 en_US.UTF-8.src
--- share/locale/ctype/en_US.UTF-8.src  7 Aug 2005 10:03:45 -   1.1
+++ share/locale/ctype/en_US.UTF-8.src  6 Jan 2011 16:24:39 -
@@ -491,9 +491,9 @@
  * U+0300 - U+036F : Combining Diacritical Marks
  */
 
-GRAPH 0x0300 - 0x034f  0x0360 - 0x036f
-PRINT 0x0300 - 0x034f  0x0360 - 0x036f
-SWIDTH1   0x0300 - 0x034f  0x0360 - 0x036f
+GRAPH 0x0300 - 0x034e  0x0350 - 0x036f
+PRINT 0x0300 - 0x034e  0x0350 - 0x036f
+SWIDTH0   0x0300 - 0x034e  0x0350 - 0x036f
 
 MAPUPPER   0x0345 0x0399 
 
@@ -583,7 +583,7 @@
 LOWER 0x04c8  0x04ca  0x04cc  0x04ce  0x04d1  0x04d3  0x04d5
 LOWER 0x04d7  0x04d9  0x04db  0x04dd  0x04df  0x04e1  0x04e3
 LOWER 0x04e5  0x04e7  0x04e9  0x04eb  0x04ed  0x04ef  0x04f1
-LOWER 0x04f3  0x04f5  0x04f9
+LOWER 0x04f3  0x04f5  0x04f7  0x04f9
 PUNCT 0x0482
 UPPER 0x0400 - 0x042f  0x0460  0x0462  0x0464  0x0466  0x0468
 UPPER 0x046a  0x046c  0x046e  0x0470  0x0472  0x0474  0x0476
@@ -595,9 +595,10 @@
 UPPER 0x04c5  0x04c7  0x04c9  0x04cb  0x04cd  0x04d0  0x04d2
 UPPER 0x04d4  0x04d6  0x04d8  0x04da  0x04dc  0x04de  0x04e0
 UPPER 0x04e2  0x04e4  0x04e6  0x04e8  0x04ea  0x04ec  0x04ee
-UPPER 0x04f0  0x04f2  0x04f4  0x04f8
-PRINT 0x0400 - 0x0486  0x0488 - 0x04ce  0x04d0 - 0x04f5  0x04f8  0x04f9
-SWIDTH1   0x0400 - 0x0486  0x0488 - 0x04ce  0x04d0 - 0x04f5  0x04f8  0x04f9
+UPPER 0x04f0  0x04f2  0x04f4  0x04f6  0x04f8
+PRINT 0x0400 - 0x0486  0x0488 - 0x04ce  0x04d0 - 0x04f9
+SWIDTH0   0x0483 - 0x0486  0x0488 - 0x0489
+SWIDTH1   0x0400 - 0x0482  0x048a - 0x04ce  0x04d0 - 0x04f9
 
 MAPUPPER   0x0430 - 0x044f : 0x0410 
 MAPUPPER   0x0450 - 0x045f : 0x0400 
@@ -671,6 +672,7 @@
 MAPUPPER   0x04f1 0x04f0 
 MAPUPPER   0x04f3 0x04f2 
 MAPUPPER   0x04f5 0x04f4 
+MAPUPPER   0x04f7 0x04f6 
 MAPUPPER   0x04f9 0x04f8 
 MAPLOWER   0x0400 - 0x040f : 0x0450 
 MAPLOWER   0x0410 - 0x042f : 0x0430 
@@ -744,6 +746,7 @@
 MAPLOWER   0x04f0 0x04f1 
 MAPLOWER   0x04f2 0x04f3 
 MAPLOWER   0x04f4 0x04f5 
+MAPLOWER   0x04f6 0x04f7 
 MAPLOWER   0x04f8 0x04f9 
 
 
@@ -1052,7 +1055,8 @@
 GRAPH 0x0e01 - 0x0e3a  0x0e3f - 0x0e5b
 PUNCT 0x0e3f  0x0e4f  0x0e5a  0x0e5b
 PRINT 0x0e01 - 0x0e3a  0x0e3f - 0x0e5b
-SWIDTH1   0x0e01 - 0x0e3a  0x0e3f - 0x0e5b
+SWIDTH0   0x0e31   0x0e34 - 0x0e3a  0x0e47 - 0x0e4e
+SWIDTH1   0x0e01 - 0x0e30  0x0e32 - 0x0e33  0x0e3f - 0x0e46  0x0e4f - 0x0e5b
 
 TODIGIT0x0e50 - 0x0e59 : 0x 
 
@@ -1283,6 +1287,14 @@
 
 TODIGIT0x1810 - 0x1819 : 0x 
 
+/*
+ * U+1DC0 - U+1DFF : Combining Diacritical Marks

Re: ls(1) multibyte support

2011-01-05 Thread Alexander Polakov
Hi,

here's an updated version.

1) en_US.UTF-8.src updates from FreeBSD
2) wcwidth() changed to use the same code as iswprint()
   * maybe just use iswprint() itself?
3) _RUNETYPE_SW0 changed to be !0 (and match FreeBSD). 0 value is used in
   mklocale to perform additional checks required for MAPLOWER and
   MAPUPPER, but not SWIDTHx.

--- share/locale/ctype/en_US.UTF-8.src  Wed Jan  5 12:37:22 2011
+++ share/locale/ctype/en_US.UTF-8.src  Wed Jan  5 09:47:56 2011
@@ -491,9 +491,9 @@
  * U+0300 - U+036F : Combining Diacritical Marks
  */
 
-GRAPH 0x0300 - 0x034f  0x0360 - 0x036f
-PRINT 0x0300 - 0x034f  0x0360 - 0x036f
-SWIDTH1   0x0300 - 0x034f  0x0360 - 0x036f
+GRAPH 0x0300 - 0x034e  0x0350 - 0x036f
+PRINT 0x0300 - 0x034e  0x0350 - 0x036f
+SWIDTH0   0x0300 - 0x034e  0x0350 - 0x036f
 
 MAPUPPER   0x0345 0x0399 
 
@@ -583,7 +583,7 @@
 LOWER 0x04c8  0x04ca  0x04cc  0x04ce  0x04d1  0x04d3  0x04d5
 LOWER 0x04d7  0x04d9  0x04db  0x04dd  0x04df  0x04e1  0x04e3
 LOWER 0x04e5  0x04e7  0x04e9  0x04eb  0x04ed  0x04ef  0x04f1
-LOWER 0x04f3  0x04f5  0x04f9
+LOWER 0x04f3  0x04f5  0x04f7  0x04f9
 PUNCT 0x0482
 UPPER 0x0400 - 0x042f  0x0460  0x0462  0x0464  0x0466  0x0468
 UPPER 0x046a  0x046c  0x046e  0x0470  0x0472  0x0474  0x0476
@@ -595,9 +595,10 @@
 UPPER 0x04c5  0x04c7  0x04c9  0x04cb  0x04cd  0x04d0  0x04d2
 UPPER 0x04d4  0x04d6  0x04d8  0x04da  0x04dc  0x04de  0x04e0
 UPPER 0x04e2  0x04e4  0x04e6  0x04e8  0x04ea  0x04ec  0x04ee
-UPPER 0x04f0  0x04f2  0x04f4  0x04f8
-PRINT 0x0400 - 0x0486  0x0488 - 0x04ce  0x04d0 - 0x04f5  0x04f8  0x04f9
-SWIDTH1   0x0400 - 0x0486  0x0488 - 0x04ce  0x04d0 - 0x04f5  0x04f8  0x04f9
+UPPER 0x04f0  0x04f2  0x04f4  0x04f6  0x04f8
+PRINT 0x0400 - 0x0486  0x0488 - 0x04ce  0x04d0 - 0x04f9
+SWIDTH0   0x0483 - 0x0486  0x0488 - 0x0489
+SWIDTH1   0x0400 - 0x0482  0x048a - 0x04ce  0x04d0 - 0x04f9
 
 MAPUPPER   0x0430 - 0x044f : 0x0410 
 MAPUPPER   0x0450 - 0x045f : 0x0400 
@@ -671,6 +672,7 @@
 MAPUPPER   0x04f1 0x04f0 
 MAPUPPER   0x04f3 0x04f2 
 MAPUPPER   0x04f5 0x04f4 
+MAPUPPER   0x04f7 0x04f6 
 MAPUPPER   0x04f9 0x04f8 
 MAPLOWER   0x0400 - 0x040f : 0x0450 
 MAPLOWER   0x0410 - 0x042f : 0x0430 
@@ -744,6 +746,7 @@
 MAPLOWER   0x04f0 0x04f1 
 MAPLOWER   0x04f2 0x04f3 
 MAPLOWER   0x04f4 0x04f5 
+MAPLOWER   0x04f6 0x04f7 
 MAPLOWER   0x04f8 0x04f9 
 
 
@@ -1052,7 +1055,8 @@
 GRAPH 0x0e01 - 0x0e3a  0x0e3f - 0x0e5b
 PUNCT 0x0e3f  0x0e4f  0x0e5a  0x0e5b
 PRINT 0x0e01 - 0x0e3a  0x0e3f - 0x0e5b
-SWIDTH1   0x0e01 - 0x0e3a  0x0e3f - 0x0e5b
+SWIDTH0   0x0e31   0x0e34 - 0x0e3a  0x0e47 - 0x0e4e
+SWIDTH1   0x0e01 - 0x0e30  0x0e32 - 0x0e33  0x0e3f - 0x0e46  0x0e4f - 0x0e5b
 
 TODIGIT0x0e50 - 0x0e59 : 0x 
 
@@ -1283,7 +1287,15 @@
 
 TODIGIT0x1810 - 0x1819 : 0x 
 
+/*
+ * U+1DC0 - U+1DFF : Combining Diacritical Marks Supplement
+ */
 
+GRAPH 0x1DC0 - 0x1DC3
+PRINT 0x1DC0 - 0x1DC3
+SWIDTH0   0x1DC0 - 0x1DC3
+
+
 /*
  * U+1E00 - U+1EFF : Latin Extended Additional
  */
@@ -1672,7 +1684,8 @@
 BLANK 0x2000 - 0x200b  0x202f  0x205f
 PRINT 0x2000 - 0x200b  0x2010 - 0x2029  0x202f - 0x2052  0x2057
 PRINT 0x205f
-SWIDTH1   0x2000 - 0x200b  0x2010 - 0x2029  0x202f - 0x2052  0x2057
+SWIDTH1   0x2000 - 0x200a  0x2010 - 0x2029  0x202f - 0x2052  0x2057
+SWIDTH0   0x200b - 0x200d
 SWIDTH1   0x205f
 
 
@@ -1707,9 +1720,9 @@
  * U+20D0 - U+20FF : Combining Diacritical Marks for Symbols
  */
 
-GRAPH 0x20d0 - 0x20ea
-PRINT 0x20d0 - 0x20ea
-SWIDTH1   0x20d0 - 0x20ea
+GRAPH 0x20d0 - 0x20eb
+PRINT 0x20d0 - 0x20eb
+SWIDTH0   0x20d0 - 0x20eb
 
 
 /*
@@ -1987,7 +2000,8 @@
 PUNCT 0x309b  0x309c
 PRINT 0x3041 - 0x3096  0x3099 - 0x309f
 PHONOGRAM 0x3041 - 0x3096  0x309f
-SWIDTH2   0x3041 - 0x3096  0x3099 - 0x309f
+SWIDTH0   0x3099 - 0x309a
+SWIDTH2   0x3041 - 0x3096  0x309b - 0x309f
 
 
 /*
@@ -2211,7 +2225,7 @@
 
 GRAPH 0xfe20 - 0xfe23
 PRINT 0xfe20 - 0xfe23
-SWIDTH1   0xfe20 - 0xfe23
+SWIDTH0   0xfe20 - 0xfe23
 
 
 /*
@@ -2333,8 +2347,13 @@
 GRAPH 0x1d100 - 0x1d126  0x1d12a - 0x1d172  0x1d17b - 0x1d1dd
 PUNCT 0x1d100 - 0x1d126  0x1d12a - 0x1d164  0x1d16a - 0x1d16c
 PUNCT 0x1d183  0x1d184  0x1d18c - 0x1d1a9  0x1d1ae - 0x1d1dd
-PRINT 0x1d100 - 0x1d126  0x1d12a - 0x1d172  0x1d17b - 0x1d1dd
-SWIDTH1   0x1d100 - 0x1d126  0x1d12a - 0x1d172  0x1d17b - 0x1d1dd
+PRINT 0x1d100 - 0x1d126  0x1d12a - 0x1d158  0x1d15a - 0x1d172
+PRINT 0x1d17b - 0x1d1dd
+SWIDTH0   0x1d165 - 0x1d169  0x1d16d - 0x1d172  0x1d17b - 0x1d182
+SWIDTH0   0x1d185 - 0x1d18b  0x1d1aa - 0x1d1ad
+SWIDTH1   0x1d100 - 0x1d126  0x1d12a - 0x1d158  0x1d15a - 0x1d164
+SWIDTH1   0x1d16a - 0x1d16c  0x1d183   0x1d184  0x1d18c - 0x1d1a9
+SWIDTH1   0x1d1ae - 0x1d1dd
 
 
 /*
--- lib/libc/locale/iswctype.c.orig Tue Jan  4 23:12:23 2011
+++ lib/libc/locale/iswctype.c  Wed Jan  5 10:02:36 2011
@@ -170,7 +170,9 @@
 int
 wcwidth(wchar_t c)
 {
-return (((unsigned)__runetype_w(c)  _CTYPE_SWM)  

ls(1) multibyte support

2011-01-04 Thread Alexander Polakov
Hi,

I wonder if there any plans on adding multibyte support for ls(1)?
Or maybe there's a reason why it's not a great idea (which I am not
aware of)?
Anyway, here's a patch I have. It's based on DragonFlyBSD's ls.


diff -u ls/ls.c ls/ls.c
--- ls/ls.c Wed Nov 24 17:39:05 2010
+++ ls/ls.c Tue Jan  4 19:44:35 2011
@@ -42,6 +42,7 @@
 #include errno.h
 #include fts.h
 #include grp.h
+#include locale.h
 #include pwd.h
 #include stdio.h
 #include stdlib.h
@@ -101,6 +102,8 @@
int ch, fts_options, notused;
int kflag = 0;
char *p;
+
+   setlocale(LC_ALL, );
 
/* Terminal defaults to -Cq, non-terminal defaults to -1. */
if (isatty(STDOUT_FILENO)) {
diff -u ls/util.c ls/util.c
--- ls/util.c   Wed Nov 24 17:39:05 2010
+++ ls/util.c   Tue Jan  4 21:04:22 2011
@@ -35,12 +35,14 @@
 
 #include sys/types.h
 #include sys/stat.h
+#include sys/limits.h
 
 #include ctype.h
 #include fts.h
 #include stdio.h
 #include stdlib.h
 #include string.h
+#include wchar.h
 
 #include ls.h
 #include extern.h
@@ -48,11 +50,44 @@
 int
 putname(char *name)
 {
-   int len;
+   mbstate_t mbs;
+   wchar_t wc;
+   int i, len;
+   size_t clen;
 
-   for (len = 0; *name; len++, name++)
-   putchar((!isprint(*name)  f_nonprint) ? '?' : *name);
-   return len;
+   memset(mbs, 0, sizeof(mbs));
+   len = 0;
+   while ((clen = mbrtowc(wc, name, MB_LEN_MAX, mbs)) != 0) {
+   if (clen == (size_t)-1) {
+   if (f_nonprint)
+   putchar('?');
+   else
+   putchar((unsigned char)*name);
+   name++;
+   len++;
+   memset(mbs, 0, sizeof(mbs));
+   continue;
+   }
+   if (clen == (size_t)-2) {
+   if (f_nonprint) {
+   putchar('?');
+   len++;
+   } else
+   len += printf(%s, name);
+   break;
+   }
+   if (f_nonprint  !iswprint(wc)) {
+   putchar('?');
+   name += clen;
+   len++;
+   continue;
+   }
+   for (i = 0; i  (int)clen; i++)
+   putchar((unsigned char)name[i]);
+   name += clen;
+   len += wcwidth(wc);
+   }
+   return (len);
 }
 
 void



Re: ls(1) multibyte support

2011-01-04 Thread Alexander Polakov
* Stefan Sperling s...@stsp.name [110104 23:12]:
 On Tue, Jan 04, 2011 at 09:14:51PM +0300, Alexander Polakov wrote:
  Hi,
  
  I wonder if there any plans on adding multibyte support for ls(1)?
  Or maybe there's a reason why it's not a great idea (which I am not
  aware of)?
  Anyway, here's a patch I have. It's based on DragonFlyBSD's ls.
  
 
 Any locale stuff added to applications that are used on the ramdisk
 (bsd.rd) must be inside #ifndef SMALL.
 The ls binary is linked statically so we need to prevent it from wasting
 space by pulling citrus stuff onto the ramdisk.

Sure.
 
 More importantly, there is an alleged bug in our wcwidth() implementation.
 I haven't had time to investigate, but it has been pointed out on separate
 occasions, by Jordi Beltran Creix and by n...@.
 Test program (from Jordi):
 
   #include stdio.h
   #include locale.h
   
   main ()
   {
   setlocale(LC_ALL, );
   printf(%d %d %d %d\n, wcwidth(0x53DA), wcwidth('A'),
   wcwidth(0x200B), wcwidth(0x1F));
   return 0;
   }
   
 Output is 2, 1, 1, 0, should be 2, 1, 0, -1 (according to Jordi).
 
 We should make sure that wcwidth() is working properly before changing
 applications to use it. We also need a wcwidth() man page.

I think there're 2 separate bugs and I have 2 fixes (neither one
tested).

1) wcwidth(0x200B)
This if from http://unicode.org/Public/UNIDATA/ :

200B;ZERO WIDTH SPACE;Cf;0;BN;N;
200C;ZERO WIDTH NON-JOINER;Cf;0;BN;N;
200D;ZERO WIDTH JOINER;Cf;0;BN;N;

--- share/locale/ctype/en_US.UTF-8.src.orig Tue Jan  4 22:49:22 2011
+++ share/locale/ctype/en_US.UTF-8.src  Tue Jan  4 22:50:55 2011
@@ -1672,7 +1672,8 @@
 BLANK 0x2000 - 0x200b  0x202f  0x205f
 PRINT 0x2000 - 0x200b  0x2010 - 0x2029  0x202f - 0x2052  0x2057
 PRINT 0x205f
-SWIDTH1   0x2000 - 0x200b  0x2010 - 0x2029  0x202f - 0x2052  0x2057
+SWIDTH1   0x2000 - 0x200c  0x2010 - 0x2029  0x202f - 0x2052  0x2057
+SWIDTH0   0x200b - 0x200d
 SWIDTH1   0x205f
 

2) wcwidth(0x1f)

DragonFly's man page for wcwidth(3) says that function returns -1 if 
character is not printable. _RUNETYPE_R is the flag to check.

--- lib/libc/locale/iswctype.c.orig Tue Jan  4 23:12:23 2011
+++ lib/libc/locale/iswctype.c  Tue Jan  4 23:02:37 2011
@@ -170,7 +170,11 @@
 int
 wcwidth(wchar_t c)
 {
-return (((unsigned)__runetype_w(c)  _CTYPE_SWM)  _CTYPE_SWS);
+   _RuneType r;
+   r = __runetype_w(c);
+   if (r  _RUNETYPE_R)
+   return (((unsigned)r  _CTYPE_SWM)  _CTYPE_SWS);
+   return -1;
 }
 
 wctrans_t

Again, I don't have hardware at hand to build libc so this is completely
untested.