File: execute_search_button_callback.C

package info (click to toggle)
peruser 4b33-10
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,944 kB
  • ctags: 1,064
  • sloc: cpp: 22,397; perl: 2,733; makefile: 345; sh: 335
file content (69 lines) | stat: -rw-r--r-- 1,760 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <gtk/gtk.h>

#include "npfile.h"
#include "npstringarray.h"
#include "npgroup.h"
#include "npnode.h"
#include "nptree.h"
#include "npcollections.h"

void execute_search_button_callback( GtkWidget *widget, gpointer data )
{
   NP_Collections *collections = ( NP_Collections *)data;

   if ( *collections->search_text == '\0' ||
        *collections->search_text == '\n' )
      return;
   
   gtk_object_set_data( GTK_OBJECT( collections->window ),
                        "regexp", collections->search_text );

   pack_button_callback( ( GtkWidget *)1, data );

   gtk_object_remove_data( GTK_OBJECT( collections->window ), "regexp" );

   int total = collections->search_results.get_total();
   if ( total < 0 )
   {
      collections->search_results.print_error();
      return;
   }

   gtk_clist_clear( GTK_CLIST( collections->search_clist ));

   char buffer[ 128 ];
   snprintf( buffer, sizeof buffer, "Matches: %d", total );
   gtk_label_set( GTK_LABEL( collections->search_label ), buffer );

   if ( !total )
      return;

   gtk_clist_freeze( GTK_CLIST( collections->search_clist ));

   for( int i = 0; i < total; ++i )
   {
      char *text[ 5 ];
      char *pointer = ( char *)collections->search_results[ i ];
      if ( pointer == NULL )
      {
         collections->search_results.print_error();
         break;
      }

      text[ 0 ] = strtok( pointer, ":" );
      text[ 1 ] = strtok( NULL, ":" );
      text[ 2 ] = strtok( NULL, ":" );
      text[ 3 ] = strtok( NULL, ":" );
      text[ 4 ] = strtok( NULL, "\n" );

      gtk_clist_append( GTK_CLIST( collections->search_clist ), text );
   }

   gtk_clist_thaw( GTK_CLIST( collections->search_clist ));

   return;
}