get_projname.c

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

Generated on Wed Dec 19 14:59:05 2007 for GRASS by  doxygen 1.5.4