home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / ME22-OS2.ZIP / MACROS.ZIP / COMPRESS.M < prev    next >
Text File  |  1989-02-25  |  3KB  |  92 lines

  1. /*****************************************************************************/
  2. /* COMPRESS -  implements a simple compressed viewer for source files        */
  3. /*   When you press the COMPRESS command (ALT-C is this implementation),     */
  4. /* all source lines which have some non-blank characters in the first        */
  5. /* 'CompressLevel' characters of the line are displayed. The obly legal      */
  6. /* keys in compressed viewing mode are UP, DOWN, PGUP, PGDN, ESC (exits      */
  7. /* compressed mode), + (increases the CompressLevel) and - (decreases the    */
  8. /* CompressLevel).                                                           */
  9. /*                                                                           */
  10. /* Written by Marc Adler  Magma Systems   1/5/88                             */
  11. /*                                                                           */
  12. /*****************************************************************************/
  13.  
  14. #include mekeys.h
  15.  
  16. #define TAB_LEVEL 2     /* Put your indentation level here */
  17.  
  18. int CompressLevel;
  19.  
  20. init()
  21. {
  22.   CompressLevel = TAB_LEVEL;
  23.   assign_key("compress", ALT_C);
  24. }
  25.  
  26. compress()
  27. {
  28.   old_buf = currbuf();
  29.   save_position();
  30.  
  31.   /* Create a new buffer which will hold the compressed view */
  32. start:
  33.   new_buf = create_buffer("THE COMPRESSED FILE");
  34.   gobof();
  35.   show_buffer(new_buf);
  36.   explode_window();
  37.   setcurrbuf(old_buf);
  38.  
  39.   /* Go thru the lines of the old buffer and pick all lines whose 1st */
  40.   /* non-blank character starts at a column less than CompressLevel.  */
  41.   while (1)
  42.   {
  43.     cl = currline();
  44.     message("Processing line [%d]", currlinenum());
  45.  
  46.     if (ltrim(substr(cl, 1, CompressLevel)) != "")
  47.     {
  48.       /* Transfer the line to the new buffer */
  49.       setcurrbuf(new_buf);
  50.       fast_insert(cl);  insert("\r");
  51.       gobol();
  52.     }
  53.     setcurrbuf(old_buf);
  54.     if (!down())  break;
  55.   }
  56.   
  57.   /* Display the compressed file listing */
  58.   setcurrbuf(new_buf);
  59.   gobof();
  60.   refresh();
  61.  
  62.   message(
  63. "Use UP,DOWN,PGUP,PGDN to move, + to increase level, - to decrease, ESC exits");
  64.  
  65.   while ((c = get_tty_char()) != CTRL_D && c != ESC)
  66.   {
  67.     if (c == _UP || c == _DOWN || c == PGUP || c == PGDN)       /* navigate */
  68.       command(c);
  69.     else if (c == '+')          /* increase compress level */
  70.     {
  71.       CompressLevel += TAB_LEVEL;
  72.       delete_buffer(new_buf);
  73.       setcurrbuf(old_buf);
  74.       goto start;
  75.     }
  76.     else if (c == '-' && CompressLevel > TAB_LEVEL)             /* decrease */
  77.     {
  78.       CompressLevel -= TAB_LEVEL;
  79.       delete_buffer(new_buf);
  80.       setcurrbuf(old_buf);
  81.       goto start;
  82.     }
  83.   }
  84.  
  85.   /* Get rid of the compress buffer and go back to the original buffer */
  86.   unexplode_window();
  87.   delete_buffer(new_buf);
  88.   setcurrbuf(old_buf);
  89.   restore_position();
  90. }
  91.  
  92.