home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / ftp.vapor.com / microdot-1 / md1_src_02.lzx / fkeywin.c < prev    next >
C/C++ Source or Header  |  2014-05-19  |  23KB  |  1,001 lines

  1. #include "microdot.h"
  2.  
  3. #include "ogre.h"
  4. #include "ogre_protos.h"
  5. #include "asyncio.h"
  6.  
  7. #define FK_OK 1
  8. #define FK_CANCEL 2
  9. #define FK_BASE1 10
  10. #define FK_BASE2 30
  11.  
  12. static char *fnanames[] = { "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F0" };
  13.  
  14. extern struct mdtprefs mdtprefs;
  15.  
  16. void dotermfkey( void )
  17. {
  18.     struct ogwin *ogw;
  19.     struct Window *iw;
  20.     struct IntuiMessage *im;
  21.     int c;
  22.     int Done = FALSE;
  23.  
  24.     ogw = ogreInitWindow( scr, 0, 0, "Funktionstastenbelegung..." );
  25.  
  26.     ogreAddGroup( ogw, 0, OGFRAME_OUTLINE, " Normal " );
  27.     for( c = 0; c < 10; c++ )
  28.         ogreAddString( ogw, c, 0, fnanames[ác ], FK_BASE1 + c, prefs.fkeys[ c ], 28, 128 );
  29.  
  30.     ogreAddGroup( ogw, 0, OGFRAME_OUTLINE, " Shift " );
  31.     for( c = 0; c < 10; c++ )
  32.         ogreAddString( ogw, c, 0, fnanames[ác ], FK_BASE2 + c, prefs.fkeys[ c + 10 ], 28, 128 );
  33.  
  34.     ogreAddGroup( ogw, 1, OGFRAME_NONE, NULL );
  35.     ogreAddButton( ogw, 0 | OGB_ONENTER, 'o', "_OK", FK_OK );
  36.     ogreAddHelp( ogw, 0 );
  37.     ogreAddButton( ogw, 0 | OGB_ONESC, 'a', "_Abbruch", FK_CANCEL );
  38.  
  39.     iw = ogreOpenWindow( ogw );
  40.     if( !iw )
  41.         return;
  42.  
  43.     while( !Done )
  44.     {
  45.         im = ogreWaitIM( ogw );
  46.  
  47.         if( im->Class == IDCMP_GADGETHELP || ( im->Class == IDCMP_RAWKEY && im->Code == 0x5f ) )
  48.             showguide( "fkeywin_gads" );
  49.         else if( im->Class == IDCMP_GADGETUP )
  50.         {
  51.             switch( im->Code )
  52.             {
  53.                 case FK_OK:
  54.                     Done = 2;
  55.                     break;
  56.                 case FK_CANCEL:
  57.                     Done = 1;
  58.                     break;
  59.  
  60.             }
  61.         }
  62.         ogreIMReply( ogw, im );
  63.     }
  64.  
  65.     if( Done == 2 )
  66.     {
  67.         for( c = 0; c < 10; c++ )
  68.         {
  69.             ogreCopyStringValue( ogw, FK_BASE1 + c, prefs.fkeys[ác ]á);
  70.             ogreCopyStringValue( ogw, FK_BASE2 + c, prefs.fkeys[ác + 10 ]á);
  71.         }
  72.  
  73.     }
  74.  
  75.     ogreExitWindow( ogw );
  76.  
  77. }
  78.  
  79. #define TT_OK 1
  80. #define TT_CANCEL 2
  81.  
  82. #define TT_IBM 3
  83.  
  84. #define TT_WHICHCOLS 5
  85. #define TT_SETCOLS 6
  86.  
  87. static char *colopts[]á= { "Normal", "Spezial", "Ansi", NULL };
  88.  
  89. void dotermterm( void )
  90. {
  91.     struct ogwin *ogw;
  92.     struct Window *iw;
  93.     struct IntuiMessage *im;
  94.     int Done = FALSE;
  95.  
  96.     ogw = ogreInitWindow( scr, 0, 0, "Terminal..." );
  97.  
  98.     ogreAddGroup( ogw, 0, OGFRAME_OUTLINE, " Parameter " );
  99.     ogreAddCheckbox( ogw, 0, 'i', "_IBM-Zeichensatz?", TT_IBM, ( mdtprefs.flags & MDTF_IBM ) );
  100.  
  101.     ogreAddGroup( ogw, 1, OGFRAME_OUTLINE, " Farben " );
  102.     ogreAddCycle( ogw, 0, 'f', "_Farbe", TT_WHICHCOLS, colopts, 9, mdtprefs.whichcolors );
  103.     ogreAddButton( ogw, 0, 's', "_Spezialfarben einstellen", TT_SETCOLS );
  104.  
  105.     ogreAddGroup( ogw, 2, OGFRAME_NONE, NULL );
  106.     ogreAddButton( ogw, 0 | OGB_ONENTER, 'o', "_OK", TT_OK );
  107.     ogreAddHelp( ogw, 0 );
  108.     ogreAddButton( ogw, 0 | OGB_ONESC, 'a', "_Abbruch", TT_CANCEL );
  109.  
  110.     ogreEnable( ogw, !wbwindow, TT_WHICHCOLS, TT_SETCOLS, 0 );
  111.  
  112.     iw = ogreOpenWindow( ogw );
  113.     if( !iw )
  114.         return;
  115.  
  116.     while( !Done )
  117.     {
  118.         ogreEnable( ogw, !wbwindow && ( ogreValue( ogw, TT_WHICHCOLS ) == 1 ), TT_SETCOLS, 0 );
  119.  
  120.         im = ogreWaitIM( ogw );
  121.  
  122.         if( im->Class == IDCMP_GADGETHELP)
  123.             showguidenum( "termterm_gads", im->Code );
  124.         else if( im->Class == IDCMP_GADGETUP )
  125.         {
  126.             switch( im->Code )
  127.             {
  128.                 case TT_OK:
  129.                     Done = 2;
  130.                     break;
  131.                 case TT_CANCEL:
  132.                     Done = 1;
  133.                     break;
  134.  
  135.                 case TT_SETCOLS:
  136.                     rtPaletteRequest( "Terminal-Farben einstellen:", NULL, TAG_DONE );
  137.                     break;
  138.  
  139.                 case TT_WHICHCOLS:
  140.                     if( ogreValue( ogw, TT_WHICHCOLS ) )
  141.                     {
  142.                         UBYTE tccol = mdtprefs.whichcolors;
  143.                         mdtprefs.whichcolors = ogreValue( ogw, TT_WHICHCOLS );
  144.                         term_setcolors();
  145.                         mdtprefs.whichcolors = tccol;
  146.                     }
  147.                     else
  148.                     {
  149.                         if( prefs.usecustomcolors )
  150.                             setcolors( scr );
  151.                         else
  152.                             setwbcolors( scr );
  153.                     }
  154.                     break;
  155.  
  156.  
  157.             }
  158.         }
  159.         ogreIMReply( ogw, im );
  160.     }
  161.  
  162.     if( Done == 2 )
  163.     {
  164.         if( ogreValue( ogw, TT_IBM ) )
  165.             mdtprefs.flags |= MDTF_IBM;
  166.         else
  167.             mdtprefs.flags &= ~MDTF_IBM;
  168.  
  169.         mdtprefs.whichcolors = ogreValue( ogw, TT_WHICHCOLS );
  170.         if( !wbwindow && ( mdtprefs.whichcolors == 1 ) )
  171.             term_getcolors();
  172.         savemdtprefs();
  173.     }
  174.  
  175.     if( !wbwindow )
  176.     {
  177.         if( mdtprefs.whichcolors )
  178.             term_setcolors();
  179.         else
  180.         {
  181.             if( prefs.usecustomcolors )
  182.                 setcolors( scr );
  183.             else
  184.                 setwbcolors( scr );
  185.         }
  186.     }
  187.  
  188.     ogreExitWindow( ogw );
  189. }
  190.  
  191. #define TR_OK 1
  192. #define TR_CANCEL 2
  193.  
  194. #define TR_DOWNPATH 3
  195. #define TR_DOWNPATHSEL 4
  196. #define TR_UPPATH 5
  197. #define TR_UPPATHSEL 6
  198.  
  199. #define TR_AUTOUP 7
  200. #define TR_AUTODOWN 8
  201.  
  202. void dotermtransfer( void )
  203. {
  204.     struct ogwin *ogw;
  205.     struct Window *iw;
  206.     struct IntuiMessage *im;
  207.     int Done = FALSE;
  208.  
  209.     ogw = ogreInitWindow( scr, 0, 0, "Transfer..." );
  210.  
  211.     ogreAddGroup( ogw, 0, OGFRAME_OUTLINE, " Pfade " );
  212.     ogreAddString( ogw, 0, 'p', "  Upload-_Pfad:", TR_UPPATH, prefs.term_uploadpath, 30, 128 );
  213.     ogreAddButton( ogw, 0 | OGGP_KEEPSIZE, 'P', "?", TR_UPPATHSEL );
  214.     ogreAddString( ogw, 1, 'l', "Down_load-Pfad:", TR_DOWNPATH, prefs.term_downloadpath, 30, 128 );
  215.     ogreAddButton( ogw, 1 | OGGP_KEEPSIZE, 'L', "?", TR_DOWNPATHSEL );
  216.  
  217.     ogreAddGroup( ogw, 1, OGFRAME_OUTLINE, " Auto " );
  218.     ogreAddCheckbox( ogw, 0, 'u', "_Auto-_Upload?", TR_AUTOUP, ( prefs.flags & MDF_TERM_AUTOUL ) );
  219.     ogreAddCheckbox( ogw, 0, 'd', "_Auto-_Download?", TR_AUTODOWN, ( prefs.flags & MDF_TERM_AUTODL ) );
  220.  
  221.     ogreAddGroup( ogw, 2, OGFRAME_NONE, NULL );
  222.     ogreAddButton( ogw, 0 | OGB_ONENTER, 'o', "_OK", TT_OK );
  223.     ogreAddHelp( ogw, 0 );
  224.     ogreAddButton( ogw, 0 | OGB_ONESC, 'a', "_Abbruch", TT_CANCEL );
  225.  
  226.     iw = ogreOpenWindow( ogw );
  227.     if( !iw )
  228.         return;
  229.  
  230.     while( !Done )
  231.     {
  232.         im = ogreWaitIM( ogw );
  233.  
  234.         if( im->Class == IDCMP_GADGETHELP)
  235.             showguidenum( "termtransfer_gads", im->Code );
  236.         else if( im->Class == IDCMP_GADGETUP )
  237.         {
  238.             switch( im->Code )
  239.             {
  240.                 case TR_OK:
  241.                     Done = 2;
  242.                     break;
  243.                 case TR_CANCEL:
  244.                     Done = 1;
  245.                     break;
  246.  
  247.                 case TR_UPPATHSEL:
  248.                     newdofrseldir( ogw, TR_UPPATH , "Standard-Uploadpfad:" );
  249.                     break;
  250.  
  251.                 case TR_DOWNPATHSEL:
  252.                     newdofrseldir( ogw, TR_DOWNPATH , "Standard-Downloadpfad:" );
  253.                     break;
  254.             }
  255.         }
  256.         ogreIMReply( ogw, im );
  257.     }
  258.  
  259.     if( Done == 2 )
  260.     {
  261.         if( ogreValue( ogw, TR_AUTODOWN ) )
  262.             prefs.flags |= MDF_TERM_AUTODL;
  263.         else
  264.             prefs.flags &= ~MDF_TERM_AUTODL;
  265.  
  266.         if( ogreValue( ogw, TR_AUTOUP ) )
  267.             prefs.flags |= MDF_TERM_AUTOUL;
  268.         else
  269.             prefs.flags &= ~MDF_TERM_AUTOUL;
  270.  
  271.         ogreCopyStringValue( ogw, TR_UPPATH, prefs.term_uploadpath );
  272.         ogreCopyStringValue( ogw, TR_DOWNPATH, prefs.term_downloadpath );
  273.  
  274.         rtChangeReqAttr( fr[ FR_TERMUPLOAD], RTFI_Dir, prefs.term_uploadpath, TAG_DONE );
  275.     }
  276.  
  277.     ogreExitWindow( ogw );
  278.  
  279. }
  280.  
  281. #define DTS_LV 1
  282. #define DTS_OK 2
  283. #define DTS_CANCEL 3
  284. #define DTS_DEL 4
  285. #define DTS_NEW 5
  286.  
  287. int dotermsel( void )
  288. {
  289.     struct ogwin *ogw;
  290.     struct Window *iw;
  291.     struct IntuiMessage *im;
  292.     int    Done = FALSE;
  293.     struct AsyncFile *f;
  294.     APTR tcpool;
  295.     struct mdtprefs *list, new;
  296.     int lvactive = -1, lastsel = -1;
  297.     ULONG lastsecs = 0, lastmics = 0;
  298.     char oldactivemdt[á20 ];
  299.     int c = 0;
  300.  
  301.     strcpy( oldactivemdt, prefs.term_currentmdt );
  302.  
  303.     tcpool = LibCreatePool( MEMF_CLEAR, 4096, 2048 );
  304.  
  305.     ogw = ogreInitWindow( scr, WFLG_RMBTRAP, 0, "Konfiguration auswΣhlen:" );
  306.     ogreAddGroup( ogw, 0, OGFRAME_NONE, NULL );
  307.     ogreAddList( ogw, 0, 0xff, NULL, DTS_LV, 30, 10, 0, NULL );
  308.     ogreLVInit( ogw, DTS_LV );
  309.  
  310.     ogreLVAddEntry( ogw, DTS_LV, "½Pointserver╗", prefs.term_currentmdt[á0 ] ? 0 : 1, NULL );
  311.     if( !prefs.term_currentmdt[á0 ]á)
  312.         lvactive = 0;
  313.  
  314.     pushhomedir();
  315.     f = OpenAsync( "microdot.mdtprefs", MODE_READ, sizeof( new ) * 16 );
  316.     if( f )
  317.     {
  318.         while( ReadAsync( f, &new, sizeof( new ) ) == sizeof( new ) )
  319.         {
  320.             list = LibAllocPooled( tcpool, sizeof( new ) );
  321.             if( !list )
  322.                 break;
  323.             *list = new;
  324.             if( !stricmp( new.name, prefs.term_currentmdt ) )
  325.             {
  326.                 ogreLVAddEntry( ogw, DTS_LV, list->name, 1, list );
  327.                 lvactive = c;
  328.             }
  329.             else
  330.                 ogreLVAddEntry( ogw, DTS_LV, list->name, 0, list );
  331.             c++;
  332.         }
  333.         CloseAsync( f );
  334.     }
  335.     popdir();
  336.  
  337.     ogreAddButton( ogw, 1, 'n', "_Neu", DTS_NEW );
  338.     ogreAddButton( ogw, 1, 'l', "_L÷schen", DTS_DEL );
  339.  
  340.     ogreAddButton( ogw, 2 | OGB_ONENTER, 'o', "_Ok", DTS_OK );
  341.     ogreAddHelp( ogw, 2 );
  342.     ogreAddButton( ogw, 2 | OGB_ONESC, 'a', "_Abbruch", DTS_CANCEL );
  343.  
  344.     iw = ogreOpenWindow( ogw );
  345.     if( !iw )
  346.         return( 0 );
  347.  
  348.     while( !Done )
  349.     {
  350.         ogreEnable( ogw, lvactive >= 0, DTS_NEW, 0 );
  351.         ogreEnable( ogw, lvactive > 0, DTS_DEL, 0 );
  352.  
  353.         im = ogreWaitIM( ogw );
  354.  
  355.         if( im->Class == IDCMP_GADGETHELP)
  356.             showguidenum( "term_cfgsel_gads", im->Code );
  357.         else if( im->Class == IDCMP_GADGETUP )
  358.         {
  359.             switch( im->Code )
  360.             {
  361.                 case DTS_LV:
  362.                     lvactive = ogreValue( ogw, DTS_LV );
  363.                     if( lvactive == lastsel )
  364.                         if( DoubleClick( lastsecs, lastmics, im->Seconds, im->Micros ) )
  365.                             goto doexit;
  366.  
  367.                     lastsel = lvactive;
  368.                     lastsecs = im->Seconds;
  369.                     lastmics = im->Micros;
  370.                     break;
  371.  
  372.                 case DTS_OK:
  373. doexit:
  374.                     if( lvactive >= 0 )
  375.                     {
  376.                         Done = 2;
  377.                         prefs.term_currentmdt[á0 ]á= 0;
  378.                         if( lvactive )
  379.                         {
  380.                             struct ogrevn *vn = ogreLVGetEntry( ogw, DTS_LV, lvactive );
  381.                             if( vn )
  382.                                 strcpy( prefs.term_currentmdt, vn->txt );
  383.                         }
  384.                     }
  385.                     break;
  386.  
  387.                 case DTS_DEL:
  388.                     if( lvactive > 0 )
  389.                     {
  390.                         ogreLVRemEntry( ogw, DTS_LV, lvactive );
  391.                         ogreLVRefresh( ogw, DTS_LV );
  392.                     }                    
  393.                     break;
  394.                     
  395.                 case DTS_NEW:
  396.                     if( lvactive >= 0 )
  397.                     {
  398.                         struct ogrevn *vn = ogreLVGetEntry( ogw, DTS_LV, lvactive );
  399.  
  400.                         list = LibAllocPooled( tcpool, sizeof( *list ) );
  401.                         if( list )
  402.                         {
  403.                             if( vn && vn->userdata )
  404.                                 *list = * ( ( struct mdtprefs * ) vn->userdata );
  405.                             else
  406.                             {
  407.                                 new = mdtprefs;
  408.                                 selectmdtprefs( NULL );
  409.                                 *list = mdtprefs;
  410.                                 mdtprefs = new;
  411.                             }
  412. redo:
  413.                             if( rtGetString( list->name, 19, 0, rinfo, RTGS_TextFmt, "Neue Terminalkonfiguration: Name eingeben", RTGS_Flags, GSREQF_CENTERTEXT, TAG_DONE ) )
  414.                             {
  415.                                 int c;
  416.                                 struct ogrevn *vn;
  417.  
  418.                                 for( c = 0; ; c++ )
  419.                                 {
  420.                                     vn = ogreLVGetEntry( ogw, DTS_LV, c );
  421.                                     if( !vn )
  422.                                         break;
  423.                                     if( !stricmp( vn->txt, list->name ) )
  424.                                     {
  425.                                         askreq( "Name existiert bereits!", "Wiederholen" );
  426.                                         goto redo;
  427.                                     }
  428.                                 }
  429.  
  430.                                 ogreLVAddEntry( ogw, DTS_LV, list->name, 0, list );
  431.                                 ogreLVRefresh( ogw, DTS_LV );
  432.                             }
  433.                         }
  434.                     }
  435.                     break;
  436.                     
  437.                 case DTS_CANCEL:
  438.                     Done = 1;
  439.                     break;
  440.             }
  441.         }
  442.     }
  443.  
  444.     if( Done == 2 )
  445.     {
  446.         pushhomedir();
  447.         f = OpenAsync( "microdot.mdtprefs", MODE_WRITE, sizeof( new ) * 16 );
  448.         if( f )
  449.         {
  450.             struct ogrevn *vn;
  451.             int c;
  452.             for( c = 1; ; c++ )
  453.             {
  454.                 vn = ogreLVGetEntry( ogw, DTS_LV, c );
  455.                 if( !vn )
  456.                     break;
  457.                 WriteAsync( f, vn->userdata, sizeof( struct mdtprefs ) );
  458.             }
  459.             CloseAsync( f );
  460.         }
  461.         popdir();
  462.     }
  463.  
  464.     ogreExitWindow( ogw );
  465.     LibDeletePool( tcpool );
  466.  
  467.     return( ( Done == 2 ) && stricmp( prefs.term_currentmdt, oldactivemdt ) );
  468. }
  469.  
  470. #define SD_OK 1
  471. #define SD_CANCEL 2
  472. #define SD_DEVICE 3
  473. #define SD_UNIT 4
  474. #define SD_BAUD 5
  475. #define SD_RTS 6
  476. #define SD_HS 7
  477. #define SD_SHARED 8
  478. #define SD_MINIT 9
  479. #define SD_MDIAL 10
  480. #define SD_MHANGUP 11
  481. #define SD_DTR 14
  482. #define SD_CARRIER 15
  483. #define SD_7E1 16
  484.  
  485. int dotermserial( void )
  486. {
  487.     struct ogwin *ogw;
  488.     struct Window *iw;
  489.     struct IntuiMessage *im;
  490.     int Done = FALSE;
  491.  
  492.     ogw = ogreInitWindow( scr, 0, 0, "Modem-Konfiguration..." );
  493.  
  494.     ogreAddGroup( ogw, 0 | OGGP_EXPANDSTRING, OGFRAME_OUTLINE, " Serielle Parameter " );
  495.     ogreAddString( ogw, 0, 'd', "_Device:", SD_DEVICE, mdtprefs.device, 32, 32 );
  496.     ogreAddInteger( ogw, 1, 0,  "  Unit:", SD_UNIT, mdtprefs.unit, 0, MAXINT, 16, 32 );
  497.     ogreAddInteger( ogw, 1, 0, "Baud:", SD_BAUD, mdtprefs.baud, 75, MAXINT, 16, 32 );
  498.     ogreAddCheckbox( ogw, 2, 'r', "_RTS/CTS", SD_RTS, mdtprefs.flags & 1 );
  499.     ogreAddCheckbox( ogw, 2, 'h', "_Highspeed", SD_HS, mdtprefs.flags & 2 );
  500.     ogreAddCheckbox( ogw, 2, 's', "_Shared", SD_SHARED, mdtprefs.flags & 4 );
  501.     ogreAddCheckbox( ogw, 2, 'c', "_Carriercheck", SD_CARRIER, ! ( mdtprefs.flags & 8 ) );
  502.     ogreAddCheckbox( ogw, 2, '7', "_7e1", SD_7E1 , mdtprefs.flags & 16 );
  503.  
  504.     ogreAddGroup( ogw, 1 | OGGP_EXPANDSTRING, OGFRAME_OUTLINE, " Modem-Kommandos " );
  505.     ogreAddString( ogw, 0, 'i', "    _Init:", SD_MINIT, mdtprefs.modeminit, 32, 80 );
  506.     ogreAddString( ogw, 1, 0,   "  WΣhlen:", SD_MDIAL, mdtprefs.modemdial, 32, 80 );
  507.     ogreAddString( ogw, 2, 0,   "Auflegen:", SD_MHANGUP, mdtprefs.modemhangup, 32, 80 );
  508.     ogreAddCheckbox( ogw, 3, 'd', "Auflegen per _DTR-Drop", SD_DTR, prefs.flags & MDTF_DROPDTR );
  509.  
  510.     ogreAddGroup( ogw, 2, OGFRAME_NONE, NULL );
  511.     ogreAddButton( ogw, 0 | OGB_ONENTER, 'o', "_OK", SD_OK );
  512.     ogreAddHelp( ogw, 0 );
  513.     ogreAddButton( ogw, 0 | OGB_ONESC, 'a', "_Abbruch", SD_CANCEL );
  514.  
  515.     iw = ogreOpenWindow( ogw );
  516.     if( !iw )
  517.         return( 0 );
  518.  
  519.     while( !Done )
  520.     {
  521.         ogreEnable( ogw, !ogreValue( ogw, SD_7E1 ), SD_HS, 0 );
  522.  
  523.         im = ogreWaitIM( ogw );
  524.  
  525.         if( im->Class == IDCMP_GADGETHELP)
  526.             showguidenum( "termserwin_gads", im->Code );
  527.         else if( im->Class == IDCMP_GADGETUP )
  528.         {
  529.             switch( im->Code )
  530.             {
  531.                 case SD_OK:
  532.                     Done = 2;
  533.                     break;
  534.                 case SD_CANCEL:
  535.                     Done = 1;
  536.                     break;
  537.  
  538.             }
  539.         }
  540.         ogreIMReply( ogw, im );
  541.     }
  542.  
  543.     if( Done == 2 )
  544.     {
  545.         ogreCopyStringValue( ogw, SD_DEVICE, mdtprefs.device );
  546.         ogreCopyStringValue( ogw, SD_MINIT, mdtprefs.modeminit );
  547.         ogreCopyStringValue( ogw, SD_MDIAL, mdtprefs.modemdial );
  548.         ogreCopyStringValue( ogw, SD_MHANGUP, mdtprefs.modemhangup );
  549.  
  550.         mdtprefs.unit    = ogreValue( ogw, SD_UNIT );
  551.         mdtprefs.baud    = ogreValue( ogw, SD_BAUD );
  552.  
  553.         if( ogreValue( ogw, SD_RTS ) )
  554.             mdtprefs.flags |= 1;
  555.         else
  556.             mdtprefs.flags &= ~1;
  557.  
  558.         if( ogreValue( ogw, SD_DTR ) )
  559.             mdtprefs.flags |= MDTF_DROPDTR;
  560.         else
  561.             mdtprefs.flags &= ~MDTF_DROPDTR;
  562.  
  563.         if( ogreValue( ogw, SD_HS ) )
  564.             mdtprefs.flags |= 2;
  565.         else
  566.             mdtprefs.flags &= ~2;
  567.  
  568.         if( ogreValue( ogw, SD_SHARED ) )
  569.             mdtprefs.flags |= 4;
  570.         else
  571.             mdtprefs.flags &= ~4;
  572.  
  573.         if( !ogreValue( ogw, SD_CARRIER ) )
  574.             mdtprefs.flags |= 8;
  575.         else
  576.             mdtprefs.flags &= ~8;
  577.  
  578.         if( ogreValue( ogw, SD_7E1 ) )
  579.             mdtprefs.flags |= MDTF_7E1;
  580.         else
  581.             mdtprefs.flags &= ~MDTF_7E1;
  582.  
  583.         savemdtprefs();
  584.     }
  585.  
  586.     ogreExitWindow( ogw );
  587.     return( Done == 2 );
  588. }
  589.  
  590. static struct MinList phonebooklist;
  591. static APTR phonebookpool;
  592.  
  593. #define MDPSIZE (sizeof(struct mdphone)*2)
  594.  
  595. struct pbid {
  596.     UWORD    id;
  597.     UWORD    len;
  598. };
  599. #define PBID 0xB003
  600.  
  601. static void loadphone( void )
  602. {
  603.     struct AsyncFile *f;
  604.     struct mmdphone *new;
  605.     UBYTE  buffer[áMDPSIZE ], buffer2[áMDPSIZE ];
  606.     struct pbid pbid;
  607.  
  608.     NewList( ( struct List * ) &phonebooklist );
  609.     phonebookpool = LibCreatePool( MEMF_CLEAR, sizeof( struct mmdphone ) * 8, sizeof( struct mmdphone ) * 4 );
  610.  
  611.     pushhomedir();
  612.     f = OpenAsync( "microdot.phonebook", MODE_READ, 4096 );
  613.     popdir();
  614.     if( !f )
  615.         return;    
  616.  
  617.     for(;;)
  618.     {
  619.         if( ReadAsync( f, &pbid, sizeof( pbid ) ) != sizeof( pbid ) )
  620.             break;
  621.         if( pbid.id != PBID )
  622.             break;
  623.         ReadAsync( f, buffer, pbid.len );
  624.         new = LibAllocPooled( phonebookpool, sizeof( *new ) );
  625.         if( !new )
  626.             break;
  627.         lzw_unpack( buffer, buffer2 );
  628.         memcpy( &new->mdp, buffer2, sizeof( struct mdphone ) );
  629.         AddTail( ( struct List * ) &phonebooklist, ( struct Node * ) new );
  630.     }
  631.     CloseAsync( f );
  632. }
  633.  
  634. static void savephone( void )
  635. {
  636.     struct AsyncFile *f;
  637.     UBYTE  buffer[áMDPSIZE ];
  638.     struct pbid pbid;
  639.     struct mmdphone *m = ( struct mmdphone * )phonebooklist.mlh_Head;
  640.  
  641.     pushhomedir();
  642.     f = OpenAsync( "microdot.phonebook", MODE_WRITE, 4096 );
  643.     popdir();
  644.     if( !f )
  645.         return;    
  646.  
  647.     pbid.id = PBID;
  648.     while( m->n.mln_Succ )
  649.     {
  650.         pbid.len = lzw_pack( &m->mdp, buffer, sizeof( struct mmdphone ), 10 );
  651.  
  652.         WriteAsync( f, &pbid, sizeof( pbid ) );
  653.         WriteAsync( f, buffer, pbid.len );
  654.         m = ( struct mmdphone * ) m->n.mln_Succ;
  655.     }
  656.     CloseAsync( f );
  657. }
  658.  
  659. static void freephone( void )
  660. {
  661.     if( phonebookpool )
  662.     {
  663.         LibDeletePool( phonebookpool );
  664.         phonebookpool = NULL;
  665.     }
  666. }
  667.  
  668. static void pb2lv( struct ogwin *ogw, ULONG id )
  669. {
  670.     struct mmdphone *m = ( struct mmdphone * )phonebooklist.mlh_Head;
  671.  
  672.     ogreLVInit( ogw, id );
  673.     while( m->n.mln_Succ )
  674.     {
  675.         ogreLVAddEntry( ogw, id, m->mdp.name, 0, m );
  676.         m = ( struct mmdphone * ) m->n.mln_Succ;
  677.     }
  678. }
  679.  
  680. #define PB_LV 1
  681. #define PB_OK 2
  682. #define PB_CANCEL 3
  683. #define PB_ADD 4
  684. #define PB_DEL 5
  685.  
  686. #define PB_NAME 6
  687. #define PB_PHONE 7
  688. #define PB_USERID 8
  689. #define PB_PASSWORD 9
  690. #define PB_SERIAL 10
  691. #define PB_AUTOLOGIN 11
  692.  
  693.  
  694. static STRPTR *tcfgtab;
  695. static APTR tcfgpool;
  696. static void maketcfgtab( void )
  697. {
  698.     int ntcfg;
  699.     struct mdtprefs new;
  700.     int c = 1;
  701.     struct AsyncFile *f;
  702.  
  703.     tcfgpool = LibCreatePool( MEMF_CLEAR, 2048, 1024 );
  704.  
  705.     pushhomedir();
  706.     ntcfg = getfilelen( "microdot.mdtprefs" );
  707.     if( ntcfg < (long)sizeof( new ) )
  708.     {
  709.         popdir();
  710.         tcfgtab = LibAllocPooled( tcfgpool, 8 );
  711.         tcfgtab[á0 ]á= "½Pointserver╗";
  712.         return;
  713.     }
  714.     tcfgtab = LibAllocPooled( tcfgpool, ( ntcfg / sizeof( new ) ) * 4 + 8 );
  715.     tcfgtab[á0 ]á= "½Pointserver╗";
  716.     f = OpenAsync( "microdot.mdtprefs", MODE_READ, sizeof( new ) * 16 );
  717.     while( ReadAsync( f, &new, sizeof( new ) ) == sizeof( new ) )
  718.     {
  719.         tcfgtab[ác ]á= LibAllocPooled( tcfgpool, strlen( new.name ) + 1 );
  720.         strcpy( tcfgtab[ác++ ], new.name );
  721.     }
  722.     CloseAsync( f );
  723.     popdir();
  724. }
  725. static void freetcfgtab( void )
  726. {
  727.     if( tcfgpool )
  728.     {
  729.         LibDeletePool( tcfgpool );
  730.         tcfgpool = NULL;
  731.     }
  732. }
  733. static int getcfgnum( char *name )
  734. {
  735.     char **p = tcfgtab;
  736.     int c = 1;
  737.  
  738.     p++;
  739.     while( *p )
  740.     {
  741.         if( !stricmp( name, *p++ ) )
  742.             return( c );
  743.         c++;
  744.     }
  745.     return( 0 );
  746. }
  747.  
  748. static void showpb( struct ogwin *ogw, int which )
  749. {
  750.     struct mmdphone *m = ( struct mmdphone * ) GetEntry( &phonebooklist, which );
  751.  
  752.     if( !m )
  753.         return;
  754.  
  755.     ogreSetStringValue( ogw, PB_NAME, m->mdp.name );
  756.     ogreSetStringValue( ogw, PB_PHONE, m->mdp.phone );
  757.     ogreSetStringValue( ogw, PB_USERID, m->mdp.username );
  758.     ogreSetStringValue( ogw, PB_PASSWORD, m->mdp.password );
  759.     ogreSetValue( ogw, PB_AUTOLOGIN, m->mdp.autologin );
  760.     ogreSetValue( ogw, PB_SERIAL, getcfgnum( m->mdp.prefs ) );
  761. }
  762.  
  763. static void donewpb( struct ogwin *ogw, struct mmdphone *cmp )
  764. {
  765.     struct mmdphone *new;
  766.  
  767.     new = LibAllocPooled( phonebookpool, sizeof( *new ) );
  768.     if( !new )
  769.         return;
  770.     /*if( cmp )
  771.         *new = *cmp;*/
  772.     strcpy( new->mdp.name, "-- Neuer Eintrag --" );
  773.     AddTail( &phonebooklist, new );
  774.     pb2lv( ogw, PB_LV );
  775. }
  776.  
  777. void dotermphone( void )
  778. {
  779.     struct ogwin *ogw;
  780.     struct Window *iw;
  781.     struct IntuiMessage *im;
  782.     int    Done = FALSE;
  783.     int lvactive = -1;
  784.     struct ogrevn *vn;
  785.  
  786.     loadphone();
  787.     maketcfgtab();
  788.  
  789.     ogw = ogreInitWindow( scr, WFLG_RMBTRAP, 0, "Telefonbuch" );
  790.  
  791.     ogreAddGroup( ogw, 0, OGFRAME_NONE, NULL );
  792.     ogreAddList( ogw, 0, 0xff, NULL, PB_LV, 40, 8, 0, NULL );
  793.     pb2lv( ogw, PB_LV );
  794.     ogreAddButton( ogw, 1, 'n', "_Neu", PB_ADD );
  795.     ogreAddButton( ogw, 1, 'l', "_L÷schen", PB_DEL );
  796.  
  797.     ogreAddString( ogw, 2, 0, "Boxname:", PB_NAME, "", 42, 40 );
  798.     ogreAddString( ogw, 3, 0, "Telefon:", PB_PHONE, "", 42, 128 );
  799.     ogreAddString( ogw, 4, 0, "Username:", PB_USERID , "", 42, 80 );
  800.     ogreAddString( ogw, 5, 0, "Passwort:", PB_PASSWORD, "", 42, 80 );
  801.  
  802.     ogreAddCycle( ogw, 6, 'k', "_Konfiguration:", PB_SERIAL, tcfgtab, 20, 0 );
  803.     ogreAddCheckbox( ogw, 6, 't', "Automa_tischer Login?", PB_AUTOLOGIN, 0 );
  804.  
  805.     ogreAddButton( ogw, 7 | OGB_ONENTER, 'o', "_Ok", PB_OK );
  806.     ogreAddHelp( ogw, 7 );
  807.     ogreAddButton( ogw, 7 | OGB_ONESC, 'a', "_Abbruch", PB_CANCEL );
  808.  
  809.     iw = ogreOpenWindow( ogw );
  810.     if( !iw )
  811.         return;
  812.  
  813.     while( !Done )
  814.     {
  815.         ogreEnable( ogw, lvactive >= 0, PB_NAME, PB_PHONE, PB_USERID, PB_PASSWORD, PB_SERIAL, PB_AUTOLOGIN, 0 );
  816.  
  817.         im = ogreWaitIM( ogw );
  818.  
  819.         if( im->Class == IDCMP_GADGETHELP)
  820.             showguidenum( "term_phone_gads", im->Code );
  821.         else if( im->Class == IDCMP_GADGETUP )
  822.         {
  823.             switch( im->Code )
  824.             {
  825.                 case PB_ADD:
  826.                     vn = NULL;
  827.                     if( lvactive >= 0 )
  828.                     {
  829.                         vn = ogreLVGetEntry( ogw, PB_LV, lvactive );
  830.                     }
  831.                     donewpb( ogw, vn ? vn->userdata : NULL);
  832.                     lvactive = GetNumEntries( &phonebooklist ) - 1;
  833.                     ogreLVSelect( ogw, PB_LV, lvactive );
  834.                     ogreLVRefresh( ogw, PB_LV );
  835.                     showpb( ogw, lvactive );
  836.                     break;
  837.  
  838.                 case PB_DEL:
  839.                     if( lvactive >= 0 )
  840.                     {
  841.                         vn = ogreLVGetEntry( ogw, PB_LV, lvactive );
  842.                         Remove( ( struct Node * ) vn->userdata );
  843.                         pb2lv( ogw, PB_LV );
  844.                         ogreLVRefresh( ogw, PB_LV );
  845.                         lvactive = -1;
  846.                     }
  847.                     break;
  848.  
  849.                 case PB_NAME:
  850.                     vn = ogreLVGetEntry( ogw, PB_LV, lvactive );
  851.                     if( vn )
  852.                     {
  853.                         ogreCopyStringValue( ogw, PB_NAME, ( ( struct mmdphone * ) vn->userdata ) -> mdp.name );
  854.                         ogreLVRefresh( ogw, PB_LV );
  855.                     }
  856.                     break;
  857.  
  858.                 case PB_PHONE:
  859.                     vn = ogreLVGetEntry( ogw, PB_LV, lvactive );
  860.                     if( vn )
  861.                     {
  862.                         ogreCopyStringValue( ogw, PB_PHONE, ( ( struct mmdphone * ) vn->userdata ) -> mdp.phone );
  863.                     }
  864.                     break;
  865.  
  866.                 case PB_USERID:
  867.                     vn = ogreLVGetEntry( ogw, PB_LV, lvactive );
  868.                     if( vn )
  869.                     {
  870.                         ogreCopyStringValue( ogw, PB_USERID, ( ( struct mmdphone * ) vn->userdata ) -> mdp.username );
  871.                     }
  872.                     break;
  873.  
  874.                 case PB_PASSWORD:
  875.                     vn = ogreLVGetEntry( ogw, PB_LV, lvactive );
  876.                     if( vn )
  877.                     {
  878.                         ogreCopyStringValue( ogw, PB_PASSWORD, ( ( struct mmdphone * ) vn->userdata ) -> mdp.password );
  879.                     }
  880.                     break;
  881.  
  882.                 case PB_AUTOLOGIN:
  883.                     vn = ogreLVGetEntry( ogw, PB_LV, lvactive );
  884.                     if( vn )
  885.                     {
  886.                         ( ( struct mmdphone * ) vn->userdata ) -> mdp.autologin = ogreValue( ogw, PB_AUTOLOGIN ) ? 1 : 0;
  887.                     }
  888.                     break;
  889.  
  890.                 case PB_SERIAL:
  891.                     vn = ogreLVGetEntry( ogw, PB_LV, lvactive );
  892.                     if( vn )
  893.                     {
  894.                         int v = ogreValue( ogw, PB_SERIAL );
  895.                         strcpy( ( ( struct mmdphone * ) vn->userdata ) -> mdp.prefs, !v ? "" : tcfgtab[áv ]á);
  896.                     }
  897.                     break;
  898.  
  899.                 case PB_OK:
  900.                     Done = 2;
  901.                     break;
  902.  
  903.                 case PB_CANCEL:
  904.                     Done = 1;
  905.                     break;
  906.  
  907.                 case PB_LV:
  908.                     lvactive = ogreValue( ogw, PB_LV );
  909.                     showpb( ogw, lvactive );
  910.                     break;
  911.             }
  912.         }
  913.         ogreIMReply( ogw, im );
  914.     }
  915.  
  916.     ogreExitWindow( ogw );
  917.  
  918.     if( Done == 2 )
  919.         savephone();
  920.     freephone();
  921.     freetcfgtab();
  922. }
  923.  
  924. struct mdphone *dotermphonesel( void )
  925. {
  926.     struct ogwin *ogw;
  927.     struct Window *iw;
  928.     struct IntuiMessage *im;
  929.     int    Done = FALSE;
  930.     int lvactive = -1, lastactive = -1;
  931.     ULONG lastsecs = 0, lastmics = 0;
  932.     struct ogrevn *vn;
  933.     struct mmdphone *m;
  934.     static struct mdphone mdp;
  935.  
  936.     loadphone();
  937.     maketcfgtab();
  938.  
  939.     ogw = ogreInitWindow( scr, WFLG_RMBTRAP, 0, "Telefonbucheintrag auswΣhlen:" );
  940.  
  941.     ogreAddGroup( ogw, 0, OGFRAME_NONE, NULL );
  942.     ogreAddList( ogw, 0, 0xff, NULL, PB_LV, 40, 8, 0, NULL );
  943.     pb2lv( ogw, PB_LV );
  944.     ogreAddButton( ogw, 1 | OGB_ONENTER, 'o', "_Ok", PB_OK );
  945.     ogreAddHelp( ogw, 1 );
  946.     ogreAddButton( ogw, 1 | OGB_ONESC, 'a', "_Abbruch", PB_CANCEL );
  947.  
  948.     iw = ogreOpenWindow( ogw );
  949.     if( !iw )
  950.         return( NULL );
  951.  
  952.     while( !Done )
  953.     {
  954.         ogreEnable( ogw, lvactive >= 0, PB_OK, FALSE );
  955.  
  956.         im = ogreWaitIM( ogw );
  957.  
  958.         if( im->Class == IDCMP_GADGETHELP)
  959.             showguidenum( "term_phonesel_gads", im->Code );
  960.         else if( im->Class == IDCMP_GADGETUP )
  961.         {
  962.             switch( im->Code )
  963.             {
  964.                 case PB_OK:
  965.                     Done = 2;
  966.                     break;
  967.  
  968.                 case PB_CANCEL:
  969.                     Done = 1;
  970.                     break;
  971.  
  972.                 case PB_LV:
  973.                     lvactive = ogreValue( ogw, PB_LV );
  974.                     if( ( lvactive >= 0 ) && ( lvactive == lastactive ) )
  975.                     {
  976.                         if( DoubleClick( lastsecs, lastmics, im->Seconds, im->Micros ) )
  977.                             Done = 2;
  978.                     }
  979.                     lastactive = lvactive;
  980.                     lastsecs = im->Seconds;
  981.                     lastmics = im->Micros;
  982.                     break;
  983.             }
  984.         }
  985.         ogreIMReply( ogw, im );
  986.     }
  987.  
  988.     vn = ogreLVGetEntry( ogw, PB_LV, lvactive );
  989.     if( vn )    
  990.     {
  991.         m = vn->userdata;
  992.         mdp = m->mdp;
  993.     }
  994.     else
  995.         Done = 0;
  996.  
  997.     ogreExitWindow( ogw );
  998.  
  999.     return( Done == 2 ? &mdp : NULL );
  1000. }
  1001.