aboutsummaryrefslogtreecommitdiff
path: root/countrows.c
diff options
context:
space:
mode:
authorbremner <bremner@09fa754a-f411-0410-976a-da6bfa213b30>2006-06-01 18:56:34 +0000
committerbremner <bremner@09fa754a-f411-0410-976a-da6bfa213b30>2006-06-01 18:56:34 +0000
commit7a583e3a287eb468e82e6509b467b6701e50dade (patch)
tree5c8ef119ec7f7653fb10f6957e2c1b622e95aa53 /countrows.c
parent98fb9daefbb8afd80c20525782cdefa86d13e92c (diff)
git-svn-id: file:///export/data/bremner/svn/trunk/inetools@5359 09fa754a-f411-0410-976a-da6bfa213b30
Diffstat (limited to 'countrows.c')
-rw-r--r--countrows.c114
1 files changed, 114 insertions, 0 deletions
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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <float.h>
+#include <errno.h>
+#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<m;i++)
+ fputs(lines[i],stdout);
+
+ fputs("end\n",stdout);
+}
+
+
+
+
+
+