home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / BBS / DOORL093.ZIP / doorlib-0.9.3.tar.bz2 / doorlib-0.9.3.tar / doorlib-0.9.3 / src / output.c < prev    next >
C/C++ Source or Header  |  2003-12-21  |  4KB  |  196 lines

  1. /*****************************************************************************
  2.  *
  3.  * $Id: output.c,v 1.5 2003/12/21 13:04:15 mbroek Exp $
  4.  * Purpose ...............: Output functions
  5.  *
  6.  *****************************************************************************
  7.  * Copyright (C) 2003 
  8.  *   
  9.  * Michiel Broek        FIDO:        2:280/2802
  10.  * Beekmansbos 10
  11.  * 1971 BV IJmuiden
  12.  * the Netherlands
  13.  *
  14.  * This file is part of doorlib for Unix.
  15.  *
  16.  * This BBS is free software; you can redistribute it and/or modify it
  17.  * under the terms of the GNU General Public License as published by the
  18.  * Free Software Foundation; either version 2, or (at your option) any
  19.  * later version.
  20.  *
  21.  * MBSE BBS is distributed in the hope that it will be useful, but
  22.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  23.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  24.  * General Public License for more details.
  25.  * 
  26.  * You should have received a copy of the GNU General Public License
  27.  * along with MBSE BBS; see the file COPYING.  If not, write to the Free
  28.  * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  29.  *****************************************************************************/
  30.  
  31. #include "../config.h"
  32. #include "door.h"
  33.  
  34.  
  35.  
  36. int termmode;                   /* 0 = tty, 1 = ANSI        */
  37.  
  38.  
  39.  
  40. /*
  41.  * Function will print about of enters specified
  42.  */
  43. void door_enter(int num)
  44. {
  45.     int i;
  46.  
  47.     for (i = 0; i < num; i++)
  48.     fprintf(stdout, "\n");
  49.     fflush(stdout);
  50. }
  51.  
  52.  
  53.  
  54. void door_cout(int fg, int bg, char *Str)
  55. {
  56.     door_color(fg, bg);
  57.     fprintf(stdout, Str);
  58.     fflush(stdout);
  59. }
  60.  
  61.  
  62.  
  63. /*
  64.  * Changes ansi background and foreground color
  65.  */
  66. void door_color(int fg, int bg)
  67. {
  68.     if (termmode == 1) {
  69.           
  70.     int att=0, fore=37, back=40;
  71.  
  72.     if (fg<0 || fg>31 || bg<0 || bg>7) {
  73.         fprintf(stdout, "ANSI: Illegal door_color specified: %i, %i\n", fg, bg);
  74.         fflush(stdout);
  75.         return; 
  76.     }
  77.  
  78.     fprintf(stdout, "\x1B[");
  79.     if ( fg > 15) {
  80.         fprintf(stdout, "5;");
  81.         fg-=16;
  82.     }
  83.     if (fg > 7) {
  84.         att=1;
  85.         fg=fg-8;
  86.     }
  87.        
  88.     if      (fg==0) fore=30;
  89.     else if (fg==1) fore=34;
  90.     else if (fg==2) fore=32;
  91.     else if (fg==3) fore=36;
  92.     else if (fg==4) fore=31;
  93.     else if (fg==5) fore=35;
  94.     else if (fg==6) fore=33;
  95.     else            fore=37;
  96.                                         
  97.     if      (bg==1) back=44;
  98.     else if (bg==2) back=42;
  99.     else if (bg==3) back=46;
  100.     else if (bg==4) back=41;
  101.     else if (bg==5) back=45;
  102.     else if (bg==6) back=43;
  103.     else if (bg==7) back=47;
  104.     else            back=40;
  105.  
  106.     fprintf(stdout, "%d;%d;%dm", att, fore, back);
  107.     fflush(stdout);
  108.     }
  109. }
  110.  
  111.  
  112.  
  113. void door_center(char *string)
  114. {
  115.     int     Strlen, Maxlen = 70, i, x, z;
  116.     char    *Str;
  117.  
  118.     Str = calloc(81, sizeof(char));
  119.     Strlen = strlen(string);
  120.  
  121.     if (Strlen == Maxlen)
  122.     fprintf(stdout, "%s\n", string);
  123.     else {
  124.     x = Maxlen - Strlen;
  125.     z = x / 2;
  126.     for (i = 0; i < z; i++)
  127.         strcat(Str, " ");
  128.     strcat(Str, string);
  129.     fprintf(stdout, "%s\n", Str);
  130.     }
  131.  
  132.     fflush(stdout);
  133.     free(Str);
  134. }
  135.  
  136.  
  137.  
  138. void door_clear(void)
  139. {
  140.     if (termmode == 1) {
  141.     door_color(LIGHTGRAY, BLACK);
  142.     fprintf(stdout, ANSI_HOME);
  143.     fprintf(stdout, ANSI_CLEAR);
  144.     fflush(stdout);
  145.     } else
  146.     door_enter(1); 
  147. }
  148.  
  149.  
  150.  
  151. /*
  152.  * Moves cursor to specified position
  153.  */
  154. void door_locate(int y, int x)
  155. {
  156.     if (termmode > 0) {
  157.     if (doorsys.screenlen != 0) {
  158.         if (y > doorsys.screenlen || x > 80) {
  159.         fprintf(stdout, "ANSI: Invalid screen coordinates: %i, %i\n", y, x);
  160.         fprintf(stdout, "ANSI: doorsys.screenlen: %i\n", doorsys.screenlen);
  161.         fflush(stdout);
  162.         return;
  163.         }
  164.     } else {
  165.         if (y > 25 || x > 80) {
  166.         fprintf(stdout, "ANSI: Invalid screen coordinates: %i, %i\n", y, x);
  167.         fflush(stdout);
  168.         return; 
  169.         }
  170.     }
  171.     fprintf(stdout, "\x1B[%i;%iH", y, x);
  172.     fflush(stdout);
  173.     }
  174. }
  175.  
  176.  
  177.  
  178. void door_line(int  Len)
  179. {
  180.     int x;
  181.  
  182.     if (termmode == 0)
  183.     for (x = 0; x < Len; x++)
  184.         fprintf(stdout, "-");
  185.  
  186.     if (termmode == 1)
  187.     for (x = 0; x < Len; x++)
  188.         fprintf(stdout, "%c", 196);
  189.  
  190.     fprintf(stdout, " \n");
  191.     fflush(stdout);
  192. }
  193.  
  194.  
  195.  
  196.