~wattazoum/albert/albert-mod

« back to all changes in this revision

Viewing changes to Help.c

  • Committer: Oumar Aziz OUATTARA (alias wattazoum)
  • Date: 2008-09-04 08:56:22 UTC
  • Revision ID: oumar_aziz_ouattara_alias_wattazoum-20080904085622-lepfwv8src1d4t0u
Initial import 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************/
 
2
/***  FILE :     Help.c                                             ***/
 
3
/***  AUTHOR:    Trent Whiteley                                     ***/
 
4
/***  MODIFIED:                                                     ***/
 
5
/***                                                                ***/
 
6
/***  PUBLIC ROUTINES:                                              ***/
 
7
/***    int Help();                                                 ***/
 
8
/***  PRIVATE ROUTINES:                                             ***/
 
9
/***    char * getHelp();                                           ***/
 
10
/***    void displayHelp();                                         ***/
 
11
/***  MODULE DESCRIPTION:                                           ***/
 
12
/***    This module contains routines used to handle the help       ***/
 
13
/***    system for albert.                                          ***/
 
14
/**********************************************************************/
 
15
 
 
16
#include <stdio.h>
 
17
#include <string.h>
 
18
#include <curses.h>
 
19
#include "Help.h"
 
20
 
 
21
int initHelp()
 
22
{
 
23
  initscr();                            /* initialize LINES and COLS */
 
24
  helpLines = LINES;
 
25
  helpCols = COLS;
 
26
  clear();                              /* clear the buffer */
 
27
  refresh();                            /* display the buffer */
 
28
  endwin();
 
29
}
 
30
 
 
31
int Help(topic)
 
32
char topic[];
 
33
{
 
34
  char str[80], *helpPtr, *test;
 
35
 
 
36
  char * getHelp();
 
37
  void displayHelp();
 
38
  void scrollScreen();
 
39
 
 
40
  scrollScreen();
 
41
  str[0] = '\0';
 
42
  if(!strlen(topic)){
 
43
    strcpy(str, "H");                   /* if no topic, display menu */
 
44
  }
 
45
  else{
 
46
    strcpy(str, topic);
 
47
  }
 
48
  while(strlen(str)){
 
49
    helpPtr = getHelp(str);
 
50
    if(helpPtr){
 
51
      displayHelp(helpPtr, helpLines, helpCols);
 
52
    }
 
53
    else{
 
54
      printf("No help is available for %s\n", str);
 
55
    }
 
56
    printf(" Type a letter for help, or carriage return to\n return\
 
57
        to the Albert session.\n\n\nHELP--> ");
 
58
    fflush(stdout);
 
59
    test = fgets(str, 80, stdin);
 
60
    str[strlen(str)-1] = '\0';
 
61
  }
 
62
  return(TRUE);
 
63
}
 
64
 
 
65
 
 
66
 
 
67
 
 
68
char * getHelp(helpRqst)
 
69
char *helpRqst;
 
70
{
 
71
  int i;
 
72
 
 
73
  for(i = 0; i < NUM_COMMANDS; ++i){
 
74
    if(!strncmp(helpRqst, Help_lines[i].help_topic, strlen(helpRqst))){
 
75
      return(Help_lines[i].help_text);
 
76
    }
 
77
  }
 
78
  return(NULL);
 
79
}
 
80
 
 
81
 
 
82
 
 
83
 
 
84
void displayHelp(helpPtr, rows, cols)
 
85
char *helpPtr;
 
86
int rows;
 
87
int cols;
 
88
{
 
89
  char line[500 + 1], *blank, *pos = helpPtr;
 
90
  int i, j, done, blankNdx;
 
91
 
 
92
  for(j = 0; *pos; ++j){
 
93
    for(i = 0, done = FALSE, blankNdx = 0; i < cols && *pos && !done; ++i,
 
94
++pos){
 
95
      if(*pos == ' ' || *pos == '\t'){
 
96
        blank = pos;            /* set blank to point to most current white space */
 
97
        blankNdx = i;           /* save the index to the last white space */
 
98
      }
 
99
      else if(*pos == '\n'){
 
100
        done = TRUE;
 
101
      }
 
102
      line[i] = *pos;
 
103
    }
 
104
    if(*(pos-1) == '\n'){       /* substitute EOL for CRLF */
 
105
      line[i-1] = '\0';
 
106
    }
 
107
    else if(blankNdx != 0){     /* set EOL at last white space encountered */
 
108
      line[blankNdx] = '\0';
 
109
      pos = blank;
 
110
    }
 
111
    else{                       /* if no white space encountered, break up the word */
 
112
      line[cols + 1] = '\0';
 
113
    }
 
114
    printf("%s\n", line);       /* write the line */
 
115
    if(j >= rows-2){
 
116
      j += 3;                   /* increment the row counter */
 
117
      printf("\nHit Return to continue-->");    /* print more message at
 
118
bottom left of screen */
 
119
      fflush(stdout);
 
120
      getchar();
 
121
      printf("\n");
 
122
      j = 0;                    /* reset the line number */
 
123
    }
 
124
  }
 
125
}
 
126
 
 
127
 
 
128
void more(lines)
 
129
int *lines;
 
130
{
 
131
  if(*lines >= helpLines-2){
 
132
    *lines = 0;
 
133
    printf("\nHit Return to continue-->");    /* print more message at
 
134
bottom left of screen */
 
135
    fflush(stdout);
 
136
    getchar();
 
137
    printf("\n");
 
138
  }
 
139
}
 
140
 
 
141
 
 
142
 
 
143
void scrollScreen()
 
144
{
 
145
  int i;
 
146
 
 
147
  for(i = 0; i < helpLines; ++i){
 
148
    printf("\n");
 
149
  }
 
150
}
 
151
 
 
152