~sircmpwn/public-inbox

scdoc: Allow for an input file argument v1 PROPOSED

Peter Hutterer
Peter Hutterer: 1
 Allow for an input file argument

 2 files changed, 24 insertions(+), 10 deletions(-)
Other programs like Meson should be improved to handle stdin better.
It's a standard feature of Unix and many commands benefit from the
additional simplicity of pipelines.



          
          
          
        
      

      
      
      
      

      
      
        
          

Peter Hutterer
thanks for the explanation

On Wed, Jul 08, 2020 at 07:45:57PM -0400, Drew DeVault wrote:
Next
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/public-inbox/patches/11521/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH scdoc] Allow for an input file argument Export this patch

Peter Hutterer
Requiring stdin makes it hard to incorporate scdoc into environments where
pipes aren't readily available or where the input file is present in the file
system anyway.

One example for this is meson, see e.g. sway's meson.build. Sway has to run
scdoc through a shell because we can't just pass the file name.

Fix this, handling an input file is only an fopen call away anyway.
---
 scdoc.1.scd |  7 ++++---
 src/main.c  | 27 ++++++++++++++++++++-------
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/scdoc.1.scd b/scdoc.1.scd
index 74c38d2..2d052b3 100644
--- a/scdoc.1.scd
+++ b/scdoc.1.scd
@@ -6,12 +6,13 @@ scdoc - generate *man*(7) manual pages

# SYNOPSIS

*scdoc* < _input_
*scdoc* [_input_]

# DESCRIPTION

The scdoc utility reads *scdoc*(5) syntax from the standard input and writes
*man*(7) style roff to the standard output.
The scdoc utility reads *scdoc*(5) syntax from the given input file
and writes *man*(7) style roff to the standard output. Where no input file
is given, scdoc reads from standard input.

# SEE ALSO

diff --git a/src/main.c b/src/main.c
index 7bb6c42..42d1163 100644
--- a/src/main.c
+++ b/src/main.c
@@ -738,21 +738,34 @@ static void output_scdoc_preamble(struct parser *p) {
}

int main(int argc, char **argv) {
	if (argc == 2 && strcmp(argv[1], "-v") == 0) {
		printf("scdoc " VERSION "\n");
		return 0;
	} else if (argc > 1) {
		fprintf(stderr, "Usage: scdoc < input.scd > output.roff\n");
		return 1;
	}
	struct parser p = {
		.input = stdin,
		.output = stdout,
		.line = 1,
		.col = 1
	};
	if (argc == 2) {
		if (strcmp(argv[1], "-v") == 0) {
			printf("scdoc " VERSION "\n");
			return 0;
		} else {
			p.input = fopen(argv[1], "r");
			if (!p.input) {
				fprintf(stderr, "Failed to open input file '%s' (%s)\n",
						argv[1], strerror(errno));
				return 1;
			}
		}
	} else if (argc > 1) {
		fprintf(stderr, "Usage: scdoc < input.scd > output.roff\n");
		return 1;
	}
	output_scdoc_preamble(&p);
	parse_preamble(&p);
	parse_document(&p);

	if (p.input != stdin)
		fclose(p.input);

	return 0;
}
-- 
2.26.2
NACK