0.0.21 • Published 9 years ago

c-format-stream v0.0.21

Weekly downloads
3
License
GPL v3
Repository
github
Last release
9 years ago

c-format-stream

A Transform stream to format C and C-like code. It's intended to work like clang-format, but it's a lot more opinionated (and, you'll find, somewhat dumber, although there are some cool benefits). It's mostly intended as a cleaning tool for preprocessors such as compp, but you'll find it also works well on its own if you need a standalone C formatter to plug into your other scripts. It scrubs the input with regex and then applies indentation and newlines as necessary.

Usage

Command-line

Install with npm install -g c-format-stream. The binary is named c-format.

$ c-format -h

  Usage: c-format INFILE [OUTFILE] [-hvni]

  INFILE should be "-" for stdin. OUTFILE defaults to stdout.

  -h show this help and exit
  -v show version number and exit
  -n number of newlines to preserve
  -i type of indentation string

  For the '-i' argument, strings of type 'sN', where N is some
  nonnegative integer, or 't' are accepted. The 'sN' type says
  to use N spaces for indentation, while 't' says to use tabs.

  Example: c-format test.c -n4 -is3

Node Module

var CFormatStream = require('c-format-stream');
var formattedStream = getReadableStreamSomehow().pipe(new CFormatStream({
  numNewlinesToPreserve: 3, // cuts off after this
                            // enter 0 to destroy all empty newlines
  indentationString: "\t"   // use tabs for indentation
}));

// fires when stream has no more data
formattedStream.on('end', function(){
  doSomethingWhenStreamIsDone();
});

// an error has occurred! >=(
formattedStream.on('error', function(err){
  doSomethingOnError(err);
});

As it inherits from the Transform stream interface, this stream can use both the standard readable and writable interfaces detailed in the node documentation.

Applications

This was written to help test compp, the preprocessor part of composter, a C compiler written in coffeescript. Both are in active development, so feel free to check out either of those two projects if you're interested in this one.

LICENSE

GPL v3

0.0.21

9 years ago

0.0.20

9 years ago

0.0.19

9 years ago

0.0.18

9 years ago

0.0.17

9 years ago

0.0.16

9 years ago

0.0.15

9 years ago

0.0.14

9 years ago

0.0.13

9 years ago

0.0.12

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago

0.0.0

9 years ago