Class StdinExtension

java.lang.Object
org.metricshub.jawk.ext.AbstractExtension
org.metricshub.jawk.ext.StdinExtension
All Implemented Interfaces:
JawkExtension

public class StdinExtension extends AbstractExtension implements JawkExtension
Enable stdin processing in Jawk, to be used in conjunction with the -ni parameter. Since normal input processing is turned off via -ni, this is provided to enable a way to read input from stdin.

To use:

 StdinGetline() == 1 { print "--> " $0 }
 

The extension functions are as follows:

  • StdinHasInput -
    Returns 1 when StdinGetline() does not block (i.e., when input is available or upon an EOF), 0 otherwise.
    Parameters:

    • none
    Returns:
    • 1 when StdinGetline() does not block, 0 otherwise.
  • StdinGetline -
    Retrieve a line of input from stdin. The operation will block until input is available, EOF, or an IO error.
    Parameters:

    • none
    Returns:
    • 1 upon successful read of a line of input from stdin, 0 upon an EOF, and -1 when an IO error occurs.
  • StdinBlock -
    Block until a call to StdinGetline() would not block.
    Parameters:

    • chained block function - optional
    Returns:
    • "Stdin" if this block object is triggered
Author:
Danny Daglas
  • Field Details

  • Constructor Details

    • StdinExtension

      public StdinExtension()
  • Method Details

    • init

      public void init(VariableManager vm, JRT jrt, AwkSettings settings)
      Called after the creation and before normal processing of the extension, pass in the Jawk Runtime Manager and the Variable Manager once.

      It is guaranteed init() is called before invoke() is called.

      Specified by:
      init in interface JawkExtension
      Overrides:
      init in class AbstractExtension
      Parameters:
      vm - Reference to the Variable Manager
      jrt - Reference to the Runtime
      settings - Reference to the settings
    • getExtensionName

      public String getExtensionName()
      Description copied from class: AbstractExtension

      getExtensionName.

      Specified by:
      getExtensionName in interface JawkExtension
      Overrides:
      getExtensionName in class AbstractExtension
      Returns:
      name of the extension package.
    • stdinHasInputFunction

      public int stdinHasInputFunction()
    • stdinGetlineFunction

      public Object stdinGetlineFunction()
    • stdinBlockFunction

      public BlockObject stdinBlockFunction(Object... args)