! . */
| 731 | |
| 732 | /*! . */ |
| 733 | int GMT_Destroy_Options (void *V_API, struct GMT_OPTION **head) { |
| 734 | /* Delete the entire linked list of options, such as those created by GMT_Create_Options */ |
| 735 | |
| 736 | struct GMT_OPTION *current = NULL, *to_delete = NULL; |
| 737 | struct GMTAPI_CTRL *API = NULL; |
| 738 | |
| 739 | if (V_API == NULL) return_error (V_API, GMT_NOT_A_SESSION); /* GMT_Create_Session has not been called */ |
| 740 | API = gmtparse_get_api_ptr (V_API); /* Cast to GMTAPI_CTRL pointer */ |
| 741 | |
| 742 | current = *head; |
| 743 | if (current && current->option < 0) { |
| 744 | GMT_Report(API, GMT_MSG_ERROR, "GMT_Destroy_Options(): GMT_OPTION struct has junk. Returning before crash\n"); |
| 745 | *head = NULL; |
| 746 | return (GMT_OK); /* Should we return an error state instead? */ |
| 747 | } |
| 748 | |
| 749 | while (current) { /* Start at head and loop over the list and delete the options, one by one. */ |
| 750 | to_delete = current; /* The one we want to delete */ |
| 751 | current = current->next; /* But first grab the pointer to the next item */ |
| 752 | gmt_M_str_free (to_delete->arg); /* The option had a text argument allocated by strdup, so free it first */ |
| 753 | gmt_M_free (API->GMT, to_delete); /* Then free the structure which was allocated by gmt_M_memory */ |
| 754 | } |
| 755 | *head = NULL; /* Reset head to NULL value since it no longer points to any allocated memory */ |
| 756 | return (GMT_OK); /* No error encountered */ |
| 757 | } |
| 758 | |
| 759 | /*! . */ |
| 760 | struct GMT_OPTION *GMT_Duplicate_Options (void *V_API, struct GMT_OPTION *head) { |