home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / window / ultrawin / uwdemo / str_ctrl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-02  |  5.4 KB  |  146 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /* STR_CTRL.C                                                               */
  4. /*                                         Kevin Huck/Boyd Gafford 02/01/92 */
  5. /*                                                                          */
  6. /* We have had several customers try to output strings that contain control */
  7. /* characters such as \r \n \t etc. and wonder why they display funny       */
  8. /* characters in the window. The reason for this is that the UltraWin output*/
  9. /* routines don't process ANY characters differently that ANY OTHER         */
  10. /* characters.  This is done for speed.  However, we decided to show you    */
  11. /* how to extend the library by adding a string function that does process  */
  12. /* these characters and more and can easily be extended.  While not as fast */
  13. /* as other output routines, this routine will make things like file        */
  14. /* browsers easier to write.                                                */
  15. /*                                                                          */
  16. /*------------------------- characters processed ---------------------------*/
  17. /* \r Carriage Return - moves "x" to first column in current row.           */
  18. /* \n Line Feed       - moves "y" down one position, scrolling if at bottom.*/
  19. /* \t Tab             - moves "x" to the next tab column or end of row.     */
  20. /* \b Backspace       - moves "x" back one, outputting a space at that pos. */
  21. /* \007 Bell          - sounds the speaker for 1/10th of a second.          */
  22. /*                                                                          */
  23. /****************************************************************************/
  24. #include <stdlib.h>
  25. #include "uw.h"
  26. #include "uw_globx.h"
  27. #include "uw_keys.h"
  28.  
  29. /*-------------------------- a golbal WINDOW variable ----------------------*/
  30. WINDOW Main_wn;
  31.  
  32. /*-------------------------- just some prototypes --------------------------*/
  33. void msg_line( char *msg );
  34. void wn_st_ctrl( char *s, WINDOW *wnp );
  35.  
  36.  
  37. /*********/
  38. /* ~main */
  39. /*       ********************************************************************/
  40. /****************************************************************************/
  41. int main()
  42. {
  43.     int i, r;
  44.     WINDOW *wnp = &Main_wn;
  45.  
  46.     init_video(80, 25);
  47.     init_clock(0x3333);
  48.     wn_create( 0, 0, V_cols-1, V_rows-1, DBL_BDR, WN_NORMAL, wnp );
  49.     wn_color( LIGHTGRAY, BLUE, wnp );
  50.     wn_bdr_color( LIGHTGRAY, BLUE, wnp );
  51.     wn_name("<<< EnQue's String Control Char Processing Demonstration >>>", wnp);
  52.     wn_set(wnp);
  53.  
  54.     wn_init_tabs(3, wnp);
  55.  
  56.     mv_cs( 0, 2, wnp );
  57.     wn_st( "This is a string with a CR at the end\r",wnp);
  58.     wait_event();
  59.     wn_st( "This string should overwrite the previous",wnp);
  60.     wait_event();
  61.     mv_cs( 0, 4, wnp );
  62.     wn_st( "This is a string with a LF at the end\n",wnp);
  63.     wait_event();
  64.     wn_st( "This string should be below the previous",wnp);
  65.     mv_cs( 0, 6, wnp );
  66.     wn_st( "This\tis\ta\tstring\twith\tTABS\tbetween\teach\tword",wnp);
  67.     wait_event();
  68.     mv_cs( 0, 8, wnp );
  69.     wn_st( "This is a string with mistakes bacq\bkspaced ovew\br them",wnp);
  70.     wait_event();
  71.     mv_cs( 0, 10, wnp );
  72.     wn_st( "This is a string with a bell\007 character in it",wnp);
  73.     wait_event();
  74.  
  75.     wn_color(YELLOW,BLUE,wnp);
  76.     mv_cs( 0, 12, wnp );
  77.     wn_st_ctrl( "This is a string with a CR at the end\r",wnp);
  78.     wait_event();
  79.     wn_st( "This string should overwrite the previous",wnp);
  80.     wait_event();
  81.     mv_cs( 0, 14, wnp );
  82.     wn_st_ctrl( "This is a string with a LF at the end\n",wnp);
  83.     wait_event();
  84.     wn_st( "This string should be below the previous",wnp);
  85.     mv_cs( 0, 16, wnp );
  86.     wn_st_ctrl( "This\tis\ta\tstring\twith\tTABS\tbetween\teach\tword",wnp);
  87.     wait_event();
  88.     mv_cs( 0, 18, wnp );
  89.     wn_st_ctrl( "This is a string with mistakes bacq\bkspaced ovew\br them",wnp);
  90.     wait_event();
  91.     mv_cs( 0, 20, wnp );
  92.     wn_st_ctrl( "This is a string with a bell\007 character in it",wnp);
  93.     wait_event();
  94.  
  95.     msg_line("Demo complete, press any key to quit!");
  96.     wait_event();
  97.     wn_destroy(wnp);
  98.     end_video();
  99.     return(0);
  100. }
  101. /*** end of main ***/
  102.  
  103. /*************/
  104. /* ~msg_line */
  105. /*           ****************************************************************/
  106. /* Display the message at the last line on the screen.                      */
  107. /****************************************************************************/
  108. void msg_line( char *msg )
  109. {
  110.     int save_att = Main_wn.att;
  111.  
  112.     wn_color(BLACK, LIGHTGRAY, &Main_wn);
  113.     mv_cs(0, V_rows - 3, &Main_wn);
  114.     wn_claol(&Main_wn);
  115.     wn_plst(CENTERED, V_rows - 3, msg, &Main_wn);
  116.     Main_wn.att = save_att;
  117. }
  118. /*** end of message_line ***/
  119.  
  120. /***************/
  121. /* ~wn_st_ctrl */
  122. /*             **************************************************************/
  123. /* Take the string and output it to the window with processing!             */
  124. /****************************************************************************/
  125. void wn_st_ctrl( char *s, WINDOW *wnp )
  126. {
  127.     int c, end_flag = 0;
  128.  
  129.     while( !end_flag )
  130.     {
  131.         switch( c = *s++ )
  132.         {
  133.             case '\0': end_flag = 1;        break;
  134.             case 0x07: tone(1024,10);       break;
  135.             case '\r': wnp->csr_x = 0;      break;
  136.             case '\n': wn_csr_dn(1,wnp);      break;
  137.             case '\t': wn_tab_right(1,wnp); break;
  138.             case '\b': wn_csr_left(1,wnp), wn_ch(' ', wnp), wn_csr_left(1,wnp); break;
  139.             default  : wn_ch(c, wnp);       break;
  140.         }
  141.     }
  142. }
  143. /*** end of wn_st_ctrl ***/
  144.  
  145. /**** END OF FILE ****/
  146.