Liberdade
###################################################################################
###################################################################################
###################################################################################
##############
# procedures #
##############
proc erroargs {qtde} { append frase1 "Erro: " $qtde " argumentos." puts $frase1 puts "Sintaxe correta: cice ORIGEM CIFRA DESTINO" puts "\tORIGEM e DESTINO devem ser caminhos para arquivos(path)." # [format %c 250] abaixo eh usado para exibir o caractere "u" com acento agudo corretamente append frase2 "\tCIFRA deve ser um n" [format %c 250] "mero entre 2 e 26." puts [format $frase2] puts "Exemplo: cice ./msg1 13 ~/txt-cifrados/msg1-cice" unset frase1 frase2 exit
}
#####################################
# Analisando os argumentos passados #
#####################################
# * path do arquivo destino if {$argc < 3} {erroargs Poucos} if {$argc > 3} {erroargs Muitos}
set var(origem) [lindex $argv 0] set var(cifra) [lindex $argv 1] set var(destino) [lindex $argv 2]
set arq [file exists $var(origem)] if {!$arq} { puts [append frase "Erro: O arquivo " $var(origem) " n" [format %c 227] "o existe."] unset frase exit
}
unset arq
if {!$arq} { puts -nonewline [append frase1 "Erro: O arquivo " $var(origem) " n" [format %c 227] "o"] puts [append frase2 " tem permiss" [format %c 227] "o de leitura."] unset frase1 frase2 exit
}
unset arq
set nr [string is integer $var(cifra)] if {!$nr} { puts -nonewline [append frase1 "Erro: A cifra passada n" [format %c 227] "o " [format %c 233]] puts [append frase2 " um valor inteiro."] unset frase1 frase2 exit
}
if {$var(cifra) < 2 || $var(cifra) > 26} { puts -nonewline [append frase1 "Erro: A cifra passada n" [format %c 227] "o " [format %c 233]] puts [append frase2 " um valor inteiro entre 2 e 26."]