| | @@ -1,8 +1,8 @@ |
| 1 | 1 | |
| 2 | 2 | /* |
| 3 | | -** The implementation of the TH core. This file contains the parser, and |
| 3 | +** The implementation of the TH core. This file contains the parser, and |
| 4 | 4 | ** the implementation of the interface in th.h. |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | #include "config.h" |
| 8 | 8 | #include "th.h" |
| | @@ -16,11 +16,11 @@ |
| 16 | 16 | /* |
| 17 | 17 | ** Interpreter structure. |
| 18 | 18 | */ |
| 19 | 19 | struct Th_Interp { |
| 20 | 20 | Th_Vtab *pVtab; /* Copy of the argument passed to Th_CreateInterp() */ |
| 21 | | - char *zResult; /* Current interpreter result (Th_Malloc()ed) */ |
| 21 | + char *zResult; /* Current interpreter result (Th_Malloc()ed) */ |
| 22 | 22 | int nResult; /* number of bytes in zResult */ |
| 23 | 23 | Th_Hash *paCmd; /* Table of registered commands */ |
| 24 | 24 | Th_Frame *pFrame; /* Current execution frame */ |
| 25 | 25 | int isListMode; /* True if thSplitList() should operate in "list" mode */ |
| 26 | 26 | }; |
| | @@ -42,25 +42,25 @@ |
| 42 | 42 | ** are stored in the Th_Frame.paVar hash table member of the associated |
| 43 | 43 | ** stack frame object. |
| 44 | 44 | ** |
| 45 | 45 | ** When an interpreter is created, a single Th_Frame structure is also |
| 46 | 46 | ** allocated - the global variable scope. Th_Interp.pFrame (the current |
| 47 | | -** interpreter frame) is initialised to point to this Th_Frame. It is |
| 48 | | -** not deleted for the lifetime of the interpreter (because the global |
| 47 | +** interpreter frame) is initialised to point to this Th_Frame. It is |
| 48 | +** not deleted for the lifetime of the interpreter (because the global |
| 49 | 49 | ** frame never goes out of scope). |
| 50 | 50 | ** |
| 51 | 51 | ** New stack frames are created by the Th_InFrame() function. Before |
| 52 | 52 | ** invoking its callback function, Th_InFrame() allocates a new Th_Frame |
| 53 | 53 | ** structure with pCaller set to the current frame (Th_Interp.pFrame), |
| 54 | 54 | ** and sets the current frame to the new frame object. After the callback |
| 55 | 55 | ** has been invoked, the allocated Th_Frame is deleted and the value |
| 56 | 56 | ** of the current frame pointer restored. |
| 57 | | -** |
| 58 | | -** By default, the Th_SetVar(), Th_UnsetVar() and Th_GetVar() functions |
| 59 | | -** access variable values in the current frame. If they need to access |
| 57 | +** |
| 58 | +** By default, the Th_SetVar(), Th_UnsetVar() and Th_GetVar() functions |
| 59 | +** access variable values in the current frame. If they need to access |
| 60 | 60 | ** the global frame, they do so by traversing the pCaller pointer list. |
| 61 | | -** Likewise, the Th_LinkVar() function uses the pCaller pointers to |
| 61 | +** Likewise, the Th_LinkVar() function uses the pCaller pointers to |
| 62 | 62 | ** link to variables located in the global or other stack frames. |
| 63 | 63 | */ |
| 64 | 64 | struct Th_Frame { |
| 65 | 65 | Th_Hash *paVar; /* Variables defined in this scope */ |
| 66 | 66 | Th_Frame *pCaller; /* Calling frame */ |
| | @@ -84,11 +84,11 @@ |
| 84 | 84 | ** value. |
| 85 | 85 | */ |
| 86 | 86 | struct Th_Variable { |
| 87 | 87 | int nRef; /* Number of references to this structure */ |
| 88 | 88 | int nData; /* Number of bytes at Th_Variable.zData */ |
| 89 | | - char *zData; /* Data for scalar variables */ |
| 89 | + char *zData; /* Data for scalar variables */ |
| 90 | 90 | Th_Hash *pHash; /* Data for array variables */ |
| 91 | 91 | }; |
| 92 | 92 | |
| 93 | 93 | /* |
| 94 | 94 | ** Hash table API: |
| | @@ -110,19 +110,19 @@ |
| 110 | 110 | static void thFreeVariable(Th_HashEntry*, void*); |
| 111 | 111 | static void thFreeCommand(Th_HashEntry*, void*); |
| 112 | 112 | |
| 113 | 113 | /* |
| 114 | 114 | ** The following are used by both the expression and language parsers. |
| 115 | | -** Given that the start of the input string (z, n) is a language |
| 115 | +** Given that the start of the input string (z, n) is a language |
| 116 | 116 | ** construct of the relevant type (a command enclosed in [], an escape |
| 117 | 117 | ** sequence etc.), these functions determine the number of bytes |
| 118 | 118 | ** of the input consumed by the construct. For example: |
| 119 | 119 | ** |
| 120 | 120 | ** int nByte; |
| 121 | 121 | ** thNextCommand(interp, "[expr $a+1] $nIter", 18, &nByte); |
| 122 | 122 | ** |
| 123 | | -** results in variable nByte being set to 11. Or, |
| 123 | +** results in variable nByte being set to 11. Or, |
| 124 | 124 | ** |
| 125 | 125 | ** thNextVarname(interp, "$a+1", 4, &nByte); |
| 126 | 126 | ** |
| 127 | 127 | ** results in nByte being set to 2. |
| 128 | 128 | */ |
| | @@ -132,24 +132,24 @@ |
| 132 | 132 | static int thNextNumber (Th_Interp*, const char *z, int n, int *pN); |
| 133 | 133 | static int thNextSpace (Th_Interp*, const char *z, int n, int *pN); |
| 134 | 134 | |
| 135 | 135 | /* |
| 136 | 136 | ** Given that the input string (z, n) contains a language construct of |
| 137 | | -** the relevant type (a command enclosed in [], an escape sequence |
| 137 | +** the relevant type (a command enclosed in [], an escape sequence |
| 138 | 138 | ** like "\xFF" or a variable reference like "${varname}", perform |
| 139 | 139 | ** substitution on the string and store the resulting string in |
| 140 | 140 | ** the interpreter result. |
| 141 | 141 | */ |
| 142 | 142 | static int thSubstCommand(Th_Interp*, const char *z, int n); |
| 143 | 143 | static int thSubstEscape (Th_Interp*, const char *z, int n); |
| 144 | 144 | static int thSubstVarname(Th_Interp*, const char *z, int n); |
| 145 | 145 | |
| 146 | 146 | /* |
| 147 | | -** Given that there is a th1 word located at the start of the input |
| 147 | +** Given that there is a th1 word located at the start of the input |
| 148 | 148 | ** string (z, n), determine the length in bytes of that word. If the |
| 149 | | -** isCmd argument is non-zero, then an unescaped ";" byte not |
| 150 | | -** located inside of a block or quoted string is considered to mark |
| 149 | +** isCmd argument is non-zero, then an unescaped ";" byte not |
| 150 | +** located inside of a block or quoted string is considered to mark |
| 151 | 151 | ** the end of the word. |
| 152 | 152 | */ |
| 153 | 153 | static int thNextWord(Th_Interp*, const char *z, int n, int *pN, int isCmd); |
| 154 | 154 | |
| 155 | 155 | /* |
| | @@ -176,13 +176,13 @@ |
| 176 | 176 | ** Append nAdd bytes of content copied from zAdd to the end of buffer |
| 177 | 177 | ** pBuffer. If there is not enough space currently allocated, resize |
| 178 | 178 | ** the allocation to make space. |
| 179 | 179 | */ |
| 180 | 180 | static int thBufferWrite( |
| 181 | | - Th_Interp *interp, |
| 182 | | - Buffer *pBuffer, |
| 183 | | - const char *zAdd, |
| 181 | + Th_Interp *interp, |
| 182 | + Buffer *pBuffer, |
| 183 | + const char *zAdd, |
| 184 | 184 | int nAdd |
| 185 | 185 | ){ |
| 186 | 186 | int nReq; |
| 187 | 187 | |
| 188 | 188 | if( nAdd<0 ){ |
| | @@ -311,19 +311,19 @@ |
| 311 | 311 | Th_HashDelete(interp, pFrame->paVar); |
| 312 | 312 | interp->pFrame = pFrame->pCaller; |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | /* |
| 316 | | -** The first part of the string (zInput,nInput) contains an escape |
| 316 | +** The first part of the string (zInput,nInput) contains an escape |
| 317 | 317 | ** sequence. Set *pnEscape to the number of bytes in the escape sequence. |
| 318 | 318 | ** If there is a parse error, return TH_ERROR and set the interpreter |
| 319 | 319 | ** result to an error message. Otherwise return TH_OK. |
| 320 | 320 | */ |
| 321 | 321 | static int thNextEscape( |
| 322 | 322 | Th_Interp *interp, |
| 323 | | - const char *zInput, |
| 324 | | - int nInput, |
| 323 | + const char *zInput, |
| 324 | + int nInput, |
| 325 | 325 | int *pnEscape |
| 326 | 326 | ){ |
| 327 | 327 | int i = 2; |
| 328 | 328 | |
| 329 | 329 | assert(nInput>0); |
| | @@ -344,18 +344,18 @@ |
| 344 | 344 | return TH_OK; |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /* |
| 348 | 348 | ** The first part of the string (zInput,nInput) contains a variable |
| 349 | | -** reference. Set *pnVarname to the number of bytes in the variable |
| 350 | | -** reference. If there is a parse error, return TH_ERROR and set the |
| 349 | +** reference. Set *pnVarname to the number of bytes in the variable |
| 350 | +** reference. If there is a parse error, return TH_ERROR and set the |
| 351 | 351 | ** interpreter result to an error message. Otherwise return TH_OK. |
| 352 | 352 | */ |
| 353 | 353 | int thNextVarname( |
| 354 | 354 | Th_Interp *interp, |
| 355 | | - const char *zInput, |
| 356 | | - int nInput, |
| 355 | + const char *zInput, |
| 356 | + int nInput, |
| 357 | 357 | int *pnVarname |
| 358 | 358 | ){ |
| 359 | 359 | int i; |
| 360 | 360 | |
| 361 | 361 | assert(nInput>0); |
| | @@ -401,19 +401,19 @@ |
| 401 | 401 | return TH_OK; |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | /* |
| 405 | 405 | ** The first part of the string (zInput,nInput) contains a command |
| 406 | | -** enclosed in a "[]" block. Set *pnCommand to the number of bytes in |
| 407 | | -** the variable reference. If there is a parse error, return TH_ERROR |
| 408 | | -** and set the interpreter result to an error message. Otherwise return |
| 406 | +** enclosed in a "[]" block. Set *pnCommand to the number of bytes in |
| 407 | +** the variable reference. If there is a parse error, return TH_ERROR |
| 408 | +** and set the interpreter result to an error message. Otherwise return |
| 409 | 409 | ** TH_OK. |
| 410 | 410 | */ |
| 411 | 411 | int thNextCommand( |
| 412 | 412 | Th_Interp *interp, |
| 413 | | - const char *zInput, |
| 414 | | - int nInput, |
| 413 | + const char *zInput, |
| 414 | + int nInput, |
| 415 | 415 | int *pnCommand |
| 416 | 416 | ){ |
| 417 | 417 | int nBrace = 0; |
| 418 | 418 | int nSquare = 0; |
| 419 | 419 | int i; |
| | @@ -438,17 +438,17 @@ |
| 438 | 438 | |
| 439 | 439 | return TH_OK; |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | /* |
| 443 | | -** Set *pnSpace to the number of whitespace bytes at the start of |
| 443 | +** Set *pnSpace to the number of whitespace bytes at the start of |
| 444 | 444 | ** input string (zInput, nInput). Always return TH_OK. |
| 445 | 445 | */ |
| 446 | 446 | int thNextSpace( |
| 447 | 447 | Th_Interp *interp, |
| 448 | | - const char *zInput, |
| 449 | | - int nInput, |
| 448 | + const char *zInput, |
| 449 | + int nInput, |
| 450 | 450 | int *pnSpace |
| 451 | 451 | ){ |
| 452 | 452 | int i; |
| 453 | 453 | for(i=0; i<nInput && th_isspace(zInput[i]); i++); |
| 454 | 454 | *pnSpace = i; |
| | @@ -457,21 +457,21 @@ |
| 457 | 457 | |
| 458 | 458 | /* |
| 459 | 459 | ** The first byte of the string (zInput,nInput) is not white-space. |
| 460 | 460 | ** Set *pnWord to the number of bytes in the th1 word that starts |
| 461 | 461 | ** with this byte. If a complete word cannot be parsed or some other |
| 462 | | -** error occurs, return TH_ERROR and set the interpreter result to |
| 462 | +** error occurs, return TH_ERROR and set the interpreter result to |
| 463 | 463 | ** an error message. Otherwise return TH_OK. |
| 464 | 464 | ** |
| 465 | | -** If the isCmd argument is non-zero, then an unescaped ";" byte not |
| 466 | | -** located inside of a block or quoted string is considered to mark |
| 465 | +** If the isCmd argument is non-zero, then an unescaped ";" byte not |
| 466 | +** located inside of a block or quoted string is considered to mark |
| 467 | 467 | ** the end of the word. |
| 468 | 468 | */ |
| 469 | 469 | static int thNextWord( |
| 470 | 470 | Th_Interp *interp, |
| 471 | | - const char *zInput, |
| 472 | | - int nInput, |
| 471 | + const char *zInput, |
| 472 | + int nInput, |
| 473 | 473 | int *pnWord, |
| 474 | 474 | int isCmd |
| 475 | 475 | ){ |
| 476 | 476 | int iEnd = 0; |
| 477 | 477 | |
| | @@ -531,12 +531,12 @@ |
| 531 | 531 | return thEvalLocal(interp, &zWord[1], nWord-2); |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | /* |
| 535 | 535 | ** The input string (zWord, nWord) contains a th1 variable reference |
| 536 | | -** (a '$' byte followed by a variable name). Perform substitution on |
| 537 | | -** the input string and store the resulting string in the interpreter |
| 536 | +** (a '$' byte followed by a variable name). Perform substitution on |
| 537 | +** the input string and store the resulting string in the interpreter |
| 538 | 538 | ** result. |
| 539 | 539 | */ |
| 540 | 540 | static int thSubstVarname( |
| 541 | 541 | Th_Interp *interp, |
| 542 | 542 | const char *zWord, |
| | @@ -572,11 +572,11 @@ |
| 572 | 572 | return Th_GetVar(interp, &zWord[1], nWord-1); |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /* |
| 576 | 576 | ** The input string (zWord, nWord) contains a th1 escape sequence. |
| 577 | | -** Perform substitution on the input string and store the resulting |
| 577 | +** Perform substitution on the input string and store the resulting |
| 578 | 578 | ** string in the interpreter result. |
| 579 | 579 | */ |
| 580 | 580 | static int thSubstEscape( |
| 581 | 581 | Th_Interp *interp, |
| 582 | 582 | const char *zWord, |
| | @@ -608,11 +608,11 @@ |
| 608 | 608 | return TH_OK; |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | /* |
| 612 | 612 | ** The input string (zWord, nWord) contains a th1 word. Perform |
| 613 | | -** substitution on the input string and store the resulting |
| 613 | +** substitution on the input string and store the resulting |
| 614 | 614 | ** string in the interpreter result. |
| 615 | 615 | */ |
| 616 | 616 | static int thSubstWord( |
| 617 | 617 | Th_Interp *interp, |
| 618 | 618 | const char *zWord, |
| | @@ -640,20 +640,20 @@ |
| 640 | 640 | int (*xGet)(Th_Interp *, const char*, int, int *) = 0; |
| 641 | 641 | int (*xSubst)(Th_Interp *, const char*, int) = 0; |
| 642 | 642 | |
| 643 | 643 | switch( zWord[i] ){ |
| 644 | 644 | case '\\': |
| 645 | | - xGet = thNextEscape; xSubst = thSubstEscape; |
| 645 | + xGet = thNextEscape; xSubst = thSubstEscape; |
| 646 | 646 | break; |
| 647 | 647 | case '[': |
| 648 | 648 | if( !interp->isListMode ){ |
| 649 | | - xGet = thNextCommand; xSubst = thSubstCommand; |
| 649 | + xGet = thNextCommand; xSubst = thSubstCommand; |
| 650 | 650 | break; |
| 651 | 651 | } |
| 652 | 652 | case '$': |
| 653 | 653 | if( !interp->isListMode ){ |
| 654 | | - xGet = thNextVarname; xSubst = thSubstVarname; |
| 654 | + xGet = thNextVarname; xSubst = thSubstVarname; |
| 655 | 655 | break; |
| 656 | 656 | } |
| 657 | 657 | default: { |
| 658 | 658 | thBufferWrite(interp, &output, &zWord[i], 1); |
| 659 | 659 | continue; /* Go to the next iteration of the for(...) loop */ |
| | @@ -685,11 +685,11 @@ |
| 685 | 685 | ** Return true if one of the following is true of the buffer pointed |
| 686 | 686 | ** to by zInput, length nInput: |
| 687 | 687 | ** |
| 688 | 688 | ** + It is empty, or |
| 689 | 689 | ** + It contains nothing but white-space, or |
| 690 | | -** + It contains no non-white-space characters before the first |
| 690 | +** + It contains no non-white-space characters before the first |
| 691 | 691 | ** newline character. |
| 692 | 692 | ** |
| 693 | 693 | ** Otherwise return false. |
| 694 | 694 | */ |
| 695 | 695 | static int thEndOfLine(const char *zInput, int nInput){ |
| | @@ -725,16 +725,16 @@ |
| 725 | 725 | ** // Free all memory allocated by Th_SplitList(). The arrays pointed |
| 726 | 726 | ** // to by argv and argl are invalidated by this call. |
| 727 | 727 | ** // |
| 728 | 728 | ** Th_Free(interp, argv); |
| 729 | 729 | ** |
| 730 | | -*/ |
| 730 | +*/ |
| 731 | 731 | static int thSplitList( |
| 732 | 732 | Th_Interp *interp, /* Interpreter context */ |
| 733 | | - const char *zList, /* Pointer to buffer containing input list */ |
| 733 | + const char *zList, /* Pointer to buffer containing input list */ |
| 734 | 734 | int nList, /* Size of buffer pointed to by zList */ |
| 735 | | - char ***pazElem, /* OUT: Array of list elements */ |
| 735 | + char ***pazElem, /* OUT: Array of list elements */ |
| 736 | 736 | int **panElem, /* OUT: Lengths of each list element */ |
| 737 | 737 | int *pnCount /* OUT: Number of list elements */ |
| 738 | 738 | ){ |
| 739 | 739 | int rc = TH_OK; |
| 740 | 740 | |
| | @@ -774,14 +774,14 @@ |
| 774 | 774 | assert((lenbuf.nBuf/sizeof(int))==nCount); |
| 775 | 775 | |
| 776 | 776 | assert((pazElem && panElem) || (!pazElem && !panElem)); |
| 777 | 777 | if( pazElem && rc==TH_OK ){ |
| 778 | 778 | int i; |
| 779 | | - char *zElem; |
| 779 | + char *zElem; |
| 780 | 780 | int *anElem; |
| 781 | 781 | char **azElem = Th_Malloc(interp, |
| 782 | | - sizeof(char*) * nCount + /* azElem */ |
| 782 | + sizeof(char*) * nCount + /* azElem */ |
| 783 | 783 | sizeof(int) * nCount + /* anElem */ |
| 784 | 784 | strbuf.nBuf /* space for list element strings */ |
| 785 | 785 | ); |
| 786 | 786 | anElem = (int *)&azElem[nCount]; |
| 787 | 787 | zElem = (char *)&anElem[nCount]; |
| | @@ -795,11 +795,11 @@ |
| 795 | 795 | *panElem = anElem; |
| 796 | 796 | } |
| 797 | 797 | if( pnCount ){ |
| 798 | 798 | *pnCount = nCount; |
| 799 | 799 | } |
| 800 | | - |
| 800 | + |
| 801 | 801 | finish: |
| 802 | 802 | thBufferFree(interp, &strbuf); |
| 803 | 803 | thBufferFree(interp, &lenbuf); |
| 804 | 804 | return rc; |
| 805 | 805 | } |
| | @@ -876,18 +876,18 @@ |
| 876 | 876 | if( rc==TH_OK ){ |
| 877 | 877 | Th_Command *p = (Th_Command *)(pEntry->pData); |
| 878 | 878 | const char **azArg = (const char **)argv; |
| 879 | 879 | rc = p->xProc(interp, p->pContext, argc, azArg, argl); |
| 880 | 880 | } |
| 881 | | - |
| 881 | + |
| 882 | 882 | /* If an error occurred, add this command to the stack trace report. */ |
| 883 | 883 | if( rc==TH_ERROR ){ |
| 884 | 884 | char *zRes; |
| 885 | 885 | int nRes; |
| 886 | 886 | char *zStack = 0; |
| 887 | 887 | int nStack = 0; |
| 888 | | - |
| 888 | + |
| 889 | 889 | zRes = Th_TakeResult(interp, &nRes); |
| 890 | 890 | if( TH_OK==Th_GetVar(interp, (char *)"::th_stack_trace", -1) ){ |
| 891 | 891 | zStack = Th_TakeResult(interp, &nStack); |
| 892 | 892 | } |
| 893 | 893 | Th_ListAppend(interp, &zStack, &nStack, zFirst, zInput-zFirst); |
| | @@ -912,15 +912,15 @@ |
| 912 | 912 | ** |
| 913 | 913 | ** Argument iFrame is interpreted as follows: |
| 914 | 914 | ** |
| 915 | 915 | ** * If iFrame is 0, this means the current frame. |
| 916 | 916 | ** |
| 917 | | -** * If iFrame is negative, then the nth frame up the stack, where |
| 918 | | -** n is the absolute value of iFrame. A value of -1 means the |
| 917 | +** * If iFrame is negative, then the nth frame up the stack, where |
| 918 | +** n is the absolute value of iFrame. A value of -1 means the |
| 919 | 919 | ** calling procedure. |
| 920 | 920 | ** |
| 921 | | -** * If iFrame is +ve, then the nth frame from the bottom of the |
| 921 | +** * If iFrame is +ve, then the nth frame from the bottom of the |
| 922 | 922 | ** stack. An iFrame value of 1 means the toplevel (global) frame. |
| 923 | 923 | */ |
| 924 | 924 | static Th_Frame *getFrame(Th_Interp *interp, int iFrame){ |
| 925 | 925 | Th_Frame *p = interp->pFrame; |
| 926 | 926 | int i; |
| | @@ -948,28 +948,28 @@ |
| 948 | 948 | |
| 949 | 949 | |
| 950 | 950 | /* |
| 951 | 951 | ** Evaluate th1 script (zProgram, nProgram) in the frame identified by |
| 952 | 952 | ** argument iFrame. Leave either an error message or a result in the |
| 953 | | -** interpreter result and return a th1 error code (TH_OK, TH_ERROR, |
| 953 | +** interpreter result and return a th1 error code (TH_OK, TH_ERROR, |
| 954 | 954 | ** TH_RETURN, TH_CONTINUE or TH_BREAK). |
| 955 | 955 | */ |
| 956 | 956 | int Th_Eval(Th_Interp *interp, int iFrame, const char *zProgram, int nProgram){ |
| 957 | 957 | int rc = TH_OK; |
| 958 | 958 | Th_Frame *pSavedFrame = interp->pFrame; |
| 959 | 959 | |
| 960 | | - /* Set Th_Interp.pFrame to the frame that this script is to be |
| 960 | + /* Set Th_Interp.pFrame to the frame that this script is to be |
| 961 | 961 | ** evaluated in. The current frame is saved in pSavedFrame and will |
| 962 | 962 | ** be restored before this function returns. |
| 963 | 963 | */ |
| 964 | 964 | interp->pFrame = getFrame(interp, iFrame); |
| 965 | 965 | |
| 966 | 966 | if( !interp->pFrame ){ |
| 967 | 967 | rc = TH_ERROR; |
| 968 | 968 | }else{ |
| 969 | 969 | int nInput = nProgram; |
| 970 | | - |
| 970 | + |
| 971 | 971 | if( nInput<0 ){ |
| 972 | 972 | nInput = th_strlen(zProgram); |
| 973 | 973 | } |
| 974 | 974 | rc = thEvalLocal(interp, zProgram, nInput); |
| 975 | 975 | } |
| | @@ -995,13 +995,13 @@ |
| 995 | 995 | ** array key name. |
| 996 | 996 | */ |
| 997 | 997 | static int thAnalyseVarname( |
| 998 | 998 | const char *zVarname, |
| 999 | 999 | int nVarname, |
| 1000 | | - const char **pzOuter, /* OUT: Pointer to scalar/array name */ |
| 1000 | + const char **pzOuter, /* OUT: Pointer to scalar/array name */ |
| 1001 | 1001 | int *pnOuter, /* OUT: Number of bytes at *pzOuter */ |
| 1002 | | - const char **pzInner, /* OUT: Pointer to array key (or null) */ |
| 1002 | + const char **pzInner, /* OUT: Pointer to array key (or null) */ |
| 1003 | 1003 | int *pnInner, /* OUT: Number of bytes at *pzInner */ |
| 1004 | 1004 | int *pisGlobal /* OUT: Set to true if this is a global ref */ |
| 1005 | 1005 | ){ |
| 1006 | 1006 | const char *zOuter = zVarname; |
| 1007 | 1007 | int nOuter; |
| | @@ -1044,11 +1044,11 @@ |
| 1044 | 1044 | return TH_OK; |
| 1045 | 1045 | } |
| 1046 | 1046 | |
| 1047 | 1047 | /* |
| 1048 | 1048 | ** Input string (zVar, nVar) contains a variable name. This function locates |
| 1049 | | -** the Th_Variable structure associated with the named variable. The |
| 1049 | +** the Th_Variable structure associated with the named variable. The |
| 1050 | 1050 | ** variable name may be a global or local scalar or array variable |
| 1051 | 1051 | ** |
| 1052 | 1052 | ** If the create argument is non-zero and the named variable does not exist |
| 1053 | 1053 | ** it is created. Otherwise, an error is left in the interpreter result |
| 1054 | 1054 | ** and NULL returned. |
| | @@ -1057,11 +1057,11 @@ |
| 1057 | 1057 | ** an error is left in the interpreter result and NULL returned. If |
| 1058 | 1058 | ** arrayok is true an array name is Ok. |
| 1059 | 1059 | */ |
| 1060 | 1060 | static Th_Variable *thFindValue( |
| 1061 | 1061 | Th_Interp *interp, |
| 1062 | | - const char *zVar, /* Pointer to variable name */ |
| 1062 | + const char *zVar, /* Pointer to variable name */ |
| 1063 | 1063 | int nVar, /* Number of bytes at nVar */ |
| 1064 | 1064 | int create, /* If true, create the variable if not found */ |
| 1065 | 1065 | int arrayok, /* If true, an array is Ok. Otherwise array==error */ |
| 1066 | 1066 | int noerror /* If false, set interpreter result to error message */ |
| 1067 | 1067 | ){ |
| | @@ -1079,11 +1079,11 @@ |
| 1079 | 1079 | if( isGlobal ){ |
| 1080 | 1080 | while( pFrame->pCaller ) pFrame = pFrame->pCaller; |
| 1081 | 1081 | } |
| 1082 | 1082 | |
| 1083 | 1083 | pEntry = Th_HashFind(interp, pFrame->paVar, zOuter, nOuter, create); |
| 1084 | | - assert(pEntry || !create); |
| 1084 | + assert(pEntry || create<=0); |
| 1085 | 1085 | if( !pEntry ){ |
| 1086 | 1086 | goto no_such_var; |
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | 1089 | pValue = (Th_Variable *)pEntry->pData; |
| | @@ -1135,12 +1135,12 @@ |
| 1135 | 1135 | } |
| 1136 | 1136 | return 0; |
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | /* |
| 1140 | | -** String (zVar, nVar) must contain the name of a scalar variable or |
| 1141 | | -** array member. Look up the variable, store its current value in |
| 1140 | +** String (zVar, nVar) must contain the name of a scalar variable or |
| 1141 | +** array member. Look up the variable, store its current value in |
| 1142 | 1142 | ** the interpreter result and return TH_OK. |
| 1143 | 1143 | ** |
| 1144 | 1144 | ** If the named variable does not exist, return TH_ERROR and leave |
| 1145 | 1145 | ** an error message in the interpreter result. |
| 1146 | 1146 | */ |
| | @@ -1174,12 +1174,12 @@ |
| 1174 | 1174 | ** |
| 1175 | 1175 | ** If (zVar, nVar) refers to an existing array, TH_ERROR is returned |
| 1176 | 1176 | ** and an error message left in the interpreter result. |
| 1177 | 1177 | */ |
| 1178 | 1178 | int Th_SetVar( |
| 1179 | | - Th_Interp *interp, |
| 1180 | | - const char *zVar, |
| 1179 | + Th_Interp *interp, |
| 1180 | + const char *zVar, |
| 1181 | 1181 | int nVar, |
| 1182 | 1182 | const char *zValue, |
| 1183 | 1183 | int nValue |
| 1184 | 1184 | ){ |
| 1185 | 1185 | Th_Variable *pValue; |
| | @@ -1210,13 +1210,13 @@ |
| 1210 | 1210 | ** Create a variable link so that accessing variable (zLocal, nLocal) is |
| 1211 | 1211 | ** the same as accessing variable (zLink, nLink) in stack frame iFrame. |
| 1212 | 1212 | */ |
| 1213 | 1213 | int Th_LinkVar( |
| 1214 | 1214 | Th_Interp *interp, /* Interpreter */ |
| 1215 | | - const char *zLocal, int nLocal, /* Local varname */ |
| 1215 | + const char *zLocal, int nLocal, /* Local varname */ |
| 1216 | 1216 | int iFrame, /* Stack frame of linked var */ |
| 1217 | | - const char *zLink, int nLink /* Linked varname */ |
| 1217 | + const char *zLink, int nLink /* Linked varname */ |
| 1218 | 1218 | ){ |
| 1219 | 1219 | Th_Frame *pSavedFrame = interp->pFrame; |
| 1220 | 1220 | Th_Frame *pFrame; |
| 1221 | 1221 | Th_HashEntry *pEntry; |
| 1222 | 1222 | Th_Variable *pValue; |
| | @@ -1253,17 +1253,21 @@ |
| 1253 | 1253 | pValue = thFindValue(interp, zVar, nVar, 0, 1, 0); |
| 1254 | 1254 | if( !pValue ){ |
| 1255 | 1255 | return TH_ERROR; |
| 1256 | 1256 | } |
| 1257 | 1257 | |
| 1258 | | - Th_Free(interp, pValue->zData); |
| 1259 | | - pValue->zData = 0; |
| 1258 | + if( pValue->zData ){ |
| 1259 | + Th_Free(interp, pValue->zData); |
| 1260 | + pValue->zData = 0; |
| 1261 | + } |
| 1260 | 1262 | if( pValue->pHash ){ |
| 1261 | 1263 | Th_HashIterate(interp, pValue->pHash, thFreeVariable, (void *)interp); |
| 1262 | 1264 | Th_HashDelete(interp, pValue->pHash); |
| 1263 | 1265 | pValue->pHash = 0; |
| 1264 | 1266 | } |
| 1267 | + |
| 1268 | + thFindValue(interp, zVar, nVar, -1, 1, 1); /* Finally, delete from frame */ |
| 1265 | 1269 | return TH_OK; |
| 1266 | 1270 | } |
| 1267 | 1271 | |
| 1268 | 1272 | /* |
| 1269 | 1273 | ** Return an allocated buffer containing a copy of string (z, n). The |
| | @@ -1299,11 +1303,11 @@ |
| 1299 | 1303 | if( interp ){ |
| 1300 | 1304 | char *zRes = 0; |
| 1301 | 1305 | int nRes = 0; |
| 1302 | 1306 | |
| 1303 | 1307 | Th_SetVar(interp, (char *)"::th_stack_trace", -1, 0, 0); |
| 1304 | | - |
| 1308 | + |
| 1305 | 1309 | Th_StringAppend(interp, &zRes, &nRes, zPre, -1); |
| 1306 | 1310 | if( zRes[nRes-1]=='"' ){ |
| 1307 | 1311 | Th_StringAppend(interp, &zRes, &nRes, z, n); |
| 1308 | 1312 | Th_StringAppend(interp, &zRes, &nRes, (const char *)"\"", 1); |
| 1309 | 1313 | }else{ |
| | @@ -1381,12 +1385,12 @@ |
| 1381 | 1385 | return (char *)Th_Malloc(pInterp, 1); |
| 1382 | 1386 | } |
| 1383 | 1387 | } |
| 1384 | 1388 | |
| 1385 | 1389 | |
| 1386 | | -/* |
| 1387 | | -** Wrappers around the supplied malloc() and free() |
| 1390 | +/* |
| 1391 | +** Wrappers around the supplied malloc() and free() |
| 1388 | 1392 | */ |
| 1389 | 1393 | void *Th_Malloc(Th_Interp *pInterp, int nByte){ |
| 1390 | 1394 | void *p = pInterp->pVtab->xMalloc(nByte); |
| 1391 | 1395 | if( p ){ |
| 1392 | 1396 | memset(p, 0, nByte); |
| | @@ -1398,16 +1402,16 @@ |
| 1398 | 1402 | pInterp->pVtab->xFree(z); |
| 1399 | 1403 | } |
| 1400 | 1404 | } |
| 1401 | 1405 | |
| 1402 | 1406 | /* |
| 1403 | | -** Install a new th1 command. |
| 1407 | +** Install a new th1 command. |
| 1404 | 1408 | ** |
| 1405 | 1409 | ** If a command of the same name already exists, it is deleted automatically. |
| 1406 | 1410 | */ |
| 1407 | 1411 | int Th_CreateCommand( |
| 1408 | | - Th_Interp *interp, |
| 1412 | + Th_Interp *interp, |
| 1409 | 1413 | const char *zName, /* New command name */ |
| 1410 | 1414 | Th_CommandProc xProc, /* Command callback proc */ |
| 1411 | 1415 | void *pContext, /* Value to pass as second arg to xProc */ |
| 1412 | 1416 | void (*xDel)(Th_Interp *, void *) /* Command destructor callback */ |
| 1413 | 1417 | ){ |
| | @@ -1425,27 +1429,27 @@ |
| 1425 | 1429 | } |
| 1426 | 1430 | pCommand->xProc = xProc; |
| 1427 | 1431 | pCommand->pContext = pContext; |
| 1428 | 1432 | pCommand->xDel = xDel; |
| 1429 | 1433 | pEntry->pData = (void *)pCommand; |
| 1430 | | - |
| 1434 | + |
| 1431 | 1435 | return TH_OK; |
| 1432 | 1436 | } |
| 1433 | 1437 | |
| 1434 | 1438 | /* |
| 1435 | | -** Rename the existing command (zName, nName) to (zNew, nNew). If nNew is 0, |
| 1439 | +** Rename the existing command (zName, nName) to (zNew, nNew). If nNew is 0, |
| 1436 | 1440 | ** the command is deleted instead of renamed. |
| 1437 | 1441 | ** |
| 1438 | 1442 | ** If successful, TH_OK is returned. If command zName does not exist, or |
| 1439 | | -** if command zNew already exists, an error message is left in the |
| 1443 | +** if command zNew already exists, an error message is left in the |
| 1440 | 1444 | ** interpreter result and TH_ERROR is returned. |
| 1441 | 1445 | */ |
| 1442 | 1446 | int Th_RenameCommand( |
| 1443 | | - Th_Interp *interp, |
| 1444 | | - const char *zName, /* Existing command name */ |
| 1447 | + Th_Interp *interp, |
| 1448 | + const char *zName, /* Existing command name */ |
| 1445 | 1449 | int nName, /* Number of bytes at zName */ |
| 1446 | | - const char *zNew, /* New command name */ |
| 1450 | + const char *zNew, /* New command name */ |
| 1447 | 1451 | int nNew /* Number of bytes at zNew */ |
| 1448 | 1452 | ){ |
| 1449 | 1453 | Th_HashEntry *pEntry; |
| 1450 | 1454 | Th_HashEntry *pNewEntry; |
| 1451 | 1455 | |
| | @@ -1499,11 +1503,11 @@ |
| 1499 | 1503 | ** If an error occurs (if (zList, nList) is not a valid list) an error |
| 1500 | 1504 | ** message is left in the interpreter result and TH_ERROR returned. |
| 1501 | 1505 | ** |
| 1502 | 1506 | ** If successful, *pnCount is set to the number of elements in the list. |
| 1503 | 1507 | ** panElem is set to point at an array of *pnCount integers - the lengths |
| 1504 | | -** of the element values. *pazElem is set to point at an array of |
| 1508 | +** of the element values. *pazElem is set to point at an array of |
| 1505 | 1509 | ** pointers to buffers containing the array element's data. |
| 1506 | 1510 | ** |
| 1507 | 1511 | ** To free the arrays allocated at *pazElem and *panElem, the caller |
| 1508 | 1512 | ** should call Th_Free() on *pazElem only. Exactly one such call to |
| 1509 | 1513 | ** Th_Free() must be made per call to Th_SplitList(). |
| | @@ -1525,13 +1529,13 @@ |
| 1525 | 1529 | ** Th_Free(interp, azElem); |
| 1526 | 1530 | ** |
| 1527 | 1531 | */ |
| 1528 | 1532 | int Th_SplitList( |
| 1529 | 1533 | Th_Interp *interp, |
| 1530 | | - const char *zList, /* Pointer to buffer containing list */ |
| 1534 | + const char *zList, /* Pointer to buffer containing list */ |
| 1531 | 1535 | int nList, /* Number of bytes at zList */ |
| 1532 | | - char ***pazElem, /* OUT: Array of pointers to element data */ |
| 1536 | + char ***pazElem, /* OUT: Array of pointers to element data */ |
| 1533 | 1537 | int **panElem, /* OUT: Array of element data lengths */ |
| 1534 | 1538 | int *pnCount /* OUT: Number of elements in list */ |
| 1535 | 1539 | ){ |
| 1536 | 1540 | int rc; |
| 1537 | 1541 | interp->isListMode = 1; |
| | @@ -1542,16 +1546,16 @@ |
| 1542 | 1546 | } |
| 1543 | 1547 | return rc; |
| 1544 | 1548 | } |
| 1545 | 1549 | |
| 1546 | 1550 | /* |
| 1547 | | -** Append a new element to an existing th1 list. The element to append |
| 1551 | +** Append a new element to an existing th1 list. The element to append |
| 1548 | 1552 | ** to the list is (zElem, nElem). |
| 1549 | 1553 | ** |
| 1550 | 1554 | ** A pointer to the existing list must be stored at *pzList when this |
| 1551 | | -** function is called. The length must be stored in *pnList. The value |
| 1552 | | -** of *pzList must either be NULL (in which case *pnList must be 0), or |
| 1555 | +** function is called. The length must be stored in *pnList. The value |
| 1556 | +** of *pzList must either be NULL (in which case *pnList must be 0), or |
| 1553 | 1557 | ** a pointer to memory obtained from Th_Malloc(). |
| 1554 | 1558 | ** |
| 1555 | 1559 | ** This function calls Th_Free() to free the buffer at *pzList and sets |
| 1556 | 1560 | ** *pzList to point to a new buffer containing the new list value. *pnList |
| 1557 | 1561 | ** is similarly updated before returning. The return value is always TH_OK. |
| | @@ -1568,13 +1572,13 @@ |
| 1568 | 1572 | ** Th_Free(interp, zList); |
| 1569 | 1573 | ** |
| 1570 | 1574 | */ |
| 1571 | 1575 | int Th_ListAppend( |
| 1572 | 1576 | Th_Interp *interp, /* Interpreter context */ |
| 1573 | | - char **pzList, /* IN/OUT: Ptr to ptr to list */ |
| 1577 | + char **pzList, /* IN/OUT: Ptr to ptr to list */ |
| 1574 | 1578 | int *pnList, /* IN/OUT: Current length of *pzList */ |
| 1575 | | - const char *zElem, /* Data to append */ |
| 1579 | + const char *zElem, /* Data to append */ |
| 1576 | 1580 | int nElem /* Length of nElem */ |
| 1577 | 1581 | ){ |
| 1578 | 1582 | Buffer output; |
| 1579 | 1583 | int i; |
| 1580 | 1584 | |
| | @@ -1623,13 +1627,13 @@ |
| 1623 | 1627 | ** Append a new element to an existing th1 string. This function uses |
| 1624 | 1628 | ** the same interface as the Th_ListAppend() function. |
| 1625 | 1629 | */ |
| 1626 | 1630 | int Th_StringAppend( |
| 1627 | 1631 | Th_Interp *interp, /* Interpreter context */ |
| 1628 | | - char **pzStr, /* IN/OUT: Ptr to ptr to list */ |
| 1632 | + char **pzStr, /* IN/OUT: Ptr to ptr to list */ |
| 1629 | 1633 | int *pnStr, /* IN/OUT: Current length of *pzStr */ |
| 1630 | | - const char *zElem, /* Data to append */ |
| 1634 | + const char *zElem, /* Data to append */ |
| 1631 | 1635 | int nElem /* Length of nElem */ |
| 1632 | 1636 | ){ |
| 1633 | 1637 | char *zNew; |
| 1634 | 1638 | int nNew; |
| 1635 | 1639 | |
| | @@ -1647,11 +1651,11 @@ |
| 1647 | 1651 | *pnStr = nNew; |
| 1648 | 1652 | |
| 1649 | 1653 | return TH_OK; |
| 1650 | 1654 | } |
| 1651 | 1655 | |
| 1652 | | -/* |
| 1656 | +/* |
| 1653 | 1657 | ** Delete an interpreter. |
| 1654 | 1658 | */ |
| 1655 | 1659 | void Th_DeleteInterp(Th_Interp *interp){ |
| 1656 | 1660 | assert(interp->pFrame); |
| 1657 | 1661 | assert(0==interp->pFrame->pCaller); |
| | @@ -1668,11 +1672,11 @@ |
| 1668 | 1672 | |
| 1669 | 1673 | /* Delete the interpreter structure itself. */ |
| 1670 | 1674 | Th_Free(interp, (void *)interp); |
| 1671 | 1675 | } |
| 1672 | 1676 | |
| 1673 | | -/* |
| 1677 | +/* |
| 1674 | 1678 | ** Create a new interpreter. |
| 1675 | 1679 | */ |
| 1676 | 1680 | Th_Interp * Th_CreateInterp(Th_Vtab *pVtab){ |
| 1677 | 1681 | Th_Interp *p; |
| 1678 | 1682 | |
| | @@ -1702,11 +1706,11 @@ |
| 1702 | 1706 | Operator *pOp; |
| 1703 | 1707 | Expr *pParent; |
| 1704 | 1708 | Expr *pLeft; |
| 1705 | 1709 | Expr *pRight; |
| 1706 | 1710 | |
| 1707 | | - char *zValue; /* Pointer to literal value */ |
| 1711 | + char *zValue; /* Pointer to literal value */ |
| 1708 | 1712 | int nValue; /* Length of literal value buffer */ |
| 1709 | 1713 | }; |
| 1710 | 1714 | |
| 1711 | 1715 | /* Unary operators */ |
| 1712 | 1716 | #define OP_UNARY_MINUS 2 |
| | @@ -1758,11 +1762,11 @@ |
| 1758 | 1762 | {"+", OP_UNARY_PLUS, 1, ARG_NUMBER}, |
| 1759 | 1763 | {"~", OP_BITWISE_NOT, 1, ARG_INTEGER}, |
| 1760 | 1764 | {"!", OP_LOGICAL_NOT, 1, ARG_INTEGER}, |
| 1761 | 1765 | |
| 1762 | 1766 | /* Binary operators. It is important to the parsing in Th_Expr() that |
| 1763 | | - * the two-character symbols ("==") appear before the one-character |
| 1767 | + * the two-character symbols ("==") appear before the one-character |
| 1764 | 1768 | * ones ("="). And that the priorities of all binary operators are |
| 1765 | 1769 | * integers between 2 and 12. |
| 1766 | 1770 | */ |
| 1767 | 1771 | {"<<", OP_LEFTSHIFT, 4, ARG_INTEGER}, |
| 1768 | 1772 | {">>", OP_RIGHTSHIFT, 4, ARG_INTEGER}, |
| | @@ -1789,16 +1793,16 @@ |
| 1789 | 1793 | {0,0,0,0} |
| 1790 | 1794 | }; |
| 1791 | 1795 | |
| 1792 | 1796 | /* |
| 1793 | 1797 | ** The first part of the string (zInput,nInput) contains a number. |
| 1794 | | -** Set *pnVarname to the number of bytes in the numeric string. |
| 1798 | +** Set *pnVarname to the number of bytes in the numeric string. |
| 1795 | 1799 | */ |
| 1796 | 1800 | static int thNextNumber( |
| 1797 | | - Th_Interp *interp, |
| 1798 | | - const char *zInput, |
| 1799 | | - int nInput, |
| 1801 | + Th_Interp *interp, |
| 1802 | + const char *zInput, |
| 1803 | + int nInput, |
| 1800 | 1804 | int *pnLiteral |
| 1801 | 1805 | ){ |
| 1802 | 1806 | int i; |
| 1803 | 1807 | int seenDot = 0; |
| 1804 | 1808 | for(i=0; i<nInput; i++){ |
| | @@ -1864,11 +1868,11 @@ |
| 1864 | 1868 | if( eArgType==ARG_NUMBER ){ |
| 1865 | 1869 | if( (zLeft==0 || TH_OK==Th_ToInt(0, zLeft, nLeft, &iLeft)) |
| 1866 | 1870 | && (zRight==0 || TH_OK==Th_ToInt(0, zRight, nRight, &iRight)) |
| 1867 | 1871 | ){ |
| 1868 | 1872 | eArgType = ARG_INTEGER; |
| 1869 | | - }else if( |
| 1873 | + }else if( |
| 1870 | 1874 | (zLeft && TH_OK!=Th_ToDouble(interp, zLeft, nLeft, &fLeft)) || |
| 1871 | 1875 | (zRight && TH_OK!=Th_ToDouble(interp, zRight, nRight, &fRight)) |
| 1872 | 1876 | ){ |
| 1873 | 1877 | /* A type error. */ |
| 1874 | 1878 | rc = TH_ERROR; |
| | @@ -1876,11 +1880,11 @@ |
| 1876 | 1880 | }else if( eArgType==ARG_INTEGER ){ |
| 1877 | 1881 | rc = Th_ToInt(interp, zLeft, nLeft, &iLeft); |
| 1878 | 1882 | if( rc==TH_OK && zRight ){ |
| 1879 | 1883 | rc = Th_ToInt(interp, zRight, nRight, &iRight); |
| 1880 | 1884 | } |
| 1881 | | - } |
| 1885 | + } |
| 1882 | 1886 | } |
| 1883 | 1887 | |
| 1884 | 1888 | if( rc==TH_OK && eArgType==ARG_INTEGER ){ |
| 1885 | 1889 | int iRes = 0; |
| 1886 | 1890 | switch( pExpr->pOp->eOp ) { |
| | @@ -1978,11 +1982,11 @@ |
| 1978 | 1982 | #define ISTERM(x) (apToken[x] && (!apToken[x]->pOp || apToken[x]->pLeft)) |
| 1979 | 1983 | |
| 1980 | 1984 | for(jj=0; jj<nToken; jj++){ |
| 1981 | 1985 | if( apToken[jj]->pOp && apToken[jj]->pOp->eOp==OP_OPEN_BRACKET ){ |
| 1982 | 1986 | int nNest = 1; |
| 1983 | | - int iLeft = jj; |
| 1987 | + int iLeft = jj; |
| 1984 | 1988 | |
| 1985 | 1989 | for(jj++; jj<nToken; jj++){ |
| 1986 | 1990 | Operator *pOp = apToken[jj]->pOp; |
| 1987 | 1991 | if( pOp && pOp->eOp==OP_OPEN_BRACKET ) nNest++; |
| 1988 | 1992 | if( pOp && pOp->eOp==OP_CLOSE_BRACKET ) nNest--; |
| | @@ -2052,11 +2056,11 @@ |
| 2052 | 2056 | /* |
| 2053 | 2057 | ** Parse a string containing a TH expression to a list of tokens. |
| 2054 | 2058 | */ |
| 2055 | 2059 | static int exprParse( |
| 2056 | 2060 | Th_Interp *interp, /* Interpreter to leave error message in */ |
| 2057 | | - const char *zExpr, /* Pointer to input string */ |
| 2061 | + const char *zExpr, /* Pointer to input string */ |
| 2058 | 2062 | int nExpr, /* Number of bytes at zExpr */ |
| 2059 | 2063 | Expr ***papToken, /* OUT: Array of tokens. */ |
| 2060 | 2064 | int *pnToken /* OUT: Size of token array */ |
| 2061 | 2065 | ){ |
| 2062 | 2066 | int i; |
| | @@ -2127,11 +2131,11 @@ |
| 2127 | 2131 | memcpy(pNew->zValue, z, pNew->nValue); |
| 2128 | 2132 | i += pNew->nValue; |
| 2129 | 2133 | } |
| 2130 | 2134 | if( (nToken%16)==0 ){ |
| 2131 | 2135 | /* Grow the apToken array. */ |
| 2132 | | - Expr **apTokenOld = apToken; |
| 2136 | + Expr **apTokenOld = apToken; |
| 2133 | 2137 | apToken = Th_Malloc(interp, sizeof(Expr *)*(nToken+16)); |
| 2134 | 2138 | memcpy(apToken, apTokenOld, sizeof(Expr *)*nToken); |
| 2135 | 2139 | } |
| 2136 | 2140 | |
| 2137 | 2141 | /* Put the new token at the end of the apToken array */ |
| | @@ -2152,11 +2156,11 @@ |
| 2152 | 2156 | /* |
| 2153 | 2157 | ** Evaluate the string (zExpr, nExpr) as a Th expression. Store |
| 2154 | 2158 | ** the result in the interpreter interp and return TH_OK if |
| 2155 | 2159 | ** successful. If an error occurs, store an error message in |
| 2156 | 2160 | ** the interpreter result and return an error code. |
| 2157 | | -*/ |
| 2161 | +*/ |
| 2158 | 2162 | int Th_Expr(Th_Interp *interp, const char *zExpr, int nExpr){ |
| 2159 | 2163 | int rc; /* Return Code */ |
| 2160 | 2164 | int i; /* Loop counter */ |
| 2161 | 2165 | |
| 2162 | 2166 | int nToken = 0; |
| | @@ -2169,11 +2173,11 @@ |
| 2169 | 2173 | /* Parse the expression to a list of tokens. */ |
| 2170 | 2174 | rc = exprParse(interp, zExpr, nExpr, &apToken, &nToken); |
| 2171 | 2175 | |
| 2172 | 2176 | /* If the parsing was successful, create an expression tree from |
| 2173 | 2177 | ** the parsed list of tokens. If successful, apToken[0] is set |
| 2174 | | - ** to point to the root of the expression tree. |
| 2178 | + ** to point to the root of the expression tree. |
| 2175 | 2179 | */ |
| 2176 | 2180 | if( rc==TH_OK ){ |
| 2177 | 2181 | rc = exprMakeTree(interp, apToken, nToken); |
| 2178 | 2182 | } |
| 2179 | 2183 | |
| | @@ -2210,11 +2214,11 @@ |
| 2210 | 2214 | ** the callback function xCallback for each entry. The second argument |
| 2211 | 2215 | ** passed to xCallback is a copy of the fourth argument passed to this |
| 2212 | 2216 | ** function. |
| 2213 | 2217 | */ |
| 2214 | 2218 | void Th_HashIterate( |
| 2215 | | - Th_Interp *interp, |
| 2219 | + Th_Interp *interp, |
| 2216 | 2220 | Th_Hash *pHash, |
| 2217 | 2221 | void (*xCallback)(Th_HashEntry *pEntry, void *pContext), |
| 2218 | 2222 | void *pContext |
| 2219 | 2223 | ){ |
| 2220 | 2224 | int i; |
| | @@ -2244,14 +2248,14 @@ |
| 2244 | 2248 | Th_Free(interp, pHash); |
| 2245 | 2249 | } |
| 2246 | 2250 | } |
| 2247 | 2251 | |
| 2248 | 2252 | /* |
| 2249 | | -** This function is used to insert or delete hash table items, or to |
| 2253 | +** This function is used to insert or delete hash table items, or to |
| 2250 | 2254 | ** query a hash table for an existing item. |
| 2251 | 2255 | ** |
| 2252 | | -** If parameter op is less than zero, then the hash-table element |
| 2256 | +** If parameter op is less than zero, then the hash-table element |
| 2253 | 2257 | ** identified by (zKey, nKey) is removed from the hash-table if it |
| 2254 | 2258 | ** exists. NULL is returned. |
| 2255 | 2259 | ** |
| 2256 | 2260 | ** Otherwise, if the hash-table contains an item with key (zKey, nKey), |
| 2257 | 2261 | ** a pointer to the associated Th_HashEntry is returned. If parameter |
| | @@ -2258,11 +2262,11 @@ |
| 2258 | 2262 | ** op is greater than zero, then a new entry is added if one cannot |
| 2259 | 2263 | ** be found. If op is zero, then NULL is returned if the item is |
| 2260 | 2264 | ** not already present in the hash-table. |
| 2261 | 2265 | */ |
| 2262 | 2266 | Th_HashEntry *Th_HashFind( |
| 2263 | | - Th_Interp *interp, |
| 2267 | + Th_Interp *interp, |
| 2264 | 2268 | Th_Hash *pHash, |
| 2265 | 2269 | const char *zKey, |
| 2266 | 2270 | int nKey, |
| 2267 | 2271 | int op /* -ve = delete, 0 = find, +ve = insert */ |
| 2268 | 2272 | ){ |
| | @@ -2326,11 +2330,11 @@ |
| 2326 | 2330 | ** '\f' 0x0C |
| 2327 | 2331 | ** '\r' 0x0D |
| 2328 | 2332 | ** |
| 2329 | 2333 | ** Whitespace characters have the 0x01 flag set. Decimal digits have the |
| 2330 | 2334 | ** 0x2 flag set. Single byte printable characters have the 0x4 flag set. |
| 2331 | | -** Alphabet characters have the 0x8 bit set. |
| 2335 | +** Alphabet characters have the 0x8 bit set. |
| 2332 | 2336 | ** |
| 2333 | 2337 | ** The special list characters have the 0x10 flag set |
| 2334 | 2338 | ** |
| 2335 | 2339 | ** { } [ ] \ ; ' " |
| 2336 | 2340 | ** |
| | @@ -2477,14 +2481,14 @@ |
| 2477 | 2481 | return z - zBegin; |
| 2478 | 2482 | } |
| 2479 | 2483 | |
| 2480 | 2484 | /* |
| 2481 | 2485 | ** Try to convert the string passed as arguments (z, n) to an integer. |
| 2482 | | -** If successful, store the result in *piOut and return TH_OK. |
| 2486 | +** If successful, store the result in *piOut and return TH_OK. |
| 2483 | 2487 | ** |
| 2484 | | -** If the string cannot be converted to an integer, return TH_ERROR. |
| 2485 | | -** If the interp argument is not NULL, leave an error message in the |
| 2488 | +** If the string cannot be converted to an integer, return TH_ERROR. |
| 2489 | +** If the interp argument is not NULL, leave an error message in the |
| 2486 | 2490 | ** interpreter result too. |
| 2487 | 2491 | */ |
| 2488 | 2492 | int Th_ToInt(Th_Interp *interp, const char *z, int n, int *piOut){ |
| 2489 | 2493 | int i = 0; |
| 2490 | 2494 | int iOut = 0; |
| | @@ -2512,20 +2516,20 @@ |
| 2512 | 2516 | return TH_OK; |
| 2513 | 2517 | } |
| 2514 | 2518 | |
| 2515 | 2519 | /* |
| 2516 | 2520 | ** Try to convert the string passed as arguments (z, n) to a double. |
| 2517 | | -** If successful, store the result in *pfOut and return TH_OK. |
| 2521 | +** If successful, store the result in *pfOut and return TH_OK. |
| 2518 | 2522 | ** |
| 2519 | | -** If the string cannot be converted to a double, return TH_ERROR. |
| 2520 | | -** If the interp argument is not NULL, leave an error message in the |
| 2523 | +** If the string cannot be converted to a double, return TH_ERROR. |
| 2524 | +** If the interp argument is not NULL, leave an error message in the |
| 2521 | 2525 | ** interpreter result too. |
| 2522 | 2526 | */ |
| 2523 | 2527 | int Th_ToDouble( |
| 2524 | | - Th_Interp *interp, |
| 2525 | | - const char *z, |
| 2526 | | - int n, |
| 2528 | + Th_Interp *interp, |
| 2529 | + const char *z, |
| 2530 | + int n, |
| 2527 | 2531 | double *pfOut |
| 2528 | 2532 | ){ |
| 2529 | 2533 | if( !sqlite3IsNumber((const char *)z, 0) ){ |
| 2530 | 2534 | Th_ErrorMessage(interp, "expected number, got: \"", z, n); |
| 2531 | 2535 | return TH_ERROR; |
| | @@ -2566,33 +2570,33 @@ |
| 2566 | 2570 | ** the double fVal and return TH_OK. |
| 2567 | 2571 | */ |
| 2568 | 2572 | int Th_SetResultDouble(Th_Interp *interp, double fVal){ |
| 2569 | 2573 | int i; /* Iterator variable */ |
| 2570 | 2574 | double v = fVal; /* Input value */ |
| 2571 | | - char zBuf[128]; /* Output buffer */ |
| 2572 | | - char *z = zBuf; /* Output cursor */ |
| 2575 | + char zBuf[128]; /* Output buffer */ |
| 2576 | + char *z = zBuf; /* Output cursor */ |
| 2573 | 2577 | int iDot = 0; /* Digit after which to place decimal point */ |
| 2574 | 2578 | int iExp = 0; /* Exponent (NN in eNN) */ |
| 2575 | | - const char *zExp; /* String representation of iExp */ |
| 2579 | + const char *zExp; /* String representation of iExp */ |
| 2576 | 2580 | |
| 2577 | 2581 | /* Precision: */ |
| 2578 | 2582 | #define INSIGNIFICANT 0.000000000001 |
| 2579 | 2583 | #define ROUNDER 0.0000000000005 |
| 2580 | 2584 | double insignificant = INSIGNIFICANT; |
| 2581 | 2585 | |
| 2582 | 2586 | /* If the real value is negative, write a '-' character to the |
| 2583 | 2587 | * output and transform v to the corresponding positive number. |
| 2584 | | - */ |
| 2588 | + */ |
| 2585 | 2589 | if( v<0.0 ){ |
| 2586 | 2590 | *z++ = '-'; |
| 2587 | 2591 | v *= -1.0; |
| 2588 | 2592 | } |
| 2589 | 2593 | |
| 2590 | | - /* Normalize v to a value between 1.0 and 10.0. Integer |
| 2594 | + /* Normalize v to a value between 1.0 and 10.0. Integer |
| 2591 | 2595 | * variable iExp is set to the exponent. i.e the original |
| 2592 | 2596 | * value is (v * 10^iExp) (or the negative thereof). |
| 2593 | | - */ |
| 2597 | + */ |
| 2594 | 2598 | if( v>0.0 ){ |
| 2595 | 2599 | while( (v+ROUNDER)>=10.0 ) { iExp++; v *= 0.1; } |
| 2596 | 2600 | while( (v+ROUNDER)<1.0 ) { iExp--; v *= 10.0; } |
| 2597 | 2601 | } |
| 2598 | 2602 | v += ROUNDER; |
| 2599 | 2603 | |