VirtualBox

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

Last change on this file since 323 was 323, checked in by bird, 19 years ago

nuke-trailing-whitespace-p

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

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