From b939caccaa3aa0b61e2c02fb7064737729952d00 Mon Sep 17 00:00:00 2001 From: claudiol Date: Thu, 15 Mar 2018 19:05:36 -0400 Subject: [PATCH] Created command information extractor for the Wiki. Added test descriptions to one library. --- newrpl/lib-30-complex.c | 12 + tools/extractcmd/extractcmd/.gitignore | 73 ++++++ tools/extractcmd/extractcmd/extractcmd.pro | 6 + tools/extractcmd/extractcmd/main.c | 279 +++++++++++++++++++++ 4 files changed, 370 insertions(+) create mode 100644 tools/extractcmd/extractcmd/.gitignore create mode 100644 tools/extractcmd/extractcmd/extractcmd.pro create mode 100644 tools/extractcmd/extractcmd/main.c diff --git a/newrpl/lib-30-complex.c b/newrpl/lib-30-complex.c index 67c4d79..c69e516 100644 --- a/newrpl/lib-30-complex.c +++ b/newrpl/lib-30-complex.c @@ -18,6 +18,7 @@ // REPLACE THE NUMBER #define LIBRARY_NUMBER 30 +//@TITLE=Operations with Complex Numbers // LIST OF COMMANDS EXPORTED, // INCLUDING INFORMATION FOR SYMBOLIC COMPILER @@ -6411,6 +6412,7 @@ void LIB_HANDLER() case RE: { + //@SHORT_DESC=Real part of a complex number if(rplDepthData()<1) { rplError(ERR_BADARGCOUNT); return; @@ -6466,6 +6468,8 @@ void LIB_HANDLER() } case IM: { + //@SHORT_DESC=Imaginary part of a complex number + if(rplDepthData()<1) { rplError(ERR_BADARGCOUNT); return; @@ -6524,6 +6528,8 @@ void LIB_HANDLER() } case ARG: { + //@SHORT_DESC=Argument of a complex number + if(rplDepthData()<1) { rplError(ERR_BADARGCOUNT); return; @@ -6617,6 +6623,8 @@ void LIB_HANDLER() } case CONJ: { + //@SHORT_DESC=Conjugate of a complex number + if(rplDepthData()<1) { rplError(ERR_BADARGCOUNT); return; @@ -6668,6 +6676,8 @@ void LIB_HANDLER() case CPLX2REAL: + //@SHORT_DESC=Split Complex into two Reals + if(rplDepthData()<1) { rplError(ERR_BADARGCOUNT); return; @@ -6688,6 +6698,8 @@ void LIB_HANDLER() case REAL2CPLX: { + //@SHORT_DESC=Make Complex from real and imaginary parts + if(rplDepthData()<2) { rplError(ERR_BADARGCOUNT); return; diff --git a/tools/extractcmd/extractcmd/.gitignore b/tools/extractcmd/extractcmd/.gitignore new file mode 100644 index 0000000..fab7372 --- /dev/null +++ b/tools/extractcmd/extractcmd/.gitignore @@ -0,0 +1,73 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + diff --git a/tools/extractcmd/extractcmd/extractcmd.pro b/tools/extractcmd/extractcmd/extractcmd.pro new file mode 100644 index 0000000..fc18d89 --- /dev/null +++ b/tools/extractcmd/extractcmd/extractcmd.pro @@ -0,0 +1,6 @@ +TEMPLATE = app +CONFIG += console +CONFIG -= app_bundle +CONFIG -= qt + +SOURCES += main.c diff --git a/tools/extractcmd/extractcmd/main.c b/tools/extractcmd/extractcmd/main.c new file mode 100644 index 0000000..33a283b --- /dev/null +++ b/tools/extractcmd/extractcmd/main.c @@ -0,0 +1,279 @@ +/* + * Copyright (c) 2014-2015, Claudio Lapilli and the newRPL Team + * All rights reserved. + * This file is released under the 3-clause BSD license. + * See the file LICENSE.txt that shipped with this distribution. + */ + + +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + + char *mainbuffer; + + if(argc<2) { + printf("NewRPL command extract - Version 1.0\n"); + printf("Usage: extractcmd -d \n"); + printf("\nOptions:\n"); + printf("\t\t-d \tSpecify a the directory where the output file will be created (by default, same as the source file)\n\n\n"); + return 0; + } + + int argidx=1; + int needoutputpath=0; + int needcleanup=0; + int nameoffset,namelen; + char *outputfile=NULL; + char *outputpath=NULL; + char *inputfile=NULL; + while(argidxinputfile)&&(*end!='.')&&(*end!='/')&&(*end!='\\')) --end; + if(end<=inputfile) end=inputfile+strlen(inputfile); + else if(*end!='.') { libname=end; end=inputfile+strlen(inputfile); } + needcleanup++; + + while(strrchr(libname,'-')>libname) libname=strrchr(libname,'-')+1; + + outputfile=malloc(end-libname+10+((outputpath)? strlen(outputpath):0)); + if(!outputfile) { + fprintf(stderr,"error: Memory allocation error\n"); + return 1; + } + nameoffset=0; + namelen=end-libname; + if(outputpath) { + strcpy(outputfile,outputpath); + nameoffset=strlen(outputpath); + if(outputpath[nameoffset-1]!='/') outputpath[nameoffset++]='/'; + } + memmove(outputfile+nameoffset,libname,namelen); + strcpy(outputfile+nameoffset+namelen,".txt"); + + } + + // HERE WE HAVE THE SECTION NAME AT outputfile[nameoffset]..outputfile[nameoffset+namelen-1] + + // READ THE INPUT FILE INTO A BUFFER + FILE *f=fopen(inputfile,"rb"); + if(f==NULL) { + fprintf(stderr,"error: File not found %s\n",inputfile); + if(needcleanup) free(outputfile); + return 1; + } + fseek(f,0,SEEK_END); + long long length=ftell(f); + fseek(f,0,SEEK_SET); + + mainbuffer=malloc(length); + if(!mainbuffer) { + fprintf(stderr,"error: Memory allocation error\n"); + if(needcleanup) free(outputfile); + return 1; + } + if(fread(mainbuffer,1,length,f)!=(size_t)length) { + fprintf(stderr,"error: Can't read from input file\n"); + if(needcleanup) free(outputfile); + free(mainbuffer); + return 1; + } + fclose(f); + + // HERE WE HAVE THE MAIN FILE LOADED, EXTRACT THE COMMANDS + + + // FIND COMMANDS + + char *chunk=mainbuffer; + int ncmd=0,extcommand; + char *cmdname[1000],*cmdstring[1000],*cmddesc[1000]; + int cmdnamelen[1000],cmdstrlen[1000],cmddesclen[1000]; + int line=1; + char *libtitle=0; + int libtitlelen=0; + int currentcmd=0; + + int k; + // SET ALL LENGTHS TO ZERO + for(k=0;k<1000;++k) + { + cmdnamelen[k]=cmdstrlen[k]=cmddesclen[k]=0; + } + + while(chunk-mainbuffer