source: trunk/tools/vslick/odin32.e@ 7154

Last change on this file since 7154 was 7150, checked in by bird, 24 years ago

Fixing kLog features...

File size: 27.0 KB
Line 
1/* $Id: odin32.e,v 1.8 2001-10-22 04:11:08 bird Exp $
2 *
3 * Visual SlickEdit Documentation Macros.
4 *
5 * Copyright (c) 1999-2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
6 *
7 * Project Odin Software License can be found in LICENSE.TXT
8 *
9 ****
10 *
11 * This define the following keys:
12 *---------------------------------
13 * Ctrl+Shift+C: Class description box.
14 * Ctrl+Shift+F: Function/method description box.
15 * Ctrl+Shift+M: Module(file) description box
16 * Ctrl+Shift+O: One-liner (comment)
17 *
18 * Ctrl+Shift+G: Global box
19 * Ctrl+Shift+H: Header box
20 * Ctrl+Shift+I: Internal function box
21 * Ctrl+Shift+K: Const/macro box
22 * Ctrl+Shift+S: Struct/Typedef box
23 *
24 * Ctrl+Shift+T:
25 *
26 * Ctrl+Shift+B: KLOGENTRYX(..)
27 * Ctrl+Shift+E: KLOGEXIT(..)
28 * Ctrl+Shift+N: Do kLog stuff for the current file. No questions.
29 * Ctrl+Shift+Q: Do kLog stuff for the current file. Ask a lot of questions.
30 *
31 * Remember to set the correct sOdin32UserName, sOdin32UserEmail and sOdin32UserInitials
32 * before compiling and loading the macros into Visual SlickEdit.
33 *
34 * These macros are compatible with both 3.0(c) and 4.0(b).
35 *
36 */
37defeventtab default_keys
38def 'C-S-A' = odin32_signature
39def 'C-S-B' = odin32_klogentry
40def 'C-S-C' = odin32_classbox
41def 'C-S-E' = odin32_klogexit
42def 'C-S-F' = odin32_funcbox
43def 'C-S-G' = odin32_globalbox
44def 'C-S-H' = odin32_headerbox
45def 'C-S-I' = odin32_intfuncbox
46def 'C-S-K' = odin32_constbox
47def 'C-S-M' = odin32_modulebox
48def 'C-S-N' = odin32_klog_file_no_ask
49def 'C-S-O' = odin32_oneliner
50def 'C-S-Q' = odin32_klog_file_ask
51def 'C-S-S' = odin32_structbox
52def 'C-S-T' = odin32_maketagfile
53
54
55//MARKER. Editor searches for this line!
56#pragma option(redeclvars, on)
57#include 'slick.sh'
58
59/* Remeber to change these! */
60static _str sOdin32UserInitials = "kso";
61static _str sOdin32UserName = "knut st. osmundsen";
62static _str sOdin32UserEmail = "knut.stange.osmundsen@mynd.no";
63
64
65
66/**
67 * Insers a date string. The date is in ISO format.
68 */
69void odin32_date()
70{
71 int i,j;
72 _str date;
73
74 date = _date('U');
75 i = pos("/", date);
76 j = pos("/", date, i+1);
77 month = substr(date, 1, i-1);
78 if (length(month) == 1) month = '0'month;
79 day = substr(date, i+1, j-i-1);
80 if (length(day) == 1) day = '0'day;
81 year = substr(date, j+1);
82 _insert_text(nls("%s-%s-%s", year, month, day));
83}
84
85
86/**
87 * Get the current year.
88 * @returns Current year string.
89 */
90_str odin32_year()
91{
92 date = _date('U');
93 return substr(date, pos("/",date, pos("/",date)+1)+1, 4);
94}
95
96
97/**
98 * Inserts the first line in a box.
99 * @param sTag Not used - box tag.
100 */
101static void odin32_firstline(sTag)
102{
103 begin_line();
104 if (file_eq(p_extension, 'asm'))
105 _insert_text(";\n");
106 else
107 {
108 _insert_text("/");
109 for (i = 0; i < 80-1; i++)
110 _insert_text("*");
111 _insert_text("\n");
112 }
113}
114
115/**
116 * Inserts a line with a '*' in both ends and some text (a) inside.
117 * @param a text.
118 */
119void odin32_starlinestr(a)
120{
121 if (file_eq(p_extension, 'asm'))
122 {
123 _insert_text("; ");
124 _insert_text(a);
125 _insert_text("\n");
126 }
127 else
128 {
129 _insert_text("* ");
130 _insert_text(a);
131 for (i = 0; i < 80-3-length(a); i++)
132 _insert_text(" ");
133 _insert_text("*\n");
134 }
135}
136
137
138/**
139 * Empty line with a '*' in both ends.
140 */
141void odin32_starline()
142{
143 odin32_starlinestr("");
144}
145
146
147/**
148 * Inserts the last line in a box.
149 */
150void odin32_lastline()
151{
152 if (file_eq(p_extension, 'asm'))
153 _insert_text(";\n");
154 else
155 {
156 for (i = 0; i < 80-1; i++)
157 _insert_text("*");
158 _insert_text("/\n");
159 }
160}
161
162
163
164/**
165 * Inserts a signature. Form: "//Initials ISO-date:"
166 * @remark defeventtab
167 */
168void odin32_signature()
169{
170 if (file_eq(p_extension, 'asm'))
171 _insert_text(";"sOdin32UserInitials" ");
172 else
173 _insert_text("//"sOdin32UserInitials" ");
174
175 odin32_date()
176 _insert_text(":");
177}
178
179
180/**
181 * SDS - Classbox(/header).
182 * @remark defeventtab
183 */
184void odin32_classbox()
185{
186 _begin_line();
187 _insert_text("/**\n");
188 _insert_text(" * \n");
189 _insert_text(" * @shortdesc \n");
190 _insert_text(" * @dstruct \n");
191 _insert_text(" * @version \n");
192 _insert_text(" * @verdesc \n");
193 _insert_text(" * @author " sOdin32UserName " (" sOdin32UserEmail ")\n");
194 _insert_text(" * @approval \n");
195 _insert_text(" */\n");
196
197 up(8);
198 p_col += 3;
199}
200
201
202/**
203 * SDS - functionbox(/header).
204 * @remark defeventtab
205 */
206void odin32_funcbox()
207{
208 _begin_line();
209 if (file_eq(p_extension, 'asm'))
210 {
211 _insert_text(";;\n");
212 _insert_text("; \n");
213 _insert_text("; @cproto \n");
214 _insert_text("; @returns \n");
215 _insert_text("; @param \n");
216 _insert_text("; @uses \n");
217 _insert_text("; @equiv \n");
218 _insert_text("; @time \n");
219 _insert_text("; @sketch \n");
220 _insert_text("; @status \n");
221 _insert_text("; @author "sOdin32UserName" (" sOdin32UserEmail ")\n");
222 _insert_text("; @remark \n");
223 up(11);
224 p_col = 3;
225 }
226 else
227 {
228 _insert_text("/**\n");
229 _insert_text(" * \n");
230 _insert_text(" * @returns \n");
231 _insert_text(" * @param \n");
232 _insert_text(" * @equiv \n");
233 _insert_text(" * @time \n");
234 _insert_text(" * @sketch \n");
235 _insert_text(" * @status \n");
236 _insert_text(" * @author "sOdin32UserName" (" sOdin32UserEmail ")\n");
237 _insert_text(" * @remark \n");
238 _insert_text(" */\n");
239 up(10);
240 p_col = 4;
241 }
242}
243
244
245/**
246 *
247 * @remark defeventtab
248 */
249void odin32_globalbox()
250{
251 odin32_firstline("Global");
252 odin32_starlinestr(" Global Variables");
253 odin32_lastline();
254}
255
256
257void odin32_headerbox()
258{
259 odin32_firstline("Header");
260 odin32_starlinestr(" Header Files");
261 odin32_lastline();
262}
263
264
265void odin32_intfuncbox()
266{
267 odin32_firstline("IntFunc");
268 odin32_starlinestr(" Internal Functions");
269 odin32_lastline();
270}
271
272
273void odin32_constbox()
274{
275 odin32_firstline("Const");
276 odin32_starlinestr(" Defined Constants And Macros");
277 odin32_lastline();
278}
279
280
281void odin32_oneliner()
282{
283 end_line();
284 do
285 {
286 _insert_text(" ");
287 } while (p_col < 41);
288
289 if (file_eq(p_extension, 'asm'))
290 {
291 _insert_text("; ");
292 }
293 else
294 {
295 _insert_text("/* */");
296 p_col = p_col - 3;
297 }
298}
299
300
301void odin32_structbox()
302{
303 odin32_firstline("Struct");
304 odin32_starlinestr(" Structures and Typedefs");
305 odin32_lastline();
306}
307
308
309void odin32_modulebox()
310{
311 _begin_line();
312 if (file_eq(p_extension, 'asm'))
313 {
314 _insert_text("; $Id: odin32.e,v 1.8 2001-10-22 04:11:08 bird Exp $\n");
315 _insert_text("; \n");
316 _insert_text("; \n");
317 _insert_text("; \n");
318 _insert_text("; Copyright (c) " odin32_year() " "sOdin32UserName" (" sOdin32UserEmail ")\n");
319 _insert_text("; \n");
320 _insert_text("; Project Odin Software License can be found in LICENSE.TXT\n");
321 _insert_text("; \n");
322 up(6);
323 p_col = 3;
324 }
325 else
326 {
327 _insert_text("/* $Id: odin32.e,v 1.8 2001-10-22 04:11:08 bird Exp $\n");
328 _insert_text(" * \n");
329 _insert_text(" * \n");
330 _insert_text(" * \n");
331 _insert_text(" * Copyright (c) " odin32_year() " "sOdin32UserName" (" sOdin32UserEmail ")\n");
332 _insert_text(" *\n");
333 _insert_text(" * Project Odin Software License can be found in LICENSE.TXT\n");
334 _insert_text(" *\n");
335 _insert_text(" */\n");
336 up(7);
337 p_col = 4;
338 }
339}
340
341
342_command void odin32_maketagfile()
343{
344 /* We'll */
345 if (file_match('-p 'maybe_quote_filename(strip_filename(_project_name,'e'):+TAG_FILE_EXT),1)=="")
346 _project_update_files_retag(true,false,false,true);
347 else
348 _project_update_files_retag(false,false,false,false);
349}
350
351_command void odin32_setcurrentdir()
352{
353 //_ini_get_value(_project_name,"COMPILER","WORKINGDIR", workingdir);
354 //cd(workingdir);
355 /* Go the the directory containing the project filename */
356 cd(strip_filename(_project_name, 'NE'));
357}
358
359
360/**
361 * Hot-Key: Inserts a KLOGENTRY statement at start of nearest function.
362 */
363void odin32_klogentry()
364{
365 _save_pos2(org_pos);
366
367 /*
368 * Go to nearest function.
369 */
370 if (!odin32_func_goto_nearest())
371 {
372 /*
373 * Get parameters.
374 */
375 _str sParams = odin32_getparams();
376 if (sParams)
377 {
378 /*
379 * Insert text.
380 */
381 if (!search("{"))
382 {
383 p_col++;
384 cArgs = odin32_countparams(sParams);
385 if (cArgs > 0)
386 {
387 sArgs = "";
388 for (i = 0; i < cArgs; i++)
389 {
390 _str sType, sName, sDefault
391 if (!odin32_enumparams(sParams, i, sType, sName, sDefault))
392 sArgs = sArgs', 'sName;
393 }
394
395 _insert_text("\n KLOGENTRY"cArgs"(\""sParams"\""sArgs");"); /* todo tab size.. or smart indent */
396 }
397 else
398 _insert_text("\n KLOGENTRY0();"); /* todo tab size.. or smart indent */
399
400 /*
401 * Check if the next word is KLOGENTRY.
402 */
403 next_word();
404 if (def_next_word_style == 'E')
405 prev_word();
406 if (substr(cur_word(iIgnorePos), 1, 9) == "KLOGENTRY")
407 delete_line();
408
409 }
410 else
411 message("didn't find {");
412 }
413 else
414 message("odin32_getparams failed, sParams=" sParams);
415 return;
416 }
417
418 _restore_pos2(org_pos);
419}
420
421
422/**
423 * Hot-Key: Inserts a KLOGEXIT statement at cursor location.
424 */
425void odin32_klogexit()
426{
427 _save_pos2(org_pos);
428
429 /*
430 * Go to nearest function.
431 */
432 if (!prev_proc())
433 {
434 /*
435 * Get parameters.
436 */
437 _str sType = odin32_getreturntype(true);
438 _restore_pos2(org_pos);
439 if (sType)
440 {
441 /*
442 * Insert text.
443 */
444 cur_col = p_col;
445 if (sType == 'void' || sType == 'VOID')
446 {
447 while (p_col <= p_SyntaxIndent)
448 keyin(" ");
449 _insert_text("KLOGEXITVOID();");
450 }
451 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");
462 for (i = 1; i < cur_col; i++)
463 _insert_text(" ");
464 search(")","E-");
465
466 /*
467 * Check if it's a simple return statement.
468 */
469 _save_pos2(valuepos);
470 next_word();
471 if (def_next_word_style == 'E')
472 prev_word();
473 if (cur_word(iIgnorePos) == 'return')
474 {
475 p_col += length('return');
476 _save_pos2(posStart);
477 offStart = _QROffset();
478 if (!search(";", "E+"))
479 {
480 offEnd = _QROffset();
481 _restore_pos2(posStart);
482 _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));
485 _restore_pos2(valuepos);
486 _save_pos2(valuepos);
487 _insert_text(sValue);
488 }
489 }
490 _restore_pos2(valuepos);
491
492 /*
493 * Remove old KLOGEXIT statement on previous line if any.
494 */
495 _save_pos2(valuepos);
496 newexitline = p_line;
497 p_line--; p_col = 1;
498 next_word();
499 if (def_next_word_style == 'E')
500 prev_word();
501 if (p_line == newexitline - 1 && substr(cur_word(iIgnorePos), 1, 8) == 'KLOGEXIT')
502 delete_line();
503 _restore_pos2(valuepos);
504 }
505 }
506 else
507 message("odin32_getparams failed, sType=" sType);
508 return;
509 }
510
511 _restore_pos2(org_pos);
512}
513
514
515/**
516 * Processes a file - ask user all the time.
517 */
518void odin32_klog_file_ask()
519{
520 odin32_klog_file_int(true)
521}
522
523
524/**
525 * Processes a file - no questions.
526 */
527void odin32_klog_file_no_ask()
528{
529 odin32_klog_file_int(false)
530}
531
532
533
534/**
535 * Processes a file.
536 */
537static void odin32_klog_file_int(boolean fAsk)
538{
539 show_all();
540 bottom();
541 _refresh_scroll();
542
543 /* ask question so we can get to the right position somehow.. */
544 if (fAsk && _message_box("kLog process this file?", "Visual SlickEdit", MB_YESNO | MB_ICONQUESTION) != IDYES)
545 return;
546
547 /*
548 * Entries.
549 */
550 while (!prev_proc())
551 {
552 //say 'entry main loop: ' odin32_getfunction();
553
554 /*
555 * Skip prototypes.
556 */
557 if (odin32_prototype())
558 continue;
559
560 /*
561 * Ask user.
562 */
563 center_line();
564 _refresh_scroll();
565 sFunction = odin32_getfunction();
566 rc = fAsk ? _message_box("Process this function ("sFunction")?", "Visual SlickEdit", MB_YESNOCANCEL | MB_ICONQUESTION) : IDYES;
567 if (rc == IDYES)
568 {
569 _save_pos2(procpos);
570 odin32_klogentry();
571 _restore_pos2(procpos);
572 }
573 else if (rc == IDNO)
574 continue;
575 else
576 break;
577 }
578
579 /*
580 * Exits.
581 */
582 bottom(); _refresh_scroll();
583 boolean fUserCancel = false;
584 while (!prev_proc() && !fUserCancel)
585 {
586 _save_pos2(procpos);
587 sCurFunction = odin32_getfunction();
588 //say 'exit main loop: ' sCurFunction
589
590 /*
591 * Skip prototypes.
592 */
593 if (odin32_prototype())
594 continue;
595
596 /*
597 * Select procedure.
598 */
599 while (!search("return", "WE<+") && odin32_getfunction() == sCurFunction)
600 {
601 //say 'exit sub loop: ' p_line
602 /*
603 * Ask User.
604 */
605 center_line();
606 _refresh_scroll();
607 sFunction = odin32_getfunction();
608 rc = fAsk ? _message_box("Process this exit from "sFunction"?", "Visual SlickEdit", MB_YESNOCANCEL | MB_ICONQUESTION) : IDYES;
609 deselect();
610 if (rc == IDYES)
611 {
612 _save_pos2(returnpos);
613 odin32_klogexit();
614 _restore_pos2(returnpos);
615 p_line++;
616 }
617 else if (rc != IDNO)
618 {
619 fUserCancel = true;
620 break;
621 }
622 p_line++; /* just so we won't hit it again. */
623 }
624
625 /*
626 * If void function we'll have to check if there is and return; prior to the ending '}'.
627 */
628 _restore_pos2(procpos);
629 _save_pos2(procpos);
630 sType = odin32_getreturntype(true);
631 if (!fUserCancel && sType && (sType == 'void' || sType == 'VOID'))
632 {
633 if ( !search("{", "E+")
634 && !find_matching_paren())
635 {
636 _save_pos2(funcend);
637 prev_word();
638 if (cur_word(iIgnorePos) != "return")
639 {
640 /*
641 * Ask User.
642 */
643 _restore_pos2(funcend);
644 center_line();
645 _refresh_scroll();
646 sFunction = odin32_getfunction();
647 rc = fAsk ? _message_box("Process this exit from "sFunction"?", "Visual SlickEdit", MB_YESNOCANCEL | MB_ICONQUESTION) : IDYES;
648 deselect();
649 if (rc == IDYES)
650 {
651 _save_pos2(returnpos);
652 odin32_klogexit();
653 _restore_pos2(returnpos);
654 }
655 }
656 }
657 }
658
659 /*
660 * Next proc.
661 */
662 _restore_pos2(procpos);
663 }
664
665
666}
667
668
669
670/**
671 * Moves cursor to nearest function start.
672 */
673int odin32_func_goto_nearest()
674{
675 cur_line = p_line;
676 prev_line = -1;
677 next_line = -1;
678 _save_pos2(org_pos);
679
680 if (!prev_proc(1))
681 {
682 prev_line = p_line;
683 if (!next_proc(1) && p_line == cur_line)
684 {
685 _restore_pos2(org_pos);
686 return 0;
687 }
688 _restore_pos2(org_pos);
689 _save_pos2(org_pos);
690 }
691
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 }
703
704 if (prev_line != -1 && (next_line == -1 || cur_line - prev_line <= next_line - cur_line))
705 {
706 prev_proc(1);
707 return 0;
708 }
709
710 if (next_line != -1 && (prev_line == -1 || cur_line - prev_line > next_line - cur_line))
711 {
712 next_proc();
713 return 0;
714 }
715
716 return -1;
717}
718
719
720/**
721 * Check if nearest function is a prototype.
722 */
723boolean odin32_prototype()
724{
725 /*
726 * Check if this is a real function implementation.
727 */
728 _save_pos2(procpos);
729 if (!odin32_func_goto_nearest())
730 {
731 proc_line = p_line;
732
733 if (!search("{", "E+"))
734 {
735 prev_proc();
736 if (p_line != proc_line)
737 {
738 _restore_pos2(procpos);
739 return true;
740 }
741 }
742 }
743 _restore_pos2(procpos);
744
745 return false;
746}
747
748
749/**
750 * Gets the name fo the current function.
751 */
752static _str odin32_getfunction()
753{
754 return current_proc();
755}
756
757
758/**
759 * Goes to the neares function and gets its parameters.
760 * @remark Should be reimplemented to use tags (if someone can figure out how to query that stuff).
761 */
762static _str odin32_getparams()
763{
764 _save_pos2(org_pos);
765
766 /*
767 * Go to nearest function.
768 */
769 if ( !odin32_func_goto_nearest()
770 && !search("(") /* makes some assumptions. */
771 )
772 {
773 /*
774 * Get parameters.
775 */
776 _save_pos2(posStart);
777 offStart = _QROffset();
778 if (!find_matching_paren())
779 {
780 offEnd = _QROffset();
781 _restore_pos2(posStart);
782 p_col++;
783 _str sParamsRaw = strip(get_text(offEnd - offStart - 1));
784
785
786 /*
787 * Remove new lines and double spaces within params.
788 */
789 _str sParams = "";
790
791 int i;
792 for (i = 1, chPrev = ' '; i <= length(sParamsRaw); i++)
793 {
794 ch = substr(sParamsRaw, i, 1);
795
796 /*
797 * Do fixups.
798 */
799 if (ch == " " && chPrev == " ")
800 continue;
801
802 if ((ch :== "\n") || (ch :== "\r") || (ch :== "\t"))
803 {
804 if (chPrev == ' ')
805 continue;
806 ch = ' ';
807 }
808
809 if (ch == ',' && chPrev == ' ')
810 {
811 sParams = substr(sParams, 1, length(sParams) - 1);
812 }
813
814 if (ch == '*')
815 {
816 if (chPrev != ' ')
817 sParams = sParams :+ ' * ';
818 else
819 sParams = sParams :+ '* ';
820 chPrev = ' ';
821 }
822 else
823 {
824 sParams = sParams :+ ch;
825 chPrev = ch;
826 }
827
828 } /* for */
829
830 sParams = strip(sParams);
831 if (sParams == 'void' || sParams == 'VOID')
832 sParams = "";
833 _restore_pos2(org_pos);
834 return sParams;
835 }
836 else
837 message("find_matchin_paren failed");
838 }
839
840 _restore_pos2(org_pos);
841 return false;
842}
843
844
845
846/**
847 * Enumerates the parameters to the function.
848 * @param sParams Parameter string from odin32_getparams.
849 * @param iParam The index (0-based) of the parameter to get.
850 * @param sType Type. (output)
851 * @param sName Name. (output)
852 * @param sDefault Default value. (output)
853 * @remark Doesn't perhaps handle function pointers very well (I think)?
854 * @remark Should be reimplemented to use tags (if someone can figure out how to query that stuff).
855 */
856static int odin32_enumparams(_str sParams, int iParam, _str &sType, _str &sName, _str &sDefault)
857{
858 int i;
859 int iParLevel;
860 int iCurParam;
861 int iStartParam;
862
863 sType = sName = sDefault = "";
864
865 /* no use working on empty string! */
866 if (length(sParams) == 0)
867 return -1;
868
869 /* find the parameter in question */
870 for (iStartParam = i = 1, iParLevel = iCurParam = 0; i <= length(sParams); i++)
871 {
872 _str ch = substr(sParams, i, 1);
873 if (ch == ',' && iParLevel == 0)
874 {
875 /* is it this parameter ? */
876 if (iParam == iCurParam)
877 break;
878
879 iCurParam++;
880 iStartParam = i + 1;
881 }
882 else if (ch == '(')
883 iParLevel++;
884 else if (ch == ')')
885 iParLevel--;
886 }
887
888 /* did we find the parameter? */
889 if (iParam == iCurParam)
890 { /* (yeah, we did!) */
891 sArg = strip(substr(sParams, iStartParam, i - 1));
892
893 /* lazy approach, which doens't support function types */
894
895 if (pos('=', sParams) > 0) /* default */
896 {
897 sDefault = strip(substr(sParams, pos('=', sParams) + 1));
898 sArg = strip(substr(sArg, 1, pos('=', sParams) - 1));
899 }
900
901 for (i = length(sArg); i > 1; i--)
902 {
903 _str ch = substr(sArg, i, 1);
904 if ( !(ch >= 'a' && ch <= 'z')
905 && !(ch >= 'A' && ch <= 'Z')
906 && !(ch >= '0' && ch <= '9')
907 && ch != '_' && ch != '$')
908 break;
909 }
910 sName = strip(substr(sArg, i + 1));
911 sType = strip(substr(sArg, 1, i));
912
913 return 0;
914 }
915
916 return -1;
917}
918
919
920/**
921 * Counts the parameters to the function.
922 * @param sParams Parameter string from odin32_getparams.
923 * @remark Should be reimplemented to use tags (if someone can figure out how to query that stuff).
924 */
925static int odin32_countparams(_str sParams)
926{
927 int i;
928 int iParLevel;
929 int iCurParam;
930
931 sType = sName = sDefault = "";
932
933 /* check for 0 parameters */
934 if (length(sParams) == 0)
935 return 0;
936
937 /* find the parameter in question */
938 for (i = 1, iParLevel = iCurParam = 0; i <= length(sParams); i++)
939 {
940 _str ch = substr(sParams, i, 1);
941 if (ch == ',' && iParLevel == 0)
942 {
943 iCurParam++;
944 }
945 else if (ch == '(')
946 iParLevel++;
947 else if (ch == ')')
948 iParLevel--;
949 }
950
951 return iCurParam + 1;
952}
953
954/**
955 * Gets the return type.
956 */
957static _str odin32_getreturntype(boolean fPureType = false)
958{
959 _save_pos2(org_pos);
960
961 /*
962 * Go to nearest function.
963 */
964 if (!odin32_func_goto_nearest())
965 {
966 /*
967 * Return type is from function start to function name...
968 */
969 _save_pos2(posStart);
970 offStart = _QROffset();
971
972 if (!search("(")) /* makes some assumptions. */
973 {
974 prev_word();
975 offEnd = _QROffset();
976 _restore_pos2(posStart);
977 _str sTypeRaw = strip(get_text(offEnd - offStart - 1));
978
979 /*
980 * Remove static, inline, _Optlink, stdcall, EXPENTRY etc.
981 */
982 if (fPureType)
983 {
984 sTypeRaw = stranslate(sTypeRaw, "", "__static__", "I");
985 sTypeRaw = stranslate(sTypeRaw, "", "__static", "I");
986 sTypeRaw = stranslate(sTypeRaw, "", "static__", "I");
987 sTypeRaw = stranslate(sTypeRaw, "", "static", "I");
988 sTypeRaw = stranslate(sTypeRaw, "", "__inline__", "I");
989 sTypeRaw = stranslate(sTypeRaw, "", "__inline", "I");
990 sTypeRaw = stranslate(sTypeRaw, "", "inline__", "I");
991 sTypeRaw = stranslate(sTypeRaw, "", "inline", "I");
992 sTypeRaw = stranslate(sTypeRaw, "", "EXPENTRY", "I");
993 sTypeRaw = stranslate(sTypeRaw, "", "_Optlink", "I");
994 sTypeRaw = stranslate(sTypeRaw, "", "__stdcall", "I");
995 sTypeRaw = stranslate(sTypeRaw, "", "__cdecl", "I");
996 sTypeRaw = stranslate(sTypeRaw, "", "_cdecl", "I");
997 sTypeRaw = stranslate(sTypeRaw, "", "cdecl", "I");
998 sTypeRaw = stranslate(sTypeRaw, "", "PASCAL", "I");
999 sTypeRaw = stranslate(sTypeRaw, "", "__far", "I");
1000 sTypeRaw = stranslate(sTypeRaw, "", "_far", "I");
1001 sTypeRaw = stranslate(sTypeRaw, "", "far", "I");
1002 sTypeRaw = stranslate(sTypeRaw, "", "__near", "I");
1003 sTypeRaw = stranslate(sTypeRaw, "", "_near", "I");
1004 sTypeRaw = stranslate(sTypeRaw, "", "near", "I");
1005 sTypeRaw = stranslate(sTypeRaw, "", "WIN32API", "I");
1006 sTypeRaw = stranslate(sTypeRaw, "", "WINAPI", "I");
1007 }
1008
1009 /*
1010 * Remove new lines and double spaces within params.
1011 */
1012 _str sType = "";
1013
1014 int i;
1015 for (i = 1, chPrev = ' '; i <= length(sTypeRaw); i++)
1016 {
1017 ch = substr(sTypeRaw, i, 1);
1018
1019 /*
1020 * Do fixups.
1021 */
1022 if (ch == " " && chPrev == " ")
1023 continue;
1024
1025 if ((ch :== "\n") || (ch :== "\r") || (ch :== "\t"))
1026 {
1027 if (chPrev == ' ')
1028 continue;
1029 ch = ' ';
1030 }
1031
1032 if (ch == ',' && chPrev == ' ')
1033 {
1034 sType = substr(sType, 1, length(sType) - 1);
1035 }
1036
1037 if (ch == '*')
1038 {
1039 if (chPrev != ' ')
1040 sType = sType :+ ' * ';
1041 else
1042 sType = sType :+ '* ';
1043 chPrev = ' ';
1044 }
1045 else
1046 {
1047 sType = sType :+ ch;
1048 chPrev = ch;
1049 }
1050
1051 } /* for */
1052
1053 sType = strip(sType);
1054
1055 _restore_pos2(org_pos);
1056 return sType;
1057 }
1058 else
1059 message('odin32_getreturntype: can''t find ''(''.');
1060 }
1061
1062 _restore_pos2(org_pos);
1063 return false;
1064}
Note: See TracBrowser for help on using the repository browser.