home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / block.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-30  |  6.4 KB  |  214 lines

  1. /*
  2.     GWAda Development Environment for 386/486 PCs   
  3.     Copyright (C) 1993, Arthur Vargas Lopes  & Michael Bliss Feldman
  4.                         vlopes@vortex.ufrgs.br mfeldman@seas.gwu.edu
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; version 2 of the License.    
  9.  
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21. /*  block.c  */
  22.  
  23. #include <externs.h>
  24.  
  25.  
  26. void AVL_PROCESS_COPY()
  27. {
  28.     AVL_EDIT_COPY(1);
  29. }
  30.  
  31.  
  32. void AVL_REMOVE_BLOCK()
  33. {
  34.     ;
  35. }
  36.  
  37.  
  38. void AVL_EDIT_COPY(int no)
  39. {
  40.     AVL_EDIT_WINDOW_PTR w;
  41.     AVL_LINE_PTR temp, temp2, temp3;
  42.     struct rccoord old;
  43.     char new_line[(AVL_MAX_LINEL*2+10)];
  44.     char save[AVL_MAX_LINEL + 2];
  45.     int i, j, k;
  46.     if ((avl_block_first_line == NULL) ||
  47.         (avl_block_last_line == NULL)) {
  48.         AVL_ERROR("Block was not marked");
  49.         return;
  50.         }
  51.     avl_block_first_line2 =
  52.     avl_block_last_line2 = NULL;
  53.     w = &avl_windows[avl_window];
  54.     temp = w -> current_line;
  55.     if (w -> txt_col > (k = strlen(temp -> line)))
  56.         AVL_CURSOR_END();
  57.     for(i = 0; i < w -> txt_col; ++i)  /* Make first line of block */
  58.         new_line[i] = temp -> line[i];
  59.     for(j = avl_block_first_col; avl_block_first_line -> line[j] != '\0'; ++j) {
  60.         new_line[i++] = avl_block_first_line -> line[j];
  61.         if (avl_block_first_line == avl_block_last_line)
  62.             if (j == avl_block_last_col)  
  63.                 break;
  64.         }
  65.     /* First line will now be completed */
  66.     if (w -> txt_col != k)
  67.         strcpy(save,&temp -> line[w -> txt_col]);
  68.     else
  69.         strcpy(save,"");
  70.     w -> changed = 1;
  71.     if (avl_block_first_line == avl_block_last_line)  { /* Done */
  72.         for(j = w -> txt_col; temp -> line[j] != '\0'; ++j)
  73.             new_line[i++] = temp -> line[j];
  74.         new_line[i++] = '\0';
  75.         if (i >= AVL_MAX_LINEL)  
  76.              AVL_ERROR("Block's first line too long. Will truncate!");
  77.         new_line[AVL_MAX_LINEL] = '\0';
  78.         strcpy(temp -> line,new_line);
  79.         AVL_UPDATE_LINE();
  80.         return;
  81.         }
  82.     new_line[i++] = '\0';
  83.     if (i >= AVL_MAX_LINEL)  
  84.          AVL_ERROR("Block's first line too long. Will truncate!");
  85.     new_line[AVL_MAX_LINEL] = '\0';
  86.     strcpy(temp -> line,new_line);
  87.     AVL_UPDATE_LINE();
  88.     /* There is more than one line */        
  89.     temp2 = temp;
  90.     for(temp = avl_block_first_line -> next; 
  91.         temp -> previous != avl_block_last_line; 
  92.         temp = temp -> next)  {
  93.         temp3 = AVL_MAKE_LINE(temp -> line, 1);
  94.         AVL_LINK(temp3,temp2);
  95.         temp2 = temp3;
  96.         }
  97.     for(i = 0; i < avl_block_last_col; ++i)
  98.         new_line[i] = temp3 -> line[i];
  99.     new_line[i++] = '\0';
  100.     strcat(new_line,save);
  101.     if (strlen(new_line) >= AVL_MAX_LINEL)  {
  102.         AVL_ERROR("Last block's line too long. Will truncate!");
  103.         new_line[AVL_MAX_LINEL] = '\0';
  104.         }
  105.     strcpy(temp3 -> line, new_line);
  106.     i = w -> scr_row;
  107.     j = w -> scr_col;
  108.     w -> scr_col = 1;
  109.     AVL_MAKE_NUMBER();
  110.     temp3 = w -> current_line;
  111.     for(temp = w -> current_line -> next; ++(w -> scr_row) <= 24 && temp != w -> head;
  112.         temp = temp -> next) {
  113.         _settextposition(w -> scr_row,1);
  114.         w -> current_line = temp;
  115.         AVL_UPDATE_LINE();
  116.         }
  117.     w -> current_line = temp3;
  118.     w -> scr_row = i;
  119.     w -> scr_col = j;
  120.     _settextposition(i,j);
  121. }
  122.  
  123.  
  124. void AVL_CLEAR_BLOCK()
  125. {
  126.     AVL_LINE_PTR t1, t2;
  127.     avl_message[0] = '\0';
  128.     if (avl_block_first_line == NULL ||
  129.         avl_block_last_line == NULL) return;
  130.     for(t1 = avl_block_first_line; t1 != avl_block_last_line; t1 = t2) {
  131.         t2 = t1 -> next;
  132.         free(t1);
  133.         }
  134.     free(t1);
  135.     avl_block_first_line2 =
  136.     avl_block_last_line2  = NULL;
  137.     avl_block_first_line = NULL;
  138.     avl_block_last_line = NULL;
  139. }
  140.  
  141. void AVL_LINK(AVL_LINE_PTR this,AVL_LINE_PTR  at)
  142. {
  143.     this -> previous = at;
  144.     this -> next     = at -> next;
  145.     at -> next -> previous = this;
  146.     at -> next = this;
  147. }
  148.  
  149. void AVL_MAKE_BLOCK()
  150. {
  151.     AVL_LINE_PTR t1, t2, t3, temp;
  152.     int i, j;
  153.     if (avl_block_first_line -> line_no > avl_block_last_line -> line_no) { /* Swap */
  154.         temp = avl_block_first_line;
  155.         avl_block_first_line = avl_block_first_line2 = avl_block_last_line;
  156.         avl_block_last_line  = avl_block_last_line2  = temp;
  157.         i = avl_block_first_col;
  158.         avl_block_first_col = avl_block_first_col2 = avl_block_last_col;
  159.         avl_block_last_col  = i;
  160.         avl_block_last_col2 = i;
  161.         }
  162.     if (avl_block_first_line == avl_block_last_line)
  163.         if (avl_block_last_col < avl_block_first_col)  { /* Swap only cols */
  164.             i = avl_block_first_col;
  165.             avl_block_first_col = avl_block_first_col2 = avl_block_last_col;
  166.             avl_block_last_col  = avl_block_last_col2  = i;
  167.             }
  168.     t1 = AVL_MAKE_LINE(avl_block_first_line -> line,1);
  169.     t1 -> next = t1 -> previous = t1;
  170.     if (avl_block_first_line == avl_block_last_line)  {
  171.         avl_block_first_line = t1;
  172.         avl_block_last_line = t1;
  173.         return;
  174.         }
  175.     temp = avl_block_first_line -> next;
  176.     avl_block_first_line = t1;
  177.     for(; temp -> previous != avl_block_last_line;
  178.         temp = temp -> next)  {
  179.         t2 = AVL_MAKE_LINE(temp -> line,1);
  180.         AVL_LINK(t2,t1);
  181.         t1 = t2;
  182.         }
  183.     avl_block_last_line = t1;
  184. }
  185.  
  186.  
  187. void AVL_GUIDE_MBLOCK()
  188. {
  189.     if ((avl_block_first_line != NULL) && (avl_block_last_line != NULL)) 
  190.         AVL_CLEAR_BLOCK();
  191.     if (avl_block_first_line == NULL) {
  192.         avl_block_first_line = avl_windows[avl_window].current_line;
  193.         if (avl_block_first_line -> line_no == 0)  
  194.             avl_windows[avl_window].current_line = 
  195.                 avl_block_first_line = avl_block_first_line -> next;
  196.         avl_block_first_col  = avl_windows[avl_window].txt_col;
  197.         avl_block_first_line2 = avl_windows[avl_window].current_line;
  198.         avl_block_first_col2  = avl_windows[avl_window].txt_col;
  199.         strcpy(avl_message,"Now mark the block's end");
  200.         AVL_UPDATE_STATUS_LINE();
  201.         }
  202.     else {
  203.         avl_block_last_line = avl_windows[avl_window].current_line;
  204.         if (avl_block_last_line -> line_no == 0)
  205.             avl_windows[avl_window].current_line = 
  206.                 avl_block_last_line = avl_block_last_line -> previous;
  207.         avl_block_last_col  = avl_windows[avl_window].txt_col;
  208.         avl_block_last_line2 = avl_windows[avl_window].current_line;
  209.         avl_block_last_col2  = avl_windows[avl_window].txt_col;
  210.         strcpy(avl_message,"Block marked");
  211.         AVL_UPDATE_STATUS_LINE();
  212.         AVL_MAKE_BLOCK();
  213.         }
  214. }
  215.