/* * read_secs() * Do sector reads */ static void read_secs(daddr_t start, void *buf, uint nsec) { struct msg m; /* * By default, we assume block I/O primitives are available */ if (can_blkio) { m.m_op = FS_BLKREAD | (can_dma ? 0 : M_READ); m.m_nseg = 1; m.m_buf = buf; m.m_buflen = stob(nsec); m.m_arg = nsec; m.m_arg1 = start; if (msg_send(ioport, &m) >= 0) { return; } } /* * Try it the older way if we can */ ASSERT((start+nsec) <= 0x007fffff, "read_secs: io read > 4G"); can_blkio = 0; m.m_op = FS_ABSREAD | (can_dma ? 0 : M_READ); m.m_nseg = 1; m.m_buf = buf; m.m_arg = m.m_buflen = stob(nsec); m.m_arg1 = stob(start); if (msg_send(ioport, &m) < 0) { ASSERT(0, "read_secs: io error"); } }
void Conf_LoadConfig() { configfile = fopen("config.txt", "r"); if (!configfile) { return; // just use the defaults from conf_init } else { while(!feof(configfile)) { strcpy(key,""); strcpy(value,""); fscanf(configfile,"%s :: %s\r\n",&key,&value); if (!strcmp("useTraceFunc",key)) useTraceFunc = stob(value); ForValue("useBrushFunc") useBrushFunc = stob(value); ForValue("tickRate") tickRate = clampatoi(value,MIN_TICKRATE,MAX_TICKRATE); ForValue("quakeDir") strncpy(quakeDir,value,sizeof(quakeDir)); ForValue("ttAverageFreq") ttAverageFreq = clampatoi(value,1,3600); ForValue("ttFileName") strncpy(ttFileName,value,sizeof(ttFileName)); } fclose(configfile); } }
boolean_t vm_external_within( vm_size_t new_size, vm_size_t old_size) { vm_size_t new_bytes; vm_size_t old_bytes; assert(new_size >= old_size); /* * "old_bytes" is calculated to be the actual amount of space * allocated for a map of size "old_size". */ old_bytes = stob(old_size); if (old_bytes <= SMALL_SIZE) old_bytes = SMALL_SIZE; else if (old_bytes <= LARGE_SIZE) old_bytes = power_of_2(old_bytes); /* * "new_bytes" is the map size required to map the "new_size" object. * Since the rounding algorithms are the same, we needn't actually * round up new_bytes to get the correct answer */ new_bytes = stob(new_size); return(new_bytes <= old_bytes); }
/* * write_secs() * Do sector writes * * This routine is much like read_secs() above, so check its comments * when reading this code. */ static void write_secs(daddr_t start, void *buf, uint nsec) { struct msg m; if (can_blkio) { m.m_op = FS_BLKWRITE; m.m_nseg = 1; m.m_buf = buf; m.m_buflen = stob(nsec); m.m_arg = nsec; m.m_arg1 = start; if (msg_send(ioport, &m) >= 0) { return; } } ASSERT((start+nsec) <= 0x007fffff, "write_secs: io write > 4G"); can_blkio = 0; m.m_op = FS_ABSWRITE; m.m_nseg = 1; m.m_buf = buf; m.m_arg = m.m_buflen = stob(nsec); m.m_arg1 = stob(start); if (msg_send(ioport, &m) < 0) { ASSERT(0, "write_secs: io error"); } }
Joystick Joystick::deserialize(std::string input){ Joystick joy; joy.is_xbox = stob(pullObject("\"is_xbox\"", input)); joy.type = std::stoi(pullObject("\"type\"",input)); joy.name = unquote(pullObject("\"name\"", input)); joy.buttons = std::stoi(pullObject("\"buttons\"", input)); joy.button_count = std::stoi(pullObject("\"button_count\"", input)); std::vector<int8_t> axes_deserialized = deserializeList(pullObject("\"axes\"",input), std::function<int8_t(std::string)>([&](std::string input){ return std::stoi(input);}), true); if(axes_deserialized.size() == joy.axes.size()){ joy.axes = axes_deserialized; } else { throw std::out_of_range("Exception: deserialization resulted in array of " + std::to_string(axes_deserialized.size()) + " axes, expected " + std::to_string(joy.axes.size())); } joy.axis_count = std::stoi(pullObject("\"axis_count\"", input)); std::vector<uint8_t> axis_types_deserialized = deserializeList(pullObject("\"axis_types\"",input), std::function<uint8_t(std::string)>([&](std::string input){ return std::stoi(input);}), true); if(axis_types_deserialized.size() == joy.axis_types.size()){ joy.axis_types = axis_types_deserialized; } else { throw std::out_of_range("Exception: deserialization resulted in array of " + std::to_string(axis_types_deserialized.size()) + " axis types, expected " + std::to_string(joy.axis_types.size())); } std::vector<int16_t> povs_deserialized = deserializeList(pullObject("\"povs\"",input), std::function<int16_t(std::string)>([&](std::string input){ return std::stoi(input);}), true); if(povs_deserialized.size() == joy.povs.size()){ joy.povs = povs_deserialized; } else { throw std::out_of_range("Exception: deserialization resulted in array of " + std::to_string(povs_deserialized.size()) + " povs, expected " + std::to_string(joy.povs.size())); } joy.pov_count = std::stoi(pullObject("\"pov_count\"", input)); joy.outputs = std::stoi(pullObject("\"outputs\"", input)); joy.left_rumble = std::stoi(pullObject("\"left_rumble\"", input)); joy.right_rumble = std::stoi(pullObject("\"right_rumble\"", input)); return joy; }
/* * index_buf() * Get a pointer to a run of data under a particular buf entry * * As a side effect, move us to front of list to make us relatively * undesirable for aging. */ void * index_buf(struct buf *b, uint index, uint nsec) { ASSERT_DEBUG((index+nsec) <= b->b_nsec, "index_buf: too far"); get(b); ll_movehead(&allbufs, b->b_list); if ((index == 0) && (nsec == 1)) { /* * Only looking at 1st sector. See about reading * only 1st sector, if we don't yet have it. */ if ((b->b_flags & B_SEC0) == 0) { /* * Load the sector, mark it as present */ read_secs(b->b_start, b->b_data, 1); b->b_flags |= B_SEC0; } } else if ((b->b_flags & B_SECS) == 0) { /* * Otherwise if we don't have the whole buffer, get * it now. Don't read in sector 0 if we already * have it. */ if (b->b_flags & B_SEC0) { read_secs(b->b_start + 1, (char *)b->b_data + SECSZ, b->b_nsec - 1); } else { read_secs(b->b_start, b->b_data, b->b_nsec); } b->b_flags |= (B_SEC0|B_SECS); } return((char *)b->b_data + stob(index)); }
bool Map::getFallbackBool(const std::string& fall) const { std::string fallback=getFallbackString(fall); if (fallback.empty()) return false; else return stob(fallback); }
/* * Return the number of bytes needed for a vm_external_map given the * size of the object to be mapped, i.e. the size of the map that was * created by vm_external_create. */ vm_size_t vm_external_map_size( vm_offset_t size) { vm_size_t bytes; bytes = stob(size); if (bytes != 0) if (bytes <= SMALL_SIZE) { bytes = SMALL_SIZE; } else { bytes = power_of_2(bytes); } return bytes; }
void vm_external_copy( vm_external_map_t old_map, vm_size_t old_size, vm_external_map_t new_map) { /* * Cannot copy non-existent maps */ if ((old_map == VM_EXTERNAL_NULL) || (new_map == VM_EXTERNAL_NULL)) return; /* * Copy old map to new */ memcpy(new_map, old_map, stob(old_size)); }
//_______________________________________________________________________________________________________ void parseConfig(std::string path) { struct stat buffer; if (stat(path.c_str(), &buffer) != 0) { printf("[MAIN] Error opening config file path \"%s\"\n", path.c_str()); printf("[MAIN] Using default config instead.\n"); fflush(stdout); return; } else { printf("[MAIN] Using config file \"%s\"\n", path.c_str()); fflush(stdout); } std::map<std::string, std::string> cfg; std::fstream cfg_file; cfg_file.open(path, std::fstream::in); // read configs from file while (!cfg_file.eof()) { std::string line; std::getline(cfg_file, line); // comment lines if (line.front() == '#' || line.front() == '/') continue; std::string key = line.substr(0, line.find(':')); std::string value = line.substr(line.find(':') + 1, std::string::npos); cfg[key] = value; } cfg_file.close(); // store configs m_i2c_bus = (int) std::stoi(cfg["i2c_bus"]); m_mpu_address = (uint8_t) std::stoi(cfg["mpu_address"]); m_dsp_resolution = (uint8_t) std::stoi(cfg["dsp_resolution"]); m_dsp_hands = (uint8_t) std::stoi(cfg["dsp_hands"]); m_log_level = std::stoi(cfg["log_level"]); m_alert_threshold = std::stoi(cfg["alert_threshold"]); m_start_imu = stob(cfg["start_imu"], m_start_imu); m_start_ldc = stob(cfg["start_ldc"], m_start_ldc); m_start_env = stob(cfg["start_env"], m_start_env); m_start_dsp = stob(cfg["start_dsp"], m_start_dsp); m_start_bat = stob(cfg["start_bat"], m_start_bat); m_colors = stob(cfg["colors"], m_colors); m_idonly = stob(cfg["idonly"], m_idonly); }
void vm_external_destroy( vm_external_map_t map, vm_size_t size) { vm_size_t bytes; if (map == VM_EXTERNAL_NULL) return; bytes = stob(size); if (bytes <= SMALL_SIZE) { bytes = SMALL_SIZE; } else { bytes = power_of_2(bytes); } kfree((vm_offset_t)map, bytes); }
vm_external_map_t vm_external_create( vm_offset_t size) { vm_size_t bytes; vm_external_map_t result = VM_EXTERNAL_NULL; bytes = stob(size); if (bytes <= SMALL_SIZE) { if ((result = (vm_external_map_t)kalloc(SMALL_SIZE)) != NULL) { memset(result, 0, SMALL_SIZE); } } else if (bytes <= LARGE_SIZE) { bytes = power_of_2(bytes); if ((result = (vm_external_map_t)kalloc(bytes)) != NULL) { memset(result, 0, bytes); } } return(result); }
BoolToken(string b): TokenWithValue(BOOL), val(stob(b)) {}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); this->setFixedWidth(400); processingDialog = new ProcessingDialog; output = new Output; about = new About; help = new Help; connect(this, SIGNAL(sendOutput(QString,QByteArray)), output, SLOT(receiveOutput(QString,QByteArray))); QFile prop("prop.fbxgui"); if(prop.exists()) { prop.open(QIODevice::ReadOnly); QTextStream in(&prop); ui->input_folder->setText(in.readLine()); ui->output_folder->setText(in.readLine()); ui->flipV->setChecked(stob(in.readLine())); ui->packC->setChecked(stob(in.readLine())); ui->showLog->setChecked(stob(in.readLine())); ui->maxM->setValue(in.readLine().toInt()); ui->maxB->setValue(in.readLine().toInt()); ui->maxW->setValue(in.readLine().toInt()); ui->fbx->setChecked(stob(in.readLine())); ui->g3db->setChecked(stob(in.readLine())); ui->g3dj->setChecked(stob(in.readLine())); ui->sinput_folder->setText(in.readLine()); ui->soutput_folder->setText(in.readLine()); ui->sflipV->setChecked(stob(in.readLine())); ui->spackC->setChecked(stob(in.readLine())); ui->sshowLog->setChecked(stob(in.readLine())); ui->smaxM->setValue(in.readLine().toInt()); ui->smaxB->setValue(in.readLine().toInt()); ui->smaxW->setValue(in.readLine().toInt()); ui->sfbx->setChecked(stob(in.readLine())); ui->sg3db->setChecked(stob(in.readLine())); ui->sg3dj->setChecked(stob(in.readLine())); prop.close(); } }
//_______________________________________________________________________________________________________ void parseArgs(int argc, char** argv) { // parse command line arguments // -h --help | display help message // --no-color | no color output // --id-only | only test for ID correctness // --config:path | parse config file at path // --dsp:[0/1] | enable/disable display test // --imu:[0/1] | enable/disable IMU test // --env:[0/1] | enable/disable EnvSens test // --ldc:[0/1] | enable/disable LDC test // --bat:[0/1] | enable/disable BatGauge test // if (argc == 1) { parseConfig("./platypus.conf"); } else { std::vector<std::string> args; args.assign(argv + 1, argv + argc); // check if custom config file is used, if not use ./platypus.conf bool cfg_chg = false; for (size_t i = 0; i < args.size(); ++i) { if (args[i].find("--config:") != std::string::npos) cfg_chg = true; } if (!cfg_chg) parseConfig("./platypus.conf"); // parse arguments for (size_t i = 0; i < args.size(); ++i) { if (args[i] == "-h" || args[i] == "--help") { printf("Usage: %s <ARGS>\n", argv[0]); printf("\n"); printf("No arguments: use config file './platypus.conf'\n"); printf("\n"); printf("arguments:\n"); printf("\t -h --help\t| display help message\n"); printf("\t --no-color\t| no color output\n"); printf("\t --id-only\t| only test for ID correctness\n"); printf("\t --config:path\t| parse config file at path\n"); printf("\t --dsp:[0/1]\t| enable/disable display test\n"); printf("\t --imu:[0/1]\t| enable/disable IMU test\n"); printf("\t --env:[0/1]\t| enable/disable EnvSens test\n"); printf("\t --ldc:[0/1]\t| enable/disable LDC test\n"); printf("\t --bat:[0/1]\t| enable/disable BatGauge test\n"); fflush(stdout); exit(0); } if (args[i] == "--no-color") m_colors = false; if (args[i] == "--id-only") m_idonly = true; if (args[i].find("--config:") != std::string::npos) parseConfig(args[i].substr(9)); if (args[i].find("--dsp:") != std::string::npos) m_start_dsp = stob(args[i].substr(6), m_start_dsp); if (args[i].find("--imu:") != std::string::npos) m_start_imu = stob(args[i].substr(6), m_start_imu); if (args[i].find("--env:") != std::string::npos) m_start_env = stob(args[i].substr(6), m_start_env); if (args[i].find("--ldc:") != std::string::npos) m_start_ldc = stob(args[i].substr(6), m_start_ldc); if (args[i].find("--bat:") != std::string::npos) m_start_bat = stob(args[i].substr(6), m_start_bat); } } }
void MainWindow::on_actionOpen_triggered() { QFile prop(QFileDialog::getOpenFileName(this, tr("Select File"), "prop.fbxgui", "Prop File (*.fbxgui)")); if(prop.exists()) { prop.open(QIODevice::ReadOnly); QTextStream in(&prop); ui->input_folder->setText(in.readLine()); ui->output_folder->setText(in.readLine()); ui->flipV->setChecked(stob(in.readLine())); ui->packC->setChecked(stob(in.readLine())); ui->showLog->setChecked(stob(in.readLine())); ui->maxM->setValue(in.readLine().toInt()); ui->maxB->setValue(in.readLine().toInt()); ui->maxW->setValue(in.readLine().toInt()); ui->fbx->setChecked(stob(in.readLine())); ui->g3db->setChecked(stob(in.readLine())); ui->g3dj->setChecked(stob(in.readLine())); ui->sinput_folder->setText(in.readLine()); ui->soutput_folder->setText(in.readLine()); ui->sflipV->setChecked(stob(in.readLine())); ui->spackC->setChecked(stob(in.readLine())); ui->sshowLog->setChecked(stob(in.readLine())); ui->smaxM->setValue(in.readLine().toInt()); ui->smaxB->setValue(in.readLine().toInt()); ui->smaxW->setValue(in.readLine().toInt()); ui->sfbx->setChecked(stob(in.readLine())); ui->sg3db->setChecked(stob(in.readLine())); ui->sg3dj->setChecked(stob(in.readLine())); prop.close(); } }
/* * resize_buf() * Indicate that the cached region is changing to newsize * * If "fill" is non-zero, the incremental contents are filled from disk. * Otherwise the buffer space is left uninitialized. * * Returns 0 on success, 1 on error. */ int resize_buf(daddr_t d, uint newsize, int fill) { char *p; struct buf *b; ASSERT_DEBUG(newsize <= EXTSIZ, "resize_buf: too large"); ASSERT_DEBUG(newsize > 0, "resize_buf: zero"); /* * If it isn't currently buffered, we don't care yet */ if (!(b = hash_lookup(bufpool, d))) { return(0); } /* * Current activity--move to end of age list */ ll_movehead(&allbufs, b->b_list); /* * Resize to current size is a no-op */ if (newsize == b->b_nsec) { return(0); } /* * Ok, we're going to do it, interlock */ get(b); /* * Get the buffer space */ ASSERT_DEBUG(!(fill && (newsize < b->b_nsec)), "resize_buf: fill && shrink"); p = realloc(b->b_data, stob(newsize)); if (p == 0) { return(1); } b->b_data = p; /* * If needed, fill from disk */ if (fill && (b->b_flags & B_SECS)) { ASSERT_DEBUG(newsize > b->b_nsec, "resize_buf: fill when shrinking"); read_secs(b->b_start + b->b_nsec, p + stob(b->b_nsec), newsize - b->b_nsec); } /* * Update buf and return success */ bufsize = (int)bufsize + ((int)newsize - (int)b->b_nsec); b->b_nsec = newsize; while (bufsize > coresec) { age_buf(); } return(0); }
/* * find_buf() * Given starting sector #, return pointer to buf */ struct buf * find_buf(daddr_t d, uint nsec, int flags) { struct buf *b; ASSERT_DEBUG(nsec > 0, "find_buf: zero"); ASSERT_DEBUG(nsec <= EXTSIZ, "find_buf: too big"); /* * If we can find it, this is easy */ b = hash_lookup(bufpool, d); if (b) { return(b); } /* * Get a buf struct */ b = malloc(sizeof(struct buf)); if (b == 0) { return(0); } /* * Make room in our buffer cache if needed */ while ((bufsize+nsec) > coresec) { age_buf(); } /* * Get the buffer space */ b->b_data = malloc(stob(nsec)); if (b->b_data == 0) { free(b); return(0); } /* * Add us to pool, and mark us very new */ b->b_list = ll_insert(&allbufs, b); if (b->b_list == 0) { free(b->b_data); free(b); return(0); } if (hash_insert(bufpool, d, b)) { ll_delete(b->b_list); free(b->b_data); free(b); return(0); } /* * Fill in the rest & return */ init_lock(&b->b_lock); b->b_start = d; b->b_nsec = nsec; b->b_locks = 0; b->b_handles = 0; b->b_nhandle = 0; if (flags & ABC_FILL) { b->b_flags = 0; } else { b->b_flags = B_SEC0 | B_SECS; } bufsize += nsec; /* * If ABC_BG, initiate fill now */ if (flags & ABC_BG) { qio(b, Q_FILLBUF); } return(b); }