atom* amaguq::read_pair(const std::string& s, unsigned& idx) { list* l; atom* car; atom* cdr; if (s[idx] == ')') { ++idx; return hp.h[2]; // empty list } car = reads(s, idx); gobble_whitespace(s, idx); if (s[idx] == '.') { ++idx; cdr = reads(s, idx); gobble_whitespace(s, idx); if (s[idx] != ')') { // expect ')' else throw excptn TODO } ++idx; } else { cdr = read_pair(s, idx); } l = new list(car, cdr); hp.alloc(l); return l; }
void dirdist_calc(void) { string sTemp; printf("Direction/Distance Calculator\n\n"); printf("You are at quadrant %d,%d sector %d,%d\n\n", q1, q2, /* @@@ cint(s1), cint(s2)); */ (int)s1, (int)s2); printf("Please enter initial X coordinate: "); reads(sTemp); c1 = atoi(sTemp); printf("Please enter initial Y coordinate: "); reads(sTemp); a = atoi(sTemp); printf("Please enter final X coordinate: "); reads(sTemp); w1 = atoi(sTemp); printf("Please enter final Y coordinate: "); reads(sTemp); x = atoi(sTemp); compute_vector(); }
queIntegRnd::queIntegRnd (FILE* f) { // генерация ключа keygen=random(1000)+1; // чтение параметров char buf[256]; reads(f, buf); strpar1 = strdup(buf); reads(f, buf); strpar2 = strdup(buf); // разбор параметров sscanf(strpar1, "%d %i %i\n", &group, &rmin, &rmax); // инициализация типа вопроса qtype = type; }
void intro(void) { string sTemp; printf ("\n\n"); printf (" *************************************\n"); printf (" * *\n"); printf (" * *\n"); printf (" * * * Super Star Trek * * *\n"); printf (" * *\n"); printf (" * *\n"); printf (" *************************************\n\n\n\n\n"); printf("\nDo you need instructions (y/n): "); reads(sTemp); if (sTemp[0] == 'y' || sTemp[0] == 'Y') showfile("startrek.doc"); printf ("\n\n\n\n"); printf(" ------*------\n"); printf(" ------------- `--- ------'\n"); printf(" `-------- --' / /\n"); printf(" \\\\------- --\n"); printf(" '-----------'\n"); printf("\n The USS Enterprise --- NCC - 1701\n\n\n"); }
Node::Node(const Block &blk) { // notice here char* mem = (char*)malloc(BLOCK_SIZE); memcpy(mem, blk.data, BLOCK_SIZE); isleaf = mem[0]; isroot = mem[1]; mem += 2*sizeof(char); int pSize = readi(mem), kSize = readi(mem), typeId = readi(mem), strLen = readi(mem); //system("pause"); int p = 0; for( int i = 0; i < pSize; i++ ) { p = readi(mem); P.push_back(p); } for( int i = 0; i < kSize; i++ ) { AttrType k; if( typeId == 0 ) { // int k = AttrType(readi(mem)); } else if( typeId == 1 ) { // float k = AttrType(readf(mem)); } else if( typeId == 2 ) { // string k = AttrType(reads(mem, strLen)); } K.push_back(k); } }
quest13::quest13(FILE* f) { char* buf = new char[256]; randomize(); keygen = random (1000) + 1; reads(f,buf); strpar1 = strdup(buf); reads(f,buf); strpar2 = strdup(buf); sscanf(strpar1,"%d %d",&amin,&amax); qtype = type; delete buf; }
void main() { clrscr(); reads(); write(); stored_names(); getch(); }
atom* amaguq::read(const std::string& s) { unsigned idx = 0; atom* a; a = reads(s, idx); a->interpreter = this; return a; }
/* * Read a line (ended by \n) from the specified file and call sepfield() to * break the line up into fields. */ static int getfields(FILE *fd) { int count; static char cmdline[1024]; do { count = reads(fileno(fd), cmdline, 1000); if (count<=0) return -1; count = sepfield(cmdline, 0); } while (count==0); return count; }
int main(int argc, char **argv) { int sockfd; /*pour l'adresse ip du serveur*/ struct sockaddr_in *srvaddr; /* taille de la reponse */ char buff[80]; int slen; /* Céer l'adresse du serveur*/ srvaddr = creerSock(argv[1], argv[2],SOCK_STREAM,&sockfd); if (connect(sockfd, (const struct sockaddr *) srvaddr, sizeof(*srvaddr)) < 0) { perror("Dasn connect "); } slen = reads(sockfd, buff, 80); write(0,buff,slen); close(sockfd); }
int main(int argc, char *argv[]) { ScopedMPIComm< MeraculousCounterOptions > world(argc, argv); MemoryUtils::getMemoryUsage(); std::string outputFilename = Options::getOptions().getOutputFile(); try { OptionsBaseInterface::FileListType &inputs = Options::getOptions().getInputFiles(); LOG_VERBOSE_OPTIONAL(1, world.rank() == 0, "Reading Input Files"); ReadSetStream reads(inputs, world.rank(), world.size()); LOG_DEBUG_GATHER(1, MemoryUtils::getMemoryUsage()); KS spectrum(world, KS::estimateRawKmers(world, inputs)); spectrum.buildKmerSpectrum(reads, false); if (Log::isVerbose(1)) { std::string hist = spectrum.getHistogram(false); LOG_VERBOSE_OPTIONAL(1, world.rank() == 0, "Collective Kmer Histogram\n" << hist); } std::string outputFilenameBase = outputFilename + ".mercount.m" + boost::lexical_cast<std::string>(KmerSizer::getSequenceLength()); spectrum.dumpCounts(outputFilenameBase, KmerSpectrumOptions::getOptions().getMinDepth()); outputFilenameBase = outputFilename + ".mergraph.m" + boost::lexical_cast<std::string>(KmerSizer::getSequenceLength()) + ".D" + boost::lexical_cast<std::string>(KmerSpectrumOptions::getOptions().getMinDepth()); spectrum.dumpGraphs(outputFilenameBase, KmerSpectrumOptions::getOptions().getMinDepth()); world.barrier(); LOG_VERBOSE_OPTIONAL(1, world.rank() == 0, "Finished"); } catch (std::exception &e) { LOG_ERROR(1, "MeraculousCounter threw an exception! Aborting...\n\t" << e.what()); world.abort(1); } catch (...) { LOG_ERROR(1, "MeraculousCounter threw an error!"); world.abort(1); } return 0; }
void sheild_control(void) { int i; string sTemp; if (d[7] < 0.0) { printf("Sheild Control inoperable\n"); return; } printf("Energy available = %d\n\n", e + s); printf("Input number of units to shields: "); reads(sTemp); printf("\n"); i = atoi(sTemp); if (i < 0 || s == i) { printf("<Sheilds Unchanged>\n\n"); return; } if (i >= e + s) { printf("Sheild Control Reports:\n"); printf(" 'This is not the Federation Treasury.'\n"); printf("<Sheilds Unchanged>\n\n"); return; } e = e + s - i; s = i; printf("Deflector Control Room report:\n"); printf(" 'Shields now at %d units per your command.'\n\n", s); }
void Node::resetByBlock(const Block &blk) { char* mem = (char*)malloc(BLOCK_SIZE); memcpy(mem, blk.data, BLOCK_SIZE); isleaf = mem[0]; isroot = mem[1]; mem += 2*sizeof(char); int pSize = readi(mem), kSize = readi(mem), typeId = readi(mem), strLen = readi(mem); //system("pause"); std::vector<AttrType>::iterator iter_K=K.begin(); for ( ;iter_K!=K.end();) iter_K=K.erase(iter_K); std::vector<int>::iterator iter_P=P.begin(); for ( ;iter_P!=P.end();) iter_P=P.erase(iter_P); int p = 0; for( int i = 0; i < pSize; i++ ) { p = readi(mem); P.push_back(p); } for( int i = 0; i < kSize; i++ ) { AttrType k; if( typeId == 0 ) { // int k = AttrType(readi(mem)); } else if( typeId == 1 ) { // float k = AttrType(readf(mem)); } else if( typeId == 2 ) { // string k = AttrType(reads(mem, strLen)); } K.push_back(k); } }
void end_of_game(void) { string sTemp; if (b9 > 0) { printf("The Federation is in need of a new starship commander for\n"); printf("a similar mission.\n\n"); printf("If there is a volunteer, let him step forward and"); printf(" enter 'aye':\n"); reads(sTemp); printf("\n"); if (! strncmp(sTemp, "aye", 3)) new_game(); } exit(0); }
atom* amaguq::reads(const std::string& s, unsigned& idx) { atom *a = nullptr; gobble_whitespace(s, idx); if ('#' == s[idx]) { if ('t' == s[idx + 1]) { idx += 2; a = hp.h[0]; } else if ('f' == s[idx + 1]) { idx += 2; a = hp.h[1]; } else if ('\\' == s[idx + 1]) { a = char_helper(s, idx); hp.alloc(a); } } else if ('"' == s[idx]) { a = str_helper(s, idx); hp.alloc(a); } else if ('(' == s[idx]) { a = read_pair(s, ++idx); } else if ((s[idx] >= 'a' && s[idx] <= 'z') || (s[idx] >= 'A' && s[idx] <= 'Z')) { a = symbol_helper(s, idx); hp.alloc(a); } else if (('\'' == s[idx])) { a = reads(s, ++idx); // TODO should the intermediate stuff be added to the heap? // TODO this adds another cons cell allocation around the quoted // symbol. Causing ('if ...) to not work. Should it? a = new quote(a); hp.alloc(a); } else { a = fixnum_helper(s, idx); hp.alloc(a); } return a; }
/* return 1 = loaded, 0 = not loaded, -1 = can't tell */ static int already_loaded (const char *name) { int fd, ret = 0; char buffer[4096]; fd = open ("/proc/modules", O_RDONLY); if (fd < 0) return -1; while ( reads ( fd, buffer, sizeof( buffer ))) { char *p; p = strchr (buffer, ' '); if (p) { const char *n; // Truncate buffer at first space and check for matches, with // the idiosyncrasy that _ and - are interchangeable because the // 2.6 kernel does weird things. *p = 0; for (p = buffer, n = name; ; p++, n++) { if (*p != *n) { if ((*p == '_' || *p == '-') && (*n == '_' || *n == '-')) continue; break; } // If we made it to the end, that's a match. if (!*p) { ret = 1; goto done; } } } } done: close (fd); return ret; }
void library_computer(void) { string sTemp; if (d[8] < 0.0) { printf("Library Computer inoperable\n"); return; } printf("Computer active and awaiting command: "); reads(sTemp); printf("\n"); if (! strncmp(sTemp, "0", 1)) galactic_record(); else if (! strncmp(sTemp, "1", 1)) status_report(); else if (! strncmp(sTemp, "2", 1)) torpedo_data(); else if (! strncmp(sTemp, "3", 1)) nav_data(); else if (! strncmp(sTemp, "4", 1)) dirdist_calc(); else if (! strncmp(sTemp, "5", 1)) galaxy_map(); else { printf("Functions available from Library-Computer:\n\n"); printf(" 0 = Cumulative Galactic Record\n"); printf(" 1 = Status Report\n"); printf(" 2 = Photon Torpedo Data\n"); printf(" 3 = Starbase Nav Data\n"); printf(" 4 = Direction/Distance Calculator\n"); printf(" 5 = Galaxy 'Region Name' Map\n\n"); } }
void phaser_control(void) { int i; int iEnergy; int h1, h; string sTemp; if (d[4] < 0.0) { printf("Phasers Inoperative\n\n"); return; } if (k3 <= 0) { printf("Science Officer Spock reports:\n"); printf(" 'Sensors show no enemy ships in this quadrant'\n\n"); return; } if (d[8] < 0.0) /* @@@ printf("Computer failure happers accuracy.\n"); */ printf("Computer failure hampers accuracy.\n"); printf("Phasers locked on target;\n"); printf("Energy available = %d units\n\n", e); printf("Number of units to fire: "); reads(sTemp); printf("\n"); iEnergy = atoi(sTemp); if (iEnergy <= 0) return; if (e - iEnergy < 0) { printf("Not enough energy available.\n\n"); return; } e = e - iEnergy; if (d[8] < 0.0) /* @@@ iEnergy = iEnergy * rnd(); */ iEnergy = (int)(iEnergy * rnd()); h1 = iEnergy / k3; for (i = 1; i <= 3; i++) { if (k[i][3] > 0) { /* @@@ h = (h1 / function_d(0) * (rnd() + 2)); */ h = (int)(h1 / function_d(0) * (rnd() + 2)); if (h <= .15 * k[i][3]) { printf("Sensors show no damage to enemy at "); printf("%d, %d\n\n", k[i][1], k[i][2]); } else { k[i][3] = k[i][3] - h; printf("%d unit hit on Klingon at sector ", h); printf("%d, %d\n", k[i][1], k[i][2]); if (k[i][3] <= 0) { printf("*** Klingon Destroyed ***\n\n"); k3--; k9--; z1 = k[i][1]; z2 = k[i][2]; strcpy(sA, " "); insert_in_quadrant(); k[i][3] = 0; g[q1][q2] = g[q1][q2] - 100; z[q1][q2] = g[q1][q2]; if (k9 <= 0) won_game(); } else /* @@@ printf("\n"); */ printf(" (Sensors show %d units remaining.)\n\n", k[i][3]); } } } klingons_shoot(); }
/* * This function builds a list of dependency rules from /lib/modules/`uname -r`/modules.dep. * It then fills every modules and aliases with their default options, found by parsing * modprobe.conf (or modules.conf, or conf.modules). */ static struct dep_t *build_dep(void) { int fd; struct utsname un; struct dep_t *first = NULL; struct dep_t *current = NULL; char *filename; int continuation_line = 0; int k_version; if (uname(&un)) bb_error_msg_and_die("can't determine kernel version"); k_version = 0; if (un.release[0] == '2') { k_version = un.release[2] - '0'; } filename = xasprintf(CONFIG_DEFAULT_MODULES_DIR"/%s/"CONFIG_DEFAULT_DEPMOD_FILE, un.release); fd = open(filename, O_RDONLY); if (ENABLE_FEATURE_CLEAN_UP) free(filename); if (fd < 0) { /* Ok, that didn't work. Fall back to looking in /lib/modules */ fd = open(CONFIG_DEFAULT_MODULES_DIR"/"CONFIG_DEFAULT_DEPMOD_FILE, O_RDONLY); if (fd < 0) { bb_error_msg_and_die("cannot parse " CONFIG_DEFAULT_DEPMOD_FILE); } } while (reads(fd, line_buffer, sizeof(line_buffer))) { int l = strlen(line_buffer); char *p = 0; while (l > 0 && isspace(line_buffer[l-1])) { line_buffer[l-1] = '\0'; l--; } if (l == 0) { continuation_line = 0; continue; } /* Is this a new module dep description? */ if (!continuation_line) { /* find the dep beginning */ char *col = strchr(line_buffer, ':'); char *dot = col; if (col) { /* This line is a dep description */ const char *mods; char *modpath; char *mod; /* Find the beginning of the module file name */ *col = '\0'; mods = bb_basename(line_buffer); /* find the path of the module */ modpath = strchr(line_buffer, '/'); /* ... and this is the path */ if (!modpath) modpath = line_buffer; /* module with no path */ /* find the end of the module name in the file name */ if (ENABLE_FEATURE_2_6_MODULES && (k_version > 4) && (col[-3] == '.') && (col[-2] == 'k') && (col[-1] == 'o')) dot = col - 3; else if ((col[-2] == '.') && (col[-1] == 'o')) dot = col - 2; mod = xstrndup(mods, dot - mods); /* enqueue new module */ if (!current) { first = current = xzalloc(sizeof(struct dep_t)); } else { current->m_next = xzalloc(sizeof(struct dep_t)); current = current->m_next; } current->m_name = mod; current->m_path = xstrdup(modpath); /*current->m_options = NULL; - xzalloc did it*/ /*current->m_isalias = 0;*/ /*current->m_depcnt = 0;*/ /*current->m_deparr = 0;*/ /*current->m_next = 0;*/ p = col + 1; } else /* this line is not a dep description */ p = NULL; } else /* It's a dep description continuation */ p = line_buffer; /* p points to the first dependable module; if NULL, no dependable module */ if (p && (p = skip_whitespace(p))[0] != '\0') { char *end = &line_buffer[l-1]; const char *deps; char *dep; char *next; int ext = 0; while (isblank(*end) || (*end == '\\')) end--; do { /* search the end of the dependency */ next = strchr(p, ' '); if (next) { *next = '\0'; next--; } else next = end; /* find the beginning of the module file name */ deps = bb_basename(p); if (deps == p) deps = skip_whitespace(deps); /* find the end of the module name in the file name */ if (ENABLE_FEATURE_2_6_MODULES && (k_version > 4) && (next[-2] == '.') && (next[-1] == 'k') && (next[0] == 'o')) ext = 3; else if ((next[-1] == '.') && (next[0] == 'o')) ext = 2; /* Cope with blank lines */ if ((next-deps-ext+1) <= 0) continue; dep = xstrndup(deps, next - deps - ext + 1); /* Add the new dependable module name */ current->m_depcnt++; current->m_deparr = xrealloc(current->m_deparr, sizeof(char *) * current->m_depcnt); current->m_deparr[current->m_depcnt - 1] = dep; p = next + 2; } while (next < end); } /* is there other dependable module(s) ? */ continuation_line = (line_buffer[l-1] == '\\'); } /* while (reads(...)) */ close(fd); /* * First parse system-specific options and aliases * as they take precedence over the kernel ones. * >=2.6: we only care about modprobe.conf * <=2.4: we care about modules.conf and conf.modules */ if (ENABLE_FEATURE_2_6_MODULES && (fd = open("/etc/modprobe.conf", O_RDONLY)) < 0) if (ENABLE_FEATURE_2_4_MODULES && (fd = open("/etc/modules.conf", O_RDONLY)) < 0) if (ENABLE_FEATURE_2_4_MODULES) fd = open("/etc/conf.modules", O_RDONLY); if (fd >= 0) { include_conf(&first, ¤t, line_buffer, sizeof(line_buffer), fd); close(fd); } /* Only 2.6 has a modules.alias file */ if (ENABLE_FEATURE_2_6_MODULES) { /* Parse kernel-declared module aliases */ filename = xasprintf(CONFIG_DEFAULT_MODULES_DIR"/%s/modules.alias", un.release); fd = open(filename, O_RDONLY); if (fd < 0) { /* Ok, that didn't work. Fall back to looking in /lib/modules */ fd = open(CONFIG_DEFAULT_MODULES_DIR"/modules.alias", O_RDONLY); } if (ENABLE_FEATURE_CLEAN_UP) free(filename); if (fd >= 0) { include_conf(&first, ¤t, line_buffer, sizeof(line_buffer), fd); close(fd); } /* Parse kernel-declared symbol aliases */ filename = xasprintf(CONFIG_DEFAULT_MODULES_DIR"/%s/modules.symbols", un.release); fd = open(filename, O_RDONLY); if (fd < 0) { /* Ok, that didn't work. Fall back to looking in /lib/modules */ fd = open(CONFIG_DEFAULT_MODULES_DIR"/modules.symbols", O_RDONLY); } if (ENABLE_FEATURE_CLEAN_UP) free(filename); if (fd >= 0) { include_conf(&first, ¤t, line_buffer, sizeof(line_buffer), fd); close(fd); } } return first; }
static struct dep_t *build_dep ( void ) { int fd; struct utsname un; struct dep_t *first = 0; struct dep_t *current = 0; char buffer [256]; char *filename = buffer; int continuation_line = 0; if ( uname ( &un )) return 0; strcpy ( filename, "/lib/modules/" ); strcat ( filename, un.release ); strcat ( filename, "/modules.dep" ); if ((fd = open ( filename, O_RDONLY )) < 0) return 0; while ( reads ( fd, buffer, sizeof( buffer ))) { char *p; int l = xstrlen ( buffer ); if ( buffer [l-1] == '\n' ) { buffer [l-1] = 0; l--; } if ( l == 0 ) { continuation_line = 0; continue; } if ( !continuation_line ) { char *col = strchr ( buffer, ':' ); if ( col ) { char *mods; char *mod; int ext = 0; *col = 0; mods = strrchr ( buffer, '/' ); if ( !mods ) mods = buffer; else mods++; if (( *(col-2) == '.' ) && ( *(col-1) == 'o' )) ext = 2; mod = xstrndup ( mods, col - mods - ext ); if ( !current ) { first = current = (struct dep_t *) malloc ( sizeof ( struct dep_t )); } else { current->m_next = (struct dep_t *) malloc ( sizeof ( struct dep_t )); current = current->m_next; } current->m_module = mod; current->m_depcnt = 0; current->m_deparr = 0; current->m_next = 0; //printf ( "%s:\n", mod ); p = col + 1; } else p = 0; } else p = buffer; if ( p && *p ) { char *end = &buffer [l-1]; char *deps = strrchr ( end, '/' ); char *dep; int ext = 0; while ( isblank ( *end ) || ( *end == '\\' )) end--; deps = strrchr ( p, '/' ); if ( !deps || ( deps < p )) { deps = p; while ( isblank ( *deps )) deps++; } else deps++; if (( *(end-1) == '.' ) && ( *end == 'o' )) ext = 2; /* Cope with blank lines */ if ((end-deps-ext+1) <= 0) continue; dep = xstrndup ( deps, end - deps - ext + 1 ); current->m_depcnt++; current->m_deparr = (char **) xrealloc ( current->m_deparr, sizeof ( char *) * current->m_depcnt ); current->m_deparr [current->m_depcnt - 1] = dep; //printf ( " %d) %s\n", current->m_depcnt, current->m_deparr [current->m_depcnt -1] ); } if ( buffer [l-1] == '\\' ) continuation_line = 1; else continuation_line = 0; } close ( fd ); return first; }
void photon_torpedoes(void) { /* @@@ int c2, c3, x3, y3, x5; */ int x3, y3, x5; string sTemp; double_t c1; if (p <= 0) { printf("All photon torpedoes expended\n"); return; } if (d[5] < 0.0) { printf("Photon Tubes not operational\n"); return; } printf("Course (0-9): "); reads(sTemp); printf("\n"); c1 = atof(sTemp); if (c1 == 9.0) c1 = 1.0; /* @@@ if (c1 < 0 || c1 > 9.0) */ if (c1 < 1.0 || c1 > 9.0) { printf("Ensign Chekov roports:\n"); printf(" Incorrect course data, sir!\n\n"); return; } e = e - 2; p--; /* @@@ c2 = cint(c1); */ /* @@@ c3 = c2 + 1; */ /* @@@ x1 = c[0][c2] + (c[0][c3] - c[0][c2]) * (c1 - c2); */ /* @@@ x2 = c[1][c2] + (c[1][c3] - c[1][c2]) * (c1 - c2); */ x1 = c[1][(int)c1] + (c[1][(int)c1 + 1] - c[1][(int)c1]) * (c1 - (int)c1); x2 = c[2][(int)c1] + (c[2][(int)c1 + 1] - c[2][(int)c1]) * (c1 - (int)c1); x = s1 + x1; y = s2 + x2; x3 = cint(x); /* @@@ note: this is a true integer round in the MS BASIC version */ y3 = cint(y); /* @@@ note: this is a true integer round in the MS BASIC version */ x5 = 0; printf("Torpedo Track:\n"); while (x3 >= 1 && x3 <= 8 && y3 >= 1 && y3 <= 8) { printf(" %d, %d\n", x3, y3); strcpy(sA, " "); z1 = x3; z2 = y3; string_compare(); if (z3 == 0) { torpedo_hit(); klingons_shoot(); return; } x = x + x1; y = y + x2; x3 = cint(x); /* @@@ note: this is a true integer round in the MS BASIC version */ y3 = cint(y); /* @@@ note: this is a true integer round in the MS BASIC version */ } printf("Torpedo Missed\n\n"); klingons_shoot(); }
static struct dep_t *build_dep ( void ) { int fd; struct utsname un; struct dep_t *first = 0; struct dep_t *current = 0; char buffer[256]; char *filename = buffer; int continuation_line = 0; if ( uname ( &un )) return 0; // check for buffer overflow in following code if ( xstrlen ( un.release ) > ( sizeof( buffer ) - 64 )) { return 0; } strcpy ( filename, "/lib/modules/" ); strcat ( filename, un.release ); strcat ( filename, "/modules.dep" ); if (( fd = open ( filename, O_RDONLY )) < 0 ) return 0; while ( reads ( fd, buffer, sizeof( buffer ))) { int l = xstrlen ( buffer ); char *p = 0; while ( isspace ( buffer [l-1] )) { buffer [l-1] = 0; l--; } if ( l == 0 ) { continuation_line = 0; continue; } if ( !continuation_line ) { char *col = strchr ( buffer, ':' ); if ( col ) { char *mods; char *mod; int ext = 0; *col = 0; mods = strrchr ( buffer, '/' ); if ( !mods ) mods = buffer; else mods++; if (( *(col-2) == '.' ) && ( *(col-1) == 'o' )) ext = 2; mod = xstrndup ( mods, col - mods - ext ); if ( !current ) { first = current = (struct dep_t *) xmalloc ( sizeof ( struct dep_t )); } else { current-> m_next = (struct dep_t *) xmalloc ( sizeof ( struct dep_t )); current = current-> m_next; } current-> m_module = mod; current-> m_isalias = 0; current-> m_depcnt = 0; current-> m_deparr = 0; current-> m_next = 0; //printf ( "%s:\n", mod ); p = col + 1; } else p = 0; } else p = buffer; if ( p && *p ) { char *end = &buffer [l-1]; char *deps = strrchr ( end, '/' ); char *dep; int ext = 0; while ( isblank ( *end ) || ( *end == '\\' )) end--; deps = strrchr ( p, '/' ); if ( !deps || ( deps < p )) { deps = p; while ( isblank ( *deps )) deps++; } else deps++; if (( *(end-1) == '.' ) && ( *end == 'o' )) ext = 2; /* Cope with blank lines */ if ((end-deps-ext+1) <= 0) continue; dep = xstrndup ( deps, end - deps - ext + 1 ); current-> m_depcnt++; current-> m_deparr = (char **) xrealloc ( current-> m_deparr, sizeof ( char *) * current-> m_depcnt ); current-> m_deparr [current-> m_depcnt - 1] = dep; //printf ( " %d) %s\n", current-> m_depcnt, current-> m_deparr [current-> m_depcnt -1] ); } if ( buffer [l-1] == '\\' ) continuation_line = 1; else continuation_line = 0; } close ( fd ); // alias parsing is not 100% correct (no correct handling of continuation lines within an alias) ! if (( fd = open ( "/etc/modules.conf", O_RDONLY )) < 0 ) if (( fd = open ( "/etc/conf.modules", O_RDONLY )) < 0 ) return first; continuation_line = 0; while ( reads ( fd, buffer, sizeof( buffer ))) { int l; char *p; p = strchr ( buffer, '#' ); if ( p ) *p = 0; l = xstrlen ( buffer ); while ( l && isspace ( buffer [l-1] )) { buffer [l-1] = 0; l--; } if ( l == 0 ) { continuation_line = 0; continue; } if ( !continuation_line ) { if (( strncmp ( buffer, "alias", 5 ) == 0 ) && isspace ( buffer [5] )) { char *alias, *mod; alias = buffer + 6; while ( isspace ( *alias )) alias++; mod = alias; while ( !isspace ( *mod )) mod++; *mod = 0; mod++; while ( isspace ( *mod )) mod++; // fprintf ( stderr, "ALIAS: '%s' -> '%s'\n", alias, mod ); if ( !current ) { first = current = (struct dep_t *) xmalloc ( sizeof ( struct dep_t )); } else { current-> m_next = (struct dep_t *) xmalloc ( sizeof ( struct dep_t )); current = current-> m_next; } current-> m_module = xstrdup ( alias ); current-> m_isalias = 1; if (( strcmp ( alias, "off" ) == 0 ) || ( strcmp ( alias, "null" ) == 0 )) { current-> m_depcnt = 0; current-> m_deparr = 0; } else { current-> m_depcnt = 1; current-> m_deparr = xmalloc ( 1 * sizeof( char * )); current-> m_deparr[0] = xstrdup ( mod ); } current-> m_next = 0; } } } close ( fd ); return first; }
void new_game(void) { string sTemp; initialize(); new_quadrant(); short_range_scan(); while(1) { if (s + e <= 10 && (e < 10 || d[7] < 0)) { printf("\n** Fatal Error ** "); printf("You've just stranded your ship in space.\n\n"); printf("You have insufficient maneuvering energy,"); printf(" and Shield Control is presently\n"); printf("incapable of cross circuiting to engine room!!\n\n"); end_of_time(); } printf("Command? "); reads(sTemp); printf("\n"); if (! strncmp(sTemp, "nav", 3)) course_control(); else if (! strncmp(sTemp, "srs", 3)) short_range_scan(); else if (! strncmp(sTemp, "lrs", 3)) long_range_scan(); else if (! strncmp(sTemp, "pha", 3)) phaser_control(); else if (! strncmp(sTemp, "tor", 3)) photon_torpedoes(); else if (! strncmp(sTemp, "she", 3)) sheild_control(); else if (! strncmp(sTemp, "dam", 3)) damage_control(); else if (! strncmp(sTemp, "com", 3)) library_computer(); else if (! strncmp(sTemp, "xxx", 3)) resign_commision(); else { printf("Enter one of the following:\n\n"); printf(" nav - To Set Course\n"); printf(" srs - Short Range Sensors\n"); printf(" lrs - Long Range Sensors\n"); printf(" pha - Phasers\n"); printf(" tor - Photon Torpedoes\n"); printf(" she - Sheild Control\n"); printf(" dam - Damage Control\n"); printf(" com - Library Computer\n"); printf(" xxx - Resign Command\n"); printf("\n"); } } }
void course_control(void) { int i; /* @@@ int c2, c3, q4, q5; */ int q4, q5; string sTemp; double_t c1; char sX[4] = "8"; printf("Course (0-9): "); reads(sTemp); printf("\n"); c1 = atof(sTemp); if (c1 == 9.0) c1 = 1.0; if (c1 < 0 || c1 > 9.0) { printf("Lt. Sulu roports:\n"); printf(" Incorrect course data, sir!\n\n"); return; } if (d[1] < 0.0) strcpy(sX, "0.2"); printf("Warp Factor (0-%s): ", sX); reads(sTemp); printf("\n"); w1 = atof(sTemp); if (d[1] < 0.0 && w1 > 0.21) { printf("Warp Engines are damaged. "); printf("Maximum speed = Warp 0.2.\n\n"); return; } if (w1 <= 0.0) return; if (w1 > 8.1) { printf("Chief Engineer Scott reports:\n"); printf(" The engines won't take warp %4.1f!\n\n", w1); return; } n = cint(w1 * 8.0); /* @@@ note: this is a real round in the original basic */ if (e - n < 0) { printf("Engineering reports:\n"); printf(" Insufficient energy available for maneuvering"); printf(" at warp %4.1f!\n\n", w1); if (s >= n && d[7] >= 0.0) { printf("Deflector Control Room acknowledges:\n"); printf(" %d units of energy presently deployed to shields.\n", s); } return; } klingons_move(); repair_damage(); strcpy(sA, " "); /* @@@ z1 = cint(s1); */ z1 = (int)s1; /* @@@ z2 = cint(s2); */ z2 = (int)s2; insert_in_quadrant(); /* @@@ c2 = cint(c1); */ /* @@@ c3 = c2 + 1; */ /* @@@ x1 = c[0][c2] + (c[0][c3] - c[0][c2]) * (c1 - c2); */ /* @@@ x2 = c[1][c2] + (c[1][c3] - c[1][c2]) * (c1 - c2); */ x1 = c[1][(int)c1] + (c[1][(int)c1 + 1] - c[1][(int)c1]) * (c1 - (int)c1); x2 = c[2][(int)c1] + (c[2][(int)c1 + 1] - c[2][(int)c1]) * (c1 - (int)c1); x = s1; y = s2; q4 = q1; q5 = q2; for (i = 1; i <= n; i++) { s1 = s1 + x1; s2 = s2 + x2; /* @@@ z1 = cint(s1); */ z1 = (int)s1; /* @@@ z2 = cint(s2); */ z2 = (int)s2; if (z1 < 1 || z1 >= 9 || z2 < 1 || z2 >= 9) { exceed_quadrant_limits(); complete_maneuver(); return; } string_compare(); if (z3 != 1) /* Sector not empty */ { s1 = s1 - x1; s2 = s2 - x2; printf("Warp Engines shut down at sector "); printf("%d, %d due to bad navigation.\n\n", z1, z2); i = n + 1; } } complete_maneuver(); }
/* * This function builds a list of dependency rules from /lib/modules/`uname -r`\modules.dep. * It then fills every modules and aliases with their default options, found by parsing * modprobe.conf (or modules.conf, or conf.modules). */ static struct dep_t *build_dep ( void ) { int fd; struct utsname un; struct dep_t *first = 0; struct dep_t *current = 0; char buffer[2048]; char *filename; int continuation_line = 0; int k_version; k_version = 0; if ( uname ( &un )) bb_error_msg_and_die("can't determine kernel version"); if (un.release[0] == '2') { k_version = un.release[2] - '0'; } filename = bb_xasprintf("/lib/modules/%s/modules.dep", un.release ); fd = open ( filename, O_RDONLY ); if (ENABLE_FEATURE_CLEAN_UP) free(filename); if (fd < 0) { /* Ok, that didn't work. Fall back to looking in /lib/modules */ if (( fd = open ( "/lib/modules/modules.dep", O_RDONLY )) < 0 ) { return 0; } } while ( reads ( fd, buffer, sizeof( buffer ))) { int l = strlen ( buffer ); char *p = 0; while ( l > 0 && isspace ( buffer [l-1] )) { buffer [l-1] = 0; l--; } if ( l == 0 ) { continuation_line = 0; continue; } /* Is this a new module dep description? */ if ( !continuation_line ) { /* find the dep beginning */ char *col = strchr ( buffer, ':' ); char *dot = col; if ( col ) { /* This line is a dep description */ char *mods; char *modpath; char *mod; /* Find the beginning of the module file name */ *col = 0; mods = strrchr ( buffer, '/' ); if ( !mods ) mods = buffer; /* no path for this module */ else mods++; /* there was a path for this module... */ /* find the path of the module */ modpath = strchr ( buffer, '/' ); /* ... and this is the path */ if ( !modpath ) modpath = buffer; /* module with no path */ /* find the end of the module name in the file name */ if ( ENABLE_FEATURE_2_6_MODULES && (k_version > 4) && ( *(col-3) == '.' ) && ( *(col-2) == 'k' ) && ( *(col-1) == 'o' ) ) dot = col - 3; else if (( *(col-2) == '.' ) && ( *(col-1) == 'o' )) dot = col - 2; mod = bb_xstrndup ( mods, dot - mods ); /* enqueue new module */ if ( !current ) { first = current = (struct dep_t *) xmalloc ( sizeof ( struct dep_t )); } else { current-> m_next = (struct dep_t *) xmalloc ( sizeof ( struct dep_t )); current = current-> m_next; } current-> m_name = mod; current-> m_path = bb_xstrdup(modpath); current-> m_options = NULL; current-> m_isalias = 0; current-> m_depcnt = 0; current-> m_deparr = 0; current-> m_next = 0; p = col + 1; } else /* this line is not a dep description */ p = 0; } else /* It's a dep description continuation */ p = buffer; while ( p && *p && isblank(*p)) p++; /* p points to the first dependable module; if NULL, no dependable module */ if ( p && *p ) { char *end = &buffer [l-1]; char *deps; char *dep; char *next; int ext = 0; while ( isblank ( *end ) || ( *end == '\\' )) end--; do { /* search the end of the dependency */ next = strchr (p, ' ' ); if (next) { *next = 0; next--; } else next = end; /* find the beginning of the module file name */ deps = strrchr ( p, '/' ); if ( !deps || ( deps < p )) { deps = p; while ( isblank ( *deps )) deps++; } else deps++; /* find the end of the module name in the file name */ if ( ENABLE_FEATURE_2_6_MODULES && (k_version > 4) && ( *(next-2) == '.' ) && ( *(next-1) == 'k' ) && ( *next == 'o' ) ) ext = 3; else if (( *(next-1) == '.' ) && ( *next == 'o' )) ext = 2; /* Cope with blank lines */ if ((next-deps-ext+1) <= 0) continue; dep = bb_xstrndup ( deps, next - deps - ext + 1 ); /* Add the new dependable module name */ current-> m_depcnt++; current-> m_deparr = (char **) xrealloc ( current-> m_deparr, sizeof ( char *) * current-> m_depcnt ); current-> m_deparr [current-> m_depcnt - 1] = dep; p = next + 2; } while (next < end); } /* is there other dependable module(s) ? */ if ( buffer [l-1] == '\\' ) continuation_line = 1; else continuation_line = 0; } close ( fd ); /* * First parse system-specific options and aliases * as they take precedence over the kernel ones. */ if (!ENABLE_FEATURE_2_6_MODULES || ( fd = open ( "/etc/modprobe.conf", O_RDONLY )) < 0 ) if (( fd = open ( "/etc/modules.conf", O_RDONLY )) < 0 ) fd = open ( "/etc/conf.modules", O_RDONLY ); if (fd >= 0) { include_conf (&first, ¤t, buffer, sizeof(buffer), fd); close(fd); } /* Only 2.6 has a modules.alias file */ if (ENABLE_FEATURE_2_6_MODULES) { /* Parse kernel-declared aliases */ filename = bb_xasprintf("/lib/modules/%s/modules.alias", un.release); if ((fd = open ( filename, O_RDONLY )) < 0) { /* Ok, that didn't work. Fall back to looking in /lib/modules */ fd = open ( "/lib/modules/modules.alias", O_RDONLY ); } if (ENABLE_FEATURE_CLEAN_UP) free(filename); if (fd >= 0) { include_conf (&first, ¤t, buffer, sizeof(buffer), fd); close(fd); } } return first; }
/* * This function reads aliases and default module options from a configuration file * (/etc/modprobe.conf syntax). It supports includes (only files, no directories). */ static void include_conf ( struct dep_t **first, struct dep_t **current, char *buffer, int buflen, int fd ) { int continuation_line = 0; // alias parsing is not 100% correct (no correct handling of continuation lines within an alias) ! while ( reads ( fd, buffer, buflen)) { int l; char *p; p = strchr ( buffer, '#' ); if ( p ) *p = 0; l = strlen ( buffer ); while ( l && isspace ( buffer [l-1] )) { buffer [l-1] = 0; l--; } if ( l == 0 ) { continuation_line = 0; continue; } if ( !continuation_line ) { if (( strncmp ( buffer, "alias", 5 ) == 0 ) && isspace ( buffer [5] )) { char *alias, *mod; if ( parse_tag_value ( buffer + 6, &alias, &mod )) { /* handle alias as a module dependent on the aliased module */ if ( !*current ) { (*first) = (*current) = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t )); } else { (*current)-> m_next = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t )); (*current) = (*current)-> m_next; } (*current)-> m_name = bb_xstrdup ( alias ); (*current)-> m_isalias = 1; if (( strcmp ( mod, "off" ) == 0 ) || ( strcmp ( mod, "null" ) == 0 )) { (*current)-> m_depcnt = 0; (*current)-> m_deparr = 0; } else { (*current)-> m_depcnt = 1; (*current)-> m_deparr = xmalloc ( 1 * sizeof( char * )); (*current)-> m_deparr[0] = bb_xstrdup ( mod ); } (*current)-> m_next = 0; } } else if (( strncmp ( buffer, "options", 7 ) == 0 ) && isspace ( buffer [7] )) { char *mod, *opt; /* split the line in the module/alias name, and options */ if ( parse_tag_value ( buffer + 8, &mod, &opt )) { struct dep_t *dt; /* find the corresponding module */ for ( dt = *first; dt; dt = dt-> m_next ) { if ( strcmp ( dt-> m_name, mod ) == 0 ) break; } if ( dt ) { if ( ENABLE_FEATURE_MODPROBE_MULTIPLE_OPTIONS ) { char* new_opt = NULL; while( ( opt = parse_command_string( opt, &new_opt ) ) ) { dt-> m_options = append_option( dt-> m_options, new_opt ); } } else { dt-> m_options = append_option( dt-> m_options, opt ); } } } } else if (( strncmp ( buffer, "include", 7 ) == 0 ) && isspace ( buffer [7] )) { int fdi; char *filename = buffer + 8; while ( isspace ( *filename )) filename++; if (( fdi = open ( filename, O_RDONLY )) >= 0 ) { include_conf(first, current, buffer, buflen, fdi); close(fdi); } } } } }
/* * This function reads aliases and default module options from a configuration file * (/etc/modprobe.conf syntax). It supports includes (only files, no directories). */ static void include_conf(struct dep_t **first, struct dep_t **current, char *buffer, int buflen, int fd) { int continuation_line = 0; // alias parsing is not 100% correct (no correct handling of continuation lines within an alias)! while (reads(fd, buffer, buflen)) { int l; *strchrnul(buffer, '#') = '\0'; l = strlen(buffer); while (l && isspace(buffer[l-1])) { buffer[l-1] = '\0'; l--; } if (l == 0) { continuation_line = 0; continue; } if (continuation_line) continue; if (is_conf_command(buffer, "alias")) { char *alias, *mod; if (parse_tag_value(buffer + 6, &alias, &mod)) { /* handle alias as a module dependent on the aliased module */ if (!*current) { (*first) = (*current) = xzalloc(sizeof(struct dep_t)); } else { (*current)->m_next = xzalloc(sizeof(struct dep_t)); (*current) = (*current)->m_next; } (*current)->m_name = xstrdup(alias); (*current)->m_isalias = 1; if ((strcmp(mod, "off") == 0) || (strcmp(mod, "null") == 0)) { /*(*current)->m_depcnt = 0; - done by xzalloc */ /*(*current)->m_deparr = 0;*/ } else { (*current)->m_depcnt = 1; (*current)->m_deparr = xmalloc(sizeof(char *)); (*current)->m_deparr[0] = xstrdup(mod); } /*(*current)->m_next = NULL; - done by xzalloc */ } } else if (is_conf_command(buffer, "options")) { char *mod, *opt; /* split the line in the module/alias name, and options */ if (parse_tag_value(buffer + 8, &mod, &opt)) { struct dep_t *dt; /* find the corresponding module */ for (dt = *first; dt; dt = dt->m_next) { if (strcmp(dt->m_name, mod) == 0) break; } if (dt) { if (ENABLE_FEATURE_MODPROBE_MULTIPLE_OPTIONS) { char* new_opt = NULL; while ((opt = parse_command_string(opt, &new_opt))) { dt->m_options = append_option(dt->m_options, new_opt); } } else { dt->m_options = append_option(dt->m_options, opt); } } } } else if (is_conf_command(buffer, "include")) { int fdi; char *filename; filename = skip_whitespace(buffer + 8); fdi = open(filename, O_RDONLY); if (fdi >= 0) { include_conf(first, current, buffer, buflen, fdi); close(fdi); } } else if (ENABLE_FEATURE_MODPROBE_BLACKLIST && (is_conf_command(buffer, "blacklist"))) { char *mod; struct dep_t *dt; mod = skip_whitespace(buffer + 10); for (dt = *first; dt; dt = dt->m_next) { if (strcmp(dt->m_name, mod) == 0) break; } if (dt) dt->m_isblacklisted = 1; } } /* while (reads(...)) */ }
void CArchiveMerge::Merge() { if ( _hasSpecial ) { // the last one is special archive _specialArchiveName = *_inputFilenames.rbegin(); vector < string >::iterator ite = _inputFilenames.end() - 1; _special_owner = _inputFilenames.size() - 1; _inputFilenames.erase( ite ); _specialArchiveEmpty = false; _specialReader.Open( _specialArchiveName ); if ( !_specialArchiveEmpty ) { _specialArchiveEmpty = !_specialReader.LoadNextRead( _specialAl ); if ( !_specialArchiveEmpty ) *_readNo = *_readNo + 1; } } unsigned int nTemp = _inputFilenames.size(); // sanity check if ( nTemp == 0 ) { printf("ERROR: There is no temporary archive.\n"); exit(1); } // initialize MOSAIK readers for all temp files vector< MosaikReadFormat::CAlignmentReader* > readers; SortNMergeUtilities::OpenMosaikReader( readers, _inputFilenames ); Mosaik::AlignedRead mr; unsigned int nDone = 0; vector< bool > done(nTemp, false); vector< SortNMergeUtilities::AlignedReadPair > reads(nTemp); // prepare BAM writers _sBam.Open( _outputFilename + ".special.bam", _sHeader ); _rBam.Open( _outputFilename + ".bam", _rHeader ); // pick the min one vector< SortNMergeUtilities::AlignedReadPair >::iterator ite; Mosaik::AlignedRead minRead; bool isDone = false; while ( !isDone ) { //SortNMergeUtilities::FindMinElement(reads, ite); minRead.Clear(); for ( unsigned int i = 0; i < nTemp; i++ ) { if ( !SortNMergeUtilities::LoadNextReadPair(readers[i], i, reads) ) { done[i] = true; nDone++; isDone = true; } else { UpdateReferenceIndex( reads[i].read, i ); *_readNo = *_readNo + 1; if ( i == 0 ) minRead = reads[i].read; else { minRead.Mate1Alignments.push_back( reads[i].read.Mate1Alignments[0] ); if ( _isPairedEnd ) minRead.Mate2Alignments.push_back( reads[i].read.Mate2Alignments[0] ); } } } // sanity check if ( isDone && ( nDone != nTemp ) ) { cout << "ERROR: The number of reads in archives do not match." << endl; exit(1); } if ( !isDone ) { WriteAlignment( minRead ); CalculateStatisticsCounters( minRead ); } } // Close BAMs _sBam.Close(); //_uBam.Close(); _rBam.Close(); // close readers SortNMergeUtilities::CloseMosaikReader( readers ); if ( _hasSpecial ) _specialReader.Close(); }
static dsk_err_t unsqueeze(SQ_COMPRESS_DATA *self) { dsk_err_t err; unsigned short magic, checksum; unsigned char c; unsigned short dictlen; unsigned short nd; unsigned short node; signed short code; self->ck_sum = 0; err = readu(self, &magic); if (err) return err; if (magic != MAGIC) return DSK_ERR_COMPRESS; err = readu(self, &checksum); /* Filename (skip) */ do { err = readc(self, &c); if (err) return err; } while (c); /* Dictionary length */ err = readu(self, &dictlen); if (err) return err; if (dictlen > MAXNODE) return DSK_ERR_COMPRESS; /* Dictionary */ for (nd = 0; nd < dictlen; nd++) { err = reads(self, &self->huf_node[nd].left); if (err) return err; err = reads(self, &self->huf_node[nd].right); if (err) return err; } /* Now start decoding data */ self->huf_out = 0; self->huf_nout = 8; node = 0; rle_reset(self); /* if dictlen == 0, the file is empty */ if (dictlen) while (1) { if (self->huf_nout == 8) { self->huf_nout = 0; err = readc(self, &self->huf_out); if (err) return err; } code = self->huf_out & st_masks[self->huf_nout]; ++self->huf_nout; if (code) code = self->huf_node[node].right; else code = self->huf_node[node].left; if (code < 0) { if (-1 - code == SQ_EOF) break; /* Reached EOF */ err = wrbyte(self, (unsigned char)(-1 - code)); if (err) return err; node = 0; } else node = code; } if (self->rle_char != -1) { err = ckputc(self, (unsigned char)(self->rle_char)); if (err) return err; } if (checksum != self->ck_sum) return DSK_ERR_COMPRESS; return DSK_ERR_OK; }