예제 #1
0
파일: line.c 프로젝트: mingpen/OpenNT
/* compare two lines. return TRUE if they are the same. uses
 * ignore_blanks to determine whether to ignore any
 * spaces/tabs in the comparison.
 */
BOOL
line_compare(LINE line1, LINE line2)
{
        LPSTR p1, p2;

        /* Assert: At least one of them is not null ??? */

        if ((line1 == NULL) || (line2 == NULL)) {
                /* null line handles do not compare */
                return(FALSE);
        }

        /* check that the hashcodes match */
        if (line_gethashcode(line1) != line_gethashcode(line2)) {
                return(FALSE);
        }

        /* hashcodes match - are the lines really the same ? */
        /* note that this is coupled to gutils\utils.c in definition of blank */
        p1 = line_gettext(line1);
        p2 = line_gettext(line2);
        do {
                if (ignore_blanks) {
                        while ( (*p1 == ' ') || (*p1 == '\t')) {
                                p1++;
                        }
                        while ( (*p2 == ' ') || (*p2 == '\t')) {
                                p2++;
                        }
                }
                if (*p1 != *p2) {
                        return(FALSE);
                }
        } while ( (*p1++ != '\0') && (*p2++ != '\0'));

        return(TRUE);
}
예제 #2
0
/*
 * return the text associated with a given column of a given row.
 * Return a pointer that does not need to be freed after use - ie
 * a pointer into our data somewhere, not a copy
 */
LPSTR
view_gettext(VIEW view, long row, int col)
{
    int line;
    int state;
    LPSTR pstr;
    HRESULT hr;

    pstr = NULL;   /* kill spurious diagnostic */
    if (view == NULL) {
        return(NULL);
    }

    ViewEnter();

    if ((0 > row) || (row >= view->rows)) {
        ViewLeave();
        return(NULL);
    }

    if (view->bExpand) {
        /* we are in expand mode */

        state = section_getstate(view->pLines[row].section);

        switch (col) {
        case 0:
            /* row nr */

            /* line numbers can be from either original file
             * this is a menu-selectable option
             */
            line = 0;
            switch (line_numbers) {
            case IDM_NONRS:
                pstr = NULL;
                break;

            case IDM_LNRS:
                line = view->pLines[row].nr_left;
                if (state == STATE_MOVEDRIGHT
                    || state == STATE_SIMILARRIGHT) {
                    line = -line;
                }
                break;

            case IDM_RNRS:
                line = view->pLines[row].nr_right;
                if (state == STATE_MOVEDLEFT
                    || state == STATE_SIMILARLEFT) {
                    line = -line;
                }
                break;
            }
            if (line == 0) {
                ViewLeave();
                return(NULL);
            }

            if (line < 0) {
                /* lines that are moved appear twice.
                 * show the correct-sequence line nr
                 * for the out-of-seq. copy in brackets.
                 */
                hr = StringCchPrintf(view->nrtext, 12, "(%d)", abs(line));
                if (FAILED(hr)) {
                    OutputError(hr, IDS_SAFE_PRINTF);
                    return(NULL);
                }

            } else {
                hr = StringCchPrintf(view->nrtext, 12, "%d", line);
                if (FAILED(hr)) {
                    OutputError(hr, IDS_SAFE_PRINTF);
                    return(NULL);
                }
            }
            pstr = view->nrtext;
            break;

        case 1:
            /* tag text - represents the state of the line */


            switch (state) {
            case STATE_SAME:
                pstr = "    ";
                break;

            case STATE_LEFTONLY:
            case STATE_SIMILARLEFT:
                pstr = " <! ";
                break;

            case STATE_RIGHTONLY:
            case STATE_SIMILARRIGHT:
                pstr = " !> ";
                break;

            case STATE_MOVEDLEFT:
                pstr = " <- ";
                break;

            case STATE_MOVEDRIGHT:
                pstr = " -> ";
                break;
            }
            break;

        case 2:
            /* main text - line */
            pstr = line_gettext(view->pLines[row].line);
            break;
        }
    } else {
        /* outline mode */
        switch (col) {
        case 0:
            /* row number - just the line number */
            hr = StringCchPrintf(view->nrtext, 12, "%d", row+1);
            if (FAILED(hr)) {
                OutputError(hr, IDS_SAFE_PRINTF);
                return(NULL);
            }
            pstr = view->nrtext;
            break;

        case 1:
            /* tag */
            pstr = compitem_gettext_tag(view->pItems[row]);
            break;

        case 2:
            /* result text */
            pstr = compitem_gettext_result(view->pItems[row]);
            break;
        }
    }
    ViewLeave();
    return(pstr);
}