OMCompiler/Compiler/Util/Print.mo
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of OpenModelica. | ||
| 3 | * | ||
| 4 | * Copyright (c) 1998-2026, 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 AGPL VERSION 3 LICENSE OR | ||
| 11 | * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. | ||
| 12 | * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES | ||
| 13 | * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL | ||
| 14 | * VERSION 3, 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: | ||
| 19 | * http://www.openmodelica.org or | ||
| 20 | * https://github.com/OpenModelica/ or | ||
| 21 | * http://www.ida.liu.se/projects/OpenModelica, | ||
| 22 | * and in the OpenModelica distribution. | ||
| 23 | * | ||
| 24 | * GNU AGPL version 3 is obtained from: | ||
| 25 | * https://www.gnu.org/licenses/licenses.html#GPL | ||
| 26 | * | ||
| 27 | * This program is distributed WITHOUT ANY WARRANTY; without | ||
| 28 | * even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 29 | * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH | ||
| 30 | * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. | ||
| 31 | * | ||
| 32 | * See the full OSMC Public License conditions for more details. | ||
| 33 | * | ||
| 34 | */ | ||
| 35 | |||
| 36 | encapsulated package Print | ||
| 37 | " file: Print.mo | ||
| 38 | package: Print | ||
| 39 | description: Printing to buffers | ||
| 40 | |||
| 41 | |||
| 42 | This module contains a buffered print function to be used instead of | ||
| 43 | the built in print function, when the output should be redirected to | ||
| 44 | some other place. It also contains print functions for error messages, to be | ||
| 45 | used in interactive mode." | ||
| 46 | |||
| 47 | ✗ | public function saveAndClearBuf "saves and clears content of buffer and return a handle to the saved buffer so it can be restored by restorBuf later on" | |
| 48 | output Integer handle; | ||
| 49 | external "C" handle = Print_saveAndClearBuf(OpenModelica.threadData()) annotation(Library = "omcruntime"); | ||
| 50 | end saveAndClearBuf; | ||
| 51 | |||
| 52 | 15332781 | public function restoreBuf | |
| 53 | input Integer handle; | ||
| 54 | external "C" Print_restoreBuf(OpenModelica.threadData(),handle) annotation(Library = "omcruntime"); | ||
| 55 | end restoreBuf; | ||
| 56 | |||
| 57 | 15332781 | public function printErrorBuf | |
| 58 | input String inString; | ||
| 59 | |||
| 60 | external "C" Print_printErrorBuf(OpenModelica.threadData(),inString) annotation(Library = "omcruntime"); | ||
| 61 | end printErrorBuf; | ||
| 62 | |||
| 63 | 328 | public function clearErrorBuf | |
| 64 | |||
| 65 | external "C" Print_clearErrorBuf(OpenModelica.threadData()) annotation(Library = "omcruntime"); | ||
| 66 | end clearErrorBuf; | ||
| 67 | |||
| 68 | 3019 | public function getErrorString | |
| 69 | output String outString; | ||
| 70 | |||
| 71 | external "C" outString = Print_getErrorString(OpenModelica.threadData()) annotation(Library = "omcruntime"); | ||
| 72 | end getErrorString; | ||
| 73 | |||
| 74 | 3002 | public function printBuf | |
| 75 | input String inString; | ||
| 76 | |||
| 77 | external "C" Print_printBufLen(OpenModelica.threadData(),inString,stringLength(inString)) annotation(Library = "omcruntime"); | ||
| 78 | end printBuf; | ||
| 79 | |||
| 80 | 68989712 | public function clearBuf | |
| 81 | |||
| 82 | external "C" Print_clearBuf(OpenModelica.threadData()) annotation(Library = "omcruntime"); | ||
| 83 | end clearBuf; | ||
| 84 | |||
| 85 | 15350182 | public function getString "Does not clear the buffer" | |
| 86 | output String outString; | ||
| 87 | |||
| 88 | external "C" outString = Print_getString(OpenModelica.threadData()) annotation(Library = "omcruntime"); | ||
| 89 | end getString; | ||
| 90 | |||
| 91 | 15332795 | public function writeBuf "Writes the buffer to a file" | |
| 92 | input String filename; | ||
| 93 | |||
| 94 | external "C" Print_writeBuf(OpenModelica.threadData(), filename) annotation(Library = "omcruntime"); | ||
| 95 | end writeBuf; | ||
| 96 | |||
| 97 | 8428 | public function writeBufConvertLines | |
| 98 | "Writes the print buffer to the filename, with /*#modelicaLine...*/ directives converted to #line C preprocessor macros" | ||
| 99 | input String filename; | ||
| 100 | external "C" Print_writeBufConvertLines(OpenModelica.threadData(),filename) annotation(Library = "omcruntime"); | ||
| 101 | end writeBufConvertLines; | ||
| 102 | |||
| 103 | 48 | public function getBufLength | |
| 104 | "Gets the actual length of the filled space in the print buffer." | ||
| 105 | output Integer outBufFilledLength; | ||
| 106 | |||
| 107 | external "C" outBufFilledLength = Print_getBufLength(OpenModelica.threadData()) annotation(Library = "omcruntime"); | ||
| 108 | end getBufLength; | ||
| 109 | |||
| 110 | 135364876 | public function printBufSpace | |
| 111 | "Prints the given number of spaces to the print buffer." | ||
| 112 | input Integer inNumOfSpaces; | ||
| 113 | |||
| 114 | external "C" Print_printBufSpace(OpenModelica.threadData(),inNumOfSpaces) annotation(Library = "omcruntime"); | ||
| 115 | end printBufSpace; | ||
| 116 | |||
| 117 | 13858982 | public function printBufNewLine | |
| 118 | "Prints one new line character to the print buffer." | ||
| 119 | |||
| 120 | external "C" Print_printBufNewLine(OpenModelica.threadData()) annotation(Library = "omcruntime"); | ||
| 121 | end printBufNewLine; | ||
| 122 | |||
| 123 | 1559167 | public function hasBufNewLineAtEnd | |
| 124 | "Tests if the last outputted character in the print buffer is a new line. | ||
| 125 | It is a (temporary) workaround to stringLength()'s O(n) cost." | ||
| 126 | output Boolean outHasNewLineAtEnd ; | ||
| 127 | |||
| 128 | external "C" outHasNewLineAtEnd = Print_hasBufNewLineAtEnd(OpenModelica.threadData()) annotation(Library = "omcruntime"); | ||
| 129 | end hasBufNewLineAtEnd; | ||
| 130 | |||
| 131 | annotation(__OpenModelica_Interface="util"); | ||
| 132 | end Print; | ||
| 133 |