diff --git a/src/testa_isomorfismo.sh b/src/testa_isomorfismo.sh index 8bfea18682f84e6f1897a06d582384a66f9d3484..84e32595a273e2a9f12affcb455f93b597ddd9fc 100755 --- a/src/testa_isomorfismo.sh +++ b/src/testa_isomorfismo.sh @@ -6,6 +6,21 @@ if [ "$#" -ne 2 ]; then exit 1 fi +# Verifica se os dois arquivos existem +if [ ! -f "$1" ] || [ ! -f "$2" ]; then + echo "Erro: forneça arquivos que existam." + exit 1 +fi + +# Verifica se os caminhos dos arquivos são iguais +ABS1=$(realpath "$1") +ABS2=$(realpath "$2") + +if [ "$ABS1" = "$ABS2" ]; then + echo "Os dois caminhos de arquivo são idênticos — forneça arquivos diferentes." + exit 1 +fi + # Determina o diretório base do projeto if [ -f "./src/isomorfismo" ]; then # Executando da raiz do projeto @@ -39,6 +54,11 @@ CFG2="a-${BASENAME2}.015t.cfg" RM_ESTILO_GV=$SRC_DIR/tira_style.gvpr FORMAT_IN_GV=$SRC_DIR/formata_input.gvpr +# arquivos de entrada para ./isomorfismo +INPUT1="$INPUT_DIR/$BASENAME1.in" +INPUT2="$INPUT_DIR/$BASENAME2.in" + + # Gera os arquivos .dot usando gcc no diretório temporário gcc -fdump-tree-cfg-graph "$CODE1" -o /dev/null gcc -fdump-tree-cfg-graph "$CODE2" -o /dev/null @@ -58,6 +78,10 @@ mv "$DOT2" "$TEMPDIR/${BASENAME2}.dot" DOT1="$TEMPDIR/${BASENAME1}.dot" DOT2="$TEMPDIR/${BASENAME2}.dot" +# arquivos de saida de ./isomorfismo +OUTPUT1="$DOT1.out" +OUTPUT2="$DOT2.out" + # remove os estilo de cada .dot gerado gvpr -c -f "$RM_ESTILO_GV" "$DOT1" > "$DOT1.tmp" && mv "$DOT1.tmp" "$DOT1" gvpr -c -f "$RM_ESTILO_GV" "$DOT2" > "$DOT2.tmp" && mv "$DOT2.tmp" "$DOT2" @@ -67,16 +91,16 @@ dot -Tpng "$DOT1" > "$DOT1.png" dot -Tpng "$DOT2" > "$DOT2.png" # gera o input a partir do .dot e o coloca no diretorio de inputs -gvpr -f "$FORMAT_IN_GV" "$DOT1" > "$INPUT_DIR/$BASENAME1" -gvpr -f "$FORMAT_IN_GV" "$DOT2" > "$INPUT_DIR/$BASENAME2" +gvpr -f "$FORMAT_IN_GV" "$DOT1" > "$INPUT1" +gvpr -f "$FORMAT_IN_GV" "$DOT2" > "$INPUT2" # executa o algoritmo que gera a string de isomorfismo -"$SRC_DIR/isomorfismo" < "$INPUT_DIR/$BASENAME1" > "$DOT1.out" -"$SRC_DIR/isomorfismo" < "$INPUT_DIR/$BASENAME2" > "$DOT2.out" +"$SRC_DIR/isomorfismo" < "$INPUT1" > "$OUTPUT1" +"$SRC_DIR/isomorfismo" < "$INPUT2" > "$OUTPUT2" # verifica se as string são iguais ou não, baseado no código de saída ($?) -if diff -q "$DOT1.out" "$DOT2.out" > /dev/null; then - echo "os dois DGs são isomórficos" +if diff -q "$OUTPUT1" "$OUTPUT2" > /dev/null; then + echo "isomórficos" else - echo "os dois DGs NÃO são isomórficos" + echo "não isomórficos" fi \ No newline at end of file