ReactOS  0.4.14-dev-998-g623dd26
man.c File Reference
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <wincon.h>
Include dependency graph for man.c:

Go to the source code of this file.

Macros

#define MAXLINE   256
 
#define BOLD   7|9
 
#define ITALIC   3|9
 
#define NORMAL   7|0
 

Functions

void SetCl (WORD cl)
 
int OpenF (char *name)
 
int CloseF (void)
 
void Usage (void)
 
int AnalyzeArgv (char *)
 
int AnalyzeFile ()
 
void sh_outp (char *cur_string)
 
void th_outp (char *cur_string, char *THtag)
 
void text_outp (char *cur_string)
 
int main (int argc, char *argv[])
 

Variables

FILEmanfile
 
char OpenFlag =0
 
char manpath [MAXLINE] ="c:\\man\\"
 

Macro Definition Documentation

◆ BOLD

#define BOLD   7|9

Definition at line 24 of file man.c.

◆ ITALIC

#define ITALIC   3|9

Definition at line 25 of file man.c.

◆ MAXLINE

#define MAXLINE   256

Definition at line 23 of file man.c.

◆ NORMAL

#define NORMAL   7|0

Definition at line 26 of file man.c.

Function Documentation

◆ AnalyzeArgv()

int AnalyzeArgv ( char argument)

Definition at line 89 of file man.c.

90 {
91  int element;
92  char HelpFlag=0;
93  char *keys[]={"--help","/h","/?","-h"};
94  char *sections[]={".1",".2",".3",".4",".5",".6",".7",".8",".9"};
95  char *filename=(char*)malloc(sizeof(char)*MAXLINE);
96 
97  strcpy(filename,argument); //save argument value
98 
99  for(element=0;element<_countof(keys);element++)
100  {
101  if(!strcmp(keys[element],argument))
102  {
103  Usage();
104  HelpFlag=1;
105  }
106  }
107 
108  element = 0;
109 
110  if(!HelpFlag)
111  {
112 
113  if(OpenF(filename))
114  {
116  {
117  strcpy(filename,argument);
118  element++;
119  }
120 
121  if(element>=_countof(sections)) printf("No manual for %s\n",argument);
122  }
123 
124  }
125 
126  return element;
127 }
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
#define _countof(array)
Definition: fontsub.cpp:30
const char * filename
Definition: ioapi.h:135
struct section sections[2]
Definition: diskspace.c:792
#define MAXLINE
Definition: man.c:23
int OpenF(char *name)
Definition: man.c:50
void Usage(void)
Definition: man.c:82
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define malloc
Definition: debug_ros.c:4
#define printf
Definition: config.h:203

Referenced by main().

◆ AnalyzeFile()

int AnalyzeFile ( )

Definition at line 165 of file man.c.

166 {
167  char *cur_string=(char*)malloc(sizeof(char)*MAXLINE);
168  char *THtag=(char*)malloc(sizeof(char)*MAXLINE);
169 
170 
171 
172 
173  while(fgets(cur_string,MAXLINE,manfile))
174 
175 /* TAGs processing */
176  if((cur_string[0]=='.')&&(cur_string[1]=='S')&&
177  (cur_string[2]=='H')) // .SH tag
178  {
179  SetCl(BOLD);
180  sh_outp(cur_string);
181  SetCl(NORMAL);
182  }
183  else
184  if((cur_string[0]=='.')&&(cur_string[1]=='I')&&
185  (cur_string[2]==' ')) // .I tag
186  {
187  SetCl(ITALIC);
188  text_outp(cur_string);
189  SetCl(NORMAL);
190  }
191  else
192  if((cur_string[0]=='.')&&(cur_string[1]=='/')&&
193  (cur_string[2]=='\"')); // ./" tag (comment)
194 
195  else
196  if((cur_string[0]=='.')&&(cur_string[1]=='T')&&
197  (cur_string[2]=='H')) // .TH tag
198  {
199  strcpy(THtag,cur_string);
200  }
201  else
202  if((cur_string[0]=='.')&&(cur_string[1]=='B')&&
203  (cur_string[2]==' ')) // .B tag
204  {
205  SetCl(BOLD);
206  text_outp(cur_string);
207  SetCl(NORMAL);
208  }
209  else
210  if((cur_string[0]=='.')&&(cur_string[1]=='N')&&
211  (cur_string[2]=='L'))
212  {
213  putchar('\n');
214  putchar(' ');
215  }
216 
217  else
218  {
219  text_outp(cur_string); // print plane text
220  }
221  th_outp(cur_string, THtag);
222  /* END of TAGs processing */
223 
224  free(cur_string);
225  free(THtag);
226  return 0;
227 }
void th_outp(char *cur_string, char *THtag)
Definition: man.c:137
#define free
Definition: debug_ros.c:5
FILE * manfile
Definition: man.c:38
int putchar(int c)
Definition: crtsupp.c:12
#define MAXLINE
Definition: man.c:23
void SetCl(WORD cl)
Definition: man.c:44
void sh_outp(char *cur_string)
Definition: man.c:129
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
#define NORMAL
Definition: man.c:26
#define ITALIC
Definition: man.c:25
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define malloc
Definition: debug_ros.c:4
void text_outp(char *cur_string)
Definition: man.c:150
#define BOLD
Definition: man.c:24

Referenced by OpenF().

◆ CloseF()

int CloseF ( void  )

Definition at line 70 of file man.c.

71 {
72  int retval=0;
73 
74  if(fclose(manfile))
75  OpenFlag=0;
76  else retval=-1;
77 
78  return retval;
79 }
FILE * manfile
Definition: man.c:38
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
char OpenFlag
Definition: man.c:39

Referenced by main().

◆ main()

int main ( int argc  ,
char argv[] 
)

hosttype.c Copyright (C) 2002 by Brian Palmer brian.nosp@m.p@sg.nosp@m.inet..nosp@m.com

Definition at line 231 of file man.c.

232 {
233 
234  switch(argc)
235  {
236  case 1: Usage(); break;
237  case 2: AnalyzeArgv(argv[1]);break;
238  default: Usage();break;
239  }
240 
241  if(OpenFlag)CloseF();
242  SetCl(NORMAL);
243  return 0;
244 }
static int argc
Definition: ServiceArgs.c:12
int CloseF(void)
Definition: man.c:70
#define argv
Definition: mplay32.c:18
int AnalyzeArgv(char *)
Definition: man.c:89
void SetCl(WORD cl)
Definition: man.c:44
void Usage(void)
Definition: man.c:82
#define NORMAL
Definition: man.c:26
char OpenFlag
Definition: man.c:39

◆ OpenF()

int OpenF ( char name)

Definition at line 50 of file man.c.

51 {
52  int retval=0;
53  char *manpath_local=(char*)malloc(sizeof(char)*MAXLINE);
54 
55  strcpy(manpath_local, manpath); //save mandir value
56 
57  if((manfile=fopen((strcat(manpath_local,name)),"r"))!=NULL)
58  {
59  OpenFlag=1;
60  AnalyzeFile();
61  }
62  else
63  retval=-1;
64 
65  free(manpath_local);
66  return retval;
67 }
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
#define free
Definition: debug_ros.c:5
char manpath[MAXLINE]
Definition: man.c:40
FILE * manfile
Definition: man.c:38
#define MAXLINE
Definition: man.c:23
smooth NULL
Definition: ftsmooth.c:416
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
int AnalyzeFile()
Definition: man.c:165
Definition: name.c:38
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define malloc
Definition: debug_ros.c:4
char OpenFlag
Definition: man.c:39

Referenced by AnalyzeArgv().

◆ SetCl()

void SetCl ( WORD  cl)

Definition at line 44 of file man.c.

45 {
47 }
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:174
BOOL WINAPI SetConsoleTextAttribute(IN HANDLE hConsoleOutput, IN WORD wAttributes)
Definition: console.c:643
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265

Referenced by AnalyzeFile(), main(), and th_outp().

◆ sh_outp()

void sh_outp ( char cur_string)

Definition at line 129 of file man.c.

130 {
131  int symbol;
132  putchar('\n');
133  putchar('\n');
134  for(symbol=3;putchar(cur_string[symbol]); symbol++);
135 }
int putchar(int c)
Definition: crtsupp.c:12

Referenced by AnalyzeFile().

◆ text_outp()

void text_outp ( char cur_string)

Definition at line 150 of file man.c.

151 {
152  int symbol=0;
153 
154  if(cur_string[0]=='.')
155  while(cur_string[symbol]!=' ')
156  symbol++;
157 
158  for(;cur_string[symbol]!='\n'; symbol++)
159  putchar(cur_string[symbol]);
160 
161  putchar(' ');
162 }
int putchar(int c)
Definition: crtsupp.c:12

Referenced by AnalyzeFile().

◆ th_outp()

void th_outp ( char cur_string,
char THtag 
)

Definition at line 137 of file man.c.

138 {
139  int symbol;
140  putchar('\n');
141  putchar('\n');
142  putchar('\t');
143  putchar('\t');
144  SetCl(ITALIC);
145  for(symbol=3;putchar(THtag[symbol]); symbol++);
146  putchar('\n');
147  SetCl(NORMAL);
148 }
int putchar(int c)
Definition: crtsupp.c:12
void SetCl(WORD cl)
Definition: man.c:44
#define NORMAL
Definition: man.c:26
#define ITALIC
Definition: man.c:25

Referenced by AnalyzeFile().

◆ Usage()

void Usage ( void  )

Definition at line 82 of file man.c.

83 {
84  puts("usage: man [command]");
85  puts("see \"man man\" for details");
86 }
int puts(const char *string)
Definition: crtsupp.c:23

Referenced by AnalyzeArgv(), and main().

Variable Documentation

◆ manfile

FILE* manfile

Definition at line 38 of file man.c.

Referenced by AnalyzeFile(), CloseF(), and OpenF().

◆ manpath

char manpath[MAXLINE] ="c:\\man\\"

Definition at line 40 of file man.c.

Referenced by OpenF().

◆ OpenFlag

char OpenFlag =0

Definition at line 39 of file man.c.

Referenced by CloseF(), main(), and OpenF().