{ "", NULL }
};
-ASPTR *asptr;
+ASPTR *asptr = NULL;
ASMODE asmode = {false, false, false, false, false};
WORD getadr(const char *prog, const char *str, PASS pass)
{
- WORD adr = 0x0;
+ WORD adr = 0;
if(str[0] == '=') {
adr = getliteral(str, pass);
WORD grword(const char *str, bool is_x)
{
- WORD r;
+ WORD r = 0;
/* "GR[0-7]" 以外の文字列では、0xFFFFを返して終了 */
if(strlen(str) != 3 ||
/* GR0は指標レジスタとして用いることができない */
if(is_x == true && r == 0x0) {
setcerr(120, ""); /* GR0 in operand x */
- return 0x0;
+ return 0;
}
return r;
}
void writememory(WORD word, WORD adr, PASS pass)
{
- char *n;
+ char *n = NULL;
/* メモリオーバーの場合、エラー発生 */
if(adr >= sys->memsize) {
void writestr(const char *str, bool literal, PASS pass)
{
assert(str[0] == '\'');
- int i;
bool lw = false;
/* 「'」の場合、1文字スキップし、次の文字が「'」でなければ正常終了 */
- for(i = 1; str[i] != '\'' || str[++i] == '\''; i++) {
+ for(int i = 1; str[i] != '\'' || str[++i] == '\''; i++) {
/* 「'」が閉じないまま文字列が終了した場合はエラー */
if(!str[i]) {
setcerr(123, str); /* unclosed quote */
void assemble_ds(const CMDLINE *cmdl, PASS pass)
{
- int i;
if(cmdl->opd->opdc != 1) {
setcerr(106, ""); /* operand count mismatch */
return;
}
- for(i = 0; i < atoi(cmdl->opd->opdv[0]); i++) {
+ for(int i = 0; i < atoi(cmdl->opd->opdv[0]); i++) {
writememory(0x0, (asptr->ptr)++, pass);
if(cerr->num > 0) {
break;
void assemble_dc(const CMDLINE *cmdl, PASS pass)
{
- int i;
if(cmdl->opd->opdc == 0 || cmdl->opd->opdc >= OPDSIZE) {
setcerr(106, ""); /* operand count mismatch */
return;
}
- for(i = 0; i < cmdl->opd->opdc; i++) {
+ for(int i = 0; i < cmdl->opd->opdc; i++) {
writedc(cmdl->opd->opdv[i], pass);
if(cerr->num > 0) {
break;
void assemble_in(const CMDLINE *cmdl, PASS pass)
{
- char *line = malloc_chk(LINESIZE + 1, "assemble_in.line");
+ char *line = NULL;
+
+ line = malloc_chk(LINESIZE + 1, "assemble_in.line");
if(cmdl->opd->opdc == 0 || cmdl->opd->opdc > 2) {
setcerr(106, ""); /* operand count mismatch */
return;
void assemble_out(const CMDLINE *cmdl, PASS pass)
{
- char *line = malloc_chk(LINESIZE + 1, "assemble_out.line");
+ char *line = NULL;
+
+ line = malloc_chk(LINESIZE + 1, "assemble_out.line");
if(cmdl->opd->opdc == 0 || cmdl->opd->opdc > 2) {
setcerr(106, ""); /* operand count mismatch */
return;
void assemble_rpush(const CMDLINE *cmdl, PASS pass)
{
- int i;
- char *line = malloc_chk(LINESIZE + 1, "assemble_rpush.line");
+ char *line = NULL;
+
+ line = malloc_chk(LINESIZE + 1, "assemble_rpush.line");
if(cmdl->opd->opdc > 0) {
setcerr(106, ""); /* operand count mismatch */
return;
}
- for(i = 1; i <= GRSIZE-1; i++) {
+ for(int i = 1; i <= GRSIZE-1; i++) {
sprintf(line, " PUSH 0,GR%d", i);
assembleline(line, pass);
}
void assemble_rpop(const CMDLINE *cmdl, PASS pass)
{
- int i;
- char *line = malloc_chk(LINESIZE + 1, "assemble_rpop.line");
+ char *line = NULL;
+
+ line = malloc_chk(LINESIZE + 1, "assemble_rpop.line");
if(cmdl->opd->opdc > 0) {
setcerr(106, ""); /* operand count mismatch */
return;
}
- for(i = GRSIZE-1; i >= 1; i--) {
+ for(int i = GRSIZE-1; i >= 1; i--) {
sprintf(line, " POP GR%d", i);
assembleline(line, pass);
}
bool casl2cmd(CMD *cmdtbl, const CMDLINE *cmdl, PASS pass)
{
- int i;
- void (*cmdptr)();
- for(i = 0; cmdtbl[i].name[0]; i++) {
+ void (*cmdptr)() = NULL;
+
+ for(int i = 0; cmdtbl[i].name[0]; i++) {
if(strcmp(cmdl->cmd, cmdtbl[i].name) == 0) {
cmdptr = cmdtbl[i].ptr;
(*cmdptr)(cmdl, pass);
bool assemble_comet2cmd(const CMDLINE *cmdl, PASS pass)
{
- WORD cmd, r_r1, x_r2, adr;
+ WORD cmd = 0;
+ WORD r_r1 = 0;
+ WORD x_r2 = 0;
+ WORD adr = 0;
/* オペランドなし */
if(cmdl->opd->opdc == 0) {
bool assembleline(const char *line, PASS pass)
{
- CMDLINE *cmdl;
+ CMDLINE *cmdl = NULL;
bool stat = true;
- int i;
cmdl = linetok(line);
stat = (cerr->num == 0) ? true : false;
}
FREE(cmdl->label);
if(cmdl->opd != NULL) {
- for(i = 0; i < cmdl->opd->opdc; i++) {
+ for(int i = 0; i < cmdl->opd->opdc; i++) {
FREE(cmdl->opd->opdv[i]);
}
}
bool assemblefile(const char *file, PASS pass)
{
int lineno = 1;
- char *line;
- FILE *fp;
+ char *line = NULL;
+ FILE *fp = NULL;
if((fp = fopen(file, "r")) == NULL) {
cerr->num = errno;
void outassemble(const char *file)
{
- FILE *fp;
+ FILE *fp = NULL;
if((fp = fopen(file, "w")) == NULL) {
perror(file);
*
* @param *str ファイル名
*/
-const char *objfile_name(const char *str);
+char *objfile_name(const char *str);
/**
* @brief casl2コマンドのオプション
addcerrlist(ARRAYSIZE(cerr_casl2), cerr_casl2);
}
-const char *objfile_name(const char *str)
+char *objfile_name(const char *name)
{
const char *default_name = "a.o";
- return (str == NULL) ? default_name : str;
+ return strdup_chk(
+ (name == NULL || !name[0]) ? default_name : name,
+ "objfile_name"
+ );
}
/**
*/
int main(int argc, char *argv[])
{
- int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS, opt, i, stat = 0;
- char *af[argc], *objfile = NULL;
- const char *version = PACKAGE_VERSION, *cmdversion = "casl2 of YACASL2 version %s\n";
+ int memsize = DEFAULT_MEMSIZE;
+ int clocks = DEFAULT_CLOCKS;
+ int opt = 0;
+ int stat = 0;
+ int asfilecnt = 0;
+ char **asfile = NULL;
+ char *objfile = NULL;
+ const char *version = PACKAGE_VERSION;
+ const char *cmdversion = "casl2 of YACASL2 version %s\n";
const char *usage =
"Usage: %s [-slLaAtTdmvh] [-oO[<OBJECTFILE>]] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE1[ FILE2 ...]\n";
asmode.onlyassemble = true;
break;
case 'o':
- objfile = strdup_chk(objfile_name(optarg), "objfile");
+ objfile = objfile_name(optarg);
break;
case 'O':
asmode.onlyassemble = true;
- objfile = strdup_chk(objfile_name(optarg), "objfile");
+ objfile = objfile_name(optarg);
break;
case 't':
execmode.trace = true;
}
create_cmdtable(HASH_CMDTYPE); /* 命令の名前とタイプがキーのハッシュ表を作成 */
reset(memsize, clocks); /* 仮想マシンCOMET IIのリセット */
- for(i = 0; i < argc - optind; i++) { /* 引数からファイル名配列を取得 */
- af[i] = argv[optind + i];
+ asfilecnt = argc - optind;
+ asfile = calloc_chk(asfilecnt, sizeof(char *), "asfile");
+ for(int i = 0; i < asfilecnt; i++) { /* 引数からファイル名配列を取得 */
+ asfile[i] = argv[optind + i];
}
/* アセンブル */
- if(assemble(i, af, 0) == false || asmode.onlylabel == true) {
+ if(assemble(asfilecnt, asfile, 0) == false || asmode.onlylabel == true) {
goto shutdown;
}
/* オブジェクトファイル名が指定されている場合は、アセンブル結果をオブジェクトファイルに出力 */
shutdown:
shutdown(); /* 仮想マシンCOMET IIのシャットダウン */
casl2fin:
- free_cmdtable(HASH_CMDTYPE);
FREE(objfile);
+ FREE(asfile);
+ free_cmdtable(HASH_CMDTYPE);
if(cerr->num > 0) {
stat = 1;
}
*/
int main(int argc, char *argv[])
{
- int opt, stat = 0;
- const char *version = PACKAGE_VERSION, *cmdversion = "disassemble of YACASL2 version %s\n";
+ int opt = 0;
+ int stat = 0;
+ const char *version = PACKAGE_VERSION;
+ const char *cmdversion = "disassemble of YACASL2 version %s\n";
const char *usage = "Usage: %s [-vh] FILE\n";
/* エラーの定義 */
if(argv[optind] == NULL) {
setcerr(211, ""); /* object file not specified */
fprintf(stderr, "disassemble error - %d: %s\n", cerr->num, cerr->msg);
- exit(1);
+ goto casl2revfin;
}
disassemble_file(argv[optind]); /* プログラム実行 */
casl2revfin:
cerr->num = 0;
}
-CERR *cerr;
+CERR *cerr = NULL;
CERRLIST *cerrlist = NULL;
void addcerrlist(int cerrc, CERR cerrv[])
{
- int i;
- CERRLIST *p = NULL, *q = malloc_chk(sizeof(CERRLIST), "cerrlist");
+ CERRLIST *stat = NULL;
+ CERRLIST *p = NULL;
assert(cerrc > 0 && cerrv != NULL);
- for(i = 0; i < cerrc; i++) {
+ for(int i = 0; i < cerrc; i++) {
if(p == NULL) {
- p = q;
+ stat = p = malloc_chk(sizeof(CERRLIST), "cerrlist");
} else {
- p = p->next = malloc_chk(sizeof(CERRLIST), "cerrlist.next");
+ p = p->next = malloc_chk(sizeof(CERRLIST), "cerrlist->next");
}
p->cerr = &cerrv[i];
p->next = NULL;
}
p->next = cerrlist;
- cerrlist = q;
+ cerrlist = stat;
}
void printcerrlist()
{
- CERRLIST *p;
+ CERRLIST *p = NULL;
if(cerrlist == NULL) {
puts("error list is null.");
char *getcerrmsg(int num)
{
- CERRLIST *p;
+ CERRLIST *p = NULL;
char *msg = "unknown error";
for(p = cerrlist; p != NULL; p = p->next) {
void freecerr()
{
- CERRLIST *p = cerrlist, *q;
+ CERRLIST *p = NULL;
+ CERRLIST *q = NULL;
/* 現在のエラーメッセージを解放 */
FREE(cerr->msg);
char *strip_end(char *s)
{
- int i;
- i = strlen(s) - 1;
- while(i > 0 && (s[i] == '\n' || s[i] == ' ' || s[i] == '\t')) {
- s[i--] = '\0';
+ for(int i = strlen(s) - 1; i > 0 && (s[i] == '\n' || s[i] == ' ' || s[i] == '\t'); i--) {
+ s[i] = '\0';
}
return s;
}
char *strip_casl2_comment(char *s)
{
- int i;
bool quoting = false;
- for(i = 0; s[i]; i++) {
+ for(int i = 0; s[i]; i++) {
/* 「'」で囲まれた文字列の場合。「''」は無視 */
if(s[i] == '\'' && s[i+1] != '\'' && (quoting == false || s[i-1] != '\'')) {
quoting = !quoting;
*/
int main(int argc, char *argv[])
{
- int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS;
- int opt, stat = 0;
- const char *version = PACKAGE_VERSION, *cmdversion = "comet2 of YACASL2 version %s\n";
+ int memsize = DEFAULT_MEMSIZE;
+ int clocks = DEFAULT_CLOCKS;
+ int opt = 0;
+ int stat = 0;
+ const char *version = PACKAGE_VERSION;
+ const char *cmdversion = "comet2 of YACASL2 version %s\n";
const char *usage = "Usage: %s [-tTdmvh] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE\n";
/* エラーの定義 */
*/
int main(int argc, char *argv[])
{
- int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS;
- int opt, stat = 0;
- const char *version = PACKAGE_VERSION, *cmdversion = "comet2monitor: COMET II machine code monitor of YACASL2 version %s\n";
+ int memsize = DEFAULT_MEMSIZE;
+ int clocks = DEFAULT_CLOCKS;
+ int opt = 0;
+ int stat = 0;
+ const char *version = PACKAGE_VERSION;
+ const char *cmdversion = "comet2monitor: COMET II machine code monitor of YACASL2 version %s\n";
const char *usage = "Usage: %s [-vh] [-M <MEMORYSIZE>] [-C <CLOCKS>]\n";
/* エラーの定義 */
void disassemble_puts_code(int ascol, WORD pradr, int wordc, WORD wordv[])
{
- int i;
- for(i = 0; i < codecol-ascol; i++){
+ for(int i = 0; i < codecol-ascol; i++){
fprintf(stdout, " ");
}
if(wordc == 1) {
WORD x = 0;
char *g = NULL;
int cnt = 0;
+
cnt += fprintf(stdout, " %-7s ", cmdname);
if(cmdtype == R_ADR_X) {
cnt += fprintf(stdout, "%s,", g = grstr((word & 0x00F0) >> 4));
void disassemble_cmd_r(CMDTYPE cmdtype, const char *cmdname, WORD word, WORD pradr)
{
- char *g = NULL, *g1 = NULL, *g2 = NULL;
+ char *g = NULL;
+ char *g1 = NULL;
+ char *g2 = NULL;
int cnt = 0;
+
cnt += fprintf(stdout, " %-7s ", cmdname);
if(cmdtype == R1_R2) {
g1 = grstr((word & 0x00F0) >> 4);
void disassemble_dc(WORD word, WORD pradr)
{
int cnt = 0;
+
cnt = fprintf(stdout, " DC %-5d ", word);
disassemble_puts_code(cnt, pradr, 1, (WORD []){word});
fprintf(stdout, " ::" );
void disassemble_ds(WORD wcnt, WORD pradr)
{
- int cnt = 0, i;
+ int cnt = 0;
+
cnt = fprintf(stdout, " DS %-5d ", wcnt);
disassemble_puts_code(cnt, pradr, 1, (WORD []){0});
- for(i = 0; i < wcnt - 1; i++) {
+ for(int i = 0; i < wcnt - 1; i++) {
fprintf(stdout, "\n");
disassemble_puts_code(0, pradr+1, 1, (WORD []){0});
}
WORD zero_data_cnt(FILE *stream)
{
- WORD cnt = 0, word = 0;
+ WORD cnt = 0;
+ WORD word = 0;
+
while(!feof(stream) && word == 0) {
word = fgetword(stream);
cnt++;
bool disassemble_file(const char *file)
{
bool stat = true;
- FILE *fp;
- WORD i = 0, word, cmd, zcnt;
+ FILE *fp = NULL;
+ WORD i = 0;
+ WORD word = 0;
+ WORD cmd = 0;
+ WORD zcnt = 0;
CMDTYPE cmdtype = 0;
- char *cmdname;
+ const char *cmdname = NULL;
bool inst = true;
assert(file != NULL);
void disassemble_memory(WORD start, WORD end)
{
- WORD i, cmd;
+ WORD cmd = 0;
CMDTYPE cmdtype = 0;
- char *cmdname;
+ const char *cmdname = NULL;
bool inst = true;
- for(i = start; i <= end; i++) {
+ for(int i = start; i <= end; i++) {
cmd = sys->memory[i] & 0xFF00;
cmdname = getcmdname(cmd);
cmdtype = getcmdtype(cmd);
void dspregister()
{
- int i;
- char *sp, *pr, *fr;
- for(i = 0; i < GRSIZE; i++ ) {
+ char *sp = NULL;
+ char *pr = NULL;
+ char *fr = NULL;
+ for(int i = 0; i < GRSIZE; i++ ) {
fprintf(stdout, "#%04X: GR%d: ", sys->cpu->pr, i);
print_dumpword(sys->cpu->gr[i], execmode.logical);
fprintf(stdout, "\n");
fprintf(stdout, "#%04X: PR: %6d = #%04X = %s\n",
sys->cpu->pr, sys->cpu->pr, sys->cpu->pr, pr = word2bit(sys->cpu->pr));
fprintf(stdout, "#%04X: FR (OF SF ZF): %s\n",
- sys->cpu->pr, ((fr = word2bit(sys->cpu->fr)) + 13));
+ sys->cpu->pr, ((fr = word2bit(sys->cpu->fr)) + 13)); /* FRは末尾3けたを表示 */
FREE(sp);
FREE(pr);
int main(int argc, char *argv[])
{
bool logicalmode = false; /* レジストリの内容を論理値(0から65535)で表示する場合はtrue */
- int opt, stat = 0;
- WORD word;
- const char *version = PACKAGE_VERSION, *cmdversion = "dumpword of YACASL2 version %s\n";
+ int opt = 0;
+ int stat = 0;
+ WORD word = 0;
+ const char *version = PACKAGE_VERSION;
+ const char *cmdversion = "dumpword of YACASL2 version %s\n";
const char *usage = "Usage: %s [-alh] WORD\n";
/* エラーの定義 */
WORD get_r_r1(WORD oprx)
{
- WORD r;
- char *s;
+ WORD r = 0;
+ char *s = NULL;
if((r = ((oprx & 0x00F0) >>4)) > GRSIZE - 1) {
setcerr(205, s = pr2str(sys->cpu->pr)); /* r/r1 in word #1 - not GR */
WORD get_x_r2(WORD oprx)
{
- WORD x;
- char *s;
+ WORD x = 0;
+ char *s = NULL;
if((x = (oprx & 0x000F)) > GRSIZE - 1) {
setcerr(206, s = pr2str(sys->cpu->pr)); /* r/r1 in word #1 - not GR */
WORD get_val_adr_x(WORD adr, WORD oprx)
{
- WORD a;
- char *s;
+ WORD a = 0;
+ char *s = NULL;
if((a = get_adr_x(adr, oprx)) >= sys->memsize) {
setcerr(207, s = pr2str(sys->cpu->pr + 1)); /* address in word #2 - out of memory */
WORD loadassemble(const char *file, WORD start)
{
- FILE *fp;
- WORD end;
+ FILE *fp = NULL;
+ WORD end = 0;
assert(file != NULL);
if((fp = fopen(file, "rb")) == NULL) {
void pop()
{
assert(sys->cpu->sp > execptr->end);
- WORD w;
- char *s;
+ WORD w = 0;
+ char *s = NULL;
if(sys->cpu->sp >= sys->memsize) {
setcerr(203, s = pr2str(sys->cpu->pr)); /* Stack Pointer (SP) - stack underflow */
void call()
{
assert(sys->cpu->sp > execptr->end && sys->cpu->sp <= sys->memsize);
- WORD w[2];
- w[0] = sys->memory[sys->cpu->pr];
- w[1] = sys->memory[sys->cpu->pr + 1];
sys->memory[--(sys->cpu->sp)] = sys->cpu->pr + 1;
- sys->cpu->pr = get_adr_x(w[1], w[0]);
+ sys->cpu->pr = get_adr_x(
+ sys->memory[sys->cpu->pr + 1],
+ sys->memory[sys->cpu->pr]
+ );
}
void ret()
void svc()
{
- WORD w[2];
- w[0] = sys->memory[sys->cpu->pr];
- w[1] = sys->memory[sys->cpu->pr + 1];
- switch(get_adr_x(w[1], w[0]))
+ switch(get_adr_x(
+ sys->memory[sys->cpu->pr + 1],
+ sys->memory[sys->cpu->pr]
+ )
+ )
{
case 0x0: /* STOP */
execptr->stop = true;
void exec()
{
- clock_t clock_begin, clock_end;
- void (*cmdptr)();
- char *s;
+ clock_t clock_begin = 0;
+ clock_t clock_end = 0;
+ void (*cmdptr)() = NULL;
+ char *s = NULL;
const char *monmsg = "COMET II machine code monitor. Type ? for help.\n";
create_cmdtable(HASH_CODE); /* 命令のコードとタイプがキーのハッシュ表を作成 */
unsigned hash(int keyc, HKEY *keyv[], int tabsize)
{
- int i, j;
unsigned hashval = 0;
enum {
HASHNUM = 31
};
- for(i = 0; i < keyc; i++) {
+ for(int i = 0; i < keyc; i++) {
switch(keyv[i]->type) {
case CHARS:
- for(j = 0; keyv[i]->val.s[j]; j++) {
+ for(int j = 0; keyv[i]->val.s[j]; j++) {
hashval = keyv[i]->val.s[j] + HASHNUM * hashval;
}
break;
};
HKEY *label_hashkey(const char *value) {
- HKEY *key;
+ HKEY *key = NULL;
key = malloc_chk(sizeof(HKEY), "label_hashkey");
key->type = CHARS;
- key->val.s = strdup_chk(value, "label_hashkey.value");
+ key->val.s = strdup_chk(value, "label_hashkey->value");
return key;
}
unsigned labelhash(const char *prog, const char *label)
{
- HKEY *keys[2];
- int i = 0, j;
- unsigned h;
+ HKEY *keys[2] = {NULL};
+ int i = 0;
+ unsigned h = 0;
if(prog[0]) {
keys[i++] = label_hashkey(prog);
}
keys[i] = label_hashkey(label);
h = hash(i+1, keys, LABELTABSIZE);
- for(j = 0; j < i + 1; j++) {
+ for(int j = 0; j < i + 1; j++) {
FREE(keys[j]->val.s);
FREE(keys[j]);
}
WORD getlabel(const char *prog, const char *label)
{
assert(prog != NULL && label != NULL);
- LABELTAB *p;
- LABELARRAY *l;
+ LABELTAB *p = NULL;
+ LABELARRAY *l = NULL;
for(p = labels[labelhash(prog, label)]; p != NULL; p = p->next) {
l = p->label;
bool addlabel(const char *prog, const char *label, WORD adr)
{
assert(label != NULL);
- LABELTAB *p;
- LABELARRAY *l;
- unsigned h;
+ LABELTAB *p = NULL;
+ LABELARRAY *l = NULL;
+ unsigned h = 0;
/* 登録されたラベルを検索。すでに登録されている場合はエラー発生 */
if(getlabel(prog, label) != 0xFFFF) {
void printlabel()
{
- int i, s = 0;
- LABELTAB *p;
- LABELARRAY **l;
+ int s = 0;
+ LABELTAB *p = NULL;
+ LABELARRAY **l = {NULL};
l = calloc_chk(labelcnt, sizeof(LABELARRAY **), "labels");
- for(i = 0; i < LABELTABSIZE; i++) {
+ for(int i = 0; i < LABELTABSIZE; i++) {
for(p = labels[i]; p != NULL; p = p->next) {
assert(p->label != NULL);
l[s++] = p->label;
}
}
qsort(l, s, sizeof(*l), compare_adr);
- for(i = 0; i < s; i++) {
+ for(int i = 0; i < s; i++) {
if(l[i]->prog[0]) {
fprintf(stdout, "%s.", l[i]->prog);
}
void freelabel()
{
int i;
- LABELTAB *p, *q;
+ LABELTAB *p = NULL;
+ LABELTAB *q = NULL;
for(i = 0; i < LABELTABSIZE; i++) {
for(p = labels[i]; p != NULL; p = q) {
bool getbps(WORD adr)
{
- BPSLIST *p;
+ BPSLIST *p = NULL;
for(p = bps[adrhash(adr)]; p != NULL; p = p->next) {
if(p->adr == adr) {
bool addbps(WORD adr)
{
- BPSLIST *p;
- unsigned h;
+ BPSLIST *p = NULL;
+ unsigned h = 0;
/* 登録されたラベルを検索。すでに登録されている場合は終了 */
if(getbps(adr) == true) {
bool delbps(WORD adr)
{
- BPSLIST *p, *q;
- unsigned h;
+ BPSLIST *p = NULL;
+ BPSLIST *q = NULL;
+ unsigned h = 0;
bool res = false;
p = bps[h = adrhash(adr)];
void listbps()
{
int i, cnt = 0;
- BPSLIST *p;
+ BPSLIST *p = NULL;
fprintf(stdout, "List of breakpoints\n");
for(i = 0; i < BPSTABSIZE; i++) {
void freebpslist(BPSLIST *head)
{
- BPSLIST *p, *q;
+ BPSLIST *p = NULL;
+ BPSLIST *q = NULL;
for(p = head; p != NULL; p = q) {
q = p->next;
FREE(p);
void freebps()
{
- int i;
- for(i = 0; i < BPSTABSIZE; i++) {
+ for(int i = 0; i < BPSTABSIZE; i++) {
freebpslist(bps[i]);
bps[i] = NULL;
}
MONARGS *monargstok(const char *str)
{
MONARGS *args = malloc_chk(sizeof(MONARGS), "args");
- char *tok, *p, sepc = ' ';
- int i = 0;
+ char *tok = NULL;
+ char *p = NULL;
+ char sepc = ' ';
args->argc = 0;
if(!str || !str[0]) {
}
tok = p = strdup_chk(str, "argstok.p");
do {
- i = strcspn(p, " ");
+ int i = strcspn(p, " ");
sepc = p[i];
args->argv[(args->argc)++] = strndup_chk(p, i, "args->argv[]");
p += i + 1;
- i = 0;
} while(sepc == ' ');
FREE(tok);
return args;
MONCMDLINE *monlinetok(const char *line)
{
- char *tokens, *p;
- int i;
+ char *tokens = NULL;
+ char *p = NULL;
+ int i = 0;
MONCMDLINE *moncmdl = NULL;
if(!line[0] || line[0] == '\n') {
void monitor()
{
char *buf = NULL;
- MONCMDLINE *moncmdl;
+ MONCMDLINE *moncmdl = NULL;
MONCMDTYPE cmdtype = MONREPEAT;
do {
/**
* COMET IIの仮想実行マシンシステム
*/
-SYSTEM *sys;
+SYSTEM *sys = NULL;
/**
* プログラム実行時の開始と終了のアドレス
*/
-EXECPTR *execptr;
+EXECPTR *execptr = NULL;
/**
* システムCOMET IIの命令表
/**
* ハッシュ表
*/
-static CMDTAB *cmdtab[HASH_MAX][CMDTABSIZE];
+static CMDTAB *cmdtab[HASH_MAX][CMDTABSIZE] = {NULL};
/**
* 命令の名前とタイプからハッシュ値を生成する
*/
unsigned hash_cmdtype(const char *cmd, CMDTYPE type)
{
- HKEY *keys[2];
- unsigned hashval;
+ HKEY *keys[2] = {NULL};
+ unsigned hashval = 0;
/* 命令名を設定 */
keys[0] = malloc_chk(sizeof(HKEY), "hash_cmdtype.keys[0]");
{
CMDTAB *p = NULL;
unsigned hashval;
- int i;
- for(i = 0; i < comet2cmdsize; i++) {
+ for(int i = 0; i < comet2cmdsize; i++) {
p = malloc_chk(sizeof(CMDTAB), "create_cmdtable.p");
p->cmd = &comet2cmd[i];
if(hash == HASH_CMDTYPE) {
*/
void free_cmdtable(CMDTAB_HASH hash)
{
- int i;
- CMDTAB *p, *q;
+ CMDTAB *p = NULL;
+ CMDTAB *q = NULL;
- for(i = 0; i < CMDTABSIZE; i++) {
+ for(int i = 0; i < CMDTABSIZE; i++) {
for(p = cmdtab[hash][i]; p != NULL; p = q) {
q = p->next;
FREE(p);
*/
WORD getcmdcode(const char *cmd, CMDTYPE type)
{
- CMDTAB *p;
+ CMDTAB *p = NULL;
WORD w = 0xFFFF;
assert(cmd != NULL);
*/
unsigned hash_code(WORD code)
{
- HKEY *keys[1];
- unsigned h;
+ HKEY *keys[1] = {NULL};
+ unsigned h = 0;
/* 命令コードを設定 */
keys[0] = malloc_chk(sizeof(HKEY), "hash_code.key");
*/
const void (*getcmdptr(WORD code))
{
- CMDTAB *t;
+ CMDTAB *t = NULL;
const void *ptr = NULL;
for(t = cmdtab[HASH_CODE][hash_code(code)]; t != NULL; t = t->next) {
*/
CMDTYPE getcmdtype(WORD code)
{
- CMDTAB *t;
+ CMDTAB *t = NULL;
CMDTYPE type = NONE;
for(t = cmdtab[HASH_CODE][hash_code(code)]; t != NULL; t = t->next) {
*/
char *getcmdname(WORD code)
{
- CMDTAB *t;
+ CMDTAB *t = NULL;
char *cmd = NULL;
for(t = cmdtab[HASH_CODE][hash_code(code)]; t != NULL; t = t->next) {
char *grstr(WORD word)
{
assert(word <= 7);
- char *str = malloc_chk(3 + 1, "grstr.str");
+ char *str = NULL;
+
+ str = malloc_chk(3 + 1, "grstr.str");
sprintf(str, "GR%d", word);
return str;
}
*/
void reset(int memsize, int clocks)
{
- int i;
-
sys = malloc_chk(sizeof(SYSTEM), "sys");
/* メモリサイズを設定 */
sys->memsize = memsize;
sys->memory = calloc_chk(sys->memsize, sizeof(WORD), "memory");
/* CPUを初期化 */
sys->cpu = malloc_chk(sizeof(CPU), "cpu");
- for(i = 0; i < GRSIZE; i++) { /* 汎用レジスタ */
+ for(int i = 0; i < GRSIZE; i++) { /* 汎用レジスタ */
sys->cpu->gr[i] = 0x0;
}
sys->cpu->sp = sys->memsize; /* スタックポインタ */
{
assert(isdigit(str[0]) || str[0] == '-');
- char *check;
+ char *check = NULL;
int n;
/* WORD値に変換 */
n = strtol(str, &check, 10);
{
assert(str[0] == '#');
- WORD w = 0x0;
- char *check;
+ WORD w = 0;
+ char *check = NULL;
str++;
if(*str == '-' || strlen(str) > 4) {
setcerr(116, str-1); /* out of hex range */
MAXLEN = 16, /* WORD値を2進数で表したときの最大桁数 */
};
WORD mask = 0x8000;
- char *bit = malloc_chk(MAXLEN + 1, "word2bit.bit");
+ char *bit = NULL;
int i = 0;
+ bit = malloc_chk(MAXLEN + 1, "word2bit.bit");
do {
bit[i++] = (word & mask) ? '1' : '0';
} while((mask >>= 1) > 0);