Blame src/ArgV.h

Packit 8f70b4
/*
Packit 8f70b4
 * lftp - file transfer program
Packit 8f70b4
 *
Packit 8f70b4
 * Copyright (c) 1996-2017 by Alexander V. Lukyanov (lav@yars.free.net)
Packit 8f70b4
 *
Packit 8f70b4
 * This program is free software; you can redistribute it and/or modify
Packit 8f70b4
 * it under the terms of the GNU General Public License as published by
Packit 8f70b4
 * the Free Software Foundation; either version 3 of the License, or
Packit 8f70b4
 * (at your option) any later version.
Packit 8f70b4
 *
Packit 8f70b4
 * This program is distributed in the hope that it will be useful,
Packit 8f70b4
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8f70b4
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 8f70b4
 * GNU General Public License for more details.
Packit 8f70b4
 *
Packit 8f70b4
 * You should have received a copy of the GNU General Public License
Packit 8f70b4
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 8f70b4
 */
Packit 8f70b4
Packit 8f70b4
#ifndef ARGV_H
Packit 8f70b4
#define ARGV_H
Packit 8f70b4
Packit 8f70b4
#include "trio.h"
Packit 8f70b4
#include "StringSet.h"
Packit 8f70b4
#include "getopt.h"
Packit 8f70b4
Packit 8f70b4
class ArgV : public StringSet
Packit 8f70b4
{
Packit 8f70b4
   int ind;
Packit 8f70b4
Packit 8f70b4
public:
Packit 8f70b4
   ArgV() { ind=0; }
Packit 8f70b4
   ArgV(const char *a0) : StringSet(&a0,1) { ind=0; }
Packit 8f70b4
   ArgV(const char *a0, const char *args);
Packit 8f70b4
   ArgV(const ArgV& a) : StringSet(a) { ind=0; }
Packit 8f70b4
   ArgV(const ArgV *a) : StringSet(*a) { ind=0; }
Packit 8f70b4
   ArgV(int new_c,const char * const *new_v) : StringSet(new_v,new_c) { ind=0; }
Packit 8f70b4
   ~ArgV();
Packit 8f70b4
Packit 8f70b4
   ArgV& Append(const char *s) { StringSet::Append(s); return *this; }
Packit 8f70b4
   ArgV& Append(int a) { char buf[32]; sprintf(buf,"%d",a); return Append(buf); }
Packit 8f70b4
   ArgV& Add(const char *a) { return Append(a); } // alias
Packit 8f70b4
Packit 8f70b4
   xstring& CombineTo(xstring& res,int start_index=0,int end_index=0) const;
Packit 8f70b4
   const char *CombineTo(xstring_c& res,int start_index=0,int end_index=0) const {
Packit 8f70b4
      xstring tmp; tmp.move_here(res);
Packit 8f70b4
      return res.move_here(CombineTo(tmp,start_index,end_index));
Packit 8f70b4
   }
Packit 8f70b4
   char *Combine(int start_index=0,int end_index=0) const { return CombineTo(xstring::get_tmp(),start_index,end_index).borrow(); }
Packit 8f70b4
Packit 8f70b4
   // for the UNIX shell
Packit 8f70b4
   xstring& CombineShellQuotedTo(xstring& res,int start) const;
Packit 8f70b4
   char *CombineShellQuoted(int start) const { return CombineShellQuotedTo(xstring::get_tmp(),start).borrow(); }
Packit 8f70b4
   // for lftp's CmdExec
Packit 8f70b4
   xstring& CombineQuotedTo(xstring& res,int start_index=0) const;
Packit 8f70b4
   const char *CombineQuotedTo(xstring_c& res,int start_index=0) const {
Packit 8f70b4
      xstring tmp; tmp.move_here(res);
Packit 8f70b4
      return res.move_here(CombineQuotedTo(tmp,start_index));
Packit 8f70b4
   }
Packit 8f70b4
   char *CombineQuoted(int start_index=0) const { return CombineQuotedTo(xstring::get_tmp(),start_index).borrow(); }
Packit 8f70b4
   xstring& CombineCmdTo(xstring& res,int i=0) const;
Packit 8f70b4
   char *CombineCmd(int i=0) const { return CombineCmdTo(xstring::get_tmp(),i).borrow(); }
Packit 8f70b4
Packit 8f70b4
   int getopt_long(const char *opts,const struct option *lopts,int *lind=0);
Packit 8f70b4
   int getopt(const char *opts)
Packit 8f70b4
      {
Packit 8f70b4
	 return getopt_long(opts,0,0);
Packit 8f70b4
      }
Packit 8f70b4
   const char *getopt_error_message(int e);
Packit 8f70b4
Packit 8f70b4
   void seek(int n);
Packit 8f70b4
   void rewind() { seek(0); }
Packit 8f70b4
   const char *getnext();
Packit 8f70b4
Packit 8f70b4
   const char *getarg(int n) const { return String(n); }
Packit 8f70b4
   const char *getcurr() const { return ind
Packit 8f70b4
   int getindex() const { return ind; }
Packit 8f70b4
   void setarg(int n,const char *s) { Replace(n,s); }
Packit 8f70b4
   void delarg(int n) { if(ind>n)--ind; Remove(n); }
Packit 8f70b4
   void insarg(int n,const char *s) { InsertBefore(n,s); }
Packit 8f70b4
   const char *a0() const { return getarg(0); }
Packit 8f70b4
   void back();
Packit 8f70b4
   int count() const { return Count(); }
Packit 8f70b4
   const char *const*GetV() const { return Set(); }
Packit 8f70b4
   char **GetVNonConst() { return SetNonConst(); }
Packit 8f70b4
};
Packit 8f70b4
Packit 8f70b4
#endif//ARGV_H