home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 2 / MECOMP-CD-II.iso / amiga / datatypes / mpegsystem_datatype / prefs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-01  |  8.2 KB  |  298 lines

  1.  
  2. /*
  3. **
  4. **  $VER: prefs.c 1.5 (1.6.98)
  5. **  mpegsystem.datatype 1.5
  6. **
  7. **  Prefernces
  8. **
  9. **  Written 1997/1998 by Roland 'Gizzy' Mainz
  10. **  Original example source from David N. Junod
  11. **
  12. */
  13.  
  14. /* main includes */
  15. #include "classbase.h"
  16. #include "classdata.h"
  17.  
  18.  
  19. /****** mpegsystem.datatype/preferences *****************************************
  20. *
  21. *   NAME
  22. *       preferences
  23. *
  24. *   DESCRIPTION
  25. *       The "ENV:Classes/DataTypes/mpegsystem.prefs" file contains global
  26. *       settings for the datatype.
  27. *       The preferences file is an ASCII file containing one line where the
  28. *       preferences can be set.
  29. *       It can be superset by a local variable with the same name.
  30. *
  31. *       Each line can contain settings, special settings for some projects
  32. *       can be set using the MATCHPROJECT option.
  33. *       Lines beginning with a '#' or ';' chars are treated as comments.
  34. *       Lines are limitted to 256 chars.
  35. *
  36. *   TEMPLATE
  37. *       MATCHPROJECT/K,VERBOSE/S,NOVERBOSE/S,VERBOSESYNTAX/S,
  38. *       NOVERBOSESYNTAX/S,VERBOSEDEBUG=DEBUG/S,NOVERBOSEDEBUG=NODEBUG/S,
  39. *       IGNOREERRORS/S,NOIGNOREERRORS/S
  40. *
  41. *       MATCHPROJECT -- The settings in this line belongs only to this
  42. *           project(s), e.g. if the case-insensitive pattern does not match,
  43. *           this line is ignored.
  44. *           The maximum length of the pattern is 128 chars.
  45. *           Defaults to #?, which matches any project.
  46. *
  47. *       VERBOSE -- Print information about the animation. Currently
  48. *           the frame numbers and the used compression are printed, after all
  49. *           number of scanned/loaded frames, set FPS rate, dimensions (width/
  50. *           height/depth), sample information etc.
  51. *
  52. *       NOVERBOSE -- Turns VERBOSE mode off.
  53. *           Be _carefull_ with this options, this turns really ALL error 
  54. *           messages OFF !
  55. *
  56. *       VERBOSESYNTAX -- Print information about syntax errors
  57. *
  58. *       NOVERBOSESYNTAX -- Turns the VERBOSESYNTAX option off.
  59. *
  60. *       DEBUG
  61. *       VERBOSEDEBUG -- Turns debugging mode on to get internal debugging
  62. *           info without recompiling the whole source.
  63. *
  64. *       NODEBUG
  65. *       NOVERBOSEDEBUG -- Turns the DEBUG option off.
  66. *
  67. *       IGNOREERRORS -- Ignores errors if system stream parsing fails;
  68. *           the video+audio parts attempts to load the data until the
  69. *           last scanned packet occurs.
  70. *
  71. *       NOIGNOREERRORS -- Turns the IGNOREERRORS option off.
  72. *
  73. *   NOTE
  74. *       - An invalid prefs file line will be ignored and forces the VERBOSE
  75. *         output.
  76. *
  77. *   BUGS
  78. *       - Low memory may cause that the prefs file won't be parsed.
  79. *
  80. *       - Lines are limitted to 256 chars
  81. *
  82. *       - An invalid prefs file line will be ignored.
  83. *
  84. *       - The sample path length is limitted to 200 chars. A larger
  85. *         value may crash the machine if an error occurs.
  86. *
  87. ******************************************************************************
  88. *
  89. */
  90.  
  91.  
  92. static
  93. STRPTR GetPrefsVar( struct ClassBase *cb, STRPTR name )
  94. {
  95.           STRPTR buff;
  96.     const ULONG  buffsize = 16UL;
  97.  
  98.     if( buff = (STRPTR)AllocVec( (buffsize + 2UL), (MEMF_PUBLIC | MEMF_CLEAR) ) )
  99.     {
  100.       if( GetVar( name, buff, buffsize, GVF_BINARY_VAR ) != (-1L) )
  101.       {
  102.         ULONG varsize = IoErr();
  103.  
  104.         varsize += 2UL;
  105.  
  106.         if( varsize > buffsize )
  107.         {
  108.           FreeVec( buff );
  109.  
  110.           if( buff = (STRPTR)AllocVec( (varsize + 2UL), (MEMF_PUBLIC | MEMF_CLEAR) ) )
  111.           {
  112.             if( GetVar( name, buff, varsize, GVF_BINARY_VAR ) != (-1L) )
  113.             {
  114.               return( buff );
  115.             }
  116.           }
  117.         }
  118.         else
  119.         {
  120.           return( buff );
  121.         }
  122.       }
  123.  
  124.       FreeVec( buff );
  125.     }
  126.  
  127.     return( NULL );
  128. }
  129.  
  130.  
  131. static
  132. BOOL matchstr( struct ClassBase *cb, STRPTR pat, STRPTR s )
  133. {
  134.     TEXT buff[ 512 ];
  135.  
  136.     if( pat && s )
  137.     {
  138.       if( ParsePatternNoCase( pat, buff, (sizeof( buff ) - 1) ) != (-1L) )
  139.       {
  140.         if( MatchPatternNoCase( buff, s ) )
  141.         {
  142.           return( TRUE );
  143.         }
  144.       }
  145.     }
  146.  
  147.     return( FALSE );
  148. }
  149.  
  150.  
  151. void ReadENVPrefs( struct ClassBase *cb, struct MPEGSystemInstData *msid )
  152. {
  153.     struct RDArgs envvarrda =
  154.     {
  155.       NULL,
  156.       256L,
  157.       0L,
  158.       0L,
  159.       NULL,
  160.       0L,
  161.       NULL,
  162.       RDAF_NOPROMPT
  163.     };
  164.  
  165.     struct
  166.     {
  167.       STRPTR  matchproject;
  168.       long   *verbose;
  169.       long   *noverbose;
  170.       long   *dosyntax;
  171.       long   *nodosyntax;
  172.       long   *dodebug;
  173.       long   *nododebug;
  174.       long   *ignoreerrors;
  175.       long   *noignoreerrors;
  176.     } mpegsystemargs;
  177.  
  178.     TEXT   varbuff[ 258 ];
  179.     STRPTR var;
  180.  
  181.     if( var = GetPrefsVar( cb, "Classes/DataTypes/mpegsystem.prefs" ) )
  182.     {
  183.       STRPTR prefsline      = var,
  184.              nextprefsline;
  185.       ULONG  linecount      = 1UL;
  186.  
  187.       /* Be sure that "var" contains at least one break-char */
  188.       strcat( var, "\n" );
  189.  
  190.       while( nextprefsline = strpbrk( prefsline, "\n" ) )
  191.       {
  192.         stccpy( varbuff, prefsline, (int)MIN( (sizeof( varbuff ) - 2UL), (((ULONG)(nextprefsline - prefsline)) + 1UL) ) );
  193.  
  194.         /* be sure that this line isn't a comment line or an empty line */
  195.         if( (varbuff[ 0 ] != '#') && (varbuff[ 0 ] != ';') && (varbuff[ 0 ] != '\n') && (strlen( varbuff ) > 2UL) )
  196.         {
  197.           /* Prepare ReadArgs processing */
  198.           strcat( varbuff, "\n" );                                       /* Add NEWLINE-char            */
  199.           envvarrda . RDA_Source . CS_Buffer = varbuff;                  /* Buffer                      */
  200.           envvarrda . RDA_Source . CS_Length = strlen( varbuff ) + 1UL;  /* Set up input buffer length  */
  201.           envvarrda . RDA_Source . CS_CurChr = 0L;
  202.           envvarrda . RDA_Buffer = NULL;
  203.           envvarrda . RDA_BufSiz = 0L;
  204.           memset( (void *)(&mpegsystemargs), 0, sizeof( mpegsystemargs ) );          /* Clear result array          */
  205.  
  206.           if( ReadArgs( "MATCHPROJECT/K,"
  207.                         "VERBOSE/S,"
  208.                         "NOVERBOSE/S,"
  209.                         "VERBOSESYNTAX/S,"
  210.                         "NOVERBOSESYNTAX/S,"
  211.                         "VERBOSEDEBUG=DEBUG/S,"
  212.                         "NOVERBOSEDEBUG=NODEBUG/S,"
  213.                         "IGNOREERRORS/S,"
  214.                         "NOIGNOREERRORS/S", (LONG *)(&mpegsystemargs), (&envvarrda) ) )
  215.           {
  216.             BOOL noignore = TRUE;
  217.  
  218.             if( (mpegsystemargs . matchproject) && (msid -> msid_ProjectName) )
  219.             {
  220.               noignore = matchstr( cb, (mpegsystemargs . matchproject), (msid -> msid_ProjectName) );
  221.             }
  222.  
  223.             if( noignore )
  224.             {
  225.               if( mpegsystemargs . verbose )
  226.               {
  227.                 OpenLogfile( cb, msid );
  228.               }
  229.  
  230.               if( mpegsystemargs . noverbose )
  231.               {
  232.                 if( (msid -> msid_VerboseOutput) && ((msid -> msid_VerboseOutput) != -1L) )
  233.                 {
  234.                   Close( (msid -> msid_VerboseOutput) );
  235.                 }
  236.  
  237.                 msid -> msid_VerboseOutput = -1L;
  238.               }
  239.  
  240.               if( mpegsystemargs . dosyntax )
  241.               {
  242.                 msid -> msid_DoSyntax = TRUE;
  243.               }
  244.  
  245.               if( mpegsystemargs . nodosyntax )
  246.               {
  247.                 msid -> msid_DoSyntax = FALSE;
  248.               }
  249.  
  250.               if( mpegsystemargs . dodebug )
  251.               {
  252.                 msid -> msid_DoDebug = TRUE;
  253.               }
  254.  
  255.               if( mpegsystemargs . nododebug )
  256.               {
  257.                 msid -> msid_DoDebug = FALSE;
  258.               }
  259.  
  260.               if( mpegsystemargs . ignoreerrors )
  261.               {
  262.                 msid -> msid_IgnoreErrors = TRUE;
  263.               }
  264.  
  265.               if( mpegsystemargs . noignoreerrors )
  266.               {
  267.                 msid -> msid_IgnoreErrors = FALSE;
  268.               }
  269.             }
  270.             else
  271.             {
  272.               verbose_printf( cb, msid, "prefs line %lu ignored\n", linecount );
  273.             }
  274.  
  275.             FreeArgs( (&envvarrda) );
  276.           }
  277.           else
  278.           {
  279.             LONG ioerr = IoErr();
  280.             TEXT errbuff[ 256 ];
  281.  
  282.             Fault( ioerr, "Classes/DataTypes/mpegsystem.prefs", errbuff, (LONG)sizeof( errbuff ) );
  283.  
  284.             error_printf( cb, msid, "preferences \"%s\" line %lu\n", errbuff, linecount );
  285.           }
  286.         }
  287.  
  288.         prefsline = ++nextprefsline;
  289.         linecount++;
  290.       }
  291.  
  292.       FreeVec( var );
  293.     }
  294. }
  295.  
  296.  
  297.  
  298.