aboutsummaryrefslogtreecommitdiff
path: root/rat2canon.c
diff options
context:
space:
mode:
authorbremner <bremner@09fa754a-f411-0410-976a-da6bfa213b30>2006-07-11 11:15:06 +0000
committerbremner <bremner@09fa754a-f411-0410-976a-da6bfa213b30>2006-07-11 11:15:06 +0000
commitf2f3ec70cd3c86583c1eb03b0da63f74b6aefe05 (patch)
treeb7ca132811f02c0d88df78ccfa938cbb74d6086b /rat2canon.c
parent8f05bec6673c1d3e7fdce52e305b712bd6f989ac (diff)
git-svn-id: file:///export/data/bremner/svn/trunk/inetools@5464 09fa754a-f411-0410-976a-da6bfa213b30
Diffstat (limited to 'rat2canon.c')
-rw-r--r--rat2canon.c50
1 files changed, 8 insertions, 42 deletions
diff --git a/rat2canon.c b/rat2canon.c
index bc38132..4225462 100644
--- a/rat2canon.c
+++ b/rat2canon.c
@@ -51,62 +51,26 @@ int main(argc,argv)
char **argv;
{
int i,j;
-
-
char format[BUFSIZ];
- char buf[BUFSIZ];
-
-
- char *cursor;
-
+ char *ok[]={ "integer", "rational" };
+ char *type;
+ char buf[BUFSIZ];
process_args(argc,argv,DOCSTRING);
-
-
lrs_mp_init (MP_DIGITS,stdin,stdout);
- while ( fgets(buf,BUFSIZ,stdin) !=NULL )
- {
- fputs(buf,stdout);
- for (cursor=buf; isblank(*cursor); cursor++);
- if (strncmp(cursor,"begin",5)==0) break;
- }
-
- if (fgets(buf,BUFSIZ,stdin)==NULL) {
- fprintf(stderr,"No parameter line");
- exit(1);
- }
+ scan_for_begin(&m,&n,&type);
+ check_type(type, ok, 2);
- m=strtol(buf,&cursor,10);
- if (errno==ERANGE || m==0){
- fprintf(stderr,"Missing or absurd row count");
- exit(1);
- }
-
An=calloc(m,sizeof(lrs_mp*));
Ad=calloc(m,sizeof(lrs_mp*));
rows=calloc(m,sizeof(int));
- n=strtol(cursor,&cursor,10);
- if (errno==ERANGE || m==0){
- fprintf(stderr,"Missing or absurd column count");
- exit(1);
- }
for (i=0; i<m; i++){
rows[i]=i;
An[i]=calloc(n,sizeof(lrs_mp));
Ad[i]=calloc(n,sizeof(lrs_mp));
}
-
- while (isblank(*cursor)){
- cursor++;
- }
-
- if (strncmp(cursor,"integer",7) != 0 && strncmp(cursor,"rational",8)){
- fprintf(stderr,"oops. I don't know what to do with a file of type %s\n",
- cursor);
- exit(1);
- }
printf("%ld %ld rational\n",m,n);
@@ -164,9 +128,11 @@ int main(argc,argv)
}
}
+ {
- fgets(buf,BUFSIZ,stdin); /* clean off last line */
+ fgets(buf,BUFSIZ,stdin); /* clean off last line */
+ }
qsort(rows,m,sizeof(int), cmprow);
for (i=0; i< m; i++){