! . */
| 3664 | |
| 3665 | /*! . */ |
| 3666 | GMT_LOCAL int gmtapi_export_postscript (struct GMTAPI_CTRL *API, int object_ID, unsigned int mode, struct GMT_POSTSCRIPT *P_obj) { |
| 3667 | /* Does the actual work of writing out the specified PS to a destination. |
| 3668 | * The mode not used yet. |
| 3669 | */ |
| 3670 | int item, error; |
| 3671 | unsigned int kind; |
| 3672 | struct GMTAPI_DATA_OBJECT *S_obj = NULL; |
| 3673 | struct GMT_POSTSCRIPT *P_copy = NULL; |
| 3674 | struct GMT_POSTSCRIPT_HIDDEN *PH = NULL; |
| 3675 | struct GMT_CTRL *GMT = API->GMT; |
| 3676 | |
| 3677 | GMT_Report (API, GMT_MSG_DEBUG, "gmtapi_export_postscript: Passed ID = %d and mode = %d\n", object_ID, mode); |
| 3678 | |
| 3679 | if (object_ID == GMT_NOTSET) return (gmtlib_report_error (API, GMT_OUTPUT_NOT_SET)); |
| 3680 | if ((item = gmtlib_validate_id (API, GMT_IS_POSTSCRIPT, object_ID, GMT_OUT, GMT_NOTSET)) == GMT_NOTSET) return (gmtlib_report_error (API, API->error)); |
| 3681 | |
| 3682 | S_obj = API->object[item]; /* This is the API object for the output destination */ |
| 3683 | if (S_obj->status != GMT_IS_UNUSED && !(mode & GMT_IO_RESET)) { /* Only allow writing of a data set once, unless we override by resetting the mode */ |
| 3684 | return (gmtlib_report_error (API, GMT_WRITTEN_ONCE)); |
| 3685 | } |
| 3686 | if (mode & GMT_IO_RESET) mode -= GMT_IO_RESET; |
| 3687 | |
| 3688 | /* Passed sanity and allowed to write */ |
| 3689 | |
| 3690 | switch (S_obj->method) { /* File, array, stream etc ? */ |
| 3691 | case GMT_IS_FILE: |
| 3692 | /* gmtlib_write_ps will report where it is writing from if level is GMT_MSG_INFORMATION */ |
| 3693 | GMT_Report (API, GMT_MSG_INFORMATION, "Write PS to %s %s\n", gmtapi_method (S_obj->method), S_obj->filename); |
| 3694 | if ((error = gmtlib_write_ps (GMT, S_obj->filename, S_obj->method, mode, P_obj))) return (gmtlib_report_error (API, error)); |
| 3695 | break; |
| 3696 | case GMT_IS_STREAM: |
| 3697 | /* gmtlib_write_ps will report where it is writing from if level is GMT_MSG_INFORMATION */ |
| 3698 | kind = (S_obj->fp == GMT->session.std[GMT_OUT]) ? 0 : 1; /* 0 if stdout, 1 otherwise for user pointer */ |
| 3699 | GMT_Report (API, GMT_MSG_INFORMATION, "Write PS to %s %s output stream\n", gmtapi_method (S_obj->method), GMT_stream[kind]); |
| 3700 | if ((error = gmtlib_write_ps (GMT, S_obj->fp, S_obj->method, mode, P_obj))) return (gmtlib_report_error (API, error)); |
| 3701 | break; |
| 3702 | case GMT_IS_FDESC: |
| 3703 | /* gmtlib_write_ps will report where it is writing from if level is GMT_MSG_INFORMATION */ |
| 3704 | kind = (*((int *)S_obj->fp) == GMT_OUT) ? 0 : 1; /* 0 if stdout, 1 otherwise for user pointer */ |
| 3705 | GMT_Report (API, GMT_MSG_INFORMATION, "Write PS to %s %s output stream\n", gmtapi_method (S_obj->method), GMT_stream[kind]); |
| 3706 | if ((error = gmtlib_write_ps (GMT, S_obj->fp, S_obj->method, mode, P_obj))) return (gmtlib_report_error (API, error)); |
| 3707 | break; |
| 3708 | case GMT_IS_DUPLICATE: /* Duplicate the input cpt */ |
| 3709 | if (S_obj->resource) return (gmtlib_report_error (API, GMT_PTR_NOT_NULL)); /* The output resource must be NULL */ |
| 3710 | GMT_Report (API, GMT_MSG_INFORMATION, "Duplicating PS to GMT_POSTSCRIPT memory location\n"); |
| 3711 | if ((P_copy = GMT_Duplicate_Data (API, GMT_IS_POSTSCRIPT, mode, P_obj))) |
| 3712 | return (gmtlib_report_error (API, GMT_MEMORY_ERROR)); |
| 3713 | S_obj->resource = P_copy; /* Set resource pointer from object to this PS */ |
| 3714 | break; |
| 3715 | case GMT_IS_REFERENCE: /* Just pass memory location */ |
| 3716 | if (S_obj->resource) return (gmtlib_report_error (API, GMT_PTR_NOT_NULL)); /* The output resource must be NULL */ |
| 3717 | GMT_Report (API, GMT_MSG_INFORMATION, "Referencing PS to GMT_POSTSCRIPT memory location\n"); |
| 3718 | PH = gmt_get_P_hidden (P_obj); |
| 3719 | PH->alloc_level = S_obj->alloc_level; /* Since we are passing it up to the caller */ |
| 3720 | S_obj->resource = P_obj; /* Set resource pointer from object to this PS */ |
| 3721 | break; |
| 3722 | default: |
| 3723 | GMT_Report (API, GMT_MSG_ERROR, "Wrong method used to export PS\n"); |
no test coverage detected