VirtualBox

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

Last change on this file since 2421 was 2413, checked in by bird, 14 years ago

copyright year update.

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

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