3 * NATIVE NAME: ReactOS manual browser
4 * AUTHOR : Semyon Novikov (tappak)
5 * PROJECT : ReactOS Operating System
6 * DESCRIPTION: manual file browser (Use Linux man file syntax)
13 * 2. Non ENVIRONMENT manpath varrible
14 * 3. At the end of man page must be ./" tag!
30 int OpenF(char* name
);
33 int AnalyzeArgv(char *);
40 char manpath
[MAXLINE
]="c:\\man\\";
46 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE
),cl
);
53 char *manpath_local
=(char*)malloc(sizeof(char)*MAXLINE
);
55 strcpy(manpath_local
, manpath
); //save mandir value
57 if((manfile
=fopen((strcat(manpath_local
,name
)),"r"))!=NULL
)
65 strcpy(manpath_local
, manpath
);
84 puts("usage: man [command]");
85 puts("see \"man man\" for details");
89 AnalyzeArgv(char *argument
)
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
);
97 strcpy(filename
,argument
); //save argument value
99 for(element
=0; element
< 5;element
++)
100 if(!strcmp(keys
[element
],argument
))
111 while(OpenF(strcat(filename
,sections
[element
])) && (element
<9))
113 strcpy(filename
,argument
);
117 if(element
>8) printf("No manual for %s\n",argument
);
122 void sh_outp(char *cur_string
)
127 for(symbol
=3;putchar(cur_string
[symbol
]); symbol
++);
130 void th_outp(char *cur_string
, char *THtag
)
138 for(symbol
=3;putchar(THtag
[symbol
]); symbol
++);
143 void text_outp(char *cur_string
)
148 if(cur_string
[0]=='.')
149 while(cur_string
[symbol
]!=' ')
152 if(symbol
) TagFlag
=1;
154 for(;cur_string
[symbol
]!='\n'; symbol
++)
155 putchar(cur_string
[symbol
]);
162 char *cur_string
=(char*)malloc(sizeof(char)*MAXLINE
);
163 char *THtag
=(char*)malloc(sizeof(char)*MAXLINE
);
168 while(fgets(cur_string
,MAXLINE
,manfile
))
170 /* TAGs processing */
171 if((cur_string
[0]=='.')&&(cur_string
[1]=='S')&&
172 (cur_string
[2]=='H')) // .SH tag
179 if((cur_string
[0]=='.')&&(cur_string
[1]=='I')&&
180 (cur_string
[2]==' ')) // .I tag
183 text_outp(cur_string
);
187 if((cur_string
[0]=='.')&&(cur_string
[1]=='/')&&
188 (cur_string
[2]=='\"')); // ./" tag (comment)
191 if((cur_string
[0]=='.')&&(cur_string
[1]=='T')&&
192 (cur_string
[2]=='H')) // .TH tag
194 strcpy(THtag
,cur_string
);
197 if((cur_string
[0]=='.')&&(cur_string
[1]=='B')&&
198 (cur_string
[2]==' ')) // .B tag
201 text_outp(cur_string
);
205 if((cur_string
[0]=='.')&&(cur_string
[1]=='N')&&
206 (cur_string
[2]=='L'))
212 else text_outp(cur_string
); // print plane text
213 th_outp(cur_string
, THtag
);
214 /* END of TAGs processing */
220 main(int argc
, char *argv
[])
225 case 1: Usage(); break;
226 case 2: AnalyzeArgv(argv
[1]);break;
227 default: Usage();break;
230 if(OpenFlag
)CloseF();