Beispiel #1
0
Bstring Bstring::substr(int i,int j) const
{
    int k = 0;

    if (j < i)
        return Bstring("");

    else {
        if (i<0)
            i = 0;
        
        if (j >= count)
            j = count-1;


        Bstring tmpstring(j-i+1, 0); //allocates space, but doesn't fill

        for(k=0;i<=j;i++,k++)
            tmpstring.str[k] = str[i];

        tmpstring.str[k] = '\0';

        return tmpstring;
    }
}
Beispiel #2
0
Bstring Bstring::operator +(const Bstring& s) const
{
    Bstring tmpstring(count+s.count, 0); //allocate space but dont fill

    strcpy(tmpstring.str,str);
    strcat(tmpstring.str,s.str);

    return tmpstring;
}
Beispiel #3
0
Bstring Bstring::operator +(char c) const
{
    Bstring tmpstring(count+1, 0); //allocate space but don't fill
    strcpy(tmpstring.str,str);
    tmpstring.str[count] = c;
    tmpstring.str[count+1] = '\0';

    return tmpstring;
}
Beispiel #4
0
void ad_comm::allocate(void)
{
#if defined (_WIN32)
    directory_prefix='\\';
#else
    directory_prefix='/';
#endif
    adstring tmpstring;

#if defined(_MSC_VER)
    //remove path
    for (int i = (int)adprogram_name.size(); i >= 1; i--)
    {
        if (adprogram_name(i)==directory_prefix)
        {
            adprogram_name=adprogram_name(i+1,adprogram_name.size());
            break;
        }
    }
#endif

#if defined(_WIN32)
    // strip off the .exe
#ifdef __MINGW64__
    size_t _n = adprogram_name.size();
    assert(_n <= INT_MAX);
    int n = (int)_n;
#else
    int n = (int)adprogram_name.size();
#endif
    if (n > 4)
    {
        if (adprogram_name(n - 3) == '.'
                && tolower(adprogram_name(n - 2)) == 'e'
                && tolower(adprogram_name(n - 1)) == 'x'
                && tolower(adprogram_name(n)) == 'e')
        {
            n -= 4;
        }
    }
    adprogram_name=adprogram_name(1,n);
#endif

    // change the working directory name
    if (argc > 1)
    {
        int on=0;
        if ( (on=option_match(argc,argv,"-wd"))>-1)
        {
            if (on>argc-2 || argv[on+1][0] == '-')
            {
                cerr << "Invalid input data command line option"
                     " -- ignored" << endl;
            }
            else
            {
                tmpstring = adstring(argv[on+1]);
                wd_flag=1;
            }
        }
    }
    if (length(tmpstring))
    {
        if (tmpstring(length(tmpstring)) == directory_prefix)
        {
            adprogram_name=tmpstring + adprogram_name;
            working_directory_path = tmpstring;
        }
        else
        {
            adprogram_name=tmpstring + directory_prefix + adprogram_name;
            working_directory_path = tmpstring + directory_prefix;
        }
    }

    tmpstring=adprogram_name + adstring(".dat");
    if (argc > 1)
    {
        int on=0;
        if ( (on=option_match(argc,argv,"-ind"))>-1)
        {
            if (on>argc-2 || argv[on+1][0] == '-')
            {
                cerr << "Invalid input data command line option"
                     " -- ignored" << endl;
            }
            else
            {
                tmpstring = adstring(argv[on+1]);
            }
        }
    }
    global_datafile= new cifstream(tmpstring);
    if (!global_datafile)
    {
        cerr << "Error trying to open data input file "
             << tmpstring << endl;
    }
    else
    {
        if (!(*global_datafile))
        {
            cerr << "Error trying to open data input file "
                 << tmpstring << endl;
            delete global_datafile;
            global_datafile=NULL;
        }
    }
    adstring ts=adprogram_name + adstring(".log");
    global_logfile= new ofstream( (char*)ts);

    int biopt=-1;
    int aiopt=-1;
    biopt=option_match(argc,argv,"-binp");
    aiopt=option_match(argc,argv,"-ainp");

    tmpstring=adprogram_name + adstring(".bin");
    if (!global_bparfile && aiopt == -1)
    {
        if (biopt>-1)
        {
            if (biopt>argc-2 || argv[biopt+1][0] == '-')
            {
                cerr << "Invalid input parameter file command line option"
                     " -- ignored" << endl;
            }
            else
            {
                tmpstring = adstring(argv[biopt+1]);
            }
        }
        global_bparfile= new uistream(tmpstring);
        if (global_bparfile)
        {
            if (!(*global_bparfile))
            {
                if (biopt>-1)
                {
                    cerr << "Error trying to open binary inoput par file "
                         << tmpstring << endl;
                    exit(1);
                }
                delete global_bparfile;
                global_bparfile=NULL;
            }
        }
    }
    tmpstring=adprogram_name + adstring(".pin");
    if (!global_parfile)
    {
        if (aiopt>-1)
        {
            if (aiopt>argc-2 || argv[aiopt+1][0] == '-')
            {
                cerr << "Invalid input parameter file command line option"
                     " -- ignored" << endl;
            }
            else
            {
                tmpstring = adstring(argv[aiopt+1]);
            }
        }
        global_parfile= new cifstream(tmpstring);
        if (global_parfile)
        {
            if (!(*global_parfile))
            {
                if (aiopt>-1)
                {
                    cerr << "Error trying to open ascii inoput par file "
                         << tmpstring << endl;
                    exit(1);
                }
                delete global_parfile;
                global_parfile=NULL;
            }
        }
    }
}