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

Annotation of OpenXM/src/k097/Doc/genhelp.k, Revision 1.2

1.2     ! takayama    1: /* $OpenXM: OpenXM/src/k097/Doc/genhelp.k,v 1.1 2001/01/04 12:29:32 takayama Exp $ */
1.1       takayama    2:
                      3: /* Todo
                      4:
1.2     ! takayama    5:   * Example should be rewrited to Ex.
1.1       takayama    6:   * Args and references should be given in the Helplist.
1.2     ! takayama    7:     See slib.k for the format of Helplist.
        !             8:     [ , , null, null,"short description"] No arg and no ( ), no reference.
        !             9:     [ , , ["a","b"],["Load_sm1"],"short description"]
        !            10:     [ , , [ ], null,"short description"]  No arg, no reference.
1.1       takayama   11:
                     12: */
                     13:
1.2     ! takayama   14: /* It is for category == null */
1.1       takayama   15: def foo() {
1.2     ! takayama   16:   local n,i,j,key,s,aaa,ref,keys,shortDesc,category;
1.1       takayama   17:
                     18:   Println("DO NOT EDIT THIS FILE. ");
                     19:   Println("It is AUTHOMATICALLY GENERATED.");
                     20:   sm1(" (cat standard-0.texi) system ");
                     21:   n = Length(Helplist);
1.2     ! takayama   22:   keys = [" "];  /* This is a gate keeper for shell. */
        !            23:   for (i=0; i< n; i++ ) {
        !            24:     category = Helplist[i,0];
        !            25:     if (Tag(category) == 0) {
        !            26:       keys = Append(keys,Helplist[i,1,0]);
        !            27:     }
        !            28:   }
        !            29:   keys = sm1(keys," shell ");
        !            30:   n = Length(keys);
        !            31:
1.1       takayama   32:   Println("/*&C ");
                     33:   Println("@menu ");
1.2     ! takayama   34:   for (i=1; i<n; i++) {
        !            35:     Print("* "); Print(keys[i]); Println("::");
1.1       takayama   36:   }
                     37:   Println("@end menu"); Ln();
                     38:   Println(" */"); Ln();
                     39:
1.2     ! takayama   40:   for (j=1; j<n; j++) {
        !            41:      Print("//&C @c "); Print(j); Print("/"); Println(n-1);
        !            42:      Stderr.Print(j/(n-1)); Stderr.Print(" ");
        !            43:      Stderr.Flush();
        !            44:      i = 0;
        !            45:      while (i < n-1) {
        !            46:        if (keys[j] == Helplist[i,1,0]) {
        !            47:          key = Helplist[i,1,0];
        !            48:          s = Helplist[i,1,1];
        !            49:          if (Length(Helplist[i,1]) > 2) {
        !            50:            if (Length(Helplist[i,1]) != 5) {
        !            51:               Stderr.Print(Helplist[i,1]);
        !            52:               Stderr.Println(" has a bad format. ");
        !            53:               Error("Stop by an error.");
        !            54:            }
        !            55:            aaa = Helplist[i,1,2];
        !            56:            ref = Helplist[i,1,3];
        !            57:            shortDesc = Helplist[i,1,4];
        !            58:          }else{
        !            59:            aaa = " (?) ";
        !            60:            ref = "Not yet written.";
        !            61:            shortDesc = " ";
        !            62:          }
        !            63:          break;
        !            64:        }
        !            65:        i++;
1.1       takayama   66:      }
1.2     ! takayama   67:      printItem(key,s,aaa,ref,shortDesc);
1.1       takayama   68:   }
                     69:
                     70:   sm1(" (cat standard-1.texi) system ");
                     71:
                     72: }
                     73:
1.2     ! takayama   74: def printItem(key,s,aaa,ref,shortDesc) {
        !            75:   local desc,example,i,shortDesc;
1.1       takayama   76:   desc = splitExample(s);
                     77:
                     78:   Println("/*&en ");
                     79:   Print("@c  "); Print(" -------------  start of ");
                     80:   Print(key); Println(" --------------");
                     81:   Println("@menu");
                     82:   Print("* "); Print(key); Println("::");
                     83:   Println("@end menu");
                     84:   Print("@node "); Print(key); Println(",,, STANDARD function");
                     85:   Print("@subsection @code{"); Print(key); Println("}");
                     86:   Print("@findex "); Println(key);
                     87:   Println("@table @t");
1.2     ! takayama   88:   Print("@item "); Print(key);
        !            89:   if (Tag(aaa) != 0) {
        !            90:     if (IsArray(aaa)) {
        !            91:       Print(AsciiToString(LeftBracket)); /* ( */
        !            92:       if (Length(aaa) >0) {
        !            93:         for (i=0; i<Length(aaa)-1; i++) {
        !            94:           Print("@var{"); Print(aaa[i]);
        !            95:           Print("},");
        !            96:         }
        !            97:         Print("@var{"); Print(aaa[Length(aaa)-1]);
        !            98:         Print("}");
        !            99:       }
        !           100:       Print(AsciiToString(RightBracket)); /* ) */
        !           101:     }else{
        !           102:       Println(aaa);
        !           103:     }
        !           104:   }else{
        !           105:     Ln();
        !           106:   }
        !           107:   Print(":: "); Println(shortDesc);
1.1       takayama  108:   Println("@end table");
                    109:   Ln();
                    110:   Println(" */");
                    111:
                    112:   Println("/*&en ");
                    113:   Println("@itemize @bullet");
                    114:   Print("@item "); Println(desc[0]);
                    115:   Println("@end itemize");
                    116:   Println(" */ ");
                    117:
                    118:   if (Length(desc) == 2) {
                    119:     Println("/*&C ");
                    120:     Println("@example");
                    121:     Println(desc[1]);
                    122:     Println("@end example");
                    123:     Ln();
                    124:     Println(" */ ");
                    125:   }
1.2     ! takayama  126:   if (Tag(ref) != 0) {
        !           127:     Println("/*&C ");
        !           128:     Println("@table @t");
        !           129:     Println("@item See also");
        !           130:     if (IsArray(ref)) {
        !           131:       if (Length(ref) > 0) {
        !           132:         for (i=0; i<Length(ref)-1; i++) {
        !           133:           Print("@code{");
        !           134:           Print(ref[i]); Print("}"); Print(", ");
        !           135:         }
        !           136:         Print("@code{");
        !           137:         Print(ref[Length(ref)-1]); Println("} ");
        !           138:       }
        !           139:     }else{
        !           140:       Println(ref);
        !           141:     }
        !           142:     Println("@end table");
        !           143:     Ln();
        !           144:     Println(" */ ");
        !           145:   }
1.1       takayama  146: }
                    147:
                    148: def findKey(keys,s) {
                    149:   local n,m,i,j,r,k,ii,II;
                    150:   s = StringToAsciiArray(s);
                    151:   II = Length(keys);
                    152:   for (ii=0; ii<II; ii++) {
                    153:     k = StringToAsciiArray(keys[ii]);
                    154:     n = Length(k); m = Length(s);
                    155:     i = 0;
                    156:     while( i<m-n ) {
                    157:       r = true;
                    158:       for (j=0; j<n; j++) {
                    159:         if (k[j] != s[i+j]) {
                    160:            r = false;
                    161:         }
                    162:       }
                    163:       if (r == true) return(true);
                    164:       i++;
                    165:     }
                    166:   }
                    167:   return(false);
                    168: }
                    169:
                    170: def splitExample(s) {
                    171:   local desc,example,n,i,inExample,newl,news,tt;
                    172:   if (IsArray(s) && Length(s) == 1) {
                    173:     s = s[0];
                    174:   }
                    175:   if (IsString(s)) {
                    176:     s = StringToAsciiArray(s);
                    177:     tt = [ ];
                    178:     news = [ ];
                    179:     n = Length(s);
                    180:     for (i=0; i<n; i++) {
                    181:       tt = Append(tt,s[i]);
                    182:       if (s[i] == 10) {
                    183:         if (Length(tt) > 0) {
                    184:           tt = Map(tt,"AsciiToString");
                    185:           tt = AddString(tt);
                    186:         }else{
                    187:           tt = AsciiToString(10);
                    188:         }
                    189:         news = Append(news,tt);
                    190:         tt = [ ];
                    191:       }
                    192:     }
                    193:     if (Length(tt) > 0) {
                    194:        tt = Map(tt,"AsciiToString");
                    195:        tt = AddString(tt);
                    196:        news = Append(news, tt);
                    197:     }
                    198:     s = news;
                    199:   }
                    200:   n = Length(s);
                    201:   inExample = false;
                    202:   newl = AsciiToString(10);
                    203:   desc = " "; example = " ";
                    204:   i = 0;
                    205:   while (i<n) {
                    206:     if (findKey(["Ex.","Example","example"],s[i])) {
                    207:       inExample = true;
                    208:     }
                    209:     s[i] = addEscape(s[i]);
                    210:     if (inExample) {
                    211:       example = AddString([example,newl,s[i]]);
                    212:     }else{
                    213:       desc = AddString([desc,newl,s[i]]);
                    214:     }
                    215:     i++;
                    216:   }
                    217:   if (Length(example) < 2) {
                    218:      return([desc]);
                    219:   }else{
                    220:     return([desc,example]);
                    221:   }
                    222: }
                    223:
                    224: def addEscape(s) {
1.2     ! takayama  225:   local i,n,ans,leftCurryBrace,rightCurryBrace,at,leftIneq,rightIneq,
        !           226:         ex0;
1.1       takayama  227:   leftCurryBrace = 123;
                    228:   rightCurryBrace = 125;
1.2     ! takayama  229:   leftIneq = 60; /* < */
        !           230:   rightIneq = 62; /* > */
        !           231:   at = 64; /* @ */
        !           232:   ex0 = StringToAsciiArray("Ex.");
1.1       takayama  233:   s = StringToAsciiArray(s);
                    234:   n = Length(s);
1.2     ! takayama  235:   s = Join(s,[0,0,0,0]);
1.1       takayama  236:   ans = [ ];
1.2     ! takayama  237:   i = 0;
        !           238:   while (i < n) {
1.1       takayama  239:     if (s[i] == leftCurryBrace) {
                    240:       ans = Join(ans,[64,leftCurryBrace]);
                    241:     }else if (s[i] == rightCurryBrace) {
                    242:       ans = Join(ans,[64,rightCurryBrace]);
1.2     ! takayama  243:     }else if (s[i] == leftIneq && s[i+1] == leftIneq) {
        !           244:       ans = Join(ans,Append(StringToAsciiArray("@var"),leftCurryBrace));
        !           245:       i++;
        !           246:     }else if (s[i] == rightIneq && s[i+1] == rightIneq) {
        !           247:       ans = Join(ans,[rightCurryBrace]);
        !           248:       i++;
        !           249:     }else if ([s[i],s[i+1],s[i+2]] == ex0) {
        !           250:       i = i+2;
        !           251:     }else {
1.1       takayama  252:       ans = Append(ans,s[i]);
                    253:     }
1.2     ! takayama  254:     i++;
1.1       takayama  255:   }
                    256:   return(AddString(Map(ans,"AsciiToString")));
                    257: }
                    258:
                    259: foo();

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>