File: clip_os2.cpp

package info (click to toggle)
efte 1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 3,800 kB
  • sloc: cpp: 43,587; ansic: 1,228; makefile: 271; objc: 92; sh: 40
file content (85 lines) | stat: -rw-r--r-- 2,085 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*    clip_os2.cpp
 *
 *    Copyright (c) 2008, eFTE SF Group (see AUTHORS file)
 *    Copyright (c) 1994-1996, Marko Macek
 *
 *    You may distribute under the terms of either the GNU General Public
 *    License or the Artistic License, as specified in the README file.
 *
 */

#include "fte.h"
#include "clip.h"

int GetPMClip(int clipboard) {
    ClipData cd;
    unsigned int i, j, l, dx;
    EPoint P;

    if (clipboard != 0) {
        // only one clipboard supported
        return 0;
    }
    if (GetClipText(&cd) == 0) {
        SSBuffer->Clear();
        j = 0;
        l = 0;

        for (i = 0; i < cd.fLen; i++) {
            if (cd.fChar[i] == 0x0A) {
                SSBuffer->AssertLine(l);
                P.Col = 0;
                P.Row = l++;
                dx = 0;
                if ((i > 0) && (cd.fChar[i-1] == 0x0D)) dx++;
                SSBuffer->InsertLine(P, i - j - dx, cd.fChar + j);
                j = i + 1;
            }
        }
        if (j < cd.fLen) { // remainder
            i = cd.fLen;
            SSBuffer->AssertLine(l);
            P.Col = 0;
            P.Row = l++;
            dx = 0;
            if ((i > 0) && (cd.fChar[i-1] == 0x0D)) dx++;
            SSBuffer->InsText(P.Row, P.Col, i - j - dx, cd.fChar + j);
            j = i + 1;
        }

        // now that we don't need cd.fChar anymore, free it
        free(cd.fChar);
    }
    return 0;
}

int PutPMClip(int clipboard) {
    char *p = 0;
    int l = 0;
    PELine L;
    int Len;
    ClipData cd;
    int rc;

    if (clipboard != 0) {
        // only one clipboard supported
        return 0;
    }
    for (int i = 0; i < SSBuffer->RCount; i++) {
        L = SSBuffer->RLine(i);
        p = (char *)realloc(p, l + (Len = L->Count) + 2);
        memcpy(p + l, L->Chars, L->Count);
        l += Len;
        if (i < SSBuffer->RCount - 1) {
            p[l++] = 13;
            p[l++] = 10;
        }
    }
    p = (char *)realloc(p, l + 1);
    p[l++] = 0;
    cd.fChar = p;
    cd.fLen = l;
    rc = (PutClipText(&cd) == 0);
    free(p);
    return rc ? 1 : 0;
}