hist.c

Go to the documentation of this file.
00001 /****************************************************************************
00002 *
00003 * MODULE:       Vector library 
00004 *               
00005 * AUTHOR(S):    Radim Blazek
00006 *
00007 *
00008 * PURPOSE:      Higher level functions for reading/writing/manipulating vectors.
00009 *
00010 * COPYRIGHT:    (C) 2001 by the GRASS Development Team
00011 *
00012 *               This program is free software under the GNU General Public
00013 *               License (>=v2). Read the file COPYING that comes with GRASS
00014 *               for details.
00015 *
00016 *****************************************************************************/
00017 #include <stdlib.h>
00018 #include <stdio.h>
00019 #include <string.h>
00020 #include <grass/Vect.h>
00021 
00028 int 
00029 Vect_hist_command ( struct Map_info *Map )
00030 {
00031     char *cmd, buf[2000];
00032 
00033     G_debug (3, "Vect_hist_command()");
00034 
00035     cmd = G_recreate_command();
00036 
00037     Vect_hist_write ( Map, "COMMAND: " );
00038     Vect_hist_write ( Map, cmd );
00039     Vect_hist_write ( Map, "\n" );
00040 
00041     sprintf ( buf, "GISDBASE: %s\n", G_gisdbase()); /* Needed ?*/
00042     Vect_hist_write ( Map, buf );
00043 
00044     sprintf ( buf, "LOCATION: %s MAPSET: %s USER: %s DATE: %s\n", 
00045                     G_location(), G_mapset(), G_whoami(), G_date()); /* Needed ?*/
00046     Vect_hist_write ( Map, buf );
00047     
00048     return 0;
00049 }
00050 
00057 int 
00058 Vect_hist_write ( struct Map_info *Map, char *str )
00059 {
00060     int ret ;
00061     
00062     G_debug (5, "Vect_hist_write()");
00063     ret = fprintf ( Map->hist_fp, str ); 
00064     fflush ( Map->hist_fp );
00065 
00066     return ( ret ); 
00067 }
00068 
00077 char * 
00078 Vect_hist_read ( char *s, int size, struct Map_info *Map )
00079 {
00080     int ret;
00081     G_debug (5, "Vect_hist_read()");
00082 
00083     if ( Map->hist_fp == NULL ) return NULL; /* OK for shapefile etc. */
00084 
00085     ret = G_getl2 (s, size, Map->hist_fp);
00086 
00087     if ( ret == 1 ) return s;
00088 
00089     return NULL;
00090 }
00091 
00098 void 
00099 Vect_hist_rewind ( struct Map_info *Map )
00100 {
00101     G_debug (3, "Vect_hist_rewind()");
00102 
00103     if ( Map->hist_fp != NULL )
00104         rewind ( Map->hist_fp );
00105 }
00106 
00113 int 
00114 Vect_hist_copy ( struct Map_info *In, struct Map_info *Out )
00115 {
00116     size_t red, ret;
00117     char buf[1000];
00118     
00119     G_debug (3, "Vect_hist_copy()");
00120 
00121     if ( In->hist_fp == NULL ) return 0; /* This is correct (old hist doesn't exist) */
00122     if ( Out->hist_fp == NULL ) return -1; 
00123 
00124     fseek ( Out->hist_fp, (long)0, SEEK_END);
00125     rewind ( In->hist_fp );
00126 
00127     while ( (red = fread (buf, sizeof(char), sizeof(char)*1000, In->hist_fp)) ) {
00128         if ( !(ret = fwrite (buf, sizeof(char), red, Out->hist_fp))) {
00129             return (-1);
00130         }
00131         fflush ( Out->hist_fp );
00132     }
00133 
00134     /* In ends with \n ? */
00135     fseek ( In->hist_fp, (long)-1, SEEK_END);
00136     if ( fread ( buf, sizeof(char), sizeof(char), In->hist_fp) != 1 ) {
00137         return -1;
00138     }
00139 
00140     if ( buf[0] != '\n' ) {
00141         Vect_hist_write ( Out, "\n");
00142     }
00143 
00144     /* Separator */
00145     Vect_hist_write ( Out, "---------------------------------------------------------------------------------\n");
00146     return ( 0 ); 
00147 }
00148 

Generated on Sun Apr 6 17:32:44 2008 for GRASS by  doxygen 1.5.5