mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 08:25:03 +00:00
New version of man by Semyon Novikov. Manual pages should be located in c:\\man for now, later it will be enhanced to environment variable.
I have changed the makefile so it is compatible with ReactOS, and compiles just by running 'make'. There are some warnings also, but I didn't have time to fix them. svn path=/trunk/; revision=9490
This commit is contained in:
parent
7a98b74d8b
commit
0f711c642b
3 changed files with 259 additions and 0 deletions
23
rosapps/sysutils/man/makefile
Normal file
23
rosapps/sysutils/man/makefile
Normal file
|
@ -0,0 +1,23 @@
|
|||
#
|
||||
|
||||
PATH_TO_TOP = ../../../reactos
|
||||
|
||||
TARGET_NORC = yes
|
||||
|
||||
TARGET_TYPE = program
|
||||
|
||||
TARGET_APPTYPE = console
|
||||
|
||||
TARGET_NAME = man
|
||||
|
||||
TARGET_SDKLIBS = ntdll.a
|
||||
|
||||
TARGET_CFLAGS = -D__USE_W32API -Wall
|
||||
|
||||
TARGET_OBJECTS = $(TARGET_NAME).o
|
||||
|
||||
include $(PATH_TO_TOP)/rules.mak
|
||||
|
||||
include $(TOOLS_PATH)/helper.mk
|
||||
|
||||
# EOF
|
229
rosapps/sysutils/man/man.c
Normal file
229
rosapps/sysutils/man/man.c
Normal file
|
@ -0,0 +1,229 @@
|
|||
/*
|
||||
* FILE : man.c
|
||||
* NATIVE NAME: ReactOS manual browser
|
||||
* AUTHOR : Semyon Novikov (tappak)
|
||||
* PROJECT : ReactOS Operating System
|
||||
* DESCRIPTION: manual file browser (Use Linux man file syntax)
|
||||
* DATE : 2004-03-29
|
||||
* LICENSE : GPL
|
||||
*/
|
||||
|
||||
/* Known issues.
|
||||
* 1. Scroll screen
|
||||
* 2. Non ENVIRONMENT manpath varrible
|
||||
* 3. At the end of man page must be ./" tag!
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <windows.h>
|
||||
#include <wincon.h>
|
||||
|
||||
#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();
|
||||
/*=================*/
|
||||
|
||||
/*====[Globals]====*/
|
||||
FILE* manfile;
|
||||
char OpenFlag=0;
|
||||
char manpath[MAXLINE]="c:\\man\\";
|
||||
/*=================*/
|
||||
|
||||
void
|
||||
SetCl(WORD cl)
|
||||
{
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),cl);
|
||||
}
|
||||
|
||||
int
|
||||
OpenF(char* name)
|
||||
{
|
||||
int retval=0;
|
||||
char *manpath_local=(char*)malloc(sizeof(char)*MAXLINE);
|
||||
|
||||
strcpy(manpath_local, manpath); //save mandir value
|
||||
|
||||
if((manfile=fopen((strcat(manpath_local,name)),"r"))!=NULL)
|
||||
{
|
||||
OpenFlag=1;
|
||||
AnalyzeFile();
|
||||
}
|
||||
else
|
||||
retval=-1;
|
||||
|
||||
strcpy(manpath_local, manpath);
|
||||
return retval;
|
||||
}
|
||||
|
||||
int
|
||||
CloseF()
|
||||
{
|
||||
int retval=0;
|
||||
|
||||
if(fclose(manfile))
|
||||
OpenFlag=0;
|
||||
else retval=-1;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
Usage()
|
||||
{
|
||||
puts("usage: man [command]");
|
||||
puts("see \"man man\" for details");
|
||||
}
|
||||
|
||||
int
|
||||
AnalyzeArgv(char *argument)
|
||||
{
|
||||
char element=0;
|
||||
char HelpFlag=0;
|
||||
char *keys[]={"--help","/h","/?","-h"};
|
||||
char *sections[]={".1",".2",".3",".4",".5",".6",".7",".8",".9"};
|
||||
char *filename=(char*)malloc(sizeof(char)*MAXLINE);
|
||||
|
||||
strcpy(filename,argument); //save argument value
|
||||
|
||||
for(element=0; element < 5;element++)
|
||||
if(!strcmp(keys[element],argument))
|
||||
{
|
||||
Usage();
|
||||
HelpFlag=1;
|
||||
}
|
||||
|
||||
element = 0;
|
||||
|
||||
if(!HelpFlag)
|
||||
|
||||
if(OpenF(filename))
|
||||
while(OpenF(strcat(filename,sections[element])) && (element<9))
|
||||
{
|
||||
strcpy(filename,argument);
|
||||
element++;
|
||||
}
|
||||
|
||||
if(element>8) printf("No manual for %s\n",argument);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
int
|
||||
AnalyzeFile()
|
||||
{
|
||||
char *cur_string=(char*)malloc(sizeof(char)*MAXLINE);
|
||||
char symbol=0;
|
||||
char *THtag=(char*)malloc(sizeof(char)*MAXLINE);
|
||||
|
||||
|
||||
void sh_outp(void)
|
||||
{
|
||||
putchar('\n');
|
||||
putchar('\n');
|
||||
for(symbol=3;putchar(cur_string[symbol]); symbol++);
|
||||
}
|
||||
|
||||
void th_outp(void)
|
||||
{
|
||||
putchar('\n');
|
||||
putchar('\n');
|
||||
putchar('\t');
|
||||
putchar('\t');
|
||||
SetCl(ITALIC);
|
||||
for(symbol=3;putchar(THtag[symbol]); symbol++);
|
||||
putchar('\n');
|
||||
SetCl(NORMAL);
|
||||
}
|
||||
|
||||
void text_outp(void)
|
||||
{
|
||||
char TagFlag=0;
|
||||
symbol=0;
|
||||
|
||||
if(cur_string[0]=='.')
|
||||
while(cur_string[symbol]!=' ')
|
||||
symbol++;
|
||||
|
||||
if(symbol) TagFlag=1;
|
||||
|
||||
for(symbol;cur_string[symbol]!='\n'; symbol++)
|
||||
putchar(cur_string[symbol]);
|
||||
putchar(' ');
|
||||
}
|
||||
|
||||
while(fgets(cur_string,MAXLINE,manfile))
|
||||
|
||||
/* TAGs processing */
|
||||
if((cur_string[0]=='.')&&(cur_string[1]=='S')&&
|
||||
(cur_string[2]=='H')) // .SH tag
|
||||
{
|
||||
SetCl(BOLD);
|
||||
sh_outp();
|
||||
SetCl(NORMAL);
|
||||
}
|
||||
else
|
||||
if((cur_string[0]=='.')&&(cur_string[1]=='I')&&
|
||||
(cur_string[2]==' ')) // .I tag
|
||||
{
|
||||
SetCl(ITALIC);
|
||||
text_outp();
|
||||
SetCl(NORMAL);
|
||||
}
|
||||
else
|
||||
if((cur_string[0]=='.')&&(cur_string[1]=='/')&&
|
||||
(cur_string[2]=='\"')); // ./" tag (comment)
|
||||
|
||||
else
|
||||
if((cur_string[0]=='.')&&(cur_string[1]=='T')&&
|
||||
(cur_string[2]=='H')) // .TH tag
|
||||
{
|
||||
strcpy(THtag,cur_string);
|
||||
}
|
||||
else
|
||||
if((cur_string[0]=='.')&&(cur_string[1]=='B')&&
|
||||
(cur_string[2]==' ')) // .B tag
|
||||
{
|
||||
SetCl(BOLD);
|
||||
text_outp();
|
||||
SetCl(NORMAL);
|
||||
}
|
||||
else
|
||||
if((cur_string[0]=='.')&&(cur_string[1]=='N')&&
|
||||
(cur_string[2]=='L'))
|
||||
{
|
||||
putchar('\n');
|
||||
putchar(' ');
|
||||
}
|
||||
|
||||
else text_outp(); // print plane text
|
||||
th_outp();
|
||||
/* END of TAGs processing */
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
switch(argc)
|
||||
{
|
||||
case 1: Usage(); break;
|
||||
case 2: AnalyzeArgv(argv[1]);break;
|
||||
default: Usage();break;
|
||||
}
|
||||
|
||||
if(OpenFlag)CloseF();
|
||||
SetCl(NORMAL);
|
||||
}
|
||||
|
7
rosapps/sysutils/man/used_tags.txt
Normal file
7
rosapps/sysutils/man/used_tags.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
.B bold
|
||||
.I italic
|
||||
.SH section (BOLD string without /n)
|
||||
.TH at the end (page comment)
|
||||
.NL
|
||||
.\" comment
|
||||
|
Loading…
Reference in a new issue