[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.1, Thu Jan 4 12:29:32 2001 UTC (23 years, 5 months ago) by takayama
Branch: MAIN

A new online help generation system for kan/k0.

/* $OpenXM: OpenXM/src/k097/Doc/genhelp.k,v 1.1 2001/01/04 12:29:32 takayama Exp $ */

/* Todo
  
  * Helplist should be sorted.
  * Ex. should be removed.
  * Args and references should be given in the Helplist.

*/

def foo() {
  local n,i,key,s,aaa,ref;

  Println("DO NOT EDIT THIS FILE. ");
  Println("It is AUTHOMATICALLY GENERATED.");
  sm1(" (cat standard-0.texi) system ");
  n = Length(Helplist);
  Println("/*&C ");
  Println("@menu ");
  for (i=0; i<n; i++) {
    Print("* "); Print(Helplist[i,0]); Println("::");
  }
  Println("@end menu"); Ln();
  Println(" */"); Ln();

  n = Length(Helplist);
  for (i=0; i<n; i++) {
     Print("//&C @c "); Println(i);
     key = Helplist[i,0];
     s = Helplist[i,1];
     if (Length(Helplist[i]) > 2) {
       aaa = Helplist[i,2];
       ref = Helplist[i,3];
     }else{
       aaa = " (?) ";
       ref = "Not yet written.";
     }
     printItem(key,s,aaa,ref);
  }

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

}

def printItem(key,s,aaa,ref) {
  local desc,example;
  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);  Println(aaa);
  Print(":: "); Println(desc[0]);
  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(" */ ");
  }
  Println("/*&C ");
  Println("@table @t");
  Println("@item Reference");
  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;
  leftCurryBrace = 123;
  rightCurryBrace = 125;
  at = 64;
  s = StringToAsciiArray(s);
  n = Length(s);
  ans = [ ];
  for (i=0; i<n; i++) {
    if (s[i] == leftCurryBrace) {
      ans = Join(ans,[64,leftCurryBrace]);
    }else if (s[i] == rightCurryBrace) {
      ans = Join(ans,[64,rightCurryBrace]);
    }else{
      ans = Append(ans,s[i]);
    }
  }
  return(AddString(Map(ans,"AsciiToString")));
}

foo();