Changeset 7149 for trunk/tools


Ignore:
Timestamp:
Oct 22, 2001, 5:54:53 AM (24 years ago)
Author:
bird
Message:

Added kLog features.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/vslick/odin32.e

    r4361 r7149  
    1 /* $Id: odin32.e,v 1.6 2000-10-02 04:08:49 bird Exp $
     1/* $Id: odin32.e,v 1.7 2001-10-22 03:54:53 bird Exp $
    22 *
    33 * Visual SlickEdit Documentation Macros.
     
    2222 * Ctrl+Shift+S: Struct/Typedef box
    2323 *
    24  * Ctrl+Shift+T: Makes tag file
     24 * Ctrl+Shift+T:
     25 *
     26 * Ctrl+Shift+B: KLOGENTRYX(..)
     27 * Ctrl+Shift+E: KLOGEXIT(..)
     28 * Ctrl+Shift+Q: Do kLog stuff for the current file.
    2529 *
    2630 * Remember to set the correct sOdin32UserName, sOdin32UserEmail and sOdin32UserInitials
     
    3236defeventtab default_keys
    3337def  'C-S-A' = odin32_signature
     38def  'C-S-B' = odin32_klogentry
    3439def  'C-S-C' = odin32_classbox
     40def  'C-S-E' = odin32_klogexit
    3541def  'C-S-F' = odin32_funcbox
    3642def  'C-S-G' = odin32_globalbox
     
    4046def  'C-S-M' = odin32_modulebox
    4147def  'C-S-O' = odin32_oneliner
     48def  'C-S-Q' = odin32_klog_file
    4249def  'C-S-S' = odin32_structbox
    4350def  'C-S-T' = odin32_maketagfile
     
    303310    if (file_eq(p_extension, 'asm'))
    304311    {
    305         _insert_text("; $Id: odin32.e,v 1.6 2000-10-02 04:08:49 bird Exp $\n");
     312        _insert_text("; $Id: odin32.e,v 1.7 2001-10-22 03:54:53 bird Exp $\n");
    306313        _insert_text("; \n");
    307314        _insert_text("; \n");
     
    316323    else
    317324    {
    318         _insert_text("/* $Id: odin32.e,v 1.6 2000-10-02 04:08:49 bird Exp $\n");
     325        _insert_text("/* $Id: odin32.e,v 1.7 2001-10-22 03:54:53 bird Exp $\n");
    319326        _insert_text(" * \n");
    320327        _insert_text(" * \n");
     
    348355}
    349356
     357
     358/**
     359 * Hot-Key: Inserts a KLOGENTRY statement at start of nearest function.
     360 */
     361void odin32_klogentry()
     362{
     363    _save_pos2(org_pos);
     364
     365    /*
     366     * Go to nearest function.
     367     */
     368    if (!odin32_func_goto_nearest())
     369    {
     370        /*
     371         * Get parameters.
     372         */
     373        _str sParams = odin32_getparams();
     374        if (sParams)
     375        {
     376            /*
     377             * Insert text.
     378             */
     379            if (!search("{"))
     380            {
     381                p_col++;
     382                cArgs = odin32_countparams(sParams);
     383                if (cArgs > 0)
     384                {
     385                    sArgs = "";
     386                    for (i = 0; i < cArgs; i++)
     387                    {
     388                        _str sType, sName, sDefault
     389                        if (!odin32_enumparams(sParams, i, sType, sName, sDefault))
     390                            sArgs = sArgs', 'sName;
     391                    }
     392
     393                    _insert_text("\n    KLOGENTRY"cArgs"(\""sParams"\""sArgs");"); /* todo tab size.. or smart indent */
     394                }
     395                else
     396                    _insert_text("\n    KLOGENTRY0();"); /* todo tab size.. or smart indent */
     397
     398                /*
     399                 * Check if the next word is KLOGENTRY.
     400                 */
     401                next_word();
     402                if (def_next_word_style == 'E')
     403                    prev_word();
     404                if (substr(cur_word(iIgnorePos), 1, 9) == "KLOGENTRY")
     405                    delete_line();
     406
     407            }
     408            else
     409                message("didn't find {");
     410        }
     411        else
     412            message("odin32_getparams failed, sParams=" sParams);
     413        return;
     414    }
     415
     416    _restore_pos2(org_pos);
     417}
     418
     419
     420/**
     421 * Hot-Key: Inserts a KLOGEXIT statement at cursor location.
     422 */
     423void odin32_klogexit()
     424{
     425    _save_pos2(org_pos);
     426
     427    /*
     428     * Go to nearest function.
     429     */
     430    if (!prev_proc())
     431    {
     432        /*
     433         * Get parameters.
     434         */
     435        _str sType = odin32_getreturntype(true);
     436        _restore_pos2(org_pos);
     437        if (sType)
     438        {
     439            /*
     440             * Insert text.
     441             */
     442            cur_col = p_col;
     443            if (sType == 'void' || sType == 'VOID')
     444            {
     445                while (p_col <= p_SyntaxIndent)
     446                    keyin(" ");
     447                _insert_text("KLOGEXITVOID();");
     448            }
     449            else
     450            {
     451                if (sType == 'unsigned' || sType == 'UNSIGNED' || sType == 'DWORD' || sType == 'ULONG' || sType == 'UINT')
     452                    _insert_text("KLOGEXITUINT();");
     453                else if (sType == 'unsigned' || sType == 'UNSIGNED' || sType == 'DWORD' || sType == 'ULONG' || sType == 'UINT')
     454                    _insert_text("KLOGEXITINT();");
     455                else if (sType == 'void *' || sType == 'VOID *' || sType == 'PVOID')
     456                    _insert_text("KLOGEXITHEX();");
     457                else
     458                    _insert_text("KLOGEXIT(\""sType"\", );");
     459                _insert_text("\n");
     460                for (i = 1; i < cur_col; i++)
     461                    _insert_text(" ");
     462                search(")","E-");
     463
     464                /*
     465                 * Check if it's a simple return statement.
     466                 */
     467                _save_pos2(valuepos);
     468                next_word();
     469                if (def_next_word_style == 'E')
     470                    prev_word();
     471                if (cur_word(iIgnorePos) == 'return')
     472                {
     473                    p_col += length('return');
     474                    _save_pos2(posStart);
     475                    offStart = _QROffset();
     476                    if (!search(";", "E+"))
     477                    {
     478                        offEnd = _QROffset();
     479                        _restore_pos2(posStart);
     480                        _str sValue = strip(get_text(offEnd - offStart));
     481                        if (substr(sValue, 1, 1) == '(' && substr(sValue, length(sValue), 1) == ')')
     482                            sValue = strip(substr(sValue, 2, length(sValue) - 2));
     483                        _restore_pos2(valuepos);
     484                        _save_pos2(valuepos);
     485                        _insert_text(sValue);
     486                    }
     487                }
     488                _restore_pos2(valuepos);
     489
     490                /*
     491                 * Remove old KLOGEXIT statement on previous line if any.
     492                 */
     493                _save_pos2(valuepos);
     494                newexitline = p_line;
     495                p_line--; p_col = 1;
     496                next_word();
     497                if (def_next_word_style == 'E')
     498                    prev_word();
     499                if (p_line == newexitline - 1 && substr(cur_word(iIgnorePos), 1, 8) == 'KLOGEXIT')
     500                    delete_line();
     501                _restore_pos2(valuepos);
     502            }
     503        }
     504        else
     505            message("odin32_getparams failed, sType=" sType);
     506        return;
     507    }
     508
     509    _restore_pos2(org_pos);
     510}
     511
     512
     513/**
     514 * Goes thru a file.
     515 */
     516void odin32_klog_file()
     517{
     518    show_all();
     519    bottom();
     520    _refresh_scroll();
     521
     522    /* ask question so we can get to the right position somehow.. */
     523    if (_message_box("kLog process this file?", "Visual SlickEdit", MB_YESNO | MB_ICONQUESTION) != IDYES)
     524        return;
     525
     526    /*
     527     * Entries.
     528     */
     529    while (!prev_proc())
     530    {
     531        /*
     532         * Skip prototypes.
     533         */
     534        if (odin32_prototype())
     535            continue;
     536
     537        /*
     538         * Ask user.
     539         */
     540        center_line();
     541        _refresh_scroll();
     542        sFunction = odin32_getfunction();
     543        rc = _message_box("Process this function ("sFunction")?", "Visual SlickEdit", MB_YESNOCANCEL | MB_ICONQUESTION);
     544        if (rc == IDYES)
     545        {
     546            _save_pos2(procpos);
     547            odin32_klogentry();
     548            _restore_pos2(procpos);
     549        }
     550        else if (rc == IDNO)
     551            continue;
     552        else
     553            break;
     554    }
     555
     556    /*
     557     * Exits.
     558     */
     559    bottom(); _refresh_scroll();
     560    boolean fUserCancel = false;
     561    while (!prev_proc() && !fUserCancel)
     562    {
     563        _save_pos2(procpos);
     564        sCurFunction = odin32_getfunction();
     565
     566        /*
     567         * Skip prototypes.
     568         */
     569        if (odin32_prototype())
     570            continue;
     571
     572        /*
     573         * Select procedure.
     574         */
     575        while (!search("return", "WE<+") && odin32_getfunction() == sCurFunction)
     576        {
     577            /*
     578             * Ask User.
     579             */
     580            center_line();
     581            _refresh_scroll();
     582            sFunction = odin32_getfunction();
     583            rc = _message_box("Process this exit from "sFunction"?", "Visual SlickEdit", MB_YESNOCANCEL | MB_ICONQUESTION);
     584            deselect();
     585            if (rc == IDYES)
     586            {
     587                _save_pos2(returnpos);
     588                odin32_klogexit();
     589                _restore_pos2(returnpos);
     590                p_line++;
     591            }
     592            else if (rc != IDNO)
     593            {
     594                fUserCancel = true;
     595                break;
     596            }
     597            p_line++;                       /* just so we won't hit it again. */
     598        }
     599
     600        /*
     601         * If void function we'll have to check if there is and return; prior to the ending '}'.
     602         */
     603        _restore_pos2(procpos);
     604        _save_pos2(procpos);
     605        sType = odin32_getreturntype(true);
     606        if (!fUserCancel && sType && (sType == 'void' || sType == 'VOID'))
     607        {
     608            if (    !search("{", "E+")
     609                &&  !find_matching_paren())
     610            {
     611                _save_pos2(funcend);
     612                prev_word();
     613                if (cur_word(iIgnorePos) != "return")
     614                {
     615                    /*
     616                     * Ask User.
     617                     */
     618                    _restore_pos2(funcend);
     619                    center_line();
     620                    _refresh_scroll();
     621                    sFunction = odin32_getfunction();
     622                    rc = _message_box("Process this exit from "sFunction"?", "Visual SlickEdit", MB_YESNOCANCEL | MB_ICONQUESTION);
     623                    deselect();
     624                    if (rc == IDYES)
     625                    {
     626                        _save_pos2(returnpos);
     627                        odin32_klogexit();
     628                        _restore_pos2(returnpos);
     629                    }
     630                }
     631            }
     632        }
     633
     634        /*
     635         * Next proc.
     636         */
     637        _restore_pos2(procpos);
     638    }
     639
     640
     641}
     642
     643
     644
     645/**
     646 * Moves cursor to nearest function start.
     647 */
     648int odin32_func_goto_nearest()
     649{
     650    cur_line = p_line;
     651    prev_line = -1;
     652    next_line = -1;
     653    _save_pos2(org_pos);
     654
     655    if (!prev_proc(1))
     656    {
     657        prev_line = p_line;
     658        if (!next_proc(1) && p_line == cur_line)
     659        {
     660            _restore_pos2(org_pos);
     661            return 0;
     662        }
     663        _restore_pos2(org_pos);
     664        _save_pos2(org_pos);
     665    }
     666
     667    if (!next_proc(1))
     668    {
     669        next_line = p_line;
     670        if (!prev_proc(1) && p_line == cur_line)
     671        {
     672            _restore_pos2(org_pos);
     673            return 0;
     674        }
     675        _restore_pos2(org_pos);
     676        _save_pos2(org_pos);
     677    }
     678
     679    if (prev_line != -1 && (next_line == -1 || cur_line - prev_line <= next_line - cur_line))
     680    {
     681        prev_proc(1);
     682        return 0;
     683    }
     684
     685    if (next_line != -1 && (prev_line == -1 || cur_line - prev_line > next_line - cur_line))
     686    {
     687        next_proc();
     688        return 0;
     689    }
     690
     691    return -1;
     692}
     693
     694
     695/**
     696 * Check if nearest function is a prototype.
     697 */
     698boolean odin32_prototype()
     699{
     700    /*
     701     * Check if this is a real function implementation.
     702     */
     703    _save_pos2(procpos);
     704    if (!odin32_func_goto_nearest())
     705    {
     706        proc_line = p_line;
     707
     708        if (!search("{", "E+"))
     709        {
     710            prev_proc();
     711            if (p_line != proc_line)
     712            {
     713                _restore_pos2(procpos);
     714                return true;
     715            }
     716        }
     717    }
     718    _restore_pos2(procpos);
     719
     720    return false;
     721}
     722
     723
     724/**
     725 * Gets the name fo the current function.
     726 */
     727static _str odin32_getfunction()
     728{
     729    return current_proc();
     730}
     731
     732
     733/**
     734 * Goes to the neares function and gets its parameters.
     735 * @remark  Should be reimplemented to use tags (if someone can figure out how to query that stuff).
     736 */
     737static _str odin32_getparams()
     738{
     739    _save_pos2(org_pos);
     740
     741    /*
     742     * Go to nearest function.
     743     */
     744    if (    !odin32_func_goto_nearest()
     745        &&  !search("(")               /* makes some assumptions. */
     746        )
     747    {
     748        /*
     749         * Get parameters.
     750         */
     751        _save_pos2(posStart);
     752        offStart = _QROffset();
     753        if (!find_matching_paren())
     754        {
     755            offEnd = _QROffset();
     756            _restore_pos2(posStart);
     757            p_col++;
     758            _str sParamsRaw = strip(get_text(offEnd - offStart - 1));
     759
     760
     761            /*
     762             * Remove new lines and double spaces within params.
     763             */
     764            _str sParams = "";
     765
     766            int i;
     767            for (i = 1, chPrev = ' '; i <= length(sParamsRaw); i++)
     768            {
     769                ch = substr(sParamsRaw, i, 1);
     770
     771                /*
     772                 * Do fixups.
     773                 */
     774                if (ch == " " && chPrev == " ")
     775                        continue;
     776
     777                if ((ch :== "\n") || (ch :== "\r") || (ch :== "\t"))
     778                {
     779                    if (chPrev == ' ')
     780                        continue;
     781                    ch = ' ';
     782                }
     783
     784                if (ch == ',' && chPrev == ' ')
     785                {
     786                    sParams = substr(sParams, 1, length(sParams) - 1);
     787                }
     788
     789                if (ch == '*')
     790                {
     791                    if (chPrev != ' ')
     792                        sParams = sParams :+ ' * ';
     793                    else
     794                        sParams = sParams :+ '* ';
     795                    chPrev = ' ';
     796                }
     797                else
     798                {
     799                    sParams = sParams :+ ch;
     800                    chPrev = ch;
     801                }
     802
     803            } /* for */
     804
     805            sParams = strip(sParams);
     806            if (sParams == 'void' || sParams == 'VOID')
     807                sParams = "";
     808            _restore_pos2(org_pos);
     809            return sParams;
     810        }
     811        else
     812            message("find_matchin_paren failed");
     813    }
     814
     815    _restore_pos2(org_pos);
     816    return false;
     817}
     818
     819
     820
     821/**
     822 * Enumerates the parameters to the function.
     823 * @param   sParams     Parameter string from odin32_getparams.
     824 * @param   iParam      The index (0-based) of the parameter to get.
     825 * @param   sType       Type. (output)
     826 * @param   sName       Name. (output)
     827 * @param   sDefault    Default value. (output)
     828 * @remark  Doesn't perhaps handle function pointers very well (I think)?
     829 * @remark  Should be reimplemented to use tags (if someone can figure out how to query that stuff).
     830 */
     831static int odin32_enumparams(_str sParams, int iParam, _str &sType, _str &sName, _str &sDefault)
     832{
     833    int     i;
     834    int     iParLevel;
     835    int     iCurParam;
     836    int     iStartParam;
     837
     838    sType = sName = sDefault = "";
     839
     840    /* no use working on empty string! */
     841    if (length(sParams) == 0)
     842        return -1;
     843
     844    /* find the parameter in question */
     845    for (iStartParam = i = 1, iParLevel = iCurParam = 0; i <= length(sParams); i++)
     846    {
     847        _str ch = substr(sParams, i, 1);
     848        if (ch == ',' && iParLevel == 0)
     849        {
     850            /* is it this parameter ? */
     851            if (iParam == iCurParam)
     852                break;
     853
     854            iCurParam++;
     855            iStartParam = i + 1;
     856        }
     857        else if (ch == '(')
     858            iParLevel++;
     859        else if (ch == ')')
     860            iParLevel--;
     861    }
     862
     863    /* did we find the parameter? */
     864    if (iParam == iCurParam)
     865    {   /* (yeah, we did!) */
     866        sArg = strip(substr(sParams, iStartParam, i - 1));
     867
     868        /* lazy approach, which doens't support function types */
     869
     870        if (pos('=', sParams) > 0)      /* default */
     871        {
     872            sDefault = strip(substr(sParams, pos('=', sParams) + 1));
     873            sArg = strip(substr(sArg, 1, pos('=', sParams) - 1));
     874        }
     875
     876        for (i = length(sArg); i > 1; i--)
     877        {
     878            _str ch = substr(sArg, i, 1);
     879            if (    !(ch >= 'a' &&  ch <= 'z')
     880                &&  !(ch >= 'A' &&  ch <= 'Z')
     881                &&  !(ch >= '0'  && ch <= '9')
     882                &&  ch != '_' && ch != '$')
     883                break;
     884        }
     885        sName = strip(substr(sArg, i + 1));
     886        sType = strip(substr(sArg, 1, i));
     887
     888        return 0;
     889    }
     890
     891    return -1;
     892}
     893
     894
     895/**
     896 * Counts the parameters to the function.
     897 * @param   sParams     Parameter string from odin32_getparams.
     898 * @remark  Should be reimplemented to use tags (if someone can figure out how to query that stuff).
     899 */
     900static int odin32_countparams(_str sParams)
     901{
     902    int     i;
     903    int     iParLevel;
     904    int     iCurParam;
     905
     906    sType = sName = sDefault = "";
     907
     908    /* check for 0 parameters */
     909    if (length(sParams) == 0)
     910        return 0;
     911
     912    /* find the parameter in question */
     913    for (i = 1, iParLevel = iCurParam = 0; i <= length(sParams); i++)
     914    {
     915        _str ch = substr(sParams, i, 1);
     916        if (ch == ',' && iParLevel == 0)
     917        {
     918            iCurParam++;
     919        }
     920        else if (ch == '(')
     921            iParLevel++;
     922        else if (ch == ')')
     923            iParLevel--;
     924    }
     925
     926    say 'returntype='odin32_getreturntype(true);
     927
     928    return iCurParam + 1;
     929}
     930
     931/**
     932 * Gets the return type.
     933 */
     934static _str odin32_getreturntype(boolean fPureType = false)
     935{
     936    _save_pos2(org_pos);
     937
     938    /*
     939     * Go to nearest function.
     940     */
     941    if (!odin32_func_goto_nearest())
     942    {
     943        /*
     944         * Return type is from function start to function name...
     945         */
     946        _save_pos2(posStart);
     947        offStart = _QROffset();
     948
     949        if (!search("("))               /* makes some assumptions. */
     950        {
     951            prev_word();
     952            offEnd = _QROffset();
     953            _restore_pos2(posStart);
     954            _str sTypeRaw = strip(get_text(offEnd - offStart - 1));
     955
     956            /*
     957             * Remove static, inline, _Optlink, stdcall, EXPENTRY etc.
     958             */
     959            if (fPureType)
     960            {
     961                sTypeRaw = stranslate(sTypeRaw, "", "__static__", "I");
     962                sTypeRaw = stranslate(sTypeRaw, "", "__static", "I");
     963                sTypeRaw = stranslate(sTypeRaw, "", "static__", "I");
     964                sTypeRaw = stranslate(sTypeRaw, "", "static", "I");
     965                sTypeRaw = stranslate(sTypeRaw, "", "__inline__", "I");
     966                sTypeRaw = stranslate(sTypeRaw, "", "__inline", "I");
     967                sTypeRaw = stranslate(sTypeRaw, "", "inline__", "I");
     968                sTypeRaw = stranslate(sTypeRaw, "", "inline", "I");
     969                sTypeRaw = stranslate(sTypeRaw, "", "EXPENTRY", "I");
     970                sTypeRaw = stranslate(sTypeRaw, "", "_Optlink", "I");
     971                sTypeRaw = stranslate(sTypeRaw, "", "__stdcall", "I");
     972                sTypeRaw = stranslate(sTypeRaw, "", "__cdecl", "I");
     973                sTypeRaw = stranslate(sTypeRaw, "", "_cdecl", "I");
     974                sTypeRaw = stranslate(sTypeRaw, "", "cdecl", "I");
     975                sTypeRaw = stranslate(sTypeRaw, "", "PASCAL", "I");
     976                sTypeRaw = stranslate(sTypeRaw, "", "__far", "I");
     977                sTypeRaw = stranslate(sTypeRaw, "", "_far", "I");
     978                sTypeRaw = stranslate(sTypeRaw, "", "far", "I");
     979                sTypeRaw = stranslate(sTypeRaw, "", "__near", "I");
     980                sTypeRaw = stranslate(sTypeRaw, "", "_near", "I");
     981                sTypeRaw = stranslate(sTypeRaw, "", "near", "I");
     982                sTypeRaw = stranslate(sTypeRaw, "", "WIN32API", "I");
     983                sTypeRaw = stranslate(sTypeRaw, "", "WINAPI", "I");
     984            }
     985
     986            /*
     987             * Remove new lines and double spaces within params.
     988             */
     989            _str sType = "";
     990
     991            int i;
     992            for (i = 1, chPrev = ' '; i <= length(sTypeRaw); i++)
     993            {
     994                ch = substr(sTypeRaw, i, 1);
     995
     996                /*
     997                 * Do fixups.
     998                 */
     999                if (ch == " " && chPrev == " ")
     1000                        continue;
     1001
     1002                if ((ch :== "\n") || (ch :== "\r") || (ch :== "\t"))
     1003                {
     1004                    if (chPrev == ' ')
     1005                        continue;
     1006                    ch = ' ';
     1007                }
     1008
     1009                if (ch == ',' && chPrev == ' ')
     1010                {
     1011                    sType = substr(sType, 1, length(sType) - 1);
     1012                }
     1013
     1014                if (ch == '*')
     1015                {
     1016                    if (chPrev != ' ')
     1017                        sType = sType :+ ' * ';
     1018                    else
     1019                        sType = sType :+ '* ';
     1020                    chPrev = ' ';
     1021                }
     1022                else
     1023                {
     1024                    sType = sType :+ ch;
     1025                    chPrev = ch;
     1026                }
     1027
     1028            } /* for */
     1029
     1030            sType = strip(sType);
     1031
     1032            _restore_pos2(org_pos);
     1033            return sType;
     1034        }
     1035        else
     1036            message('odin32_getreturntype: can''t find ''(''.');
     1037    }
     1038
     1039    _restore_pos2(org_pos);
     1040    return false;
     1041}
Note: See TracChangeset for help on using the changeset viewer.