1 #include <unistd.h> 2 #include "global.h" 3 4 static int which_env = -1; /* 0 = cur, 1 = target */ 5 select_current_env(void)6int select_current_env(void) 7 { 8 if (which_env < 0) { 9 G_create_alt_env(); 10 which_env = 0; 11 } 12 if (which_env != 0) { 13 G_switch_env(); 14 which_env = 0; 15 } 16 17 return 0; 18 } 19 select_target_env(void)20int select_target_env(void) 21 { 22 if (which_env < 0) { 23 G_create_alt_env(); 24 which_env = 1; 25 } 26 if (which_env != 1) { 27 G_switch_env(); 28 which_env = 1; 29 } 30 31 return 0; 32 } 33 show_env(void)34int show_env(void) 35 { 36 fprintf(stderr, "env(%d) switch to LOCATION %s, MAPSET %s\n", which_env, 37 G_getenv_nofatal("LOCATION_NAME") == 38 NULL ? "?" : G_getenv_nofatal("LOCATION_NAME"), 39 G_getenv_nofatal("MAPSET") == NULL ? "?" : G_getenv_nofatal("MAPSET")); 40 G_sleep(2); 41 42 return 0; 43 } 44