A
download b_search.cpp
Language: C++
LOC: 297
Project Info
BinkleyTerm XE(btxe)
Server: SourceForge
Type: cvs
...e\b\btxe\btxe\btnt\sources\
   Addr.cpp
   Addr.h
   aglcrc.cpp
   aglcrc.h
   asyn_lnx.cpp
   asyn_os2.cpp
   asyn_w32.cpp
   async.h
   asyos2v1.h
   b_banner.cpp
   b_bbs.cpp
   b_faxrcv.cpp
   b_flofil.cpp
   b_frproc.cpp
   b_help.cpp
   b_initva.cpp
   b_logs.cpp
   b_passwo.cpp
   b_proto.cpp
   b_rspfil.cpp
   b_sbinit.cpp
   b_script.cpp
   b_search.cpp
   b_sessio.cpp
   b_spawn.cpp
   b_term.cpp
   b_termov.cpp
   b_today.cpp
   b_wazoo.cpp
   b_whack.cpp
   b_wzsend.cpp
   banner.cpp
   banner.h
   BasicString.h
   bbs_ctra.cpp
   bbs_data.cpp
   bbs_incl.h
   bbs_io.cpp
   bink.h
   bink_asm.cpp
   binkdlg.cpp
   binkpipe.h
   box.h
   brec.cpp
   bsend.cpp
   bt.cpp
   btconfig.cpp
   btutil.cpp
   buffer.h
   cache.cpp
   cache.h
   callback.cpp
   callerid.cpp
   callwin.cpp
   callwin.h
   capi.cpp
   cfosline.cpp
   chat.cpp
   com.h
   com_dos.h
   com_lnx.h
   com_os2.h
   com_w32.h
   common.cpp
   cpuload.cpp
   css.cpp
   css.h
   data.cpp
   debug.cpp
   debug.h
   defines.h
   dosfuncs.cpp
   emsi.cpp
   emxmxcom.cpp
   evtparse.cpp
   evtsetup.cpp
   exceptio.cpp
   exceptio.h
   Exceptions.cpp
   Exceptions.h
   externs.h
   faxproto.h
   fcfgread.cpp
   fidomail.h
   file_all.cpp
   file_dos.cpp
   file_io.h
   file_lnx.cpp
   file_os2.cpp
   file_w32.cpp
   foffsets.h
   fossil.cpp
   freepoll.cpp
   ftsc.cpp
   gethcomm.h
   heap.cpp
   history.cpp
   history.h
   hydra.cpp
   hydra.h
   includes.cpp
   includes.h
   janus.cpp
   janus.h
   keybd.h
   keyfncs.h
   keymap.cpp
   langload.cpp
   language.h
   lngmagic.h
   m7rec.cpp
   m7send.cpp
   mailer.cpp
   mailovly.cpp
   mailroot.cpp
   maxcomm.h
   maxmcp.cpp
   maxmcp.h
   maxprm.cpp
   mdm_proc.cpp
   misc.cpp
   msgs.h
   Node.cpp
   Node.h
   NodeList.cpp
   NodeList.h
   nodeproc.cpp
   os2_pm.cpp
   outbound.cpp
   pipe.cpp
   pktmsgs.cpp
   pktmsgs.h
   protcomm.cpp
   prototyp.h
   recvbark.cpp
   recvsync.cpp
   sbuf.cpp
   sbuf.h
   sched.cpp
   sched.h
   script2.cpp
   SelfTest.cpp
   SelfTest.h
   sendbark.cpp
   sendsync.cpp
   squish.cpp
   squish.h
   srif.cpp
   statetbl.cpp
   stats.cpp
   stdafx.cpp
   stdafx.h
   timer.cpp
   timer.h
   times.cpp
   types.h
   v7debug.cpp
   version.cpp
   version7.cpp
   version7.h
   vfos_dos.cpp
   vfos_lnx.cpp
   vfos_os2.cpp
   vfos_qnx.cpp
   vfos_w32.cpp
   vfossil.h
   video.h
   vt100.cpp
   vt100.h
   xfer.h
   xmrec.cpp
   xmsend.cpp
   xstring.h
   yoohoo.cpp
   zmodem.cpp
   zmodem.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
// Description : BinkleyTerm Phone list Search Module

/* Include this file before any other includes or defines! */

#include "includes.h"

static int LOCALFUNC SaveScanList (int);
static void LOCALFUNC wait_for_keypress (void);

int
list_search ()
{
    int saved_baud;
    long t1;
    int i, k, l;
    int dirty;
    ADDR addr;
    ADDR* addrp;
    unsigned int kbd_input;
    char junk[256];

    static unsigned int save_chars[] =
        {
            SHF1, SHF2, SHF3, SHF4, SHF5,
            SHF6, SHF7, SHF8, SHF9, SHF10
        };

    static unsigned int load_chars[] =
        {
            ALTF1, ALTF2, ALTF3, ALTF4, ALTF5,
            ALTF6, ALTF7, ALTF8, ALTF9, ALTF10
        };

    static unsigned int command_chars[] =
        {
            PF1, PF2, PF3, PF4, PF5,
            PF6, PF7, PF8, PF9, PF10
        };

    /* Input the phone numbers we want to scan */

    dirty = 1;

    /* Print out a null string in a nice way for unforgiving OS. */

#define NICE_TEXT(n) (((n) == NULL) ? "(none)" : n)

    for (;;)
    {
        if (dirty)
        {
            screen_clear ();
            printf (MSG_TXT (M_PHONE_HELP));
            printf (MSG_TXT (M_PHONE_HELP2));
            if (set_loaded)
                printf (MSG_TXT (M_LAST_SET), set_loaded);
            printf (MSG_TXT (M_CURRENT_PHONES));
            for (k = 0; k < 10; k += 2)
            {
                printf ("%2d: %35s %2d: %35s\n", k + 1,
                        NICE_TEXT (scan_list[k]), k + 2,
                        NICE_TEXT (scan_list[k + 1]));
            }
            printf (MSG_TXT (M_INPUT_COMMAND));
            dirty = 0;
        }

        while (!KEYPRESS ())
            time_release ();
        kbd_input = FOSSIL_CHAR ();

        if (((kbd_input & 0xff) == '\n') || ((kbd_input & 0xff) == '\r'))
            break;

        if ((kbd_input & 0xff) == ESC)
            return (0);

        for (k = 0; k < 10; k++)
        {
            if (kbd_input == save_chars[k])  /* Save into a set?     */
            {
                SaveScanList (k);       /* Yes, do it           */
                dirty = 1;              /* Force redisplay      */
                k = 10;                 /* Then fool the logic  */
                break;
            }

            if (kbd_input == load_chars[k])  /* Load from a set?     */
            {
                LoadScanList (k, 1);    /* Yes, do it           */
                dirty = 1;              /* Force redisplay      */
                k = 10;                 /* Then fool the logic  */
                break;
            }

            if (kbd_input == command_chars[k])  /* Plain old Fkey?      */
                break;                  /* Yup, get out now     */
        }

        if (k == 10)                /* Not a function key   */
        {
            k = (kbd_input & 0xff) - '0';  /* Convert from digit   */
            if ((k < 0) || (k > 9))   /* Was it a digit?      */
                continue;               /* No, throw char out   */
            if (!k)                   /* Is it a zero?        */
                k = 9;                  /* That's 9 to us       */
            else
                --k;                    /* Else make zero-rel   */
        }

        printf (MSG_TXT (M_ELEMENT_CHOSEN), k + 1);
        if (scan_list[k] != NULL)
        {
            printf (MSG_TXT (M_CURRENTLY_CONTAINS), scan_list[k]);
            printf (MSG_TXT (M_PHONE_HELP3));
        }
        else
        {
            printf (MSG_TXT (M_PHONE_HELP4));
        }
        // gets (junk);                         /* Get user's input     */
        // CEH 990104: this was not safe
        fgets (junk, sizeof (junk), stdin);
        ++dirty;                    /* Always redisplay     */
        if ((l = (int) strlen (junk)) == 0)  /* If nothing there,    */
            continue;                 /* move along           */

        if (l == 1 && *junk == ' ') /* If just a space...   */
        {
            if (scan_list[k] != NULL) /* Delete old number    */
                free (scan_list[k]);
            scan_list[k] = NULL;      /* Clean up the ref     */
            continue;                 /* End this iteration   */
        }

        /* Get rid of old num if any */

        if (scan_list[k] != NULL)
        {
            free (scan_list[k]);
        }

        /* Allocate space for new num */

        if ((scan_list[k] = (char*)calloc (1, (unsigned int) (++l))) == NULL)
        {
            printf (MSG_TXT (M_MEM_ERROR));
            return (0);               /* Get out for error    */
        }
        strcpy (scan_list[k], junk);  /* Save new number      */
    }

    /* Actual Search logic */

    status_line (MSG_TXT (M_STARTING_SCAN));
    for (;;)
    {
        l = 0;
        for (k = 0; k < 10; k++)
        {
            if (scan_list[k] == NULL)
                continue;
            addrp = NULL;
            strcpy (junk, scan_list[k]);
            if (!isdigit (junk[0]) && junk[0] != '\"')
            {
// TODO                (*userfunc) (junk, &addr);
                if ((addr.Net != 0xffff)
                        && (addr.Node != 0xffff)
                        && (addr.Zone != 0xffff))
                {
                    sprintf (junk, "%s", Full_Addr_Str (&addr));
                    addrp = &addr;
                }
                else
                    continue;
            }
            if (strchr (junk, '/') != NULL)
            {
                char *c;

                c = skip_blanks (junk);
                if (find_address (c, &addr))
                    addrp = &addr;

                if (!nodeproc (junk))
                    break;

                status_line (MSG_TXT (M_PROCESSING_NODE),
                             Full_Addr_Str (&addr),
                             newnodedes.SystemName);

                strcpy (junk, (char *) (newnodedes.PhoneNumber));
            }
            saved_baud = baud;

            if (try_1_connect (junk, addrp))  /* Attempt to connect */
            {
                status_line (MSG_TXT (M_CONNECTED_TO_ITEM), k + 1);
                free (scan_list[k]);
                scan_list[k] = NULL;
                gong ();
                return (1);
            }

            ++l;
            baud = saved_baud;
            program_baud ();
            cur_baud = pbtypes[baud];
            t1 = timerset (2 * PER_SECOND);

            while (!timeup (t1))      /* pause for 2 seconds  */
            {
                if (KEYPRESS ())
                {
                    i = FOSSIL_CHAR () & 0xff;
                    if (i == ESC)         /* Abort for ESCape     */
                    {
                        status_line (MSG_TXT (M_CONNECT_ABORTED));
                        return (0);
                    }
                }
                time_release ();
            }
        }

        if (!l)
            break;
    }

    return (0);
}

int
LoadScanList (int number, int report_errors)
{
    int k, l;
    FILE *ScanFile;
    char junk[256];

    sprintf (junk, "%sBinkScan.LS%c", BINKpath, number + '0');
    if ((ScanFile = fopen (junk, read_binary)) == NULL)
    {
        if (report_errors)
        {
            printf (MSG_TXT (M_UNABLE_TO_OPEN), junk);
            printf ("\n");
            wait_for_keypress ();
        }
        return (0);
    }

    for (k = 0; k < 10; k++)
    {
        if (fread (junk, 36, 1, ScanFile) != 1)
        {
            if (report_errors)
            {
                printf (MSG_TXT (M_SET_READ_ERROR), number + 1);
                wait_for_keypress ();
            }
            fclose (ScanFile);
            return (0);
        }

        if (scan_list[k] != NULL)
        {
            free (scan_list[k]);
            scan_list[k] = NULL;
        }

        l = (int) strlen (junk);
        if (l)
        {
            if ((scan_list[k] = (char*)calloc (1, (unsigned int) (++l))) == NULL)  /* Allocate space    */
            {
                if (report_errors)
                {
                    printf (MSG_TXT (M_MEM_ERROR));
                    wait_for_keypress ();
                }
                fclose (ScanFile);
                return (0);
            }

            strcpy (scan_list[k], junk);  /* Save new number   */
        }
    }

    l = fclose (ScanFile);
    if (report_errors)
    {
        if (l)
            printf (MSG_TXT (M_SET_CLOSE_ERR), number + 1);
        else
        {
            printf (MSG_TXT (M_SET_LOADED), number + 1);
            set_loaded = number + 1;
        }
        wait_for_keypress ();
    }

    return (l);
}

static int LOCALFUNC
SaveScanList (int number)
{
    int k, l;
    FILE *ScanFile;
    char junk[256];

    sprintf (junk, "%sBinkScan.LS%c", BINKpath, number + '0');
    if ((ScanFile = fopen (junk, write_binary)) == NULL)
    {
        printf (MSG_TXT (M_UNABLE_TO_OPEN), junk);
        printf ("\n");
        wait_for_keypress ();
        return (0);
    }

    for (k = 0; k < 10; k++)
    {
        for (l = 0; l < 36; l++)
            junk[l] = '\0';

        if (scan_list[k] != NULL)
            strcpy (junk, scan_list[k]);

        if (fwrite (junk, 36, 1, ScanFile) != 1)
        {
            printf (MSG_TXT (M_SET_WRITE_ERROR), number + 1);
            wait_for_keypress ();
            fclose (ScanFile);
            return (0);
        }
    }

    l = fclose (ScanFile);
    if (l)
        printf (MSG_TXT (M_SET_CLOSE_ERR), number + 1);
    else
    {
        printf (MSG_TXT (M_SET_SAVED), number + 1);
        set_loaded = number + 1;
    }

    wait_for_keypress ();
    return (l);
}

static void LOCALFUNC
wait_for_keypress (void)
{
    printf ("%s\n", MSG_TXT (M_PRESS_ENTER));
    while (!KEYPRESS ())
        time_release ();
    FOSSIL_CHAR ();
}

/* $Id: b_search.cpp,v 1.1 2005/01/01 15:18:11 vildanov Exp $ */

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us