#module NEWSSKIP "V4.0"
/*----------------------------------------------------------------------
        N E W S S K I P . C

 Author:
     Geoff Huston
       Computer Services Centre
       Australian National University

 Functionality:
        Skip unread news in a newsgroup

 External Functions:
        clear_err_line
        err_line
        ga_search_name
        util_cvrt

 Version:

    V1.0    17-Jul-1986
    V3.0    23-Apr-1987     GIH     Version 3 release
    V4.0    30-Oct-1987     GIH     NEWS Version 4.0 Release
----------------------------------------------------------------------*/

#include "newsinclude.h"
#include "newsdefine.h"
#include "newsextern.h"


/*----------------------------------------------------------------------
 *  s c r e e n _ u p d a t e _ g r e a d
 *
 *  Update the read field of the directory screen display
 *----------------------------------------------------------------------
 */

screen_update_gread(g)
    int g;
{
    int indx;

    if ((screen_active) && (indx = ga[g]->grp_display_indx))
    {
        if ((ga[g]->grp_reg) && (ga[g]->grp_unread)) smg$change_rendition(&grp_vd,&indx,c$rfi(4),c$rfi(1),c$rfi(5),c$rfi(SMG$M_BOLD),0);
        else  smg$change_rendition(&grp_vd,&indx,c$rfi(4),c$rfi(1),c$rfi(5),c$rfi(0),0);
        if (ga[g]->grp_unread)
        {
            sprintf(err_oline,"%5d",ga[g]->grp_unread);
            smg$put_chars(&grp_vd,c$dsc(err_oline),&indx,c$rfi(73),0,0,0,0);
        }
        else smg$put_chars(&grp_vd,c$dsc("     "),&indx,c$rfi(73),0,0,0,0);
    }
}

/*----------------------------------------------------------------------
 *  s c r e e n _ u p d a t e _ i r e a d
 *
 *  Update an item display on the screen to indicate that the item
 *  has been read
 *----------------------------------------------------------------------
 */

screen_update_iread(g,i)
    int g,
        i;
{
    int indx;

    if (screen_active && ga[g]->grp_iavdsize)
    {
        if (ga[g]->grp_ia[i].itm_unread) smg$change_rendition(&(ga[g]->grp_iavd),&i,c$rfi(4),c$rfi(1),c$rfi(5),c$rfi(SMG$M_BOLD),0);
        else smg$change_rendition(&(ga[g]->grp_iavd),&i,c$rfi(4),c$rfi(1),c$rfi(5),c$rfi(0),0);
    }
}

/*--------------COMMAND  FUNCTIONS---------------------------------------
 *  d o _ s k i p
 *
 *  define verb SKIP
 *      routine     do_skip
 *      parameter   P1,         label=NEWSGROUP
 *      qualifier   ALL,        nonnegatable
 *      disallow    (ALL and NEWSGROUP)
 *
 *  scan over all remaining new news in newsgroup
 *----------------------------------------------------------------------
 */

do_skip()
{
    char ngroup[SUBJLEN];
    $DESCRIPTOR(ngroup_dsc,ngroup);
    short ngroup_len;
    int g,
        i;

    clear_err_line();
    if (cli$present(c$dsc("ALL")) == CLI$_PRESENT)
    {
        for (g = 1; g <= ga_size; ++g)
        {
            if (ga[g]->grp_unread)
            {
                ga[g]->grp_unread = 0;
                if (screen_active) screen_update_gread(g);
                if (ga[g]->grp_ia)
                {
                    for (i = 1; i <= ga[g]->grp_count; ++i)
                    {
                        if (ga[g]->grp_ia[i].itm_unread)
                        {
                            ga[g]->grp_ia[i].itm_unread = 0;
                            if (screen_active) screen_update_iread(g,i);
                        }
                    }
                }
            }
        }
        return(0);
    }

    g = curr_g;
    if (cli$get_value(c$dsc("NEWSGROUP"),&ngroup_dsc,&ngroup_len) != CLI$_ABSENT)
    {
        ngroup[ngroup_len] = '\0';
        util_cvrt(ngroup,ngroup);

        if (!(g = ga_search_name(ngroup)))
        {
            sprintf(err_oline,"\tError: Skip - no such Newsgroup: %s\n",ngroup);
            err_line(err_oline);
            return(0);
        }
    }

    if (!g) return(err_line("\tWarning: Skip - No Newsgroup selected\n"),0);

    if (ga[g]->grp_unread)
    {
        ga[g]->grp_unread = 0;
        if (screen_active) screen_update_gread(g);
        if (ga[g]->grp_ia)
        {
            for (i = 1; i <= ga[g]->grp_count; ++i)
            {
                if (ga[g]->grp_ia[i].itm_unread)
                {
                    ga[g]->grp_ia[i].itm_unread = 0;
                    if (screen_active) screen_update_iread(g,i);
                }
            }
        }
    }
    return(0);
}
