Ethereal-dev: Re: [Ethereal-dev] help dir needs a Makefile.am

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Mon, 1 Dec 2003 17:08:02 -0800

On Nov 24, 2003, at 1:15 PM, Ulf Lamping wrote:

I'm still having problems, checking in the (already finished) changes of gtk/help_dlg.c, as still no one finds the time to write a Makefile.am in the new help dir.

As I'm not able to write such (I have no knowledge of the automake things), I will check in the generated .h files to the .txt files, so the Unix generation process will not be broken by the changes in gtk/help_dlg.c.

Unfortunately, that caused problems when building on Windows, as it tried to overwrite the ".h" files.

Getting rid of those files didn't help - the script used to build them used "tr", which I don't have installed as part of my Cygwin.

Perhaps it should just read the help files from a "help" subdirectory of the data file directory at run time? That gets rid of the second Windows build problem I had *and* eliminates the need to generate ".h" files on UNIX (or Windows), and also allows help contents to be updated without recompiling Ethereal.

See the attached patch to "help_dlg.c". (It should be fixed to handle open errors and I/O errors, and should probably also try to handle "lines" (for which read paragraphs) of arbitrary size (read into the buffer with "fgets()"; if the string doesn't end with a "\n", double the length of the buffer, and repeat the "fgets()", reading stuff in after the "\n" - repeat until done).
Index: gtk/help_dlg.c
===================================================================
RCS file: /cvsroot/ethereal/gtk/help_dlg.c,v
retrieving revision 1.38
diff -c -r1.38 gtk/help_dlg.c
*** gtk/help_dlg.c	27 Nov 2003 23:25:55 -0000	1.38
--- gtk/help_dlg.c	2 Dec 2003 01:05:07 -0000
***************
*** 31,36 ****
--- 31,37 ----
  #include <string.h>
  #include <stdio.h>
  
+ #include "epan/filesystem.h"
  #include "help_dlg.h"
  #include "prefs.h"
  #include "gtkglobals.h"
***************
*** 38,60 ****
  #include "compat_macros.h"
  #include "dlg_utils.h"
  
- 
- /* include texts from converted ascii ".txt" files */
- #include "../help/overview.h"
- #include "../help/capture_filters.h"
- #include "../help/display_filters.h"
- #include "../help/well_known.h"
- #include "../help/faq.h"
- 
- 
  typedef enum {
    OVERVIEW_HELP,
    CFILTER_HELP,
    DFILTER_HELP,
    WELL_KNOWN_HELP,
!   FAQ_HELP
  } help_type_t;
  
  static void help_close_cb(GtkWidget *w, gpointer data);
  static void help_destroy_cb(GtkWidget *w, gpointer data);
  static void insert_text(GtkWidget *w, const char *buffer, int nchars);
--- 39,63 ----
  #include "compat_macros.h"
  #include "dlg_utils.h"
  
  typedef enum {
    OVERVIEW_HELP,
    CFILTER_HELP,
    DFILTER_HELP,
    WELL_KNOWN_HELP,
!   FAQ_HELP,
!   NUM_HELP_TYPES
  } help_type_t;
  
+ #define HELP_DIR	"help"
+ 
+ static const char *helpfile_names[NUM_HELP_TYPES] = {
+   HELP_DIR G_DIR_SEPARATOR_S "overview.txt",
+   HELP_DIR G_DIR_SEPARATOR_S "capture_filters.txt",
+   HELP_DIR G_DIR_SEPARATOR_S "display_filters.txt",
+   HELP_DIR G_DIR_SEPARATOR_S "well_known.txt",
+   HELP_DIR G_DIR_SEPARATOR_S "faq.txt"
+ };
+ 
  static void help_close_cb(GtkWidget *w, gpointer data);
  static void help_destroy_cb(GtkWidget *w, gpointer data);
  static void insert_text(GtkWidget *w, const char *buffer, int nchars);
***************
*** 227,280 ****
  #endif
  }
  
- 
  static void set_help_text(GtkWidget *w, help_type_t type)
  {
-   int i;
  #ifndef HAVE_LIBPCAP
    char *tmp;
  #endif
  
  
  #if GTK_MAJOR_VERSION < 2
    gtk_text_freeze(GTK_TEXT(w));
  #endif
  
-   switch(type) {
- 
-   case OVERVIEW_HELP :
-     for (i=0; i<OVERVIEW_PARTS; i++) {
-       insert_text(w, overview_part[i], strlen(overview_part[i]));
-     }
-     break;
-   case CFILTER_HELP :
  #ifndef HAVE_LIBPCAP
      tmp = "NOTE: packet capturing is not enabled in this version!\n \n";
      insert_text(w, tmp, strlen(tmp));
  #endif
!     for (i=0; i<CAPTURE_FILTERS_PARTS; i++) {
!       insert_text(w, capture_filters_part[i], strlen(capture_filters_part[i]));
!     }
!     break;
!   case DFILTER_HELP :
!     for (i=0; i<DISPLAY_FILTERS_PARTS; i++) {
!       insert_text(w, display_filters_part[i], strlen(display_filters_part[i]));
      }
!     break;
!   case WELL_KNOWN_HELP :
!     for (i=0; i<WELL_KNOWN_PARTS; i++) {
!       insert_text(w, well_known_part[i], strlen(well_known_part[i]));
!     }
!     break;
!   case FAQ_HELP :
!     for (i=0; i<FAQ_PARTS; i++) {
!       insert_text(w, faq_part[i], strlen(faq_part[i]));
!     }
!     break;
!   default :
!     g_assert_not_reached();
!     break;
!   } /* switch(type) */
  #if GTK_MAJOR_VERSION < 2
    gtk_text_thaw(GTK_TEXT(w));
  #endif
--- 230,267 ----
  #endif
  }
  
  static void set_help_text(GtkWidget *w, help_type_t type)
  {
  #ifndef HAVE_LIBPCAP
    char *tmp;
  #endif
+   char *help_file_path;
+   FILE *help_file;
+   char line[4096+1];	/* XXX - size? */
  
+   g_assert(type < NUM_HELP_TYPES);
  
  #if GTK_MAJOR_VERSION < 2
    gtk_text_freeze(GTK_TEXT(w));
  #endif
  
  #ifndef HAVE_LIBPCAP
+   if (type == CFILTER_HELP) {
      tmp = "NOTE: packet capturing is not enabled in this version!\n \n";
      insert_text(w, tmp, strlen(tmp));
+   } else
  #endif
!   {
!     help_file_path = get_datafile_path(helpfile_names[type]);
!     help_file = fopen(help_file_path, "r");
!     if (help_file != NULL) {
!       /* XXX - report open errors, and check for I/O errors */
!       while (fgets(line, sizeof line, help_file) != NULL)
!         insert_text(w, line, strlen(line));
!       fclose(help_file);
      }
!     g_free(help_file_path);
!   }
  #if GTK_MAJOR_VERSION < 2
    gtk_text_thaw(GTK_TEXT(w));
  #endif