Commit d7dcb5e1 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

add minimal commands mechanism

parent f16d5f59
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ add_subdirectory(src/signaltk/core)
add_subdirectory(src/signaltk/plot)
add_subdirectory(src/signaltk/util)

add_executable(signaltk src/signaltk_cli.cc)
add_executable(signaltk src/signaltk_cli.cc src/signaltk.cc)
target_link_libraries(signaltk signaltk-plot signaltk-graphics signaltk-util ${CAIRO_LIBRARIES})

add_subdirectory(test/plot)

src/signaltk.cc

0 → 100644
+46 −0
Original line number Diff line number Diff line
/**
 * This file is part of the "FnordMetric" project
 *   Copyright (c) 2018 Paul Asmuth
 *
 * FnordMetric is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License v3.0. You should have received a
 * copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */
#include <signaltk.h>
#include <iostream>

namespace signaltk {

const std::vector<Command> command_list {

  // command: img new
  Command {
    .name = {"img", "new"},
  },

};

int cmd(
    Context* ctx,
    const char** args,
    int arg_count) {
  for (const auto& cmd : command_list) {
    if (cmd.name.size() > arg_count) {
      continue;
    }

    for (size_t i = 0; i < cmd.name.size(); ++i) {
      if (cmd.name[i] != args[i]) {
        continue;
      }
    }

    return 0;
  }

  return -1;
}

} // namespace signaltk

src/signaltk.h

0 → 100644
+30 −0
Original line number Diff line number Diff line
/**
 * This file is part of the "FnordMetric" project
 *   Copyright (c) 2018 Paul Asmuth
 *
 * FnordMetric is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License v3.0. You should have received a
 * copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */
#pragma once
#include <stdlib.h>
#include <vector>
#include <string>

namespace signaltk {

struct Context {

};

struct Command {
  std::vector<std::string> name;
};

extern const std::vector<Command> command_list;

int cmd(Context*, const char** args, int arg_count);

} // namespace signaltk
+8 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/file.h>
#include <signaltk.h>
#include <signaltk/util/flagparser.h>
#include <signaltk/util/fileutil.h>
#include <signaltk/util/return_code.h>
@@ -145,7 +146,12 @@ int main(int argc, const char** argv) {
  }
  */

  auto rc = ReturnCode::success();
  signaltk::Context ctx;
  auto rc = signaltk::cmd(&ctx, argv + 1, argc - 1); // FIXME

  return rc.isSuccess() ? 0 : 1;
  if (rc == 0) {
    return EXIT_SUCCESS;
  } else {
    return EXIT_FAILURE;
  }
}