//#define XERR __FILE__
#include "main.ih"

int main(int argc, char **argv)
try
{
    string line;
    if (argc == 1)
    {
        MemoryStream ms{ "1kB", true };
        cerr << "extracting from ID = " << ms.id() << 
                                            " until non-empty line\n";
        while (true)
        {
            cout << "? ";
            if (getline(cin, line) and not line.empty())
                break;

            ms.clear();
            ms.seekg(0);
            ms >> line;
            cerr << "Got " << line << '\n';
        }
    }
    else
    {
        MemoryStream ms{ stoi(argv[1]) };
        cerr << "inserting LIST into " << argv[1] << 
                                                " until non-empty line\n";
        while (true)
        {
            cout << "? ";

            if (getline(cin, line) and not line.empty())
                break;

            ms.clear();
            ms.seekp(0);
            cerr << "write LIST\n";
            ms << "LIST" << endl;
        }
    }
}
catch (exception const &exc)
{
    cerr << exc.what() << '\n';
}
catch (...)
{
    cerr << "exception\n";
}
