/usr/lib/libreoffice/share/extensions/DmathsAddon/OOoGdmath/Fonction.xba is in libreoffice-dmaths 3.4+dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Fonction" script:language="StarBasic">'OOoGdmath
'Copyright (C) 2005-2009 Gilles Daurat
'This program is free software; you can redistribute it and/or
'modify it under the terms of the GNU General Public License
'as published by the Free Software Foundation; either version 2
'of the License, or (at your option) any later version.
'This program is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'GNU General Public License for more details.
'You should have received a copy of the GNU General Public License
'along with this program; if not, write to the Free Software
'Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
' Variables pour le trace de fonction
Option Explicit
Dim Operande(0 To 100) As Double
Dim Operateur(0 To 100) As Variant
Dim Coperande(0 To 50) As String
Dim Coperateur(0 To 50) As String
Sub Main
End Sub
Function CalculeFonction(texte$, Defini)
Dim nombre, puissance, i, c
SupprimeEspace texte$
RemplaceTexte texte$, "Pi", Trim(Str(Pi))
RemplaceTexte texte$, "pi", Trim(Str(Pi))
nombre = ""
ni = 0
oi = 0
puissance = 0
For i = 1 To Len(texte$)
c = Mid$(texte$, i, 1)
If (c >= "0" And c <= "9") Or c = "." Or c = "," Or (c = "E" And nombre <> "") Or (c = "-" And puissance = 1) Then
If nombre = "*" Then nombre = ""
If c = "," Then c = "."
nombre = nombre & c
If c = "E" Then puissance = 1
Else
If nombre <> "" And nombre <> "*" Then
Operande(ni) = val(nombre)
ni = ni + 1
nombre = "*"
puissance = 0
End If
If c = "-" And nombre <> "*" Then
Operateur(oi) = "O"
oi = oi + 1
puissance = 0
Else
If c = "+" And nombre <> "*" Then
Operateur(oi) = "K"
oi = oi + 1
puissance = 0
Else
If c = "+" Or c = "-" Then
' il faut calculer l'operation precedente
' et prendre l'oppose si necessaire
If oi > 0 Then
Do While (InStr(1, "[(=)]", Operateur(oi - 1)) = 0)
CalculeOperation Defini
If oi = 0 Then Exit Do
Loop
End If
If oi > 0 Then
If Operateur(oi - 1) = "O" Then
CalculeOperation Defini
End If
End If
Operateur(oi) = c
oi = oi + 1
nombre = ""
End If
End If
End If
Select Case c
Case "*", "/"
If oi > 0 Then
If Operateur(oi - 1) = "*" Or Operateur(oi - 1) = "/" Then
CalculeOperation Defini
End If
End If
Operateur(oi) = c
nombre = ""
oi = oi + 1
Case "^", "¨"
If oi > 0 Then
If Operateur(oi - 1) = c Then
CalculeOperation Defini
End If
End If
nombre = ""
Operateur(oi) = c
oi = oi + 1
Case "c", "C", "s", "S", "T", "t", "R", "r", "L", "l", "E", "e"
Operateur(oi) = c
oi = oi + 1
If c = "L" Or c = "l" Then i = i - 1
i = i + 2
nombre = ""
Case "("
If nombre = "*" Then
Operateur(oi) = "*"
oi = oi + 1
End If
nombre = ""
Operateur(oi) = c
oi = oi + 1
Case ")"
While Operateur(oi - 1) <> "("
CalculeOperation Defini
Wend
Operateur(oi - 1) = ""
oi = oi - 1
' If oi > 0 Then
' If InStr(1, "cstrle", Operateur(oi - 1)) <> 0 Then
' CalculeOperation Defini
' End If
' End If
nombre = "*"
End Select
End If
Next i
If nombre <> "" And nombre <> "*" Then
Operande(ni) = Val(nombre)
ni = ni + 1
End If
While oi > 0
CalculeOperation Defini
Wend
CalculeFonction = Operande(0)
End Function
Sub CalculeOperation(Defini)
Dim ok1, ok2
If oi > 0 Then
Select Case Operateur(oi - 1)
Case "e", "E"
If Abs(Operande(ni - 1)) < 700 Then
Operande(ni - 1) = Exp(Operande(ni - 1))
Else
Defini = 0
End If
Operateur(oi) = ""
oi = oi - 1
Case "l", "L"
If Operande(ni - 1) > 0 Then
Operande(ni - 1) = Log(Operande(ni - 1))
Else
Defini = 0
End If
Operateur(oi) = ""
oi = oi - 1
Case "r", "R"
If Operande(ni - 1) >= 0 Then
Operande(ni - 1) = Sqr(Operande(ni - 1))
Else
Defini = 0
End If
Operateur(oi) = ""
oi = oi - 1
Case "c", "C"
Operande(ni - 1) = Cos(Operande(ni - 1))
Operateur(oi) = ""
oi = oi - 1
Case "s", "S"
Operande(ni - 1) = Sin(Operande(ni - 1))
Operateur(oi) = ""
oi = oi - 1
Case "t", "T"
Operande(ni - 1) = Tan(Operande(ni - 1))
Operateur(oi) = ""
oi = oi - 1
Case "K"
Operande(ni - 1) = Operande(ni - 1)
Operateur(oi - 1) = ""
oi = oi - 1
Case "O"
Operande(ni - 1) = -Operande(ni - 1)
Operateur(oi - 1) = ""
oi = oi - 1
Case "¨"
If Int(Operande(ni - 1)) = Operande(ni - 1) Then
If EstPair(Operande(ni - 1)) And Operande(ni - 2) < 0 Then
Defini = 0
Else
Operande(ni - 2) = Sgn(Operande(ni - 2)) * Abs(Operande(ni - 2)) ^ (1 / Operande(ni - 1))
End If
Else
If Operande(ni - 1) = 0 Then
ok1 = True
Else
ok1 = EstPair(1 / Operande(ni - 1))
End If
If Operande(ni - 1) = 1 Then
ok2 = True
Else
ok2 = EstPair((1 / Operande(ni - 1)) - 1)
End If
If ok1 Then
If Operande(ni - 2) > 0 Then
Operande(ni - 2) = Operande(ni - 2) ^ (1 / Operande(ni - 1))
Else
Defini = 0
End If
Else
If ok2 Then
Operande(ni - 2) = Sgn(Operande(ni - 2)) * Abs(Operande(ni - 2)) ^ (1 / Operande(ni - 1))
Else
If Operande(ni - 2) > 0 Then
Operande(ni - 2) = Operande(ni - 2) ^ (1 / Operande(ni - 1))
Else
Defini = 0
End If
End If
End If
End If
Operateur(oi) = ""
oi = oi - 1
ni = ni - 1
Case "^"
If Int(Operande(ni - 1)) = Operande(ni - 1) Then
Operande(ni - 2) = Operande(ni - 2) ^ Operande(ni - 1)
Else
If Operande(ni - 1) = 0 Then
ok1 = True
Else
ok1 = EstPair(1 / Operande(ni - 1))
End If
If Operande(ni - 1) = 1 Then
ok2 = True
Else
ok2 = EstPair((1 / Operande(ni - 1)) - 1)
End If
If ok1 Then
If Operande(ni - 2) > 0 Then
Operande(ni - 2) = Operande(ni - 2) ^ Operande(ni - 1)
Else
Defini = 0
End If
Else
If ok2 Then
Operande(ni - 2) = Sgn(Operande(ni - 2)) * Abs(Operande(ni - 2)) ^ Operande(ni - 1)
Else
If Operande(ni - 2) > 0 Then
Operande(ni - 2) = Operande(ni - 2) ^ Operande(ni - 1)
Else
Defini = 0
End If
End If
End If
End If
Operateur(oi) = ""
oi = oi - 1
ni = ni - 1
Case "+"
Operande(ni - 2) = Operande(ni - 2) + Operande(ni - 1)
Operateur(oi) = ""
oi = oi - 1
ni = ni - 1
Case "-"
Operande(ni - 2) = Operande(ni - 2) - Operande(ni - 1)
Operateur(oi) = ""
oi = oi - 1
ni = ni - 1
Case "*"
Operande(ni - 2) = Operande(ni - 2) * Operande(ni - 1)
Operateur(oi) = ""
oi = oi - 1
ni = ni - 1
Case "/"
If Operande(ni - 1) <> 0 Then
Operande(ni - 2) = Operande(ni - 2) / Operande(ni - 1)
Else
Defini = 0
End If
Operateur(oi) = ""
oi = oi - 1
ni = ni - 1
End Select
End If
End Sub
</script:module>
|