home *** CD-ROM | disk | FTP | other *** search
- // ************************************************************************* //
- // Begin COMMON mod, functions that are common amoung many Asylum releases //
- // If you get a duplicate function error, then you have it installed twice //
- // remove your oldest duplicated functions. //
- // ************************************************************************* //
- // These are the non-overlayed functions to help out on speed
-
- #include "vars.h"
- #pragma hdrstop
-
-
- #include <stdarg.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #include <ctype.h>
- #include <conio.h>
-
-
-
- // Will search the batch queue for the file specified by fn and return where it
- // is in the batch queue
- int find_batch_queue(char *fn)
- {
- int i;
-
- for (i=0; i<numbatch; i++) {
- if (strcmp(fn,batch[i].filename)==0)
- // if (batch[i].sending)
- return(i);
- }
-
- return(-1);
- }
-
-
- // Removes a file off the batch queue specified by fn
- void remove_batch(char *fn)
- {
- int x;
-
- x = find_batch_queue(fn);
- if(x > -1)
- delbatch(x);
- }
-
-
- void BEEP(void)
- {
- outstr("\007");
- }
-
- // Clears to end of line
- void EOL(void)
- {
- outstr("\033[K");
- }
-
- // This will count how many items you have in a list, but the list is defined
- // as a regualr char string, therefore you must define how wide and how many
- // coloumns you have. The list must end in a 0 for this function to find the
- // end of it...
- int pd_amount_in_list(char *list, int rows, int cols)
- {
- int x=0;
- while(list[x*(cols)] && !hangup)
- {
- ++x;
- if(x>=rows)
- return(rows);
- }
- return(x);
- }
-
-
-
- // This will 'strip' all white spaces from the front and end of a string
- // Will turn ' This is me ' -=> 'This is me'
- // 4.23 has a trimstr which will 'trim' the left part of the string
- char * strip_string(char *string)
- {
- int x=0, y;
- while(isspace(string[x]) && string[x] && !hangup)
- ++x;
-
- y=strlen(string);
- memmove(string, string+x, y-x+1);
- string[y-x]=0;
-
- y=strlen(string);
- --y;
-
- while(isspace(string[y]) && y >= 0 && !hangup)
- --y;
-
- string[y+1]=0;
-
-
- return(string);
- }
-
- // Fixes one of wwiv's 'aligned' files ie... "FILE .ARJ" -> "FILE.ARJ"
- char *unalign(char *filename)
- {
- char *temp, *exttemp;
-
- temp=strstr(filename, " ");
- if(temp)
- {
- temp[0]=0;
- ++temp;
-
- exttemp=strstr(temp, ".");
- if(exttemp)
- strcat(filename, exttemp);
- }
- return(filename);
- }
-
-
- int outchr(unsigned char c)
- /*
- * This function outputs one character to the screen, and if output to the
- * com port is enabled, the character is output there too. ANSI graphics are
- * also trapped here, and the ansi function is called to execute the ANSI
- * codes
- */
- {
- int i, i1, nc, displayed = 0;
- char cc[20];
- static char pipe_color[3];
-
-
- if (change_color == 5) {
- change_color = 0;
- return (outstr((char *) interpret(c)));
- } if (change_color == 4) {
- if (c == 15)
- change_color = 5;
- else
- change_color = 0;
- return 0;
- } else if (change_color == 3) {
- change_color = 0;
- pipe_color[1] = c;
- pipe_color[2] = 0;
-
- if (isdigit(pipe_color[0])) {
- if (isdigit(pipe_color[1]) || (pipe_color[1] == ' ')) {
- nc = atoi(pipe_color);
- } else {
- change_color = -1;
- }
- } else if ((pipe_color[0] == ' ') && isdigit(pipe_color[1])) {
- nc = atoi(pipe_color + 1);
- } else if ((pipe_color[0] == 'b') || (pipe_color[0] == 'B')) {
- nc = 16 + atoi(pipe_color + 1);
- } else {
- change_color = -1;
- }
- if (nc >= 32)
- change_color = -1;
-
-
- if (change_color == -1) {
- outchr('|');
- return (outstr(pipe_color) + 1);
- } else {
- if (nc < 16) {
- makeansi((curatr & 0xf0) | nc, cc, 0);
- /* buildfor(nc, cc); */
- } else {
- makeansi((curatr & 0x0f) | (nc << 4), cc, 0);
- /* buildback(nc, cc); */
- }
- outstr(cc);
- }
- return 0; /* color was printed, no chars displayed */
- } else if (change_color == 2) {
- pipe_color[0] = c;
- ++change_color;
- return 0;
- } else if (change_color == 1) {
- change_color = 0;
- if ((c >= '0') && (c <= '9'))
- ansic(c - '0');
- return 0;
- }
- if (c == 3) {
- change_color = 1;
- return 0;
- } else if (c == 15) {
- change_color = 4;
- return 0;
- } else if ((c == '|') && (g_flags & g_flag_pipe_colors) &&
- (change_color != -1)) {
- change_color = 2;
- return 0;
- } else if ((c == 10) && endofline[0]) {
- if (!in_extern)
- displayed = outstr(endofline);
- endofline[0] = 0;
- } else if (change_color == -1) {
- change_color = 0;
- }
- if (global_handle) {
- if (echo)
- global_char(c);
- }
- if (!(sysinfo.flags & OP_FLAGS_NEW_CHATSOUND)) {
- if (chatcall && !x_only && !(syscfg.sysconfig & sysconfig_no_beep))
- setbeep(1);
- }
- if (outcom && !x_only && (c != 9)) {
- if (!(!okansi() && (ansiptr || c == 27))) {
- outcomch(echo ? c : 'X');
- displayed = 1;
- }
- }
- if (ansiptr) {
- ansistr[ansiptr++] = c;
- ansistr[ansiptr] = 0;
- if ((((c < '0') || (c > '9')) && (c != '[') && (c != ';')) ||
- (ansistr[1] != '[') || (ansiptr > 75))
- execute_ansi();
- } else if (c == 27) {
- ansistr[0] = 27;
- ansiptr = 1;
- ansistr[ansiptr] = 0;
- } else {
- if (c == 9) {
- i1 = WhereX();
- for (i = i1; i < (((i1 / 8) + 1) * 8); i++)
- displayed += outchr(32);
- } else if (echo || lecho) {
- out1ch(c);
- displayed = 1;
- if (c == 10) {
- ++lines_listed;
- if (lines_listed >= screenlinest - 3) {
- if (!in_extern) {
- if ((tagging) && !(thisuser.sysstatus & sysstatus_no_tag) &&
- filelist && !chatting) {
- if (num_listed != 0)
- tag_files();
- lines_listed = 0;
- }
- }
- }
- if (lines_listed >= screenlinest - 1) {
- if (sysstatus_pause_on_page & thisuser.sysstatus)
- if (!x_only)
- pausescr();
- lines_listed = 0;
- }
- }
- } else {
- out1ch('X');
- displayed = 1;
- }
- }
- if (chatcall)
- setbeep(0);
-
- return (displayed);
- }
-
- int outstr(unsigned char *s)
- /* This function outputs a string of characters to the screen (and remotely
- * if applicable). The com port is also checked first to see if a remote
- * user has hung up
- */
- {
- int i=0;
- int displayed=0;
-
- checkhangup();
- if (!hangup)
- while (s[i])
- displayed += outchr(s[i++]);
-
- return displayed;
- }
-
-
-
- int npr(char *fmt, ...)
- /* just like printf, only out to the com port */
- {
- va_list ap;
- char s[512];
-
- va_start(ap, fmt);
- vsprintf(s, fmt, ap);
- va_end(ap);
- return(outstr(s));
- }
-
-
-