]> git.sesse.net Git - vlc/commitdiff
ncurses: factorize (no need to use a macro here).
authorRémi Duraffort <ivoire@videolan.org>
Fri, 24 Jul 2009 08:12:55 +0000 (10:12 +0200)
committerRémi Duraffort <ivoire@videolan.org>
Fri, 24 Jul 2009 08:12:55 +0000 (10:12 +0200)
modules/gui/ncurses.c

index 6f7b224d93383c803207da1495b202425d3aaf40..3a23b6ae13679ad66855d52c8b47d7f65787f61b 100644 (file)
@@ -549,18 +549,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
 {
     intf_sys_t *p_sys = p_intf->p_sys;
     vlc_value_t val;
-
-    #define ReturnTrue \
-    do { \
-    pl_Release( p_intf ); \
-    return 1; \
-    } while(0)
-
-    #define ReturnFalse \
-    do { \
-    pl_Release( p_intf ); \
-    return 0; \
-    } while(0)
+    int i_ret = 1;
 
     playlist_t *p_playlist = pl_Hold( p_intf );
 
@@ -577,17 +566,17 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
                 var_Get( p_playlist, "random", &val );
                 val.b_bool = !val.b_bool;
                 var_Set( p_playlist, "random", val );
-                ReturnTrue;
+                goto end;
             case 'l':
                 var_Get( p_playlist, "loop", &val );
                 val.b_bool = !val.b_bool;
                 var_Set( p_playlist, "loop", val );
-                ReturnTrue;
+                goto end;
             case 'R':
                 var_Get( p_playlist, "repeat", &val );
                 val.b_bool = !val.b_bool;
                 var_Set( p_playlist, "repeat", val );
-                ReturnTrue;
+                goto end;
 
             /* Playlist sort */
             case 'o':
@@ -595,13 +584,13 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
                                             PlaylistGetRoot( p_intf ),
                                             SORT_TITLE_NODES_FIRST, ORDER_NORMAL );
                 p_sys->b_need_update = true;
-                ReturnTrue;
+                goto end;
             case 'O':
                 playlist_RecursiveNodeSort( p_playlist,
                                             PlaylistGetRoot( p_intf ),
                                             SORT_TITLE_NODES_FIRST, ORDER_REVERSE );
                 p_sys->b_need_update = true;
-                ReturnTrue;
+                goto end;
 
             /* Playlist view */
             case 'v':
@@ -615,7 +604,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
                 }
                 //p_sys->b_need_update = true;
                 PlaylistRebuild( p_intf );
-                ReturnTrue;
+                goto end;
 
             /* Playlist navigation */
             case 'g':
@@ -721,7 +710,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
                 b_box_plidx_follow = true;
             PL_UNLOCK;
             p_sys->b_box_plidx_follow = b_box_plidx_follow;
-            ReturnTrue;
+            goto end;
         }
     }
     if( p_sys->i_box_type == BOX_BROWSE )
@@ -804,7 +793,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
         {
             if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
             if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
-            ReturnTrue;
+            goto end;
         }
     }
     else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO ||
@@ -815,33 +804,33 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
         {
             case KEY_HOME:
                 p_sys->i_box_start = 0;
-                ReturnTrue;
+                goto end;
 #ifdef __FreeBSD__
             case KEY_SELECT:
 #endif
             case KEY_END:
                 p_sys->i_box_start = p_sys->i_box_lines_total - 1;
-                ReturnTrue;
+                goto end;
             case KEY_UP:
                 if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
-                ReturnTrue;
+                goto end;
             case KEY_DOWN:
                 if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
                 {
                     p_sys->i_box_start++;
                 }
-                ReturnTrue;
+                goto end;
             case KEY_PPAGE:
                 p_sys->i_box_start -= p_sys->i_box_lines;
                 if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
-                ReturnTrue;
+                goto end;
             case KEY_NPAGE:
                 p_sys->i_box_start += p_sys->i_box_lines;
                 if( p_sys->i_box_start >= p_sys->i_box_lines_total )
                 {
                     p_sys->i_box_start = p_sys->i_box_lines_total - 1;
                 }
-                ReturnTrue;
+                goto end;
             default:
                 break;
         }
@@ -853,24 +842,24 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
             case KEY_HOME:
                 p_sys->f_slider = 0;
                 ManageSlider( p_intf );
-                ReturnTrue;
+                goto end;
 #ifdef __FreeBSD__
             case KEY_SELECT:
 #endif
             case KEY_END:
                 p_sys->f_slider = 99.9;
                 ManageSlider( p_intf );
-                ReturnTrue;
+                goto end;
             case KEY_UP:
                 p_sys->f_slider += 5.0;
                 if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
                 ManageSlider( p_intf );
-                ReturnTrue;
+                goto end;
             case KEY_DOWN:
                 p_sys->f_slider -= 5.0;
                 if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
                 ManageSlider( p_intf );
-                ReturnTrue;
+                goto end;
 
             default:
                 break;
@@ -884,7 +873,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
             case KEY_CLEAR:
             case 0x0c:      /* ^l */
                 clear();
-                ReturnTrue;
+                goto end;
             case KEY_ENTER:
             case '\r':
             case '\n':
@@ -897,7 +886,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
                     SearchPlaylist( p_intf, p_sys->psz_old_search );
                 }
                 p_sys->i_box_type = BOX_PLAYLIST;
-                ReturnTrue;
+                goto end;
             case 0x1b: /* ESC */
                 /* Alt+key combinations return 2 keys in the terminal keyboard:
                  * ESC, and the 2nd key.
@@ -914,10 +903,13 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
                  *
                  */
                 if( wgetch( p_sys->w ) != ERR )
-                    ReturnFalse;
+                {
+                    i_ret = 0;
+                    goto end;
+                }
                 p_sys->i_box_plidx = p_sys->i_before_search;
                 p_sys->i_box_type = BOX_PLAYLIST;
-                ReturnTrue;
+                goto end;
             case KEY_BACKSPACE:
             case 0x7f:
                 RemoveLastUTF8Entity( p_sys->psz_search_chain, i_chain_len );
@@ -949,7 +941,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
         free( p_sys->psz_old_search );
         p_sys->psz_old_search = NULL;
         SearchPlaylist( p_intf, p_sys->psz_search_chain );
-        ReturnTrue;
+        goto end;
     }
     else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
     {
@@ -960,7 +952,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
             case KEY_CLEAR:
             case 0x0c:          /* ^l */
                 clear();
-                ReturnTrue;
+                break;
             case KEY_ENTER:
             case '\r':
             case '\n':
@@ -985,12 +977,15 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
                     p_sys->b_box_plidx_follow = true;
                 }
                 p_sys->i_box_type = BOX_PLAYLIST;
-                ReturnTrue;
+                break;
             case 0x1b:  /* ESC */
                 if( wgetch( p_sys->w ) != ERR )
-                    ReturnFalse;
+                {
+                    i_ret = 0;
+                    break;
+                }
                 p_sys->i_box_type = BOX_PLAYLIST;
-                ReturnTrue;
+                break;
             case KEY_BACKSPACE:
             case 0x7f:
                 RemoveLastUTF8Entity( p_sys->psz_open_chain, i_chain_len );
@@ -1016,10 +1011,9 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
                     free( psz_utf8 );
                 }
 #endif
-                break;
             }
         }
-        ReturnTrue;
+        goto end;
     }
 
 
@@ -1028,12 +1022,16 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
     {
         case 0x1b:  /* ESC */
             if( wgetch( p_sys->w ) != ERR )
-                ReturnFalse;
+            {
+                i_ret = 0;
+                break;
+            }
         case 'q':
         case 'Q':
         case KEY_EXIT:
             libvlc_Quit( p_intf->p_libvlc );
-            ReturnFalse;
+            i_ret = 0;
+            break;
 
         /* Box switching */
         case 'i':
@@ -1042,49 +1040,49 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
             else
                 p_sys->i_box_type = BOX_INFO;
             p_sys->i_box_lines_total = 0;
-            ReturnTrue;
+            break;
         case 'm':
             if( p_sys->i_box_type == BOX_META )
                 p_sys->i_box_type = BOX_NONE;
             else
                 p_sys->i_box_type = BOX_META;
             p_sys->i_box_lines_total = 0;
-            ReturnTrue;
+            break;
         case 'L':
             if( p_sys->i_box_type == BOX_LOG )
                 p_sys->i_box_type = BOX_NONE;
             else
                 p_sys->i_box_type = BOX_LOG;
-            ReturnTrue;
+            break;
         case 'P':
             if( p_sys->i_box_type == BOX_PLAYLIST )
                 p_sys->i_box_type = BOX_NONE;
             else
                 p_sys->i_box_type = BOX_PLAYLIST;
-            ReturnTrue;
+            break;
         case 'B':
             if( p_sys->i_box_type == BOX_BROWSE )
                 p_sys->i_box_type = BOX_NONE;
             else
                 p_sys->i_box_type = BOX_BROWSE;
-            ReturnTrue;
+            break;
         case 'x':
             if( p_sys->i_box_type == BOX_OBJECTS )
                 p_sys->i_box_type = BOX_NONE;
             else
                 p_sys->i_box_type = BOX_OBJECTS;
-            ReturnTrue;
+            break;
         case 'S':
             if( p_sys->i_box_type == BOX_STATS )
                 p_sys->i_box_type = BOX_NONE;
             else
                 p_sys->i_box_type = BOX_STATS;
-            ReturnTrue;
+            break;
         case 'c':
             p_sys->b_color = !p_sys->b_color;
             if( p_sys->b_color && !p_sys->b_color_started )
                 start_color_and_pairs( p_intf );
-            ReturnTrue;
+            break;
         case 'h':
         case 'H':
             if( p_sys->i_box_type == BOX_HELP )
@@ -1092,40 +1090,42 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
             else
                 p_sys->i_box_type = BOX_HELP;
             p_sys->i_box_lines_total = 0;
-            ReturnTrue;
+            break;
         case '/':
             if( p_sys->i_box_type != BOX_SEARCH )
             {
-                if( p_sys->psz_search_chain == NULL )
-                    ReturnTrue;
-                p_sys->psz_search_chain[0] = '\0';
-                p_sys->b_box_plidx_follow = false;
-                p_sys->i_before_search = p_sys->i_box_plidx;
-                p_sys->i_box_type = BOX_SEARCH;
+                if( p_sys->psz_search_chain )
+                {
+                    p_sys->psz_search_chain[0] = '\0';
+                    p_sys->b_box_plidx_follow = false;
+                    p_sys->i_before_search = p_sys->i_box_plidx;
+                    p_sys->i_box_type = BOX_SEARCH;
+                }
             }
-            ReturnTrue;
+            break;
         case 'A': /* Open */
             if( p_sys->i_box_type != BOX_OPEN )
             {
-                if( p_sys->psz_open_chain == NULL )
-                    ReturnTrue;
-                p_sys->psz_open_chain[0] = '\0';
-                p_sys->i_box_type = BOX_OPEN;
+                if( p_sys->psz_open_chain )
+                {
+                    p_sys->psz_open_chain[0] = '\0';
+                    p_sys->i_box_type = BOX_OPEN;
+                }
             }
-            ReturnTrue;
+            break;
 
         /* Navigation */
         case KEY_RIGHT:
             p_sys->f_slider += 1.0;
             if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
             ManageSlider( p_intf );
-            ReturnTrue;
+            break;
 
         case KEY_LEFT:
             p_sys->f_slider -= 1.0;
             if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
             ManageSlider( p_intf );
-            ReturnTrue;
+            break;
 
         /* Common control */
         case 'f':
@@ -1149,60 +1149,61 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
                     var_Set( p_playlist, "fullscreen", val );
                 }
             }
-            ReturnFalse;
+            i_ret = 0;
+            break;
         }
 
         case ' ':
             PlayPause( p_intf );
-            ReturnTrue;
+            break;
 
         case 's':
             playlist_Stop( p_playlist );
-            ReturnTrue;
+            break;
 
         case 'e':
             Eject( p_intf );
-            ReturnTrue;
+            break;
 
         case '[':
             if( p_sys->p_input )
                 var_SetVoid( p_sys->p_input, "prev-title" );
-            ReturnTrue;
+            break;
 
         case ']':
             if( p_sys->p_input )
                 var_SetVoid( p_sys->p_input, "next-title" );
-            ReturnTrue;
+            break;
 
         case '<':
             if( p_sys->p_input )
                 var_SetVoid( p_sys->p_input, "prev-chapter" );
-            ReturnTrue;
+            break;
 
         case '>':
             if( p_sys->p_input )
                 var_SetVoid( p_sys->p_input, "next-chapter" );
-            ReturnTrue;
+            break;
 
         case 'p':
             playlist_Prev( p_playlist );
             clear();
-            ReturnTrue;
+            break;
 
         case 'n':
             playlist_Next( p_playlist );
             clear();
-            ReturnTrue;
+            break;
 
         case 'a':
             aout_VolumeUp( p_playlist, 1, NULL );
             clear();
-            ReturnTrue;
+            break;
 
         case 'z':
             aout_VolumeDown( p_playlist, 1, NULL );
             clear();
-            ReturnTrue;
+            break;
 
         /*
          * ^l should clear and redraw the screen
@@ -1210,13 +1211,15 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
         case KEY_CLEAR:
         case 0x0c:          /* ^l */
             clear();
-            ReturnTrue;
+            break;
 
         default:
-            ReturnFalse;
+            i_ret = 0;
     }
-#undef ReturnFalse
-#undef ReturnTrue
+
+end:
+    pl_Release( p_intf );
+    return i_ret;
 }
 
 static void ManageSlider( intf_thread_t *p_intf )