PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ create_new_file_config()

static SHPLOADERCONFIG * create_new_file_config ( const char *  filename)
static

Definition at line 901 of file shp2pgsql-gui.c.

902{
903 SHPLOADERCONFIG *loader_file_config;
904 char *table_start, *table_end;
905 int i;
906
907 /* Generate a new configuration by copying the global options first and then
908 adding in the specific values for this file */
909 loader_file_config = malloc(sizeof(SHPLOADERCONFIG));
910 memcpy(loader_file_config, global_loader_config, sizeof(SHPLOADERCONFIG));
911
912 /* Note: we must copy the encoding here since it is the only pass-by-reference
913 type set in set_loader_config_defaults() and each config needs its own copy
914 of any referenced items */
915 loader_file_config->encoding = strdup(global_loader_config->encoding);
916 if ( loader_file_config->encoding == NULL )
917 {
918 free(loader_file_config);
919 pgui_seterr("Unable to allocate memory for encoding");
920 return 0;
921 }
922
923 /* Copy the filename (we'll remove the .shp extension in a sec) */
924 loader_file_config->shp_file = strdup(filename);
925 if ( loader_file_config->shp_file == NULL )
926 {
927 free(loader_file_config->encoding);
928 free(loader_file_config);
929 pgui_seterr("Unable to allocate memory for filename");
930 return 0;
931 }
932
933 /* Generate the default table name from the filename */
934 table_start = loader_file_config->shp_file + strlen(loader_file_config->shp_file);
935 while (*table_start != '/' && *table_start != '\\' && table_start > loader_file_config->shp_file)
936 table_start--;
937
938 /* Forward one to start of actual characters */
939 table_start++;
940
941 /* Roll back from end to first . character. */
942 table_end = loader_file_config->shp_file + strlen(loader_file_config->shp_file);
943 while (*table_end != '.' && table_end > loader_file_config->shp_file && table_end > table_start )
944 table_end--;
945
946 /* Copy the table name */
947 loader_file_config->table = malloc(table_end - table_start + 1);
948 memcpy(loader_file_config->table, table_start, table_end - table_start);
949 loader_file_config->table[table_end - table_start] = '\0';
950
951 /* Force the table name to lower case */
952 for (i = 0; i < table_end - table_start; i++)
953 {
954 if (isupper(loader_file_config->table[i]) != 0)
955 loader_file_config->table[i] = tolower(loader_file_config->table[i]);
956 }
957
958 /* Set the default schema to public */
959 loader_file_config->schema = strdup("public");
960
961 /* Set the default geo column name */
963 loader_file_config->geo_col = strdup(GEOGRAPHY_DEFAULT);
964 else
965 loader_file_config->geo_col = strdup(GEOMETRY_DEFAULT);
966
967 return loader_file_config;
968}
void * malloc(YYSIZE_T)
void free(void *)
#define GEOGRAPHY_DEFAULT
#define GEOMETRY_DEFAULT
static void static void static void static void pgui_seterr(const char *fmt,...) __attribute__((format(printf
static SHPLOADERCONFIG * global_loader_config

References shp_loader_config::encoding, free(), shp_loader_config::geo_col, shp_loader_config::geography, GEOGRAPHY_DEFAULT, GEOMETRY_DEFAULT, global_loader_config, malloc(), pgui_seterr(), shp_loader_config::schema, shp_loader_config::shp_file, and shp_loader_config::table.

Referenced by pgui_action_open_file_dialog(), and process_single_uri().

Here is the call graph for this function:
Here is the caller graph for this function: