MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / gmtapi_import_postscript

Function gmtapi_import_postscript

src/gmt_api.c:3590–3663  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3588
3589/*! . */
3590GMT_LOCAL struct GMT_POSTSCRIPT * gmtapi_import_postscript (struct GMTAPI_CTRL *API, int object_ID, unsigned int mode) {
3591 /* Does the actual work of loading in a PS struct.
3592 * The mode is not used yet.
3593 * Note: Memory is allocated to hold the GMT_POSTSCRIPT structure except for method GMT_IS_REFERENCE.
3594 */
3595
3596 int item;
3597 unsigned int kind;
3598 struct GMT_POSTSCRIPT *P_obj = NULL, *P_orig = NULL;
3599 struct GMT_POSTSCRIPT_HIDDEN *PH = NULL;
3600 struct GMTAPI_DATA_OBJECT *S_obj = NULL;
3601 struct GMT_CTRL *GMT = API->GMT;
3602
3603 GMT_Report (API, GMT_MSG_DEBUG, "gmtapi_import_postscript: Passed ID = %d and mode = %d\n", object_ID, mode);
3604
3605 if (object_ID == GMT_NOTSET) return_null (API, GMT_NO_INPUT);
3606 if ((item = gmtlib_validate_id (API, GMT_IS_POSTSCRIPT, object_ID, GMT_IN, GMTAPI_OPTION_INPUT)) == GMT_NOTSET)
3607 return_null (API, API->error);
3608
3609 S_obj = API->object[item]; /* Use S_obj as shorthand */
3610 if (S_obj->status != GMT_IS_UNUSED) { /* Already read this resource before; are we allowed to re-read? */
3611 if (S_obj->method == GMT_IS_STREAM || S_obj->method == GMT_IS_FDESC) return_null (API, GMT_READ_ONCE); /* Not allowed to re-read streams */
3612 if (!(mode & GMT_IO_RESET)) return_null (API, GMT_READ_ONCE); /* Not authorized to re-read */
3613 }
3614
3615 /* Passed sanity and allowed to read */
3616
3617 switch (S_obj->method) { /* File, array, stream etc ? */
3618 case GMT_IS_FILE:
3619 /* gmtlib_read_ps will report where it is reading from if level is GMT_MSG_INFORMATION */
3620 GMT_Report (API, GMT_MSG_INFORMATION, "Reading PS from %s %s\n", gmtapi_method (S_obj->method), S_obj->filename);
3621 if ((P_obj = gmtlib_read_ps (GMT, S_obj->filename, S_obj->method, mode)) == NULL)
3622 return_null (API, GMT_CPT_READ_ERROR);
3623 S_obj->resource = P_obj; /* Retain pointer to the allocated data so we use garbage collection later */
3624 break;
3625 case GMT_IS_STREAM:
3626 /* gmtlib_read_ps will report where it is reading from if level is GMT_MSG_INFORMATION */
3627 kind = (S_obj->fp == GMT->session.std[GMT_IN]) ? 0 : 1; /* 0 if stdin, 1 otherwise for user pointer */
3628 GMT_Report (API, GMT_MSG_INFORMATION, "Reading PS from %s %s stream\n", gmtapi_method (S_obj->method), GMT_stream[kind]);
3629 if ((P_obj = gmtlib_read_ps (GMT, S_obj->fp, S_obj->method, mode)) == NULL)
3630 return_null (API, GMT_CPT_READ_ERROR);
3631 S_obj->resource = P_obj; /* Retain pointer to the allocated data so we use garbage collection later */
3632 break;
3633 case GMT_IS_FDESC:
3634 /* gmtlib_read_ps will report where it is reading from if level is GMT_MSG_INFORMATION */
3635 kind = (*((int *)S_obj->fp) == GMT_IN) ? 0 : 1; /* 0 if stdin, 1 otherwise for user pointer */
3636 GMT_Report (API, GMT_MSG_INFORMATION, "Reading PS from %s %s stream\n", gmtapi_method (S_obj->method), GMT_stream[kind]);
3637 if ((P_obj = gmtlib_read_ps (GMT, S_obj->fp, S_obj->method, mode)) == NULL)
3638 return_null (API, GMT_CPT_READ_ERROR);
3639 S_obj->resource = P_obj; /* Retain pointer to the allocated data so we use garbage collection later */
3640 break;
3641 case GMT_IS_DUPLICATE: /* Duplicate the input CPT palette */
3642 GMT_Report (API, GMT_MSG_INFORMATION, "Duplicating PS from GMT_POSTSCRIPT memory location\n");
3643 if ((P_orig = S_obj->resource) == NULL) return_null (API, GMT_PTR_IS_NULL);
3644 if ((P_obj = GMT_Duplicate_Data (API, GMT_IS_POSTSCRIPT, mode, P_orig)))
3645 return_null (API, GMT_MEMORY_ERROR);
3646 break;
3647 case GMT_IS_REFERENCE: /* Just pass memory location, so nothing is allocated */

Callers 1

gmtapi_import_dataFunction · 0.85

Calls 6

GMT_ReportFunction · 0.85
gmtlib_validate_idFunction · 0.85
gmtapi_methodFunction · 0.85
gmtlib_read_psFunction · 0.85
GMT_Duplicate_DataFunction · 0.85
gmt_get_P_hiddenFunction · 0.85

Tested by

no test coverage detected