home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / WWIVMODS / PRE412.ZIP / ANSI.MOD < prev    next >
Text File  |  1990-09-10  |  12KB  |  525 lines

  1. Tolkien #1 @3456
  2. Thu Aug 30 00:52:43 1990
  3. /*************************************************************************
  4.  *                                                                       *
  5.  *          Module ANSI.C. Additional commands for WWIV 4.07+            *
  6.  *                                                                       *
  7.  *      These functions brought to you courtesy of The Fellowship        *
  8.  *         [314] 644-5777 ■■■ WWIVNet @3456 ■■■ 1200/2400 baud           *
  9.  *                                                                       *
  10.  *************************************************************************/
  11.  
  12. #include <sys\stat.h>
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <time.h>
  16. #include <stdlib.h>
  17. #include <io.h>
  18. #include <fcntl.h>
  19. #include <alloc.h>
  20. #include "vardec.h"
  21. #include "fcns.h"
  22.  
  23.  
  24. extern int hangup;
  25. extern userrec thisuser;
  26. extern int echo;
  27.  
  28. /*
  29.  * You should add the following section to your FCNS.H file if you use
  30.  * these functions:
  31.  *
  32.  *  File: ansi.c 
  33.  *
  34.  * int okfancy();                           
  35.  * int primetime();                         
  36.  * void yesorno();                                     
  37.  * void backprint(char *s, int d1, int d2, int d3);    
  38.  * void shimmer(char *s, int i);                       
  39.  * void slowtype(int color, char *s);                  
  40.  * void spin(char *s, int d1);                         
  41.  * void noise(int startfreq, int endfreq, int step, int paws, int repeats);
  42.  * void padleftwrite(int color, char *s, int endpos);  
  43.  * void goxy(int i, int j);                            
  44.  * void left(int i);                                   
  45.  * void right(int i);                                  
  46.  * void up(int i);                                     
  47.  * void down(int i);                                   
  48.  * void ansiclearline();                               
  49.  *
  50.  * I added this before the BBS.C section, simply because it's alphabetical.
  51.  * It doesn't really matter where you put it, however.
  52.  *
  53.  * You will also need to either add this to your BBS.PRJ file (if you use
  54.  * the Integrated Environment) or add it to your MAKEFILE.MAK file if
  55.  * you use the MAKE utility (which I recommend). Neither of these options
  56.  * are difficult and you should be able to figure it out. Note that because
  57.  * of the commenting, this file is usable as is.
  58.  *
  59.  */
  60.  
  61. #define USERCOLORS 10
  62. /* 
  63.  * This is how many colors in your userrec struct. Our is 10, though
  64.  * we actually have 100+ color combinations available.
  65.  *
  66.  */
  67.  
  68. /*═════════════════════════════════════════════════════════════════════════*/
  69.  
  70. int okfancy()
  71. /*
  72.  * If an exempt_time (2) is set for the user then okfancy() is true, else
  73.  * it is false. There are other ways to do this but since exempt_time
  74.  * was not used anywhere else in our code, why not?
  75.  *
  76.  */
  77. {
  78.   if (thisuser.exempt & exempt_time)
  79.     return(1);
  80.   else
  81.     return(0);
  82. }
  83. /*
  84.  * Usage: 
  85.  *
  86.  * if (okfancy()) {
  87.  *
  88.  */
  89.  
  90. /*═════════════════════════════════════════════════════════════════════════*/
  91.  
  92. int primetime()
  93. /*
  94.  * This function checks to see if the current time is between the declared
  95.  * prime time, for uploading, downloading, bimodeming, etc. If it is then
  96.  * this function is returned as true (1), else it is false (0);
  97.  *
  98.  */
  99. {
  100.   if ((timer()>17*3600.0) && (timer()<23*3600.0))
  101.     return(1);
  102.   else
  103.     return(0);
  104. }
  105. /*
  106.  * Usage:
  107.  *
  108.  * if (!primetime()) {
  109.  *
  110.  */
  111.  
  112. /*═════════════════════════════════════════════════════════════════════════*/
  113.  
  114. void yesorno()
  115. /*
  116.  * This function prints out "Yes or No" in yellow, pauses, and backspaces.
  117.  * ANSI is not required.
  118.  */
  119. {
  120.   backprint("Yes or No",2,5,400);
  121. }
  122. /*
  123.  * Usage:
  124.  *
  125.  * yesorno();
  126.  *
  127.  */
  128.  
  129. /*═════════════════════════════════════════════════════════════════════════*/
  130.  
  131. void backprint(char *s, int d1, int d2, int d3)
  132. /*
  133.  * This function prints out a string, with a user-specifiable delay between
  134.  * each character, and a user-definable pause after the entire string has
  135.  * been printed, then it backspaces the string. The color is also definable.
  136.  * The parameters are as follows:
  137.  *   
  138.  * char *s : the string to print
  139.  * int d1  : the color of the string
  140.  * int d2  : delay between each character, in milliseconds
  141.  * int d3  : delay between completion of string and backspacing
  142.  *
  143.  * ANSI is not required.
  144.  *
  145.  */
  146. {
  147.   int i1, i2, i3;
  148.  
  149.   i3 = 0;
  150.   i1 = echo;
  151.   echo = 1;
  152.   i2=strlen(s);
  153.   ansic(d1);
  154.   delay(d2);
  155.  
  156.   while ((s[i3]) && (!hangup)) {
  157.     outchr(s[i3]);
  158.     delay(d2);
  159.     i3++;
  160.   }
  161.  
  162.   delay(d3);
  163.  
  164.   for (i3=0; i3 < i2; i3++) {
  165.     backspace();
  166.     delay(5);
  167.   }
  168.  
  169.   echo = i1;
  170. }
  171. /*
  172.  * Usage:
  173.  *
  174.  * prt(1,"Your Command: ");
  175.  * backprint("(Y)es, (N)o, or (Q)uit",2,5,400);
  176.  *
  177.  */
  178.  
  179. /*═════════════════════════════════════════════════════════════════════════*/
  180.  
  181. void shimmer(char *s, int i)
  182. /*
  183.  * If the user has "fancy ANSI" on (exempt of 2 is what we used for this)
  184.  * then the string to be printed will shimmer through the number of
  185.  * colors defined in the userrec struct in VARDEC.H. ANSI is checked, and
  186.  * if the user does not have ANSI and does not have "fancy ANSI" enabled
  187.  * then the string is simply printed normally. A <CR> is not done.
  188.  *
  189.  */
  190. {
  191.   int x,y;
  192.  
  193.   x=strlen(s);
  194.   y=0;
  195.  
  196.   if ((okansi()) && (okfancy())) {
  197.     do {
  198.       if (y!=i) {
  199.         prt(y,s);
  200.         left(x);
  201.       }
  202.       y++;
  203.     } while(y<USERCOLORS);
  204.   }
  205.   prt(i,s);
  206.   ansic(0);
  207. }
  208. /*
  209.  * Usage:
  210.  *
  211.  * shimmer("This is the sysop!",1);
  212.  * nl();
  213.  *
  214.  */
  215.  
  216. /*═════════════════════════════════════════════════════════════════════════*/
  217.  
  218. void slowtype(int color, char *s)
  219. /*
  220.  * This function will type out a string at random speed, as if there were
  221.  * someone actually typing it. The color is the first parameter, just as
  222.  * in the prt() function. A <CR> is not done.
  223.  *
  224.  * ANSI not required.
  225.  *
  226.  */
  227. {
  228.   int x;
  229.  
  230.   x=0;
  231.   randomize();
  232.   ansic(color);
  233.   checkhangup();
  234.   while ((s[x]) && (!hangup)) {
  235.     outchr(s[x]);
  236.     delay(random(80)+80);
  237.     x++;
  238.   }
  239. }
  240. /*
  241.  * Usage:
  242.  *
  243.  * nl();
  244.  * slowtype(1,"Downloading again, I see.");
  245.  * nl();
  246.  * slowtype(1,"Well, go ahead then...");
  247.  * nl();
  248.  *
  249.  */
  250.  
  251. /*═════════════════════════════════════════════════════════════════════════*/
  252.  
  253. void spin(char *s, int d1)
  254. /*
  255.  * This function will print out a string, making each character "spin"
  256.  * using the / - \ | sequence. The color is definable and is the
  257.  * second parameter, not the first. If the user does not have ANSI
  258.  * then the string is simply printed normally.
  259.  *
  260.  */
  261. {
  262.   int i1, i3, dly;
  263.  
  264.   dly  = 30;
  265.   i3   = 0;
  266.   i1   = echo;
  267.   echo = 1;
  268.  
  269.   if ((okansi()) && (okfancy())) {
  270.     ansic(d1);
  271.     while ((s[i3]) && (!hangup)) {
  272.       delay(dly);
  273.       outstr("/\x1b[1D");
  274.       delay(dly);
  275.       outstr("-\x1b[1D");
  276.       delay(dly);
  277.       outstr("\\\x1b[1D");
  278.       delay(dly);
  279.       outstr("|\x1b[1D");
  280.       delay(dly);
  281.       outchr(s[i3]);
  282.       i3++;
  283.     }
  284.   } else {
  285.     outstr(s);
  286.   }
  287.   echo = i1;
  288. }
  289. /*
  290.  * Usage:
  291.  *
  292.  * spin("This is the sysop, may I help you?",1);
  293.  *
  294.  */
  295.  
  296. /*═════════════════════════════════════════════════════════════════════════*/
  297.  
  298. void noise(int startfreq, int endfreq, int step, int paws, int repeats)
  299. /* 
  300.  * This function takes several parameters. Depending on these parameters,
  301.  * a noise will be made locally. We use this for such things as newuser
  302.  * logon, file access, chain access, logoff, chat, etc.
  303.  *
  304.  * The parameters are as follows:
  305.  *
  306.  * startfreq : The start frequency in hertz.
  307.  * endfreq   : The end frequency in hertz.
  308.  * step      : The number of hertz to step between startfreq and endfreq.
  309.  *             This number should be negative if endfreq is less than
  310.                              startfreq.
  311.  * paws      : The paws in milliseconds between repetitions.
  312.  * repeats   : The number of times to repeat the entire sequence.
  313.  *
  314.  * ANSI not required.
  315.  *
  316.  */
  317. {
  318.   int i,x,z;
  319.  
  320.   x=0;
  321.   if (startfreq<endfreq) {
  322.     do {
  323.       z=startfreq;
  324.       do {
  325.         sound(z);
  326.         delay(paws);
  327.         z+=step;
  328.       } while ((z <= endfreq) && (!hangup));
  329.       x++;
  330.     } while((x < repeats) && (!hangup));
  331.   } else {
  332.     do {
  333.       z=startfreq;
  334.       do {
  335.         sound(z);
  336.         delay(paws);
  337.         z+=step;
  338.       } while ((z >= endfreq) && (!hangup));
  339.       x++;
  340.     } while((x < repeats) && (!hangup));
  341.   }
  342.   nosound();
  343. }
  344. /*
  345.  * Usage:
  346.  *
  347.  * noise(100,1200,20,5,3);
  348.  * newuser();
  349.  *
  350.  */
  351.  
  352. /*═════════════════════════════════════════════════════════════════════════*/
  353.  
  354. void padleftwrite(int color, char *s, int endpos)
  355. /*
  356.  * This function prints a string and pads it with enough spaces on the
  357.  * right of the string to make the next string print starting right after
  358.  * endpos.  Useful for lining things up in columns, etc. The color is
  359.  * definable and is the first parameter.
  360.  *
  361.  * ANSI not required.
  362.  *
  363.  */
  364. {
  365.   int i;
  366.  
  367.   prt(color,s);
  368.   for (i=wherex();i<endpos;i++) {
  369.     outstr(" ");
  370.   }
  371. }
  372. /*
  373.  * Usage:
  374.  *
  375.  * padleftwrite(1,"Message #1",41);
  376.  * prt(1,"Message #2");
  377.  * nl();
  378.  *
  379.  */
  380.  
  381. /*═════════════════════════════════════════════════════════════════════════*/
  382.  
  383. void goxy(int i, int j)
  384. /*
  385.  * This function will position the cursor at x:i, y:j coordinates on the
  386.  * screen. If the user has no ANSI then nothing happens.
  387.  *
  388.  */
  389. {
  390.   char s[12];
  391.  
  392.   if (okansi()) {
  393.     sprintf(s,"\x1b[%d;%dH",j,i);
  394.     outstr(s);
  395.   }
  396. }
  397. /*
  398.  * Usage:
  399.  *
  400.  * goxy(41,13);
  401.  *
  402.  */
  403.  
  404. /*═════════════════════════════════════════════════════════════════════════*/
  405.  
  406. void left(int i)
  407. /*
  408.  * This function will reposition the cursor i spaces to the left, or if the
  409.  * cursor is on the left side of the screen already then it will not move.
  410.  * If the user has no ANSI then nothing happens.
  411.  *
  412.  */
  413. {
  414.   char s[10];
  415.  
  416.   if (okansi()) {
  417.     sprintf(s,"\x1b[%dD",i);
  418.     outstr(s);
  419.   }
  420. }
  421. /*
  422.  * Usage:
  423.  *
  424.  * left(5);
  425.  *
  426.  */
  427.  
  428. /*═════════════════════════════════════════════════════════════════════════*/
  429.  
  430. void right(int i)
  431. /*
  432.  * This function repositions the cursor i spaces to the right, not moving it 
  433.  * at all if it is already on the righthand side of the screen. If the
  434.  * user hasn't got ANSI then nothing happens.
  435.  *
  436.  */
  437. {
  438.   char s[10];
  439.  
  440.   if (okansi()) {
  441.     sprintf(s,"\x1b[%dC",i);
  442.     outstr(s);
  443.   }
  444. }
  445. /*
  446.  * Usage:
  447.  *
  448.  * right(4);
  449.  *
  450.  */
  451.  
  452. /*═════════════════════════════════════════════════════════════════════════*/
  453.  
  454. void up(int i)
  455. /*
  456.  * This function repositions the cursor i spaces upwards, not moving it at
  457.  * all if it is already on the upper line of the screen. If the user has no
  458.  * ANSI then nothing happens.
  459.  *
  460.  */
  461. {
  462.   char s[10];
  463.  
  464.   if (okansi()) {
  465.     sprintf(s,"\x1b[%dA",i);
  466.     outstr(s);
  467.   }
  468. }
  469. /*
  470.  * Usage: 
  471.  *
  472.  * up(12);
  473.  *
  474.  */
  475.  
  476. /*═════════════════════════════════════════════════════════════════════════*/
  477.  
  478. void down(int i)
  479. /*
  480.  * This function repositions the cursor i spaces to the bottom, not moving it
  481.  * at all if it is already on the bottom line of the screen. If the user has
  482.  * no ANSI then nothing happens.
  483.  *
  484.  */
  485. {
  486.   char s[10];
  487.  
  488.   if (okansi()) {
  489.     sprintf(s,"\x1b[%dB",i);
  490.     outstr(s);
  491.   }
  492. }
  493. /*
  494.  * Usage:
  495.  *
  496.  * down(7);
  497.  *
  498.  */
  499.  
  500. /*═════════════════════════════════════════════════════════════════════════*/
  501.  
  502. void ansiclearline()
  503. /*
  504.  * This function clears the current line, if the user has ANSI, otherwise
  505.  * nothing happens.
  506.  *
  507.  */
  508. {
  509.   if (okansi()) {
  510.     outstr("\x1b[K");
  511.   }
  512. }
  513. /*
  514.  * Usage:
  515.  *
  516.  * for(i=0;i<15;i++) {
  517.  *   up(1);
  518.  *   left(80);
  519.  *   ansiclearline();
  520.  * }
  521.  *
  522.  */
  523.  
  524. /*═════════════════════════════════════════════════════════════════════════*/
  525.