home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume8 / graph+ / part03 / project.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-01  |  1018 b   |  46 lines

  1. /*
  2.  * Copyright (C) 1986   Alan Kent
  3.  *
  4.  * Permission is granted to freely distribute part or
  5.  * all of this code as long as it is not for profit
  6.  * and this message is retained in the code.
  7.  *
  8.  * No resposibility is taken for any damage or incorect
  9.  * results this program generates.
  10.  * 
  11.  */
  12.  
  13.  
  14. #include <stdio.h>
  15. #include "graph.h"
  16.  
  17.  
  18. extern table_st *new_table ();
  19. extern double eval ();
  20.  
  21.  
  22. table_st *
  23. project ( table , attr_expr_list )
  24. table_st *table;
  25. expr_list_st *attr_expr_list;
  26. {
  27.     table_st *newtab , *p;
  28.     expr_list_st *list;
  29.     int count;
  30.     int i;
  31.  
  32.     if ( table == NULL )
  33.     abort ( "cannot project on an empty table" );
  34.     count = 0;
  35.     for ( list = attr_expr_list; list != NULL; list = list->next )
  36.     count++;
  37.     newtab = new_table ( count , table->size );
  38.     for ( list = attr_expr_list , p = newtab; list != NULL; list = list->next , p = p->next ) {
  39.     for ( i = 0; i < table->size; i++ )
  40.         p->data[i] = eval ( table , i , list->expr );
  41.     }
  42.     free_table ( table );
  43.     return ( newtab );
  44. }
  45.  
  46.