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

📄 edit.c

📁 DOS下Editor的源代码
💻 C
字号:
/* --------------- edit.c ----------- */

#include "dflat.h"

extern DBOX PrintSetup;

char DFlatApplication[] = "Edit";
static char Untitled[] = "Untitled";

static int wndpos;

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 void DeleteFile(WINDOW);
static int EditorProc(WINDOW, MESSAGE, PARAM, PARAM);
static char *NameComponent(char *);
static int PrintSetupProc(WINDOW, MESSAGE, PARAM, PARAM);
static void FixTabMenu(void);
static int LineStartsAt;        /* holds position where next line should start */
static int StartLine;   /* flag which tells us if valid text has started */
char **Argv;

#define CHARSLINE 80
#define LINESPAGE 66

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

    for (index=0,jndex=0,kndex=0;index<argc;index++)
        {
        argptr = rawargs[index];
        if (*argptr == '/')
            {
            argptr++;
            optargs[kndex++] = argptr;
            } /* end if. */
        else
            {
            fileargs[jndex++] = argptr;
            } /* end else. */

        } /* end for. */

   return kndex;

} /* end classify_args. */

/*
* by yangyf
* array fileargs save file name
* array optargs save option

* eg : edit /b /s /c fname1 fname2 fname3
* fileargs[0] = "fname1"
* fileargs[1] = "fname2"
* fileargs[2] = "fname3"
* optargs[0] = b
* optargs[1] = s
* optargs[2] = c
*/
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;
    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
            {
            printf("Invalid parameter - /%s\n", strupr(optargs[index]));
            exit(1);
            }

        }

    if (help_flag)
        {
        printf("FreeDOS Editor\tVersion 0.5.\n\n"
               "Syntax: EDIT [/B] [/H] [/?] [file(s)]\n"
               "  /B     Forces monochrome mode\n"
               "  /H     Displays the maximum number of lines possible for your hardware\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;

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

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

	/*  Load the files from args - if the file does not exist, open a new
        window.... */
	while (argc > 1)
        {
        /*  Check if the file exists... */
        if ((fp = fopen(fileargs[1],"r")) == NULL)
            {
            NewFile(wnd,fileargs[1]);
            }
		else
            PadWindow(wnd, fileargs[1]);

    	--argc;
		argv++;
        }

    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[64];
    char *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_DELETEFILE:
		    DeleteFile(inFocus);
		    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;
				case ID_CALENDAR:
/*                    Calendar(hwnd); */
					return TRUE;
		case ID_ABOUT:
		    MessageBox(
             "About FreeDOS Edit",
			"   谀哪哪哪哪哪哪哪哪哪哪哪縗n"
			"   

⌨️ 快捷键说明

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