示例#1
0
文件: conmenu.cpp 项目: bbonev/vslib
int con_full_box( int x, int y, const char *title, VArray *va, ConMenuInfo *menu_info )
{
  ScrollPos scroll;
  scroll.wrap = 0;
  scroll.set_min_max( 0, va->count()-1 );
  scroll.set_pagesize( con_max_y() - 3 ); /* one title and two status */
  scroll.go( 0 );

  char pos_str[32];

  con_xy( 1, 1 );
  con_puts( title, menu_info->ti );
  con_ce( menu_info->ti );
  while(4)
    {
    VString str;
    int z;
    for( z = 0; z < scroll.pagesize(); z++ )
      {
      if ( scroll.page() + z < va->count() )
        str = va->get( scroll.page() + z );
      else
        str = "~";
      str = str_dot_reduce( str, con_max_x()-1 );
      con_xy( 1, z + 2 );
      int c = ( scroll.page() + z == scroll.pos() ) ? menu_info->ch : menu_info->cn;
      con_puts( str, c );
      con_ce( c );
      }
    sprintf( pos_str, " %5d of %5d", scroll.pos()+1, scroll.max()+1 );
    con_out( con_max_x() - 15, 1, pos_str, menu_info->ti );
    int ch;
    switch( (ch = con_getch()) )
      {
      case 27 : menu_info->ec = 27; return -1; break;
      case  8 : menu_info->ec =  8; return -1; break;
      case KEY_BACKSPACE : menu_info->ec =  KEY_BACKSPACE; return -1; break;
      case 13 : menu_info->ec = 13; return scroll.pos(); break;
      case KEY_UP    : scroll.up(); break;
      case KEY_DOWN  : scroll.down(); break;
      case KEY_NPAGE : scroll.npage(); break;
      case KEY_PPAGE : scroll.ppage(); break;
      case KEY_HOME  : scroll.home(); break;
      case KEY_END   : scroll.end(); break;
      default:
        if ( tolower(ch) == tolower(menu_info->ac) )
          {
          menu_info->ec = menu_info->ac;
          return -2;
          }
          break;
      }
    }
}
示例#2
0
文件: console.c 项目: abc6081/daq
char con_kbhit()
{
#ifdef LINUX

  int i, g;  
  
  nodelay(stdscr, TRUE);
  i = ( ( g = getch() ) == ERR ? 0 : g );
  nodelay(stdscr, FALSE);

  return i;   

#else
  
  char c=0;

  if(kbhit())            
    c = (char)con_getch();  
  return(c);

#endif
}
示例#3
0
void tree_view()
{
  VString str;
  if (dir_tree.count() == 0)
    {
    tree_load();
    if (dir_tree.count() == 0) 
      tree_rebuild();
    }
  say1( " " );
  int new_pos = tree_index( work_path );
  if ( new_pos == -1 )
    new_pos = 0;

  BSet set; /* used for searching */
  set.set_range1( 'a', 'z' );
  set.set_range1( 'A', 'Z' );
  set.set_range1( '0', '9' );
  set.set_str1( "._-~" );
  set.set_str1( "?*>[]" );
  
  ScrollPos scroll;
  scroll.set_min_max( 0, dir_tree.count()-1 );
  scroll.set_pagesize( PS+2 );
  scroll.go( new_pos );
  
  int key = 0;
  int opos = -1;
  int opage = -1;
  while( key != 27 && key != 13 && key != '-' && 
         toupper( key ) != 'Q' && toupper( key ) != 'X' && key != KEY_ALT_X )
    {
    if ( key >= 'A' && key <= 'Z' ) key = tolower( key );
    if ( key == 's' )
      {
        str = "";
        say1( "Enter search pattern: ( use TAB to advance )" );
        key = con_getch();
        while( set.in( key ) || key == 8 || key == KEY_BACKSPACE || key == 9 )
          {
          if ( key == 8 || key == KEY_BACKSPACE )
            str_trim_right( str, 1 );
          else
          if ( key != 9 )
            str_add_ch( str, key );
          say2( str );
          
          if ( dir_tree.count() == 0 ) { key = con_getch(); continue; }
          
          int z;
          if ( key == 9 )
            {
            z = scroll.pos() + 1;
            if (z > scroll.max() ) z = scroll.min();
            }
          else
            z = scroll.pos();
          int direction = 1;
          int found = 0;
          int loops = 0;
          VString s_mask = str;
          vfu_expand_mask( s_mask );
          while(1)
            {
            if ( z > scroll.max() ) z = scroll.min();
            if ( z < scroll.min() ) z = scroll.max();
            
            VString str1 = dir_tree[z];
            str_trim_right( str1, 1 );
            int j = str_rfind(str1,'/');
            if (j < 0) 
              str1 = "";
            else
              str_trim_left( str1, j+1 );
            found = ( FNMATCH( s_mask, str1 ) == 0 );
            if ( found ) break;
            z += direction;
            if ( loops++ > dir_tree.count() ) break;
            }
          if (found)
            {
            scroll.go(z);
            tree_draw_page( scroll );
            tree_draw_pos( scroll, opos );
            }
          key = con_getch();
          }
        say1( "" );
        say2( "" );
      }
    else
    switch( key )
      {
      case KEY_UP     : scroll.up(); break;
      case KEY_DOWN   : scroll.down(); break;
      case KEY_PPAGE  : scroll.ppage(); break;
      case KEY_NPAGE  : scroll.npage(); break;
      case KEY_HOME   : scroll.home(); break;
      case KEY_END    : scroll.end(); break;
      case 'r'        : tree_rebuild();
                        scroll.set_min_max( 0, dir_tree.count()-1 );
                        scroll.home();
                        say1( "Rebuild done." );
                        break;
      case 'w'        : tree_save(); break;
      case 'l'        : tree_load(); 
                        scroll.set_min_max( 0, dir_tree.count()-1 );
                        scroll.home();
                        break;
      case 'z'        : 
      case KEY_CTRL_Z :
                        str = dir_tree[scroll.pos()];
                        str_tr( str, "\\", "/" );
                        size_cache_set( str, vfu_dir_size( str ) );
                        tree_draw_page( scroll );
                        tree_draw_pos( scroll, opos );
                        say1( "Done." );
                        break;
      }
    if (opage != scroll.page()) 
      tree_draw_page( scroll );
    if (opos != scroll.pos() - scroll.page() || opage != scroll.page()) 
      tree_draw_pos( scroll, opos );
    opos = scroll.pos() - scroll.page();
    opage = scroll.page();
    key = con_getch();
    }
  if ( key == 13 )
    {
    str = dir_tree[scroll.pos()];
    str_tr( str, "\\", "/" );
    vfu_chdir( str );
    }
  do_draw = 2;
};
示例#4
0
int vfu_get_dir_name( const char *prompt, VString &target, int should_exist )
{ 
  int res = -1;
  /*
  #ifdef _TARGET_UNIX_
  leaveok(stdscr, FALSE);
  #endif
  */
  VArray dir_list;
   
  say1(prompt); 
  say2(""); 
  
  int pos = 0; 
  int page = 0;
  int ch = 0; 
  
  int insert = 1;
  int firsthit = 1;
  
  pos = str_len( target );

  //------------------------------------------------------------------
  
  con_cshow();
  say2( target, firsthit ? cINPUT2 : cINPUT );
  while(1) 
    {
    int mx = con_max_x() - 1;
    VString target_out = target;
    if ( (pos < page) || (pos+1 > page + mx) || (page > 0 && pos == page) ) 
      page = pos - mx / 2;
    if ( page < 0 ) page = 0;

    str_trim_left( target_out, page );
    str_sleft( target_out, mx );
    str_pad( target_out, -mx );
    if ( page > 0 )
      str_set_ch( target_out, 0, '<' );
    if ( str_len( target ) - page > mx )
      str_set_ch( target_out, mx-1, '>' );
    
    say2( target_out, firsthit ? cINPUT2 : cINPUT );
    con_xy( pos-page+1, con_max_y() );

    
    if (ch == 0) ch = con_getch();
    if (ch == '\\') ch = '/'; /* dos hack :)) */
    if ( ch == '/' && str_find( target, '/' ) == -1 && target[0] == '~' )
      {
      target = tilde_expand( target );
      str_fix_path( target );
      pos = str_len( target );
      ch = 0;
      }
      
    if ((ch == 8 || ch == KEY_BACKSPACE) && pos > 0) 
      { 
      pos--; 
      str_del( target, pos, 1 );
      } 
    else
    if (ch == KEY_CTRL_A && str_len( target ) > 0)
      {
      int z = str_len( target )-1;
      if ( str_get_ch(target, z) == '/' ) z--;
      while ( z > 0 && str_get_ch(target,z) != '/' ) z--;
      z++;
      str_sleft(target,z);
      pos = z;
      }
    else
    if ( ch == 9 && str_len( target ) > 0)
      { 
      int z; 
      dir_list.undef();
      VString dmain; /* main/base path */
      VString dtail; /* item that should be expanded/glob */
      
      dmain = str_file_path( target );
      dtail = str_file_name_ext( target );
      
      /*
      int lastslash = str_rfind(target, '/');
      if ( lastslash == -1 ) 
        {
        dmain = "";
        dtail = target;
        }
      else
        {
        dmain = target;
        dtail = target;
        str_sleft( dmain, lastslash+1 );
        str_trim_left( dtail, lastslash+1 );
        }
      */
      
      __glob_gdn( dmain, dtail, dir_list );
  
      z = dir_list.count()-1;
      if (dir_list.count()) 
        {
        if ( dir_list.count() > 1)
          {
          int mc = 0; /* match count        */
          int mi = 0; /* match letter index */
          while(4)
            {
            mc = 0;
            int li; /* counter */
            for ( li = 0; li < dir_list.count(); li++ )
              {
              if ( str_get_ch( dir_list[ 0], mi ) == 
                   str_get_ch( dir_list[li], mi ) )
                mc++;
              }
            if ( mc != dir_list.count() )
              break;
            mi++;
            }
          target.setn( dmain + dir_list[0], str_len( dmain ) + mi );
          pos = str_len( target );
          say2( target, cINPUT );
          con_xy( pos+1, con_max_y() );
          
          vfu_beep();
          ch = con_getch();
          if ( ch != 9 ) { dir_list.undef(); continue; }
          dir_list.sort();
          con_chide();
          z = vfu_menu_box( 10, 5, "Complete...", &dir_list );
          con_cshow();
          ch = 0;
          }
        else
          ch = 0;
        if ( z != -1 )
          {
          while( str_len( target ) > 0 && target[-1] != '/' )
            str_chop( target );
          target += dir_list[z];
          }
        
        pos = str_len( target );
        
        dir_list.undef();
        if (ch != 0) continue;
        }
      else
        { /* no match found -- cannot complete */
        vfu_beep();
        }
      } 
    else 
    if (ch == 13)
      { 
      res = 1;
      break; 
      } 
    else 
    if (ch == 27) 
      { 
      target = "";
      res = 0;
      break; 
      } 
    if (ch == KEY_CTRL_U)
      { 
      target = "";
      pos = 0;
      }
    else
    if (ch == KEY_CTRL_X)
      {
        char t[MAX_PATH];
        if ( target[0] == '~' )
          target = tilde_expand( target );
        expand_path( target, t );
        str_fix_path( t );
        target = t;
        pos = str_len( target );
      }
    else 
    if (ch >= 32 && ch <= 255 ) // && pos < 70) 
      { 
      if (firsthit) 
        {
        target = "";
        pos = 0;
        }
      if (!insert) str_del( target, pos, 1 );
      str_ins_ch( target, pos, ch );
      pos++;
      } else
    if( ch == KEY_LEFT  )
      {
      if (pos > 0)
        pos--;
      } else
    if( ch == KEY_RIGHT )
      {
      if (pos < str_len( target ))
        pos++;
      } else
    if ( ch == KEY_IC   ) insert = !insert; else
    if ( ch == KEY_HOME ) pos = 0; else
    if ( ch == KEY_END  ) pos = str_len(target); else
    if ( ch == KEY_DC  && pos < str_len(target) ) 
       str_del( target, pos, 1 ); else
    if ( ch == KEY_NPAGE || ch == KEY_PPAGE )
      {
      con_chide();
      int zz = vfu_hist_menu( 5, 5, ( ch == KEY_PPAGE ) ? "Dir Entry History" : "ChDir History", 
                              ( ch == KEY_PPAGE ) ? HID_GETDIR : HID_CHDIR );
      con_cshow();
      if (zz != -1)
        {
        const char* pc = vfu_hist_get( ( ch == KEY_PPAGE ) ? HID_GETDIR : HID_CHDIR, zz );
        if ( pc )
          {
          target = pc;
          pos = str_len( target );
          }
        }
      }
    ch = 0; 
    firsthit = 0;
    }
  con_chide();
  
  //------------------------------------------------------------------
  str_cut_spc( target );
  if ( res == 1 && target[0] == '~' )
    {
    target = tilde_expand( target );
    str_fix_path( target );
    }
/*  
  if ( target.len() > 0 )
    { 
    // well this tmp is kind of s... ama k'vo da pravi chovek :)
    // FIXME: dos version?
    if ( __ExpandGetDirName && target[0] != '/'
       #ifdef _TARGET_GO32_
       && !( target[1] == ':' && target[2] == '/' )
       #endif
       )
      target = CPath + target;
    StrFixPath( target ); // add trailing slash if not exist
    } 
*/    
  /*
  #ifdef _TARGET_UNIX_
  leaveok(stdscr, TRUE);
  #endif
  */
  if ( res == 1 && str_len( target ) > 0 && should_exist && !dir_exist( target ))
    {
    vfu_beep();
    int ch = tolower( vfu_ask( "Directory does not exist! Create? "
                               "( ENTER=Yes, ESC=cancel )",
                               "\033\rcC" ));
    if ( ch == 27 ) 
      {
      res = 0;
      target = ""; 
      }
    else
    if ( ch == 13 )
       if (make_path( target ))
         {
         if(tolower(
            vfu_ask( "Cannot create path! ( ESC=cancel, C=continue-anyway )", 
            "\033Cc" )) == 27)
            {
            res = 0;
            target = "";
            }
         }
    }
  
  say1(" "); 
  say2(" "); 
  if ( str_len( target ) > 0)
    {
    str_fix_path( target );
    vfu_hist_add( HID_GETDIR, target );
    }
    
  str_cut_spc( target );
  
  ASSERT( res == 0 || res == 1 );
  return res;
} 
示例#5
0
void CaenVmeManual(int32_t BHandle, short first_call)
{       

    static  man_par_t   man     ;
    char                                key,dis_main_menu ;
    uint32_t                    value ;


    if (first_call)
    {                                                           // Default Value 
        man.addr = 0xEE000000 ;      
        man.level = 1 ;           
        man.am = cvA32_U_DATA ;            
        man.dtsize = cvD16 ;        
        man.basaddr = 0xEE000000 ; 
        man.blts = 256 ;          
        man.ncyc = 1 ;            
        man.autoinc = 0 ;  
        
        // Allocate 32K for the software buffer containing data for blt 

        man.buff = (uint32_t *)malloc(16*1024*1024);
        if (man.buff == NULL)
        {
            con_printf(" !!! Error. Can't allocate memory for BLT buffer. ");
            exit(-1);
        }
    }

    for (;;)
    {
        dis_main_menu = 0 ;

        clrscr() ;

        dis_main_menu = 0 ;

        con_printf("\n     CAEN VME Manual Controller \n\n") ;

        con_printf(" R - READ\n") ;
        con_printf(" W - WRITE\n") ;
        con_printf(" B - BLOCK TRANSFER READ\n") ;
        con_printf(" T - BLOCK TRANSFER WRITE\n") ;
        con_printf(" I - CHECK INTERRUPT\n") ;
        con_printf(" 1 - ADDRESS                  [%08"PRIX32"]\n",man.addr) ;
        con_printf(" 2 - BASE ADDRESS             [%08"PRIX32"]\n",man.basaddr) ;
        con_printf(" 3 - DATA FORMAT              [") ; 
        if (man.dtsize == cvD8)
            con_printf("D8]\n") ; 
        if (man.dtsize == cvD16)
            con_printf("D16]\n") ; 
        if (man.dtsize == cvD32)
            con_printf("D32]\n") ; 
        if (man.dtsize == cvD64)
            con_printf("D64]\n") ; 
           
        con_printf(" 4 - ADDRESSING MODE          [") ;  
        if (man.am == cvA16_U)
            con_printf("A16]\n") ; 
        if (man.am == cvA24_U_DATA)
            con_printf("A124]\n") ; 
        if (man.am == cvA32_U_DATA)
            con_printf("A32]\n") ; 
        if (man.am == cvCR_CSR)
            con_printf("CR/CSR]\n") ; 
     
        con_printf(" 5 - BLOCK TRANSFER SIZE      [%"PRIu32"]\n",man.blts) ;
        con_printf(" 6 - AUTO INCREMENT ADDRESS   [") ; 
        if (man.autoinc)
            con_printf("ON] \n") ;
        else
            con_printf("OFF]\n") ;

        con_printf(" 7 - NUMBER OF CYCLES         [") ;
        if (man.ncyc)
            con_printf("%d]\n",man.ncyc) ; 
        else
            con_printf("Infinite\n") ;
                                         
        con_printf(" 8 - VIEW BLT DATA\n") ;          
        con_printf(" F - FRONT PANEL I/O\n") ; 
        con_printf(" Q - QUIT MANUAL CONTROLLER\n") ; 


        do
        {
            gotoxy(X_COMM,Y_COMM) ;

            key = toupper(con_getch()) ;

            clear_line(Y_COMM) ;
            clear_line(Y_COMM+1) ;
            clear_line(Y_COMM+2) ;
            gotoxy(X_COMM,Y_COMM) ;

            switch (key)  
            {
            case  'R' : CaenVmeRead(BHandle, &man) ;
                break ; 

            case  'W' : CaenVmeWrite(BHandle, &man) ; 
                break ;

            case  'B' : CaenVmeReadBlt(BHandle, &man) ; 
                break ;

            case  'T' : CaenVmeWriteBlt(BHandle, &man) ;
                break ;

            case  'I' : CaenVmeIrqCheck(BHandle, &man) ;
                break ;

            case  '1' : con_printf(" Please enter new Address : ") ;

                if (con_scanf("%"SCNx32,&value) != EOF)
                    man.addr = man.basaddr + value ;

                con_printf_xy(X_ADDR,Y_ADDR,"%08"PRIX32,man.addr) ;
                clear_line(Y_COMM) ;

                break ;

            case  '2' : con_printf(" Please enter new Base Address : ") ;

                if (con_scanf("%"SCNx32,&value) != EOF)
                {
                    man.addr -= man.basaddr ;   
                    man.basaddr = value ;
                    man.addr += man.basaddr ;
                }

                con_printf_xy(X_BADDR,Y_BADDR,"%08"PRIX32,man.basaddr) ;
                con_printf_xy(X_ADDR,Y_ADDR,"%08"PRIX32,man.addr) ;

                clear_line(Y_COMM) ;

                break ;

            case  '3' : gotoxy(X_DSIZE,Y_DSIZE) ;

                switch(man.dtsize)
                {
                case cvD8  : man.dtsize = cvD16 ;
                    con_printf("D16]\n") ;
                    break ;     
                case cvD16 : man.dtsize = cvD32 ;
                    con_printf("D32]\n") ;
                    break ;     
                case cvD32 : man.dtsize = cvD64 ;
                    con_printf("D64]\n") ;
                    break ;     
                case cvD64 : man.dtsize = cvD8 ;
                    con_printf("D8] \n") ;
                    break ;     

                case cvD16_swapped :
                case cvD32_swapped :
                case cvD64_swapped :
                default :
                    break;
                }

                break ;

            case  '4' : gotoxy(X_AM,Y_AM) ;

                switch(man.am)
                {
                case cvA16_U      : man.am = cvA24_U_DATA ;
                    con_printf("A24]\n") ;
                    break ;     
                case cvA24_U_DATA : man.am = cvA32_U_DATA ;
                    con_printf("A32]\n") ;
                    break ;     
                case cvA32_U_DATA : man.am = cvCR_CSR ;
                    con_printf("CR/SCR]\n") ;
                    break ;     
                case cvCR_CSR     : man.am = cvA16_U ;
                    con_printf("A16]   \n") ;
                    break ;     
                }

                break ;

            case  '5' : con_printf(" Please enter Block Transfer Size : ") ;

                if (con_scanf("%"SCNu32,&value) != EOF)
                    man.blts = value ;
                con_printf_xy(X_BLTSIZE,Y_BLTSIZE,"%"PRIu32"]        \n",man.blts) ;

                clear_line(Y_COMM) ;
                                        
                break ;

            case  '6' : gotoxy(X_AUTOINC,Y_AUTOINC) ;

                man.autoinc ^= 1 ;
                if (man.autoinc)
                    con_printf("ON] \n") ;
                else
                    con_printf("OFF]\n") ;

                break ;

            case  '7' : con_printf(" Please enter Number of Cycles : ") ;
                                        
                if (con_scanf("%"SCNu32,&value) != EOF)
                    man.ncyc = (ushort)value ;
                gotoxy(X_NCYCLES,Y_NCYCLES) ;
                if (man.ncyc)
                    con_printf("%"PRIu32"]       \n",man.ncyc) ;
                else
                    con_printf("Infinite]\n",man.ncyc) ;

                clear_line(Y_COMM) ;

                break ;

            case  '8' : ViewReadBltData(&man);
                dis_main_menu = 1;      // Display Main Menu
                break ;

            case  'Q' : free(man.buff);         // Release the memory buffer for BLT 
                return ;
                                        
            default   : break ;
            }

        }
        while (!dis_main_menu) ;
        
    }                                                                           // End 'for(;;)' 
}
示例#6
0
void ViewReadBltData(man_par_t *man)
{
    ushort              i,j,line, page=0, gotow, dtsize ;
    uint32_t    ndata;
    uint32_t    *d32;
    ushort              *d16;
    uchar               *d8;
    char                key = 0;
    char                msg[80];
    FILE                *fsave;

    d32 = man->buff ;
    d16 = (ushort *)man->buff ;
    d8  = (uchar *)man->buff ;

    dtsize = man->dtsize ;

    while( key != 'Q' )                         // Loop. Exit if 'Q' is pressed  
    {
        ndata = man->blts / dtsize;

        clrscr() ;
        con_printf("\n VIEW BUFFER\n\n") ; 
        con_printf(" Num.    Addr     Hex         Dec \n\n");
    
        // Write a page 
        for( line=0, i=page * 16; (line<16) && (i<ndata); line++, i++)
        {
            if( dtsize == cvD32 || dtsize == cvD64)             
                con_printf(" %05u   %04X     %08X    %-10d \n",i,i*4,d32[i],d32[i]);
                          
            if( dtsize == cvD16) 
                con_printf(" %05u   %04X     %04X        %-6d \n",i,i*2,d16[i],d16[i]);

            if( dtsize == cvD8)                             
                con_printf(" %05u   %04X     %02X          %-4d \n",i,i,d8[i],d8[i]);                   
        }
        
        // Print the line menu
        con_printf("\n[Q] Quit  [D] Data_size  [S] Save  [G] Goto");
        if( page != 0 )
            con_printf("  [P] Previous");
        if( i != ndata )
            con_printf("  [N] Next");

        key=toupper(con_getch()) ;              // Wait for command

        clear_line(22);

        switch (key)
        {
        case 'N' :      if(i<ndata)             // Next page 
                page++;
            break ;
        case 'P' :      if(page>0)              // Previous page 
                page--;
            break ;     
        case 'D' :      dtsize = dtsize * 2;    // Change data size (8,16,32) 
            if(dtsize > 4) 
                dtsize = 1;
            page = 0;
            break ;
        case 'G' :      con_printf("Insert data number (dec) : ") ; // Go to data 
            con_scanf("%d",(ushort *)&gotow) ;

            if(gotow>ndata)
            {
                clear_line(22) ;  
                con_printf(" Invalid data number ");
            }
            else
                page=gotow/16;
            break ;
     
        case 'S' :      clear_line(23) ;
            con_printf_xy(1,23," File Name : ") ; // Save buffer to file 
            if (con_scanf("%s",msg) == EOF)
                break ;
      
            if((fsave=fopen(msg,"w")) == NULL)
            {
                clear_line(23) ;
                con_printf_xy(1,23," Can't open file ");
            }
            else
            {
                for(j=0;j<ndata;j++)
                {
                    if( dtsize == cvD32 || dtsize == cvD64)  
                        fprintf(fsave,"%05u\t%08X\t%-10d\n",j,d32[j],d32[j]);
                    if( dtsize == cvD16) 
                        fprintf(fsave,"%05u\t%04X\t%-6d\n",j,d16[j],d16[j]);
                    if( dtsize == cvD8)  
                        fprintf(fsave,"%05u\t%02X\t%-4d\n",j,d8[j],d8[j]);
                }

                fclose(fsave);
            }
            break ;
        default  :  break ;
   
        }
    } 
}
示例#7
0
int con_toggle_box( int x, int y, const char *title, ToggleEntry* toggles, ConMenuInfo *menu_info  )
{
  ScrollPos scroll;
  int z;

  int w = -1;
  int h = -1;

  int maxlen = 0;
  int count  = 0;
  while( toggles[count].key != -1 )
    {
    int sl = strlen( toggles[count].name );
    if (sl > maxlen) maxlen = sl;
    count++;
    }
  maxlen += 6+3; // 6 for state string and 3 for " key " string in the front

  if (w == -1) w = maxlen;
  if (h == -1) h = count;

  z = strlen(title);
  if (w < z) w = z;
  if (h > count) h = count;
  if (h == 0) h = 1;

  // FIXME: those should be fixed!!!
  if (x + w > con_max_x()) w = con_max_x() - x - 1;
  if (y + h > con_max_y()-4) h = con_max_y() - y - 5;

  VString str;
  VString str1;
  VString hots = "";
  for(z = 0; z < count; z++)
    if (strncmp("--", toggles[z].name, 2))
      str_add_ch( hots, toggles[z].key );
    else
      str_add_ch( hots,' ' );
  con_xy(x,y);
  int ch = 0;

  str = "";
  str = title;
  str_pad( str,-w, menu_info->bo ? '-' : ' ' );
  if (str_len(str) > w) str_sleft(str,w);
  if (menu_info->bo)
    str = ".-" + str + "-.";
  else
    str = "  " + str + "  ";
  con_out(x,y,str,menu_info->ti);
  y++;

  scroll.wrap = 1;
  scroll.set_min_max( 0, count-1 );
  scroll.set_pagesize( h );
  scroll.go( 0 );

  while(1)
    {
    for( z = 0; z < scroll.pagesize(); z++ )
      {
      if (scroll.page() + z >= count)
        {
        str = " ~";
        str_pad( str, -(w+2), ' ');
        }
      else
        {
        int sep = (strncmp("--", toggles[scroll.page()+z].name, 2) == 0);
        if (sep)
          {
          str = "";
          str += toggles[scroll.page()+z].name;
          str_pad( str, -w, '-');
          str += "--";
          }
        else
          {
          str = " "; str_add_ch( str, toggles[scroll.page()+z].key ); str += " ";
          str += toggles[scroll.page()+z].name;
          str_pad( str, -(w-6), ' ');
          str1 = toggles[scroll.page()+z].states[*(toggles[scroll.page()+z].data)];
          str_pad( str1, 6, ' '); str1 += " ";
          str += " " + str1;
          }
        }
      if (menu_info->bo)
        str = "|" + str + "|";
      else
        str = " " + str + " ";
//      if (str.len() > w) StrSLeft(str,w);
//      str = " " + str + " ";
      con_out( x, y+z, str, ( scroll.page()+z != scroll.pos() ) ? menu_info->cn : menu_info->ch );
      }
    if (menu_info->bo)
      {
      str = "";
      str_pad( str, w+2, '-' );
      str = "`" + str + "'";
      con_out( x, y+scroll.pagesize(), str, menu_info->cn );
      }
    ch = con_getch();
    menu_info->ec = ch;

    if ( ch == KEY_UP    ) scroll.up();
    if ( ch == KEY_DOWN  ) scroll.down();
    if ( ch == KEY_NPAGE ) scroll.npage();
    if ( ch == KEY_PPAGE ) scroll.ppage();
    if ( ch == KEY_HOME  ) scroll.home();
    if ( ch == KEY_END   ) scroll.end();

    if ( ch < 0 || ch > 255 ) continue;
    if ( ch == 27 ) return 0;
    if ( ch == 13 /* && strncmp("--", toggles[scroll.pos].name, 2) */ ) return 1;
    z = ( ch == ' ' ) ? scroll.pos() : z = str_find( hots, ch );
    if (z > -1 && strncmp("--", toggles[z].name, 2) )
      {
      int state = *(toggles[z].data) + 1;
      if (toggles[z].states[state] == NULL) state = 0;
      *(toggles[z].data) = state;
      }
    }
  return -1;
}
示例#8
0
int con_menu_box( int x, int y, const char *title, VArray *va, int hotkeys, ConMenuInfo *menu_info  )
{
  ScrollPos scroll;
  int z;

  int w = -1;
  int h = -1;

  if (w == -1) w = va->max_len();
  if (h == -1) h = va->count();

  z = strlen(title);
  if (w < z) w = z;
  if (h > va->count()) h = va->count();
  if (h == 0) h = 1;

  // FIXME: those should be fixed!!!
  if (x + w > con_max_x()) w = con_max_x() - x - 4;
  if (y + h > con_max_y()-4) h = con_max_y() - y - 4;

  VString str;
  VString hots = "";
  if ( hotkeys > -1 )
    {
    for(z = 0; z < va->count(); z++)
      if (strncmp("--", va->get(z), 2))
        str_add_ch( hots, char(((const char*)(va->get(z)))[hotkeys]) );
      else
        str_add_ch( hots,' ' );
    str_up(hots);
    }
  con_xy(x,y);
  int ch = 0;

  str = " ";
  str += title;
  str += " ";
  str_pad( str,-(w), menu_info->bo ? '-' : ' ' );
  if (str_len(str) > w) str_sleft(str,w);
  if (menu_info->bo)
    str = ".-" + str + "-.";
  else
    str = "  " + str + "  ";
  con_out(x,y,str,menu_info->ti);
  y++;

  scroll.wrap = 1;
  scroll.set_min_max( 0, va->count()-1 );
  scroll.set_pagesize( h );
  scroll.go( 0 );

  while(1)
    {
    for( z = 0; z < scroll.pagesize(); z++ )
      {
      str = (scroll.page()+z >= va->count())? "~" : va->get(scroll.page()+z);

      if ( menu_info->hide_magic[0] )
        {
        int i = str_rfind( str, menu_info->hide_magic );
        if ( i != -1)
          str_sleft( str, i );
        }
 
      str_pad( str,-w , (strncmp("--", str, 2) == 0)?'-':' ');
      if (str_len(str) > w) 
        str = str_dot_reduce( str, w );
      if (menu_info->bo)
        str = "| " + str + " |";
      else
        str = "  " + str + "  ";
      con_out( x, y+z, str, ( scroll.page()+z != scroll.pos() ) ? menu_info->cn : menu_info->ch );
      }
    if (menu_info->bo)
      {
      str = "";
      str_pad( str, w+2, '-' );
      str = "`" + str + "'";
      con_out( x, y+scroll.pagesize(), str, menu_info->cn );
      }
    ch = con_getch();
    menu_info->ec = ch;

    if ( ch == KEY_UP    ) scroll.up();
    if ( ch == KEY_DOWN  ) scroll.down();
    if ( ch == KEY_NPAGE ) scroll.npage();
    if ( ch == KEY_PPAGE ) scroll.ppage();
    if ( ch == KEY_HOME  ) scroll.home();
    if ( ch == KEY_END   ) scroll.end();

    if ( ch < 0 || ch > 255 ) continue;
    if ( ch == 27 )
      {
      menu_info->ac = 0;
      return -1;
      }
    if ( ch == 13 )
      {
      if (strncmp("--", va->get(scroll.pos()), 2) != 0) // ako e "--" e separator
        {
        menu_info->ec = hots[scroll.pos()];
        menu_info->ac = -1;
        return scroll.pos();
        }
      }
    if ( menu_info->ac > -1 && ch == menu_info->ac )
      {
      if (strncmp("--", va->get(scroll.pos()), 2) != 0) // ako e "--" e separator
        {
        menu_info->ec = hots[scroll.pos()];
        menu_info->ac = -2;
        return scroll.pos();
        }
      }
    z = str_find( hots, toupper(ch) );
    if (z > -1)
      {
      menu_info->ec = hots[z];
      menu_info->ac = -1;
      return z;
      }
    }
  menu_info->ac = -1;
  return -1;
};
示例#9
0
文件: form_in.cpp 项目: bbonev/vslib
int TextInput( int x, int y, const char *prompt, int maxlen, int fieldlen, VString *strres, void (*handlekey)( int key, VString &s, int &pos ) )
{
  int res = 0;
  int insert = 1;
  VString str = *strres;
  VString tmp;
  int ch;

  ScrollPos scroll;
  scroll.set_min_max( 0, str_len( str ) );
  scroll.set_pagesize( fieldlen );
  scroll.go( str_len(str) );

  int show = 1;
  int firsthit = 1;
  int opage = -1;
  con_cshow();
  while(1)
    {
    if (opage != scroll.page()) show = 1;
    if (show)
      {
      str_copy( tmp, str, scroll.page(), scroll.pagesize() );
      str_pad( tmp, -scroll.pagesize() );
      tmp = " " + tmp + " ";
      if ( scroll.page() > 0 ) str_set_ch( tmp, 0, '<' );
      if ( scroll.page()+scroll.pagesize() < str_len(str) ) str_set_ch( tmp, str_len(tmp)-1, '>' );
      con_out(x, y, tmp, firsthit ? EditStrFH : EditStrBF );
      show = 0;
      opage = scroll.page();
      }
    con_xy( x + scroll.pos() - scroll.page() + 1 , y );
    ch = con_getch();
    if( ch >= 32 && ch <= 255 && ch != KEY_BACKSPACE && str_len(str) < maxlen - 1 )
      {
      if (firsthit)
        {
        str = "";
        scroll.go(0);
        firsthit = 0;
        }
        if (!insert) str_del( str, scroll.pos(), 1 );
        str_ins_ch( str, scroll.pos(), ch );
        scroll.set_min_max( 0, str_len( str ) );
        scroll.go( scroll.pos() );
        scroll.down();
      show = 1;
      };
    if (firsthit)
      {
      show = 1;
      firsthit = 0;
      }

    if( ch == 27 )
      {
      res = 0;
      break;
      } else
    if( ch == 13 )
      {
      *strres = str;
      res = 1;
      break;
      } else
    if( ch == KEY_CTRL_U )
      {
      scroll.go(0);
      str = "";
      show = 1;
      } else
    if( (ch == KEY_BACKSPACE || ch == 8 ) && (scroll.pos() > 0) )
      {
      scroll.up();
      str_del( str, scroll.pos(), 1 );
      show = 1;
      } else
    if ( ch == KEY_IC    ) insert = !insert; else
    if ( ch == KEY_LEFT  ) scroll.up(); else
    if ( ch == KEY_RIGHT ) scroll.down(); else
    /*
    if ( ch == KEY_PPAGE ) scroll.ppage(); else
    if ( ch == KEY_NPAGE ) scroll.npage(); else
    */
    if ( ch == KEY_HOME || ch == KEY_CTRL_A ) scroll.go(0); else
    if ( ch == KEY_END  || ch == KEY_CTRL_E ) scroll.go(str_len(str)); else
    if ( ( ch == KEY_DC || ch == KEY_CTRL_D ) && scroll.pos() < str_len(str) )
      {
      str_del( str, scroll.pos(), 1 );
      show = 1;
      } else
    if ( handlekey )
      {
      int npos = scroll.pos();
      handlekey( ch, str, npos );
      scroll.set_min_max( 0, str_len( str ) );
      scroll.go( scroll.pos() );
      if (scroll.pos() != npos) scroll.go( npos );
      show = 1;
      }

    scroll.set_min_max( 0, str_len( str ) );
    scroll.go( scroll.pos() );
    }
  con_chide();
  return res;
}
示例#10
0
文件: MainWrapp.c 项目: gsimi/rich-pd
static void commandList(void)
{
	unsigned short  nOfSys = 0, nOfCmd = 0, pageSys = 0, 
					i, j, page = 0, row, column;
	int				cmd;

	while( strcmp(function[nOfCmd].cmdName, "NOCOMMAND") )
		nOfCmd++;

	while( 1 )
	{
		clrscr();
		con_puts("       --- Demonstration of use of CAEN HV Wrapper Library --- ");
		gotoxy(1, 3);
		for(i=page*20;(i<(page*20+20))&&(strcmp(function[i].cmdName,"NOCOMMAND"));i++)
		{
			row = 3 + (i - page * 20)%10;
			column = ((i - page * 20) > 9 ? 30 : 1);
			gotoxy(column, row);
			con_printf("[%c] %s", alpha[i], function[i].cmdName);
		}

		for( j = pageSys*10; (j<pageSys*10+10)&&(System[j].ID!=-1); j++ )
		{
			row = 3+(j-pageSys*10)%10;
			gotoxy(60,row);
			con_printf("System[%d]: %d", j, System[j].Handle);
		}

		gotoxy(1, 14);
		con_printf("[r] Loop = %s",loop ? "Yes" : "No");

		gotoxy(1, 15);
		con_printf("[x] Exit \n\n");

		switch(cmd = tolower(con_getch()))
		{
			// Handle future next page command
			//	case "next page"
			//		if( nOfCmd > page*20 + 20 )
			//			page++;
			//		else
			//			page = 0;
			//       break;

			// Handle future next system command
			//  case "next system"
			//		while( System[nOfSys].ID != -1 )
            //			nOfSys++;
			//		if( nOfSys > pageSys*10+10 )
            //			pageSys++;
			//		else
            //			pageSys = 0;
			//        break;

	   case 'r':
	     loop = (loop ? 0 : 1);
	    break;

		case 'x':
			quitProgram();
			break;

	    default:
			if( cmd >= 'a' && cmd < 'a' + nOfCmd )
				(*function[cmd-'a'].pFun)();      
	        break;
      }
  }
}