char *strdup_chk(const char *s, const char *tag)
{
assert(s != NULL);
- char *t = NULL;
-
- t = malloc_chk(strlen(s) + 1, tag);
+ char *t = malloc_chk(strlen(s) + 1, tag);
strcpy(t, s);
return t;
}
}
}
+char *strrev(const char *s)
+{
+ char *t = strdup_chk(s, "strrev.t");
+ int l = strlen(t);
+
+ for(int i = 0; i < l-1-i; i++) {
+ char tmp = t[i];
+ t[i] = t[l-1-i];
+ t[l-1-i] = tmp;
+ }
+ return t;
}
enum {
MAXLEN = 5, /* WORD値を10進数で表したときの最大けた数 */
};
- char *n = malloc_chk(MAXLEN + 1, "word2n.n");
+ char *s = malloc_chk(MAXLEN + 1, "word2n.n");
+ char *t = NULL;
int d = 0; /* けた数 */
do{
- n[d++] = word % 10 + '0';
+ s[d++] = word % 10 + '0';
} while((word /= 10) > 0);
- for(int i = 0; i < d; i++) {
- char tmp = n[i];
- n[i] = n[(d-1)-i];
- n[(d-1)-i] = tmp;
- }
- n[d] = '\0';
- return n;
+ s[d] = '\0';
+ t = strrev(s);
+ FREE(s);
+ return t;
}
char *word2bit(const WORD word)
void print_dumpword(WORD word, bool logicalmode)
{
- char *bit = NULL;
+ char *bit = word2bit(word);
if(logicalmode == true) {
- fprintf(stdout, "%6d", word);
+ fprintf(stdout, "%6u", word);
} else {
fprintf(stdout, "%6d", (signed short)word);
}
- fprintf(stdout, " = #%04X = %s", word, (bit = word2bit(word)));
+ fprintf(stdout, " = #%04X = %s", word, bit);
/* 「文字の組」の符号表に記載された文字と、改行(CR)/タブを表示 */
if(word >= 0x20 && word <= 0x7E) {
fprintf(stdout, " = \'%c\'", word);
--- /dev/null
+include ../Define.mk
+include ../Test.mk
+
+CC := gcc
+CFLAGS := -Wall -Wextra -g
+
+CMDSRC_FILE := cmd.c
+TARGETDIR := ../../../src
+INCLUDEDIR := ../../../include
+TESTTARGET_FILES := $(TARGETDIR)/cmem.c # Set test target files
+
+$(CMD_FILE): $(CMDSRC_FILE) $(TESTTARGET_FILES)
+ $(CC) $(CFLAGS) -I $(INCLUDEDIR) -o $@ $^
+
+clean_cmd:
+ @rm -rf cmd.dSYM cmd
+
+clean: clean_cmd