[BACK]Return to oxlistusage.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / util

Diff for /OpenXM/src/util/oxlistusage.c between version 1.1 and 1.2

version 1.1, 2017/03/10 01:32:50 version 1.2, 2017/03/19 12:39:52
Line 1 
Line 1 
 /* $OpenXM$ */  /* $OpenXM: OpenXM/src/util/oxlistusage.c,v 1.1 2017/03/10 01:32:50 takayama Exp $ */
 #include <stdio.h>  #include <stdio.h>
 #include <ctype.h>  #include <ctype.h>
 #include <stdlib.h>  #include <stdlib.h>
Line 7 
Line 7 
 #include <string.h>  #include <string.h>
 #include "oxlistlocalf.h"  #include "oxlistlocalf.h"
   
   void putchar0(int c);
   int fsgetc(FILE *fp);
   int readchar(void);
   int isReserved(char *name);
   void printf0(char *s);
   int shouldReplace(char *name);
   void printf1(char *name);
   int readcomment(void);
   int readcomment2(void);
   
   #define MAX_ITEM 1024*10
 int Mydebug=0;  int Mydebug=0;
   
 objectp KClval;  objectp KClval;
Line 15  int Linenumber = 0;
Line 26  int Linenumber = 0;
 int Saki = 0;  int Saki = 0;
 int Debug2 = 0;  int Debug2 = 0;
 FILE *Inop = NULL;  FILE *Inop = NULL;
   char *Functions[MAX_ITEM];
   char *Args[MAX_ITEM];
   char *Usages[MAX_ITEM];
   int Entries=0;
   
 char *readstring(void);  char *readstring(int endquote);
   
 void *mymalloc(int n) { return malloc(n); }  void *mymalloc(int n) { return malloc(n); }
   
Line 110  int KClex() {
Line 125  int KClex() {
         Saki = fsgetc(Inop); break;          Saki = fsgetc(Inop); break;
       }        }
       if ( Saki == '\"' ) {        if ( Saki == '\"' ) {
         str = readstring();          str = readstring('\"');
         if (Mydebug) printf("[string: %s]",str);          if (Mydebug) printf("[string: %s]",str);
   
         KClval = newObject_d();          KClval = newObject_d();
Line 123  int KClex() {
Line 138  int KClex() {
         break;          break;
       }        }
       if (Saki == '\'' ) {        if (Saki == '\'' ) {
         d = readchar();          str = readstring('\'');
           if (strlen(str)==1) d=str[0];
           else d='E';
         Saki = fsgetc(Inop);          Saki = fsgetc(Inop);
   
         KClval = newObject_d();          KClval = newObject_d();
Line 191  int KClex() {
Line 208  int KClex() {
       if (Mydebug) printf("identifier string=[%s]",name);        if (Mydebug) printf("identifier string=[%s]",name);
       if (isdigit(name[0])) {        if (isdigit(name[0])) {
         /****************************          /****************************
       /**case : machine integer.        case : machine integer.
     KClval = newObject_d();      KClval = newObject_d();
     KClval->tag = Sinteger;      KClval->tag = Sinteger;
     sscanf(name,"%d",&(KClval->lc.ival));*************/      sscanf(name,"%d",&(KClval->lc.ival));*************/
Line 204  int KClex() {
Line 221  int KClex() {
         break;          break;
       } /* else : Identifier case.*/        } /* else : Identifier case.*/
   
       if (d = isReserved(name)) {        if ((d = isReserved(name))) {
         if (Replace) printf0(name);          if (Replace) printf0(name);
         return(d);          return(d);
       } else {        } else {
Line 361  int KClex() {
Line 378  int KClex() {
 }  }
   
   
 readcomment() {  int readcomment() {
   int c;    int c;
   while (1) {    while (1) {
     c = fsgetc(Inop);      c = fsgetc(Inop);
Line 376  readcomment() {
Line 393  readcomment() {
   }    }
 }  }
   
 readcomment2() {  int readcomment2() {
   int c;    int c;
   while (1) {    while (1) {
     c = fsgetc(Inop);      c = fsgetc(Inop);
Line 391  readcomment2() {
Line 408  readcomment2() {
 }  }
   
   
 char *readstring() {  char *readstring(int endquote) {
   static char strtmp[1024]; /* temporary */    static char strtmp[1024]; /* temporary */
   static int size = 1024;    static int size = 1024;
   static char *str = strtmp;    static char *str = strtmp;
Line 404  char *readstring() {
Line 421  char *readstring() {
   while (1) {    while (1) {
     c = fsgetc(Inop);      c = fsgetc(Inop);
     if (Replace) putchar0(c);      if (Replace) putchar0(c);
     if (c == '\"') {      if (c == endquote) {
       str[i] = '\0';        str[i] = '\0';
       return(str);        return(str);
     }      }
Line 416  char *readstring() {
Line 433  char *readstring() {
     if (c == '\\') {      if (c == '\\') {
       c = fsgetc(Inop);        c = fsgetc(Inop);
       if (Replace) {        if (Replace) {
         putchar0(c);          putchar0(c);
       }        }
         switch(c) {  /* interprete as escape sequence. */
         case 'n': c='\n'; break;
         case 't': c='\t'; break;
         default: break;
         }
       if (c == EOF) {        if (c == EOF) {
         fprintf(stderr,"%d: Unexpected end of file in the escape sequence.\n",Linenumber);          fprintf(stderr,"%d: Unexpected end of file in the escape sequence.\n",Linenumber);
         str[i]= '\0';          str[i]= '\0';
Line 436  char *readstring() {
Line 458  char *readstring() {
 }  }
   
   
 readchar() {  int readchar() {
   int c;    int c;
   if (Replace) putchar0('\'');    if (Replace) putchar0('\'');
   c = fsgetc(Inop); /* 'c.'   '\.c' */    c = fsgetc(Inop); /* 'c.'   '\.c' */
Line 463  readchar() {
Line 485  readchar() {
   return(c);    return(c);
 }  }
   
 putchar0(c)  void putchar0(c)
   int c;    int c;
 {  {
   if (c > 0) putchar(c);    if (c > 0) putchar(c);
 }  }
   
 printf0(s)  void printf0(s)
   char *s;    char *s;
 {  {
   int i = 0;    int i = 0;
   while (s[i] != '\0') putchar0(s[i++]);    while (s[i] != '\0') putchar0(s[i++]);
 }  }
   
 printf1(s)  void printf1(s)
   char *s;    char *s;
 {  {
   int i = 0;    int i = 0;
Line 484  printf1(s)
Line 506  printf1(s)
   while (s[i] != '\0') putchar0(s[i++]);    while (s[i] != '\0') putchar0(s[i++]);
 }  }
   
 isReserved(s)  int isReserved(s)
   char *s;    char *s;
 {  {
   char *r[] = {"auto","break","case","char","const","continue",    char *r[] = {"auto","break","case","char","const","continue",
Line 494  isReserved(s)
Line 516  isReserved(s)
                "switch","typedef","union","unsigned","volatile",                 "switch","typedef","union","unsigned","volatile",
                "void","while",                 "void","while",
                "print","module","local","def","sm1","load","Test","special",                 "print","module","local","def","sm1","load","Test","special",
                "class","super","operator","final","extends",                 "class","super","final","extends",
                "incetanceVariable","this","new","startOfThisClass",                 "incetanceVariable","this","new","startOfThisClass",
                "sizeOfThisClass","PSfor","OutputPrompt"};                 "sizeOfThisClass","PSfor","OutputPrompt"};
   
Line 505  isReserved(s)
Line 527  isReserved(s)
                TYPEDEF, UNION,                 TYPEDEF, UNION,
                UNSIGNED, VOLATILE, VOID, WHILE,                 UNSIGNED, VOLATILE, VOID, WHILE,
                PRINT,MODULE,LOCAL,DEF,SM1,LOAD,TEST,SPECIAL,                 PRINT,MODULE,LOCAL,DEF,SM1,LOAD,TEST,SPECIAL,
                CLASS,SUPER,OPERATOR,FINAL,EXTENDS,INCETANCEVARIABLE,                 CLASS,SUPER,FINAL,EXTENDS,INCETANCEVARIABLE,
                THIS, NEW, STARTOFTHISCLASS, SIZEOFTHISCLASS,PSFOR,PROMPT};                 THIS, NEW, STARTOFTHISCLASS, SIZEOFTHISCLASS,PSFOR,PROMPT};
   int  n = 52; /* Length of the list above */    int  n = 51; /* Length of the list above */
   /* You have to change simple.y, too. */    /* You have to change simple.y, too. */
   
   int i;    int i;
Line 521  isReserved(s)
Line 543  isReserved(s)
   
 }  }
   
 shouldReplace(s)  int shouldReplace(s)
   char *s;    char *s;
 {  {
   char *r[] = {"dummy"};    char *r[] = {"dummy"};
Line 543  int fsgetc(FILE *fp) {
Line 565  int fsgetc(FILE *fp) {
   return(fgetc(fp));    return(fgetc(fp));
 }  }
   
   int oxgOut(char *inFname) {
     FILE *fp;
     int i;
     fp = stdout;
     for (i=0; i<Entries; i++) {
       fprintf(fp,"/*&usage begin:\n");
       fprintf(fp,"%s%s\n",Functions[i],Args[i]);
       fprintf(fp,"description: %s\n",Usages[i]);
       fprintf(fp,"end: */\n\n");
     }
     return(0);
   }
   
 int main(int argc,char *argv[]) {  int outUsage(char *inFname,int oxg) {
   int c;    int c;
   char usage[1024*10];    char usage[1024*100];
   char fname[1024];    char fname[1024];
   char *args[1024];    char *args[1024];
     char outbuf[1024*10];
   char *tt;    char *tt;
   int prevtype;    int prevtype;
   int i;    int i;
   if (argc <= 1) Inop = stdin;    Entries=0;
   else {  
     Inop = fopen(argv[1],"r");  
     if (Inop == NULL) {  
       fprintf(stderr,"File %s is not found.\n",argv[1]); return(-1);  
     }  
   }  
   while ((c=KClex()) != EOF) {    while ((c=KClex()) != EOF) {
     if (c == DEF) {      if (c == DEF) {
       c=KClex();        c=KClex();
       if (c != ID) {        if (c != ID) {
         fprintf(stderr,"ID (identifier) is expected, but the token type is %d\n",c);          fprintf(stderr,"ID (identifier) is expected, but the token type is %d. See isReserved() in oxlistusage.c\n",c);
       }else {        }else {
         if (Mydebug) printf("ID=%s",(KClval->lc).str);          if (Mydebug) printf("ID=%s",(KClval->lc).str);
         strcpy(fname,(KClval->lc).str); // def ...          strcpy(fname,(KClval->lc).str); // def ...
Line 590  int main(int argc,char *argv[]) {
Line 619  int main(int argc,char *argv[]) {
           }            }
         }          }
         if (prevtype == QUOTE) {          if (prevtype == QUOTE) {
           printf("Function %s(",fname);            /**/printf("\nFunction: %s(",fname);
             Functions[Entries]=(char *)mymalloc(strlen(fname)+2);
             strcpy(Functions[Entries],fname);
             sprintf(outbuf,"(");
           for (i=0; args[i] != NULL; i++) {            for (i=0; args[i] != NULL; i++) {
             printf("%s",args[i]);              /**/printf("%s",args[i]);
             if (args[i+1] != NULL) printf(",");              sprintf(&(outbuf[strlen(outbuf)]),"%s",args[i]);
               if (args[i+1] != NULL) {
                 /**/printf(",");
                 sprintf(&(outbuf[strlen(outbuf)]),",");
                }
           }            }
           printf(")\n");            /**/printf(")\n");
           printf("Usage: %s\n",usage);            sprintf(&(outbuf[strlen(outbuf)]),")");
             Args[Entries] = (char *)mymalloc(strlen(outbuf)+2);
             strcpy(Args[Entries],outbuf);
             /**/printf("Usage: %s\n",usage);
             Usages[Entries] = (char *)mymalloc(strlen(usage)+2);
             strcpy(Usages[Entries],usage);
             Entries++;
         }          }
       }        }
     }      }
   }    }
     if (oxg) { oxgOut(inFname); Entries=0;}
   return(0);    return(0);
   }
   
   int main(int argc,char *argv[]) {
     int i;
     int oxg=0;
     Inop = stdin;
     for (i=1; i<argc; i++) {
       if (argv[i][0] == '-') {
         if (strcmp(argv[i],"--oxgentexi")==0) oxg=1;
       }else {
         Inop = fopen(argv[i],"r");
         if (Inop == NULL) {
           fprintf(stderr,"File %s is not found.\n",argv[1]); return(-1);
         }
         outUsage(argv[i],oxg);
         fclose(Inop);
       }
     }
     if (Inop == stdin) outUsage("stdin",oxg);
 }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

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