From 7a583e3a287eb468e82e6509b467b6701e50dade Mon Sep 17 00:00:00 2001 From: bremner Date: Thu, 1 Jun 2006 18:56:34 +0000 Subject: git-svn-id: file:///export/data/bremner/svn/trunk/inetools@5359 09fa754a-f411-0410-976a-da6bfa213b30 --- countrows.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 countrows.c (limited to 'countrows.c') diff --git a/countrows.c b/countrows.c new file mode 100644 index 0000000..9120827 --- /dev/null +++ b/countrows.c @@ -0,0 +1,114 @@ +/* + * Reads a polyhedron file on stdin, counts the rows, and outputs + * an equivalent file with a corrected row count. + * + * David Bremner. bremner@cs.unb.ca + * + */ + +static char rcsid[]="$Id: rat2float.c 2343 2006-04-04 12:34:35Z bremner $"; + +#ifndef LRSMP +#error This file only compiles with LRSMP +#endif + +#include +#include +#include +#include +#include +#include "lrsmp.h" + + + +typedef lrs_mp integer_t; +#define MP_DIGITS 1000L + + +#include "countrows.ds" + + +int main(argc,argv) + int argc; + char **argv; +{ + int i,j; + long int m,n; + + char **lines; + int line_count; + char buf[BUFSIZ]; + + char *type; + char *cursor; + + + CHECK_HELP; + + lrs_mp_init (MP_DIGITS,stdin,stdout); + + while ( fgets(buf,BUFSIZ,stdin) !=NULL ) { + fputs(buf,stdout); + if (strncmp(buf,"begin",5)==0) break; + } + + if (fgets(buf,BUFSIZ,stdin)==NULL) { + fprintf(stderr,"No parameter line"); + exit(1); + } + + cursor=buf; + + while(isspace(*cursor)) + cursor++; + + while (!isspace(*cursor)) + cursor++; + + n=strtol(cursor,&cursor,10); + if (errno==ERANGE || n==0){ + fprintf(stderr,"Missing or absurd column count"); + exit(1); + } + + line_count=2*n; + lines=calloc(line_count,sizeof(char *)); + + while (isblank(*cursor)){ + cursor++; + } + + type=strdup(cursor); + + m=0; + do { + if (fgets(buf,BUFSIZ,stdin)==NULL) { + fprintf(stderr,"missing end"); + exit(1); + } + if (strncmp(buf,"end",3)!=0){ + if (m>=line_count){ + line_count *=2; + lines=realloc(lines,line_count*sizeof(char *)); + } + + lines[m++]=strdup(buf); + } + + } while (strncmp(buf,"end",3)!=0); + + + + printf("%ld %ld %s",m,n,type); + + for (i=0;i