home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d8xx / d832 / term.lha / Term / term-3.1-Source.lha / termConfig.c < prev    next >
C/C++ Source or Header  |  1993-02-18  |  43KB  |  1,926 lines

  1. /*
  2. **    termConfig.c
  3. **
  4. **    Configuration processing routines
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* Number of chunks to stop at. */
  13.  
  14. #define    NUM_STOPS    16
  15.  
  16.     /* Reset routine function pointer. */
  17.  
  18. typedef VOID        (* RESET)(APTR,STRPTR);
  19.  
  20.     /* Local routines. */
  21.  
  22. STATIC BYTE        ReadSerialPrefs(struct SerialPrefs *Prefs);
  23.  
  24. STATIC VOID        ResetSerialConfig(struct SerialSettings *SerialConfig);
  25. STATIC VOID        ResetModem(struct ModemSettings *ModemConfig);
  26. STATIC VOID        ResetScreen(struct ScreenSettings *ScreenConfig);
  27. STATIC VOID        ResetTerminal(struct TerminalSettings *TerminalConfig);
  28. STATIC VOID        ResetEmulation(struct EmulationSettings *EmulationConfig);
  29. STATIC VOID        ResetClip(struct ClipSettings *ClipConfig);
  30. STATIC VOID        ResetCapture(struct CaptureSettings *CaptureConfig);
  31. STATIC VOID        ResetFile(struct FileSettings *FileConfig,STRPTR PathBuffer);
  32. STATIC VOID        ResetPath(struct PathSettings *PathConfig,STRPTR PathBuffer);
  33. STATIC VOID        ResetMisc(struct MiscSettings *MiscConfig);
  34. STATIC VOID        ResetCommand(struct CommandSettings *CommandConfig);
  35.  
  36. STATIC BYTE        WriteConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,BYTE Type,APTR TempBuffer,STRPTR Password);
  37. STATIC BYTE        WriteConfigChunks(struct IFFHandle *Handle,struct Configuration *Config,APTR TempBuffer,STRPTR Password);
  38. STATIC UBYTE        IsConfigChunk(ULONG ID);
  39. STATIC BYTE        ReadConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,UBYTE Type,LONG Len,STRPTR Password);
  40.  
  41. STATIC UWORD SizeTable[] =
  42. {
  43.     sizeof(struct SerialSettings),
  44.     sizeof(struct ModemSettings),
  45.     sizeof(struct CommandSettings),
  46.     sizeof(struct ScreenSettings),
  47.     sizeof(struct TerminalSettings),
  48.     sizeof(struct PathSettings),
  49.     sizeof(struct MiscSettings),
  50.     sizeof(struct ClipSettings),
  51.     sizeof(struct CaptureSettings),
  52.     sizeof(struct FileSettings),
  53.     sizeof(struct EmulationSettings)
  54. };
  55.  
  56. STATIC RESET ResetTable[] =
  57. {
  58.     (RESET)ResetSerialConfig,
  59.     (RESET)ResetModem,
  60.     (RESET)ResetCommand,
  61.     (RESET)ResetScreen,
  62.     (RESET)ResetTerminal,
  63.     ResetPath,
  64.     (RESET)ResetMisc,
  65.     (RESET)ResetClip,
  66.     (RESET)ResetCapture,
  67.     ResetFile,
  68.     (RESET)ResetEmulation
  69. };
  70.  
  71. STATIC ULONG TypeTable[] =
  72. {
  73.     ID_SERL,
  74.     ID_MODM,
  75.     ID_COMD,
  76.     ID_SCRN,
  77.     ID_TRML,
  78.     ID_PATH,
  79.     ID_MISC,
  80.     ID_CLIP,
  81.     ID_CPTR,
  82.     ID_FILE,
  83.     ID_EMLN
  84. };
  85.  
  86. STATIC ULONG Stops[NUM_STOPS * 2] =
  87. {
  88.     ID_TERM,ID_VERS,
  89.     ID_TERM,ID_DIAL,
  90.     ID_TERM,ID_DATE,
  91.     ID_TERM,ID_PHON,
  92.     ID_TERM,ID_PSWD,
  93.  
  94.     ID_TERM,ID_SERL,
  95.     ID_TERM,ID_MODM,
  96.     ID_TERM,ID_COMD,
  97.     ID_TERM,ID_SCRN,
  98.     ID_TERM,ID_TRML,
  99.     ID_TERM,ID_PATH,
  100.     ID_TERM,ID_MISC,
  101.     ID_TERM,ID_CLIP,
  102.     ID_TERM,ID_CPTR,
  103.     ID_TERM,ID_FILE,
  104.     ID_TERM,ID_EMLN
  105. };
  106.  
  107.     /* ReadSerialPrefs():
  108.      *
  109.      *    Reads the default serial preferences settings.
  110.      */
  111.  
  112. STATIC BYTE
  113. ReadSerialPrefs(struct SerialPrefs *Prefs)
  114. {
  115.     struct IFFHandle    *Handle;
  116.     BYTE             Success = FALSE;
  117.  
  118.         /* Allocate an IFF handle. */
  119.  
  120.     if(Handle = AllocIFF())
  121.     {
  122.             /* Open the preferences settings file. */
  123.  
  124.         if(Handle -> iff_Stream = Open("ENV:sys/serial.prefs",MODE_OLDFILE))
  125.         {
  126.                 /* Make it known as a DOS file handle. */
  127.  
  128.             InitIFFasDOS(Handle);
  129.  
  130.                 /* Open the file for reading. */
  131.  
  132.             if(!OpenIFF(Handle,IFFF_READ))
  133.             {
  134.                     /* Stop at the `body' chunk. */
  135.  
  136.                 if(!StopChunk(Handle,ID_PREF,ID_SERL))
  137.                 {
  138.                         /* Look for it... */
  139.  
  140.                     if(!ParseIFF(Handle,IFFPARSE_SCAN))
  141.                     {
  142.                             /* Read the data. */
  143.  
  144.                         if(ReadChunkBytes(Handle,Prefs,sizeof(struct SerialPrefs)) == sizeof(struct SerialPrefs))
  145.                             Success = TRUE;
  146.                     }
  147.                 }
  148.  
  149.                     /* Close the handle. */
  150.  
  151.                 CloseIFF(Handle);
  152.             }
  153.  
  154.                 /* Release the handle. */
  155.  
  156.             Close(Handle -> iff_Stream);
  157.         }
  158.  
  159.             /* Clean up. */
  160.  
  161.         FreeIFF(Handle);
  162.     }
  163.  
  164.         /* Return sucess/failure. */
  165.  
  166.     return(Success);
  167. }
  168.  
  169. STATIC VOID
  170. ResetSerialConfig(struct SerialSettings *SerialConfig)
  171. {
  172.     STATIC BYTE            SerialPrefsRead        = FALSE,
  173.                     SerialPrefsReadFailed    = FALSE;
  174.     STATIC struct SerialPrefs    SerialPrefs;
  175.  
  176.         /* The program will only try to read the preferences
  177.          * settings once; if the first access failed, no
  178.          * other accesses will be made.
  179.          */
  180.  
  181.     if(!SerialPrefsRead && !SerialPrefsReadFailed)
  182.         SerialPrefsReadFailed = ReadSerialPrefs(&SerialPrefs) ^ TRUE;
  183.  
  184.         /* Did we succeed in reading the file? */
  185.  
  186.     if(!SerialPrefsRead)
  187.     {
  188.         SerialConfig -> BaudRate        = 2400;
  189.         SerialConfig -> BitsPerChar        = 8;
  190.         SerialConfig -> Parity            = PARITY_NONE;
  191.         SerialConfig -> StopBits        = 1;
  192.         SerialConfig -> HandshakingProtocol    = HANDSHAKING_NONE;
  193.         SerialConfig -> xONxOFF            = TRUE;
  194.         SerialConfig -> SerialBufferSize    = 32768;
  195.     }
  196.     else
  197.     {
  198.             /* Fill in the common data. */
  199.  
  200.         SerialConfig -> BaudRate        = SerialPrefs . sp_BaudRate;
  201.         SerialConfig -> SerialBufferSize    = SerialPrefs . sp_InputBuffer;
  202.         SerialConfig -> BitsPerChar        = SerialPrefs . sp_BitsPerChar;
  203.         SerialConfig -> StopBits        = SerialPrefs . sp_StopBits;
  204.  
  205.             /* Convert the handshaking mode. */
  206.  
  207.         switch(SerialPrefs . sp_InputHandshake)
  208.         {
  209.             case HSHAKE_NONE:
  210.  
  211.                 SerialConfig -> HandshakingProtocol    = HANDSHAKING_NONE;
  212.                 SerialConfig -> xONxOFF            = FALSE;
  213.  
  214.                 break;
  215.  
  216.             case HSHAKE_RTS:
  217.  
  218.                 SerialConfig -> HandshakingProtocol    = HANDSHAKING_RTSCTS;
  219.                 SerialConfig -> xONxOFF            = FALSE;
  220.  
  221.                 break;
  222.  
  223.             default:
  224.  
  225.                 SerialConfig -> HandshakingProtocol    = HANDSHAKING_NONE;
  226.                 SerialConfig -> xONxOFF            = TRUE;
  227.  
  228.                 break;
  229.         }
  230.  
  231.             /* Convert the parity settings. */
  232.  
  233.         if(SerialPrefs . sp_Parity <= PARITY_SPACE)
  234.             SerialConfig -> Parity = SerialPrefs . sp_Parity;
  235.         else
  236.             SerialConfig -> Parity = PARITY_NONE;
  237.     }
  238.  
  239.     strcpy(SerialConfig -> SerialDevice,SERIALNAME);
  240.  
  241.     SerialConfig -> Duplex        = DUPLEX_FULL;
  242.     SerialConfig -> HighSpeed    = FALSE;
  243.     SerialConfig -> Shared        = FALSE;
  244.     SerialConfig -> BreakLength    = 250000;
  245.     SerialConfig -> UnitNumber    = 0;
  246.     SerialConfig -> StripBit8    = FALSE;
  247.     SerialConfig -> CheckCarrier    = FALSE;
  248.     SerialConfig -> PassThrough    = FALSE;
  249. }
  250.  
  251. STATIC VOID
  252. ResetModem(struct ModemSettings *ModemConfig)
  253. {
  254.     strcpy(ModemConfig -> ModemInit,    "ATZ\\r");
  255.     strcpy(ModemConfig -> ModemExit,    "");
  256.     strcpy(ModemConfig -> ModemHangup,    "~~~~~~~~+++\\r~~~~~~ATH0\\r");
  257.     strcpy(ModemConfig -> DialPrefix,    "~~ATDP");
  258.     strcpy(ModemConfig -> DialSuffix,    "\\r");
  259.  
  260.     strcpy(ModemConfig -> NoCarrier,    "NO CARRIER");
  261.     strcpy(ModemConfig -> NoDialTone,    "NO DIALTONE");
  262.     strcpy(ModemConfig -> Connect,        "CONNECT");
  263.     strcpy(ModemConfig -> Voice,        "VOICE");
  264.     strcpy(ModemConfig -> Ring,        "RING");
  265.     strcpy(ModemConfig -> Busy,        "BUSY");
  266.  
  267.     ModemConfig -> RedialDelay        = 2;
  268.     ModemConfig -> DialRetries        = 10;
  269.     ModemConfig -> DialTimeout        = 60;
  270.     ModemConfig -> ConnectAutoBaud        = FALSE;
  271.     ModemConfig -> DropDTR            = FALSE;
  272.     ModemConfig -> RedialAfterHangup    = FALSE;
  273. }
  274.  
  275. STATIC VOID
  276. ResetScreen(struct ScreenSettings *ScreenConfig)
  277. {
  278.     ScreenConfig -> DisplayMode        = DEFAULT_MONITOR_ID|HIRES_KEY;
  279.     ScreenConfig -> ColourMode        = COLOUR_AMIGA;
  280.     ScreenConfig -> MakeScreenPublic    = TRUE;
  281.     ScreenConfig -> ShanghaiWindows        = FALSE;
  282.     ScreenConfig -> TitleBar        = TRUE;
  283.     ScreenConfig -> StatusLine        = STATUSLINE_STANDARD;
  284.     ScreenConfig -> Blinking        = TRUE;
  285.     ScreenConfig -> FasterLayout        = FALSE;
  286.     ScreenConfig -> UseWorkbench        = FALSE;
  287.  
  288.     strcpy(ScreenConfig -> FontName,"topaz.font");
  289.     ScreenConfig -> FontHeight = 8;
  290.  
  291.     ScreenConfig -> PubScreenName[0]    = 0;
  292. }
  293.  
  294. STATIC VOID
  295. ResetTerminal(struct TerminalSettings *TerminalConfig)
  296. {
  297.     TerminalConfig -> BellMode        = BELL_AUDIBLE;
  298.     TerminalConfig -> AlertMode        = ALERT_BEEP_SCREEN;
  299.     TerminalConfig -> EmulationMode        = EMULATION_ANSIVT100;
  300.     TerminalConfig -> FontMode        = FONT_STANDARD;
  301.  
  302.     TerminalConfig -> SendCR        = CR_ASCR;
  303.     TerminalConfig -> SendLF        = LF_ASLF;
  304.     TerminalConfig -> ReceiveCR        = CR_ASCR;
  305.     TerminalConfig -> ReceiveLF        = LF_ASLF;
  306.  
  307.     TerminalConfig -> NumColumns        = 0;
  308.     TerminalConfig -> NumLines        = 0;
  309.  
  310.     TerminalConfig -> KeyMapFileName[0]    = 0;
  311.     TerminalConfig -> EmulationFileName[0]    = 0;
  312.     TerminalConfig -> BeepFileName[0]    = 0;
  313.  
  314.     strcpy(TerminalConfig -> TextFontName,"topaz.font");
  315.     TerminalConfig -> TextFontHeight = 8;
  316. }
  317.  
  318. STATIC VOID
  319. ResetEmulation(struct EmulationSettings *EmulationConfig)
  320. {
  321.     EmulationConfig -> CursorMode        = KEYMODE_STANDARD;
  322.     EmulationConfig -> NumericMode        = KEYMODE_STANDARD;
  323.  
  324.     EmulationConfig -> NewLineMode        = FALSE;
  325.     EmulationConfig -> InsertMode        = FALSE;
  326.  
  327.     EmulationConfig -> LineWrap        = TRUE;
  328.     EmulationConfig -> CursorWrap        = FALSE;
  329.  
  330.     EmulationConfig -> FontScale        = SCALE_NORMAL;
  331.     EmulationConfig -> ScrollMode        = SCROLL_JUMP;
  332.     EmulationConfig -> DestructiveBackspace    = FALSE;
  333.     EmulationConfig -> SwapBSDelete        = FALSE;
  334.     EmulationConfig -> PrinterEnabled    = TRUE;
  335.     EmulationConfig -> AnswerBack[0]    = 0;
  336. }
  337.  
  338. STATIC VOID
  339. ResetClip(struct ClipSettings *ClipConfig)
  340. {
  341.     ClipConfig -> ClipboardUnit    = 0;
  342.     ClipConfig -> LineDelay        = 0;
  343.     ClipConfig -> CharDelay        = 0;
  344.  
  345.     ClipConfig -> InsertPrefix[0] = 0;
  346.     strcpy(ClipConfig -> InsertSuffix,"\\r");
  347. }
  348.  
  349. STATIC VOID
  350. ResetCapture(struct CaptureSettings *CaptureConfig)
  351. {
  352.     CaptureConfig -> LogActions        = FALSE;
  353.     CaptureConfig -> LogCall        = FALSE;
  354.     CaptureConfig -> LogFileName[0]        = 0;
  355.  
  356.     CaptureConfig -> MaxBufferSize        = 0;
  357.     CaptureConfig -> BufferEnabled        = TRUE;
  358.  
  359.     CaptureConfig -> ConnectAutoCapture    = FALSE;
  360.     CaptureConfig -> CaptureFilterMode    = FILTER_BOTH;
  361.     CaptureConfig -> CapturePath[0]        = 0;
  362.  
  363.     CaptureConfig -> CallLogFileName[0]    = 0;
  364.     CaptureConfig -> BufferPath[0]        = 0;
  365. }
  366.  
  367. STATIC VOID
  368. ResetFile(struct FileSettings *FileConfig,STRPTR PathBuffer)
  369. {
  370.     if(!PathBuffer)
  371.         PathBuffer = "TERM:config";
  372.  
  373.     strcpy(FileConfig -> ProtocolFileName,"xprzmodem.library");
  374.  
  375.     if(!LastTranslation[0])
  376.     {
  377.         strcpy(LastTranslation,PathBuffer);
  378.  
  379.         AddPart(LastTranslation,"translation.prefs",MAX_FILENAME_LENGTH);
  380.     }
  381.  
  382.     strcpy(FileConfig -> TranslationFileName,LastTranslation);
  383.  
  384.     if(!LastMacros[0])
  385.     {
  386.         strcpy(LastMacros,PathBuffer);
  387.  
  388.         AddPart(LastMacros,"functionkeys.prefs",MAX_FILENAME_LENGTH);
  389.     }
  390.  
  391.     strcpy(FileConfig -> MacroFileName,LastMacros);
  392.  
  393.     if(!LastFastMacros[0])
  394.     {
  395.         strcpy(LastFastMacros,PathBuffer);
  396.  
  397.         AddPart(LastFastMacros,"fastmacros.prefs",MAX_FILENAME_LENGTH);
  398.     }
  399.  
  400.     strcpy(FileConfig -> FastMacroFileName,LastFastMacros);
  401.  
  402.     if(!LastCursorKeys[0])
  403.     {
  404.         strcpy(LastCursorKeys,PathBuffer);
  405.  
  406.         AddPart(LastCursorKeys,"cursorkeys.prefs",MAX_FILENAME_LENGTH);
  407.     }
  408.  
  409.     strcpy(FileConfig -> CursorFileName,LastCursorKeys);
  410. }
  411.  
  412. STATIC VOID
  413. ResetPath(struct PathSettings *PathConfig,STRPTR PathBuffer)
  414. {
  415.     if(!PathBuffer)
  416.         PathBuffer = "TERM:config";
  417.  
  418.     strcpy(PathConfig -> DefaultStorage,PathBuffer);
  419.  
  420.     PathConfig -> ASCIIUploadPath[0]    = 0;
  421.     PathConfig -> ASCIIDownloadPath[0]    = 0;
  422.     PathConfig -> TextUploadPath[0]        = 0;
  423.     PathConfig -> TextDownloadPath[0]    = 0;
  424.     PathConfig -> BinaryUploadPath[0]    = 0;
  425.     PathConfig -> BinaryDownloadPath[0]    = 0;
  426.  
  427.     strcpy(PathConfig -> HelpFile,"PROGDIR:term.guide");
  428.  
  429.     strcpy(PathConfig -> DefaultStorage,PathBuffer);
  430.  
  431.     GetEnvDOS(PathConfig -> Editor,"EDITOR");
  432. }
  433.  
  434. STATIC VOID
  435. ResetMisc(struct MiscSettings *MiscConfig)
  436. {
  437.     MiscConfig -> Priority            = 1;
  438.     MiscConfig -> BackupConfig        = FALSE;
  439.  
  440.     MiscConfig -> OpenFastMacroPanel    = FALSE;
  441.     MiscConfig -> ReleaseDevice        = TRUE;
  442.  
  443.     MiscConfig -> TransferServer        = TRUE;
  444.     MiscConfig -> EmulationServer        = TRUE;
  445.  
  446.     MiscConfig -> OverridePath        = TRUE;
  447.     MiscConfig -> AutoUpload        = TRUE;
  448.     MiscConfig -> SetArchivedBit        = FALSE;
  449.     MiscConfig -> IdentifyFiles        = IDENTIFY_FILETYPE;
  450.     MiscConfig -> TransferIcons        = FALSE;
  451. }
  452.  
  453. STATIC VOID
  454. ResetCommand(struct CommandSettings *CommandConfig)
  455. {
  456.     CommandConfig -> StartupMacro[0]    = 0;
  457.     CommandConfig -> LogoffMacro[0]        = 0;
  458.     CommandConfig -> UploadMacro[0]        = 0;
  459.     CommandConfig -> DownloadMacro[0]    = 0;
  460. }
  461.  
  462.     /* ResetConfig():
  463.      *
  464.      *    Initialize configuration with default values.
  465.      */
  466.  
  467. VOID
  468. ResetConfig(struct Configuration *Config,STRPTR PathBuffer)
  469. {
  470.     if(!PathBuffer)
  471.         PathBuffer = "TERM:config";
  472.  
  473.     ResetPath(Config -> PathConfig,PathBuffer);
  474.     ResetFile(Config -> FileConfig,PathBuffer);
  475.  
  476.     ResetSerialConfig(Config -> SerialConfig);
  477.     ResetModem(Config -> ModemConfig);
  478.     ResetScreen(Config -> ScreenConfig);
  479.     ResetTerminal(Config -> TerminalConfig);
  480.     ResetEmulation(Config -> EmulationConfig);
  481.     ResetClip(Config -> ClipConfig);
  482.     ResetCapture(Config -> CaptureConfig);
  483.     ResetMisc(Config -> MiscConfig);
  484.     ResetCommand(Config -> CommandConfig);
  485. }
  486.  
  487. VOID
  488. DeleteConfigEntry(struct Configuration *Config,BYTE Type)
  489. {
  490.     if(Type == PREF_ALL)
  491.     {
  492.         for(Type = PREF_SERIAL ; Type <= PREF_EMULATION ; Type++)
  493.             DeleteConfigEntry(Config,Type);
  494.     }
  495.     else
  496.     {
  497.         switch(Type)
  498.         {
  499.             case PREF_SERIAL:
  500.  
  501.                 if(Config -> SerialConfig)
  502.                 {
  503.                     FreeVec(Config -> SerialConfig);
  504.  
  505.                     Config -> SerialConfig = NULL;
  506.                 }
  507.  
  508.                 break;
  509.  
  510.             case PREF_MODEM:
  511.  
  512.                 if(Config -> ModemConfig)
  513.                 {
  514.                     FreeVec(Config -> ModemConfig);
  515.  
  516.                     Config -> ModemConfig = NULL;
  517.                 }
  518.  
  519.                 break;
  520.  
  521.             case PREF_COMMAND:
  522.  
  523.                 if(Config -> CommandConfig)
  524.                 {
  525.                     FreeVec(Config -> CommandConfig);
  526.  
  527.                     Config -> CommandConfig = NULL;
  528.                 }
  529.  
  530.                 break;
  531.  
  532.             case PREF_SCREEN:
  533.  
  534.                 if(Config -> ScreenConfig)
  535.                 {
  536.                     FreeVec(Config -> ScreenConfig);
  537.  
  538.                     Config -> ScreenConfig = NULL;
  539.                 }
  540.  
  541.                 break;
  542.  
  543.             case PREF_TERMINAL:
  544.  
  545.                 if(Config -> TerminalConfig)
  546.                 {
  547.                     FreeVec(Config -> TerminalConfig);
  548.  
  549.                     Config -> TerminalConfig = NULL;
  550.                 }
  551.  
  552.                 break;
  553.  
  554.             case PREF_PATH:
  555.  
  556.                 if(Config -> PathConfig)
  557.                 {
  558.                     FreeVec(Config -> PathConfig);
  559.  
  560.                     Config -> PathConfig = NULL;
  561.                 }
  562.  
  563.                 break;
  564.  
  565.             case PREF_MISC:
  566.  
  567.                 if(Config -> MiscConfig)
  568.                 {
  569.                     FreeVec(Config -> MiscConfig);
  570.  
  571.                     Config -> MiscConfig = NULL;
  572.                 }
  573.  
  574.                 break;
  575.  
  576.             case PREF_CLIP:
  577.  
  578.                 if(Config -> ClipConfig)
  579.                 {
  580.                     FreeVec(Config -> ClipConfig);
  581.  
  582.                     Config -> ClipConfig = NULL;
  583.                 }
  584.  
  585.                 break;
  586.  
  587.             case PREF_CAPTURE:
  588.  
  589.                 if(Config -> CaptureConfig)
  590.                 {
  591.                     FreeVec(Config -> CaptureConfig);
  592.  
  593.                     Config -> CaptureConfig = NULL;
  594.                 }
  595.  
  596.                 break;
  597.  
  598.             case PREF_FILE:
  599.  
  600.                 if(Config -> FileConfig)
  601.                 {
  602.                     FreeVec(Config -> FileConfig);
  603.  
  604.                     Config -> FileConfig = NULL;
  605.                 }
  606.  
  607.                 break;
  608.  
  609.             case PREF_EMULATION:
  610.  
  611.                 if(Config -> EmulationConfig)
  612.                 {
  613.                     FreeVec(Config -> EmulationConfig);
  614.  
  615.                     Config -> EmulationConfig = NULL;
  616.                 }
  617.  
  618.                 break;
  619.         }
  620.     }
  621. }
  622.  
  623. VOID
  624. ResetConfigEntry(struct Configuration *Configuration,BYTE Type,BYTE Default)
  625. {
  626.     if(Type == PREF_ALL)
  627.     {
  628.         for(Type = PREF_SERIAL ; Type <= PREF_EMULATION ; Type++)
  629.             ResetConfigEntry(Configuration,Type,Default);
  630.     }
  631.     else
  632.     {
  633.         switch(Type)
  634.         {
  635.             case PREF_SERIAL:
  636.  
  637.                 if(Default || !Config -> SerialConfig)
  638.                     ResetSerialConfig(Configuration -> SerialConfig);
  639.                 else
  640.                     memcpy(Configuration -> SerialConfig,Config -> SerialConfig,sizeof(struct SerialSettings));
  641.  
  642.                 break;
  643.  
  644.             case PREF_MODEM:
  645.  
  646.                 if(Default || !Config -> ModemConfig)
  647.                     ResetModem(Configuration -> ModemConfig);
  648.                 else
  649.                     memcpy(Configuration -> ModemConfig,Config -> ModemConfig,sizeof(struct ModemSettings));
  650.  
  651.                 break;
  652.  
  653.             case PREF_COMMAND:
  654.  
  655.                 if(Default || !Config -> CommandConfig)
  656.                     ResetCommand(Configuration -> CommandConfig);
  657.                 else
  658.                     memcpy(Configuration -> CommandConfig,Config -> CommandConfig,sizeof(struct CommandSettings));
  659.  
  660.                 break;
  661.  
  662.             case PREF_SCREEN:
  663.  
  664.                 if(Default || !Config -> ScreenConfig)
  665.                     ResetScreen(Configuration -> ScreenConfig);
  666.                 else
  667.                     memcpy(Configuration -> ScreenConfig,Config -> ScreenConfig,sizeof(struct ScreenSettings));
  668.  
  669.                 break;
  670.  
  671.             case PREF_TERMINAL:
  672.  
  673.                 if(Default || !Config -> TerminalConfig)
  674.                     ResetTerminal(Configuration -> TerminalConfig);
  675.                 else
  676.                     memcpy(Configuration -> TerminalConfig,Config -> TerminalConfig,sizeof(struct TerminalSettings));
  677.  
  678.                 break;
  679.  
  680.             case PREF_PATH:
  681.  
  682.                 if(Default || !Config -> PathConfig)
  683.                     ResetPath(Configuration -> PathConfig,NULL);
  684.                 else
  685.                     memcpy(Configuration -> PathConfig,Config -> PathConfig,sizeof(struct PathSettings));
  686.  
  687.                 break;
  688.  
  689.             case PREF_MISC:
  690.  
  691.                 if(Default || !Config -> MiscConfig)
  692.                     ResetMisc(Configuration -> MiscConfig);
  693.                 else
  694.                     memcpy(Configuration -> MiscConfig,Config -> MiscConfig,sizeof(struct MiscSettings));
  695.  
  696.                 break;
  697.  
  698.             case PREF_CLIP:
  699.  
  700.                 if(Default || !Config -> ClipConfig)
  701.                     ResetClip(Configuration -> ClipConfig);
  702.                 else
  703.                     memcpy(Configuration -> ClipConfig,Config -> ClipConfig,sizeof(struct ClipSettings));
  704.  
  705.                 break;
  706.  
  707.             case PREF_CAPTURE:
  708.  
  709.                 if(Default || !Config -> CaptureConfig)
  710.                     ResetCapture(Configuration -> CaptureConfig);
  711.                 else
  712.                     memcpy(Configuration -> CaptureConfig,Config -> CaptureConfig,sizeof(struct CaptureSettings));
  713.  
  714.                 break;
  715.  
  716.             case PREF_FILE:
  717.  
  718.                 if(Default || !Config -> FileConfig)
  719.                     ResetFile(Configuration -> FileConfig,NULL);
  720.                 else
  721.                     memcpy(Configuration -> FileConfig,Config -> FileConfig,sizeof(struct FileSettings));
  722.  
  723.                 break;
  724.  
  725.             case PREF_EMULATION:
  726.  
  727.                 if(Default || !Config -> EmulationConfig)
  728.                     ResetEmulation(Configuration -> EmulationConfig);
  729.                 else
  730.                     memcpy(Configuration -> EmulationConfig,Config -> EmulationConfig,sizeof(struct EmulationSettings));
  731.  
  732.                 break;
  733.         }
  734.     }
  735. }
  736.  
  737. APTR
  738. GetConfigEntry(struct Configuration *Config,BYTE Type)
  739. {
  740.     switch(Type)
  741.     {
  742.         case PREF_SERIAL:
  743.  
  744.             return(Config -> SerialConfig);
  745.  
  746.         case PREF_MODEM:
  747.  
  748.             return(Config -> ModemConfig);
  749.  
  750.         case PREF_COMMAND:
  751.  
  752.             return(Config -> CommandConfig);
  753.  
  754.         case PREF_SCREEN:
  755.  
  756.             return(Config -> ScreenConfig);
  757.  
  758.         case PREF_TERMINAL:
  759.  
  760.             return(Config -> TerminalConfig);
  761.  
  762.         case PREF_PATH:
  763.  
  764.             return(Config -> PathConfig);
  765.  
  766.         case PREF_MISC:
  767.  
  768.             return(Config -> MiscConfig);
  769.  
  770.         case PREF_CLIP:
  771.  
  772.             return(Config -> ClipConfig);
  773.  
  774.         case PREF_CAPTURE:
  775.  
  776.             return(Config -> CaptureConfig);
  777.  
  778.         case PREF_FILE:
  779.  
  780.             return(Config -> FileConfig);
  781.  
  782.         case PREF_EMULATION:
  783.  
  784.             return(Config -> EmulationConfig);
  785.  
  786.         default:
  787.  
  788.             return(NULL);
  789.     }
  790. }
  791.  
  792. BYTE
  793. CreateConfigEntry(struct Configuration *Config,BYTE Type)
  794. {
  795.     if(Type == PREF_ALL)
  796.     {
  797.         for(Type = PREF_SERIAL ; Type <= PREF_EMULATION ; Type++)
  798.         {
  799.             if(!CreateConfigEntry(Config,Type))
  800.             {
  801.                 DeleteConfigEntry(Config,PREF_ALL);
  802.  
  803.                 return(FALSE);
  804.             }
  805.         }
  806.  
  807.         return(TRUE);
  808.     }
  809.     else
  810.     {
  811.         APTR Data;
  812.  
  813.         switch(Type)
  814.         {
  815.             case PREF_SERIAL:
  816.  
  817.                 Data = Config -> SerialConfig;
  818.                 break;
  819.  
  820.             case PREF_MODEM:
  821.  
  822.                 Data = Config -> ModemConfig;
  823.                 break;
  824.  
  825.             case PREF_COMMAND:
  826.  
  827.                 Data = Config -> CommandConfig;
  828.                 break;
  829.  
  830.             case PREF_SCREEN:
  831.  
  832.                 Data = Config -> ScreenConfig;
  833.                 break;
  834.  
  835.             case PREF_TERMINAL:
  836.  
  837.                 Data = Config -> TerminalConfig;
  838.                 break;
  839.  
  840.             case PREF_PATH:
  841.  
  842.                 Data = Config -> PathConfig;
  843.                 break;
  844.  
  845.             case PREF_MISC:
  846.  
  847.                 Data = Config -> MiscConfig;
  848.                 break;
  849.  
  850.             case PREF_CLIP:
  851.  
  852.                 Data = Config -> ClipConfig;
  853.                 break;
  854.  
  855.             case PREF_CAPTURE:
  856.  
  857.                 Data = Config -> CaptureConfig;
  858.                 break;
  859.  
  860.             case PREF_FILE:
  861.  
  862.                 Data = Config -> FileConfig;
  863.                 break;
  864.  
  865.             case PREF_EMULATION:
  866.  
  867.                 Data = Config -> EmulationConfig;
  868.                 break;
  869.  
  870.             default:
  871.  
  872.                 return(FALSE);
  873.         }
  874.  
  875.         if(!Data)
  876.         {
  877.             if(Data = AllocVec(SizeTable[Type - 1],MEMF_ANY | MEMF_CLEAR))
  878.             {
  879.                 (*ResetTable[Type - 1])(Data,NULL);
  880.  
  881.                 switch(Type)
  882.                 {
  883.                     case PREF_SERIAL:
  884.  
  885.                         Config -> SerialConfig        = Data;
  886.                         break;
  887.  
  888.                     case PREF_MODEM:
  889.  
  890.                         Config -> ModemConfig        = Data;
  891.                         break;
  892.  
  893.                     case PREF_COMMAND:
  894.  
  895.                         Config -> CommandConfig        = Data;
  896.                         break;
  897.  
  898.                     case PREF_SCREEN:
  899.  
  900.                         Config -> ScreenConfig        = Data;
  901.                         break;
  902.  
  903.                     case PREF_TERMINAL:
  904.  
  905.                         Config -> TerminalConfig    = Data;
  906.                         break;
  907.  
  908.                     case PREF_PATH:
  909.  
  910.                         Config -> PathConfig        = Data;
  911.                         break;
  912.  
  913.                     case PREF_MISC:
  914.  
  915.                         Config -> MiscConfig        = Data;
  916.                         break;
  917.  
  918.                     case PREF_CLIP:
  919.  
  920.                         Config -> ClipConfig        = Data;
  921.                         break;
  922.  
  923.                     case PREF_CAPTURE:
  924.  
  925.                         Config -> CaptureConfig        = Data;
  926.                         break;
  927.  
  928.                     case PREF_FILE:
  929.  
  930.                         Config -> FileConfig        = Data;
  931.                         break;
  932.  
  933.                     case PREF_EMULATION:
  934.  
  935.                         Config -> EmulationConfig    = Data;
  936.                         break;
  937.                 }
  938.  
  939.                 return(TRUE);
  940.             }
  941.             else
  942.                 return(FALSE);
  943.         }
  944.         else
  945.             return(TRUE);
  946.     }
  947. }
  948.  
  949. VOID
  950. DeleteConfiguration(struct Configuration *Config)
  951. {
  952.     if(Config)
  953.     {
  954.         DeleteConfigEntry(Config,PREF_ALL);
  955.  
  956.         FreeVec(Config);
  957.     }
  958. }
  959.  
  960. struct Configuration *
  961. CreateConfiguration(BYTE Fill)
  962. {
  963.     struct Configuration *Config;
  964.  
  965.     if(Config = (struct Configuration *)AllocVec(sizeof(struct Configuration),MEMF_ANY | MEMF_CLEAR))
  966.     {
  967.         if(Fill)
  968.         {
  969.             if(!CreateConfigEntry(Config,PREF_ALL))
  970.             {
  971.                 FreeVec(Config);
  972.  
  973.                 return(NULL);
  974.             }
  975.         }
  976.  
  977.         return(Config);
  978.     }
  979.     else
  980.         return(NULL);
  981. }
  982.  
  983. STATIC BYTE
  984. WriteConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,BYTE Type,APTR TempBuffer,STRPTR Password)
  985. {
  986.     APTR Data;
  987.  
  988.     switch(Type)
  989.     {
  990.         case PREF_SERIAL:
  991.  
  992.             Data = Config -> SerialConfig;
  993.             break;
  994.  
  995.         case PREF_MODEM:
  996.  
  997.             Data = Config -> ModemConfig;
  998.             break;
  999.  
  1000.         case PREF_COMMAND:
  1001.  
  1002.             Data = Config -> CommandConfig;
  1003.             break;
  1004.  
  1005.         case PREF_SCREEN:
  1006.  
  1007.             Data = Config -> ScreenConfig;
  1008.             break;
  1009.  
  1010.         case PREF_TERMINAL:
  1011.  
  1012.             Data = Config -> TerminalConfig;
  1013.             break;
  1014.  
  1015.         case PREF_PATH:
  1016.  
  1017.             Data = Config -> PathConfig;
  1018.             break;
  1019.  
  1020.         case PREF_MISC:
  1021.  
  1022.             Data = Config -> MiscConfig;
  1023.             break;
  1024.  
  1025.         case PREF_CLIP:
  1026.  
  1027.             Data = Config -> ClipConfig;
  1028.             break;
  1029.  
  1030.         case PREF_CAPTURE:
  1031.  
  1032.             Data = Config -> CaptureConfig;
  1033.             break;
  1034.  
  1035.         case PREF_FILE:
  1036.  
  1037.             Data = Config -> FileConfig;
  1038.             break;
  1039.  
  1040.         case PREF_EMULATION:
  1041.  
  1042.             Data = Config -> EmulationConfig;
  1043.             break;
  1044.  
  1045.         default:
  1046.  
  1047.             Data = NULL;
  1048.             break;
  1049.     }
  1050.  
  1051.     if(Data)
  1052.     {
  1053.         if(TempBuffer)
  1054.         {
  1055.             Encrypt(Data,SizeTable[Type - 1],TempBuffer,Password,20);
  1056.  
  1057.             Data = TempBuffer;
  1058.         }
  1059.  
  1060.         if(!PushChunk(Handle,0,TypeTable[Type - 1],SizeTable[Type - 1]))
  1061.         {
  1062.             if(WriteChunkRecords(Handle,Data,SizeTable[Type - 1],1) == 1)
  1063.             {
  1064.                 if(!PopChunk(Handle))
  1065.                     return(TRUE);
  1066.             }
  1067.         }
  1068.  
  1069.         return(FALSE);
  1070.     }
  1071.     else
  1072.         return(TRUE);
  1073. }
  1074.  
  1075. STATIC UBYTE
  1076. IsConfigChunk(ULONG ID)
  1077. {
  1078.     UBYTE Type;
  1079.  
  1080.     for(Type = PREF_SERIAL ; Type <= PREF_EMULATION ; Type++)
  1081.     {
  1082.         if(ID == TypeTable[Type - 1])
  1083.             return(Type);
  1084.     }
  1085.  
  1086.     return(0);
  1087. }
  1088.  
  1089. STATIC BYTE
  1090. WriteConfigChunks(struct IFFHandle *Handle,struct Configuration *Config,APTR TempBuffer,STRPTR Password)
  1091. {
  1092.     UBYTE Type;
  1093.  
  1094.     for(Type = PREF_SERIAL ; Type <= PREF_EMULATION ; Type++)
  1095.     {
  1096.         if(!WriteConfigChunk(Handle,Config,Type,TempBuffer,Password))
  1097.             return(FALSE);
  1098.     }
  1099.  
  1100.     return(TRUE);
  1101. }
  1102.  
  1103. VOID
  1104. SaveConfig(struct Configuration *Src,struct Configuration *Dst)
  1105. {
  1106.     if(Dst -> SerialConfig && Src -> SerialConfig)
  1107.         memcpy(Dst -> SerialConfig,Src -> SerialConfig,sizeof(struct SerialSettings));
  1108.  
  1109.     if(Dst -> ModemConfig && Src -> ModemConfig)
  1110.         memcpy(Dst -> ModemConfig,Src -> ModemConfig,sizeof(struct ModemSettings));
  1111.  
  1112.     if(Dst -> ScreenConfig && Src -> ScreenConfig)
  1113.         memcpy(Dst -> ScreenConfig,Src -> ScreenConfig,sizeof(struct ScreenSettings));
  1114.  
  1115.     if(Dst -> TerminalConfig && Src -> TerminalConfig)
  1116.         memcpy(Dst -> TerminalConfig,Src -> TerminalConfig,sizeof(struct TerminalSettings));
  1117.  
  1118.     if(Dst -> EmulationConfig && Src -> EmulationConfig)
  1119.         memcpy(Dst -> EmulationConfig,Src -> EmulationConfig,sizeof(struct EmulationSettings));
  1120.  
  1121.     if(Dst -> ClipConfig && Src -> ClipConfig)
  1122.         memcpy(Dst -> ClipConfig,Src -> ClipConfig,sizeof(struct ClipSettings));
  1123.  
  1124.     if(Dst -> CaptureConfig && Src -> CaptureConfig)
  1125.         memcpy(Dst -> CaptureConfig,Src -> CaptureConfig,sizeof(struct CaptureSettings));
  1126.  
  1127.     if(Dst -> CommandConfig && Src -> CommandConfig)
  1128.         memcpy(Dst -> CommandConfig,Src -> CommandConfig,sizeof(struct CommandSettings));
  1129.  
  1130.     if(Dst -> MiscConfig && Src -> MiscConfig)
  1131.         memcpy(Dst -> MiscConfig,Src -> MiscConfig,sizeof(struct MiscSettings));
  1132.  
  1133.     if(Dst -> PathConfig && Src -> PathConfig)
  1134.         memcpy(Dst -> PathConfig,Src -> PathConfig,sizeof(struct PathSettings));
  1135.  
  1136.     if(Dst -> FileConfig && Src -> FileConfig)
  1137.         memcpy(Dst -> FileConfig,Src -> FileConfig,sizeof(struct FileSettings));
  1138. }
  1139.  
  1140. VOID
  1141. UpdateConfig(struct Configuration *Src,struct Configuration *Dst)
  1142. {
  1143.     if(Src -> SerialConfig)
  1144.         memcpy(Dst -> SerialConfig,Src -> SerialConfig,sizeof(struct SerialSettings));
  1145.  
  1146.     if(Src -> ModemConfig)
  1147.         memcpy(Dst -> ModemConfig,Src -> ModemConfig,sizeof(struct ModemSettings));
  1148.  
  1149.     if(Src -> ScreenConfig)
  1150.         memcpy(Dst -> ScreenConfig,Src -> ScreenConfig,sizeof(struct ScreenSettings));
  1151.  
  1152.     if(Src -> TerminalConfig)
  1153.         memcpy(Dst -> TerminalConfig,Src -> TerminalConfig,sizeof(struct TerminalSettings));
  1154.  
  1155.     if(Src -> EmulationConfig)
  1156.         memcpy(Dst -> EmulationConfig,Src -> EmulationConfig,sizeof(struct EmulationSettings));
  1157.  
  1158.     if(Src -> ClipConfig)
  1159.         memcpy(Dst -> ClipConfig,Src -> ClipConfig,sizeof(struct ClipSettings));
  1160.  
  1161.     if(Src -> CaptureConfig)
  1162.         memcpy(Dst -> CaptureConfig,Src -> CaptureConfig,sizeof(struct CaptureSettings));
  1163.  
  1164.     if(Src -> CommandConfig)
  1165.         memcpy(Dst -> CommandConfig,Src -> CommandConfig,sizeof(struct CommandSettings));
  1166.  
  1167.     if(Src -> MiscConfig)
  1168.         memcpy(Dst -> MiscConfig,Src -> MiscConfig,sizeof(struct MiscSettings));
  1169.  
  1170.     if(Src -> PathConfig)
  1171.         memcpy(Dst -> PathConfig,Src -> PathConfig,sizeof(struct PathSettings));
  1172.  
  1173.     if(Src -> FileConfig)
  1174.         memcpy(Dst -> FileConfig,Src -> FileConfig,sizeof(struct FileSettings));
  1175. }
  1176.  
  1177. VOID
  1178. SwapConfig(struct Configuration *Src,struct Configuration *Dst)
  1179. {
  1180.     swmem(Dst -> SerialConfig,Src -> SerialConfig,sizeof(struct SerialSettings));
  1181.     swmem(Dst -> ModemConfig,Src -> ModemConfig,sizeof(struct ModemSettings));
  1182.     swmem(Dst -> ScreenConfig,Src -> ScreenConfig,sizeof(struct ScreenSettings));
  1183.     swmem(Dst -> TerminalConfig,Src -> TerminalConfig,sizeof(struct TerminalSettings));
  1184.     swmem(Dst -> EmulationConfig,Src -> EmulationConfig,sizeof(struct EmulationSettings));
  1185.     swmem(Dst -> ClipConfig,Src -> ClipConfig,sizeof(struct ClipSettings));
  1186.     swmem(Dst -> CaptureConfig,Src -> CaptureConfig,sizeof(struct CaptureSettings));
  1187.     swmem(Dst -> CommandConfig,Src -> CommandConfig,sizeof(struct CommandSettings));
  1188.     swmem(Dst -> MiscConfig,Src -> MiscConfig,sizeof(struct MiscSettings));
  1189.     swmem(Dst -> PathConfig,Src -> PathConfig,sizeof(struct PathSettings));
  1190.     swmem(Dst -> FileConfig,Src -> FileConfig,sizeof(struct FileSettings));
  1191. }
  1192.  
  1193.     /* SavePhonebook(STRPTR Name):
  1194.      *
  1195.      *    Save the current phone book to a disk file.
  1196.      */
  1197.  
  1198. BYTE
  1199. SavePhonebook(STRPTR Name)
  1200. {
  1201.     struct IFFHandle    *Handle;
  1202.     BYTE             Success = FALSE;
  1203.  
  1204.     if(Phonebook && NumPhoneEntries)
  1205.     {
  1206.         if(Handle = (struct IFFHandle *)AllocIFF())
  1207.         {
  1208.             if(Handle -> iff_Stream = Open(Name,MODE_NEWFILE))
  1209.             {
  1210.                 InitIFFasDOS(Handle);
  1211.  
  1212.                 if(!OpenIFF(Handle,IFFF_WRITE))
  1213.                 {
  1214.                     if(!PushChunk(Handle,ID_TERM,ID_CAT,IFFSIZE_UNKNOWN))
  1215.                     {
  1216.                         if(!PushChunk(Handle,ID_TERM,ID_FORM,IFFSIZE_UNKNOWN))
  1217.                         {
  1218.                             if(!PushChunk(Handle,0,ID_VERS,IFFSIZE_UNKNOWN))
  1219.                             {
  1220.                                 struct TermInfo TermInfo;
  1221.  
  1222.                                 TermInfo . Version    = TermVersion;
  1223.                                 TermInfo . Revision    = TermRevision;
  1224.  
  1225.                                 if(WriteChunkRecords(Handle,&TermInfo,sizeof(struct TermInfo),1) == 1)
  1226.                                 {
  1227.                                     if(!PopChunk(Handle))
  1228.                                     {
  1229.                                         STRPTR TempBuffer = NULL;
  1230.  
  1231.                                         if(PhonePasswordUsed)
  1232.                                         {
  1233.                                             if(!PushChunk(Handle,0,ID_PSWD,20))
  1234.                                             {
  1235.                                                 Success = TRUE;
  1236.  
  1237.                                                 if(WriteChunkBytes(Handle,PhonePassword,20) != 20)
  1238.                                                     Success = FALSE;
  1239.  
  1240.                                                 if(PopChunk(Handle))
  1241.                                                     Success = FALSE;
  1242.  
  1243.                                                 if(Success)
  1244.                                                 {
  1245.                                                     LONG Max = sizeof(struct PhoneHeader),Type;
  1246.  
  1247.                                                     for(Type = PREF_SERIAL ; Type <= PREF_EMULATION ; Type++)
  1248.                                                     {
  1249.                                                         if(SizeTable[Type - 1] > Max)
  1250.                                                             Max = SizeTable[Type - 1];
  1251.                                                     }
  1252.  
  1253.                                                     if(!(TempBuffer = AllocVec(Max,MEMF_ANY)))
  1254.                                                         Success = FALSE;
  1255.                                                 }
  1256.                                             }
  1257.                                         }
  1258.                                         else
  1259.                                             Success = TRUE;
  1260.  
  1261.                                         if(Success)
  1262.                                         {
  1263.                                             Success = FALSE;
  1264.  
  1265.                                             if(!PushChunk(Handle,0,ID_DIAL,IFFSIZE_UNKNOWN))
  1266.                                             {
  1267.                                                 if(WriteChunkBytes(Handle,&NumPhoneEntries,sizeof(LONG)) == sizeof(LONG))
  1268.                                                 {
  1269.                                                     if(!PopChunk(Handle))
  1270.                                                     {
  1271.                                                         if(!PopChunk(Handle))
  1272.                                                         {
  1273.                                                             LONG i;
  1274.  
  1275.                                                             Success = TRUE;
  1276.  
  1277.                                                             for(i = 0 ; Success && i < NumPhoneEntries ; i++)
  1278.                                                             {
  1279.                                                                 Success = FALSE;
  1280.  
  1281.                                                                 if(!PushChunk(Handle,ID_TERM,ID_FORM,IFFSIZE_UNKNOWN))
  1282.                                                                 {
  1283.                                                                     if(!PushChunk(Handle,0,ID_PHON,sizeof(struct PhoneHeader)))
  1284.                                                                     {
  1285.                                                                         if(TempBuffer)
  1286.                                                                         {
  1287.                                                                             Encrypt((UBYTE *)Phonebook[i] -> Header,sizeof(struct PhoneHeader),TempBuffer,PhonePassword,20);
  1288.  
  1289.                                                                             if(WriteChunkRecords(Handle,TempBuffer,sizeof(struct PhoneHeader),1) == 1)
  1290.                                                                             {
  1291.                                                                                 if(!PopChunk(Handle))
  1292.                                                                                 {
  1293.                                                                                     if(WriteConfigChunks(Handle,Phonebook[i] -> Config,TempBuffer,PhonePassword))
  1294.                                                                                     {
  1295.                                                                                         struct TimeDateNode *TimeDateNode;
  1296.  
  1297.                                                                                         Success = TRUE;
  1298.  
  1299.                                                                                         TimeDateNode = (struct TimeDateNode *)Phonebook[i] -> TimeDateList . mlh_Head;
  1300.  
  1301.                                                                                         while(TimeDateNode -> VanillaNode . ln_Succ)
  1302.                                                                                         {
  1303.                                                                                             if(!PushChunk(Handle,0,ID_DATE,IFFSIZE_UNKNOWN))
  1304.                                                                                             {
  1305.                                                                                                 if(WriteChunkBytes(Handle,&TimeDateNode -> Header,sizeof(struct TimeDateHeader)) != sizeof(struct TimeDateHeader))
  1306.                                                                                                 {
  1307.                                                                                                     Success = FALSE;
  1308.  
  1309.                                                                                                     break;
  1310.                                                                                                 }
  1311.                                                                                                 else
  1312.                                                                                                 {
  1313.                                                                                                     if(WriteChunkBytes(Handle,TimeDateNode -> Table,TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate)) != TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate))
  1314.                                                                                                     {
  1315.                                                                                                         Success = FALSE;
  1316.  
  1317.                                                                                                         break;
  1318.                                                                                                     }
  1319.                                                                                                 }
  1320.  
  1321.                                                                                                 if(PopChunk(Handle))
  1322.                                                                                                 {
  1323.                                                                                                     Success = FALSE;
  1324.  
  1325.                                                                                                     break;
  1326.                                                                                                 }
  1327.  
  1328.                                                                                                 TimeDateNode = (struct TimeDateNode *)TimeDateNode -> VanillaNode . ln_Succ;
  1329.                                                                                             }
  1330.                                                                                         }
  1331.                                                                                     }
  1332.                                                                                     else
  1333.                                                                                         Success = FALSE;
  1334.                                                                                 }
  1335.                                                                             }
  1336.                                                                         }
  1337.                                                                         else
  1338.                                                                         {
  1339.                                                                             if(WriteChunkRecords(Handle,Phonebook[i] -> Header,sizeof(struct PhoneHeader),1) == 1)
  1340.                                                                             {
  1341.                                                                                 if(!PopChunk(Handle))
  1342.                                                                                 {
  1343.                                                                                     if(WriteConfigChunks(Handle,Phonebook[i] -> Config,NULL,NULL))
  1344.                                                                                     {
  1345.                                                                                         struct TimeDateNode *TimeDateNode;
  1346.  
  1347.                                                                                         Success = TRUE;
  1348.  
  1349.                                                                                         TimeDateNode = (struct TimeDateNode *)Phonebook[i] -> TimeDateList . mlh_Head;
  1350.  
  1351.                                                                                         while(TimeDateNode -> VanillaNode . ln_Succ)
  1352.                                                                                         {
  1353.                                                                                             if(!PushChunk(Handle,0,ID_DATE,IFFSIZE_UNKNOWN))
  1354.                                                                                             {
  1355.                                                                                                 if(WriteChunkBytes(Handle,&TimeDateNode -> Header,sizeof(struct TimeDateHeader)) != sizeof(struct TimeDateHeader))
  1356.                                                                                                 {
  1357.                                                                                                     Success = FALSE;
  1358.  
  1359.                                                                                                     break;
  1360.                                                                                                 }
  1361.                                                                                                 else
  1362.                                                                                                 {
  1363.                                                                                                     if(WriteChunkBytes(Handle,TimeDateNode -> Table,TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate)) != TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate))
  1364.                                                                                                     {
  1365.                                                                                                         Success = FALSE;
  1366.  
  1367.                                                                                                         break;
  1368.                                                                                                     }
  1369.                                                                                                 }
  1370.  
  1371.                                                                                                 if(PopChunk(Handle))
  1372.                                                                                                 {
  1373.                                                                                                     Success = FALSE;
  1374.  
  1375.                                                                                                     break;
  1376.                                                                                                 }
  1377.  
  1378.                                                                                                 TimeDateNode = (struct TimeDateNode *)TimeDateNode -> VanillaNode . ln_Succ;
  1379.                                                                                             }
  1380.                                                                                         }
  1381.                                                                                     }
  1382.                                                                                     else
  1383.                                                                                         Success = FALSE;
  1384.                                                                                 }
  1385.                                                                             }
  1386.                                                                         }
  1387.                                                                     }
  1388.  
  1389.                                                                     if(PopChunk(Handle))
  1390.                                                                         Success = FALSE;
  1391.                                                                 }
  1392.                                                             }
  1393.                                                         }
  1394.                                                     }
  1395.                                                 }
  1396.                                             }
  1397.                                         }
  1398.  
  1399.                                         if(TempBuffer)
  1400.                                             FreeVec(TempBuffer);
  1401.                                     }
  1402.                                 }
  1403.                             }
  1404.                         }
  1405.  
  1406.                         if(PopChunk(Handle))
  1407.                             Success = FALSE;
  1408.                     }
  1409.  
  1410.                     CloseIFF(Handle);
  1411.                 }
  1412.  
  1413.                 Close(Handle -> iff_Stream);
  1414.             }
  1415.  
  1416.             FreeIFF(Handle);
  1417.         }
  1418.  
  1419.         if(Success)
  1420.             SetProtection(Name,FIBF_EXECUTE);
  1421.         else
  1422.             DeleteFile(Name);
  1423.     }
  1424.  
  1425.     return(Success);
  1426. }
  1427.  
  1428. STATIC BYTE
  1429. ReadConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,UBYTE Type,LONG Len,STRPTR Password)
  1430. {
  1431.     if(CreateConfigEntry(Config,Type))
  1432.     {
  1433.         APTR Data;
  1434.  
  1435.         switch(Type)
  1436.         {
  1437.             case PREF_SERIAL:
  1438.  
  1439.                 Data = Config -> SerialConfig;
  1440.                 break;
  1441.  
  1442.             case PREF_MODEM:
  1443.  
  1444.                 Data = Config -> ModemConfig;
  1445.                 break;
  1446.  
  1447.             case PREF_COMMAND:
  1448.  
  1449.                 Data = Config -> CommandConfig;
  1450.                 break;
  1451.  
  1452.             case PREF_SCREEN:
  1453.  
  1454.                 Data = Config -> ScreenConfig;
  1455.                 break;
  1456.  
  1457.             case PREF_TERMINAL:
  1458.  
  1459.                 Data = Config -> TerminalConfig;
  1460.                 break;
  1461.  
  1462.             case PREF_PATH:
  1463.  
  1464.                 Data = Config -> PathConfig;
  1465.                 break;
  1466.  
  1467.             case PREF_MISC:
  1468.  
  1469.                 Data = Config -> MiscConfig;
  1470.                 break;
  1471.  
  1472.             case PREF_CLIP:
  1473.  
  1474.                 Data = Config -> ClipConfig;
  1475.                 break;
  1476.  
  1477.             case PREF_CAPTURE:
  1478.  
  1479.                 Data = Config -> CaptureConfig;
  1480.                 break;
  1481.  
  1482.             case PREF_FILE:
  1483.  
  1484.                 Data = Config -> FileConfig;
  1485.                 break;
  1486.  
  1487.             case PREF_EMULATION:
  1488.  
  1489.                 Data = Config -> EmulationConfig;
  1490.                 break;
  1491.         }
  1492.  
  1493.         Len = MIN(SizeTable[Type - 1],Len);
  1494.  
  1495.         if(ReadChunkBytes(Handle,Data,Len) == Len)
  1496.         {
  1497.             if(Password)
  1498.                 Decrypt(Data,Len,Data,Password,20);
  1499.  
  1500.             return(TRUE);
  1501.         }
  1502.     }
  1503.  
  1504.     return(FALSE);
  1505. }
  1506.  
  1507.     /* LoadPhonebook(STRPTR Name):
  1508.      *
  1509.      *    Restore a phone book from a disk file.
  1510.      */
  1511.  
  1512. BYTE
  1513. LoadPhonebook(STRPTR Name)
  1514. {
  1515.     struct PhoneEntry    **PrivatePhonebook;
  1516.     LONG             PrivatePhoneSize    = 0,
  1517.                  CurrentPhoneSize    = 0,
  1518.                  Count            = 0,
  1519.                  Index            = 0;
  1520.     BYTE             Success        = FALSE,
  1521.                  LastHadTime        = TRUE,
  1522.                  UsePhonePassword    = FALSE,
  1523.                  FirstChunk        = TRUE,
  1524.                  UseOld            = FALSE;
  1525.     struct IFFHandle    *Handle;
  1526.     struct ContextNode    *Chunk;
  1527.     struct TimeDateNode    *TimeDateNode;
  1528.     UBYTE             ConfigChunkType,
  1529.                  PasswordBuffer[20];
  1530.  
  1531.  
  1532.     if(Handle = AllocIFF())
  1533.     {
  1534.         if(Handle -> iff_Stream = Open(Name,MODE_OLDFILE))
  1535.         {
  1536.             InitIFFasDOS(Handle);
  1537.  
  1538.             if(!OpenIFF(Handle,IFFF_READ))
  1539.             {
  1540.                 if(!StopChunks(Handle,Stops,NUM_STOPS))
  1541.                 {
  1542.                     while(!ParseIFF(Handle,IFFPARSE_SCAN))
  1543.                     {
  1544.                         Chunk = CurrentChunk(Handle);
  1545.  
  1546.                         if(Chunk -> cn_ID == ID_VERS)
  1547.                         {
  1548.                             struct TermInfo TermInfo;
  1549.  
  1550.                             if(ReadChunkBytes(Handle,&TermInfo,sizeof(struct TermInfo)) == sizeof(struct TermInfo))
  1551.                             {
  1552.                                 if(TermInfo . Version != TermVersion || (TermInfo . Version == TermVersion && TermInfo . Revision > TermRevision))
  1553.                                 {
  1554.                                     if(TermInfo . Version == 2 && TermInfo . Revision == 4)
  1555.                                         UseOld = TRUE;
  1556.  
  1557.                                     break;
  1558.                                 }
  1559.                             }
  1560.                             else
  1561.                                 break;
  1562.                         }
  1563.  
  1564.                         if(Chunk -> cn_ID == ID_PSWD)
  1565.                         {
  1566.                             if(ReadChunkBytes(Handle,PasswordBuffer,20) == 20)
  1567.                             {
  1568.                                 if(PhonePasswordUsed)
  1569.                                 {
  1570.                                     if(!memcmp(PhonePassword,PasswordBuffer,20))
  1571.                                     {
  1572.                                         UsePhonePassword = TRUE;
  1573.  
  1574.                                         continue;
  1575.                                     }
  1576.                                 }
  1577.  
  1578.                                 memset(SharedBuffer,0,21);
  1579.  
  1580.                                 if(GetString(FALSE,TRUE,21,LocaleString(MSG_PHONEPANEL_PLEASE_ENTER_PASSWORD_TXT),SharedBuffer))
  1581.                                 {
  1582.                                     UBYTE AnotherBuffer[20];
  1583.  
  1584.                                     Encrypt(SharedBuffer,20,AnotherBuffer,SharedBuffer,strlen(SharedBuffer));
  1585.  
  1586.                                     if(!memcmp(PasswordBuffer,AnotherBuffer,20))
  1587.                                     {
  1588.                                         UsePhonePassword = TRUE;
  1589.  
  1590.                                         continue;
  1591.                                     }
  1592.                                     else
  1593.                                     {
  1594.                                         MyEasyRequest(Window,LocaleString(MSG_TERMPHONE_WRONG_PASSWORD_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Name);
  1595.  
  1596.                                         break;
  1597.                                     }
  1598.                                 }
  1599.                                 else
  1600.                                     break;
  1601.                             }
  1602.                             else
  1603.                                 break;
  1604.                         }
  1605.  
  1606.                         if(Chunk -> cn_ID == ID_DIAL)
  1607.                         {
  1608.                             if(ReadChunkBytes(Handle,&CurrentPhoneSize,sizeof(LONG)) == sizeof(LONG))
  1609.                             {
  1610.                                 if(!(PrivatePhonebook = CreatePhonebook(CurrentPhoneSize,&PrivatePhoneSize,TRUE)))
  1611.                                     break;
  1612.                             }
  1613.                             else
  1614.                                 break;
  1615.                         }
  1616.  
  1617.                         if(Chunk -> cn_ID == ID_PHON)
  1618.                         {
  1619.                             WORD Size = MIN(sizeof(struct PhoneHeader),Chunk -> cn_Size);
  1620.  
  1621.                             if(!LastHadTime)
  1622.                             {
  1623.                                 if(TimeDateNode = CreateTimeDateNode(-1,-1,"",2))
  1624.                                     AddTail((struct List *)&PrivatePhonebook[Index] -> TimeDateList,&TimeDateNode -> VanillaNode);
  1625.                             }
  1626.  
  1627.                             if(!FirstChunk)
  1628.                                 Index++;
  1629.                             else
  1630.                                 FirstChunk = FALSE;
  1631.  
  1632.                             if(ReadChunkBytes(Handle,PrivatePhonebook[Index] -> Header,Size) == Size)
  1633.                             {
  1634.                                 if(UsePhonePassword)
  1635.                                     Decrypt((UBYTE *)PrivatePhonebook[Index] -> Header,sizeof(struct PhoneHeader),(UBYTE *)PrivatePhonebook[Index] -> Header,PasswordBuffer,20);
  1636.  
  1637.                                 PrivatePhonebook[Index] -> Count = -1;
  1638.  
  1639.                                 LastHadTime = FALSE;
  1640.  
  1641.                                 Count++;
  1642.                             }
  1643.                             else
  1644.                                 break;
  1645.                         }
  1646.  
  1647.                         if(ConfigChunkType = IsConfigChunk(Chunk -> cn_ID))
  1648.                         {
  1649.                             if(UsePhonePassword)
  1650.                             {
  1651.                                 if(!ReadConfigChunk(Handle,PrivatePhonebook[Index] -> Config,ConfigChunkType,Chunk -> cn_Size,PasswordBuffer))
  1652.                                 {
  1653.                                     if(Count)
  1654.                                         CurrentPhoneSize = Count - 1;
  1655.                                     else
  1656.                                         CurrentPhoneSize = 0;
  1657.  
  1658.                                     break;
  1659.                                 }
  1660.                             }
  1661.                             else
  1662.                             {
  1663.                                 if(!ReadConfigChunk(Handle,PrivatePhonebook[Index] -> Config,ConfigChunkType,Chunk -> cn_Size,NULL))
  1664.                                 {
  1665.                                     if(Count)
  1666.                                         CurrentPhoneSize = Count - 1;
  1667.                                     else
  1668.                                         CurrentPhoneSize = 0;
  1669.  
  1670.                                     break;
  1671.                                 }
  1672.                             }
  1673.                         }
  1674.  
  1675.                         if(Chunk -> cn_ID == ID_DATE)
  1676.                         {
  1677.                             WORD Count = (Chunk -> cn_Size - sizeof(struct TimeDateHeader)) / sizeof(struct TimeDate);
  1678.  
  1679.                             if(TimeDateNode = CreateTimeDateNode(-1,-1,"",Count))
  1680.                             {
  1681.                                 if(ReadChunkBytes(Handle,&TimeDateNode -> Header,sizeof(struct TimeDateHeader)) == sizeof(struct TimeDateHeader))
  1682.                                 {
  1683.                                     if(ReadChunkRecords(Handle,TimeDateNode -> Table,sizeof(struct TimeDate),Count) == Count)
  1684.                                     {
  1685.                                         AdaptTimeDateNode(TimeDateNode);
  1686.  
  1687.                                         AddTail((struct List *)&PrivatePhonebook[Index] -> TimeDateList,&TimeDateNode -> VanillaNode);
  1688.  
  1689.                                         LastHadTime = TRUE;
  1690.                                     }
  1691.                                     else
  1692.                                         FreeTimeDateNode(TimeDateNode);
  1693.                                 }
  1694.                                 else
  1695.                                     FreeTimeDateNode(TimeDateNode);
  1696.                             }
  1697.                         }
  1698.                     }
  1699.  
  1700.                     if(CurrentPhoneSize)
  1701.                     {
  1702.                         LONG i;
  1703.  
  1704.                         if(!LastHadTime)
  1705.                         {
  1706.                             if(TimeDateNode = CreateTimeDateNode(-1,-1,"",2))
  1707.                                 AddTail((struct List *)&PrivatePhonebook[Index] -> TimeDateList,&TimeDateNode -> VanillaNode);
  1708.                         }
  1709.  
  1710.                         if(Phonebook)
  1711.                             DeletePhonebook(Phonebook,PhoneSize,TRUE);
  1712.  
  1713.                         Phonebook    = PrivatePhonebook;
  1714.                         PhoneSize    = PrivatePhoneSize;
  1715.                         NumPhoneEntries    = CurrentPhoneSize;
  1716.                         Success        = TRUE;
  1717.  
  1718.                         memcpy(PhonePassword,PasswordBuffer,20);
  1719.                         PhonePasswordUsed = UsePhonePassword;
  1720.  
  1721.                         for(i = NumPhoneEntries ; i < PhoneSize ; i++)
  1722.                         {
  1723.                             if(Phonebook[i])
  1724.                             {
  1725.                                 if(Phonebook[i] -> Config)
  1726.                                     DeleteConfiguration(Phonebook[i] -> Config);
  1727.  
  1728.                                 FreeVec(Phonebook[i]);
  1729.  
  1730.                                 Phonebook[i] = NULL;
  1731.                             }
  1732.                         }
  1733.  
  1734.                         FreeDialList(TRUE);
  1735.                     }
  1736.                     else
  1737.                     {
  1738.                         if(PrivatePhoneSize)
  1739.                         {
  1740.                             DeletePhonebook(PrivatePhonebook,PrivatePhoneSize,TRUE);
  1741.  
  1742.                             Success = FALSE;
  1743.                         }
  1744.                     }
  1745.                 }
  1746.  
  1747.                 CloseIFF(Handle);
  1748.             }
  1749.  
  1750.             Close(Handle -> iff_Stream);
  1751.         }
  1752.  
  1753.         FreeIFF(Handle);
  1754.     }
  1755.  
  1756.     if(UseOld)
  1757.         return(LoadOldPhonebook(Name));
  1758.     else
  1759.         return(Success);
  1760. }
  1761.  
  1762.     /* WriteConfig(STRPTR Name,struct Configuration *Config):
  1763.      *
  1764.      *    Write the configuration to a file, very much like
  1765.      *    WriteIFFData().
  1766.      */
  1767.  
  1768. BYTE
  1769. WriteConfig(STRPTR Name,struct Configuration *Config)
  1770. {
  1771.     struct IFFHandle    *Handle;
  1772.     BYTE             Success = FALSE;
  1773.  
  1774.         /* Allocate a handle. */
  1775.  
  1776.     if(Handle = AllocIFF())
  1777.     {
  1778.             /* Open an output stream. */
  1779.  
  1780.         if(Handle -> iff_Stream = Open(Name,MODE_NEWFILE))
  1781.         {
  1782.                 /* Tell iffparse that this is
  1783.                  * a DOS handle.
  1784.                  */
  1785.  
  1786.             InitIFFasDOS(Handle);
  1787.  
  1788.                 /* Open the handle for writing. */
  1789.  
  1790.             if(!OpenIFF(Handle,IFFF_WRITE))
  1791.             {
  1792.                     /* Push outmost chunk onto stack. */
  1793.  
  1794.                 if(!PushChunk(Handle,ID_TERM,ID_FORM,IFFSIZE_UNKNOWN))
  1795.                 {
  1796.                         /* Add a version identifier. */
  1797.  
  1798.                     if(!PushChunk(Handle,0,ID_VERS,IFFSIZE_UNKNOWN))
  1799.                     {
  1800.                         struct TermInfo TermInfo;
  1801.  
  1802.                         TermInfo . Version    = TermVersion;
  1803.                         TermInfo . Revision    = TermRevision;
  1804.  
  1805.                             /* Write the version data. */
  1806.  
  1807.                         if(WriteChunkBytes(Handle,&TermInfo,sizeof(struct TermInfo)) == sizeof(struct TermInfo))
  1808.                         {
  1809.                                 /* Pop the version chunk, i.e. write it to the file. */
  1810.  
  1811.                             if(PopChunk(Handle))
  1812.                                 Success = FALSE;
  1813.                             else
  1814.                             {
  1815.                                 if(WriteConfigChunks(Handle,Config,NULL,NULL))
  1816.                                     Success = TRUE;
  1817.                             }
  1818.                         }
  1819.                         else
  1820.                             Success = FALSE;
  1821.                     }
  1822.  
  1823.                         /* Seems that we're done, now try to pop the FORM chunk
  1824.                          * and return.
  1825.                          */
  1826.  
  1827.                     if(PopChunk(Handle))
  1828.                         Success = FALSE;
  1829.                 }
  1830.  
  1831.                     /* Close the handle (flush any pending data). */
  1832.  
  1833.                 CloseIFF(Handle);
  1834.             }
  1835.  
  1836.                 /* Close the DOS handle itself. */
  1837.  
  1838.             Close(Handle -> iff_Stream);
  1839.         }
  1840.  
  1841.             /* And free the IFF handle. */
  1842.  
  1843.         FreeIFF(Handle);
  1844.     }
  1845.  
  1846.     if(Success)
  1847.         SetProtection(Name,FIBF_EXECUTE);
  1848.  
  1849.     return(Success);
  1850. }
  1851.  
  1852.     /* ReadConfig(STRPTR Name,struct Configuration *Config):
  1853.      *
  1854.      *    Read the configuration file, very much the same as ReadIFFData().
  1855.      */
  1856.  
  1857. BYTE
  1858. ReadConfig(STRPTR Name,struct Configuration *Config)
  1859. {
  1860.     struct IFFHandle    *Handle;
  1861.     BYTE             Success    = FALSE,
  1862.                  UseOld        = FALSE;
  1863.     struct ContextNode    *Chunk;
  1864.     UBYTE             ConfigChunkType;
  1865.  
  1866.     if(Handle = AllocIFF())
  1867.     {
  1868.         if(Handle -> iff_Stream = Open(Name,MODE_OLDFILE))
  1869.         {
  1870.             InitIFFasDOS(Handle);
  1871.  
  1872.             if(!OpenIFF(Handle,IFFF_READ))
  1873.             {
  1874.                 if(!StopChunks(Handle,Stops,NUM_STOPS))
  1875.                 {
  1876.                     while(!ParseIFF(Handle,IFFPARSE_SCAN))
  1877.                     {
  1878.                         Chunk = CurrentChunk(Handle);
  1879.  
  1880.                         if(Chunk -> cn_ID == ID_VERS)
  1881.                         {
  1882.                             struct TermInfo TermInfo;
  1883.  
  1884.                             if(ReadChunkBytes(Handle,&TermInfo,sizeof(struct TermInfo)) == sizeof(struct TermInfo))
  1885.                             {
  1886.                                 if(TermInfo . Version != TermVersion || (TermInfo . Version == TermVersion && TermInfo . Revision > TermRevision))
  1887.                                 {
  1888.                                     if(TermInfo . Version == 2 && TermInfo . Revision == 4)
  1889.                                         UseOld = TRUE;
  1890.  
  1891.                                     break;
  1892.                                 }
  1893.                             }
  1894.                             else
  1895.                                 break;
  1896.                         }
  1897.  
  1898.                         if(ConfigChunkType = IsConfigChunk(Chunk -> cn_ID))
  1899.                         {
  1900.                             if(ReadConfigChunk(Handle,Config,ConfigChunkType,Chunk -> cn_Size,NULL))
  1901.                                 Success = TRUE;
  1902.                             else
  1903.                             {
  1904.                                 Success = FALSE;
  1905.  
  1906.                                 break;
  1907.                             }
  1908.                         }
  1909.                     }
  1910.                 }
  1911.  
  1912.                 CloseIFF(Handle);
  1913.             }
  1914.  
  1915.             Close(Handle -> iff_Stream);
  1916.         }
  1917.  
  1918.         FreeIFF(Handle);
  1919.     }
  1920.  
  1921.     if(UseOld)
  1922.         return(ReadOldConfig(Name,Config));
  1923.     else
  1924.         return(Success);
  1925. }
  1926.