New version of man by Semyon Novikov. Manual pages should be located in c:\\man for...
authorAleksey Bragin <aleksey@reactos.org>
Tue, 25 May 2004 18:49:04 +0000 (18:49 +0000)
committerAleksey Bragin <aleksey@reactos.org>
Tue, 25 May 2004 18:49:04 +0000 (18:49 +0000)
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

rosapps/sysutils/man/makefile [new file with mode: 0644]
rosapps/sysutils/man/man.c [new file with mode: 0644]
rosapps/sysutils/man/used_tags.txt [new file with mode: 0644]

diff --git a/rosapps/sysutils/man/makefile b/rosapps/sysutils/man/makefile
new file mode 100644 (file)
index 0000000..db1f877
--- /dev/null
@@ -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
diff --git a/rosapps/sysutils/man/man.c b/rosapps/sysutils/man/man.c
new file mode 100644 (file)
index 0000000..8c192a0
--- /dev/null
@@ -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);
+}
+
diff --git a/rosapps/sysutils/man/used_tags.txt b/rosapps/sysutils/man/used_tags.txt
new file mode 100644 (file)
index 0000000..79aa27c
--- /dev/null
@@ -0,0 +1,7 @@
+.B bold
+.I italic
+.SH section (BOLD string without /n)
+.TH at the end (page comment)
+.NL
+.\" comment
+