~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/sys/gen/help.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #include <stdarg.h>
  2 #include <stdio.h>
  3 #include <stdlib.h>
  4 
  5 #define TINA_HELPDIR "TINA_HELPDIR"
  6 #define HELP_DEFAULT "default"
  7 
  8 /* Print help from a file <help_file_name> in <help_win>, searching
  9  * directories in this order: current directory, directory specified by
 10  * environment variable TINA_HELPDIR, home directory. (Re-reads file on
 11  * each button press to simplify adding help (instant gratification!).
 12  * (Usually output to Help tool's text subwindow.) */
 13 void print_help(void *help_win, char *help_file_name)
 14 {
 15     char help_file_path[256];
 16     FILE *help_file;
 17     char *string_append();
 18     void format_sw();
 19 
 20     /* Ensure help file name is not NULL or "" */
 21     if (!help_file_name || !*help_file_name)
 22     {
 23 #ifdef DEBUG
 24         format_sw(help_win, "NULL help filename passed,"
 25                   "using \"default\" instead\n");
 26 #endif                          /* DEBUG */
 27         help_file_name = HELP_DEFAULT;
 28     }
 29 
 30     /* Try to find in current directory */
 31     string_append(help_file_path, help_file_name, ".hlp", NULL);
 32     help_file = fopen(help_file_path, "r");
 33 
 34     /* Try to find in help directory (from env var */
 35     if (!help_file)
 36     {
 37         char *helpdir = getenv(TINA_HELPDIR);
 38 
 39 #ifdef DEBUG
 40         format_sw(help_win, "Can't open %s\n", help_file_path);
 41 #endif                          /* DEBUG */
 42 
 43         if (helpdir)
 44         {
 45             string_append(help_file_path, helpdir, "/", help_file_name, ".hlp", NULL);
 46             help_file = fopen(help_file_path, "r");
 47         }
 48     }
 49 
 50     /* Try to find in home directory */
 51     if (!help_file)
 52     {
 53         char *home = getenv("HOME");
 54 #ifdef DEBUG
 55         format_sw(help_win, "Can't open %s\n", help_file_path);
 56 #endif                          /* DEBUG */
 57         if (home)
 58         {
 59             string_append(help_file_path, home, "/", help_file_name, ".hlp", NULL);
 60             help_file = fopen(help_file_path, "r");
 61         }
 62     }
 63 
 64     /* Print contents of help file (if found) */
 65     if (help_file)
 66     {
 67         char helpline[256];
 68         while (fgets(helpline, 256, help_file))
 69         {
 70             format_sw(help_win, "%s", helpline);
 71         }
 72         fclose(help_file);
 73     }
 74     else
 75     {
 76 #ifdef DEBUG
 77         format_sw(help_win, "Can't open %s\n", help_file_path);
 78 #endif                          /* DEBUG */
 79         format_sw(help_win, "No help available yet on this.\n");
 80     }
 81 }
 82 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.