fop(1) and Rust sysexits support (no yacexits!) #18

Closed
emma wants to merge 0 commits from fop into main
Owner
No description provided.
emma added the
enhancement
label 2023-12-27 22:58:06 -07:00
trinity was assigned by emma 2023-12-27 22:58:06 -07:00
emma added 5 commits 2023-12-27 22:58:06 -07:00
emma added 1 commit 2023-12-27 23:21:06 -07:00
trinity reviewed 2023-12-28 16:36:47 -07:00
trinity left a comment
Owner

The code probably runs (I haven't tested compiling yet) but I hope you heed my suggestions.

The code probably runs (I haven't tested compiling yet) but I hope you heed my suggestions.
GNUmakefile Outdated
@ -59,1 +61,4 @@
sysexits: build_dir
# bandage solution until bindgen(1) gets stdin support
printf '#define EXIT_FAILURE 1\n' | cat - include/sysexits.h \
Owner

Why define EXIT_FAILURE here? It's already in the C standard library. Unless this is for Rust purposes specifically.

Why define EXIT_FAILURE here? It's already in the C standard library. Unless this is for Rust purposes specifically.
Author
Owner

This is for Rust only :)

This is for Rust only :)
emma marked this conversation as resolved
GNUmakefile Outdated
@ -60,0 +64,4 @@
printf '#define EXIT_FAILURE 1\n' | cat - include/sysexits.h \
> build/include/sysexits.h
bindgen --default-macro-constant-type signed --use-core \
"$$(printf '#include <sysexits.h>\n' \
Owner

Why $$ here? I can't quite follow.

Why `$$` here? I can't quite follow.
Author
Owner

$$ escapes the $ so that make doesnt try to resolve the subshell as a variable

`$$` escapes the `$` so that make doesnt try to resolve the subshell as a variable
emma marked this conversation as resolved
GNUmakefile Outdated
@ -60,0 +65,4 @@
> build/include/sysexits.h
bindgen --default-macro-constant-type signed --use-core \
"$$(printf '#include <sysexits.h>\n' \
| cpp -M -idirafter "$$PWD/build/include" - \
Owner

Can cpp not take a relative path? It can be safely assumed that a Makefile is executed with PWD being the Makefile's parent directory. Why pass $PWD/path literally versus the path itself with the shell doing the variable expansion?

Can cpp not take a relative path? It can be safely assumed that a Makefile is executed with PWD being the Makefile's parent directory. Why pass `$PWD/path` literally versus the path itself with the shell doing the variable expansion?
Author
Owner

it can, but i think i had a reason in a prior solution not to use the relative path because it causes side effects. i will look back into it

it can, but i think i had a reason in a prior solution not to use the relative path because it causes side effects. i will look back into it
emma marked this conversation as resolved
GNUmakefile Outdated
@ -60,0 +66,4 @@
bindgen --default-macro-constant-type signed --use-core \
"$$(printf '#include <sysexits.h>\n' \
| cpp -M -idirafter "$$PWD/build/include" - \
| sed 's/ /\n/g' | grep sysexits.h)" \
Owner

It would be nice to have a further level of indent to indicate the pipeline within the "$( )". I have a hard time reading this.

It would be nice to have a further level of indent to indicate the pipeline within the `"$(` `)"`. I have a hard time reading this.
Owner

Multiple pipeline statements on the same line also make this a little tricky for me.

Multiple pipeline statements on the same line also make this a little tricky for me.
emma marked this conversation as resolved
src/fop.rs Outdated
@ -0,0 +38,4 @@
})
},
None => {
eprintln!("{}", usage);
Owner

It would be better to check that there are enough arguments before anything else to avoid unnecessary operations.

It would be better to check that there are enough arguments before anything else to avoid unnecessary operations.
emma marked this conversation as resolved
src/fop.rs Outdated
@ -0,0 +45,4 @@
let mut buf = String::new();
stdin().read_line(&mut buf).unwrap();
let mut fields = buf.split('␞').collect::<Vec<&str>>();
Owner

Perhaps we should have a defines.h to set magic numbers like the ASCII record separator as the delimiter.

Perhaps we should have a defines.h to set magic numbers like the ASCII record separator as the delimiter.
Owner

I think it would be better to have ASCII horizontal tabs as the delimiter if standard output is a tty so output is readable in all fonts and on all terminals. At least npc(1) exists.

I think it would be better to have ASCII horizontal tabs as the delimiter if standard output is a tty so output is readable in all fonts and on all terminals. At least npc(1) exists.
Author
Owner

Perhaps we should have a defines.h to set magic numbers like the ASCII record separator as the delimiter.

I tried this, but for an unknown reason bindgen will not output Rust bindings to the variable set in the header file. I will investigate further

> Perhaps we should have a defines.h to set magic numbers like the ASCII record separator as the delimiter. I tried this, but for an unknown reason bindgen will not output Rust bindings to the variable set in the header file. I will investigate further
Author
Owner

I’m going to write a library in Rust (with C bindings) which handles ASV stuff.

I’m going to write a library in Rust (with C bindings) which handles ASV stuff.
emma marked this conversation as resolved
emma added 2 commits 2023-12-28 23:01:50 -07:00
emma requested review from trinity 2023-12-28 23:23:24 -07:00
emma self-assigned this 2023-12-28 23:23:27 -07:00
trinity was unassigned by emma 2023-12-28 23:23:27 -07:00
trinity reviewed 2024-01-07 07:40:37 -07:00
src/fop.rs Outdated
@ -0,0 +29,4 @@
let argv = args().collect::<Vec<String>>();
argv.get(2).unwrap_or_else(|| {
eprintln!("Usage: {} index command [args...]", argv[0]);
Owner

It would be nice to be able to narrow down fields.

Usage: fop (-f [file field]) (-g [group field]) (-r [record field]) (-u [unit field]) command arguments...

That way if data looks like A [US] B [RS] C [US] D [GS] E [FS]
you can do fop -f 1 -g 1 -r 2 -u 2 sed 's/D/F/ and get A [US] B [RS] C [US] F [GS] E [FS]. The same could be accomplished simpler but the point is to allow fine-grained control within ASV structures.

It would be nice to be able to narrow down fields. ``` Usage: fop (-f [file field]) (-g [group field]) (-r [record field]) (-u [unit field]) command arguments... ``` That way if data looks like `A [US] B [RS] C [US] D [GS] E [FS]` you can do `fop -f 1 -g 1 -r 2 -u 2 sed 's/D/F/` and get `A [US] B [RS] C [US] F [GS] E [FS]`. The same could be accomplished simpler but the point is to allow fine-grained control within ASV structures.
Author
Owner

I’m not exactly sure what the best way to go about this would be. I didn’t see this before adding the -d option.

I’m not exactly sure what the best way to go about this would be. I didn’t see this before adding the `-d` option.
Author
Owner

I suppose we need to resolve #19 before we can truly decide on what to do.

I suppose we need to resolve #19 before we can truly decide on what to do.
Author
Owner

After going over this with Trinity verbally, we have decided to merge the existing fop(1) implementation while we work on resolving #19.

After going over this with Trinity verbally, we have decided to merge the existing fop(1) implementation while we work on resolving #19.
emma added 5 commits 2024-01-15 16:30:30 -07:00
emma added 1 commit 2024-01-15 16:34:15 -07:00
emma changed title from WIP: fop(1) and Rust sysexits support (no yacexits!) to fop(1) and Rust sysexits support (no yacexits!) 2024-01-15 16:43:24 -07:00
emma referenced this issue from a commit 2024-01-15 16:50:16 -07:00
emma closed this pull request 2024-01-15 16:50:25 -07:00

Pull request closed

Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: bonsai/harakit#18
No description provided.