home *** CD-ROM | disk | FTP | other *** search
- /*
- * Convert Yak 1.3-5 settings files to Yak 2.0 settings file.
- *
- * Read 1.3-5 yak.prefs & 1.5 yak.hotkeys
- * Write ENV:yak.prefs
- *
- * Ph. Bastiani, 8/10/94.
- *
- */
-
- #define __USE_SYSBASE
-
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <dos/dos.h>
- #include <dos/dostags.h>
- #include <intuition/intuition.h>
- #include <libraries/commodities.h>
- #include <libraries/locale.h>
- #include <libraries/iffparse.h>
- #include <workbench/startup.h>
-
- #include <proto/exec.h>
- #include <proto/commodities.h>
- #include <proto/dos.h>
- #include <proto/intuition.h>
- #include <proto/locale.h>
- #include <proto/iffparse.h>
- #include <proto/wb.h>
-
- #include <string.h>
- #include <stdarg.h>
-
- #include "code.h"
- #include "yak.h"
- #include "handlers.h"
- #include "hotkey_types.h"
- #include "hotkey_naming.h"
- #include "icon.h"
- #include "Settings.h"
-
- #define CATCOMP_BLOCK
- #define CATCOMP_NUMBERS
- #include "yak_locale_strings.h"
- #undef CATCOMP_BLOCK
-
- extern struct WBStartup *WBMsg;
- extern void AutomaticNaming (YakHotKey *yhk);
-
- #ifdef _DCC
- extern struct ExecBase *SysBase;
- extern struct DosLibrary *DOSBase;
-
- struct IntuitionBase *IntuitionBase;
-
- /* global data - library bases and the like */
- struct Library *IFFParseBase;
- struct Library *CxBase;
-
- #endif
-
- static char *DefaultAREXXPort="AREXX";
-
- static char *ProgramName=NULL;
-
- #define CONFIG_ID13 0x594b3133 /* YK13 */
- #define CONFIG_ID15 0x594b3135 /* YK15 */
- #define HOTKEY_ID15 0x594B4B31 /* YKK1 */
-
-
- /*
- * Old types of hotkey currently supported
- */
- #define OLD15_DOS_COMMAND 0
- #define OLD15_CLOSE_WINDOW 1
- #define OLD15_ZIP_WINDOW 2
- #define OLD15_SHRINK_WINDOW 3
- #define OLD15_EXPAND_WINDOW 4
- #define OLD15_CYCLE_WINDOWS 5
- #define OLD15_OPEN_PALETTE 6
- #define OLD15_SCREEN_TO_FRONT 7
- #define OLD15_SCREEN_TO_BACK 8
- #define OLD15_ACTIVATE_WORKBENCH 9
- #define OLD15_CENTRE_SCREEN 10
- #define OLD15_BLANK_DISPLAY 11
- #define OLD15_INSERT_TEXT 12
- #define OLD15_INSERT_DATE 13
- #define OLD15_SHOW_INTERFACE 14
- #define OLD15_BACK_CYCLE_WINDOWS 15
- #define OLD15_SET_DEF_PUB_SCREEN 16
- #define OLD15_MENU_SHORTCUT 17
- #define OLD15_NUM_HOTKEY_TYPES 18
-
- #define OLD13_SHOW_INTERFACE 0
- #define OLD13_CLOSE_WINDOW 1
- #define OLD13_ZIP_WINDOW 2
- #define OLD13_SHRINK_WINDOW 3
- #define OLD13_EXPAND_WINDOW 4
- #define OLD13_ACTIVATE_WORKBENCH 5
- #define OLD13_OPEN_PALETTE 6
- #define OLD13_DOS_COMMAND 7
- #define OLD13_INSERT_DATE 8
- #define OLD13_CYCLE_WINDOWS 9
- #define OLD13_SCREEN_TO_FRONT 10
- #define OLD13_CENTRE_SCREEN 11
- #define OLD13_SCREEN_TO_BACK 12
- #define OLD13_BLANK_DISPLAY 13
- #define OLD13_NUM_HOTKEY_TYPES 14
-
-
-
- static BOOL OldScreenCycling; /* temporary variable */
-
- BOOL *convtog[] = {
- &Window_To_Front.State,
- &Window_To_Back.State,
- &autopoint,
- &keyactivate,
- &OldScreenCycling,
- &autopop,
- &rmbactivate,
- NULL, /* OBSOLETE */
- NULL, /* OBSOLETE */
- &wildstar,
- &scractivate,
- &noclick,
- &mmbactivate,
- &blackborder,
- &blankmouseonkey,
- &mmbshift,
- &unixdirs
- };
-
- STRPTR convpat[] = {
- patterns[0].patstr,
- Window_To_Front.ScreenPatternData.patstr,
- patterns[1].patstr,
- NULL
- };
-
-
-
- UWORD conv13act[] = {
- SHOW_INTERFACE,
- CLOSE_WINDOW,
- ZIP_WINDOW,
- SHRINK_WINDOW,
- EXPAND_WINDOW,
- ACTIVATE_WORKBENCH,
- OPEN_PALETTE,
- EXECUTE_COMMAND,
- INSERT_DATE,
- CYCLE_WINDOWS,
- SCREEN_TO_FRONT,
- CENTRE_SCREEN,
- SCREEN_TO_BACK,
- BLANK_DISPLAY
- };
-
- UWORD conv15act[] = {
- EXECUTE_COMMAND,
- CLOSE_WINDOW,
- ZIP_WINDOW,
- SHRINK_WINDOW,
- EXPAND_WINDOW,
- CYCLE_WINDOWS,
- OPEN_PALETTE,
- SCREEN_TO_FRONT,
- SCREEN_TO_BACK,
- ACTIVATE_WORKBENCH,
- CENTRE_SCREEN,
- BLANK_DISPLAY,
- INSERT_TEXT,
- INSERT_DATE,
- SHOW_INTERFACE,
- CYCLE_WINDOWS,
- SET_DEF_PUB_SCREEN,
- MENU_SHORTCUT
- };
-
-
-
-
- /* close what we opened */
- static void
- CloseResources(void)
- {
- FreeOurIcon(); /* may already be gone, but so what? */
-
- if (ProgramName) FreeVec(ProgramName);
-
- /* NULL pointers are valide so don't waste time to test them */
- CloseLibrary((struct Library *)IntuitionBase);
- CloseLibrary(IFFParseBase);
- CloseLibrary(CxBase);
- CloseLocaleStuff();
- }
-
- /* open libraries, devices that we need */
- static BOOL
- OpenResources(void)
- {
- if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37L)) &&
- (IFFParseBase = OpenLibrary("iffparse.library", 37L)) &&
- (CxBase = OpenLibrary("commodities.library",36L)))
- {
- return TRUE;
- }
- CloseResources();
- return FALSE;
- }
-
-
-
- /* simple requester with args */
- void
- PostError(char *body, ... )
- {
- struct EasyStruct es;
- va_list args;
-
- /* 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 Convert";
- es.es_TextFormat = body;
- es.es_GadgetFormat = "OK";
-
- /* display the requester */
- EasyRequestArgs(NULL, &es, NULL, args);
-
- /* free the arguments */
- va_end( args );
- }
-
-
- static __regargs BOOL
- FReadLong(BPTR fh, LONG *n)
- {
- return (BOOL)(FRead(fh, (UBYTE *)n, sizeof(LONG), 1) == 1);
- }
-
- static __regargs BOOL
- FReadString(BPTR fh, char *buf, LONG len)
- {
- FGets(fh, buf, len-1);
- buf[strlen(buf)-1] = '\0'; /* '\n' --> '\0' */
- return (BOOL)(IoErr() == 0);
- }
-
-
-
- /*
- * This function scans integers in a string
- * It returns the number of integers found.
- * Max, is the maxumum number of integers to find to avoid writing beyond the limit
- * of the array
- */
-
- static UBYTE
- ScanInt( char *str, UBYTE Max, int *array )
- {
- int i;
- UBYTE n = 0;
- BYTE neg;
- BOOL new_token;
-
- while ((*str != '\0') && (n < Max))
- {
- while (*str == ' ')
- ++str;
-
- if (*str == '-')
- {
- ++str;
- neg = 1;
- }
- else
- {
- neg = 0;
- }
-
- i = 0;
-
- new_token = (*str >= '0' && *str <= '9');
-
- while (*str >= '0' && *str <= '9')
- i = (i << 1) + (i << 3) + *str++ - '0';
-
- if (new_token)
- {
- array[n] = (int)((neg)?-i:i);
- n++;
- }
-
- if (*str != '\0')
- ++str;
- }
- return(n);
- }
-
-
-
-
-
- /* Load old settings */
- void
- LoadOldSettings(void)
- {
- BPTR inconf, inkeys;
- LONG ID, n, i;
- BOOL boolboy;
- UWORD type, opts;
- char keydef[512];
- char keyarg[512];
- char pat[PATLEN+1], buf[256];
- LONG num;
- YakHotKey *yhk;
- YakHotKey *datehk, *doshk;
-
- /* First: set default values */
- SetDefaultSettings();
-
- if (inconf=Open("S:Yak.prefs", MODE_OLDFILE))
- {
-
- FReadLong(inconf, &ID);
- if ( (ID == CONFIG_ID13) || (ID == CONFIG_ID15) )
- {
- /* TOGGLES */
- FReadLong(inconf, &n);
- for (i = 0; i < n; i++)
- {
- FRead(inconf, (UBYTE *)&boolboy, sizeof(BOOL), 1);
- if (convtog[i])
- *convtog[i] = boolboy;
- }
-
- if (OldScreenCycling)
- {
- Window_To_Front.Options |= Opt_ScreenToFront;
- Window_To_Back.Options |= Opt_ScreenToBack;
- }
- else
- {
- Window_To_Front.Options &= ~Opt_ScreenToFront;
- Window_To_Back.Options &= ~Opt_ScreenToBack;
- }
-
- /* HOTKEYS */
- if (ID == CONFIG_ID13)
- {
- inkeys = inconf;
- FReadLong(inkeys, &n);
- for (i = 0; i < n; i++)
- {
- type = i;
- FReadString(inkeys, keydef, 256);
-
- if (yhk = NewYakHotKey(conv13act[type]))
- {
- yhk->yhk_State = YKHK_ACTIVE;
-
- ModifyYHKKeyDef(yhk, keydef);
-
- /* No arguments , no options*/
- DefaultOptions(yhk);
-
- if (type == OLD13_CENTRE_SCREEN)
- yhk->yhk_Option[1].Flags = HKO_MOVE_HORIZONTAL_CENTER|HKO_NO_VERTICAL_MOVING;
-
- if (type == OLD13_DOS_COMMAND)
- doshk = yhk;
-
- if (type == OLD13_INSERT_DATE)
- datehk = yhk;
-
- AutomaticNaming (yhk);
- }
- }
-
- }
- else /* CONFIG_ID15 */
- {
- if (inkeys=Open("S:Yak.hotkeys", MODE_OLDFILE))
- {
- FReadLong(inkeys, &n);
- if (n == HOTKEY_ID15)
- {
- FReadLong(inkeys, &n);
- for (i = 0; i < n; i++)
- {
- FRead(inkeys, (UBYTE *)&type, sizeof(UWORD), 1);
- FRead(inkeys, (UBYTE *)&opts, sizeof(UWORD), 1);
- FReadString(inkeys, keydef, 512);
- FReadString(inkeys, keyarg, 512);
-
- if (yhk = NewYakHotKey(conv15act[type]))
- {
- yhk->yhk_State = YKHK_ACTIVE;
-
- ModifyYHKKeyDef(yhk, keydef);
-
- DefaultOptions(yhk);
-
- if(yhktypes[yhk->yhk_Type].yhkt_OptsList[0].Desc == ChangeScreenHKOption)
- {
- yhk->yhk_Option[0].Flags = (1<<opts);
- }
-
- if (type == OLD15_BACK_CYCLE_WINDOWS)
- {
- yhk->yhk_Option[1].Flags = HKO_BACK_CYCLE;
- }
-
- if (type == OLD15_CENTRE_SCREEN)
- yhk->yhk_Option[1].Flags = HKO_MOVE_HORIZONTAL_CENTER|HKO_NO_VERTICAL_MOVING;
-
- if (*keyarg)
- {
- switch(type)
- {
- case OLD15_DOS_COMMAND:
- if (((keyarg[0]=='r') || (keyarg[0]=='R')) &&
- ((keyarg[1]=='x') || (keyarg[1]=='X')) &&
- ((keyarg[2]==' ')))
- {
- /* AREXX command */
- yhk->yhk_Option[1].Flags = HKO_AREXX_COMMAND|HKO_AREXX_PORT|HKO_COMMAND;
- yhk->yhk_Option[1].ArgStr[0] = DupStr(&keyarg[3]);
- yhk->yhk_Option[1].ArgStr[1] = DupStr(DefaultAREXXPort);
- }
- else
- {
- /* DOS Command */
- yhk->yhk_Option[1].Flags = HKO_CLI_COMMAND|HKO_COMMAND|HKO_STACK_COMMAND|HKO_PRIORITY_COMMAND;
- yhk->yhk_Option[1].ArgStr[0] = DupStr(keyarg);
- }
- break;
-
- case OLD15_INSERT_TEXT:
- yhk->yhk_Option[0].ArgStr[0] = DupStr(keyarg);
- yhk->yhk_Option[0].Flags = HKO_INSERT_STRING;
- break;
-
- case OLD15_INSERT_DATE:
- yhk->yhk_Option[0].ArgStr[0] = DupStr(keyarg);
- yhk->yhk_Option[0].Flags = HKO_DATE_FORMAT;
- break;
-
- case OLD15_MENU_SHORTCUT:
- if (ScanInt(keyarg, 3, (int *)yhk->yhk_Option[0].ArgNum) == 3)
- yhk->yhk_Option[0].Flags |= (HKO_SUBITEM|HKO_SUBITEM_NUMBER);
- break;
- }
- }
- AutomaticNaming (yhk);
- }
- }
- }
- else
- PostError(getString(Invalid_existing_file_ERR), "S:Yak.hotkeys");
-
- Close(inkeys);
- }
- }
-
- /* PATTERNS */
- FReadLong(inconf, &n);
- for (i = 0; i < n; i++)
- {
- FReadString(inconf, pat, PATLEN+1);
- if (convpat[i])
- {
- strncpy(convpat[i], pat, PATLEN);
- convpat[i][PATLEN] = '\0';
- }
- else
- {
- /* ClickWindows : OBSOLETE */
- if (strcmp("~(Workbench)", pat))
- {
- Window_To_Front.Options &= ~Opt_ExcludeWbWindow;
- }
- else
- {
- Window_To_Front.Options |= Opt_ExcludeWbWindow;
- }
- }
-
- }
- strcpy(Window_To_Back.ScreenPatternData.patstr, Window_To_Front.ScreenPatternData.patstr);
-
- if (ID == CONFIG_ID13)
- {
- /* POPCOMMAND */
- FReadString(inconf, buf, 256);
- doshk->yhk_Option[1].ArgStr[0] = DupStr(buf);
- doshk->yhk_Option[1].Flags = HKO_CLI_COMMAND|HKO_COMMAND|HKO_STACK_COMMAND|HKO_PRIORITY_COMMAND;
-
- /* DATE FORMAT */
- FReadString(inconf, buf, 256);
- datehk->yhk_Option[1].ArgStr[0] = DupStr(buf);
- datehk->yhk_Option[1].Flags = HKO_DATE_FORMAT;
- }
-
- /* CLICK VOLUME */
- if (FReadLong(inconf, &num))
- click_volume = num;
-
- /* BLANK SECS */
- if (FReadLong(inconf, &num))
- blanksecs = num;
-
- /* MBLANK SECS */
- if (FReadLong(inconf, &num))
- mblanksecs = num;
-
- /* MBLANK METHOD */
- if (FReadLong(inconf, &num))
- mouseblank = num;
-
- /* AUTOPOINT DELAY */
- if (FReadLong(inconf, &num))
- autopoint_delay = num;
- }
- else
- PostError(getString(Invalid_existing_file_ERR), "S:Yak.prefs");
-
- Close(inconf);
- }
- else
- PostError("%s S:Yak.prefs", getString(Opening_prefs_file_ERR));
- }
-
-
- #ifdef _DCC
- void _waitwbmsg(void);
- static void
- uncalled(void)
- {
- _waitwbmsg();
- }
- #endif
-
- #define DEF_CURRENTDIR "SYS:"
-
- void
- MAIN(void)
- {
- BPTR newdir=NULL, olddir;
-
- if (OpenResources())
- {
- if (WBMsg) /* WB Startup */
- {
- struct WBArg *wbarg=&WBMsg->sm_ArgList[0];
-
- /* Get Program Name */
- if (ProgramName=AllocVec(256, MEMF_CLEAR))
- {
- BPTR lock=GetProgramDir();
- if (NameFromLock(lock, ProgramName, 256))
- AddPart(ProgramName, wbarg->wa_Name, 256);
- }
-
- /* Current Directory */
- if (newdir = Lock(DEF_CURRENTDIR, ACCESS_READ))
- olddir = CurrentDir(newdir);
- }
- else /* CLI Startup */
- {
- /* Get Program Name */
- if (ProgramName=AllocVec(256, MEMF_CLEAR))
- GetProgramName(ProgramName, 256);
- }
-
- /* process tool-types */
- GetOurIcon(ProgramName);
-
- /* Open the right locale if tooltype LANGUAGE is used */
- OpenLocaleStuff(TTString("LANGUAGE",NULL));
-
- PostError(getString(About_Convert_STRING));
-
- InitYakHotKeyList();
-
- LoadOldSettings();
-
- /* Kill old running Yak so that it doesn't interefre with new prefs */
- BrokerCommand("Yak", CXCMD_KILL);
-
- SaveSettings(ENVARC_CONFIG_FILE);
-
- CopyFile(ENVARC_CONFIG_FILE, ENV_CONFIG_FILE);
-
- DeleteYakHotKeyList();
-
- if (newdir)
- {
- CurrentDir(olddir);
- UnLock(newdir);
- }
-
- CloseResources();
- }
- }
-