Skip to content

Commit

Permalink
These files have been added to enforce the "one class per file" rule.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Vitter committed Dec 21, 2008
1 parent 3d87992 commit 423339f
Show file tree
Hide file tree
Showing 4 changed files with 410 additions and 0 deletions.
22 changes: 22 additions & 0 deletions apps/matrix/app_config.cpp
@@ -0,0 +1,22 @@
// Copyright (c) 1994 Darren Erik Vengroff
//
// File: app_config.cpp
// Author: Darren Erik Vengroff <darrenv@eecs.umich.edu>
// Created: 10/7/94
//




#include "app_config.h"

#ifdef NDEBUG
bool verbose = false;
#else
bool verbose = true;
#endif

TPIE_OS_SIZE_T test_mm_size = DEFAULT_TEST_MM_SIZE;
TPIE_OS_OFFSET test_size = DEFAULT_TEST_SIZE;
int random_seed = 17;

147 changes: 147 additions & 0 deletions apps/matrix/app_config.h
@@ -0,0 +1,147 @@
//
// File: app_config.h
// Authors: Darren Erik Vengroff
// Octavian Procopiuc <tavi@cs.duke.edu>
//
// Created: 10/6/94
//
// $Id: app_config.h,v 1.36 2004-08-17 16:49:16 jan Exp $
//
#ifndef _APP_CONFIG_H
#define _APP_CONFIG_H

// Get the configuration as set up by the TPIE configure script.
#include <tpie/config.h>

// <><><><><><><><><><><><><><><><><><><><><><> //
// <><><><><><><> Developer use <><><><><><><> //
// <><><><><><><><><><><><><><><><><><><><><><> //

// Set up some defaults for the test applications

#include <tpie/portability.h>
#include <sys/types.h> // for size_t
#include <cstdlib> // for random()

#define DEFAULT_TEST_SIZE (20000000)
#define DEFAULT_RANDOM_SEED 17
#define DEFAULT_TEST_MM_SIZE (1024 * 1024 * 32)

extern bool verbose;
extern TPIE_OS_SIZE_T test_mm_size;
extern TPIE_OS_OFFSET test_size;
extern int random_seed;


// <><><><><><><><><><><><><><><><><><><><><><> //
// <><><> Choose default BTE COLLECTION <><><> //
// <><><><><><><><><><><><><><><><><><><><><><> //

#if (!defined(BTE_COLLECTION_IMP_MMAP) && !defined(BTE_COLLECTION_IMP_UFS) && !defined(BTE_COLLECTION_IMP_USER_DEFINED))
// Define only one (default is BTE_COLLECTION_IMP_MMAP)
#define BTE_COLLECTION_IMP_MMAP
//#define BTE_COLLECTION_IMP_UFS
//#define BTE_COLLECTION_IMP_USER_DEFINED
#endif

// <><><><><><><><><><><><><><><><><><><><><><> //
// <><><><><><> Choose BTE STREAM <><><><><><> //
// <><><><><><><><><><><><><><><><><><><><><><> //

// Define only one (default is BTE_STREAM_IMP_UFS)
#define BTE_STREAM_IMP_UFS
//#define BTE_STREAM_IMP_MMAP
//#define BTE_STREAM_IMP_STDIO
//#define BTE_STREAM_IMP_USER_DEFINED


// <><><><><><><><><><><><><><><><><><><><><><><><> //
// <> BTE_COLLECTION_MMAP configuration options <> //
// <><><><><><><><><><><><><><><><><><><><><><><><> //

// Define write behavior.
// Allowed values:
// 0 (synchronous writes)
// 1 (asynchronous writes using MS_ASYNC - see msync(2))
// 2 (asynchronous bulk writes) [default]
#ifndef BTE_COLLECTION_MMAP_LAZY_WRITE
#define BTE_COLLECTION_MMAP_LAZY_WRITE 2
#endif

// <><><><><><><><><><><><><><><><><><><><><><><><> //
// <> BTE_COLLECTION_UFS configuration options <> //
// <><><><><><><><><><><><><><><><><><><><><><><><> //



// <><><><><><><><><><><><><><><><><><><><><><><><> //
// <><> BTE_STREAM_MMAP configuration options <><> //
// <><><><><><><><><><><><><><><><><><><><><><><><> //

#ifdef BTE_STREAM_IMP_MMAP
// Define logical blocksize factor (default is 32)
#ifndef BTE_STREAM_MMAP_BLOCK_FACTOR
#ifdef _WIN32
#define BTE_STREAM_MMAP_BLOCK_FACTOR 4
#else
#define BTE_STREAM_MMAP_BLOCK_FACTOR 32
#endif
#endif

// Enable/disable TPIE read ahead; default is enabled (set to 1)
//#define BTE_STREAM_MMAP_READ_AHEAD 1

// read ahead method, ignored unless BTE_STREAM_MMAP_READ_AHEAD is set
// to 1; if USE_LIBAIO is enabled, use asynchronous IO read ahead;
// otherwise use use mmap-based read ahead; default is mmap-based read
// ahead (USE_LIBAIO not defined)

//#define USE_LIBAIO
#endif


// <><><><><><><><><><><><><><><><><><><><><><><><> //
// <><> BTE_STREAM_UFS configuration options <><><> //
// <><><><><><><><><><><><><><><><><><><><><><><><> //

#ifdef BTE_STREAM_IMP_UFS
// Define logical blocksize factor (default is 32)
#ifndef STREAM_UFS_BLOCK_FACTOR
#ifdef _WIN32
#define STREAM_UFS_BLOCK_FACTOR 4
#else
#define STREAM_UFS_BLOCK_FACTOR 32
#endif
#endif

// Enable/disable TPIE read ahead; default is disabled (set to 0)
#define STREAM_UFS_READ_AHEAD 0
// read ahead method, ignored unless STREAM_UFS_READ_AHEAD is set
// to 1; if USE_LIBAIO is set to 1, use asynchronous IO read ahead;
// otherwise no TPIE read ahead is done; default is disabled (set to 0)
#define USE_LIBAIO 0
#endif


// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> //
// logging and assertions; //
// this should NOT be modified by user!!! //
// in order to enable/disable library/application logging, //
// run tpie configure script with appropriate options //
// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> //

// Use logs if requested.
#if TP_LOG_APPS
#define TPL_LOGGING 1
#endif

#include <tpie/tpie_log.h>

// Enable assertions if requested.
#if TP_ASSERT_APPS
#define DEBUG_ASSERTIONS 1
#endif

#include <tpie/tpie_assert.h>

#endif
178 changes: 178 additions & 0 deletions apps/matrix/getopts.cpp
@@ -0,0 +1,178 @@
// Modified and added to the TPIE distribution in April 2003 by
// Octavian Procopiuc <tavi@cs.duke.edu>

/* getopts.cpp - Command line argument parser
*
* Whom: Steve Mertz <steve@dragon-ware.com>
* Date: 20010111
* Why: Because I couldn't find one that I liked. So I wrote this one.
*
*/
/*
* Copyright (c) 2001, 2002, Steve Mertz <steve@dragon-ware.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of Dragon Ware nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <cstdio>
#include <cstdlib>
#include <string.h>

#include "getopts.h"

int option_index = 1;
/* int getopts_usage()
*
* Returns: 1 - Successful
*/
int getopts_usage(char *progName, struct options opts[]) {

size_t count;
size_t i;
char *cmd=NULL;
TPIE_OS_SIZE_T optlen = 30;

printf("Usage: %s [options]\nOptions:\n", progName);
printf(" --help, -h ");
for (i = 11; i < optlen; i++) {
printf(" ");
}
printf("Display this information.\n");
for (count = 0; opts[count].description; count++) {
if (opts[count].name && opts[count].shortName) {
cmd = reinterpret_cast<char*>(calloc(1, strlen(opts[count].name) + strlen(opts[count].shortName) + optlen));
if (opts[count].args) {
sprintf(cmd, "--%s, -%s <args> ", opts[count].name, opts[count].shortName);
} else {
sprintf(cmd, "--%s, -%s ", opts[count].name, opts[count].shortName);
}
} else if (opts[count].name) {
cmd = reinterpret_cast<char*>(calloc(1, strlen(opts[count].name) + optlen));
if (opts[count].args) {
sprintf(cmd, "--%s <args> ", opts[count].name);
} else {
sprintf(cmd, "--%s ", opts[count].name);
}
} else if (opts[count].shortName) {
cmd = reinterpret_cast<char*>(calloc(1, strlen(opts[count].shortName) + optlen));
if (opts[count].args) {
sprintf(cmd, "-%s <args> ", opts[count].shortName);
} else {
sprintf(cmd, "-%s ", opts[count].shortName);
}
}
for (i = strlen(cmd); i < optlen; i++) {
cmd[i] = ' ';
}
printf(" %s%s\n", cmd, opts[count].description);
free(cmd);
}
return 1;
}

/* int getopts()
*
* Returns: -1 - Couldn't allocate memory. Please handle me.
* 0 - No arguements to parse
* # - The number in the struct for the matched arg.
*
*/
int getopts(int argc, char **argv, struct options opts[], char **args)
{
int count1;
size_t sizeOfArgs;

if (argc == 1 || option_index == argc)
return 0;

/* Search for '-h' or '--help' first. Then we can just exit */
for (count1 = 1; count1 < argc; count1++)
{
if (!strcmp(argv[count1], "-h") || !strcmp(argv[count1], "--help"))
{
useage:
getopts_usage(argv[0], opts);
exit(0);
}
}
/* End of -h --help section */
*args = NULL;
if (option_index <= argc)
{
for (count1 = 0; opts[count1].description; count1++)
{
if ((opts[count1].name && !strcmp(opts[count1].name,
(argv[option_index]+2))) ||
(opts[count1].shortName && !strcmp(opts[count1].shortName,
(argv[option_index]+1))))
{
if (opts[count1].args)
{
option_index++;
if (option_index >= argc)
goto useage;
/* This grossness that follows is to supporte having a '-' in the
argument. It's all squished together like this because I use
an 80 char wide screen for my coding. If you don't like it, help
yourself to fixing it so you do. */
if (*argv[option_index] == '-')
{
int optionSeeker;
for (optionSeeker = 0; opts[optionSeeker].description;
optionSeeker++)
{
if ((opts[optionSeeker].name &&
!strcmp(opts[optionSeeker].name,
(argv[option_index]+2))) ||
(opts[optionSeeker].shortName &&
!strcmp(opts[optionSeeker].shortName,
(argv[option_index]+1))))
{
goto useage;
}
}
/* End of gross hack for supporting '-' in arguments. */
}
sizeOfArgs = strlen(argv[option_index]);
if ((*args = reinterpret_cast<char*>(calloc(1, sizeOfArgs+1))) == NULL)
return -1;
strncpy(*args, argv[option_index], sizeOfArgs);
}
option_index++;
return opts[count1].number;
}
}
}
return 0;
}






0 comments on commit 423339f

Please sign in to comment.