Thread: Need help for code menu driver

  1. #1
    Registered User
    Join Date
    Jan 2013

    Need help for code menu driver

    I need same help to write code for this problem like in ncurses to my actual API

    Scrolling Menus

    If the subwindow given for a window is not big enough to show all the items, then the menu will be scrollable. When you are on the last item in the present list, if you send REQ_DOWN_ITEM, it gets translated into REQ_SCR_DLINE and the menu scrolls by one item. You can manually give REQ_SCR_ operations to do scrolling.

    #define MENU_MAX 25
    struct menu_s
         char *name;
         char text[ MENU_MAX ][ 128 ];
         char arguments[ MENU_MAX ][ 128 ];
         int commands[ MENU_MAX ]; 
         char back_argument[ 128 ];
         int back_command;
         int numlines;
         int cursor;
         int defaultcursor;
     menu_t *menu_new( const char *name ) {
         menu_t *menu = malloc( sizeof( menu_t ) );
         if( !menu ) {
             return 0;
        menu->numlines = 0; 
        menu->cursor = 0; 
        menu->defaultcursor = 0;
        menu->name = strdup( name ); 
        if( !menu->name ) {
             free( menu );
             return 0;
         return menu;
    void menu_delete( menu_t *menu ) { 
        free( menu->name ); 
        free( menu ); 
    void menu_reset_num_lines( menu_t *menu ) {
         menu->numlines = 0; 
    void menu_set_text( menu_t *menu, int line, const char *text ) {
         snprintf( menu->text[ line ], sizeof( menu->text[ 0 ] ), "%s", text );
         if( line >= menu->numlines ) menu->numlines = line + 1;
     void menu_set_enter_command( menu_t *menu, int line, int command,  const char *argument ) { 
        menu->commands[ line ] = command;
        snprintf( menu->arguments[ line ], sizeof( menu->arguments[ 0 ] ),  "%s", argument );
    void menu_set_back_command( menu_t *menu, int command, const char *argument ) { 
        menu->back_command = command;
        snprintf( menu->back_argument, sizeof( menu->back_argument ),  "%s", argument ); 
    void menu_set_cursor( menu_t *menu, int cursor ) { 
        menu->cursor = cursor; 
    const char *menu_get_name( menu_t *menu ) { 
        return menu->name; 
    int menu_get_num_lines( menu_t *menu ) { 
        return menu->numlines;
    const char *menu_get_text( menu_t *menu, int line ) {
         return menu->text[ line ]; 
    int menu_get_enter_command( menu_t *menu, int line ) {
         return menu->commands[ line ]; 
    const char *menu_get_enter_argument( menu_t *menu, int line ) {     return menu->arguments[ line ];
    int menu_get_back_command( menu_t *menu ) {
         return menu->back_command; 
    const char *menu_get_back_argument( menu_t *menu ) { 
        return menu->back_argument; 
    int menu_get_cursor( menu_t *menu ) {
         return menu->cursor;
    Last edited by sete; 01-07-2013 at 06:56 PM.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Long Beach, CA
    This looks very familiar:
    how to optimize "for" statement
    make a loop for scrolling lines in menu box

    It's considered good practice to search a forum to see if somebody else had your problem, and a solution has already been provided. That avoids duplication of effort. This is a good read on general forum etiquette: How To Ask Questions The Smart Way (don't take the title personally). Also, read these links: forum guidelines and homework policy.

    We don't hand out code here, but we do help you fix it. So take your best shot at this, and post back, you'll get some help. Also, read the two threads I linked to above. They have some info that will help you. In particular, my post in the "make loop..." thread (link). You must understand what you are doing and how to solve the problem before you begin to write code. Work it out on paper first.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    And from the same ISP as well - it sure is a popular topic in one part of the world.

    You missed these lines from your code.
     * Copyright (c) 2003 Billy Biggs <>.
     * This program is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation; either version 2, or (at your option)
     * any later version.
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * GNU General Public License for more details.
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the Free Software Foundation,
     * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include "menu.h"
    It's from here Repository - [tvtime] Contents of /tvtime/src/menu.c

    Most of the other code from your two 'friends' in the other posts mentioned by anduril462 is either copy/paste from the same sourceforge project, or a thinly disguised rename.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. hi how to check my serial port is intrupt driver or poll driver?
    By nkrao123@gmail. in forum Networking/Device Communication
    Replies: 5
    Last Post: 09-19-2011, 11:20 PM
  2. [C++] USB gadget driver, unbound kernel driver?
    By Jelte in forum C++ Programming
    Replies: 0
    Last Post: 01-13-2010, 08:53 AM
  3. Menu code is too large
    By Yuri in forum C++ Programming
    Replies: 8
    Last Post: 01-09-2008, 03:43 PM
  4. Menu driven code
    By liquidcourage1 in forum C++ Programming
    Replies: 13
    Last Post: 04-23-2006, 05:51 PM
  5. using a driver function to test my code??
    By tommy69 in forum C Programming
    Replies: 24
    Last Post: 03-20-2004, 07:12 PM