home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magazyn Amiga Shareware Floppies
/
ma15.dms
/
ma15.adf
/
Yak
/
Source
/
convert.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-17
|
5KB
|
221 lines
/****************************************************************************
* Convert Yak 1.4 settings files to Yak 1.5 settings files.
*
* Read 1.4 yak.prefs, write 1.5 yak.prefs and yak.hotkeys,
* rename old yak.prefs as yak.prefs.old.
*
* Martin W Scott, 14 May 1993.
****************************************************************************/
#include <exec/types.h>
#include <dos/dos.h>
#include <intuition/intuition.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <string.h>
#include <stdarg.h>
#include "yak.h"
#include "hotkey_types.h"
struct IntuitionBase *IntuitionBase;
static void
CloseResources(void)
{
if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
}
static BOOL
OpenResources(void)
{
if (IntuitionBase = (void *)OpenLibrary("intuition.library", 37L))
return TRUE;
return FALSE;
}
/* simple requester with args */
void
PostError(char *body, ... )
{
struct EasyStruct es;
va_list args;
if (!IntuitionBase)
{
Write(Output(), "Need AmigaDos 2.0+\n", -1);
return;
}
/* setup the argument array */
va_start( args, body );
/* initialise the structure */
es.es_StructSize = sizeof(struct EasyStruct);
es.es_Flags = 0L;
es.es_Title = "Yak Message";
es.es_TextFormat = body;
es.es_GadgetFormat = "OK";
/* display the requester */
EasyRequestArgs(NULL, &es, NULL, args);
/* free the arguments */
va_end( args );
}
/* write a LONG to a file (in binary format) - returns success*/
static BOOL __regargs
FWriteLong(BPTR fh, LONG n)
{
return (BOOL)(FWrite(fh, (UBYTE *)&n, sizeof(LONG), 1) == 1);
}
/* read a LONG to a file (in binary format) - returns success */
static BOOL __regargs
FReadLong(BPTR fh, LONG *n)
{
return (BOOL)(FRead(fh, (UBYTE *)n, sizeof(LONG), 1) == 1);
}
/* write a string to a file (in binary format) - returns success*/
/* '\n' is appended */
static BOOL __regargs
FWriteString(BPTR fh, char *buf)
{
FPuts(fh, buf);
FPutC(fh, '\n');
return (BOOL)(IoErr() == 0);
}
/* read a string to a file (in binary format) - returns success */
/* '\n' is stripped and buf null-terminated; assumes dest large enough */
static BOOL __regargs
FReadString(BPTR fh, char *buf, LONG len)
{
FGets(fh, buf, len-1);
buf[strlen(buf)-1] = '\0'; /* '\n' --> '\0' */
return (BOOL)(IoErr() == 0);
}
#define OLD_CONFIG_ID 0x594b3133 /* YK13 */
#define NEW_CONFIG_ID 0x594b3135 /* YK15 */
#define HOTKEY_ID 0x594B4B31 /* 'YKK1' */
UWORD convtab[] = {
SHOW_INTERFACE, CLOSE_WINDOW, ZIP_WINDOW, SHRINK_WINDOW,
EXPAND_WINDOW, ACTIVATE_WORKBENCH, OPEN_PALETTE, DOS_COMMAND,
INSERT_DATE, CYCLE_WINDOWS, SCREEN_TO_FRONT, CENTRE_SCREEN,
SCREEN_TO_BACK, BLANK_DISPLAY
};
void
DoConvert(void)
{
BPTR inprefs, outprefs, outkeys;
LONG n, i;
UWORD type, opts;
BOOL boolboy;
char buf[256];
if (inprefs = Open("S:Yak.prefs", MODE_OLDFILE))
{
if (outprefs = Open("S:Yak.prefs.new", MODE_NEWFILE))
{
if (outkeys = Open("S:Yak.hotkeys", MODE_NEWFILE))
{
FReadLong(inprefs, &n);
if (n == OLD_CONFIG_ID)
{
FWriteLong(outprefs, NEW_CONFIG_ID);
FWriteLong(outkeys, HOTKEY_ID);
/* TOGGLES */
FReadLong(inprefs, &n);
FWriteLong(outprefs, n);
for (i = 0; i < n; i++)
{
FRead(inprefs, (UBYTE *)&boolboy, sizeof(BOOL), 1);
FWrite(outprefs, (UBYTE *)&boolboy, sizeof(BOOL), 1);
}
/* HOTKEYS */
FReadLong(inprefs, &n);
FWriteLong(outkeys, n);
for (i = 0; i < n; i++)
{
FReadString(inprefs, buf, 256);
type = convtab[i]; opts = 0;
FWrite(outkeys, (UBYTE *)&type, sizeof(UWORD), 1);
FWrite(outkeys, (UBYTE *)&opts, sizeof(UWORD), 1);
FWriteString(outkeys, buf);
FWriteString(outkeys, "");
}
/* PATTERNS */
FReadLong(inprefs, &n);
FWriteLong(outprefs, n);
for (i = 0; i < n; i++)
{
FReadString(inprefs, buf, 256);
FWriteString(outprefs, buf);
}
/* POPKEY */
FReadString(inprefs, buf, 256);
/* DATE FORMAT */
FReadString(inprefs, buf, 256);
/* CLICK VOLUME */
FReadLong(inprefs, &n);
FWriteLong(outprefs, n);
/* BLANK SECS */
FReadLong(inprefs, &n);
FWriteLong(outprefs, n);
/* MBLANK SECS */
if (!FReadLong(inprefs, &n))
n = 5;
FWriteLong(outprefs, n);
/* MBLANK METHOD */
if (!FReadLong(inprefs, &n))
n = MB_SPRITES;
FWriteLong(outprefs, n);
Close(inprefs);
Close(outprefs);
Close(outkeys);
Rename("S:Yak.prefs", "S:Yak.prefs.old");
Rename("S:Yak.prefs.new", "S:Yak.prefs");
PostError("Wrote new Yak.prefs file and Yak.hotkeys file.\nOld preferences file is S:Yak.prefs.old.");
return;
}
PostError("Invalid existing Yak.prefs file");
Close(outkeys);
}
else PostError("Can't create Yak.hotkeys file");
Close(outprefs);
}
else PostError("Can't create Yak.prefs.new file");
Close(inprefs);
}
else PostError("Can't open existing Yak.prefs file");
}
void
__main(void)
{
if (OpenResources())
{
DoConvert();
CloseResources();
}
} /* main */