syslinux-3.08-2 sources from FC4
[bootcd.git] / syslinux / menu / libmenu / help.c
1 /* -*- c -*- ------------------------------------------------------------- *
2  *   
3  *   Copyright 2004-2005 Murali Krishnan Ganapathy - All Rights Reserved
4  *
5  *   This program is free software; you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8  *   Boston MA 02111-1307, USA; either version 2 of the License, or
9  *   (at your option) any later version; incorporated herein by reference.
10  *
11  * ----------------------------------------------------------------------- */
12
13 #include "help.h"
14 #include <stdio.h>
15 #include "string.h"
16
17 char helpbasedir[HELPDIRLEN]; // name of help directory limited to HELPDIRLEN
18
19 void showhelp(const char *filename)
20 {
21    char nc,nr;
22    FILE *f;
23    char line[512]; // Max length of a line
24
25    nc = getnumcols();
26    nr = getnumrows();
27    cls();
28    drawbox(0,0,nr,nc-1,HELPPAGE,0x07,HELPBOX);
29
30    drawhorizline(2,0,nc-1,HELPPAGE,0x07,HELPBOX,0); // dumb==0
31    if (filename == NULL) { // print file contents
32      gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE);
33      cswprint("Help system not initialized",0x07,HELP_LEFT_MARGIN);
34      return;
35    }
36    
37    f = fopen(filename,"r");
38    if (!f) { // No such file
39       sprintf(line, "File %s not found",filename);
40       gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE);
41       cswprint(line,0x07,HELP_LEFT_MARGIN);
42       return;
43    }
44
45    // Now we have a file just print it.
46    fgets(line,sizeof line,f); // Get first line (TITLE)
47    gotoxy(1,(nc-strlen(line))/2,HELPPAGE);
48    csprint(line,0x07);
49
50    gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE);
51    while ( fgets(line, sizeof line, f) ) cswprint(line,0x07,HELP_LEFT_MARGIN);
52    fclose(f);
53 }
54
55 void runhelpsystem(unsigned int helpid)
56 {
57    char dp;
58    char scan;
59    char filename[HELPDIRLEN+16];
60
61    dp = getdisppage();
62    if (dp != HELPPAGE) setdisppage(HELPPAGE);
63    if (helpbasedir[0] != 0) {
64       sprintf(filename,"%s/hlp%05d.txt",helpbasedir,helpid);
65       showhelp(filename);
66    }
67    else showhelp (NULL);
68    while (1) {
69      inputc(&scan);
70      if (scan == ESCAPE) break;
71    }
72    if (dp != HELPPAGE) setdisppage(dp);
73 }
74
75 void init_help(const char *helpdir)
76 {
77    if (helpdir != NULL)
78       strcpy(helpbasedir,helpdir);
79    else helpbasedir[0] = 0;
80 }
81
82 void close_help(void)
83 {
84 }