📄 trace_impl.c
字号:
return "TRACE_Get_next_composite(): Memory violation " "detected after writing ByteInfo.\n"; case 49: return "TRACE_Peek_next_composite(): Unexpected EOF detected."; case 60: return "Cannot locate YCOORDMAP in the internal table."; case 61: return "TRACE_Peek_next_ycoordmap(): Inconsistency detected " "in the number of methods from input text file.\n"; case 63: return "TRACE_Get_next_ycoordmap(): Memory violation " "detected before writing Yaxis coordinate map.\n"; case 64: return "TRACE_Get_next_ycoordmap(): Memory violation " "detected after writing Yaxis coordinate map.\n"; case 65: return "TRACE_Get_next_ycoordmap(): Memory violation " "detected before writing MethodIDs.\n"; case 66: return "TRACE_Get_next_ycoordmap(): Memory violation " "detected after writing Methods.\n"; default: return "Unknown Message ID "; }}TRACE_EXPORTint TRACE_Open( const char filespec[], TRACE_file *fp ){ TRACE_file tr; if ( strncmp( filespec, "-h", 2 ) == 0 ) { *fp = NULL; return 0; } tr = (TRACE_file) malloc( sizeof(struct _trace_file) ); tr->fd = fopen( filespec, "r" ); if ( tr->fd == NULL ) { *fp = NULL; return 1; } tr->max_types = MAX_CATEGORIES; tr->num_types = 0; tr->types = (DRAW_Category **) malloc( tr->max_types * sizeof(DRAW_Category *) ); tr->ymap = NULL; tr->prime = NULL; tr->cmplx = NULL; *fp = tr; return 0;}TRACE_EXPORTint TRACE_Close( TRACE_file *fp ){ TRACE_file tr; int idx; tr = *fp; if ( tr->types != NULL ) { for ( idx = 0; idx < tr->num_types; idx++ ) { Category_free( tr->types[ idx ] ); tr->types[ idx ] = NULL; } tr->num_types = 0; free( tr->types ); } if ( tr->prime != NULL ) { Primitive_free( tr->prime ); tr->prime = NULL; } if ( tr->cmplx != NULL ) { Composite_free( tr->cmplx ); tr->cmplx = NULL; } if ( tr->fd != NULL ) fclose( tr->fd ); *fp = NULL; return 0;}TRACE_EXPORTint TRACE_Peek_next_kind( const TRACE_file fp, TRACE_Rec_Kind_t *next_kind ){ while ( fgets( fp->line, MAX_LINE_LEN, fp->fd ) != NULL ) { if ( strncmp( fp->line, "Category", 8 ) == 0 ) { *next_kind = TRACE_CATEGORY; return 0; } else if ( strncmp( fp->line, "YCoordMap", 9 ) == 0 ) { *next_kind = TRACE_YCOORDMAP; return 0; } else if ( strncmp( fp->line, "Primitive", 9 ) == 0 ) { *next_kind = TRACE_PRIMITIVE_DRAWABLE; return 0; } else if ( strncmp( fp->line, "Composite", 9 ) == 0 ) { *next_kind = TRACE_COMPOSITE_DRAWABLE; return 0; } } *next_kind = TRACE_EOF; return 0;}TRACE_EXPORTint TRACE_Peek_next_category( const TRACE_file fp, int *num_legend, int *num_label, int *num_methods ){ DRAW_Category *type; TRACE_Category_head_t *hdr; char typename[10]; int type_idx; int line_pos; char *newline; char *info_A, *info_B; char category_format[] = "%s index=%d name=%s topo=%s " "color=(%d,%d,%d,%d,%s width=%d %n"; char topology[10]; int red, green, blue, alpha; char mody[10]; int width; char legend[MAX_LEGEND_LEN]; int legend_len; char label[MAX_LABEL_LEN]; int label_len; char str4methods[MAX_LABEL_LEN]; int methods_len; sscanf( fp->line, category_format, typename, &type_idx, legend, topology, &red, &green, &blue, &alpha, mody, &width, &line_pos );#if defined( DEBUG ) printf( "%s %d %s %s (%d,%d,%d,%d) %d ", typename, type_idx, legend, topology, red, green, blue, alpha, width ); fflush( NULL );#endif legend_len = strlen( legend ); newline = (char *) (fp->line + line_pos); /* Set InfoKeys */ info_A = NULL; info_B = NULL; if ( ( info_A = strstr( newline, "< " ) ) != NULL && ( info_B = strstr( info_A, " >" ) ) != NULL ) { info_A = (char *) (info_A + 2); sprintf( info_B, "%c", '\0' ); strncpy( label, info_A, MAX_LABEL_LEN );#if defined( DEBUG ) printf( "<%s>", label ); fflush( NULL );#endif newline = (char *) (info_B + 2); label_len = strlen( label ); } else label_len = 0;#if defined( DEBUG ) printf( "\n" ); fflush( NULL );#endif /* Set Methods */ info_A = NULL; info_B = NULL; if ( ( info_A = strstr( newline, "{ " ) ) != NULL && ( info_B = strstr( info_A, " }" ) ) != NULL ) { info_A = (char *) (info_A + 2); sprintf( info_B, "%c", '\0' ); strncpy( str4methods, info_A, MAX_LABEL_LEN );#if defined( DEBUG ) printf( "{%s}", str4methods ); fflush( NULL );#endif newline = (char *) (info_B + 2); /* Assume only 1 method ID */ methods_len = 1; } else methods_len = 0;#if defined( DEBUG ) printf( "\n" ); fflush( NULL );#endif type = Category_alloc( legend_len, label_len, methods_len ); hdr = type->hdr; /* Set the Output Parameters of the routine */ hdr->index = type_idx; if ( strncmp( topology, "Event", 5 ) == 0 ) hdr->shape = TRACE_SHAPE_EVENT; else if ( strncmp( topology, "State", 5 ) == 0 ) hdr->shape = TRACE_SHAPE_STATE; else if ( strncmp( topology, "Arrow", 5 ) == 0 ) hdr->shape = TRACE_SHAPE_ARROW; else { fprintf( stderr, "TRACE_Peek_next_category(): Unknown shape.\n" ); hdr->shape = -1; } hdr->red = red; hdr->green = green; hdr->blue = blue; hdr->alpha = alpha; hdr->width = width; if ( legend_len > 0 ) strcpy( type->legend, legend ); if ( label_len > 0 ) strcpy( type->label, label ); if ( methods_len > 0 ) /* Assume 1 method ID */ type->methods[ 0 ] = atoi( str4methods ); if ( fp->num_types >= fp->max_types ) return 10; fp->types[ fp->num_types ] = type; *num_legend = legend_len; *num_label = label_len; *num_methods = methods_len; return 0;}TRACE_EXPORTint TRACE_Get_next_category( const TRACE_file fp, TRACE_Category_head_t *head, int *num_legend, char legend_base[], int *legend_pos, const int legend_max, int *num_label, char label_base[], int *label_pos, const int label_max, int *num_methods, int method_base[], int *method_pos, const int method_max ){ DRAW_Category *type; int legend_len, label_len; type = fp->types[ fp->num_types ]; if ( type == NULL ) { fprintf( stderr, "TRACE_Get_next_category(): Cannot locate " "current category in Category Table.\n" ); return 20; } (fp->num_types)++; /* Copy current Category_head_t to the caller's allocated buffer */ Category_head_copy( head, type->hdr ); if ( type->legend != NULL ) { legend_len = strlen( type->legend ); if ( legend_len > 0 ) { if ( *legend_pos >= legend_max ) return 21; memcpy( &(legend_base[ *legend_pos ]), type->legend, sizeof( char ) * legend_len ); *num_legend = legend_len; *legend_pos += *num_legend; if ( *legend_pos > legend_max ) return 22; } } if ( type->label != NULL ) { label_len = strlen( type->label ); if ( label_len > 0 ) { if ( *label_pos >= label_max ) return 23; memcpy( &(label_base[ *label_pos ]), type->label, sizeof( char ) * label_len ); *num_label = label_len; *label_pos += *num_label; if ( *label_pos > label_max ) return 24; } } if ( type->num_methods > 0 ) { if ( *method_pos >= method_max ) return 25; memcpy( &(method_base[ *method_pos ]), type->methods, sizeof( int ) * type->num_methods ); *num_methods = type->num_methods; *method_pos += *num_methods; if ( *method_pos > method_max ) return 26; } return 0;}TRACE_EXPORTint TRACE_Peek_next_ycoordmap( TRACE_file fp, int *num_rows, int *num_columns, int *max_column_name, int *max_title_name, int *num_methods ){ DRAW_YCoordMap *ymap; char mapname[10]; int Nrows, Ncols, Nmeths; int line_pos; char *newline; char ymap_sz_fmt[] = "%s Nrows=%d Ncolumns=%d Nmethods=%d %n"; char title_fmt[] = "title=%s colnames=< %n"; int *map_elems; int max_colnames; char *info_A, *info_B; char str4methods[MAX_LABEL_LEN]; int methods_len; int icol, irow, idx; sscanf( fp->line, ymap_sz_fmt, mapname, &Nrows, &Ncols, &Nmeths, &line_pos );#if defined( DEBUG ) printf( "%s(%d,%d,%d)] :\n", mapname, Nrows, Ncols, Nmeths );#endif newline = (char *)(fp->line+line_pos); ymap = YCoordMap_alloc( Nrows, Ncols, Nmeths ); sscanf( newline, title_fmt, ymap->title_name, &line_pos ); newline = (char *) (newline+line_pos);#if defined( DEBUG ) printf( "Title=%s \nColumnLabels=< LineID -> ", ymap->title_name );#endif max_colnames = 0; for ( icol = 0; icol < Ncols-1; icol++ ) { sscanf( newline, "%s %n", ymap->column_names[icol], &line_pos ); newline = (char *) (newline+line_pos);#if defined( DEBUG ) printf( "%s ", ymap->column_names[icol] );#endif if ( max_colnames < strlen( ymap->column_names[icol] ) + 1 ) max_colnames = strlen( ymap->column_names[icol] ) + 1; } newline += 2;#if defined( DEBUG ) printf( ">\n" );#endif map_elems = ymap->elems; idx = 0; for ( irow = 0; irow < Nrows; irow++ ) { sscanf( newline, "( %d %n", &map_elems[ idx++ ], &line_pos ); newline = (char *) (newline+line_pos);#if defined( DEBUG ) printf( "%d -> ", map_elems[ idx-1 ] );#endif for ( icol = 1; icol < Ncols-1; icol++ ) { sscanf( newline, "%d %n", &map_elems[ idx++ ], &line_pos ); newline = (char *) (newline+line_pos);#if defined( DEBUG ) printf( "%d ", map_elems[ idx-1] );#endif } sscanf( newline, "%d ) %n", &map_elems[ idx++ ], &line_pos ); newline = (char *) (newline+line_pos);#if defined( DEBUG ) printf( "%d\n", map_elems[ idx-1 ] );#endif } /* Set Methods */ info_A = NULL; info_B = NULL; if ( ( info_A = strstr( newline, "{ " ) ) != NULL && ( info_B = strstr( info_A, " }" ) ) != NULL ) { info_A = (char *) (info_A + 2); sprintf( info_B, "%c", '\0' ); strncpy( str4methods, info_A, MAX_LABEL_LEN );#if defined( DEBUG ) printf( "{%s}", str4methods );#endif newline = (char *) (info_B + 2); /* Assume only 1 method ID */ methods_len = 1; } else methods_len = 0;#if defined( DEBUG ) printf( "\n" );#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -