Пример #1
0
int main()
try
{
	vector<string> vs;
	vs.push_back("Technicalities");
	vs.push_back("a");
	vs.push_back("A");
	vs.push_back("hellohellohell");	// same length as "Technicalities"
	vs.push_back("Hellohellohell");	// lexicographically 'H' < 'h'
//	vs.push_back("");	// the empty string
	vs.push_back("Technicalities");	// More technicalities
	vs.push_back("!");	// same length as "a"

	cout << "sizes: ";
	vector<int> lengths = get_sizes(vs);
	for (int i=0; i<lengths.size(); ++i) cout << lengths[i] << ' ';
	cout << '\n';

	int i = longest(vs);
	cout << "longest(): index==" << i << "; string=='" << vs[i] << "'\n";	// note the quotes: I want to be able to see the empty string

	cout << "shortest(): '" << shortest(vs) << "'\n";	// note the quotes: I want to be able to see the empty string

	cout << "lex_first(): '" << lex_first(vs) << "'\n";
	
	lex_last(vs,i);	// pass 'i' for lex_last() to return into
	cout << "lex_last(): index==" << i << "; string=='" << vs[i] << "'\n";	// note the quotes: I want to be able to see the empty string
																			// note: had vs been empty, this code would have accessed vs[-1]; Ouch!

	keep_window_open("~");	// For some Windows(tm) setups
}
catch (runtime_error e) {	// this code is to produce error messages
	cout << e.what() << '\n';
	keep_window_open("~");	// For some Windows(tm) setups
}
Пример #2
0
int SshFunc::sign_data(char *key, size_t klen, struct iovec *sigbufs, char *fmt, ...)
{
    int i, rc;
    va_list argp;
    char *para, *p, *pos;
    size_t para_len;
    int num_bufs = get_sizes(fmt);
    struct iovec *tmp_bufs;
    int *d_nums;
    char *skey = key;
    size_t sklen = klen;

    if (!sshAuth) 
        return 0;

    tmp_bufs = new struct iovec[num_bufs];
    d_nums = new int[num_bufs];
    if (key == NULL) {
        skey = session_key;
        sklen = key_len;
    }

    va_start(argp, fmt);
    pos = p = fmt;
    i = -1;
    while (*p != '\0') {
        switch (*p) {
            case 'd':
                d_nums[i] = va_arg(argp, int);
                d_nums[i] = htonl(d_nums[i]);
                tmp_bufs[i].iov_len = sizeof(int);
                tmp_bufs[i].iov_base = &d_nums[i];
                break;
            case 's':
                tmp_bufs[i].iov_base = va_arg(argp, char *);
                if (*pos != 's') {
                    tmp_bufs[i].iov_len = atoi((const char *)pos);
                } else {
                    tmp_bufs[i].iov_len = strlen((char *)tmp_bufs[i].iov_base) + 1;
                }
                break;
            case '%':
                pos = p + 1;
                i++;
                break;
        }
        p++;
    }
    va_end(argp);

    rc = sign_data(skey, key_len, tmp_bufs, num_bufs, sigbufs);
    delete []d_nums;
    delete []tmp_bufs;

    return rc;
}
Пример #3
0
/**
 * \brief Reads the input file, and pulls out the necessary data for use in the plan
 * \param [in] line The line of input data.
 * \param [out] output The data and storage for the load.
 * \return int True if the data was read, false if it wasn't
 * \sa makeCUDAMEMPlan 
 * \sa initCUDAMEMPlan
 * \sa execCUDAMEMPlan
 * \sa perfCUDAMEMPlan
 * \sa killCUDAMEMPlan
*/
int parseCUDAMEMPlan(char *line, LoadPlan *output) {
	output->input_data = get_sizes(line);
	output->name = CUDAMEM;
	return (output->input_data->isize + output->input_data->csize + output->input_data->dsize > 0);
}
Пример #4
0
/**
 * \brief Reads the input file, and pulls out the necessary data for use in the plan
 * \param line The line of input text.
 * \param output The struct that holds the values for the load.
 * \return True if the data was read, false if it wasn't
 */
int parseOPENCL_MEMPlan(char *line, LoadPlan *output){  // <- Replace YOUR_NAME with the name of your module.
    output->input_data = get_sizes(line);
    output->name = OPENCLMEM;     // <- Replace YOUR_NAME with the name of your module.
    output->input_data;     // <- Change NUMBER_OF_YOUR_MEMBERS to equal however many int fields your data type holds.
    return output->input_data->isize + output->input_data->csize + output->input_data->dsize;     // <- Return flag to know whether the parsing succeeded or not. Do not change.
}
Пример #5
0
/**
 * \brief Reads the input file, and pulls out the necessary data for use in the plan
 * \param [in] line The input line for the plan.
 * \param [out] output Holds the data for the load.
 * \return int True if the data was read, false if it wasn't
 * \sa makeFFT2Plan
 * \sa initFFT2Plan
 * \sa execFFT2Plan
 * \sa perfFFT2Plan
 * \sa killFFT2Plan
 */
int parseFFT2Plan(char *line, LoadPlan *output){
    output->input_data = get_sizes(line);
    output->name = FFT2D;
    return (output->input_data->isize + output->input_data->csize + output->input_data->dsize > 0);
}