Blame view

build2/epsilon-master/ion/src/shared/tools/event_parser.cpp 741 Bytes
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  /* This tools read human-readable events on stdin and outputs machine-readable
   * ones on stdout. */
  
  #include <iostream>
  #include <cassert>
  #include <ion/events.h>
  
  using namespace Ion::Events;
  
  int eventIndexFromName(std::string name) {
    for (int i=0; i<255; i++) {
      Event e(i);
      if (e.name() != nullptr && std::string(e.name()) == name) {
        return i;
      }
    }
    return -1;
  }
  
  int main(int argc, char * argv[]) {
    std::string eventName;
    while (std::getline(std::cin, eventName)) {
      int eventIndex = eventIndexFromName(eventName);
      if (eventIndex < 0) {
        std::cerr << "Error: Could not recognize event \"" << eventName << "\"" << std::endl;
        return -1;
      }
      std::cout << (unsigned char)eventIndex;
    }
  }