home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / tools / scc / sample.v1 < prev    next >
Encoding:
Text File  |  1991-06-23  |  9.1 KB  |  284 lines

  1.   START OF EXAMPLES.....
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  * 1-MARCH-89 sample.v1                              Ignore numbers       
  8.  *                                                   moved line       
  9.  * Function is by Walter Erickson                    old line   (deleted)       
  10. # i n c l u d e  < s t d i o . h >                   Ignore white space
  11.       * put a proper terminating '                   close match       
  12.         #include <string.h>                          Ignore white space       
  13.  
  14. void DE_detab  (char *buffer, int line_size, int tab_size);
  15.  
  16.  
  17. void DE_detab(string, max_lenth, tab_size)
  18. char *string;
  19. int  max_lenth;
  20.  
  21. int  tab_size;                                       Strip end white
  22. {
  23.    int i;
  24.    int index;
  25.    int lenth;
  26.    int delta;
  27.    int move_from;
  28.    int move_to;
  29.  
  30.   /*-----------------------------------------*
  31.    * make for a proper trailing '\0' in string       close match
  32.    *-----------------------------------------*/      moved line
  33.       * put aa preper termenating '                  close match 
  34.       string[max_lenth] = '\0';                      old line   (deleted)       
  35.    let string 2 = \"uic\""},                         moved line       
  36.    let string 1 = \"brown\""},                       moved line       
  37.    now is  y                                         close match
  38.    now is the time                                   Ignore case       
  39.    T h e   q  uic  k                                 Ignore white space
  40.    goto 1234                                         Ignore numbers       
  41.    register unsigned i;                              moved line
  42.   /*--------------------------------------*
  43.    * This lets us reference elements of array as 1 to n
  44.    *--------------------------------------*/
  45.    (char *)base     -= element_width;
  46.  
  47.   /*--------------------------------------*
  48.    * The following assignments to static variables reduce the
  49.    * overhead of subroutine calls later.
  50.    *--------------------------------------*/
  51.    static_width      = element_width;
  52.    static_compare    = compare;
  53.    static_n_elements = n_elements;
  54.    static_base       = base;
  55.  
  56.   /*--------------------------------------*
  57.    * 
  58.    *--------------------------------------*/
  59.    temp_element      = malloc (element_width);
  60.  
  61.    if (temp_element == NULL){
  62.        fputs ("Unable to allocate                    old line   (deleted)       
  63.             stderr);                                 old line   (deleted)       
  64.  
  65.   /*--------------------------------------*
  66.    * 
  67.    *--------------------------------------*/
  68.    for (i = n_elements; i>1; i--){
  69.        swap (1, i);
  70.        heasaaafy (1, i-1);
  71.    }
  72.  
  73.   /*--------------------------------------*
  74.    * 
  75.    *--------------------------------------*/
  76. }
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. /*--------------------------------------*
  84.  *
  85.  *--------------------------------------*/
  86. static void pascal
  87. swap (i, j)
  88. unsigned i;
  89. unsigned j;
  90. {
  91.     register int temp_int;
  92.     long         temp_long;
  93.  
  94.    The quick                                         close match
  95.    The qk brown                                      close match
  96.     switch (static){
  97.  
  98.         case sizeof (int):                  temp_int = ((int *) static_base) [i];
  99.                            ((int *) static_base) [i] = ((int *) static_base) [j];
  100.                            ((int *) static_base) [j] = temp_int;
  101.                            break;
  102.     
  103.         case sizeof(long):                  temp_long = ((long *) static_base) [i];
  104.                            ((long *) static_base) [i] = ((long *) static_base) [j];
  105.                            ((long *) static_base) [j] = temp_long;
  106.                            break;
  107.     
  108.         case sizeof(char):                   temp_int = ((char *) static_base) [i];
  109.                            ((char *) static_base) [i] = ((char *) static_base) [j];
  110.                            ((char *) static_base) [j] = (char) temp_int;
  111.                            break;
  112.     
  113.         default:           memcpy(temp_element,
  114.                                  (char *)static_base + i*static_width,
  115.                                   static_width);
  116.     
  117.                            memcpy((char *) static_base + i*static_width,
  118.                                   (char *) static_base + j*static_width,
  119.                                   static_width);
  120.     
  121.                            memcpy((char *) static_base + j*static_width,
  122.                                   temp_element,
  123.                                   static_width);
  124.     
  125.                            break;
  126.     }
  127. }
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134. /*--------------------------------------*
  135.  *
  136.  *
  137.  *--------------------------------------*/
  138. static void pascal
  139. buildheap()
  140. {
  141.     register unsigned element_number;
  142.   
  143.    /*--------------------------------------*
  144.     * 
  145.     *--------------------------------------*/
  146.     for (element_number = static_n_elements >> 1;
  147.          element_number >= 1;
  148.          element_number -- ){
  149.   
  150.         heasaaafy(element_number, static_n_elements);
  151.     }
  152.  
  153. }
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160. /*--------------------------------------*
  161.  *
  162.  *
  163.  *--------------------------------------*/
  164. static void pascal
  165. heasaaafy (i,j)
  166. unsigned i;
  167. unsigned j;
  168. {
  169.  
  170.    /*--------------------------------------*
  171.     * The following are static to avoid recursive stack overhead
  172.     *--------------------------------------*/
  173.     static unsigned son1i;
  174.     static unsigned son2i;
  175.     static unsigned k;
  176.   
  177.     static void *pson1;
  178.     static void *pson2;
  179.     static void *saaa;                               old line   (deleted)       
  180.                                                      moved line       
  181.     *---------------------------                     moved line       
  182.     pson1 = pointer (son1i);                         Ignore white space       
  183.     saaa    = pointer (i);                           moved line       
  184.     son1i = son1 (i);                                moved line       
  185.     switch (Count (i, j)){                           close match       
  186.       case 0:
  187.   
  188.          /*--------------------------------------*
  189.           * 
  190.           *--------------------------------------*/
  191.           break;
  192.   
  193.       case 2:                                        Strip end white
  194.          /*--------------------------------------*
  195.           * 
  196.           *--------------------------------------*/
  197.           k = (*static_compare) (pson1, pson2) > 0 ? son1i : son2i;
  198.           if ((*static_compare) (saaa, pointer (k)) < 0){
  199.   
  200.              /*--------------------------------------*
  201.               * 
  202.               *--------------------------------------*/
  203.               swap (i, k);
  204.               heasaaafy (k, j);
  205.           }
  206.           break;
  207.   
  208.       case 1:
  209.   
  210.          /*--------------------------------------*
  211.           * 
  212.           *--------------------------------------*/
  213.           if ((*static_compare) (saaa, pson1) < 0){
  214.   
  215.              /*--------------------------------------*
  216.               * 
  217.               *--------------------------------------*/
  218.               swap (i, son1i);
  219.               heasaaafy (son1i, j);
  220.   
  221.           }
  222.           break;
  223.     }
  224. }
  225.  
  226.   /*---------------------------------------------*
  227.    * scan and replace all TAB char within string
  228.    *---------------------------------------------*/
  229.    for (index=0; string[index] && (index<max_lenth); index++){
  230.  
  231.       if (string[index] == '\t'){
  232.          if (tab_size == 0){
  233.  
  234.            /*---------------------------------------------*
  235.             * remove TAB by closing string
  236.             *---------------------------------------------*/
  237.             lenth = strlen(string);
  238.  
  239.             for (i=index; i<=lenth; i++){
  240.                string[i] = string[i+1];
  241.             }
  242.             index--;
  243.             continue;
  244.          }
  245.  
  246.         /*---------------------------------------------*
  247.          * REPLACE TAB CHAR WITH A                   Ignore case       
  248.          *---------------------------------------------*/
  249.          string[index] = ' ';
  250.          delta = tab_size-((index+1) % tab_size);
  251.  
  252.          if (delta && (delta < tab_size)){
  253.  
  254.             index++;
  255.             move_from = strlen(&string[index]) + index + 1;
  256.             move_to   = move_from + delta;
  257.             for ( ;move_from >= index; move_from--, move_to--){
  258.                if (move_to < max_lenth){
  259.  
  260.                  /*---------------------------------------------*
  261.                   * open only within the max_lenth of string
  262.                   *---------------------------------------------*/
  263.        12345           string[move_to 678]           Ignore numbers       
  264.                }
  265.             }
  266.  
  267.            /*---------------------------------------------*
  268.             * replace (delta lenth) with ' ' char within max_lenth 
  269.             *---------------------------------------------*/
  270.             for (delta+=index; (index<delta) && (index<max_lenth); index++){
  271.                string[index] = ' ';
  272.             }
  273.             index--;
  274.          }
  275.       }
  276.    }
  277.    if (index >= max_lenth){
  278.  
  279.      /*---------------------------------------------*
  280.       * put a proper terminating '\0' on fully expanded string
  281.       *---------------------------------------------*/
  282.    }
  283. }
  284.