home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / W / WWIVSOR.ZIP / BBSUTL2.C < prev    next >
C/C++ Source or Header  |  1995-04-25  |  5KB  |  271 lines

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1995 by Wayne Bell
  5.  
  6. Distribution of the source code for WWIV, in any form, modified or unmodified,
  7. without PRIOR, WRITTEN APPROVAL by the author, is expressly prohibited.
  8. Distribution of compiled versions of WWIV is limited to copies compiled BY
  9. THE AUTHOR.  Distribution of any copies of WWIV not compiled by the author
  10. is expressly prohibited.
  11.  
  12.  
  13. *****************************************************************************/
  14.  
  15.  
  16.  
  17. #include "vars.h"
  18.  
  19. #pragma hdrstop
  20.  
  21. #include "vardec1.h"
  22.  
  23. #include <stdarg.h>
  24. #include <ctype.h>
  25. #include <conio.h>
  26.  
  27.  
  28.  
  29. void CLS(void)
  30. {
  31.   if (okansi())
  32.     outstr("\x1b[2J");
  33.   else
  34.     outchr(12);
  35. }
  36.  
  37. void CURSORUP( int x )
  38. {
  39.   npr("\033[%uA",(x));
  40. }
  41.  
  42. void CURSORDOWN( int x )
  43. {
  44.   npr("\033[%uB",(x));
  45. }
  46.  
  47. void CURSORRIGHT(int x)
  48. {
  49.   npr("\033[%uC",(x));
  50. }
  51.  
  52. void CURSORLEFT(int x)
  53. {
  54.   npr("\033[%uD",(x));
  55. }
  56.  
  57. char *justify_string(char *string, int length, int bg, int type)
  58. {
  59.   int x,x1;
  60.  
  61.   string[length]=0;
  62.   x=strlen(string);
  63.  
  64.   if (x<length) {
  65.  
  66.     if (type==JUSTIFY_LEFT) {
  67.  
  68.       memset(string+x, bg, length-x);
  69.  
  70.     } else if (type==JUSTIFY_RIGHT) {
  71.  
  72.       memmove(string+length-x, string, x);
  73.       memset(string, bg, length-x);
  74.  
  75.     } else if (type==JUSTIFY_CENTER) {
  76.  
  77.       x1=(length-x)/2;
  78.  
  79.       memmove(string+x1, string, x);
  80.       memset(string, bg, x1);
  81.       memset(string+x+x1, bg, length-(x+x1));
  82.  
  83.     }
  84.   }
  85.   return(string);
  86. }
  87.  
  88.  
  89. unsigned char *trimstr1(unsigned char *s)
  90. {
  91.   int i,i1;
  92.  
  93.   /* find real end of it */
  94.   i=strlen(s);
  95.   while ((i>0) && (isspace(s[i-1])))
  96.     --i;
  97.  
  98.   /* find real beginning */
  99.   i1=0;
  100.   while ((i1<i) && (isspace(s[i1])))
  101.     ++i1;
  102.  
  103.   /* knock spaces off the length */
  104.   i -= i1;
  105.  
  106.   /* move over the desired subsection */
  107.   memmove(s, s+i1, i);
  108.  
  109.   /* ensure null-terminated */
  110.   s[i]=0;
  111.  
  112.   return(s);
  113. }
  114.  
  115. void outstr_color(char *s)
  116. {
  117.   g_flags |= g_flag_pipe_colors;
  118.   outstr(s);
  119.   g_flags &= ~g_flag_pipe_colors;
  120. }
  121.  
  122. void npr_color(char *fmt, ...)
  123. {
  124.   va_list ap;
  125.   char s[512];
  126.  
  127.   va_start(ap, fmt);
  128.   vsprintf(s, fmt, ap);
  129.   va_end(ap);
  130.  
  131.   outstr_color(s);
  132.  
  133. }
  134.  
  135. void repeat_char(unsigned char x, int amount)
  136. {
  137.   int cur=0;
  138.  
  139.   while(cur<amount && !hangup)
  140.   {
  141.     outchr(x);
  142.     ++cur;
  143.   }
  144. }
  145.  
  146. char *strstr_nocase(char *s1, char *s2)
  147. {
  148.   int len=strlen(s2), pos=0;
  149.  
  150.   while(s1[pos])
  151.   {
  152.     if(strncmpi(s1+pos, s2, len)==0)
  153.       return(s1+pos);
  154.  
  155.     ++pos;
  156.   }
  157.   return NULL;
  158. }
  159.  
  160. void statusbar(statusbarrec *sb)
  161. {
  162.   float pos;
  163.   int maj_pos, min_pos;
  164.   int total_fractions=(sb->width-1)*sb->amount_per_square;
  165.  
  166.  
  167.   if(sb->current_item==0) // Initialize
  168.   {
  169.     int x=0;
  170.  
  171.     ansic(sb->surround_color);
  172.     outchr(sb->side_char1);
  173.  
  174.     setc(sb->box_color);
  175.     while(x<sb->width)
  176.     {
  177.       outchr(sb->empty_space);
  178.       ++x;
  179.     }
  180.  
  181.     ansic(sb->surround_color);
  182.     outchr(sb->side_char2);
  183.  
  184.     if(okansi())
  185.       CURSORLEFT(sb->width);
  186.     else
  187.     {
  188.       x=0;
  189.       while(x<sb->width+1)
  190.       {
  191.         outchr('\b');
  192.         ++x;
  193.       }
  194.     }
  195.  
  196.     sb->last_maj_pos=0;
  197.     sb->last_min_pos=0;
  198.  
  199.     return;
  200.   }
  201.  
  202.   pos=((float)sb->current_item/sb->total_items);
  203.   pos=pos * total_fractions;
  204.  
  205.   maj_pos=pos/sb->amount_per_square;
  206.   min_pos=pos-(maj_pos*sb->amount_per_square);
  207.  
  208.   if(min_pos==0)
  209.     min_pos=sb->amount_per_square-1;
  210.   else
  211.     --min_pos;
  212.  
  213.   if(maj_pos==sb->last_maj_pos)
  214.   {
  215.     if(min_pos==sb->last_min_pos)
  216.       return;
  217.  
  218.     setc(sb->box_color);
  219.     outchr('\b');
  220.     outchr(sb->square_list[min_pos]);
  221.  
  222.     sb->last_min_pos=min_pos;
  223.  
  224.     return;
  225.   }
  226.  
  227.   setc(sb->box_color);
  228.   outchr('\b');
  229.   outchr(sb->square_list[sb->amount_per_square-1]);
  230.   sb->last_min_pos=min_pos;
  231.  
  232.   ++sb->last_maj_pos;
  233.   while(sb->last_maj_pos < maj_pos)
  234.   {
  235.     ++sb->last_maj_pos;
  236.     outchr(sb->square_list[sb->amount_per_square-1]);
  237.   }
  238.   outchr(sb->square_list[min_pos]);
  239.  
  240.   sb->last_maj_pos=maj_pos;
  241.  
  242.   return;
  243. }
  244.  
  245. void strip_heart_colors(char *text)
  246. {
  247.   int pos=0;
  248.   int len=strlen(text);
  249.  
  250.   while(pos<len && text[pos] != 26 && !hangup)
  251.   {
  252.     if(text[pos]==3)
  253.     {
  254.       memmove(text+pos, text+pos+2, len-pos);
  255.       --len;
  256.       --len;
  257.     }
  258.     else
  259.       ++pos;
  260.   }
  261. }
  262.  
  263. // Set up a new control break handler so that my getch's won't break out of the bbs
  264. int new_control_break(void)
  265. {
  266.   sysoplog("Control Break pressed.  Program NOT aborting");
  267.   return 1;
  268. }
  269.  
  270.  
  271.