/* valid Commands for Input/Output Copyright (C) 1998 Martin Vogt This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation. For more information look at the file COPYRIGHT in this package */ #include "commandTable.h" #include using namespace std; CommandTable::CommandTable(){ nCommandDesc=0; } CommandTable::~CommandTable(){ } const char* CommandTable::getCommand(int nr) { int i; const char* back=""; for(i=0;i nlen) && (name[nlen]==' ')) { return commandDesc[i].longName; } } if (strlen(commandDesc[i].shortName) > 0) { nlen=strlen(commandDesc[i].shortName); comp=strncmp(commandDesc[i].shortName,name,nlen); if (comp == 0) { if (strlen(name) == nlen) { return commandDesc[i].shortName; } else if ((strlen(name) > nlen) && (name[nlen]==' ')) { return commandDesc[i].shortName; } } } } return back; } int CommandTable::getNr(const char* command) { int i; int comp; int back=-1; unsigned int nlen; for(i=0;i nlen) && (command[nlen]==' ')) { return commandDesc[i].number; } } if (strlen(commandDesc[i].shortName) > 0) { nlen=strlen(commandDesc[i].shortName); comp=strncmp(commandDesc[i].shortName,command,nlen); if (comp == 0) { if (strlen(command) == nlen) { return commandDesc[i].number; } else if((strlen(command) > nlen) && (command[nlen]==' ')){ return commandDesc[i].number; } } } } return back; } const char* CommandTable::getArgs(const char* command,const char* wholeLine) { unsigned int i; unsigned int n; const char* back; back=wholeLine; n=strlen(command); if (n==0) return back; for(i=0;i n) { back++; } return back; } void CommandTable::print() { int i; cout << "internal Help System V. 0.2\n"; cout << "known commands are :\n\n"; for(i=0;igetCommandCounter(); CommandDescription* cmdDesc; for (i=0;igetCommandDescription(i); insert(cmdDesc); } } void CommandTable::insert(CommandDescription* cmdDesc) { const char* lNameTest; const char* sNameTest; int pos=getPos(cmdDesc->number); if (pos != -1) { cout << "number "<< cmdDesc->number << " for command "<< cmdDesc->longName << " already defined!" << endl; } lNameTest=getCommand(cmdDesc->longName); if (strlen(lNameTest) > 0) { cout << "longName "<< cmdDesc->longName << " already defined." << "Previous definition has number : " << getNr(cmdDesc->longName) << endl; } sNameTest=getCommand(cmdDesc->shortName); if (strlen(sNameTest) > 0) { cout << "shortName "<< cmdDesc->shortName << " already defined." << "Previous definition has number : " << getNr(cmdDesc->shortName) << endl; } commandDesc[nCommandDesc].lexternalUse=cmdDesc->lexternalUse; commandDesc[nCommandDesc].lReturn=cmdDesc->lReturn; commandDesc[nCommandDesc].longName=cmdDesc->longName; commandDesc[nCommandDesc].shortName=cmdDesc->shortName; commandDesc[nCommandDesc].number=cmdDesc->number; commandDesc[nCommandDesc].help=cmdDesc->help; nCommandDesc++; } int CommandTable::getReturnFlag(int cmdNr) { int i=getPos(cmdNr); CommandDescription* cmdDesc; if (i == -1) { return -1; } cmdDesc=getCommandDescription(i); return cmdDesc->lReturn; }