• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

legal_name.c

Go to the documentation of this file.
00001 
00017 #include <stdio.h>
00018 #include <string.h>
00019 #include <grass/gis.h>
00020 #include <grass/glocale.h>
00021 
00022 
00036 int G_legal_filename(const char *s)
00037 {
00038     if (*s == '.' || *s == 0) {
00039         fprintf(stderr, _("Illegal filename.  Cannot be '.' or 'NULL'\n"));
00040         return -1;
00041     }
00042 
00043     for (; *s; s++)
00044         if (*s == '/' || *s == '"' || *s == '\'' || *s <= ' ' ||
00045             *s == '@' || *s == ',' || *s == '=' || *s == '*' || *s > 0176) {
00046             fprintf(stderr,
00047                     _("Illegal filename. Character <%c> not allowed.\n"), *s);
00048             return -1;
00049         }
00050 
00051     return 1;
00052 }
00053 
00054 
00068 int G_check_input_output_name(const char *input, const char *output,
00069                               int error)
00070 {
00071     char *mapset;
00072 
00073     if (output == NULL)
00074         return 0;               /* don't die on undefined parameters */
00075     if (G_legal_filename(output) == -1) {
00076         if (error == GR_FATAL_EXIT) {
00077             G_fatal_error(_("Output raster map name <%s> is not valid map name"),
00078                           output);
00079         }
00080         else if (error == GR_FATAL_PRINT) {
00081             G_warning(_("Output raster map name <%s> is not valid map name"),
00082                       output);
00083             return 1;
00084         }
00085         else {                  /* GR_FATAL_RETURN */
00086             return 1;
00087         }
00088     }
00089 
00090     mapset = G_find_cell2(input, "");
00091 
00092     if (mapset == NULL) {
00093         if (error == GR_FATAL_EXIT) {
00094             G_fatal_error(_("Raster map <%s> not found"), input);
00095         }
00096         else if (error == GR_FATAL_PRINT) {
00097             G_warning(_("Raster map <%s> not found"), input);
00098             return 1;
00099         }
00100         else {                  /* GR_FATAL_RETURN */
00101             return 1;
00102         }
00103     }
00104 
00105     if (strcmp(mapset, G_mapset()) == 0) {
00106         char nm[1000], ms[1000];
00107         const char *in;
00108 
00109         if (G__name_is_fully_qualified(input, nm, ms)) {
00110             in = nm;
00111         }
00112         else {
00113             in = input;
00114         }
00115 
00116         if (strcmp(in, output) == 0) {
00117             if (error == GR_FATAL_EXIT) {
00118                 G_fatal_error(_("Output raster map <%s> is used as input"),
00119                               output);
00120             }
00121             else if (error == GR_FATAL_PRINT) {
00122                 G_warning(_("Output raster map <%s> is used as input"),
00123                           output);
00124                 return 1;
00125             }
00126             else {              /* GR_FATAL_RETURN */
00127                 return 1;
00128             }
00129         }
00130     }
00131 
00132     return 0;
00133 }

Generated on Wed Oct 13 2010 12:09:29 for GRASS Programmer's Manual by  doxygen 1.7.1