NS_IMETHODIMP
nsHTMLEditorLog::RemoveInlineProperty(nsIAtom *aProperty, const nsAString &aAttribute)
{
  nsAutoHTMLEditorLogLock logLock(this);

  if (!mLocked && mFileStream)
  {
    nsAutoString propStr;

    aProperty->ToString(propStr);

    PrintSelection();
    Write("atomService = Components.classes[\"@mozilla.org/atom-service;1\"].getService(Components.interfaces.nsIAtomService);\n");
    Write("propAtom = atomService.getAtom(\"");
    PrintUnicode(propStr);
    Write("\");\n");
    Write("GetCurrentEditor().removeInlineProperty(propAtom, \"");
    if (aAttribute.Length())
      PrintUnicode(aAttribute);
    Write("\");\n");

    Flush();
  }

  return nsHTMLEditor::RemoveInlineProperty(aProperty, aAttribute);
}
NS_IMETHODIMP
nsHTMLEditorLog::SetBodyAttribute(const nsAString& aAttr, const nsAString& aValue)
{
  nsAutoHTMLEditorLogLock logLock(this);

  if (!mLocked && mFileStream)
  {
    Write("GetCurrentEditor().setBodyAttribute(\"");
    PrintUnicode(aAttr);
    Write("\", \"");
    PrintUnicode(aValue);
    Write("\");\n");
    Flush();
  }

  return nsHTMLEditor::SetBodyAttribute(aAttr, aValue);
}
Beispiel #3
0
int main(int argc, char* argv[])
{
//	C_char( );
//	W_char( );
//	T_char( );
	PrintUnicode( );
	return 0;
}
Beispiel #4
0
void Log::WriteRaw(const String& message, bool error)
{
    Log* instance = Subsystem<Log>();
    if (!instance)
        return;

    // If not in the main thread, store message for later processing
    if (!Thread::IsMainThread())
    {
        MutexLock lock(instance->logMutex);
        instance->threadMessages.Push(StoredLogMessage(message, LOG_RAW, error));
        return;
    }
    
    // Prevent recursion during log event
    if (instance->inWrite)
        return;

    instance->lastMessage = message;

    if (instance->quiet)
    {
        // If in quiet mode, still print the error message to the standard error stream
        if (error)
            PrintUnicode(message, true);
    }
    else
        PrintUnicode(message, error);

    if (instance->logFile)
    {
        instance->logFile->Write(message.CString(), message.Length());
        instance->logFile->Flush();
    }

    instance->inWrite = true;

    LogMessageEvent& event = instance->logMessageEvent;
    event.message = message;
    event.level = error ? LOG_ERROR : LOG_INFO;
    instance->SendEvent(event);

    instance->inWrite = false;
}
NS_IMETHODIMP
nsHTMLEditorLog::MakeOrChangeList(const nsAString& aListType, bool entireList, const nsAString& aBulletType)
{
  nsAutoHTMLEditorLogLock logLock(this);

  if (!mLocked && mFileStream)
  {
    PrintSelection();

    Write("GetCurrentEditor().makeOrChangeList(\"");
    PrintUnicode(aListType);
    Write("\", ");
    Write(entireList ? "true" : "false");
    Write(", \"");
    PrintUnicode(aBulletType);
    Write("\");\n");
    Flush();
  }

  return nsHTMLEditor::MakeOrChangeList(aListType, entireList, aBulletType);
}
nsresult
nsHTMLEditorLog::PrintAttributeNode(nsIDOMNode *aNode, int32_t aDepth)
{
  nsresult result;
  nsCOMPtr<nsIDOMAttr> attr = do_QueryInterface(aNode);

  NS_ENSURE_TRUE(attr, NS_ERROR_NULL_POINTER);

  nsAutoString str;

  result = attr->GetName(str);

  NS_ENSURE_SUCCESS(result, result);

  Write("a");
  WriteInt(aDepth);
  Write(" = GetCurrentEditor().editorDocument.createAttribute(\"");
  PrintUnicode(str);
  Write("\");\n");

  result = attr->GetValue(str);

  NS_ENSURE_SUCCESS(result, result);

  Write("a");
  WriteInt(aDepth);
  Write(".value = \"");
  PrintUnicode(str);
  Write("\";\n");
  
  Write("n");
  WriteInt(aDepth);
  Write(".setAttributeNode(a");
  WriteInt(aDepth);
  Write(");\n");

  return NS_OK;
}
nsresult
nsHTMLEditorLog::PrintElementNode(nsIDOMNode *aNode, int32_t aDepth)
{
  nsresult result;
  nsAutoString tag, name, value;
  nsCOMPtr<nsIDOMElement> ele = do_QueryInterface(aNode);
  nsCOMPtr<nsIDOMNamedNodeMap> map;

  NS_ENSURE_TRUE(ele, NS_ERROR_NULL_POINTER);

  result = ele->GetTagName(tag);

  NS_ENSURE_SUCCESS(result, result);

  Write("n");
  WriteInt(aDepth);
  Write(" = GetCurrentEditor().editorDocument.createElement(\"");
  PrintUnicode(tag);
  Write("\");\n");

  result = aNode->GetAttributes(getter_AddRefs(map));

  NS_ENSURE_SUCCESS(result, result);

  NS_ENSURE_TRUE(map, NS_ERROR_NULL_POINTER);

  uint32_t i, len;
  nsCOMPtr<nsIDOMNode> attr;

  result = map->GetLength(&len);

  NS_ENSURE_SUCCESS(result, result);

  for (i = 0; i < len; i++)
  {
    result = map->Item(i, getter_AddRefs(attr));

    NS_ENSURE_SUCCESS(result, result);

    NS_ENSURE_TRUE(attr, NS_ERROR_NULL_POINTER);

    result = PrintAttributeNode(attr, aDepth);

    NS_ENSURE_SUCCESS(result, result);
  }

  result = PrintNodeChildren(aNode, aDepth);

  return result;
}
NS_IMETHODIMP
nsHTMLEditorLog::SetBackgroundColor(const nsAString& aColor)
{
  nsAutoHTMLEditorLogLock logLock(this);

  if (!mLocked && mFileStream)
  {
    Write("GetCurrentEditor().setBackgroundColor(\"");
    PrintUnicode(aColor);
    Write("\");\n");
    Flush();
  }

  return nsHTMLEditor::SetBackgroundColor(aColor);
}
NS_IMETHODIMP
nsHTMLEditorLog::InsertAsCitedQuotation(const nsAString& aQuotedText,
                                        const nsAString& aCitation,
                                        bool aInsertHTML,
                                        nsIDOMNode **aNodeInserted)
{
  nsAutoHTMLEditorLogLock logLock(this);

  if (!mLocked && mFileStream)
  {
    PrintSelection();
    Write("GetCurrentEditor().insertAsCitedQuotation(\"");
    PrintUnicode(aQuotedText);
    Write("\", \"");
    PrintUnicode(aCitation);
    Write("\", ");
    Write(aInsertHTML ? "true" : "false");
    Write("\");\n");
    Flush();
  }

  return nsHTMLEditor::InsertAsCitedQuotation(aQuotedText, aCitation, aInsertHTML,
                                              aNodeInserted);
}
NS_IMETHODIMP
nsHTMLEditorLog::Align(const nsAString& aAlign)
{
  nsAutoHTMLEditorLogLock logLock(this);

  if (!mLocked && mFileStream)
  {
    PrintSelection();

    Write("GetCurrentEditor().align(\"");
    PrintUnicode(aAlign);
    Write("\");\n");
    Flush();
  }

  return nsHTMLEditor::Align(aAlign);
}
NS_IMETHODIMP
nsHTMLEditorLog::SetParagraphFormat(const nsAString& aParagraphFormat)
{
  nsAutoHTMLEditorLogLock logLock(this);

  if (!mLocked && mFileStream)
  {
    PrintSelection();
    Write("GetCurrentEditor().setParagraphFormat(\"");
    PrintUnicode(aParagraphFormat);
    Write("\");\n");

    Flush();
  }

  return nsHTMLEditor::SetParagraphFormat(aParagraphFormat);
}
NS_IMETHODIMP
nsHTMLEditorLog::SetDocumentTitle(const nsAString& aTitle)
{
  nsAutoHTMLEditorLogLock logLock(this);

  if (!mLocked && mFileStream)
  {
    PrintSelection();

    Write("GetCurrentEditor().setDocumentTitle(\"");
    nsAutoString str(aTitle);
    PrintUnicode(str);
    Write("\");\n");
    Flush();
  }

  return nsHTMLEditor::SetDocumentTitle(aTitle);
}
NS_IMETHODIMP
nsHTMLEditorLog::PasteAsCitedQuotation(const nsAString& aCitation,
                                       int32_t aClipboardType)
{
  nsAutoHTMLEditorLogLock logLock(this);

  if (!mLocked && mFileStream)
  {
    PrintSelection();
    Write("GetCurrentEditor().pasteAsCitedQuotation(\"");
    PrintUnicode(aCitation);
    Write("\", ");
    WriteInt(aClipboardType);
    Write(");\n");
    Flush();
  }

  return nsHTMLEditor::PasteAsCitedQuotation(aCitation, aClipboardType);
}
NS_IMETHODIMP
nsHTMLEditorLog::InsertText(const nsAString& aStringToInsert)
{
  nsAutoHTMLEditorLogLock logLock(this);

  if (!mLocked && mFileStream)
  {
    PrintSelection();

    Write("GetCurrentEditor().insertText(\"");
    nsAutoString str(aStringToInsert);
    PrintUnicode(str);
    Write("\");\n");

    Flush();
  }

  return nsHTMLEditor::InsertText(aStringToInsert);
}
NS_IMETHODIMP
nsHTMLEditorLog::InsertAsPlaintextQuotation(const nsAString& aQuotedText,
                                            bool aAddCites,
                                            nsIDOMNode **aNodeInserted)
{
  nsAutoHTMLEditorLogLock logLock(this);

  if (!mLocked && mFileStream)
  {
    PrintSelection();
    Write("GetCurrentEditor().insertAsQuotation(\"");
    PrintUnicode(aQuotedText);
    Write("\");\n");
    Flush();
  }

  return nsHTMLEditor::InsertAsPlaintextQuotation(aQuotedText,
                                                  aAddCites,
                                                  aNodeInserted);
}
nsresult
nsHTMLEditorLog::PrintTextNode(nsIDOMNode *aNode, int32_t aDepth)
{
  nsresult result;

  nsCOMPtr<nsIDOMCharacterData> cd = do_QueryInterface(aNode);

  NS_ENSURE_TRUE(cd, NS_ERROR_NULL_POINTER);

  nsAutoString str;

  result = cd->GetData(str);

  NS_ENSURE_SUCCESS(result, result);

  Write("n");
  WriteInt(aDepth);
  Write(" = GetCurrentEditor().editorDocument.createTextNode(\"");
  PrintUnicode(str);
  Write("\");\n");

  return NS_OK;
}
Beispiel #17
0
String ReadLine()
{
    String ret;
    
    #ifdef _WIN32
    HANDLE input = GetStdHandle(STD_INPUT_HANDLE);
    HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
    if (input == INVALID_HANDLE_VALUE || output == INVALID_HANDLE_VALUE)
        return ret;

    // Use char-based input
    SetConsoleMode(input, ENABLE_PROCESSED_INPUT);

    INPUT_RECORD record;
    DWORD events = 0;
    DWORD readEvents = 0;

    if (!GetNumberOfConsoleInputEvents(input, &events))
        return ret;

    while (events--)
    {
        ReadConsoleInputW(input, &record, 1, &readEvents);
        if (record.EventType == KEY_EVENT && record.Event.KeyEvent.bKeyDown)
        {
            unsigned c = record.Event.KeyEvent.uChar.UnicodeChar;
            if (c)
            {
                if (c == '\b')
                {
                    PrintUnicode("\b \b");
                    size_t length = currentLine.LengthUTF8();
                    if (length)
                        currentLine = currentLine.SubstringUTF8(0, length - 1);
                }
                else if (c == '\r')
                {
                    PrintUnicode("\n");
                    ret = currentLine;
                    currentLine.Clear();
                    return ret;
                }
                else
                {
                    // We have disabled echo, so echo manually
                    wchar_t out = (wchar_t)c;
                    DWORD charsWritten;
                    WriteConsoleW(output, &out, 1, &charsWritten, 0);
                    currentLine.AppendUTF8(c);
                }
            }
        }
    }
    #else
    int flags = fcntl(STDIN_FILENO, F_GETFL);
    fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK);
    for (;;)
    {
        int ch = fgetc(stdin);
        if (ch >= 0 && ch != '\n')
            ret += (char)ch;
        else
            break;
    }
    #endif

    return ret;
}
Beispiel #18
0
void PrintUnicodeLine(const String& str, bool error)
{
    PrintUnicode(str + '\n', error);
}