// m2c.cpp - Convert Morse code to english. The format of the Morse code is as described
//           in c2m.cpp. In converting back to characters we make sure that no row is more than 
//           ROWMAX (=50) columns.

#include <iostream>
#include <cstring>
#include <string>
using namespace std;
#include "morse.h"

const int ROWMAX = 50;

int main()
{
	const int MAXLINE = 256;
	char line[MAXLINE];
	char c;
	int count = 0;  // number of characters in morse token
	int spaces = 0; // number of consecutives white characters
        int llen = 0;   // number of characters in a line
	while (cin.get(c)) {
		if (isspace(c)) {
		    spaces++;
		    if (spaces == 6) {
			cout.put(' ');
			llen++;
		    } else if (spaces == 1) {
			line[count] = '\0';
			if (count > 0) {
			    cout << Morse::morse2char(line);
		            count = 0;
			    llen++;
			}
		    }
		    if (llen > ROWMAX) {
			cout << endl;
			llen = 0;
		    }
		} else {
		    if (count < MAXLINE-1)
		        line[count++] = c;
		    spaces = 0;
		}
	}
	cout << endl;
	return 0;
}
