ModelicaUtilities.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * This file is part of OpenModelica.
  3. *
  4. * Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
  5. * c/o Linköpings universitet, Department of Computer and Information Science,
  6. * SE-58183 Linköping, Sweden.
  7. *
  8. * All rights reserved.
  9. *
  10. * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE BSD NEW LICENSE OR THE
  11. * GPL VERSION 3 LICENSE OR THE OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
  12. * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
  13. * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
  14. * ACCORDING TO RECIPIENTS CHOICE.
  15. *
  16. * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
  17. * Public License (OSMC-PL) are obtained from OSMC, either from the above
  18. * address, from the URLs: http://www.openmodelica.org or
  19. * http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica
  20. * distribution. GNU version 3 is obtained from:
  21. * http://www.gnu.org/copyleft/gpl.html. The New BSD License is obtained from:
  22. * http://www.opensource.org/licenses/BSD-3-Clause.
  23. *
  24. * This program is distributed WITHOUT ANY WARRANTY; without even the implied
  25. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS
  26. * EXPRESSLY SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE
  27. * CONDITIONS OF OSMC-PL.
  28. *
  29. */
  30. #include "ModelicaUtilities.h"
  31. #include "modelica_string.h"
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include "omc_error.h"
  35. void ModelicaMessage(const char* string) {
  36. ModelicaFormatMessage("%s", string);
  37. }
  38. extern void ModelicaVFormatMessage(const char*string, va_list args) {
  39. va_infoStreamPrint(LOG_STDOUT, 0, string, args);
  40. }
  41. void ModelicaFormatMessage(const char* string,...) {
  42. va_list args;
  43. va_start(args, string);
  44. ModelicaVFormatMessage(string, args);
  45. va_end(args);
  46. }
  47. MODELICA_NORETURN void OpenModelica_Simulation_ModelicaError(const char* string) MODELICA_NORETURNATTR;
  48. void OpenModelica_Simulation_ModelicaError(const char* string) {
  49. throwStreamPrint(NULL, "%s", string);
  50. }
  51. MODELICA_NORETURN void OpenModelica_Simulation_ModelicaVFormatError(const char*string, va_list args) MODELICA_NORETURNATTR;
  52. void OpenModelica_Simulation_ModelicaVFormatError(const char*string, va_list args) {
  53. va_throwStreamPrint(NULL, string, args);
  54. }
  55. void (*OpenModelica_ModelicaError)(const char*) MODELICA_NORETURNATTR = OpenModelica_Simulation_ModelicaError;
  56. void (*OpenModelica_ModelicaVFormatError)(const char*,va_list) MODELICA_NORETURNATTR = OpenModelica_Simulation_ModelicaVFormatError;
  57. void ModelicaError(const char* string) {
  58. OpenModelica_ModelicaError(string);
  59. }
  60. void ModelicaVFormatError(const char*string, va_list args) {
  61. OpenModelica_ModelicaVFormatError(string,args);
  62. }
  63. void ModelicaFormatError(const char* string, ...) {
  64. va_list args;
  65. va_start(args, string);
  66. OpenModelica_ModelicaVFormatError(string,args);
  67. va_end(args);
  68. }
  69. char* ModelicaAllocateString(size_t len) {
  70. char *res = ModelicaAllocateStringWithErrorReturn(len);
  71. if (!res) {
  72. ModelicaFormatError("%s:%d: ModelicaAllocateString failed", __FILE__, __LINE__);
  73. }
  74. return res;
  75. }
  76. char* ModelicaAllocateStringWithErrorReturn(size_t len) {
  77. char *res = omc_alloc_interface.malloc_string(len+1);
  78. if (res != NULL) {
  79. res[len] = '\0';
  80. }
  81. return res;
  82. }