home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / util / gblanker-38.8.lha / GBlanker / GSource / BGUI / PrefInterp.c < prev    next >
C/C++ Source or Header  |  1994-12-31  |  20KB  |  556 lines

  1. #include <exec/memory.h>
  2. #include <libraries/bgui_macros.h>
  3.  
  4. #include <clib/exec_protos.h>
  5. #include <clib/dos_protos.h>
  6. #include <clib/intuition_protos.h>
  7. #include <clib/bgui_protos.h>
  8. #include <clib/asl_protos.h>
  9. #include "/Libraries/Garshnelib/Garshnelib_protos.h"
  10. #include <clib/alib_protos.h>
  11.  
  12. #include <pragmas/exec_pragmas.h>
  13. #include <pragmas/dos_pragmas.h>
  14. #include <pragmas/intuition_pragmas.h>
  15. #include <pragmas/bgui_pragmas.h>
  16. #include <pragmas/asl_pragmas.h>
  17. #include "/Libraries/Garshnelib/Garshnelib_pragmas.h"
  18.  
  19. #include <ctype.h>
  20. #include <string.h>
  21.  
  22. #include "PrefInterp.h"
  23. #include "/protos/parse.h"
  24. #include "/protos/var.h"
  25. #include "/defs.h"
  26.  
  27. extern struct Library *DOSBase;
  28.  
  29. ULONG Map[] = { SLIDER_Level, INDIC_Level, TAG_END };
  30. struct IBox WinBox, OldBox;
  31. struct Library *IntuitionBase, *BGUIBase, *GarshnelibBase;
  32. Object *ModuleObj, **Objects;
  33. struct Window *ModuleWnd;
  34. struct MsgPort *ReplyPort = 0L;
  35. ULONG ModuleSigs = 0L;
  36. LONG NumGadgets;
  37. VOID *Memory = 0L;
  38. PrefObject *Prefs;
  39.  
  40. STRPTR MakeBoxVarName( STRPTR ProgName, STRPTR IfcName )
  41. {
  42.     static BYTE FileName[108], *Ptr;
  43.  
  44.     strcpy( FileName, ProgName );
  45.     strcat( FileName, "/" );
  46.     strcat( FileName, IfcName );
  47.     if( Ptr = strstr( FileName, ".ifc" ))
  48.         *Ptr = '\0';
  49.     strcat( FileName, ".win" );
  50.     
  51.     return FileName;
  52. }
  53.  
  54. VOID FontRequest( struct TextAttr *Attr )
  55. {
  56.     struct Library *AslBase = OpenLibrary( "asl.library", 37L );
  57.     struct FontRequester *fReq;
  58.  
  59.     if( !AslBase )
  60.         return;
  61.     
  62.     fReq = AllocAslRequestTags( ASL_FontRequest,
  63.                                ASL_FontName, Attr->ta_Name,
  64.                                ASL_FontHeight, Attr->ta_YSize,
  65.                                ASL_MaxHeight, 100, TAG_DONE );
  66.     if( fReq )
  67.     {
  68.         if( AslRequestTags( fReq,
  69.                            ASLFO_Window, ModuleWnd,
  70.                            ASLFO_SleepWindow, TRUE,
  71.                            ASLFO_TitleText, ( LONG )"Please choose a font...",
  72.                            TAG_DONE ))
  73.         {
  74.             CopyMem( fReq->fo_Attr.ta_Name, Attr->ta_Name, 31 );
  75.             Attr->ta_YSize = fReq->fo_Attr.ta_YSize;
  76.         }
  77.         FreeAslRequest( fReq );
  78.     }
  79.  
  80.     CloseLibrary( AslBase );
  81. }   
  82.  
  83. VOID SendMessageToPort( LONG Type, STRPTR PortName )
  84. {
  85.     struct MsgPort *ForeignPort;
  86.     BlankMsg *ClientMsg;
  87.     
  88.     if( ForeignPort = FindPort( PortName ))
  89.     {
  90.         if( ClientMsg = AllocPooled( Memory, sizeof( BlankMsg )))
  91.         {
  92.             ClientMsg->bm_Mess.mn_ReplyPort = ReplyPort;
  93.             ClientMsg->bm_Mess.mn_Length = sizeof( BlankMsg );
  94.             ClientMsg->bm_Type = Type;
  95.             PutMsg( ForeignPort, ( struct Message * )ClientMsg );
  96.         }
  97.     }
  98. }
  99.  
  100. LONG main( LONG argc, STRPTR argv[] )
  101. {
  102.     Object *VertGroup, *SaveBtn, *TestBtn, *CancelBtn, *DisplayBtn, *CtrlGrp;
  103.     Object *NameInf, *SizeInf;
  104.     LONG i, j, LastNonGrp = 0, DispID = -1, Min, Max, *Types, rc, ID, Sigs;
  105.     BYTE DescripName[108], PrefsName[108], BogusBuf[128], ValidPrefs = FALSE;
  106.     STRPTR *Labels, *KeyStrs, BoxVarName;
  107.     ULONG Args[] = { 0L, 0L };
  108.     Object **Indics;
  109.     BPTR Descrip, Tmp;
  110.  
  111.     if( argc != 2 )
  112.         return RETURN_WARN;
  113.     
  114.     if( FindPort( "GarshnePrefs" ))
  115.         return RETURN_WARN;
  116.  
  117.     IntuitionBase = OpenLibrary( "intuition.library", 37 );
  118.     BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION );
  119.     GarshnelibBase = OpenLibrary( "Garshnelib.library", 37 );
  120.  
  121.     if( !IntuitionBase || !BGUIBase || !GarshnelibBase )
  122.         goto JAIL;
  123.     
  124.     if(!( Memory = CreatePool( MEMF_CLEAR, 1024, 512 )))
  125.         goto JAIL;
  126.  
  127.     if(!( ReplyPort = CreatePort( "GarshnePrefs", 0L )))
  128.         goto JAIL;
  129.  
  130.     strcpy( DescripName, argv[1] );
  131.     strcat( DescripName, ".ifc" );
  132.  
  133.     strcpy( PrefsName, argv[1] );
  134.     strcat( PrefsName, ".prefs" );
  135.     
  136.     if(!( Descrip = Open( DescripName, MODE_OLDFILE )))
  137.         goto JAIL;
  138.  
  139.     NumGadgets = ScanDigit( Descrip );
  140.  
  141.     Objects = AllocPooled( Memory, sizeof( Object * ) * ( NumGadgets + 1 ));
  142.     Indics = AllocPooled( Memory, sizeof( Object * ) * ( NumGadgets + 1 ));
  143.     Prefs = AllocPooled( Memory, sizeof( PrefObject ) * ( NumGadgets + 1 ));
  144.     Types = AllocPooled( Memory, sizeof( LONG ) * ( NumGadgets + 1 ));
  145.     KeyStrs = AllocPooled( Memory, sizeof( STRPTR ) * ( NumGadgets + 1 ));
  146.     
  147.     if( !Objects || !Indics || !Prefs || !Types || !KeyStrs )
  148.         goto PREJAIL;
  149.  
  150.     VertGroup = BGUI_NewObject( BGUI_GROUP_GADGET,
  151.                                GROUP_Style, GRSTYLE_VERTICAL,
  152.                                HOffset( 3 ), VOffset( 3 ), Spacing( 3 ),
  153.                                TAG_END );
  154.  
  155.     BoxVarName = MakeBoxVarName( FilePart( argv[0] ), FilePart( argv[1] ));
  156.  
  157.     if( GetVar37( BoxVarName, ( STRPTR )&WinBox, sizeof( struct IBox ),
  158.                  GVF_BINARY_VAR|GVF_DONT_NULL_TERM ) != -1 )
  159.     {
  160.         OldBox = WinBox;
  161.         ModuleObj = BGUI_NewObject( BGUI_WINDOW_OBJECT,
  162.                                    WINDOW_MasterGroup, VertGroup,
  163.                                    WINDOW_Title, FilePart( argv[1] ),
  164.                                    WINDOW_Bounds, &WinBox,
  165.                                    TAG_END );
  166.     }
  167.     else
  168.     {
  169.         ModuleObj = BGUI_NewObject( BGUI_WINDOW_OBJECT,
  170.                                    WINDOW_MasterGroup, VertGroup,
  171.                                    WINDOW_Title, FilePart( argv[1] ),
  172.                                    TAG_END );
  173.     }
  174.         
  175.     if( Tmp = Open( PrefsName, MODE_OLDFILE ))
  176.     {
  177.         Read( Tmp, Prefs, sizeof( LONG )); /* Ignore entry count */
  178.         if( Read( Tmp, Prefs, sizeof( PrefObject ) * NumGadgets ) ==
  179.            sizeof( PrefObject ) * NumGadgets )
  180.             ValidPrefs = TRUE;
  181.         Close( Tmp );
  182.     }
  183.  
  184.     for( i = 0; i < NumGadgets; i++ )
  185.     {
  186.         STRPTR IDStr, LabelStr;
  187.         
  188.         IDStr = ScanToken( Descrip );
  189.         switch( tolower( IDStr[0] ))
  190.         {
  191.         case 'c':
  192.             Types[i] = GAD_CYCLE;
  193.             break;
  194.         case 'd':
  195.             Types[i] = ( tolower( IDStr[1] ) == 'i' )? GAD_DISPLAY : GAD_DELIM;
  196.             break;
  197.         case 'f':
  198.             Types[i] = GAD_FONT;
  199.             break;
  200.         case 's':
  201.             Types[i] = ( tolower( IDStr[1] ) == 'l' )? GAD_SLIDER : GAD_STRING;
  202.             break;
  203.         }
  204.         
  205.         switch( Prefs[i].po_Type = Types[i] )
  206.         {
  207.         case GAD_CYCLE:
  208.             LabelStr = ScanToken( Descrip );
  209.             KeyStrs[i] = ScanToken( Descrip );
  210.             Labels = ScanTokenArray( Descrip );
  211.             if( ValidPrefs )
  212.                 ScanDigit( Descrip );
  213.             else
  214.                 Prefs[i].po_Active = ScanDigit( Descrip );
  215.             Objects[i] =
  216.                 BGUI_NewObject( BGUI_CYCLE_GADGET,
  217.                                GA_ID, i + 10,
  218.                                LAB_Label, LabelStr,
  219.                                LAB_Underscore, '_',
  220.                                FRM_Type, FRTYPE_BUTTON,
  221.                                CYC_Labels, Labels,
  222.                                CYC_Active, Prefs[i].po_Active,
  223.                                TAG_DONE );
  224.             break;
  225.         case GAD_SLIDER:
  226.             LabelStr = ScanToken( Descrip );
  227.             KeyStrs[i] = ScanToken( Descrip );
  228.             Min = ScanDigit( Descrip );
  229.             Max = ScanDigit( Descrip );
  230.             if( ValidPrefs )
  231.                 ScanDigit( Descrip );
  232.             else
  233.                 Prefs[i].po_Level = ScanDigit( Descrip );
  234.             Objects[i] =
  235.                 BGUI_NewObject( BGUI_SLIDER_GADGET,
  236.                                GA_ID, i + 10,
  237.                                LAB_Label, LabelStr,
  238.                                LAB_Underscore, '_',
  239.                                SLIDER_Min, Min, 
  240.                                SLIDER_Max, Max,
  241.                                SLIDER_Level, Prefs[i].po_Level,
  242.                                TAG_DONE );
  243.             Indics[i] =
  244.                 BGUI_NewObject( BGUI_INDICATOR_GADGET,
  245.                                INDIC_Min, Min,
  246.                                INDIC_Max, Max,
  247.                                INDIC_Level, Prefs[i].po_Level,
  248.                                INDIC_Justification, IDJ_CENTER,
  249.                                TAG_DONE );
  250.             break;
  251.         case GAD_FONT:
  252.             if( ValidPrefs )
  253.             {
  254.                 ScanToken( Descrip );
  255.                 ScanDigit( Descrip );
  256.             }
  257.             else
  258.             {
  259.