source: fact/FADctrl/FADctrl.cc@ 11285

Last change on this file since 11285 was 11205, checked in by ogrimm, 13 years ago
Adaptions to allow compilation on Ubuntu
File size: 1.6 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 // Add command to history
52 if(strlen(Command) > 0 && LastHist != Command) {
53 add_history(Command);
54 LastHist = Command;
55 }
56
57 // Process command (use SendCommandNB(), see mail from C. Gaspar 18/2/2011)
58 DimClient::sendCommandNB(SERVER_NAME"/Command", Command);
59 free(Command);
60 }
61
62 // Save history buffer
63 int Ret = write_history(READLINE_HIST_FILE.c_str());
64 if (Ret != 0 ) printf("Error writing history file to '%s' (%s)\n", READLINE_HIST_FILE.c_str(), strerror(Ret));
65}
Note: See TracBrowser for help on using the repository browser.