Re: Исходный код генератора
От: remark Россия http://www.1024cores.net/
Дата: 08.10.09 15:59
Оценка:
Исходный код генератора:

#include <stdio.h>
#include <stdlib.h>
#include <direct.h> 

int main(int argc, char** argv)
{
    size_t N = 10;
    if (argc > 1 && atoi(argv[1]) > 0)
        N = atoi(argv[1]);

    {
        char buf [1024];
        sprintf(buf, "noguard%u", N);
        _mkdir(buf);
        _chdir(buf);

        for (size_t i = 0; i != N; i += 1)
        {
            char buf [1024];
            sprintf(buf, "header_%u.h", i);
            FILE* f = fopen(buf, "w");
            for (size_t j = i + 1; j != N; j += 1)
            {
                fprintf(f, "#include \"header_%u.h\"\n", j);
            }
            fprintf(f, "\n");
            fprintf(f, "extern int i;\n\n");
            fclose(f);
        }

        FILE* f = fopen("main.cpp", "w");
        for (size_t i = 0; i != N; i += 1)
        {
            fprintf(f, "#include \"header_%u.h\"\n", i);
        }
        fprintf(f, "\n");
        fprintf(f, "int i = 0;\n\n");
        fprintf(f, "int main() {}\n\n");
        fclose(f);

        _chdir("..");
    }

    {
        char buf [1024];
        sprintf(buf, "pragma%u", N);
        _mkdir(buf);
        _chdir(buf);

        for (size_t i = 0; i != N; i += 1)
        {
            char buf [1024];
            sprintf(buf, "header_%u.h", i);
            FILE* f = fopen(buf, "w");
            fprintf(f, "#pragma once\n\n");
            for (size_t j = i + 1; j != N; j += 1)
            {
                fprintf(f, "#include \"header_%u.h\"\n", j);
            }
            fprintf(f, "\n");
            fprintf(f, "extern int i;\n\n");
            fclose(f);
        }

        FILE* f = fopen("main.cpp", "w");
        for (size_t i = 0; i != N; i += 1)
        {
            fprintf(f, "#include \"header_%u.h\"\n", i);
        }
        fprintf(f, "\n");
        fprintf(f, "int i = 0;\n\n");
        fprintf(f, "int main() {}\n\n");
        fclose(f);

        _chdir("..");
    }

    {
        char buf [1024];
        sprintf(buf, "guard%u", N);
        _mkdir(buf);
        _chdir(buf);

        for (size_t i = 0; i != N; i += 1)
        {
            char buf [1024];
            sprintf(buf, "header_%u.h", i);
            FILE* f = fopen(buf, "w");
            fprintf(f, "#ifndef GUARD_%u_H\n", i);
            fprintf(f, "#define GUARD_%u_H\n\n", i);
            for (size_t j = i + 1; j != N; j += 1)
            {
                fprintf(f, "#include \"header_%u.h\"\n", j);
            }
            fprintf(f, "\n");
            fprintf(f, "extern int i;\n\n");
            fprintf(f, "#endif\n\n", i);
            fclose(f);
        }

        FILE* f = fopen("main.cpp", "w");
        for (size_t i = 0; i != N; i += 1)
        {
            fprintf(f, "#include \"header_%u.h\"\n", i);
        }
        fprintf(f, "\n");
        fprintf(f, "int i = 0;\n\n");
        fprintf(f, "int main() {}\n\n");
        fclose(f);

        _chdir("..");
    }

    {
        char buf [1024];
        sprintf(buf, "external%u", N);
        _mkdir(buf);
        _chdir(buf);

        for (size_t i = 0; i != N; i += 1)
        {
            char buf [1024];
            sprintf(buf, "header_%u.h", i);
            FILE* f = fopen(buf, "w");
            fprintf(f, "#ifndef GUARD_%u_H\n", i);
            fprintf(f, "#define GUARD_%u_H\n\n", i);
            for (size_t j = i + 1; j != N; j += 1)
            {
                fprintf(f, "#ifndef GUARD_%u_H\n", j);
                fprintf(f, "#include \"header_%u.h\"\n", j);
                fprintf(f, "#endif\n");
            }
            fprintf(f, "\n");
            fprintf(f, "extern int i;\n\n");
            fprintf(f, "#endif\n\n", i);
            fclose(f);
        }

        FILE* f = fopen("main.cpp", "w");
        for (size_t i = 0; i != N; i += 1)
        {
            fprintf(f, "#ifndef GUARD_%u_H\n", i);
            fprintf(f, "#include \"header_%u.h\"\n", i);
            fprintf(f, "#endif\n");
        }
        fprintf(f, "\n");
        fprintf(f, "int i = 0;\n\n");
        fprintf(f, "int main() {}\n\n");
        fclose(f);

        _chdir("..");
    }
}



1024cores &mdash; all about multithreading, multicore, concurrency, parallelism, lock-free algorithms
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.