117 lines
2.2 KiB
C
117 lines
2.2 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <proto/exec.h>
|
|
#include <proto/dos.h>
|
|
#include <proto/intuition.h>
|
|
#include <proto/window.h>
|
|
#include <proto/layout.h>
|
|
#include <proto/texteditor.h>
|
|
|
|
#include <reaction/reaction_macros.h>
|
|
|
|
#include <classes/window.h>
|
|
|
|
#include <gadgets/texteditor.h>
|
|
|
|
#include "phed-init.h"
|
|
#include "phed-file.h"
|
|
|
|
const char *version = "$VER: phED Version 0.1";
|
|
|
|
enum
|
|
{
|
|
GID_TEXTEDITOR = 0,
|
|
GID_LAST
|
|
};
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
struct Window *window;
|
|
struct Gadget *gadgets[GID_LAST];
|
|
|
|
Object *Win_Object;
|
|
|
|
ULONG signal, result;
|
|
ULONG done = FALSE;
|
|
|
|
APTR text;
|
|
|
|
char *buf;
|
|
|
|
if(argc > 0)
|
|
{
|
|
buf = loadText(argv[1]);
|
|
|
|
text = &buf;
|
|
}
|
|
|
|
if(openLibraries())
|
|
{
|
|
Win_Object = WindowObject,
|
|
WA_ScreenTitle, "Projekt Hirnfrei",
|
|
WA_Title, "phED",
|
|
WA_SizeGadget, TRUE,
|
|
WA_DepthGadget, TRUE,
|
|
WA_DragBar, TRUE,
|
|
WA_CloseGadget, TRUE,
|
|
WA_Activate, TRUE,
|
|
WA_Width, 400,
|
|
WA_Height, 400,
|
|
WINDOW_ParentGroup, HGroupObject,
|
|
StartVGroup,
|
|
StartMember, gadgets[GID_TEXTEDITOR] = TextEditorObject,
|
|
GA_ID, GID_TEXTEDITOR,
|
|
GA_RelVerify, TRUE,
|
|
GA_TEXTEDITOR_Contents, (APTR) buf,
|
|
EndMember,
|
|
End,
|
|
EndMember,
|
|
EndWindow;
|
|
|
|
if(Win_Object)
|
|
{
|
|
if(window = (struct Window *) RA_OpenWindow(Win_Object))
|
|
{
|
|
ULONG wait, changed;
|
|
UBYTE *buffer;
|
|
|
|
GetAttr(WINDOW_SigMask, Win_Object, &signal);
|
|
|
|
while(!done)
|
|
{
|
|
wait = Wait(signal|SIGBREAKF_CTRL_C);
|
|
|
|
if(wait & SIGBREAKF_CTRL_C) done = TRUE;
|
|
else
|
|
{
|
|
while((result = RA_HandleInput(Win_Object, NULL)) != WMHI_LASTMSG)
|
|
{
|
|
switch(result)
|
|
{
|
|
case WMHI_CLOSEWINDOW:
|
|
GetAttr(GA_TEXTEDITOR_HasChanged, gadgets[GID_TEXTEDITOR], &changed);
|
|
|
|
if(changed)
|
|
{
|
|
buffer = (UBYTE *) DoGadgetMethod(gadgets[GID_TEXTEDITOR], window, NULL, GM_TEXTEDITOR_ExportText, NULL);
|
|
|
|
if(!argv[1]) saveText("unbenannt.txt", buffer);
|
|
else saveText(argv[1], buffer);
|
|
}
|
|
|
|
done = TRUE;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
DisposeObject(Win_Object);
|
|
}
|
|
}
|
|
closeLibraries();
|
|
|
|
if(buf) free(buf);
|
|
} |