コード例 #1
0
ファイル: lcs.c プロジェクト: Teybeo/Diff
/*
    Cette fonction extrait la (une) lcs des chaines a et b à partir de la matrice
*/
void extract_lcs(char** matrix, char** a, char** b, int x, int y, char** lcs, bool ignore_case_content)
{
    static int i = 0;

    if (x == 0 || y == 0)
        return;

    if(ignore_case_content)
    {
        if (strcasecmp(a[x - 1], b[y - 1]) == 0)
        {
            extract_lcs(matrix, a, b, x - 1, y - 1, lcs, ignore_case_content);
            lcs[i] = a[x - 1];
            i++;
        }
        else if (matrix[y][x] == matrix[y - 1][x])
            extract_lcs(matrix, a, b, x, y - 1, lcs, ignore_case_content); // On prend le chemin du haut
        else
            extract_lcs(matrix, a, b, x - 1, y, lcs, ignore_case_content); // On prend le chemin de gauche
    }
    else
    {
        if (strcmp(a[x - 1], b[y - 1]) == 0)
        {
            extract_lcs(matrix, a, b, x - 1, y - 1, lcs, ignore_case_content);
            lcs[i] = a[x - 1];
            i++;
        }
        else if (matrix[y][x] == matrix[y - 1][x])
            extract_lcs(matrix, a, b, x, y - 1, lcs, ignore_case_content); // On prend le chemin du haut
        else
            extract_lcs(matrix, a, b, x - 1, y, lcs, ignore_case_content); // On prend le chemin de gauche
    }
}
コード例 #2
0
ファイル: main.c プロジェクト: Raphawelh/Diff
int main(int argc, char** argv)
{
    Options* options = NULL;

#ifdef ARGV_INPUT
    if (argc < 3) {
        puts("Nombre de parametres insuffisants");
        return 1;
    }
    char* path_a = argv[1];
    char* path_b = argv[2];

    options = parse_options(argc, argv);

#else
    char path_a[256] = {};
    char path_b[256] = {};
    fgets(path_a, 256, stdin);
    fgets(path_b, 256, stdin);
    path_a[strlen(path_a)-1] = '\0';
    path_b[strlen(path_b)-1] = '\0';
#endif

    if (options == NULL)
    {
        puts("Erreur lecture des options");
        return 0;
    }


    int size_a = 0;
    int size_b = 0;

    char** file_a = load_file(options->path_a, &size_a);
    if (file_a == NULL)
        return 0;

    char** file_b = load_file(options->path_b, &size_b);
    if (file_b == NULL)
        return 0;

    char** lcs = calloc(sizeof(char*), max(size_a, size_b) + 1);

    char** matrix = build_lcs_matrix(file_a, file_b, size_a, size_b);
    extract_lcs(matrix, file_a, file_b, size_a, size_b, lcs);

    putchar('\n');

    int size_lcs = 0;
    while (lcs[size_lcs++] != 0);
    size_lcs--;

    if (options->brief)
        is_different(file_a, size_a, file_b, size_b);
    else if (options->output_mode == OUTPUT_MODE_NORMAL)
    {
        if (options->ignore_case_content)
            ignore_casse(file_a, size_a, file_b, size_b, lcs, size_lcs);
        else
            print_diff_normal(file_a, size_a, file_b, size_b, lcs, size_lcs);
    }

    return 0;
}