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

📄 saveload.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
Copyright 2001-2003 Free Software Foundation, Inc.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.  

You may contact the author at:

mailto::camille@bluegrass.net

or by snail mail at:

David Lindauer
850 Washburn Ave Apt 99
Louisville, KY 40222

 **********************************************************************

SAVELOAD.C handles project and workspace file save and load.  The
loading algorithms are pretty generic, as long as the nesting is maintained
the ordering doesn't matter and it will also just discard any xml nodes it
doesn't know what to do with so even going backwards in the IDE version
will allow it to still be loaded.

 **********************************************************************

 */
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include <stdio.h>
#include <ctype.h>

#define PROJVERS 5
#define WSPVERS 1

#include "header.h"
#include "xml.h"

extern HINSTANCE hInstance;
extern HWND hwndProject;
extern int changedProject;
extern char szProjectFilter[];
extern struct tagfile *tagFileList;
extern char szProjectTitle[], szProjectName[];
extern HWND hwndToolEdit, hwndToolDebug, hwndToolBuild;
extern LOGFONT EditFont;
extern HWND hwndClient, hwndStatus, hwndFrame;
extern PROJLIST *projectList;
extern int browseInfo;
extern char *findhist1[MAX_COMBO_HISTORY];
extern char *findhist2[MAX_COMBO_HISTORY];
extern char *replacehist[MAX_COMBO_HISTORY];
extern char *watchhist[MAX_COMBO_HISTORY];
extern char *fifhistory[MAX_COMBO_HISTORY];
extern COLORREF keywordColor;
extern COLORREF numberColor;
extern COLORREF commentColor;
extern COLORREF stringColor;
extern COLORREF escapeColor;
extern COLORREF backgroundColor;
extern COLORREF textColor;
extern int custColors[16];
extern int numberofdrawwindows;
extern int editFlags;
extern DWINFO *newInfo;
extern HANDLE children[MAX_CHILDREN];
extern int tabs;
extern char szDrawClassName[];
extern char szUntitled[];
extern char hbpNames[4][256];
extern int hbpAddresses[4];
extern char hbpModes[4], hbpSizes[4], hbpEnables;

PROJLIST *LoadErr(struct xmlNode *root, char *name, PROJLIST *list)
{
    xmlFree(root);
    projectList = list;
    ProjectFreeList();
    ExtendedMessageBox("Load Error", MB_SETFOREGROUND | MB_SYSTEMMODAL, 
        "Project File %s is the wrong format", name);
    return 0;
} PROJLIST *NoMemory(struct xmlNode *root, char *list)
{
    xmlFree(root);
    projectList = list;
    ProjectFreeList();
    ExtendedMessageBox("Load Error", MB_SETFOREGROUND | MB_SYSTEMMODAL, 
        "Out of memory");
    return 0;
} void NoMemoryWS(void)
{
    ExtendedMessageBox("Load Error", MB_SETFOREGROUND | MB_SYSTEMMODAL, 
        "Out of memory");
}

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

int IsNode(struct xmlNode *node, char *name)
{
    return (!strcmp(node->elementType, name));
} int IsAttrib(struct xmlAttr *attr, char *name)
{
    return (!strcmp(attr->name, name));
} void addcr(char *buf)
{
    char buf2[2048],  *p = buf2;
    strcpy(buf2, buf);
    while (*p)
    {
        if (*p == '\n')
            *p++ = '\r';
        *buf++ =  *p++;
    }
    *buf = 0;


}

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

void RestorePlacement(struct xmlNode *node, int version)
{
    struct xmlAttr *attribs = node->attribs;
    while (attribs)
    {
        if (IsAttrib(attribs, "VALUE"))
        {
            WINDOWPLACEMENT wp;
            wp.length = sizeof(WINDOWPLACEMENT);
            sscanf(attribs->value, "%d %d %d %d %d %d %d %d %d %d",  &wp.flags,
                &wp.showCmd,  &wp.ptMinPosition.x, &wp.ptMinPosition.y, 
                &wp.ptMaxPosition.x, &wp.ptMaxPosition.y, 
                &wp.rcNormalPosition.left, &wp.rcNormalPosition.top, 
                &wp.rcNormalPosition.right, &wp.rcNormalPosition.bottom);
            wp.flags = 0;
            SetWindowPlacement(hwndFrame, &wp);
        } attribs = attribs->next;
    }
}

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

void RestoreDocks(struct xmlNode *node, int version)
{
    CCD_params d[20];
    int ids[20];
    int count = 0;
    struct xmlNode *dchildren = node->children;
    while (dchildren && count < 20)
    {
        if (IsNode(dchildren, "DOCK"))
        {
            struct xmlAttr *attribs = dchildren->attribs;
            while (attribs)
            {
                if (IsAttrib(attribs, "ID"))
                    ids[count] = atoi(attribs->value);
                else if (IsAttrib(attribs, "VALUE"))
                {
                    sscanf(attribs->value, 
                        "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d>\n",  &d[count].flags, &d[count].flexparams,  &d[count].rowindex, &d[count].colindex,  &d[count].hidden, &d[count].hiddenwidth,  &d[count].oldsize.left, &d[count].oldsize.top, &d[count].oldsize.right, &d[count].oldsize.bottom,  &d[count].position.left, &d[count].position.top, &d[count].position.right, &d[count].position.bottom,  &d[count].lastposition.left, &d[count].lastposition.top, &d[count].lastposition.right, &d[count].lastposition.bottom);
                } attribs = attribs->next;
            }
            adjustforbadplacement(ids[count], &d[count]);
            count++;
        }
        dchildren = dchildren->next;
    }
    dmgrSetInfo(ids, &d[0], count);
}

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

void RestoreHistory(struct xmlNode *node, int version)
{
    int count = 0;
    char buf[256];
    char **histitem = 0;
    struct xmlAttr *attribs = node->attribs;
    struct xmlNode *children = node->children;
    while (attribs)
    {
        if (IsAttrib(attribs, "TYPE"))
        {
            if (!strcmp(attribs->value, "FIND1"))
                histitem = findhist1;
            else if (!strcmp(attribs->value, "FIND2"))
                histitem = findhist2;
            else if (!strcmp(attribs->value, "REPLACE"))
                histitem = replacehist;
            else if (!strcmp(attribs->value, "WATCH"))
                histitem = watchhist;
            else if (!strcmp(attribs->value, "FINDINFILES"))
                histitem = fifhistory;
        } attribs = attribs->next;
    }
    if (!histitem)
        return ;
    for (count = 0; count < MAX_COMBO_HISTORY; count++)
    if (histitem[count])
    {
        free(histitem[count]);
        histitem[count] = 0;
    }
    count = 0;
    while (children && count < MAX_COMBO_HISTORY)
    {
        if (IsNode(children, "HISTITEM"))
        {
            attribs = children->attribs;
            while (attribs && count < MAX_COMBO_HISTORY)
            {
                if (IsAttrib(attribs, "VALUE"))
                {
                    histitem[count++] = strdup(attribs->value);
                }
                attribs = attribs->next;
            }
        }
        children = children->next;
    }
}

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

int RestoreFont(struct xmlNode *node, int version)
{
    int i, j = 0, n;
    LOGFONT lf;
    char *bf = node->textData;
    for (i = 0; i < sizeof(LOGFONT); i++)
    {
        sscanf(bf, "%d%n", &n, &j);
        *(((unsigned char*) &lf) + i) = n;
        bf += j;
    } 

    ApplyFontSettings(&lf);
}

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

void RestoreColors(struct xmlNode *node, int version)
{
    int i, j = 0;
    struct xmlAttr *attribs = node->attribs;
    char *bf = node->textData;
    while (attribs)
    {
        if (IsAttrib(attribs, "KEYWORD"))
            keywordColor = atoi(attribs->value);
        else if (IsAttrib(attribs, "NUMBER"))
            numberColor = atoi(attribs->value);
        else if (IsAttrib(attribs, "COMMENT"))
            commentColor = atoi(attribs->value);
        else if (IsAttrib(attribs, "STRING"))
            stringColor = atoi(attribs->value);
        else if (IsAttrib(attribs, "ESCAPE"))
            escapeColor = atoi(attribs->value);
        else if (IsAttrib(attribs, "BACKGROUND"))
            backgroundColor = atoi(attribs->value);
        else if (IsAttrib(attribs, "TEXT"))
            textColor = atoi(attribs->value);

        attribs = attribs->next;
    } for (i = 0; i < 16; i++)
    {
        sscanf(bf, "%d%n", &custColors[i], &j);
        bf += j;
    }
}

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

void RestoreTabs(struct xmlNode *node, int version)
{
    struct xmlAttr *attribs = node->attribs;
    while (attribs)
    {
        if (IsAttrib(attribs, "SPACING"))
            tabs = atoi(attribs->value);
        attribs = attribs->next;
    } 
}

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

void RestoreEditflags(struct xmlNode *node, int version)
{
    struct xmlAttr *attribs = node->attribs;
    while (attribs)
    {
        if (IsAttrib(attribs, "FLAGS"))
            editFlags = atoi(attribs->value);
        attribs = attribs->next;
    } 
}

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

void RestoreWindows(struct xmlNode *node, int version)
{
    MDICREATESTRUCT mc;
    static DWINFO info;
    int i;
    struct xmlNode *children = node->children;
    while (children)
    {
        if (IsNode(children, "WINDOW"))
        {
            struct xmlAttr *attribs = children->attribs;
            memset(&info, 0, sizeof(info));
            memset(&mc, 0, sizeof(mc));
            while (attribs)
            {
                if (IsAttrib(attribs, "NAME"))
                {
                    strcpy(info.dwName, attribs->value);
                    abspath(info.dwName);
                } 
                else if (IsAttrib(attribs, "TITLE"))
                    strcpy(info.dwTitle, attribs->value);
                else if (IsAttrib(attribs, "X"))
                    mc.x = atoi(attribs->value);
                else if (IsAttrib(attribs, "Y"))
                    mc.y = atoi(attribs->value);
                else if (IsAttrib(attribs, "WIDTH"))
                    mc.cx = atoi(attribs->value);
                else if (IsAttrib(attribs, "HEIGHT"))
                    mc.cy = atoi(attribs->value);
                else if (IsAttrib(attribs, "LINENO"))
                    info.dwLineNo = atoi(attribs->value);
                attribs = attribs->next;
            }
            newInfo = &info;
            mc.szClass = szDrawClassName;
            mc.szTitle = szUntitled;
            mc.hOwner = hInstance;
            mc.style = WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW | WS_SYSMENU
                | WS_SIZEBOX | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
            mc.lParam = 0;
            SendMessage(hwndClient, WM_MDICREATE, 0, (LPARAM) &mc);
            Sleep(250);
        }
        children = children->next;
    }

}

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

void RestoreChangeLn(struct xmlNode *node, int version)
{
    struct xmlNode *children = node->children;
    struct tagfile *l,  **ls = &tagFileList;
    struct xmlAttr *attribs;
    while (*ls)
        ls = &(*ls)->next;
    while (children)
    {
        if (IsNode(children, "FILE"))
        {
            struct xmlNode *fchildren = children->children;
            struct tagchangeln *c = 0,  **x = &c;
            *ls = calloc(sizeof(struct tagfile), 1);
            if (!ls)
            {
                NoMemoryWS();
                return ;
            } attribs = children->attribs;
            while (attribs)
            {
                if (IsAttrib(attribs, "NAME"))
                {
                    strcpy((*ls)->name, attribs->value);
                    abspath((*ls)->name);
                }
                attribs = attribs->next;
            }
            l = tagFileList;
            while (l)
            {
                if (!strcmp(l->name, (*ls)->name))
                    break;
                l = l->next;
            }
            if (l !=  *ls)
            {
                free(*ls);
                *ls = 0;
            }
            else
                ls = &(*ls)->next;
            while (fchildren)
            {
                if (IsNode(fchildren, "LINE"))
                {
                    // assumes enumerated in order
                    *x = calloc(sizeof(struct tagchangeln), 1);
                    if (! *x)
                    {
                        NoMemoryWS();
                        return ;
                    } attribs = fchildren->attribs;
                    while (attribs)
                    {
                        if (IsAttrib(attribs, "NUM"))
                            (*x)->lineno = atoi(attribs->value);
                        else if (IsAttrib(attribs, "DELTA"))
                            (*x)->delta = atoi(attribs->value);
                        attribs = attribs->next;
                    }
                    x = &(*x)->next;
                }
                fchildren = fchildren->next;
            }
            l->changedLines = c;
        }
        children = children->next;
    }
}

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

void RestoreTags(struct xmlNode *node, int version)
{

⌨️ 快捷键说明

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