home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / term / term41source.lha / Extras / Source / term-Source.lha / termConfig.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-14  |  55.5 KB  |  2,531 lines

  1. /*
  2. **    termConfig.c
  3. **
  4. **    Configuration processing routines
  5. **
  6. **    Copyright © 1990-1994 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* Number of chunks to stop at. */
  13.  
  14. #define    NUM_STOPS    19
  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. STATIC VOID        ResetTransfer(struct TransferSettings *TransferConfig,STRPTR DefaultLib);
  36.  
  37. STATIC BYTE        WriteConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,BYTE Type,APTR TempBuffer,STRPTR Password);
  38. STATIC BYTE        WriteConfigChunks(struct IFFHandle *Handle,struct Configuration *Config,APTR TempBuffer,STRPTR Password);
  39. STATIC UBYTE        IsConfigChunk(ULONG ID);
  40. STATIC BYTE        ReadConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,UBYTE Type,LONG Len,STRPTR Password);
  41.  
  42. STATIC UWORD SizeTable[] =
  43. {
  44.     sizeof(struct SerialSettings),
  45.     sizeof(struct ModemSettings),
  46.     sizeof(struct CommandSettings),
  47.     sizeof(struct ScreenSettings),
  48.     sizeof(struct TerminalSettings),
  49.     sizeof(struct PathSettings),
  50.     sizeof(struct MiscSettings),
  51.     sizeof(struct ClipSettings),
  52.     sizeof(struct CaptureSettings),
  53.     sizeof(struct FileSettings),
  54.     sizeof(struct EmulationSettings),
  55.     sizeof(struct TransferSettings)
  56. };
  57.  
  58. STATIC RESET ResetTable[] =
  59. {
  60.     (RESET)ResetSerialConfig,
  61.     (RESET)ResetModem,
  62.     (RESET)ResetCommand,
  63.     (RESET)ResetScreen,
  64.     (RESET)ResetTerminal,
  65.     ResetPath,
  66.     (RESET)ResetMisc,
  67.     (RESET)ResetClip,
  68.     (RESET)ResetCapture,
  69.     ResetFile,
  70.     (RESET)ResetEmulation,
  71.     ResetTransfer
  72. };
  73.  
  74. STATIC ULONG TypeTable[] =
  75. {
  76.     ID_SERL,
  77.     ID_MODM,
  78.     ID_COMD,
  79.     ID_SCRN,
  80.     ID_TRML,
  81.     ID_PATH,
  82.     ID_MISC,
  83.     ID_CLIP,
  84.     ID_CPTR,
  85.     ID_FILE,
  86.     ID_EMLN,
  87.     ID_XFER
  88. };
  89.  
  90. STATIC ULONG Stops[NUM_STOPS * 2] =
  91. {
  92.     ID_TERM,ID_CAT,
  93.     ID_TERM,ID_VERS,
  94.     ID_TERM,ID_DIAL,
  95.     ID_TERM,ID_DATE,
  96.     ID_TERM,ID_PHON,
  97.     ID_TERM,ID_PSWD,
  98.  
  99.     ID_TERM,ID_SERL,
  100.     ID_TERM,ID_MODM,
  101.     ID_TERM,ID_COMD,
  102.     ID_TERM,ID_SCRN,
  103.     ID_TERM,ID_TRML,
  104.     ID_TERM,ID_PATH,
  105.     ID_TERM,ID_MISC,
  106.     ID_TERM,ID_CLIP,
  107.     ID_TERM,ID_CPTR,
  108.     ID_TERM,ID_FILE,
  109.     ID_TERM,ID_EMLN,
  110.     ID_TERM,ID_XFER,
  111.     ID_TERM,ID_WINF
  112. };
  113.  
  114. enum    {    CR_IGNORE,CR_ASCR,CR_ASCRLF };
  115. enum    {    LF_IGNORE,LF_ASLF,LF_ASLFCR };
  116.  
  117. VOID __regargs
  118. FixOldConfig(struct Configuration *Config,UBYTE ConfigChunkType,BOOLEAN IsPhonebook,LONG Version,LONG Revision)
  119. {
  120.     if((Version == 3 && Revision < 6) || Version < 3)
  121.     {
  122.         if(ConfigChunkType == PREF_SERIAL)
  123.             Config -> SerialConfig -> UseOwnDevUnit = TRUE;
  124.     
  125.         if(ConfigChunkType == PREF_SCREEN)
  126.         {
  127.             Config -> ScreenConfig -> UsePens    = TRUE;
  128.             Config -> ScreenConfig -> Depth        = 0;
  129.             Config -> ScreenConfig -> PenColourMode    = 42;    // Avoid trouble
  130.         }
  131.     
  132.         if(ConfigChunkType == PREF_TRANSFER)
  133.             Config -> TransferConfig -> MangleFileNames = FALSE;
  134.     
  135.         if(ConfigChunkType == PREF_MODEM)
  136.             Config -> ModemConfig -> AbortHangsUp = FALSE;
  137.     
  138.         if(ConfigChunkType == PREF_COMMAND && IsPhonebook)
  139.         {
  140.             strcpy(Config -> CommandConfig -> LoginMacro,Config -> CommandConfig -> StartupMacro);
  141.     
  142.             memset(Config -> CommandConfig -> StartupMacro,0,sizeof(Config -> CommandConfig -> StartupMacro));
  143.         }
  144.     
  145.         if(ConfigChunkType == PREF_CAPTURE)
  146.             Config -> CaptureConfig -> SearchHistory = 10;
  147.     
  148.         if(ConfigChunkType == PREF_EMULATION)
  149.         {
  150.             if(Config -> EmulationConfig -> DestructiveBackspace < 0 || Config -> EmulationConfig -> DestructiveBackspace > 2)
  151.                 Config -> EmulationConfig -> DestructiveBackspace = 1;
  152.         }
  153.     }
  154.  
  155.     if((Version == 4 && Revision < 1) || Version < 4)
  156.     {
  157.         if(ConfigChunkType == PREF_MODEM)
  158.         {
  159.             Config -> ModemConfig -> RedialDelay    = (Config -> ModemConfig -> RedialDelay / 6) * 60 + (Config -> ModemConfig -> RedialDelay % 6) * 10;
  160.             Config -> ModemConfig -> TimeToConnect    = (Config -> ModemConfig -> TimeToConnect / 6) * 60 + (Config -> ModemConfig -> TimeToConnect % 6) * 10;
  161.         }
  162.  
  163.         if(ConfigChunkType == PREF_TERMINAL)
  164.         {
  165.             switch(Config -> TerminalConfig -> SendCR)
  166.             {
  167.                 case CR_IGNORE:
  168.  
  169.                     Config -> TerminalConfig -> SendCR = EOL_IGNORE;
  170.                     break;
  171.  
  172.                 case CR_ASCR:
  173.  
  174.                     Config -> TerminalConfig -> SendCR = EOL_CR;
  175.                     break;
  176.  
  177.                 case CR_ASCRLF:
  178.  
  179.                     Config -> TerminalConfig -> SendCR = EOL_CRLF;
  180.                     break;
  181.             }
  182.  
  183.             switch(Config -> TerminalConfig -> ReceiveCR)
  184.             {
  185.                 case CR_IGNORE:
  186.  
  187.                     Config -> TerminalConfig -> ReceiveCR = EOL_IGNORE;
  188.                     break;
  189.  
  190.                 case CR_ASCR:
  191.  
  192.                     Config -> TerminalConfig -> ReceiveCR = EOL_CR;
  193.                     break;
  194.  
  195.                 case CR_ASCRLF:
  196.  
  197.                     Config -> TerminalConfig -> ReceiveCR = EOL_CRLF;
  198.                     break;
  199.             }
  200.  
  201.             switch(Config -> TerminalConfig -> SendLF)
  202.             {
  203.                 case LF_IGNORE:
  204.  
  205.                     Config -> TerminalConfig -> SendLF = EOL_IGNORE;
  206.                     break;
  207.  
  208.                 case LF_ASLF:
  209.  
  210.                     Config -> TerminalConfig -> SendLF = EOL_LF;
  211.                     break;
  212.  
  213.                 case LF_ASLFCR:
  214.  
  215.                     Config -> TerminalConfig -> SendLF = EOL_LFCR;
  216.                     break;
  217.             }
  218.  
  219.             switch(Config -> TerminalConfig -> ReceiveLF)
  220.             {
  221.                 case LF_IGNORE:
  222.  
  223.                     Config -> TerminalConfig -> ReceiveLF = EOL_IGNORE;
  224.                     break;
  225.  
  226.                 case LF_ASLF:
  227.  
  228.                     Config -> TerminalConfig -> ReceiveLF = EOL_LF;
  229.                     break;
  230.  
  231.                 case LF_ASLFCR:
  232.  
  233.                     Config -> TerminalConfig -> ReceiveLF = EOL_LFCR;
  234.                     break;
  235.             }
  236.         }
  237.  
  238.         if(ConfigChunkType == PREF_TRANSFER)
  239.         {
  240.             switch(Config -> TransferConfig -> SendCR)
  241.             {
  242.                 case CR_IGNORE:
  243.  
  244.                     Config -> TransferConfig -> SendCR = EOL_IGNORE;
  245.                     break;
  246.  
  247.                 case CR_ASCR:
  248.  
  249.                     Config -> TransferConfig -> SendCR = EOL_CR;
  250.                     break;
  251.  
  252.                 case CR_ASCRLF:
  253.  
  254.                     Config -> TransferConfig -> SendCR = EOL_CRLF;
  255.                     break;
  256.             }
  257.  
  258.             switch(Config -> TransferConfig -> ReceiveCR)
  259.             {
  260.                 case CR_IGNORE:
  261.  
  262.                     Config -> TransferConfig -> ReceiveCR = EOL_IGNORE;
  263.                     break;
  264.  
  265.                 case CR_ASCR:
  266.  
  267.                     Config -> TransferConfig -> ReceiveCR = EOL_CR;
  268.                     break;
  269.  
  270.                 case CR_ASCRLF:
  271.  
  272.                     Config -> TransferConfig -> ReceiveCR = EOL_CRLF;
  273.                     break;
  274.             }
  275.  
  276.             switch(Config -> TransferConfig -> SendLF)
  277.             {
  278.                 case LF_IGNORE:
  279.  
  280.                     Config -> TransferConfig -> SendLF = EOL_IGNORE;
  281.                     break;
  282.  
  283.                 case LF_ASLF:
  284.  
  285.                     Config -> TransferConfig -> SendLF = EOL_LF;
  286.                     break;
  287.  
  288.                 case LF_ASLFCR:
  289.  
  290.                     Config -> TransferConfig -> SendLF = EOL_LFCR;
  291.                     break;
  292.             }
  293.  
  294.             switch(Config -> TransferConfig -> ReceiveLF)
  295.             {
  296.                 case LF_IGNORE:
  297.  
  298.                     Config -> TransferConfig -> ReceiveLF = EOL_IGNORE;
  299.                     break;
  300.  
  301.                 case LF_ASLF:
  302.  
  303.                     Config -> TransferConfig -> ReceiveLF = EOL_LF;
  304.                     break;
  305.  
  306.                 case LF_ASLFCR:
  307.  
  308.                     Config -> TransferConfig -> ReceiveLF = EOL_LFCR;
  309.                     break;
  310.             }
  311.         }
  312.     }
  313. }
  314.  
  315. VOID __regargs
  316. FixScreenPens(struct ScreenSettings *ScreenConfig)
  317. {
  318.     WORD i,Count;
  319.  
  320.     for(Count = 0, i = DETAILPEN ; i <= BARTRIMPEN ; i++)
  321.     {
  322.         if(ScreenConfig -> PenArray[i])
  323.             Count++;
  324.     }
  325.  
  326.     if(!Count)
  327.         ScreenConfig -> UsePens = TRUE;
  328. }
  329.  
  330.     /* ReadSerialPrefs():
  331.      *
  332.      *    Reads the default serial preferences settings.
  333.      */
  334.  
  335. STATIC BYTE
  336. ReadSerialPrefs(struct SerialPrefs *Prefs)
  337. {
  338.     struct IFFHandle    *Handle;
  339.     BYTE             Success = FALSE;
  340.     LONG             Error = 0;
  341.  
  342.         /* Allocate an IFF handle. */
  343.  
  344.     if(Handle = AllocIFF())
  345.     {
  346.             /* Open the preferences settings file. */
  347.  
  348.         if(Handle -> iff_Stream = Open("ENV:sys/serial.prefs",MODE_OLDFILE))
  349.         {
  350.                 /* Make it known as a DOS file handle. */
  351.  
  352.             InitIFFasDOS(Handle);
  353.  
  354.                 /* Open the file for reading. */
  355.  
  356.             if(!(Error = OpenIFF(Handle,IFFF_READ)))
  357.             {
  358.                     /* Stop at the `body' chunk. */
  359.  
  360.                 if(!(Error = StopChunk(Handle,ID_PREF,ID_SERL)))
  361.                 {
  362.                         /* Look for it... */
  363.  
  364.                     if(!ParseIFF(Handle,IFFPARSE_SCAN))
  365.                     {
  366.                             /* Read the data. */
  367.  
  368.                         if(ReadChunkBytes(Handle,Prefs,sizeof(struct SerialPrefs)) == sizeof(struct SerialPrefs))
  369.                             Success = TRUE;
  370.                         else
  371.                             Error = IoErr();
  372.                     }
  373.                 }
  374.  
  375.                     /* Close the handle. */
  376.  
  377.                 CloseIFF(Handle);
  378.             }
  379.  
  380.                 /* Release the handle. */
  381.  
  382.             Close(Handle -> iff_Stream);
  383.         }
  384.         else
  385.             Error = IoErr();
  386.  
  387.             /* Clean up. */
  388.  
  389.         FreeIFF(Handle);
  390.     }
  391.     else
  392.         Error = ERR_NO_MEM;
  393.  
  394.     if(Error)
  395.         SetIoErr(Error);
  396.  
  397.         /* Return sucess/failure. */
  398.  
  399.     return(Success);
  400. }
  401.  
  402. STATIC VOID
  403. ResetSerialConfig(struct SerialSettings *SerialConfig)
  404. {
  405.     STATIC BYTE            SerialPrefsRead        = FALSE,
  406.                     SerialPrefsReadFailed    = FALSE;
  407.     STATIC struct SerialPrefs    SerialPrefs;
  408.  
  409.         /* The program will only try to read the preferences
  410.          * settings once; if the first access failed, no
  411.          * other accesses will be made.
  412.          */
  413.  
  414.     if(!SerialPrefsRead && !SerialPrefsReadFailed)
  415.         SerialPrefsReadFailed = ReadSerialPrefs(&SerialPrefs) ^ TRUE;
  416.  
  417.         /* Did we succeed in reading the file? */
  418.  
  419.     if(!SerialPrefsRead)
  420.     {
  421.         SerialConfig -> BaudRate        = 19200;
  422.         SerialConfig -> BitsPerChar        = 8;
  423.         SerialConfig -> Parity            = PARITY_NONE;
  424.         SerialConfig -> StopBits        = 1;
  425.         SerialConfig -> HandshakingProtocol    = HANDSHAKING_NONE;
  426.         SerialConfig -> xONxOFF            = TRUE;
  427.         SerialConfig -> SerialBufferSize    = 32768;
  428.     }
  429.     else
  430.     {
  431.             /* Fill in the common data. */
  432.  
  433.         SerialConfig -> BaudRate        = SerialPrefs . sp_BaudRate;
  434.         SerialConfig -> SerialBufferSize    = SerialPrefs . sp_InputBuffer;
  435.         SerialConfig -> BitsPerChar        = SerialPrefs . sp_BitsPerChar;
  436.         SerialConfig -> StopBits        = SerialPrefs . sp_StopBits;
  437.  
  438.             /* Convert the handshaking mode. */
  439.  
  440.         switch(SerialPrefs . sp_InputHandshake)
  441.         {
  442.             case HSHAKE_NONE:
  443.  
  444.                 SerialConfig -> HandshakingProtocol    = HANDSHAKING_NONE;
  445.                 SerialConfig -> xONxOFF            = FALSE;
  446.  
  447.                 break;
  448.  
  449.             case HSHAKE_RTS:
  450.  
  451.                 SerialConfig -> HandshakingProtocol    = HANDSHAKING_RTSCTS;
  452.                 SerialConfig -> xONxOFF            = FALSE;
  453.  
  454.                 break;
  455.  
  456.             default:
  457.  
  458.                 SerialConfig -> HandshakingProtocol    = HANDSHAKING_NONE;
  459.                 SerialConfig -> xONxOFF            = TRUE;
  460.  
  461.                 break;
  462.         }
  463.  
  464.             /* Convert the parity settings. */
  465.  
  466.         if(SerialPrefs . sp_Parity <= PARITY_SPACE)
  467.             SerialConfig -> Parity = SerialPrefs . sp_Parity;
  468.         else
  469.             SerialConfig -> Parity = PARITY_NONE;
  470.  
  471.         SerialPrefsRead = TRUE;
  472.     }
  473.  
  474.     strcpy(SerialConfig -> SerialDevice,SERIALNAME);
  475.  
  476.     SerialConfig -> Duplex        = DUPLEX_FULL;
  477.     SerialConfig -> HighSpeed    = FALSE;
  478.     SerialConfig -> Shared        = FALSE;
  479.     SerialConfig -> BreakLength    = 250000;
  480.     SerialConfig -> UnitNumber    = 0;
  481.     SerialConfig -> StripBit8    = FALSE;
  482.     SerialConfig -> CheckCarrier    = FALSE;
  483.     SerialConfig -> PassThrough    = FALSE;
  484.     SerialConfig -> IgnoreCarrier    = FALSE;
  485.  
  486.     SerialConfig -> Quantum        = 256;
  487.  
  488.     SerialConfig -> UseNet        = FALSE;
  489.     SerialConfig -> NetID        = 0002;
  490. }
  491.  
  492. STATIC VOID
  493. ResetModem(struct ModemSettings *ModemConfig)
  494. {
  495.     strcpy(ModemConfig -> ModemInit,    "ATZ\\r");
  496.     strcpy(ModemConfig -> ModemExit,    "");
  497.     strcpy(ModemConfig -> ModemHangup,    "~~~~~~~~+++~~~~~~ATH0\\r");
  498.     strcpy(ModemConfig -> DialPrefix,    "~~ATDP");
  499.     strcpy(ModemConfig -> DialSuffix,    "\\r");
  500.  
  501.     strcpy(ModemConfig -> NoCarrier,    "NO CARRIER");
  502.     strcpy(ModemConfig -> NoDialTone,    "NO DIALTONE");
  503.     strcpy(ModemConfig -> Connect,        "CONNECT");
  504.     strcpy(ModemConfig -> Voice,        "VOICE");
  505.     strcpy(ModemConfig -> Ring,        "RING");
  506.     strcpy(ModemConfig -> Busy,        "BUSY");
  507.     strcpy(ModemConfig -> Ok,        "OK");
  508.     strcpy(ModemConfig -> Error,        "ERROR");
  509.  
  510.     ModemConfig -> RedialDelay        = 20;
  511.     ModemConfig -> DialRetries        = 10;
  512.     ModemConfig -> DialTimeout        = 60;
  513.     ModemConfig -> ConnectAutoBaud        = FALSE;
  514.     ModemConfig -> DropDTR            = FALSE;
  515.     ModemConfig -> RedialAfterHangup    = FALSE;
  516.  
  517.     ModemConfig -> NoCarrierIsBusy        = TRUE;
  518.  
  519.     ModemConfig -> ConnectLimit        = 0;
  520.     ModemConfig -> ConnectLimitMacro[0]    = 0;
  521.  
  522.     ModemConfig -> TimeToConnect        = 0;
  523. }
  524.  
  525. STATIC VOID
  526. ResetScreen(struct ScreenSettings *ScreenConfig)
  527. {
  528.     memset(ScreenConfig,0,sizeof(struct ScreenSettings));
  529.  
  530.     ScreenConfig -> DisplayMode        = DEFAULT_MONITOR_ID | HIRESLACE_KEY;
  531.     ScreenConfig -> ColourMode        = COLOUR_AMIGA;
  532.     ScreenConfig -> MakeScreenPublic    = TRUE;
  533.     ScreenConfig -> ShanghaiWindows        = FALSE;
  534.     ScreenConfig -> TitleBar        = TRUE;
  535.     ScreenConfig -> StatusLine        = STATUSLINE_STANDARD;
  536.     ScreenConfig -> Blinking        = TRUE;
  537.     ScreenConfig -> FasterLayout        = FALSE;
  538.     ScreenConfig -> UseWorkbench        = FALSE;
  539.  
  540.     strcpy(ScreenConfig -> FontName,"topaz.font");
  541.     ScreenConfig -> FontHeight = 8;
  542.  
  543.     ScreenConfig -> PubScreenName[0]    = 0;
  544.     ScreenConfig -> TimeMode        = ONLINETIME_BOTH;
  545.     ScreenConfig -> UsePens            = TRUE;
  546.     ScreenConfig -> PenColourMode        = COLOUR_AMIGA;
  547.  
  548.     ScreenConfig -> DisplayWidth        = 0;
  549.     ScreenConfig -> DisplayHeight        = 0;
  550.     ScreenConfig -> OverscanType        = OSCAN_TEXT;
  551.  
  552.     ScreenConfig -> ShareScreen        = FALSE;
  553.     ScreenConfig -> SplitStatus        = FALSE;
  554. }
  555.  
  556. STATIC VOID
  557. ResetTerminal(struct TerminalSettings *TerminalConfig)
  558. {
  559.     TerminalConfig -> BellMode        = BELL_AUDIBLE;
  560.     TerminalConfig -> AlertMode        = ALERT_BEEP_SCREEN;
  561.     TerminalConfig -> EmulationMode        = EMULATION_ANSIVT100;
  562.     TerminalConfig -> FontMode        = FONT_STANDARD;
  563.  
  564.     TerminalConfig -> SendCR        = EOL_CR;
  565.     TerminalConfig -> SendLF        = EOL_LF;
  566.     TerminalConfig -> ReceiveCR        = EOL_CR;
  567.     TerminalConfig -> ReceiveLF        = EOL_LF;
  568.  
  569.     TerminalConfig -> NumColumns        = 0;
  570.     TerminalConfig -> NumLines        = 0;
  571.  
  572.     TerminalConfig -> KeyMapFileName[0]    = 0;
  573.     TerminalConfig -> EmulationFileName[0]    = 0;
  574.     TerminalConfig -> BeepFileName[0]    = 0;
  575.  
  576.     strcpy(TerminalConfig -> TextFontName,"topaz.font");
  577.     TerminalConfig -> TextFontHeight = 8;
  578.  
  579.     TerminalConfig -> UseTerminalTask = FALSE;
  580.     TerminalConfig -> Pad = 0;
  581.  
  582.     strcpy(TerminalConfig -> IBMFontName,"IBM.font");
  583.     TerminalConfig -> IBMFontHeight = 8;
  584. }
  585.  
  586. STATIC VOID
  587. ResetEmulation(struct EmulationSettings *EmulationConfig)
  588. {
  589.     EmulationConfig -> CursorMode        = KEYMODE_STANDARD;
  590.     EmulationConfig -> NumericMode        = KEYMODE_STANDARD;
  591.  
  592.     EmulationConfig -> NewLineMode        = FALSE;
  593.     EmulationConfig -> InsertMode        = FALSE;
  594.  
  595.     EmulationConfig -> LineWrap        = TRUE;
  596.     EmulationConfig -> CursorWrap        = FALSE;
  597.  
  598.     EmulationConfig -> FontScale        = SCALE_NORMAL;
  599.     EmulationConfig -> ScrollMode        = SCROLL_JUMP;
  600.     EmulationConfig -> DestructiveBackspace    = FALSE;
  601.     EmulationConfig -> SwapBSDelete        = FALSE;
  602.     EmulationConfig -> PrinterEnabled    = TRUE;
  603.     EmulationConfig -> AnswerBack[0]    = 0;
  604.     EmulationConfig -> CLSResetsCursor    = 0;
  605.  
  606.     EmulationConfig -> KeysLocked        = FALSE;
  607.     EmulationConfig -> MaxScroll        = 0;
  608.     EmulationConfig -> MaxJump        = 1;
  609.     EmulationConfig -> CursorLocked        = FALSE;
  610.     EmulationConfig -> FontLocked        = FALSE;
  611.     EmulationConfig -> Pad            = 0;
  612. }
  613.  
  614. STATIC VOID
  615. ResetClip(struct ClipSettings *ClipConfig)
  616. {
  617.     ClipConfig -> ClipboardUnit    = 0;
  618.     ClipConfig -> LineDelay        = 0;
  619.     ClipConfig -> CharDelay        = 0;
  620.  
  621.     ClipConfig -> InsertPrefix[0] = 0;
  622.     strcpy(ClipConfig -> InsertSuffix,"\\r");
  623.  
  624.     ClipConfig -> LinePrompt[0]    = 0;
  625.     ClipConfig -> SendTimeout    = 0;
  626.     ClipConfig -> PacingMode    = PACE_DIRECT;
  627. }
  628.  
  629. STATIC VOID
  630. ResetCapture(struct CaptureSettings *CaptureConfig)
  631. {
  632.     CaptureConfig -> LogActions        = FALSE;
  633.     CaptureConfig -> LogCall        = FALSE;
  634.     CaptureConfig -> LogFileName[0]        = 0;
  635.  
  636.     CaptureConfig -> MaxBufferSize        = 0;
  637.     CaptureConfig -> BufferEnabled        = TRUE;
  638.  
  639.     CaptureConfig -> ConnectAutoCapture    = FALSE;
  640.     CaptureConfig -> CaptureFilterMode    = FILTER_BOTH;
  641.     CaptureConfig -> CapturePath[0]        = 0;
  642.  
  643.     CaptureConfig -> CallLogFileName[0]    = 0;
  644.     CaptureConfig -> BufferPath[0]        = 0;
  645.  
  646.     CaptureConfig -> AutoCaptureDate    = AUTOCAPTURE_DATE_NAME;
  647.     CaptureConfig -> SearchHistory        = 10;
  648.  
  649.     CaptureConfig -> OpenBufferWindow    = BUFFER_END;
  650.     CaptureConfig -> OpenBufferScreen    = BUFFER_TOP;
  651.     CaptureConfig -> BufferScreenPosition    = SCREEN_CENTRE;
  652.     CaptureConfig -> BufferWidth        = 80;
  653.  
  654.     CaptureConfig -> RememberBufferWindow    = FALSE;
  655.     CaptureConfig -> RememberBufferScreen    = FALSE;
  656.  
  657.     CaptureConfig -> BufferScreenMode    = INVALID_ID;
  658. }
  659.  
  660. STATIC VOID
  661. ResetFile(struct FileSettings *FileConfig,STRPTR PathBuffer)
  662. {
  663.     if(!PathBuffer)
  664.         PathBuffer = "TERM:config";
  665.  
  666.     strcpy(FileConfig -> ProtocolFileName,"xprzmodem.library");
  667.  
  668.     if(!LastTranslation[0])
  669.     {
  670.         strcpy(LastTranslation,PathBuffer);
  671.  
  672.         AddPart(LastTranslation,"translation.prefs",MAX_FILENAME_LENGTH);
  673.     }
  674.  
  675.     strcpy(FileConfig -> TranslationFileName,LastTranslation);
  676.  
  677.     if(!LastMacros[0])
  678.     {
  679.         strcpy(LastMacros,PathBuffer);
  680.  
  681.         AddPart(LastMacros,"functionkeys.prefs",MAX_FILENAME_LENGTH);
  682.     }
  683.  
  684.     strcpy(FileConfig -> MacroFileName,LastMacros);
  685.  
  686.     if(!LastFastMacros[0])
  687.     {
  688.         strcpy(LastFastMacros,PathBuffer);
  689.  
  690.         AddPart(LastFastMacros,"fastmacros.prefs",MAX_FILENAME_LENGTH);
  691.     }
  692.  
  693.     strcpy(FileConfig -> FastMacroFileName,LastFastMacros);
  694.  
  695.     if(!LastCursorKeys[0])
  696.     {
  697.         strcpy(LastCursorKeys,PathBuffer);
  698.  
  699.         AddPart(LastCursorKeys,"cursorkeys.prefs",MAX_FILENAME_LENGTH);
  700.     }
  701.  
  702.     strcpy(FileConfig -> CursorFileName,LastCursorKeys);
  703. }
  704.  
  705. STATIC VOID
  706. ResetPath(struct PathSettings *PathConfig,STRPTR PathBuffer)
  707. {
  708.     if(!PathBuffer)
  709.         PathBuffer = "TERM:config";
  710.  
  711.     strcpy(PathConfig -> DefaultStorage,PathBuffer);
  712.  
  713.     PathConfig -> ASCIIUploadPath[0]    = 0;
  714.     PathConfig -> ASCIIDownloadPath[0]    = 0;
  715.     PathConfig -> TextUploadPath[0]        = 0;
  716.     PathConfig -> TextDownloadPath[0]    = 0;
  717.     PathConfig -> BinaryUploadPath[0]    = 0;
  718.     PathConfig -> BinaryDownloadPath[0]    = 0;
  719.  
  720.     strcpy(PathConfig -> HelpFile,"PROGDIR:term.guide");
  721.  
  722.     strcpy(PathConfig -> DefaultStorage,PathBuffer);
  723.  
  724.     GetEnvDOS(PathConfig -> Editor,"EDITOR");
  725. }
  726.  
  727. STATIC VOID
  728. ResetMisc(struct MiscSettings *MiscConfig)
  729. {
  730.     MiscConfig -> Priority            = 1;
  731.     MiscConfig -> BackupConfig        = FALSE;
  732.  
  733.     MiscConfig -> OpenFastMacroPanel    = FALSE;
  734.     MiscConfig -> ReleaseDevice        = TRUE;
  735.  
  736.     MiscConfig -> TransferServer        = TRUE;
  737.     MiscConfig -> EmulationServer        = TRUE;
  738.  
  739.     MiscConfig -> OverridePath        = TRUE;
  740.     MiscConfig -> AutoUpload        = TRUE;
  741.     MiscConfig -> SetArchivedBit        = FALSE;
  742.     MiscConfig -> IdentifyFiles        = IDENTIFY_FILETYPE;
  743.     MiscConfig -> TransferIcons        = FALSE;
  744.     MiscConfig -> CreateIcons        = FALSE;
  745.     MiscConfig -> SimpleIO            = FALSE;
  746.     MiscConfig -> PerfMeter            = FALSE;
  747.  
  748.     MiscConfig -> IOBufferSize        = 32768;
  749.     MiscConfig -> HideUploadIcon        = FALSE;
  750. }
  751.  
  752. STATIC VOID
  753. ResetCommand(struct CommandSettings *CommandConfig)
  754. {
  755.     CommandConfig -> StartupMacro[0]    = 0;
  756.     CommandConfig -> LogoffMacro[0]        = 0;
  757.     CommandConfig -> LoginMacro[0]        = 0;
  758.     CommandConfig -> UploadMacro[0]        = 0;
  759.     CommandConfig -> DownloadMacro[0]    = 0;
  760. }
  761.  
  762. STATIC VOID
  763. ResetTransfer(struct TransferSettings *TransferConfig,STRPTR DefaultLib)
  764. {
  765.     if(!DefaultLib)
  766.         strcpy(TransferConfig -> DefaultLibrary,"xprzmodem.library");
  767.     else
  768.         strcpy(TransferConfig -> DefaultLibrary,DefaultLib);
  769.  
  770.     strcpy(TransferConfig -> ASCIIUploadLibrary,    "xprascii.library");
  771.     strcpy(TransferConfig -> ASCIIDownloadLibrary,    "xprascii.library");
  772.  
  773.     TransferConfig -> TextUploadLibrary[0]        = 0;
  774.     TransferConfig -> TextDownloadLibrary[0]    = 0;
  775.  
  776.     TransferConfig -> BinaryUploadLibrary[0]    = 0;
  777.     TransferConfig -> BinaryDownloadLibrary[0]    = 0;
  778.  
  779.     TransferConfig -> InternalASCIIUpload        = FALSE;
  780.     TransferConfig -> InternalASCIIDownload        = FALSE;
  781.     TransferConfig -> QuietTransfer            = FALSE;
  782.     TransferConfig -> MangleFileNames        = FALSE;
  783.  
  784.     TransferConfig -> LinePrompt[0]            = 0;
  785.     TransferConfig -> SendTimeout            = 0;
  786.     TransferConfig -> PacingMode            = PACE_DIRECT;
  787.     TransferConfig -> StripBit8            = FALSE;
  788.     TransferConfig -> IgnoreDataPastArnold        = TRUE;
  789.     TransferConfig -> TerminatorChar        = 0x1A;
  790.     TransferConfig -> SendCR            = EOL_CR;
  791.     TransferConfig -> SendLF            = EOL_LF;
  792.     TransferConfig -> ReceiveCR            = EOL_CR;
  793.     TransferConfig -> ReceiveLF            = EOL_LF;
  794. }
  795.  
  796.     /* ResetConfig():
  797.      *
  798.      *    Initialize configuration with default values.
  799.      */
  800.  
  801. VOID __regargs
  802. ResetConfig(struct Configuration *Config,STRPTR PathBuffer)
  803. {
  804.     if(!PathBuffer)
  805.         PathBuffer = "TERM:config";
  806.  
  807.     ResetPath(Config -> PathConfig,PathBuffer);
  808.     ResetFile(Config -> FileConfig,PathBuffer);
  809.  
  810.     ResetSerialConfig(Config -> SerialConfig);
  811.     ResetModem(Config -> ModemConfig);
  812.     ResetScreen(Config -> ScreenConfig);
  813.     ResetTerminal(Config -> TerminalConfig);
  814.     ResetEmulation(Config -> EmulationConfig);
  815.     ResetClip(Config -> ClipConfig);
  816.     ResetCapture(Config -> CaptureConfig);
  817.     ResetMisc(Config -> MiscConfig);
  818.     ResetCommand(Config -> CommandConfig);
  819.     ResetTransfer(Config -> TransferConfig,Config -> FileConfig -> ProtocolFileName);
  820. }
  821.  
  822. VOID __regargs
  823. DeleteConfigEntry(struct Configuration *Config,BYTE Type)
  824. {
  825.     if(Type == PREF_ALL)
  826.     {
  827.         for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  828.             DeleteConfigEntry(Config,Type);
  829.     }
  830.     else
  831.     {
  832.         switch(Type)
  833.         {
  834.             case PREF_SERIAL:
  835.  
  836.                 if(Config -> SerialConfig)
  837.                 {
  838.                     FreeVecPooled(Config -> SerialConfig);
  839.  
  840.                     Config -> SerialConfig = NULL;
  841.                 }
  842.  
  843.                 break;
  844.  
  845.             case PREF_MODEM:
  846.  
  847.                 if(Config -> ModemConfig)
  848.                 {
  849.                     FreeVecPooled(Config -> ModemConfig);
  850.  
  851.                     Config -> ModemConfig = NULL;
  852.                 }
  853.  
  854.                 break;
  855.  
  856.             case PREF_COMMAND:
  857.  
  858.                 if(Config -> CommandConfig)
  859.                 {
  860.                     FreeVecPooled(Config -> CommandConfig);
  861.  
  862.                     Config -> CommandConfig = NULL;
  863.                 }
  864.  
  865.                 break;
  866.  
  867.             case PREF_SCREEN:
  868.  
  869.                 if(Config -> ScreenConfig)
  870.                 {
  871.                     FreeVecPooled(Config -> ScreenConfig);
  872.  
  873.                     Config -> ScreenConfig = NULL;
  874.                 }
  875.  
  876.                 break;
  877.  
  878.             case PREF_TERMINAL:
  879.  
  880.                 if(Config -> TerminalConfig)
  881.                 {
  882.                     FreeVecPooled(Config -> TerminalConfig);
  883.  
  884.                     Config -> TerminalConfig = NULL;
  885.                 }
  886.  
  887.                 break;
  888.  
  889.             case PREF_PATH:
  890.  
  891.                 if(Config -> PathConfig)
  892.                 {
  893.                     FreeVecPooled(Config -> PathConfig);
  894.  
  895.                     Config -> PathConfig = NULL;
  896.                 }
  897.  
  898.                 break;
  899.  
  900.             case PREF_MISC:
  901.  
  902.                 if(Config -> MiscConfig)
  903.                 {
  904.                     FreeVecPooled(Config -> MiscConfig);
  905.  
  906.                     Config -> MiscConfig = NULL;
  907.                 }
  908.  
  909.                 break;
  910.  
  911.             case PREF_CLIP:
  912.  
  913.                 if(Config -> ClipConfig)
  914.                 {
  915.                     FreeVecPooled(Config -> ClipConfig);
  916.  
  917.                     Config -> ClipConfig = NULL;
  918.                 }
  919.  
  920.                 break;
  921.  
  922.             case PREF_CAPTURE:
  923.  
  924.                 if(Config -> CaptureConfig)
  925.                 {
  926.                     FreeVecPooled(Config -> CaptureConfig);
  927.  
  928.                     Config -> CaptureConfig = NULL;
  929.                 }
  930.  
  931.                 break;
  932.  
  933.             case PREF_FILE:
  934.  
  935.                 if(Config -> FileConfig)
  936.                 {
  937.                     FreeVecPooled(Config -> FileConfig);
  938.  
  939.                     Config -> FileConfig = NULL;
  940.                 }
  941.  
  942.                 break;
  943.  
  944.             case PREF_EMULATION:
  945.  
  946.                 if(Config -> EmulationConfig)
  947.                 {
  948.                     FreeVecPooled(Config -> EmulationConfig);
  949.  
  950.                     Config -> EmulationConfig = NULL;
  951.                 }
  952.  
  953.                 break;
  954.  
  955.             case PREF_TRANSFER:
  956.  
  957.                 if(Config -> TransferConfig)
  958.                 {
  959.                     FreeVecPooled(Config -> TransferConfig);
  960.  
  961.                     Config -> TransferConfig = NULL;
  962.                 }
  963.  
  964.                 break;
  965.         }
  966.     }
  967. }
  968.  
  969. VOID __regargs
  970. ResetConfigEntry(struct Configuration *Configuration,BYTE Type,BYTE Default)
  971. {
  972.     if(Type == PREF_ALL)
  973.     {
  974.         for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  975.             ResetConfigEntry(Configuration,Type,Default);
  976.     }
  977.     else
  978.     {
  979.         switch(Type)
  980.         {
  981.             case PREF_SERIAL:
  982.  
  983.                 if(Default || !Config -> SerialConfig)
  984.                     ResetSerialConfig(Configuration -> SerialConfig);
  985.                 else
  986.                     memcpy(Configuration -> SerialConfig,Config -> SerialConfig,sizeof(struct SerialSettings));
  987.  
  988.                 break;
  989.  
  990.             case PREF_MODEM:
  991.  
  992.                 if(Default || !Config -> ModemConfig)
  993.                     ResetModem(Configuration -> ModemConfig);
  994.                 else
  995.                     memcpy(Configuration -> ModemConfig,Config -> ModemConfig,sizeof(struct ModemSettings));
  996.  
  997.                 break;
  998.  
  999.             case PREF_COMMAND:
  1000.  
  1001.                 if(Default || !Config -> CommandConfig)
  1002.                     ResetCommand(Configuration -> CommandConfig);
  1003.                 else
  1004.                     memcpy(Configuration -> CommandConfig,Config -> CommandConfig,sizeof(struct CommandSettings));
  1005.  
  1006.                 break;
  1007.  
  1008.             case PREF_SCREEN:
  1009.  
  1010.                 if(Default || !Config -> ScreenConfig)
  1011.                     ResetScreen(Configuration -> ScreenConfig);
  1012.                 else
  1013.                     memcpy(Configuration -> ScreenConfig,Config -> ScreenConfig,sizeof(struct ScreenSettings));
  1014.  
  1015.                 FixScreenPens(Configuration -> ScreenConfig);
  1016.  
  1017.                 break;
  1018.  
  1019.             case PREF_TERMINAL:
  1020.  
  1021.                 if(Default || !Config -> TerminalConfig)
  1022.                     ResetTerminal(Configuration -> TerminalConfig);
  1023.                 else
  1024.                     memcpy(Configuration -> TerminalConfig,Config -> TerminalConfig,sizeof(struct TerminalSettings));
  1025.  
  1026.                 break;
  1027.  
  1028.             case PREF_PATH:
  1029.  
  1030.                 if(Default || !Config -> PathConfig)
  1031.                     ResetPath(Configuration -> PathConfig,NULL);
  1032.                 else
  1033.                     memcpy(Configuration -> PathConfig,Config -> PathConfig,sizeof(struct PathSettings));
  1034.  
  1035.                 break;
  1036.  
  1037.             case PREF_MISC:
  1038.  
  1039.                 if(Default || !Config -> MiscConfig)
  1040.                     ResetMisc(Configuration -> MiscConfig);
  1041.                 else
  1042.                     memcpy(Configuration -> MiscConfig,Config -> MiscConfig,sizeof(struct MiscSettings));
  1043.  
  1044.                 break;
  1045.  
  1046.             case PREF_CLIP:
  1047.  
  1048.                 if(Default || !Config -> ClipConfig)
  1049.                     ResetClip(Configuration -> ClipConfig);
  1050.                 else
  1051.                     memcpy(Configuration -> ClipConfig,Config -> ClipConfig,sizeof(struct ClipSettings));
  1052.  
  1053.                 break;
  1054.  
  1055.             case PREF_CAPTURE:
  1056.  
  1057.                 if(Default || !Config -> CaptureConfig)
  1058.                     ResetCapture(Configuration -> CaptureConfig);
  1059.                 else
  1060.                     memcpy(Configuration -> CaptureConfig,Config -> CaptureConfig,sizeof(struct CaptureSettings));
  1061.  
  1062.                 break;
  1063.  
  1064.             case PREF_FILE:
  1065.  
  1066.                 if(Default || !Config -> FileConfig)
  1067.                     ResetFile(Configuration -> FileConfig,NULL);
  1068.                 else
  1069.                     memcpy(Configuration -> FileConfig,Config -> FileConfig,sizeof(struct FileSettings));
  1070.  
  1071.                 break;
  1072.  
  1073.             case PREF_EMULATION:
  1074.  
  1075.                 if(Default || !Config -> EmulationConfig)
  1076.                     ResetEmulation(Configuration -> EmulationConfig);
  1077.                 else
  1078.                     memcpy(Configuration -> EmulationConfig,Config -> EmulationConfig,sizeof(struct EmulationSettings));
  1079.  
  1080.                 break;
  1081.  
  1082.             case PREF_TRANSFER:
  1083.  
  1084.                 if(Default || !Config -> TransferConfig)
  1085.                     ResetTransfer(Configuration -> TransferConfig,Config -> FileConfig -> ProtocolFileName);
  1086.                 else
  1087.                     memcpy(Configuration -> TransferConfig,Config -> TransferConfig,sizeof(struct TransferSettings));
  1088.  
  1089.                 break;
  1090.         }
  1091.     }
  1092. }
  1093.  
  1094. APTR __regargs
  1095. GetConfigEntry(struct Configuration *Config,BYTE Type)
  1096. {
  1097.     switch(Type)
  1098.     {
  1099.         case PREF_SERIAL:
  1100.  
  1101.             return(Config -> SerialConfig);
  1102.  
  1103.         case PREF_MODEM:
  1104.  
  1105.             return(Config -> ModemConfig);
  1106.  
  1107.         case PREF_COMMAND:
  1108.  
  1109.             return(Config -> CommandConfig);
  1110.  
  1111.         case PREF_SCREEN:
  1112.  
  1113.             return(Config -> ScreenConfig);
  1114.  
  1115.         case PREF_TERMINAL:
  1116.  
  1117.             return(Config -> TerminalConfig);
  1118.  
  1119.         case PREF_PATH:
  1120.  
  1121.             return(Config -> PathConfig);
  1122.  
  1123.         case PREF_MISC:
  1124.  
  1125.             return(Config -> MiscConfig);
  1126.  
  1127.         case PREF_CLIP:
  1128.  
  1129.             return(Config -> ClipConfig);
  1130.  
  1131.         case PREF_CAPTURE:
  1132.  
  1133.             return(Config -> CaptureConfig);
  1134.  
  1135.         case PREF_FILE:
  1136.  
  1137.             return(Config -> FileConfig);
  1138.  
  1139.         case PREF_EMULATION:
  1140.  
  1141.             return(Config -> EmulationConfig);
  1142.  
  1143.         case PREF_TRANSFER:
  1144.  
  1145.             return(Config -> TransferConfig);
  1146.  
  1147.         default:
  1148.  
  1149.             return(NULL);
  1150.     }
  1151. }
  1152.  
  1153. BYTE __regargs
  1154. CreateConfigEntry(struct Configuration *Config,BYTE Type)
  1155. {
  1156.     if(Type == PREF_ALL)
  1157.     {
  1158.         for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1159.         {
  1160.             if(!CreateConfigEntry(Config,Type))
  1161.             {
  1162.                 DeleteConfigEntry(Config,PREF_ALL);
  1163.  
  1164.                 return(FALSE);
  1165.             }
  1166.         }
  1167.  
  1168.         return(TRUE);
  1169.     }
  1170.     else
  1171.     {
  1172.         APTR Data;
  1173.  
  1174.         switch(Type)
  1175.         {
  1176.             case PREF_SERIAL:
  1177.  
  1178.                 Data = Config -> SerialConfig;
  1179.                 break;
  1180.  
  1181.             case PREF_MODEM:
  1182.  
  1183.                 Data = Config -> ModemConfig;
  1184.                 break;
  1185.  
  1186.             case PREF_COMMAND:
  1187.  
  1188.                 Data = Config -> CommandConfig;
  1189.                 break;
  1190.  
  1191.             case PREF_SCREEN:
  1192.  
  1193.                 Data = Config -> ScreenConfig;
  1194.                 break;
  1195.  
  1196.             case PREF_TERMINAL:
  1197.  
  1198.                 Data = Config -> TerminalConfig;
  1199.                 break;
  1200.  
  1201.             case PREF_PATH:
  1202.  
  1203.                 Data = Config -> PathConfig;
  1204.                 break;
  1205.  
  1206.             case PREF_MISC:
  1207.  
  1208.                 Data = Config -> MiscConfig;
  1209.                 break;
  1210.  
  1211.             case PREF_CLIP:
  1212.  
  1213.                 Data = Config -> ClipConfig;
  1214.                 break;
  1215.  
  1216.             case PREF_CAPTURE:
  1217.  
  1218.                 Data = Config -> CaptureConfig;
  1219.                 break;
  1220.  
  1221.             case PREF_FILE:
  1222.  
  1223.                 Data = Config -> FileConfig;
  1224.                 break;
  1225.  
  1226.             case PREF_EMULATION:
  1227.  
  1228.                 Data = Config -> EmulationConfig;
  1229.                 break;
  1230.  
  1231.             case PREF_TRANSFER:
  1232.  
  1233.                 Data = Config -> TransferConfig;
  1234.                 break;
  1235.  
  1236.             default:
  1237.  
  1238.                 return(FALSE);
  1239.         }
  1240.  
  1241.         if(!Data)
  1242.         {
  1243.             if(Data = AllocVecPooled(SizeTable[Type - 1],MEMF_ANY | MEMF_CLEAR))
  1244.             {
  1245.                 (*ResetTable[Type - 1])(Data,NULL);
  1246.  
  1247.                 switch(Type)
  1248.                 {
  1249.                     case PREF_SERIAL:
  1250.  
  1251.                         Config -> SerialConfig        = Data;
  1252.                         break;
  1253.  
  1254.                     case PREF_MODEM:
  1255.  
  1256.                         Config -> ModemConfig        = Data;
  1257.                         break;
  1258.  
  1259.                     case PREF_COMMAND:
  1260.  
  1261.                         Config -> CommandConfig        = Data;
  1262.                         break;
  1263.  
  1264.                     case PREF_SCREEN:
  1265.  
  1266.                         Config -> ScreenConfig        = Data;
  1267.                         break;
  1268.  
  1269.                     case PREF_TERMINAL:
  1270.  
  1271.                         Config -> TerminalConfig    = Data;
  1272.                         break;
  1273.  
  1274.                     case PREF_PATH:
  1275.  
  1276.                         Config -> PathConfig        = Data;
  1277.                         break;
  1278.  
  1279.                     case PREF_MISC:
  1280.  
  1281.                         Config -> MiscConfig        = Data;
  1282.                         break;
  1283.  
  1284.                     case PREF_CLIP:
  1285.  
  1286.                         Config -> ClipConfig        = Data;
  1287.                         break;
  1288.  
  1289.                     case PREF_CAPTURE:
  1290.  
  1291.                         Config -> CaptureConfig        = Data;
  1292.                         break;
  1293.  
  1294.                     case PREF_FILE:
  1295.  
  1296.                         Config -> FileConfig        = Data;
  1297.                         break;
  1298.  
  1299.                     case PREF_EMULATION:
  1300.  
  1301.                         Config -> EmulationConfig    = Data;
  1302.                         break;
  1303.  
  1304.                     case PREF_TRANSFER:
  1305.  
  1306.                         Config -> TransferConfig    = Data;
  1307.                         break;
  1308.                 }
  1309.  
  1310.                 return(TRUE);
  1311.             }
  1312.             else
  1313.                 return(FALSE);
  1314.         }
  1315.         else
  1316.             return(TRUE);
  1317.     }
  1318. }
  1319.  
  1320. VOID __regargs
  1321. DeleteConfiguration(struct Configuration *Config)
  1322. {
  1323.     if(Config)
  1324.     {
  1325.         DeleteConfigEntry(Config,PREF_ALL);
  1326.  
  1327.         FreeVecPooled(Config);
  1328.     }
  1329. }
  1330.  
  1331. struct Configuration * __regargs
  1332. CreateConfiguration(BYTE Fill)
  1333. {
  1334.     struct Configuration *Config;
  1335.  
  1336.     if(Config = (struct Configuration *)AllocVecPooled(sizeof(struct Configuration),MEMF_ANY | MEMF_CLEAR))
  1337.     {
  1338.         if(Fill)
  1339.         {
  1340.             if(!CreateConfigEntry(Config,PREF_ALL))
  1341.             {
  1342.                 FreeVecPooled(Config);
  1343.  
  1344.                 return(NULL);
  1345.             }
  1346.         }
  1347.  
  1348.         return(Config);
  1349.     }
  1350.     else
  1351.         return(NULL);
  1352. }
  1353.  
  1354. STATIC BYTE
  1355. WriteConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,BYTE Type,APTR TempBuffer,STRPTR Password)
  1356. {
  1357.     APTR Data;
  1358.  
  1359.     switch(Type)
  1360.     {
  1361.         case PREF_SERIAL:
  1362.  
  1363.             Data = Config -> SerialConfig;
  1364.             break;
  1365.  
  1366.         case PREF_MODEM:
  1367.  
  1368.             Data = Config -> ModemConfig;
  1369.             break;
  1370.  
  1371.         case PREF_COMMAND:
  1372.  
  1373.             Data = Config -> CommandConfig;
  1374.             break;
  1375.  
  1376.         case PREF_SCREEN:
  1377.  
  1378.             Data = Config -> ScreenConfig;
  1379.             break;
  1380.  
  1381.         case PREF_TERMINAL:
  1382.  
  1383.             Data = Config -> TerminalConfig;
  1384.             break;
  1385.  
  1386.         case PREF_PATH:
  1387.  
  1388.             Data = Config -> PathConfig;
  1389.             break;
  1390.  
  1391.         case PREF_MISC:
  1392.  
  1393.             Data = Config -> MiscConfig;
  1394.             break;
  1395.  
  1396.         case PREF_CLIP:
  1397.  
  1398.             Data = Config -> ClipConfig;
  1399.             break;
  1400.  
  1401.         case PREF_CAPTURE:
  1402.  
  1403.             Data = Config -> CaptureConfig;
  1404.             break;
  1405.  
  1406.         case PREF_FILE:
  1407.  
  1408.             Data = Config -> FileConfig;
  1409.             break;
  1410.  
  1411.         case PREF_EMULATION:
  1412.  
  1413.             Data = Config -> EmulationConfig;
  1414.             break;
  1415.  
  1416.         case PREF_TRANSFER:
  1417.  
  1418.             Data = Config -> TransferConfig;
  1419.             break;
  1420.  
  1421.         default:
  1422.  
  1423.             Data = NULL;
  1424.             break;
  1425.     }
  1426.  
  1427.     if(Data)
  1428.     {
  1429.         if(TempBuffer)
  1430.         {
  1431.             Encrypt(Data,SizeTable[Type - 1],TempBuffer,Password,20);
  1432.  
  1433.             Data = TempBuffer;
  1434.         }
  1435.  
  1436.         if(!PushChunk(Handle,0,TypeTable[Type - 1],SizeTable[Type - 1]))
  1437.         {
  1438.             if(WriteChunkRecords(Handle,Data,SizeTable[Type - 1],1) == 1)
  1439.             {
  1440.                 if(!PopChunk(Handle))
  1441.                     return(TRUE);
  1442.             }
  1443.         }
  1444.  
  1445.         return(FALSE);
  1446.     }
  1447.     else
  1448.         return(TRUE);
  1449. }
  1450.  
  1451. STATIC UBYTE
  1452. IsConfigChunk(ULONG ID)
  1453. {
  1454.     UBYTE Type;
  1455.  
  1456.     for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1457.     {
  1458.         if(ID == TypeTable[Type - 1])
  1459.             return(Type);
  1460.     }
  1461.  
  1462.     return(0);
  1463. }
  1464.  
  1465. STATIC BYTE
  1466. WriteConfigChunks(struct IFFHandle *Handle,struct Configuration *Config,APTR TempBuffer,STRPTR Password)
  1467. {
  1468.     UBYTE Type;
  1469.  
  1470.     for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1471.     {
  1472.         if(!WriteConfigChunk(Handle,Config,Type,TempBuffer,Password))
  1473.             return(FALSE);
  1474.     }
  1475.  
  1476.     return(TRUE);
  1477. }
  1478.  
  1479. VOID __regargs
  1480. SaveConfig(struct Configuration *Src,struct Configuration *Dst)
  1481. {
  1482.     if(Dst -> SerialConfig && Src -> SerialConfig)
  1483.         memcpy(Dst -> SerialConfig,Src -> SerialConfig,sizeof(struct SerialSettings));
  1484.  
  1485.     if(Dst -> ModemConfig && Src -> ModemConfig)
  1486.         memcpy(Dst -> ModemConfig,Src -> ModemConfig,sizeof(struct ModemSettings));
  1487.  
  1488.     if(Dst -> ScreenConfig && Src -> ScreenConfig)
  1489.     {
  1490.         memcpy(Dst -> ScreenConfig,Src -> ScreenConfig,sizeof(struct ScreenSettings));
  1491.  
  1492.         FixScreenPens(Dst -> ScreenConfig);
  1493.     }
  1494.  
  1495.     if(Dst -> TerminalConfig && Src -> TerminalConfig)
  1496.         memcpy(Dst -> TerminalConfig,Src -> TerminalConfig,sizeof(struct TerminalSettings));
  1497.  
  1498.     if(Dst -> EmulationConfig && Src -> EmulationConfig)
  1499.         memcpy(Dst -> EmulationConfig,Src -> EmulationConfig,sizeof(struct EmulationSettings));
  1500.  
  1501.     if(Dst -> ClipConfig && Src -> ClipConfig)
  1502.         memcpy(Dst -> ClipConfig,Src -> ClipConfig,sizeof(struct ClipSettings));
  1503.  
  1504.     if(Dst -> CaptureConfig && Src -> CaptureConfig)
  1505.         memcpy(Dst -> CaptureConfig,Src -> CaptureConfig,sizeof(struct CaptureSettings));
  1506.  
  1507.     if(Dst -> CommandConfig && Src -> CommandConfig)
  1508.         memcpy(Dst -> CommandConfig,Src -> CommandConfig,sizeof(struct CommandSettings));
  1509.  
  1510.     if(Dst -> MiscConfig && Src -> MiscConfig)
  1511.         memcpy(Dst -> MiscConfig,Src -> MiscConfig,sizeof(struct MiscSettings));
  1512.  
  1513.     if(Dst -> PathConfig && Src -> PathConfig)
  1514.         memcpy(Dst -> PathConfig,Src -> PathConfig,sizeof(struct PathSettings));
  1515.  
  1516.     if(Dst -> FileConfig && Src -> FileConfig)
  1517.         memcpy(Dst -> FileConfig,Src -> FileConfig,sizeof(struct FileSettings));
  1518.  
  1519.     if(Dst -> TransferConfig && Src -> TransferConfig)
  1520.         memcpy(Dst -> TransferConfig,Src -> TransferConfig,sizeof(struct TransferSettings));
  1521. }
  1522.  
  1523. VOID __regargs
  1524. UpdateConfig(struct Configuration *Src,struct Configuration *Dst)
  1525. {
  1526.     if(Src -> SerialConfig)
  1527.         memcpy(Dst -> SerialConfig,Src -> SerialConfig,sizeof(struct SerialSettings));
  1528.  
  1529.     if(Src -> ModemConfig)
  1530.         memcpy(Dst -> ModemConfig,Src -> ModemConfig,sizeof(struct ModemSettings));
  1531.  
  1532.     if(Src -> ScreenConfig)
  1533.     {
  1534.         memcpy(Dst -> ScreenConfig,Src -> ScreenConfig,sizeof(struct ScreenSettings));
  1535.  
  1536.         FixScreenPens(Dst -> ScreenConfig);
  1537.     }
  1538.  
  1539.     if(Src -> TerminalConfig)
  1540.         memcpy(Dst -> TerminalConfig,Src -> TerminalConfig,sizeof(struct TerminalSettings));
  1541.  
  1542.     if(Src -> EmulationConfig)
  1543.         memcpy(Dst -> EmulationConfig,Src -> EmulationConfig,sizeof(struct EmulationSettings));
  1544.  
  1545.     if(Src -> ClipConfig)
  1546.         memcpy(Dst -> ClipConfig,Src -> ClipConfig,sizeof(struct ClipSettings));
  1547.  
  1548.     if(Src -> CaptureConfig)
  1549.         memcpy(Dst -> CaptureConfig,Src -> CaptureConfig,sizeof(struct CaptureSettings));
  1550.  
  1551.     if(Src -> CommandConfig)
  1552.         memcpy(Dst -> CommandConfig,Src -> CommandConfig,sizeof(struct CommandSettings));
  1553.  
  1554.     if(Src -> MiscConfig)
  1555.         memcpy(Dst -> MiscConfig,Src -> MiscConfig,sizeof(struct MiscSettings));
  1556.  
  1557.     if(Src -> PathConfig)
  1558.         memcpy(Dst -> PathConfig,Src -> PathConfig,sizeof(struct PathSettings));
  1559.  
  1560.     if(Src -> FileConfig)
  1561.         memcpy(Dst -> FileConfig,Src -> FileConfig,sizeof(struct FileSettings));
  1562.  
  1563.     if(Src -> TransferConfig)
  1564.         memcpy(Dst -> TransferConfig,Src -> TransferConfig,sizeof(struct TransferSettings));
  1565. }
  1566.  
  1567. VOID __regargs
  1568. SwapConfig(struct Configuration *Src,struct Configuration *Dst)
  1569. {
  1570.     swmem(Dst -> SerialConfig,Src -> SerialConfig,sizeof(struct SerialSettings));
  1571.     swmem(Dst -> ModemConfig,Src -> ModemConfig,sizeof(struct ModemSettings));
  1572.     swmem(Dst -> ScreenConfig,Src -> ScreenConfig,sizeof(struct ScreenSettings));
  1573.     swmem(Dst -> TerminalConfig,Src -> TerminalConfig,sizeof(struct TerminalSettings));
  1574.     swmem(Dst -> EmulationConfig,Src -> EmulationConfig,sizeof(struct EmulationSettings));
  1575.     swmem(Dst -> ClipConfig,Src -> ClipConfig,sizeof(struct ClipSettings));
  1576.     swmem(Dst -> CaptureConfig,Src -> CaptureConfig,sizeof(struct CaptureSettings));
  1577.     swmem(Dst -> CommandConfig,Src -> CommandConfig,sizeof(struct CommandSettings));
  1578.     swmem(Dst -> MiscConfig,Src -> MiscConfig,sizeof(struct MiscSettings));
  1579.     swmem(Dst -> PathConfig,Src -> PathConfig,sizeof(struct PathSettings));
  1580.     swmem(Dst -> FileConfig,Src -> FileConfig,sizeof(struct FileSettings));
  1581.     swmem(Dst -> TransferConfig,Src -> TransferConfig,sizeof(struct TransferSettings));
  1582. }
  1583.  
  1584.     /* SavePhonebook(STRPTR Name):
  1585.      *
  1586.      *    Save the current phone book to a disk file.
  1587.      */
  1588.  
  1589. BYTE __regargs
  1590. SavePhonebook(STRPTR Name)
  1591. {
  1592.     struct IFFHandle    *Handle;
  1593.     BYTE             Success = FALSE;
  1594.     LONG             Error = 0;
  1595.  
  1596.     if(Phonebook && NumPhoneEntries)
  1597.     {
  1598.         if(Handle = (struct IFFHandle *)AllocIFF())
  1599.         {
  1600.             if(Handle -> iff_Stream = Open(Name,MODE_NEWFILE))
  1601.             {
  1602.                 InitIFFasDOS(Handle);
  1603.  
  1604.                 if(!(Error = OpenIFF(Handle,IFFF_WRITE)))
  1605.                 {
  1606.                     if(!(Error = PushChunk(Handle,ID_TERM,ID_CAT,IFFSIZE_UNKNOWN)))
  1607.                     {
  1608.                         if(!(Error = PushChunk(Handle,ID_TERM,ID_FORM,IFFSIZE_UNKNOWN)))
  1609.                         {
  1610.                             if(!(Error = PushChunk(Handle,0,ID_VERS,IFFSIZE_UNKNOWN)))
  1611.                             {
  1612.                                 struct TermInfo TermInfo;
  1613.  
  1614.                                 TermInfo . Version    = TermVersion;
  1615.                                 TermInfo . Revision    = TermRevision;
  1616.  
  1617.                                 if(WriteChunkRecords(Handle,&TermInfo,sizeof(struct TermInfo),1) == 1)
  1618.                                 {
  1619.                                     if(!(Error = PopChunk(Handle)))
  1620.                                     {
  1621.                                         STRPTR TempBuffer = NULL;
  1622.  
  1623.                                         if(PhonePasswordUsed)
  1624.                                         {
  1625.                                             if(!(Error = PushChunk(Handle,0,ID_PSWD,20)))
  1626.                                             {
  1627.                                                 Success = TRUE;
  1628.  
  1629.                                                 if(WriteChunkBytes(Handle,PhonePassword,20) != 20)
  1630.                                                     Success = FALSE;
  1631.  
  1632.                                                 if(PopChunk(Handle))
  1633.                                                     Success = FALSE;
  1634.  
  1635.                                                 if(Success)
  1636.                                                 {
  1637.                                                     LONG Max = sizeof(struct PhoneHeader),Type;
  1638.  
  1639.                                                     for(Type = PREF_SERIAL ; Type <= PREF_TRANSFER ; Type++)
  1640.                                                     {
  1641.                                                         if(SizeTable[Type - 1] > Max)
  1642.                                                             Max = SizeTable[Type - 1];
  1643.                                                     }
  1644.  
  1645.                                                     if(!(TempBuffer = AllocVecPooled(Max,MEMF_ANY)))
  1646.                                                     {
  1647.                                                         Error = ERR_NO_MEM;
  1648.  
  1649.                                                         Success = FALSE;
  1650.                                                     }
  1651.                                                 }
  1652.                                             }
  1653.                                         }
  1654.                                         else
  1655.                                             Success = TRUE;
  1656.  
  1657.                                         if(Success)
  1658.                                         {
  1659.                                             Success = FALSE;
  1660.  
  1661.                                             if(!(Error = PushChunk(Handle,0,ID_DIAL,IFFSIZE_UNKNOWN)))
  1662.                                             {
  1663.                                                 if(WriteChunkBytes(Handle,&NumPhoneEntries,sizeof(LONG)) == sizeof(LONG))
  1664.                                                 {
  1665.                                                     if(!(Error = PopChunk(Handle)))
  1666.                                                     {
  1667.                                                         if(!(Error = PopChunk(Handle)))
  1668.                                                         {
  1669.                                                             LONG i;
  1670.  
  1671.                                                             Success = TRUE;
  1672.  
  1673.                                                             for(i = 0 ; Success && i < NumPhoneEntries ; i++)
  1674.                                                             {
  1675.                                                                 Success = FALSE;
  1676.  
  1677.                                                                 if(!(Error = PushChunk(Handle,ID_TERM,ID_FORM,IFFSIZE_UNKNOWN)))
  1678.                                                                 {
  1679.                                                                     if(!(Error = PushChunk(Handle,0,ID_PHON,sizeof(struct PhoneHeader))))
  1680.                                                                     {
  1681.                                                                         if(TempBuffer)
  1682.                                                                         {
  1683.                                                                             Encrypt((UBYTE *)Phonebook[i] -> Header,sizeof(struct PhoneHeader),TempBuffer,PhonePassword,20);
  1684.  
  1685.                                                                             if(WriteChunkRecords(Handle,TempBuffer,sizeof(struct PhoneHeader),1) == 1)
  1686.                                                                             {
  1687.                                                                                 if(!(Error = PopChunk(Handle)))
  1688.                                                                                 {
  1689.                                                                                     if(WriteConfigChunks(Handle,Phonebook[i] -> Config,TempBuffer,PhonePassword))
  1690.                                                                                     {
  1691.                                                                                         struct TimeDateNode *TimeDateNode;
  1692.  
  1693.                                                                                         Success = TRUE;
  1694.  
  1695.                                                                                         TimeDateNode = (struct TimeDateNode *)Phonebook[i] -> TimeDateList . mlh_Head;
  1696.  
  1697.                                                                                         while(TimeDateNode -> VanillaNode . ln_Succ)
  1698.                                                                                         {
  1699.                                                                                             if(!(Error = PushChunk(Handle,0,ID_DATE,IFFSIZE_UNKNOWN)))
  1700.                                                                                             {
  1701.                                                                                                 if(WriteChunkBytes(Handle,&TimeDateNode -> Header,sizeof(struct TimeDateHeader)) != sizeof(struct TimeDateHeader))
  1702.                                                                                                 {
  1703.                                                                                                     Error = IoErr();
  1704.  
  1705.                                                                                                     Success = FALSE;
  1706.  
  1707.                                                                                                     break;
  1708.                                                                                                 }
  1709.                                                                                                 else
  1710.                                                                                                 {
  1711.                                                                                                     if(WriteChunkBytes(Handle,TimeDateNode -> Table,TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate)) != TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate))
  1712.                                                                                                     {
  1713.                                                                                                         Error = IoErr();
  1714.  
  1715.                                                                                                         Success = FALSE;
  1716.  
  1717.                                                                                                         break;
  1718.                                                                                                     }
  1719.                                                                                                 }
  1720.  
  1721.                                                                                                 if(Success)
  1722.                                                                                                 {
  1723.                                                                                                     if(Error = PopChunk(Handle))
  1724.                                                                                                     {
  1725.                                                                                                         Success = FALSE;
  1726.     
  1727.                                                                                                         break;
  1728.                                                                                                     }
  1729.                                                                                                 }
  1730.  
  1731.                                                                                                 TimeDateNode = (struct TimeDateNode *)TimeDateNode -> VanillaNode . ln_Succ;
  1732.                                                                                             }
  1733.                                                                                         }
  1734.                                                                                     }
  1735.                                                                                     else
  1736.                                                                                     {
  1737.                                                                                         Error = IoErr();
  1738.  
  1739.                                                                                         Success = FALSE;
  1740.                                                                                     }
  1741.                                                                                 }
  1742.                                                                             }
  1743.                                                                             else
  1744.                                                                                 Error = IoErr();
  1745.                                                                         }
  1746.                                                                         else
  1747.                                                                         {
  1748.                                                                             if(WriteChunkRecords(Handle,Phonebook[i] -> Header,sizeof(struct PhoneHeader),1) == 1)
  1749.                                                                             {
  1750.                                                                                 if(!(Error = PopChunk(Handle)))
  1751.                                                                                 {
  1752.                                                                                     if(WriteConfigChunks(Handle,Phonebook[i] -> Config,NULL,NULL))
  1753.                                                                                     {
  1754.                                                                                         struct TimeDateNode *TimeDateNode;
  1755.  
  1756.                                                                                         Success = TRUE;
  1757.  
  1758.                                                                                         TimeDateNode = (struct TimeDateNode *)Phonebook[i] -> TimeDateList . mlh_Head;
  1759.  
  1760.                                                                                         while(TimeDateNode -> VanillaNode . ln_Succ)
  1761.                                                                                         {
  1762.                                                                                             if(!(Error = PushChunk(Handle,0,ID_DATE,IFFSIZE_UNKNOWN)))
  1763.                                                                                             {
  1764.                                                                                                 if(WriteChunkBytes(Handle,&TimeDateNode -> Header,sizeof(struct TimeDateHeader)) != sizeof(struct TimeDateHeader))
  1765.                                                                                                 {
  1766.                                                                                                     Error = IoErr();
  1767.  
  1768.                                                                                                     Success = FALSE;
  1769.  
  1770.                                                                                                     break;
  1771.                                                                                                 }
  1772.                                                                                                 else
  1773.                                                                                                 {
  1774.                                                                                                     if(WriteChunkBytes(Handle,TimeDateNode -> Table,TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate)) != TimeDateNode -> Table[0] . Count * sizeof(struct TimeDate))
  1775.                                                                                                     {
  1776.                                                                                                         Error = IoErr();
  1777.  
  1778.                                                                                                         Success = FALSE;
  1779.  
  1780.                                                                                                         break;
  1781.                                                                                                     }
  1782.                                                                                                 }
  1783.  
  1784.                                                                                                 if(Success)
  1785.                                                                                                 {
  1786.                                                                                                     if(Error = PopChunk(Handle))
  1787.                                                                                                     {
  1788.                                                                                                         Success = FALSE;
  1789.     
  1790.                                                                                                         break;
  1791.                                                                                                     }
  1792.                                                                                                 }
  1793.  
  1794.                                                                                                 TimeDateNode = (struct TimeDateNode *)TimeDateNode -> VanillaNode . ln_Succ;
  1795.                                                                                             }
  1796.                                                                                         }
  1797.                                                                                     }
  1798.                                                                                     else
  1799.                                                                                     {
  1800.                                                                                         Success = FALSE;
  1801.  
  1802.                                                                                         Error = IoErr();
  1803.                                                                                     }
  1804.                                                                                 }
  1805.                                                                             }
  1806.                                                                             else
  1807.                                                                                 Error = IoErr();
  1808.                                                                         }
  1809.                                                                     }
  1810.  
  1811.                                                                     if(Success)
  1812.                                                                     {
  1813.                                                                         if(PopChunk(Handle))
  1814.                                                                             Success = FALSE;
  1815.                                                                     }
  1816.                                                                 }
  1817.                                                             }
  1818.                                                         }
  1819.                                                     }
  1820.                                                 }
  1821.                                                 else
  1822.                                                     Error = IoErr();
  1823.                                             }
  1824.                                         }
  1825.  
  1826.                                         if(TempBuffer)
  1827.                                             FreeVecPooled(TempBuffer);
  1828.                                     }
  1829.                                 }
  1830.                                 else
  1831.                                     Error = IoErr();
  1832.                             }
  1833.                         }
  1834.  
  1835.                         if(Success)
  1836.                         {
  1837.                             if(Error = PopChunk(Handle))
  1838.                                 Success = FALSE;
  1839.                         }
  1840.                     }
  1841.  
  1842.                     CloseIFF(Handle);
  1843.                 }
  1844.  
  1845.                 Close(Handle -> iff_Stream);
  1846.             }
  1847.             else
  1848.                 Error = IoErr();
  1849.  
  1850.             FreeIFF(Handle);
  1851.         }
  1852.         else
  1853.             Error = ERR_NO_MEM;
  1854.  
  1855.         if(Success)
  1856.             AddProtection(Name,FIBF_EXECUTE);
  1857.         else
  1858.             DeleteFile(Name);
  1859.     }
  1860.  
  1861.     if(Error)
  1862.         SetIoErr(Error);
  1863.  
  1864.     return(Success);
  1865. }
  1866.  
  1867. STATIC BYTE
  1868. ReadConfigChunk(struct IFFHandle *Handle,struct Configuration *Config,UBYTE Type,LONG Len,STRPTR Password)
  1869. {
  1870.     if(CreateConfigEntry(Config,Type))
  1871.     {
  1872.         APTR Data;
  1873.  
  1874.         switch(Type)
  1875.         {
  1876.             case PREF_SERIAL:
  1877.  
  1878.                 Data = Config -> SerialConfig;
  1879.                 break;
  1880.  
  1881.             case PREF_MODEM:
  1882.  
  1883.                 Data = Config -> ModemConfig;
  1884.                 break;
  1885.  
  1886.             case PREF_COMMAND:
  1887.  
  1888.                 Data = Config -> CommandConfig;
  1889.                 break;
  1890.  
  1891.             case PREF_SCREEN:
  1892.  
  1893.                 Data = Config -> ScreenConfig;
  1894.                 break;
  1895.  
  1896.             case PREF_TERMINAL:
  1897.  
  1898.                 Data = Config -> TerminalConfig;
  1899.                 break;
  1900.  
  1901.             case PREF_PATH:
  1902.  
  1903.                 Data = Config -> PathConfig;
  1904.                 break;
  1905.  
  1906.             case PREF_MISC:
  1907.  
  1908.                 Data = Config -> MiscConfig;
  1909.                 break;
  1910.  
  1911.             case PREF_CLIP:
  1912.  
  1913.                 Data = Config -> ClipConfig;
  1914.                 break;
  1915.  
  1916.             case PREF_CAPTURE:
  1917.  
  1918.                 Data = Config -> CaptureConfig;
  1919.                 break;
  1920.  
  1921.             case PREF_FILE:
  1922.  
  1923.                 Data = Config -> FileConfig;
  1924.                 break;
  1925.  
  1926.             case PREF_EMULATION:
  1927.  
  1928.                 Data = Config -> EmulationConfig;
  1929.                 break;
  1930.  
  1931.             case PREF_TRANSFER:
  1932.  
  1933.                 Data = Config -> TransferConfig;
  1934.                 break;
  1935.         }
  1936.  
  1937.         Len = MIN(SizeTable[Type - 1],Len);
  1938.  
  1939.         if(ReadChunkBytes(Handle,Data,Len) == Len)
  1940.         {
  1941.             if(Password)
  1942.                 Decrypt(Data,Len,Data,Password,20);
  1943.  
  1944.             if(Type == PREF_SCREEN)
  1945.                 FixScreenPens(Data);
  1946.  
  1947.             return(TRUE);
  1948.         }
  1949.     }
  1950.  
  1951.     return(FALSE);
  1952. }
  1953.  
  1954.     /* LoadPhonebook(STRPTR Name):
  1955.      *
  1956.      *    Restore a phone book from a disk file.
  1957.      */
  1958.  
  1959. BYTE __regargs
  1960. LoadPhonebook(STRPTR Name)
  1961. {
  1962.     struct PhoneEntry    **PrivatePhonebook;
  1963.     LONG             PrivatePhoneSize    = 0,
  1964.                  CurrentPhoneSize    = 0,
  1965.                  Count            = 0,
  1966.                  Index            = 0;
  1967.     BYTE             Success        = FALSE,
  1968.                  LastHadTime        = TRUE,
  1969.                  UsePhonePassword    = FALSE,
  1970.                  FirstChunk        = TRUE,
  1971.                  UseOld            = FALSE;
  1972.     struct IFFHandle    *Handle;
  1973.     struct ContextNode    *Chunk;
  1974.     struct TimeDateNode    *TimeDateNode;
  1975.     UBYTE             ConfigChunkType,
  1976.                  PasswordBuffer[20];
  1977.     BYTE             CheckedChunk = FALSE;
  1978.     LONG             Error = 0;
  1979.  
  1980.     if(Handle = AllocIFF())
  1981.     {
  1982.         if(Handle -> iff_Stream = Open(Name,MODE_OLDFILE))
  1983.         {
  1984.             InitIFFasDOS(Handle);
  1985.  
  1986.             if(!(Error = OpenIFF(Handle,IFFF_READ)))
  1987.             {
  1988.                 if(!(Error = StopChunks(Handle,(LONG *)Stops,NUM_STOPS)))
  1989.                 {
  1990.                     struct TermInfo TermInfo;
  1991.  
  1992.                     while(!ParseIFF(Handle,IFFPARSE_SCAN))
  1993.                     {
  1994.                         Chunk = CurrentChunk(Handle);
  1995.  
  1996.                             /* Is this the first chunk to be read? */
  1997.  
  1998.                         if(!CheckedChunk)
  1999.                         {
  2000.                                 /* The first chunk must be a
  2001.                                  * catalog chunk, or this is
  2002.                                  * not a proper phonebook file.
  2003.                                  */
  2004.  
  2005.                             if(Chunk -> cn_ID != ID_CAT)
  2006.                                 break;
  2007.                             else
  2008.                                 CheckedChunk = TRUE;
  2009.                         }
  2010.  
  2011.                         if(Chunk -> cn_ID == ID_VERS)
  2012.                         {
  2013.                             if(ReadChunkBytes(Handle,&TermInfo,sizeof(struct TermInfo)) == sizeof(struct TermInfo))
  2014.                             {
  2015.                                 if(TermInfo . Version != TermVersion || (TermInfo . Version == TermVersion && TermInfo . Revision > TermRevision))
  2016.                                 {
  2017.                                     if(TermInfo . Version == 2 && TermInfo . Revision == 4)
  2018.                                         UseOld = TRUE;
  2019.  
  2020.                                     if(TermInfo . Version != 3)
  2021.                                         break;
  2022.                                 }
  2023.                             }
  2024.                             else
  2025.                             {
  2026.                                 Error = IoErr();
  2027.  
  2028.                                 break;
  2029.                             }
  2030.                         }
  2031.  
  2032.                         if(Chunk -> cn_ID == ID_PSWD)
  2033.                         {
  2034.                             if(ReadChunkBytes(Handle,PasswordBuffer,20) == 20)
  2035.                             {
  2036.                                 if(PhonePasswordUsed)
  2037.                                 {
  2038.                                     if(!memcmp(PhonePassword,PasswordBuffer,20))
  2039.                                     {
  2040.                                         UsePhonePassword = TRUE;
  2041.  
  2042.                                         continue;
  2043.                                     }
  2044.                                 }
  2045.  
  2046.                                 memset(SharedBuffer,0,21);
  2047. #ifdef BETA
  2048.                                 StopBetaTask();
  2049. #endif    /* BETA */
  2050.                                 if(GetString(FALSE,TRUE,21,LocaleString(MSG_PHONEPANEL_PLEASE_ENTER_PASSWORD_TXT),SharedBuffer))
  2051.                                 {
  2052.                                     UBYTE AnotherBuffer[20];
  2053.  
  2054.                                     Encrypt(SharedBuffer,20,AnotherBuffer,SharedBuffer,strlen(SharedBuffer));
  2055.  
  2056.                                     if(!memcmp(PasswordBuffer,AnotherBuffer,20))
  2057.                                     {
  2058.                                         UsePhonePassword = TRUE;
  2059.  
  2060.                                         continue;
  2061.                                     }
  2062.                                     else
  2063.                                     {
  2064.                                         MyEasyRequest(Window,LocaleString(MSG_TERMPHONE_WRONG_PASSWORD_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Name);
  2065.  
  2066.                                         break;
  2067.                                     }
  2068.                                 }
  2069.                                 else
  2070.                                     break;
  2071.                             }
  2072.                             else
  2073.                             {
  2074.                                 Error = IoErr();
  2075.  
  2076.                                 break;
  2077.                             }
  2078.                         }
  2079.  
  2080.                         if(Chunk -> cn_ID == ID_DIAL)
  2081.                         {
  2082.                             if(ReadChunkBytes(Handle,&CurrentPhoneSize,sizeof(LONG)) == sizeof(LONG))
  2083.                             {
  2084.                                 if(!CurrentPhoneSize)
  2085.                                     break;
  2086.                                 else
  2087.                                 {
  2088.                                     if(!(PrivatePhonebook = CreatePhonebook(CurrentPhoneSize,&PrivatePhoneSize,TRUE)))
  2089.                                     {
  2090.                                         Error = ERR_NO_MEM;
  2091.  
  2092.                                         break;
  2093.                                     }
  2094.                                 }
  2095.                             }
  2096.                             else
  2097.                             {
  2098.                                 Error = IoErr();
  2099.  
  2100.                                 break;
  2101.                             }
  2102.                         }
  2103.  
  2104.                         if(Chunk -> cn_ID == ID_PHON)
  2105.                         {
  2106.                             WORD Size = MIN(sizeof(struct PhoneHeader),Chunk -> cn_Size);
  2107.  
  2108.                             if(!CurrentPhoneSize)
  2109.                                 break;
  2110.  
  2111.                             if(!LastHadTime)
  2112.                             {
  2113.                                 if(TimeDateNode = CreateTimeDateNode(-1,-1,"",2))
  2114.                                     AddTail((struct List *)&PrivatePhonebook[Index] -> TimeDateList,&TimeDateNode -> VanillaNode);
  2115.                             }
  2116.  
  2117.                             if(!FirstChunk)
  2118.                                 Index++;
  2119.                             else
  2120.                                 FirstChunk = FALSE;
  2121.  
  2122.                             if(ReadChunkBytes(Handle,PrivatePhonebook[Index] -> Header,Size) == Size)
  2123.                             {
  2124.                                 if(UsePhonePassword)
  2125.                                     Decrypt((UBYTE *)PrivatePhonebook[Index] -> Header,Size,(UBYTE *)PrivatePhonebook[Index] -> Header,PasswordBuffer,20);
  2126.  
  2127.                                 PrivatePhonebook[Index] -> Count = -1;
  2128.  
  2129.                                 LastHadTime = FALSE;
  2130.  
  2131.                                 Count++;
  2132.                             }
  2133.                             else
  2134.                             {
  2135.                                 Error = IoErr();
  2136.  
  2137.                                 break;
  2138.                             }
  2139.                         }
  2140.  
  2141.                         if(ConfigChunkType = IsConfigChunk(Chunk -> cn_ID))
  2142.                         {
  2143.                             if(!CurrentPhoneSize)
  2144.                                 break;
  2145.  
  2146.                             if(UsePhonePassword)
  2147.                             {
  2148.                                 if(!ReadConfigChunk(Handle,PrivatePhonebook[Index] -> Config,ConfigChunkType,Chunk -> cn_Size,PasswordBuffer))
  2149.                                 {
  2150.                                     if(Count)
  2151.                                         CurrentPhoneSize = Count - 1;
  2152.                                     else
  2153.                                         CurrentPhoneSize = 0;
  2154.  
  2155.                                     break;
  2156.                                 }
  2157.                                 else
  2158.                                     FixOldConfig(PrivatePhonebook[Index] -> Config,ConfigChunkType,TRUE,TermInfo . Version,TermInfo . Revision);
  2159.                             }
  2160.                             else
  2161.                             {
  2162.                                 if(!ReadConfigChunk(Handle,PrivatePhonebook[Index] -> Config,ConfigChunkType,Chunk -> cn_Size,NULL))
  2163.                                 {
  2164.                                     if(Count)
  2165.                                         CurrentPhoneSize = Count - 1;
  2166.                                     else
  2167.                                         CurrentPhoneSize = 0;
  2168.  
  2169.                                     break;
  2170.                                 }
  2171.                                 else
  2172.                                     FixOldConfig(PrivatePhonebook[Index] -> Config,ConfigChunkType,TRUE,TermInfo . Version,TermInfo . Revision);
  2173.                             }
  2174.                         }
  2175.  
  2176.                         if(Chunk -> cn_ID == ID_DATE)
  2177.                         {
  2178.                             WORD Count = (Chunk -> cn_Size - sizeof(struct TimeDateHeader)) / sizeof(struct TimeDate);
  2179.  
  2180.                             if(!CurrentPhoneSize)
  2181.                                 break;
  2182.  
  2183.                             if(TimeDateNode = CreateTimeDateNode(-1,-1,"",Count))
  2184.                             {
  2185.                                 if(ReadChunkBytes(Handle,&TimeDateNode -> Header,sizeof(struct TimeDateHeader)) == sizeof(struct TimeDateHeader))
  2186.                                 {
  2187.                                     if(ReadChunkRecords(Handle,TimeDateNode -> Table,sizeof(struct TimeDate),Count) == Count)
  2188.                                     {
  2189.                                         AdaptTimeDateNode(TimeDateNode);
  2190.  
  2191.                                         AddTail((struct List *)&PrivatePhonebook[Index] -> TimeDateList,&TimeDateNode -> VanillaNode);
  2192.  
  2193.                                         LastHadTime = TRUE;
  2194.                                     }
  2195.                                     else
  2196.                                     {
  2197.                                         Error = IoErr();
  2198.  
  2199.                                         FreeTimeDateNode(TimeDateNode);
  2200.                                     }
  2201.                                 }
  2202.                                 else
  2203.                                 {
  2204.                                     Error = IoErr();
  2205.  
  2206.                                     FreeTimeDateNode(TimeDateNode);
  2207.                                 }
  2208.                             }
  2209.                         }
  2210.                     }
  2211.  
  2212.                     if(CurrentPhoneSize)
  2213.                     {
  2214.                         LONG i;
  2215.  
  2216.                         if(!LastHadTime)
  2217.                         {
  2218.                             if(TimeDateNode = CreateTimeDateNode(-1,-1,"",2))
  2219.                                 AddTail((struct List *)&PrivatePhonebook[Index] -> TimeDateList,&TimeDateNode -> VanillaNode);
  2220.                         }
  2221.  
  2222.                         if(Phonebook)
  2223.                             DeletePhonebook(Phonebook,PhoneSize,TRUE);
  2224.  
  2225.                         Phonebook    = PrivatePhonebook;
  2226.                         PhoneSize    = PrivatePhoneSize;
  2227.                         NumPhoneEntries    = CurrentPhoneSize;
  2228.                         Success        = TRUE;
  2229.  
  2230.                         memcpy(PhonePassword,PasswordBuffer,20);
  2231.                         PhonePasswordUsed = UsePhonePassword;
  2232.  
  2233.                         for(i = NumPhoneEntries ; i < PhoneSize ; i++)
  2234.                         {
  2235.                             if(Phonebook[i])
  2236.                             {
  2237.                                 if(Phonebook[i] -> Config)
  2238.                                     DeleteConfiguration(Phonebook[i] -> Config);
  2239.  
  2240.                                 FreeVecPooled(Phonebook[i]);
  2241.  
  2242.                                 Phonebook[i] = NULL;
  2243.                             }
  2244.                         }
  2245.  
  2246.                         FreeDialList(TRUE);
  2247.                     }
  2248.                     else
  2249.                     {
  2250.                         if(PrivatePhoneSize)
  2251.                         {
  2252.                             DeletePhonebook(PrivatePhonebook,PrivatePhoneSize,TRUE);
  2253.  
  2254.                             Success = FALSE;
  2255.                         }
  2256.                     }
  2257.                 }
  2258.  
  2259.                 CloseIFF(Handle);
  2260.             }
  2261.  
  2262.             Close(Handle -> iff_Stream);
  2263.         }
  2264.         else
  2265.             Error = IoErr();
  2266.  
  2267.         FreeIFF(Handle);
  2268.     }
  2269.     else
  2270.         Error = ERR_NO_MEM;
  2271.  
  2272.     if(Error)
  2273.         SetIoErr(Error);
  2274.  
  2275.     if(UseOld)
  2276.         return(LoadOldPhonebook(Name));
  2277.     else
  2278.         return(Success);
  2279. }
  2280.  
  2281.     /* WriteConfig(STRPTR Name,struct Configuration *Config):
  2282.      *
  2283.      *    Write the configuration to a file, very much like
  2284.      *    WriteIFFData().
  2285.      */
  2286.  
  2287. BYTE __regargs
  2288. WriteConfig(STRPTR Name,struct Configuration *Config)
  2289. {
  2290.     struct IFFHandle    *Handle;
  2291.     BYTE             Success = FALSE;
  2292.     LONG             Error = 0;
  2293.  
  2294.         /* Allocate a handle. */
  2295.  
  2296.     if(Handle = AllocIFF())
  2297.     {
  2298.             /* Open an output stream. */
  2299.  
  2300.         if(Handle -> iff_Stream = Open(Name,MODE_NEWFILE))
  2301.         {
  2302.                 /* Tell iffparse that this is
  2303.                  * a DOS handle.
  2304.                  */
  2305.  
  2306.             InitIFFasDOS(Handle);
  2307.  
  2308.                 /* Open the handle for writing. */
  2309.  
  2310.             if(!(Error = OpenIFF(Handle,IFFF_WRITE)))
  2311.             {
  2312.                     /* Push outmost chunk onto stack. */
  2313.  
  2314.                 if(!(Error = PushChunk(Handle,ID_TERM,ID_FORM,IFFSIZE_UNKNOWN)))
  2315.                 {
  2316.                         /* Add a version identifier. */
  2317.  
  2318.                     if(!(Error = PushChunk(Handle,0,ID_VERS,IFFSIZE_UNKNOWN)))
  2319.                     {
  2320.                         struct TermInfo TermInfo;
  2321.  
  2322.                         TermInfo . Version    = TermVersion;
  2323.                         TermInfo . Revision    = TermRevision;
  2324.  
  2325.                             /* Write the version data. */
  2326.  
  2327.                         if(WriteChunkBytes(Handle,&TermInfo,sizeof(struct TermInfo)) == sizeof(struct TermInfo))
  2328.                         {
  2329.                                 /* Pop the version chunk, i.e. write it to the file. */
  2330.  
  2331.                             if(Error = PopChunk(Handle))
  2332.                                 Success = FALSE;
  2333.                             else
  2334.                             {
  2335.                                 if(WriteConfigChunks(Handle,Config,NULL,NULL))
  2336.                                 {
  2337.                                     LONG i;
  2338.  
  2339.                                     Success = TRUE;
  2340.  
  2341.                                     for(i = 0 ; Success && i < WINDOW_COUNT ; i++)
  2342.                                     {
  2343.                                         if(!(Error = PushChunk(Handle,0,ID_WINF,sizeof(struct WindowInfo))))
  2344.                                         {
  2345.                                             if(WriteChunkBytes(Handle,&WindowInfoTable[i],sizeof(struct WindowInfo)) == sizeof(struct WindowInfo))
  2346.                                             {
  2347.                                                 if(Error = PopChunk(Handle))
  2348.                                                     Success = FALSE;
  2349.                                             }
  2350.                                             else
  2351.                                             {
  2352.                                                 Error = IoErr();
  2353.  
  2354.                                                 Success = FALSE;
  2355.                                             }
  2356.                                         }
  2357.                                         else
  2358.                                             Success = FALSE;
  2359.                                     }
  2360.                                 }
  2361.                             }
  2362.                         }
  2363.                         else
  2364.                         {
  2365.                             Error = IoErr();
  2366.  
  2367.                             Success = FALSE;
  2368.                         }
  2369.                     }
  2370.  
  2371.                         /* Seems that we're done, now try to pop the FORM chunk
  2372.                          * and return.
  2373.                          */
  2374.  
  2375.                     if(Success)
  2376.                     {
  2377.                         if(Error = PopChunk(Handle))
  2378.                             Success = FALSE;
  2379.                     }
  2380.                 }
  2381.  
  2382.                     /* Close the handle (flush any pending data). */
  2383.  
  2384.                 CloseIFF(Handle);
  2385.             }
  2386.  
  2387.                 /* Close the DOS handle itself. */
  2388.  
  2389.             Close(Handle -> iff_Stream);
  2390.         }
  2391.         else
  2392.             Error = IoErr();
  2393.  
  2394.             /* And free the IFF handle. */
  2395.  
  2396.         FreeIFF(Handle);
  2397.     }
  2398.     else
  2399.         Error = ERR_NO_MEM;
  2400.  
  2401.     if(Success)
  2402.         AddProtection(Name,FIBF_EXECUTE);
  2403.  
  2404.     return(Success);
  2405. }
  2406.  
  2407.     /* ReadConfig(STRPTR Name,struct Configuration *Config):
  2408.      *
  2409.      *    Read the configuration file, very much the same as ReadIFFData().
  2410.      */
  2411.  
  2412. BYTE __regargs
  2413. ReadConfig(STRPTR Name,struct Configuration *Config)
  2414. {
  2415.     struct IFFHandle    *Handle;
  2416.     BYTE             Success    = FALSE,
  2417.                  UseOld        = FALSE;
  2418.     struct ContextNode    *Chunk;
  2419.     UBYTE             ConfigChunkType;
  2420.     LONG             Error = 0;
  2421.  
  2422.     if(Handle = AllocIFF())
  2423.     {
  2424.         if(Handle -> iff_Stream = Open(Name,MODE_OLDFILE))
  2425.         {
  2426.             InitIFFasDOS(Handle);
  2427.  
  2428.             if(!(Error = OpenIFF(Handle,IFFF_READ)))
  2429.             {
  2430.                 if(!StopChunks(Handle,(LONG *)Stops,NUM_STOPS))
  2431.                 {
  2432.                     struct TermInfo TermInfo;
  2433.  
  2434.                     while(!ParseIFF(Handle,IFFPARSE_SCAN))
  2435.                     {
  2436.                         Chunk = CurrentChunk(Handle);
  2437.  
  2438.                             /* Oops! Some is trying to
  2439.                              * use the phone book file as
  2440.                              * a configuration file.
  2441.                              */
  2442.  
  2443.                         if(Chunk -> cn_ID == ID_CAT)
  2444.                         {
  2445.                             Success = FALSE;
  2446.  
  2447.                             break;
  2448.                         }
  2449.  
  2450.                         if(Chunk -> cn_ID == ID_VERS)
  2451.                         {
  2452.                             if(ReadChunkBytes(Handle,&TermInfo,sizeof(struct TermInfo)) == sizeof(struct TermInfo))
  2453.                             {
  2454.                                 if(TermInfo . Version != TermVersion || (TermInfo . Version == TermVersion && TermInfo . Revision > TermRevision))
  2455.                                 {
  2456.                                     if(TermInfo . Version == 2 && TermInfo . Revision == 4)
  2457.                                         UseOld = TRUE;
  2458.  
  2459.                                     if(TermInfo . Version != 3)
  2460.                                         break;
  2461.                                 }
  2462.                             }
  2463.                             else
  2464.                             {
  2465.                                 Error = IoErr();
  2466.  
  2467.                                 break;
  2468.                             }
  2469.                         }
  2470.  
  2471.                         if(Chunk -> cn_ID == ID_WINF)
  2472.                         {
  2473.                             struct WindowInfo Info;
  2474.  
  2475.                             if(ReadChunkBytes(Handle,&Info,sizeof(Info)) == sizeof(Info))
  2476.                             {
  2477.                                 Success = TRUE;
  2478.  
  2479.                                 ReplaceWindowInfo(&Info);
  2480.                             }
  2481.                             else
  2482.                             {
  2483.                                 Error = IoErr();
  2484.  
  2485.                                 Success = FALSE;
  2486.                                 break;
  2487.                             }
  2488.                         }
  2489.                         else
  2490.                         {
  2491.                             if(ConfigChunkType = IsConfigChunk(Chunk -> cn_ID))
  2492.                             {
  2493.                                 if(ReadConfigChunk(Handle,Config,ConfigChunkType,Chunk -> cn_Size,NULL))
  2494.                                 {
  2495.                                     FixOldConfig(Config,ConfigChunkType,FALSE,TermInfo . Version,TermInfo . Revision);
  2496.  
  2497.                                     Success = TRUE;
  2498.                                 }
  2499.                                 else
  2500.                                 {
  2501.                                     Error = IoErr();
  2502.  
  2503.                                     Success = FALSE;
  2504.  
  2505.                                     break;
  2506.                                 }
  2507.                             }
  2508.                         }
  2509.                     }
  2510.                 }
  2511.  
  2512.                 CloseIFF(Handle);
  2513.             }
  2514.  
  2515.             Close(Handle -> iff_Stream);
  2516.         }
  2517.  
  2518.         FreeIFF(Handle);
  2519.     }
  2520.     else
  2521.         Error = IoErr();
  2522.  
  2523.     if(Error)
  2524.         SetIoErr(Error);
  2525.  
  2526.     if(UseOld)
  2527.         return(ReadOldConfig(Name,Config));
  2528.     else
  2529.         return(Success);
  2530. }
  2531.