Пример #1
0
static void
cpbPushContent (const wchar_t *characters, size_t length) {
  if (length > 0) {
    Queue *queue = cpbGetHistoryQueue(1);

    if (queue) {
      Element *element = getQueueTail(queue);

      if (element) {
        const HistoryEntry *entry = getElementItem(element);

        if (length == entry->length) {
          if (wmemcmp(characters, entry->characters, length) == 0) {
            return;
          }
        }
      }

      {
        HistoryEntry *entry;

        if ((entry = malloc(sizeof(*entry)))) {
          if ((entry->characters = cpbAllocateCharacters(length))) {
            wmemcpy(entry->characters, characters, length);
            entry->length = length;

            if (enqueueItem(queue, entry)) {
              return;
            }

            free(entry->characters);
          } else {
            logMallocError();
          }

          free(entry);
        } else {
          logMallocError();
        }
      }
    }
  }
}
Пример #2
0
static wchar_t *
cpbReadScreen (size_t *length, int fromColumn, int fromRow, int toColumn, int toRow) {
  wchar_t *newBuffer = NULL;
  int columns = toColumn - fromColumn + 1;
  int rows = toRow - fromRow + 1;

  if ((columns >= 1) && (rows >= 1) && (beginOffset >= 0)) {
    wchar_t fromBuffer[rows * columns];

    if (readScreenText(fromColumn, fromRow, columns, rows, fromBuffer)) {
      wchar_t toBuffer[rows * (columns + 1)];
      wchar_t *toAddress = toBuffer;

      const wchar_t *fromAddress = fromBuffer;
      int row;

      for (row=fromRow; row<=toRow; row+=1) {
        int column;

        for (column=fromColumn; column<=toColumn; column+=1) {
          wchar_t character = *fromAddress++;
          if (iswcntrl(character) || iswspace(character)) character = WC_C(' ');
          *toAddress++ = character;
        }

        if (row != toRow) *toAddress++ = WC_C('\r');
      }

      /* make a new permanent buffer of just the right size */
      {
        size_t newLength = toAddress - toBuffer;

        if ((newBuffer = cpbAllocateCharacters(newLength))) {
          wmemcpy(newBuffer, toBuffer, (*length = newLength));
        }
      }
    }
  }

  return newBuffer;
}
Пример #3
0
int
cpbAddContent (const wchar_t *characters, size_t length) {
  size_t newLength = clipboardLength + length;

  if (newLength > clipboardSize) {
    size_t newSize = newLength | 0XFF;
    wchar_t *newCharacters = cpbAllocateCharacters(newSize);

    if (!newCharacters) {
      logMallocError();
      return 0;
    }

    wmemcpy(newCharacters, clipboardCharacters, clipboardLength);
    if (clipboardCharacters) free(clipboardCharacters);
    clipboardCharacters = newCharacters;
    clipboardSize = newSize;
  }

  wmemcpy(&clipboardCharacters[clipboardLength], characters, length);
  clipboardLength += length;
  return 1;
}