home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume8 / graph+ / part03 / printtab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-01  |  1.7 KB  |  99 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 double eval ();
  19.  
  20.  
  21.  
  22. print_table ( table , filename , mode )
  23. table_st *table;
  24. char *filename , *mode;
  25. {
  26.     table_st *p;
  27.     int i;
  28.     int cols;
  29.     FILE *fp;
  30.  
  31.  
  32.     if ( filename == NULL )
  33.     fp = stdout;
  34.     else {
  35.     fp = fopen ( filename , mode );
  36.     if ( fp == NULL )
  37.         abort ( "failed to open print file '%s'" , filename );
  38.     }
  39.     if ( table == NULL ) {
  40.     fprintf ( fp , "empty table\n" );
  41.     }
  42.     else {
  43.     cols = 0;
  44.     for ( p = table; p != NULL; p = p->next )
  45.         cols++;
  46.     for ( i = 0; i < table->size; i++ ) {
  47.         for ( p = table; p != NULL; p = p->next ) {
  48.         fprintf ( fp , "%g" , p->data[i] );
  49.         if ( p->next != NULL )
  50.             fprintf ( fp , "\t" );
  51.         }
  52.         fprintf ( fp , "\n" );
  53.     }
  54.     }
  55.     if ( fp != stdout )
  56.     fclose ( fp );
  57. }
  58.  
  59.  
  60.  
  61. print_expr ( value , filename , mode )
  62. double value;
  63. char *filename , *mode;
  64. {
  65.     FILE *fp;
  66.  
  67.     if ( filename == NULL )
  68.     fp = stdout;
  69.     else {
  70.     fp = fopen ( filename , mode );
  71.     if ( fp == NULL )
  72.         abort ( "failed to open print file '%s'" , filename );
  73.     }
  74.     fprintf ( fp , "%g\n" , value );
  75.     if ( fp != stdout )
  76.     fclose ( fp );
  77. }
  78.  
  79.  
  80.  
  81. print_string ( string , filename , mode )
  82. char *string;
  83. char *filename , *mode;
  84. {
  85.     FILE *fp;
  86.  
  87.     if ( filename == NULL )
  88.     fp = stdout;
  89.     else {
  90.     fp = fopen ( filename , mode );
  91.     if ( fp == NULL )
  92.         abort ( "failed to open print file '%s'" , filename );
  93.     }
  94.     fprintf ( fp , "%s\n" , string );
  95.     if ( fp != stdout )
  96.     fclose ( fp );
  97. }
  98.  
  99.