SAI ||
Sommersemester 1997 ||
Systemnahe Software II ||
Übungen
<- Alle Module
Lösung zu Blatt 2 (Aufgabe 2): ksmain.c
Hauptprogramm: Aufruf von multisearch mit dem
Knapsack-Algorithmus als Parameter.
/*
* ksmain.c - main function for knapsack searching.
*
* Martin Hasch, University of Ulm, April 1997
*/
#include <stdio.h>
#include <stdlib.h>
#include "typedef.h"
#include "knapsack.h"
#include "msearch.h"
static char *cmdname; /* first argv component */
/*
* Display usage and exit.
*/
static void usage(void)
{
fprintf(stderr, "Usage: %s code processes timeout\n", cmdname);
exit(EXIT_FAILURE);
}
/*
* Translate given string argument into a number.
* Call usage() in case of failure.
*/
static unsigned long getarg(char *arg)
{
char *rest;
unsigned long result;
result = strtoul(arg, &rest, 0);
if ( *rest )
usage();
return result;
}
/*
* Process command line into appropriate call of multisearch.
*/
int main(int argc, char *argv[])
{
Code code;
unsigned nproc;
unsigned timeout;
cmdname = argv[0];
if ( argc != 4 )
usage();
code = getarg(argv[1]);
nproc = getarg(argv[2]);
timeout = getarg(argv[3]);
multisearch(code, 0L, ks_maxkey(), knapsack, nproc, timeout);
exit(EXIT_SUCCESS);
}
<- Alle Module
SAI ||
Sommersemester 1997 ||
Systemnahe Software II ||
Übungen
Martin Hasch, Mai 1997