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

Linux Cross Reference
Tina6/tina-libs/tina/sys/sysGen_help.c

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

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/sys/sysGen_help.c,v $
 37  * Date    :  $Date: 2009/05/15 15:50:50 $
 38  * Version :  $Revision: 1.6 $
 39  * CVS Id  :  $Id: sysGen_help.c,v 1.6 2009/05/15 15:50:50 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42 */
 43 /**
 44  *  @file Tina's built in help facility for Tool level documentation.
 45  *  @brief A simple ascii file can be associated with parts of the Tina
 46  *  interface in order to provide rapid (though basic) information.
 47  *
 48  *
 49  *********
 50 */
 51 
 52 #include "sysGen_help.h"
 53 
 54 #if HAVE_CONFIG_H
 55   #include <config.h>
 56 #endif
 57 
 58 #include <stdio.h>
 59 #include <stdlib.h>
 60 #include <tina/sys/sysGen_string.h>
 61 #include <tina/sys/sysGen_format.h>
 62 
 63 
 64 #define TINA_HELPDIR "TINA_HELPDIR"
 65 #define HELP_DEFAULT "default"
 66 
 67 void print_help(void *help_win, char *help_file_name)
 68 {
 69 /**
 70  * @file Print help from a file <help_file_name> in <help_win>, searching
 71  * directories in this order: current directory, directory specified by
 72  * environment variable TINA_HELPDIR, home directory. (Re-reads file on
 73  * each button press to simplify adding help (instant gratification!).
 74  * (Usually output to Help tool's text subwindow.) 
 75 */
 76 
 77         char help_file_path[256];
 78         FILE *help_file;
 79 
 80         /* Ensure help file name is not NULL or "" */
 81         if (!help_file_name || !*help_file_name)
 82         {
 83 #ifdef DEBUG
 84                 format_sw(help_win, "NULL help filename passed,"
 85                                                         "using \"default\" instead\n");
 86 #endif                                                                                                  /* DEBUG */
 87                 help_file_name = HELP_DEFAULT;
 88         }
 89 
 90         /* Try to find in current directory */
 91         string_append(help_file_path, help_file_name, ".hlp", NULL);
 92         help_file = fopen(help_file_path, "r");
 93 
 94         /* Try to find in help directory (from env var */
 95         if (!help_file)
 96         {
 97                 char *helpdir = getenv("TINA_HELPDIR");
 98 
 99 #ifdef DEBUG
100                 format_sw(help_win, "Can't open %s\n", help_file_path);
101 #endif                                                                                                  /* DEBUG */
102 
103                 if (helpdir)
104                 {
105                         string_append(help_file_path, helpdir, "/", help_file_name, ".hlp",
106                                                                                 NULL);
107                         help_file = fopen(help_file_path, "r");
108                 }
109         }
110 
111         /* Try to find in home directory */
112         if (!help_file)
113         {
114                 char *home = getenv("HOME");
115 #ifdef DEBUG
116                 format_sw(help_win, "Can't open %s\n", help_file_path);
117 #endif                                                                                                  /* DEBUG */
118                 if (home)
119                 {
120                         string_append(help_file_path, home, "/", help_file_name, ".hlp",
121                                                                                 NULL);
122                         help_file = fopen(help_file_path, "r");
123                 }
124         }
125 
126         /* Print contents of help file (if found) */
127         if (help_file)
128         {
129                 char helpline[256];
130                 while (fgets(helpline, 256, help_file))
131                 {
132                         format_sw(help_win, "%s", helpline);
133                 }
134                 fclose(help_file);
135         } else
136         {
137 #ifdef DEBUG
138                 format_sw(help_win, "Can't open %s\n", help_file_path);
139 #endif                                                                                                  /* DEBUG */
140                 format_sw(help_win, "No help file found (has TINA_HELPDIR been set?).\n\n");
141         }
142 }
143 

~ [ 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.