Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Application.C

00001 /* $Id: Application.C,v 1.2 2000/11/03 22:03:28 rpav Exp $
00002  *
00003  * SFW - Studio FrameWork
00004  * Copyright (C) 2000  Ryan Pavlik
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019  *
00020  */
00021 
00022 /*
00023  * Application class
00024  *
00025  */ 
00026 
00027 #include <cstring>
00028 #include <SFW/Log.H>
00029 #include <SFW/Application.H>
00030 
00031 #define ARG_SHORT_INCREASE 32
00032 #define ARG_LONG_INCREASE  16
00033 
00034 TYPE_INIT(SFW::Application);
00035 
00036 using namespace SFW;
00037 
00038 Application::Application() {
00039     argSpecShort = new char[ARG_SHORT_INCREASE + 1];
00040     argSpecLong  = new option[ARG_LONG_INCREASE + 1];
00041 
00042     argShortCap  = ARG_SHORT_INCREASE;
00043     argLongNum   = 0;
00044     argLongCap   = ARG_LONG_INCREASE;
00045 
00046     argSpecShort[0]        = 0;
00047     argSpecLong[0].name    = 0;
00048     argSpecLong[0].has_arg = 0;
00049     argSpecLong[0].flag    = 0;
00050     argSpecLong[0].val     = 0;
00051 }
00052 
00053 void Application::addOpt(char name, int argType) {
00054     int size = 1 + argType; 
00055     int idx  = strlen(argSpecShort);
00056 
00057     if(size > 2)
00058     size = 2;
00059     
00060     /* We need to make more */
00061     if((idx + size) > argShortCap) {
00062     char *tmp    = new char[idx + ARG_SHORT_INCREASE]; // +1 accounted for
00063     argShortCap += ARG_SHORT_INCREASE;
00064     
00065     strcpy(tmp, argSpecShort);
00066     delete[] argSpecShort;
00067     argSpecShort = tmp;
00068     }
00069 
00070     argSpecShort[idx++] = name;
00071 
00072     if(argType >= 1)
00073     argSpecShort[idx++] = ':';
00074     if(argType == 2)
00075     argSpecShort[idx++] = ':';
00076 
00077     argSpecShort[idx] = 0;
00078 }
00079 
00080 void Application::addLongOpt(const string &name, int argType) {
00081     if(argType > 2)
00082     argType = 2;
00083     
00084     /* If we need more, make more */
00085     if(argLongCap == argLongNum) {
00086     option *tmp = new option[argLongCap + ARG_LONG_INCREASE + 1];
00087     
00088     memcpy(tmp, argSpecLong, sizeof(option) * argLongNum);
00089     delete[] argSpecLong;
00090     argSpecLong = tmp;
00091     }
00092 
00093     argSpecLong[argLongNum].name    = new char[name.size() + 1];
00094     strcpy((char*)argSpecLong[argLongNum].name, name.c_str());
00095     argSpecLong[argLongNum].has_arg = argType;
00096     argSpecLong[argLongNum].flag    = 0;
00097     argSpecLong[argLongNum++].val   = 0;
00098 
00099     argSpecLong[argLongNum].name    = 0;
00100     argSpecLong[argLongNum].has_arg = 0;
00101     argSpecLong[argLongNum].flag    = 0;
00102     argSpecLong[argLongNum].val     = 0;
00103 }

Generated at Tue Jan 2 15:38:33 2001 for SFW by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000