Changeset 7160 for trunk/tools


Ignore:
Timestamp:
Oct 23, 2001, 4:14:02 AM (24 years ago)
Author:
bird
Message:

Mostly working kLog support.

File:
1 edited

Legend:

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

    r7150 r7160  
    1 /* $Id: odin32.e,v 1.8 2001-10-22 04:11:08 bird Exp $
     1/* $Id: odin32.e,v 1.9 2001-10-23 02:14:02 bird Exp $
    22 *
    33 * Visual SlickEdit Documentation Macros.
     
    312312    if (file_eq(p_extension, 'asm'))
    313313    {
    314         _insert_text("; $Id: odin32.e,v 1.8 2001-10-22 04:11:08 bird Exp $\n");
     314        _insert_text("; $Id: odin32.e,v 1.9 2001-10-23 02:14:02 bird Exp $\n");
    315315        _insert_text("; \n");
    316316        _insert_text("; \n");
     
    325325    else
    326326    {
    327         _insert_text("/* $Id: odin32.e,v 1.8 2001-10-22 04:11:08 bird Exp $\n");
     327        _insert_text("/* $Id: odin32.e,v 1.9 2001-10-23 02:14:02 bird Exp $\n");
    328328        _insert_text(" * \n");
    329329        _insert_text(" * \n");
     
    376376        if (sParams)
    377377        {
     378            _str sRetType = odin32_getreturntype(true);
     379            if (!sRetType || sRetType == "")
     380                sRetType = "void";      /* paranoia! */
     381
    378382            /*
    379383             * Insert text.
    380384             */
    381             if (!search("{"))
     385            if (!odin32_searchcode("{"))
    382386            {
    383387                p_col++;
     
    393397                    }
    394398
    395                     _insert_text("\n    KLOGENTRY"cArgs"(\""sParams"\""sArgs");"); /* todo tab size.. or smart indent */
     399                    _insert_text("\n    KLOGENTRY"cArgs"(\""sRetType"\",\""sParams"\""sArgs");"); /* todo tab size.. or smart indent */
    396400                }
    397401                else
    398                     _insert_text("\n    KLOGENTRY0();"); /* todo tab size.. or smart indent */
     402                    _insert_text("\n    KLOGENTRY0(\""sRetType"\");"); /* todo tab size.. or smart indent */
    399403
    400404                /*
     
    439443        if (sType)
    440444        {
     445            boolean fReturn = true;     /* true if an return statment is following the KLOGEXIT statement. */
     446
    441447            /*
    442448             * Insert text.
     
    444450            cur_col = p_col;
    445451            if (sType == 'void' || sType == 'VOID')
    446             {
    447                 while (p_col <= p_SyntaxIndent)
    448                     keyin(" ");
    449                 _insert_text("KLOGEXITVOID();");
     452            {   /* procedure */
     453                fReturn = cur_word(iIgnorePos) == 'return';
     454                if (!fReturn)
     455                {
     456                    while (p_col <= p_SyntaxIndent)
     457                        keyin(" ");
     458                }
     459
     460                _insert_text("KLOGEXITVOID();\n");
     461
     462                if (fReturn)
     463                {
     464                    for (i = 1; i < cur_col; i++)
     465                        _insert_text(" ");
     466                }
     467                search(")","E-");
    450468            }
    451469            else
    452             {
    453                 if (sType == 'unsigned' || sType == 'UNSIGNED' || sType == 'UINT')
    454                     _insert_text("KLOGEXITUINT();");
    455                 else if (sType == 'int' || sType == 'INT')
    456                     _insert_text("KLOGEXITINT();");
    457                 else if (sType == 'void *' || sType == 'VOID *' || sType == 'PVOID' || sType == 'LPVOID')
    458                     _insert_text("KLOGEXITHEX();");
    459                 else
    460                     _insert_text("KLOGEXIT(\""sType"\", );");
    461                 _insert_text("\n");
     470            {   /* function */
     471                _insert_text("KLOGEXIT();\n");
    462472                for (i = 1; i < cur_col; i++)
    463473                    _insert_text(" ");
     
    465475
    466476                /*
    467                  * Check if it's a simple return statement.
     477                 * Insert value if possible.
    468478                 */
    469479                _save_pos2(valuepos);
     
    476486                    _save_pos2(posStart);
    477487                    offStart = _QROffset();
    478                     if (!search(";", "E+"))
     488                    if (!odin32_searchcode(";", "E+"))
    479489                    {
    480490                        offEnd = _QROffset();
    481491                        _restore_pos2(posStart);
    482492                        _str sValue = strip(get_text(offEnd - offStart));
    483                         if (substr(sValue, 1, 1) == '(' && substr(sValue, length(sValue), 1) == ')')
    484                             sValue = strip(substr(sValue, 2, length(sValue) - 2));
     493                        //say 'sValue = 'sValue;
    485494                        _restore_pos2(valuepos);
    486495                        _save_pos2(valuepos);
     
    489498                }
    490499                _restore_pos2(valuepos);
    491 
    492                 /*
    493                  * Remove old KLOGEXIT statement on previous line if any.
    494                  */
     500            }
     501
     502            /*
     503             * Remove old KLOGEXIT statement on previous line if any.
     504             */
     505            _save_pos2(valuepos);
     506            newexitline = p_line;
     507            p_line--; p_col = 1;
     508            next_word();
     509            if (def_next_word_style == 'E')
     510                prev_word();
     511            if (p_line == newexitline - 1 && substr(cur_word(iIgnorePos), 1, 8) == 'KLOGEXIT')
     512                delete_line();
     513            _restore_pos2(valuepos);
     514
     515            /*
     516             * Check for missing '{...}'.
     517             */
     518            if (fReturn)
     519            {
     520                boolean fFound = false;
    495521                _save_pos2(valuepos);
    496                 newexitline = p_line;
    497                 p_line--; p_col = 1;
    498                 next_word();
    499                 if (def_next_word_style == 'E')
     522                p_col--; find_matching_paren(); p_col += 2;
     523                odin32_searchcode(';', 'E+'); /* places us at the ';' of the return. (hopefully) */
     524
     525                _str ch = odin32_get_next_code_text();
     526                if (ch != '}')
     527                {
     528                    _restore_pos2(valuepos);
     529                    _save_pos2(valuepos);
     530                    p_col--; find_matching_paren(); p_col += 2;
     531                    odin32_searchcode(';', 'E+'); /* places us at the ';' of the return. (hopefully) */
     532                    p_col++;
     533                    if (odin32_more_code_on_line())
     534                        _insert_text(' }');
     535                    else
     536                    {
     537                        _save_pos2(returnget);
     538                        odin32_searchcode("return", "E-");
     539                        return_col = p_col;
     540                        _restore_pos2(returnget);
     541
     542                        end_line();
     543                        _insert_text("\n");
     544                        while (p_col < return_col - p_SyntaxIndent)
     545                            _insert_text(' ');
     546                        _insert_text('}');
     547                    }
     548
     549                    _restore_pos2(valuepos);
     550                    _save_pos2(valuepos);
    500551                    prev_word();
    501                 if (p_line == newexitline - 1 && substr(cur_word(iIgnorePos), 1, 8) == 'KLOGEXIT')
    502                     delete_line();
     552                    p_col -= p_SyntaxIndent;
     553                    codecol = p_col;
     554                    _insert_text("{\n");
     555                    while (p_col < codecol)
     556                        _insert_text(' ');
     557                }
     558
    503559                _restore_pos2(valuepos);
    504560            }
    505561        }
    506562        else
    507             message("odin32_getparams failed, sType=" sType);
     563            message("odin32_getreturntype failed, sType=" sType);
    508564        return;
    509565    }
     
    597653         * Select procedure.
    598654         */
    599         while (!search("return", "WE<+") && odin32_getfunction() == sCurFunction)
     655        while (   !odin32_searchcode("return", "WE<+")
     656               &&  odin32_getfunction() == sCurFunction)
    600657        {
    601658            //say 'exit sub loop: ' p_line
     
    631688        if (!fUserCancel && sType && (sType == 'void' || sType == 'VOID'))
    632689        {
    633             if (    !search("{", "E+")
     690            if (    !odin32_searchcode("{", "E+")
    634691                &&  !find_matching_paren())
    635692            {
     
    667724
    668725
    669 
    670726/**
    671727 * Moves cursor to nearest function start.
     
    678734    _save_pos2(org_pos);
    679735
     736    if (!next_proc(1))
     737    {
     738        next_line = p_line;
     739        if (!prev_proc(1) && p_line == cur_line)
     740        {
     741            _restore_pos2(org_pos);
     742            return 0;
     743        }
     744        _restore_pos2(org_pos);
     745        _save_pos2(org_pos);
     746    }
     747    else
     748        p_col++;                        /* fixes problem with single function files. */
     749
    680750    if (!prev_proc(1))
    681751    {
     
    690760    }
    691761
    692     if (!next_proc(1))
    693     {
    694         next_line = p_line;
    695         if (!prev_proc(1) && p_line == cur_line)
    696         {
    697             _restore_pos2(org_pos);
    698             return 0;
    699         }
    700         _restore_pos2(org_pos);
    701         _save_pos2(org_pos);
    702     }
    703762
    704763    if (prev_line != -1 && (next_line == -1 || cur_line - prev_line <= next_line - cur_line))
     
    714773    }
    715774
     775    _restore_pos2(org_pos);
    716776    return -1;
    717777}
     
    731791        proc_line = p_line;
    732792
    733         if (!search("{", "E+"))
     793        if (!odin32_searchcode("{"))
    734794        {
    735795            prev_proc();
     
    752812static _str odin32_getfunction()
    753813{
    754     return current_proc();
     814    sFunctionName = current_proc();
     815    if (!sFunctionName)
     816        sFunctionName == "";
     817    //say 'functionanme='sFunctionName;
     818    return sFunctionName;
    755819}
    756820
     
    768832     */
    769833    if (    !odin32_func_goto_nearest()
    770         &&  !search("(")               /* makes some assumptions. */
     834        &&  !odin32_searchcode("(")               /* makes some assumptions. */
    771835        )
    772836    {
     
    889953    if (iParam == iCurParam)
    890954    {   /* (yeah, we did!) */
    891         sArg = strip(substr(sParams, iStartParam, i - 1));
     955        sArg = strip(substr(sParams, iStartParam, i - iStartParam));
    892956
    893957        /* lazy approach, which doens't support function types */
     
    9701034        offStart = _QROffset();
    9711035
    972         if (!search("("))               /* makes some assumptions. */
     1036        if (!odin32_searchcode("("))               /* makes some assumptions. */
    9731037        {
    9741038            prev_word();
    9751039            offEnd = _QROffset();
    9761040            _restore_pos2(posStart);
    977             _str sTypeRaw = strip(get_text(offEnd - offStart - 1));
    978 
     1041            _str sTypeRaw = strip(get_text(offEnd - offStart));
     1042
     1043            //say 'sTypeRaw='sTypeRaw;
    9791044            /*
    9801045             * Remove static, inline, _Optlink, stdcall, EXPENTRY etc.
     
    10051070                sTypeRaw = stranslate(sTypeRaw, "", "WIN32API", "I");
    10061071                sTypeRaw = stranslate(sTypeRaw, "", "WINAPI", "I");
     1072                sTypeRaw = stranslate(sTypeRaw, "", "__operator__", "I"); /* operator fix */
     1073                sTypeRaw = stranslate(sTypeRaw, "", "__operator", "I");   /* operator fix */
     1074                sTypeRaw = stranslate(sTypeRaw, "", "operator__", "I");   /* operator fix */
     1075                sTypeRaw = stranslate(sTypeRaw, "", "operator", "I");     /* operator fix */
    10071076            }
    10081077
     
    10631132    return false;
    10641133}
     1134
     1135
     1136/**
     1137 * Search for some piece of code.
     1138 */
     1139static int odin32_searchcode(_str sSearchString, _str sOptions = "E+")
     1140{
     1141    int rc;
     1142    rc = search(sSearchString, sOptions);
     1143    while (!rc && !odin32_in_code())
     1144    {
     1145        p_col++;
     1146        rc = search(sSearchString, sOptions);
     1147    }
     1148    return rc;
     1149}
     1150
     1151
     1152/**
     1153 * Checks if cursor is in code or in comment.
     1154 */
     1155static boolean odin32_in_code()
     1156{
     1157    _save_pos2(searchsave);
     1158    boolean fRc = !_in_comment();
     1159    _restore_pos2(searchsave);
     1160    return fRc;
     1161}
     1162
     1163
     1164/*
     1165 * Gets the next piece of code.
     1166 */
     1167static _str odin32_get_next_code_text()
     1168{
     1169    _str ch;
     1170    _save_pos2(searchsave);
     1171    ch = odin32_get_next_code_text2();
     1172    _restore_pos2(searchsave);
     1173    return ch;
     1174}
     1175
     1176
     1177/**
     1178 * Checks if there is more code on the line.
     1179 */
     1180static boolean odin32_more_code_on_line()
     1181{
     1182    boolean fRc;
     1183    int     curline = p_line;
     1184
     1185    _save_pos2(searchsave);
     1186    odin32_get_next_code_text2();
     1187    fRc = curline == p_line;
     1188    _restore_pos2(searchsave);
     1189
     1190    return fRc;
     1191}
     1192
     1193
     1194/**
     1195 * Gets the next piece of code.
     1196 * Doesn't preserver cursor position.
     1197 */
     1198static _str odin32_get_next_code_text2()
     1199{
     1200    _str ch;
     1201    do
     1202    {
     1203        curcol = ++p_col;
     1204        end_line()
     1205        if (p_col <= curcol)
     1206        {
     1207            p_line++;
     1208            p_col = 1;
     1209        }
     1210        else
     1211            p_col = curcol;
     1212
     1213        ch = get_text();
     1214        //say ch ' ('_asc(ch)')';
     1215        while (ch == "#")                  /* preprocessor stuff */
     1216        {
     1217            p_col = 1;
     1218            p_line++;
     1219            ch = get_text();
     1220            //say ch ' ('_asc(ch)')';
     1221            continue;
     1222        }
     1223    } while (ch :== ' ' || ch :== "\t" || ch :== "\n" || ch :== "\r" || !odin32_in_code());
     1224
     1225    return ch;
     1226}
     1227
Note: See TracChangeset for help on using the changeset viewer.