Re: [dev] C variants, compilers and completeness

2023-08-01 Thread LM
On Mon 24 Jul 2023, Sagar Acharya wrote:
> I see C compilers recommended by suckless are:
>
> tinycc
> simplecc
> cproc
> qbe
> lacc
>
> Which variant of C do they offer? What are the differences and do they offer 
> sufficient features to express with a program completely?

I tried to check if Michael Forney's C compiler was on the list and ran across
this page while searching:
https://developers.redhat.com/blog/2021/04/27/the-mir-c-interpreter-and-just-in-time-jit-compiler#how_the_mir_c_compiler_compares_with_other_c_compilers
Thought it had some interesting comparisons of the compilers even if it is
comparing them to an interpreter.  Michael Forney's compiler is cproc which I
thought was a very interesting and well designed alternative to GNU and llvm.
I've also read that Rob Landley (who was active on the musl mailing list) had
plans to work on a C compiler, but I think that project is dead.  The code he
was working on is still available and there's more information about his tcc
forks here: https://landley.net/code/tinycc/  I know some projects use tcc
successfully, but they're usually small projects.  I thought pcc was also
interesting for its cross platform capabilities, but probably not as efficient
as some of the other choices and I think the version of C supported was rather
dated.

Sincerely
L. Michaels
https://www.softwarefreedomday.org/



Re: [dev] Announcing a couple small X11 utilities

2023-08-01 Thread Yan Doroshenko

Hello,


I've addressed most of your concerns, please check the attached patch 
and let me know what else can be done.



Regards,

Yan


On 7/31/23 11:44, NRK wrote:

Hi Yan,

On Sat, Jul 29, 2023 at 02:46:29PM +0200, Yan Doroshenko wrote:

I've created a patch for sxot that adds a -m (--monitor) param that allows
to select which monitor to capture in a multihead setup. Let me know what
you think.

Thanks for the patch, I don't use a multimonitor setup to test it out
properly, but there are already a couple things which aren't too good.

+   int m[1];
+   str_to_int(str_from_cstr(argv[++i]), m);

str_to_int() does certain error checking (such as overflow) and returns
false in case of failure. That return value should not be ignored. It
should fatally error out if str_to_int() returns false.

It's also weird to use `int m[1]` instead of using `int m` and then
taking a pointer.

+   XRRScreenResources *screen;
+   screen = XRRGetScreenResources (x11.dpy, 
DefaultRootWindow(x11.dpy));

I'm not familiar with Xrander (and my local manpage is lacking
documentation for this function) but given that it returns a pointer, it
most likely needs to be error checked.

+   XRRCrtcInfo *crtc_info;
+   crtc_info = XRRGetCrtcInfo (x11.dpy, screen, 
screen->crtcs[m[0]]);

Same here, most likely needs error checking. But even more importantly:

screen->crtcs[m[0]]

one can never assume anything about data that came from outside. There's
no guarantee that m[0] won't be bigger than the len of `screen->crtcs`.

I see that there's a `ncrtc` member, which likely contains the len of
`crtcs`. You should check to make sure that it doesn't exceed that.

If you compile with AddressSanitizer (see the "recommended debug build"
on the README) and input some absurdly high value, you'll notice the
buffer overflow:

$ ./sxot -m 1024 >/dev/null
=
==11432==ERROR: AddressSanitizer: heap-buffer-overflow on address 
0x61a02600 at pc 0x00404271 bp 0x7ffe95aa74a0 sp 0x7ffe95aa7498

And even if you enter a valid value, ASan reports 2 leaks (output
cleaned up):

$ ./sxot -m 0 >/dev/null
SUMMARY: AddressSanitizer: 1296 byte(s) leaked in 2 allocation(s).

So something probably needs to be freed above.

- NRK

diff --git a/sxot.c b/sxot.c
index de87126..094cd7b 100644
--- a/sxot.c
+++ b/sxot.c
@@ -31,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 
 typedef uint8_t u8;
 typedef uint32_tu32;
@@ -207,7 +208,8 @@ main(int argc, char *argv[])
 		"usage: sxot [options]\n"
 		"Options:\n"
 		"  -g, --geomCapture the specified rectangle\n"
-		"  -c, --curosr   Capture the cursor also\n"
+		"  -c, --cursor   Capture the cursor also\n"
+		"  -m, --monitor nCapture the specified monitor\n"
 	);
 	Str version = S(
 		"sxot " VERSION "\n"
@@ -237,6 +239,38 @@ main(int argc, char *argv[])
 			if (!parse_geom(opt.v, str_from_cstr(argv[++i]))) {
 fatal(S("invalid geometry\n"));
 			}
+
+		} else if (str_eq(arg, S("--monitor")) || str_eq(arg, S("-m"))) {
+			int m;
+			if (!str_to_int(str_from_cstr(argv[++i]), )) {
+fatal(S("invalid monitor number\n"));
+			}
+
+			int n;
+			XRRMonitorInfo *monitors;
+			monitors = XRRGetMonitors(x11.dpy, x11.root, true, );
+
+			free(monitors);
+
+			if (n == -1) {
+fatal(S("get monitors failed\n"));
+			}
+			if (m >= n) {
+fatal(S("no monitor with such index\n"));
+			}
+
+			XRRScreenResources *screen;
+			screen = XRRGetScreenResources(x11.dpy, DefaultRootWindow(x11.dpy));
+			XRRCrtcInfo *crtc_info;
+			crtc_info = XRRGetCrtcInfo(x11.dpy, screen, screen->crtcs[m]);
+
+			opt.x = crtc_info->x;
+			opt.y = crtc_info->y;
+			opt.h = crtc_info->height;
+			opt.w = crtc_info->width;
+
+			free(crtc_info);
+			free(screen);
 		} else if (str_eq(arg, S("--cursor")) || str_eq(arg, S("-c"))) {
 			opt.capture_cursor = true;
 		} else if (str_eq(arg, S("--help")) || str_eq(arg, S("-h"))) {


OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: [dev] C variants, compilers and completeness

2023-08-01 Thread Pontus Stenetorp
On Mon 24 Jul 2023, Sagar Acharya wrote:
> 
> I see C compilers recommended by suckless are:
> 
> tinycc
> simplecc
> cproc
> qbe
> lacc
> 
> Which variant of C do they offer? What are the differences and do they offer 
> sufficient features to express with a program completely?

Whether they are sufficient depends on your use case. Everything else is 
covered in their documentation.

https://bellard.org/tcc

http://git.simple-cc.org/scc/file/README.html

https://sr.ht/~mcf/cproc

https://github.com/larmel/lacc



Re: [dev] sbm dmenu bookmarker

2023-08-01 Thread Страхиња Радић
On 23/07/31 08:15AM, Randy Palamar wrote:
> `grep -v -e '#' -e '^$' $BOOKMARKS | dmenu -i -l 20 | cut -f 1 -d ' '`
> 
> Then I pipe it to the clipboard or a plumber script depending
> on what I want to do with it (bound to a keybind in dwm).
> 
> To add bookmarks I either use a text editor or just echo:
> 
> `echo "https://nsa.gov file sharing, hosting provider" >> $BOOKMARKS`

Since bookmarks are related to the Web, I usually keep them inside of my 
bloated web browser for the bloated Web (the very term [in the digital 
sense] originates from Netscape IIRC). They can be copied to the clipboard from 
there and pasted into st. Anything else I just type out. ¯\_(ツ)_/¯


signature.asc
Description: PGP signature


Re: [dev] sbm dmenu bookmarker

2023-08-01 Thread Spenser Truex
Thanks for your feedbacks, however, the script bm is the
simplification/attempted improvement of of bmks which I got from some
unknown source (apologies if you are the uncredited author).
-- 
CAEE B377 FC82 BAF9 102C  D22F C5CE D003 1AA8 E281
Spenser Truexhttps://equwal.com


signature.asc
Description: PGP signature