/usr/lib/libreoffice/share/extensions/DmathsAddon/OOoGdmath/InsereExpression.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 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 | <?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="InsereExpression" 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.
option explicit
public oDoc as object
Private Coperande(0 To 50) As String
Private Coperateur(0 To 50) As String
Private DeltaExposant As Integer
Private NiveauExposant As Integer
Private oi As Single
Private ni As Single
Sub Main()
InsereExpression(ThisComponent)
End Sub
Function InsereEquation(oDoc) as Object
dim odocument as object
dim odispatcher as object
dim oEquation as Object
dim lesObjets as Object
dim i
odocument = oDoc.getcurrentController().Frame
odispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
odispatcher.executeDispatch(odocument, ".uno:InsertObjectStarMath", "", 0, Array())
odispatcher.executeDispatch(odocument, ".uno:Escape", "", 0, Array())
lesObjets= oDoc.EmbeddedObjects
For i=0 to lesObjets.Count-1
if lesObjets(i).supportsService("com.sun.star.text.TextEmbeddedObject") then
if (lesObjets(i).embeddedObject.supportsService("com.sun.star.formula.FormulaProperties")) then InsereEquation=lesObjets(i)
end if
next i
End Function
Sub SelectionneExpression(oDoc as Object)
dim Texte as string
Dim AncienTexte as string
dim oViewCursor as Object, oText as object
oViewCursor = oDoc.getcurrentcontroller().getViewCursor()
oText=oDoc.Text
Texte=""
do
AncienTexte=Texte
oViewCursor.goleft(1,True)
Texte=oViewCursor.getString()
dim a,b
if Texte<>"" then a=(asc(left(Texte,1))<>13) else a=False
b=(left(Texte,1)<>" ")
Loop While ((Texte<>AncienTexte) and a and b)
if (Texte<>AncienTexte) then
oViewCursor.goright(1,true)
end if
End sub
Function RemplaceTexteSelectionne(texte as string) as boolean
Dim oSelections As Object, oSel As Object, oText As Object
Dim lSelCount As Long, lWhichSelection As Long
' The current selection in the current controller.
'If there is no current controller, it returns NULL.
oSelections = ThisComponent.getCurrentSelection()
If Not IsNull(oSelections) Then
oText = ThisComponent.Text
lSelCount = oSelections.getCount()
For lWhichSelection = 0 To lSelCount - 1
oSel = oSelections.getByIndex(lWhichSelection)
oSel.setString(texte)
Next
End If
RemplaceTexteSelectionne=True
end function
Function RetourneTexteSelectionne(oDoc as Object) as string
Dim oSelections As Object, oSel As Object, oText As Object
Dim lSelCount As Long, lWhichSelection As Long
dim STexte as string
' The current selection in the current controller.
'If there is no current controller, it returns NULL.
oSelections = oDoc.getCurrentSelection()
If Not IsNull(oSelections) Then
oText = oDoc.Text
lSelCount = oSelections.getCount()
For lWhichSelection = 0 To lSelCount - 1
oSel = oSelections.getByIndex(lWhichSelection)
STexte=oSel.getString()
Next
End If
RetourneTexteSelectionne=STexte
end function
Function IsAnythingSelected(oDoc As Object) As Boolean
Dim oSelections As Object, oSel As Object, oText As Object, oCursor As Object
IsAnythingSelected = False
If IsNull(oDoc) Then
Exit Function
end if
' The current selection in the current controller.
'If there is no current controller, it returns NULL.
oSelections = oDoc.getCurrentSelection()
If IsNull(oSelections) Then
Exit Function
end if
If oSelections.getCount() = 0 Then
Exit Function
end if
If oSelections.getCount() > 1 Then
IsAnythingSelected = True
Else
oSel = oSelections.getByIndex(0)
oCursor = oDoc.Text.CreateTextCursorByRange(oSel)
If Not oCursor.IsCollapsed() Then
IsAnythingSelected = True
end if
End If
End Function
Function InsereExpression(oDoc as Object) as object
dim Texte as string,Texte1 as string
dim TexteFonction
dim i as integer, a as integer, aa as integer
dim oCursor, oText
If Not IsAnythingSelected(oDoc) Then
SelectionneExpression(oDoc)
end if
If IsAnythingSelected(oDoc) Then
Texte=RetourneTexteSelectionne(oDoc)
TexteFonction = Array("COS", "SIN", "TAN", "RAC", "EXP", "LN", "LOG", "ABS", "NOR", "MES", "VEC", "BAR", "INT", "SOM", "PRO", "SYS", "LIM", "ANG")
For i = 0 To 17
a = InStr(1, Texte, TexteFonction(i))
If a <> 0 Then
if i=5 then
aa=a + 2
else
aa=a+3
end if
If aa <= Len(Texte) Then
If InStr(1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", UCase(mid(Texte,aa,1))) <> 0 Then a = 0
End If
End If
While (a <> 0)
Texte=left(Texte,a-1) & "%" & mid(Texte,a)
aa=a+len(TexteFonction(i))
Texte1= left(Texte,aa)
if i=5 then
Texte1=Texte1 & "n"
end if
Texte=Texte1 & "%" & mid(Texte,aa+1)
a = InStr(aa, UCase(Texte), TexteFonction(i))
If a <> 0 Then
if i=5 then
aa=a + 2
else
aa=a+ 3
end if
If aa <= Len(Texte) Then
If InStr(1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", UCase(mid(Texte,aa,1))) <> 0 Then
a = 0
end if
End If
End If
Wend
Next i
oCursor = oDoc.currentcontroller.getViewCursor()
oText=oDoc.Text
oText.insertString(oCursor,CalculeExpression(Texte),True)
InsereExpression = InsereEquation(oDoc)
Else
MsgBoxP "message5"
End If
End Function
Sub SupprimeEspace(texte$)
dim i,j
dim c as string
i = Len(texte$)
j = 1
Do
Select Case Mid(texte$, j, 1)
Case " ", Chr$(160)
texte$ = Left$(texte$, j - 1) & Right$(texte$, Len(texte$) - j)
Case "$"
Do
j = j + 1
i = i - 1
c = Mid$(texte$, j, 1)
Loop While (c <> "$") And (j < 1000)
j = j + 1
Case Else
j = j + 1
End Select
i = i - 1
Loop While (i > 0)
End Sub
Sub AjouteParentheses(texte, carac)
Dim a, variab
a = InStr(1, texte, "%" & carac)
While (a <> 0)
If a + 1 + len(carac) <= Len(texte) Then
variab = Mid$(texte, a + 1 + len(carac), 1)
Else
variab = "?"
End If
If InStr(1, "abcdefghijklmnopqrstuvwxyz", variab) <> 0 Then
texte = Left(texte, a + 1) & "(" & variab & ")" & Right(texte, Len(texte) - a - 2)
Else
If variab = "\" Then
j = a + 3
i = j
While (j <= Len(texte)) And (InStr(1, "abcdefghijklmnopqrstuvwxyz", Mid$(texte, j, 1)) <> 0)
j = j + 1
Wend
texte = Left(texte, a + 1) & "(\" & Mid(texte, i, j - i) & ")" & Right(texte, Len(texte) + 1 - j)
End If
End If
a = InStr(a + 1, texte, "%" & carac)
Wend
End Sub
Function CalculeExpression(texte as string ) as String
Dim nombre, i, a, c, ai, cuf, LeChamp$, ii, Delimit, cp, ca
Dim ccs as string, cs as string, TheTest as Boolean, voperande$, b, aa, bb
Dim j, k, cc
Dim espace3 as string, espace4 as string, espace1 as string, espace2 as string
espace3=" "
espace4=" "
If texte <> "" Then
Call AjouteParentheses(texte, "cos")
Call AjouteParentheses(texte, "sin")
Call AjouteParentheses(texte, "tan")
Call AjouteParentheses(texte, "rac")
Call AjouteParentheses(texte, "exp")
Call AjouteParentheses(texte, "lnn")
Call AjouteParentheses(texte, "log")
Call AjouteParentheses(texte, "abs")
Call AjouteParentheses(texte, "nor")
Call AjouteParentheses(texte, "mes")
nombre = ""
ni = 0
oi = 0
NiveauExposant = 4
For i = 1 To Len(texte)
c = Mid$(texte, i, 1)
If c = "%" Then
ai = i + 1
a = InStr(i + 1, texte, "%")
c = Mid(texte, i + 1, a - i - 1)
Select Case UCase(c)
Case "LNN"
c = "n"
Case "LOG"
c = "g"
Case "SOM"
c = "x"
Case "SYS"
c = "y"
Case "LIM"
c = "j"
Case "ANG"
c = "h"
Case Else
c = Left(c, 1)
End Select
i = a
End If
If c <> "%" Then
If (InStr(1, "()[]ƒ;=:+-*/^cCsStTrReElLgGAaMmNnVvBbIiXxPpYyJjHh$.,", c) = 0 Or ((nombre = " " Or nombre = "" Or Right(nombre, 1) = ".") And c = ".") Or (CestUnNombre(nombre) And c = ",")) Or ((InStr(1, "cCsStTrReElLgGAaMmNnVvBbIiXxPpYyJjHh", c) <> 0) And MIIf(i = Len(texte), True, (InStr(1, "([", Mid$(texte, i + 1, 1)) = 0))) Then
If c = Chr(34) Then
a = InStr(i + 1, texte, Chr(34))
If a <> 0 Then
nombre = nombre + Mid(texte, i + 1, a - i - 1)
i = a
End If
Else
If Left(nombre, 1) = "*" And c <> " " Then
nombre = ""
End If
nombre = nombre + c
End If
Else
If nombre <> "" And Left(nombre, 1) <> "*" And nombre <> " " Then
Coperande(ni) = FormatTexte(i - Len(nombre), nombre) + nombre
SupprimeEspaceOperandeDroite Coperande(ni)
SupprimeEspaceOperandeGauche Coperande(ni)
ni = ni + 1
nombre = "*"
End If
If c = "-" And (Left(nombre, 1) <> "*" Or nombre = " ") Then
Coperateur(oi) = FormatTexte(i - 1, " O ") + " O "
nombre = ""
oi = oi + 1
Else
If c = "+" And (Left(nombre, 1) <> "*" Or nombre = " ") Then
Coperateur(oi) = FormatTexte(i - 1, " K ") + " K "
oi = oi + 1
nombre = ""
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, "[(=)]", ROperateur(Coperateur(oi - 1))) = 0)
InsereOperation
If oi = 0 Then Exit Do
Loop
End If
Coperateur(oi) = FormatTexte(i - 1, " " + c + " ") + " " + c + " "
oi = oi + 1
nombre = ""
NiveauExposant = 4
End If
End If
End If
Select Case UCase(c)
Case ":"
If oi > 0 Then
If InStr(1, Chr(34) + ":cCsStTrReElLgGAaMmNnVvBbIiXxPpYyJj$", ROperateur(Coperateur(oi - 1))) <> 0 Then InsereOperation
End If
Coperateur(oi) = FormatTexte(i - 1, " " + c + " ") + " " + c + " "
nombre = ""
oi = oi + 1
Case ".", "*", "/", ";", "=", "ƒ", ","
If oi > 0 Then
Do While NiveauPriorite(ROperateur(Coperateur(oi - 1))) > NiveauPriorite(c)
InsereOperation
If oi = 0 Then Exit Do
Loop
End If
Coperateur(oi) = FormatTexte(i - 1, " " + c + " ") + " " + c + " "
nombre = ""
oi = oi + 1
NiveauExposant = 4
Case "^"
If oi > 0 Then
Do While NiveauPriorite(ROperateur(Coperateur(oi - 1))) >= NiveauPriorite(c)
InsereOperation
If oi = 0 Then Exit Do
Loop
End If
Coperateur(oi) = FormatTexte(i - 1, " " + c + " ") + " " + c + " "
nombre = ""
oi = oi + 1
NiveauExposant = 4
Case "C", "S", "T", "R", "L", "E", "G", "A", "N", "M", "V", "B", "I", "X", "P", "Y", "J", "H", "$"
cuf = False
If i > 0 Then cuf = (Mid$(texte, i, 1) = "%")
If c = "$" Then cuf = True
If cuf And (c = "$" Or Mid$(texte, i + 1, 1) = "(" Or Mid$(texte, i + 1, 1) = "[") Then
If nombre = "*" Then
nombre = ""
If c = "$" Then
Coperateur(oi) = FormatTexte(i, c) + ".."
Else
Coperateur(oi) = FormatTexte(i, c) + "."
End If
oi = oi + 1
Else
Coperateur(oi) = FormatTexte(ai, c) + c
nombre = ""
oi = oi + 1
End If
If c = "$" Then
LeChamp$ = ""
ii = i
Do
i = i + 1
c = Mid$(texte, i, 1)
If c <> "$" Then LeChamp$ = LeChamp$ + c
Loop While (c <> "$")
Coperande(ni) = FormatTexte(ii + 1, LeChamp$) + LeChamp$
ni = ni + 1
End If
Else
If nombre = "*" Then
Coperande(ni - 1) = Coperande(ni - 1) + c
Else
nombre = nombre + c
End If
End If
Case "(", "[", "{"
If nombre = "*" Then
nombre = ""
Coperateur(oi) = FormatTexte(i, c) + "."
oi = oi + 1
End If
nombre = ""
Coperateur(oi) = FormatTexte(i, c + " ") + c + " "
oi = oi + 1
NiveauExposant = 4
Case ")", "]", "}"
Delimit = MIIf(c = ")", "(", MIif(c = "]", "[", "{"))
cp = "$"
ca = "$"
If oi > 0 Then cp = ROperateur(Coperateur(oi - 1))
If oi > 0 Then
Do While ROperateur(Coperateur(oi - 1)) <> Delimit
cp = ROperateur(Coperateur(oi - 1))
InsereOperation
If oi = 0 Then Exit Do
Loop
If oi > 0 Then
Coperateur(oi - 1) = ""
oi = oi - 1
End If
if oi>0 then
if instr(1,"vV", ROperateur(COperateur(oi-1))) then cp=ROperateur(COperateur(oi-1))
End if
End If
ccs = "$"
If oi > 0 Then ca = ROperateur(Coperateur(oi - 1))
If i + 1 <= Len(texte) Then ccs = Mid$(texte, i + 1, 1)
If ccs <> "^" And ccs <> "/" And ccs <> "." Then If i + 2 <= Len(texte) Then ccs = Mid$(texte, i + 2, 1)
If NiveauPriorite(ca) >= NiveauPriorite(ccs) Or ca = "y" Then
cs = ca
Else
If NiveauPriorite(ccs) = 10 Then ccs = "."
cs = ccs
End If
TheTest = (cp <> "(" Or cs = "^") And (NiveauPrioritePar(cp) <= NiveauPrioritePar(cs) And cp <> "/") Or (cs = "/" And cp = "^") Or (cp = "/" And cs = "^")
a = InStr(1, Coperande(ni - 1), "\g")
If a <> 0 Then
a = InStr(a + 2, Coperande(ni - 1), "g")
a = InStr(a + 1, Coperande(ni - 1), "g")
voperande$ = Right(Coperande(ni - 1), Len(Coperande(ni - 1)) - a)
SupprimeEspace voperande$
Else
voperande$ = Coperande(ni - 1)
SupprimeEspace voperande$
End If
If InStr(1, "abcdefghijklmnopqrstuvwxyz", voperande$) <> 0 Then
SupprimeEspaceOperandeDroite Coperande(ni - 1)
SupprimeEspaceOperandeGauche Coperande(ni - 1)
End If
If (((cp = "O" Or cp = "K") And cs <> "/") Or TheTest Or (InStr(1, "abcdefghijklmnopqrstuvwxyz", voperande$) <> 0 And cp = "(")) And Not (InStr(1, "abcdefghijklmnopqrstuvwxyz", voperande$) <> 0 And InStr(1, "cslgt", LCase(cs)) <> 0) And InStr(1, "reanmvbixpyjh", LCase(cs)) = 0 Then
If FractionDetectee(Coperande(ni - 1)) And InStr(1, "ixpyj", cs) = 0 Then
Coperande(ni - 1) = "left" & Delimit & "(" & espace1 & Coperande(ni - 1) & espace2 & "right" & c
Else
Coperande(ni - 1) = Delimit & MIIf(FractionAGauche(Coperande(ni - 1)), espace4, espace3) & Coperande(ni - 1) & MIIf(FractionADroite(Coperande(ni - 1)), espace4, espace3) & c
End If
Else
a = Asc(Left(voperande$, 1))
If (a = 45 Or a = 43) And cs <> "/" Then
If FractionDetectee(Coperande(ni - 1)) And InStr(1, "ixpyj", cs) = 0 Then
Coperande(ni - 1) = "left" & Delimit & espace1 & Coperande(ni - 1) & espace2 & "right" & c
Else
Coperande(ni - 1) = Delimit & MIIf(FractionAGauche(Coperande(ni - 1)), espace4, espace3) & Coperande(ni - 1) & MIIf(FractionADroite(Coperande(ni - 1)), espace4, espace3) & c
End If
End If
End If
NiveauExposant = MIif(FractionDetectee(Coperande(ni - 1)), 8, 4)
nombre = "*"
End Select
End If
End If
Next i
If nombre <> "" And nombre <> "*" And nombre <> " " Then
If oi > 0 Then
If InStr(1, "cstrleganmvbok", ROperateur(Coperateur(oi - 1))) <> 0 Then
InsereOperation
End If
End If
Coperande(ni) = FormatTexte(i - Len(nombre), nombre) + nombre
SupprimeEspaceOperandeDroite Coperande(ni)
SupprimeEspaceOperandeGauche Coperande(ni)
ni = ni + 1
End If
While oi > 0
InsereOperation
Wend
For i = 1 To ni - 1
Coperande(0) = Coperande(0) & " " & Coperande(i)
Next i
a = 0
Do
a = InStr(1, Coperande(0), "\g")
If a <> 0 Then
a = a + 1
b = InStr(a + 1, Coperande(0), "g")
cc = InStr(b + 1, Coperande(0), "g")
i = Val(Mid(Coperande(0), a + 1, b - a - 1))
j = Val(Mid(Coperande(0), b + 1,cc - b - 1))
COperande(0) = left(COperande(0),a-2) & mid(COperande(0),cc+1)
End If
Loop While (a <> 0)
CalculeExpression() = COperande(0)
End if
End Function
Sub InsereOperation()
dim param() as string
dim a, FormatOperateur as string
dim espace1 as string, espace2 as string
dim espace3 as string, espace4 as string
dim fi,i,rac1,rac2
dim deb3
espace1=" "
espace2=" "
If oi > 0 Then
a = InStr(1, Coperateur(oi - 1), "\g")
a = InStr(a + 2, Coperateur(oi - 1), "g")
a = InStr(a + 1, Coperateur(oi - 1), "g")
FormatOperateur = Left(Coperateur(oi - 1), a)
Select Case UCase(ROperateur(Coperateur(oi - 1)))
Case "e","E"
Coperande(ni - 1) = "{func e^{" & Coperande(ni - 1) & "}}"
Coperateur(oi) = ""
oi = oi - 1
Case "g", "G"
Coperande(ni - 1) = "{log" & Coperande(ni - 1) & "}"
Coperateur(oi) = ""
oi = oi - 1
Case "l", "L"
Coperande(ni - 1) = "{ln " & Coperande(ni - 1) & "}"
Coperateur(oi) = ""
oi = oi - 1
Case "n", "N"
Coperande(ni - 1) = "{ldline {" & Coperande(ni - 1) & "} rdline}"
Coperateur(oi) = ""
oi = oi - 1
Case "v", "V"
Coperande(ni - 1) = "{widevec {" & Coperande(ni - 1) & "}}"
Coperateur(oi) = ""
oi = oi - 1
Case "b", "B"
Coperande(ni - 1) = "{overstrike {" & Coperande(ni - 1) & "}}"
Coperateur(oi) = ""
oi = oi - 1
Case "H","h"
Coperande(ni - 1) = "{widehat {" & Coperande(ni - 1) & "}}"
Coperateur(oi) = ""
oi = oi - 1
Case "m", "M"
Coperande(ni - 1) = "{overline {" & Coperande(ni - 1) & "}}"
Coperateur(oi) = ""
oi = oi - 1
Case "a", "A"
Coperande(ni - 1) = "{abs {" & Coperande(ni - 1) & "}}"
Coperateur(oi) = ""
oi = oi - 1
Case "r", "R"
a = InStr(1, Coperande(ni - 1), " \; ")
If a <> 0 Then
rac1 = Left$(Coperande(ni - 1), a - 1)
rac2 = Mid$(Coperande(ni - 1), a + 4)
else
rac1=""
rac2=COperande(ni-1)
End If
Coperande(ni - 1) = "{nroot{" & rac1 & "}{" & rac2 & "}}"
Coperateur(oi) = ""
oi = oi - 1
Case "c", "C"
Coperande(ni - 1) = "{Cos " & Coperande(ni - 1) & "}"
Coperateur(oi) = ""
oi = oi - 1
Case "s", "S"
Coperande(ni - 1) = "{Sin " & Coperande(ni - 1) & "}"
Coperateur(oi) = ""
oi = oi - 1
Case "t", "T"
Coperande(ni - 1) = "{Tan " & Coperande(ni - 1) & "}"
Coperateur(oi) = ""
oi = oi - 1
Case "I"
RemplaceTexte Coperande(ni - 1), " \; ", "\;"
ChargeParametre Coperande(ni - 1), param, "\;"
Coperande(ni - 1) = "{int from{" & param(0) & "} to {" & param(1) & "} {" & param(2) & "}}"
Coperateur(oi) = ""
oi = oi - 1
Case "X"
RemplaceTexte Coperande(ni - 1), " \; ", "\;"
ChargeParametre Coperande(ni - 1), param(), "\;"
Coperande(ni - 1) = "{sum from{" & param(0) & "} to {" & param(1) & "} {" & param(2) & "}}"
Coperateur(oi) = ""
oi = oi - 1
Case "P"
RemplaceTexte Coperande(ni - 1), " \; ", "\;"
ChargeParametre Coperande(ni - 1), param(), "\;"
Coperande(ni - 1) = "{prod from {" & param(0) & "}to {" & param(1) & "} {" & param(2) & "}}"
Coperateur(oi) = ""
oi = oi - 1
Case "Y"
RemplaceTexte Coperande(ni - 1), " \; ", "\;"
fi = ChargeParametre(Coperande(ni - 1), param(), "\;") - 1
Coperande(ni - 1) = "{alignl left lbrace stack {"
For i = 0 To fi
if i=fi then
Coperande(ni - 1) = Coperande(ni - 1) & param(i) & "}"
else
Coperande(ni - 1) = Coperande(ni - 1) & param(i) & "#"
end if
Next i
COperande(ni-1) = COperande(ni-1) & "right none}"
Coperateur(oi) = ""
oi = oi - 1
Case "J"
RemplaceTexte Coperande(ni - 1), " \; ", "\;"
ChargeParametre Coperande(ni - 1), param(), "\;"
Coperande(ni - 1) = "{Lim from {" & param(0) & " rightarrow " & param(1) & " } {" & param(2) & "}}"
Coperateur(oi) = ""
oi = oi - 1
Case "K"
Coperateur(oi - 1) = FormatOperateur & " + "
SupprimeEspaceOperandeGauche Coperateur(oi - 1)
If ni > 0 Then
Coperande(ni - 1) = Coperateur(oi - 1) & Coperande(ni - 1)
Else
SupprimeEspaceOperandeDroite Coperateur(oi - 1)
Coperande(0) = Coperateur(oi - 1)
End If
Coperateur(oi) = ""
oi = oi - 1
Case "O"
Coperateur(oi - 1) = FormatOperateur & " - "
SupprimeEspaceOperandeGauche Coperateur(oi - 1)
If ni > 0 Then
Coperande(ni - 1) = Coperateur(oi - 1) & Coperande(ni - 1)
Else
SupprimeEspaceOperandeDroite Coperateur(oi - 1)
Coperande(0) = Coperateur(oi - 1)
End If
Coperateur(oi) = ""
oi = oi - 1
Case "^"
deb3 = Left(Coperande(ni - 2), 3)
If InStr(1, Coperande(ni - 2), "\g") = 1 Then
a = InStr(3, Coperande(ni - 2), "g") + 1
a = InStr(a, Coperande(ni - 2), "g") + 1
deb3 = Left(Mid(Coperande(ni - 2), a), 3)
End If
If deb3 = "sin" Or deb3 = "cos" Or deb3 = "tan" Then
Coperande(ni - 2) = "{{" & Left(Coperande(ni - 2), a + 2) & "} ^ {" & Coperande(ni - 1) & "}" & Right(Coperande(ni - 2), Len(Coperande(ni - 2)) - (a + 2)) & "}"
Else
Coperande(ni - 2) = "{" & Coperande(ni - 2) & "} ^ {" & Coperande(ni - 1) & "}"
End If
Coperateur(oi) = ""
oi = oi - 1
ni = ni - 1
NiveauExposant = NiveauExposant + 4
Case "="
If ni > 1 Then
Coperande(ni - 2) = Coperande(ni - 2) & Coperateur(oi - 1) & Coperande(ni - 1)
ni = ni - 1
Else
SupprimeEspaceOperandeGauche Coperateur(oi - 1)
If ni > 0 Then
Coperande(ni - 1) = Coperateur(oi - 1) & Coperande(ni - 1)
Else
SupprimeEspaceOperandeDroite Coperateur(oi - 1)
Coperande(ni) = Coperateur(oi - 1)
End If
End If
Coperateur(oi) = ""
oi = oi - 1
Case ";"
Coperande(ni - 2) = Coperande(ni - 2) & " \; " & Coperande(ni - 1)
Coperateur(oi) = ""
oi = oi - 1
ni = ni - 1
Case ","
Coperande(ni - 2) = Coperande(ni - 2) & " , " & Coperande(ni - 1)
Coperateur(oi) = ""
oi = oi - 1
ni = ni - 1
Case "|"
Coperande(ni - 2) = Coperande(ni - 2) & " ; " & Coperande(ni - 1)
Coperateur(oi) = ""
oi = oi - 1
ni = ni - 1
Case "ƒ"
Coperande(ni - 2) = Coperande(ni - 2) & FormatOperateur & "ƒ" & Coperande(ni - 1)
Coperateur(oi) = ""
oi = oi - 1
ni = ni - 1
Case "+"
If ni > 0 Then
If espace1 = "" And Not FractionADroite(Coperande(ni - 2)) Then SupprimeEspaceOperandeGauche Coperateur(oi - 1)
If espace1 = "" And Not FractionAGauche(Coperande(ni - 1)) Then SupprimeEspaceOperandeDroite Coperateur(oi - 1)
If espace2 = "" And FractionADroite(Coperande(ni - 2)) Then SupprimeEspaceOperandeGauche Coperateur(oi - 1)
If espace2 = "" And FractionAGauche(Coperande(ni - 1)) Then SupprimeEspaceOperandeDroite Coperateur(oi - 1)
Coperande(ni - 2) = Coperande(ni - 2) & Coperateur(oi - 1) & Coperande(ni - 1)
ni = ni - 1
Else
SupprimeEspaceOperandeDroite Coperateur(oi - 1)
SupprimeEspaceOperandeGauche Coperateur(oi - 1)
Coperande(0) = Coperateur(oi - 1)
End If
Coperateur(oi) = ""
oi = oi - 1
Case "-"
if FractionAGauche(Coperande(ni - 2)) then espace3=espace2 else espace4=espace1
if FractionADroite(Coperande(ni - 2)) then espace3=espace2 else espace4=espace1
If ni > 0 Then
Coperande(ni - 2) = Coperande(ni - 2) & FormatOperateur & espace3 & "-" & espace4 & Coperande(ni - 1)
ni = ni - 1
Else
Coperande(0) = FormatOperateur & "-"
SupprimeEspaceOperandeDroite Coperande(0)
SupprimeEspaceOperandeGauche Coperande(0)
End If
Coperateur(oi) = ""
oi = oi - 1
Case ".."
Coperande(ni - 2) = Coperande(ni - 2) & " " & Coperande(ni - 1)
Coperateur(oi) = ""
oi = oi - 1
ni = ni - 1
Case "."
Coperande(ni - 2) = Coperande(ni - 2) & " " & Coperande(ni - 1)
' Coperande(ni - 2) = Coperande(ni - 2) + " " + Coperande(ni - 1)
Coperateur(oi) = ""
oi = oi - 1
ni = ni - 1
Case ":"
If ni > 0 Then
Coperande(ni - 2) = "{" & Coperande(ni - 2) & "} div {" & Coperande(ni - 1) & "}"
ni = ni - 1
Else
Coperande(0) = "{} div {" & Coperande(ni-1) & "}"
End If
Coperateur(oi) = ""
oi = oi - 1
Case "*"
If ni > 0 Then
Coperande(ni - 2) = "{" & Coperande(ni - 2) & "} times {" & Coperande(ni - 1) & "}"
ni = ni - 1
Else
Coperande(0) = "{} times {" & Coperande(ni-1) & "}"
End If
Coperateur(oi) = ""
oi = oi - 1
Case "/"
Coperande(ni - 2) = "{" & Coperande(ni - 2) & "} over {" & Coperande(ni - 1) & "}"
Coperateur(oi) = ""
oi = oi - 1
ni=ni-1
Case "$"
Coperateur(oi) = ""
oi = oi - 1
Case Else
Coperateur(oi) = ""
oi = oi - 1
End Select
End If
End Sub
Function CestUnNombre(texte as string) As Boolean
Dim i
CestUnNombre = False
If Len(texte) > 0 Then CestUnNombre = True
For i = 1 To Len(texte)
If InStr(1, "0123456789 ", Mid(texte, i, 1)) = 0 Then
CestUnNombre = False
Exit Function
End If
Next i
End Function
Function SupprimeEspaceOperandeDroite(texte) As Boolean
Dim seod, aa, a, ki, kj
seod = 0
SupprimeEspaceOperandeDroite = False
Do
aa = InStrD(1, texte, "\g")
If aa > 0 Then
ExtraitDebutFin aa, texte, ki, kj
kj = kj - 1
a = InStr(aa, texte, "g") + 1
a = InStr(a, texte, "g") + 1
a = InStr(a, texte, "g") + kj + 1
If Mid(texte, a, 1) = " " And a = Len(texte) Then
texte = Left(texte, aa - 1) & "\g" & Trim(Str(ki)) & "g" & Trim(Str(kj)) & "g" & Mid(texte, a - kj, kj)
seod = 1
SupprimeEspaceOperandeDroite = True
Else
If Right(texte, 1) = " " Then
texte = Left(texte, Len(texte) - 1)
seod = 1
SupprimeEspaceOperandeDroite = True
Else
seod = 0
End If
End If
Else
If Right(texte, 1) = " " Then
texte = Left(texte, Len(texte) - 1)
seod = 1
SupprimeEspaceOperandeDroite = True
Else
seod = 0
End If
End If
Loop While (seod = 1)
End Function
Function SupprimeEspaceOperandeGauche(texte) As Boolean
Dim ki, kj, a
SupprimeEspaceOperandeGauche = False
If InStr(1, texte, "\g") = 1 Then
ExtraitDebutFin 1, texte, ki, kj
a = InStr(1, texte, "g") + 1
a = InStr(a, texte, "g") + 1
a = InStr(a, texte, "g") + 1
While (Mid(texte, a, 1) = " ")
ki = ki + 1
kj = kj - 1
texte = "\g" & Trim(Str(ki)) & "g" & Trim(Str(kj)) & "g" & Mid(texte, a + 1)
a = Len("\g" & Trim(Str(ki)) & "g" & Trim(Str(kj)) & "g") + 1
SupprimeEspaceOperandeGauche = True
Wend
Else
While (Left(texte, 1) = " ")
texte = Mid(texte, 2)
SupprimeEspaceOperandeGauche = True
Wend
End If
End Function
Function NiveauPrioritePar(texte) As Integer
Dim npo
npo = 10
If InStr(1, "cstrelganmvbixpyjh", texte) <> 0 Then npo = 0
If InStr(1, "^", texte) <> 0 Then npo = -10
If InStr(1, "OK", texte) <> 0 Then npo = -30
If InStr(1, "*.", texte) <> 0 Then npo = -40
If InStr(1, "+-", texte) <> 0 Then npo = -50
If InStr(1, "/", texte) <> 0 Then npo = -55
If InStr(1, "$)]}", texte) <> 0 Then npo = -60
If InStr(1, "=;ƒ,", texte) <> 0 Then npo = -70
If InStr(1, "([{", texte) <> 0 Then npo = -80
NiveauPrioritePar = npo
End Function
Function NiveauPriorite(texte) As Integer
Dim npo
npo = 10
If InStr(1, "cstrelganmvbixpyj", texte) <> 0 Then npo = 0
If InStr(1, "^", texte) <> 0 Then npo = -10
If InStr(1, "/", texte) <> 0 Then npo = -30
If InStr(1, "OK", texte) <> 0 Then npo = -40
If InStr(1, "*", texte) <> 0 Then npo = -45
If InStr(1, ".", texte) <> 0 Then npo = -48
If InStr(1, "+-", texte) <> 0 Then npo = -50
If InStr(1, "$)]}", texte) <> 0 Then npo = -60
If InStr(1, "=", texte) <> 0 Then npo = -65
If InStr(1, ";ƒ,", texte) <> 0 Then npo = -70
If InStr(1, "([{", texte) <> 0 Then npo = -80
NiveauPriorite = npo
End Function
Function FormatTexte(i, texte) As String
Dim ii
ii = i
' If Left(texte, 1) = " " Then
' texte = Mid(texte, 2)
' ii = ii + 1
' End If
' If Right(texte, 1) = " " Then texte = Left(texte, Len(texte) - 1)
FormatTexte = "\g" & Trim(Str(ii)) & "g" & Trim(Str(Len(texte))) & "g"
End Function
Function InStrD(isi, texte, texte1) As Integer
Dim nocur, a, i
nocur = CompteTexte(isi, texte, texte1)
If nocur >= isi Then
a = 1
For i = 1 To nocur - isi + 1
a = InStr(a, texte, texte1) + 1
Next i
InStrD = a - 1
Else
InStrD = 0
End If
End Function
Function CompteTexte(Debut, texte1, texte2) As Integer
Dim a, nbtexte
a = Debut
nbtexte = 0
Do
a = InStr(a, texte1, texte2) + 1
If Val(a) > 1 Then nbtexte = nbtexte + 1
Loop While (Val(a) > 1)
CompteTexte = nbtexte
End Function
Function ExtraitDebutFin(deb, texte, i, j) As Integer
Dim a, b, c
a = InStr(deb, texte, "\g") + 1
If a > 1 Then
b = InStr(a + 1, texte, "g")
c = InStr(b + 1, texte, "g")
i = Val(Mid$(texte, a + 1, b - a - 1))
j = Val(Mid$(texte, b + 1, c - b - 1))
ExtraitDebutFin = InStr(c + 1, texte, "\g")
Else
ExtraitDebutFin = 0
End If
End Function
Function ROperateur(texte) As String
Dim i
i = Len(texte)
While (Mid(texte, i, 1) = " ")
i = i - 1
Wend
ROperateur = Mid(texte, i, 1)
If ROperateur = "." Then If i > 1 Then If Mid(texte, i - 1, 1) = "." Then ROperateur = ".."
End Function
Function FractionDetectee(texte) As Boolean
FractionDetectee = (InStr(1, texte, "} over {") <> 0)
End Function
Function RemplaceTexte(texte As String, texte1 As String, texte2 As String, Optional a) As Integer
Dim remp As Boolean
Dim j As Integer
if ismissing(a) then a=1
remp = False
If Len(texte) > 0 And Len(texte1) <= Len(texte) Then
Do
a = InStr(a, texte, texte1)
If a <> 0 Then
texte = Left$(texte, a - 1) & texte2 & Right(texte, Len(texte) + 1 - a - Len(texte1))
remp = True
End If
Loop While (a <> 0)
End If
RemplaceTexte = remp
End Function
Function FractionADroite(texte As String) As Boolean
Dim b
FractionADroite = False
If Right(texte, 1) = "}" Then
b = PositionAccolades2(texte, Len(texte) - 1)
If Right(Left(texte, b - 1), 4) = "over" Then FractionADroite = True
End If
End Function
Function FractionAGauche(texte As String) As Boolean
Dim a,b
FractionAGauche = False
If left(texte, 1) = "{" Then
b = PositionAccolades(texte, 1)
If Right(Left(texte, b - 1), 4) = "over" Then FractionAGauche = True
End If
End Function
Function PositionAccolades(a$, p2)
Dim p As Integer, par As Integer
p = p2
par = 1
Do
p = p + 1
Select Case Mid$(a$, p, 1)
Case "{": par = par + 1
Case "}": par = par - 1
End Select
Loop Until par = 0 Or p > Len(a$)
If par <> 0 Then
PositionAccolades = -1
Else
PositionAccolades = p
End If
End Function
Function PositionAccolades2(a$, p2)
Dim p As Integer, par As Integer
p = p2
par = 1
Do
p = p - 1
Select Case Mid$(a$, p, 1)
Case "}": par = par + 1
Case "{": par = par - 1
End Select
Loop Until par = 0 Or p < 1
If par <> 0 Then
PositionAccolades2 = -1
Else
PositionAccolades2 = p
End If
End Function
Function ChargeParametre(texte$, tableau() As String, Optional Separateur)
Dim nbpv, j, i, a$
if ismissing(Separateur) then Separateur=";"
texte$ = texte$ & Separateur
nbpv = 0
For j = 1 To Len(texte$)
If Mid$(texte$, j, Len(Separateur)) = Separateur Then nbpv = nbpv + 1
Next j
ReDim tableau(0 To nbpv - 1) as String
For j = 0 To nbpv - 1
tableau(j) = ""
Next j
i = 0
For j = 1 To Len(texte$)
a$ = Mid$(texte$, j, Len(Separateur))
If a$ = Separateur Then
i = i + 1
j = j + Len(Separateur) - 1
Else
tableau(i) = tableau(i) & Mid$(texte$, j, 1)
End If
Next j
texte$ = Left$(texte$, Len(texte$) - Len(Separateur))
ChargeParametre = i
End Function
</script:module>
|