diff options
| author | Frank Warmerdam <warmerdam@pobox.com> | 2010-06-01 18:00:18 +0000 |
|---|---|---|
| committer | Frank Warmerdam <warmerdam@pobox.com> | 2010-06-01 18:00:18 +0000 |
| commit | 6ce177c84c3b5045edd2c630cdcd6236bec2eb2b (patch) | |
| tree | c056d64f56232ca573825f894072ddbb0975e1dd /src | |
| parent | dee2be7f508395ef4a58a75079480d4992a180f8 (diff) | |
| download | PROJ-6ce177c84c3b5045edd2c630cdcd6236bec2eb2b.tar.gz PROJ-6ce177c84c3b5045edd2c630cdcd6236bec2eb2b.zip | |
rework indentation
git-svn-id: http://svn.osgeo.org/metacrs/proj/trunk@1848 4e78687f-474d-0410-85f9-8d5e500ac6b2
Diffstat (limited to 'src')
| -rw-r--r-- | src/pj_init.c | 516 |
1 files changed, 258 insertions, 258 deletions
diff --git a/src/pj_init.c b/src/pj_init.c index 91230a70..17141b0f 100644 --- a/src/pj_init.c +++ b/src/pj_init.c @@ -87,17 +87,17 @@ get_opt(paralist **start, FILE *fid, char *name, paralist *next) { /************************************************************************/ static paralist * get_defaults(paralist **start, paralist *next, char *name) { - FILE *fid; - - if ( (fid = pj_open_lib("proj_def.dat", "rt")) != NULL) { - next = get_opt(start, fid, "general", next); - rewind(fid); - next = get_opt(start, fid, name, next); - (void)fclose(fid); - } - if (errno) - errno = 0; /* don't care if can't open file */ - return next; + FILE *fid; + + if ( (fid = pj_open_lib("proj_def.dat", "rt")) != NULL) { + next = get_opt(start, fid, "general", next); + rewind(fid); + next = get_opt(start, fid, name, next); + (void)fclose(fid); + } + if (errno) + errno = 0; /* don't care if can't open file */ + return next; } /************************************************************************/ @@ -105,48 +105,48 @@ get_defaults(paralist **start, paralist *next, char *name) { /************************************************************************/ static paralist * get_init(paralist **start, paralist *next, char *name) { - char fname[MAX_PATH_FILENAME+ID_TAG_MAX+3], *opt; - FILE *fid; - paralist *init_items = NULL; - const paralist *orig_next = next; + char fname[MAX_PATH_FILENAME+ID_TAG_MAX+3], *opt; + FILE *fid; + paralist *init_items = NULL; + const paralist *orig_next = next; - (void)strncpy(fname, name, MAX_PATH_FILENAME + ID_TAG_MAX + 1); + (void)strncpy(fname, name, MAX_PATH_FILENAME + ID_TAG_MAX + 1); - /* - ** Search for file/key pair in cache - */ + /* + ** Search for file/key pair in cache + */ - init_items = pj_search_initcache( name ); - if( init_items != NULL ) - { - next->next = init_items; - while( next->next != NULL ) - next = next->next; - return next; - } - - /* - ** Otherwise we try to open the file and search for it. - */ - if ((opt = strrchr(fname, ':')) != NULL) - *opt++ = '\0'; - else { pj_errno = -3; return(0); } - if ( (fid = pj_open_lib(fname, "rt")) != NULL) - next = get_opt(start, fid, opt, next); - else - return(0); - (void)fclose(fid); - if (errno == 25) - errno = 0; /* unknown problem with some sys errno<-25 */ - - /* - ** If we seem to have gotten a result, insert it into the - ** init file cache. - */ - if( next != NULL && next != orig_next ) - pj_insert_initcache( name, orig_next->next ); - - return next; + init_items = pj_search_initcache( name ); + if( init_items != NULL ) + { + next->next = init_items; + while( next->next != NULL ) + next = next->next; + return next; + } + + /* + ** Otherwise we try to open the file and search for it. + */ + if ((opt = strrchr(fname, ':')) != NULL) + *opt++ = '\0'; + else { pj_errno = -3; return(0); } + if ( (fid = pj_open_lib(fname, "rt")) != NULL) + next = get_opt(start, fid, opt, next); + else + return(0); + (void)fclose(fid); + if (errno == 25) + errno = 0; /* unknown problem with some sys errno<-25 */ + + /* + ** If we seem to have gotten a result, insert it into the + ** init file cache. + */ + if( next != NULL && next != orig_next ) + pj_insert_initcache( name, orig_next->next ); + + return next; } /************************************************************************/ @@ -220,211 +220,211 @@ pj_init_plus( const char *definition ) PJ * pj_init(int argc, char **argv) { - char *s, *name; - paralist *start = NULL; - PJ *(*proj)(PJ *); - paralist *curr; - int i; - PJ *PIN = 0; - const char *old_locale; - - errno = pj_errno = 0; - start = NULL; - - old_locale = setlocale(LC_NUMERIC, NULL); - setlocale(LC_NUMERIC,"C"); - - /* put arguments into internal linked list */ - if (argc <= 0) { pj_errno = -1; goto bum_call; } - for (i = 0; i < argc; ++i) - if (i) - curr = curr->next = pj_mkparam(argv[i]); - else - start = curr = pj_mkparam(argv[i]); - if (pj_errno) goto bum_call; - - /* check if +init present */ - if (pj_param(start, "tinit").i) { - paralist *last = curr; - - if (!(curr = get_init(&start, curr, pj_param(start, "sinit").s))) - goto bum_call; - if (curr == last) { pj_errno = -2; goto bum_call; } - } - - /* find projection selection */ - if (!(name = pj_param(start, "sproj").s)) - { pj_errno = -4; goto bum_call; } - for (i = 0; (s = pj_list[i].id) && strcmp(name, s) ; ++i) ; - if (!s) { pj_errno = -5; goto bum_call; } - - /* set defaults, unless inhibited */ - if (!pj_param(start, "bno_defs").i) - curr = get_defaults(&start, curr, name); - proj = (PJ *(*)(PJ *)) pj_list[i].proj; - - /* allocate projection structure */ - if (!(PIN = (*proj)(0))) goto bum_call; - PIN->params = start; - PIN->is_latlong = 0; - PIN->is_geocent = 0; - PIN->is_long_wrap_set = 0; - PIN->long_wrap_center = 0.0; - strcpy( PIN->axis, "enu" ); - - PIN->gridlist = NULL; - PIN->gridlist_count = 0; - - PIN->vgridlist_geoid = NULL; - PIN->vgridlist_geoid_count = 0; - - /* set datum parameters */ - if (pj_datum_set(start, PIN)) goto bum_call; - - /* set ellipsoid/sphere parameters */ - if (pj_ell_set(start, &PIN->a, &PIN->es)) goto bum_call; - - PIN->a_orig = PIN->a; - PIN->es_orig = PIN->es; - - PIN->e = sqrt(PIN->es); - PIN->ra = 1. / PIN->a; - PIN->one_es = 1. - PIN->es; - if (PIN->one_es == 0.) { pj_errno = -6; goto bum_call; } - PIN->rone_es = 1./PIN->one_es; - - /* Now that we have ellipse information check for WGS84 datum */ - if( PIN->datum_type == PJD_3PARAM - && PIN->datum_params[0] == 0.0 - && PIN->datum_params[1] == 0.0 - && PIN->datum_params[2] == 0.0 - && PIN->a == 6378137.0 - && ABS(PIN->es - 0.006694379990) < 0.000000000050 )/*WGS84/GRS80*/ - { - PIN->datum_type = PJD_WGS84; - } + char *s, *name; + paralist *start = NULL; + PJ *(*proj)(PJ *); + paralist *curr; + int i; + PJ *PIN = 0; + const char *old_locale; + + errno = pj_errno = 0; + start = NULL; + + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC,"C"); + + /* put arguments into internal linked list */ + if (argc <= 0) { pj_errno = -1; goto bum_call; } + for (i = 0; i < argc; ++i) + if (i) + curr = curr->next = pj_mkparam(argv[i]); + else + start = curr = pj_mkparam(argv[i]); + if (pj_errno) goto bum_call; + + /* check if +init present */ + if (pj_param(start, "tinit").i) { + paralist *last = curr; + + if (!(curr = get_init(&start, curr, pj_param(start, "sinit").s))) + goto bum_call; + if (curr == last) { pj_errno = -2; goto bum_call; } + } + + /* find projection selection */ + if (!(name = pj_param(start, "sproj").s)) + { pj_errno = -4; goto bum_call; } + for (i = 0; (s = pj_list[i].id) && strcmp(name, s) ; ++i) ; + if (!s) { pj_errno = -5; goto bum_call; } + + /* set defaults, unless inhibited */ + if (!pj_param(start, "bno_defs").i) + curr = get_defaults(&start, curr, name); + proj = (PJ *(*)(PJ *)) pj_list[i].proj; + + /* allocate projection structure */ + if (!(PIN = (*proj)(0))) goto bum_call; + PIN->params = start; + PIN->is_latlong = 0; + PIN->is_geocent = 0; + PIN->is_long_wrap_set = 0; + PIN->long_wrap_center = 0.0; + strcpy( PIN->axis, "enu" ); + + PIN->gridlist = NULL; + PIN->gridlist_count = 0; + + PIN->vgridlist_geoid = NULL; + PIN->vgridlist_geoid_count = 0; + + /* set datum parameters */ + if (pj_datum_set(start, PIN)) goto bum_call; + + /* set ellipsoid/sphere parameters */ + if (pj_ell_set(start, &PIN->a, &PIN->es)) goto bum_call; + + PIN->a_orig = PIN->a; + PIN->es_orig = PIN->es; + + PIN->e = sqrt(PIN->es); + PIN->ra = 1. / PIN->a; + PIN->one_es = 1. - PIN->es; + if (PIN->one_es == 0.) { pj_errno = -6; goto bum_call; } + PIN->rone_es = 1./PIN->one_es; + + /* Now that we have ellipse information check for WGS84 datum */ + if( PIN->datum_type == PJD_3PARAM + && PIN->datum_params[0] == 0.0 + && PIN->datum_params[1] == 0.0 + && PIN->datum_params[2] == 0.0 + && PIN->a == 6378137.0 + && ABS(PIN->es - 0.006694379990) < 0.000000000050 )/*WGS84/GRS80*/ + { + PIN->datum_type = PJD_WGS84; + } - /* set PIN->geoc coordinate system */ - PIN->geoc = (PIN->es && pj_param(start, "bgeoc").i); + /* set PIN->geoc coordinate system */ + PIN->geoc = (PIN->es && pj_param(start, "bgeoc").i); - /* over-ranging flag */ - PIN->over = pj_param(start, "bover").i; + /* over-ranging flag */ + PIN->over = pj_param(start, "bover").i; - /* longitude center for wrapping */ - PIN->has_geoid_vgrids = pj_param(start, "tgeoidgrids").i; + /* longitude center for wrapping */ + PIN->has_geoid_vgrids = pj_param(start, "tgeoidgrids").i; - /* longitude center for wrapping */ - PIN->is_long_wrap_set = pj_param(start, "tlon_wrap").i; - if (PIN->is_long_wrap_set) - PIN->long_wrap_center = pj_param(start, "rlon_wrap").f; + /* longitude center for wrapping */ + PIN->is_long_wrap_set = pj_param(start, "tlon_wrap").i; + if (PIN->is_long_wrap_set) + PIN->long_wrap_center = pj_param(start, "rlon_wrap").f; - /* axis orientation */ - if( (pj_param(start,"saxis").s) != NULL ) + /* axis orientation */ + if( (pj_param(start,"saxis").s) != NULL ) + { + static const char *axis_legal = "ewnsud"; + const char *axis_arg = pj_param(start,"saxis").s; + if( strlen(axis_arg) != 3 ) { - static const char *axis_legal = "ewnsud"; - const char *axis_arg = pj_param(start,"saxis").s; - if( strlen(axis_arg) != 3 ) - { - pj_errno = PJD_ERR_AXIS; - goto bum_call; - } - - if( strchr( axis_legal, axis_arg[0] ) == NULL - || strchr( axis_legal, axis_arg[1] ) == NULL - || (axis_arg[2] && strchr( axis_legal, axis_arg[1] ) == NULL)) - { - pj_errno = PJD_ERR_AXIS; - goto bum_call; - } + pj_errno = PJD_ERR_AXIS; + goto bum_call; + } - /* it would be nice to validate we don't have on axis repeated */ - strcpy( PIN->axis, axis_arg ); + if( strchr( axis_legal, axis_arg[0] ) == NULL + || strchr( axis_legal, axis_arg[1] ) == NULL + || (axis_arg[2] && strchr( axis_legal, axis_arg[1] ) == NULL)) + { + pj_errno = PJD_ERR_AXIS; + goto bum_call; } - PIN->is_long_wrap_set = pj_param(start, "tlon_wrap").i; - if (PIN->is_long_wrap_set) - PIN->long_wrap_center = pj_param(start, "rlon_wrap").f; - - /* central meridian */ - PIN->lam0=pj_param(start, "rlon_0").f; - - /* central latitude */ - PIN->phi0 = pj_param(start, "rlat_0").f; - - /* false easting and northing */ - PIN->x0 = pj_param(start, "dx_0").f; - PIN->y0 = pj_param(start, "dy_0").f; - - /* general scaling factor */ - if (pj_param(start, "tk_0").i) - PIN->k0 = pj_param(start, "dk_0").f; - else if (pj_param(start, "tk").i) - PIN->k0 = pj_param(start, "dk").f; - else - PIN->k0 = 1.; - if (PIN->k0 <= 0.) { - pj_errno = -31; - goto bum_call; - } - - /* set units */ - s = 0; - if ((name = pj_param(start, "sunits").s) != NULL) { - for (i = 0; (s = pj_units[i].id) && strcmp(name, s) ; ++i) ; - if (!s) { pj_errno = -7; goto bum_call; } - s = pj_units[i].to_meter; - } - if (s || (s = pj_param(start, "sto_meter").s)) { - PIN->to_meter = strtod(s, &s); - if (*s == '/') /* ratio number */ - PIN->to_meter /= strtod(++s, 0); - PIN->fr_meter = 1. / PIN->to_meter; - } else - PIN->to_meter = PIN->fr_meter = 1.; - - /* prime meridian */ - s = 0; - if ((name = pj_param(start, "spm").s) != NULL) { - const char *value = NULL; - char *next_str = NULL; - - for (i = 0; pj_prime_meridians[i].id != NULL; ++i ) + /* it would be nice to validate we don't have on axis repeated */ + strcpy( PIN->axis, axis_arg ); + } + + PIN->is_long_wrap_set = pj_param(start, "tlon_wrap").i; + if (PIN->is_long_wrap_set) + PIN->long_wrap_center = pj_param(start, "rlon_wrap").f; + + /* central meridian */ + PIN->lam0=pj_param(start, "rlon_0").f; + + /* central latitude */ + PIN->phi0 = pj_param(start, "rlat_0").f; + + /* false easting and northing */ + PIN->x0 = pj_param(start, "dx_0").f; + PIN->y0 = pj_param(start, "dy_0").f; + + /* general scaling factor */ + if (pj_param(start, "tk_0").i) + PIN->k0 = pj_param(start, "dk_0").f; + else if (pj_param(start, "tk").i) + PIN->k0 = pj_param(start, "dk").f; + else + PIN->k0 = 1.; + if (PIN->k0 <= 0.) { + pj_errno = -31; + goto bum_call; + } + + /* set units */ + s = 0; + if ((name = pj_param(start, "sunits").s) != NULL) { + for (i = 0; (s = pj_units[i].id) && strcmp(name, s) ; ++i) ; + if (!s) { pj_errno = -7; goto bum_call; } + s = pj_units[i].to_meter; + } + if (s || (s = pj_param(start, "sto_meter").s)) { + PIN->to_meter = strtod(s, &s); + if (*s == '/') /* ratio number */ + PIN->to_meter /= strtod(++s, 0); + PIN->fr_meter = 1. / PIN->to_meter; + } else + PIN->to_meter = PIN->fr_meter = 1.; + + /* prime meridian */ + s = 0; + if ((name = pj_param(start, "spm").s) != NULL) { + const char *value = NULL; + char *next_str = NULL; + + for (i = 0; pj_prime_meridians[i].id != NULL; ++i ) + { + if( strcmp(name,pj_prime_meridians[i].id) == 0 ) { - if( strcmp(name,pj_prime_meridians[i].id) == 0 ) - { - value = pj_prime_meridians[i].defn; - break; - } + value = pj_prime_meridians[i].defn; + break; } + } - if( value == NULL - && (dmstor(name,&next_str) != 0.0 || *name == '0') - && *next_str == '\0' ) - value = name; - - if (!value) { pj_errno = -46; goto bum_call; } - PIN->from_greenwich = dmstor(value,NULL); - } + if( value == NULL + && (dmstor(name,&next_str) != 0.0 || *name == '0') + && *next_str == '\0' ) + value = name; + + if (!value) { pj_errno = -46; goto bum_call; } + PIN->from_greenwich = dmstor(value,NULL); + } + else + PIN->from_greenwich = 0.0; + + /* projection specific initialization */ + if (!(PIN = (*proj)(PIN)) || errno || pj_errno) { + bum_call: /* cleanup error return */ + if (!pj_errno) + pj_errno = errno; + if (PIN) + pj_free(PIN); else - PIN->from_greenwich = 0.0; - - /* projection specific initialization */ - if (!(PIN = (*proj)(PIN)) || errno || pj_errno) { -bum_call: /* cleanup error return */ - if (!pj_errno) - pj_errno = errno; - if (PIN) - pj_free(PIN); - else - for ( ; start; start = curr) { - curr = start->next; - pj_dalloc(start); - } - PIN = 0; - } - setlocale(LC_NUMERIC,old_locale); - - return PIN; + for ( ; start; start = curr) { + curr = start->next; + pj_dalloc(start); + } + PIN = 0; + } + setlocale(LC_NUMERIC,old_locale); + + return PIN; } /************************************************************************/ @@ -439,22 +439,22 @@ bum_call: /* cleanup error return */ void pj_free(PJ *P) { - if (P) { - paralist *t = P->params, *n; - - /* free parameter list elements */ - for (t = P->params; t; t = n) { - n = t->next; - pj_dalloc(t); - } - - /* free array of grid pointers if we have one */ - if( P->gridlist != NULL ) - pj_dalloc( P->gridlist ); - - /* free projection parameters */ - P->pfree(P); - } + if (P) { + paralist *t = P->params, *n; + + /* free parameter list elements */ + for (t = P->params; t; t = n) { + n = t->next; + pj_dalloc(t); + } + + /* free array of grid pointers if we have one */ + if( P->gridlist != NULL ) + pj_dalloc( P->gridlist ); + + /* free projection parameters */ + P->pfree(P); + } } |
