Like Tree1Likes
  • 1 Post By memcpy

Scroll up and down line by line (from buffer) in c

This is a discussion on Scroll up and down line by line (from buffer) in c within the C Programming forums, part of the General Programming Boards category; I write code to extract data from xmltv listings and display them perchannel in page with 15 line. How to ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    8

    Scroll up and down line by line (from buffer) in c

    I write code to extract data from xmltv listings and display them perchannel in page with 15 line. How to make to scroll up and down line by line in page (from buffer) until last line information from listings perchannel is end and them move to next page that display information for another channel?
    channel 1:
    Code:
    |   line1   |                      |   line2   |                |-----------|
    |   line2   |                      |   line3   |                |-----------|
    |   line3   | scroll down line =>  |   line4   | then clear =>  | lastline  | 
    |   line4   |                      |-----------|                |           |
    |-----------|                      |   line15  |                |           |
    |   line15  |                      |   line16  |                |           |
    then move to => channel 2:
    Code:
    |   line1   |                      |   line2   |                |-----------|
    |   line2   |                      |   line3   |                |-----------|
    |   line3   | scroll down line =>  |   line4   | then clear =>  | lastline  |
    |   line4   |                      |-----------|                |           |
    |-----------|                      |   line15  |                |           |
    |   line15  |                      |   line16  |                |           |
    etc.

    My code:
    Code:
    int epg_show_perchannel( tvtime_osd_t* osd, int page, station_mgr_t *stationmgr, xmltv_t *xmltv, int channel )
    {
    if (!page)
        return 0;
    if ( xmltv ){
        const int buf_length = 255;
        const int max_num_lines = 15;
        const int num_stations = station_get_num_stations( stationmgr );
        char *old_channel = strdup( xmltv_get_channel( xmltv ) );
        char buf[buf_length+1];
        int cur = 0;
        time_t curtime = time( 0 );
        const char *xmltv_id = 0;
    
        if (channel > num_stations)  
            channel = 1;
        else if (channel < 1 )
            channel = num_stations;
    
        if (!(xmltv_id = station_get_xmltv_id( stationmgr, channel-1 ))) 
            xmltv_id = xmltv_lookup_channel( xmltv, station_get_name( stationmgr, channel-1 ));
        xmltv_set_channel( xmltv, xmltv_id);
        xmltv_refresh_withtime( xmltv, curtime );
    
        /* List header with Channel number + name */
        snprintf(buf, buf_length, "%d Next on [%s] %s:", channel, station_get_channel(stationmgr,channel-1), station_get_name( stationmgr, channel-1));
        tvtime_osd_list_set_text( osd, cur++, buf );
        tvtime_osd_list_set_hilight(osd, -1);   
    
        while ((cur-1) < max_num_lines) {
            xmltv_refresh_withtime( xmltv, curtime );
    
            if (xmltv_get_title( xmltv )) {
                char start_time[50];
                time_t start_timestamp = xmltv_get_start_time( xmltv );
                time_t end_timestamp = xmltv_get_end_time( xmltv );
                strftime( start_time, 50, "%H:%M", localtime( &start_timestamp ) );
    
                /* starttime of current program + Now showing program */
                snprintf(buf, buf_length, "%s %s", start_time, xmltv_get_title( xmltv ));       
                if (xmltv_get_sub_title( xmltv )){
                    strncat(buf," (",buf_length-strlen(buf));  
                    strncat(buf,xmltv_get_sub_title( xmltv ),buf_length-strlen(buf));
                    strncat(buf,")",buf_length-strlen(buf));  
                }
                tvtime_osd_list_set_multitext( osd, cur++, buf, 1);
    
                if (!xmltv_get_next_title( xmltv )) {
                    char end_time[50];
                    /* no next program, print endtime of current programme */       
                    strftime( end_time, 50, "%H:%M", localtime( &end_timestamp ) );
                    snprintf(buf, buf_length, "%s %s", end_time, "");       
                    tvtime_osd_list_set_multitext( osd, cur++, buf, 1);
                }
            curtime = end_timestamp;
    
            } else {
                /* No XMLTV information for this channel */
                tvtime_osd_list_set_text( osd, cur++, "");
            }
    
        }
        tvtime_osd_list_set_lines( osd, cur );
        tvtime_osd_show_list( osd, 1, 1 );
    
        xmltv_set_channel(xmltv, old_channel);
        free(old_channel);
        xmltv_refresh( xmltv );
    
    } else {
        tvtime_osd_list_set_text( osd, 0, "No XMLTV Program Guide information available" );
        tvtime_osd_list_set_lines( osd, 1 );
        tvtime_osd_show_list( osd, 1, 1 );
    }
    return channel;
    }
    My code, actualy show page with only 15 line and then move to next channel.

    I want to scroll down list until information from xmltv listings for channel is end, and then move to next channel.

    Name:  Kt0MY.jpg
Views: 246
Size:  54.5 KB
    Name:  eWDyT.jpg
Views: 226
Size:  56.1 KB

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Remarkably similar to > [git:tvtime/master] program guide from #1097855, needs some fixes, just cmnd-F and "your" code is almost verbatim there.
    Salem likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Read text file line by line and write lines to other files
    By magische_vogel in forum C Programming
    Replies: 10
    Last Post: 01-23-2011, 10:51 AM
  2. Replies: 7
    Last Post: 12-13-2010, 02:13 PM
  3. Reading a buffer line by line, while using system read
    By Hammad Saleem in forum C Programming
    Replies: 9
    Last Post: 05-27-2008, 06:41 AM
  4. Replies: 1
    Last Post: 05-21-2006, 12:17 AM
  5. reading command line arguments into buffer
    By jpp1cd in forum C Programming
    Replies: 2
    Last Post: 12-12-2002, 08:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21