void Joystick::load(const XMLReader& root_reader) { std::string cfg_name; if (root_reader.read("name", cfg_name) && name == cfg_name) { // Read calibration data if (XMLReader reader = root_reader.get_section("calibration")) { std::vector<CalibrationData> calibration_data; const std::vector<XMLReader>& sections = reader.get_sections(); for(std::vector<XMLReader>::const_iterator i = sections.begin(); i != sections.end(); ++i) { CalibrationData data; //i->read("axis", ); //i->read("precision", ); i->read("invert", data.invert); i->read("center-min", data.center_min); i->read("center-max", data.center_max); i->read("range-min", data.range_min); i->read("range-max", data.range_max); calibration_data.push_back(data); } set_calibration(calibration_data); } { // Read axis mapping const std::vector<std::string>& cfg_axis_map = root_reader.get_string_list("axis-map"); std::vector<int> mapping; for(std::vector<std::string>::const_iterator i = cfg_axis_map.begin(); i != cfg_axis_map.end(); ++i) { int type = 0; int code = 0; str2event(*i, type, code); mapping.push_back(code); } set_axis_mapping(mapping); } { // Read button mapping const std::vector<std::string>& cfg_button_map = root_reader.get_string_list("button-map"); std::vector<int> mapping; for(std::vector<std::string>::const_iterator i = cfg_button_map.begin(); i != cfg_button_map.end(); ++i) { int type = 0; int code = 0; str2event(*i, type, code); mapping.push_back(code); } set_button_mapping(mapping); } } }
/* * This function will look at the line and pick out pieces of it. */ static int extract_timestamp(const char *b, event *e) { char *ptr, *tmp, *tnode, *ttype; e->node = NULL; tmp = strndupa(b, 120); ptr = strtok(tmp, " "); if (ptr) { // Check to see if this is the node info if (*ptr == 'n') { tnode = ptr+5; ptr = strtok(NULL, " "); } else tnode = NULL; // at this point we have type= ttype = ptr+5; // Now should be pointing to msg= ptr = strtok(NULL, " "); if (ptr) { if (*(ptr+9) == '(') ptr+=9; else ptr = strchr(ptr, '('); if (ptr) { // now we should be pointed at the timestamp char *eptr; ptr++; eptr = strchr(ptr, ')'); if (eptr) *eptr = 0; if (str2event(ptr, e)) { fprintf(stderr, "Error extracting time stamp (%s)\n", ptr); return 0; } else if ((start_time && e->sec < start_time) || (end_time && e->sec > end_time)) return 0; else { if (tnode) e->node = strdup(tnode); e->type = audit_name_to_msg_type(ttype); } return 1; } // else we have a bad line } // else we have a bad line } // else we have a bad line return 0; }
/* Returns 0 on success and 1 on error */ static int extract_timestamp(const char *b, au_event_t *e) { char *ptr, *tmp; int rc = 1; e->host = NULL; if (*b == 'n') tmp = strndupa(b, 340); else tmp = strndupa(b, 80); ptr = audit_strsplit(tmp); if (ptr) { // Optionally grab the node - may or may not be included if (*ptr == 'n') { e->host = strdup(ptr+5); (void)audit_strsplit(NULL);// Bump along to next one } // at this point we have type= ptr = audit_strsplit(NULL); if (ptr) { if (*(ptr+9) == '(') ptr+=9; else ptr = strchr(ptr, '('); if (ptr) { // now we should be pointed at the timestamp char *eptr; ptr++; eptr = strchr(ptr, ')'); if (eptr) *eptr = 0; if (str2event(ptr, e) == 0) rc = 0; } // else we have a bad line } // else we have a bad line } if (rc) free((void *)e->host); // else we have a bad line return rc; }