예제 #1
0
void
PDFWriter::ToUnicode(const char *string, BString &unicode)
{
	int32 len = strlen(string);
	int32 srcLen = len, destLen = 255;
	int32 state = 0;
	char buffer[256];
	int32 srcStart = 0;
	int i = 0;

	unicode = "";
	if (len == 0) return;

	do {
		convert_from_utf8(B_UNICODE_CONVERSION, &string[srcStart], &srcLen,
			buffer, &destLen, &state);
		srcStart += srcLen;
		len -= srcLen;
		srcLen = len;

		char *b = unicode.LockBuffer(i + destLen);
		memcpy(&b[i], buffer, destLen);
		unicode.UnlockBuffer(i + destLen);
		i += destLen;
		destLen = 255;
	} while (len > 0);
}
예제 #2
0
void
BF_GUI_Text::FromUtf8(const char *pc_Source,char *pc_Dest)
{
	int32	iIN;
	int32	iOUT;
	int32	iStatus;
	uint32	iCP = GetConversion();

		if ( iCodePage == CP_UTF8 )
		{
			strcpy(pc_Dest,pc_Source);
		}
		else
		{
			iIN = strlen(pc_Source);
			iOUT = 255;
			convert_from_utf8(iCP,pc_Source,&iIN,pc_Dest,&iOUT,&iStatus);
			pc_Dest[iOUT] = 0;
		}
}
예제 #3
0
void
PDFWriter::DrawChar(uint16 unicode, const char* utf8, int16 size)
{
	// try to convert from utf8 to MacRoman encoding schema...
	int32 srcLen  = size;
	int32 destLen = 1;
	char dest[3] = "\0\0";
	int32 state = 0;
	bool embed = true;
	font_encoding encoding = macroman_encoding;
	char fontName[B_FONT_FAMILY_LENGTH+B_FONT_STYLE_LENGTH+1];

	if (convert_from_utf8(B_MAC_ROMAN_CONVERSION, utf8, &srcLen, dest, &destLen,
			&state, 0) != B_OK || dest[0] == 0) {
		// could not convert to MacRoman
		font_encoding fenc;
		uint16 index = 0;
		uint8 enc;

		GetFontName(&fState->beFont, fontName);
		embed = EmbedFont(fontName);

		REPORT(kDebug, -1, "find_encoding unicode %d\n", (int)unicode);
		if (find_encoding(unicode, enc, index)) {
			// is code point in the Adobe Glyph List?
			// Note if rendering the glyphs only would be desired, we could
			// always use the second method below (MakeUserDefinedEncoding),
			// but extracting text from the generated PDF would be almost
			// impossible (OCR!)
			REPORT(kDebug, -1, "encoding for %x -> %d %d", unicode, (int)enc,
				(int)index);
			// use one of the user pre-defined encodings
			if (fState->beFont.FileFormat() == B_TRUETYPE_WINDOWS) {
				encoding = font_encoding(enc + tt_encoding0);
			} else {
				encoding = font_encoding(enc + t1_encoding0);
			}
			*dest = index;
		} else if (embed) {
			// if the font is embedded, create a user defined encoding at runtime
			uint8 index;
			MakeUserDefinedEncoding(unicode, enc, index);
			*dest = index;
			encoding = font_encoding(user_defined_encoding_start + enc);
		} else if (find_in_cid_tables(unicode, fenc, index, fFontSearchOrder)) {
			// font is not embedded use one of the CJK fonts for substitution
			REPORT(kDebug, -1, "cid table %d index = %d", (int)fenc, (int)index);
			dest[0] = unicode / 256;
			dest[1] = unicode % 256;
			destLen = 2;
			encoding = fenc;
			embed = false;
		} else {
			static bool found = false;
			REPORT(kDebug, -1, "encoding for %x not found!", (int)unicode);
			if (!found) {
				found = true;
				REPORT(kError, fPage, "Could not find an encoding for character "
					"with unicode %d! Message is not repeated for other unicode "
					"values.", (int)unicode);
			}
			*dest = 0; // paint a box (is 0 a box in MacRoman) or
			return; // simply skip character
		}
	} else {
		REPORT(kDebug, -1, "macroman srcLen=%d destLen=%d dest= %d %d!", srcLen,
			destLen, (int)dest[0], (int)dest[1]);
	}

	// Note we have to build the user defined encoding before it is used in
	// PDF_find_font!
	if (!MakesPDF()) return;

	int		font;

	GetFontName(&fState->beFont, fontName, embed, encoding);
	font = FindFont(fontName, embed, encoding);
	if (font < 0) {
		REPORT(kWarning, fPage, "**** PDF_findfont(%s) failed, back to default "
			"font", fontName);
		font = PDF_findfont(fPdf, "Helvetica", "macroman", 0);
	}

	fState->font = font;

	uint16 face = fState->beFont.Face();
	PDF_set_parameter(fPdf, "underline", (face & B_UNDERSCORE_FACE) != 0
		? "true" : "false");
	PDF_set_parameter(fPdf, "strikeout", (face & B_STRIKEOUT_FACE) != 0
		? "true" : "false");
	PDF_set_value(fPdf, "textrendering", (face & B_OUTLINED_FACE) != 0 ? 1 : 0);

	PDF_setfont(fPdf, fState->font, scale(fState->beFont.Size()));

	const float x = tx(fState->penX);
	const float y = ty(fState->penY);
	const float rotation = fState->beFont.Rotation();
	const bool rotate = rotation != 0.0;

	if (rotate) {
		PDF_save(fPdf);
		PDF_translate(fPdf, x, y);
		PDF_rotate(fPdf, rotation);
	    PDF_set_text_pos(fPdf, 0, 0);
	} else
	    PDF_set_text_pos(fPdf, x, y);

	PDF_show2(fPdf, dest, destLen);

	if (rotate) {
		PDF_restore(fPdf);
	}
}
예제 #4
0
int
ACE_Svc_Conf_Lexer::scan (YYSTYPE* ace_yylval,
                          ACE_Svc_Conf_Param* param)

{
  ace_yy_buffer_state* buffer = param->buffer;

  // If we are not currently in any state, skip over whitespace
  if (buffer->state_ == ACE_NO_STATE)
    {
      while (buffer->index_ < buffer->size_ &&
             isspace (buffer->input_[buffer->index_]))
        {
          // Make sure that we count all of the new lines
          if (buffer->input_[buffer->index_] == '\n')
            {
              ++param->yylineno;
            }
          ++buffer->index_;
        }
    }

  size_t current;
  size_t last = buffer->size_ + (buffer->eof_ ? 1 : 0);
  for (current = buffer->index_; current < last; current++)
    {
      static const char* separators = " \t\r\n:*(){}";
      char c = (buffer->eof_ && current == buffer->size_ ?
                                     '\n' : buffer->input_[current]);
      switch (buffer->state_)
        {
          case ACE_COMMENT:
            if (c == '\n')
              {
                buffer->state_ = ACE_NO_STATE;
                buffer->index_ = current + 1;
                ++param->yylineno;
              }
            break;
          case ACE_STRING:
            if (!(c >= ' ' && c <= '~'))
              {
                // The character at currrent is definitely not part of
                // the string so we need to move current back one.
                --current;

                // Get the starting point of our string (skipping the quote)
                char* source = buffer->input_ + buffer->index_ + 1;

                // Now, we need to move back in the string until we find the
                // same character that started the string
                bool string_end_found = false;
                if (current > buffer->index_)
                  {
                    for (size_t i = current - buffer->index_; i-- != 0; )
                      {
                        if (source[i] == buffer->string_start_)
                          {
                            current = buffer->index_ + i + 1;
                            string_end_found = true;
                            break;
                          }
                      }
                  }

                if (!string_end_found)
                  {
                    ace_yyerror (++param->yyerrno,
                                 param->yylineno,
                                 ACE_TEXT ("Unable to find the end of the string"));
                    return ACE_NO_STATE;
                  }

                size_t amount = (current - buffer->index_) - 1;
#if defined (ACE_USES_WCHAR)
                ACE_TCHAR target[ACE_YY_CONVERSION_SPACE] = ACE_TEXT ("");
                size_t length = 0;
                if (!convert_from_utf8 (buffer->converter_,
                                        source,
                                        amount,
                                        target,
                                        ACE_YY_CONVERSION_SPACE,
                                        length))
                  {
                    ace_yyerror (++param->yyerrno,
                                 param->yylineno,
                                 ACE_TEXT ("Unable to convert string from UTF-8"));
                    return ACE_NO_STATE;
                  }
                amount = length;
#else
                char* target = source;
#endif /* ACE_USES_WCHAR */
                ace_yylval->ident_ = param->obstack.copy (target, amount);
                buffer->state_ = ACE_NO_STATE;
                buffer->index_ = current + 1;
                return ACE_STRING;
              }
            break;
          case ACE_NO_STATE:
            if (c == '"' || c == '\'')
              {
                buffer->string_start_ = c;
                buffer->state_ = ACE_STRING;
              }
            else if (c == '#')
              {
                buffer->state_ = ACE_COMMENT;
              }
            else if (ACE_OS::strchr (separators, c) != 0)
              {
                if (c == '\n')
                  {
                    ++param->yylineno;
                  }

                if (current == buffer->index_ + 1)
                  {
                    int const lower = ACE_OS::ace_tolower (
                                          buffer->input_[current - 1]);
                    if (c == ':' &&
                        (buffer->input_[current - 1] == '%' ||
                         (lower >= 'a' && lower <= 'z')))
                      {
                        // This is considered a path, so we need to
                        // skip over the ':' and go around the loop
                        // again
                        break;
                      }
                  }

                if (current == buffer->index_)
                  {
                    buffer->index_ = current + 1;
                    if (isspace (c))
                      {
                        // This is an empty line.
                        // Let's look for something else.
                        break;
                      }
                    else
                      {
                        return c;
                      }
                  }

                // String from buffer->index_ to current (inclusive)
                size_t size = (current - buffer->index_) + 1;
                ACE_TEMPORARY_STRING (str, size);
                ACE_OS::strncpy (str, buffer->input_ + buffer->index_,
                                 size - 1);
                str[size - 1] = '\0';


                if (ACE_OS::strcmp (str, "dynamic") == 0)
                  {
                    buffer->index_ = current;
                    return ACE_DYNAMIC;
                  }
                else if (ACE_OS::strcmp (str, "static") == 0)
                  {
                    buffer->index_ = current;
                    return ACE_STATIC;
                  }
                else if (ACE_OS::strcmp (str, "suspend") == 0)
                  {
                    buffer->index_ = current;
                    return ACE_SUSPEND;
                  }
                else if (ACE_OS::strcmp (str, "resume") == 0)
                  {
                    buffer->index_ = current;
                    return ACE_RESUME;
                  }
                else if (ACE_OS::strcmp (str, "remove") == 0)
                  {
                    buffer->index_ = current;
                    return ACE_REMOVE;
                  }
                else if (ACE_OS::strcmp (str, "stream") == 0)
                  {
                    buffer->index_ = current;
                    return ACE_USTREAM;
                  }
                else if (ACE_OS::strcmp (str, "Module") == 0)
                  {
                    buffer->index_ = current;
                    return ACE_MODULE_T;
                  }
                else if (ACE_OS::strcmp (str, "Service_Object") == 0)
                  {
                    buffer->index_ = current;
                    return ACE_SVC_OBJ_T;
                  }
                else if (ACE_OS::strcmp (str, "STREAM") == 0)
                  {
                    buffer->index_ = current;
                    return ACE_STREAM_T;
                  }
                else if (ACE_OS::strcmp (str, "active") == 0)
                  {
                    buffer->index_ = current;
                    return ACE_ACTIVE;
                  }
                else if (ACE_OS::strcmp (str, "inactive") == 0)
                  {
                    buffer->index_ = current;
                    return ACE_INACTIVE;
                  }
                else
                  {
                    // Get the string and save it in ace_yylval
                    int token = ACE_IDENT;
                    size_t amount = size - 1;
#if defined (ACE_USES_WCHAR)
                    ACE_TCHAR target[ACE_YY_CONVERSION_SPACE] = ACE_TEXT ("");
                    size_t length = 0;
                    if (!convert_from_utf8 (buffer->converter_,
                                            str,
                                            amount,
                                            target,
                                            ACE_YY_CONVERSION_SPACE,
                                            length))
                      {
                        ace_yyerror (++param->yyerrno,
                                     param->yylineno,
                                     ACE_TEXT ("Unable to convert ")
                                     ACE_TEXT ("identifier from UTF-8"));
                        return ACE_NO_STATE;
                      }
                    amount = length;
#else
                    char* target = str;
#endif /* ACE_USES_WCHAR */
                    ace_yylval->ident_ = param->obstack.copy (target, amount);

                    // Determine the difference between pathname and ident
                    if (ACE_OS::ace_isdigit (ace_yylval->ident_[0]))
                      {
                        token = ACE_PATHNAME;
                      }
                    else
                      {
                        static const ACE_TCHAR* path_parts =
                                                ACE_TEXT ("/\\:%.~-");
                        for (const ACE_TCHAR* p = path_parts; *p != '\0'; p++)
                          {
                            if (ACE_OS::strchr (ace_yylval->ident_, *p) != 0)
                              {
                                token = ACE_PATHNAME;
                                break;
                              }
                          }
                      }

                    buffer->state_ = ACE_NO_STATE;
                    buffer->index_ = current;
                    return token;
                  }
              }
            break;
          default:
            ace_yyerror (++param->yyerrno,
                         param->yylineno,
                         ACE_TEXT ("Unexpected state in ACE_Svc_Conf_Lexer::scan"));
            return ACE_NO_STATE;
        }
    }

  // We need more from the input source so, we will move the remainder of
  // the buffer to the front and signal that we need more
  if (!buffer->eof_)
    {
      buffer->need_more_ = true;
      if (buffer->state_ == ACE_COMMENT)
        {
          buffer->index_ = 0;
          buffer->size_  = 0;
        }
      else
        {
          buffer->size_ = current - buffer->index_;
          if (buffer->size_ != 0 && buffer->index_ != 0)
            ACE_OS::memmove (buffer->input_,
                             buffer->input_ + buffer->index_, buffer->size_);
          buffer->index_ = 0;
          buffer->state_ = ACE_NO_STATE;
        }
    }
  return ACE_NO_STATE;
}
예제 #5
0
_EXPORT status_t mail_convert_from_utf8 (
	uint32 dstEncoding,
	const char *src,
	int32 *srcLen,
	char *dst,
	int32 *dstLen,
	int32 *state,
	char substitute)
{
	int32		copyAmount;
	status_t	errorCode;
	int32		originalDstLen = *dstLen;
	int32		tempDstLen;
	int32		tempSrcLen;

	if (dstEncoding == B_MAIL_UTF8_CONVERSION)
	{
		copyAmount = *srcLen;
		if (*dstLen < copyAmount)
			copyAmount = *dstLen;
		memcpy (dst, src, copyAmount);
		*srcLen = copyAmount;
		*dstLen = copyAmount;
		return B_OK;
	}

	if (dstEncoding == B_MAIL_US_ASCII_CONVERSION)
	{
		int32			characterLength;
		int32			dstRemaining = *dstLen;
		unsigned char	letter;
		int32			srcRemaining = *srcLen;

		// state contains the number of source bytes to skip, left over from a
		// partial UTF-8 character split over the end of the buffer from last
		// time.
		if (srcRemaining <= *state) {
			*state -= srcRemaining;
			*dstLen = 0;
			return B_OK;
		}
		srcRemaining -= *state;
		src += *state;
		*state = 0;

		while (true) {
			if (srcRemaining <= 0 || dstRemaining <= 0)
				break;
			letter = *src;
			if (letter < 0x80)
				characterLength = 1; // Regular ASCII equivalent code.
			else if (letter < 0xC0)
				characterLength = 1; // Invalid in-between data byte 10xxxxxx.
			else if (letter < 0xE0)
				characterLength = 2;
			else if (letter < 0xF0)
				characterLength = 3;
			else if (letter < 0xF8)
				characterLength = 4;
			else if (letter < 0xFC)
				characterLength = 5;
			else if (letter < 0xFE)
				characterLength = 6;
			else
				characterLength = 1; // 0xFE and 0xFF are invalid in UTF-8.
			if (letter < 0x80)
				*dst++ = *src;
			else
				*dst++ = substitute;
			dstRemaining--;
			if (srcRemaining < characterLength) {
				// Character split past the end of the buffer.
				*state = characterLength - srcRemaining;
				srcRemaining = 0;
			} else {
				src += characterLength;
				srcRemaining -= characterLength;
			}
		}
		// Update with the amounts used.
		*srcLen = *srcLen - srcRemaining;
		*dstLen = *dstLen - dstRemaining;
		return B_OK;
	}

	errorCode = convert_from_utf8 (dstEncoding, src, srcLen, dst, dstLen, state, substitute);
	if (errorCode != B_OK)
		return errorCode;

	if (dstEncoding != B_JIS_CONVERSION)
		return B_OK;

	// B_JIS_CONVERSION (ISO-2022-JP) works by shifting between different
	// character subsets.  For E-mail headers (and other uses), it needs to be
	// switched back to ASCII at the end (otherwise the last character gets
	// lost or other weird things happen in the headers).  Note that we can't
	// just append the escape code since the convert_from_utf8 "state" will be
	// wrong.  So we append an ASCII letter and throw it away, leaving just the
	// escape code.  Well, it actually switches to the Roman character set, not
	// ASCII, but that should be OK.

	tempDstLen = originalDstLen - *dstLen;
	if (tempDstLen < 3) // Not enough space remaining in the output.
		return B_OK; // Sort of an error, but we did convert the rest OK.
	tempSrcLen = 1;
	errorCode = convert_from_utf8 (dstEncoding, "a", &tempSrcLen,
		dst + *dstLen, &tempDstLen, state, substitute);
	if (errorCode != B_OK)
		return errorCode;
	*dstLen += tempDstLen - 1 /* don't include the ASCII letter */;
	return B_OK;
}
예제 #6
0
void
Renamer_Remove::RenameList(BList* FileList)
{
	Renamer::RenameList(FileList);

	bool FromRight1 = bool(fDirection1->Menu()
		->IndexOf(fDirection1->Menu()->FindMarked()));
	bool FromRight2 = bool(fDirection2->Menu()
		->IndexOf(fDirection2->Menu()->FindMarked()));

	FileListItem* ListItem;
	BString ResultString, Part2;
	int EndPart1, StartPart2;

	int32 Position1 = fPosition1->Value();
	int32 Position2 = fPosition2->Value();	
	int32 positionMaxValue = 0;
	int32 UTF_LengthOfFilename, LengthOfFilename;
		
	for (int i = 0; i < fNumberOfItems; i++) {
		ListItem = (FileListItem* )FileList->ItemAt(i);
		UTF_LengthOfFilename = LengthOfFilename = ListItem->fName.Length();

		if (LengthOfFilename > positionMaxValue)
			positionMaxValue = LengthOfFilename;

		char* tempStr = new char[UTF_LengthOfFilename + 1];

		convert_from_utf8(B_ISO1_CONVERSION, ListItem->fName.String(),
			&UTF_LengthOfFilename, tempStr, &LengthOfFilename, 0);
		tempStr[LengthOfFilename] = 0;

		if (FromRight1) {
			EndPart1 = (LengthOfFilename >= Position1)
				? LengthOfFilename - Position1 : 0;
		} else {
			EndPart1 = (LengthOfFilename >= Position1)
				? Position1 : LengthOfFilename;
		}

		if (FromRight2) {
			StartPart2 = (LengthOfFilename >= Position2)
				? LengthOfFilename - Position2 : 0;
		} else {
			StartPart2 = (LengthOfFilename >= Position2)
				? Position2 : LengthOfFilename;
		}

		if (StartPart2 < EndPart1)
			std::swap(StartPart2, EndPart1);

		ResultString.SetTo(tempStr, EndPart1);

		BString(tempStr).CopyInto(Part2, StartPart2,
			LengthOfFilename - StartPart2);
		ResultString.Append(Part2);

		LengthOfFilename = ResultString.Length();
		UTF_LengthOfFilename = LengthOfFilename*  2;
		char* utf_String = new char[UTF_LengthOfFilename + 1];
		
		convert_to_utf8(B_ISO1_CONVERSION, ResultString.String(),
			&LengthOfFilename, utf_String, &UTF_LengthOfFilename, 0);
		utf_String[UTF_LengthOfFilename] = 0;

		ListItem->SetNewName(utf_String);
	}
	fPosition1->SetMaxValue(positionMaxValue);
	fPosition2->SetMaxValue(positionMaxValue);
}
예제 #7
0
static bytea *
decrypt_internal(int is_pubenc, int need_text, text *data,
				 text *key, text *keypsw, text *args)
{
	int			err;
	MBuf	   *src = NULL,
			   *dst = NULL;
	uint8		tmp[VARHDRSZ];
	uint8	   *restmp;
	bytea	   *res;
	int			res_len;
	PGP_Context *ctx = NULL;
	struct debug_expect ex;
	int			got_unicode = 0;


	init_work(&ctx, need_text, args, &ex);

	src = mbuf_create_from_data((uint8 *) VARDATA(data),
								VARSIZE(data) - VARHDRSZ);
	dst = mbuf_create(VARSIZE(data) + 2048);

	/*
	 * reserve room for header
	 */
	mbuf_append(dst, tmp, VARHDRSZ);

	/*
	 * set key
	 */
	if (is_pubenc)
	{
		uint8	   *psw = NULL;
		int			psw_len = 0;
		MBuf	   *kbuf;

		if (keypsw)
		{
			psw = (uint8 *) VARDATA(keypsw);
			psw_len = VARSIZE(keypsw) - VARHDRSZ;
		}
		kbuf = create_mbuf_from_vardata(key);
		err = pgp_set_pubkey(ctx, kbuf, psw, psw_len, 1);
		mbuf_free(kbuf);
	}
	else
		err = pgp_set_symkey(ctx, (uint8 *) VARDATA(key),
							 VARSIZE(key) - VARHDRSZ);

	/*
	 * decrypt
	 */
	if (err >= 0)
		err = pgp_decrypt(ctx, src, dst);

	/*
	 * failed?
	 */
	if (err < 0)
		goto out;

	if (ex.expect)
		check_expect(ctx, &ex);

	/* remember the setting */
	got_unicode = pgp_get_unicode_mode(ctx);

out:
	if (src)
		mbuf_free(src);
	if (ctx)
		pgp_free(ctx);

	if (err)
	{
		px_set_debug_handler(NULL);
		if (dst)
			mbuf_free(dst);
		ereport(ERROR,
				(errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
				 errmsg("%s", px_strerror(err))));
	}

	res_len = mbuf_steal_data(dst, &restmp);
	mbuf_free(dst);

	/* res_len includes VARHDRSZ */
	res = (bytea *) restmp;
	SET_VARSIZE(res, res_len);

	if (need_text && got_unicode)
	{
		text	   *utf = convert_from_utf8(res);

		if (utf != res)
		{
			clear_and_pfree(res);
			res = utf;
		}
	}
	px_set_debug_handler(NULL);

	/*
	 * add successfull decryptions also into RNG
	 */
	add_entropy(res, key, keypsw);

	return res;
}
예제 #8
0
void
TermView::DefaultState::KeyDown(const char* bytes, int32 numBytes)
{
	int32 key;
	int32 mod;
	int32 rawChar;
	BMessage* currentMessage = fView->Looper()->CurrentMessage();
	if (currentMessage == NULL)
		return;

	currentMessage->FindInt32("modifiers", &mod);
	currentMessage->FindInt32("key", &key);
	currentMessage->FindInt32("raw_char", &rawChar);

	fView->_ActivateCursor(true);

	// handle multi-byte chars
	if (numBytes > 1) {
		if (fView->fEncoding != M_UTF8) {
			char destBuffer[16];
			int32 destLen = sizeof(destBuffer);
			int32 state = 0;
			convert_from_utf8(fView->fEncoding, bytes, &numBytes, destBuffer,
				&destLen, &state, '?');
			fView->_ScrollTo(0, true);
			fView->fShell->Write(destBuffer, destLen);
			return;
		}

		fView->_ScrollTo(0, true);
		fView->fShell->Write(bytes, numBytes);
		return;
	}

	// Terminal filters RET, ENTER, F1...F12, and ARROW key code.
	const char *toWrite = NULL;

	switch (*bytes) {
		case B_RETURN:
			if (rawChar == B_RETURN)
				toWrite = "\r";
			break;

		case B_DELETE:
			toWrite = DELETE_KEY_CODE;
			break;

		case B_BACKSPACE:
			// Translate only the actual backspace key to the backspace
			// code. CTRL-H shall just be echoed.
			if (!((mod & B_CONTROL_KEY) && rawChar == 'h'))
				toWrite = BACKSPACE_KEY_CODE;
			break;

		case B_LEFT_ARROW:
			if (rawChar == B_LEFT_ARROW) {
				if ((mod & B_SHIFT_KEY) != 0) {
					if (fView->fListener != NULL)
						fView->fListener->PreviousTermView(fView);
					return;
				}
				if ((mod & B_CONTROL_KEY) || (mod & B_COMMAND_KEY))
					toWrite = CTRL_LEFT_ARROW_KEY_CODE;
				else
					toWrite = LEFT_ARROW_KEY_CODE;
			}
			break;

		case B_RIGHT_ARROW:
			if (rawChar == B_RIGHT_ARROW) {
				if ((mod & B_SHIFT_KEY) != 0) {
					if (fView->fListener != NULL)
						fView->fListener->NextTermView(fView);
					return;
				}
				if ((mod & B_CONTROL_KEY) || (mod & B_COMMAND_KEY))
					toWrite = CTRL_RIGHT_ARROW_KEY_CODE;
				else
					toWrite = RIGHT_ARROW_KEY_CODE;
			}
			break;

		case B_UP_ARROW:
			if (mod & B_SHIFT_KEY) {
				fView->_ScrollTo(fView->fScrollOffset - fView->fFontHeight,
					true);
				return;
			}
			if (rawChar == B_UP_ARROW) {
				if (mod & B_CONTROL_KEY)
					toWrite = CTRL_UP_ARROW_KEY_CODE;
				else
					toWrite = UP_ARROW_KEY_CODE;
			}
			break;

		case B_DOWN_ARROW:
			if (mod & B_SHIFT_KEY) {
				fView->_ScrollTo(fView->fScrollOffset + fView->fFontHeight,
					true);
				return;
			}

			if (rawChar == B_DOWN_ARROW) {
				if (mod & B_CONTROL_KEY)
					toWrite = CTRL_DOWN_ARROW_KEY_CODE;
				else
					toWrite = DOWN_ARROW_KEY_CODE;
			}
			break;

		case B_INSERT:
			if (rawChar == B_INSERT)
				toWrite = INSERT_KEY_CODE;
			break;

		case B_HOME:
			if (rawChar == B_HOME)
				toWrite = HOME_KEY_CODE;
			break;

		case B_END:
			if (rawChar == B_END)
				toWrite = END_KEY_CODE;
			break;

		case B_PAGE_UP:
			if (mod & B_SHIFT_KEY) {
				fView->_ScrollTo(
					fView->fScrollOffset - fView->fFontHeight  * fView->fRows,
					true);
				return;
			}
			if (rawChar == B_PAGE_UP)
				toWrite = PAGE_UP_KEY_CODE;
			break;

		case B_PAGE_DOWN:
			if (mod & B_SHIFT_KEY) {
				fView->_ScrollTo(
					fView->fScrollOffset + fView->fFontHeight * fView->fRows,
					true);
				return;
			}
			if (rawChar == B_PAGE_DOWN)
				toWrite = PAGE_DOWN_KEY_CODE;
			break;

		case B_FUNCTION_KEY:
			for (int32 i = 0; i < 12; i++) {
				if (key == function_keycode_table[i]) {
					toWrite = function_key_char_table[i];
					break;
				}
			}
			break;
	}

	// If the above code proposed an alternative string to write, we get it's
	// length. Otherwise we write exactly the bytes passed to this method.
	size_t toWriteLen;
	if (toWrite != NULL) {
		toWriteLen = strlen(toWrite);
	} else {
		toWrite = bytes;
		toWriteLen = numBytes;
	}

	fView->_ScrollTo(0, true);
	fView->fShell->Write(toWrite, toWriteLen);
}
예제 #9
0
void GetScrap(void **handle, uint32 type, int32 offset)
{
	M68kRegisters r;
	D(bug("GetScrap handle %p, type %08lx, offset %ld\n", handle, type, offset));
	return;	//!! GetScrap is currently broken (should use Clipboard Manager)
			//!! replace with clipboard notification in BeOS R4.1

	switch (type) {
		case 'TEXT':
			D(bug(" clipping TEXT\n"));
			if (be_clipboard->Lock()) {
				BMessage *clipper = be_clipboard->Data(); 
				char *clip;
				ssize_t length;

				// Check if we already copied this data
				if (clipper->HasData("application/x-SheepShaver-cookie", B_MIME_TYPE))
					return;
				bigtime_t cookie = system_time();
				clipper->AddData("application/x-SheepShaver-cookie", B_MIME_TYPE, &cookie, sizeof(bigtime_t)); 

				// No, is there text in it?
				if (clipper->FindData("text/plain", B_MIME_TYPE, &clip, &length) == B_OK) {
					D(bug(" text/plain found\n"));

					// Convert text from UTF-8 to Mac charset
					int32 src_length = length;
					int32 dest_length = length;
					int32 state = 0;
					char *outbuf = new char[dest_length];
					if (convert_from_utf8(B_MAC_ROMAN_CONVERSION, clip, &src_length, outbuf, &dest_length, &state) == B_OK) {
						for (int i=0; i<dest_length; i++)
							if (outbuf[i] == 10)
								outbuf[i] = 13;

						// Add text to Mac clipboard
						static uint16 proc[] = {
							0x598f,					// subq.l	#4,sp
							0xa9fc,					// ZeroScrap()
							0x2f3c, 0, 0,			// move.l	#length,-(sp)
							0x2f3c, 'TE', 'XT',		// move.l	#'TEXT',-(sp)
							0x2f3c, 0, 0,			// move.l	#outbuf,-(sp)
							0xa9fe,					// PutScrap()
							0x588f,					// addq.l	#4,sp
							M68K_RTS
						};
						*(int32 *)(proc + 3) = dest_length;
						*(char **)(proc + 9) = outbuf;
						we_put_this_data = true;
						Execute68k((uint32)proc, &r);
					} else {
						D(bug(" text conversion failed\n"));
					}
					delete[] outbuf;
				}
				be_clipboard->Commit();
				be_clipboard->Unlock();
			}
			break;

		case 'PICT':
			D(bug(" clipping PICT\n"));
			if (be_clipboard->Lock()) {
				BMessage *clipper = be_clipboard->Data(); 
				char *clip;
				ssize_t length;

				// Check if we already copied this data
				if (clipper->HasData("application/x-SheepShaver-cookie", B_MIME_TYPE))
					return;
				bigtime_t cookie = system_time();
				clipper->AddData("application/x-SheepShaver-cookie", B_MIME_TYPE, &cookie, sizeof(bigtime_t)); 

				static uint16 proc2[] = {
					0x598f,					// subq.l	#4,sp
					0xa9fc,					// ZeroScrap()
					0x2f3c, 0, 0,			// move.l	#length,-(sp)
					0x2f3c, 'PI', 'CT',		// move.l	#'PICT',-(sp)
					0x2f3c, 0, 0,			// move.l	#buf,-(sp)
					0xa9fe,					// PutScrap()
					0x588f,					// addq.l	#4,sp
					M68K_RTS
				};

				// No, is there a pict ?
				if (clipper->FindData("image/pict", B_MIME_TYPE, &clip, &length) == B_OK ) {
					D(bug(" image/pict found\n"));

					// Add pict to Mac clipboard
					*(int32 *)(proc2 + 3) = length;
					*(char **)(proc2 + 9) = clip;
					we_put_this_data = true;
					Execute68k((uint32)proc2, &r);
#if 0
				// No, is there a bitmap ?
				} else if (clipper->FindData("image/x-be-bitmap", B_MIME_TYPE, &clip, &length) == B_OK || output_cap > 0) {
					D(bug(" image/x-be-bitmap found\nstarting conversion to PICT\n"));

					BMemoryIO *in_buffer = new BMemoryIO(clip, length);
					BMallocIO *out_buffer = new BMallocIO();
					status_t result=roster->Translate(output_trans,in_buffer,NULL,out_buffer,'PICT');
					D(bug("result of conversion:%08x buffer_size:%d\n",result,out_buffer->BufferLength()));

					// Add pict to Mac clipboard
					*(int32 *)(proc2 + 3) = out_buffer->BufferLength();
					*(char **)(proc2 + 9) = (char *)out_buffer->Buffer();
					we_put_this_data = true;
					Execute68k(proc2, &r);

					delete in_buffer;
					delete out_buffer;
#endif
				}
				be_clipboard->Commit();
				be_clipboard->Unlock();
			}
			break;
	}
}