Beispiel #1
0
Static void checkSticky(Char *note, boolean *attrib)
{
  short i = 2;
  short l;
  Char c;
  Char a[256];

  if (*note == '\0')
    return;
  l = strlen(note);
  while (i <= l) {
    c = note[i-1];
    if (islower(c)) {
      if (i < l && note[i] == ':') {
	delete1(note, i + 1);
	l--;
	attrib[c - 'a'] = !attrib[c - 'a'];
      } else
	attrib[c - 'a'] = false;
    }
    i++;
  }
  attribs(a, note);
  for (c = 'z'; c >= 'a'; c--) {
    if (attrib[c - 'a'] && pos1(c, a) == 0)
      insertChar(c, note, 3);
  }
}
Beispiel #2
0
int dp(node* dict, char prefix[], char suffix[], int n) {
  if (!suffix[0]) {
    if (lookup(dict, prefix))
      return n;
    else
      return 0;
  }

  if (n <= 0)
    return 0;

  if (doubleLookup(dict, prefix, suffix))
    return n;

  char choices[ALPHABET_SIZE];
  int nchoices, i, j, result;
  nchoices = i = j = result = 0;

  getChoices(dict, prefix, choices, &nchoices);

  int results[2 + 2 * nchoices];
  results[i++] = accept(dict, prefix, suffix, n);
  results[i++] = delete(dict, prefix, suffix, n);

  for (j = 0; j < nchoices; ++j)
    results[i++] = swap(dict, prefix, suffix, n, choices[j]);

  for (j = 0; j < nchoices; ++j)
    results[i++] = insertChar(dict, prefix, suffix, n, choices[j]);

  for (i = 0; i < 2 + 2 * nchoices; i++)
    result = results[i] > result ? results[i] : result;

  return result;
}
Beispiel #3
0
static void
insertStr(struct edit *edit, char *str)
{
	while (*str) {
		insertChar(edit, *str);
		str++;
	}
}
Beispiel #4
0
/*
 * IMSpace - handle a space in insert mode
 */
vi_rc IMSpace( void )
{
    startNewLineUndo();
    CheckAbbrev( abbrevBuff, &abbrevCnt );
    abbrevCnt = 0;
    return( insertChar( FALSE, TRUE ) );

} /* IMSpace */
Beispiel #5
0
void MyMultiEdit::keyPressEvent( QKeyEvent *e )
{
  if( e->key() == Key_Tab )
    {
      insertChar('\t');
      return;
    }
  QMultiLineEdit::keyPressEvent(e);
  return;
}
Beispiel #6
0
static bool insertString( input_buffer *input, char *str )
{
    while( *str != '\0' ) {
        if( !insertChar( input, *str++ ) ) {
            return( false );
        }
    }
    return( true );

} /* insertString */
Beispiel #7
0
void PrefCharacter::slotDlgSpecCharClosed()
{
  if (m_dlgSpecChar)
  {
    disconnect(m_dlgSpecChar, SIGNAL(insertChar(QChar)), this, SLOT(slotSpecChar(QChar)));
    disconnect(m_dlgSpecChar, SIGNAL(finished()), this, SLOT(slotDlgSpecCharClosed()));
    m_dlgSpecChar->deleteLater();
    m_dlgSpecChar = 0;
  }
}
Beispiel #8
0
/* paste from clipboard */
static void paste(text_t *data) {
	char *clipbuf=TCOD_sys_clipboard_get();
	if ( clipbuf ) {
		if ( data->sel_start != MAX_INT ) {
			deleteSelection(data);
		}
		while (*clipbuf) {
			insertChar(data,*clipbuf++);
		}
	}
}
Beispiel #9
0
/*
 * IMEscapeNextChar - handle ^Q and ^V in insert mode
 */
vi_rc IMEscapeNextChar( void )
{
    vi_rc   rc;

    startNewLineUndo();
    LastEvent = '^';
    rc = insertChar( FALSE, FALSE );
    EditFlags.EscapedInsertChar = TRUE;
    return( rc );

} /* IMEscapeNextChar */
SpecialCharDialog::SpecialCharDialog( QWidget* parent, const char* name, bool modal, WFlags fl)
    :SpecialCharDialogS( parent, name, modal, fl )
{
  connect ( FilterLineEdit, SIGNAL(textChanged(const QString&)), 
      SLOT(filterChars(const QString&)) );
  connect ( CharsListBox, SIGNAL(doubleClicked(QListBoxItem*)), 
      SLOT(insertCode()) );
  connect (buttonOk, SIGNAL(clicked()), SLOT(insertCode()));
  connect (buttonChar, SIGNAL(clicked()), SLOT(insertChar()));
  connect (buttonCancel, SIGNAL(clicked()), SLOT(cancel()));
  filterChars("");
}
Beispiel #11
0
void PrefCharacter::slotSelectSpecChar()
{
  QString s = CharacterTree->currentItem()->text(2);
  QChar c = s[0];

  if (m_dlgSpecChar == 0)
  {
    m_dlgSpecChar = new DlgSpecChar(this, Prefs::editorFont(), c);
    connect(m_dlgSpecChar, SIGNAL(insertChar(QChar)), this, SLOT(slotSpecChar(QChar)));
    connect(m_dlgSpecChar, SIGNAL(finished()), this, SLOT(slotDlgSpecCharClosed()));
  }
  m_dlgSpecChar->show();
}
Beispiel #12
0
void
TextBuffer::insertSpan( std::string s, TextSpan &span ) { 

	startEdit( span.begin, span.end );

	if ( !span.empty() ) removeSpan(span);

	for ( t_CKUINT i=0; i < s.size(); i++) { 
		if ( s[i] == '\n' ) insertLine( span.end );
		else insertChar( s[i], span.end );
	}

	endEdit ( span.begin, span.end );
}
Beispiel #13
0
/* Put a character into a text buffer overwriting any text under the cursor */
void W_EDITBOX::overwriteChar(QChar ch)
{
	if (ch == '\0') return;

	ASSERT(insPos <= aText.length(), "overwriteChar: Invalid insertion point");

	if (insPos == aText.length())
	{
		// At end of string.
		insertChar(ch);
		return;
	}

	/* Store the character */
	aText[insPos] = ch;

	/* Update the insertion point */
	++insPos;
}
Beispiel #14
0
/*
 * IMChar - insert a character in insert mode
 */
vi_rc IMChar( void )
{
    if( CurrentFile == NULL ) {
        return( ERR_NO_ERR );
    }
    CurrentFile->need_autosave = TRUE;

    startNewLineUndo();
    if( EditFlags.EscapedInsertChar ) {
        DisplayWorkLine( SSKillsFlags( LastEvent ) ||
                         SSKillsFlags( WorkLine->data[CurrentPos.column - 1] ) );
        WorkLine->data[CurrentPos.column - 1] = LastEvent;
        GoToColumn( CurrentPos.column + 1, WorkLine->len + 1 );
        EditFlags.EscapedInsertChar = FALSE;
        return( ERR_NO_ERR );
    }

    return( insertChar( TRUE, TRUE ) );

} /* IMChar */
Beispiel #15
0
/*
 * IMCloseBracket - handle a ')' being entered in insert mode
 */
vi_rc IMCloseBracket( void )
{
    vi_rc       rc;
    i_mark      pos;

    startNewLineUndo();
    insertChar( TRUE, FALSE );
    if( EditFlags.ShowMatch ) {

        ReplaceCurrentLine();
        rc = FindMatch( &pos );
        if( rc == ERR_NO_ERR ) {
            tempMatch( &pos );
        }
        GetCurrentLine();

    }
    GoToColumn( CurrentPos.column + 1, WorkLine->len + 1 );
    return( ERR_NO_ERR );

} /* IMCloseBracket */
Beispiel #16
0
int main(void) {

	DList* mainList;
	mainList = startList(); // Starts the list with NULL value

	mainList = insertChar(mainList, 'C');
	//mainList = insertChar(mainList, 'H');
	//mainList = insertChar(mainList, 'E');
	//mainList = insertChar(mainList, 'R');
	//mainList = insertChar(mainList, 'R');
	//mainList = insertChar(mainList, 'Y');

	printList(mainList);

	mainList = freeListChar(mainList, 'C');

	printf("Remove: \n");
	printList(mainList);

	return EXIT_SUCCESS;
}
Beispiel #17
0
/* Put a character into a text buffer overwriting any text under the cursor */
bool W_EDITBOX::overwriteChar(QChar ch)
{
	if (ch == QChar('\0'))
	{
		return false;
	}

	ASSERT(insPos <= aText.length(), "overwriteChar: Invalid insertion point");
	dirty = true;

	if (insPos == aText.length())
	{
		// At end of string.
		return insertChar(ch);
	}

	/* Store the character */
	aText[insPos] = ch;

	/* Update the insertion point */
	++insPos;

	return true;
}
Beispiel #18
0
void ExternalInputSource::pushCharRef(Char ch, const NamedCharRef &ref)
{
  ASSERT(cur() == start());
  noteCharRef(startIndex() + (cur() - start()), ref);
  insertChar(ch);
}
Beispiel #19
0
 //listens to key presses when selected, records all keyboard input
void textIn::keyListen(sf::Event &e){

  try{
    //if there are any text objects to cycle through
    if(text.size() != 0){

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) &&  caretIndex > 0){

            //this is on the condition that the caret is not moved to the back of the box when it is
            //writing text that is longer than the box, the user can delete stuff rather than go back
            //to see what they have written as this kind of input box is very small and needs to be lower in
            //overhead
            if(caret2.getPosition().x - 16 > getPosX()){

                caretIndex--;
                setCaret(caretPosition.at(caretIndex), getPosY(), getHeight());
            }
        }
        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) && (caretIndex < caretPosition.size() -1)){

            caretIndex++;
            setCaret(caretPosition.at(caretIndex), getPosY(), getHeight());
        }
    }

    //this is not key pressed event at all this is textEntered its entirely different
    if (e.type == sf::Event::TextEntered){

        if (e.text.unicode < 128 && getSelected()){

             //if the same key as the last one was pressed not too recently
            if(lastKey == e.text.unicode ){

                //if a second has passed
                if(getTicks(0.7)){

                    //if the caret is next to the front most text object append text to the front of the vector else
                    //insert the character to the point where the caret is colliding
                    if(text.size() == 0 || caretX > (text.back().getPosition().x + text.back().getLocalBounds().width) - 10){

                        addChar(e.text.unicode);
                    }else{

                        insertChar( textIndex(), e.text.unicode);
                    }
               }

             //if backspace has been hit
            }else if( 8 == e.text.unicode){

                    //if the caret is next to the front most text object remove the front most object with remove char
                    //else remove the character at the point where the caret is colliding
                    if( text.size() == 0 || caretX > (text.back().getPosition().x + text.back().getLocalBounds().width) - 10){

                        removeChar();
                    }else{

                        if(caretIndex != 0)
                            removeChar(textIndex());
                    }

             //if the caret is next to the front most text object append text to the front of the vector else
            //insert the character to the point where the caret is colliding
            }else if(text.size() == 0 || caretX > (text.back().getPosition().x + text.back().getLocalBounds().width)  - 10)  {

                addChar(e.text.unicode);
                lastKey = e.text.unicode;
                getTicks(0.03);

            }else{

                insertChar(textIndex(), e.text.unicode);
                lastKey = e.text.unicode;
                getTicks(0.03);
            }
        }
    }
  }catch(...){

    std::cout<< "mystery error in key listen function caught";

    //seems to stabilise mystery eror 75% of the time
    resetPositions();
  }
}
Beispiel #20
0
void W_EDITBOX::run(W_CONTEXT *psContext)
{
	/* Note the edit state */
	unsigned editState = state & WEDBS_MASK;

	/* Only have anything to do if the widget is being edited */
	if ((editState & WEDBS_MASK) == WEDBS_FIXED)
	{
		return;
	}

	/* If there is a mouse click outside of the edit box - stop editing */
	int mx = psContext->mx;
	int my = psContext->my;
	if (mousePressed(MOUSE_LMB) && (mx < x || mx > x + width || my < y || my > y + height))
	{
		screenClearFocus(psContext->psScreen);
		return;
	}

	/* note the widget state */
	iV_SetFont(FontID);

	/* Loop through the characters in the input buffer */
	bool done = false;
	utf_32_char unicode;
	for (unsigned key = inputGetKey(&unicode); key != 0 && !done; key = inputGetKey(&unicode))
	{
		// Don't blink while typing.
		blinkOffset = wzGetTicks();

		int len = 0;

		/* Deal with all the control keys, assume anything else is a printable character */
		switch (key)
		{
		case INPBUF_LEFT :
			/* Move the cursor left */
			insPos = MAX(insPos - 1, 0);

			/* If the cursor has gone off the left of the edit box,
			 * need to update the printable text.
			 */
			if (insPos < printStart)
			{
				printStart = MAX(printStart - WEDB_CHARJUMP, 0);
				fitStringStart();
			}
			debug(LOG_INPUT, "EditBox cursor left");
			break;
		case INPBUF_RIGHT :
			/* Move the cursor right */
			len = aText.length();
			insPos = MIN(insPos + 1, len);

			/* If the cursor has gone off the right of the edit box,
			 * need to update the printable text.
			 */
			if (insPos > printStart + printChars)
			{
				printStart = MIN(printStart + WEDB_CHARJUMP, len - 1);
				fitStringStart();
			}
			debug(LOG_INPUT, "EditBox cursor right");
			break;
		case INPBUF_UP :
			debug(LOG_INPUT, "EditBox cursor up");
			break;
		case INPBUF_DOWN :
			debug(LOG_INPUT, "EditBox cursor down");
			break;
		case INPBUF_HOME :
			/* Move the cursor to the start of the buffer */
			insPos = 0;
			printStart = 0;
			fitStringStart();
			debug(LOG_INPUT, "EditBox cursor home");
			break;
		case INPBUF_END :
			/* Move the cursor to the end of the buffer */
			insPos = aText.length();
			if (insPos != printStart + printChars)
			{
				fitStringEnd();
			}
			debug(LOG_INPUT, "EditBox cursor end");
			break;
		case INPBUF_INS :
			if (editState == WEDBS_INSERT)
			{
				editState = WEDBS_OVER;
			}
			else
			{
				editState = WEDBS_INSERT;
			}
			debug(LOG_INPUT, "EditBox cursor insert");
			break;
		case INPBUF_DEL :
			delCharRight();

			/* Update the printable text */
			fitStringStart();
			debug(LOG_INPUT, "EditBox cursor delete");
			break;
		case INPBUF_PGUP :
			debug(LOG_INPUT, "EditBox cursor page up");
			break;
		case INPBUF_PGDN :
			debug(LOG_INPUT, "EditBox cursor page down");
			break;
		case INPBUF_BKSPACE :
			/* Delete the character to the left of the cursor */
			delCharLeft();

			/* Update the printable text */
			if (insPos <= printStart)
			{
				printStart = MAX(printStart - WEDB_CHARJUMP, 0);
			}
			fitStringStart();
			debug(LOG_INPUT, "EditBox cursor backspace");
			break;
		case INPBUF_TAB :
			debug(LOG_INPUT, "EditBox cursor tab");
			break;
		case INPBUF_CR :
		case KEY_KPENTER:                  // either normal return key || keypad enter
			/* Finish editing */
			focusLost(psContext->psScreen);
			screenClearFocus(psContext->psScreen);
			debug(LOG_INPUT, "EditBox cursor return");
			return;
			break;
		case INPBUF_ESC :
			debug(LOG_INPUT, "EditBox cursor escape");
			break;

		default:
			if (keyDown(KEY_LCTRL) || keyDown(KEY_RCTRL))
			{
				switch (key)
				{
					case KEY_V:
						aText = wzGetSelection();
						insPos = aText.length();
						/* Update the printable text */
						fitStringEnd();
						debug(LOG_INPUT, "EditBox paste");
						break;
					default:
						break;
				}
				break;
			}
			/* Dealt with everything else this must be a printable character */
			if (editState == WEDBS_INSERT)
			{
				insertChar(unicode);
			}
			else
			{
				overwriteChar(unicode);
			}
			len = aText.length();
			/* Update the printable chars */
			if (insPos == len)
			{
				fitStringEnd();
			}
			else
			{
				fitStringStart();
				if (insPos > printStart + printChars)
				{
					printStart = MIN(printStart + WEDB_CHARJUMP, len - 1);
					if (printStart >= len)
					{
						fitStringStart();
					}
				}
			}
			break;
		}
	}

	/* Store the current widget state */
	state = (state & ~WEDBS_MASK) | editState;
}
Beispiel #21
0
/* update returns false if enter has been pressed, true otherwise */
bool TCOD_text_update (TCOD_text_t txt, TCOD_key_t key) {
	int cx,cy,oldpos;
    text_t * data = (text_t*)txt;
    TCOD_IFNOT(data && data->con ) return false;
	oldpos = data->cursor_pos;
	/* for real-time keyboard : only on key release */
    if ( key.pressed ) {
	    /* process keyboard input */
	    switch (key.vk) {
	        case TCODK_BACKSPACE: /* get rid of the last character */
				if ( data->sel_start != MAX_INT ) {
					deleteSelection(data);
				} else {
					deleteChar(data);
				}
	            break;
			case TCODK_DELETE:
				if ( key.shift ) {
					/* SHIFT-DELETE : cut to clipboard */
					cut(data);
				} else {
					if ( data->sel_start != MAX_INT ) {
						deleteSelection(data);
					} else if ( data->text[data->cursor_pos] ) {
						data->cursor_pos++;
						deleteChar(data);
					}
				}
				break;
			/* shift + arrow / home / end = selection */
			/* ctrl + arrow = word skipping. ctrl + shift + arrow = word selection */
			case TCODK_LEFT:
				if ( data->multiline && key.shift && data->sel_end == -1) {
					data->sel_end = data->cursor_pos;
				}
				if ( data->cursor_pos > 0 ) {
					if ( key.lctrl || key.rctrl ) {
						previous_word(data);
					} else data->cursor_pos--;
					selectStart(data,oldpos,key);
				}
				break;
			case TCODK_RIGHT:
				if ( data->multiline && key.shift && data->sel_start == MAX_INT ) {
					data->sel_start = data->cursor_pos;
				}
				if ( data->text[data->cursor_pos] ) {
					if ( key.lctrl || key.rctrl ) {
						next_word(data);
					} else data->cursor_pos++;
					selectEnd(data,oldpos,key);
				}
				break;
			case TCODK_UP :
				get_cursor_coords(data,&cx,&cy);
				if ( data->multiline && key.shift && data->sel_end == -1) {
					data->sel_end = data->cursor_pos;
				}
				set_cursor_pos(data,cx,cy-1,false);
				selectStart(data,oldpos,key);
				break;
			case TCODK_DOWN :
				get_cursor_coords(data,&cx,&cy);
				if ( data->multiline && key.shift && data->sel_start == MAX_INT ) {
					data->sel_start = data->cursor_pos;
				}
				set_cursor_pos(data,cx,cy+1,false);
				selectEnd(data,oldpos,key);
				break;
			case TCODK_HOME:
				get_cursor_coords(data,&cx,&cy);
				if ( data->multiline && key.shift && data->sel_end == -1) {
					data->sel_end = data->cursor_pos;
				}
				if ( key.lctrl || key.rctrl ) {
					set_cursor_pos(data,0,0,true);
				} else {
					set_cursor_pos(data,0,cy,true);
				}
				selectStart(data,oldpos,key);
				break;
			case TCODK_END:
				get_cursor_coords(data,&cx,&cy);
				if ( data->multiline && key.shift && data->sel_start == MAX_INT ) {
					data->sel_start = data->cursor_pos;
				}
				if ( key.lctrl || key.rctrl ) {
					set_cursor_pos(data,data->w,data->h,true);
				} else {
					set_cursor_pos(data,data->w-1,cy,true);
				}
				selectEnd(data,oldpos,key);
				break;
	        case TCODK_ENTER: /* validate input */
	        case TCODK_KPENTER:
				if ( data->sel_start != MAX_INT ) {
					deleteSelection(data);
				}
				if ( data->multiline ) {
					get_cursor_coords(data,&cx,&cy);
					if ( cy < data->h-1 ) insertChar(data,'\n');
				} else {
		            data->input_continue = false;
				}
	            break;
			case TCODK_TAB :
				if (data->tab_size ) {
					int count=data->tab_size;
					if ( data->sel_start != MAX_INT ) {
						deleteSelection(data);
					}
					while ( count > 0 ) {
						insertChar(data,' ');
						count--;
					}
				}
				break;
	        default: { /* append a new character */
				if ( (key.c == 'c' || key.c=='C' || key.vk == TCODK_INSERT) && (key.lctrl || key.rctrl) ) {
					/* CTRL-C or CTRL-INSERT : copy to clipboard */
					copy(data);
				} else if ( (key.c == 'x' || key.c=='X') && (key.lctrl || key.rctrl) ) {
					/* CTRL-X : cut to clipboard */
					cut(data);
				} else if ( ((key.c == 'v' || key.c=='V') && (key.lctrl || key.rctrl))
					|| ( key.vk == TCODK_INSERT && key.shift )
					 ) {
					/* CTRL-V or SHIFT-INSERT : paste from clipboard */
					paste(data);
				} else if (key.c > 31) {
					if ( data->sel_start != MAX_INT ) {
						deleteSelection(data);
					}
					insertChar(data,(char)(key.c));
	            }
	            break;
	        }
	    }
    }
    return data->input_continue;
}
BOOL CALLBACK AnsiCharPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_INITDIALOG :
        {
			_listView.init(_hInst, _hSelf);
			int codepage = (*_ppEditView)->getCurrentBuffer()->getEncoding();
			_listView.setValues(codepage==-1?0:codepage);
			_listView.display();

            return TRUE;
        }

		case WM_NOTIFY:
		{
			switch (((LPNMHDR)lParam)->code)
			{
				case NM_DBLCLK:
				{
					LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE) lParam;
					int i = lpnmitem->iItem;

					if (i == -1)
						return TRUE;

					insertChar((unsigned char)i);
					return TRUE;
				}

				case LVN_KEYDOWN:
				{
					switch (((LPNMLVKEYDOWN)lParam)->wVKey)
					{
						case VK_RETURN:
						{
							int i = ListView_GetSelectionMark(_listView.getHSelf());

							if (i == -1)
								return TRUE;

							insertChar((unsigned char)i);
							return TRUE;
						}
						default:
							break;
					}
				}
				break;

				default:
					break;
			}
		}
		return TRUE;

        case WM_SIZE:
        {
            int width = LOWORD(lParam);
            int height = HIWORD(lParam);
			::MoveWindow(_listView.getHSelf(), 0, 0, width, height, TRUE);
            break;
        }

        default :
            return DockingDlgInterface::run_dlgProc(message, wParam, lParam);
    }
	return DockingDlgInterface::run_dlgProc(message, wParam, lParam);
}
Beispiel #23
0
void markDebeamed(voice_index voice, Char *note)
{
  if (isVocal(voice) && afterSlur(voice) == 0 && unbeamVocal() &&
      pos1(duration(voice), flagged) > 0)
    insertChar('a', note, 2);
}
Beispiel #24
0
/*
 * IMCloseBrace - handle '}' in insert mode
 */
vi_rc IMCloseBrace( void )
{
    int         i, j;
    int         ts;
    fcb         *cfcb;
    line        *cline;
    vi_rc       rc;
    int         newcol;
    i_mark      pos;

    startNewLineUndo();
    insertChar( TRUE, FALSE );
    newcol = CurrentPos.column + 1;
    if( EditFlags.ShowMatch ) {
        ReplaceCurrentLine();
        rc = FindMatch( &pos );
        if( rc == ERR_NO_ERR ) {
            tempMatch( &pos );
        }
        GetCurrentLine();
    }
    if( EditFlags.CMode ) {
        i = 0;
        while( isspace( WorkLine->data[i] ) ) {
            i++;
        }
        if( WorkLine->data[i] == '}' ) {
            /*
             * added a {, so:
             *   find matching }
             *   find out indentation of that line
             *   shift current line over to that indentation
             *   set current indentation to that
             */

            ReplaceCurrentLine();
            rc = findMatchingBrace( &pos );
            if( rc == ERR_NO_ERR ) {
                newcol = VirtualColumnOnCurrentLine( CurrentPos.column );
                CGimmeLinePtr( pos.line, &cfcb, &cline );
                i = FindStartOfALine( cline );
                i = GetVirtualCursorPosition( cline->data, i );
                j = i - VirtualColumnOnCurrentLine( CurrentPos.column );
                ts = EditVars.ShiftWidth;
                if( j > 0 ) {
                    EditVars.ShiftWidth = j;
                    Shift( CurrentPos.line, CurrentPos.line, '>', FALSE );
                } else if( j < 0 ) {
                    EditVars.ShiftWidth = -j;
                    Shift( CurrentPos.line, CurrentPos.line, '<', FALSE );
                }
                EditVars.ShiftWidth = ts;
                newcol = 1 + RealColumnOnCurrentLine( j + newcol );
            }
            GetCurrentLine();
        }
    }
    GoToColumn( newcol, WorkLine->len + 1 );
    return( ERR_NO_ERR );

} /* IMCloseBrace */
Beispiel #25
0
Xchar ExternalInputSource::fill(Messenger &mgr)
{
  ASSERT(cur() == end());
  while (end() >= bufLim_) {
    // need more data
    while (so_ == 0) {
      if (soIndex_ >= sov_.size())
	return eE;
      if (soIndex_ > 0)
	info_->noteStorageObjectEnd(bufLimOffset_ - (bufLim_ - end()));
      const StorageObjectSpec &spec = info_->spec(soIndex_);
      if (mayNotExist_) {
	NullMessenger nullMgr;
	sov_[soIndex_]
	  = spec.storageManager->makeStorageObject(spec.specId, spec.baseId,
						   spec.search,
						   mayRewind_, nullMgr,
						   info_->id(soIndex_));
      }
      else
	sov_[soIndex_]
	  = spec.storageManager->makeStorageObject(spec.specId, spec.baseId,
						   spec.search,
						   mayRewind_, mgr,
						   info_->id(soIndex_));
      so_ = sov_[soIndex_].pointer();
      if (so_) {
	decoder_ = spec.codingSystem->makeDecoder();
	info_->setDecoder(soIndex_, decoder_);
	zapEof_ = spec.zapEof;
	switch (spec.records) {
	case StorageObjectSpec::asis:
	  recordType_ = asis;
	  insertRS_ = false;
	  break;
	case StorageObjectSpec::cr:
	  recordType_ = cr;
	  break;
	case StorageObjectSpec::lf:
	  recordType_ = lf;
	  break;
	case StorageObjectSpec::crlf:
	  recordType_ = crlf;
	  break;
	case StorageObjectSpec::find:
	  recordType_ = unknown;
	  break;
	default:
	  CANNOT_HAPPEN();
	}
	soIndex_++;
	readSize_ = so_->getBlockSize();
	nLeftOver_ = 0;
	break;
      }
      else
	setAccessError();
      soIndex_++;
    }

    size_t keepSize = end() - start();
    const size_t align = sizeof(int)/sizeof(Char);
    size_t readSizeChars = (readSize_ + (sizeof(Char) - 1))/sizeof(Char);
    readSizeChars = roundUp(readSizeChars, align);
    size_t neededSize;		// in Chars
    size_t startOffset;
    // compute neededSize and readSize
    unsigned minBytesPerChar = decoder_->minBytesPerChar();
    if (nLeftOver_ == 0 && minBytesPerChar >= sizeof(Char)) {
      // In this case we want to do decoding in place.
      // FIXME It might be a win on some systems (Irix?) to arrange that the
      // read buffer is on a page boundary.

      if (keepSize >= size_t(-1)/sizeof(Char) - (align - 1) - insertRS_)
	abort();			// FIXME throw an exception
      
      // Now size_t(-1)/sizeof(Char) - (align - 1) - insertRS_ - keepSize > 0
      if (readSizeChars
	  > size_t(-1)/sizeof(Char) - (align - 1) - insertRS_ - keepSize)
	abort();
      neededSize = roundUp(readSizeChars + keepSize + insertRS_, align);
      startOffset = ((neededSize > bufSize_ ? neededSize : bufSize_)
		     - readSizeChars - insertRS_ - keepSize);
    }
    else {
      // Needs to be room for everything before decoding.
      neededSize = (keepSize + insertRS_ + readSizeChars
		    + (nLeftOver_ + sizeof(Char) - 1)/sizeof(Char));
      // Also must be room for everything after decoding.
      size_t neededSize2
	= (keepSize + insertRS_
	   // all the converted characters
	   + (nLeftOver_ + readSize_)/minBytesPerChar
	   // enough Chars to contain left over bytes
	   + ((readSize_ % minBytesPerChar + sizeof(Char) - 1)
	      / sizeof(Char)));
      if (neededSize2 > neededSize)
	neededSize = neededSize2;
      neededSize = roundUp(neededSize, align);
      if (neededSize > size_t(-1)/sizeof(Char))
	abort();
      startOffset = 0;
    }
    if (bufSize_ < neededSize)
      reallocateBuffer(neededSize);
    Char *newStart = buf_ + startOffset;
    if (newStart != start() && keepSize > 0)
      memmove(newStart, start(), keepSize*sizeof(Char));
    char *bytesStart = (char *)(buf_ + bufSize_ - readSizeChars) - nLeftOver_;
    if (nLeftOver_ > 0 && leftOver_ != bytesStart)
      memmove(bytesStart, leftOver_, nLeftOver_);
    moveStart(newStart);
    bufLim_ = end();

    size_t nread;
    if (so_->read((char *)(buf_ + bufSize_ - readSizeChars), readSize_,
		  mgr, nread)) {
      if (nread > 0) {
	const char *bytesEnd = bytesStart + nLeftOver_ + nread;
	size_t nChars = decoder_->decode((Char *)end() + insertRS_,
					 bytesStart,
					 nLeftOver_ + nread
					 - (zapEof_ && bytesEnd[-1] == EOFCHAR),
					 &leftOver_);
	nLeftOver_ = bytesEnd - leftOver_;
	if (nChars > 0) {
	  if (insertRS_) {
	    noteRS();
	    *(Char *)end() = RS;
	    advanceEnd(end() + 1);
	    insertRS_ = false;
	    bufLim_ += 1;
	    bufLimOffset_ += 1;
	  }
	  bufLim_ += nChars;
	  bufLimOffset_ += nChars;
	  break;
	}
      }
    }
    else
      so_ = 0;
  }
  ASSERT(end() < bufLim_);
  if (insertRS_) {
    noteRS();
    insertChar(RS);
    insertRS_ = false;
    bufLimOffset_ += 1;
  }
  switch (recordType_) {
  case unknown:
    {
      const Char *e = findNextCrOrLf(end(), bufLim_);
      if (e) {
	if (*e == '\n') {
	  recordType_ = lf;
	  info_->noteInsertedRSs();
	  *(Char *)e = RE;
	  advanceEnd(e + 1);
	  insertRS_ = true;
	}
	else {
	  if (e + 1 < bufLim_) {
	    if (e[1] == '\n') {
	      recordType_ = crlf;
	      advanceEnd(e + 1);
	      if (e + 2 == bufLim_) {
		bufLim_--;
		bufLimOffset_--;
		insertRS_ = true;
	      }
	    }
	    else {
	      advanceEnd(e + 1);
	      recordType_ = cr;
	      info_->noteInsertedRSs();
	      insertRS_ = true;
	    }
	  }
	  else {
	    recordType_ = crUnknown;
	    advanceEnd(e + 1);
	  }
	}
      }
      else
	advanceEnd(bufLim_);
    }
    break;
  case crUnknown:
    {
      if (*cur() == '\n') {
	noteRS();
	advanceEnd(cur() + 1);
	recordType_ = crlf;
      }
      else {
	advanceEnd(cur() + 1);
	insertRS_ = true;
	recordType_ = cr;
	info_->noteInsertedRSs();
      }
    }
    break;
  case lf:
    {
      Char *e = (Char *)findNextLf(end(), bufLim_);
      if (e) {
	advanceEnd(e + 1);
	*e = RE;
	insertRS_ = true;
      }
      else
	advanceEnd(bufLim_);
    }
    break;
  case cr:
    {
      const Char *e = findNextCr(end(), bufLim_);
      if (e) {
	advanceEnd(e + 1);
	insertRS_ = true;
      }
      else
	advanceEnd(bufLim_);
    }
    break;
  case crlf:
    {
      const Char *e = end();
      for (;;) {
	e = findNextLf(e, bufLim_);
	if (!e) {
	  advanceEnd(bufLim_);
	  break;
	}
	// Need to delete final RS if not followed by anything.
	if (e + 1 == bufLim_) {
	  bufLim_--;
	  bufLimOffset_--;
	  advanceEnd(e);
	  insertRS_ = true;
	  break;
	}
	noteRSAt(e);
	e++;
      }
    }
    break;
  case asis:
    advanceEnd(bufLim_);
    break;
  default:
    CANNOT_HAPPEN();
  }

  return nextChar();
}
Beispiel #26
0
Local Char *processOther(Char *Result, Char *note_,
			 struct LOC_processLine *LINK)
{
  Char note[256];

  strcpy(note, note_);
  switch (thisNote(LINK->voice)) {

  case other:
    if (note[0] == grace_group) {
      if (strlen(note) == 1)
	LINK->ngrace = 1;
      else
	LINK->ngrace = pos1(note[1], digits);
      if (LINK->ngrace > 0)
	LINK->ngrace--;
    }
    break;

  /* For a zword, take note of pitch but do not change the contents */
  /* Add spurious duration because repitch expects duration to be present */
  case zword:
    strcpy(LINK->cutnote, note);
    predelete(LINK->cutnote, 1);
    insertChar('4', LINK->cutnote, 2);
    checkOctave(LINK->voice, LINK->cutnote);
    renewPitch(LINK->voice, LINK->cutnote);
    break;

  case lyrtag:
    extractLyrtag(LINK->voice, note);
    break;

  case rbrac:
    endBeam(LINK->voice);
    break;

  case rparen:
  case rlparen:
    endSlur(LINK->voice, note);
    break;

  case lbrac:
    beginBeam(LINK->voice, note);
    break;

  case lparen:
    maybeDotted(note, LINK);
    beginSlur(LINK->voice, note);
    break;

  case mword:
    error3(LINK->voice, "Meter change must be the first word of its bar");
    break;

  case atword:
    lyricsAdjust(LINK->voice, note);
    break;
  }
  return strcpy(Result, note);
}
Beispiel #27
0
void genericAction(char *tmpBuffer, int size, char c)
{
	if(isControl())
	{
		toggleControl();

		setPressedChar(c);

		// control character
		switch(c)
		{
			case 'x':// cut
				// make sure highlight bounds are correct
				if(beginHighlight == -1 || endHighlight == -1)
				{
					return;
				}

				if(beginHighlight > endHighlight)
				{
					quickSwap(&beginHighlight, &endHighlight);
				}

				// perform cut
				setClipboardRange(tmpBuffer, beginHighlight, endHighlight);
				removeText(tmpBuffer, size);
				moveKBCursorAbsolute(beginHighlight);

				// reset the edit mode
				clearFakeHighlight();
				select = 0;
				break;
			case 'c':// copy
				// make sure highlight bounds are correct
				if(beginHighlight == -1 || endHighlight == -1)
				{
					return;
				}

				if(beginHighlight > endHighlight)
				{
					quickSwap(&beginHighlight, &endHighlight);
				}

				// perform copy
				setClipboardRange(tmpBuffer, beginHighlight, endHighlight);

				// reset the edit mode
				clearFakeHighlight();
				select = 0;
				break;
			case 'v':// paste
				if(beginHighlight != -1 && endHighlight != -1)
				{
					if(beginHighlight > endHighlight)
					{
						quickSwap(&beginHighlight, &endHighlight);
					}

					// we need to overwrite, but first check to make sure we don't overdo it
					if(strlen(tmpBuffer) - (endHighlight - beginHighlight) + strlen(getClipboard()) > size)
					{
						// after removing the current text and adding the new text, we are going over the size
						return;
					}

					// remove the current text
					removeText(tmpBuffer, size);
					moveKBCursorAbsolute(beginHighlight);
					clearFakeHighlight();
					select = 0;

					// cursor is now where we want to add the new text
					// we know also that there is enough room, so just insert the text

					// ensure we are inserting, even if overwrite
					uint16 tInsert = insert;
					insert = 1;

					char *tAdd = getClipboard();

					// loop and add chars
					while(*tAdd != 0)
					{
						insertChar(tmpBuffer, size, *tAdd);
						tAdd++;
					}

					// reset insert
					insert = tInsert;
				}
				else
				{
					if(strlen(tmpBuffer) + strlen(getClipboard()) > size)
					{
						// after adding the new text, we are going over the size
						return;
					}

					clearFakeHighlight();
					select = 0;

					// add the text
					char *tAdd = getClipboard();

					// loop and add chars
					while(*tAdd != 0)
					{
						insertChar(tmpBuffer, size, *tAdd);
						tAdd++;
					}
				}

				break;
		}
	}
	else
	{
		if(getKBCursor() < 0)
		{
			moveKBCursorAbsolute(0);
		}
		else if(getKBCursor() >= size)
		{
			moveKBCursorAbsolute(size - 1);
		}

		if(beginHighlight != -1 && endHighlight != -1)
		{
			if(beginHighlight > endHighlight)
			{
				quickSwap(&beginHighlight, &endHighlight);
			}

			// we have to clear out the data before performing the action
			removeText(tmpBuffer, size);

			// move the cursor
			moveKBCursorAbsolute(beginHighlight);

			// reset the edit mode
			clearFakeHighlight();
			select = 0;

			if(c == BSP || c == DEL)
			{
				// we've done the work required, exit

				return;
			}
		}

		if(c == BSP)
		{
			// backspace
			if(getKBCursor() == 0) // handle backspacing nothing
			{
				return;
			}

			int z;
			for(z=getKBCursor()-1;z<=size;z++)
			{
				tmpBuffer[z] = tmpBuffer[z+1];
			}

			moveKBCursorRelative(CURSOR_BACKWARD);
		}
		else if(c == DEL)
		{
			// del
			if(tmpBuffer[getKBCursor()] == 0) // handle deleting nothing
			{
				return;
			}

			moveKBCursorRelative(CURSOR_FORWARD);

			int z;
			for(z=getKBCursor()-1;z<=size;z++)
			{
				tmpBuffer[z] = tmpBuffer[z+1];
			}

			moveKBCursorRelative(CURSOR_BACKWARD);
		}
		else
		{
			// normal add
			insertChar(tmpBuffer, size, c);
		}

		tmpBuffer[size] = 0;
	}
}
Beispiel #28
0
void DlgSpecChar::slotUser1( )
{
  emit insertChar(chr());
  closeDialog();
}
Beispiel #29
0
void DlgSpecChar::slotDoubleClicked()
{
  emit insertChar(chr());
  closeDialog();
}
Beispiel #30
0
/*
 * getStringInWindow: main routine
 */
static bool getStringInWindow( input_buffer *input )
{
    vi_key      event;
    bool        old_mode;

    ReadingAString = true;
    initInput( input );
    input->last_str = alloca( input->buffer_length );
    memset( input->last_str, 0, input->buffer_length );
    if( input->h != NULL ) {
        input->curr_hist = input->h->curr;
    }
    for( ;; ) {
        event = GetNextEvent( false );
        event = cursorKeyFilter( input, event );
        event = historyFilter( input, event );
        event = specialKeyFilter( input, event );
        switch( event ) {
        case VI_KEY( NULL ):
            break;
        case VI_KEY( SHIFT_TAB ):
        case VI_KEY( TAB ):
            if( !fileComplete( input, event ) ) {
                endColumn( input );
                break;
            }
            /* fall through */
        case VI_KEY( ENTER ):
            if( input->buffer[0] == NO_ADD_TO_HISTORY_KEY ) {
                strcpy( &input->buffer[0], &input->buffer[1] );
            } else {
                addHistory( input );
            }
            /* fall through */
        case VI_KEY( ESC ):
            finiInput( input );
            /*
             * this call may not be necessary if the file complete window has
             * already closed of natural causes but it doesn't harm anything
             * if called when not needed - so we leave it here.
             */
            FinishFileComplete();
            ReadingAString = false;
            return( event != VI_KEY( ESC ) );
        case VI_KEY( INS ):
            input->overstrike = !input->overstrike;
            if( !EditFlags.NoInputWindow ) {
                NewCursor( input->window.id, input->overstrike ? EditVars.NormalCursorType : EditVars.InsertCursorType );
            }
            break;
        case VI_KEY( CTRL_END ):
            saveStr( input );
            input->buffer[input->curr_pos] = '\0';
            break;
        case VI_KEY( CTRL_X ):
        case VI_KEY( CTRL_U ):
            saveStr( input );
            input->buffer[0] = '\0';
            endColumn( input );
            break;
        case VI_KEY( CTRL_INS ):
            swapString( input );
            break;
        case VI_KEY( CTRL_V ):
        case VI_KEY( CTRL_Q ):
            insertChar( input, '^' );
            displayLine( input );
            // here we have a bit of a kluge
            input->curr_pos -= 1;
            event = GetNextEvent( false );
            saveStr( input );
            old_mode = input->overstrike;
            input->overstrike = true;
            insertChar( input, event );
            input->overstrike = old_mode;
            break;
        case VI_KEY( ALT_END ):
            /* just want to redraw the line - for windows */
            break;
        default:
            if( (event >= 32 && event < 256) || event == VI_KEY( CTRL_A ) ) {
                saveStr( input );
                if( !insertChar( input, event ) ) {
                    MyBeep();
                }
            }
        }
        if( !EditFlags.NoInputWindow ) {
            displayLine( input );
        }
    }

} /* getStringInWindow */