00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <string.h>
00018 #include <unistd.h>
00019 #include <stdlib.h>
00020 #include "gis.h"
00021 #include "glocale.h"
00022
00023 int G_ask_proj_name(proj_id, proj_name)
00024 char *proj_id;
00025 char *proj_name;
00026 {
00027 char path[1024], buff[1024], answer[50], *a;
00028 struct Key_Value *in_proj_keys;
00029 char *Tmp_file;
00030 FILE *Tmp_fd = NULL;
00031 int in_stat, i, npr;
00032
00033 sprintf(path,"%s/etc/projections",G_gisbase());
00034 while (access(path,0) !=0)
00035 {
00036 sprintf(buff,_("%s not found"),path);
00037 G_fatal_error(buff);
00038 }
00039 in_proj_keys = G_read_key_value_file(path,&in_stat);
00040 if (in_stat != 0)
00041 {
00042 sprintf(buff,_("ERROR in reading %s"),path);
00043 G_fatal_error(buff);
00044 }
00045 npr = in_proj_keys->nitems;
00046 Tmp_file = G_tempfile ();
00047 if (NULL == (Tmp_fd = fopen (Tmp_file, "w"))) {
00048 G_fatal_error(_("Cannot open temp file")) ;
00049 }
00050 for (i=0; i<npr; i++) {
00051 fprintf(Tmp_fd,"%s -- %s\n",in_proj_keys->key[i],in_proj_keys->value[i]);
00052 }
00053 fclose(Tmp_fd);
00054
00055 for(;;) {
00056
00057 do {
00058 fprintf(stderr,_("\n\nPlease specify projection name\n"));
00059 fprintf(stderr,_("Enter 'list' for the list of available projections\n"));
00060 fprintf (stderr, _("Hit RETURN to cancel request\n"));
00061 fprintf(stderr,">");
00062 } while(!G_gets(answer));
00063
00064 G_strip(answer);
00065 if(strlen(answer)==0) return -1;
00066 if (strcmp(answer,"list") == 0) {
00067 if (isatty(1)) {
00068 sprintf(buff,"$GRASS_PAGER %s",Tmp_file);
00069 }
00070 else
00071 sprintf(buff,"cat %s",Tmp_file);
00072 system(buff);
00073 }
00074 else {
00075 a = G_find_key_value(answer,in_proj_keys);
00076 if (a==NULL)
00077 {
00078 fprintf(stderr,_("\ninvalid projection\n"));
00079 }
00080 else break;
00081 }
00082 }
00083
00084 sprintf(proj_id,"%s",answer);
00085 sprintf(proj_name,"%s",a);
00086 remove ( Tmp_file );
00087 return 1;
00088 }
00089