void test_addwf_given_d_is_1_result_should_store_into_file_register(void) { int fileAddress = 0x80; memory[fileAddress] = 0x17; WREG = 0x20; int d = DIR_fileRegister, accessType = AccessRAM; addwf (fileAddress, d, accessType); TEST_ASSERT_EQUAL(0x20, WREG); TEST_ASSERT_EQUAL(0x37, PORTA); }
void test_addwf_given_accessType_is_1_result_should_store_into_general_purpose_register(void) { int fileAddress = 0x423; memory [fileAddress] = 0x17; WREG = 0x20; BSR = 0x4; int d = DIR_fileRegister, accessType = BankRAM; addwf (fileAddress, d, accessType); int dataMemoryAddr = getFileAddress (fileAddress, accessType); TEST_ASSERT_EQUAL(0x20, WREG); TEST_ASSERT_EQUAL(0x37, memory[dataMemoryAddr]); }
void test_addwf_given_d_is_0_result_should_store_into_WREG(void) { int fileAddress = 0x23; memory[fileAddress] = 0xEE; WREG = 0x12; int d = DIR_WREG, accessType = AccessRAM; addwf (fileAddress, d, accessType); int dataMemoryAddr = getFileAddress (fileAddress, accessType); TEST_ASSERT_EQUAL_INT8(0x00, WREG); TEST_ASSERT_EQUAL(0xEE, memory[dataMemoryAddr]); TEST_ASSERT_EQUAL(0x0F, STATUS); }
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ int open_files(struct subcmd **cmdsp, int argc, char **argv) { struct subcmd *scp; struct wf wrtfiles[MAXWF]; /* place to keep track of output files */ FILE *f; char *p, *q, *hloc; int i; FILE *findwf(char *filename, struct wf *wftable); void addwf(char *filename, FILE *stream, struct wf *wftable); #ifdef DEBUG printf("%d input files.\n",num_files); if (firstfile) for (i = firstfile; i < argc; i++) printf("\t%s\n", argv[i]); printf("Commands: \n"); if (*cmdsp == NULL) { printf("none\n"); return(OK); } else for (scp = *cmdsp; scp; scp = *++cmdsp) { printf("\tcommand: "); if (scp->cmd_idx < 0) printf("(NOT)"); printf("%s\n", cmdnames[abs(scp->cmd_idx)]); for (i = 0; i < 2; i++) { printf("\t\tAddress %d: ", i + 1); if (scp->saddr[i].type == NO_ADDRESS) printf("none\n"); else if (scp->saddr[i].type == LINENO_ADDRESS) printf("(lineno) %d\n", scp->saddr[i].val.lineno); else printf("(context) %s\n", scp->saddr[i].val.pch); }; for (i = 0; i < 3; i++) { printf("\t\tArg %d: ", i + 1); if (scp->args[i] == NULL) printf("NULL\n"); else printf("%s\n", scp->args[i]); } } #endif for (i = 0; i < MAXWF; wrtfiles[i++].filename = NULL); for (scp = *cmdsp; scp; scp = *++cmdsp) { switch (cmd_table[abs(scp->cmd_idx)].cmd_tag) { case PUT_TEXT_FROM_FILE: if ((f = fopen(scp->args[0], "r")) == NULL) /* @8c */ { fprintf(stderr,"sed: could not read file %s\n", scp->args[0]); return(BAIL_OUT); } free(scp->args[0]); // (FILE *)scp->args[0] = f; scp->args[0] = (char *)f; /* @Z9a */ break; case APPEND_PATTERN_TO_FILE: if ( (f = findwf(scp->args[0], wrtfiles)) == NULL) { // @5d if ((f = fopen(scp->args[0], "at")) == NULL) /* @5a */ if ((f = fopen(scp->args[0], "wt")) == NULL) { fprintf(stderr,"sed: could not write file %s\n", scp->args[0]); return(BAIL_OUT); } else addwf(scp->args[0], f, wrtfiles); } free(scp->args[0]); // (FILE *)scp->args[0] = f; scp->args[0] = (char *)f; break; case CHANGE: for (p = scp->args[2]; p && *p; p++) { if (*p == 'w') { hloc = p+1; if (strlen(++p) < sizeof(FILE *)+2) { p = realloc(scp->args[2], strlen(scp->args[2]) + sizeof(FILE *) +2); scp->args[2] = p; for (; *p != 'w'; p++); p++; } /* else @6d*/ p = skipwhite(p); for (q = p; *q && !isspace(*q); q++); *q = '\0'; if ( (f = findwf(p, wrtfiles)) == NULL) { if ((f = fopen(p, "w")) == NULL) /*@6c@8c*/ { fprintf(stderr, "sed: could not write file %s\n", p); return(BAIL_OUT); } else addwf(p, f, wrtfiles); } // (FILE *)*hloc = f; break; } } break; } } for (i = 0; i < MAXWF && wrtfiles[i].filename; free(wrtfiles[i++].filename)); return(OK); }