source: trunk/SlickEdit/kdev.e@ 2826

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

kdev.e: updates

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