Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/dll/aim/util.c
1072 views
1
/*
2
* AOL Instant Messanger Module for BitchX
3
*
4
* By Nadeem Riaz ([email protected])
5
*
6
* util.c
7
*
8
* utility/misc functions
9
*/
10
11
#include <irc.h>
12
#include <struct.h>
13
#include <hook.h>
14
#include <ircaux.h>
15
#include <output.h>
16
#include <lastlog.h>
17
#include <status.h>
18
#include <vars.h>
19
#include <window.h>
20
#include <module.h>
21
#include <modval.h>
22
23
#include <string.h>
24
#include <stdlib.h>
25
#include <stdarg.h>
26
#include <stdio.h>
27
#include "toc.h"
28
#include "aim.h"
29
30
31
void statusprintf(char *fmt, ...)
32
{
33
char data[MAX_STATUS_MSG_LEN];
34
char *sfmt, *prompt;
35
va_list ptr;
36
37
/* Tack on prompt */
38
prompt = get_dllstring_var("aim_prompt");
39
sfmt = (char *) malloc(strlen(prompt) + strlen(fmt)+5);
40
strcpy(sfmt,prompt);
41
strcat(sfmt," ");
42
strcat(sfmt,fmt);
43
44
va_start(ptr, fmt);
45
vsnprintf(data, MAX_STATUS_MSG_LEN - 1 , sfmt, ptr);
46
va_end(ptr);
47
free(sfmt);
48
statusput(LOG_CRAP,data);
49
return;
50
}
51
52
void statusput(int log_type, char *buf) {
53
int lastlog_level;
54
lastlog_level = set_lastlog_msg_level(log_type);
55
56
if (get_dllint_var("aim_window") > 0)
57
if (!(target_window = get_window_by_name("AIM")))
58
target_window = current_window;
59
60
if (window_display && buf)
61
{
62
add_to_log(irclog_fp, 0, buf, 0);
63
add_to_screen(buf);
64
}
65
66
target_window = NULL;
67
set_lastlog_msg_level(lastlog_level);
68
return;
69
}
70
71
void msgprintf(char *fmt, ...)
72
{
73
char data[MAX_STATUS_MSG_LEN];
74
va_list ptr;
75
76
va_start(ptr, fmt);
77
vsnprintf(data, MAX_STATUS_MSG_LEN - 1 , fmt, ptr);
78
va_end(ptr);
79
statusput(LOG_CRAP,data);
80
return;
81
}
82
83
void debug_printf(char *fmt, ...)
84
{
85
#ifdef DEBUG_AIM
86
FILE *fp;
87
char data[MAX_OUTPUT_MSG_LEN];
88
va_list ptr;
89
if ( ! (fp=fopen(AIM_DEBUG_LOG,"a")) ) {
90
perror("ERROR couldn't open debug log file!@$\n");
91
}
92
va_start(ptr, fmt);
93
vsnprintf(data, MAX_OUTPUT_MSG_LEN - 1 , fmt, ptr);
94
va_end(ptr);
95
fprintf(fp,"%s\n",data);
96
fflush(fp);
97
fclose(fp);
98
return;
99
#endif
100
}
101
102
char *rm_space(char *s) {
103
char *rs;
104
int x,y;
105
rs = (char *) malloc(strlen(s) + 1);
106
x = y = 0;
107
108
for (x =0; x<strlen(s);x++) {
109
if ( s[x] != ' ' ) {
110
rs[y] = s[x];
111
y++;
112
}
113
}
114
rs[y] = '\0';
115
return rs;
116
}
117
118
/*
119
* Still dont like split args routines in bitchx (new_next_arg)
120
* It doesnt allow for args with "'s in them, next_arg doesnt allow
121
* for args with spaces !@$. Need a *real* split routne that can handle
122
* both (with escaping)
123
*/
124
125
/*
126
char **split_args(char *args,int max;) {
127
int x;
128
char *list[32];
129
int arg = 0;
130
int escape = 0;
131
int open_quote = 0;
132
for (x=0;x<strlen(args);x++) {
133
if ( args[x] == '\' ) {
134
if ( ! escape ) {
135
escape = 1;
136
continue;
137
}
138
} else ( ! escape && args[x] == '"' ) {
139
if ( open_quote ) {
140
push(@args,$warg);
141
$warg ="";
142
arg++;
143
$argbegin = $x+1;
144
open_quote = 0;
145
} else {
146
open_quote = 1;
147
}
148
continue;
149
} elsif ( ! $escape && ! $open_quote && substr($text,$x,1) eq " " ) {
150
if ( ! $space ) {
151
push(@args,$warg);
152
$warg ="";
153
$arg++;
154
$space = 1;
155
}
156
$argbegin = $x+1;
157
next;
158
}
159
if ( $space ) {
160
$argbegin = $x;
161
$space = 0;
162
} elsif ( $escape ) {
163
$escape = 0;
164
}
165
$warg .= substr($text,$x,1);
166
}
167
}
168
}
169
170
171
*/
172
173