From e59d422d50ab0a2e4936cef28156f0f58fe6ac10 Mon Sep 17 00:00:00 2001 From: James Brock Date: Mon, 19 Feb 2024 20:04:14 +0900 Subject: [PATCH] flakes for hffix library and fixprint app fixprint default to color output. --- .gitignore | 1 + README.md | 22 ++++++++++++++- flake.nix | 66 ++++++++++++++++++++++++++++++++++++------- util/src/fixprint.cpp | 15 ++++++++-- 4 files changed, 90 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index d0931db..262e0cd 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ util/bin tags README.html test/data/*.fix +result diff --git a/README.md b/README.md index dca7e49..ba46274 100644 --- a/README.md +++ b/README.md @@ -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! diff --git a/flake.nix b/flake.nix index 072097f..1e403a9 100644 --- a/flake.nix +++ b/flake.nix @@ -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"; }; + }; }); } diff --git a/util/src/fixprint.cpp b/util/src/fixprint.cpp index 78b8b08..306dd75 100644 --- a/util/src/fixprint.cpp +++ b/util/src/fixprint.cpp @@ -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 field_dictionary; hffix::dictionary_init_field(field_dictionary);