home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / dev / c / curses / src / tgoto.c < prev    next >
C/C++ Source or Header  |  1994-02-21  |  3KB  |  99 lines

  1. /* -*-C-*-
  2.  *
  3.  *
  4.  * Filename : Workbench2.0:src/curses/tgoto.c
  5.  *
  6.  * Author   : Simon J Raybould.    (sie@fulcrum.co.uk).
  7.  *
  8.  * Date     : Wed Feb 24 21:48:37 1993
  9.  *
  10.  * Desc     : goto a specified point on the screen.
  11.  *
  12.  *
  13.  * THIS CODE IS NOT PUBLIC DOMAIN
  14.  * ==============================
  15.  * 
  16.  * This code is copyright Simon J Raybould 1992, all rights are reserved.
  17.  * All code, ideas, data structures and algorithms remain the property of the
  18.  * author. Neither the whole nor sections of this code may be used as part
  19.  * of other code without the authors consent. If you wish to use some of this
  20.  * code then please email me at (sie@fulcrum.bt.co.uk).
  21.  *
  22.  * This source is not public domain, so you do not have any right to alter it
  23.  * or sell it for personal gain. The source is prcolided purely for reference
  24.  * purposes. You may re-compile the source with any compiler you choose.
  25.  * You must not distribute altered copies without the authors consent. My
  26.  * intention is that the source will help people isolate any bugs much more
  27.  * effectively.
  28.  *
  29.  * Disclaimer
  30.  * ==========
  31.  *
  32.  * No implication is made as to this code being fit for any purpose at all.
  33.  * I (the author) shall not be held responsible for any loss of data or damage 
  34.  * to property that may result from its use or misuse.
  35.  *
  36.  *
  37.  * Revision History
  38.  * ================
  39.  *
  40.  * $Log: tgoto.c,v $
  41.  * Revision 1.1  1993/05/17  23:33:10  sie
  42.  * Initial revision
  43.  *
  44.  *
  45.  */
  46.  
  47. #ifndef lint
  48. static char *rcsid = "$Header: /SRC/lib/curses/src/RCS/tgoto.c,v 1.1 1993/05/17 23:33:10 sie Exp $";
  49. #endif /* lint */
  50.  
  51. #include <stdio.h>
  52.  
  53. static void swap(int *a, int *b) { int t; t = *a; *a = *b; *b = t; }
  54.  
  55. char *
  56. tgoto(char *cm, int col, int line)
  57. {
  58.   static char buf[80];
  59.   char *ptr = cm, *bptr = buf;
  60.   
  61.   while(*ptr) {
  62.     if(*ptr == '%') {
  63.       if(!*++ptr) break;
  64.       switch(*ptr) {
  65.       case 'd':                 /* decimal value */
  66.         bptr += sprintf(bptr, "%d", line);
  67.         swap(&line, &col);
  68.         break;
  69.       case '2':                 /* decimal value */
  70.         bptr += sprintf(bptr, "%2d", line);
  71.         swap(&line, &col);
  72.         break;
  73.       case '3':                 /* decimal value */
  74.         bptr += sprintf(bptr, "%3d", line);
  75.         swap(&line, &col);
  76.         break;
  77.       case '.':                 /* character value */
  78.         bptr += sprintf(bptr, "%c", line);
  79.         swap(&line, &col);
  80.         break;
  81.       case 'r':                 /* reverse line and col */
  82.         swap(&line, &col);
  83.         break;
  84.       case 'i':                 /* in line and col */
  85.         line++;
  86.         col++;
  87.         break;
  88.       case '%':
  89.         *bptr++ = '%';
  90.         break;
  91.       }
  92.     } else
  93.       *bptr++ = *ptr;
  94.     ptr++;
  95.   } /* end of while(*ptr) */
  96.   return buf;
  97. }
  98.  
  99.