// Works for HTML Documents, http links etc // if it starts with file:, then fire off the filename void ExecuteFile(LPSTR FileName) { if (strncmp(FileName, "file:", 5) == 0) { //find the line number char Buffer[MAX_PATH]; char* s = strrchr(FileName, ':'); int LineNo; if (s != NULL) { int i; s++; for (i = 0; s[i] != 0; i++) { if (!isdigit(s[i])) { s = NULL; break; } } } if (s == NULL) LineNo = 0; // the null line else { s[-1] = 0; LineNo = atoi(s); } FileName += 5; /* skip over "file:" */ if (strncmp("{Hugs}", FileName, 6) == 0) { strcpy(Buffer, hugsdir()); strcat(Buffer, &FileName[6]); } else if (IsRelativeFile(FileName)) { GetCurrentDirectory(MAX_PATH, Buffer); if (!IsSeparatorChar(Buffer[strlen(Buffer) - 1])) strcat(Buffer, "\\"); strcat(Buffer, FileName); } else strcpy(Buffer, FileName); startEdit(LineNo, Buffer); } else { int Res = (int) ShellExecute(hThisWindow, NULL, FileName, NULL, NULL, SW_SHOWNORMAL); if (Res <= 32) { char Buffer[MAX_PATH*2]; strcpy(Buffer, "Failed to launch file:\n"); strcat(Buffer, FileName); MessageBox(hThisWindow, Buffer, "Hugs98", MB_ICONWARNING); } } }
static UString GetIDString(const wchar_t *srcString, unsigned &finishPos) { UString result; bool quotes = false; for (finishPos = 0;;) { wchar_t c = srcString[finishPos]; if (c == 0) break; finishPos++; bool isSeparatorChar = IsSeparatorChar(c); if (c == kNewLineChar || (isSeparatorChar && !quotes) || (c == kQuoteChar && quotes)) break; else if (c == kQuoteChar) quotes = true; else result += c; } result.Trim(); RemoveCr(result); return result; }
StringLexer::LEXEME_TYPE StringLexer::ParseString(SString ¤tString, BOOL fPermitUnescapedQuotes) { BOOL fIsFirstCharacter = TRUE; WCHAR wcCurrentChar = INVALID_CHARACTER; WCHAR wcOpeningQuote = INVALID_CHARACTER; currentString.Clear(); // Read until we find another lexeme that's not a string character for (;;) { BOOL fIsEscaped = FALSE; wcCurrentChar = PopCharacter(&fIsEscaped); if (wcCurrentChar == INVALID_CHARACTER) { // Found invalid character encoding BINDER_LOG(L"StringLexer::ParseString: Invalid character encoding"); return LEXEME_TYPE_INVALID; } if (IsEOS(wcCurrentChar)) { if (IsQuoteCharacter(wcOpeningQuote)) { // EOS and unclosed quotes is an error BINDER_LOG(L"StringLexer::ParseString: EOS and unclosed quotes"); return LEXEME_TYPE_INVALID; } else { // Reached end of input and therefore of string break; } } if (fIsFirstCharacter) { fIsFirstCharacter = FALSE; // If first character is quote, then record its quoteness if (IsQuoteCharacter(wcCurrentChar)) { wcOpeningQuote = wcCurrentChar; continue; } } if (wcCurrentChar == wcOpeningQuote) { // We've found the closing quote for a quoted string break; } if (!fPermitUnescapedQuotes && !fIsEscaped && IsQuoteCharacter(wcCurrentChar) && !IsQuoteCharacter(wcOpeningQuote)) { // Unescaped quotes in the middle of the string are an error BINDER_LOG(L"StringLexer::ParseString: Quote in the middle of a string"); return LEXEME_TYPE_INVALID; } if (IsSeparatorChar(wcCurrentChar) && !IsQuoteCharacter(wcOpeningQuote) && !fIsEscaped) { // Unescaped separator char terminates the string PushCharacter(wcCurrentChar, fIsEscaped); break; } // Add character to current string currentString.Append(wcCurrentChar); } if (!IsQuoteCharacter(wcOpeningQuote)) { // Remove trailing white spaces from unquoted string BINDER_LOG(L"StringLexer::ParseString: Trimming string"); TrimTrailingWhiteSpaces(currentString); } BINDER_LOG_STRING(L"string", currentString); return LEXEME_TYPE_STRING; }
/*---------------------------------------------------------------------- NextWord isole le mot suivant dans la suite des buffers de de texte. Ce mot peut e^tre vide. Retourne le nombre de se'parateurs qui pre'ce`dent le de'but du mot. Rend la position a` laquelle le mot de'bute : - l'adresse du buffer du 1er caracte`re. - l'index dans ce buffer du 1er caracte`re. - le mot isole'. - la longueur des se'parateurs qui pre'ce`dent le de'but du mot. ----------------------------------------------------------------------*/ static int NextWord (SpecFont font, int variant, PtrTextBuffer *buffer, int *rank, CHAR_T *word, int *width) { PtrTextBuffer adbuff; int i, j; int lg, nbChars; ThotBool still; ThotBool changedebut; /* Initialisations */ word[0] = EOS; lg = 0; nbChars = 0; j = 0; still = TRUE; /* La position du debut du mot */ adbuff = *buffer; i = *rank; /* A priori le debuTEXT('\253'),t du mot est correctement repere */ changedebut = FALSE; while (still) { if (j == THOT_MAX_CHAR - 1) /* Le mot est trop long */ still = FALSE; else if (i >= adbuff->BuLength) /* Il faut changer de buffer */ if (adbuff->BuNext == NULL) still = FALSE; else { adbuff = adbuff->BuNext; i = 0; } else { /* FnCopy du caractere */ word[j] = adbuff->BuContent[i]; if (word[j] == '\'') /* Cas particulier du cote */ if (j <= 1) { changedebut = TRUE; lg += BoxCharacterWidth (word[j], variant, font); if (j == 1) /* Il faut comptabiliser le caractere precedent */ lg += BoxCharacterWidth (word[j - 1], variant, font); nbChars += j + 1; j = 0; } else still = FALSE; else if (IsSeparatorChar (word[j])) { /* On ne traite pas les separateurs en debut de mot */ if (j > 0) { word[j] = EOS; still = FALSE; } else { /* Le debut du mot est deplace */ changedebut = TRUE; lg += BoxCharacterWidth (word[j], variant, font); nbChars++; } } else { j++; if (changedebut) { /* Repere le debut du mot */ changedebut = FALSE; *buffer = adbuff; *rank = i; /* i pointe deja sur le 1er caractere du mot */ } } /* Passe au caractere suivant */ i++; } } /* Termine le mot */ word[j] = EOS; if (nbChars == 0) *width = 0; else *width = lg; return nbChars; }
BOOL IsRelativeFile(LPCSTR s) { return ((s[0] == '.' && s[1] == '.' && IsSeparatorChar(s[2])) || (s[0] == '.' && IsSeparatorChar(s[2]))); }