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

📄 edit.c

📁 edit 0.82 freedos中的文本编辑器
💻 C
字号:
/*  FreeDOS Editor

    Some portions copyright (c) Joe Cosentino 2000-2004.
    Modified by Eric Auer 2002.

*/

/* I N C L U D E S /////////////////////////////////////////////////////// */

#include "dflat.h"

/* D E F I N E S ///////////////////////////////////////////////////////// */

#define CHARSLINE 80
#define LINESPAGE 66

/* G L O B A L S ///////////////////////////////////////////////////////// */

extern DBOX PrintSetup;
char DFlatApplication[] = "Edit";
static char Untitled[] = "Untitled";
static int wndpos, LineStartsAt, StartLine, LineCtr, CharCtr;
static char *ports[] = {
    "Lpt1", "Lpt2", "Lpt3",
    "Com1", "Com2", "Com3", "Com4",
    NULL
};

/* P R O T O T Y P E S /////////////////////////////////////////////////// */

int classify_args(int, char *[], char *[], char *[]);
static int MemoPadProc(WINDOW, MESSAGE, PARAM, PARAM);
static void NewFile(WINDOW,char *);
static void SelectFile(WINDOW);
static void PadWindow(WINDOW, char *);
static void OpenPadWindow(WINDOW, char *,char *);
static void LoadFile(WINDOW);
static void PrintPad(WINDOW);
static void SaveFile(WINDOW, int);
static int EditorProc(WINDOW, MESSAGE, PARAM, PARAM);
static char *NameComponent(char *);
static int PrintSetupProc(WINDOW, MESSAGE, PARAM, PARAM);
static void FixTabMenu(void);

/* F U N C T I O N S ///////////////////////////////////////////////////// */

int classify_args(int argc, char *rawargs[], char *fileargs[], char *optargs[])
{
    int index, jndex, kndex;
    char *argptr;

    /* skip index=0, aka argv[0]==edit.exe */
    for (index=1,jndex=0,kndex=0;index<argc;index++)
        {
        argptr=rawargs[index];
        if (*argptr == '/')
            {
            argptr++;
            optargs[kndex++]=argptr;
            } 
        else
            {
            fileargs[jndex++]=argptr;
            } 

        }

   return kndex;

} 

void main(int argc, char *argv[])
{
    WINDOW wnd;
    FILE *fp;
    char *fileargs[64], *optargs[64];
    int n_options, n_files, index, help_flag=0;

    n_options=classify_args(argc, argv, fileargs, optargs);
    n_files=argc-n_options-1/*argv[0]*/;
    for (index=0;index<n_options;index++)
        {
        if (optargs[index][0] == '?') help_flag=1;
        else if (optargs[index][0] == 'B' || optargs[index][0] == 'b') cfg.mono=1;
        else if (optargs[index][0] == 'H' || optargs[index][0] == 'h') cfg.ScreenLines=SCREENHEIGHT;
        else if (optargs[index][0] == 'R' || optargs[index][0] == 'r') cfg.read_only=1;
        else
            {
            printf("Invalid parameter - /%s\n", strupr(optargs[index]));
            exit(1);
            }

        }

    if (help_flag)
        {
        printf("FreeDOS Editor\tVersion " VERSION ".\n\n"
               "Syntax: EDIT [/B] [/R] [/?] [file(s)]\n"
               "  /B     Forces monochrome mode\n"
               "  /R     Opens a file as read only\n"
               "  /?     Displays this help message\n"
               "  [file] Specifies initial file(s) to load.  Wildcards and multiple\n"
               "         files can be given\n");
        exit(1);
        }

    if (!init_messages())
        return;

#ifdef ENABLEGLOBALARGV
    Argv = argv;
#endif

    if (!LoadConfig())
        cfg.ScreenLines = SCREENHEIGHT;

    wnd = CreateWindow(APPLICATION, "FreeDOS Edit", 0, 0, -1, -1, &MainMenu, NULL, MemoPadProc, MOVEABLE | SIZEABLE | HASBORDER | MINMAXBOX | HASSTATUSBAR);
    LoadHelpFile(DFlatApplication);
    SendMessage(wnd, SETFOCUS, TRUE, 0);
    if (cfg.loadblank)
        NewFile(wnd,NULL);

    /* Load the files from args - if the file does not exist, open a new
       window.... */
    for (index=0;index<n_files;index++)
        {
        /*  Check if the file exists... */
        /* added by Eric: Do NOT try to open files with names */
        /* that contain wildcards, otherwise you may NewFile  */
        /* files with wildcards in their names. Sigh! 11/2002 */
        fp = NULL;
        if (((strchr(fileargs[index],'*') == NULL)) && ((strchr(fileargs[index],'?') == NULL)) && ((fp = fopen(fileargs[index],"rt")) == NULL))
            {
            NewFile(wnd,fileargs[index]);
            }
        else
            {
            if (fp != NULL)
                 fclose(fp);  /* don't leave open file handle [from test if exists in above if] */

            PadWindow(wnd, fileargs[index]);
            }

        }

    while (dispatch_message());

}

/* ------ open text files and put them into editboxes ----- */
static void PadWindow(WINDOW wnd, char *FileName)
{
    int ax,criterr=1;
    struct ffblk ff;
    char path[66],*cp;

    CreatePath(path, FileName, FALSE, FALSE);
    cp = path+strlen(path);
    CreatePath(path, FileName, TRUE, FALSE);
    while (criterr == 1)
        {
        ax = findfirst(path, &ff, 0);
        criterr = TestCriticalError();
        }

    while (ax == 0 && !criterr)
        {
        strcpy(cp, ff.ff_name);
        OpenPadWindow(wnd, path,NULL);
        ax = findnext(&ff);
        }

}

/* ------- window processing module for the Edit application window ----- */
static int MemoPadProc(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
{
    int rtn;

    switch (msg)
        {
        case CREATE_WINDOW:
            rtn = DefaultWndProc(wnd, msg, p1, p2);
            if (cfg.InsertMode)
                SetCommandToggle(&MainMenu, ID_INSERT);

            if (cfg.WordWrap)
                SetCommandToggle(&MainMenu, ID_WRAP);

            FixTabMenu();
            return rtn;
        case COMMAND:
            switch ((int)p1)
                {
                case ID_NEW:
                    NewFile(wnd,NULL);
                    return TRUE;
                case ID_OPEN:
                    SelectFile(wnd);
                    return TRUE;
                case ID_SAVE:
                    SaveFile(inFocus, FALSE);
                    return TRUE;
                case ID_SAVEAS:
                    SaveFile(inFocus, TRUE);
                    return TRUE;
                case ID_CLOSE:
                    SendMessage(inFocus, CLOSE_WINDOW, 0, 0);
                    SkipApplicationControls();
                    return TRUE;
                case ID_PRINTSETUP:
                    DialogBox(wnd, &PrintSetup, TRUE, PrintSetupProc);
                    return TRUE;
                case ID_PRINT:
                    PrintPad(inFocus);
                    return TRUE;
                case ID_EXIT:
                    break;
                case ID_WRAP:
                    cfg.WordWrap = GetCommandToggle(&MainMenu, ID_WRAP);
                    return TRUE;
                case ID_INSERT:
                    cfg.InsertMode = GetCommandToggle(&MainMenu, ID_INSERT);
                    return TRUE;
                case ID_TAB2:
                    cfg.Tabs = 2;
                    FixTabMenu();
                    return TRUE;
                case ID_TAB4:
                    cfg.Tabs = 4;
                    FixTabMenu();
                    return TRUE;
                case ID_TAB6:
                    cfg.Tabs = 6; 
                    FixTabMenu();
                    return TRUE;
                case ID_TAB8:
                    cfg.Tabs = 8;
                    FixTabMenu();
                    return TRUE;
#ifndef NOCALENDAR
                case ID_CALENDAR:
                    Calendar(wnd); 
                    return TRUE;
#endif
                case ID_ABOUT:
                    {
                    char aboutMsg[] =
                               "          FreeDOS Edit           \n"
                               "          Version @              \n"
                               "                                 \n"
                               "   FreeDOS Edit is based on the  \n"
                               "   D-Flat application published  \n"
                               "   in Dr. Dobb's Journal.        \n"
                               "                                 \n"
                               "    哪哪哪哪哪哪哪哪哪哪哪哪

⌨️ 快捷键说明

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