Commit 2defe17a authored by Jan Koester's avatar Jan Koester
Browse files

commands arguments no are working

parent 2f6e7870
Loading
Loading
Loading
Loading
+71 −3
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <systempp/sysconsole.h>
#include <systempp/sysfile.h>
#include <systempp/sysutils.h>
#include <systempp/sysexec.h>
#include <systempp/sysutils.h>

#include "fresh.h"

@@ -35,20 +37,86 @@ int main(int argc,char *argv[]){
    int i=0;
    libsystempp::CharArray input;
    for(;;){
INPUT:
        input.clear();
        libsystempp::Console[SYSIN] >> input;
        
        if(input.length()==0)
            goto INPUT;
        else if(input=="exit")
            break;
        
        class args {
        public:
            args(){
                nextargs=nullptr;
            }
            ~args(){
                delete nextargs;
            }
            libsystempp::CharArray arg;
            args                  *nextargs;
        }*ftargs=nullptr,*ltargs=nullptr;
        
        unsigned long spos=0,amount=0;
        
        for(int epos=0; epos<=input.length(); ++epos){
            if(input[epos]==' ' || epos==input.length()){
                if(ftargs){
                    ltargs->nextargs=new args;
                    ltargs=ltargs->nextargs;
                }else{
                    ftargs=new args;
                    ltargs=ftargs;
                }
                libsystempp::CharArray buf;
                input.substr(buf,spos,epos);
                if(epos<(input.length()-1))
                    spos=++epos;
                ltargs->arg=buf;
                ++amount;
            }
        }
        
        char **cargs=nullptr;
        cargs=new char*[amount+1];
        
        int capos=0;
        
        for(args *curargs=ftargs; curargs; curargs=curargs->nextargs){
            cargs[capos]=new char[curargs->arg.length()+1];
            char *buf=nullptr;
            curargs->arg.to_cbuffer(&buf);
            libsystempp::scopy(buf,buf+libsystempp::getlen(buf),cargs[capos]);
            cargs[capos][libsystempp::getlen(buf)]='\0';
            capos++;
            delete[] buf;
        }
        
        cargs[capos]=nullptr;
        
        libsystempp::Console[SYSOUT] << cargs[0];
        
        for(const char *value=PATH[i]; value; value=PATH[++i]){
            libsystempp::Directory dir(value);
            for(libsystempp::Directory *cdir=&dir; cdir; cdir=cdir->nextDirectory()){
                cdir->list();
                for(libsystempp::File *cfile=cdir->getFile(); cfile; cfile=cfile->nextFile()){
                    libsystempp::Console[SYSOUT] <<  cfile->getName() << libsystempp::Console[SYSOUT].endl;
                    if(input==cfile->getName()){
                        libsystempp::Console[SYSOUT] << PATH[i] << libsystempp::Console[SYSOUT].endl;
                    if(libsystempp::ncompare(cfile->getName(),libsystempp::getlen(cfile->getName()),
                        cargs[0],libsystempp::getlen(cargs[0]))==0){
                        libsystempp::Exec exec(("/",nullptr),cfile->getPath(),(const char**)cargs);
                        exec.join();
                        for(i=0; i<amount; i++)
                            delete [] cargs[i];
                        delete[] cargs;
                        goto INPUT;
                    }
                }
            }
        }
        for(i=0; i<amount; i++)
            delete [] cargs[i];
        delete[] cargs;
    }
    return 0;
}

src/shell.cpp

0 → 100644
+47 −0
Original line number Diff line number Diff line
/*******************************************************************************
Copyright (c) 2022, Jan Koester jan.koester@gmx.net
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the <organization> nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/

#include "shell.h"

fresh::ShellCommand::ShellCommand(){
    _nextShellCommand=nullptr;
}

fresh::ShellCommand::~ShellCommand(){
}

fresh::Shell::Shell(){
}

fresh::Shell::~Shell(){
}

void fresh::Shell::addCommand(fresh::ShellCommand* mycmd){
}

void fresh::Shell::parse(const libsystempp::CharArray* input){
}

src/shell.h

0 → 100644
+56 −0
Original line number Diff line number Diff line
/*******************************************************************************
Copyright (c) 2022, Jan Koester jan.koester@gmx.net
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the <organization> nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/

#include <systempp/sysarray.h>

#pragma once

namespace fresh {
    
    class ShellCommand {
    public:
        virtual void runCommand(int argc,const char **argv)=0;
    protected:
        ShellCommand();
        ~ShellCommand();
        libsystempp::CharArray  Command;        
    private:
        ShellCommand           *_nextShellCommand;
        friend class Shell;
    };
    
    class Shell{
    public:
        Shell();
        ~Shell();
        void addCommand(ShellCommand *mycmd);
        void parse(const libsystempp::CharArray *input);
    private:
        ShellCommand *_firstShellCommand;
        ShellCommand *_lastShellCommand;
    };
};