source: trunk/SlickEdit/kdev.e@ 3132

Last change on this file since 3132 was 3132, checked in by bird, 7 years ago

kdev.e: Emit RT_NOREF rather than NOREF.

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