main() { int c, i, j; i = linecount = 0; while ((c = getchar()) != EOF) { line[i] = c; i++; if (i > ((MAXLINE / TABSTOP) - 1)) { addLine(i); // start filling up 'line' again from 0 i = 0; // if we are about to go over the linecount, print what we have so far if (linecount >= MAXLINES) { printLines(); } } } // add any remaining characters to the list if (i > 0) { addLine(i); } printLines(); putchar('\n'); return 0; }
void Interface::viewComputerXPersons(QString id) { string command_string; QString command; QString d_id; clearConsole(); printLines(); printMenuHead("COMPUTER RELATIONS"); cout << request.outputComputerXPersons(id); printSimpleLines(); cout << "Type 'delete id' to delete relation or leave empty to return" << endl; printSimpleLines(); cout << "Query: "; getline(cin, command_string); command = request.extractCommand(QString::fromStdString(command_string)); if(command == "delete") { d_id = request.extractId(QString::fromStdString(command_string)); if(request.deleteRelation(id, d_id)) { string c_name = request.getComputer(id).getName().toStdString(); string p_name = request.getPerson(d_id).getName().toStdString(); setStatus("Relation of '" + c_name + "' to '" + p_name + "' deleted!"); } else { setStatus("Unable to delete relation"); } } }
void generateKwic(std::istream &in, std::ostream &out) { std::vector<std::vector<Word>> lines {readLines(in)}; std::vector<std::vector<Word>> preparedLines {prepareLines(lines)}; printLines(preparedLines, out); }
int main(int argc, char ** argv){ char * x[MAX_LINES]; int lines = readLines(x, MAX_LINES); printf("\nprintout the input:\n"); qsort(x,0,lines-1); printLines(x,lines); }
void Interface::viewCompsOrPersons() { newMenu("VIEW"); char ch = ' '; cout << "(1) utility menu for computer scientists\n" "(2) utility menu for computers\n" "enter anything else to go to main menu \n"; printLines(); cout << "Choice: "; cin.ignore(1, '\n'); ch = cin.get(); switch(ch) { case '1': viewPersons(); break; case '2': viewComputers(); break; default: break; } }
//========PRIVATE FUNCTIONS========== //--menus-- void Interface::addCompOrPerson() { newMenu("ADD VIEW"); char ch = ' '; cout << "(1) to add a computer scientist\n" "(2) to add a computer\n" "enter anything else to go to main menu \n"; printLines(); cout << "Choice: "; cin.ignore(1, '\n'); ch = cin.get(); switch(ch) { case '1': addPerson(); break; case '2': addComputer(); break; default: break; } }
void printLines(Line * l) { if (l != NULL) { printLines(l->prev); printf("\t\tLine %d, %d times\n", l->number, l->count); } }
int main(void) { if( (lines = readLines(nLinesData)) <= MAXLINES) { printf("The original:\n"); printLines(nLinesData); sort(nLinesData); printf("The result:\n"); printLines(nLinesData); return 0; } else { printf("error Too many lines input.\n"); return 1; } }
void printVariable(Variable * var) { if (var != NULL) { printVariable(var->left); printf("\tVariable %s, occured %d times:\n", var->name, var->count); printLines(var->last_line); printVariable(var->right); } }
void Editor::run() { while(true) { int ch = getch(); // Read the next typed character. std::string& line = lines.at(y); // Get the string that holds the information about the line we're on if(ch == '\r') { if(y < lines.size()) { lines.insert(lines.begin() + y + 1, ""); } else { lines.push_back(""); } y++; x = 0; } else if(ch == KEY_UP) { if(y > 0) { y--; } checkLineBounds(); } else if(ch == KEY_DOWN) { if(y < lines.size() - 1) { y++; } checkLineBounds(); } else if(ch == KEY_LEFT) { if(x > 0) { x--; } } else if(ch == KEY_RIGHT) { if(x < line.size()) { x++; } } else { if(x < line.length()) { line.insert(line.begin() + x, ch); } else { line += (char) ch; } x++; } printLines(); wmove(window, y, x); wrefresh(window); } }
int main(int argc, char *argv[]) { progname = argv[0]; char *infile = NULL; int optc, optid; while ((optc = getopt_long(argc, argv, GETOPTS, long_opts, &optid)) != -1) { switch (optc) { case 0: { if (long_opts[optid].flag == 0) { show_help = 1; } break; } case 'f': { infile = strdup(optarg); break; } default: { show_help = 1; break; } } } if (show_help || optind < argc) { printf("%d %d %d\n", show_help, optind, argc); showHelp(); return EXIT_FAILURE; } FILE *input_file = stdin; if (infile != NULL) { input_file = fopen(infile, "r"); if (input_file == NULL) { fprintf(stderr, "Unable to open file %s!\n", infile); return EXIT_FAILURE; } free(infile); } printLines(input_file); return EXIT_SUCCESS; }
int tacFile(FILE* fp) { const int bufIncrSize = 10; int lineCounter = 0; char** arrayLines = (char**) mymalloc((lineCounter + 1) * sizeof (char *)); char* buffer = (char*) mymalloc(10); char* line = (char*) mymalloc(1); *line = 0; while (readFile(buffer, bufIncrSize, fp)) { //lee del archivo de a 10 caracteres o hasta que encuentre fin de linea char *newLine = concatBuffer(line, buffer); //le concatena a line el contenido del buffer myfree(line); line = newLine; char lastCharacterBuffer = buffer[strlen(buffer) - 1]; arrayLines = storeNewLine(lastCharacterBuffer, &lineCounter, arrayLines, &line); } printLines(lineCounter, arrayLines); myfree(line); myfree(arrayLines); myfree(buffer); return (EXIT_SUCCESS); }
void Interface::searchResultsComputers(string search_string) { QVector<Computer> search_results = request.searchComputers(QString::fromStdString(search_string)); clearConsole(); printLines(); printMenuHead("SEARCH RESULTS"); if(search_results.size() > 0) { for(int i = 0; i < search_results.size(); i++) { cout << search_results[i] << endl; } } else { cout << "NO RESULTS(did you forget to prepend search string with a correct searchtype?)" << endl; } printSettingsStatus(); printStatus(); }
void Interface::addPerson() { clearConsole(); printLines(); printMenuHead("ADD PERSON"); Person temp; char ch; cin >> temp; cout << "Are you sure you want to add " << temp.getName().toStdString() << "?(y/n): "; cin >> ch; if(ch == 'y' || ch == 'Y') { if(request.addPerson(temp)) { setStatus("\"" + temp.getName().toStdString() + "\" added to computer scientists!"); } else { setStatus("\"" + temp.getName().toStdString() + "\" could not be added to computer scientists!"); } } }
/* * Read commands until we are told to stop. */ static void doCommands(void) { const char *cp; char *endbuf, buf[USERSIZE]; int len, num1, num2; smallint have1, have2; while (TRUE) { /* Returns: * -1 on read errors or EOF, or on bare Ctrl-D. * 0 on ctrl-C, * >0 length of input string, including terminating '\n' */ len = read_line_input(NULL, ": ", buf, sizeof(buf), /*timeout*/ -1); if (len <= 0) return; endbuf = &buf[len - 1]; while ((endbuf > buf) && isblank(endbuf[-1])) endbuf--; *endbuf = '\0'; cp = skip_blank(buf); have1 = FALSE; have2 = FALSE; if ((curNum == 0) && (lastNum > 0)) { curNum = 1; curLine = lines.next; } if (!getNum(&cp, &have1, &num1)) continue; cp = skip_blank(cp); if (*cp == ',') { cp++; if (!getNum(&cp, &have2, &num2)) continue; if (!have1) num1 = 1; if (!have2) num2 = lastNum; have1 = TRUE; have2 = TRUE; } if (!have1) num1 = curNum; if (!have2) num2 = num1; switch (*cp++) { case 'a': addLines(num1 + 1); break; case 'c': deleteLines(num1, num2); addLines(num1); break; case 'd': deleteLines(num1, num2); break; case 'f': if (*cp && !isblank(*cp)) { bb_error_msg("bad file command"); break; } cp = skip_blank(cp); if (*cp == '\0') { if (fileName) printf("\"%s\"\n", fileName); else puts("No file name"); break; } free(fileName); fileName = xstrdup(cp); break; case 'i': addLines(num1); break; case 'k': cp = skip_blank(cp); if ((*cp < 'a') || (*cp > 'z') || cp[1]) { bb_error_msg("bad mark name"); break; } marks[*cp - 'a'] = num2; break; case 'l': printLines(num1, num2, TRUE); break; case 'p': printLines(num1, num2, FALSE); break; case 'q': cp = skip_blank(cp); if (have1 || *cp) { bb_error_msg("bad quit command"); break; } if (!dirty) return; len = read_line_input(NULL, "Really quit? ", buf, 16, /*timeout*/ -1); /* read error/EOF - no way to continue */ if (len < 0) return; cp = skip_blank(buf); if ((*cp | 0x20) == 'y') /* Y or y */ return; break; case 'r': if (*cp && !isblank(*cp)) { bb_error_msg("bad read command"); break; } cp = skip_blank(cp); if (*cp == '\0') { bb_error_msg("no file name"); break; } if (!have1) num1 = lastNum; if (readLines(cp, num1 + 1)) break; if (fileName == NULL) fileName = xstrdup(cp); break; case 's': subCommand(cp, num1, num2); break; case 'w': if (*cp && !isblank(*cp)) { bb_error_msg("bad write command"); break; } cp = skip_blank(cp); if (!have1) { num1 = 1; num2 = lastNum; } if (*cp == '\0') cp = fileName; if (cp == NULL) { bb_error_msg("no file name specified"); break; } writeLines(cp, num1, num2); break; case 'z': switch (*cp) { case '-': printLines(curNum - 21, curNum, FALSE); break; case '.': printLines(curNum - 11, curNum + 10, FALSE); break; default: printLines(curNum, curNum + 21, FALSE); break; } break; case '.': if (have1) { bb_error_msg("no arguments allowed"); break; } printLines(curNum, curNum, FALSE); break; case '-': if (setCurNum(curNum - 1)) printLines(curNum, curNum, FALSE); break; case '=': printf("%d\n", num1); break; case '\0': if (have1) { printLines(num2, num2, FALSE); break; } if (setCurNum(curNum + 1)) printLines(curNum, curNum, FALSE); break; default: bb_error_msg("unimplemented command"); break; } } }
bool _flushDWARFLines(const PEImage& img, mspdb::Mod* mod, DWARF_LineState& state) { if(state.lineInfo.size() == 0) return true; unsigned int saddr = state.lineInfo[0].offset; unsigned int eaddr = state.lineInfo.back().offset; int segIndex = state.section; if (segIndex < 0) segIndex = img.findSection(saddr + state.seg_offset); if(segIndex < 0) { // throw away invalid lines (mostly due to "set address to 0") state.lineInfo.resize(0); return true; //return false; } // if(saddr >= 0x4000) // return true; const DWARF_FileName* dfn; if(state.file == 0) dfn = state.file_ptr; else if(state.file > 0 && state.file <= state.files.size()) dfn = &state.files[state.file - 1]; else return false; std::string fname = dfn->file_name; if(isRelativePath(fname) && dfn->dir_index > 0 && dfn->dir_index <= state.include_dirs.size()) { std::string dir = state.include_dirs[dfn->dir_index - 1]; if(dir.length() > 0 && dir[dir.length() - 1] != '/' && dir[dir.length() - 1] != '\\') dir.append("\\"); fname = dir + fname; } for(size_t i = 0; i < fname.length(); i++) if(fname[i] == '/') fname[i] = '\\'; if (!mod) { printLines(fname.c_str(), segIndex, img.findSectionSymbolName(segIndex), state.lineInfo.data(), state.lineInfo.size()); state.lineInfo.resize(0); return true; } #if 1 bool dump = false; // (fname == "cvtest.d"); //qsort(&state.lineInfo[0], state.lineInfo.size(), sizeof(state.lineInfo[0]), cmpAdr); #if 0 printf("%s:\n", fname.c_str()); for(size_t ln = 0; ln < state.lineInfo.size(); ln++) printf(" %08x: %4d\n", state.lineInfo[ln].offset + 0x401000, state.lineInfo[ln].line); #endif int rc = 1; unsigned int firstLine = state.lineInfo[0].line; unsigned int firstAddr = state.lineInfo[0].offset; unsigned int firstEntry = 0; unsigned int entry = 0; for(size_t ln = firstEntry; ln < state.lineInfo.size(); ln++) { if(state.lineInfo[ln].line < firstLine || state.lineInfo[ln].offset < firstAddr) { if(ln > firstEntry) { unsigned int length = state.lineInfo[entry-1].offset + 1; // firstAddr has been subtracted before if(dump) printf("AddLines(%08x+%04x, Line=%4d+%3d, %s)\n", firstAddr, length, firstLine, entry - firstEntry, fname.c_str()); rc = mod->AddLines(fname.c_str(), segIndex + 1, firstAddr, length, firstAddr, firstLine, (unsigned char*) &state.lineInfo[firstEntry], (ln - firstEntry) * sizeof(state.lineInfo[0])); firstLine = state.lineInfo[ln].line; firstAddr = state.lineInfo[ln].offset; firstEntry = entry; } } else if(ln > firstEntry && state.lineInfo[ln].offset == state.lineInfo[ln-1].offset) continue; // skip entries without offset change state.lineInfo[entry].line = state.lineInfo[ln].line - firstLine; state.lineInfo[entry].offset = state.lineInfo[ln].offset - firstAddr; entry++; } unsigned int length = eaddr - firstAddr; if(dump) printf("AddLines(%08x+%04x, Line=%4d+%3d, %s)\n", firstAddr, length, firstLine, entry - firstEntry, fname.c_str()); rc = mod->AddLines(fname.c_str(), segIndex + 1, firstAddr, length, firstAddr, firstLine, (unsigned char*) &state.lineInfo[firstEntry], (entry - firstEntry) * sizeof(state.lineInfo[0])); #else unsigned int firstLine = 0; unsigned int firstAddr = 0; int rc = mod->AddLines(fname.c_str(), segIndex + 1, saddr, eaddr - saddr, firstAddr, firstLine, (unsigned char*) &state.lineInfo[0], state.lineInfo.size() * sizeof(state.lineInfo[0])); #endif state.lineInfo.resize(0); return rc > 0; }
/* * Read commands until we are told to stop. */ static void doCommands(void) { const char *cp; char *endbuf, *newname, buf[USERSIZE]; int len, num1, num2, have1, have2; while (TRUE) { printf(": "); fflush(stdout); if (fgets(buf, sizeof(buf), stdin) == NULL) return; len = strlen(buf); if (len == 0) return; endbuf = &buf[len - 1]; if (*endbuf != '\n') { bb_error_msg("command line too long"); do { len = fgetc(stdin); } while ((len != EOF) && (len != '\n')); continue; } while ((endbuf > buf) && isblank(endbuf[-1])) endbuf--; *endbuf = '\0'; cp = buf; while (isblank(*cp)) cp++; have1 = FALSE; have2 = FALSE; if ((curNum == 0) && (lastNum > 0)) { curNum = 1; curLine = lines.next; } if (!getNum(&cp, &have1, &num1)) continue; while (isblank(*cp)) cp++; if (*cp == ',') { cp++; if (!getNum(&cp, &have2, &num2)) continue; if (!have1) num1 = 1; if (!have2) num2 = lastNum; have1 = TRUE; have2 = TRUE; } if (!have1) num1 = curNum; if (!have2) num2 = num1; switch (*cp++) { case 'a': addLines(num1 + 1); break; case 'c': deleteLines(num1, num2); addLines(num1); break; case 'd': deleteLines(num1, num2); break; case 'f': if (*cp && !isblank(*cp)) { bb_error_msg("bad file command"); break; } while (isblank(*cp)) cp++; if (*cp == '\0') { if (fileName) printf("\"%s\"\n", fileName); else printf("No file name\n"); break; } newname = strdup(cp); if (newname == NULL) { bb_error_msg("no memory for file name"); break; } if (fileName) free(fileName); fileName = newname; break; case 'i': addLines(num1); break; case 'k': while (isblank(*cp)) cp++; if ((*cp < 'a') || (*cp > 'a') || cp[1]) { bb_error_msg("bad mark name"); break; } marks[*cp - 'a'] = num2; break; case 'l': printLines(num1, num2, TRUE); break; case 'p': printLines(num1, num2, FALSE); break; case 'q': while (isblank(*cp)) cp++; if (have1 || *cp) { bb_error_msg("bad quit command"); break; } if (!dirty) return; printf("Really quit? "); fflush(stdout); buf[0] = '\0'; fgets(buf, sizeof(buf), stdin); cp = buf; while (isblank(*cp)) cp++; if ((*cp == 'y') || (*cp == 'Y')) return; break; case 'r': if (*cp && !isblank(*cp)) { bb_error_msg("bad read command"); break; } while (isblank(*cp)) cp++; if (*cp == '\0') { bb_error_msg("no file name"); break; } if (!have1) num1 = lastNum; if (readLines(cp, num1 + 1)) break; if (fileName == NULL) fileName = strdup(cp); break; case 's': subCommand(cp, num1, num2); break; case 'w': if (*cp && !isblank(*cp)) { bb_error_msg("bad write command"); break; } while (isblank(*cp)) cp++; if (!have1) { num1 = 1; num2 = lastNum; } if (*cp == '\0') cp = fileName; if (cp == NULL) { bb_error_msg("no file name specified"); break; } writeLines(cp, num1, num2); break; case 'z': switch (*cp) { case '-': printLines(curNum-21, curNum, FALSE); break; case '.': printLines(curNum-11, curNum+10, FALSE); break; default: printLines(curNum, curNum+21, FALSE); break; } break; case '.': if (have1) { bb_error_msg("no arguments allowed"); break; } printLines(curNum, curNum, FALSE); break; case '-': if (setCurNum(curNum - 1)) printLines(curNum, curNum, FALSE); break; case '=': printf("%d\n", num1); break; case '\0': if (have1) { printLines(num2, num2, FALSE); break; } if (setCurNum(curNum + 1)) printLines(curNum, curNum, FALSE); break; default: bb_error_msg("unimplemented command"); break; } } }
/* * Do the substitute command. * The current line is set to the last substitution done. */ static void subCommand(const char * cmd, NUM num1, NUM num2) { int delim; char * cp; char * oldStr; char * newStr; LEN oldLen; LEN newLen; LEN deltaLen; LEN offset; LINE * lp; LINE * nlp; BOOL globalFlag; BOOL printFlag; BOOL didSub; BOOL needPrint; char buf[USERSIZE]; if ((num1 < 1) || (num2 > lastNum) || (num1 > num2)) { fprintf(stderr, "Bad line range for substitute\n"); return; } globalFlag = FALSE; printFlag = FALSE; didSub = FALSE; needPrint = FALSE; /* * Copy the command so we can modify it. */ strcpy(buf, cmd); cp = buf; if (isBlank(*cp) || (*cp == '\0')) { fprintf(stderr, "Bad delimiter for substitute\n"); return; } delim = *cp++; oldStr = cp; cp = strchr(cp, delim); if (cp == NULL) { fprintf(stderr, "Missing 2nd delimiter for substitute\n"); return; } *cp++ = '\0'; newStr = cp; cp = strchr(cp, delim); if (cp) *cp++ = '\0'; else cp = ""; while (*cp) switch (*cp++) { case 'g': globalFlag = TRUE; break; case 'p': printFlag = TRUE; break; default: fprintf(stderr, "Unknown option for substitute\n"); return; } if (*oldStr == '\0') { if (searchString[0] == '\0') { fprintf(stderr, "No previous search string\n"); return; } oldStr = searchString; } if (oldStr != searchString) strcpy(searchString, oldStr); lp = findLine(num1); if (lp == NULL) return; oldLen = strlen(oldStr); newLen = strlen(newStr); deltaLen = newLen - oldLen; offset = 0; nlp = NULL; while (num1 <= num2) { offset = findString(lp, oldStr, oldLen, offset); if (offset < 0) { if (needPrint) { printLines(num1, num1, FALSE); needPrint = FALSE; } offset = 0; lp = lp->next; num1++; continue; } needPrint = printFlag; didSub = TRUE; dirty = TRUE; /* * If the replacement string is the same size or shorter * than the old string, then the substitution is easy. */ if (deltaLen <= 0) { memcpy(&lp->data[offset], newStr, newLen); if (deltaLen) { memcpy(&lp->data[offset + newLen], &lp->data[offset + oldLen], lp->len - offset - oldLen); lp->len += deltaLen; } offset += newLen; if (globalFlag) continue; if (needPrint) { printLines(num1, num1, FALSE); needPrint = FALSE; } lp = lp->next; num1++; continue; } /* * The new string is larger, so allocate a new line * structure and use that. Link it in in place of * the old line structure. */ nlp = (LINE *) malloc(sizeof(LINE) + lp->len + deltaLen); if (nlp == NULL) { fprintf(stderr, "Cannot get memory for line\n"); return; } nlp->len = lp->len + deltaLen; memcpy(nlp->data, lp->data, offset); memcpy(&nlp->data[offset], newStr, newLen); memcpy(&nlp->data[offset + newLen], &lp->data[offset + oldLen], lp->len - offset - oldLen); nlp->next = lp->next; nlp->prev = lp->prev; nlp->prev->next = nlp; nlp->next->prev = nlp; if (curLine == lp) curLine = nlp; free(lp); lp = nlp; offset += newLen; if (globalFlag) continue; if (needPrint) { printLines(num1, num1, FALSE); needPrint = FALSE; } lp = lp->next; num1++; } if (!didSub) fprintf(stderr, "No substitutions found for \"%s\"\n", oldStr); }
/* * Do the substitute command. * The current line is set to the last substitution done. */ static void subCommand(const char *cmd, int num1, int num2) { char *cp, *oldStr, *newStr, buf[USERSIZE]; int delim, oldLen, newLen, deltaLen, offset; LINE *lp, *nlp; int globalFlag, printFlag, didSub, needPrint; if (bad_nums(num1, num2, "substitute")) return; globalFlag = FALSE; printFlag = FALSE; didSub = FALSE; needPrint = FALSE; /* * Copy the command so we can modify it. */ strcpy(buf, cmd); cp = buf; if (isblank(*cp) || (*cp == '\0')) { bb_error_msg("bad delimiter for substitute"); return; } delim = *cp++; oldStr = cp; cp = strchr(cp, delim); if (cp == NULL) { bb_error_msg("missing 2nd delimiter for substitute"); return; } *cp++ = '\0'; newStr = cp; cp = strchr(cp, delim); if (cp) *cp++ = '\0'; else cp = (char*)""; while (*cp) switch (*cp++) { case 'g': globalFlag = TRUE; break; case 'p': printFlag = TRUE; break; default: bb_error_msg("unknown option for substitute"); return; } if (*oldStr == '\0') { if (searchString[0] == '\0') { bb_error_msg("no previous search string"); return; } oldStr = searchString; } if (oldStr != searchString) strcpy(searchString, oldStr); lp = findLine(num1); if (lp == NULL) return; oldLen = strlen(oldStr); newLen = strlen(newStr); deltaLen = newLen - oldLen; offset = 0; nlp = NULL; while (num1 <= num2) { offset = findString(lp, oldStr, oldLen, offset); if (offset < 0) { if (needPrint) { printLines(num1, num1, FALSE); needPrint = FALSE; } offset = 0; lp = lp->next; num1++; continue; } needPrint = printFlag; didSub = TRUE; dirty = TRUE; /* * If the replacement string is the same size or shorter * than the old string, then the substitution is easy. */ if (deltaLen <= 0) { memcpy(&lp->data[offset], newStr, newLen); if (deltaLen) { memcpy(&lp->data[offset + newLen], &lp->data[offset + oldLen], lp->len - offset - oldLen); lp->len += deltaLen; } offset += newLen; if (globalFlag) continue; if (needPrint) { printLines(num1, num1, FALSE); needPrint = FALSE; } lp = lp->next; num1++; continue; } /* * The new string is larger, so allocate a new line * structure and use that. Link it in place of * the old line structure. */ nlp = xmalloc(sizeof(LINE) + lp->len + deltaLen); nlp->len = lp->len + deltaLen; memcpy(nlp->data, lp->data, offset); memcpy(&nlp->data[offset], newStr, newLen); memcpy(&nlp->data[offset + newLen], &lp->data[offset + oldLen], lp->len - offset - oldLen); nlp->next = lp->next; nlp->prev = lp->prev; nlp->prev->next = nlp; nlp->next->prev = nlp; if (curLine == lp) curLine = nlp; free(lp); lp = nlp; offset += newLen; if (globalFlag) continue; if (needPrint) { printLines(num1, num1, FALSE); needPrint = FALSE; } lp = lp->next; num1++; } if (!didSub) bb_error_msg("no substitutions found for \"%s\"", oldStr); }
/* write here first, then move to hg/lib/genePred.c */ void printExons(char *snpName, struct genePred *gene, char *chrom, int start, int end, struct dnaSeq *seq) { int iExon = 0; // which exon int startExon = 0; int endExon = 0; struct dyString *dy = NULL; char *seqBuffer; int size; char *ptr = seq->dna; // actual nucleotide positions int exonStart = 0; int exonEnd = 0; // arg checking if (start > end) { fprintf(stderr, "error with %s (start exceeds end)\n", gene->name); return; } startExon = findExonPos(gene, start); endExon = findExonPos(gene, end); // more checking if (startExon == -1 || endExon == -1) { fprintf(stderr, "error with %s (startExon = %d; endExon = %d)\n", gene->name, startExon, endExon); return; } // simple case if (startExon == endExon) { // printf("simple case; all in one exon\n"); size = end - start + 1; seqBuffer = needMem(size); strncpy(seqBuffer, &ptr[start], size); printf("> %s %s:%d-%d (%s)\n", gene->name, chrom, start, end, snpName); printLines(stdout, seqBuffer, 50); freeMem(seqBuffer); // *seqBuffer = 0; return; } // printf("not simple case; flank in multiple exons\n"); // printf("startExon = %d; endExon = %d\n", startExon, endExon); // append to dyString dy = newDyString(512); // remainder of first exon exonEnd = gene->exonEnds[startExon-1]; size = exonEnd - start + 1; seqBuffer = needMem(size); strncpy(seqBuffer, &ptr[start], size); dyStringPrintf(dy, "%s", seqBuffer); freeMem(seqBuffer); // middle exons for (iExon = startExon + 1; iExon < endExon; iExon++) { exonStart = gene->exonStarts[iExon-1]; exonEnd = gene->exonEnds[iExon-1]; size = exonEnd - exonStart + 1; seqBuffer = needMem(size); strncpy(seqBuffer, &ptr[exonStart], size); dyStringPrintf(dy, "%s", seqBuffer); freeMem(seqBuffer); } // start of last exon exonStart = gene->exonStarts[endExon-1]; size = end - exonStart + 1; seqBuffer = needMem(size); strncpy(seqBuffer, &ptr[exonStart], size); dyStringPrintf(dy, "%s", seqBuffer); freeMem(seqBuffer); printf("> %s %s:%d-%d (%s)\n", gene->name, chrom, start, end, snpName); printLines(stdout, dy->string, 50); dyStringFree(&dy); }
void Interface::doCommand(QString command_string, char type) { QString command = request.extractCommand(command_string); QString id = request.extractId(command_string); clearConsole(); printLines(); if(type == 'p') //PERSON { if(request.getPerson(id).getId().isEmpty()) //needed to prevent crashes { setStatus("Person #" + id.toStdString() + " does not exist or is omitted!"); return; } printMenuHead(command.toUpper().toStdString() + " PERSON"); if(command == "edit") { editPerson(id); } else if(command == "delete") { deletePerson(id); } else if(command == "addr") { addPersonRelation(id); } else if(command == "viewr") { viewPersonXComputers(id); } } else if(type == 'c') //COMPUTER { if(request.getComputer(id).getId().isEmpty()) //needed to prevent crashes { setStatus("Computer #" + id.toStdString() + " does not exist!"); return; } printMenuHead(command.toUpper().toStdString() + " COMPUTER"); if(command == "edit") { editComputer(id); } else if(command == "delete") { deleteComputer(id); } else if(command == "addr") { addComputerRelation(id); } else if(command == "viewr") { viewComputerXPersons(id); } } }