Annotation of hatari/src/trace.c, revision 1.1.1.2

1.1       root        1: /*
                      2:  * Hatari - trace.c
                      3:  *
                      4:  * This file is distributed under the GNU Public License, version 2 or at
                      5:  * your option any later version. Read the file gpl.txt for details.
                      6:  *
                      7:  * This files allows to dynamically output trace messages, based on the content
                      8:  * of HatariTraceLevel. Multiple trace levels can be set at once, by setting
                      9:  * the corresponding bits in HatariTraceLevel/
                     10:  *
                     11: */
                     12: 
1.1.1.2 ! root       13: const char Trace_rcsid[] = "Hatari $Id: trace.c,v 1.5 2008/03/30 10:08:38 thothy Exp $";
1.1       root       14: 
                     15: 
1.1.1.2 ! root       16: /* 2007/09/28  [NP]    Creation of trace.c                             */
1.1       root       17: 
                     18: 
1.1.1.2 ! root       19: #include <stdlib.h>
1.1       root       20: #include <string.h>
                     21: #include <stdio.h>
                     22: 
                     23: #include "trace.h"
                     24: 
                     25: 
                     26: struct { Uint32 Level;
                     27:         const char *Name;
                     28: }
                     29: TraceOptions[] = {
                     30:        { HATARI_TRACE_VIDEO_SYNC       , "video_sync" } ,
                     31:        { HATARI_TRACE_VIDEO_RES        , "video_res" } ,
                     32:        { HATARI_TRACE_VIDEO_COLOR      , "video_color" } ,
                     33:        { HATARI_TRACE_VIDEO_BORDER_V   , "video_border_v" } ,
                     34:        { HATARI_TRACE_VIDEO_BORDER_H   , "video_border_h" } ,
                     35:        { HATARI_TRACE_VIDEO_ADDR       , "video_addr" } ,
                     36:        { HATARI_TRACE_VIDEO_HBL        , "video_hbl" } ,
                     37:        { HATARI_TRACE_VIDEO_VBL        , "video_vbl" } ,
                     38:        { HATARI_TRACE_VIDEO_STE        , "video_ste" } ,
                     39:        { HATARI_TRACE_VIDEO_ALL        , "video_all" } ,
                     40: 
                     41:        { HATARI_TRACE_MFP_EXCEPTION    , "mfp_exception" } ,
                     42:        { HATARI_TRACE_MFP_START        , "mfp_start" } ,
                     43:        { HATARI_TRACE_MFP_READ         , "mfp_read" } ,
                     44:        { HATARI_TRACE_MFP_WRITE        , "mfp_write" } ,
                     45:        { HATARI_TRACE_MFP_ALL          , "mfp_all" } ,
                     46: 
                     47:        { HATARI_TRACE_PSG_WRITE_REG    , "psg_write_reg" } ,
                     48:        { HATARI_TRACE_PSG_WRITE_DATA   , "psg_write_data" } ,
                     49:        { HATARI_TRACE_PSG_ALL          , "psg_all" } ,
                     50: 
                     51:        { HATARI_TRACE_CPU_PAIRING      , "cpu_pairing" } ,
                     52:        { HATARI_TRACE_CPU_DISASM       , "cpu_disasm" } ,
                     53:        { HATARI_TRACE_CPU_EXCEPTION    , "cpu_exception" } ,
                     54:        { HATARI_TRACE_CPU_ALL          , "cpu_all" } ,
                     55: 
                     56:        { HATARI_TRACE_INT              , "int" } ,
                     57: 
                     58:        { HATARI_TRACE_FDC              , "fdc" } ,
                     59: 
                     60:        { HATARI_TRACE_IKBD             , "ikbd" } ,
                     61: 
                     62: 
                     63:        { HATARI_TRACE_ALL              , "all" }
                     64: };
                     65: 
                     66: 
                     67: Uint32 HatariTraceLevel = HATARI_TRACE_NONE;
                     68: 
                     69: 
                     70: 
                     71: /* Parse a list of comma separated strings.            */
                     72: /* If the string is prefixed with an optional '+',     */
                     73: /* corresponding trace level is turned on.             */
                     74: /* If the string is prefixed with a '-', corresponding */
                     75: /* trace level is turned off.                          */
                     76: /* Result is stored in HatariTraceLevel.               */
                     77: 
                     78: int    ParseTraceOptions ( char *OptionsStr )
                     79: {
                     80:   char *OptionsCopy;
                     81:   char *cur, *sep;
                     82:   int  i;
                     83:   int  Mode;                           /* 0=add, 1=del */
                     84:   int  MaxOptions;
                     85: 
1.1.1.2 ! root       86: #ifndef HATARI_TRACE_ACTIVATED
        !            87:   fprintf(stderr, "\nError: Trace option has not been activated during compile time.\n");
        !            88:   exit(1);
        !            89: #endif
1.1       root       90: 
                     91:   MaxOptions = sizeof ( TraceOptions ) / sizeof ( TraceOptions[ 0 ] );
                     92: 
                     93:   /* special case for "help" : display the list of possible trace levels */
                     94:   if ( strcmp ( OptionsStr , "help" ) == 0 )
                     95:     {
                     96:       fprintf ( stderr , "\nList of available trace levels :\n" );
                     97: 
                     98:       for ( i = 0 ; i < MaxOptions ; i++ )
                     99:        fprintf ( stderr , "  %s\n" , TraceOptions[ i ].Name );
                    100: 
                    101:       fprintf ( stderr , "Multiple trace levels can be separated by ','\n" );
                    102:       fprintf ( stderr , "Levels can be prefixed by '+' or '-' to be mixed.\n\n" );
                    103:       return 0;
                    104:     }
                    105: 
                    106:   HatariTraceLevel = HATARI_TRACE_NONE;
                    107: 
                    108:   OptionsCopy = strdup ( OptionsStr );
                    109:   if ( !OptionsCopy )
                    110:     {
                    111:       fprintf ( stderr , "strdup error in ParseTraceOptions\n" );
                    112:       return 0;
                    113:     }
                    114: 
                    115:   cur = OptionsCopy;
                    116:   while ( cur )
                    117:     {
                    118:       sep = strchr ( cur , ',' );
                    119:       if ( sep )                       /* end of next options */
                    120:         *sep++ = '\0';
                    121: 
                    122:       Mode = 0;                                /* default is 'add' */
                    123:       if ( *cur == '+' )
                    124:         { Mode = 0; cur++; }
                    125:       else if ( *cur == '-' )
                    126:         { Mode = 1; cur++; }
                    127: 
                    128:       for ( i = 0 ; i < MaxOptions ; i++ )
                    129:        {
                    130:          if ( strcmp ( cur , TraceOptions[ i ].Name ) == 0 )
                    131:            break;
                    132:        }
                    133: 
                    134:       if ( i < MaxOptions )            /* option found */
                    135:        {
                    136:          if ( Mode == 0 )      HatariTraceLevel |= TraceOptions[ i ].Level;
                    137:          else                  HatariTraceLevel &= (~TraceOptions[ i ].Level);
                    138:        }
                    139: 
                    140:       else
                    141:         {
                    142:          fprintf ( stderr , "unknown trace option %s\n" , cur );
                    143:          free ( OptionsCopy );
                    144:          return 0;
                    145:        }
                    146: 
                    147:       cur = sep;
                    148:     }
                    149: 
                    150:   //fprintf ( stderr , "trace parse <%x>\n" , HatariTraceLevel );
                    151: 
                    152:   free ( OptionsCopy );
                    153:   return 1;
                    154: }
                    155: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.