FileType *ConsoleTools::selectType(HRCParser *hrcParser, LineSource *lineSource){ FileType *type = null; if (typeDescription != null){ type = hrcParser->getFileType(typeDescription); if (type == null){ for(int idx = 0;; idx++){ type = hrcParser->enumerateFileTypes(idx); if (type == null) break; if (type->getDescription() != null && type->getDescription()->length() >= typeDescription->length() && DString(type->getDescription(), 0, typeDescription->length()).equalsIgnoreCase(typeDescription)) break; if (type->getName()->length() >= typeDescription->length() && DString(type->getName(), 0, typeDescription->length()).equalsIgnoreCase(typeDescription)) break; type = null; } } } if (typeDescription == null || type == null){ StringBuffer textStart; int totalLength = 0; for(int i = 0; i < 4; i++){ String *iLine = lineSource->getLine(i); if (iLine == null) break; textStart.append(iLine); textStart.append(DString("\n")); totalLength += iLine->length(); if (totalLength > 500) break; } type = hrcParser->chooseFileType(inputFileName, &textStart, 0); } return type; }
FileType *ColorerFilter::selectType(HRCParser *hrcParser, String *fline) { FileType *type = null; if (typeDescription != null) { type = hrcParser->getFileType(typeDescription); if (type == null) { for(int idx = 0;; idx++) { type = hrcParser->enumerateFileTypes(idx); if (type == null) { break; } if (type->getDescription() != null && type->getDescription()->length() >= typeDescription->length() && DString(type->getDescription(), 0, typeDescription->length()).equalsIgnoreCase(typeDescription)) { break; } if (type->getName()->length() >= typeDescription->length() && DString(type->getName(), 0, typeDescription->length()).equalsIgnoreCase(typeDescription)) { break; } type = null; } } } if (typeDescription == null || type == null) { type = hrcParser->chooseFileType(inputFileName, fline, 0); } return type; }
void ConsoleTools::listTypes(bool load, bool useNames){ Writer *writer = null; try{ writer = new StreamWriter(stdout, outputEncodingIndex, bomOutput); ParserFactory pf(catalogPath); HRCParser *hrcParser = pf.getHRCParser(); fprintf(stderr, "\nloading file types...\n"); for(int idx = 0;; idx++){ FileType *type = hrcParser->enumerateFileTypes(idx); if (type == null) break; if (useNames){ writer->write(StringBuffer(type->getName())+"\n"); }else{ if (type->getGroup() != null){ writer->write(StringBuffer(type->getGroup()) + ": "); } writer->write(type->getDescription()); writer->write(DString("\n")); } if (load) type->getBaseScheme(); } delete writer; }catch(Exception &e){ delete writer; fprintf(stderr, "%s\n", e.getMessage()->getChars()); } }