source: fact/FADctrl/FADctrl.cc

Last change on this file was 11289, checked in by ogrimm, 9 years ago
Fixed bug when changing active boards just before a run is started
File size: 1.7 KB
Line 
1//
2//  FADctrl
3//
4
5#include <stdio.h>
6#include <readline/history.h>
7#include <string>
8
9#include "FAD.h"
10
11using namespace std;
12
13const string READLINE_HIST_FILE = string(getenv("HOME"))+"/.history_FADctrl";
14
15// ================
16//   Main program
17// ================
18
19int main(int argc, char *argv[]) {
20
21  std::vector<std::string> List;
22 
23  // Board list from command line?
24  for (int i=1; i<argc; i++) List.push_back(argv[i]);
25 
26  // Uses getc() for readline library (allows interruption by signal) and load history buffer
27  rl_getc_function = getc;
28  read_history(READLINE_HIST_FILE.c_str());
29
30  if (system("clear") == -1) {
31        printf("Error with system() call\n");
32  }
33  printf("\n*** FADctrl (built %s, %s, revision %s) *** \n\n",__DATE__, __TIME__, REVISION);
34
35  // Construct main instance (static ensures destructor is called with exit())
36  static class FAD M(List);
37
38  // Do not kill process if writing to closed socket
39  signal(SIGPIPE, SIG_IGN);
40
41  // Command loop
42  char *Command;
43  std::string LastHist;
44
45  while (!M.ExitRequest) {
46    Command = readline("FADctrl> ");
47       
48        // Check for interruption by signal
49    if (Command == NULL) continue;
50
51        // Process exit request for reasons of responsiveness here
52        if (strcmp(Command, "exit") == 0) break;
53       
54        // Add command to history
55    if(strlen(Command) > 0 && LastHist != Command) {
56          add_history(Command);
57          LastHist = Command;
58        }
59
60    // Process command (use SendCommandNB(), see mail from C. Gaspar 18/2/2011)
61        DimClient::sendCommandNB(SERVER_NAME"/Command", Command);
62    free(Command);
63  }
64 
65  // Save history buffer 
66  int Ret = write_history(READLINE_HIST_FILE.c_str());
67  if (Ret != 0 ) printf("Error writing history file to '%s' (%s)\n", READLINE_HIST_FILE.c_str(), strerror(Ret));
68}
Note: See TracBrowser for help on using the repository browser.