代码编辑器1.9.0

多线程!!!

#include <winsock2.h>
#include <windows.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <fstream>
#include <conio.h>
#include <stdio.h>
#include <string>
#include <atomic>
#include <time.h>
#include <mutex>
#include <map>

#pragma comment(lib,"ws2_32.lib")

#define FASTEST

#define pass
#define PASS
#define UP                                      72
#define DOWN                                    80
#define LEFT                                    75
#define RIGHT                                   77
#define H                                       29
#define W                                       114
#define BUFLEN                                  256

#define FASTCODE                                ((1 << 16) | (8 << 9) | (0))
#define TITLE                                   "title FastCode 1.9.0"

#define helps "\
<h,H,?>                                         \n\
<s,S>                                           \n\
<q,Q>                                           \n\
<!>                                             \n\
<o,O>                                           \n\
<r,R,:>                                         \n\
<t,T,^>                                         \n\
<y,Y,@>     num                                 \n\
<x,X>       num                                 \n\
<b,B,<>     str                                 \n\
<f,F,>>     str                                 \n\
<e,E,->     num                                 \n\
<{>         num,begin,step                      \n\
<\">        num,begin,step                      \n\
<\'>        num,begin,step                      \n\
<l,L,|>     num,begin,step,+ str                \n\
<l,L,|>     num,begin,step,- num                \n\
</>                                             \n\
<k,K>       str                                 \n\
<p,P>       str,color                           \n\
<w,W,$>     \n command                          \n\
<c,C,=>                                         \n\
<v,V,~>                                         \n\
<m,M,%>     str1,str2                           \n\
<d,D,;>     str                                 \n\
Ctrl + A                                        \n\
Ctrl + B                                        \n\
Ctrl + D                                        \n\
Ctrl + E                                        \n\
Ctrl + F                                        \n\
Ctrl + L                                        \n\
Ctrl + O                                        \n\
Ctrl + R                                        \n\
Ctrl + S                                        \n\
Ctrl + T                                        \n\
Ctrl + U                                        \n\
Ctrl + W                                        \n\
Ctrl + Back                                     \n\
Ctrl + Enter                                    \n\
F1                                              \n\
F2                                              \n\
F3                                              \n\
F4                                              \n\
F5                                              \n\
F6                                              \n\
A ~ Z                                           \n\
Delete                                          \n\
Enter                                           \n\
Back                                            \n\
Tab                                             \n\
Esc                                             \n\
"

#ifndef min
#define min(a, b) ({                                                            \
    typeof(a) x = (a);                                                          \
    typeof(b) y = (b);                                                          \
    x < y ? x : y;                                                              \
})
#endif

#ifndef max
#define max(a, b) ({                                                            \
    typeof(a) x = (a);                                                          \
    typeof(b) y = (b);                                                          \
    x > y ? x : y;                                                              \
})
#endif

#define color(tc)                                                               \
    SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), tc)

#define gotoxy(xx, yy)                                                          \
    do{                                                                         \
        COORD position = {xx, yy};                                              \
        SetConsoleCursorPosition (                                              \
            GetStdHandle (STD_OUTPUT_HANDLE),                                   \
            position                                                            \
        );                                                                      \
    }while(false)

typedef signed char                             int8;
typedef signed short                            int16;
typedef signed long                             int32;
typedef signed long long                        int64;
typedef unsigned char                           uint8;
typedef unsigned short                          uint16;
typedef unsigned long                           uint32;
typedef unsigned long long                      uint64;
typedef unsigned char                           byte_t;
typedef unsigned short                          word_t;
typedef unsigned long                           iterator;
typedef void*                                   pointer_t;

template <typename type> class vector {
    public:
        type* p;
        size_t Len;
        size_t Size;
        vector () {
            p = NULL;
            Len = 0;
            Size = 0;
        }
        ~vector () {
            delete[] p;
        }
        size_t size () {
            return Size;
        }
        size_t len () {
            return Len;
        }
        void exp () {
            Len = (Len << 1) + 1;
            if (p == NULL) {
                p = new type [ Len ];
            } else {
                type *tp = new type [ Len ];
                for (size_t it = 0; it < Size; it++)
                    tp[ it ] = p[ it ];
                delete[] p;
                p = tp;
            }
            return;
        }
        void exp (size_t ts) {
            while (ts >= Len)
                exp ();
            return;
        }
        type& operator [] (size_t it) {
            if (it >= Len)
                exp (it);
            return p[ it ];
        }
        type at (size_t it) {
            if (it >= Len)
                exp (it);
            return p[ it ];
        }
        void push_back (type& x) {
            if (Size == Len)
                exp ();
            p[ Size++ ] = x;
            return;
        }
        void push_back (type&& x) {
            if (Size == Len)
                exp ();
            p[ Size++ ] = x;
            return;
        }
        void push_back (vector <type>& vc) {
            for (size_t i = 0; i < vc.size(); i++)
                push_back (vc[i]);
            return;
        }
        void pop_back () {
            if (Size > 0)
                Size--;
            return;
        }
        void pop_back (size_t ts) {
            if (Size >= ts)
                Size -= ts;
            else
                Size = 0;
            return;
        }
        void insert (size_t it, type& x) {
            if (Size == Len) exp ();
            for (size_t it_t = Size; it_t > it; it_t--)
                p[ it_t ] = p[it_t - 1];
            p[ it ] = x;
            Size++;
            return;
        }
        void insert (size_t it, type&& x) {
            if (Size == Len)
                exp ();
            for (size_t it_t = Size; it_t > it; it_t--)
                p[ it_t ] = p[it_t - 1];
            p[ it ] = x;
            Size++;
            return;
        }
        void erase (size_t it) {
            Size--;
            for (size_t it_t = it; it_t < Size; it_t++)
                p[ it_t ] = p[it_t + 1];
            return;
        }
        void reverse () {
            for (size_t it = 0; it < (Size >> 1); it++) {
                type tt = p[ it ];
                p[ it ] = p[Size - it - 1];
                p[Size - it - 1] = tt;
            }
            return;
        }
        void operator ++ () {
            if (Size == Len)
                exp ();
            Size++;
            return;
        }
        void operator ++ (int) {
            if (Size == Len)
                exp ();
            Size++;
            return;
        }
        void operator += (type& x) {
            if (Size == Len)
                exp ();
            p[ Size++ ] = x;
            return;
        }
        void operator += (type&& x) {
            if (Size == Len)
                exp ();
            p[ Size++ ] = x;
            return;
        }
        void operator += (vector <type>& vc) {
            for (size_t i = 0; i < vc.size(); i++)
                push_back (vc[i]);
            return;
        }
        void operator -- () {
            if (Size > 0)
                Size--;
            return;
        }
        void operator -- (int) {
            if (Size > 0)
                Size--;
            return;
        }
        void operator -= (size_t ts) {
            if (Size >= ts)
                Size -= ts;
            else Size = 0;
            return;
        }
        void operator = (vector <type>& vc) {
            for (size_t i = 0; i < vc.size(); i++)
                push_back (vc[i]);
            return;
        }
};

template <typename type> struct node {
    type v;
    node <type>* pre;
    node <type>* next;
    node () {
        pre = next = NULL;
    }
};
template <typename type> class list {
    public:
        node <type>* head;
        node <type>* tail;
        list () {
            head = new node <type>;
            tail = new node <type>;
            head -> next = tail;
            tail -> pre = head;
        }
        ~list () {
            node <type>* fn = head;
            node <type>* sn = head;
            while (fn !=NULL) {
                sn = sn -> next;
                delete fn;
                fn = sn;
            }
        }
        node <type>* begin () {
            return head;
        }
        node <type>* end () {
            return tail;
        }
        void push_back (type& x) {
            node <type>* tn = new node <type>;
            tn -> v = x;
            tn -> pre = tail -> pre;
            tn -> next = tail;
            tail -> pre -> next = tn;
            tail -> pre = tn;
            return;
        }
        void push_back (type&& x) {
            node <type>* tn = new node <type>;
            tn -> v = x;
            tn -> pre = tail -> pre;
            tn -> next = tail;
            tail -> pre -> next = tn;
            tail -> pre = tn;
            return;
        }
        void push_back (list <type>& tl) {
            node <type>* tn = tl.begin();
            tn = tn -> next;
            while (tn != tl.end()) {
                push_back(tn -> v);
                tn = tn -> next;
            }
            return;
        }
        void pop_back () {
            node <type>* tn = tail -> pre;
            if (tn != head) {
                tail -> pre = tn -> pre;
                tn -> pre -> next = tail;
                delete tn;
            }
            return;
        }
        void insert (node <type>* in, type& x) {
            node <type>* tn = new node <type>;
            tn -> v = x;
            tn -> pre = in;
            tn -> next = in -> next;
            in -> next -> pre = tn;
            in -> next = tn;
            return;
        }
        void insert (node <type>* in, type&& x) {
            node <type>* tn = new node <type>;
            tn -> v = x;
            tn -> pre = in;
            tn -> next = in -> next;
            in -> next -> pre = tn;
            in -> next = tn;
            return;
        }
        void erase (node <type>* en) {
            node <type>* tn = en -> next;
            if (tn != tail) {
                en -> next = tn -> next;
                tn -> next -> pre = en;
                delete tn;
            }
            return;
        }
        void operator += (type& x) {
            node <type>* tn = new node <type>;
            tn -> v = x;
            tn -> pre = tail -> pre;
            tn -> next = tail;
            tail -> pre -> next = tn;
            tail -> pre = tn;
            return;
        }
        void operator += (type&& x) {
            node <type>* tn = new node <type>;
            tn -> v = x;
            tn -> pre = tail -> pre;
            tn -> next = tail;
            tail -> pre -> next = tn;
            tail -> pre = tn;
            return;
        }
        void operator += (list <type>& tl) {
            node <type>* tn = tl.begin();
            tn = tn -> next;
            while (tn != tl.end()) {
                push_back(tn -> v);
                tn = tn -> next;
            }
            return;
        }
        void operator -- () {
            node <type>* tn = tail -> pre;
            if (tn != head) {
                tail -> pre = tn -> pre;
                tn -> pre -> next = tail;
                delete tn;
            }
            return;
        }
        void operator = (list <type>& tl) {
            node <type>* tn = tl.begin();
            tn = tn -> next;
            while (tn != tl.end()) {
                push_back(tn -> v);
                tn = tn -> next;
            }
            return;
        }
};

class server {
    public:
        int                         error;
        int                         address_length;
        WORD                        wVersionRequested;
        SOCKET                      socket_server;
        SOCKET                      socket_client;
        WSADATA                     wsaData;
        SOCKADDR_IN                 server_address;
        SOCKADDR_IN                 client_address;
        int init (int port = 5000) {
            wVersionRequested = MAKEWORD(2, 2);
            error = WSAStartup(wVersionRequested, &wsaData);
            if (error != 0) {
                printf(
                    "Cant initiates use of the Winsock DLL by a process!\n"
                );
                return 1;
            }
            if (
                LOBYTE(wsaData.wVersion) != 2 ||
                HIBYTE(wsaData.wVersion) != 2
            ) {
                printf("could not find a usable WinSock DLL!\n");
                WSACleanup();
                return 1;
            }
            server_address.sin_family = AF_INET;
            server_address.sin_addr.S_un.S_addr = htonl(INADDR_ANY);
            server_address.sin_port = htons(port);
            socket_server = socket  (
                                AF_INET,
                                SOCK_STREAM,
                                IPPROTO_TCP
                            );
            if (INVALID_SOCKET == socket_server) {
                printf(
                    "socket function failed with error: %ld\n",
                    WSAGetLastError()
                );
                WSACleanup();
                return 1;
            }
            if (
                SOCKET_ERROR == 
                bind(
                    socket_server,
                    (SOCKADDR *)&server_address,
                    sizeof(server_address)
                )
            ) {
                printf(
                    "bind failed with error %u\n",
                    WSAGetLastError()
                );
                closesocket(socket_server);
                WSACleanup();
                return 1;
            }
            if (SOCKET_ERROR == listen(socket_server, 1))
                printf(
                    "listen function failed with error: %d\n",
                    WSAGetLastError()
                );
            address_length = sizeof(client_address);
            socket_client = accept(
                                socket_server,
                                (SOCKADDR *)&client_address,
                                &address_length
                            );
            if (INVALID_SOCKET == socket_client)
                printf(
                    "accept failed with error: %ld\n",
                    WSAGetLastError()
                );
            return 0;
        }
        int recv (char* buf, int len, int flags = 0) {
            int ret = ::recv(socket_client, buf, len, flags);
            if (ret <= 0) {
                if (ret == 0) {
                    printf("Connection closed\n");
                } else {
                    printf (
                        "recv failed: %d\n",
                        WSAGetLastError()
                    );
                    closesocket(socket_client);
                    closesocket(socket_server);
                    WSACleanup();
                }
            }
            return ret;
        }
        int send (char* buf, int len, int flags = 0) {
            int ret = ::send (socket_client, buf, len, flags);
            if (SOCKET_ERROR == ret) {
                printf(
                    "send failed with error: %d\n",
                    WSAGetLastError()
                );
                closesocket(socket_client);
                closesocket(socket_server);
                WSACleanup();
            }
            return ret;
        }
        int close () {
            if (SOCKET_ERROR == closesocket(socket_client)) {
                printf(
                    "closesocket function failed with error %d\n",
                    WSAGetLastError()
                );
                WSACleanup();
                return 1;
            }
            if (SOCKET_ERROR == closesocket(socket_server)) {
                printf(
                    "closesocket function failed with error %d\n",
                    WSAGetLastError()
                );
                WSACleanup();
                return 1;
            }
            WSACleanup();
            return 0;
        }
};

class client {
    public:
    WSADATA wsaData;
    SOCKET clientSocket;
    sockaddr_in serverAddr;
    int bytesSent;
    int init (
        const char* addr = "127.0.0.1", int port = 5000
    ) {
        if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
            printf("Failed to initialize winsock.\n");
            return 1;
        }
        clientSocket = socket(AF_INET, SOCK_STREAM, 0);
        if (clientSocket == INVALID_SOCKET) {
            printf("Failed to create socket.\n");
            WSACleanup();
            return 1;
        }
        serverAddr.sin_family = AF_INET;
        serverAddr.sin_addr.s_addr = inet_addr(addr);
        serverAddr.sin_port = htons(port);
        if (
            connect(
                clientSocket,
                (sockaddr*)&serverAddr,
                sizeof(serverAddr)
            ) == SOCKET_ERROR
        ) {
            printf("Failed to connect to server.\n");
            closesocket(clientSocket);
            WSACleanup();
            return 1;
        }
        return 0;
    }
    int recv (char* buf, int len, int flags = 0) {
        int ret = ::recv(clientSocket, buf, len, flags);
        if (ret <= 0) {
            if (ret == 0) {
                printf("Connection closed\n");
                return 1;
            } else {
                printf(
                    "recv failed: %d\n",
                    WSAGetLastError()
                );
                closesocket(clientSocket);
                WSACleanup();
                return 1;
            }
        }
        return 0;
    }
    int send (char* buf, int len, int flags = 0) {
        bytesSent = ::send(clientSocket, buf, len, 0);
        if (bytesSent == SOCKET_ERROR) {
            printf("Failed to send data to server.\n");
            closesocket(clientSocket);
            WSACleanup();
            return 1;
        }
        return 0;
    }
    int close () {
        closesocket(clientSocket);
        WSACleanup();
        return 0;
    }
};

namespace snake {
    #define X 23
    #define Y 40
    #define MAXLEN 75
    #define MINTIME 75
    unsigned int snake[MAXLEN][2];
    unsigned int len;
    unsigned int lastt[2];
    unsigned int score;
    unsigned int max_score;
    unsigned int way;
    double wait;
    int input;
    unsigned int food[2];
    bool empty = true;
    void welcome    ();
    void init       ();
    void drawmap    ();
    void drawsnake  ();
    void move       ();
    void clt        ();
    void getin      ();
    void putfood    ();
    void eatfood    ();
    bool gameover   ();
    int start       ();
    #undef X
    #undef Y
    #undef MAXLEN
    #undef MINTIME
}

struct Pos {
    char                                        ch;
    byte_t                                      cl;
};

list <vector <char> >                           doc;
node <vector <char> >*                          ty;
iterator                                        tx;
node <vector <char> >*                          py;
iterator                                        px;
long                                            cnt;
bool                                            lock;
bool                                            edit;
size_t                                          lines;

char                                            name[BUFLEN];
char                                            exen[BUFLEN];
char                                            path[BUFLEN];
bool                                            isat[256];
Pos                                             preout[H][W];
Pos                                             thisout[H][W];

std::map <std::string, byte_t>   keyword;

std::atomic <signed char>                       sig;

void whelp          ();
void rpath          ();
void rdocu          (int argc, char* argv);
void init           (int argc, char** argv);
void save           ();
void doccopy        (const char* from, const char* to);
void cppcopy        (const char* to);
void output         (LPVOID id);
bool cfn            (int ch);
bool cctrl          (int ch);
bool ccom           (int ch);
void input          (LPVOID id);

int main (int argc, char** argv) {
    try {
        DWORD input_id;
        DWORD output_id;
        HANDLE input_handle;
        HANDLE output_handle;
        system (TITLE);
        system ("mode con lines=31 cols=120");
        CONSOLE_CURSOR_INFO cursor_info = {1, 0};
        SetConsoleCursorInfo (
            GetStdHandle (STD_OUTPUT_HANDLE),
            &cursor_info
        );
        color (15);
        whelp ();
        rpath ();
        init (argc, argv);
        input_handle = (HANDLE)::CreateThread (NULL, 0,
            (LPTHREAD_START_ROUTINE)input, (LPVOID)&input_id,
            0, &input_id
        );
        output_handle = (HANDLE)::CreateThread (NULL, 0,
            (LPTHREAD_START_ROUTINE)output, (LPVOID)&output_id,
            0, &output_id
        );
        while (sig != -1) {
            ;
        }
    }
    catch (...) {
        printf ("异常产生!\n");
        throw ;
    }
    system ("pause");
    return 0;
}

inline __attribute__ ((always_inline))
void whelp () {
    FILE* fp = fopen ("FCDOC\\help.txt", "w");
    fprintf (fp, helps);
    fclose (fp);
    return;
}
inline __attribute__ ((always_inline))
void rpath () {
    FILE*                                       fp = fopen ("FCDOC\\path.txt", "r");
    system ("cls");
    if (fp == NULL) {
        printf ("编译器路径:");
        gets (path);
        FILE*                                   sf = fopen ("path.txt", "w");
        fprintf (sf, "%s", path);
        fclose (sf);
    } else {
        fscanf (fp, "%s", path);
    }
    fclose (fp);
}
inline __attribute__ ((always_inline))
void rdocu (int argc, char* argv) {
    int                                         ch;
    size_t                                      sum;
    size_t                                      pre;
    vector <char>                               tv;
    FILE*                                       fp = fopen (argv, "r");
    iterator                                    nt = strlen (argv) - 1;
    system ("cls");
    printf ("读取中...\n\n");
    #ifndef FASTEST
    color (136);
    printf ("                                                                ");
    color (15);
    #endif
    for (; nt > 0; nt--) { 
        if (argv[nt - 1] == '\\')
            break;
    }
    if (argc != 1) {
        for (iterator it = 0; argv[nt] != '\0'; it++) {
            name[it]                            = argv[nt];
            nt++;
        }
    }
    fseek (fp, 0, 2);
    sum                                         = ftell (fp);
    fseek (fp, 0, 0);
    ch                                          = fgetc (fp);
    pre                                         = 0;
    while (ch != EOF) {
        if (ch == 10) {
            node <vector <char> >* tn           = new node <vector <char> >;
            for (iterator it = 0; it < tv.size(); it++) {
                tn -> v.push_back (tv[it]);
            }
            tn -> pre                           = doc.tail -> pre;
            tn -> next                          = doc.tail;
            doc.tail -> pre -> next             = tn;
            doc.tail -> pre                     = tn;
            while (tv.size () != 0) {
                tv.pop_back ();
            }
        } else if (ch == 9) {
            do {
                tv                              += ' ';
            } while (tv.size () % 4 != 0);
        } else {
            tv                                  += ch;
        }
#ifndef FASTEST
        gotoxy (0, 1);
        printf ("%d / %d", ftell (fp), sum);
        gotoxy (0, 2);
        size_t                                  temp = ftell (fp) * 64 / sum;
        if (temp != pre) {
            pre                                 = temp;
            color (170);
            for (iterator it = 0; it < temp; it++) {
                printf (" ");
            }
            color (15);
        }
#endif
        ch                                      = fgetc(fp);
    }
    if (tv.size () != 0) {
        node <vector <char> >*                  tn = new node <vector <char> >;
        for (iterator it = 0; it < tv.size(); it++)
            tn -> v.push_back (tv[it]);
        tn -> pre                               = doc.tail -> pre;
        tn -> next                              = doc.tail;
        doc.tail -> pre -> next                 = tn;
        doc.tail -> pre                         = tn;
    }
    fclose (fp);
    Sleep (500);
    return;
}
inline __attribute__ ((always_inline))
void init (int argc, char** argv) {
    system ("cls");
    printf ("初始化...\n");
    if (argc != 1) {
        rdocu (argc, argv[1]);
    } else {
        system ("cls");
        printf ("文件名:");
        gets (name);
        FILE*                                   fp = fopen (name, "r");
        if (fp) {
            fclose (fp);
            rdocu (argc, name);
        } else {
            vector <char>                       tv;
            doc                                 += tv;
        }
    }
    iterator it = 0;
    for (; name[it] != '.' && name[it] != '\0'; it++) {
        exen[it] = name[it];
    }
    exen[it++] = '.';
    exen[it++] = 'e';
    exen[it++] = 'x';
    exen[it++] = 'e';
    exen[it++] = '\0';
    char                                        ts[W];
    sprintf (ts, "title %s", name);
    system (ts);
    ty                                          = doc.begin () -> next;
    tx                                          = 0;
    py                                          = doc.begin () -> next;
    px                                          = 0;
    lock                                        = true;
    sig                                         = 1;
    for (iterator yi = 0; yi < H - 1; yi++) {
        for (iterator xi = 0; xi < W - 7; xi++) {
            preout[yi][xi].cl                   = 15;
            preout[yi][xi].ch                   = ' ';
        }   
    }
    for (iterator yi = 0; yi < H - 1; yi++) {
        for (iterator xi = 0; xi < W - 7; xi++) {
            thisout[yi][xi].cl                  = 15;
            thisout[yi][xi].ch                  = ' ';
        }   
    }
    isat['~']                                   = true;
    isat['!']                                   = true;
    isat['%']                                   = true;
    isat['^']                                   = true;
    isat['&']                                   = true;
    isat['*']                                   = true;
    isat['(']                                   = true;
    isat[')']                                   = true;
    isat['-']                                   = true;
    isat['+']                                   = true;
    isat['=']                                   = true;
    isat['{']                                   = true;
    isat['}']                                   = true;
    isat['[']                                   = true;
    isat[']']                                   = true;
    isat['|']                                   = true;
    isat[':']                                   = true;
    isat[';']                                   = true;
    isat['<']                                   = true;
    isat['>']                                   = true;
    isat[',']                                   = true;
    isat['.']                                   = true;
    isat['?']                                   = true;
    isat['/']                                   = true;
    keyword["alignas"]                          = 11;
    keyword["alignof"]                          = 11;
    keyword["and"]                              = 11;
    keyword["and_eq"]                           = 11;
    keyword["asm"]                              = 11;
    keyword["auto"]                             = 11;
    keyword["bitand"]                           = 11;
    keyword["bitor"]                            = 11;
    keyword["bool"]                             = 11;
    keyword["break"]                            = 11;
    keyword["case"]                             = 11;
    keyword["catch"]                            = 11;
    keyword["char"]                             = 11;
    keyword["char16_t"]                         = 11;
    keyword["char32_t"]                         = 11;
    keyword["class"]                            = 11;
    keyword["compl"]                            = 11;
    keyword["const"]                            = 11;
    keyword["constexpr"]                        = 11;
    keyword["const_cast"]                       = 11;
    keyword["continue"]                         = 11;
    keyword["decltype"]                         = 11;
    keyword["default"]                          = 11;
    keyword["delete"]                           = 11;
    keyword["do"]                               = 11;
    keyword["double"]                           = 11;
    keyword["dynamic_cast"]                     = 11;
    keyword["else"]                             = 11;
    keyword["enum"]                             = 11;
    keyword["explicit"]                         = 11;
    keyword["export"]                           = 11;
    keyword["extern"]                           = 11;
    keyword["false"]                            = 11;
    keyword["float"]                            = 11;
    keyword["for"]                              = 11;
    keyword["friend"]                           = 11;
    keyword["goto"]                             = 11;
    keyword["if"]                               = 11;
    keyword["inline"]                           = 11;
    keyword["int"]                              = 11;
    keyword["long"]                             = 11;
    keyword["mutable"]                          = 11;
    keyword["namespace"]                        = 11;
    keyword["new"]                              = 11;
    keyword["noexcept"]                         = 11;
    keyword["not"]                              = 11;
    keyword["not_eq"]                           = 11;
    keyword["nullptr"]                          = 11;
    keyword["operator"]                         = 11;
    keyword["or"]                               = 11;
    keyword["or_eq"]                            = 11;
    keyword["private"]                          = 11;
    keyword["protected"]                        = 11;
    keyword["public"]                           = 11;
    keyword["register"]                         = 11;
    keyword["reinterpret_cast"]                 = 11;
    keyword["return"]                           = 11;
    keyword["short"]                            = 11;
    keyword["signed"]                           = 11;
    keyword["sizeof"]                           = 11;
    keyword["static"]                           = 11;
    keyword["static_assert"]                    = 11;
    keyword["static_cast"]                      = 11;
    keyword["struct"]                           = 11;
    keyword["switch"]                           = 11;
    keyword["template"]                         = 11;
    keyword["this"]                             = 11;
    keyword["thread_local"]                     = 11;
    keyword["throw"]                            = 11;
    keyword["true"]                             = 11;
    keyword["try"]                              = 11;
    keyword["typedef"]                          = 11;
    keyword["typeid"]                           = 11;
    keyword["typeof"]                           = 11;
    keyword["typename"]                         = 11;
    keyword["union"]                            = 11;
    keyword["unsigned"]                         = 11;
    keyword["using"]                            = 11;
    keyword["virtual"]                          = 11;
    keyword["void"]                             = 11;
    keyword["volatile"]                         = 11;
    keyword["wchar_t"]                          = 11;
    keyword["while"]                            = 11;
    keyword["xor"]                              = 11;
    keyword["xor_eq"]                           = 11;
    system ("cls");
    return;
}
inline __attribute__ ((always_inline))
void save () {
    edit                                        = false;
    char                                        calls[BUFLEN];
    sprintf (calls, "title %s", name);
    system (calls);
    FILE*                                       fp = fopen(name, "w");
    node <vector <char> >*                      sp = doc.begin () -> next;
    while (sp != doc.end ()) {
        for (iterator it = 0; it < sp -> v.size(); it++)
            fputc (sp -> v[it], fp);
        fputc ('\n', fp);
        sp                                      = sp -> next;
    }
    fclose(fp);
    return;
}
inline __attribute__ ((always_inline))
void doccopy (const char* from, const char* to) {
    FILE*                                       fp = fopen (from, "r");
    if (fp == NULL) {
        printf ("打开失败!\n");
        return;
    }
    FILE*                                       tp = fopen (to, "w");
    char                                        ch;
    ch                                          = fgetc (fp);
    while (ch != EOF) {
        fputc (ch, tp);
        ch                                      = fgetc (fp);
    }
    fclose (fp);
    fclose (tp);
    printf ("成功!\n");
    return;
}
inline __attribute__ ((always_inline))
void cppcopy (const char* to) {
    FILE*                                       fp = fopen (name, "r");
    FILE*                                       tp = fopen (to, "w");
    char                                        ch;
    ch                                          = fgetc (fp);
    while (ch != EOF) {
        fputc (ch, tp);
        ch                                      = fgetc (fp);
    }
    fclose (fp);
    fclose (tp);
    printf ("成功!\n");
    return;
}
inline __attribute__ ((always_inline))
void output (LPVOID id) {
    std::mutex                                  mlock;
    while (true) {
        while (true) {
            if (sig == 1) {
                sig                             = 0;
                break;
            } else if (sig == -1) {
                return;
            }
        }
        node <vector <char> >* pt               = py;
        mlock.lock ();
        node <vector <char> >* end              = doc.end ();
        mlock.unlock ();
        bool                                    special = false;
        bool                                    isinc   = false;
        bool                                    isstr   = false;
        bool                                    isch    = false;
        bool                                    isnum   = false;
        for (iterator yy = 0; yy < H - 1 && pt != end; yy++) {
            byte_t                              cl;
            iterator                            xx;
            std::string                         ks;
            if (!special) {
                isinc                           = false;
                isstr                           = false;
                isch                            = false;
                isnum                           = false;
            }
            for (xx = 0; xx < W - 7 && xx + px < pt -> v.size (); xx++) {
                char                            putch = pt -> v.at(xx + px);
                if ((!isinc) && (!isstr) && (!isch)) {
                    if (
                        (putch >= 'A' && putch <= 'Z') ||
                        (putch >= 'a' && putch <= 'z') ||
                        (putch >= '0' && putch <= '9') ||
                        (putch == '_')
                    ) {
                        ks                      += putch;
                    } else {
                        mlock.lock ();
                        if (keyword[ks] != 0) {
                            for (iterator it = 0; it < ks.size(); it++) {
                                if (pt == ty && xx + px - ks.size() + it == tx)
                                    thisout[yy][xx + px - ks.size() + it].cl = 240;
                                else
                                    thisout[yy][xx + px - ks.size() + it].cl = keyword[ks];
                            }
                        }
                        mlock.unlock ();
                        ks                      = "";
                    }
                } else {
                    ks                          = "";
                }
                if (putch == ' ' || isat[(int)putch] == true || xx + px == 0) {
                    isnum                           = true;
                } else if(putch < '0' || putch > '9') {
                    isnum                       = false;
                }
                if ((!isstr) && (!isch)  && (isinc || putch == '#'))  {
                    cl                          = 10;
                    isinc                       = true;
                } else if ((!isinc) && (!isch)  && (isstr || putch == '\"')) {
                    cl                          = 11;
                    if (pt -> v[xx + px] == '\"' && !special)
                        isstr                   = !isstr;
                } else if ((!isinc) && (!isstr) && (isch  || putch == '\'')) {
                    cl                          = 14;
                    if (pt -> v[xx + px] == '\'' && !special)
                        isch                    = !isch;
                } else if (
                    (!isinc) && (!isstr) && (!isch) && (isnum) &&
                    (putch >= '0' && putch <= '9')
                ) {
                    cl                          = 11;
                } else if (isat[(int)putch] == true) {
                    cl                          = 9;
                } else {
                    cl                          = 15;
                }
                if (pt == ty && xx + px == tx) {
                    cl                          = 240;
                }
                thisout[yy][xx].cl              = cl;
                thisout[yy][xx].ch              = putch;
                if (putch == '\\' && !special) {
                    special                     = true;
                } else {
                    special                     = false;
                }
            }
            cl                                  = 15;
            if (pt == ty && tx == pt -> v.size ()) {
                cl                              = 240;
            }
            thisout[yy][xx].cl                  = cl;
            thisout[yy][xx].ch                  = ' ';
            pt                                  = pt -> next;
        }
        pt                                      = py;
        mlock.lock ();
        gotoxy (0, 0);
        for (iterator yy = 0; yy < H - 1 && pt != end; yy++) {
            color (15);
            printf ("%4d ", (int)(lines + yy));
            for (iterator xx = 0; xx < W - 6; xx++) {
                if (
                    thisout[yy][xx].ch != preout[yy][xx].ch ||
                    thisout[yy][xx].cl != preout[yy][xx].cl
                ) {
                    gotoxy ((short)(xx + 5), (short)yy);
                    color (thisout[yy][xx].cl);
                    printf ("%c", thisout[yy][xx].ch);  
                }
            }
            color (12);
            gotoxy ((short)(W - 2), (short)yy);
            if (pt -> v.size() > W - 8) {
                printf (" > ");
            } else {
                printf ("   ");
            }
            printf ("\n");
            pt                                      = pt -> next;
        }
        color (15);
        printf ("%114c", ' ');
        memcpy (preout, thisout, sizeof (preout));
        mlock.unlock ();
        for (iterator yi = 0; yi < H - 1; yi++) {
            for (iterator xi = 0; xi < W - 7; xi++) {
                thisout[yi][xi].cl                  = 15;
                thisout[yi][xi].ch                  = ' ';
            }   
        }
    }
    return;
}
inline __attribute__ ((always_inline))
bool cfn (int ch) {
    if (ch == 0) {
        char                                    prt[W + 7];
        memset(prt, '\b', sizeof(prt));
        prt[W + 6] = '\0';
        printf("%s", prt);
        ch                                      = getch ();
        switch (ch) {
            case 59: {
                printf (helps);
                system ("pause");
                break;
            }
            case 60: {
                save ();
                char                            calls[BUFLEN];
                sprintf (
                    calls, "%s %s -o %s -Ofast -m32 -std=gnu++14 -lwsock32",
                    path, name, exen
                );
                printf("%s\n", calls);
                system (calls);
                sprintf (calls, "start %s", exen);
                system (calls);
                system ("pause");
                break;
            }
            case 61: {
                save ();
                char                            calls[BUFLEN];
                sprintf (
                    calls, "%s %s -o %s -Ofast -m32 -std=gnu++14 -lwsock32",
                    path, name, exen
                );
                printf("%s\n", calls);
                system (calls);
                sprintf (calls, "%s", exen);
                system (calls);
                system ("pause");
                break;
            }
            case 62: {
                save ();
                char                            calls[BUFLEN];
                sprintf (
                    calls, "%s %s -o %s -Ofast -m32 -std=gnu++14 -lwsock32",
                    path, name, exen
                );
                printf("%s\n", calls);
                system (calls);
                system ("pause");
                break;
            }
            case 63: {
                char                            calls[BUFLEN];
                sprintf (calls, "start %s", exen);
                system (calls);
                system ("pause");
                break;
            }
            case 64: {
                char                            calls[BUFLEN];
                sprintf (calls, "%s", exen);
                system (calls);
                system ("pause");
                break;
            }
            case 65: {
                save ();
                system (name);
                system ("pause");
                break;
            }
            default:
                break;
        }
        for (iterator yi = 0; yi < H - 1; yi++) {
            for (iterator xi = 0; xi < W - 7; xi++) {
                preout[yi][xi].cl               = 15;
                preout[yi][xi].ch               = ' ';
            }   
        }
        system ("cls");
        return true;
    }
    return false;
}
inline __attribute__ ((always_inline))
bool cctrl (int ch) {
    if (ch == 1) {
        ty -> v.insert (tx, 'a');
        tx++;
        ty -> v.insert (tx, 'u');
        tx++;           ty -> v.insert (tx, 't');
        tx++;
        ty -> v.insert (tx, 'o');
        tx++;
        ty -> v.insert (tx, ' ');
        tx++;
        return true;
    } else if (ch == 2) {
        ty -> v.insert (tx, 'b');
        tx++;
        ty -> v.insert (tx, 'o');
        tx++;
        ty -> v.insert (tx, 'o');
        tx++;
        ty -> v.insert (tx, 'l');
        tx++;
        ty -> v.insert (tx, ' ');
        tx++;
        return true;
    } else if (ch == 4) {
        ty -> v.insert (tx, 'd');
        tx++;
        ty -> v.insert (tx, 'o');
        tx++;
        ty -> v.insert (tx, 'u');
        tx++;
        ty -> v.insert (tx, 'b');
        tx++;
        ty -> v.insert (tx, 'l');
        tx++;
        ty -> v.insert (tx, 'e');
        tx++;
        ty -> v.insert (tx, ' ');
        tx++;
        return true;
    } else if (ch == 5) {
        ty -> v.insert (tx, 'e');
        tx++;
        ty -> v.insert (tx, 'x');
        tx++;
        ty -> v.insert (tx, 't');
        tx++;
        ty -> v.insert (tx, 'e');
        tx++;
        ty -> v.insert (tx, 'r');
        tx++;
        ty -> v.insert (tx, 'n');
        tx++;
        ty -> v.insert (tx, ' ');
        tx++;
        return true;
    } else if (ch == 6) {
        ty -> v.insert (tx, 'f');
        tx++;
        ty -> v.insert (tx, 'l');
        tx++;
        ty -> v.insert (tx, 'o');
        tx++;
        ty -> v.insert (tx, 'a');
        tx++;
        ty -> v.insert (tx, 't');
        tx++;
        ty -> v.insert (tx, ' ');
        tx++;
        return true;
    } else if (ch == 12) {
        ty -> v.insert (tx, 'l');
        tx++;
        ty -> v.insert (tx, 'o');
        tx++;
        ty -> v.insert (tx, 'n');
        tx++;
        ty -> v.insert (tx, 'g');
        tx++;
        ty -> v.insert (tx, ' ');
        tx++;
        return true;
    } else if (ch == 15) {
        ty -> v.insert (tx, 'o');
        tx++;
        ty -> v.insert (tx, 'p');
        tx++;
        ty -> v.insert (tx, 'e');
        tx++;
        ty -> v.insert (tx, 'r');
        tx++;
        ty -> v.insert (tx, 'a');
        tx++;
        ty -> v.insert (tx, 't');
        tx++;
        ty -> v.insert (tx, 'o');
        tx++;
        ty -> v.insert (tx, 'r');
        tx++;
        ty -> v.insert (tx, ' ');
        tx++;
        return true;
    } else if (ch == 18) {
        ty -> v.insert (tx, 'r');
        tx++;
        ty -> v.insert (tx, 'e');
        tx++;
        ty -> v.insert (tx, 'g');
        tx++;
        ty -> v.insert (tx, 'i');
        tx++;
        ty -> v.insert (tx, 's');
        tx++;
        ty -> v.insert (tx, 't');
        tx++;
        ty -> v.insert (tx, 'e');
        tx++;
        ty -> v.insert (tx, 'r');
        tx++;
        ty -> v.insert (tx, ' ');
        tx++;
        return true;
    } else if (ch == 19) {
        ty -> v.insert (tx, 's');
        tx++;
        ty -> v.insert (tx, 'i');
        tx++;
        ty -> v.insert (tx, 'g');
        tx++;
        ty -> v.insert (tx, 'n');
        tx++;
        ty -> v.insert (tx, 'e');
        tx++;
        ty -> v.insert (tx, 'd');
        tx++;
        ty -> v.insert (tx, ' ');
        tx++;
        return true;
    } else if (ch == 20) {
        ty -> v.insert (tx, 't');
        tx++;
        ty -> v.insert (tx, 'e');
        tx++;
        ty -> v.insert (tx, 'm');
        tx++;
        ty -> v.insert (tx, 'p');
        tx++;
        ty -> v.insert (tx, 'l');
        tx++;
        ty -> v.insert (tx, 'a');
        tx++;
        ty -> v.insert (tx, 't');
        tx++;
        ty -> v.insert (tx, 'e');
        tx++;
        ty -> v.insert (tx, ' ');
        tx++;
        return true;
    } else if (ch == 21) {
        ty -> v.insert (tx, 'u');
        tx++;
        ty -> v.insert (tx, 'n');
        tx++;
        ty -> v.insert (tx, 's');
        tx++;
        ty -> v.insert (tx, 'i');
        tx++;
        ty -> v.insert (tx, 'g');
        tx++;
        ty -> v.insert (tx, 'n');
        tx++;
        ty -> v.insert (tx, 'e');
        tx++;
        ty -> v.insert (tx, 'd');
        tx++;
        ty -> v.insert (tx, ' ');
        tx++;
        return true;
    } else if (ch == 23) {
        tx = ty -> v.size();
        return true;
    }
    return false;
}
inline __attribute__ ((always_inline))
bool ccom (int ch) {
    if (ch == 10) {
        char                                    prt[W + 7];
        memset(prt, '\b', sizeof(prt));
        prt[W + 6]                              = '\0';
        printf("%sFastCode:>  ", prt);
        ch                                      = getchar ();
        switch (ch) {
            case 'h':
            case 'H':
            case '?': {
                printf (helps);
                system ("pause");
                edit                            = false;
                break;
            }
            case 's':
            case 'S': {
                save ();
                break;
            }
            case 'q':
            case 'Q': {
                save ();
                sig                             = -1;
                exit (0);
            }
            case '!': {
                sig                             = -1;
                exit (0);
            }
            case 'o':
            case 'O': {
                save ();
                char                            calls[BUFLEN];
                sprintf (
                    calls, "%s %s -o %s -Ofast -m32 -std=gnu++14 -lwsock32",
                    path, name, exen
                );
                printf("%s\n", calls);
                system (calls);
                sprintf (calls, "start %s", exen);
                system (calls);
                system ("pause");
                break;
            }
            case 'r':
            case 'R':
            case ':': {
                save ();
                char                            calls[BUFLEN];
                sprintf (
                    calls, "%s %s -o %s -Ofast -m32 -std=gnu++14 -lwsock32",
                    path, name, exen
                );
                printf("%s\n", calls);
                system (calls);
                sprintf (calls, "%s", exen);
                system (calls);
                system ("pause");
                break;
            }
            case 't':
            case 'T':
            case '^': {
                tx                              = 0;
                cnt                             = 0;
                lines                           = 0;
                ty                              = doc.begin () -> next;
                py                              = doc.begin () -> next;
                edit                            = false;
                break;
            }
            case 'y':
            case 'Y':
            case '@': {
                unsigned int    linenum;
                scanf ("%d", &linenum);
                tx                              = 0;
                cnt                             = 0;
                lines                           = 0;
                ty                              = doc.begin () -> next;
                py                              = doc.begin () -> next;
                for (iterator it = 0; it < linenum; it++) {
                    if (ty -> next != doc.end ()) {
                        ty                      = ty -> next;
                        py                      = py -> next;
                        lines++;
                    }
                }
                edit                            = false;
                break;
            }
            case 'x':
            case 'X': {
                unsigned int                    colnum;
                scanf ("%d", &colnum);
                tx                              = colnum;
                if (tx < 0) {
                    tx                          = 0;
                }
                if (tx > ty -> v.size()) {
                    tx                          = ty -> v.size();
                }
                edit                            = false;
                break;
            }
            case 'b':
            case 'B':
            case '<': {
                edit                            = false;
                int                             len;
                bool                            okk;
                char                            word[BUFLEN];
                getchar ();
                gets (word);
                len                             = strlen(word);
                while (ty -> pre != doc.begin()) {
                    tx                          = 0;
                    ty                          = ty -> pre;
                    cnt--;
                    for (; (signed int)tx < (signed int)ty -> v.size() - len; tx++) {
                        okk                     = true;
                        for (iterator it = 0; it < len; it++) {
                            if (word[it] != ty -> v[tx + it]) {
                                okk             = false;
                                break;
                            }
                        }
                        if (okk) {
                            goto                FL_END;
                        }
                    }
                }
                break;
FL_END:
                break;
            }
            case 'f':
            case 'F':
            case '>': {
                edit                            = false;
                int                             len;
                bool                            okk;
                char                            word[BUFLEN];
                getchar ();
                gets (word);
                len                             = strlen(word);
                while (ty -> next != doc.end()) {
                    tx                          = 0;
                    ty                          = ty -> next;
                    cnt++;
                    for (; (signed int)tx < (signed int)ty -> v.size() - len; tx++) {
                        okk = true;
                        for (iterator it = 0; it < len; it++) {
                            if (word[it] != ty -> v[tx + it]) {
                                okk             = false;
                                break; 
                            }
                        }
                        if (okk) {
                            goto                FR_END;
                        }
                    }
                }
                break;
FR_END:
                break;
            }
            case 'e':
            case 'E':
            case '-': {
                int                             num;
                scanf ("%d", &num);
                for (iterator it = 0; it < num; it++) {
                    if (tx > 0) {
                        tx--;
                        ty -> v.erase (tx);
                    }
                }
                break;
            }
            case '{': {
                int                             num;
                int                             step;
                int                             begin;
                char                            word[BUFLEN];
                scanf ("%d,%d,%d", &num, &begin, &step);
                for (iterator it = 0; it < num; it++) {
                    sprintf (word, "%d", it * step + begin);
                    for (iterator i = 0; word[i] != '\0'; i++) {
                        ty -> v.insert (tx, word[i]);
                        tx++;
                    }
                    ty -> v.insert (tx, ',');
                    tx++;
                    ty -> v.insert (tx, ' ');
                    tx++;
                }
                break;
            }
            case '\'': {
                int                             num;
                int                             step;
                char                            begin;
                scanf ("%d,%c,%d", &num, &begin, &step);
                for (iterator it = 0; it < num; it++) {
                    ty -> v.insert (tx, '\'');
                    tx++;
                    ty -> v.insert (tx, (char)(it * step) + begin);
                    tx++;
                    ty -> v.insert (tx, '\'');
                    tx++;
                    ty -> v.insert (tx, ',');
                    tx++;
                    ty -> v.insert (tx, ' ');
                    tx++;
                }
                break;
            }
            case '\"': {
                int                             num;
                int                             step;
                char                            begin;
                scanf ("%d,%c,%d", &num, &begin, &step);
                for (iterator it = 0; it < num; it++) {
                    ty -> v.insert (tx, (char)(it * step) + begin);
                    tx++;
                }
                break;
            }
            case 'l':
            case 'L':
            case '|': {
                int                             num;
                int                             deln;
                int                             step;
                int                             begin;
                char                            ch;
                char                            str[BUFLEN];
                node <vector <char> >*  tn = ty;
                scanf ("%d,%d,%d,%c", &num, &begin, &step, &ch);
                if (ch == '-') {
                    scanf ("%d", &deln);
                    tx                          -= deln;
                    while (tx < 0) {
                        tx++;
                        deln--;
                    }
                } else if (ch == '+') {
                    getchar ();
                    gets (str);
                }
                for (iterator it = 0; it < num; it++) {
                    if (ch == '-') {
                        for (iterator it = 0; it < deln; it++)
                            tn -> v.erase (tx);
                    } else if (ch == '+') {
                        for (iterator l = 0; str[l] != '\0'; l++)
                            tn -> v.insert (l + tx, str[l]);
                    }
                    for (iterator l = 0; l < step; l++) {
                        if (tn -> next != doc.end())
                            tn                  = tn -> next;
                        else
                            goto    LF_END;
                    }
                }
                break;
LF_END:
                break;
            }
            case '/': {
                ty -> v.insert (0, '#');
                ty -> v.insert (0, '/');
                ty -> v.insert (0, '/');
                tx                              = 0;
                break;
            }
            case 'k':
            case 'K': {
                char                            word[BUFLEN];
                scanf ("%s", word);
                keyword[word]                   = 11;
                edit                            = false;
                break;
            }
            case 'p':
            case 'P': {
                unsigned int                    tcolor;
                char                            word[BUFLEN];
                scanf ("%s", word);
                scanf ("%d", &tcolor);
                keyword[word]                   = (byte_t)tcolor;
                edit                            = false;
                break;
            }
            case '.': {
                int                             ret;
                unsigned int                    tcolor;
                char                            path[BUFLEN];
                char                            word[BUFLEN];
                getchar ();
                gets (path);
                FILE* fp = fopen (path, "r");
                if (fp != NULL) {
                    while (true) {
                        ret = fscanf (fp, "%s %d", word, &tcolor);
                        if (ret != -1)
                            keyword[word]           = (byte_t)tcolor;
                        else
                            break;
                    }
                }
                edit                            = false;
                break;
            }
            case 'w':
            case 'W':
            case '$': {
                char                            calls[BUFLEN];
                getchar ();
                gets (calls);
                system (calls);
                system ("pause");
                edit                            = false;
                break;
            }
            case 'c':
            case 'C':
            case '=': {
                std::string                     TempBin;
                HGLOBAL                         hMemBin = NULL;
                PCHAR                           LockBin = NULL;
                node <vector <char> >*  tn = doc.begin () -> next;
                OpenClipboard(NULL);
                EmptyClipboard();
                while (tn != doc.end ()) {
                    for (iterator it = 0; it < tn -> v.size (); it++)
                        TempBin                 += tn -> v[it];
                    TempBin                     += '\n';
                    tn                          = tn -> next;
                }
                hMemBin                         = GlobalAlloc(GMEM_MOVEABLE, TempBin.size() + 1);
                LockBin                         = (PCHAR)GlobalLock(hMemBin);
                RtlMoveMemory(LockBin, TempBin.c_str(), TempBin.size() + 1);
                GlobalUnlock(hMemBin);
                LockBin                         = NULL;
                SetClipboardData(CF_TEXT, hMemBin);
                CloseClipboard();
                edit                            = false;
                break;
            }
            case 'v':
            case 'V':
            case '~': {
                lock                            = !lock;
                edit                            = false;
                break;
            }
            case 'm':
            case 'M':
            case '%': {
                char                            from[BUFLEN];
                char                            to[BUFLEN];
                getchar ();
                gets (from);
                gets (to);
                doccopy (from, to);
                system ("pause");
                edit                            = false;
                break;
            }
            case 'd':
            case 'D':
            case ';': {
                char                            to[BUFLEN];
                getchar ();
                gets (to);
                save ();
                cppcopy (to);
                system ("pause");
                edit                            = false;
                break;
            }
            case 'g':
            case 'G': {
                int                             no;
                scanf ("%d", &no);
                switch (no) {
                    case 2147483647: {
                        snake::start ();
                        break;
                    }
                    default:
                        break;
                }
                system (name);
                edit                            = false;
                break;
            }
            case 'i':
            case 'I': {
                getchar ();
                char                            c = getchar();
                char                            buf[BUFLEN];
                if (c == 's') {
                    server ser;
                    ser.init ();
                    node <vector <char> >* tp   = doc.begin ();
                    tp                          = tp -> next;
                    while (tp != doc.end ()) {
                        iterator it;
                        for (it = 0; it < tp -> v.size (); it++) {
                            buf[it]             = tp -> v[it];
                        }
                        buf[it++]               = '\n';
                        buf[it++]               = '\0';
                        ser.send (buf, strlen (buf) + 1);
                        tp                      = tp -> next;
                    }
                    ser.close ();
                    system ("pause");
                } else if (c == 'r') {
                    client cli;
                    FILE* fp                    = fopen ("recv.cpp", "w");
                    char                        recvadd[BUFLEN];
                    char                        recvbuf[BUFLEN];
                    getchar ();
                    gets (recvadd);
                    cli.init(recvadd);
                    while (true) {
                        int ret                 = cli.recv(recvbuf, BUFLEN);
                        if (ret == 0) {
                            fprintf (fp, "%s", recvbuf);
                        } else {
                            break;
                        }
                    }
                    cli.close ();
                    fclose (fp);
                    system ("pause");
                }
                edit                            = false;            
                break;
            }
            default:
                break;
        }
        CONSOLE_CURSOR_INFO cursor_info         = {1, 0};
        SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &cursor_info);
        for (iterator yi = 0; yi < H - 1; yi++) {
            for (iterator xi = 0; xi < W - 7; xi++) {
                preout[yi][xi].cl               = 15;
                preout[yi][xi].ch               = ' ';
            }   
        }
        system ("cls");
        return true;
    }
    return false;
}
inline __attribute__ ((always_inline))
void input (LPVOID id) {
    int                                         ch;
    std::mutex                                  mlock;
    while (true) {
        ch                                      = getch ();
        edit                                    = true;
        mlock.lock ();
        if (cfn (ch)) {
            if (sig == -1)
                return;
        } else if (cctrl (ch)) {
            if (sig == -1)
                return;
        } else if (ch == 8) {                                               //Back
            if (tx == 0) {
                if (ty -> pre != doc.begin ()) {
                    ty                          = ty -> pre;
                    tx                          = ty -> v.size();
                    for (iterator it = 0; it < ty -> next -> v.size (); it++)
                        ty -> v                 += ty -> next -> v[it];
                    doc.erase (ty);
                    cnt--;
                }
            } else {
                ty -> v.erase (tx - 1);
                tx--;
            }
        } else if (ch == 9) {                                               //Tab
            do {
                ty -> v.insert (tx, ' ');
                tx++;
            } while (tx % 4 != 0);
        } else if (ccom (ch)) {
            if (sig == -1)
                return;
        } else if (ch == 13) {                                              //Enter
            node <vector <char> >* tn           = new node <vector <char> >;
            for (iterator it = tx; it < ty -> v.size (); it++)
                tn -> v += ty -> v[it];
            ty -> v                             -= (ty -> v.size() - tx);
            tn -> pre                           = ty;
            tn -> next                          = ty -> next;
            ty -> next -> pre                   = tn;
            ty -> next                          = tn;
            ty                                  = ty -> next;
            tx                                  = 0;
            while (
                tx < ty -> pre -> v.size () &&
                ty -> pre -> v[tx] == ' '
            ) {
                ty -> v.insert (tx, ' ');
                tx++;
            }
            cnt++;
        } else if (ch == 27) {                                              //Esc
            save ();
            sig                                 = -1;
            return;
        } else if (lock && ch == '(')  {
            ty -> v.insert (tx, (char)ch);
            tx++;
            ty -> v.insert (tx, ')');
        } else if (lock && ch == '[')  {
            ty -> v.insert (tx, (char)ch);
            tx++;
            ty -> v.insert (tx, ']');
        } else if (lock && ch == '{')  {
            ty -> v.insert (tx, (char)ch);
            tx++;
            ty -> v.insert (tx, '}');
        } else if (lock && ch == '\"') {
            ty -> v.insert (tx, (char)ch);
            tx++;
            ty -> v.insert (tx, '\"');
        } else if (lock && ch == '\'') {
            ty -> v.insert (tx, (char)ch);
            tx++;
            ty -> v.insert (tx, '\'');
        } else if (ch == 224) {
            ch = getch ();
            switch (ch) {
                case 83: {                                                  //Delete
                    if (tx == ty -> v.size()) {
                        if (ty -> next != doc.end ()) {
                            for (iterator it = 0; it < ty -> next -> v.size (); it++)
                                ty -> v         += ty -> next -> v[it];
                            doc.erase (ty);
                        }
                    } else {
                        ty -> v.erase (tx);
                    }
                    break;
                }
                case UP: {
                    if (ty -> pre != doc.begin ()) {
                        ty                      = ty -> pre;
                        tx                      = min (tx, ty -> v.size ());
                        cnt--;
                    }
                    edit                        = false;
                    break;
                }
                case DOWN: {
                    if (ty -> next != doc.end ()) {
                        ty                      = ty -> next;
                        tx                      = min (tx, ty -> v.size ());
                        cnt++;
                    }
                    edit                        = false;
                    break;
                }
                case LEFT: {
                    if (tx > 0) {
                        tx--;
                    }
                    edit                        = false;
                    break;
                }
                case RIGHT: {
                    if (tx < ty -> v.size ()) {
                        tx++;
                    }
                    edit                        = false;
                    break;
                }
            }
        } else if (ch == 127) {
            do {
                if (tx != 0) {
                    tx--;
                    ty -> v.erase (tx);
                }
            } while (tx % 4 != 0);
        } else {
            ty -> v.insert (tx, (char)ch);
            tx++;
        }
        while (cnt > H - 2) {
            lines++;
            cnt--;
            py                          = py -> next;
        }
        while (cnt < 0) {
            lines--;
            cnt++;
            py                          = py -> pre;
        }
        if (edit) {
            edit                        = false;
            char                        calls[BUFLEN];
            sprintf (calls, "title %s*", name);
            system (calls);
        }
        mlock.unlock();
        sig                             = 1;
    }
    return;
}

namespace snake {
    #define X 23
    #define Y 40
    #define MAXLEN 75
    #define MINTIME 75
    void welcome () {
        printf  ("游戏规则:\n");
        printf  ("w,a,s,d,控制移动\n");
        getch   ();
        system  ("cls");
        return;
    }
    void init () {
        system ("title 贪吃蛇");
        CONSOLE_CURSOR_INFO cursor_info = {1, 0};
        SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &cursor_info);
        std::fstream in ("score.txt", std::ios::in);
        if (!in.fail ())
            in >> max_score;
        else
            welcome ();
        in.close ();
        len = 4;
        snake[0][0] = X >> 1;
        snake[0][1] = Y >> 1;
        snake[1][0] = (X >> 1) + 1;
        snake[1][1] = Y >> 1;
        snake[2][0] = (X >> 1) + 2;
        snake[2][1] = Y >> 1;
        snake[3][0] = (X >> 1) + 3;
        snake[3][1] = Y >> 1;
        way = UP;
        wait = 150.0;
        return;
    }
    void drawmap (){
        color (255);
        for (unsigned int xx = 0; xx < X; xx++){
            gotoxy (0, (short)xx);
            printf ("  ");
            gotoxy ((short)(Y * 2 - 2), (short)xx);
            printf ("  ");
        }
        for (unsigned int yy = 0; yy < Y; yy++){
            gotoxy ((short)(yy * 2), 0);
            printf ("  ");
            gotoxy ((short)(yy * 2), (short)(X - 1));
            printf ("  ");
        }
        return;
    }
    void drawsnake (){
        color (255);
        gotoxy (0,0);
        printf ("  ");
        color (10);
        gotoxy ((short)(snake[0][1] * 2), (short)snake[0][0]);
        printf ("□");
        gotoxy ((short)(snake[1][1] * 2), (short)snake[1][0]);
        printf ("■");
        return;
    }
    void move () {
        lastt[0] = snake[len-1][0];
        lastt[1] = snake[len-1][1];
        for (unsigned int tc = len - 1; tc > 0; tc--){
            snake[tc][0] = snake[tc-1][0];
            snake[tc][1] = snake[tc-1][1];
        }
        switch (way) {
            case UP: {
                snake[0][0]--;
                break;
            }
            case DOWN: {
                snake[0][0]++;
                break;
            }
            case LEFT: {
                snake[0][1]--;
                break;
            }
            case RIGHT: {
                snake[0][1]++;
                break;
            }
        }
        return;
    }
    void clt () {
        color (0);
        gotoxy ((short)(lastt[1] * 2), (short)lastt[0]);
        printf ("  ");
        return;
    }
    void getin () {
        if (kbhit () != 0) {
            while (kbhit() != 0)
                input = getch ();
            switch (input) {
                case 'W':
                case 'w': {
                    if (way != DOWN)
                        way = UP;
                    break;
                }
                case 'S':
                case 's': {
                    if (way != UP)
                        way = DOWN;
                    break;
                }
                case 'A':
                case 'a':{
                    if (way != RIGHT)
                        way = LEFT;
                    break;
                }
                case 'D':
                case 'd':{
                    if (way != LEFT)
                        way = RIGHT;
                    break;
                }
            }
        }
        return;
    }
    void putfood () {
        if (empty) {
            bool flag = true;
            srand (time (NULL));
            while (flag) {
                food[0] = rand () % (X - 2) + 1;
                food[1] = rand () % (Y - 2) + 1;
                flag = false;
                for (unsigned int tc = 0; tc < len; tc++) {
                    if(snake[tc][0] == food[0] && snake[tc][1] == food[1])
                        flag = true;
                } 
            }
            empty = false;
            color (14);
            gotoxy ((short)(food[1] * 2), (short)food[0]);
            printf ("◆");
        }
        return;
    }
    void eatfood () {
        if (snake[0][0] == food[0] && snake[0][1] == food[1]) {
            empty = true;
            score++;
            if(wait >= MINTIME)
                wait -= 0.5;
            if(len < MAXLEN)
                len++;
        }
        return;
    }
    bool gameover () {
        bool over = false;
        if (
            snake[0][0] == 0 || snake[0][0] == X - 1 ||
            snake[0][1] == 0 || snake[0][1] == Y - 1
        ) {
            over = true;
        }
        for (unsigned int tc = 1; tc < len; tc++)
            if (snake[0][0] == snake[tc][0] && snake[0][1] == snake[tc][1])
                over = true;
        if (over == true) {
            system ("cls");
            while (kbhit() != 0)
                getch ();
            printf ("Game over!\n");
            printf ("Score:%d\n",score);
            printf ("Max score:%d\n",max_score);
            getch ();
            system ("cls");
            printf ("Save...\n");
            if (score > max_score) {
                std::fstream write;
                write.open ("score.txt",std::ios::out);
                write << score;
                write.close ();
                max_score = score;
            }
        }
        return over;
    }
    int start () {
        init ();
        drawmap ();
        Sleep (3000);
        while (true) {
            clt         ();
            drawsnake   ();
            putfood     ();
            eatfood     ();
            getin       ();
            move        ();
            if (gameover ())
                break;
            Sleep ((DWORD)(wait));
        }
        return 0;
    }
    #undef X
    #undef Y
    #undef MAXLEN
    #undef MINTIME
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/370535.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Java并发(二十三)----同步模式之保护性暂停

1、定义 即 Guarded Suspension&#xff0c;用在一个线程等待另一个线程的执行结果 要点 有一个结果需要从一个线程传递到另一个线程&#xff0c;让他们关联同一个 GuardedObject 如果有结果不断从一个线程到另一个线程那么可以使用消息队列 JDK 中&#xff0c;join 的实现…

嵌入式学习第十六天!(Linux文件查看、查找命令、标准IO)

Linux软件编程 1. Linux&#xff1a; 操作系统的内核&#xff1a; 1. 管理CPU 2. 管理内存 3. 管理硬件设备 4. 管理文件系统 5. 任务调度 2. Shell&#xff1a; 1. 保护Linux内核&#xff08;用户和Linux内核不直接操作&#xff0c;通过操作Shell&#xff0c;Shell和内核交互…

Ubuntu Linux 下安装和卸载cmake 3.28.2版本

一、安装cmake 1.首先&#xff0c;先从cmake官网下载cmake-3.28.2-linux-x86_64.tar.gz 2.用FinalShell 等文件上传工具&#xff0c;将这个压缩包上传到 虚拟机的某个路径去&#xff08;自选&#xff09; 3. cd /usr/local/bin/&#xff0c;然后创建cmake文件夹&#xff0c;…

重温《深入理解Java虚拟机:JVM高级特性与最佳实践(第二版)》 –– 学习笔记(二)

第二部分&#xff1a;自动内存管理机制 第2章&#xff1a;Java内存区域与内存溢出异常 2.1 概述 Java 与 C 之间有一堵由内存动态分配和垃圾收集技术围成的高墙。 Java 程序员在 虚拟机自动内存管理机制 的帮助下&#xff0c;无需为每一个 new 操作去写配对的 delete/free …

Cox等级资料是个坑

R语言做&#xff01;初学者先进来看看&#xff01;&#xff01;&#xff01; SCI冲 COX多因素模型需要满足的条件&#xff1a; 1.各观测值间相互独立&#xff0c;即残差之间不存在自相关&#xff1b; 2.因变量和自变量之间存在线性关系&#xff1b; 3.残差的方差齐&#xf…

鸿蒙ArkUI实现开关switch组件

鸿蒙ArkUI官方提供的toggle组件实现了开关的样式&#xff0c;但在使用过程中还是非常的不方便。 DIY可视化对鸿蒙ArkUI实现开关switch组件扩展后满足基本的switch需求&#xff0c;支持绑定值、设置标题文本、整个背景样式等。 /*** 开关*/ Component export default struct Di…

Angular BaseView抽离页面公用属性

前言 如果有一系列的页面布局很类似&#xff0c;为了节省时间&#xff0c;我们可以把这些类似的页面所通用的属性和方法抽离成一个BaseView&#xff0c;让其它页面继承该基础页面&#xff0c;同时将一些经常改变的属性和差异的属性写到配置文件里。例如树容器初始时是否展开、…

npm ERR! code CERT_HAS_EXPIRED

执行npm i报错&#xff1a; npm ERR! code ETIMEDOUT npm ERR! syscall connect npm ERR! errno ETIMEDOUT npm ERR! network request to https://registry.npmjs.org/react-redux failed, reason: connect ETIMEDOUT 104.16.2.35:443 npm ERR! network This is a problem rel…

[设计模式Java实现附plantuml源码~结构型]处理多维度变化——桥接模式

前言&#xff1a; 为什么之前写过Golang 版的设计模式&#xff0c;还在重新写Java 版&#xff1f; 答&#xff1a;因为对于我而言&#xff0c;当然也希望对正在学习的大伙有帮助。Java作为一门纯面向对象的语言&#xff0c;更适合用于学习设计模式。 为什么类图要附上uml 因为很…

python_蓝桥杯刷题记录_笔记_全AC代码_入门3

前言 记录我的解法以及笔记思路&#xff0c;谢谢观看。 题单目录 1.P2141 [NOIP2014 普及组] 珠心算测验 2.P1567 统计天数 3.P1055 [NOIP2008 普及组] ISBN 号码 4.P1200 [USACO1.1] 你的飞碟在这儿 Your Ride Is Here 5.P1308 [NOIP2011 普及组] 统计单词数 6.P1047 […

[职场] CAD设计师简历模板 #微信#知识分享#学习方法

CAD设计师简历模板 一份优秀的简历能帮助你更好地让你所应聘的公司了解你&#xff0c;并能更好地找到你想要的工作。因此&#xff0c;如何撰写一份优异的简历显得尤为重要。以下是申请“CAD设计师”职位时的一份简历模板&#xff0c;供大家参考阅读。 蓝山简历 求职意向&#…

CSDN文章导出工具

源码地址&#xff1a; github:https://github.com/lishuangquan1987/CSDNExportergitee:https://gitee.com/lishuangquan1987/csdnexporter 介绍 最近有CSDN博客导出来的需求&#xff0c;翻看了很多开源工具&#xff0c;都不能用或者不好用&#xff0c;于是决定自己做一个。…

vulhub中Adminer远程文件读取漏洞复现(CVE-2021-43008)

Adminer是一个PHP编写的开源数据库管理工具&#xff0c;支持MySQL、MariaDB、PostgreSQL、SQLite、MS SQL、Oracle、Elasticsearch、MongoDB等数据库。 在其版本1.12.0到4.6.2之间存在一处因为MySQL LOAD DATA LOCAL导致的文件读取漏洞。 参考链接&#xff1a; https://gith…

外包干了10个月,技术退步明显.......

先说一下自己的情况&#xff0c;大专生&#xff0c;18年通过校招进入武汉某软件公司&#xff0c;干了接近4年的功能测试&#xff0c;今年年初&#xff0c;感觉自己不能够在这样下去了&#xff0c;长时间呆在一个舒适的环境会让一个人堕落! 而我已经在一个企业干了四年的功能测…

【JavaEE进阶】 图书管理系统开发日记——肆

文章目录 &#x1f343;前言&#x1f38d;约定前后端交互接⼝&#x1f340;服务器代码实现&#x1f6a9;控制层&#x1f6a9;业务层&#x1f6a9;数据层 &#x1f334;前端代码的修改⭕总结 &#x1f343;前言 今天我们来实现修改图书模块 首先我们先来看一下&#xff0c;需要…

深度学习在智能交互中的应用:人与机器的和谐共生

深度学习与人类的智能交互是当前人工智能领域研究的热点之一。深度学习作为机器学习的一个重要分支&#xff0c;具有强大的特征学习和模式识别能力&#xff0c;可以模拟人脑的神经网络进行数据分析和预测。而人类的智能交互则是指人类与机器之间的信息交流和操作互动&#xff0…

运维自动化bingo前端

项目目录结构介绍 项目创建完成之后&#xff0c;我们会看到bingo_web项目其实是一个文件夹&#xff0c;我们进入到文件夹内部就会发现一些目录和文件&#xff0c;我们简单回顾一下里面的部分核心目录与文件。 ├─node_modules/ # node的包目录&#xff0c;项目运行的依赖包…

逆向基础-破解密码

1.通过study PE查看.exe程序的位数 打开 x32dbg 从暂停到运行程序 原理&#xff1a;软件算出的密码与用户输入的密码作比较 破解流程&#xff1a;查信息 --> 找内存关键数据 --> 测试

Optimizer:基于.Net开发的、提升Windows系统性能的终极开源工具

我们电脑使用久了后&#xff0c;就会产生大量的垃圾文件、无用的配置等&#xff0c;手动删除非常麻烦&#xff0c;今天推荐一个开源工具&#xff0c;可以快速帮助我们更好的优化Windos电脑。 01 项目简介 Optimizer是一个面向Windows系统的优化工具&#xff0c;旨在提升计算机…

[GN] 23种设计模式 —— 常见设计模式学习总结

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言创建型模式 —— 创建的艺术结构型模式 —— 组合的艺术适配器模式 -- 不兼容结构的协调对象适配器类适配器模式优缺点适用场景 组合模式 -- 树形结构的处理例子…