⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test1.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 5 页
字号:
        int pos = p->selstartcharpos, col = 0, col2;
        while (pos)
        {
            if (p->text[pos].ch == '\n')
            {
                pos++;
                break;
            }
            pos--;
        }
        while (pos != p->selstartcharpos)
        {
            if (p->text[pos].ch == '\t')
            {
                col = col + p->tabs;
                col /= p->tabs;
                col *= p->tabs;
            }
            else
                col++;
            pos++;
        }
        col2 = col + p->tabs;
        col2 /= p->tabs;
        col2 *= p->tabs;
        while (col < col2)
        {
            insertchar(hwnd, p, ' ');
            col++;
        }
    }
}

/**********************************************************************
 * tab to the current line position
 **********************************************************************/
void insertcrtabs(HWND hwnd, EDITDATA *p)
{
    int pos, n;
    int oldinsert = p->inserting;
    if (!p->colorize)
        return ;
    if (editFlags &AUTO_INDENT)
        return ;
    p->inserting = TRUE;
    pos = p->selstartcharpos - 1;
    while (1)
    {
        while (pos && p->text[pos - 1].ch != '\n')
            pos--;
        while (p->text[pos].ch && isspace(p->text[pos].ch) && p->text[pos].ch 
            != '\n')
            pos++;
        if (p->text[pos].ch != '#')
            break;
        while (pos && p->text[pos - 1].ch != '\n')
            pos--;
        if (!pos)
            break;
        pos--;
    }
    n = curcol(p, p->text, pos);
    while (n >= p->tabs)
    {
        inserttab(hwnd, p);
        n -= p->tabs;
    }
    while (n--)
        insertchar(hwnd, p, ' ');
    p->inserting = oldinsert;
}

//-------------------------------------------------------------------------

int spacedend(EDITDATA *p, int pos)
{
    int rv = 0;
    while (pos && p->text[pos - 1].ch != '\n')
        pos--;
    rv = pos;
    while (p->text[pos].ch && isspace(p->text[pos].ch) && p->text[pos].ch !=
        '\n')
        pos++;
    if (p->text[pos].ch == '}')
        return rv;
    else
        return 0;
}

//-------------------------------------------------------------------------

int preprocline(EDITDATA *p, int pos)
{
    int rv;
    while (pos && p->text[pos - 1].ch != '\n')
        pos--;
    rv = pos;
    while (isspace(p->text[pos].ch))
        pos++;
    if (p->text[pos].ch == '#')
        return rv;
    else
        return  - 1;
}

/**********************************************************************
 * tab to the current line position
 **********************************************************************/
void InsertEndTabs(HWND hwnd, EDITDATA *p, int newend)
{
    int pos, n;
    int solpos, eospos;
    int lsolpos, leospos;
    int oldinsert = p->inserting;
    if (p->colorize != COLORIZE_C)
        return ;
    if (!newend)
        return ;
    if (editFlags &AUTO_FORMAT)
        return ;
    p->inserting = TRUE;
    leospos = pos = p->selstartcharpos - 1;
    while (isspace(p->text[leospos].ch) && p->text[leospos].ch != '\n')
        leospos++;
    if (lsolpos = spacedend(p, pos))
    {
        int indentlevel = 0;
        eospos = 0;
        pos--;
        while (pos > 0)
        {
            int pos1 = preprocline(p, pos);
            if (pos1 !=  - 1)
                pos = pos1;
            else if (p->text[pos].color != commentColor)
                if (p->text[pos].ch == '{')
			// LOOK HERE
            if (!indentlevel)
            {
                while (pos && p->text[pos - 1].ch != '\n')
                        pos--;
                while (isspace(p->text[pos].ch))
                    pos++;
                eospos = pos;
                break;
            }
            else
                indentlevel--;
            else if (p->text[pos].ch == '}')
                indentlevel++;
            pos--;
        }
        n = curcol(p, p->text, eospos);
        p->selstartcharpos = lsolpos;
        p->selendcharpos = leospos;
        Replace(hwnd, p, "", 0);
        while (n >= p->tabs)
        {
            inserttab(hwnd, p);
            n -= p->tabs;
        }
        while (n--)
            insertchar(hwnd, p, ' ');
        p->selstartcharpos = ++p->selendcharpos; // skip past '}'
    }
    p->inserting = oldinsert;
}

//-------------------------------------------------------------------------

void SelectIndent(HWND hwnd, EDITDATA *p, int insert)
{
    int olds = p->selstartcharpos;
    int olde = p->selendcharpos;
    int start = p->selstartcharpos;
    int end = p->selendcharpos;
    int oldinsert = p->inserting;
    UNDO *u;
    if (start == end)
        return ;
    if (end < start)
    {
        start = p->selendcharpos;
        end = p->selstartcharpos;
    }
    if (end && p->text[end - 1].ch == '\n')
        end--;
    p->inserting = TRUE;
    if (insert)
        u = undo_insertindent(p);
    else
        u = undo_deleteindent(p);
    while (start && p->text[start - 1].ch != '\n')
        start--;
    while (p->text[end].ch && p->text[end].ch != '\n')
        end++;
    p->undoing++;
    olds = start;
    while (start < end)
    {
        if (insert)
        {
            p->selstartcharpos = p->selendcharpos = start;
            inserttab(hwnd, p);
            end += p->selstartcharpos - start;
        }
        else
        {
            if (isspace(p->text[start].ch) && p->text[start].ch != '\n')
            {
                int count = 0;
                if (p->text[start + count].ch == ' ')
                    while (++count < p->tabs)
                        if (p->text[start + count].ch != ' ')
                            break;
                        else
                            count++;
                        else
                            count++;
                p->selstartcharpos = start;
                p->selendcharpos = start + count;
                Replace(hwnd, p, "", 0);
                end -= count;
            }
        }
        while (p->text[start].ch && p->text[start].ch != '\n')
            start++;
        if (p->text[start].ch)
            start++;
    }
    p->undoing--;
    p->selendcharpos = end;
    p->selstartcharpos = olds;
    p->inserting = oldinsert;
    if (u)
    {
        u->postselend = end;
        u->postselstart = olds;
    }
    InvalidateRect(hwnd, 0, 0);
}

//-------------------------------------------------------------------------

void DeletePound(HWND hwnd, EDITDATA *p)
{
    int n, m;
    if (p->colorize != COLORIZE_C)
        return ;
    if (editFlags &AUTO_FORMAT)
        return ;
    if (p->text[p->selstartcharpos - 1].ch != '#')
        return ;
    n = p->selstartcharpos - 1;
    while (n && p->text[n - 1].ch != '\n')
        n--;
    m = n;
    while (isspace(p->text[m].ch) && p->text[m].ch != '#')
        m++;
    if (p->text[m].ch != '#')
        return ;
    p->selstartcharpos = n;
    p->selendcharpos = m;
    Replace(hwnd, p, "", 0);
    p->selstartcharpos = p->selendcharpos = n + 1;
    ScrollCaretIntoView(hwnd, p);
}

//-------------------------------------------------------------------------

void DeletePercent(HWND hwnd, EDITDATA *p)
{
    int n, m;
    if (p->colorize != COLORIZE_ASM)
        return ;
    if (editFlags &AUTO_FORMAT)
        return ;
    if (p->text[p->selstartcharpos - 1].ch != '%')
        return ;
    n = p->selstartcharpos - 1;
    while (n && p->text[n - 1].ch != '\n')
        n--;
    m = n;
    while (isspace(p->text[m].ch) && p->text[m].ch != '%')
        m++;
    if (p->text[m].ch != '%')
        return ;
    p->selstartcharpos = n;
    p->selendcharpos = m;
    Replace(hwnd, p, "", 0);
    p->selstartcharpos = p->selendcharpos = n + 1;
    ScrollCaretIntoView(hwnd, p);
}

/**********************************************************************
 * go backwards to the last tab position
 **********************************************************************/
void backtab(HWND hwnd, EDITDATA *p)
{
    int pos = p->selstartcharpos, col = 0, col2;
    if (pos)
    {
        if (p->text[pos - 1].ch == '\t')
            p->selstartcharpos--;
        else
        {
            int sol;
            if (p->text[pos].ch == '\n')
                pos--;
            while (pos)
            {
                if (p->text[pos].ch == '\n')
                {
                    pos++;
                    break;
                }
                pos--;
            }
            sol = pos;
            while (pos != p->selstartcharpos)
            {
                if (p->text[pos].ch == '\t')
                {
                    col = col + p->tabs;
                    col /= p->tabs;
                    col *= p->tabs;
                }
                else
                    col++;
                pos++;
            }
            col2 = col - 1;
            col2 /= p->tabs;
            col2 *= p->tabs;
            col = 0;
            while (col < col2)
            {
                if (p->text[pos].ch == '\t')
                {
                    col = col + p->tabs;
                    col /= p->tabs;
                    col *= p->tabs;
                }
                else
                    col++;
                sol++;
            }
            p->selstartcharpos = sol;
        }
        Replace(hwnd, p, "", 0);
    }

}

/**********************************************************************
 * removecr cuts a CR/LF pair
 **********************************************************************/
void removecr(HWND hwnd, EDITDATA *p, int utype)
{
    #ifdef OLD_EDIT_FORMAT
        int del = 1;
    #else 
        int del = 0;
    #endif 
    int sel = SelLine(p, p->selstartcharpos);

    #ifdef OLD_EDIT_FORMAT
        if (p->text[p->selstartcharpos].ch == '\r' && p->text[p
            ->selstartcharpos + 1].ch == '\n')
    #else 
		// LOOK HERE
            if (p->text[p->selstartcharpos].ch == '\n')
    #endif 
            del++, sel++;
    SendMessage(GetParent(hwnd), EN_LINECHANGE, sel,  - 1);
    undo_deletechar(p, CRLF_DUMMY, utype);
    memcpy(p->text + p->selstartcharpos, p->text + p->selstartcharpos + del, (p
        ->textlen - p->selstartcharpos - del + 1) *sizeof(INTERNAL_CHAR));
    p->textlen -= del;
    SendUpdate(hwnd);
    p->sendchangeonpaint = TRUE;
    VScrollLen(hwnd,  - 1, FALSE);
    VScrollPos(hwnd,  - 1, FALSE);
}

/**********************************************************************
 * removechar cuts a character from the text (delete or back arrow)
 **********************************************************************/
void removechar(HWND hwnd, EDITDATA *p, int utype)
{
    if (p->inserting && p->selstartcharpos != p->selendcharpos)
    {
        Replace(hwnd, p, "", 0);
        ScrollCaretIntoView(hwnd, p);
    }
    else
    {
        int del;
        if (p->selstartcharpos == p->textlen)
            return ;
        #ifdef OLD_EDIT_FORMAT
            if (p->text[p->selstartcharpos].ch == '\r' || p->text[p
                ->selstartcharpos].ch == '\n')
            {
			// LOOK HERE kinda funny... probably the directives ought to line up...
            #else 
                if (p->text[p->selstartcharpos].ch == '\n')
                {
                #endif 
                removecr(hwnd, p, utype);
                ScrollCaretIntoView(hwnd, p);
                drawline(hwnd, p, p->selstartcharpos);
            }
            else
            {
                undo_deletechar(p, p->text[p->selstartcharpos].ch, utype);
                memcpy(p->text + p->selstartcharpos, p->text + p
                    ->selstartcharpos + 1, (p->textlen - p->selstartcharpos)
                    *sizeof(INTERNAL_CHAR));
                p->textlen--;
                drawline(hwnd, p, p->selstartcharpos);
            }
        }
        p->selendcharpos = p->selstartcharpos;
    }
    /**********************************************************************
     * SelToClipboard copies the current selection to the clipboard

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -