Code Monkey home page Code Monkey logo

trident's Introduction

Trident: The multiple-pipe system

Trident provides an easy way to pipe the output of one command to not just one but many targets. These targets can be other commands, or files, and it can be filtered (line-wise) through a regular expression.

Introduction

A trident file is split into Jobs, which consist of

  • A job name. A valid job name starts with either a letter or an underscore, followed by zero or more letters, digits or underscores. That means, job0 is a valid name, but 0job is not.
  • A command. This is any program, along with any number of arguments. Arguments which contain any of the reserved words JOB, CMD, OUT or FILE must be set in quotation marks (either single or double quotes are allowed).
  • One or more targets. A target can either be a file, or another job. A target can also contain a regular expression, in which case the output of this job will be filtered through this RegEx, and only those lines which match are passed to the actual target.

Syntax

To define a new job, use the keyword JOB followed by the job name. Then, the keyword CMD is followed by the program and its arguments. Finally, the keyword OUT indicates the start of the list of targets. A target consists of an optional RegEx (enclosed in /re/), either the keyword FILE and the name of a file (absolute or relative path), or JOB followed by the job name. The special file names stdout and stderr are reserved for their standard usage.

To invert a regular expression (and thus output every line not matching it), precede it by an exclamation mark: ! /re/.

Examples

This example file in essence recreates the functionality of grep:

JOB repeat
CMD cat
OUT
	- /regular exression/ FILE stdout

A sightly more sophisticated example might read URLs and store the associated IPs in a file.

JOB repeat
CMD cat
OUT
	- /^\([0-9]\{1,3\}.\)\{3\}[0-9]\{1,3\}$/ FILE ips.dat
	- /\w/ JOB query_dns

JOB query_dns
CMD dig +short a -f -
OUT
	- FILE queried_ips.dat

In this example, the main job reads data from stdin, and all lines that match a (very crude) match for an IP are written directly to a file. Those lines that contain at least one word character are queried from a DNS first, and then written to a different file. Note that no two jobs can access the same file at the same time (except for stdout and stderr).

Command line interface

Trident takes as command line arguments the paths to the input files, which are read in the order that they appear in. All files are considered as one continuous stream of input.

After parsing all input files, by default trident executes the first job defined in the input. This behaviour can be overwritten by using the command line option -s to explicitly provide a job name:

./trident example.tr -s latex

Compilation

Trident uses Flex and Bison/Yacc for parsing input, so both of those need to be installed.

This repository uses CMake as its build system, so to compile trident simply run

mkdir build
cd build
cmake ..
make -j

After finishing the compilation, an executable file called trident will be created in the directory build. If you want to install the program system-wide, additionally run

sudo make install

trident's People

Contributors

mgessinger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.