Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read the input from stdin instead of a .frm file #265

Merged
merged 2 commits into from
Jul 7, 2022

Conversation

tueda
Copy link
Collaborator

@tueda tueda commented Feb 10, 2018

Work in progress. This is an experimental implementation of #264. Example:

cat <<END | form -q -stdin
Off stats;
S x;
L F = (1+x)^2;
P;
.end
END

Setup parameters (#:...) are not supported yet.

It also works with Windows (an binary available in AppVeyor: https://ci.appveyor.com/project/tueda/form/build/job/5ndaxgejblwqa4ho/artifacts).

@tueda tueda changed the title Add -stdin command line option to use stdin as input [WIP] Add -stdin option Feb 10, 2018
@coveralls
Copy link

coveralls commented Feb 10, 2018

Coverage Status

Coverage increased (+0.009%) to 48.222% when pulling 50f39cd on tueda:stdin into eaf85a7 on vermaseren:master.

@tueda
Copy link
Collaborator Author

tueda commented Feb 11, 2018

Now setup parameters are supported. Example:

cat <<END | form -stdin
#:workspace 1234K
#:wtimestats on
On setup;
S x;
L F = (1+x)^2;
P;
.end
END

@tueda
Copy link
Collaborator Author

tueda commented Apr 23, 2018

Squashed into one commit. Ready to merge (once the others agree).

Possible improvement: currently the stdin is read one by one, for simplicity, by ReadFile(stream->handle,&c,1) in ReadFromStream.

@tueda tueda changed the title [WIP] Add -stdin option Add -stdin option: stdin as a FORM input instead of a .frm file Apr 23, 2018
@alexmyczko
Copy link
Contributor

Normally for stdin as file input - is used, if - must be given as parameter to program it's -- -.

Can -stdin be replaced by - for consistency among other command line software? so it should just be
form -

@tueda
Copy link
Collaborator Author

tueda commented Nov 21, 2018

I think - for stdin is a reasonable choice.

@tueda
Copy link
Collaborator Author

tueda commented Nov 21, 2018

By the way, the PADXXX macros are useless, memory inefficient, and moreover hard to merge two changes! (Now this branch is non-trivially conflicting with the master...)

@tueda
Copy link
Collaborator Author

tueda commented Dec 3, 2018

Now the filename - means stdin.

@tueda tueda changed the title Add -stdin option: stdin as a FORM input instead of a .frm file Read the input from stdin instead of a .frm file Dec 3, 2018
@benruijl
Copy link
Collaborator

benruijl commented Jul 6, 2022

Is this change still ready to be merged?

@tueda
Copy link
Collaborator Author

tueda commented Jul 7, 2022

It seems that there are no conflicts with the current master branch (though the current master fails to pass the tests and travis-ci.org is dead), but probably it has conflicts with 5.0 via PADXXX, I guess.

@benruijl
Copy link
Collaborator

benruijl commented Jul 7, 2022

I've changed the pull request so that the banner is printed first and the line echoing is disabled. Now form can be used pretty cleanly from the command line as if it were an interpreter! I imagine this may be useful when teaching form.

@tueda can you check if moving the header print is safe for parFORM? If so ,we can merge it :)

@tueda
Copy link
Collaborator Author

tueda commented Jul 7, 2022

We can ignore ParFORM for now because MPI doesn't automatically broadcast stdin (see, for example, https://stackoverflow.com/q/49016638) so it doesn't work anyway. I have added an error message for the case where - is specified in ParFORM.

You can use "Rebase and merge" (or "Squash and merge" if you want).

@benruijl
Copy link
Collaborator

benruijl commented Jul 7, 2022

I've moved the printing of the header, even when we don't use stdin mode. I think it's safe (MsgPrint needs to be initialized, etc).

tueda and others added 2 commits July 7, 2022 12:47
This patch makes FORM read the input from the standard input rather than
a file when "-" is given in the command line option.

Example:
  cat <<END | form -
  #:workspace 1234K
  #:wtimestats on
  On setup;
  S x;
  L F = (1+x)^2;
  P;
  .end
  END

Stdin mode is forbidden in ParFORM, since in many MPI implementations stdin is only
accessible from one of the MPI processes.
- Disable line echoing by default in stdin mode
@benruijl benruijl merged commit b431780 into vermaseren:master Jul 7, 2022
@jodavies
Copy link
Collaborator

36f5536 causes tform's header to always state "-1 workers", by the way.

@tueda
Copy link
Collaborator Author

tueda commented Jul 17, 2022

Right, I've confirmed that git revert 36f5536 fixes "-1 workers".

If PrintHeader is called before DoTail, then any command-line options like -w4 are not processed yet (i.e., AM.totalnumberofthreads is 0), so tform has to print "-1 workers", I guess.

@jodavies
Copy link
Collaborator

Actually, this also breaks the -q option, the header prints regardless.

@tueda
Copy link
Collaborator Author

tueda commented Oct 11, 2022

Maybe a solution would be:

  1. Revert the position of PrintHeader(1) back to just before IniVars(), and
  2. Use AM.silent = 1 (as the -q option) instead of AC.NoShowInput = 1 for - (stdin),

though I'm not sure what is the exact differences between AM.silent = 1 and AC.NoShowInput = 1.

@tueda
Copy link
Collaborator Author

tueda commented Oct 11, 2022

A safer option:

  1. Revert PrintHeader(1),
  2. Keep AC.NoShowInput = 1 for - (stdin), and
  3. Skip PrintHeader(1) if AM.FromStdin is 1.

By the way, if FORM always doesn't print the version header for the stdin case, how can one know the exact version of FORM running? Currently, parsing the version header is the only way to know that.

@alexmyczko
Copy link
Contributor

alexmyczko commented Oct 11, 2022

form has a -v option to only print its version and exit?

@benruijl
Copy link
Collaborator

@tueda I'll push your latest suggestion. I've tested it and it seems to work. Running form without any arguments or with -v still prints the version.

@tueda
Copy link
Collaborator Author

tueda commented Oct 11, 2022

form has a -v option to only print its version and exit?

Yes, indeed this seems to be enough. The user program may run FORM twice, form -v to check the version and then form - for the main program. (For python-form, I wrote code checking the version and running the main program in one-go, without the stdin mode.)

I'll push your latest suggestion. I've tested it and it seems to work. Running form without any arguments or with -v still prints the version.

Nice! Go ahead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants