legal_vname.c

Go to the documentation of this file.
00001 #include <string.h>
00002 #include <grass/gis.h>
00003 #include <grass/Vect.h>
00004 #include <grass/glocale.h>
00005 
00016 int Vect_legal_filename (char *s)
00017 {
00018     char buf[GNAME_MAX];
00019     
00020     sprintf(buf, "%s", s);
00021     
00022     if (*s == '.' || *s == 0) {
00023         fprintf(stderr, _("Illegal vector map name <%s>. May not contain '.' or 'NULL'.\n"), buf);
00024         return -1;
00025     }
00026 
00027     /* file name must start with letter */
00028     if (! ((*s >= 'A' && *s <= 'Z') || (*s >= 'a' && *s <= 'z')) ) {
00029         fprintf(stderr, _("Illegal vector map name <%s>. Must start with a letter.\n"), buf);
00030         return -1;
00031     }
00032 
00033     for (s++ ; *s; s++)
00034         if (! ((*s >= 'A' && *s <= 'Z') || (*s >= 'a' && *s <= 'z') || (*s >= '0' && *s <= '9') || *s == '_' || *s == '@' ) ) {
00035                 fprintf(stderr, _("Illegal vector map name <%s>. Character <%c> not allowed.\n"), buf, *s);
00036             return -1;
00037         }
00038 
00039     return 1;
00040 }
00041 
00054 int Vect_check_input_output_name ( char * input, char * output, int error )
00055 {
00056     char *mapset;
00057 
00058     if ( Vect_legal_filename(output) == -1 ) {
00059         if ( error == GV_FATAL_EXIT ) {
00060             G_fatal_error ( _("Output name '%s' is not valid vector name."), output );  
00061         } else if ( error == GV_FATAL_PRINT ) {
00062             G_warning ( _("Output name '%s' is not valid vector name."), output );
00063             return 1;
00064         } else { /* GV_FATAL_RETURN */
00065             return 1;
00066         }
00067     }
00068 
00069     mapset = G_find_vector2 (input, "");
00070     
00071     if ( mapset == NULL ) {
00072         if ( error == GV_FATAL_EXIT ) {
00073             G_fatal_error ( _("Cannot find input map '%s'"), input );  
00074         } else if ( error == GV_FATAL_PRINT ) {
00075             G_warning ( _("Cannot find input map '%s'"), input );
00076             return 1;
00077         } else { /* GV_FATAL_RETURN */
00078             return 1;
00079         }
00080     }
00081 
00082     if ( strcmp(mapset,G_mapset()) == 0 ) {
00083         char *in, nm[1000], ms[1000];
00084         
00085         if ( G__name_is_fully_qualified(input,nm,ms) ) {
00086             in = nm;
00087         } else {
00088             in = input;
00089         }
00090         
00091         if ( strcmp(in,output) == 0 ) {
00092             if ( error == GV_FATAL_EXIT ) {
00093                 G_fatal_error ( _("Output map '%s' is used as input"), output );  
00094             } else if ( error == GV_FATAL_PRINT ) {
00095                 G_warning ( _("Output map '%s' is used as input"), output );
00096                 return 1;
00097             } else { /* GV_FATAL_RETURN */
00098                 return 1;
00099             }
00100         }
00101     }
00102 
00103     return 0;
00104 }
00105 

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