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

get_projname.c

Go to the documentation of this file.
00001 /*
00002  ****************************************************************************
00003  *
00004  * MODULE:       GRASS 5 gis library, get_projname.c
00005  * AUTHOR(S):    unknown
00006  * PURPOSE:      Get projection name from user
00007  * COPYRIGHT:    (C) 2000 by the GRASS Development Team
00008  *
00009  *               This program is free software under the GNU General Public
00010  *               License (>=v2). Read the file COPYING that comes with GRASS
00011  *               for details.
00012  *
00013  *****************************************************************************/
00014 
00015 #include <string.h>
00016 #include <unistd.h>
00017 #include <stdlib.h>
00018 #include <grass/gis.h>
00019 #include <grass/glocale.h>
00020 
00021 int G_ask_proj_name(char *proj_id, char *proj_name)
00022 {
00023     char path[GPATH_MAX], buff[GPATH_MAX], answer[50], *a;
00024     struct Key_Value *in_proj_keys;
00025     char *Tmp_file;
00026     FILE *Tmp_fd = NULL;
00027     int in_stat, i, npr;
00028 
00029     sprintf(path, "%s/etc/projections", G_gisbase());
00030     while (access(path, 0) != 0)
00031         G_fatal_error(_("%s not found"), path);
00032     in_proj_keys = G_read_key_value_file(path, &in_stat);
00033     if (in_stat != 0)
00034         G_fatal_error(_("ERROR in reading %s"), path);
00035     npr = in_proj_keys->nitems;
00036     Tmp_file = G_tempfile();
00037     if (NULL == (Tmp_fd = fopen(Tmp_file, "w"))) {
00038         G_fatal_error(_("Cannot open temp file"));
00039     }
00040     for (i = 0; i < npr; i++) {
00041         fprintf(Tmp_fd, "%s -- %s\n", in_proj_keys->key[i],
00042                 in_proj_keys->value[i]);
00043     }
00044     fclose(Tmp_fd);
00045 
00046     for (;;) {
00047 
00048         do {
00049             fprintf(stderr, _("\n\nPlease specify projection name\n"));
00050             fprintf(stderr,
00051                     _("Enter 'list' for the list of available projections\n"));
00052             fprintf(stderr, _("Hit RETURN to cancel request\n"));
00053             fprintf(stderr, ">");
00054         } while (!G_gets(answer));
00055 
00056         G_strip(answer);
00057         if (strlen(answer) == 0)
00058             return -1;
00059         if (strcmp(answer, "list") == 0) {
00060             char *pager;
00061 
00062             pager = getenv("GRASS_PAGER");
00063             if (!pager || strlen(pager) == 0)
00064                 pager = "cat";
00065 
00066             /* Always print interactive output to stderr */
00067             sprintf(buff, "%s \"%s\" 1>&2", pager,
00068                     G_convert_dirseps_to_host(Tmp_file));
00069             G_system(buff);
00070         }
00071         else {
00072             a = G_find_key_value(answer, in_proj_keys);
00073             if (a == NULL) {
00074                 fprintf(stderr, _("\ninvalid projection\n"));
00075             }
00076             else
00077                 break;
00078         }
00079     }
00080 
00081     sprintf(proj_id, "%s", answer);
00082     sprintf(proj_name, "%s", a);
00083     remove(Tmp_file);
00084     return 1;
00085 }

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