VirtualBox

source: kBuild/trunk/VSlickMacros/kdev.e@ 2701

Last change on this file since 2701 was 2701, checked in by bird, 11 years ago

kdev.e: Changed the utf-8 bom hack.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 109.9 KB
Line 
1/* $Id: kdev.e 2701 2013-11-06 19:58:56Z bird $ -*- tab-width: 4 c-indent-level: 4 -*- */
2/** @file
3 * Visual SlickEdit Documentation Macros.
4 */
5
6/*
7 * Copyright (c) 1999-2010 knut st. osmundsen <[email protected]>
8 *
9 * This file is part of kBuild.
10 *
11 * kBuild is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * kBuild is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with kBuild. If not, see <http://www.gnu.org/licenses/>
23 *
24 */
25
26/***
27 *
28 * This define the following keys:
29 *---------------------------------
30 * Ctrl+Shift+C: Class description box.
31 * Ctrl+Shift+F: Function/method description box.
32 * Ctrl+Shift+M: Module(file) description box
33 * Ctrl+Shift+O: One-liner (comment)
34 *
35 * Ctrl+Shift+G: Global box
36 * Ctrl+Shift+H: Header box
37 * Ctrl+Shift+E: Exported Symbols
38 * Ctrl+Shift+I: Internal function box
39 * Ctrl+Shift+K: Const/macro box
40 * Ctrl+Shift+S: Struct/Typedef box
41 *
42 * Ctrl+Shift+A: Signature+Date marker
43 * Ctrl+Shift+P: Mark line as change by me
44 *
45 * Ctrl+Shift+T: Update project tagfile.
46 * Ctrl+Shift+L: Load document variables.
47 *
48 * Ctrl+Shift+B: KLOGENTRYX(..)
49 * Ctrl+Shift+E: KLOGEXIT(..)
50 * Ctrl+Shift+N: Do kLog stuff for the current file. No questions.
51 * Ctrl+Shift+Q: Do kLog stuff for the current file. Ask a lot of questions.
52 *
53 * Remember to set the correct sOdin32UserName, sOdin32UserEmail and sOdin32UserInitials
54 * before compiling and loading the macros into Visual SlickEdit.
55 *
56 * These macros are compatible with both 3.0(c) and 4.0(b).
57 *
58 */
59defeventtab default_keys
60def 'C-S-A' = k_signature
61//def 'C-S-C' = k_javadoc_classbox
62def 'C-S-C' = k_calc
63def 'C-S-E' = k_box_exported
64def 'C-S-F' = k_javadoc_funcbox
65def 'C-S-G' = k_box_globals
66def 'C-S-H' = k_box_headers
67def 'C-S-I' = k_box_intfuncs
68def 'C-S-K' = k_box_consts
69def 'C-S-M' = k_javadoc_moduleheader
70def 'C-S-O' = k_oneliner
71def 'C-S-P' = k_mark_modified_line
72def 'C-S-S' = k_box_structs
73def 'C-S-T' = k_rebuild_tagfile
74def 'C-S-L' = k_style_load
75
76//optional stuff
77//def 'C-S-Q' = klib_klog_file_ask
78//def 'C-S-N' = klib_klog_file_no_ask
79//def 'C-S-1' = klib_klogentry
80//def 'C-S-3' = klib_klogexit
81
82
83//MARKER. Editor searches for this line!
84#pragma option(redeclvars, on)
85#include 'slick.sh'
86#ifndef VS_TAGDETAIL_context_args
87/* newer vslick version. */
88#include 'tagsdb.sh'
89//#pragma option(strict,on)
90/*#else: Version 4.0 (OS/2) */
91#endif
92
93#ifndef __MACOSX__
94 #define KDEV_WITH_MENU
95#endif
96
97/* Remeber to change these! */
98static _str skUserInitials = "bird";
99static _str skUserName = "knut st. osmundsen";
100static _str skUserEmail = "[email protected]";
101
102
103/*******************************************************************************
104* Global Variables *
105*******************************************************************************/
106static _str skCodeStyle = 'Opt2Ind4'; /* coding style scheme. */
107static _str skDocStyle = 'javadoc';/* options: javadoc, */
108static _str skLicense = 'GPLv3'; /* options: GPL, LGPL, Odin32, Confidential, ++ */
109static _str skCompany = ''; /* empty or company name for copyright */
110static _str skProgram = ''; /* Current program name - used by [L]GPL */
111static _str skChange = ''; /* Current change identifier. */
112
113static int ikStyleWidth = 80; /* The page width of the style. */
114static boolean fkStyleFullHeaders = false; /* false: omit some tags. */
115static int ikStyleOneliner = 41; /* The oneline comment column. */
116static int ikStyleModifyMarkColumn = 105;
117static boolean fkStyleBoxTag = false; /* true: Include tag in k_box_start. */
118
119/*******************************************************************************
120* Internal Functions *
121*******************************************************************************/
122/**
123 * Gets iso date.
124 * @returns ISO formatted date.
125 */
126static _str k_date()
127{
128 int i,j;
129 _str date;
130
131 date = _date('U');
132 i = pos("/", date);
133 j = pos("/", date, i+1);
134 _str month = substr(date, 1, i-1);
135 if (length(month) == 1) month = '0'month;
136 _str day = substr(date, i+1, j-i-1);
137 if (length(day) == 1) day = '0'day;
138 _str year = substr(date, j+1);
139 return year"-"month"-"day;
140}
141
142
143/**
144 * Get the current year.
145 * @returns Current year string.
146 */
147static _str k_year()
148{
149 _str date = _date('U');
150 return substr(date, pos("/",date, pos("/",date)+1)+1, 4);
151}
152
153
154/**
155 * Aligns a value up to a given alignment.
156 */
157static int k_alignup(int iValue, iAlign)
158{
159 if (iAlign <= 0)
160 {
161 message('k_alignup: iValue='iValue ' iAlign='iAlign);
162 iAlign = 4;
163 }
164 return ((iValue intdiv iAlign) + 1) * iAlign;
165}
166
167
168/**
169 * Reads the comment setup for this lexer/extension .
170 *
171 * @returns Success indicator.
172 * @param sLeft Left comment. (output)
173 * @param sRight Right comment. (output)
174 * @param iColumn Comment mark column. (1-based) (output)
175 * @param sExt The extension to lookup defaults to the current one.
176 * @param sLexer The lexer to lookup defaults to the current one.
177 * @remark This should be exported from box.e, but unfortunately it isn't.
178 */
179static boolean k_commentconfig(_str &sLeft, _str &sRight, int &iColumn, _str sExt = p_extension, _str sLexer = p_lexer_name)
180{
181 /* init returns */
182 sLeft = sRight = '';
183 iColumn = 0;
184
185 /*
186 * Get comment setup from the lexer.
187 */
188 _str sLine = '';
189 if (sLexer)
190 {
191 /* multiline */
192#if __VERSION__>=14.0
193 _str aComments[];
194 GetComments(aComments, "mlcomment", sLexer)
195 for (i = 0; i < aComments._length(); i++)
196 if (!pos("documentation", aComments[i]) > 0)
197 {
198 sLine = aComments[i];
199 break;
200 }
201 if (sLine != '')
202#else
203 rc = _ini_get_value(slick_path_search("user.vlx"), sLexer, 'mlcomment', sLine);
204 if (rc)
205 rc = _ini_get_value(slick_path_search("vslick.vlx"), sLexer, 'mlcomment', sLine);
206 if (!rc)
207#endif
208 {
209 sLeft = strip(word(sLine, 1));
210 sRight = strip(word(sLine, 2));
211 if (sLeft != '' && sRight != '')
212 return true;
213 }
214
215 /* failed, try single line. */
216#if __VERSION__>=14.0
217 GetComments(aComments, "linecomment", sLexer)
218 for (i = 0; i < aComments._length(); i++)
219 if (!pos("documentation", aComments[i]) > 0)
220 {
221 sLine = aComments[i];
222 break;
223 }
224 if (sLine != '')
225#else
226 rc = _ini_get_value(slick_path_search("user.vlx"), sLexer, 'linecomment', sLine);
227 if (rc)
228 rc = _ini_get_value(slick_path_search("vslick.vlx"), sLexer, 'linecomment', sLine);
229 if (!rc)
230#endif
231 {
232 sLeft = strip(word(sLine, 1));
233 sRight = '';
234 iColumn = 0;
235 _str sTmp = word(sLine, 2);
236 if (isnumber(sTmp))
237 iColumn = (int)sTmp;
238 if (sLeft != '')
239 return true;
240 }
241 }
242
243 /*
244 * Read the nonboxchars and determin user or default box.ini.
245 */
246 _str sFile = slick_path_search("ubox.ini");
247 boolean frc = _ini_get_value(sFile, sExt, 'nonboxchars', sLine);
248 if (frc)
249 {
250 sFile = slick_path_search("box.ini");
251 frc = _ini_get_value(sFile, sExt, 'nonboxchars', sLine);
252 }
253
254 if (!frc)
255 { /*
256 * Found extension.
257 */
258 sLeft = strip(eq_name2value('left',sLine));
259 if (sLeft == '\e') sLeft = '';
260 sRight = strip(eq_name2value('right',sLine));
261 if (sRight == '\e') sRight = '';
262
263 /* Read comment column too */
264 frc = _ini_get_value(sFile, sExt, 'comment_col', sLine);
265 if (frc)
266 {
267 iColumn = eq_name2value('comment_col', sLine);
268 if (iColumn == '\e') iColumn = 0;
269 }
270 else
271 iColumn = 0;
272 return true;
273 }
274
275 /* failure */
276 sLeft = sRight = '';
277 iColumn = 0;
278
279 return false;
280}
281
282
283/**
284 * Checks if current file only support line comments.
285 * @returns True / False.
286 * @remark Use builtin extension stuff!
287 */
288static boolean k_line_comment()
289{
290 _str sRight = '';
291 _str sLeft = '';
292 int iColumn;
293 boolean fLineComment = false;
294 if (k_commentconfig(sLeft, sRight, iColumn))
295 fLineComment = (sRight == '' || iColumn > 0);
296 return fLineComment;
297}
298
299
300
301#define KIC_CURSOR_BEFORE 1
302#define KIC_CURSOR_AFTER 2
303#define KIC_CURSOR_AT_END 3
304
305/**
306 * Insert a comment at current or best fitting position in the text.
307 * @param sStr The comment to insert.
308 * @param iCursor Where to put the cursor.
309 * @param iPosition Where to start the comment.
310 * Doesn't apply to column based source.
311 * -1 means at cursor position. (default)
312 * >0 means at end of line, but not before this column (1-based).
313 * This also implies a min of one space to EOL.
314 */
315void k_insert_comment(_str sStr, int iCursor, int iPosition = -1)
316{
317 _str sLeft;
318 _str sRight;
319 int iColumn;
320 if (!k_commentconfig(sLeft, sRight, iColumn))
321 {
322 sLeft = '/*'; sRight = '*/'; iColumn = 0;
323 }
324
325 int iCol = 0;
326 if (iColumn <= 0)
327 { /*
328 * not column based source
329 */
330
331 /* position us first */
332 if (iPosition > 0)
333 {
334 end_line();
335 do {
336 _insert_text(" ");
337 } while (p_col < iPosition);
338 }
339
340 /* insert comment saving the position for _BEFORE. */
341 iCol = p_col;
342 _insert_text(sLeft:+' ':+sStr);
343 if (iCursor == KIC_CURSOR_AT_END)
344 iCol = p_col;
345 /* right comment delimiter? */
346 if (sRight != '')
347 _insert_text(' ':+sRight);
348 }
349 else
350 {
351 if (p_col >= iColumn)
352 _insert_text("\n");
353 do { _insert_text(" "); } while (p_col < iColumn);
354 if (iCursor == KIC_CURSOR_BEFORE)
355 iCol = p_col;
356 _insert_text(sLeft:+' ':+sStr);
357 if (iCursor == KIC_CURSOR_AT_END)
358 iCol = p_col;
359 }
360
361 /* set cursor. */
362 if (iCursor != KIC_CURSOR_AFTER)
363 p_col = iCol;
364}
365
366
367/**
368 * Gets the comment prefix or postfix.
369 * @returns Comment prefix or postfix.
370 * @param fRight If clear left comment string - default.
371 * If set right comment string.
372 */
373static _str k_comment(boolean fRight = false)
374{
375 _str sLeft, sRight;
376 int iColumn;
377 _str sComment = '/*';
378 if (k_commentconfig(sLeft, sRight, iColumn))
379 sComment = (!fRight || iColumn > 0 ? sLeft : sRight);
380
381 return strip(sComment);
382}
383
384
385/*******************************************************************************
386* BOXES *
387*******************************************************************************/
388
389/**
390 * Inserts the first line in a box.
391 * @param sTag Not used - box tag.
392 */
393static void k_box_start(sTag)
394{
395 _str sLeft, sRight;
396 int iColumn;
397 if (!k_commentconfig(sLeft, sRight, iColumn))
398 return;
399 _begin_line();
400 if (iColumn >= 0)
401 while (p_col < iColumn)
402 _insert_text(" ");
403
404 _str sText = sLeft;
405 if (sTag != '' && fkStyleBoxTag)
406 {
407 if (substr(sText, length(sText)) != '*')
408 sText = sText:+'*';
409 sText = sText:+sTag;
410 }
411
412 int i;
413 for (i = length(sText); i <= ikStyleWidth - p_col; i++)
414 sText = sText:+'*';
415 sText = sText:+"\n";
416
417 _insert_text(sText);
418}
419
420
421/**
422 * Places a string, sStr, into a line started and ended by '*'.
423 * @param sStr Text to have between the '*'s.
424 */
425static void k_box_line(_str sStr)
426{
427 _str sLeft, sRight;
428 int iColumn;
429 if (!k_commentconfig(sLeft, sRight, iColumn))
430 return;
431 if (iColumn >= 0)
432 while (p_col < iColumn)
433 _insert_text(" ");
434
435 _str sText = '';
436 if (k_line_comment())
437 sText = sLeft;
438 if (sText == '' || substr(sText, length(sText)) != '*')
439 sText = sText:+'*';
440
441 sText = sText:+' ';
442 int i;
443 for (i = length(sText); i < p_SyntaxIndent; i++)
444 sText = sText:+' ';
445
446 sText = sText:+sStr;
447
448 for (i = length(sText) + 1; i <= ikStyleWidth - p_col; i++)
449 sText = sText:+' ';
450 sText = sText:+"*\n";
451
452 _insert_text(sText);
453}
454
455
456/**
457 * Inserts the last line in a box.
458 */
459static void k_box_end()
460{
461 _str sLeft, sRight;
462 int iColumn, i;
463 if (!k_commentconfig(sLeft, sRight, iColumn))
464 return;
465 if (iColumn >= 0)
466 while (p_col < iColumn)
467 _insert_text(" ");
468
469 _str sText = '';
470 if (k_line_comment())
471 sText = sLeft;
472 for (i = length(sText) + length(sRight); i <= ikStyleWidth - p_col; i++)
473 sText = sText:+'*';
474 sText = sText:+sRight:+"\n";
475
476 _insert_text(sText);
477}
478
479
480
481/*******************************************************************************
482* FUNCTION AND CODE PARSERS *
483*******************************************************************************/
484/**
485 * Moves cursor to nearest function start.
486 * @returns 0 if ok.
487 * -1 on failure.
488 */
489static int k_func_goto_nearest_function()
490{
491 boolean fFix = false; /* cursor at function fix. (last function) */
492 int cur_line = p_line;
493 int prev_line = -1;
494 int next_line = -1;
495 typeless org_pos;
496 _save_pos2(org_pos);
497
498 if (!next_proc(1))
499 {
500 next_line = p_line;
501 if (!prev_proc(1) && p_line == cur_line)
502 {
503 _restore_pos2(org_pos);
504 return 0;
505 }
506 _restore_pos2(org_pos);
507 _save_pos2(org_pos);
508 }
509 else
510 {
511 p_col++; /* fixes problem with single function files. */
512 fFix = true;
513 }
514
515 if (!prev_proc(1))
516 {
517 prev_line = p_line;
518 if (!next_proc(1) && p_line == cur_line)
519 {
520 _restore_pos2(org_pos);
521 return 0;
522 }
523 _restore_pos2(org_pos);
524 _save_pos2(org_pos);
525 }
526
527
528 if (prev_line != -1 && (next_line == -1 || cur_line - prev_line <= next_line - cur_line))
529 {
530 if (fFix)
531 p_col++;
532 prev_proc(1);
533 return 0;
534 }
535
536 if (next_line != -1 && (prev_line == -1 || cur_line - prev_line > next_line - cur_line))
537 {
538 next_proc();
539 return 0;
540 }
541
542 _restore_pos2(org_pos);
543 return -1;
544}
545
546
547/**
548 * Check if nearest function is a prototype.
549 * @returns True if function prototype.
550 * False if not function prototype.
551 */
552static boolean k_func_prototype()
553{
554 /*
555 * Check if this is a real function implementation.
556 */
557 typeless procpos;
558 _save_pos2(procpos);
559 if (!k_func_goto_nearest_function())
560 {
561 int proc_line = p_line;
562
563 if (!k_func_searchcode("{"))
564 {
565 prev_proc();
566 if (p_line != proc_line)
567 {
568 _restore_pos2(procpos);
569 return true;
570 }
571 }
572 }
573 _restore_pos2(procpos);
574
575 return false;
576}
577
578
579/**
580 * Gets the name fo the current function.
581 * @returns The current function name.
582 */
583static _str k_func_getfunction_name()
584{
585 _str sFunctionName = current_proc();
586 if (!sFunctionName)
587 sFunctionName = "";
588 //say 'functionanme='sFunctionName;
589 return sFunctionName;
590}
591
592
593/**
594 * Goes to the neares function and gets its parameters.
595 * @remark Should be reimplemented to use tags (if someone can figure out how to query that stuff).
596 */
597static _str k_func_getparams()
598{
599 typeless org_pos;
600 _save_pos2(org_pos);
601
602 /*
603 * Try use the tags first.
604 */
605 _UpdateContext(true);
606 int context_id = tag_current_context();
607 if (context_id <= 0)
608 {
609 k_func_goto_nearest_function();
610 context_id = tag_current_context();
611 }
612 if (context_id > 0)
613 {
614 _str args = '';
615 _str type = '';
616 tag_get_detail2(VS_TAGDETAIL_context_args, context_id, args);
617 tag_get_detail2(VS_TAGDETAIL_context_type, context_id, type);
618 if (tag_tree_type_is_func(type))
619 return args
620 //caption = tag_tree_make_caption_fast(VS_TAGMATCH_context,context_id,true,true,false);
621 }
622
623 /*
624 * Go to nearest function.
625 */
626 if ( !k_func_goto_nearest_function()
627 && !k_func_searchcode("(") /* makes some assumptions. */
628 )
629 {
630 /*
631 * Get parameters.
632 */
633 typeless posStart;
634 _save_pos2(posStart);
635 long offStart = _QROffset();
636 if (!find_matching_paren())
637 {
638 long offEnd = _QROffset();
639 _restore_pos2(posStart);
640 p_col++;
641 _str sParamsRaw = strip(get_text((int)(offEnd - offStart - 1)));
642
643
644 /*
645 * Remove new lines and double spaces within params.
646 */
647 _str sParams = "";
648
649 int i;
650 _str chPrev;
651 for (i = 1, chPrev = ' '; i <= length(sParamsRaw); i++)
652 {
653 _str ch = substr(sParamsRaw, i, 1);
654
655 /*
656 * Do fixups.
657 */
658 if (ch == " " && chPrev == " ")
659 continue;
660
661 if ((ch :== "\n") || (ch :== "\r") || (ch :== "\t"))
662 {
663 if (chPrev == ' ')
664 continue;
665 ch = ' ';
666 }
667
668 if (ch == ',' && chPrev == ' ')
669 {
670 sParams = substr(sParams, 1, length(sParams) - 1);
671 }
672
673 if (ch == '*')
674 {
675 if (chPrev != ' ')
676 sParams = sParams :+ ' * ';
677 else
678 sParams = sParams :+ '* ';
679 chPrev = ' ';
680 }
681 else
682 {
683 sParams = sParams :+ ch;
684 chPrev = ch;
685 }
686
687 } /* for */
688
689 sParams = strip(sParams);
690 if (sParams == 'void' || sParams == 'VOID')
691 sParams = "";
692 _restore_pos2(org_pos);
693 return sParams;
694 }
695 else
696 message("find_matchin_paren failed");
697 }
698
699 _restore_pos2(org_pos);
700 return false;
701}
702
703
704
705/**
706 * Enumerates the parameters to the function.
707 * @param sParams Parameter string from k_func_getparams.
708 * @param iParam The index (0-based) of the parameter to get.
709 * @param sType Type. (output)
710 * @param sName Name. (output)
711 * @param sDefault Default value. (output)
712 * @remark Doesn't perhaps handle function pointers very well (I think)?
713 * @remark Should be reimplemented to use tags (if someone can figure out how to query that stuff).
714 */
715static int k_func_enumparams(_str sParams, int iParam, _str &sType, _str &sName, _str &sDefault)
716{
717 int i;
718 int iParLevel;
719 int iCurParam;
720 int iStartParam;
721
722 sType = sName = sDefault = "";
723
724 /* no use working on empty string! */
725 if (length(sParams) == 0)
726 return -1;
727
728 /* find the parameter in question */
729 for (iStartParam = i = 1, iParLevel = iCurParam = 0; i <= length(sParams); i++)
730 {
731 _str ch = substr(sParams, i, 1);
732 if (ch == ',' && iParLevel == 0)
733 {
734 /* is it this parameter ? */
735 if (iParam == iCurParam)
736 break;
737
738 iCurParam++;
739 iStartParam = i + 1;
740 }
741 else if (ch == '(')
742 iParLevel++;
743 else if (ch == ')')
744 iParLevel--;
745 }
746
747 /* did we find the parameter? */
748 if (iParam == iCurParam)
749 { /* (yeah, we did!) */
750 _str sArg = strip(substr(sParams, iStartParam, i - iStartParam));
751 /* remove M$ stuff */
752 sArg = stranslate(sArg, "", "IN", "E");
753 sArg = stranslate(sArg, "", "OUT", "E");
754 sArg = stranslate(sArg, "", "OPTIONAL", "E");
755 sArg = strip(sArg);
756
757 /* lazy approach, which doens't support function types */
758
759 if (pos('=', sParams) > 0) /* default */
760 {
761 sDefault = strip(substr(sParams, pos('=', sParams) + 1));
762 sArg = strip(substr(sArg, 1, pos('=', sParams) - 1));
763 }
764
765 for (i = length(sArg); i > 1; i--)
766 {
767 _str ch = substr(sArg, i, 1);
768 if ( !(ch >= 'a' && ch <= 'z')
769 && !(ch >= 'A' && ch <= 'Z')
770 && !(ch >= '0' && ch <= '9')
771 && ch != '_' && ch != '$')
772 break;
773 }
774 if (sArg == "...")
775 i = 0;
776 sName = strip(substr(sArg, i + 1));
777 sType = strip(substr(sArg, 1, i));
778
779 return 0;
780 }
781
782 return -1;
783}
784
785
786/**
787 * Counts the parameters to the function.
788 * @param sParams Parameter string from k_func_getparams.
789 * @remark Should be reimplemented to use tags (if someone can figure out how to query that stuff).
790 */
791static int k_func_countparams(_str sParams)
792{
793 int i;
794 int iParLevel;
795 int iCurParam;
796 _str sType = "", sName = "", sDefault = "";
797
798 /* check for 0 parameters */
799 if (length(sParams) == 0)
800 return 0;
801
802 /* find the parameter in question */
803 for (i = 1, iParLevel = iCurParam = 0; i <= length(sParams); i++)
804 {
805 _str ch = substr(sParams, i, 1);
806 if (ch == ',' && iParLevel == 0)
807 {
808 iCurParam++;
809 }
810 else if (ch == '(')
811 iParLevel++;
812 else if (ch == ')')
813 iParLevel--;
814 }
815
816 return iCurParam + 1;
817}
818
819
820/**
821 * Gets the return type.
822 */
823static _str k_func_getreturntype(boolean fPureType = false)
824{
825 typeless org_pos;
826 _save_pos2(org_pos);
827
828 /*
829 * Go to nearest function.
830 */
831 if (!k_func_goto_nearest_function())
832 {
833 /*
834 * Return type is from function start to function name...
835 */
836 typeless posStart;
837 _save_pos2(posStart);
838 long offStart = _QROffset();
839
840 if (!k_func_searchcode("(")) /* makes some assumptions. */
841 {
842 prev_word();
843 long offEnd = _QROffset();
844 _restore_pos2(posStart);
845 _str sTypeRaw = strip(get_text((int)(offEnd - offStart)));
846
847 //say 'sTypeRaw='sTypeRaw;
848 /*
849 * Remove static, inline, _Optlink, stdcall, EXPENTRY etc.
850 */
851 if (fPureType)
852 {
853 sTypeRaw = stranslate(sTypeRaw, "", "__static__", "I");
854 sTypeRaw = stranslate(sTypeRaw, "", "__static", "I");
855 sTypeRaw = stranslate(sTypeRaw, "", "static__", "I");
856 sTypeRaw = stranslate(sTypeRaw, "", "static", "I");
857 sTypeRaw = stranslate(sTypeRaw, "", "__inline__", "I");
858 sTypeRaw = stranslate(sTypeRaw, "", "__inline", "I");
859 sTypeRaw = stranslate(sTypeRaw, "", "inline__", "I");
860 sTypeRaw = stranslate(sTypeRaw, "", "inline", "I");
861 sTypeRaw = stranslate(sTypeRaw, "", "EXPENTRY", "I");
862 sTypeRaw = stranslate(sTypeRaw, "", "_Optlink", "I");
863 sTypeRaw = stranslate(sTypeRaw, "", "__stdcall", "I");
864 sTypeRaw = stranslate(sTypeRaw, "", "__cdecl", "I");
865 sTypeRaw = stranslate(sTypeRaw, "", "_cdecl", "I");
866 sTypeRaw = stranslate(sTypeRaw, "", "cdecl", "I");
867 sTypeRaw = stranslate(sTypeRaw, "", "__PASCAL", "I");
868 sTypeRaw = stranslate(sTypeRaw, "", "_PASCAL", "I");
869 sTypeRaw = stranslate(sTypeRaw, "", "PASCAL", "I");
870 sTypeRaw = stranslate(sTypeRaw, "", "__Far32__", "I");
871 sTypeRaw = stranslate(sTypeRaw, "", "__Far32", "I");
872 sTypeRaw = stranslate(sTypeRaw, "", "Far32__", "I");
873 sTypeRaw = stranslate(sTypeRaw, "", "_Far32_", "I");
874 sTypeRaw = stranslate(sTypeRaw, "", "_Far32", "I");
875 sTypeRaw = stranslate(sTypeRaw, "", "Far32_", "I");
876 sTypeRaw = stranslate(sTypeRaw, "", "Far32", "I");
877 sTypeRaw = stranslate(sTypeRaw, "", "__far", "I");
878 sTypeRaw = stranslate(sTypeRaw, "", "_far", "I");
879 sTypeRaw = stranslate(sTypeRaw, "", "far", "I");
880 sTypeRaw = stranslate(sTypeRaw, "", "__near", "I");
881 sTypeRaw = stranslate(sTypeRaw, "", "_near", "I");
882 sTypeRaw = stranslate(sTypeRaw, "", "near", "I");
883 sTypeRaw = stranslate(sTypeRaw, "", "__loadds__", "I");
884 sTypeRaw = stranslate(sTypeRaw, "", "__loadds", "I");
885 sTypeRaw = stranslate(sTypeRaw, "", "loadds__", "I");
886 sTypeRaw = stranslate(sTypeRaw, "", "_loadds_", "I");
887 sTypeRaw = stranslate(sTypeRaw, "", "_loadds", "I");
888 sTypeRaw = stranslate(sTypeRaw, "", "loadds_", "I");
889 sTypeRaw = stranslate(sTypeRaw, "", "loadds", "I");
890 sTypeRaw = stranslate(sTypeRaw, "", "__loades__", "I");
891 sTypeRaw = stranslate(sTypeRaw, "", "__loades", "I");
892 sTypeRaw = stranslate(sTypeRaw, "", "loades__", "I");
893 sTypeRaw = stranslate(sTypeRaw, "", "_loades_", "I");
894 sTypeRaw = stranslate(sTypeRaw, "", "_loades", "I");
895 sTypeRaw = stranslate(sTypeRaw, "", "loades_", "I");
896 sTypeRaw = stranslate(sTypeRaw, "", "loades", "I");
897 sTypeRaw = stranslate(sTypeRaw, "", "WIN32API", "I");
898 sTypeRaw = stranslate(sTypeRaw, "", "WINAPI", "I");
899 sTypeRaw = stranslate(sTypeRaw, "", "LDRCALL", "I");
900 sTypeRaw = stranslate(sTypeRaw, "", "KRNLCALL", "I");
901 sTypeRaw = stranslate(sTypeRaw, "", "__operator__", "I"); /* operator fix */
902 sTypeRaw = stranslate(sTypeRaw, "", "__operator", "I"); /* operator fix */
903 sTypeRaw = stranslate(sTypeRaw, "", "operator__", "I"); /* operator fix */
904 sTypeRaw = stranslate(sTypeRaw, "", "operator", "I"); /* operator fix */
905 sTypeRaw = stranslate(sTypeRaw, "", "IN", "E");
906 sTypeRaw = stranslate(sTypeRaw, "", "OUT", "E");
907 sTypeRaw = stranslate(sTypeRaw, "", "OPTIONAL", "E");
908 }
909
910 /*
911 * Remove new lines and double spaces within params.
912 */
913 _str sType = "";
914
915 int i;
916 _str chPrev;
917 for (i = 1, chPrev = ' '; i <= length(sTypeRaw); i++)
918 {
919 _str ch = substr(sTypeRaw, i, 1);
920
921 /*
922 * Do fixups.
923 */
924 if (ch == " " && chPrev == " ")
925 continue;
926
927 if ((ch :== "\n") || (ch :== "\r") || (ch :== "\t"))
928 {
929 if (chPrev == ' ')
930 continue;
931 ch = ' ';
932 }
933
934 if (ch == ',' && chPrev == ' ')
935 {
936 sType = substr(sType, 1, length(sType) - 1);
937 }
938
939 if (ch == '*')
940 {
941 if (chPrev != ' ')
942 sType = sType :+ ' * ';
943 else
944 sType = sType :+ '* ';
945 chPrev = ' ';
946 }
947 else
948 {
949 sType = sType :+ ch;
950 chPrev = ch;
951 }
952
953 } /* for */
954
955 sType = strip(sType);
956
957 _restore_pos2(org_pos);
958 return sType;
959 }
960 else
961 message('k_func_getreturntype: can''t find ''(''.');
962 }
963
964 _restore_pos2(org_pos);
965 return false;
966}
967
968
969/**
970 * Search for some piece of code.
971 */
972static int k_func_searchcode(_str sSearchString, _str sOptions = "E+")
973{
974 int rc;
975 rc = search(sSearchString, sOptions);
976 while (!rc && !k_func_in_code())
977 {
978 p_col++;
979 rc = search(sSearchString, sOptions);
980 }
981 return rc;
982}
983
984
985/**
986 * Checks if cursor is in code or in comment.
987 * @return True if cursor in code.
988 */
989static boolean k_func_in_code()
990{
991 typeless searchsave;
992 _save_pos2(searchsave);
993 boolean fRc = !_in_comment();
994 _restore_pos2(searchsave);
995 return fRc;
996}
997
998
999/*
1000 * Gets the next piece of code.
1001 */
1002static _str k_func_get_next_code_text()
1003{
1004 typeless searchsave;
1005 _save_pos2(searchsave);
1006 _str ch = k_func_get_next_code_text2();
1007 _restore_pos2(searchsave);
1008 return ch;
1009}
1010
1011
1012/**
1013 * Checks if there is more code on the line.
1014 */
1015static boolean k_func_more_code_on_line()
1016{
1017 boolean fRc;
1018 int curline = p_line;
1019 typeless searchsave;
1020 _save_pos2(searchsave);
1021 k_func_get_next_code_text2();
1022 fRc = curline == p_line;
1023 _restore_pos2(searchsave);
1024
1025 return fRc;
1026}
1027
1028
1029/**
1030 * Gets the next piece of code.
1031 * Doesn't preserver cursor position.
1032 */
1033static _str k_func_get_next_code_text2()
1034{
1035 _str ch;
1036 do
1037 {
1038 int curcol = ++p_col;
1039 end_line();
1040 if (p_col <= curcol)
1041 {
1042 p_line++;
1043 p_col = 1;
1044 }
1045 else
1046 p_col = curcol;
1047
1048 ch = get_text();
1049 //say ch ' ('_asc(ch)')';
1050 while (ch == "#") /* preprocessor stuff */
1051 {
1052 p_col = 1;
1053 p_line++;
1054 ch = get_text();
1055 //say ch ' ('_asc(ch)')';
1056 continue;
1057 }
1058 } while (ch :== ' ' || ch :== "\t" || ch :== "\n" || ch :== "\r" || !k_func_in_code());
1059
1060 return ch;
1061}
1062
1063
1064
1065
1066/*******************************************************************************
1067* JAVA DOC STYLED WORKERS *
1068*******************************************************************************/
1069
1070/** starts a javadoc documentation box. */
1071static void k_javadoc_box_start(_str sStr = '', boolean fDouble = true)
1072{
1073 _str sLeft, sRight;
1074 int iColumn;
1075 if (!k_commentconfig(sLeft, sRight, iColumn))
1076 return;
1077 _begin_line();
1078 if (iColumn >= 0)
1079 while (p_col < iColumn)
1080 _insert_text(" ");
1081
1082 _str sText = sLeft;
1083 if (fDouble)
1084 sText = sLeft:+substr(sLeft, length(sLeft), 1);
1085 if (sStr != '')
1086 sText = sText:+' ':+sStr;
1087 sText = sText:+"\n";
1088
1089 _insert_text(sText);
1090}
1091
1092/** inserts a new line in a javadoc documentation box. */
1093static void k_javadoc_box_line(_str sStr = '', int iPadd = 0, _str sStr2 = '', int iPadd2 = 0, _str sStr3 = '')
1094{
1095 _str sLeft, sRight;
1096 int iColumn;
1097 if (!k_commentconfig(sLeft, sRight, iColumn))
1098 return;
1099 if (iColumn >= 0)
1100 while (p_col < iColumn)
1101 _insert_text(" ");
1102
1103 _str sText;
1104 if (k_line_comment())
1105 sText = sLeft;
1106 else
1107 {
1108 sText = sLeft;
1109 sText = ' ':+substr(sLeft, length(sLeft));
1110 }
1111
1112 if (sStr != '')
1113 sText = sText:+' ':+sStr;
1114 if (iPadd > 0)
1115 {
1116 int i;
1117 for (i = length(sText); i < iPadd; i++)
1118 sText = sText:+' ';
1119
1120 if (sStr2 != '')
1121 sText = sText:+sStr2;
1122
1123 if (iPadd2 > 0)
1124 {
1125 for (i = length(sText); i < iPadd2; i++)
1126 sText = sText:+' ';
1127
1128 if (sStr3 != '')
1129 sText = sText:+sStr3;
1130 }
1131 }
1132 sText = sText:+"\n";
1133
1134 _insert_text(sText);
1135}
1136
1137/** ends a javadoc documentation box. */
1138static void k_javadoc_box_end()
1139{
1140 _str sLeft, sRight;
1141 int iColumn;
1142 if (!k_commentconfig(sLeft, sRight, iColumn))
1143 return;
1144 if (iColumn >= 0)
1145 while (p_col < iColumn)
1146 _insert_text(" ");
1147
1148 _str sText;
1149 if (k_line_comment())
1150 sText = sLeft;
1151 else
1152 {
1153 sText = sRight;
1154 /*if (substr(sText, 1, 1) != '*')
1155 sText = '*':+sText;*/
1156 sText = ' ':+sText;
1157 }
1158 sText = sText:+"\n";
1159
1160 _insert_text(sText);
1161}
1162
1163
1164/**
1165 * Write a Javadoc styled classbox.
1166 */
1167void k_javadoc_classbox()
1168{
1169 int iCursorLine;
1170 int iPadd = k_alignup(12, p_SyntaxIndent);
1171
1172 k_javadoc_box_start();
1173 iCursorLine = p_RLine;
1174 k_javadoc_box_line(' ');
1175
1176 if (fkStyleFullHeaders)
1177 {
1178 k_javadoc_box_line('@shortdesc', iPadd);
1179 k_javadoc_box_line('@dstruct', iPadd);
1180 k_javadoc_box_line('@version', iPadd);
1181 k_javadoc_box_line('@verdesc', iPadd);
1182 }
1183 k_javadoc_box_line('@author', iPadd, skUserName ' <' skUserEmail '>');
1184 k_javadoc_box_line('@approval', iPadd);
1185 k_javadoc_box_end();
1186
1187 up(p_RLine - iCursorLine);
1188 end_line();
1189 keyin(' ');
1190}
1191
1192
1193/**
1194 * Javadoc - functionbox(/header).
1195 */
1196void k_javadoc_funcbox()
1197{
1198 int cArgs = 1;
1199 _str sArgs = "";
1200 int iCursorLine;
1201 int iPadd = k_alignup(11, p_SyntaxIndent);
1202
1203 /* look for parameters */
1204 boolean fFoundFn = !k_func_goto_nearest_function();
1205 if (fFoundFn)
1206 {
1207 sArgs = k_func_getparams();
1208 cArgs = k_func_countparams(sArgs);
1209 }
1210
1211 k_javadoc_box_start();
1212 iCursorLine = p_RLine;
1213 k_javadoc_box_line(' ');
1214 if (file_eq(p_extension, 'asm'))
1215 k_javadoc_box_line('@cproto', iPadd);
1216 k_javadoc_box_line('@returns', iPadd);
1217 if (fFoundFn)
1218 {
1219 /*
1220 * Determin parameter description indent.
1221 */
1222 int iPadd2 = 0;
1223 int i;
1224 for (i = 0; i < cArgs; i++)
1225 {
1226 _str sName, sType, sDefault;
1227 if ( !k_func_enumparams(sArgs, i, sType, sName, sDefault)
1228 && iPadd2 < length(sName))
1229 iPadd2 = length(sName);
1230 }
1231 iPadd2 = k_alignup((iPadd + iPadd2), p_SyntaxIndent);
1232 if (iPadd2 < 28)
1233 iPadd2 = k_alignup(28, p_SyntaxIndent);
1234
1235 /*
1236 * Insert parameter.
1237 */
1238 for (i = 0; i < cArgs; i++)
1239 {
1240 _str sName, sType, sDefault;
1241 if (!k_func_enumparams(sArgs, i, sType, sName, sDefault))
1242 {
1243 _str sStr3 = '.';
1244 if (sDefault != "")
1245 sStr3 = '(default='sDefault')';
1246 k_javadoc_box_line('@param', iPadd, sName, iPadd2, sStr3);
1247 }
1248 else
1249 k_javadoc_box_line('@param', iPadd);
1250 }
1251 }
1252 else
1253 k_javadoc_box_line('@param', iPadd);
1254
1255 if (file_eq(p_extension, 'asm'))
1256 k_javadoc_box_line('@uses', iPadd);
1257 if (fkStyleFullHeaders)
1258 {
1259 k_javadoc_box_line('@equiv', iPadd);
1260 k_javadoc_box_line('@time', iPadd);
1261 k_javadoc_box_line('@sketch', iPadd);
1262 k_javadoc_box_line('@status', iPadd);
1263 k_javadoc_box_line('@author', iPadd, skUserName ' <' skUserEmail '>');
1264 k_javadoc_box_line('@remark', iPadd);
1265 }
1266 k_javadoc_box_end();
1267
1268 up(p_RLine - iCursorLine);
1269 end_line();
1270 keyin(' ');
1271}
1272
1273
1274/**
1275 * Javadoc module header.
1276 */
1277void k_javadoc_moduleheader()
1278{
1279 int iCursorLine;
1280 int fSplit = 0;
1281
1282 _insert_text("\n");
1283 up();
1284 _begin_line();
1285 k_insert_comment('$':+'I':+'d: $', KIC_CURSOR_AT_END, -1);
1286 _end_line();
1287 _insert_text("\n");
1288
1289 k_javadoc_box_start('@file');
1290 fSplit = 1;
1291 iCursorLine = p_RLine;
1292 k_javadoc_box_line();
1293 k_javadoc_box_end();
1294 _insert_text("\n");
1295 _insert_text(k_comment() "\n");
1296
1297 if (skLicense == 'Confidential')
1298 {
1299 k_javadoc_box_line(skCompany ' confidential');
1300 k_javadoc_box_line();
1301 }
1302
1303 if (skCompany != '')
1304 {
1305 if (skLicense != 'Confidential')
1306 k_javadoc_box_line('Copyright (C) ' k_year() ' ' skCompany);
1307 else
1308 {
1309 k_javadoc_box_line('Copyright (c) ' k_year() ' ' skCompany);
1310 k_javadoc_box_line();
1311 k_javadoc_box_line('Author: ' skUserName' <' skUserEmail '>');
1312 }
1313 }
1314 else
1315 k_javadoc_box_line('Copyright (c) ' k_year() ' 'skUserName' <' skUserEmail '>');
1316 k_javadoc_box_line();
1317 _str sProg = skProgram;
1318 switch (skLicense)
1319 {
1320 case 'Odin32':
1321 k_javadoc_box_line('Project Odin Software License can be found in LICENSE.TXT.');
1322 break;
1323
1324 case 'GPL':
1325 if (!fSplit)
1326 k_javadoc_box_line();
1327 if (sProg == '')
1328 sProg = 'This program';
1329 else
1330 {
1331 k_javadoc_box_line('This file is part of ' sProg '.');
1332 k_javadoc_box_line();
1333 }
1334 k_javadoc_box_line(sProg ' is free software; you can redistribute it and/or modify');
1335 k_javadoc_box_line('it under the terms of the GNU General Public License as published by');
1336 k_javadoc_box_line('the Free Software Foundation; either version 2 of the License, or');
1337 k_javadoc_box_line('(at your option) any later version.');
1338 k_javadoc_box_line();
1339 k_javadoc_box_line(sProg ' is distributed in the hope that it will be useful,');
1340 k_javadoc_box_line('but WITHOUT ANY WARRANTY; without even the implied warranty of');
1341 k_javadoc_box_line('MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the');
1342 k_javadoc_box_line('GNU General Public License for more details.');
1343 k_javadoc_box_line();
1344 k_javadoc_box_line('You should have received a copy of the GNU General Public License');
1345 k_javadoc_box_line('along with ' sProg '; if not, write to the Free Software');
1346 k_javadoc_box_line('Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA');
1347 break;
1348
1349 case 'LGPL':
1350 if (!fSplit)
1351 k_javadoc_box_line();
1352 if (sProg == '')
1353 sProg = 'This library';
1354 else
1355 {
1356 k_javadoc_box_line('This file is part of ' sProg '.');
1357 k_javadoc_box_line();
1358 }
1359 k_javadoc_box_line(sProg ' is free software; you can redistribute it and/or');
1360 k_javadoc_box_line('modify it under the terms of the GNU Lesser General Public');
1361 k_javadoc_box_line('License as published by the Free Software Foundation; either');
1362 k_javadoc_box_line('version 2.1 of the License, or (at your option) any later version.');
1363 k_javadoc_box_line();
1364 k_javadoc_box_line(sProg ' is distributed in the hope that it will be useful,');
1365 k_javadoc_box_line('but WITHOUT ANY WARRANTY; without even the implied warranty of');
1366 k_javadoc_box_line('MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU');
1367 k_javadoc_box_line('Lesser General Public License for more details.');
1368 k_javadoc_box_line();
1369 k_javadoc_box_line('You should have received a copy of the GNU Lesser General Public');
1370 k_javadoc_box_line('License along with ' sProg '; if not, write to the Free Software');
1371 k_javadoc_box_line('Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA');
1372 break;
1373
1374 case 'GPLv3':
1375 if (!fSplit)
1376 k_javadoc_box_line();
1377 if (sProg == '')
1378 sProg = 'This program';
1379 else
1380 {
1381 k_javadoc_box_line('This file is part of ' sProg '.');
1382 k_javadoc_box_line();
1383 }
1384 k_javadoc_box_line(sProg ' is free software; you can redistribute it and/or modify');
1385 k_javadoc_box_line('it under the terms of the GNU General Public License as published by');
1386 k_javadoc_box_line('the Free Software Foundation; either version 3 of the License, or');
1387 k_javadoc_box_line('(at your option) any later version.');
1388 k_javadoc_box_line();
1389 k_javadoc_box_line(sProg ' is distributed in the hope that it will be useful,');
1390 k_javadoc_box_line('but WITHOUT ANY WARRANTY; without even the implied warranty of');
1391 k_javadoc_box_line('MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the');
1392 k_javadoc_box_line('GNU General Public License for more details.');
1393 k_javadoc_box_line();
1394 k_javadoc_box_line('You should have received a copy of the GNU General Public License');
1395 k_javadoc_box_line('along with ' sProg '. If not, see <http://www.gnu.org/licenses/>');
1396 break;
1397
1398 case 'LGPLv3':
1399 if (!fSplit)
1400 k_javadoc_box_line();
1401 if (sProg == '')
1402 sProg = 'This program';
1403 else
1404 {
1405 k_javadoc_box_line('This file is part of ' sProg '.');
1406 k_javadoc_box_line();
1407 }
1408 k_javadoc_box_line(sProg ' is free software; you can redistribute it and/or');
1409 k_javadoc_box_line('modify it under the terms of the GNU Lesser General Public');
1410 k_javadoc_box_line('License as published by the Free Software Foundation; either');
1411 k_javadoc_box_line('version 3 of the License, or (at your option) any later version.');
1412 k_javadoc_box_line();
1413 k_javadoc_box_line(sProg ' is distributed in the hope that it will be useful,');
1414 k_javadoc_box_line('but WITHOUT ANY WARRANTY; without even the implied warranty of');
1415 k_javadoc_box_line('MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the');
1416 k_javadoc_box_line('GNU Lesser General Public License for more details.');
1417 k_javadoc_box_line();
1418 k_javadoc_box_line('You should have received a copy of the GNU Lesser General Public License');
1419 k_javadoc_box_line('along with ' sProg '. If not, see <http://www.gnu.org/licenses/>');
1420 break;
1421
1422 case 'Confidential':
1423 k_javadoc_box_line('All Rights Reserved');
1424 break;
1425
1426 case 'ConfidentialNoAuthor':
1427 k_javadoc_box_line(skCompany ' confidential');
1428 k_javadoc_box_line('All Rights Reserved');
1429 break;
1430
1431 case 'VirtualBox':
1432 k_javadoc_box_line('This file is part of VirtualBox Open Source Edition (OSE), as')
1433 k_javadoc_box_line('available from http://www.virtualbox.org. This file is free software;')
1434 k_javadoc_box_line('you can redistribute it and/or modify it under the terms of the GNU')
1435 k_javadoc_box_line('General Public License (GPL) as published by the Free Software')
1436 k_javadoc_box_line('Foundation, in version 2 as it comes in the "COPYING" file of the')
1437 k_javadoc_box_line('VirtualBox OSE distribution. VirtualBox OSE is distributed in the')
1438 k_javadoc_box_line('hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.')
1439 k_javadoc_box_line('')
1440 k_javadoc_box_line('Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa')
1441 k_javadoc_box_line('Clara, CA 95054 USA or visit http://www.sun.com if you need')
1442 k_javadoc_box_line('additional information or have any questions.')
1443 break;
1444
1445 case 'VirtualBoxGPLAndCDDL':
1446 k_javadoc_box_line('This file is part of VirtualBox Open Source Edition (OSE), as')
1447 k_javadoc_box_line('available from http://www.virtualbox.org. This file is free software;')
1448 k_javadoc_box_line('you can redistribute it and/or modify it under the terms of the GNU')
1449 k_javadoc_box_line('General Public License (GPL) as published by the Free Software')
1450 k_javadoc_box_line('Foundation, in version 2 as it comes in the "COPYING" file of the')
1451 k_javadoc_box_line('VirtualBox OSE distribution. VirtualBox OSE is distributed in the')
1452 k_javadoc_box_line('hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.')
1453 k_javadoc_box_line('')
1454 k_javadoc_box_line('The contents of this file may alternatively be used under the terms')
1455 k_javadoc_box_line('of the Common Development and Distribution License Version 1.0')
1456 k_javadoc_box_line('(CDDL) only, as it comes in the "COPYING.CDDL" file of the')
1457 k_javadoc_box_line('VirtualBox OSE distribution, in which case the provisions of the')
1458 k_javadoc_box_line('CDDL are applicable instead of those of the GPL.')
1459 k_javadoc_box_line('')
1460 k_javadoc_box_line('You may elect to license modified versions of this file under the')
1461 k_javadoc_box_line('terms and conditions of either the GPL or the CDDL or both.')
1462 k_javadoc_box_line('')
1463 k_javadoc_box_line('Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa')
1464 k_javadoc_box_line('Clara, CA 95054 USA or visit http://www.sun.com if you need')
1465 k_javadoc_box_line('additional information or have any questions.')
1466 break;
1467
1468 default:
1469
1470 }
1471 k_javadoc_box_line();
1472 k_javadoc_box_end();
1473
1474 up(p_RLine - iCursorLine);
1475 end_line();
1476 keyin(' ');
1477}
1478
1479
1480
1481
1482
1483
1484
1485/*******************************************************************************
1486* Keyboard Shortcuts *
1487*******************************************************************************/
1488/** Makes global box. */
1489void k_box_globals()
1490{
1491 k_box_start('Global');
1492 k_box_line('Global Variables');
1493 k_box_end();
1494}
1495
1496/** Makes header box. */
1497void k_box_headers()
1498{
1499 k_box_start("Header");
1500 k_box_line("Header Files");
1501 k_box_end();
1502}
1503
1504/** Makes internal function box. */
1505void k_box_intfuncs()
1506{
1507 k_box_start("IntFunc");
1508 k_box_line("Internal Functions");
1509 k_box_end();
1510}
1511
1512/** Makes def/const box. */
1513void k_box_consts()
1514{
1515 k_box_start("Const");
1516 k_box_line("Defined Constants And Macros");
1517 k_box_end();
1518}
1519
1520/** Structure box */
1521void k_box_structs()
1522{
1523 k_box_start("Struct");
1524 k_box_line("Structures and Typedefs");
1525 k_box_end();
1526}
1527
1528/** Makes exported symbols box. */
1529void k_box_exported()
1530{
1531 k_box_start('Exported');
1532 k_box_line('Exported Symbols');
1533 k_box_end();
1534}
1535
1536
1537
1538/** oneliner comment */
1539void k_oneliner()
1540{
1541 _str sLeft, sRight;
1542 int iColumn;
1543 if ( k_commentconfig(sLeft, sRight, iColumn)
1544 && iColumn > 0)
1545 { /* column based needs some tricky repositioning. */
1546 _end_line();
1547 if (p_col > iColumn)
1548 {
1549 _begin_line();
1550 _insert_text("\n\r");
1551 up();
1552 }
1553 }
1554 k_insert_comment("", KIC_CURSOR_AT_END, ikStyleOneliner);
1555}
1556
1557/** mark line as modified. */
1558void k_mark_modified_line()
1559{
1560 /* not supported for column based sources */
1561 _str sLeft, sRight;
1562 int iColumn;
1563 if ( !k_commentconfig(sLeft, sRight, iColumn)
1564 || iColumn > 0)
1565 return;
1566 _str sStr;
1567 if (skChange != '')
1568 sStr = skChange ' (' skUserInitials ')';
1569 else
1570 sStr = skUserInitials;
1571 k_insert_comment(sStr, KIC_CURSOR_BEFORE, ikStyleModifyMarkColumn);
1572 down();
1573}
1574
1575
1576/**
1577 * Inserts a signature. Form: "//Initials ISO-date:"
1578 * @remark defeventtab
1579 */
1580void k_signature()
1581{
1582 /* kso I5-10000 2002-09-10: */
1583 _str sSig;
1584 if (skChange != '')
1585 sSig = skUserInitials ' ' skChange ' ' k_date() ': ';
1586 else
1587 sSig = skUserInitials ' ' k_date() ': ';
1588 k_insert_comment(sSig, KIC_CURSOR_AT_END);
1589}
1590
1591
1592/*******************************************************************************
1593* kLIB Logging *
1594*******************************************************************************/
1595/**
1596 * Hot-Key: Inserts a KLOGENTRY statement at start of nearest function.
1597 */
1598void klib_klogentry()
1599{
1600 typeless org_pos;
1601 _save_pos2(org_pos);
1602
1603 /*
1604 * Go to nearest function.
1605 */
1606 if (!k_func_goto_nearest_function())
1607 {
1608 /*
1609 * Get parameters.
1610 */
1611 _str sParams = k_func_getparams();
1612 if (sParams)
1613 {
1614 _str sRetType = k_func_getreturntype(true);
1615 if (!sRetType || sRetType == "")
1616 sRetType = "void"; /* paranoia! */
1617
1618 /*
1619 * Insert text.
1620 */
1621 if (!k_func_searchcode("{"))
1622 {
1623 p_col++;
1624 int cArgs = k_func_countparams(sParams);
1625 if (cArgs > 0)
1626 {
1627 _str sArgs = "";
1628 int i;
1629 for (i = 0; i < cArgs; i++)
1630 {
1631 _str sType, sName, sDefault;
1632 if (!k_func_enumparams(sParams, i, sType, sName, sDefault))
1633 sArgs = sArgs', 'sName;
1634 }
1635
1636 _insert_text("\n KLOGENTRY"cArgs"(\""sRetType"\",\""sParams"\""sArgs");"); /* todo tab size.. or smart indent */
1637 }
1638 else
1639 _insert_text("\n KLOGENTRY0(\""sRetType"\");"); /* todo tab size.. or smart indent */
1640
1641 /*
1642 * Check if the next word is KLOGENTRY.
1643 */
1644 next_word();
1645 if (def_next_word_style == 'E')
1646 prev_word();
1647 int iIgnorePos = 0;
1648 if (substr(cur_word(iIgnorePos), 1, 9) == "KLOGENTRY")
1649 delete_line();
1650
1651 }
1652 else
1653 message("didn't find {");
1654 }
1655 else
1656 message("k_func_getparams failed, sParams=" sParams);
1657 return;
1658 }
1659
1660 _restore_pos2(org_pos);
1661}
1662
1663
1664/**
1665 * Hot-Key: Inserts a KLOGEXIT statement at cursor location.
1666 */
1667void klib_klogexit()
1668{
1669 typeless org_pos;
1670 _save_pos2(org_pos);
1671
1672 /*
1673 * Go to nearest function.
1674 */
1675 if (!prev_proc())
1676 {
1677 /*
1678 * Get parameters.
1679 */
1680 _str sType = k_func_getreturntype(true);
1681 _restore_pos2(org_pos);
1682 if (sType)
1683 {
1684 boolean fReturn = true; /* true if an return statment is following the KLOGEXIT statement. */
1685
1686 /*
1687 * Insert text.
1688 */
1689 int cur_col = p_col;
1690 if (sType == 'void' || sType == 'VOID')
1691 { /* procedure */
1692 int iIgnorePos;
1693 fReturn = cur_word(iIgnorePos) == 'return';
1694 if (!fReturn)
1695 {
1696 while (p_col <= p_SyntaxIndent)
1697 keyin(" ");
1698 }
1699
1700 _insert_text("KLOGEXITVOID();\n");
1701
1702 if (fReturn)
1703 {
1704 int i;
1705 for (i = 1; i < cur_col; i++)
1706 _insert_text(" ");
1707 }
1708 search(")","E-");
1709 }
1710 else
1711 { /* function */
1712 _insert_text("KLOGEXIT();\n");
1713 int i;
1714 for (i = 1; i < cur_col; i++)
1715 _insert_text(" ");
1716 search(")","E-");
1717
1718 /*
1719 * Insert value if possible.
1720 */
1721 typeless valuepos;
1722 _save_pos2(valuepos);
1723 next_word();
1724 if (def_next_word_style == 'E')
1725 prev_word();
1726 int iIgnorePos;
1727 if (cur_word(iIgnorePos) == 'return')
1728 {
1729 p_col += length('return');
1730 typeless posStart;
1731 _save_pos2(posStart);
1732 long offStart = _QROffset();
1733 if (!k_func_searchcode(";", "E+"))
1734 {
1735 long offEnd = _QROffset();
1736 _restore_pos2(posStart);
1737 _str sValue = strip(get_text((int)(offEnd - offStart)));
1738 //say 'sValue = 'sValue;
1739 _restore_pos2(valuepos);
1740 _save_pos2(valuepos);
1741 _insert_text(sValue);
1742 }
1743 }
1744 _restore_pos2(valuepos);
1745 }
1746
1747 /*
1748 * Remove old KLOGEXIT statement on previous line if any.
1749 */
1750 typeless valuepos;
1751 _save_pos2(valuepos);
1752 int newexitline = p_line;
1753 p_line--; p_col = 1;
1754 next_word();
1755 if (def_next_word_style == 'E')
1756 prev_word();
1757 int iIgnorePos;
1758 if (p_line == newexitline - 1 && substr(cur_word(iIgnorePos), 1, 8) == 'KLOGEXIT')
1759 delete_line();
1760 _restore_pos2(valuepos);
1761
1762 /*
1763 * Check for missing '{...}'.
1764 */
1765 if (fReturn)
1766 {
1767 boolean fFound = false;
1768 _save_pos2(valuepos);
1769 p_col--; find_matching_paren(); p_col += 2;
1770 k_func_searchcode(';', 'E+'); /* places us at the ';' of the return. (hopefully) */
1771
1772 _str ch = k_func_get_next_code_text();
1773 if (ch != '}')
1774 {
1775 _restore_pos2(valuepos);
1776 _save_pos2(valuepos);
1777 p_col--; find_matching_paren(); p_col += 2;
1778 k_func_searchcode(';', 'E+'); /* places us at the ';' of the return. (hopefully) */
1779 p_col++;
1780 if (k_func_more_code_on_line())
1781 _insert_text(' }');
1782 else
1783 {
1784 typeless returnget;
1785 _save_pos2(returnget);
1786 k_func_searchcode("return", "E-");
1787 int return_col = p_col;
1788 _restore_pos2(returnget);
1789
1790 end_line();
1791 _insert_text("\n");
1792 while (p_col < return_col - p_SyntaxIndent)
1793 _insert_text(' ');
1794 _insert_text('}');
1795 }
1796
1797 _restore_pos2(valuepos);
1798 _save_pos2(valuepos);
1799 prev_word();
1800 p_col -= p_SyntaxIndent;
1801 int codecol = p_col;
1802 _insert_text("{\n");
1803 while (p_col < codecol)
1804 _insert_text(' ');
1805 }
1806
1807 _restore_pos2(valuepos);
1808 }
1809 }
1810 else
1811 message("k_func_getreturntype failed, sType=" sType);
1812 return;
1813 }
1814
1815 _restore_pos2(org_pos);
1816}
1817
1818
1819/**
1820 * Processes a file - ask user all the time.
1821 */
1822void klib_klog_file_ask()
1823{
1824 klib_klog_file_int(true);
1825}
1826
1827
1828/**
1829 * Processes a file - no questions.
1830 */
1831void klib_klog_file_no_ask()
1832{
1833 klib_klog_file_int(false);
1834}
1835
1836
1837
1838/**
1839 * Processes a file.
1840 */
1841static void klib_klog_file_int(boolean fAsk)
1842{
1843 show_all();
1844 bottom();
1845 _refresh_scroll();
1846
1847 /* ask question so we can get to the right position somehow.. */
1848 if (fAsk && _message_box("kLog process this file?", "Visual SlickEdit", MB_YESNO | MB_ICONQUESTION) != IDYES)
1849 return;
1850
1851 /*
1852 * Entries.
1853 */
1854 while (!prev_proc())
1855 {
1856 //say 'entry main loop: ' k_func_getfunction_name();
1857
1858 /*
1859 * Skip prototypes.
1860 */
1861 if (k_func_prototype())
1862 continue;
1863
1864 /*
1865 * Ask user.
1866 */
1867 center_line();
1868 _refresh_scroll();
1869 _str sFunction = k_func_getfunction_name();
1870 rc = fAsk ? _message_box("Process this function ("sFunction")?", "Visual SlickEdit", MB_YESNOCANCEL | MB_ICONQUESTION) : IDYES;
1871 if (rc == IDYES)
1872 {
1873 typeless procpos;
1874 _save_pos2(procpos);
1875 klib_klogentry();
1876 _restore_pos2(procpos);
1877 }
1878 else if (rc == IDNO)
1879 continue;
1880 else
1881 break;
1882 }
1883
1884 /*
1885 * Exits.
1886 */
1887 bottom(); _refresh_scroll();
1888 boolean fUserCancel = false;
1889 while (!prev_proc() && !fUserCancel)
1890 {
1891 typeless procpos;
1892 _save_pos2(procpos);
1893 _str sCurFunction = k_func_getfunction_name();
1894 //say 'exit main loop: ' sCurFunction
1895
1896 /*
1897 * Skip prototypes.
1898 */
1899 if (k_func_prototype())
1900 continue;
1901
1902 /*
1903 * Select procedure.
1904 */
1905 while ( !k_func_searchcode("return", "WE<+")
1906 && k_func_getfunction_name() == sCurFunction)
1907 {
1908 //say 'exit sub loop: ' p_line
1909 /*
1910 * Ask User.
1911 */
1912 center_line();
1913 _refresh_scroll();
1914 _str sFunction = k_func_getfunction_name();
1915 rc = fAsk ? _message_box("Process this exit from "sFunction"?", "Visual SlickEdit", MB_YESNOCANCEL | MB_ICONQUESTION) : IDYES;
1916 deselect();
1917 if (rc == IDYES)
1918 {
1919 typeless returnpos;
1920 _save_pos2(returnpos);
1921 klib_klogexit();
1922 _restore_pos2(returnpos);
1923 p_line++;
1924 }
1925 else if (rc != IDNO)
1926 {
1927 fUserCancel = true;
1928 break;
1929 }
1930 p_line++; /* just so we won't hit it again. */
1931 }
1932
1933 /*
1934 * If void function we'll have to check if there is and return; prior to the ending '}'.
1935 */
1936 _restore_pos2(procpos);
1937 _save_pos2(procpos);
1938 _str sType = k_func_getreturntype(true);
1939 if (!fUserCancel && sType && (sType == 'void' || sType == 'VOID'))
1940 {
1941 if ( !k_func_searchcode("{", "E+")
1942 && !find_matching_paren())
1943 {
1944 typeless funcend;
1945 _save_pos2(funcend);
1946 prev_word();
1947 int iIgnorePos;
1948 if (cur_word(iIgnorePos) != "return")
1949 {
1950 /*
1951 * Ask User.
1952 */
1953 _restore_pos2(funcend);
1954 center_line();
1955 _refresh_scroll();
1956 _str sFunction = k_func_getfunction_name();
1957 rc = fAsk ? _message_box("Process this exit from "sFunction"?", "Visual SlickEdit", MB_YESNOCANCEL | MB_ICONQUESTION) : IDYES;
1958 deselect();
1959 if (rc == IDYES)
1960 {
1961 typeless returnpos;
1962 _save_pos2(returnpos);
1963 klib_klogexit();
1964 _restore_pos2(returnpos);
1965 }
1966 }
1967 }
1968 }
1969
1970 /*
1971 * Next proc.
1972 */
1973 _restore_pos2(procpos);
1974 }
1975}
1976
1977/** @todo move to kkeys.e */
1978_command void k_rebuild_tagfile()
1979{
1980#if 1 /*__VERSION__ < 14.0*/
1981 if (file_match('-p 'maybe_quote_filename(strip_filename(_project_name,'e'):+TAG_FILE_EXT),1) != "")
1982 _project_update_files_retag(false, false, false, false);
1983 else
1984 _project_update_files_retag(true, false, false, true);
1985#else
1986 _str sArgs = "-refs=on";
1987 if (file_match('-p 'maybe_quote_filename(strip_filename(_project_name,'e'):+TAG_FILE_EXT),1) != "")
1988 sArgs = sArgs :+ " -retag";
1989 sArgs = sArgs :+ " " :+ _workspace_filename;
1990 build_workspace_tagfiles(sArgs);
1991#endif
1992}
1993
1994
1995/*******************************************************************************
1996* Styles *
1997*******************************************************************************/
1998static _str StyleLanguages[] =
1999{
2000 "c",
2001 "e",
2002 "java"
2003};
2004
2005struct StyleScheme
2006{
2007 _str name;
2008 _str settings[];
2009};
2010
2011static StyleScheme StyleSchemes[] =
2012{
2013 {
2014 "Opt2Ind4",
2015 {
2016 "orig_tabsize=4",
2017 "syntax_indent=4",
2018 "tabsize=4",
2019 "align_on_equal=1",
2020 "pad_condition_state=1",
2021 "indent_with_tabs=0",
2022 "nospace_before_paren=0",
2023 "indent_comments=1",
2024 "indent_case=1",
2025 "statement_comment_col=0",
2026 "disable_bestyle=0",
2027 "decl_comment_col=0",
2028 "bestyle_on_functions=0",
2029 "use_relative_indent=1",
2030 "nospace_before_brace=0",
2031 "indent_fl=1",
2032 "statement_comment_state=2",
2033 "indent_pp=1",
2034 "be_style=1",
2035 "parens_on_return=0",
2036 "eat_blank_lines=0",
2037 "brace_indent=0",
2038 "eat_pp_space=1",
2039 "align_on_parens=1",
2040 "continuation_indent=0",
2041 "cuddle_else=0",
2042 "nopad_condition=1",
2043 "pad_condition=0",
2044 "indent_col1_comments=0"
2045 }
2046 }
2047 ,
2048 {
2049 "Opt2Ind3",
2050 {
2051 "orig_tabsize=3",
2052 "syntax_indent=3",
2053 "tabsize=3",
2054 "align_on_equal=1",
2055 "pad_condition_state=1",
2056 "indent_with_tabs=0",
2057 "nospace_before_paren=0",
2058 "indent_comments=1",
2059 "indent_case=1",
2060 "statement_comment_col=0",
2061 "disable_bestyle=0",
2062 "decl_comment_col=0",
2063 "bestyle_on_functions=0",
2064 "use_relative_indent=1",
2065 "nospace_before_brace=0",
2066 "indent_fl=1",
2067 "statement_comment_state=2",
2068 "indent_pp=1",
2069 "be_style=1",
2070 "parens_on_return=0",
2071 "eat_blank_lines=0",
2072 "brace_indent=0",
2073 "eat_pp_space=1",
2074 "align_on_parens=1",
2075 "continuation_indent=0",
2076 "cuddle_else=0",
2077 "nopad_condition=1",
2078 "pad_condition=0",
2079 "indent_col1_comments=0"
2080 }
2081 }
2082 ,
2083 {
2084 "Opt2Ind8",
2085 {
2086 "orig_tabsize=8",
2087 "syntax_indent=8",
2088 "tabsize=8",
2089 "align_on_equal=1",
2090 "pad_condition_state=1",
2091 "indent_with_tabs=0",
2092 "nospace_before_paren=0",
2093 "indent_comments=1",
2094 "indent_case=1",
2095 "statement_comment_col=0",
2096 "disable_bestyle=0",
2097 "decl_comment_col=0",
2098 "bestyle_on_functions=0",
2099 "use_relative_indent=1",
2100 "nospace_before_brace=0",
2101 "indent_fl=1",
2102 "statement_comment_state=2",
2103 "indent_pp=1",
2104 "be_style=1",
2105 "parens_on_return=0",
2106 "eat_blank_lines=0",
2107 "brace_indent=0",
2108 "eat_pp_space=1",
2109 "align_on_parens=1",
2110 "continuation_indent=0",
2111 "cuddle_else=0",
2112 "nopad_condition=1",
2113 "pad_condition=0",
2114 "indent_col1_comments=0"
2115 }
2116 }
2117 ,
2118 {
2119 "Opt3Ind4",
2120 {
2121 "orig_tabsize=4",
2122 "syntax_indent=4",
2123 "tabsize=4",
2124 "align_on_equal=1",
2125 "pad_condition_state=1",
2126 "indent_with_tabs=0",
2127 "nospace_before_paren=0",
2128 "indent_comments=1",
2129 "indent_case=1",
2130 "statement_comment_col=0",
2131 "disable_bestyle=0",
2132 "decl_comment_col=0",
2133 "bestyle_on_functions=0",
2134 "use_relative_indent=1",
2135 "nospace_before_brace=0",
2136 "indent_fl=1",
2137 "statement_comment_state=2",
2138 "indent_pp=1",
2139 "be_style=2",
2140 "parens_on_return=0",
2141 "eat_blank_lines=0",
2142 "brace_indent=0",
2143 "eat_pp_space=1",
2144 "align_on_parens=1",
2145 "continuation_indent=0",
2146 "cuddle_else=0",
2147 "nopad_condition=1",
2148 "pad_condition=0",
2149 "indent_col1_comments=0"
2150 }
2151 }
2152 ,
2153 {
2154 "Opt3Ind3",
2155 {
2156 "orig_tabsize=3",
2157 "syntax_indent=3",
2158 "tabsize=3",
2159 "align_on_equal=1",
2160 "pad_condition_state=1",
2161 "indent_with_tabs=0",
2162 "nospace_before_paren=0",
2163 "indent_comments=1",
2164 "indent_case=1",
2165 "statement_comment_col=0",
2166 "disable_bestyle=0",
2167 "decl_comment_col=0",
2168 "bestyle_on_functions=0",
2169 "use_relative_indent=1",
2170 "nospace_before_brace=0",
2171 "indent_fl=1",
2172 "statement_comment_state=2",
2173 "indent_pp=1",
2174 "be_style=2",
2175 "parens_on_return=0",
2176 "eat_blank_lines=0",
2177 "brace_indent=0",
2178 "eat_pp_space=1",
2179 "align_on_parens=1",
2180 "continuation_indent=0",
2181 "cuddle_else=0",
2182 "nopad_condition=1",
2183 "pad_condition=0",
2184 "indent_col1_comments=0"
2185 }
2186 }
2187};
2188
2189
2190static void k_styles_create()
2191{
2192 /*
2193 * Find user format ini file.
2194 */
2195 _str userini = maybe_quote_filename(_config_path():+'uformat.ini');
2196 if (file_match('-p 'userini, 1) == '')
2197 {
2198 _str ini = maybe_quote_filename(slick_path_search('uformat.ini'));
2199 if (ini != '') userini = ini;
2200 }
2201
2202
2203 /*
2204 * Remove any old schemes.
2205 */
2206 int i,j,tv;
2207 for (i = 0; i < StyleSchemes._length(); i++)
2208 for (j = 0; j < StyleLanguages._length(); j++)
2209 {
2210 _str sectionname = StyleLanguages[j]:+'-scheme-':+StyleSchemes[i].name;
2211 if (!_ini_get_section(userini, sectionname, tv))
2212 {
2213 _ini_delete_section(userini, sectionname);
2214 _delete_temp_view(tv);
2215 //message("delete old scheme");
2216 }
2217 }
2218
2219 /*
2220 * Create the new schemes.
2221 */
2222 for (i = 0; i < StyleSchemes._length(); i++)
2223 {
2224 for (j = 0; j < StyleLanguages._length(); j++)
2225 {
2226 _str sectionname = StyleLanguages[j]:+'-scheme-':+StyleSchemes[i].name;
2227 int temp_view_id, k;
2228 _str orig_view_id = _create_temp_view(temp_view_id);
2229 activate_view(temp_view_id);
2230 for (k = 0; k < StyleSchemes[i].settings._length(); k++)
2231 insert_line(StyleSchemes[i].settings[k]);
2232
2233 /* Insert the scheme section. */
2234 _ini_replace_section(userini, sectionname, temp_view_id);
2235 //message(userini)
2236 //bogus id - activate_view(orig_view_id);
2237 }
2238 }
2239
2240 //last_scheme = last scheme name!!!
2241}
2242
2243
2244/*
2245 * Sets the last used beutify scheme.
2246 */
2247static k_styles_set(_str scheme)
2248{
2249
2250 /*
2251 * Find user format ini file.
2252 */
2253 _str userini = maybe_quote_filename(_config_path():+'uformat.ini');
2254 if (file_match('-p 'userini, 1) == '')
2255 {
2256 _str ini = maybe_quote_filename(slick_path_search('uformat.ini'));
2257 if (ini != '') userini = ini;
2258 }
2259
2260 /*
2261 * Set the scheme for each language.
2262 */
2263 int j;
2264 for (j = 0; j < StyleLanguages._length(); j++)
2265 {
2266 _ini_set_value(userini,
2267 StyleLanguages[j]:+'-scheme-Default',
2268 'last_scheme',
2269 scheme);
2270 }
2271}
2272
2273
2274static _str defoptions[] =
2275{
2276 "def-options-sas",
2277 "def-options-js",
2278 "def-options-bat",
2279 "def-options-c",
2280 "def-options-pas",
2281 "def-options-e",
2282 "def-options-java",
2283 "def-options-bourneshell",
2284 "def-options-csh",
2285 "def-options-vlx",
2286 "def-options-plsql",
2287 "def-options-sqlserver",
2288 "def-options-cmd"
2289};
2290
2291static _str defsetups[] =
2292{
2293 "def-setup-sas",
2294 "def-setup-js",
2295 "def-setup-bat",
2296 "def-setup-fundamental",
2297 "def-setup-process",
2298 "def-setup-c",
2299 "def-setup-pas",
2300 "def-setup-e",
2301 "def-setup-asm",
2302 "def-setup-java",
2303 "def-setup-html",
2304 "def-setup-bourneshell",
2305 "def-setup-csh",
2306 "def-setup-vlx",
2307 "def-setup-fileman",
2308 "def-setup-plsql",
2309 "def-setup-sqlserver",
2310 "def-setup-s",
2311 "def-setup-cmd"
2312};
2313
2314static _str defsetupstab8[] =
2315{
2316 "def-setup-c"
2317};
2318
2319
2320static void k_styles_setindent(int indent, int iBraceStyle, boolean iWithTabs = false)
2321{
2322 if (iBraceStyle < 1 || iBraceStyle > 3)
2323 {
2324 message('k_styles_setindent: iBraceStyle is bad (=' :+ iBraceStyle :+ ')');
2325 iBraceStyle = 2;
2326 }
2327
2328 /*
2329 * def-options for extentions known to have that info.
2330 */
2331 int i;
2332 for (i = 0; i < defoptions._length(); i++)
2333 {
2334 int idx = find_index(defoptions[i], MISC_TYPE);
2335 if (!idx)
2336 continue;
2337
2338 parse name_info(idx) with syntax_indent o2 o3 o4 flags indent_fl o7 indent_case rest;
2339
2340 /* Begin/end style */
2341 flags = flags & ~(1|2);
2342 flags = flags | (iBraceStyle - 1); /* Set style (0-based) */
2343 flags = flags & ~(16); /* no scape before parent.*/
2344 indent_fl = 1; /* Indent first level */
2345 indent_case = 1; /* Indent case from switch */
2346
2347 sNewOptions = indent' 'o2' 'o3' 'o4' 'flags' 'indent_fl' 'o7' 'indent_case' 'rest;
2348 set_name_info(idx, sNewOptions);
2349 _config_modify |= CFGMODIFY_DEFDATA;
2350 }
2351
2352 /*
2353 * def-setup for known extentions.
2354 */
2355 for (i = 0; i < defsetups._length(); i++)
2356 {
2357 idx = find_index(defsetups[i], MISC_TYPE);
2358 if (!idx)
2359 continue;
2360 sExt = substr(defsetups[i], length('def-setup-') + 1);
2361 sSetup = name_info(idx);
2362
2363 /*
2364 parse sSetup with 'MN=' mode_name ','\
2365 'TABS=' tabs ',' 'MA=' margins ',' 'KEYTAB=' keytab_name ','\
2366 'WW='word_wrap_style ',' 'IWT='indent_with_tabs ','\
2367 'ST='show_tabs ',' 'IN='indent_style ','\
2368 'WC='word_chars',' 'LN='lexer_name',' 'CF='color_flags','\
2369 'LNL='line_numbers_len','rest;
2370
2371 indent_with_tabs = 0; /* Indent with tabs */
2372
2373 /* Make sure all the values are legal */
2374 _ext_init_values(ext, lexer_name, color_flags);
2375 if (!isinteger(line_numbers_len)) line_numbers_len = 0;
2376 if (word_chars == '') word_chars = 'A-Za-z0-9_$';
2377 if (word_wrap_style == '') word_wrap_style = 3;
2378 if (show_tabs == '') show_tabs = 0;
2379 if (indent_style == '') indent_style = INDENT_SMART;
2380
2381 /* Set new indent */
2382 tabs = '+'indent;
2383 */
2384
2385 sNewSetup = sSetup;
2386
2387 /* Set new indent */
2388 if (pos('TABS=', sNewSetup) > 0)
2389 {
2390 /*
2391 * If either in defoptions or defsetupstab8 use default tab of 8
2392 * For those supporting separate syntax indent using the normal tabsize
2393 * helps us a lot when reading it...
2394 */
2395 fTab8 = false;
2396 for (j = 0; !fTab8 && j < defsetupstab8._length(); j++)
2397 if (substr(defsetupstab8[j], lastpos('-', defsetupstab8[j]) + 1) == sExt)
2398 fTab8 = true;
2399 for (j = 0; !fTab8 && j < defoptions._length(); j++)
2400 if (substr(defoptions[j], lastpos('-', defoptions[j]) + 1) == sExt)
2401 fTab8 = true;
2402
2403 parse sNewSetup with sPre 'TABS=' sValue ',' sPost;
2404 if (fTab8)
2405 sNewSetup = sPre 'TABS=+8,' sPost
2406 else
2407 sNewSetup = sPre 'TABS=+' indent ',' sPost
2408 }
2409
2410 /* Set indent with tabs flag. */
2411 if (pos('IWT=', sNewSetup) > 0)
2412 {
2413 parse sNewSetup with sPre 'IWT=' sValue ',' sPost;
2414 if (iWithTabs)
2415 sNewSetup = sPre 'IWT=1,' sPost
2416 else
2417 sNewSetup = sPre 'IWT=0,' sPost
2418 }
2419
2420 /* Do the real changes */
2421 set_name_info(idx, sNewSetup);
2422 _config_modify |= CFGMODIFY_DEFDATA;
2423 _update_buffers(sExt);
2424 }
2425}
2426
2427
2428/**
2429 * Takes necessary steps to convert a string to integer.
2430 */
2431static int k_style_emacs_var_integer(_str sVal)
2432{
2433 int i = (int)sVal;
2434 //say 'k_style_emacs_var_integer('sVal') -> 'i;
2435 return (int)sVal;
2436}
2437
2438
2439/**
2440 * Sets a Emacs style variable.
2441 */
2442static int k_style_emacs_var(_str sVar, _str sVal)
2443{
2444 /* check input. */
2445 if (sVar == '' || sVal == '')
2446 return -1;
2447 //say 'k_style_emacs_var: 'sVar'='sVal;
2448
2449 /*
2450 * Unpack the mode style parameters.
2451 */
2452 _str sStyle = name_info(_edit_window().p_index);
2453 _str sStyleName = p_mode_name;
2454 typeless iIndentAmount, fExpansion, iMinAbbrivation, fIndentAfterOpenParen, iBeginEndStyle, fIndent1stLevel, iMainStyle, iSwitchStyle,
2455 sRest, sRes0, sRes1;
2456 if (sStyleName == 'Slick-C')
2457 {
2458 parse sStyle with iMinAbbrivation sRes0 iBeginEndStyle fIndent1stLevel sRes1 iSwitchStyle sRest;
2459 iIndentAmount = p_SyntaxIndent;
2460 }
2461 else /* C */
2462 parse sStyle with iIndentAmount fExpansion iMinAbbrivation fIndentAfterOpenParen iBeginEndStyle fIndent1stLevel iMainStyle iSwitchStyle sRest;
2463
2464
2465 /*
2466 * Process the variable.
2467 */
2468 switch (sVar)
2469 {
2470 case 'mode':
2471 case 'Mode':
2472 {
2473 switch (sVal)
2474 {
2475 case 'c':
2476 case 'C':
2477 case 'c++':
2478 case 'C++':
2479 case 'cpp':
2480 case 'CPP':
2481 case 'cxx':
2482 case 'CXX':
2483 p_extension = 'c';
2484 p_mode_name = 'C';
2485 break;
2486
2487 case 'e':
2488 case 'slick-c':
2489 case 'Slick-c':
2490 case 'Slick-C':
2491 p_extension = 'e';
2492 p_mode_name = 'Slick-C';
2493 break;
2494
2495 default:
2496 message('emacs mode "'sVal'" is not known to us');
2497 return -3;
2498 }
2499 break;
2500 }
2501/* relevant emacs code:
2502(defconst c-style-alist
2503 '(("gnu"
2504 (c-basic-offset . 2)
2505 (c-comment-only-line-offset . (0 . 0))
2506 (c-offsets-alist . ((statement-block-intro . +)
2507 (knr-argdecl-intro . 5)
2508 (substatement-open . +)
2509 (label . 0)
2510 (statement-case-open . +)
2511 (statement-cont . +)
2512 (arglist-intro . c-lineup-arglist-intro-after-paren)
2513 (arglist-close . c-lineup-arglist)
2514 (inline-open . 0)
2515 (brace-list-open . +)
2516 ))
2517 (c-special-indent-hook . c-gnu-impose-minimum)
2518 (c-block-comment-prefix . "")
2519 )
2520 ("k&r"
2521 (c-basic-offset . 5)
2522 (c-comment-only-line-offset . 0)
2523 (c-offsets-alist . ((statement-block-intro . +)
2524 (knr-argdecl-intro . 0)
2525 (substatement-open . 0)
2526 (label . 0)
2527 (statement-cont . +)
2528 ))
2529 )
2530 ("bsd"
2531 (c-basic-offset . 8)
2532 (c-comment-only-line-offset . 0)
2533 (c-offsets-alist . ((statement-block-intro . +)
2534 (knr-argdecl-intro . +)
2535 (substatement-open . 0)
2536 (label . 0)
2537 (statement-cont . +)
2538 (inline-open . 0)
2539 (inexpr-class . 0)
2540 ))
2541 )
2542 ("stroustrup"
2543 (c-basic-offset . 4)
2544 (c-comment-only-line-offset . 0)
2545 (c-offsets-alist . ((statement-block-intro . +)
2546 (substatement-open . 0)
2547 (label . 0)
2548 (statement-cont . +)
2549 ))
2550 )
2551 ("whitesmith"
2552 (c-basic-offset . 4)
2553 (c-comment-only-line-offset . 0)
2554 (c-offsets-alist . ((knr-argdecl-intro . +)
2555 (label . 0)
2556 (statement-cont . +)
2557 (substatement-open . +)
2558 (block-open . +)
2559 (statement-block-intro . c-lineup-whitesmith-in-block)
2560 (block-close . c-lineup-whitesmith-in-block)
2561 (inline-open . +)
2562 (defun-open . +)
2563 (defun-block-intro . c-lineup-whitesmith-in-block)
2564 (defun-close . c-lineup-whitesmith-in-block)
2565 (brace-list-open . +)
2566 (brace-list-intro . c-lineup-whitesmith-in-block)
2567 (brace-entry-open . c-indent-multi-line-block)
2568 (brace-list-close . c-lineup-whitesmith-in-block)
2569 (class-open . +)
2570 (inclass . c-lineup-whitesmith-in-block)
2571 (class-close . +)
2572 (inexpr-class . 0)
2573 (extern-lang-open . +)
2574 (inextern-lang . c-lineup-whitesmith-in-block)
2575 (extern-lang-close . +)
2576 (namespace-open . +)
2577 (innamespace . c-lineup-whitesmith-in-block)
2578 (namespace-close . +)
2579 ))
2580 )
2581 ("ellemtel"
2582 (c-basic-offset . 3)
2583 (c-comment-only-line-offset . 0)
2584 (c-hanging-braces-alist . ((substatement-open before after)))
2585 (c-offsets-alist . ((topmost-intro . 0)
2586 (topmost-intro-cont . 0)
2587 (substatement . +)
2588 (substatement-open . 0)
2589 (case-label . +)
2590 (access-label . -)
2591 (inclass . ++)
2592 (inline-open . 0)
2593 ))
2594 )
2595 ("linux"
2596 (c-basic-offset . 8)
2597 (c-comment-only-line-offset . 0)
2598 (c-hanging-braces-alist . ((brace-list-open)
2599 (brace-entry-open)
2600 (substatement-open after)
2601 (block-close . c-snug-do-while)))
2602 (c-cleanup-list . (brace-else-brace))
2603 (c-offsets-alist . ((statement-block-intro . +)
2604 (knr-argdecl-intro . 0)
2605 (substatement-open . 0)
2606 (label . 0)
2607 (statement-cont . +)
2608 ))
2609 )
2610 ("python"
2611 (indent-tabs-mode . t)
2612 (fill-column . 78)
2613 (c-basic-offset . 8)
2614 (c-offsets-alist . ((substatement-open . 0)
2615 (inextern-lang . 0)
2616 (arglist-intro . +)
2617 (knr-argdecl-intro . +)
2618 ))
2619 (c-hanging-braces-alist . ((brace-list-open)
2620 (brace-list-intro)
2621 (brace-list-close)
2622 (brace-entry-open)
2623 (substatement-open after)
2624 (block-close . c-snug-do-while)
2625 ))
2626 (c-block-comment-prefix . "")
2627 )
2628 ("java"
2629 (c-basic-offset . 4)
2630 (c-comment-only-line-offset . (0 . 0))
2631 ;; the following preserves Javadoc starter lines
2632 (c-offsets-alist . ((inline-open . 0)
2633 (topmost-intro-cont . +)
2634 (statement-block-intro . +)
2635 (knr-argdecl-intro . 5)
2636 (substatement-open . +)
2637 (label . +)
2638 (statement-case-open . +)
2639 (statement-cont . +)
2640 (arglist-intro . c-lineup-arglist-intro-after-paren)
2641 (arglist-close . c-lineup-arglist)
2642 (access-label . 0)
2643 (inher-cont . c-lineup-java-inher)
2644 (func-decl-cont . c-lineup-java-throws)
2645 ))
2646 )
2647 )
2648*/
2649
2650 case 'c-file-style':
2651 case 'c-indentation-style':
2652 switch (sVal)
2653 {
2654 case 'bsd':
2655 case '"bsd"':
2656 case 'BSD':
2657 iBeginEndStyle = 1 | (iBeginEndStyle & ~3);
2658 p_indent_with_tabs = true;
2659 iIndentAmount = 8;
2660 p_SyntaxIndent = 8;
2661 p_tabs = "+8";
2662 //say 'bsd';
2663 break;
2664
2665 case 'k&r':
2666 case '"k&r"':
2667 case 'K&R':
2668 iBeginEndStyle = 0 | (iBeginEndStyle & ~3);
2669 p_indent_with_tabs = false;
2670 iIndentAmount = 4;
2671 p_SyntaxIndent = 4;
2672 p_tabs = "+4";
2673 //say 'k&r';
2674 break;
2675
2676 case 'linux-c':
2677 case '"linux-c"':
2678 iBeginEndStyle = 0 | (iBeginEndStyle & ~3);
2679 p_indent_with_tabs = true;
2680 iIndentAmount = 4;
2681 p_SyntaxIndent = 4;
2682 p_tabs = "+4";
2683 //say 'linux-c';
2684 break;
2685
2686 case 'yet-to-be-found':
2687 iBeginEndStyle = 2 | (iBeginEndStyle & ~3);
2688 p_indent_with_tabs = false;
2689 iIndentAmount = 4;
2690 p_SyntaxIndent = 4;
2691 p_tabs = "+4";
2692 //say 'todo';
2693 break;
2694
2695 default:
2696 message('emacs "'sVar'" value "'sVal'" is not known to us.');
2697 return -3;
2698 }
2699 break;
2700
2701 case 'c-label-offset':
2702 {
2703 int i = k_style_emacs_var_integer(sVal);
2704 if (i >= -16 && i <= 16)
2705 {
2706 if (i == -p_SyntaxIndent)
2707 iSwitchStyle = 0;
2708 else
2709 iSwitchStyle = 1;
2710 }
2711 break;
2712 }
2713
2714
2715 case 'indent-tabs-mode':
2716 p_indent_with_tabs = sVal == 't';
2717 break;
2718
2719 case 'c-indent-level':
2720 case 'c-basic-offset':
2721 {
2722 int i = k_style_emacs_var_integer(sVal);
2723 if (i > 0 && i <= 16)
2724 {
2725 iIndentAmount = i;
2726 p_SyntaxIndent = i;
2727 }
2728 else
2729 {
2730 message('emacs "'sVar'" value "'sVal'" is out of range.');
2731 return -4;
2732 }
2733 break;
2734 }
2735
2736 case 'tab-width':
2737 {
2738 int i = k_style_emacs_var_integer(sVal);
2739 if (i > 0 && i <= 16)
2740 p_tabs = '+'i;
2741 else
2742 {
2743 message('emacs "'sVar'" value "'sVal'" is out of range.');
2744 return -4;
2745 }
2746 break;
2747 }
2748
2749 case 'nuke-trailing-whitespace-p':
2750 {
2751#if 0
2752 _str sName = 'def-koptions-'p_buf_id;
2753 int idx = insert_name(sName, MISC_TYPE, "kstyledoc");
2754 if (!idx)
2755 idx = find_index(sName, MISC_TYPE);
2756 if (idx)
2757 {
2758 if (sVal == 't')
2759 set_name_info(idx, "saveoptions: +S");
2760 else
2761 set_name_info(idx, "saveoptions: -S");
2762 say 'sVal=' sVal;
2763 }
2764#endif
2765 break;
2766 }
2767
2768 default:
2769 message('emacs variable "'sVar'" (value "'sVal'") is unknown to us.');
2770 return -5;
2771 }
2772
2773 /*
2774 * Update the style?
2775 */
2776 _str sNewStyle = "";
2777 if (sStyleName == 'Slick-C')
2778 sNewStyle = iMinAbbrivation' 'sRes0' 'iBeginEndStyle' 'fIndent1stLevel' 'sRes1' 'iSwitchStyle' 'sRest;
2779 else
2780 sNewStyle = iIndentAmount' 'fExpansion' 'iMinAbbrivation' 'fIndentAfterOpenParen' 'iBeginEndStyle' 'fIndent1stLevel' 'iMainStyle' 'iSwitchStyle' 'sRest;
2781 if ( sNewStyle != ""
2782 && sNewStyle != sStyle
2783 && sStyleName == p_mode_name)
2784 {
2785 _str sName = name_name(_edit_window().p_index)
2786 //say ' sStyle='sStyle' p_mode_name='p_mode_name;
2787 //say 'sNewStyle='sNewStyle' sName='sName;
2788 if (pos('kstyledoc-', sName) <= 0)
2789 {
2790 sName = 'def-kstyledoc-'p_buf_id;
2791 int idx = insert_name(sName, MISC_TYPE, "kstyledoc");
2792 if (!idx)
2793 idx = find_index(sName, MISC_TYPE);
2794 if (idx)
2795 {
2796 if (!set_name_info(idx, sNewStyle))
2797 _edit_window().p_index = idx;
2798 }
2799 //say sName'='idx;
2800 }
2801 else
2802 set_name_info(_edit_window().p_index, sNewStyle);
2803 }
2804
2805 return 0;
2806}
2807
2808
2809/**
2810 * Parses a string with emacs variables.
2811 *
2812 * The variables are separated by new line. Junk at
2813 * the start and end of the line is ignored.
2814 */
2815static int k_style_emac_vars(_str sVars)
2816{
2817 /* process them line by line */
2818 int iLine = 0;
2819 while (sVars != '' && iLine++ < 20)
2820 {
2821 int iNext, iEnd;
2822 iEnd = iNext = pos("\n", sVars);
2823 if (iEnd <= 0)
2824 iEnd = iNext = length(sVars);
2825 else
2826 iEnd--;
2827 iNext++;
2828
2829 sLine = strip(substr(sVars, 1, iEnd), 'B', " \t\n\r");
2830 sVars = strip(substr(sVars, iNext), 'L', " \t\n\r");
2831 //say 'iLine='iLine' sVars='sVars'<eol>';
2832 //say 'iLine='iLine' sLine='sLine'<eol>';
2833 if (sLine != '')
2834 {
2835 rc = pos('[^a-zA-Z0-9-_]*([a-zA-Z0-9-_]+)[ \t]*:[ \t]*([^ \t]*)', sLine, 1, 'U');
2836 //say '0={'pos('S0')','pos('0')',"'substr(sLine,pos('S0'),pos('0'))'"'
2837 //say '1={'pos('S1')','pos('1')',"'substr(sLine,pos('S1'),pos('1'))'"'
2838 //say '2={'pos('S2')','pos('2')',"'substr(sLine,pos('S2'),pos('2'))'"'
2839 //say '3={'pos('S3')','pos('3')',"'substr(sLine,pos('S3'),pos('3'))'"'
2840 //say '4={'pos('S4')','pos('4')',"'substr(sLine,pos('S4'),pos('4'))'"'
2841 if (rc > 0)
2842 k_style_emacs_var(substr(sLine,pos('S1'),pos('1')),
2843 substr(sLine,pos('S2'),pos('2')));
2844 }
2845 }
2846 return 0;
2847}
2848
2849/**
2850 * Searches for Emacs style specification for the current document.
2851 */
2852void k_style_load()
2853{
2854 /* save the position before we start looking around the file. */
2855 typeless saved_pos;
2856 _save_pos2(saved_pos);
2857
2858 int rc;
2859
2860 /* Check first line. */
2861 top_of_buffer();
2862 _str sLine;
2863 get_line(sLine);
2864 strip(sLine);
2865 if (pos('-*-[ \t]+(.*:.*)[ \t]+-*-', sLine, 1, 'U'))
2866 {
2867 _str sVars;
2868 sVars = substr(sLine, pos('S1'), pos('1'));
2869 sVars = translate(sVars, "\n", ";");
2870 k_style_emac_vars(sVars);
2871 }
2872
2873 /* Look for the "Local Variables:" stuff from the end of the file. */
2874 bottom_of_buffer();
2875 rc = search('Local Variables:[ \t]*\n\om(.*)\ol\n.*End:.*\n', '-EU');
2876 if (!rc)
2877 {
2878 /* copy the variables out to a buffer. */
2879 _str sVars;
2880 sVars = get_text(match_length("1"), match_length("S1"));
2881 k_style_emac_vars(sVars);
2882 }
2883
2884 _restore_pos2(saved_pos);
2885}
2886
2887
2888/**
2889 * Callback function for the event of a new buffer.
2890 *
2891 * This is used to make sure there are no left over per buffer options
2892 * hanging around.
2893 */
2894void _buffer_add_kdev(int buf_id)
2895{
2896 _str sName = 'def-koptions-'buf_id;
2897 int idx = find_index(sName, MISC_TYPE);
2898 if (idx)
2899 delete_name(idx);
2900 //message("_buffer_add_kdev: " idx " name=" sName);
2901
2902 sName = 'def-kstyledoc-'buf_id;
2903 idx = find_index(sName, MISC_TYPE);
2904 if (idx)
2905 delete_name(idx);
2906
2907 //k_style_load();
2908}
2909
2910
2911/**
2912 * Callback function for the event of quitting a buffer.
2913 *
2914 * This is used to make sure there are no left over per buffer options
2915 * hanging around.
2916 */
2917void _cbquit2_kdev(int buf_id)
2918{
2919 _str sName = 'def-koptions-'buf_id;
2920 int idx = find_index(sName, MISC_TYPE);
2921 if (idx)
2922 delete_name(idx);
2923 //message("_cbquit2_kdev: " idx " " sName);
2924
2925 sName = 'def-kstyledoc-'buf_id;
2926 idx = find_index(sName, MISC_TYPE);
2927 if (idx)
2928 delete_name(idx);
2929}
2930
2931
2932/**
2933 * Called to get save options for the current buffer.
2934 *
2935 * This requires a modified loadsave.e!
2936 */
2937_str _buffer_save_kdev(int buf_id)
2938{
2939 _str sRet = ""
2940 _str sName = 'def-koptions-'buf_id;
2941 int idx = find_index(sName, MISC_TYPE);
2942 if (idx)
2943 {
2944 _str sOptions = strip(name_info(idx));
2945 if (sOptions != "")
2946 parse sOptions with . "saveoptions:" sRet .
2947 message("_buffer_save_kdev: " idx " " sName " " sOptions);
2948 }
2949 return sRet;
2950}
2951
2952
2953/**
2954 * Command similar to the add() command in math.e, only this
2955 * produces hex and doesn't do the multi line stuff.
2956 */
2957_command int k_calc()
2958{
2959 _str sLine;
2960 filter_init();
2961 typeless rc = filter_get_string(sLine);
2962 if (rc == 0)
2963 {
2964 _str sResultHex;
2965 rc = eval_exp(sResultHex, sLine, 16);
2966 if (rc == 0)
2967 {
2968 _str sResultDec;
2969 rc = eval_exp(sResultDec, sLine, 10);
2970 if (rc == 0)
2971 {
2972 _end_select();
2973 _insert_text(' = ' :+ sResultHex :+ ' (' :+ sResultDec :+ ')');
2974 return 0;
2975 }
2976 }
2977 }
2978
2979 if (isinteger(rc))
2980 message(get_message(rc));
2981 else
2982 message(rc);
2983 return 1;
2984}
2985
2986
2987
2988/*******************************************************************************
2989* Menu and Menu commands *
2990*******************************************************************************/
2991#ifdef KDEV_WITH_MENU
2992#if __VERSION__ < 18.0 /* Something with timers are busted, so excusing my code. */
2993static int iTimer = 0;
2994#endif
2995static int mhkDev = 0;
2996static int mhCode = 0;
2997static int mhDoc = 0;
2998static int mhLic = 0;
2999static int mhPre = 0;
3000
3001/*
3002 * Creates the kDev menu.
3003 */
3004static k_menu_create()
3005{
3006# if __VERSION__ < 18.0 /* Something with timers are busted, so excusing my code. */
3007 if (arg(1) == 'timer')
3008 _kill_timer(iTimer);
3009# endif
3010 menu_handle = _mdi.p_menu_handle;
3011 menu_index = find_index(_cur_mdi_menu,oi2type(OI_MENU));
3012
3013 /*
3014 * Remove any old menu.
3015 */
3016 mhDelete = iPos = 0;
3017 index = _menu_find(menu_handle, "kDev", mhDelete, iPos, 'C');
3018 //message("index="index " mhDelete="mhDelete " iPos="iPos);
3019 if (index == 0)
3020 _menu_delete(mhDelete, iPos);
3021
3022
3023 /*
3024 * Insert the "kDev" menu.
3025 */
3026 mhkDev = _menu_insert(menu_handle, 9, MF_SUBMENU, "&kDev", "", "kDev");
3027 mhCode=_menu_insert(mhkDev, -1, MF_ENABLED | MF_SUBMENU, "Coding &Style", "", "coding");
3028 rc = _menu_insert(mhCode, -1, MF_ENABLED | MF_UNCHECKED, "Braces 2, Syntax Indent 4 (knut)", "k_menu_style Opt2Ind4", "Opt2Ind4");
3029 rc = _menu_insert(mhCode, -1, MF_ENABLED | MF_UNCHECKED, "Braces 2, Syntax Indent 3", "k_menu_style Opt2Ind3", "Opt2Ind3");
3030 rc = _menu_insert(mhCode, -1, MF_ENABLED | MF_UNCHECKED, "Braces 2, Syntax Indent 8", "k_menu_style Opt2Ind8", "Opt2Ind8");
3031 rc = _menu_insert(mhCode, -1, MF_ENABLED | MF_UNCHECKED, "Braces 3, Syntax Indent 4 (giws)", "k_menu_style Opt3Ind4", "Opt3Ind4");
3032 rc = _menu_insert(mhCode, -1, MF_ENABLED | MF_UNCHECKED, "Braces 3, Syntax Indent 3 (giws)", "k_menu_style Opt3Ind3", "Opt3Ind3");
3033
3034 mhDoc= _menu_insert(mhkDev, -1, MF_ENABLED | MF_SUBMENU, "&Documentation", "", "doc");
3035 mhDSJ= _menu_insert(mhDoc, -1, MF_ENABLED | MF_UNCHECKED, "&Javadoc Style", "k_menu_doc_style javadoc", "javadoc");
3036 mhDSL= _menu_insert(mhDoc, -1, MF_GRAYED | MF_UNCHECKED, "&Linux Kernel Style", "k_menu_doc_style linux", "linux");
3037
3038 mhLic= _menu_insert(mhkDev, -1, MF_ENABLED | MF_SUBMENU, "&License", "", "License");
3039 rc = _menu_insert(mhLic, -1, MF_ENABLED | MF_UNCHECKED, "&Odin32", "k_menu_license Odin32", "Odin32");
3040 rc = _menu_insert(mhLic, -1, MF_ENABLED | MF_UNCHECKED, "&GPL", "k_menu_license GPL", "GPL");
3041 rc = _menu_insert(mhLic, -1, MF_ENABLED | MF_UNCHECKED, "&LGPL", "k_menu_license LGPL", "LGPL");
3042 rc = _menu_insert(mhLic, -1, MF_ENABLED | MF_UNCHECKED, "&GPLv3", "k_menu_license GPLv3", "GPLv3");
3043 rc = _menu_insert(mhLic, -1, MF_ENABLED | MF_UNCHECKED, "&LGPLv3", "k_menu_license LGPLv3", "LGPLv3");
3044 rc = _menu_insert(mhLic, -1, MF_ENABLED | MF_UNCHECKED, "&VirtualBox", "k_menu_license VirtualBox", "VirtualBox");
3045 rc = _menu_insert(mhLic, -1, MF_ENABLED | MF_UNCHECKED, "&VirtualBox GPL And CDDL","k_menu_license VirtualBoxGPLAndCDDL", "VirtualBoxGPLAndCDDL");
3046 rc = _menu_insert(mhLic, -1, MF_ENABLED | MF_UNCHECKED, "&Confidential", "k_menu_license Confidential", "Confidential");
3047 rc = _menu_insert(mhLic, -1, MF_ENABLED | MF_UNCHECKED, "&Confidential No Author", "k_menu_license ConfidentialNoAuthor", "ConfidentialNoAuthor");
3048
3049 rc = _menu_insert(mhkDev, -1, MF_ENABLED, "-", "", "dash vars");
3050 rc = _menu_insert(mhkDev, -1, MF_ENABLED, skChange == '' ? '&Change...' : '&Change (' skChange ')...', "k_menu_change", "");
3051 rc = _menu_insert(mhkDev, -1, MF_ENABLED, skProgram == '' ? '&Program...' : '&Program (' skProgram ')...', "k_menu_program", "");
3052 rc = _menu_insert(mhkDev, -1, MF_ENABLED, skCompany == '' ? 'Co&mpany...' : 'Co&mpany (' skCompany ')...', "k_menu_company", "");
3053 rc = _menu_insert(mhkDev, -1, MF_ENABLED, '&User Name (' skUserName ')...', "k_menu_user_name", "username");
3054 rc = _menu_insert(mhkDev, -1, MF_ENABLED, 'User &e-mail (' skUserEmail ')...', "k_menu_user_email", "useremail");
3055 rc = _menu_insert(mhkDev, -1, MF_ENABLED, 'User &Initials (' skUserInitials ')...', "k_menu_user_initials", "userinitials");
3056 rc = _menu_insert(mhkDev, -1, MF_ENABLED, "-", "", "dash preset");
3057 mhPre= _menu_insert(mhkDev, -1, MF_SUBMENU, "P&resets", "", "");
3058 rc = _menu_insert(mhPre, -1, MF_ENABLED, "The Bird", "k_menu_preset javadoc, GPL, Opt2Ind4", "bird");
3059 rc = _menu_insert(mhPre, -1, MF_ENABLED, "kLIBC", "k_menu_preset javadoc, GPL, Opt2Ind4,, kLIBC", "kLIBC");
3060 rc = _menu_insert(mhPre, -1, MF_ENABLED, "kBuild", "k_menu_preset javadoc, GPLv3, Opt2Ind4,, kBuild", "kBuild");
3061 rc = _menu_insert(mhPre, -1, MF_ENABLED, "kStuff", "k_menu_preset javadoc, GPL, Opt2Ind4,, kStuff", "kStuff");
3062 rc = _menu_insert(mhPre, -1, MF_ENABLED, "sun", "k_menu_preset javadoc, ConfidentialNoAuthor, Opt2Ind4, sun", "sun");
3063 rc = _menu_insert(mhPre, -1, MF_ENABLED, "VirtualBox", "k_menu_preset javadoc, VirtualBox, Opt2Ind4, sun", "VirtualBox");
3064
3065 k_menu_doc_style();
3066 k_menu_license();
3067 k_menu_style();
3068}
3069
3070
3071/**
3072 * Change change Id.
3073 */
3074_command k_menu_change()
3075{
3076 sRc = show("-modal k_form_simple_input", "Change ID", skChange);
3077 if (sRc != "\r")
3078 {
3079 skChange = sRc;
3080 k_menu_create();
3081 }
3082}
3083
3084
3085/**
3086 * Change program name.
3087 */
3088_command k_menu_program()
3089{
3090 sRc = show("-modal k_form_simple_input", "Program", skProgram);
3091 if (sRc != "\r")
3092 {
3093 skProgram = sRc;
3094 k_menu_create();
3095 }
3096}
3097
3098
3099/**
3100 * Change company.
3101 */
3102_command k_menu_company()
3103{
3104 if (skCompany == '')
3105 sRc = show("-modal k_form_simple_input", "Company", 'innotek GmbH');
3106 else
3107 sRc = show("-modal k_form_simple_input", "Company", skCompany);
3108 if (sRc != "\r")
3109 {
3110 skCompany = sRc;
3111 k_menu_create();
3112 }
3113}
3114
3115
3116/**
3117 * Change user name.
3118 */
3119_command k_menu_user_name()
3120{
3121 sRc = show("-modal k_form_simple_input", "User Name", skUserName);
3122 if (sRc != "\r" && sRc != '')
3123 {
3124 skUserName = sRc;
3125 k_menu_create();
3126 }
3127}
3128
3129
3130/**
3131 * Change user email.
3132 */
3133_command k_menu_user_email()
3134{
3135 sRc = show("-modal k_form_simple_input", "User e-mail", skUserEmail);
3136 if (sRc != "\r" && sRc != '')
3137 {
3138 skUserEmail = sRc;
3139 k_menu_create();
3140 }
3141}
3142
3143
3144/**
3145 * Change user initials.
3146 */
3147_command k_menu_user_initials()
3148{
3149 sRc = show("-modal k_form_simple_input", "User e-mail", skUserInitials);
3150 if (sRc != "\r" && sRc != '')
3151 {
3152 skUserInitials = sRc;
3153 k_menu_create();
3154 }
3155}
3156
3157
3158
3159/**
3160 * Checks the correct menu item.
3161 */
3162_command void k_menu_doc_style(_str sNewDocStyle = '')
3163{
3164 //say 'sNewDocStyle='sNewDocStyle;
3165 if (sNewDocStyle != '')
3166 skDocStyle = sNewDocStyle
3167 _menu_set_state(mhDoc, "javadoc", MF_UNCHECKED);
3168 _menu_set_state(mhDoc, "linux", MF_UNCHECKED | MF_GRAYED);
3169
3170 _menu_set_state(mhDoc, skDocStyle, MF_CHECKED);
3171}
3172
3173
3174/**
3175 * Checks the correct menu item.
3176 */
3177_command void k_menu_license(_str sNewLicense = '')
3178{
3179 //say 'sNewLicense='sNewLicense;
3180 if (sNewLicense != '')
3181 skLicense = sNewLicense
3182 _menu_set_state(mhLic, "Odin32", MF_UNCHECKED);
3183 _menu_set_state(mhLic, "GPL", MF_UNCHECKED);
3184 _menu_set_state(mhLic, "LGPL", MF_UNCHECKED);
3185 _menu_set_state(mhLic, "GPLv3", MF_UNCHECKED);
3186 _menu_set_state(mhLic, "LGPLv3", MF_UNCHECKED);
3187 _menu_set_state(mhLic, "VirtualBox", MF_UNCHECKED);
3188 _menu_set_state(mhLic, "VirtualBoxGPLAndCDDL", MF_UNCHECKED);
3189 _menu_set_state(mhLic, "Confidential", MF_UNCHECKED);
3190 _menu_set_state(mhLic, "ConfidentialNoAuthor", MF_UNCHECKED);
3191
3192 _menu_set_state(mhLic, skLicense, MF_CHECKED);
3193}
3194
3195
3196/**
3197 * Check the correct style menu item.
3198 */
3199_command void k_menu_style(_str sNewStyle = '')
3200{
3201 //say 'sNewStyle='sNewStyle;
3202 _menu_set_state(mhCode, "Opt1Ind4", MF_UNCHECKED);
3203 _menu_set_state(mhCode, "Opt1Ind3", MF_UNCHECKED);
3204 _menu_set_state(mhCode, "Opt1Ind8", MF_UNCHECKED);
3205 _menu_set_state(mhCode, "Opt2Ind4", MF_UNCHECKED);
3206 _menu_set_state(mhCode, "Opt2Ind3", MF_UNCHECKED);
3207 _menu_set_state(mhCode, "Opt2Ind8", MF_UNCHECKED);
3208 _menu_set_state(mhCode, "Opt3Ind4", MF_UNCHECKED);
3209 _menu_set_state(mhCode, "Opt3Ind3", MF_UNCHECKED);
3210 _menu_set_state(mhCode, "Opt3Ind8", MF_UNCHECKED);
3211
3212 if (sNewStyle != '')
3213 {
3214 int iIndent = (int)substr(sNewStyle, 8, 1);
3215 int iBraceStyle = (int)substr(sNewStyle, 4, 1);
3216 skCodeStyle = sNewStyle;
3217 k_styles_setindent(iIndent, iBraceStyle);
3218 k_styles_set(sNewStyle);
3219 }
3220
3221 _menu_set_state(mhCode, skCodeStyle, MF_CHECKED);
3222}
3223
3224
3225/**
3226 * Load a 'preset'.
3227 */
3228_command void k_menu_preset(_str sArgs = '')
3229{
3230 parse sArgs with sNewDocStyle ',' sNewLicense ',' sNewStyle ',' sNewCompany ',' sNewProgram ',' sNewChange
3231 sNewDocStyle= strip(sNewDocStyle);
3232 sNewLicense = strip(sNewLicense);
3233 sNewStyle = strip(sNewStyle);
3234 sNewCompany = strip(sNewCompany);
3235 if (sNewCompany == 'sun')
3236 sNewCompany = 'Sun Microsystems, Inc.'
3237 sNewProgram = strip(sNewProgram);
3238 sNewChange = strip(sNewChange);
3239
3240 //say 'k_menu_preset('sNewDocStyle',' sNewLicense',' sNewStyle',' sNewCompany',' sNewProgram')';
3241 k_menu_doc_style(sNewDocStyle);
3242 k_menu_license(sNewLicense);
3243 k_menu_style(sNewStyle);
3244 skCompany = sNewCompany;
3245 skProgram = sNewProgram;
3246 skChange = sNewChange;
3247 k_menu_create();
3248}
3249
3250
3251
3252/* future ones..
3253_command k_menu_setcolor()
3254{
3255 createMyColorSchemeAndUseIt();
3256}
3257
3258
3259_command k_menu_setkeys()
3260{
3261 rc = load("d:/knut/VSlickMacros/BoxerDef.e");
3262}
3263
3264_command k_menu_settings()
3265{
3266 mySettings();
3267}
3268*/
3269
3270
3271#endif /* KDEV_WITH_MENU */
3272
3273
3274/*******************************************************************************
3275* Dialogs *
3276*******************************************************************************/
3277_form k_form_simple_input {
3278 p_backcolor=0x80000005
3279 p_border_style=BDS_DIALOG_BOX
3280 p_caption='Simple Input'
3281 p_clip_controls=FALSE
3282 p_forecolor=0x80000008
3283 p_height=1120
3284 p_width=5020
3285 p_x=6660
3286 p_y=6680
3287 _text_box entText {
3288 p_auto_size=TRUE
3289 p_backcolor=0x80000005
3290 p_border_style=BDS_FIXED_SINGLE
3291 p_completion=NONE_ARG
3292 p_font_bold=FALSE
3293 p_font_italic=FALSE
3294 p_font_name='MS Sans Serif'
3295 p_font_size=8
3296 p_font_underline=FALSE
3297 p_forecolor=0x80000008
3298 p_height=270
3299 p_tab_index=1
3300 p_tab_stop=TRUE
3301 p_text='text'
3302 p_width=3180
3303 p_x=1680
3304 p_y=240
3305 p_eventtab2=_ul2_textbox
3306 }
3307 _label lblLabel {
3308 p_alignment=AL_VCENTERRIGHT
3309 p_auto_size=FALSE
3310 p_backcolor=0x80000005
3311 p_border_style=BDS_NONE
3312 p_caption='Label'
3313 p_font_bold=FALSE
3314 p_font_italic=FALSE
3315 p_font_name='MS Sans Serif'
3316 p_font_size=8
3317 p_font_underline=FALSE
3318 p_forecolor=0x80000008
3319 p_height=240
3320 p_tab_index=2
3321 p_width=1380
3322 p_word_wrap=FALSE
3323 p_x=180
3324 p_y=240
3325 }
3326 _command_button btnOK {
3327 p_cancel=FALSE
3328 p_caption='&OK'
3329 p_default=TRUE
3330 p_font_bold=FALSE
3331 p_font_italic=FALSE
3332 p_font_name='MS Sans Serif'
3333 p_font_size=8
3334 p_font_underline=FALSE
3335 p_height=360
3336 p_tab_index=3
3337 p_tab_stop=TRUE
3338 p_width=1020
3339 p_x=180
3340 p_y=660
3341 }
3342 _command_button btnCancel {
3343 p_cancel=TRUE
3344 p_caption='Cancel'
3345 p_default=FALSE
3346 p_font_bold=FALSE
3347 p_font_italic=FALSE
3348 p_font_name='MS Sans Serif'
3349 p_font_size=8
3350 p_font_underline=FALSE
3351 p_height=360
3352 p_tab_index=4
3353 p_tab_stop=TRUE
3354 p_width=840
3355 p_x=1380
3356 p_y=660
3357 }
3358}
3359
3360defeventtab k_form_simple_input
3361btnOK.on_create(_str sLabel = '', _str sText = '')
3362{
3363 p_active_form.p_caption = sLabel;
3364 lblLabel.p_caption = sLabel;
3365 entText.p_text = sText;
3366}
3367
3368btnOK.lbutton_up()
3369{
3370 sText = entText.p_text;
3371 p_active_form._delete_window(sText);
3372}
3373btnCancel.lbutton_up()
3374{
3375 sText = entText.p_text;
3376 p_active_form._delete_window("\r");
3377}
3378
3379static _str aCLikeIncs[] =
3380{
3381 "c", "ansic", "java", "rul", "vera", "cs", "js", "as", "idl", "asm", "s", "imakefile", "rc", "lex", "yacc", "antlr"
3382};
3383
3384static _str aMyLangIds[] =
3385{
3386 "applescript",
3387 "ansic",
3388 "antlr",
3389 "as",
3390 "asm",
3391 "c",
3392 "cs",
3393 "csh",
3394 "css",
3395 "conf",
3396 "d",
3397 "docbook",
3398 "dtd",
3399 "e",
3400 "html",
3401 "idl",
3402 "imakefile",
3403 "ini",
3404 "java",
3405 "js",
3406 "lex",
3407 "mak",
3408 "masm",
3409 "pas",
3410 "phpscript",
3411 "powershell",
3412 "py",
3413 "rexx",
3414 "rc",
3415 "rul",
3416 "tcl",
3417 "s",
3418 "unixasm",
3419 "vbs",
3420 "xhtml",
3421 "xml",
3422 "xmldoc",
3423 "xsd",
3424 "yacc"
3425};
3426
3427#if __VERSION__ >= 17.0
3428# require "se/lang/api/LanguageSettings.e"
3429using se.lang.api.LanguageSettings;
3430#endif
3431
3432#if __VERSION__ >= 16.0
3433int def_auto_unsurround_block;
3434#endif
3435
3436/**
3437 * Loads the standard bird settings.
3438 */
3439_command void kdev_load_settings()
3440{
3441 typeless nt1;
3442 typeless nt2;
3443 typeless nt3;
3444 typeless nt4;
3445 typeless nt5;
3446 typeless nt6;
3447 typeless i7;
3448 _str sRest;
3449 _str sTmp;
3450
3451 /*
3452 * Generl stuff.
3453 */
3454 _default_option('A', '0'); /* ALT menu */
3455 def_alt_menu = 0;
3456 _default_option('R', '130'); /* Vertical line in column 130. */
3457 def_mfsearch_init_flags = 2 | 4; /* MFSEARCH_INIT_CURWORD | MFSEARCH_INIT_SELECTION */
3458 def_line_insert = 'B'; /* insert before */
3459 def_file_types='All Files (*),' /** @todo make this prettier */
3460 'C/C++ Files (*.c;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.h;*.hh;*.hpp;*.hxx;*.inl;*.xpm),'
3461 'Assembler (*.s;*.asm;*.mac;*.S),'
3462 'Makefiles (*;*.mak;*.kmk)'
3463 'C# Files (*.cs),'
3464 'Ch Files (*.ch;*.chf;*.chs;*.cpp;*.h),'
3465 'D Files (*.d),'
3466 'Java Files (*.java),'
3467 'HTML Files (*.htm;*.html;*.shtml;*.asp;*.jsp;*.php;*.php3;*.rhtml;*.css),'
3468 'CFML Files (*.cfm;*.cfml;*.cfc),'
3469 'XML Files (*.xml;*.dtd;*.xsd;*.xmldoc;*.xsl;*.xslt;*.ent;*.tld;*.xhtml;*.build;*.plist),'
3470 'XML/SGML DTD Files (*.xsd;*.dtd),'
3471 'XML/JSP TagLib Files (*.tld;*.xml),'
3472 'Objective-C (*.m;*.mm;*.h),'
3473 'IDL Files (*.idl),'
3474 'Ada Files (*.ada;*.adb;*.ads),'
3475 'Applescript Files (*.applescript),'
3476 'Basic Files (*.vb;*.vbs;*.bas;*.frm),'
3477 'Cobol Files (*.cob;*.cbl;*.ocb),'
3478 'JCL Files (*.jcl),'
3479 'JavaScript (*.js;*.ds),'
3480 'ActionScript (*.as),'
3481 'Pascal Files (*.pas;*.dpr),'
3482 'Fortran Files (*.for;*.f),'
3483 'PL/I Files (*.pl1),'
3484 'InstallScript (*.rul),'
3485 'Perl Files (*.pl;*.pm;*.perl;*.plx),'
3486 'Python Files (*.py),'
3487 'Ruby Files (*.rb;*.rby),'
3488 'Java Properties (*.properties),'
3489 'Lua Files (*.lua),'
3490 'Tcl Files (*.tcl;*.tlib;*.itk;*.itcl;*.exp),'
3491 'PV-WAVE (*.pro),'
3492 'Slick-C (*.e;*.sh),'
3493 'SQL Files (*.sql;*.pgsql),'
3494 'SAS Files (*.sas),'
3495 'Text Files (*.txt),'
3496 'Verilog Files (*.v),'
3497 'VHDL Files (*.vhd),'
3498 'SystemVerilog Files (*.sv;*.svh;*.svi),'
3499 'Vera Files (*.vr;*.vrh),'
3500 'Erlang Files (*.erl;*.hrl),'
3501 ;
3502
3503 def_updown_col=0; /* cursor movement */
3504 def_cursorwrap=0; /* ditto. */
3505 def_click_past_end=1; /* ditto */
3506 def_start_on_first=1; /* vs A B C; view A. */
3507 def_vc_system='Subversion' /* svn is default version control */
3508#if __VERSION__ >= 16.0
3509 def_auto_unsurround_block=0; /* Delete line, not block. */
3510#endif
3511 _config_modify_flags(CFGMODIFY_DEFDATA);
3512
3513 /* Make it grok: # include <stuff.h> */
3514 for (i = 0; i < aCLikeIncs._length(); i++)
3515 replace_def_data("def-":+aCLikeIncs[i]:+"-include",
3516 '^[ \t]*(\#[ \t]*include|include|\#[ \t]*line)[ \t]#({#1:i}[ \t]#|)(<{#0[~>]#}>|"{#0[~"]#}")');
3517 replace_def_data("def-m-include", '^[ \t]*(\#[ \t]*include|\#[ \t]*import|include|\#[ \t]*line)[ \t]#({#1:i}[ \t]#|)(<{#0[~>]#}>|"{#0[~"]#}")');
3518 replace_def_data("def-e-include", '^[ \t]*(\#[ \t]*include|\#[ \t]*import|\#[ \t]*require|include)[ \t]#(''{#0[~'']#}''|"{#0[~"]#}")');
3519
3520 /* Replace the default unicode proportional font with the fixed oned. */
3521 _str sCodeFont = _default_font(CFG_SBCS_DBCS_SOURCE_WINDOW);
3522 _str sUnicodeFont = _default_font(CFG_UNICODE_SOURCE_WINDOW);
3523 if (pos("Default Unicode", sUnicodeFont) > 0 && length(sCodeFont) > 5)
3524 _default_font(CFG_UNICODE_SOURCE_WINDOW,sCodeFont);
3525 if (machine()=='INTELSOLARIS' || machine()=='SPARCSOLARIS')
3526 {
3527 _default_font(CFG_MENU,'DejaVu Sans,10,0,0,');
3528 _default_font(CFG_DIALOG,'DejaVu Sans,10,0,,');
3529 _ConfigEnvVar('VSLICKDIALOGFONT','DejaVu Sans,10,0,,');
3530 }
3531
3532 /* Not so important. */
3533 int fSearch = 0x400400; /* VSSEARCHFLAG_WRAP | VSSEARCHFLAG_PROMPT_WRAP */;
3534 _default_option('S', (_str)fSearch);
3535
3536
3537#if __VERSION__ >= 17.0
3538 /*
3539 * Language settings via API.
3540 */
3541 int fNewAff = AFF_BEGIN_END_STYLE \
3542 | AFF_INDENT_WITH_TABS \
3543 | AFF_SYNTAX_INDENT \
3544 /*| AFF_TABS*/ \
3545 | AFF_NO_SPACE_BEFORE_PAREN \
3546 | AFF_PAD_PARENS \
3547 | AFF_INDENT_CASE \
3548 | AFF_KEYWORD_CASING \
3549 | AFF_TAG_CASING \
3550 | AFF_ATTRIBUTE_CASING \
3551 | AFF_VALUE_CASING \
3552 /*| AFF_HEX_VALUE_CASING*/;
3553 def_adaptive_formatting_flags = ~fNewAff;
3554 replace_def_data("def-adaptive-formatting-flags", def_adaptive_formatting_flags);
3555 _str sLangId;
3556 foreach (sLangId in aMyLangIds)
3557 {
3558 LanguageSettings.setIndentCaseFromSwitch(sLangId, true);
3559 LanguageSettings.setBeginEndStyle(sLangId, BES_BEGIN_END_STYLE_2);
3560 LanguageSettings.setIndentWithTabs(sLangId, false);
3561 LanguageSettings.setUseAdaptiveFormatting(sLangId, true);
3562 LanguageSettings.setAdaptiveFormattingFlags(sLangId, ~fNewAff);
3563 LanguageSettings.setSaveStripTrailingSpaces(sLangId, STSO_STRIP_MODIFIED);
3564 LanguageSettings.setTabs(sLangId, "8+");
3565 LanguageSettings.setSyntaxIndent(sLangId, 4);
3566
3567 /* C/C++ setup, wrap at column 80 not 64. */
3568 sTmp = LanguageSettings.getCommentWrapOptions(sLangId);
3569 if (length(sTmp) > 10)
3570 {
3571 typeless ntBlockCommentWrap, ntDocCommentWrap, ntFixedWidth;
3572 parse sTmp with ntBlockCommentWrap ntDocCommentWrap nt3 nt4 nt5 ntFixedWidth sRest;
3573 if ((int)ntFixedWidth < 80)
3574 LanguageSettings.setCommentWrapOptions('c', ntBlockCommentWrap:+' ':+ntDocCommentWrap:+' ':+nt3:+' ':+nt4:+' ':+nt5:+' 80 ':+sRest);
3575 //replace_def_data("def-comment-wrap-c",'0 1 0 1 1 64 0 0 80 0 80 0 80 0 0 1 '); - default
3576 //replace_def_data("def-comment-wrap-c",'0 1 0 1 1 80 0 0 80 0 80 0 80 0 0 0 '); - disabled
3577 //replace_def_data("def-comment-wrap-c",'1 1 0 1 1 80 0 0 80 0 80 0 80 0 0 1 '); - enable block comment wrap.
3578 }
3579
3580 /* set the encoding to UTF-8 without any friggin useless signatures. */
3581 idxExt = name_match('def-lang-for-ext-', 1, MISC_TYPE);
3582 while (idxExt > 0)
3583 {
3584 if (name_info(idxExt) == sLangId)
3585 {
3586 parse name_name(idxExt) with 'def-lang-for-ext-' auto sExt;
3587 sVarName = 'def-encoding-' :+ sExt;
3588 idxExtEncoding = find_index(sVarName, MISC_TYPE);
3589 if (idxExtEncoding != 0)
3590 delete_name(idxExtEncoding);
3591 }
3592 idxExt = name_match('def-lang-for-ext-', 0, MISC_TYPE);
3593 }
3594 //replace_def_data('def-encoding-' :+ sLangId, '+futf8 ');
3595 idxLangEncoding = find_index('def-encoding-' :+ sLangId, MISC_TYPE);
3596 if (idxLangEncoding != 0)
3597 delete_name(idxLangEncoding);
3598
3599 }
3600 replace_def_data('def-encoding', '+futf8 ');
3601
3602 LanguageSettings.setIndentWithTabs('mak', true);
3603 LanguageSettings.setLexerName('mak', 'kmk');
3604 LanguageSettings.setSyntaxIndent('mak', 8);
3605
3606 LanguageSettings.setBeautifierProfileName('c', "bird's Style");
3607 LanguageSettings.setBeautifierProfileName('m', "bird's Objective-C Style");
3608
3609 /* Fix .asm and add .mac, .kmk, .cmd, and .pgsql. */
3610 replace_def_data("def-lang-for-ext-asm", 'masm');
3611 replace_def_data("def-lang-for-ext-mac", 'masm');
3612 replace_def_data("def-lang-for-ext-kmk", 'mak');
3613 replace_def_data("def-lang-for-ext-cmd", 'bat');
3614 replace_def_data("def-lang-for-ext-pgsql", 'plsql');
3615
3616 /*
3617 * Change the codehelp default.
3618 */
3619 int fOldCodeHelp = def_codehelp_flags;
3620 int fNewCodeHelp = fOldCodeHelp \
3621 | VSCODEHELPFLAG_AUTO_FUNCTION_HELP \
3622 | VSCODEHELPFLAG_AUTO_LIST_MEMBERS \
3623 | VSCODEHELPFLAG_SPACE_INSERTS_SPACE \
3624 | VSCODEHELPFLAG_INSERT_OPEN_PAREN \
3625 | VSCODEHELPFLAG_DISPLAY_MEMBER_COMMENTS \
3626 | VSCODEHELPFLAG_DISPLAY_FUNCTION_COMMENTS \
3627 | VSCODEHELPFLAG_REPLACE_IDENTIFIER \
3628 | VSCODEHELPFLAG_PRESERVE_IDENTIFIER \
3629 | VSCODEHELPFLAG_AUTO_PARAMETER_COMPLETION \
3630 | VSCODEHELPFLAG_AUTO_LIST_PARAMS \
3631 | VSCODEHELPFLAG_PARAMETER_TYPE_MATCHING \
3632 | VSCODEHELPFLAG_NO_SPACE_AFTER_PAREN \
3633 | VSCODEHELPFLAG_RESERVED_ON \
3634 | VSCODEHELPFLAG_MOUSE_OVER_INFO \
3635 | VSCODEHELPFLAG_AUTO_LIST_VALUES \
3636 | VSCODEHELPFLAG_FIND_TAG_PREFERS_DEFINITION \
3637 | VSCODEHELPFLAG_FIND_TAG_PREFERS_ALTERNATE \
3638 | VSCODEHELPFLAG_HIGHLIGHT_TAGS \
3639 ;
3640 fNewCodeHelp &= ~( VSCODEHELPFLAG_SPACE_COMPLETION \
3641 | VSCODEHELPFLAG_AUTO_SYNTAX_HELP \
3642 | VSCODEHELPFLAG_NO_SPACE_AFTER_COMMA \
3643 | VSCODEHELPFLAG_STRICT_LIST_SELECT \
3644 | VSCODEHELPFLAG_AUTO_LIST_VALUES \
3645 );
3646 def_codehelp_flags = fNewCodeHelp;
3647 foreach (sLangId in aMyLangIds)
3648 {
3649 _str sVarName = 'def-codehelp-' :+ sLangId;
3650 int idxVar = find_index(sVarName, MISC_TYPE);
3651 if (idxVar != 0)
3652 replace_def_data(sVarName, fNewCodeHelp);
3653 }
3654#endif
3655
3656 /** @todo
3657 * - def_save_options
3658 * - Auto restore clipboards
3659 * */
3660
3661 message("Please restart SlickEdit.")
3662}
3663
3664/**
3665 * Module initiation.
3666 */
3667definit()
3668{
3669 /* do cleanup. */
3670 for (i = 0; i < 999; i++)
3671 {
3672 index = name_match("def-koptions-", 1 /*find_first*/, MISC_TYPE);
3673 if (!index)
3674 break;
3675 delete_name(index);
3676 }
3677
3678 /* do init */
3679 k_styles_create();
3680#ifdef KDEV_WITH_MENU
3681 k_menu_create();
3682# if __VERSION__ < 18.0 /* Something with timers are busted, so excusing my code. */
3683 iTimer = _set_timer(1000, k_menu_create, "timer");
3684# endif
3685 /* createMyColorSchemeAndUseIt();*/
3686#endif
3687}
3688
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette