[digraphanalysis-cvs] digraphanalysis/src input.c, input.h, BSDmakefile, main.c, main.h,
Status: Planning
Brought to you by:
jbreker
|
From: Jeff B. <jb...@us...> - 2005-05-17 00:08:34
|
Update of /cvsroot/digraphanalysis/digraphanalysis/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29569 Modified Files: BSDmakefile main.c main.h Added Files: input.c input.h Log Message: +input.c input.h --- NEW FILE: input.h --- /* $Id: input.h,v 1.1 2005/05/17 00:08:06 jbreker Exp $ * * Copyright (C) 2005 Jeff Breker <jb...@sy...> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef _INPUT_H_ #define _INPUT_H_ #include "graph.h" char *get_field(void); void parse_input(struct graph *); #endif --- NEW FILE: input.c --- /* $Id: input.c,v 1.1 2005/05/17 00:08:06 jbreker Exp $ * * Copyright (C) 2005 Jeff Breker <jb...@sy...> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <stdio.h> #include <sysexits.h> #include "alias.h" #include "graph.h" #include "node.h" char * get_field(void) { char c; size_t size; char *string; size = 0; while(((c = getchar()) != ':') && (c != EOF)) { if(!isdigit(c)) errx(EX_DATAERR, "Invalid data input!\n"); size = size * 10; size = size + c - '0'; } if(c == EOF) errx(EX_DATAERR, "Unexpected termination of data input!\n"); string = (char *) malloc(++size); if(string != NULL) fgets(string, size, stdin); return string; } void parse_input(struct graph *graph) { struct alias *alias1; struct alias *alias2; char c; char *field1; char *field2; char *field3; struct node *node1; struct node *node2; struct node *node3; char type; for(c = type = getchar(); type == 'e' || type == 'n' || type == 'a'; c = type = getchar()) { if(((c = getchar()) != ':') && (c != EOF)) errx(EX_DATAERR, "1: Invalid character, %c (ASCII: %d), encountered!\n", c, c); if(c == EOF) break; if((field1 = get_field()) == NULL) errx(EX_OSERR, "Cannot allocate memory!\n"); if(*field1 == EOF) break; if(type != 'n') /* Grab 2nd field for edges and alias' */ { if(((c = getchar()) != ':') && (c != EOF)) errx(EX_DATAERR, "2: Invalid character, %c (ASCII: %d), encountered!\n", c, c); if(c == EOF) break; if((field2 = get_field()) == NULL) errx(EX_OSERR, "Cannot allocate memory!\n"); if(*field2 == EOF) break; if(type == 'a') /* Grab 3rd field for an alias */ { if(((c = getchar()) != ':') && (c != EOF)) errx(EX_DATAERR, "3: Invalid character, %c (ASCII: %d), encountered!\n", c, c); if(c == EOF) break; if((field3 = get_field()) == NULL) errx(EX_OSERR, "Cannot allocate memory!\n"); if(*field3 == EOF) break; } } if(((c = getchar()) != '\n') && (c != EOF)) errx(EX_DATAERR, "4: Invalid character, %c (ASCII: %d), encountered!\n", c, c); switch (type) { case 'a': node1 = node_new(field1); free(field1); if((node2 = nodelist_add(graph->node_list, node1)) != node1) node_free(node1); alias1 = alias_new(field2, field3, node2); free(field2); free(field3); if((alias2 = aliaslist_add(graph->alias_list, alias1)) != alias1) alias_free(alias1); break; case 'e': node1 = node_new(field1); free(field1); if((node2 = nodelist_add(graph->node_list, node1)) != node1) node_free(node1); node1 = node_new(field2); free(field2); if((node3 = nodelist_add(graph->node_list, node1)) != node1) node_free(node1); if((node1 = nodelist_add(node2->links, node3)) != node3) node_free(node3); break; /* a lines will eventually be renamed to n lines, when this happens * the following gets ripped out. */ case 'n': node1 = node_new(field1); free(field1); if((node2 = nodelist_add(graph->node_list, node1)) != node1) node_free(node1); break; } if(c == EOF) break; } if(c != EOF) errx(EX_DATAERR, "5: Invalid character, %c (ASCII: %d), encountered!\n", type, type); return; } Index: BSDmakefile =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/BSDmakefile,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BSDmakefile 16 May 2005 23:59:03 -0000 1.2 --- BSDmakefile 17 May 2005 00:08:06 -0000 1.3 *************** *** 18,21 **** --- 18,22 ---- SRCS= alias.c \ graph.c \ + input.c \ main.c \ node.c \ Index: main.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/main.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** main.c 16 May 2005 23:59:03 -0000 1.11 --- main.c 17 May 2005 00:08:06 -0000 1.12 *************** *** 132,162 **** } - char *get_field() - { - char c; - size_t size; - char *string; - - size = 0; - - while(((c = getchar()) != ':') && (c != EOF)) - { - if(!isdigit(c)) - errx(EX_DATAERR, "Invalid data input!\n"); - size = size * 10; - size = size + c - '0'; - } - - if(c == EOF) - errx(EX_DATAERR, "Unexpected termination of data input!\n"); - - string = (char *) malloc(++size); - - if(string != NULL) - fgets(string, size, stdin); - - return string; - } - /* DONE */ --- 132,135 ---- *************** *** 190,288 **** } - void parse_input(struct graph *graph) - { - struct alias *alias1; - struct alias *alias2; - char c; - char *field1; - char *field2; - char *field3; - struct node *node1; - struct node *node2; - struct node *node3; - char type; - - for(c = type = getchar(); type == 'e' || type == 'n' || type == 'a'; c = type = getchar()) - { - if(((c = getchar()) != ':') && (c != EOF)) - errx(EX_DATAERR, "1: Invalid character, %c (ASCII: %d), encountered!\n", c, c); - if(c == EOF) - break; - if((field1 = get_field()) == NULL) - errx(EX_OSERR, "Cannot allocate memory!\n"); - if(*field1 == EOF) - break; - if(type != 'n') /* Grab 2nd field for edges and alias' */ - { - if(((c = getchar()) != ':') && (c != EOF)) - errx(EX_DATAERR, "2: Invalid character, %c (ASCII: %d), encountered!\n", c, c); - if(c == EOF) - break; - if((field2 = get_field()) == NULL) - errx(EX_OSERR, "Cannot allocate memory!\n"); - if(*field2 == EOF) - break; - if(type == 'a') /* Grab 3rd field for an alias */ - { - if(((c = getchar()) != ':') && (c != EOF)) - errx(EX_DATAERR, "3: Invalid character, %c (ASCII: %d), encountered!\n", c, c); - if(c == EOF) - break; - if((field3 = get_field()) == NULL) - errx(EX_OSERR, "Cannot allocate memory!\n"); - if(*field3 == EOF) - break; - } - } - if(((c = getchar()) != '\n') && (c != EOF)) - errx(EX_DATAERR, "4: Invalid character, %c (ASCII: %d), encountered!\n", c, c); - - switch (type) - { - case 'a': - node1 = node_new(field1); - free(field1); - if((node2 = nodelist_add(graph->node_list, node1)) != node1) - node_free(node1); - alias1 = alias_new(field2, field3, node2); - free(field2); - free(field3); - if((alias2 = aliaslist_add(graph->alias_list, alias1)) != alias1) - alias_free(alias1); - break; - case 'e': - node1 = node_new(field1); - free(field1); - if((node2 = nodelist_add(graph->node_list, node1)) != node1) - node_free(node1); - node1 = node_new(field2); - free(field2); - if((node3 = nodelist_add(graph->node_list, node1)) != node1) - node_free(node1); - if((node1 = nodelist_add(node2->links, node3)) != node3) - node_free(node3); - break; - /* a lines will eventually be renamed to n lines, when this happens - * the following gets ripped out. - */ - case 'n': - node1 = node_new(field1); - free(field1); - if((node2 = nodelist_add(graph->node_list, node1)) != node1) - node_free(node1); - break; - } - - - if(c == EOF) - break; - } - - if(c != EOF) - errx(EX_DATAERR, "5: Invalid character, %c (ASCII: %d), encountered!\n", type, type); - - return; - } - void usage(void) { --- 163,166 ---- Index: main.h =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/main.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** main.h 16 May 2005 23:59:03 -0000 1.5 --- main.h 17 May 2005 00:08:06 -0000 1.6 *************** *** 29,34 **** struct graphlist *analysis_seperate_nodes(struct graph *); int do_analysis(struct graph *, char *); - char *get_field(void); - void parse_input(struct graph *); void usage(void); --- 29,32 ---- |