// input everything between \begin{} and \end{} void LatexTableModel::setContent(const QString &text) { QStringList sourceLines(text.split("\\\\")); for (int i=0; i<sourceLines.count(); i++) { QString pre; QString line = sourceLines.at(i).trimmed(); if (i==sourceLines.count()-1 && line.isEmpty()) break; // last empty line bool recheck = true; while (line.startsWith("\\") && recheck) { recheck = false; foreach (const QString &cmd, metaLineCommands) { if (line.startsWith(cmd)) { int behind; getCommandOptions(line, cmd.length(), &behind); pre.append(line.left(behind)); line = line.mid(behind).trimmed(); recheck = true; break; } } } LatexTableLine *ltl = new LatexTableLine(this); if (!pre.isEmpty()) ltl->setMetaLine(pre); if (!line.isEmpty()) ltl->setColLine(line); lines.append(ltl); } /* *** alternative more efficient ansatz *** int len = text.length(); int pos=skipWhitespace(text); int start = pos; LatexTableLine *ltl = new LatexTableLine(this); bool hasMetaContent = false; while (pos < len) { if (text.at(pos) == '\\') { if (pos < len && text.at(pos+1) == '\\') { ltl->setColStr(text.mid(start, pos-start)); pos+=2; start=pos; } else { QString cmd; int end = getCommand(text, cmd, pos); if (metaLineCommands.contains(cmd)) { QStringList args; getCommandOptions(text, end, end); hasMetaContent = true; } } } pos = skipWhitespace(pos); } */ }
void LatexTables::alignTableCols(QDocumentCursor &cur){ QString text = getTableText(cur); if (!cur.hasSelection()) return; QString indentation = cur.selectionStart().line().indentation(); // split off \begin and \end parts int index = text.indexOf("\\begin{")+6; int cellsStart; QList<CommandArgument> args = getCommandOptions(text, index, &cellsStart); if (args.count() < 2) return; QString tableType = args.at(0).value; // assume alignment in second arg except for the following environments (which have it in the third one) QString alignment; if (tabularNames.contains(tableType)) { alignment = args.at(1).value; } else if (tabularNamesWithOneOption.contains(tableType)) { if (args.count()<3) alignment = ""; // incomplete definition -> fall back to defaults else alignment = args.at(2).value; } else return; // not a registered table environment int cellsEnd = text.indexOf("\\end{"+tableType); if (cellsEnd<0) return; QString beginPart = text.left(cellsStart); QString endPart = text.mid(cellsEnd); LatexTableModel ltm; ltm.setContent(text.mid(cellsStart, cellsEnd-cellsStart)); QStringList l_defs=splitColDef(alignment); simplifyColDefs(l_defs); QStringList content(ltm.getAlignedLines(l_defs)); QString result = beginPart + '\n'; for (int i=0; i<content.count(); i++) { result.append(indentation + content.at(i)); } result.append(indentation + endPart); cur.replaceSelectedText(result); }
int main(int argc, char* argv[]) { struct timeval startTime, endTime; gettimeofday(&startTime, NULL); string inFileName, inDistName, pairFileName, distFileName, freqFileName; bool useGPU = true; float threshold = THRESHOLD; unsigned long long totalNumPairs = 0; int i, numReads, numSeeds, arrayDim, readSize, numThreads=1; // open the output file getCommandOptions(argc, argv, inFileName, threshold, useGPU, numThreads); inDistName = inFileName; pairFileName = inFileName; distFileName = inFileName; inDistName.append(".dist"); pairFileName.append(".epair"); distFileName.append(".edist"); FILE * inDistFile; inDistFile = fopen(inDistName.c_str(), "rb"); if (inDistFile == 0) exit(-1); freqFileName = inFileName; freqFileName.append(".frq"); numReads = loadFreq(freqFileName); bool EOFTag = false; float distArray[BUF_SIZE]; while (!EOFTag) { readSize = loadDistFile(inDistFile, distArray, EOFTag); totalNumPairs += readSize; } rewind(inDistFile); numSeeds = totalNumPairs/numReads; float ** eReads; eReads = (float**) malloc(numReads * sizeof(float*)); for (i = 0; i < numReads; ++i) eReads[i] = (float*) malloc(numSeeds * sizeof(float)); // compute embedding vectors for (i = 0; i < numReads; ++i) fread(eReads[i], sizeof(float), numSeeds, inDistFile); arrayDim = (int)(16 * pow(8.0, floor(log10((double)numReads))-1)); if (arrayDim > 1536) arrayDim = 1536; printf("\n----------------------------------------------------------------------\n"); printf(" COMPUTE EUCLID DISTANCES \n"); printf("File name: %s. numReads: %d. numSeeds: %d. threshold: %.2f\n\n", inFileName.c_str(), numReads, numSeeds, threshold); if (useGPU) { printf("USE GPU. numStreams: %d\n", NUM_STREAMS); computeEuclidDist_CUDA(eReads, pairFileName, distFileName, numReads, numSeeds, threshold, arrayDim); } else { printf("USE CPU. numThreads: %d\n", numThreads); omp_set_num_threads(numThreads); computeEuclidDist_CPU(eReads, pairFileName, distFileName, numReads, numSeeds, threshold); } fclose(inDistFile); gettimeofday(&endTime, NULL); long elapsedTime = (endTime.tv_sec - startTime.tv_sec) * 1000u + (endTime.tv_usec - startTime.tv_usec) / 1.e3 + 0.5; printf("Time taken: %.3f s\n", elapsedTime/1.e3); printf("\n----------------------------------------------------------------------\n"); return 0; }
int main(int argc, char* argv[]) { struct timeval startTime, endTime; gettimeofday(&startTime, NULL); READ *readArray = NULL; string inFileName, pairFileName, distFileName; bool hasDistances = false, useGPU = true, useMPI = false; float threshold = -1; int numThreads = 1, numReads, maxLen = 0, arrayDim, K = 6; // open the output file FILE* pairFile = NULL, *distFile = NULL; getCommandOptions(argc, argv, inFileName, threshold, hasDistances, numThreads, useGPU, useMPI, K); pairFileName = inFileName; pairFileName.append(".kpair"); distFileName = inFileName; distFileName.append(".kdist"); // read from input files numReads = readFile(inFileName, readArray, maxLen, K); if (numReads > MAX_NUM_READS || maxLen > MAX_READ_LEN) { printf("Error: unsupported numReads: %d or maxLen: %d. Exit...", numReads, maxLen); exit(-1); } if (threshold < 0 || threshold > 1) threshold = 2/log2((double)numReads); arrayDim = (int)(4 * pow(8.0, floor(log10((double)numReads))-1)); if (arrayDim > 1536) arrayDim = 1536; omp_set_num_threads(numThreads); // form the k-tuple array for each sequence from the file #pragma omp parallel for schedule(static,1) for (int i = 0; i < numReads; ++i) { readArray[i].formTuples(K); readArray[i].sortTuples(); } if (useGPU && useMPI) { // Initialize MPI state MPI_Init(NULL, NULL); // Get our MPI node number and node count int commSize, commRank, len; char name[BUF_SIZE]; MPI_Comm_size(MPI_COMM_WORLD, &commSize); MPI_Comm_rank(MPI_COMM_WORLD, &commRank); MPI_Get_processor_name(name, &len); char temp[5]; sprintf(temp,"_%d",commRank); pairFileName.append(temp); pairFile = fopen(pairFileName.c_str(), "wb"); if (hasDistances) { distFileName.append(temp); distFile = fopen(distFileName.c_str(), "wb"); } if (commRank == 0) { printf("\n----------------------------------------------------------------------\n"); printf(" COMPUTE KMER DISTANCES \n"); printf("File name: %s. K = %d\n\n", inFileName.c_str(), K); printf("numReads: %d, maxLen: %d, threshold: %.2f\n ", numReads, maxLen, threshold); printf("USE MPI. numCPUs: %d\n\n", commSize); } computeKmerDist_MPI(readArray, pairFile, distFile, hasDistances, numReads, maxLen, threshold, arrayDim, commRank, commSize, K); fclose(pairFile); if (hasDistances) fclose(distFile); if (commRank == 0) { gettimeofday(&endTime, NULL); long elapsedTime = (endTime.tv_sec - startTime.tv_sec) * 1000u + (endTime.tv_usec - startTime.tv_usec) / 1.e3 + 0.5; printf("Time taken: %.3f s\n", elapsedTime/1.e3); printf("\n----------------------------------------------------------------------\n"); } MPI_Finalize(); } else { printf("\n----------------------------------------------------------------------\n"); printf(" COMPUTE KMER DISTANCES \n"); printf("File name: %s. K = %d\n\n", inFileName.c_str(), K); printf("numReads: %d, maxLen: %d, threshold: %.2f\n ", numReads, maxLen, threshold); pairFile = fopen(pairFileName.c_str(), "wb"); if (hasDistances) distFile = fopen(distFileName.c_str(), "wb"); if (useGPU) { printf("USE GPU. numStreams: %d\n", NUM_STREAMS); computeKmerDist_CUDA(readArray, pairFile, distFile, hasDistances, numReads, maxLen, threshold, arrayDim, K); } else { printf("USE CPU. numThreads: %d\n", numThreads); computeKmerDist_CPU(readArray, pairFile, distFile, hasDistances, numReads, threshold, arrayDim, K); } fclose(pairFile); if (hasDistances) fclose(distFile); gettimeofday(&endTime, NULL); long elapsedTime = (endTime.tv_sec - startTime.tv_sec) * 1000u + (endTime.tv_usec - startTime.tv_usec) / 1.e3 + 0.5; printf("Time taken: %.3f s\n", elapsedTime/1.e3); printf("\n----------------------------------------------------------------------\n"); } return 0; }
int main(int argc, char *argv[]) { // Program variables... int tempInt = 0; char buffer[LINE_SIZE]; int sizeRead = 0; char temporaryFileName[64] = ""; FILE *tempFileHandle = 0; FILE *inputFileHandle = 0; struct debugAbbrev *debugAbPointer = 0; struct johnPassword *johnPointer = 0; // Nipper Configuration... struct nipperConfig *nipper = createNipperConfig(); // Get the command-line options... getCommandOptions(argc, argv, nipper); // Show on-line help? if (nipper->nipperMode == mode_help) showHelp(argc, argv, nipper); // Show version? else if (nipper->nipperMode == mode_version) printf("%s\n\n", program_version_banner); // ---------------------------------------------------- // PART 2: Process Configuration File else if (nipper->nipperMode == mode_process) { // Get SNMP if it has been specified... #if !defined(__WIN32__) if ((nipper->remoteIP[0] != 0) && (nipper->localIP[0] != 0) && (nipper->inputName == 0)) getRemoteConfig(nipper, temporaryFileName, sizeof(temporaryFileName), argv[nipper->localSave]+13); // Get stdin if input has not been specified... else if (nipper->inputName == 0) #else if (nipper->inputName == 0) #endif { // Init... signal(14, stdinTimeout); inputFileHandle = stdin; // Read stdin... while (feof(inputFileHandle) == 0) { // Read... memset(buffer, 0, LINE_SIZE); #if !defined(__WIN32__) alarm(2); #endif sizeRead = fread(buffer, 1, LINE_SIZE, inputFileHandle); #if !defined(__WIN32__) alarm(0); #endif // Write to file... if (tempFileHandle == 0) { sprintf(temporaryFileName, "%sdelete-me-%d", tmpDir, rand()); tempFileHandle = fopen(temporaryFileName, "w"); fwrite(buffer, 1, sizeRead, tempFileHandle); } else fwrite(buffer, 1, sizeRead, tempFileHandle); } fclose(tempFileHandle); nipper->inputName = temporaryFileName; } // Debug Output? if ((nipper->debugMode == true) && (nipper->nipperMode == mode_process)) { printf("%s\n", program_banner); printf("\n%sCommand Line Options\n====================%s\nCommand:", COL_BLUE, RESET); for (tempInt = 0; tempInt < argc; tempInt++) { printf(" %s", argv[tempInt]); } printf("\n\n"); } // Process input file(s)/stdin/snmp... if (nipper->nipperMode == mode_process) { if (processInput(nipper) == true) { // Check that version has been identified for relevent configs... nipper->nipperMode = mode_process; if (nipper->force == false) { switch (nipper->deviceType) { case type_ios_switch: case type_ios_router: case type_ios_catalyst: if (nipper->versionMajor == 0) { nipper->nipperMode = mode_help; nipper->helpMode = help_error_wrong_type; } break; case type_nmp_catalyst: case type_cos_catalyst: if (nipper->versionMajor == 0) { nipper->nipperMode = mode_help; nipper->helpMode = help_error_wrong_type; } break; case type_pix_firewall: case type_asa_firewall: case type_fwsm_firewall: if (nipper->versionMajor == 0) { nipper->nipperMode = mode_help; nipper->helpMode = help_error_wrong_type; } break; case type_css_filter: if (nipper->versionMajor == 0) { nipper->nipperMode = mode_help; nipper->helpMode = help_error_wrong_type; } break; case type_sos_firewall: case type_sonicwall: if (nipper->hostname[0] == 0) { nipper->nipperMode = mode_help; nipper->helpMode = help_error_wrong_type; } break; case type_passport: case type_bayaccelar: if (nipper->pas->boxType[0] == 0) { nipper->nipperMode = mode_help; nipper->helpMode = help_error_wrong_type; } break; } } } } if (nipper->nipperMode == mode_help) { showHelp(argc, argv, nipper); cleanup(nipper); return 1; } // ---------------------------------------------------- // PART 3: Report Pre-parsing // Default Settings... processDefaults(nipper); // Convert Names to IP Addresses... if (nipper->names == true) processNameMappings(nipper); // ---------------------------------------------------- // PART 4: Reporting // Output debug information? if (nipper->debugMode == true) { switch (nipper->deviceType) { case type_ios_router: case type_ios_switch: case type_ios_catalyst: reportIOSDebug(nipper); break; case type_pix_firewall: case type_asa_firewall: case type_fwsm_firewall: reportPIXDebug(nipper); break; case type_nmp_catalyst: case type_cos_catalyst: reportNMPDebug(nipper); break; case type_css_filter: reportCSSDebug(nipper); break; case type_sos_firewall: reportSOSDebug(nipper); break; case type_passport: case type_bayaccelar: reportPASDebug(nipper); break; case type_fw1_firewall: case type_nokiaip: reportFW1Debug(nipper); break; case type_sonicwall: reportSonicOSDebug(nipper); break; } } // Output report & john (if specified) else { // Output john? if ((nipper->johnFile != 0) && (nipper->john != 0)) { // Variables FILE *johnFile; // Create file johnFile = fopen(nipper->johnFile, "w"); if (johnFile == NULL) { nipper->nipperMode = mode_help; nipper->helpMode = help_error_john_file; } else { // Write file contents johnPointer = nipper->john; while (johnPointer != 0) { fprintf(johnFile, "%s:%s\n", johnPointer->username, johnPointer->password); johnPointer = johnPointer->next; } // Close file fclose(johnFile); } } if (nipper->nipperMode == mode_help) { showHelp(argc, argv, nipper); cleanup(nipper); return 1; } // Generate the report switch (nipper->deviceType) { case type_ios_router: case type_ios_switch: case type_ios_catalyst: generateIOSReport(nipper); break; case type_pix_firewall: case type_asa_firewall: case type_fwsm_firewall: generatePIXReport(nipper); break; case type_cos_catalyst: case type_nmp_catalyst: generateNMPReport(nipper); break; case type_css_filter: generateCSSReport(nipper); break; case type_sos_firewall: generateSOSReport(nipper); break; case type_passport: case type_bayaccelar: generatePASReport(nipper); break; case type_fw1_firewall: case type_nokiaip: generateFW1Report(nipper); break; case type_sonicwall: generateSonicOSReport(nipper); break; } if (nipper->nipperMode == mode_help) { showHelp(argc, argv, nipper); cleanup(nipper); return 1; } // Output Debug Abbreviations if (nipper->debugAbbrev == true) { printf("\n%sUnknown Abbreviations\n=====================%s\n", COL_BLUE, RESET); debugAbPointer = debugAb; while (debugAbPointer != 0) { printf(" %s (%d)\n", debugAbPointer->ab, debugAbPointer->count); debugAbPointer = debugAbPointer->next; } } } // ---------------------------------------------------- // PART 5: Cleanup // Stdin temporary file... if (temporaryFileName[0] != 0) { unlink(temporaryFileName); } } cleanup(nipper); return 0; }