コード例 #1
0
int main(int argc, char** argv) {

    if (argc != 4) {
        std::cout << "Not enough arguments." << std::endl;
        std::cout << "Usage: [input_file_name] [output_file_name] [config_file_name]" << std::endl;
        return 0;
    }
//    test_process_remove(argv[1], argv[2]);
//    test_process_replace(argv[1], argv[2], argv[3]);
    run_processor(argv[1], argv[2], argv[3]);
//    test_iterate_words(argv[1]);
//    test_iterate_sentences(argv[1]);
    return 0;
}
コード例 #2
0
ファイル: sim4004.c プロジェクト: billychia/Tutorials
/* Run the simulator using program entered by user and print results */
int main(int argc, char *argv[])
{
 
    int program[NUM_CELLS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    int instruction;
    int outlen;
    int i;
 
    /* get program */
    //printf("\n\ntype 16 instructions (0-15), each followed by enter\n");
    i = 0;
    while (i < NUM_CELLS) {
        //printf(" instruction %d: ", i);
        scanf("%d", &instruction);
        assert(instruction >= 0);
        assert(instruction < NUM_CELLS);
        program[i] = instruction;
        i++;
    }
 
    /* run program */
    //printf("\n\nrunning: \n");
    i = 0;
    while (i < NUM_CELLS) {
        //printf(" %d", program[i]);
        i++;
    }
    //printf("\n  output: ");
    outlen = run_processor(program);
    //printf("output length: %d characters\n\n", outlen);
    printf("%d\n", outlen);
 
 
    /* tests for check_range() function */
    if (TEST) {
        printf("\ntest check_range() ...\n======================\n");
        printf("  16->%d\n", check_range(16));
        printf("  18->%d\n", check_range(18));
        printf("  0->%d\n", check_range(0));
        printf("  15->%d\n", check_range(15));
        printf("  -2->%d\n", check_range(-2));
    }
 
    /* test programs and expected output */
    if (TEST) {
        printf("\ntest run_processor() ...\n========================");
        /* test 1, 3 character busy beaver */
        printf("\nTest 1: 7 1 8 0 0 0 0 0 0 0 0 0 0 0 0 0\n  expect 0-15\n  ");
        int test1[NUM_CELLS] = { 7, 1, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        int outlen1 = run_processor(test1);
        printf(" %d output characters\n", outlen1);
 
        /* test 2, 4004-IF (cell 15 not 2, output 1) */
        printf("\nTest 2: 11 2 14 15 6 8 11 10 0 7 0 10 1 7 0 0\n  expect 1\n  ");
        int test2[NUM_CELLS] = { 11, 2, 14, 15, 6, 8, 11, 10, 0, 7, 0, 10, 1, 7, 0, 0 };
        int outlen2 = run_processor(test2);
        printf(" %d output characters\n", outlen2);
 
        /* test 3, 4004-IF (cell 15 is 2, output 0) */
        printf("\nTest 3: 11 2 14 15 6 8 11 10 0 7 0 10 1 7 0 2\n  expect 0\n  ");
        int test3[NUM_CELLS] = { 11, 2, 14, 15, 6, 8, 11, 10, 0, 7, 0, 10, 1, 7, 0, 2 };
        int outlen3 = run_processor(test3);
        printf(" %d output characters\n", outlen3);
 
        /* test 4, remaining instructions, 3 4 5 9 12 13 (if no & instr 12) */
        printf("\nTest 4: 3 3 3 4 5 7 9 0 12 12 2 7 0 0 0 0\n  expect 2 1\n  ");
        int test4[NUM_CELLS] = {3, 3, 3, 4, 5, 7, 9, 0, 12, 12, 2, 7, 0, 0, 0, 0};
        int outlen4 = run_processor(test4);
        printf(" %d output characters\n", outlen4);
 
        /* test 5, remaining instructions, 3 4 5 9 12 13 (if yes & instr 13) */
        printf("\nTest 5: 3 4 5 7 9 7 0 4 13 11 10 0 7 0 0 0\n  expect 0 15\n  ");
        int test5[NUM_CELLS] = {3, 4, 5, 7, 9, 7, 0, 4, 13, 11, 10, 0, 7, 0, 0, 0};
        int outlen5 = run_processor(test5);
        printf(" %d output characters\n\n", outlen5);
    }
 
    return EXIT_SUCCESS;
}