void checkXpointer()
{
    if (listfind(g_classes, "xpointer") != -1)
        g_sharedLibReq += " -lX11";
}

void checkMilter()
{
    if (listfind(g_classes, "milter") != -1)
        g_sharedLibReq += " -lmilter -L/usr/lib/libmilter";
}


void checkReadLine()
{
    list class;
    string elem;

    while (listlen(class = fgets("READLINE", class)))
    {
        elem = strtok(class[0], " \t\n")[0];
        if (elem != "#" && listfind(g_classes, elem) != -1)
        {
            g_sharedLibReq += " -lreadline";
            return;
        }
    }
}

void checkSSL()
{
    list class;
    string elem;

    while (listlen(class = fgets("SSLCLASSES", class)))
    {
        elem = strtok(class[0], " \t\n")[0];
        if (elem != "#" && listfind(g_classes, elem) != -1)
        {
            g_sharedLibReq += " -lssl -lcrypto";
            return;
        }
    }
}


void askMilter(int all)
{
    if (!all)
        printf(
    "    The class FBB::Milter can only be compiled if you have installed\n"
    "    the file libmilter/mfapi.h. To use the class Milter, programs using\n"
    "    Milter objects must also be linked against the milter library:\n"
    "    -lmilter -l" LIBRARY "\n"
    "\n"
    "    The class FBB::Milter can safely be left out of the " LIBRARY " "
                                                            "library if\n"
    "    you're not planning to construct mail filters using FBB::Milter.\n"
    "\n"
    "    Enter y if you WANT to compile the files of the class "
                                                            "FBB::Milter.\n"
    "    Press Enter or any other line if you DON'T WANT to include the "
                                                            "class\n"
    "                                  FBB::Milter in the " LIBRARY 
                                                                " library.\n"
        );

    if (all || gets() == "y")
    {
        g_sharedLibReq += " -lmilter -L/usr/lib/libmilter";
        g_classes += (list)"milter";
    }
}

void askXpointer(int all)
{
    if (!all)
        printf(
    "    The class FBB::Xpointer can only be compiled if you have installed\n"
    "    the file X11/Xlib.h. To use the class Xpointer, programs using "
                                                            "Xpointer\n"
    "    objects must also be linked against the X11 library: -lX11 -l" 
                                                                LIBRARY "\n"
    "\n"
    "    The class FBB::Xpointer can safely be left out of the " LIBRARY " "
                                                            "library if\n"
    "    you're not planning to construct programs using Xpointer.\n"
    "\n"
    "    Enter y if you WANT to compile the files of the class "
                                                            "FBB::Xpointer.\n"
    "    Press Enter or any other line if you DON'T WANT to include the "
                                                            "class\n"
    "                                  FBB::Xpointer in the " LIBRARY 
                                                                " library.\n"
        );

    if (all || gets() == "y")
    {
        g_sharedLibReq += " -lX11";
        g_classes += (list)"xpointer";
    }
}


void askOpenSSL(int all)
{
    if (!all)
        printf(
    "    The SSL classes can only be compiled if you have installed\n"
    "    the libssl-dev development library, containing files like\n"
    "    /usr/include/openssl/bn.h. To use objects from openssl programs\n"
    "     must also be linked against the openSSL library: -lssl -l" LIBRARY 
                                                                        "\n"
    "\n"
    "    The SSL classes can safely be left out of the " LIBRARY 
                                                            " library if\n"
    "    you're not planning to construct programs using them.\n"
    "\n"
    "    Enter y if you WANT to compile the files of the SSL classes\n"
    "    Press Enter or any other line if you DON'T WANT to include the "
                                                            "SSL classes\n"
    "                                  in the " LIBRARY " library.\n"
        );

    if (all || gets() == "y")
    {
        g_sharedLibReq += " -lssl -lcrypto";
        addClasses("SSLCLASSES");
    }    
}

void askReadLine(int all)
{
    if (!all)
        printf(
    "    The classes using the readline library can only be compiled if you\n"
    "    have installed the libreadline-dev development library, containing\n"
    "    files like /usr/include/readline.h. To use objects of these\n"
    "    classes in your programs, your programs must also be linked\n"
    "    against the readline library: -lreadline -l" LIBRARY "\n"
    "\n"
    "    The classes depending on the readline library can safely be left\n"
    "    out of the " LIBRARY " library if you're not planning to construct\n"
    "    programs using them.\n"
    "\n"
    "    Enter y if you WANT to compile the classes using the\n"
    "    readline library\n"
    "    Press Enter or any other line if you DON'T WANT to include these\n"
    "                                  classes in the " LIBRARY " library.\n"
        );

    if (all || gets() == "y")
    {
        g_sharedLibReq += " -lreadline";
        addClasses("READLINE");
    }    
}

void special(int query, int all, int select)
{
    list cut;
    list line;
    int refresh;

    if (select)
    {
        checkXpointer();
        checkMilter();
        checkReadLine();
        checkSSL();
    }
    else if (g_all && query)
    {
        askXpointer(all);
        askOpenSSL(all);
        askReadLine(all);
        askMilter(all);
    }

    g_nClasses = listlen(g_classes);

    refresh = "VERSION" newer "release.yo";

    if (refresh)
        run("rm -f release.yo");

    while (listlen(line = fgets("VERSION", line)))
    {
        cut = strtok(element(0, line), "= \t\n");

        if (element(0, cut) == "VERSION")
        {
            g_version = element(1, cut);

            if (refresh)
                fprintf("release.yo", "SUBST(_CurVers_)(", g_version, ")\n");
        }
        else if (refresh && element(0, cut) == "YEARS")
            fprintf("release.yo", "SUBST(_CurYrs_)(", element(1, cut), ")\n");
    }
}


