show_base.c
1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* NINTENDO64 SAMPLE PROGRAM
*
* FILE : show_base.c
*
* Copyright (C) 1998, NINTENDO Co,Ltd.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ultra64.h>
/*
* 関数プロトタイプ宣言
*/
void syserror(char *);
u32 showBase(FILE *);
/*
* 定義
*/
#define MAX_FILENAME_LENGTH 128
/*
* メイン
*/
void main(int argc, char *argv[])
{
FILE *infofd;
if(argc != 2)
syserror("Usage : show_base <info file>");
if(!(infofd = fopen(argv[1], "r")))
syserror("Error : can't open file : info file");
if(!showBase(infofd))
syserror("Error : bad file : info file");
fclose(infofd);
}
/*
* エラー出力
*/
void syserror(char *out)
{
fprintf(stderr, "%s\n", out);
exit(1);
}
/*
* infoファイルより波形データ数を取得
*/
u32 showBase(FILE *infofd)
{
u32
flag = 0,
count = 0;
char
str[128],
filename[MAX_FILENAME_LENGTH],
*strtmp,
separater[] = " \t\n:;=()";
while(fgets(str, 128, infofd)){
strtmp = strtok(str, separater);
if(strtmp){
if(!strcmp(strtmp, "Wave")){
if(flag)
syserror("Error : bad file : info file");
strtmp = strtok(NULL, separater);
if((!strtmp) || strcmp(strtmp, "Table"))
syserror("Error : bad file : info file");
strtmp = strtok(NULL, separater);
if(!strtmp)
syserror("Error : bad file : info file");
strcpy(filename, strtmp);
flag = 1;
}
else if(!strcmp(strtmp, "base")){
if(!flag)
syserror("Error : bad file : info file");
count ++;
strtmp = strtok(NULL, separater);
if(!strtmp)
syserror("Error : bad file : info file");
printf("%s \t: 0x%x\n", filename, strtol(strtmp, NULL, 16));
flag = 0;
}
}
}
return count;
}