source: trunk/SlickEdit/kdev.e@ 3044

Last change on this file since 3044 was 3018, checked in by bird, 9 years ago

kdev.e: slickedit 21 fixes

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