|
|
|
@ -1,12 +1,18 @@
|
|
|
|
|
#include "morse.h"
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
const long DEFAULT_DASH_PAUSE = 300000;
|
|
|
|
|
const long DEFAULT_DOT_PAUSE = 150000;
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]){
|
|
|
|
|
char* inputString;
|
|
|
|
|
char* outputString;
|
|
|
|
|
// outputChar tracks the current printing character when slow printing is enabled
|
|
|
|
|
char outputChar;
|
|
|
|
|
|
|
|
|
|
long dash_delay = DEFAULT_DASH_PAUSE;
|
|
|
|
|
long dot_delay = DEFAULT_DOT_PAUSE;
|
|
|
|
|
|
|
|
|
@ -41,8 +47,6 @@ int main(int argc, char *argv[]){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (convertFromMorse){
|
|
|
|
|
char* inputString;
|
|
|
|
|
char* outputString;
|
|
|
|
|
// for every line in the input, until the end of file
|
|
|
|
|
while ((getline(&inputString, &buflen, stdin))!=EOF){
|
|
|
|
|
int stringLen = strlen(inputString);
|
|
|
|
@ -58,8 +62,6 @@ int main(int argc, char *argv[]){
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
char* inputString;
|
|
|
|
|
char* outputString;
|
|
|
|
|
// for each line of input
|
|
|
|
|
while ((getline(&inputString, &buflen, stdin))!=EOF){
|
|
|
|
|
int stringLen = strlen(inputString);
|
|
|
|
@ -70,9 +72,27 @@ int main(int argc, char *argv[]){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
outputString = string_to_morse(inputString);
|
|
|
|
|
printf("%s\n", outputString);
|
|
|
|
|
// force flush the buffer incase user is in interactive mode
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
|
|
|
|
|
if (isSlow){
|
|
|
|
|
for (int i = 0; i < strlen(outputString); i++){
|
|
|
|
|
outputChar = outputString[i];
|
|
|
|
|
if (outputChar == '-'){
|
|
|
|
|
usleep(dash_delay);
|
|
|
|
|
printf("%c", outputChar);
|
|
|
|
|
} else if (outputChar == '.'){
|
|
|
|
|
usleep(dot_delay);
|
|
|
|
|
printf("%c", outputChar);
|
|
|
|
|
} else {
|
|
|
|
|
printf("%c", outputChar);
|
|
|
|
|
}
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
} else {
|
|
|
|
|
printf("%s\n", outputString);
|
|
|
|
|
// force flush the buffer incase user is in interactive mode
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|