ReactOS  0.4.15-dev-1070-ge1a01de
man.c File Reference
#include <stdlib.h>
#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 [MAX_PATH]
 

Macro Definition Documentation

◆ BOLD

#define BOLD   7|9

Definition at line 25 of file man.c.

◆ ITALIC

#define ITALIC   3|9

Definition at line 26 of file man.c.

◆ MAXLINE

#define MAXLINE   256

Definition at line 24 of file man.c.

◆ NORMAL

#define NORMAL   7|0

Definition at line 27 of file man.c.

Function Documentation

◆ AnalyzeArgv()

int AnalyzeArgv ( char argument)

Definition at line 103 of file man.c.

104 {
105  int element;
106  char HelpFlag=0;
107  char *keys[]={"--help","/h","/?","-h"};
108  char *sections[]={".1",".2",".3",".4",".5",".6",".7",".8",".9"};
109  char *filename=(char*)malloc(sizeof(char)*MAXLINE);
110 
111  strcpy(filename,argument); //save argument value
112 
113  for(element=0;element<_countof(keys);element++)
114  {
115  if(!strcmp(keys[element],argument))
116  {
117  Usage();
118  HelpFlag=1;
119  }
120  }
121 
122  element = 0;
123 
124  if(!HelpFlag)
125  {
126 
127  if(OpenF(filename))
128  {
130  {
131  strcpy(filename,argument);
132  element++;
133  }
134 
135  if(element>=_countof(sections)) printf("No manual for %s\n",argument);
136  }
137 
138  }
139 
140  return element;
141 }
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
const char * filename
Definition: ioapi.h:135
struct section sections[2]
Definition: diskspace.c:792
#define MAXLINE
Definition: man.c:24
#define _countof(array)
Definition: sndvol32.h:68
int OpenF(char *name)
Definition: man.c:51
void Usage(void)
Definition: man.c:96
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 179 of file man.c.

180 {
181  char *cur_string=(char*)malloc(sizeof(char)*MAXLINE);
182  char *THtag=(char*)malloc(sizeof(char)*MAXLINE);
183 
184 
185 
186 
187  while(fgets(cur_string,MAXLINE,manfile))
188 
189 /* TAGs processing */
190  if((cur_string[0]=='.')&&(cur_string[1]=='S')&&
191  (cur_string[2]=='H')) // .SH tag
192  {
193  SetCl(BOLD);
194  sh_outp(cur_string);
195  SetCl(NORMAL);
196  }
197  else
198  if((cur_string[0]=='.')&&(cur_string[1]=='I')&&
199  (cur_string[2]==' ')) // .I tag
200  {
201  SetCl(ITALIC);
202  text_outp(cur_string);
203  SetCl(NORMAL);
204  }
205  else
206  if((cur_string[0]=='.')&&(cur_string[1]=='/')&&
207  (cur_string[2]=='\"')); // ./" tag (comment)
208 
209  else
210  if((cur_string[0]=='.')&&(cur_string[1]=='T')&&
211  (cur_string[2]=='H')) // .TH tag
212  {
213  strcpy(THtag,cur_string);
214  }
215  else
216  if((cur_string[0]=='.')&&(cur_string[1]=='B')&&
217  (cur_string[2]==' ')) // .B tag
218  {
219  SetCl(BOLD);
220  text_outp(cur_string);
221  SetCl(NORMAL);
222  }
223  else
224  if((cur_string[0]=='.')&&(cur_string[1]=='N')&&
225  (cur_string[2]=='L'))
226  {
227  putchar('\n');
228  putchar(' ');
229  }
230 
231  else
232  {
233  text_outp(cur_string); // print plane text
234  }
235  th_outp(cur_string, THtag);
236  /* END of TAGs processing */
237 
238  free(cur_string);
239  free(THtag);
240  return 0;
241 }
void th_outp(char *cur_string, char *THtag)
Definition: man.c:151
#define free
Definition: debug_ros.c:5
FILE * manfile
Definition: man.c:39
int putchar(int c)
Definition: crtsupp.c:12
#define MAXLINE
Definition: man.c:24
void SetCl(WORD cl)
Definition: man.c:45
void sh_outp(char *cur_string)
Definition: man.c:143
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
#define NORMAL
Definition: man.c:27
#define ITALIC
Definition: man.c:26
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:164
#define BOLD
Definition: man.c:25

Referenced by OpenF().

◆ CloseF()

int CloseF ( void  )

Definition at line 84 of file man.c.

85 {
86  int retval=0;
87 
88  if(fclose(manfile))
89  OpenFlag=0;
90  else retval=-1;
91 
92  return retval;
93 }
FILE * manfile
Definition: man.c:39
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
char OpenFlag
Definition: man.c:40

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 245 of file man.c.

246 {
247 
248  switch(argc)
249  {
250  case 1: Usage(); break;
251  case 2: AnalyzeArgv(argv[1]);break;
252  default: Usage();break;
253  }
254 
255  if(OpenFlag)CloseF();
256  SetCl(NORMAL);
257  return 0;
258 }
static int argc
Definition: ServiceArgs.c:12
int CloseF(void)
Definition: man.c:84
#define argv
Definition: mplay32.c:18
int AnalyzeArgv(char *)
Definition: man.c:103
void SetCl(WORD cl)
Definition: man.c:45
void Usage(void)
Definition: man.c:96
#define NORMAL
Definition: man.c:27
char OpenFlag
Definition: man.c:40

◆ OpenF()

int OpenF ( char name)

Definition at line 51 of file man.c.

52 {
53  int ret = 0;
54  char *cp;
55 
56  /* C:\man\\... */
57  cp = getenv("SystemDrive");
58  if (cp && *cp)
59  {
60  strcpy(manpath, cp);
61  strcat(manpath, "\\man\\");
62  }
63  else
64  {
65  strcpy(manpath, "C:\\man\\");
66  }
68 
69  manfile = fopen(manpath, "r");
70  if (manfile != NULL)
71  {
72  OpenFlag = 1;
73  AnalyzeFile();
74  }
75  else
76  {
77  ret = -1;
78  }
79 
80  return ret;
81 }
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
char manpath[MAX_PATH]
Definition: man.c:41
FILE * manfile
Definition: man.c:39
smooth NULL
Definition: ftsmooth.c:416
int ret
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
int AnalyzeFile()
Definition: man.c:179
POINT cp
Definition: magnifier.c:59
Definition: name.c:38
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
char OpenFlag
Definition: man.c:40

Referenced by AnalyzeArgv().

◆ SetCl()

void SetCl ( WORD  cl)

Definition at line 45 of file man.c.

46 {
48 }
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:200
BOOL WINAPI SetConsoleTextAttribute(IN HANDLE hConsoleOutput, IN WORD wAttributes)
Definition: console.c:669
#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 143 of file man.c.

144 {
145  int symbol;
146  putchar('\n');
147  putchar('\n');
148  for(symbol=3;putchar(cur_string[symbol]); symbol++);
149 }
int putchar(int c)
Definition: crtsupp.c:12

Referenced by AnalyzeFile().

◆ text_outp()

void text_outp ( char cur_string)

Definition at line 164 of file man.c.

165 {
166  int symbol=0;
167 
168  if(cur_string[0]=='.')
169  while(cur_string[symbol]!=' ')
170  symbol++;
171 
172  for(;cur_string[symbol]!='\n'; symbol++)
173  putchar(cur_string[symbol]);
174 
175  putchar(' ');
176 }
int putchar(int c)
Definition: crtsupp.c:12

Referenced by AnalyzeFile().

◆ th_outp()

void th_outp ( char cur_string,
char THtag 
)

Definition at line 151 of file man.c.

152 {
153  int symbol;
154  putchar('\n');
155  putchar('\n');
156  putchar('\t');
157  putchar('\t');
158  SetCl(ITALIC);
159  for(symbol=3;putchar(THtag[symbol]); symbol++);
160  putchar('\n');
161  SetCl(NORMAL);
162 }
int putchar(int c)
Definition: crtsupp.c:12
void SetCl(WORD cl)
Definition: man.c:45
#define NORMAL
Definition: man.c:27
#define ITALIC
Definition: man.c:26

Referenced by AnalyzeFile().

◆ Usage()

void Usage ( void  )

Definition at line 96 of file man.c.

97 {
98  puts("usage: man [command]");
99  puts("see \"man man\" for details");
100 }
int puts(const char *string)
Definition: crtsupp.c:23

Referenced by AnalyzeArgv(), and main().

Variable Documentation

◆ manfile

FILE* manfile

Definition at line 39 of file man.c.

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

◆ manpath

char manpath[MAX_PATH]

Definition at line 41 of file man.c.

Referenced by OpenF().

◆ OpenFlag

char OpenFlag =0

Definition at line 40 of file man.c.

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