home *** CD-ROM | disk | FTP | other *** search
/ The Arcade BBS / arcadebbs.zip / arcadebbs / bbstools / MODS / ALLMODS.ZIP / COMMON40.ZIP / COMMON2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-20  |  6.9 KB  |  301 lines

  1. // ************************************************************************* //
  2. // Begin COMMON mod, functions that are common amoung many Asylum releases   //
  3. // If you get a duplicate function error, then you have it installed twice   //
  4. // remove your oldest duplicated functions.                                  //
  5. // ************************************************************************* //
  6. // These are the non-overlayed functions to help out on speed
  7.  
  8. #include "vars.h"
  9. #pragma hdrstop
  10.  
  11.  
  12. #include <stdarg.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <errno.h>
  17. #include <ctype.h>
  18. #include <conio.h>
  19.  
  20.  
  21.  
  22. // Will search the batch queue for the file specified by fn and return where it
  23. // is in the batch queue
  24. int find_batch_queue(char *fn)
  25. {
  26.   int i;
  27.  
  28.   for (i=0; i<numbatch; i++) {
  29.     if (strcmp(fn,batch[i].filename)==0)
  30. //      if (batch[i].sending)
  31.         return(i);
  32.   }
  33.  
  34.   return(-1);
  35. }
  36.  
  37.  
  38. // Removes a file off the batch queue specified by fn
  39. void remove_batch(char *fn)
  40. {
  41.   int x;
  42.   
  43.   x = find_batch_queue(fn);
  44.   if(x > -1)
  45.     delbatch(x);
  46. }
  47.  
  48.  
  49. void BEEP(void)
  50. {
  51.   outstr("\007");
  52. }
  53.  
  54. // Clears to end of line
  55. void EOL(void)
  56. {
  57.   outstr("\033[K");
  58. }
  59.  
  60. // This will count how many items you have in a list, but the list is defined
  61. // as a regualr char string, therefore you must define how wide and how many
  62. // coloumns you have.  The list must end in a 0 for this function to find the
  63. // end of it...
  64. int pd_amount_in_list(char *list, int rows, int cols)
  65. {
  66.   int x=0;
  67.   while(list[x*(cols)] && !hangup)
  68.   {
  69.     ++x;
  70.     if(x>=rows)
  71.       return(rows);
  72.   }
  73.   return(x);
  74. }
  75.  
  76.  
  77.  
  78. // This will 'strip' all white spaces from the front and end of a string
  79. // Will turn '     This is me   ' -=> 'This is me'
  80. // 4.23 has a trimstr which will 'trim' the left part of the string
  81. char * strip_string(char *string)
  82. {
  83.   int x=0, y;
  84.   while(isspace(string[x]) && string[x] && !hangup)
  85.     ++x;
  86.     
  87.   y=strlen(string);
  88.   memmove(string, string+x, y-x+1);
  89.   string[y-x]=0;
  90.   
  91.   y=strlen(string);
  92.   --y;
  93.   
  94.   while(isspace(string[y]) && y >= 0 && !hangup)
  95.     --y;
  96.     
  97.   string[y+1]=0;
  98.   
  99.   
  100.   return(string);
  101. }
  102.  
  103. // Fixes one of wwiv's 'aligned' files ie... "FILE    .ARJ" -> "FILE.ARJ"
  104. char *unalign(char *filename)
  105. {
  106.   char *temp, *exttemp;
  107.  
  108.   temp=strstr(filename, " ");
  109.   if(temp)
  110.   {
  111.     temp[0]=0;
  112.     ++temp;
  113.  
  114.     exttemp=strstr(temp, ".");
  115.     if(exttemp)
  116.       strcat(filename, exttemp);
  117.   }
  118.   return(filename);
  119. }
  120.  
  121.  
  122. int outchr(unsigned char c)
  123. /*
  124.  * This function outputs one character to the screen, and if output to the
  125.  * com port is enabled, the character is output there too.  ANSI graphics are
  126.  * also trapped here, and the ansi function is called to execute the ANSI
  127.  * codes
  128.  */
  129. {
  130.   int             i, i1, nc, displayed = 0;
  131.   char            cc[20];
  132.   static char     pipe_color[3];
  133.  
  134.  
  135.   if (change_color == 5) {
  136.     change_color = 0;
  137.     return (outstr((char *) interpret(c)));
  138.   } if (change_color == 4) {
  139.     if (c == 15)
  140.       change_color = 5;
  141.     else
  142.       change_color = 0;
  143.     return 0;
  144.   } else if (change_color == 3) {
  145.     change_color = 0;
  146.     pipe_color[1] = c;
  147.     pipe_color[2] = 0;
  148.  
  149.     if (isdigit(pipe_color[0])) {
  150.       if (isdigit(pipe_color[1]) || (pipe_color[1] == ' ')) {
  151.         nc = atoi(pipe_color);
  152.       } else {
  153.         change_color = -1;
  154.       }
  155.     } else if ((pipe_color[0] == ' ') && isdigit(pipe_color[1])) {
  156.       nc = atoi(pipe_color + 1);
  157.     } else if ((pipe_color[0] == 'b') || (pipe_color[0] == 'B')) {
  158.       nc = 16 + atoi(pipe_color + 1);
  159.     } else {
  160.       change_color = -1;
  161.     }
  162.     if (nc >= 32)
  163.       change_color = -1;
  164.  
  165.  
  166.     if (change_color == -1) {
  167.       outchr('|');
  168.       return (outstr(pipe_color) + 1);
  169.     } else {
  170.       if (nc < 16) {
  171.         makeansi((curatr & 0xf0) | nc, cc, 0);
  172.         /* buildfor(nc, cc); */
  173.       } else {
  174.         makeansi((curatr & 0x0f) | (nc << 4), cc, 0);
  175.         /* buildback(nc, cc); */
  176.       }
  177.       outstr(cc);
  178.     }
  179.     return 0; /* color was printed, no chars displayed */
  180.   } else if (change_color == 2) {
  181.     pipe_color[0] = c;
  182.     ++change_color;
  183.     return 0;
  184.   } else if (change_color == 1) {
  185.     change_color = 0;
  186.     if ((c >= '0') && (c <= '9'))
  187.       ansic(c - '0');
  188.     return 0;
  189.   }
  190.   if (c == 3) {
  191.     change_color = 1;
  192.     return 0;
  193.   } else if (c == 15) {
  194.     change_color = 4;
  195.     return 0;
  196.   } else if ((c == '|') && (g_flags & g_flag_pipe_colors) &&
  197.              (change_color != -1)) {
  198.     change_color = 2;
  199.     return 0;
  200.   } else if ((c == 10) && endofline[0]) {
  201.     if (!in_extern)
  202.       displayed = outstr(endofline);
  203.     endofline[0] = 0;
  204.   } else if (change_color == -1) {
  205.     change_color = 0;
  206.   }
  207.   if (global_handle) {
  208.     if (echo)
  209.       global_char(c);
  210.   }
  211.   if (!(sysinfo.flags & OP_FLAGS_NEW_CHATSOUND)) {
  212.     if (chatcall && !x_only && !(syscfg.sysconfig & sysconfig_no_beep))
  213.       setbeep(1);
  214.   }
  215.   if (outcom && !x_only && (c != 9)) {
  216.     if (!(!okansi() && (ansiptr || c == 27))) {
  217.       outcomch(echo ? c : 'X');
  218.       displayed = 1;
  219.     }
  220.   }
  221.   if (ansiptr) {
  222.     ansistr[ansiptr++] = c;
  223.     ansistr[ansiptr] = 0;
  224.     if ((((c < '0') || (c > '9')) && (c != '[') && (c != ';')) ||
  225.         (ansistr[1] != '[') || (ansiptr > 75))
  226.       execute_ansi();
  227.   } else if (c == 27) {
  228.     ansistr[0] = 27;
  229.     ansiptr = 1;
  230.     ansistr[ansiptr] = 0;
  231.   } else {
  232.     if (c == 9) {
  233.       i1 = WhereX();
  234.       for (i = i1; i < (((i1 / 8) + 1) * 8); i++)
  235.         displayed += outchr(32);
  236.     } else if (echo || lecho) {
  237.       out1ch(c);
  238.       displayed = 1;
  239.       if (c == 10) {
  240.         ++lines_listed;
  241.         if (lines_listed >= screenlinest - 3) {
  242.           if (!in_extern) {
  243.             if ((tagging) && !(thisuser.sysstatus & sysstatus_no_tag) &&
  244.                 filelist && !chatting) {
  245.               if (num_listed != 0)
  246.                 tag_files();
  247.               lines_listed = 0;
  248.             }
  249.           }
  250.         }
  251.         if (lines_listed >= screenlinest - 1) {
  252.           if (sysstatus_pause_on_page & thisuser.sysstatus)
  253.             if (!x_only)
  254.               pausescr();
  255.           lines_listed = 0;
  256.         }
  257.       }
  258.     } else {
  259.       out1ch('X');
  260.       displayed = 1;
  261.     }
  262.   }
  263.   if (chatcall)
  264.     setbeep(0);
  265.  
  266.   return (displayed);
  267. }
  268.  
  269. int outstr(unsigned char *s)
  270. /* This function outputs a string of characters to the screen (and remotely
  271.  * if applicable).  The com port is also checked first to see if a remote
  272.  * user has hung up
  273.  */
  274. {
  275.   int i=0;
  276.   int displayed=0;
  277.  
  278.   checkhangup();
  279.   if (!hangup)
  280.     while (s[i])
  281.       displayed += outchr(s[i++]);
  282.  
  283.   return displayed;
  284. }
  285.  
  286.  
  287.  
  288. int npr(char *fmt, ...)
  289. /* just like printf, only out to the com port */
  290. {
  291.   va_list ap;
  292.   char s[512];
  293.  
  294.   va_start(ap, fmt);
  295.   vsprintf(s, fmt, ap);
  296.   va_end(ap);
  297.   return(outstr(s));
  298. }
  299.  
  300.  
  301.