Re: [dev] [edit] Introducing edit, a simple text editor

2023-09-27 Thread Adam Sampson
Страхиња Радић  writes:

> On closer inspection, termbox2.h does include signal.h itself[1], and
> additionally defines _XOPEN_SOURCE[2] and _DEFAULT_SOURCE, so the
> inclusion of signal.h can't be escaped.

I suspect the problem is that these kinds of macros need to be defined
before *any* of the glibc headers are included (see the
feature_test_macros man page). edit.c includes various other headers
before pulling in termbox2.h, by which time it's too late.

-- 
Adam Sampson  



Re: [dev] [edit] Introducing edit, a simple text editor

2023-09-27 Thread Страхиња Радић
On closer inspection, termbox2.h does include signal.h itself[1], and 
additionally defines _XOPEN_SOURCE[2] and _DEFAULT_SOURCE, so the inclusion of 
signal.h can't be escaped.

My testing has shown that when -std=c99 is specified, it is as if that switch 
explicitly undefines _DEFAULT_SOURCE/_XOPEN_SOURCE **defined inside the header 
file** (this is the weird part). If -D_DEFAULT_SOURCE is given as an argument, 
or without -std=c99, when gcc is called directly rather than through the 
wrapper, c99, there are no warnings:

$ c99 -E edit.c | grep fileno
if (fstat(fileno(fp), ) != 0) {
$ gcc -E edit.c | grep fileno
int fileno(FILE *);
int fileno_unlocked(FILE *);
if (fstat(fileno(fp), ) != 0) {
$ c99 -D_DEFAULT_SOURCE -E edit.c | grep fileno
int fileno(FILE *);
int fileno_unlocked(FILE *);
if (fstat(fileno(fp), ) != 0) {
$

I use Alpine Linux, thus musl libc. Searching the web yielded the answer[3] on 
Stack Overflow, though:

> If you want this to cleanly compile with -std=c99, you must consider the 
> inclusion of the _DEFAULT_SOURCE feature test macro

I'm not sure about why you wouldn't want POSIX compliance though (To compile on 
Plan9? But it has APE[4]).


[1]: 
https://github.com/arthur-jacquin/edit/blob/41cd580d80459d1f13ef923c812cf6a858b240f0/termbox2.h#L40
[2]: 
https://github.com/arthur-jacquin/edit/blob/41cd580d80459d1f13ef923c812cf6a858b240f0/termbox2.h#L29
[3]: https://stackoverflow.com/a/10435860
[4]: https://9p.io/wiki/plan9/Porting_alien_software_to_Plan_9/index.html


signature.asc
Description: PGP signature


Re: [dev] [edit] Introducing edit, a simple text editor

2023-09-27 Thread Arthur Jacquin

On 27/09/2023 17:10, Страхиња Радић wrote:


On 23/09/27 03:50PM, Arthur Jacquin wrote:


termbox2.h is not C99 compliant, yet the -std=c99 compilation flag is
set in the default configuration. On the compilers I tried, it has not
been a problem as the non-C99 parts were ignored, but I shouldn't have
assumed it would always be this way. Sorry for the annoyance.


Which parts of termbox2.h are not C99 compliant? What compiler doesn't 
"ignore"

the non-C99 compliant code when -std=c99 is passed?

I maintain my own simple editor called sled[1], which uses termbox2.h 
and
passes `-std=c99` as a default flag. I have compiled it using GCC, 
Clang/LLVM,
tinycc, on (GNU/)Linux and OpenBSD, and I have yet to encounter any 
errors.


I tried compiling your program using `CC=c99` (script wrapper to GCC) 
and
passing `-std=c99`, and there are only some warnings about implicitly 
declared
functions, nothing about `struct sigaction`. In any case, you can 
simply
include the needed headers prior to including termbox2.h (my program 
uses

signal.h to redraw after C-Z, so I include it anyway).

[1]: https://strahinja.srht.site/sled/


The whole C99 compliance thing is not perfectly clear to me, and the
clarification is on my todo list. Let me explain what I understand as
of now. If I'm wrong, correct me.

I use tinycc and gcc for testing, with the `-std=c99` flag. Like you,
I've never had any errors, but I get warnings for implicitely
declared functions (with gcc): strerror_r, cfmakeraw, and fileno.
I believe these functions are not in the C99 standard library, if I
refer to this draft[0], and I would like to avoid including
POSIX-specific headers.

So to my understanding, termbox2.h is C99 compliant, but uses
functions that are not part of the C99 standard library, and that's
why I said (incorrectly) that termbox2.h is not C99 compliant.

What I'm not sure about is how these implicitely declared functions
are treated by the linker. As I intend to rewrite the termbox2.h
parts related to these functions, this question is not crucial, and
until the rewrite is done, deleting the `-std=c99` flag should be
enough.

[0]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf







Re: [dev] [edit] Introducing edit, a simple text editor

2023-09-27 Thread Ben Green
Hello Dan,


Dan wrote:

termbox2.h:2209:22: error: storage size of ‘sa’ isn’t known
termbox2.h:2345:46: error: ‘struct sigaction’ has no member named ‘sa_handler’
termbox2.h:2345:44: error: invalid use of undefined type ‘struct sigaction’

Seems like termbox2.h expects something in your headers that is not present, 
what operating system and libc are you using?

Kind regards,

Benjamin.



Re: [dev] [edit] Introducing edit, a simple text editor

2023-09-27 Thread Страхиња Радић
On 23/09/27 03:50PM, Arthur Jacquin wrote:
> termbox2.h is not C99 compliant, yet the -std=c99 compilation flag is
> set in the default configuration. On the compilers I tried, it has not
> been a problem as the non-C99 parts were ignored, but I shouldn't have
> assumed it would always be this way. Sorry for the annoyance.

Which parts of termbox2.h are not C99 compliant? What compiler doesn't "ignore" 
the non-C99 compliant code when -std=c99 is passed?

I maintain my own simple editor called sled[1], which uses termbox2.h and 
passes `-std=c99` as a default flag. I have compiled it using GCC, Clang/LLVM, 
tinycc, on (GNU/)Linux and OpenBSD, and I have yet to encounter any errors.

I tried compiling your program using `CC=c99` (script wrapper to GCC) and 
passing `-std=c99`, and there are only some warnings about implicitly declared 
functions, nothing about `struct sigaction`. In any case, you can simply 
include the needed headers prior to including termbox2.h (my program uses 
signal.h to redraw after C-Z, so I include it anyway).

[1]: https://strahinja.srht.site/sled/


signature.asc
Description: PGP signature


Re: [dev] [edit] Introducing edit, a simple text editor

2023-09-27 Thread Arthur Jacquin

Hi Arthur, I tried to build your project, but it failed for me:

termbox2.h:2209:22: error: storage size of 'sa' isn't known
termbox2.h:2345:46: error: 'struct sigaction' has no member named 
'sa_handler'
termbox2.h:2345:44: error: invalid use of undefined type 'struct 
sigaction'


All the best,
Dan


termbox2.h is not C99 compliant, yet the -std=c99 compilation flag is
set in the default configuration. On the compilers I tried, it has not
been a problem as the non-C99 parts were ignored, but I shouldn't have
assumed it would always be this way. Sorry for the annoyance.

I removed the -std=c99 flag in the upstream, until I patch termbox2.h
for full C99 compliance. You can either pull the upstream or delete
the flag manually in config.mk.

If deleting the flag is not enough, please let me know. Otherwise,
happy editing ;)

Arthur







Re: [dev] [edit] Introducing edit, a simple text editor

2023-09-27 Thread Daniel Littlewood
Hi Arthur, I tried to build your project, but it failed for me:

termbox2.h:2209:22: error: storage size of ‘sa’ isn’t known
termbox2.h:2345:46: error: ‘struct sigaction’ has no member named ‘sa_handler’
termbox2.h:2345:44: error: invalid use of undefined type ‘struct sigaction’

All the best,
Dan

On Wed, Sep 27, 2023 at 1:15 PM Arthur Jacquin  wrote:
>
> Hello suckless developers,
>
> This is my first time here, I hope I'm doing everything correctly :)
>
> There is a bit of a story leading to this post. About a year ago, I
> discovered the kakoune text editor. At that time I was a pretty happy
> vim user, but kakoune arguments for its reversed grammar[0] resonated
> with me and soon made me want a vim replacement.
>
> Already aware of and enthusiastic about the suckless philosophy, I
> started by exploring the text editors referenced there[1]. I was
> looking for the combination of a simple yet powerful editing model and
> a truly suckless development style. As none satisfied me, I decided to
> write my own.
>
> The result is edit[2] (yeah, quite creative on the name).
>
> It uses a kakoune-inspired selection-centric, selection-then-action
> model. This makes multi-cursor or column/block editing natural,
> without getting in the way for simple editing.
>
> In a typical suckless fashion, edit is written in C99 with no external
> dependencies, and is very easy to configure, hack on and extend. The
> terminal drawing stuff is done by termbox2.h, a single-header library
> discovered on [1].
>
> In about 2.2K lines (plus 2.7K lines for termbox2.h), edit packs quite
> a few features, such as syntax highlighting, autocompletion, a line
> clipboard, and a search and replace engine supporting regular
> expressions and subpatterns and fields reuse.
>
> By now, it's fairly stable. No major change is expected, and I'm
> gradually polishing it towards version 1.0. If you're interested in
> taking the time to discover edit, the online manual page[3] might be a
> good starting point. I'm looking forward some feedback, so feel free
> to share your comments ;)
>
> Happy hacking,
>
> Arthur
>
> [0]: https://kakoune.org/why-kakoune/why-kakoune.html
> [1]: https://suckless.org/rocks/
> [2]: https://jacquin.xyz/edit
> [3]: https://jacquin.xyz/edit.1
>
>
>
>
>



[dev] [edit] Introducing edit, a simple text editor

2023-09-27 Thread Arthur Jacquin

Hello suckless developers,

This is my first time here, I hope I'm doing everything correctly :)

There is a bit of a story leading to this post. About a year ago, I
discovered the kakoune text editor. At that time I was a pretty happy
vim user, but kakoune arguments for its reversed grammar[0] resonated
with me and soon made me want a vim replacement.

Already aware of and enthusiastic about the suckless philosophy, I
started by exploring the text editors referenced there[1]. I was
looking for the combination of a simple yet powerful editing model and
a truly suckless development style. As none satisfied me, I decided to
write my own.

The result is edit[2] (yeah, quite creative on the name).

It uses a kakoune-inspired selection-centric, selection-then-action
model. This makes multi-cursor or column/block editing natural,
without getting in the way for simple editing.

In a typical suckless fashion, edit is written in C99 with no external
dependencies, and is very easy to configure, hack on and extend. The
terminal drawing stuff is done by termbox2.h, a single-header library
discovered on [1].

In about 2.2K lines (plus 2.7K lines for termbox2.h), edit packs quite
a few features, such as syntax highlighting, autocompletion, a line
clipboard, and a search and replace engine supporting regular
expressions and subpatterns and fields reuse.

By now, it's fairly stable. No major change is expected, and I'm
gradually polishing it towards version 1.0. If you're interested in
taking the time to discover edit, the online manual page[3] might be a
good starting point. I'm looking forward some feedback, so feel free
to share your comments ;)

Happy hacking,

Arthur

[0]: https://kakoune.org/why-kakoune/why-kakoune.html
[1]: https://suckless.org/rocks/
[2]: https://jacquin.xyz/edit
[3]: https://jacquin.xyz/edit.1