Skip to content

Commit

Permalink
flakes for hffix library and fixprint app
Browse files Browse the repository at this point in the history
fixprint default to color output.
  • Loading branch information
jamesdbrock committed Feb 19, 2024
1 parent 7b8c837 commit e59d422
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ util/bin
tags
README.html
test/data/*.fix
result
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,33 @@ for various parts of the library.

### Nix

The file `flake.nix` declares a *Nix* shell development environment which provides all
We have a `flake.nix`.

```
nix flake show github:jamesdbrock/hffix
```

#### Development

The `flake.nix` declares a *Nix* shell development environment which provides all
dependencies for every target in the `Makefile`, including *Doxygen*.
Enter the *Nix* shell by
[installing *Nix*](https://nixos.org/download.html)
and then running `nix develop` in this directory. From the `nix develop` prompt,
you will be able to build all `Makefile` targets.

#### Package

The *Nix* `hffix` package will provide the `hffix` C++ library.

#### Apps

Run the `fixprint` utility:

```
nix run github:jamesdbrock/hffix#fixprint
```

### Pull Requests

Pull requests welcome!
Expand Down
66 changes: 56 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,64 @@
inputs.flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
version = "1.4.0";
in
{
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [ doxygen stack gmp zlib ];
buildInputs = with pkgs; [ boost ];
LC_ALL = "C.UTF-8";
shellHook = ''
echo ""
echo ' hffix Development Environment'
echo ' To run the test suite: make test'
echo ""
rec {
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [ doxygen stack gmp zlib ];
buildInputs = with pkgs; [ boost ];
LC_ALL = "C.UTF-8";
shellHook = ''
echo ""
echo ' hffix Development Environment'
echo ' To run the test suite: make test'
echo ""
'';
};
packages = rec {
hffix = pkgs.stdenv.mkDerivation {
pname = "hffix";
inherit version;
src = ./include;
meta = with pkgs.lib; {
description = "Header-only C++ library for FIX (Financial Information eXchange) protocol";
license = licenses.mit;
platforms = platforms.all;
};
unpackPhase = ''
'';
buildPhase = ''
'';
installPhase = ''
mkdir -p $out/include
cp -r $src/* $out/include
'';
};
fixprint = pkgs.stdenv.mkDerivation {
pname = "fixprint";
inherit version;
srcs = [./util/src];
nativeBuildInputs = [ hffix ];
sourceRoot = ".";
meta = with pkgs.lib; {
description = "Print FIX messages from stdin to stdout in human-readable format";
license = licenses.mit;
platforms = platforms.all;
};
buildPhase = ''
$CXX -o fixprint src/fixprint.cpp
'';
installPhase = ''
mkdir -p $out/bin
mv fixprint $out/bin/fixprint
'';
};
};
apps = {
fixprint = {
type = "app";
program = "${packages.fixprint}/bin/fixprint";
};
};
});
}
15 changes: 12 additions & 3 deletions util/src/fixprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,24 @@ char buffer[1 << 20]; // Must be larger than the largest FIX message size.
int main(int argc, char** argv)
{
if (argc > 1 && ((0 == std::strcmp("-h", argv[1])) || (0 == std::strcmp("--help", argv[1])))) {
std::cout <<
std::cout <<
"fixprint [Options]\n\n"
"Reads raw FIX encoded data from stdin and writes annotated human-readable FIX to stdout.\n\n"
"Options:\n"
" -c --color Color output.\n";
" -c --color Color output.\n"
" --no-color No color output.\n\n";
exit(0);
}

bool color = argc > 1 && (0 == std::strcmp("-c", argv[1]) || 0 == std::strcmp("--color", argv[1]));
bool color = true;
if (argc > 1) {
if (0 == std::strcmp("-c", argv[1]))
color = true;
if (0 == std::strcmp("--color", argv[1]))
color = true;
if (0 == std::strcmp("--no-color", argv[1]))
color = false;
}

std::map<int, std::string> field_dictionary;
hffix::dictionary_init_field(field_dictionary);
Expand Down

0 comments on commit e59d422

Please sign in to comment.