All Projects → thosakwe → T2b

thosakwe / T2b

Licence: gpl-3.0
A wicked-powerful text macro language for building binary files.

Programming Languages

macros
77 projects

Projects that are alternatives of or similar to T2b

Bcal
🔢 Storage and general-purpose calculator
Stars: ✭ 329 (-11.08%)
Mutual labels:  command-line
Tv
Quickly view (satellite) imagery directly in your terminal using Unicode 9.0 characters and true color.
Stars: ✭ 347 (-6.22%)
Mutual labels:  command-line
Tsukae
🧑‍💻📊 Show off your most used shell commands
Stars: ✭ 345 (-6.76%)
Mutual labels:  command-line
Laravel Desktop Notifier
💻 Send notifications to your desktop from your Laravel Artisan Commands. An JoliNotif wrapper for Laravel.
Stars: ✭ 333 (-10%)
Mutual labels:  command-line
Xidel
Command line tool to download and extract data from HTML/XML pages or JSON-APIs, using CSS, XPath 3.0, XQuery 3.0, JSONiq or pattern matching. It can also create new or transformed XML/HTML/JSON documents.
Stars: ✭ 335 (-9.46%)
Mutual labels:  command-line
Gandi.cli
command line interface to Gandi.net products using the public API
Stars: ✭ 349 (-5.68%)
Mutual labels:  command-line
Structopt
Parse command line arguments by defining a struct
Stars: ✭ 323 (-12.7%)
Mutual labels:  command-line
Terminal Link
Create clickable links in the terminal
Stars: ✭ 361 (-2.43%)
Mutual labels:  command-line
Cmd2
cmd2 - quickly build feature-rich and user-friendly interactive command line applications in Python
Stars: ✭ 342 (-7.57%)
Mutual labels:  command-line
Reminders Cli
A simple CLI for interacting with macOS reminders
Stars: ✭ 354 (-4.32%)
Mutual labels:  command-line
Towel
Throw in the towel.
Stars: ✭ 333 (-10%)
Mutual labels:  command-line
Bfs
A breadth-first version of the UNIX find command
Stars: ✭ 336 (-9.19%)
Mutual labels:  command-line
Sad
CLI search and replace | Space Age seD
Stars: ✭ 350 (-5.41%)
Mutual labels:  command-line
Go Tea
Tea provides an Elm inspired functional framework for interactive command-line programs.
Stars: ✭ 329 (-11.08%)
Mutual labels:  command-line
Speedtest
Command line client for speedtest.net written in Go
Stars: ✭ 361 (-2.43%)
Mutual labels:  command-line
Fd
A simple, fast and user-friendly alternative to 'find'
Stars: ✭ 19,851 (+5265.14%)
Mutual labels:  command-line
Gulp Cli
Command Line Interface for gulp.
Stars: ✭ 347 (-6.22%)
Mutual labels:  command-line
Jwt Cracker
Simple HS256 JWT token brute force cracker
Stars: ✭ 365 (-1.35%)
Mutual labels:  command-line
Bulksplash
A simple command line tool that lets you bulk download images from Unsplash
Stars: ✭ 362 (-2.16%)
Mutual labels:  command-line
Facebook Cli
💻 Facebook command line tool
Stars: ✭ 350 (-5.41%)
Mutual labels:  command-line

t2b

A wicked-powerful text macro language for building binary files. Supports comments, looping, Unicode, variables, conditionals, macros and recursion.

TLDR; Check out example/.

Pre-built binaries are available for Win64 and MacOS64.

Usage

$ t2b <filename> here
$ t2b # Read directly from stdin

t2b always writes to stdout. To output to a file, simply use a greater-than sign (>).

Language

Newlines are solely for the sake of readability; all whitespace is the same.

# This is a comment!
#
# Comments must be on their own line.

# Emit a byte. In DECIMAL.
u8 10

# Emit a byte in hex.
u8 0xa

# Octal
u16 0o777

# And, of course, binary.
u8 0b00001110

# Spit out a signed integer.
i64 25677

# Print a string (no line break)
str hello

# Print with a line break.
strl hello

# Wrap in quotes to capture whitespace.
strl "hello world!"

# Escapes are supported.
str "hello, world!\n"

# Unicode?
str "\u{1234}"

# Print a newline.
endl

# Do something 5 times.
# Indentation is purely for readability.
times 5
    u8 23
    u32 24
    times 10
        # We can nest loops
        str "50 times!!!"
    endtimes
endtimes

# Capture the output of another command.
# Oh, and store it into a variable.
set foo (u8 33)

# Access its value.
set bar (get foo)

# Emit its value 3 times.
times 3 get foo endtimes

# Create a simple macro.
macro emit_twice x
begin
    times 2 (get x)
endmacro

# Call it!
emit_twice 24

Why?

The need for such a program arose when I was working on writing a simple VM. Manually hex-editing files for an ever changing bytecode spec is tedious, error-prone, and most of all - sucky.

Now there's a lightweight way to do just that.

Supported Commands

  • u8...u64 - Emit unsigned integer
  • i8...i64 - Emit signed integer
  • f - Emit float
  • d - Emit double
  • hex - Toggle hex mode on/off (defaults to OFF)
  • str <expr> - Write a string
  • strl <expr> - Write a string AND newline
  • endl - Write a newline
  • not <expr> Boolean NOT a char
  • if <cond> <pred> endif Execute <pred> if <cond> == 1
  • get <expr> - Fetch the global variable named expr
  • set <expr1> <expr2> - Assign the global variable named expr1 to expr2
  • = - Compare two values, return 0 or 1
  • times <count> <pred> endtimes - Execute <pred> <count> times. i is always set to the current iteration's index.
  • macro <name> <param-names...> begin <pred> endmacro - Declare a custom macro named <name>.
  • return - End termination of the current macro. Exits the script if not in a macro.
  • size - Return the size of an item
  • len - Equivalent to C strlen

What's next?

It's now feasible to write a machine code compiler in shell. Hooray. Not sure why you would ever do that to yourself, though.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].