void CBCSharpScanner::BeginScan ( std::istream& input ) { itsResetFlag = kJTrue; itsCurrentRange.Set(JTellg(input)+1, JTellg(input)); switch_streams(&input, NULL); }
void CBPerlScanner::BeginScan ( istream& input ) { itsResetFlag = kJTrue; itsCurrentRange.Set(JTellg(input)+1, JTellg(input)); itsProbableOperatorFlag = kJFalse; itsHereDocTag.Clear(); itsHereDocType = kDoubleQuoteString; switch_streams(&input, NULL); }
void CBHTMLScanner::BeginScan ( std::istream& input, const yy_state_type startState ) { itsResetFlag = kJTrue; itsStartState = startState; itsCurrentRange.Set(JTellg(input)+1, JTellg(input)); itsScriptLanguage.Clear(); itsPHPHereDocTag.Clear(); itsProbableJSOperatorFlag = kJFalse; switch_streams(&input, NULL); }
void GMMIMEParser::ParseByType ( std::istream& input, const GMIMEHeader& header, const JIndex isEnd ) { if (header.GetType() == kMessageType && header.GetSubType() == "rfc822") { Parse(input, isEnd, kJTrue); } else if (TextIsReadable(header)) { JString data; JIndex current = JTellg(input); data.Read(input, isEnd - current + 1); WriteTextString(&data, header); } else if (header.GetType() == kMultipartType) { if (header.GetSubType() == kMixedType || header.GetSubType() == kRelatedType) { ParseMixed(input, header); } else if (header.GetSubType() == kAlternateType) { ParseAlternate(input, header); } else { ParseMixed(input, header); } } else { JString data; JIndex current = JTellg(input); data.Read(input, isEnd - current + 1); WriteAttachment(data, header); } }
void JReadFile ( fstream& input, JString* str ) { const JSize charCount = JGetFStreamLength(input) - JTellg(input); str->Read(input, charCount); }
int GMScanner::yylex() { if (itsCurrentPosition == 0) { itsIs >> std::ws; itsCurrentPosition = JTellg(*itsIs); itsCurrentHeaderStart = itsCurrentPosition; itsText = JReadLine(*itsIs); JRegex regex; JBoolean matched; JArray<JStringRange>* subList = new JArray<JStringRange>; assert(subList != NULL); err = regex.SetPattern("^From[[:space:]]+.*.{3}[[:space:]]+.{3}[[:space:]]+[[:digit:]]+[[:space:]]+[[:digit:]]+:[[:digit:]]+:[[:digit:]]+[[:space:]]+[[:digit:]]{4}"); assert(err.OK()); matched = regex.Match(itsText, subList); delete subList; if (matched) { itsState = kHeaderStart; return itsState; } }
void GFGLink::ParseInterface ( GFGMemberFunction* fn, const JIndex line ) { std::ifstream is(itsCurrentFile); if (!is.good()) { return; } // skip to the function's line JString str; for (JIndex i = 1; i < line; i++) { str = JReadLine(is); } JSize p1 = JTellg(is); is >> std::ws; str = JReadUntilws(is); if (str != "virtual") { return; } is >> std::ws; // return type str = JReadUntilws(is); if (str == "const") { str += " " + JReadUntilws(is); } fn->SetReturnType(str); is >> std::ws; // this should be the function name str = JReadUntil(is, '('); str.TrimWhitespace(); if (str != fn->GetFnName()) { return; } // get arguments JCharacter delim = ','; while (delim == ',') { JBoolean ok = JReadUntil(is, 2, ",)", &str, &delim); if (!ok) { return; } JIndex findex; if (str.LocateSubstring("//", &findex)) { JIndex eindex; if (str.LocateSubstring("\n", &eindex) && eindex >= findex) { str.RemoveSubstring(findex, eindex); } } str.TrimWhitespace(); if (!str.IsEmpty()) { fn->AddArg(str); } } is >> std::ws; // is it const; str = JReadUntil(is, ';'); if (str.Contains("const")) { fn->ShouldBeConst(kJTrue); } JSize p2 = JTellg(is); JSeekg(is, p1); str = JRead(is, p2 - p1); fn->SetInterface(str); }
JBoolean GMMIMEParser::ReadUntilBoundary ( std::istream& input, const JString& boundary, JIndex* start, JIndex* end ) { JString endBoundary = boundary + "--\n"; JIndex startI = JTellg(input); JIndex findex = startI; JString boundaryNL = boundary + "\n"; if (itsData->LocateNextSubstring(boundaryNL, &findex)) { // a '--' precedes the boundary, so we need to back up before // those. *start = findex - 3; // the end is the character before the '\n'. *end = findex + boundaryNL.GetLength() - 2; return kJFalse; } findex = startI; if (itsData->LocateNextSubstring(endBoundary, &findex)) { // a '--' precedes the boundary, so we need to back up before // those. *start = findex - 3; // the end is the character before the '\n'. *end = findex + endBoundary.GetLength() - 2; return kJTrue; } *start = itsData->GetLength(); *end = itsData->GetLength(); return kJTrue; // I found a situation where the following code didn't work. I hadn't // thought of the case where nested boundaries where equal to the parent // boundary plus something else, ie: // // Content-Type: multipart/mixed; // boundary="=====================_40887633==_" // //--=====================_40887633==_ //Content-Type: multipart/related; // type="multipart/alternative"; // boundary="=====================_40887633==_.REL" // //--=====================_40887633==_.REL //Content-Type: multipart/alternative; // boundary="=====================_40887643==_.ALT" // //--=====================_40887643==_.ALT /* if (itsData->LocateNextSubstring(boundary, &findex)) { *start = findex - 3; JIndex eIndex = findex; if (itsData->LocateNextSubstring("\n", &eIndex)) { *end = eIndex - 1; JString tBoundary = itsData->GetSubstring(findex, eIndex - 1); if (tBoundary == endBoundary) { return kJTrue; } return kJFalse; } } *start = itsData->GetLength(); *end = itsData->GetLength(); return kJTrue; */ }
void GMMIMEParser::Parse ( std::istream& input, const JIndex isEnd, const JBoolean nested ) { GMIMEHeader* header = new GMIMEHeader(); assert(header != NULL); if (input.good()) { ParseMIMEHeader(input, header, nested); if (header->GetEncoding() == kBase64Encoding) { JString filename = header->GetFileName(); if (filename.IsEmpty()) { const JError err = JCreateTempFile(itsAttachDir, NULL, &filename); if (!err.OK()) { itsIsSuccessful = kJFalse; } } else { filename = JCombinePathAndName(itsAttachDir, filename); } if (!filename.IsEmpty()) { AdjustAttachmentName(*header, &filename); std::ofstream os(filename); JDecodeBase64(input, os); } } else if ((header->GetType() != kMultipartType) && (!header->GetFileName().IsEmpty())) { JIndex startI = JTellg(input); const JCharacter* c = itsData->GetCString() + startI; JString filename = header->GetFileName(); if (filename.IsEmpty()) { const JError err = JCreateTempFile(itsAttachDir, NULL, &filename); if (!err.OK()) { itsIsSuccessful = kJFalse; } } else { filename = JCombinePathAndName(itsAttachDir, filename); } if (!filename.IsEmpty()) { AdjustAttachmentName(*header, &filename); std::ofstream os(filename); os.write(c, isEnd - startI); } } else { // parse message body. may be recursive ParseByType(input, *header, isEnd); } } else { itsIsSuccessful = kJFalse; } if (itsTextInfo != NULL) { itsTextInfo->ForceUpdate(); } if (itsAttachInfo != NULL) { itsAttachInfo->ForceUpdate(); } delete header; }
void GMMIMEParser::ParseAlternate ( std::istream& input, const GMIMEHeader& header ) { JString boundary = "-" + header.GetBoundary(); JString data; JString junk; // slurp the initial empty part JIndex bstart, bend; ReadUntilBoundary(input, boundary, &bstart, &bend); JIndex current = JTellg(input); data.Read(input, bend - current + 1); JString text; JString charset; JString subType; GMIMEHeader shownHeader; while (1) { GMIMEHeader child; ParseMIMEHeader(input, &child); if (child.GetSubType() != kPlainType && child.GetSubType() != kHTMLType) { text = data; while (!ReadUntilBoundary(input, boundary, &bstart, &bend)) { // slurp up the rest, because it is useless to us. current = JTellg(input); data.Read(input, bend - current + 1); } current = JTellg(input); data.Read(input, bend - current + 1); data.Clear(); break; } else { shownHeader = child; } // when the following function returns true, it has found the // last boundary data.Clear(); JBoolean end = ReadUntilBoundary(input, boundary, &bstart, &bend); current = JTellg(input); data.Read(input, bstart - current); current = JTellg(input); junk.Read(input, bend - current + 1); if (end) { text = data; data.Clear(); break; } } WriteTextString(&text, shownHeader); if (itsTextInfo != NULL) { itsTextInfo->ForceUpdate(); } if (itsAttachInfo != NULL) { itsAttachInfo->ForceUpdate(); } }
void GMMIMEParser::ParseMixed ( std::istream& input, const GMIMEHeader& header ) { JString boundary = "-" + header.GetBoundary(); JString endBoundary = boundary + "--"; // slurp the initial empty part JIndex bstart, bend; ReadUntilBoundary(input, boundary, &bstart, &bend); JIndex current = JTellg(input); JString data; data.Read(input, bend - current + 1); while (1) { GMIMEHeader child; ParseMIMEHeader(input, &child); // when the following function returns true, it has found the // last boundary data.Clear(); JBoolean end; if (child.GetEncoding() == kBase64Encoding) { JString filename = child.GetFileName(); if (filename.IsEmpty()) { JCreateTempFile(itsAttachDir, NULL, &filename); } else { filename = JCombinePathAndName(itsAttachDir, filename); } if (!filename.IsEmpty()) { AdjustAttachmentName(child, &filename); std::ofstream os(filename); JDecodeBase64(input, os); end = ReadUntilBoundary(input, boundary, &bstart, &bend); // JBoolean found; // JString line; // while (line.IsEmpty() && !input.fail()) // { // line = JReadLine(input, &found); // } // JString endBoundary = boundary + "--"; // if (line.Contains(endBoundary)) // { // end = kJTrue; // } } } else if ((child.GetType() != kMultipartType) && (!child.GetFileName().IsEmpty())) { JIndex startI = JTellg(input); JIndex findex = startI; if (itsData->LocateNextSubstring(boundary, &findex)) { const JCharacter* c = itsData->GetCString() + startI; JString filename = child.GetFileName(); if (filename.IsEmpty()) { JCreateTempFile(itsAttachDir, NULL, &filename); } else { filename = JCombinePathAndName(itsAttachDir, filename); } if (!filename.IsEmpty()) { AdjustAttachmentName(child, &filename); std::ofstream os(filename); JSeekg(input, findex - 1); if (child.GetEncoding() == kQPEncoding) { JString data = itsData->GetSubstring(startI, findex - 3); ParseQuotedPrintable(&data); data.Print(os); } else { os.write(c, findex - startI - 3); } JBoolean found; JString line = JReadLine(input, &found); if (line.BeginsWith(endBoundary)) { end = kJTrue; } } } } else { end = ReadUntilBoundary(input, boundary, &bstart, &bend); ParseByType(input, child, bstart - 1); current = JTellg(input); data.Read(input, bend - current + 1); } if (end) { break; } } if (itsTextInfo != NULL) { itsTextInfo->ForceUpdate(); } if (itsAttachInfo != NULL) { itsAttachInfo->ForceUpdate(); } }