VirtualBox

source: kBuild/trunk/SlickEdit/kdev.e@ 3550

最後變更 在這個檔案從3550是 3311,由 bird 提交於 5 年 前

Slickedit: Updated to 24.0.x, automating more - no need to copy files anymore.

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

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