home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / XDME / Src / Mod / Mikro.c < prev   
Encoding:
C/C++ Source or Header  |  1996-09-27  |  15.1 KB  |  637 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     mikro.c
  5.  
  6.     DESCRIPTION
  7.     hier ist alles, was zu klein war fuer einen vernuenftigen Oberbegriff
  8.  
  9.     NOTES
  10.  
  11.     BUGS
  12.  
  13.     TODO
  14.  
  15.     EXAMPLES
  16.  
  17.     SEE ALSO
  18.  
  19.     INDEX
  20.  
  21.     HISTORY
  22.     ******** b_noll created
  23.     01-08-93 b_noll added MICRO_Init
  24.     26-08-93 b_noll added MICRO_Exit
  25.     07-08-94 null updated some docs
  26.  
  27. *!***************************************************************************
  28. *!
  29. *!  Misc Commands (Mikro.c)
  30. *!
  31. ******************************************************************************/
  32.  
  33. /**************************************
  34.         Includes
  35. **************************************/
  36. #include "defs.h"
  37. /* #include "COM.h" */
  38.  
  39.  
  40. /**************************************
  41.        Interne Prototypes
  42. **************************************/
  43. /* control */
  44. Prototype void      do_quiet    (void);
  45. Prototype void      do_eval     (void);
  46. Prototype void      do_force    (void);
  47. Prototype void      do_abort    (void);
  48. Prototype void      do_unabort  (void);
  49. Prototype void      do_break    (void);
  50. Prototype void      do_continue (void);
  51. Prototype void      clearcont   (void);
  52. Prototype void      clearbreak  (void);
  53. Prototype void      clearbreaks (void);
  54.  
  55. /* write */
  56. Prototype void      do_insertwrite (void);
  57. Prototype void      do_printf     (void);
  58. Prototype void      m_write     (char *);
  59.  
  60. /* flags */
  61. Prototype void      do_viewmode     (void);
  62. Prototype void      do_simpletabs  (void);
  63. Prototype void      do_activefront (void);
  64. Prototype void      do_sourcebreak (void);
  65. Prototype void      do_windowcyc     (void);
  66. Prototype void      do_fwovr     (void);
  67. Prototype void      do_longline     (void);
  68.  
  69.  
  70.  
  71. /*
  72. **  some commands to modify the command flow
  73. **
  74. *! >ABORT
  75. *! >UNABORT
  76. *!  they toggle a flag which controlles macro-executing
  77. *!  ABORT sets the break-flag which causes e.g. immediately macro-abortion at keys
  78. *!  or terminates line-execution
  79. *!  UNABORT allows to reset this flag in an AREXX-script,
  80. *!  is the last line produced an error, you may clear the error-flag
  81. *!  if UNABORT is the first (or only) command of a line
  82. *!
  83. *! >BREAK
  84. *! >CONTINUE
  85. *!  these two commands do nearly the same like their C-language conterparts
  86. *!  BREAK leave the current loop-construct and
  87. *!  CONTINUE goes to the next turn of the current loop-construct
  88. *!
  89. **  Note that UNABORT is obsolete since Async Rexxports are introduced,
  90. **     as after every RexxComm got in mainloop we do a clearbreaks()
  91. */
  92.  
  93. void do_abort ( void )
  94. {
  95.     globalflags.Abortcommand = 1;
  96. } /* do_abort */
  97.  
  98. void do_unabort ( void )
  99. {
  100.     globalflags.Abortcommand = 0;
  101. } /* do_unabort */
  102.  
  103. int is_aborted ( void )
  104. {
  105.     return(globalflags.Abortcommand);
  106. } /* is_aborted */
  107.  
  108.  
  109.  
  110. void do_break (void)
  111. {
  112.     LoopBreak++;
  113. } /* do_break */
  114.  
  115.  
  116.  
  117. void do_continue (void)
  118. {
  119.     LoopCont++;
  120. } /* do_continue */
  121.  
  122.  
  123. #if 0
  124. void clearcont (void)  { LoopCont = 0;  } /* clearcont */
  125. void clearbreak (void) { LoopBreak = 0; } /* clearbreak */
  126. #endif
  127.  
  128.  
  129. void clearbreaks (void)
  130. {
  131.     LoopCont  = 0;
  132.     LoopBreak = 0;
  133.     globalflags.Abortcommand = 0;
  134. } /* clearbreaks */
  135.  
  136.  
  137.  
  138.  
  139. /*
  140. **  some re-evaluation commands
  141. **
  142. *! >EVAL com
  143. *!
  144. *!  to split longer commandsequences to fit their length down to MAXIA
  145. *!  so MAXIA may stay "small" and anybody can avoid "expression too complex"
  146. *!
  147. *! >FORCE [T|S|F|R|D] command
  148. *!
  149. *!  That's a command that means conjunction
  150. *!  of EVAL, QUIET, UNFAIL and UNTITLE
  151. *!
  152. *!    T == unTitle
  153. *!    S == quiet (no Screen updating)
  154. *!    F == unFail
  155. *!    R == no Requestors
  156. *!    D == enable debugging mode
  157. *!     <no flags> -> simple eval
  158. *!
  159. *!  for this reason we have declared UNTITLE, QUIET and UNFAIL
  160. *!  obsolete, and have removed them;
  161. *!  most of their functionality can be accessed via macros.
  162. *!
  163. */
  164.  
  165. void do_eval (void)
  166. {
  167.     char* buffer = (char*)malloc(LINE_LENGTH); /* allocate a buffer */
  168.     if (buffer)
  169.     {
  170.     strcpy(buffer, av[1]);                 /* copy the command into that buffer */
  171.     do_command(buffer);                    /* execute the buffer */
  172.     free(buffer);                          /* and then free it again */
  173.     } else
  174.     {
  175.     nomemory();
  176.     globalflags.Abortcommand = 1;
  177.     } /* if */
  178. } /* do_eval */
  179.  
  180.  
  181.  
  182. void do_force (void)
  183. {
  184.     char inter_screen  = Nsu;        /* extern Nsu controlles screen updates */
  185.     char inter_title   = globalflags.Showtitle;     /* extern showtitle controlles changes in window-titling */
  186.     char inter_request = globalflags.NoRequest;     /* Disable flag for requestors */
  187.     char inter_debug   = globalflags.debug;        /* Debugging mode */
  188.  
  189.     struct TextMarker chk = { NULL, 0, 0 };
  190.  
  191.     int failures       = 0;
  192.  
  193.     char* typer = av[1];
  194.     char* av1 = av[1];
  195.     char* av2 = av[2];
  196.  
  197.     av[1] = av[2];
  198.     av[2] = NULL;
  199.  
  200.     chk.line   = Ep->line;
  201.     chk.column = Ep->column;
  202.     if (typer)
  203.     {                 /* check for any set flags */
  204.     while (*typer)
  205.     {
  206.         switch ((*typer)|32)
  207.         {
  208.         case 't':
  209.         globalflags.Showtitle = 0;
  210.         break;
  211.         case 's':
  212.         chk.ep = Ep;
  213.         Nsu = 1;
  214.         break;
  215.         case 'f':
  216.         failures = 1;
  217.         break;
  218.         case 'r':
  219.         globalflags.NoRequest = 1;
  220.         break;
  221.         case 'd':
  222.         globalflags.debug = 1;
  223.         break;
  224.         default:
  225.         error ("%s:\nInvalid flags '%s'", av[0], typer);
  226.         goto df_quit;
  227.         } /* switch */
  228.         typer++;
  229.     } /* while */
  230.     } /* if */
  231.  
  232.     do_eval();                          /* do the evaluation */
  233.  
  234.     if (failures)
  235.     {              /* (...) cancel all breaks */
  236.     extern char MacroBreak;  /* PATCH_NULL [08 Mar 1993] : added */
  237.     if (MacroBreak != 1)     /* PATCH_NULL [08 Mar 1993] : added */
  238.         globalflags.Abortcommand = 0;
  239.     /* do_unbreak();  */
  240.     } /* if */
  241.  
  242. df_quit:
  243.     /* (if necessary) restore old values */
  244.     if (chk.ep) {
  245.     Nsu = inter_screen;
  246.     if (Ep == chk.ep) {
  247.         if (Ep->line != chk.line) {
  248.         text_adjust(FALSE);
  249.         } else if (Ep->column != chk.column) {
  250.         text_adjust(FALSE);
  251. /*          } else {                */
  252. /*          text_redisplay_currline();    */
  253.         } /* if moved */
  254. /*      } else {                */
  255.     } /* if ep */
  256.     } /* if "s" */
  257.     globalflags.Showtitle = inter_title;
  258.     globalflags.NoRequest = inter_request;
  259.     globalflags.debug      = inter_debug;
  260.  
  261.     av[2] = av2;
  262.     av[1] = av1;
  263.     return;
  264. } /* do_force */
  265.  
  266.  
  267. #if 0
  268.  
  269. /*
  270. ** the following commands are disabled, they
  271. ** were replaced by some macros with FORCE
  272. */
  273.  
  274. /*
  275. * !  >UNFAIL com
  276. * !
  277. * ! That's really like EVAL, but it ignore's failures
  278. * ! Very useful if U try to call an Command but U don't
  279. * ! know if it is one, or if you don't want a failure to break your macro
  280. * !
  281. */
  282.  
  283. void do_unfail (void)
  284. {
  285.     do_eval();
  286.     globalflags.Abortcommand = 0;
  287. #if 0
  288.     do_clearallbreaks();                /* simply cancel all breaks after evaluation */
  289. #endif
  290. } /* do_unfail */
  291.  
  292.  
  293. /*
  294. * !  >UNTITLE com
  295. * !
  296. * !  That's also like EVAL, except for the feature, that
  297. * !  No Title is shown during the macrocall
  298. * !
  299. */
  300.  
  301. void do_untitle (void)
  302. {
  303.     char inter = globalflags.Showtitle;   /* extern showtitle controlles changes in window-titling */
  304.     globalflags.Showtitle = 0;          /* buffer that value and change it for evaluation, then restore it */
  305.     do_eval();
  306.     globalflags.Showtitle = inter;
  307. } /* do_untitle */
  308.  
  309. #endif /* 0 */
  310.  
  311.  
  312. /*
  313. *!  >QUIET com
  314. *!
  315. *! That's like EVAL, but during execution no window
  316. *! should be refreshed
  317. *! as _No_Screen_Update is increased during operation
  318. *!
  319. */
  320.  
  321. void do_quiet (void)
  322. {
  323.     int inter = Nsu;            /* extern Nsu controlles screen updates */
  324.     Nsu = 1;                /* buffer that value and change it for evaluation, then restore it */
  325.     do_eval();
  326.     Nsu = inter;
  327. } /* do_quiet */
  328.  
  329.  
  330.  
  331.  
  332. /*
  333. **  some write - commands
  334. **
  335. *!
  336. *! >PRINTF format parameters
  337. *!
  338. *!  create a string with format and its (up to 8) parameters
  339. *!  and write it into the current text
  340. *!
  341. *! >INSERT text
  342. *! >OVERWRITE text
  343. *!
  344. *!  insert or overwrite text in the current text without respect
  345. *!  to the specialflag INSERTMODE
  346. *!
  347. **    note that in DME it is possible to define that ^-combinations
  348. **  can be interpreted like commands or like ctrl-keystrokes
  349. **  when they are INSERTed (not in overwrite mode)
  350. **  that patch is switched with the specialvar TEXTCOM
  351. **    note that that dme-patch is permanent enabled in the xdme
  352. **  commands PRINTF, INSERT and OVERWRITE.
  353. **
  354. */
  355.  
  356. void m_write(char * string)
  357. {
  358.     char c;
  359.     char * ptr    = string;
  360.     char * pptr = ptr;
  361.  
  362. /*    char quoted        = Ep->config.autoindent; */
  363. /*    Ep->config.autoindent = 0;             */
  364.     while ((c = *ptr)) {
  365.     pptr = ptr;
  366.     while ((c != 0) &&
  367.         (c != '\t' && c != ('t'&31)) &&
  368.         (c != '\n' && c != ('n'&31)) &&
  369.         (c != '\r' && c != ('r'&31))) {
  370.         ++ptr;
  371.         c = *(ptr);
  372.     } /* while */
  373.     *ptr = 0;
  374. /* printf ("< '%s'\n", pptr); */
  375.     text_write(pptr);
  376.     if (c != 0) {
  377.         *ptr = c;
  378.         ++ptr;
  379.         switch (c) {
  380.         case '\t':
  381.         case 't'&31:
  382.         do_tab();       /* do_command ("tab"); */
  383.         /* !! might be better to create some spaces !! */
  384.         break;
  385.         case '\n':
  386.         case 'n'&31:
  387.         do_split();
  388.         do_firstcolumn();
  389.         do_down();      /*  do_command ("split first down"); OR do_command ("return first"); */
  390.         break;
  391.         case '\r':
  392.         case 'r'&31:
  393.         av[0] = "b";
  394.         do_bs();        /* do_command ("bs"); */
  395.         break;
  396.         /* default: */ /* !! oh yea - I know that there are others C-escapes, but these were thought to be important !! */
  397.         } /* switch */
  398.     } /* if */
  399.     } /* while */
  400. /*    Ep->config.autoindent = quoted; */
  401. } /* m_write */
  402.  
  403.  
  404. void do_insertwrite (void)
  405. {
  406.     char insertbackup = Ep->config.insertmode;
  407.  
  408.     Ep->config.insertmode = av[0][0] == 'i';
  409.  
  410.     m_write(av[1]);
  411.  
  412.     Ep->config.insertmode = insertbackup;
  413. } /* do_insertwrite */
  414.  
  415.  
  416. void do_printf (void)
  417. {
  418.     char* iav = av[0];
  419.     char* arg [10];
  420.     char* aux [10];
  421.     char* ptr = av[2];
  422.     char quoted;
  423.     ULONG arc = 0;
  424.     char* buf = NULL;
  425.  
  426.     if (!(buf = malloc(512))) {
  427.     nomemory();
  428.     abort2();
  429.     } /* if */
  430.  
  431.     for (arc = 0; arc < 10; ++arc) arg[arc] = NULL;
  432.     arc = 0;
  433.     while ((arg[arc] = breakout (&ptr, "ed, &aux[arc]))) {
  434. /* printf (">arg %ld == %s\n", arc, arg[arc]); */
  435.     if (++arc >= 10)
  436.         break;
  437.     } /* while */
  438.  
  439.     vsprintf (buf, av[1], (va_list)arg);
  440.     m_write (buf);
  441.  
  442.     while (arc > 0) {
  443.     --arc;
  444.     if (aux[arc])
  445.         free(aux[arc]);
  446.     } /* while */
  447.  
  448.     av[0] = iav;
  449.     free (buf);
  450. } /* do_printf */
  451.  
  452.  
  453.  
  454. /*
  455. **  some flags
  456. **  The following commands should be placed into prefs.c
  457. **
  458. *!
  459. *!  Viewmode
  460. *!    That flag disables modifications of the current
  461. *!    text; if TRUE any modifiing command causes an error
  462. *!    (modifiing commands are recognized in do_command with the
  463. *!    flag CF_VWM being FALSE)
  464. *!
  465. *!  ActivateToFront
  466. *!  Windowcycling
  467. *!    These two flags refer to SELECT:
  468. *!
  469. *!    ActivateToFront invokes a "WindowToFront()" every
  470. *!            time, windows are switched
  471. *!    Windowcycling    enables the possibility to switch
  472. *!            to the other end of Textlist, if
  473. *!            one end is reacjed with SELECT next/prev
  474. *!
  475. *!  SourceBreaks
  476. *!    That flag refers to SOURCE
  477. *!    if TRUE if an Abortcommand or a Break occurs
  478. *!    on sourcing level, the operation is aborted
  479. *!    else the next line is executed.
  480. *!
  481. *!  SimpleTabs
  482. *!    That flag is an add to SAVETABS and SAVE[old|as]
  483. *!    if Savetabs is set, SimpleTabs decides to use
  484. *!    TAB-Optimisation until the first non-blank only
  485. *!    (is usable, if a program ignores leading whitespace,
  486. *!    but does not convert tabs to spaces)
  487. *!
  488. * !  FWOvr (Fixed Width Overwrite)
  489. * !     That flag is used in connection with INSERTMODE:
  490. * !     if the User has selected Overwrite, and that flag is
  491. * !     TRUE, DEL will cause replacing the deleted char
  492. * !     by a space instead of shortening the line and
  493. * !     BS is replaced by a simple LEFT (perhaps with writing
  494. * !     a space)
  495. * !
  496. * !  TextLine/LongLine (14-06-93)
  497. * !     this flag is used to disable movement left of the end
  498. * !     of the current line; note: ending spaces are usually
  499. * !     ignored in that mode
  500. * !     (this option was done to satisfy a CED user; dunno if it helps)
  501. * !
  502. */
  503.  
  504. void do_viewmode (void)
  505. {
  506.     Ep->viewmode = test_arg(av[1], Ep->viewmode);
  507.  
  508.     if (Ep->viewmode)
  509.     title ("Viewmode ON");
  510.     else
  511.     title ("Viewmode OFF");
  512. } /* do_viewmode */
  513.  
  514.  
  515. void do_activefront (void)
  516. {
  517.     globalflags.ActivateToFront = test_arg (av[1], globalflags.ActivateToFront);
  518.  
  519.     if (globalflags.ActivateToFront)
  520.     title ("Activated Windows are moved to front now");
  521.     else
  522.     title ("Activated Windows are NOT moved front now");
  523. } /* do_activefront */
  524.  
  525.  
  526. void do_windowcyc (void)
  527. {
  528.     globalflags.Windowcycling = test_arg (av[1], globalflags.Windowcycling);
  529.  
  530.     if (globalflags.Windowcycling)
  531.     title ("Windowcycling is now ON");
  532.     else
  533.     title ("Windowcycling is now OFF");
  534. } /* do_windowcyc */
  535.  
  536.  
  537. void do_sourcebreak (void)
  538. {
  539.     globalflags.SourceBreaks = test_arg (av[1], globalflags.SourceBreaks);
  540.  
  541.     if (globalflags.SourceBreaks)
  542.     title ("Source - Breaks are Enabled");
  543.     else
  544.     title ("Source - Breaks are Ignored");
  545. } /* do_sourcebreak */
  546.  
  547.  
  548. void do_simpletabs (void)
  549. {
  550.     globalflags.SimpleTabs = test_arg (av[1], globalflags.SimpleTabs);
  551.  
  552.     if (globalflags.SimpleTabs && globalflags.Savetabs)
  553.     title ("Tabsaving up to forstnb");
  554.     else if (globalflags.Savetabs)
  555.     title ("Tabsaving full");
  556.     else
  557.     title ("Tabsaving off");
  558. } /* do_simpletabs */
  559.  
  560. #if 0
  561.  
  562. void do_fwovr (void)
  563. {
  564.     globalflags.FWOvr = test_arg (av[1], globalflags.FWOvr);
  565.  
  566.     if (globalflags.FWOvr)
  567.     title ("Overwrite Delete FixWidth is now ON");
  568.     else
  569.     title ("Overwrite Delete FixWidth is now OFF");
  570. } /* do_fwovr */
  571.  
  572.  
  573. void do_longline (void)
  574. {
  575.     globalflags.LLine = test_arg (av[1], globalflags.LLine);
  576.  
  577.     if (globalflags.LLine)
  578.     title ("Movement after EoL is now ENABLED");
  579.     else
  580.     title ("Movement after EoL is now DISABLED");
  581. } /* do_longline */
  582.  
  583.  
  584. #endif
  585.  
  586.  
  587. #if 0
  588.  
  589. static const
  590. struct CommandNode MIKRO_Commands[] = {
  591.     {ENODE("abort"),         0, CF_VWM|CF_ICO|CF_COK, (FPTR)do_abort    },
  592.     {ENODE("unabort"),       0, CF_VWM|CF_ICO|CF_COK, (FPTR)do_unabort  },
  593.     {ENODE("continue"),      0, CF_VWM|CF_ICO|CF_COK, (FPTR)do_continue },
  594.     {ENODE("break"),         0, CF_VWM|CF_ICO|CF_COK, (FPTR)do_break    },
  595.     {ENODE("rem"),           1, CF_VWM|CF_ICO|CF_COK, (FPTR)do_null     },    /* comments in lines */
  596.     {ENODE("eval"),          1,        CF_VWM|CF_COK, (FPTR)do_eval     },
  597.     {ENODE("force"),         2,        CF_VWM|CF_COK, (FPTR)do_force    },
  598.     {ENODE("overwrite"),     1,               CF_COK, (FPTR)do_insertwrite  },
  599.     {ENODE("insert"),        1,               CF_COK, (FPTR)do_insertwrite  },
  600.     {ENODE("printf"),        2,               CF_COK, (FPTR)do_printf   },
  601.     {ENODE("sourcebreaks"),  1, CF_VWM|CF_COK|CF_ICO, (FPTR)do_sourcebreak  },
  602.     {ENODE("windowcycling"), 1, CF_VWM|CF_COK|CF_ICO, (FPTR)do_windowcyc    },
  603.     {ENODE("fwovr"),         1, CF_VWM|CF_ICO|CF_COK, (FPTR)do_fwovr    },
  604.     {ENODE("activatefront"), 1, CF_VWM|CF_COK|CF_ICO, (FPTR)do_activefront  },
  605.     {ENODE("viewmode"),      1, CF_VWM|CF_COK|CF_ICO, (FPTR)do_viewmode },
  606.     {ENODE("textline"),      1, CF_VWM|CF_ICO|CF_COK, (FPTR)do_longline },
  607. };
  608.  
  609. __autoinit
  610. void MIKRO_Init (void)
  611. {
  612.     int i;
  613.  
  614.     for (i = sizeof (MIKRO_Commands)/sizeof (struct CommandNode) - 1;i >= 0; --i)
  615.     COM_Add (&MIKRO_Commands[i]);
  616. } /* MIKRO_Init */
  617.  
  618.  
  619. #if 0
  620. __autoexit
  621. void MIKRO_Exit (void)
  622. {
  623.     int  i;
  624.     APTR lock;
  625.  
  626.     for (i = sizeof (MIKRO_Commands)/sizeof (struct CommandNode) - 1; (i >= 0); DEC(i))
  627.     if (lock = COM_Lock (MIKRO_Commands[i].cn_Name))
  628.         COM_Remove (lock);
  629. } /* MIKRO_Exit */
  630. #endif /*  */
  631.  
  632. #endif
  633.  
  634. /******************************************************************************
  635. *****  ENDE mikro.c
  636. ******************************************************************************/
  637.