version 1.1, 2017/03/10 01:32:50 |
version 1.3, 2018/11/08 02:53:35 |
|
|
/* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/util/oxlistusage.c,v 1.2 2017/03/19 12:39:52 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
#include <ctype.h> |
#include <ctype.h> |
#include <stdlib.h> |
#include <stdlib.h> |
|
|
#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); } |
|
|
|
|
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(); |
|
|
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(); |
|
|
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));*************/ |
|
|
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 { |
|
|
} |
} |
|
|
|
|
readcomment() { |
int readcomment() { |
int c; |
int c; |
while (1) { |
while (1) { |
c = fsgetc(Inop); |
c = fsgetc(Inop); |
|
|
} |
} |
} |
} |
|
|
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' */ |
|
|
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; |
|
|
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", |
|
|
"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"}; |
|
|
|
|
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; |
|
|
|
|
} |
} |
|
|
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 show_help() { |
|
printf("oxlistusage [--oxgentexi --help] filename1 ...\n"); |
|
printf(" See also oxgentexi, keys: Example:\n"); |
|
} |
|
|
|
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 if (strcmp(argv[i],"--help")==0) { |
|
show_help(); return(0); |
|
} |
|
}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); |
} |
} |