Ejemplo n.º 1
0
/* this function probably belongs somewhere else */
void WhoAmI(void)
{
  extern const char BUILD[];
  extern const char VERSION[];
  PrintString3("Version: ", VERSION,CR);
  PrintString3("Build: ", BUILD,CR);
  
  tVersion Version = GetWrapperVersion();
  PrintString3("Wrapper: ", Version.pSwVer,CR);
  
  PrintString2(SPP_DEVICE_NAME,CR);
  PrintString("Msp430 Version ");
  PrintCharacter(GetMsp430HardwareRevision());
  PrintString(CR);
  
  PrintStringAndDecimal("HwVersion: ", HardwareVersion());
}
Ejemplo n.º 2
0
// Интерпретировать следующий токен
bool EscInterpreter::InterpretNext()
{
    if (IsEndOfFile()) return false;

    unsigned char ch = GetNextByte();
    switch (ch)
    {
    case 0/*NUL*/: case 7/*BEL*/: case 17/*DC1*/: case 19/*DC3*/: case 127/*DEL*/:
        break; // Игнорируемые коды
    case 24/*CAN*/:
        m_endofpage = true;
        m_x = m_y = 0;
        return false; //Конец страницы
    case 8/*BS*/: // Backspace - сдвиг на 1 символ назад
        m_x -= m_shiftx;  if (m_x < 0) m_x = 0;
        break;
    case 9/*HT*/: // Горизонтальная табуляция - реализован частный случай
        //NOTE: переустановка позиций табуляции игнорируется
        m_x += m_shiftx * 8;
        m_x = (m_x / (m_shiftx * 8)) * (m_shiftx * 8);
        break;
    case 10/*LF*/: // Line Feed - сдвиг к следующей строке
        m_y += m_shifty;
        return true;
    case 11/*VT*/: //Вертикальная табуляция - в частном случае удовлетворяет описанию.
        //NOTE: Переустановка позиций табуляции игнорируется
        m_x = 0;  m_y += m_shifty;
        return true;
    case 12/*FF*/: // Form Feed - !!! доделать
        m_endofpage = true;
        m_x = m_y = 0;
        return false;
    case 13/*CR*/: // Carriage Return - возврат каретки
        m_x = 0;
        break;
    case 14/*SO*/: // Включение шрифта вразрядку
        m_fontsp = true;
        UpdateShiftX();
        break;
    case 15/*SI*/: // Включение сжатого шрифта (17.1 символов на дюйм)
        m_fontks = true;
        UpdateShiftX();
        break;
    case 18/*DC2*/: // Выключение сжатого шрифта
        m_fontks = false;
        UpdateShiftX();
        break;
    case 20/*DC4*/: // Выключение шрифта вразрядку
        m_fontsp = false;
        UpdateShiftX();
        break;
    case 27/*ESC*/:  //Expanded Function Codes
        return InterpretEscape();

        /* иначе "напечатать" символ */
    default:
        PrintCharacter(ch);
        m_x += m_shiftx;
        break;
    }

    return true;
}
Ejemplo n.º 3
0
/*!
 * \brief Read a line.
 *
 * This functions offers some editing capabilities and is typically
 * used for text input by human users.
 *
 * Line editing can be done by entering any of the following control 
 * characters:
 *
 * - \ref EDIT_KEY_RESTORE Restores initial default line (default ESC)
 * - \ref EDIT_KEY_REMOVE Deletes character on the left of the cursor (default CTRL-H)
 * - \ref EDIT_KEY_HOME Moves cursor to the beginning of the line (default Ctrl-A).
 * - \ref EDIT_KEY_END Moves cursor to the beginning of the line (default CTRL-E)
 * - \ref EDIT_KEY_LEFT Moves cursor one character to the left (default CTRL-B)
 * - \ref EDIT_KEY_RIGHT Moves cursor one character to the right (default CTRL-F)
 * - \ref EDIT_KEY_UP Walks up the list of previously entered lines (default CTRL-R)
 * - \ref EDIT_KEY_DOWN Walks down the list of previously entered lines (default CTRL-V)
 *
 * Note, that these commands may be modified by the currently registered 
 * remapping routine.
 *
 * \param el  Pointer to an \ref EDLINE structure, obtained by a 
 *            previous call to \ref EdLineOpen.
 * \param buf Pointer to the buffer that receives the text line.
 *            If it contains a string on entry, this will be used
 *            as the default value.
 * \param siz Number of bytes available in the buffer. The maximum
 *            length of the text string is 1 less, so the string
 *            is always properly terminated.
 *
 * \return Number of characters or -1 on errors.
 *
 * \todo Hidden entry for password input.
 */
int EdLineRead(EDLINE *el, char *buf, int siz)
{
    int ch;
    int cpos;
    int i;
#ifndef EDIT_DISABLE_HISTORY
    int ipos;
    int hidx = 0;
    int refresh = 0;
#endif

    /* Make sure that the string is terminated. */
    buf[siz - 1] = '\0';

#ifndef EDIT_DISABLE_HISTORY
    EditHistorySet(el->el_hist, 0, buf);
#endif
    PrintString(el, buf);
    cpos = strlen(buf);

    for (;;) {
        ch = (*el->el_get)(el->el_iparm);
        if (ch == EOF) {
            return -1;
        }
        ch = (*el->el_map)(ch, &el->el_seq);
        if (ch == EDIT_KEY_ENTER) {
            break;
        }
        /* Backspace removes the character in front of the cursor. */
        if (ch == EDIT_KEY_REMOVE) {
            if (cpos) {
                cpos--;
                for (i = cpos; i < siz - 1; i++) {
                    buf[i] = buf[i + 1];
                }
                if (el->el_mode & EDIT_MODE_ECHO) {
                    (*el->el_put)(el->el_oparm, EDIT_CHAR_BACKSPACE);
                }
                PrintString(el, &buf[cpos]);
                (*el->el_put)(el->el_oparm, EDIT_CHAR_SPACE);
                PrintCharacter(el, EDIT_CHAR_BACKSPACE, strlen(buf) + 1 - cpos);
            }
        }
#ifndef EDIT_DISABLE_HISTORY
        else if (ch == EDIT_KEY_RESTORE) {
            hidx = 0;
            refresh = 1;
        }
        else if (ch == EDIT_KEY_UP) {
            if (EditHistoryGet(el->el_hist, hidx + 1, NULL, 0) >= 0) {
                hidx++;
                refresh = 1;
            }
        }
        else if (ch == EDIT_KEY_DOWN) {
            if (hidx > 0) {
                hidx--;
                refresh = 1;
            }
        }
#endif
        else if (ch == EDIT_KEY_RIGHT) {
            if (cpos < strlen(buf)) {
                if (el->el_mode & EDIT_MODE_ECHO) {
                    (*el->el_put)(el->el_oparm, buf[cpos]);
                }
                cpos++;
            }
        }
        else if (ch == EDIT_KEY_LEFT) {
            if (cpos) {
                if (el->el_mode & EDIT_MODE_ECHO) {
                    (*el->el_put)(el->el_oparm, EDIT_CHAR_BACKSPACE);
                }
                cpos--;
            }
        }
        else if (ch == EDIT_KEY_HOME) {
            PrintCharacter(el, EDIT_CHAR_BACKSPACE, cpos);
            cpos = 0;
        }
        else if (ch == EDIT_KEY_END) {
            PrintString(el, &buf[cpos]);
            cpos = strlen(buf);
        }
        /* Normal character, insert at cursor position if buffer is not full. */
        else if (isprint(ch) && strlen(buf) < siz - 1) {
            for (i = siz - 1; i > cpos; i--) {
                buf[i] = buf[i - 1];
            }
            buf[cpos++] = ch;
            if (el->el_mode & EDIT_MODE_ECHO) {
                (*el->el_put)(el->el_oparm, ch);
            }
            PrintString(el, &buf[cpos]);
            PrintCharacter(el, EDIT_CHAR_BACKSPACE, strlen(buf) - cpos);
        } else {
            /* Beep on buffer overflow. */
            (*el->el_put)(el->el_oparm, EDIT_CHAR_ALARM);
        }
#ifndef EDIT_DISABLE_HISTORY
        if (refresh && (el->el_mode & EDIT_MODE_HISTORY) != 0) {
            refresh = 0;
            PrintCharacter(el, EDIT_CHAR_BACKSPACE, cpos);
            ipos = strlen(buf);
            EditHistoryGet(el->el_hist, hidx, buf, siz);
            cpos = strlen(buf);
            PrintString(el, buf);
            ClearLineEnd(el, ipos - cpos);
        }
#endif
    }
    PrintString(el, EDIT_STR_EOL);
#ifndef EDIT_DISABLE_HISTORY
    EditHistoryInsert(el->el_hist, 1, buf);
#endif
    return strlen(buf);
}
Ejemplo n.º 4
0
/*!
 * \brief Clear a given number of characters on the right side.
 *
 * Replaces a given number of characters on the right side of the
 * current cursor position. The cursor position is restored by
 * printing the same number of backspace characters.
 *
 * \param el  Pointer to an \ref EDLINE structure, obtained by a 
 *            previous call to \ref EdLineOpen.
 * \param num Number of characters to clear.
 */
static void ClearLineEnd(EDLINE *el, int num)
{
    PrintCharacter(el, EDIT_CHAR_SPACE, num);
    PrintCharacter(el, EDIT_CHAR_BACKSPACE, num);
}