00001 #include <string.h>
00002 #include <grass/gis.h>
00003 #include <grass/glocale.h>
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00031 int G_legal_filename (char *s)
00032 {
00033 if (*s == '.' || *s == 0) {
00034 fprintf(stderr, _("Illegal filename. Cannot be '.' or 'NULL'\n"));
00035 return -1;
00036 }
00037
00038 for (; *s; s++)
00039 if (*s == '/' || *s == '"' || *s == '\'' || *s <= ' ' ||
00040 *s == '@' || *s == ',' || *s == '=' || *s == '*' || *s > 0176) {
00041 fprintf(stderr, _("Illegal filename. character <%c> not allowed.\n"), *s);
00042 return -1;
00043 }
00044
00045 return 1;
00046 }
00047
00060 int G_check_input_output_name ( char * input, char * output, int error )
00061 {
00062 char *mapset;
00063
00064 if ( output == NULL) return 0;
00065 if ( G_legal_filename(output) == -1 ) {
00066 if ( error == GR_FATAL_EXIT ) {
00067 G_fatal_error ( _("Output name '%s' is not valid rast name."), output );
00068 } else if ( error == GR_FATAL_PRINT ) {
00069 G_warning ( _("Output name '%s' is not valid rast name."), output );
00070 return 1;
00071 } else {
00072 return 1;
00073 }
00074 }
00075
00076 mapset = G_find_cell2 (input, "");
00077
00078 if ( mapset == NULL ) {
00079 if ( error == GR_FATAL_EXIT ) {
00080 G_fatal_error ( _("Cannot find input map '%s'"), input );
00081 } else if ( error == GR_FATAL_PRINT ) {
00082 G_warning ( _("Cannot find input map '%s'"), input );
00083 return 1;
00084 } else {
00085 return 1;
00086 }
00087 }
00088
00089 if ( strcmp(mapset,G_mapset()) == 0 ) {
00090 char *in, nm[1000], ms[1000];
00091
00092 if ( G__name_is_fully_qualified(input,nm,ms) ) {
00093 in = nm;
00094 } else {
00095 in = input;
00096 }
00097
00098 if ( strcmp(in,output) == 0 ) {
00099 if ( error == GR_FATAL_EXIT ) {
00100 G_fatal_error ( _("Output map '%s' is used as input"), output );
00101 } else if ( error == GR_FATAL_PRINT ) {
00102 G_warning ( _("Output map '%s' is used as input"), output );
00103 return 1;
00104 } else {
00105 return 1;
00106 }
00107 }
00108 }
00109
00110 return 0;
00111 }
00112