Bladeren bron

Add "const" to vector functions
Remove "const" from G__ls() etc
Miscellaneous clean-up


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@31990 15284696-431f-4ddb-bdfa-cd5b030d7da7

Glynn Clements 17 jaren geleden
bovenliggende
commit
5aa48b848a

+ 45 - 45
include/Vect.h

@@ -45,37 +45,37 @@ int Vect_get_line_cat ( struct Map_info *, int, int );
 
 
       /* List of categories */
       /* List of categories */
 struct cat_list *Vect_new_cat_list (void);
 struct cat_list *Vect_new_cat_list (void);
-int Vect_str_to_cat_list (char *, struct cat_list *);
+int Vect_str_to_cat_list (const char *, struct cat_list *);
 int Vect_array_to_cat_list (int *, int, struct cat_list *);
 int Vect_array_to_cat_list (int *, int, struct cat_list *);
 int Vect_cat_in_cat_list (int, struct cat_list *);
 int Vect_cat_in_cat_list (int, struct cat_list *);
 int Vect_destroy_cat_list (struct cat_list *);
 int Vect_destroy_cat_list (struct cat_list *);
 
 
       /* Vector array */
       /* Vector array */
 VARRAY *Vect_new_varray (int size);
 VARRAY *Vect_new_varray (int size);
-int Vect_set_varray_from_cat_string ( struct Map_info *, int, char *, int, int, VARRAY *);
+int Vect_set_varray_from_cat_string ( struct Map_info *, int, const char *, int, int, VARRAY *);
 int Vect_set_varray_from_cat_list ( struct Map_info *, int, struct cat_list *, int, int, VARRAY *);
 int Vect_set_varray_from_cat_list ( struct Map_info *, int, struct cat_list *, int, int, VARRAY *);
-int Vect_set_varray_from_db ( struct Map_info *, int, char *, int, int, VARRAY *);
+int Vect_set_varray_from_db ( struct Map_info *, int, const char *, int, int, VARRAY *);
 
 
      /* DB connection - field info */
      /* DB connection - field info */
 struct dblinks *Vect_new_dblinks_struct ( void );
 struct dblinks *Vect_new_dblinks_struct ( void );
 void Vect_reset_dblinks ( struct dblinks *p );
 void Vect_reset_dblinks ( struct dblinks *p );
-int Vect_add_dblink ( struct dblinks *p, int number, char *name, char *table, char *key, 
-	              char *db, char *driver );
+int Vect_add_dblink ( struct dblinks *p, int number, const char *name, const char *table, const char *key, 
+	              const char *db, const char *driver );
 int Vect_check_dblink ( struct dblinks *p, int field );
 int Vect_check_dblink ( struct dblinks *p, int field );
-int Vect_map_add_dblink ( struct Map_info *, int number, char *name, char *table, char *key, 
-	              char *db, char *driver );
+int Vect_map_add_dblink ( struct Map_info *, int number, const char *name, const char *table, const char *key, 
+	              const char *db, const char *driver );
 int Vect_map_del_dblink ( struct Map_info *, int number ); 
 int Vect_map_del_dblink ( struct Map_info *, int number ); 
 int Vect_map_check_dblink ( struct Map_info *, int field);
 int Vect_map_check_dblink ( struct Map_info *, int field);
 int Vect_read_dblinks ( struct Map_info * );
 int Vect_read_dblinks ( struct Map_info * );
 int Vect_write_dblinks ( struct Map_info * );
 int Vect_write_dblinks ( struct Map_info * );
 struct field_info *Vect_default_field_info ( struct Map_info *Map, int  field, 
 struct field_info *Vect_default_field_info ( struct Map_info *Map, int  field, 
-	                char *field_name, int  type );
+	                const char *field_name, int  type );
 struct field_info *Vect_get_dblink (  struct Map_info *Map, int link );
 struct field_info *Vect_get_dblink (  struct Map_info *Map, int link );
 struct field_info *Vect_get_field (  struct Map_info *Map, int field );
 struct field_info *Vect_get_field (  struct Map_info *Map, int field );
 void Vect_set_db_updated ( struct Map_info *Map );
 void Vect_set_db_updated ( struct Map_info *Map );
-char *Vect_get_column_names (struct Map_info *Map, int field);
-char *Vect_get_column_types (struct Map_info *Map, int field);
-char *Vect_get_column_names_types (struct Map_info *Map, int field);
+const char *Vect_get_column_names (struct Map_info *Map, int field);
+const char *Vect_get_column_types (struct Map_info *Map, int field);
+const char *Vect_get_column_names_types (struct Map_info *Map, int field);
 
 
       /* List of FID (feature ID) (integers) */
       /* List of FID (feature ID) (integers) */
 struct ilist *Vect_new_list (void);
 struct ilist *Vect_new_list (void);
@@ -122,28 +122,28 @@ int Vect_cidx_open ( struct Map_info *, int);
     /* Set/get Map header info */
     /* Set/get Map header info */
 int  Vect_read_header (struct Map_info *);
 int  Vect_read_header (struct Map_info *);
 int  Vect_write_header (struct Map_info *);
 int  Vect_write_header (struct Map_info *);
-char *Vect_get_name (struct Map_info *);
-char *Vect_get_mapset (struct Map_info *);
-char *Vect_get_full_name (struct Map_info *);
+const char *Vect_get_name (struct Map_info *);
+const char *Vect_get_mapset (struct Map_info *);
+const char *Vect_get_full_name (struct Map_info *);
 int  Vect_is_3d (struct Map_info *);
 int  Vect_is_3d (struct Map_info *);
-int  Vect_set_organization (struct Map_info *, char *);
-char *Vect_get_organization (struct Map_info *);
-int  Vect_set_date (struct Map_info *, char *);
-char *Vect_get_date (struct Map_info *);
-int  Vect_set_person (struct Map_info *, char *);
-char *Vect_get_person (struct Map_info *);
-int  Vect_set_map_name (struct Map_info *, char *);
-char *Vect_get_map_name (struct Map_info *);
-int  Vect_set_map_date (struct Map_info *, char *);
-char *Vect_get_map_date (struct Map_info *);
-int  Vect_set_comment (struct Map_info *, char *);
-char *Vect_get_comment (struct Map_info *);
+int  Vect_set_organization (struct Map_info *, const char *);
+const char *Vect_get_organization (struct Map_info *);
+int  Vect_set_date (struct Map_info *, const char *);
+const char *Vect_get_date (struct Map_info *);
+int  Vect_set_person (struct Map_info *, const char *);
+const char *Vect_get_person (struct Map_info *);
+int  Vect_set_map_name (struct Map_info *, const char *);
+const char *Vect_get_map_name (struct Map_info *);
+int  Vect_set_map_date (struct Map_info *, const char *);
+const char *Vect_get_map_date (struct Map_info *);
+int  Vect_set_comment (struct Map_info *, const char *);
+const char *Vect_get_comment (struct Map_info *);
 int  Vect_set_scale (struct Map_info *, int );
 int  Vect_set_scale (struct Map_info *, int );
 int  Vect_get_scale (struct Map_info *);
 int  Vect_get_scale (struct Map_info *);
 int  Vect_set_zone (struct Map_info *, int );
 int  Vect_set_zone (struct Map_info *, int );
 int  Vect_get_zone (struct Map_info *);
 int  Vect_get_zone (struct Map_info *);
 int  Vect_get_proj (struct Map_info *);
 int  Vect_get_proj (struct Map_info *);
-char *Vect_get_proj_name (struct Map_info *);
+const char *Vect_get_proj_name (struct Map_info *);
 int  Vect_set_thresh (struct Map_info *, double );
 int  Vect_set_thresh (struct Map_info *, double );
 double Vect_get_thresh (struct Map_info *);
 double Vect_get_thresh (struct Map_info *);
 int Vect_get_constraint_box ( struct Map_info *, BOUND_BOX *);
 int Vect_get_constraint_box ( struct Map_info *, BOUND_BOX *);
@@ -171,14 +171,14 @@ int Vect_set_fatal_error (int);
 int Vect_get_fatal_error ();
 int Vect_get_fatal_error ();
 
 
     /* Open/close/rewind/set_constraints for map */
     /* Open/close/rewind/set_constraints for map */
-int Vect_check_input_output_name(char *, char *, int);
-int Vect_legal_filename(char *);
+int Vect_check_input_output_name(const char *, const char *, int);
+int Vect_legal_filename(const char *);
 int Vect_set_open_level (int);
 int Vect_set_open_level (int);
-int Vect_open_old (struct Map_info *, char *, char *);
-int Vect_open_old_head (struct Map_info *, char *, char *);
-int Vect_open_new (struct Map_info *, char *, int);
-int Vect_open_update (struct Map_info *, char *, char *);
-int Vect_open_update_head ( struct Map_info *, char *, char *);
+int Vect_open_old (struct Map_info *, const char *, const char *);
+int Vect_open_old_head (struct Map_info *, const char *, const char *);
+int Vect_open_new (struct Map_info *, const char *, int);
+int Vect_open_update (struct Map_info *, const char *, const char *);
+int Vect_open_update_head ( struct Map_info *, const char *, const char *);
 int Vect_copy_head_data (struct Map_info *, struct  Map_info *);
 int Vect_copy_head_data (struct Map_info *, struct  Map_info *);
 int Vect_build ( struct Map_info *, FILE *);
 int Vect_build ( struct Map_info *, FILE *);
 int Vect_get_built ( struct Map_info *Map );
 int Vect_get_built ( struct Map_info *Map );
@@ -234,7 +234,7 @@ int Vect_get_updated_node (struct Map_info *map, int idx);
 
 
       /* History */
       /* History */
 int Vect_hist_command ( struct Map_info *Map );
 int Vect_hist_command ( struct Map_info *Map );
-int Vect_hist_write ( struct Map_info *Map, char *str );
+int Vect_hist_write ( struct Map_info *Map, const char *str );
 int Vect_hist_copy ( struct Map_info *In, struct Map_info *Out );
 int Vect_hist_copy ( struct Map_info *In, struct Map_info *Out );
 void Vect_hist_rewind ( struct Map_info *Map );
 void Vect_hist_rewind ( struct Map_info *Map );
 char *Vect_hist_read ( char *s, int size, struct Map_info *Map );
 char *Vect_hist_read ( char *s, int size, struct Map_info *Map );
@@ -287,7 +287,7 @@ int Vect_clean_small_angles_at_nodes ( struct Map_info *Map, int type, struct Ma
 	                               FILE *msgout);
 	                               FILE *msgout);
 
 
     /* Overlay */
     /* Overlay */
-int Vect_overlay_str_to_operator ( char * );
+int Vect_overlay_str_to_operator ( const char * );
 int Vect_overlay ( struct Map_info *, int, struct ilist *, struct ilist *, 
 int Vect_overlay ( struct Map_info *, int, struct ilist *, struct ilist *, 
 	           struct Map_info *, int, struct ilist *, struct ilist *,
 	           struct Map_info *, int, struct ilist *, struct ilist *,
                    int, struct Map_info *);
                    int, struct Map_info *);
@@ -300,7 +300,7 @@ void Vect_graph_set_node_costs ( GRAPH *, int, double);
 int Vect_graph_shortest_path ( GRAPH *, int, int, struct ilist *, double * );
 int Vect_graph_shortest_path ( GRAPH *, int, int, struct ilist *, double * );
 
 
     /* Network (graph) */
     /* Network (graph) */
-int Vect_net_build_graph ( struct Map_info *, int, int, int, char *, char *, char *, int, int);
+int Vect_net_build_graph ( struct Map_info *, int, int, int, const char *, const char *, const char *, int, int);
 int Vect_net_shortest_path ( struct Map_info *, int, int, struct ilist *, double *);
 int Vect_net_shortest_path ( struct Map_info *, int, int, struct ilist *, double *);
 int Vect_net_get_line_cost ( struct Map_info *, int, int, double *);
 int Vect_net_get_line_cost ( struct Map_info *, int, int, double *);
 int Vect_net_get_node_cost ( struct Map_info *, int, double *);
 int Vect_net_get_node_cost ( struct Map_info *, int, double *);
@@ -316,12 +316,12 @@ int Vect_topo_dump ( struct Map_info *, FILE *);
 double Vect_points_distance ( double, double, double, double, double, double, int);
 double Vect_points_distance ( double, double, double, double, double, double, int);
 int Vect_option_to_types (struct Option *);
 int Vect_option_to_types (struct Option *);
 int Vect_copy_map_lines ( struct Map_info *, struct Map_info * );
 int Vect_copy_map_lines ( struct Map_info *, struct Map_info * );
-int Vect_copy ( char *, char *, char *, FILE * );
-int Vect_rename ( char *, char *, FILE * );
-int Vect_copy_table ( struct Map_info *, struct Map_info *, int, int, char *, int );
-int Vect_copy_table_by_cats ( struct Map_info *, struct Map_info *, int, int, char *, int, int*, int );
+int Vect_copy ( const char *, const char *, const char *, FILE * );
+int Vect_rename ( const char *, const char *, FILE * );
+int Vect_copy_table ( struct Map_info *, struct Map_info *, int, int, const char *, int );
+int Vect_copy_table_by_cats ( struct Map_info *, struct Map_info *, int, int, const char *, int, int*, int );
 int Vect_copy_tables ( struct Map_info *, struct Map_info *, int );
 int Vect_copy_tables ( struct Map_info *, struct Map_info *, int );
-int Vect_delete ( char *map );
+int Vect_delete ( const char *map );
 int Vect_segment_intersection ( double, double, double, double, double, double, 
 int Vect_segment_intersection ( double, double, double, double, double, double, 
 	                        double, double, double, double, double, double,    
 	                        double, double, double, double, double, double,    
 				double *, double *, double *, double *, double *, double *,  
 				double *, double *, double *, double *, double *, double *,  
@@ -330,7 +330,7 @@ int Vect_line_intersection ( struct line_pnts *, struct line_pnts *,
                              struct line_pnts ***, struct line_pnts ***,
                              struct line_pnts ***, struct line_pnts ***,
                              int *, int *, int );
                              int *, int *, int );
 int Vect_line_check_intersection ( struct line_pnts *, struct line_pnts *, int );
 int Vect_line_check_intersection ( struct line_pnts *, struct line_pnts *, int );
-char *Vect_subst_var ( char *str, struct Map_info *Map);
+char *Vect_subst_var ( const char *str, struct Map_info *Map);
 
 
 /* Internal functions, MUST NOT be used in modules */
 /* Internal functions, MUST NOT be used in modules */
 int Vect_print_header (struct Map_info *);
 int Vect_print_header (struct Map_info *);
@@ -338,7 +338,7 @@ int Vect__init_head (struct Map_info *);
 
 
     /* Open/close/rewind map */
     /* Open/close/rewind map */
 int Vect_coor_info ( struct Map_info *, struct Coor_info *);
 int Vect_coor_info ( struct Map_info *, struct Coor_info *);
-char *Vect_maptype_info ( struct Map_info *);
+const char *Vect_maptype_info ( struct Map_info *);
 int Vect_open_topo (struct Map_info *, int);
 int Vect_open_topo (struct Map_info *, int);
 int Vect_save_topo ( struct Map_info *);
 int Vect_save_topo ( struct Map_info *);
 int Vect_open_spatial_index (struct Map_info *);
 int Vect_open_spatial_index (struct Map_info *);
@@ -352,7 +352,7 @@ int Vect__read_head (struct Map_info *);
 int V1_open_old_nat (struct Map_info *, int);
 int V1_open_old_nat (struct Map_info *, int);
 int V1_open_old_ogr (struct Map_info *, int);
 int V1_open_old_ogr (struct Map_info *, int);
 int V2_open_old_ogr (struct Map_info *);
 int V2_open_old_ogr (struct Map_info *);
-int V1_open_new_nat (struct Map_info *, char *, int);
+int V1_open_new_nat (struct Map_info *, const char *, int);
 int V1_rewind_nat (struct Map_info *);
 int V1_rewind_nat (struct Map_info *);
 int V1_rewind_ogr (struct Map_info *);
 int V1_rewind_ogr (struct Map_info *);
 int V2_rewind_nat (struct Map_info *);
 int V2_rewind_nat (struct Map_info *);

+ 3 - 3
include/gisdefs.h

@@ -711,9 +711,9 @@ char *G_location(void);
 char *G__location_path(void);
 char *G__location_path(void);
 
 
 /* ls.c */
 /* ls.c */
-const char **G__ls(const char *, int *);
+char **G__ls(const char *, int *);
 void G_ls(const char *, FILE *);
 void G_ls(const char *, FILE *);
-void G_ls_format(const char **, int, int, FILE *);
+void G_ls_format(char **, int, int, FILE *);
 
 
 /* lu.c */
 /* lu.c */
 int G_ludcmp(double **, int, int *, double *);
 int G_ludcmp(double **, int, int *, double *);
@@ -1124,7 +1124,7 @@ int G_read_vector_timestamp(const char *, const char *, struct TimeStamp *);
 int G_write_raster_timestamp(const char *, const struct TimeStamp *);
 int G_write_raster_timestamp(const char *, const struct TimeStamp *);
 int G_write_vector_timestamp(const char *, const struct TimeStamp *);
 int G_write_vector_timestamp(const char *, const struct TimeStamp *);
 int G_format_timestamp ( const struct TimeStamp *, char *);
 int G_format_timestamp ( const struct TimeStamp *, char *);
-int G_scan_timestamp ( struct TimeStamp *, char *);
+int G_scan_timestamp ( struct TimeStamp *, const char *);
 int G_remove_raster_timestamp (const char *);
 int G_remove_raster_timestamp (const char *);
 int G_remove_vector_timestamp (const char *);
 int G_remove_vector_timestamp (const char *);
 int G_read_grid3_timestamp (const char *,const char *, struct TimeStamp *);
 int G_read_grid3_timestamp (const char *,const char *, struct TimeStamp *);

+ 1 - 1
include/site.h

@@ -100,7 +100,7 @@ typedef struct
  
  
 typedef struct
 typedef struct
 {
 {
-  char *name, *desc, *form, *labels, *stime;
+  const char *name, *desc, *form, *labels, *stime;
   struct TimeStamp *time;
   struct TimeStamp *time;
 } Site_head;
 } Site_head;
 
 

+ 1 - 1
lib/gis/list.c

@@ -149,7 +149,7 @@ static int list_element( FILE *out,
 {
 {
     char path[GPATH_MAX];
     char path[GPATH_MAX];
     int count = 0;
     int count = 0;
-    const char **list;
+    char **list;
     int i;
     int i;
 
 
 /*
 /*

+ 8 - 8
lib/gis/ls.c

@@ -52,11 +52,11 @@ static int cmp_names(const void *aa, const void *bb)
  * \return          Pointer to array of strings containing the listing
  * \return          Pointer to array of strings containing the listing
  **/
  **/
 
 
-const char **G__ls(const char *dir, int *num_files)
+char **G__ls(const char *dir, int *num_files)
 {
 {
     struct dirent *dp;
     struct dirent *dp;
     DIR *dfd;
     DIR *dfd;
-    const char **dir_listing = NULL;
+    char **dir_listing = NULL;
     int n = 0;
     int n = 0;
 
 
     if ((dfd = opendir(dir)) == NULL)
     if ((dfd = opendir(dir)) == NULL)
@@ -66,7 +66,7 @@ const char **G__ls(const char *dir, int *num_files)
     {
     {
        if(dp->d_name[0] != '.') /* Don't list hidden files */
        if(dp->d_name[0] != '.') /* Don't list hidden files */
        {
        {
-          dir_listing = (const char **)G_realloc(dir_listing, 
+          dir_listing = (char **)G_realloc(dir_listing, 
 					   (1 + n) * sizeof(char *));
 					   (1 + n) * sizeof(char *));
           dir_listing[n] = G_store(dp->d_name);
           dir_listing[n] = G_store(dp->d_name);
           n++;
           n++;
@@ -95,12 +95,12 @@ const char **G__ls(const char *dir, int *num_files)
 void G_ls(const char *dir, FILE *stream)
 void G_ls(const char *dir, FILE *stream)
 {
 {
     int i, n;
     int i, n;
-    const char **dir_listing = G__ls(dir, &n);
+    char **dir_listing = G__ls(dir, &n);
 
 
     G_ls_format(dir_listing, n, 0, stream);
     G_ls_format(dir_listing, n, 0, stream);
 
 
     for (i = 0; i < n; i++)
     for (i = 0; i < n; i++)
-        G_free((char *)dir_listing[i]);
+        G_free(dir_listing[i]);
    
    
     G_free(dir_listing);
     G_free(dir_listing);
    
    
@@ -122,7 +122,7 @@ void G_ls(const char *dir, FILE *stream)
  * \param stream    Stream to print listing to
  * \param stream    Stream to print listing to
  **/
  **/
 
 
-void G_ls_format(const char **list, int num_items, int perline, FILE *stream)
+void G_ls_format(char **list, int num_items, int perline, FILE *stream)
 {
 {
     int i;
     int i;
 
 
@@ -166,10 +166,10 @@ void G_ls_format(const char **list, int num_items, int perline, FILE *stream)
     {
     {
 	const int max
 	const int max
 	    = num_items + column_height - (num_items % column_height);
 	    = num_items + column_height - (num_items % column_height);
-	const char **next;
+	char **next;
 
 
 	for (i = 1, next = list; i <= num_items; i++) {
 	for (i = 1, next = list; i <= num_items; i++) {
-	    const char **cur = next;
+	    char **cur = next;
 
 
 	    next += column_height;
 	    next += column_height;
 	    if (next >= list + num_items) {
 	    if (next >= list + num_items) {

+ 1 - 1
lib/gis/timestamp.c

@@ -211,7 +211,7 @@ int G_format_timestamp (
  */
  */
 int G_scan_timestamp (
 int G_scan_timestamp (
     struct TimeStamp *ts,
     struct TimeStamp *ts,
-    char *buf)
+    const char *buf)
 {
 {
     char temp[1024], *t;
     char temp[1024], *t;
     const char *slash;
     const char *slash;

+ 1 - 1
lib/init/set_data.c

@@ -284,7 +284,7 @@ list_locations (const char *gisdbase)
 int
 int
 list_mapsets (const char *location_name, const char *location)
 list_mapsets (const char *location_name, const char *location)
 {
 {
-    const char **mapsets;
+    char **mapsets;
     int i, num_mapsets;
     int i, num_mapsets;
     int any, ok, any_ok;
     int any, ok, any_ok;
     int len, tot_len;
     int len, tot_len;

+ 2 - 1
lib/sites/sites.c

@@ -205,7 +205,8 @@ int G_site_put_head ( FILE *ptr, Site_head *head)
 	                return -1; /* added to prevent crash 5/2000 MN*/
 	                return -1; /* added to prevent crash 5/2000 MN*/
 	        }
 	        }
             }
             }
-            G_format_timestamp (head->time, head->stime);
+            G_format_timestamp (head->time, buf);
+	    head->stime = G_store(buf);
 	    Vect_set_date (Map, head->stime);
 	    Vect_set_date (Map, head->stime);
         }
         }
     }
     }

+ 2 - 2
lib/vector/Vlib/array.c

@@ -81,7 +81,7 @@ Vect_new_varray (int size)
   \return -1 on error
   \return -1 on error
  */
  */
 int 
 int 
-Vect_set_varray_from_cat_string ( struct Map_info *Map, int field, char *cstring,
+Vect_set_varray_from_cat_string ( struct Map_info *Map, int field, const char *cstring,
                                 int type, int value, VARRAY *varray )
                                 int type, int value, VARRAY *varray )
 {
 {
     int ret;
     int ret;
@@ -235,7 +235,7 @@ static int in_array (int *cats, size_t ncats, int cat)
   \return -1 on error
   \return -1 on error
  */
  */
 int 
 int 
-Vect_set_varray_from_db ( struct Map_info *Map, int field, char *where,
+Vect_set_varray_from_db ( struct Map_info *Map, int field, const char *where,
                                 int type, int value, VARRAY *varray )
                                 int type, int value, VARRAY *varray )
 {
 {
     int i, n, c, centr, cat, *cats;
     int i, n, c, centr, cat, *cats;

+ 3 - 2
lib/vector/Vlib/cats.c

@@ -338,10 +338,11 @@ Vect_destroy_cat_list (struct cat_list *p)
   \return number of errors in ranges
   \return number of errors in ranges
 */
 */
 int 
 int 
-Vect_str_to_cat_list (char *str, struct cat_list *list)
+Vect_str_to_cat_list (const char *str, struct cat_list *list)
 {
 {
   int i, nr, l, err = 0;
   int i, nr, l, err = 0;
-  char *s, *e, buf[100];
+  const char *s, *e;
+  char buf[100];
   int min, max;
   int min, max;
   
   
   G_debug (3, "Vect_str_to_cat_list(): str = %s", str);
   G_debug (3, "Vect_str_to_cat_list(): str = %s", str);

+ 9 - 27
lib/vector/Vlib/dbcolumns.c

@@ -37,7 +37,7 @@
   \return list of column(s) names on success
   \return list of column(s) names on success
   \return NULL on error 
   \return NULL on error 
 */
 */
-char *Vect_get_column_names(struct Map_info *Map, int field)
+const char *Vect_get_column_names(struct Map_info *Map, int field)
 {
 {
     int num_dblinks, ncols, col;
     int num_dblinks, ncols, col;
     struct field_info *fi;
     struct field_info *fi;
@@ -46,14 +46,11 @@ char *Vect_get_column_names(struct Map_info *Map, int field)
     dbString table_name;
     dbString table_name;
     dbTable *table;
     dbTable *table;
     char buf[2000];
     char buf[2000];
-    char *ptr;
 
 
     
     
     num_dblinks = Vect_get_num_dblinks(Map);
     num_dblinks = Vect_get_num_dblinks(Map);
-    if (num_dblinks <= 0) {
+    if (num_dblinks <= 0)
 	return (NULL);
 	return (NULL);
-    }
-    else {			/* num_dblinks > 0 */
 
 
 	G_debug(3,
 	G_debug(3,
 		"Displaying column names for database connection of layer %d:",
 		"Displaying column names for database connection of layer %d:",
@@ -85,10 +82,7 @@ char *Vect_get_column_names(struct Map_info *Map, int field)
 	db_close_database(driver);
 	db_close_database(driver);
 	db_shutdown_driver(driver);
 	db_shutdown_driver(driver);
 
 
-	ptr = G_malloc ( strlen(G_chop(buf)) );
-        sprintf (ptr, "%s", buf);
-        return (ptr);
-    }
+        return G_store(G_chop(buf));
 }
 }
 
 
 /*!
 /*!
@@ -100,7 +94,7 @@ char *Vect_get_column_names(struct Map_info *Map, int field)
   \return list of column(s) types on success
   \return list of column(s) types on success
   \return NULL on error 
   \return NULL on error 
 */
 */
-char *Vect_get_column_types(struct Map_info *Map, int field)
+const char *Vect_get_column_types(struct Map_info *Map, int field)
 {
 {
     int num_dblinks, ncols, col;
     int num_dblinks, ncols, col;
     struct field_info *fi;
     struct field_info *fi;
@@ -109,14 +103,11 @@ char *Vect_get_column_types(struct Map_info *Map, int field)
     dbString table_name;
     dbString table_name;
     dbTable *table;
     dbTable *table;
     char buf[2000];
     char buf[2000];
-    char *ptr;
 
 
     
     
     num_dblinks = Vect_get_num_dblinks(Map);
     num_dblinks = Vect_get_num_dblinks(Map);
-    if (num_dblinks <= 0) {
+    if (num_dblinks <= 0)
 	return (NULL);
 	return (NULL);
-    }
-    else {			/* num_dblinks > 0 */
 
 
 	G_debug(3,
 	G_debug(3,
 		"Displaying column types for database connection of layer %d:",
 		"Displaying column types for database connection of layer %d:",
@@ -148,10 +139,7 @@ char *Vect_get_column_types(struct Map_info *Map, int field)
 	db_close_database(driver);
 	db_close_database(driver);
 	db_shutdown_driver(driver);
 	db_shutdown_driver(driver);
 
 
-	ptr = G_malloc ( strlen(G_chop(buf)) );
-        sprintf (ptr, "%s", buf);
-        return (ptr);
-    }
+        return G_store(G_chop(buf));
 }
 }
 
 
 
 
@@ -164,7 +152,7 @@ char *Vect_get_column_types(struct Map_info *Map, int field)
   \return list of column(s) types on success
   \return list of column(s) types on success
   \retutn NULL on error 
   \retutn NULL on error 
 */
 */
-char *Vect_get_column_names_types(struct Map_info *Map, int field)
+const char *Vect_get_column_names_types(struct Map_info *Map, int field)
 {
 {
     int num_dblinks, ncols, col;
     int num_dblinks, ncols, col;
     struct field_info *fi;
     struct field_info *fi;
@@ -173,14 +161,11 @@ char *Vect_get_column_names_types(struct Map_info *Map, int field)
     dbString table_name;
     dbString table_name;
     dbTable *table;
     dbTable *table;
     char buf[2000];
     char buf[2000];
-    char *ptr;
 
 
     
     
     num_dblinks = Vect_get_num_dblinks(Map);
     num_dblinks = Vect_get_num_dblinks(Map);
-    if (num_dblinks <= 0) {
+    if (num_dblinks <= 0)
 	return (NULL);
 	return (NULL);
-    }
-    else {			/* num_dblinks > 0 */
 
 
 	G_debug(3,
 	G_debug(3,
 		"Displaying column types for database connection of layer %d:",
 		"Displaying column types for database connection of layer %d:",
@@ -214,8 +199,5 @@ char *Vect_get_column_names_types(struct Map_info *Map, int field)
 	db_close_database(driver);
 	db_close_database(driver);
 	db_shutdown_driver(driver);
 	db_shutdown_driver(driver);
 
 
-	ptr = G_malloc ( strlen(G_chop(buf)) );
-        sprintf (ptr, "%s", buf);
-        return (ptr);
-    }
+        return G_store(G_chop(buf));
 }
 }

+ 7 - 7
lib/vector/Vlib/field.c

@@ -81,8 +81,8 @@ Vect_reset_dblinks ( struct dblinks *p )
   \return -1 error
   \return -1 error
 */
 */
 int
 int
-Vect_map_add_dblink ( struct Map_info *Map, int number, char *name, char *table, char *key, 
-	             char *db, char *driver )
+Vect_map_add_dblink ( struct Map_info *Map, int number, const char *name, const char *table, const char *key, 
+	             const char *db, const char *driver )
 {
 {
     int ret;
     int ret;
 
 
@@ -211,7 +211,7 @@ Vect_check_dblink ( struct dblinks *p, int field )
   \return -1 error
   \return -1 error
 */
 */
 int
 int
-Vect_add_dblink ( struct dblinks *p, int number, char *name, char *table, char *key, char *db, char *driver )
+Vect_add_dblink ( struct dblinks *p, int number, const char *name, const char *table, const char *key, const char *db, const char *driver )
 {
 {
     int ret;
     int ret;
     
     
@@ -264,13 +264,13 @@ struct field_info
 *Vect_default_field_info (
 *Vect_default_field_info (
 			  struct Map_info *Map,  
 			  struct Map_info *Map,  
 			  int  field,    
 			  int  field,    
-			  char *field_name, 
+			  const char *field_name, 
 			  int  type ) 
 			  int  type ) 
 {
 {
     struct field_info *fi;
     struct field_info *fi;
     char buf[1000], buf2[1000];
     char buf[1000], buf2[1000];
-    char *schema;
-    char *drv, *db;
+    const char *schema;
+    const char *drv, *db;
     dbConnection  connection;
     dbConnection  connection;
     
     
     G_debug (1, "Vect_default_field_info(): map = %s field = %d", Map->name, field);
     G_debug (1, "Vect_default_field_info(): map = %s field = %d", Map->name, field);
@@ -666,7 +666,7 @@ Vect_write_dblinks ( struct Map_info *Map )
   \return pointer to new string
   \return pointer to new string
 */
 */
 char *
 char *
-Vect_subst_var ( char *in, struct Map_info *Map )
+Vect_subst_var ( const char *in, struct Map_info *Map )
 {
 {
     char *c;
     char *c;
     char buf[1000], str[1000];
     char buf[1000], str[1000];

+ 20 - 21
lib/vector/Vlib/header.c

@@ -24,7 +24,7 @@
 #include <grass/Vect.h>
 #include <grass/Vect.h>
 #include <grass/glocale.h>
 #include <grass/glocale.h>
 
 
-static int lookup(char *file, char *key, char *value, size_t len);
+static int lookup(const char *file, const char *key, char *value, size_t len);
 
 
 
 
 /*!
 /*!
@@ -198,7 +198,7 @@ Vect__read_head (struct Map_info *Map)
 
 
   \return poiter to map name
   \return poiter to map name
 */
 */
-char *
+const char *
 Vect_get_name (struct Map_info *Map)
 Vect_get_name (struct Map_info *Map)
 {
 {
     return (Map->name);
     return (Map->name);
@@ -211,7 +211,7 @@ Vect_get_name (struct Map_info *Map)
 
 
   \return poiter to mapset name
   \return poiter to mapset name
 */
 */
-char *
+const char *
 Vect_get_mapset (struct Map_info *Map)
 Vect_get_mapset (struct Map_info *Map)
 {
 {
     return (Map->mapset);
     return (Map->mapset);
@@ -224,7 +224,7 @@ Vect_get_mapset (struct Map_info *Map)
 
 
   \return poiter to map name (name@mapset)
   \return poiter to map name (name@mapset)
 */
 */
-char *
+const char *
 Vect_get_full_name (struct Map_info *Map)
 Vect_get_full_name (struct Map_info *Map)
 {
 {
     char *ptr;
     char *ptr;
@@ -257,7 +257,7 @@ Vect_is_3d (struct Map_info *Map )
   \return 0
   \return 0
 */
 */
 int
 int
-Vect_set_organization (struct Map_info *Map, char *str )
+Vect_set_organization (struct Map_info *Map, const char *str )
 {
 {
     G_free ( Map->head.organization );
     G_free ( Map->head.organization );
     Map->head.organization = G_store ( str );
     Map->head.organization = G_store ( str );
@@ -272,7 +272,7 @@ Vect_set_organization (struct Map_info *Map, char *str )
   
   
   \return organization string
   \return organization string
 */
 */
-char *
+const char *
 Vect_get_organization (struct Map_info *Map)
 Vect_get_organization (struct Map_info *Map)
 {
 {
     return (Map->head.organization);
     return (Map->head.organization);
@@ -290,7 +290,7 @@ Vect_get_organization (struct Map_info *Map)
   \return 0 on success
   \return 0 on success
 */
 */
 int
 int
-Vect_set_date (struct Map_info *Map, char *str )
+Vect_set_date (struct Map_info *Map, const char *str )
 {
 {
     G_free ( Map->head.date );
     G_free ( Map->head.date );
     Map->head.date = G_store ( str );
     Map->head.date = G_store ( str );
@@ -307,7 +307,7 @@ Vect_set_date (struct Map_info *Map, char *str )
 
 
   \return date of digitization string
   \return date of digitization string
 */
 */
-char *
+const char *
 Vect_get_date (struct Map_info *Map)
 Vect_get_date (struct Map_info *Map)
 {
 {
     return (Map->head.date);
     return (Map->head.date);
@@ -322,7 +322,7 @@ Vect_get_date (struct Map_info *Map)
   \return 0 on success
   \return 0 on success
 */
 */
 int
 int
-Vect_set_person (struct Map_info *Map, char *str )
+Vect_set_person (struct Map_info *Map, const char *str )
 {
 {
     G_free ( Map->head.your_name );
     G_free ( Map->head.your_name );
     Map->head.your_name = G_store ( str );
     Map->head.your_name = G_store ( str );
@@ -336,7 +336,7 @@ Vect_set_person (struct Map_info *Map, char *str )
 
 
   \return user name string
   \return user name string
 */
 */
-char *
+const char *
 Vect_get_person (struct Map_info *Map)
 Vect_get_person (struct Map_info *Map)
 {
 {
     return (Map->head.your_name);
     return (Map->head.your_name);
@@ -351,7 +351,7 @@ Vect_get_person (struct Map_info *Map)
   \return 0 on success
   \return 0 on success
 */
 */
 int
 int
-Vect_set_map_name (struct Map_info *Map, char *str )
+Vect_set_map_name (struct Map_info *Map, const char *str )
 {
 {
     G_free ( Map->head.map_name );
     G_free ( Map->head.map_name );
     Map->head.map_name = G_store ( str );
     Map->head.map_name = G_store ( str );
@@ -365,7 +365,7 @@ Vect_set_map_name (struct Map_info *Map, char *str )
 
 
   \return map name string
   \return map name string
 */
 */
-char *
+const char *
 Vect_get_map_name (struct Map_info *Map)
 Vect_get_map_name (struct Map_info *Map)
 {
 {
     return (Map->head.map_name);
     return (Map->head.map_name);
@@ -380,7 +380,7 @@ Vect_get_map_name (struct Map_info *Map)
   \return 0 on success
   \return 0 on success
 */
 */
 int
 int
-Vect_set_map_date (struct Map_info *Map, char *str )
+Vect_set_map_date (struct Map_info *Map, const char *str )
 {
 {
     G_free ( Map->head.source_date );
     G_free ( Map->head.source_date );
     Map->head.source_date = G_store ( str );
     Map->head.source_date = G_store ( str );
@@ -394,7 +394,7 @@ Vect_set_map_date (struct Map_info *Map, char *str )
 
 
   \return date when the source map was originally produced string
   \return date when the source map was originally produced string
 */
 */
-char *
+const char *
 Vect_get_map_date (struct Map_info *Map)
 Vect_get_map_date (struct Map_info *Map)
 {
 {
     return (Map->head.source_date);
     return (Map->head.source_date);
@@ -437,7 +437,7 @@ Vect_get_scale (struct Map_info *Map)
   \return 0 on success
   \return 0 on success
 */
 */
 int
 int
-Vect_set_comment (struct Map_info *Map, char *str )
+Vect_set_comment (struct Map_info *Map, const char *str )
 {
 {
     G_free ( Map->head.line_3 );
     G_free ( Map->head.line_3 );
     Map->head.line_3 = G_store ( str );
     Map->head.line_3 = G_store ( str );
@@ -451,7 +451,7 @@ Vect_set_comment (struct Map_info *Map, char *str )
 
 
   \return comment or other info string
   \return comment or other info string
 */
 */
-char *
+const char *
 Vect_get_comment (struct Map_info *Map)
 Vect_get_comment (struct Map_info *Map)
 {
 {
     return (Map->head.line_3);
     return (Map->head.line_3);
@@ -515,11 +515,10 @@ Vect_get_proj (struct Map_info *Map)
   \return poiter to projection name
   \return poiter to projection name
 */
 */
 
 
-char *Vect_get_proj_name (struct Map_info *Map)
+const char *Vect_get_proj_name (struct Map_info *Map)
 {
 {
+    char name[256];
     int n;
     int n;
-    static char name[256];
-    char *G__projection_name();
 
 
     switch(n=Vect_get_proj(Map))
     switch(n=Vect_get_proj(Map))
     {
     {
@@ -531,7 +530,7 @@ char *Vect_get_proj_name (struct Map_info *Map)
     }
     }
     if(!lookup (PROJECTION_FILE, "name", name, sizeof(name)))
     if(!lookup (PROJECTION_FILE, "name", name, sizeof(name)))
 	strcpy (name, _("Unknown projection"));
 	strcpy (name, _("Unknown projection"));
-    return name;
+    return G_store(name);
 }
 }
 
 
 /*!
 /*!
@@ -566,7 +565,7 @@ Vect_get_thresh (struct Map_info *Map)
 
 
 
 
 /* from lib/gis/proj3.c */
 /* from lib/gis/proj3.c */
-static int lookup(char *file, char *key, char *value, size_t len)
+static int lookup(const char *file, const char *key, char *value, size_t len)
 {
 {
     char path[GPATH_MAX];
     char path[GPATH_MAX];
 
 

+ 1 - 1
lib/vector/Vlib/hist.c

@@ -62,7 +62,7 @@ Vect_hist_command ( struct Map_info *Map )
   \return the number of characters printed
   \return the number of characters printed
 */
 */
 int 
 int 
-Vect_hist_write ( struct Map_info *Map, char *str )
+Vect_hist_write ( struct Map_info *Map, const char *str )
 {
 {
     int ret ;
     int ret ;
     
     

+ 15 - 13
lib/vector/Vlib/legal_vname.c

@@ -33,9 +33,14 @@
   \return -1 if name does not start with letter A..Za..z or if name does not continue with A..Za..z0..9_@
   \return -1 if name does not start with letter A..Za..z or if name does not continue with A..Za..z0..9_@
 */
 */
 
 
-int Vect_legal_filename (char *s)
+int Vect_legal_filename (const char *s)
 {
 {
+    /* full list of SQL keywords available at
+       http://www.postgresql.org/docs/8.2/static/sql-keywords-appendix.html
+    */
+    static const char *keywords[] = {"and", "or", "not", NULL};
     char buf[GNAME_MAX];
     char buf[GNAME_MAX];
+    int i;
     
     
     sprintf(buf, "%s", s);
     sprintf(buf, "%s", s);
     
     
@@ -57,15 +62,11 @@ int Vect_legal_filename (char *s)
 	    return -1;
 	    return -1;
 	}
 	}
 
 
-    /* full list of SQL keywords available at
-       http://www.postgresql.org/docs/8.2/static/sql-keywords-appendix.html
-    */
-    if (G_strcasecmp(buf, "and") == 0 ||
-	G_strcasecmp(buf, "or") == 0 ||
-	G_strcasecmp(buf, "not") == 0) {
-	G_warning (_("Illegal vector map name <%s>. SQL keyword cannot be used as vector map name."), buf);
-	return -1;
-    }
+    for (i = 0; keywords[i]; i++)
+	if (G_strcasecmp(buf, keywords[i]) == 0) {
+	    G_warning (_("Illegal vector map name <%s>. SQL keyword cannot be used as vector map name."), buf);
+	    return -1;
+	}
 
 
     return 1;
     return 1;
 }
 }
@@ -86,9 +87,9 @@ int Vect_legal_filename (char *s)
  \return 1 error
  \return 1 error
 */
 */
 
 
-int Vect_check_input_output_name ( char * input, char * output, int error )
+int Vect_check_input_output_name ( const char * input, const char * output, int error )
 {
 {
-    char *mapset;
+    const char *mapset;
 
 
     if ( Vect_legal_filename(output) == -1 ) {
     if ( Vect_legal_filename(output) == -1 ) {
 	if ( error == GV_FATAL_EXIT ) {
 	if ( error == GV_FATAL_EXIT ) {
@@ -115,7 +116,8 @@ int Vect_check_input_output_name ( char * input, char * output, int error )
     }
     }
 
 
     if ( strcmp(mapset,G_mapset()) == 0 ) {
     if ( strcmp(mapset,G_mapset()) == 0 ) {
-	char *in, nm[1000], ms[1000];
+	const char *in;
+	char nm[GNAME_MAX], ms[GMAPSET_MAX];
 	
 	
         if ( G__name_is_fully_qualified(input,nm,ms) ) {
         if ( G__name_is_fully_qualified(input,nm,ms) ) {
 	    in = nm;
 	    in = nm;

+ 8 - 10
lib/vector/Vlib/map.c

@@ -149,14 +149,14 @@ copy_file(const char *src, const char *dst)
   \return 0 success
   \return 0 success
 */
 */
 int 
 int 
-Vect_copy ( char *in, char *mapset, char *out, FILE *msgout )
+Vect_copy ( const char *in, const char *mapset, const char *out, FILE *msgout )
 {
 {
     int i, n, ret, type;
     int i, n, ret, type;
     struct Map_info In, Out;
     struct Map_info In, Out;
     struct field_info *Fi, *Fin;
     struct field_info *Fi, *Fin;
     char   old_path[GPATH_MAX], new_path[GPATH_MAX], buf[GPATH_MAX]; 
     char   old_path[GPATH_MAX], new_path[GPATH_MAX], buf[GPATH_MAX]; 
     struct stat info;
     struct stat info;
-    char *files[] = { GRASS_VECT_FRMT_ELEMENT, GRASS_VECT_COOR_ELEMENT,
+    const char *files[] = { GRASS_VECT_FRMT_ELEMENT, GRASS_VECT_COOR_ELEMENT,
                       GRASS_VECT_HEAD_ELEMENT, GRASS_VECT_HIST_ELEMENT,
                       GRASS_VECT_HEAD_ELEMENT, GRASS_VECT_HIST_ELEMENT,
                       GV_TOPO_ELEMENT, GV_SIDX_ELEMENT, GV_CIDX_ELEMENT,
                       GV_TOPO_ELEMENT, GV_SIDX_ELEMENT, GV_CIDX_ELEMENT,
                       NULL };
                       NULL };
@@ -279,7 +279,7 @@ Vect_copy ( char *in, char *mapset, char *out, FILE *msgout )
   \return 0 success
   \return 0 success
 */
 */
 int 
 int 
-Vect_rename ( char *in, char *out, FILE *msgout )
+Vect_rename ( const char *in, const char *out, FILE *msgout )
 {
 {
     int i, n, ret, type;
     int i, n, ret, type;
     struct Map_info Map;
     struct Map_info Map;
@@ -399,7 +399,7 @@ Vect_rename ( char *in, char *out, FILE *msgout )
   \return 0 success
   \return 0 success
 */
 */
 int 
 int 
-Vect_delete ( char *map )
+Vect_delete ( const char *map )
 {
 {
     int i, n, ret;
     int i, n, ret;
     struct Map_info Map;
     struct Map_info Map;
@@ -407,12 +407,10 @@ Vect_delete ( char *map )
     char   buf[GPATH_MAX];
     char   buf[GPATH_MAX];
     DIR    *dir;
     DIR    *dir;
     struct dirent *ent; 
     struct dirent *ent; 
-    char *tmp;
+    const char *tmp;
 
 
     G_debug (3, "Delete vector '%s'", map );
     G_debug (3, "Delete vector '%s'", map );
 
 
-    G_chop ( map );
-
     if ( map == NULL || strlen ( map ) == 0 ) {
     if ( map == NULL || strlen ( map ) == 0 ) {
 	G_warning (_("Invalid vector map name <%s>"), map ? map : "null");
 	G_warning (_("Invalid vector map name <%s>"), map ? map : "null");
 	return -1;
 	return -1;
@@ -604,7 +602,7 @@ Vect_copy_tables ( struct Map_info *In, struct Map_info *Out, int field )
 */
 */
 int 
 int 
 Vect_copy_table ( struct Map_info *In, struct Map_info *Out, int field_in, 
 Vect_copy_table ( struct Map_info *In, struct Map_info *Out, int field_in, 
-	           int field_out,  char *field_name, int type )
+	           int field_out,  const char *field_name, int type )
 {
 {
     return Vect_copy_table_by_cats ( In, Out, field_in, field_out, field_name, type, NULL, 0); 
     return Vect_copy_table_by_cats ( In, Out, field_in, field_out, field_name, type, NULL, 0); 
 }
 }
@@ -626,11 +624,11 @@ Vect_copy_table ( struct Map_info *In, struct Map_info *Out, int field_in,
 */
 */
 int 
 int 
 Vect_copy_table_by_cats ( struct Map_info *In, struct Map_info *Out, int field_in, 
 Vect_copy_table_by_cats ( struct Map_info *In, struct Map_info *Out, int field_in, 
-	           int field_out,  char *field_name, int type, int *cats, int ncats )
+	           int field_out,  const char *field_name, int type, int *cats, int ncats )
 {
 {
     int    ret;
     int    ret;
     struct field_info *Fi, *Fin;
     struct field_info *Fi, *Fin;
-    char   *name, *key;
+    const char   *name, *key;
 
 
     G_debug (2, "Vect_copy_table(): field_in = %d field_out = %d", field_in, field_out);
     G_debug (2, "Vect_copy_table(): field_in = %d field_out = %d", field_in, field_out);
 
 

+ 3 - 3
lib/vector/Vlib/net.c

@@ -90,9 +90,9 @@ Vect_net_build_graph (  struct Map_info *Map,
 			int ltype,  
 			int ltype,  
        			int afield, 
        			int afield, 
 			int nfield, 
 			int nfield, 
-			char *afcol,
-			char *abcol,
-			char *ncol, 
+			const char *afcol,
+			const char *abcol,
+			const char *ncol, 
 			int geo,    
 			int geo,    
 		        int algorithm )
 		        int algorithm )
 {
 {

+ 11 - 15
lib/vector/Vlib/open.c

@@ -114,9 +114,9 @@ Vect_set_open_level (int level)
  * \return -1 in error
  * \return -1 in error
  */
  */
 int
 int
-Vect__open_old ( struct Map_info *Map, char *name, char *mapset, int update, int head_only ) 
+Vect__open_old ( struct Map_info *Map, const char *name, const char *mapset, int update, int head_only ) 
 {
 {
-  char buf[200], buf2[200], xname[512], xmapset[512], errmsg[2000];
+  char buf[GNAME_MAX+10], buf2[GMAPSET_MAX+10], xname[GNAME_MAX], xmapset[GMAPSET_MAX], errmsg[2000];
   FILE *fp;
   FILE *fp;
   int level, level_request, ferror;
   int level, level_request, ferror;
   int format, ret;
   int format, ret;
@@ -373,10 +373,7 @@ Vect__open_old ( struct Map_info *Map, char *name, char *mapset, int update, int
  * \return -1 on error
  * \return -1 on error
 */
 */
 int
 int
-Vect_open_old (
-		struct Map_info *Map,
-		char *name,
-		char *mapset)
+Vect_open_old (struct Map_info *Map, const char *name, const char *mapset)
 {
 {
     return ( Vect__open_old (Map, name, mapset, 0, 0) );
     return ( Vect__open_old (Map, name, mapset, 0, 0) );
 }
 }
@@ -394,7 +391,7 @@ Vect_open_old (
  * \return -1 on error
  * \return -1 on error
 */
 */
 int
 int
-Vect_open_update (struct Map_info *Map, char *name, char *mapset)
+Vect_open_update (struct Map_info *Map, const char *name, const char *mapset)
 {
 {
     int ret;
     int ret;
 
 
@@ -431,7 +428,7 @@ Vect_open_update (struct Map_info *Map, char *name, char *mapset)
  * \return -1 on error
  * \return -1 on error
  */
  */
 int
 int
-Vect_open_old_head (struct Map_info *Map, char *name, char *mapset)
+Vect_open_old_head (struct Map_info *Map, const char *name, const char *mapset)
 {
 {
     return ( Vect__open_old (Map, name, mapset, 0, 1) );
     return ( Vect__open_old (Map, name, mapset, 0, 1) );
 }
 }
@@ -449,7 +446,7 @@ Vect_open_old_head (struct Map_info *Map, char *name, char *mapset)
  * \return -1 on error
  * \return -1 on error
  */
  */
 int
 int
-Vect_open_update_head ( struct Map_info *Map, char *name, char *mapset)
+Vect_open_update_head ( struct Map_info *Map, const char *name, const char *mapset)
 {
 {
     int ret;
     int ret;
 
 
@@ -480,7 +477,7 @@ Vect_open_update_head ( struct Map_info *Map, char *name, char *mapset)
  * \return -1 on error
  * \return -1 on error
 */
 */
 int 
 int 
-Vect_open_new (struct Map_info *Map, char *name, int with_z)
+Vect_open_new (struct Map_info *Map, const char *name, int with_z)
 {
 {
     int  ret, ferror;
     int  ret, ferror;
     char errmsg[2000], buf[200];
     char errmsg[2000], buf[200];
@@ -499,7 +496,7 @@ Vect_open_new (struct Map_info *Map, char *name, int with_z)
     }
     }
 
 
     /* Check if map already exists */
     /* Check if map already exists */
-    if ( G_find_file(GRASS_VECT_DIRECTORY, name, G_mapset()) != NULL ) {
+    if ( G_find_file2(GRASS_VECT_DIRECTORY, name, G_mapset()) != NULL ) {
         G_warning (_("Vector map <%s> already exists and will be overwritten"), name); 
         G_warning (_("Vector map <%s> already exists and will be overwritten"), name); 
 	
 	
         ret = Vect_delete ( name );
         ret = Vect_delete ( name );
@@ -608,12 +605,11 @@ Vect_coor_info ( struct Map_info *Map, struct Coor_info *Info )
  * \return maptype string on success
  * \return maptype string on success
  * \return error message on error
  * \return error message on error
  */
  */
-char * 
+const char * 
 Vect_maptype_info ( struct Map_info *Map )
 Vect_maptype_info ( struct Map_info *Map )
 {
 {
-    char *maptype;
+    char maptype[1000];
 
 
-    maptype = G_malloc(sizeof(char) * 200);
     switch (  Map->format ) {
     switch (  Map->format ) {
         case GV_FORMAT_NATIVE :
         case GV_FORMAT_NATIVE :
             sprintf (maptype, "native");
             sprintf (maptype, "native");
@@ -625,7 +621,7 @@ Vect_maptype_info ( struct Map_info *Map )
             sprintf (maptype, "unknown %d (update Vect_maptype_info)", Map->format);
             sprintf (maptype, "unknown %d (update Vect_maptype_info)", Map->format);
     }
     }
 	
 	
-    return maptype;
+    return G_store(maptype);
 }
 }
 
 
 
 

+ 1 - 1
lib/vector/Vlib/open_nat.c

@@ -83,7 +83,7 @@ V1_open_old_nat ( struct Map_info *Map, int update)
 int 
 int 
 V1_open_new_nat (
 V1_open_new_nat (
 	      struct Map_info *Map,
 	      struct Map_info *Map,
-	      char *name,
+	      const char *name,
 	      int with_z)
 	      int with_z)
 {
 {
   char buf[1000];
   char buf[1000];

+ 1 - 1
lib/vector/Vlib/overlay.c

@@ -37,7 +37,7 @@ int Vect_overlay_and (struct Map_info *, int, struct ilist *, struct ilist *,
   \return -1 on error
   \return -1 on error
 */
 */
 int 
 int 
-Vect_overlay_str_to_operator ( char *str )
+Vect_overlay_str_to_operator ( const char *str )
 {
 {
     
     
     if ( strcmp ( str, GV_ON_AND ) == 0 )
     if ( strcmp ( str, GV_ON_AND ) == 0 )

+ 1 - 1
raster/r.colors/main.c

@@ -29,7 +29,7 @@
 #include <grass/glocale.h>
 #include <grass/glocale.h>
 #include "local_proto.h"
 #include "local_proto.h"
 
 
-static const char **rules;
+static char **rules;
 static int nrules;
 static int nrules;
 
 
 static void scan_rules(void)
 static void scan_rules(void)

+ 5 - 9
raster/r.volume/main.c

@@ -203,19 +203,15 @@ int main(int argc, char *argv[])
 
 
     /* got everything, now do output */
     /* got everything, now do output */
     if (*site_list) {
     if (*site_list) {
+	char desc[GNAME_MAX*2+40];
 	site_info.form = NULL;
 	site_info.form = NULL;
 	site_info.time = NULL;
 	site_info.time = NULL;
 	site_info.stime = NULL;
 	site_info.stime = NULL;
-	site_info.labels = (char *)G_malloc(80 * sizeof(char));
-	site_info.name = (char *)G_malloc(80 * sizeof(char));
-	site_info.desc = (char *)G_malloc(80 * sizeof(char));
-	if (site_info.desc == NULL || site_info.name == NULL ||
-	    site_info.labels == NULL)
-	    G_fatal_error(_("Memory allocation error"));
-	sprintf(site_info.desc, "from %s on map %s using clumps from %s",
+	sprintf(desc, "from %s on map %s using clumps from %s",
 		argv[0], datamap, clumpmap);
 		argv[0], datamap, clumpmap);
-	sprintf(site_info.name, "%s", site_list);
-	sprintf(site_info.labels,
+	site_info.desc = G_store(desc);
+	site_info.name = G_store(site_list);
+	site_info.labels = G_store(
 		"centroid east|centroid north|#cat vol avg t n");
 		"centroid east|centroid north|#cat vol avg t n");
 	G_site_put_head(fd_sites, &site_info);
 	G_site_put_head(fd_sites, &site_info);
     }
     }

+ 3 - 4
raster/simwe/simlib/output.c

@@ -56,6 +56,7 @@ int output_data(int tt, double ft)
       G_fatal_error ("Cannot open %s", outwalk);
       G_fatal_error ("Cannot open %s", outwalk);
     else
     else
     {
     {
+	char buf[GNAME_MAX+40];
     if(NULL == (sd = G_site_new_struct(-1,2,0,1)))
     if(NULL == (sd = G_site_new_struct(-1,2,0,1)))
         G_fatal_error("memory allocation failed for site");
         G_fatal_error("memory allocation failed for site");
 
 
@@ -64,10 +65,8 @@ int output_data(int tt, double ft)
 	else
 	else
       walkershead.name = outwalk;
       walkershead.name = outwalk;
 
 
-      walkershead.desc = G_strdup ("output walkers");
-      walkershead.desc = (char *) G_malloc (128 * sizeof (char));
-      sprintf (walkershead.desc, "output walkers of %s [raster]",
-               depth);
+      sprintf (buf, "output walkers of %s [raster]", depth);
+      walkershead.desc = G_store(buf);
       walkershead.time = NULL;
       walkershead.time = NULL;
       walkershead.stime = NULL;
       walkershead.stime = NULL;
       walkershead.labels = NULL;
       walkershead.labels = NULL;

+ 1 - 1
visualization/nviz/src/glwrappers.c

@@ -52,7 +52,7 @@ int Nset_background_cmd(Nv_data * data, Tcl_Interp * interp,	/* Current interpre
 
 
 }
 }
 
 
-int tcl_color_to_int(char *clr)
+int tcl_color_to_int(const char *clr)
 {
 {
     int r, g, b;
     int r, g, b;
     int c;
     int c;

+ 11 - 17
visualization/nviz/src/interface.h

@@ -192,7 +192,7 @@ int check_blank(Tcl_Interp *, int);
 int Nget_first_exag_cmd(Nv_data *, Tcl_Interp *, int, char **);
 int Nget_first_exag_cmd(Nv_data *, Tcl_Interp *, int, char **);
 int Nget_height_cmd(Nv_data *, Tcl_Interp *, int, char **);
 int Nget_height_cmd(Nv_data *, Tcl_Interp *, int, char **);
 /* glwrappers.c */
 /* glwrappers.c */
-int tcl_color_to_int(char *);
+int tcl_color_to_int(const char *);
 int Nresize_cmd(Nv_data *, Tcl_Interp *, int, char **);
 int Nresize_cmd(Nv_data *, Tcl_Interp *, int, char **);
 int Nfinish_cmd(ClientData, Tcl_Interp *, int, char **);
 int Nfinish_cmd(ClientData, Tcl_Interp *, int, char **);
 int Nset_background_cmd(Nv_data *, Tcl_Interp *, int, char **);
 int Nset_background_cmd(Nv_data *, Tcl_Interp *, int, char **);
@@ -365,31 +365,25 @@ struct Map_info;
 
 
 /* site_attr_commands.c */
 /* site_attr_commands.c */
 int site_attr_open_map(geosite *, int, struct Map_info **, int *, char ***, int **, int **);
 int site_attr_open_map(geosite *, int, struct Map_info **, int *, char ***, int **, int **);
-int site_attr_set_color(geosite *, int, int, int, char**, char**);
-int site_attr_set_size(geosite *, int, int, int, char**, char**);
+int site_attr_set_color(geosite *, int, int, int, const char**, const char**);
+int site_attr_set_size(geosite *, int, int, int, const char**, const char**);
 int site_attr_set_fixed_color(geosite *, int, unsigned int);
 int site_attr_set_fixed_color(geosite *, int, unsigned int);
 int site_attr_set_fixed_size(geosite *, int, float);
 int site_attr_set_fixed_size(geosite *, int, float);
 int site_attr_set_fixed_marker(geosite *, int, int);
 int site_attr_set_fixed_marker(geosite *, int, int);
 int site_attr_set(Tcl_Interp *, geosite *, int, char *, int, char *, char *);
 int site_attr_set(Tcl_Interp *, geosite *, int, char *, int, char *, char *);
 int site_attr_unset(Tcl_Interp *, geosite *, int, char *);
 int site_attr_unset(Tcl_Interp *, geosite *, int, char *);
 int site_attr_get(Tcl_Interp *, geosite *, int);
 int site_attr_get(Tcl_Interp *, geosite *, int);
-int site_attr_set_color(geosite *, int, int, int, char**, char**);
-int site_attr_set_size(geosite *, int, int, int, char**, char**);
-int site_attr_set_fixed_color(geosite *, int, unsigned int);
-int site_attr_set_fixed_size(geosite *, int, float);
-int site_attr_set_fixed_marker(geosite *, int, int);
 void site_attr_init_tcl(Tcl_Interp *, Nv_data *);
 void site_attr_init_tcl(Tcl_Interp *, Nv_data *);
 void site_attr_init(int);
 void site_attr_init(int);
-int attr_interp_entries(int , char** , char** , float **, float **, float **);
-int attr_interp_colors(int , char** , char** , float **, float **, float **, float **, float **, float **, float **);
-int attr_get_int_BBGGRR(char* );
-int attr_interp_entries(int , char** , char** , float **, float **, float **);
-int attr_interp_entries_string(int , char** , float **);
-int attr_interp_colors(int , char** , char** , float **,float **, float **, float **, float **, float **, float **);
-int attr_interp_colors_string(int , char** , float **, float **, float **);
+int attr_interp_entries(int , const char** , const char** , float **, float **, float **);
+int attr_interp_colors(int , const char** , const char** , float **, float **, float **, float **, float **, float **, float **);
+int attr_get_int_BBGGRR(const char* );
+float attr_get_RRGGBB(const char*, float *, float *, float *);
+int attr_interp_entries_string(int , const char** , float **);
+int attr_interp_colors_string(int , const char** , float **, float **, float **);
 int attr_eval_color(float , int , float *, float *, float *, float *, float *, float *, float *);
 int attr_eval_color(float , int , float *, float *, float *, float *, float *, float *, float *);
-int attr_eval_color_string(char* , int , char** , float *, float *, float *);
-float attr_eval_entry_string(char* , int , char** , float*);
+int attr_eval_color_string(const char* , int , const char** , float *, float *, float *);
+float attr_eval_entry_string(const char* , int , const char** , float*);
 
 
 /* pick_vect_commands.c */
 /* pick_vect_commands.c */
 void pick_init_tcl(Tcl_Interp *, Nv_data *);
 void pick_init_tcl(Tcl_Interp *, Nv_data *);

+ 20 - 20
visualization/nviz/src/site_attr_commands.c

@@ -277,8 +277,8 @@ void site_attr_init_tcl(Tcl_Interp * interp, Nv_data * data)
   These following functions will better stay in appropriate .h files if
   These following functions will better stay in appropriate .h files if
     these functions will be put in separate files
     these functions will be put in separate files
 */
 */
-int attr_interp_entries(int n, char** argvX, char** argvY, float **x, float **y, float **m);
-int attr_interp_colors(int n, char** argvX, char** argvY, float **x,
+int attr_interp_entries(int n, const char** argvX, const char** argvY, float **x, float **y, float **m);
+int attr_interp_colors(int n, const char** argvX, const char** argvY, float **x,
 							float **yr, float **yg, float **yb,
 							float **yr, float **yg, float **yb,
 							float **mr, float **mg, float **mb);
 							float **mr, float **mg, float **mb);
 
 
@@ -627,8 +627,8 @@ void site_attr_close_map(struct Map_info *Map, int ncols, char **cnames, int *ct
 
 
 
 
 /* declarations of following functions */
 /* declarations of following functions */
-int site_attr_set_color(geosite * gp, int nattr, int index, int n, char** argvX, char** argvY);
-int site_attr_set_size(geosite * gp, int nattr, int index, int n, char** argvX, char** argvY);
+int site_attr_set_color(geosite * gp, int nattr, int index, int n, const char** argvX, const char** argvY);
+int site_attr_set_size(geosite * gp, int nattr, int index, int n, const char** argvX, const char** argvY);
 int site_attr_set_fixed_color(geosite * gp, int nattr, unsigned int color);
 int site_attr_set_fixed_color(geosite * gp, int nattr, unsigned int color);
 int site_attr_set_fixed_size(geosite * gp, int nattr, float size);
 int site_attr_set_fixed_size(geosite * gp, int nattr, float size);
 int site_attr_set_fixed_marker(geosite * gp, int nattr, int marker);
 int site_attr_set_fixed_marker(geosite * gp, int nattr, int marker);
@@ -728,7 +728,7 @@ int site_attr_get(Tcl_Interp *interp, geosite * gp, int nattr)
 
 
 
 
 
 
-int site_attr_set_color(geosite * gp, int nattr, int index, int n, char** argvX, char** argvY)
+int site_attr_set_color(geosite * gp, int nattr, int index, int n, const char** argvX, const char** argvY)
 {
 {
 	struct Map_info *Map; geopoint *gpt; SITE_ATT *sa;
 	struct Map_info *Map; geopoint *gpt; SITE_ATT *sa;
 	int *ctypes; char **cnames; int *ndx;
 	int *ctypes; char **cnames; int *ndx;
@@ -763,7 +763,7 @@ int site_attr_set_color(geosite * gp, int nattr, int index, int n, char** argvX,
 	return(0);
 	return(0);
 }
 }
 
 
-int site_attr_set_size(geosite * gp, int nattr, int index, int n, char** argvX, char** argvY)
+int site_attr_set_size(geosite * gp, int nattr, int index, int n, const char** argvX, const char** argvY)
 {
 {
 	struct Map_info *Map; geopoint *gpt; SITE_ATT *sa;
 	struct Map_info *Map; geopoint *gpt; SITE_ATT *sa;
 	int *ctypes; char **cnames; int *ndx;
 	int *ctypes; char **cnames; int *ndx;
@@ -834,7 +834,7 @@ int site_attr_set_fixed_marker(geosite * gp, int nattr, int marker)
 /* Color conversion functions **************************************************/
 /* Color conversion functions **************************************************/
 /*******************************************************************************/
 /*******************************************************************************/
 
 
-int attr_get_int_BBGGRR(char* rrggbb)
+int attr_get_int_BBGGRR(const char* rrggbb)
 {
 {
 /* rrggbb is in the form of #RRGGBB (first char is skipped) */
 /* rrggbb is in the form of #RRGGBB (first char is skipped) */
 	char strbuf[16];
 	char strbuf[16];
@@ -846,7 +846,7 @@ int attr_get_int_BBGGRR(char* rrggbb)
 }
 }
 
 
 
 
-float attr_get_RRGGBB(char* rrggbb, float *r, float *g, float *b)
+float attr_get_RRGGBB(const char* rrggbb, float *r, float *g, float *b)
 {
 {
 /* rrggbb is in the form of #RRGGBB (first char is skipped) */
 /* rrggbb is in the form of #RRGGBB (first char is skipped) */
 	char strbuf[16];
 	char strbuf[16];
@@ -979,7 +979,7 @@ int Nget_interpolated_values_cmd(data, interp, argc, argv)
 	 - string do not: values are kept constant and change when there is a new one
 	 - string do not: values are kept constant and change when there is a new one
 
 
 ********************************************************************************/
 ********************************************************************************/
-int attr_interp_entries(int n, char** argvX, char** argvY, float **x, float **y, float **m)
+int attr_interp_entries(int n, const char** argvX, const char** argvY, float **x, float **y, float **m)
 {
 {
 	const char *function_name="attr_interp_entries";
 	const char *function_name="attr_interp_entries";
 
 
@@ -1005,7 +1005,7 @@ int attr_interp_entries(int n, char** argvX, char** argvY, float **x, float **y,
 	return(0);
 	return(0);
 }
 }
 
 
-int attr_interp_entries_string(int n, char** argvY, float **y)
+int attr_interp_entries_string(int n, const char** argvY, float **y)
 {
 {
 	int i;
 	int i;
 	*y = (float*) malloc(n*sizeof(float));
 	*y = (float*) malloc(n*sizeof(float));
@@ -1013,9 +1013,9 @@ int attr_interp_entries_string(int n, char** argvY, float **y)
 	return(0);
 	return(0);
 }
 }
 
 
-int attr_interp_colors(int n, char** argvX, char** argvY, float **x,
-							float **yr, float **yg, float **yb,
-							float **mr, float **mg, float **mb)
+int attr_interp_colors(int n, const char** argvX, const char** argvY, float **x,
+		       float **yr, float **yg, float **yb,
+		       float **mr, float **mg, float **mb)
 {
 {
 	const char *function_name="attr_interp_colors";
 	const char *function_name="attr_interp_colors";
 
 
@@ -1054,8 +1054,8 @@ int attr_interp_colors(int n, char** argvX, char** argvY, float **x,
 
 
 }
 }
 
 
-int attr_interp_colors_string(int n, char** argvY,
-							float **yr, float **yg, float **yb)
+int attr_interp_colors_string(int n, const char** argvY,
+			      float **yr, float **yg, float **yb)
 {
 {
 	int i;
 	int i;
 
 
@@ -1084,7 +1084,7 @@ float attr_eval_entry(float xvalue, int n, float *x, float *y, float *m)
 	}
 	}
 }
 }
 
 
-float attr_eval_entry_string(char* xvalue, int n, char** x, float* y)
+float attr_eval_entry_string(const char* xvalue, int n, const char** x, float* y)
 {
 {
 	int i;
 	int i;
 	if (strcmp(xvalue, x[0]) <= 0) return(y[0]);
 	if (strcmp(xvalue, x[0]) <= 0) return(y[0]);
@@ -1097,8 +1097,8 @@ float attr_eval_entry_string(char* xvalue, int n, char** x, float* y)
 }
 }
 
 
 int attr_eval_color(float xvalue, int n, float *x,
 int attr_eval_color(float xvalue, int n, float *x,
-							float *yr, float *yg, float *yb,
-							float *mr, float *mg, float *mb)
+		    float *yr, float *yg, float *yb,
+		    float *mr, float *mg, float *mb)
 {
 {
 	int i;
 	int i;
 	float r, g, b, dx;
 	float r, g, b, dx;
@@ -1118,8 +1118,8 @@ int attr_eval_color(float xvalue, int n, float *x,
 	}
 	}
 }
 }
 
 
-int attr_eval_color_string(char* xvalue, int n, char** x,
-							float *yr, float *yg, float *yb)
+int attr_eval_color_string(const char* xvalue, int n, const char** x,
+			   float *yr, float *yg, float *yb)
 {
 {
 	int i;
 	int i;
 
 

+ 1 - 1
visualization/nviz/src/site_highlight_commands.c

@@ -277,7 +277,7 @@ geopoint * site_highlight_get_geopoint(geosite * gp, int cat)
 }
 }
 
 
 
 
-int site_highlight_loop(geosite * gp, char ** argvPtr, int argcPtr, int what, int flag, float value)
+int site_highlight_loop(geosite * gp, const char ** argvPtr, int argcPtr, int what, int flag, float value)
 {
 {
 	geopoint * gpt;
 	geopoint * gpt;
 	int i;
 	int i;