[BACK]Return to genhelp.k CVS log [TXT][DIR] Up to [local] / OpenXM / src / k097 / Doc

File: [local] / OpenXM / src / k097 / Doc / genhelp.k (download)

Revision 1.2, Mon Jan 8 05:26:50 2001 UTC (23 years, 4 months ago) by takayama
Branch: MAIN
CVS Tags: R_1_3_1-2, RELEASE_1_3_1_13b, RELEASE_1_2_3_12, RELEASE_1_2_3, RELEASE_1_2_2_KNOPPIX_b, RELEASE_1_2_2_KNOPPIX, RELEASE_1_2_2, RELEASE_1_2_1, KNOPPIX_2006, HEAD, DEB_REL_1_2_3-9
Changes since 1.1: +108 -33 lines

* Cleaned unnecessary files and functions.
* Completed the new help system. Type in make in the directory
  OpenXM/src/k097/Doc

/* $OpenXM: OpenXM/src/k097/Doc/genhelp.k,v 1.2 2001/01/08 05:26:50 takayama Exp $ */

/* Todo
  
  * Example should be rewrited to Ex.
  * Args and references should be given in the Helplist.
    See slib.k for the format of Helplist.
    [ , , null, null,"short description"] No arg and no ( ), no reference.
    [ , , ["a","b"],["Load_sm1"],"short description"]
    [ , , [ ], null,"short description"]  No arg, no reference.

*/

/* It is for category == null */
def foo() {
  local n,i,j,key,s,aaa,ref,keys,shortDesc,category;

  Println("DO NOT EDIT THIS FILE. ");
  Println("It is AUTHOMATICALLY GENERATED.");
  sm1(" (cat standard-0.texi) system ");
  n = Length(Helplist);
  keys = [" "];  /* This is a gate keeper for shell. */
  for (i=0; i< n; i++ ) {
    category = Helplist[i,0];
    if (Tag(category) == 0) {
      keys = Append(keys,Helplist[i,1,0]);
    }
  }
  keys = sm1(keys," shell ");
  n = Length(keys);

  Println("/*&C ");
  Println("@menu ");
  for (i=1; i<n; i++) {
    Print("* "); Print(keys[i]); Println("::");
  }
  Println("@end menu"); Ln();
  Println(" */"); Ln();

  for (j=1; j<n; j++) {
     Print("//&C @c "); Print(j); Print("/"); Println(n-1);
     Stderr.Print(j/(n-1)); Stderr.Print(" ");
     Stderr.Flush();
     i = 0;
     while (i < n-1) {
       if (keys[j] == Helplist[i,1,0]) {
         key = Helplist[i,1,0];
         s = Helplist[i,1,1];
         if (Length(Helplist[i,1]) > 2) {
           if (Length(Helplist[i,1]) != 5) {
              Stderr.Print(Helplist[i,1]);
              Stderr.Println(" has a bad format. ");
              Error("Stop by an error.");
           }
           aaa = Helplist[i,1,2];
           ref = Helplist[i,1,3];
           shortDesc = Helplist[i,1,4];
         }else{
           aaa = " (?) ";
           ref = "Not yet written.";
           shortDesc = " ";
         }
         break;
       }
       i++;
     }
     printItem(key,s,aaa,ref,shortDesc);
  }

  sm1(" (cat standard-1.texi) system ");

}

def printItem(key,s,aaa,ref,shortDesc) {
  local desc,example,i,shortDesc;
  desc = splitExample(s);

  Println("/*&en ");
  Print("@c  "); Print(" -------------  start of ");
  Print(key); Println(" --------------");
  Println("@menu");
  Print("* "); Print(key); Println("::");
  Println("@end menu");
  Print("@node "); Print(key); Println(",,, STANDARD function");
  Print("@subsection @code{"); Print(key); Println("}");
  Print("@findex "); Println(key);
  Println("@table @t");
  Print("@item "); Print(key);  
  if (Tag(aaa) != 0) {
    if (IsArray(aaa)) {
      Print(AsciiToString(LeftBracket)); /* ( */
      if (Length(aaa) >0) {
        for (i=0; i<Length(aaa)-1; i++) {
          Print("@var{"); Print(aaa[i]);
          Print("},");
        }
        Print("@var{"); Print(aaa[Length(aaa)-1]);
        Print("}");
      }
      Print(AsciiToString(RightBracket)); /* ) */
    }else{
      Println(aaa);
    }
  }else{
    Ln();
  }
  Print(":: "); Println(shortDesc);
  Println("@end table");
  Ln();
  Println(" */");

  Println("/*&en ");
  Println("@itemize @bullet");
  Print("@item "); Println(desc[0]);
  Println("@end itemize");
  Println(" */ ");

  if (Length(desc) == 2) {
    Println("/*&C ");
    Println("@example");
    Println(desc[1]);
    Println("@end example");
    Ln();
    Println(" */ ");
  }
  if (Tag(ref) != 0) {
    Println("/*&C ");
    Println("@table @t");
    Println("@item See also");
    if (IsArray(ref)) {
      if (Length(ref) > 0) {
        for (i=0; i<Length(ref)-1; i++) {
          Print("@code{");
          Print(ref[i]); Print("}"); Print(", ");
        }
        Print("@code{");
        Print(ref[Length(ref)-1]); Println("} ");
      }
    }else{
      Println(ref);
    }
    Println("@end table");
    Ln();
    Println(" */ ");
  }
}

def findKey(keys,s) {
  local n,m,i,j,r,k,ii,II;
  s = StringToAsciiArray(s);
  II = Length(keys);
  for (ii=0; ii<II; ii++) {
    k = StringToAsciiArray(keys[ii]);
    n = Length(k); m = Length(s);
    i = 0;
    while( i<m-n ) {
      r = true;
      for (j=0; j<n; j++) {
        if (k[j] != s[i+j]) {
           r = false;
        }
      }
      if (r == true) return(true);
      i++;
    }
  }
  return(false);
}

def splitExample(s) {
  local desc,example,n,i,inExample,newl,news,tt;
  if (IsArray(s) && Length(s) == 1) {
    s = s[0];
  }
  if (IsString(s)) {
    s = StringToAsciiArray(s);
    tt = [ ];
    news = [ ];
    n = Length(s);
    for (i=0; i<n; i++) {
      tt = Append(tt,s[i]);
      if (s[i] == 10) {
        if (Length(tt) > 0) {
          tt = Map(tt,"AsciiToString");
          tt = AddString(tt);
        }else{
          tt = AsciiToString(10);
        }
        news = Append(news,tt);
        tt = [ ];
      }
    }
    if (Length(tt) > 0) {
       tt = Map(tt,"AsciiToString");
       tt = AddString(tt);
       news = Append(news, tt);
    }
    s = news;
  }
  n = Length(s);
  inExample = false;
  newl = AsciiToString(10);
  desc = " "; example = " ";
  i = 0;
  while (i<n) {
    if (findKey(["Ex.","Example","example"],s[i])) {
      inExample = true;
    }
    s[i] = addEscape(s[i]);
    if (inExample) {
      example = AddString([example,newl,s[i]]);
    }else{
      desc = AddString([desc,newl,s[i]]);
    }
    i++;
  }
  if (Length(example) < 2) {
     return([desc]);
  }else{
    return([desc,example]);
  }
}

def addEscape(s) {
  local i,n,ans,leftCurryBrace,rightCurryBrace,at,leftIneq,rightIneq,
        ex0;
  leftCurryBrace = 123;
  rightCurryBrace = 125;
  leftIneq = 60; /* < */
  rightIneq = 62; /* > */
  at = 64; /* @ */
  ex0 = StringToAsciiArray("Ex.");
  s = StringToAsciiArray(s);
  n = Length(s);
  s = Join(s,[0,0,0,0]);
  ans = [ ];
  i = 0;
  while (i < n) {
    if (s[i] == leftCurryBrace) {
      ans = Join(ans,[64,leftCurryBrace]);
    }else if (s[i] == rightCurryBrace) {
      ans = Join(ans,[64,rightCurryBrace]);
    }else if (s[i] == leftIneq && s[i+1] == leftIneq) {
      ans = Join(ans,Append(StringToAsciiArray("@var"),leftCurryBrace));
      i++;
    }else if (s[i] == rightIneq && s[i+1] == rightIneq) {
      ans = Join(ans,[rightCurryBrace]);
      i++;
    }else if ([s[i],s[i+1],s[i+2]] == ex0) {
      i = i+2;
    }else {
      ans = Append(ans,s[i]);
    }
    i++;
  }
  return(AddString(Map(ans,"AsciiToString")));
}

foo();