~ubuntu-branches/ubuntu/feisty/minicom/feisty

« back to all changes in this revision

Viewing changes to src/dial.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin A. Godisch
  • Date: 2006-10-27 05:41:23 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061027054123-9cyfsdx649zetdrv
Tags: 2.2-3
* Added upstream NEWS file, closes: #394827.
* Fixed spelling errors, closes: #395449.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#endif
28
28
 
29
29
#include "rcsid.h"
30
 
RCSID("$Id: dial.c,v 1.6 2003/04/21 23:56:46 al-guest Exp $")
 
30
RCSID("$Id: dial.c,v 1.21 2005/10/31 12:13:51 al-guest Exp $")
31
31
 
32
32
#include "port.h"
33
33
#include "minicom.h"
34
34
#include "intl.h"
35
35
 
36
 
#if VC_MUSIC
 
36
#ifdef VC_MUSIC
37
37
#  if defined(__GLIBC__)
38
38
#    include <sys/ioctl.h>
39
39
#    include <sys/kd.h>
108
108
};
109
109
 
110
110
/* Forward declaration */
111
 
static void writedialdir();
 
111
static void writedialdir(void);
112
112
 
113
113
#define dialentno(di, no) ((struct dialent *)((char *)(di) + ((no) * sizeof(struct dialent))))  
114
114
 
122
122
char *dial_user;
123
123
char *dial_pass;
124
124
 
 
125
/* Change the baud rate.  Treat all characters in the given array as if
 
126
 * they were key presses within the comm parameters dialog (C-A P) and
 
127
 * change the line speed accordingly.  Terminate when a space or other
 
128
 * unrecognised character is found.
 
129
 */
 
130
const char* change_baud(const char *s)
 
131
{
 
132
  int max = m_getmaxspd();
 
133
 
 
134
  while (s && *s
 
135
         && update_bbp_from_char(*s, P_BAUDRATE, P_BITS, P_PARITY,
 
136
                                 P_STOPB, 0, max))
 
137
    ++s;
 
138
 
 
139
  // reinitialise the port and update the status line
 
140
  if (portfd >= 0)
 
141
    port_init();
 
142
  if (st)
 
143
    mode_status();
 
144
 
 
145
  return s;
 
146
}
 
147
 
125
148
/*
126
149
 * Functions to talk to the modem.
127
150
 */
128
 
 
 
151
 
129
152
/*
130
153
 * Send a string to the modem.
131
154
 * If how == 0, '~'  sleeps 1 second.
132
155
 * If how == 1, "^~" sleeps 1 second.
133
156
 */
134
 
void mputs(s, how)
135
 
char *s;
136
 
int how;
 
157
void mputs(const char *s, int how)
137
158
{
138
159
  char c;
139
160
 
140
161
  while(*s) {
141
 
        if (*s == '^' && (*(s + 1))) {
142
 
                s++;
143
 
                if (*s == '^')
144
 
                        c = *s;
145
 
                else if (how == 1 && *s == '~') {
146
 
                        sleep(1);
147
 
                        s++;
148
 
                        continue;
149
 
                } else
150
 
                        c = (*s) & 31;
151
 
        } else if (*s == '\\' && (*(s + 1))) {
152
 
                s++;
153
 
                switch (toupper (*s)) {
154
 
                        case '\\':
155
 
                          c = *s;
156
 
                          break;
157
 
                        case 'U':
158
 
                          if (dial_user && *dial_user) 
159
 
                            mputs (dial_user, how);
160
 
                          s++;
161
 
                          continue;
162
 
                        case 'P':
163
 
                          if (dial_pass && *dial_pass)
164
 
                            mputs (dial_pass, how);
165
 
                          s++;
166
 
                          continue;
167
 
                        default:
168
 
                          s++;
169
 
                          continue;
170
 
                }
171
 
        } else
172
 
                c = *s;
173
 
        if (how == 0 && c == '~')
174
 
                sleep(1);
175
 
        else    
176
 
                write(portfd, &c, 1);
177
 
        s++;
 
162
    if (*s == '^' && (*(s + 1))) {
 
163
      s++;
 
164
      if (*s == '^')
 
165
        c = *s;
 
166
      else if (how == 1 && *s == '~') {
 
167
        sleep(1);
 
168
        s++;
 
169
        continue;
 
170
      } else
 
171
        c = (*s) & 31;
 
172
    } else if (*s == '\\' && (*(s + 1))) {
 
173
      s++;
 
174
      switch (toupper (*s)) {
 
175
        case '\\':
 
176
          c = *s;
 
177
          break;
 
178
        case 'U':
 
179
          if (dial_user && *dial_user) 
 
180
            mputs (dial_user, how);
 
181
          s++;
 
182
          continue;
 
183
        case 'P':
 
184
          if (dial_pass && *dial_pass)
 
185
            mputs (dial_pass, how);
 
186
          s++;
 
187
          continue;
 
188
        case 'B': /* line speed change. */
 
189
          s = change_baud(++s);
 
190
          continue;
 
191
        case 'L': /* toggle linefeed addition */
 
192
          toggle_addlf();
 
193
          s++; /* nothing to do with the modem, move along */
 
194
          continue;
 
195
        case 'E': /* toggle local echo */
 
196
          toggle_local_echo();
 
197
          s++; /* again, move along. */
 
198
          continue;
 
199
        default:
 
200
          s++;
 
201
          continue;
 
202
      }
 
203
    } else
 
204
      c = *s;
 
205
    if (how == 0 && c == '~')
 
206
      sleep(1);
 
207
    else
 
208
      write(portfd, &c, 1);
 
209
    s++;
178
210
  }
179
211
}
180
 
  
 
212
 
181
213
/*
182
214
 * Initialize the modem.
183
 
 */ 
184
 
void modeminit()
 
215
 */
 
216
void modeminit(void)
185
217
{
186
218
  WIN *w;
187
219
 
188
 
  if (P_MINIT[0] == '\0') return;
 
220
  if (P_MINIT[0] == '\0')
 
221
    return;
189
222
 
190
223
  w = mc_tell(_("Initializing Modem"));
191
224
  m_dtrtoggle(portfd, 1);         /* jl 23.06.97 */
196
229
/*
197
230
 * Reset the modem.
198
231
 */
199
 
void modemreset()
 
232
void modemreset(void)
200
233
{
201
234
  WIN *w;
202
235
 
203
 
  if (P_MRESET[0] == '\0') return;
 
236
  if (P_MRESET[0] == '\0')
 
237
    return;
204
238
 
205
239
  w = mc_tell(_("Resetting Modem"));
206
240
  mputs(P_MRESET, 0);
211
245
/*
212
246
 * Hang the line up.
213
247
 */
214
 
void hangup()
 
248
void hangup(void)
215
249
{
216
250
  WIN *w;
217
251
  int sec=1;
218
 
  extern time_t old_online;
219
252
 
220
253
  w = mc_tell(_("Hanging up"));
221
254
 
222
255
  timer_update();
223
256
  if (P_LOGCONN[0] == 'Y')
224
257
    do_log(_("Hangup (%ld:%02ld:%02ld)"),
225
 
           online / 3600, (online / 60) % 60, online>0 ? online % 60 : 0);
 
258
           online / 3600, (online / 60) % 60, online>0 ? online % 60 : 0);
226
259
  online = -1;
227
260
  old_online = -1;
228
261
 
230
263
    sscanf(P_MDROPDTR,"%2d",&sec);
231
264
 
232
265
  if (P_MDROPDTR[0] == 'Y' || (isdigit(P_MDROPDTR[0]) && sec>0)) {
233
 
        m_dtrtoggle(portfd, sec);   /* jl 23.06.97 */
 
266
    m_dtrtoggle(portfd, sec);   /* jl 23.06.97 */
234
267
  } else {
235
 
        mputs(P_MHANGUP, 0);
236
 
        sleep(1);
 
268
    mputs(P_MHANGUP, 0);
 
269
    sleep(1);
237
270
  }
238
 
#if _DCDFLOW
 
271
#ifdef _DCDFLOW
239
272
  /* DCD has dropped, turn off hw flow control. */
240
273
  m_sethwf(portfd, 0);
241
274
#endif
253
286
void sendbreak()
254
287
{
255
288
  WIN *w;
256
 
  
 
289
 
257
290
  w = mc_tell(_("Sending BREAK"));
258
291
  wcursor(w, CNONE);
259
292
 
264
297
WIN *dialwin;
265
298
int dialtime;
266
299
 
267
 
#if VC_MUSIC
 
300
#ifdef VC_MUSIC
268
301
 
269
302
/*
270
303
 * Play music until key is pressed.
271
304
 */
272
 
void music()
 
305
void music(void)
273
306
{
274
307
  int x, i, k;
275
308
  int consolefd = 0;
277
310
 
278
311
  /* If we're in X, we have to explicitly use the console */
279
312
  if (strncmp(getenv("TERM"), "xterm", 5) == 0 &&
280
 
        (disp = getenv("DISPLAY")) != NULL &&
281
 
        (strcmp(disp, ":0.0") == 0 ||
282
 
        (strcmp(disp, ":0") == 0))) {
283
 
        consolefd = open("/dev/console", O_WRONLY);
284
 
        if (consolefd < 0) consolefd = 0;
 
313
      (disp = getenv("DISPLAY")) != NULL &&
 
314
      (strcmp(disp, ":0.0") == 0 ||
 
315
       (strcmp(disp, ":0") == 0))) {
 
316
    consolefd = open("/dev/console", O_WRONLY);
 
317
    if (consolefd < 0) consolefd = 0;
285
318
  }
286
319
 
287
320
  /* Tell keyboard handler what we want. */
289
322
 
290
323
  /* And loop forever :-) */
291
324
  for(i = 0; i < 9; i++) {
292
 
        k = 2000 - 200 * (i % 3);
293
 
        (void) ioctl(consolefd, KIOCSOUND, k);
 
325
    k = 2000 - 200 * (i % 3);
 
326
    ioctl(consolefd, KIOCSOUND, k);
294
327
 
295
 
        /* Check keypress with timeout 160 ms */
296
 
        x = check_io(-1, 0, 160, NULL, NULL);
297
 
        if (x & 2) break;
 
328
    /* Check keypress with timeout 160 ms */
 
329
    x = check_io(-1, 0, 160, NULL, NULL);
 
330
    if (x & 2)
 
331
      break;
298
332
  }
299
 
  (void) ioctl(consolefd, KIOCSOUND, 0);
300
 
  if (consolefd) close(consolefd);
 
333
  ioctl(consolefd, KIOCSOUND, 0);
 
334
  if (consolefd)
 
335
    close(consolefd);
301
336
 
302
337
  /* Wait for keypress and absorb it */
303
 
  while((x & 2) == 0) {
 
338
  while ((x & 2) == 0) {
304
339
    x = check_io(-1, 0, 10000, NULL, NULL);
305
340
    timer_update();
306
341
  }
307
 
  (void) keyboard(KGETKEY, 0);
 
342
  keyboard(KGETKEY, 0);
308
343
}
309
344
#endif
310
345
 
312
347
 * The dial has failed. Tell user.
313
348
 * Count down until retrytime and return.
314
349
 */
315
 
static int dialfailed(s, rtime)
316
 
char *s;
317
 
int rtime;
 
350
static int dialfailed(char *s, int rtime)
318
351
{
319
352
  int f, x;
320
353
  int ret = 0;
322
355
  wlocate(dialwin, 1, 5);
323
356
  wprintf(dialwin, _("    No connection: %s.      \n"), s);
324
357
  if (rtime < 0) {
325
 
        wprintf(dialwin, _("   Press any key to continue..    "));
326
 
        if (check_io(-1, 0, 10000, NULL, NULL) & 2) 
327
 
                (void) keyboard(KGETKEY, 0);
328
 
        return(0);
 
358
    wprintf(dialwin, _("   Press any key to continue..    "));
 
359
    if (check_io(-1, 0, 10000, NULL, NULL) & 2) 
 
360
      keyboard(KGETKEY, 0);
 
361
    return 0;
329
362
  }
330
363
  wprintf(dialwin, _("     Retry in %2d seconds             "), rtime);
331
364
  
332
 
  for(f = rtime - 1; f >= 0; f--) {
333
 
        x = check_io(-1, 0, 1000, NULL, NULL);
334
 
        if (x & 2) {
335
 
                /* Key pressed - absorb it. */
336
 
                x = keyboard(KGETKEY, 0);
337
 
                if (x != ' ') ret = -1;
338
 
                break;
339
 
        }
340
 
        wlocate(dialwin, 0, 6);
341
 
        wprintf(dialwin, _("     Retry in %2d seconds             "), f);
 
365
  for (f = rtime - 1; f >= 0; f--) {
 
366
    x = check_io(-1, 0, 1000, NULL, NULL);
 
367
    if (x & 2) {
 
368
      /* Key pressed - absorb it. */
 
369
      x = keyboard(KGETKEY, 0);
 
370
      if (x != ' ')
 
371
        ret = -1;
 
372
      break;
 
373
    }
 
374
    wlocate(dialwin, 0, 6);
 
375
    wprintf(dialwin, _("     Retry in %2d seconds             "), f);
342
376
  }
343
377
#ifdef HAVE_USLEEP
344
378
  /* MARK updated 02/17/94 - Min dial delay set to 0.35 sec instead of 1 sec */
345
 
  if (f < 0) usleep(350000); /* Allow modem time to hangup if redial time == 0 */
 
379
  if (f < 0) /* Allow modem time to hangup if redial time == 0 */
 
380
    usleep(350000);
346
381
#else
347
 
  if (f < 0) sleep(1);
 
382
  if (f < 0)
 
383
    sleep(1);
348
384
#endif
349
385
  wlocate(dialwin, 1, 5);
350
386
  wprintf(dialwin, "                                       \n");
351
387
  wprintf(dialwin, "                                             ");
352
 
  return(ret);
 
388
  return ret;
353
389
}
354
390
 
355
391
/*
356
392
 * Dial a number, and display the name.
357
393
 */
358
 
long dial(d, d2)
359
 
struct dialent *d;
360
 
struct dialent **d2;
 
394
long dial(struct dialent *d, struct dialent **d2)
361
395
{
362
396
  char *s = 0, *t = 0;
363
397
  int f, x = 0;
384
418
 
385
419
  wputs(dialwin, "\n");
386
420
  wprintf(dialwin, " %s : %s\n", _("Dialing"), d->name);
387
 
  wprintf(dialwin, _("      At : %s\n"), d->number);
 
421
  wprintf(dialwin, _("      At : %s"), d->number);
 
422
  wprintf(dialwin, "\n"); /* help translators */
388
423
  if (d->lastdate[0] && d->lasttime[0])         /* jl 26.01.98 */
389
 
    wprintf(dialwin, _(" Last on : %s at %s\n"), d->lastdate, d->lasttime);
390
 
  else
391
 
    wprintf(dialwin, "\n");
 
424
    wprintf(dialwin, _(" Last on : %s at %s"), d->lastdate, d->lasttime);
 
425
  wprintf(dialwin, "\n");
392
426
  wredraw(dialwin, 1);
393
427
 
394
428
  /* Tell keyboard routines we need them. */
395
429
  keyboard(KSIGIO, 0);
396
430
 
397
431
  maxretries = atoi(P_MRETRIES);
398
 
  if (maxretries <= 0) maxretries = 1;
 
432
  if (maxretries <= 0)
 
433
    maxretries = 1;
399
434
  rdelay = atoi(P_MRDELAY);
400
 
  if (rdelay < 0) rdelay = 0;
 
435
  if (rdelay < 0)
 
436
    rdelay = 0;
401
437
 
402
438
  /* Main retry loop of dial() */
403
439
MainLoop:
404
 
  while(++retries <= maxretries) {
405
 
 
406
 
        /* See if we need to try the next tagged entry. */
407
 
        if (retries > 1 && (d->flags & FL_TAG)) {
408
 
                do {
409
 
                        d = d->next;
410
 
                        if (d == (struct dialent *)NULL) d = dialents;
411
 
                } while(!(d->flags & FL_TAG));
412
 
                wlocate(dialwin, 0, 1);
413
 
                wprintf(dialwin, _(" Dialing : %s"), d->name);
414
 
                wclreol(dialwin);
415
 
                wprintf(dialwin, _("\n      At : %s"), d->number);
416
 
                wclreol(dialwin);
417
 
                if (d->lastdate[0] && d->lasttime[0]) {
418
 
                  wprintf(dialwin, _("\n Last on : %s at %s"),
419
 
                          d->lastdate, d->lasttime);
420
 
                  wclreol(dialwin);
421
 
                }
422
 
        }
423
 
 
424
 
        /* Calculate dial time */
425
 
        dialtime = atoi(P_MDIALTIME);
426
 
        if (dialtime == 0) dialtime = 45;
427
 
        time(&now);
428
 
        last = now;
429
 
 
430
 
        /* Show used time */
431
 
        wlocate(dialwin, 0, 4);
432
 
        wprintf(dialwin, _("    Time : %-3d"), dialtime);
433
 
        if (maxretries > 1) wprintf(dialwin, _("     Attempt #%d"), retries);
434
 
        wputs(dialwin, _("\n\n\n Escape to cancel, space to retry."));
435
 
        
436
 
        /* Start the dial */
437
 
        m_flush(portfd);
438
 
        switch(d->dialtype) {
439
 
                case 0:
440
 
                        mputs(P_MDIALPRE, 0);
441
 
                        mputs(d->number, 0);
442
 
                        mputs(P_MDIALSUF, 0);
443
 
                        break;
444
 
                case 1:
445
 
                        mputs(P_MDIALPRE2, 0);
446
 
                        mputs(d->number, 0);
447
 
                        mputs(P_MDIALSUF2, 0);
448
 
                        break;
449
 
                case 2:
450
 
                        mputs(P_MDIALPRE3, 0);
451
 
                        mputs(d->number, 0);
452
 
                        mputs(P_MDIALSUF3, 0);
453
 
                        break;
454
 
        }
455
 
 
456
 
        /* Wait 'till the modem says something */
457
 
        modbuf[0] = 0;
458
 
        modidx = 0;
459
 
        s = buf;
460
 
        buf[0] = 0;
461
 
        while(dialtime > 0) {
462
 
            if (*s == 0) {
463
 
                x = check_io(portfd_connected, 0, 1000, buf, NULL);
464
 
                s = buf;
465
 
            }
466
 
            if (x & 2) {
467
 
                f = keyboard(KGETKEY, 0);
468
 
                /* Cancel if escape was pressed. */
469
 
                if (f == K_ESC) mputs(P_MDIALCAN, 0);
470
 
 
471
 
                /* On space retry. */
472
 
                if (f == ' ') {
473
 
                        mputs(P_MDIALCAN, 0);
474
 
                        dialfailed(_("Cancelled"), 4);
475
 
                        m_flush(portfd);
476
 
                        break;
477
 
                }
478
 
                (void) keyboard(KSTOP, 0);
479
 
                wclose(dialwin, 1);
480
 
                return(retst);
481
 
            }
482
 
            if (x & 1) {
483
 
                /* Data available from the modem. Put in buffer. */
484
 
                if (*s == '\r' || *s == '\n') {
485
 
                        /* We look for [\r\n]STRING[\r\n] */
486
 
                        modbuf[modidx] = 0;
487
 
                        modidx = 0;
488
 
                } else if (modidx < 127) {
489
 
                        /* Normal character. Add. */
490
 
                        modbuf[modidx++] = *s;
491
 
                        modbuf[modidx] = 0;
492
 
                }
493
 
                /* Skip to next received char */
494
 
                if (*s) s++;
495
 
                /* Only look when we got a whole line. */
496
 
                if (modidx == 0 &&
497
 
                    !strncmp(modbuf, P_MCONNECT, strlen(P_MCONNECT))) {
498
 
                        timer_update(); /* the login scipt may take long.. */
499
 
                        retst = 0;
500
 
                        /* Try to do auto-bauding */
501
 
                        if (sscanf(modbuf + strlen(P_MCONNECT), "%ld", &nb) == 1)
502
 
                                retst = nb;
503
 
                        linespd = retst;
504
 
 
505
 
                        /* Try to figure out if this system supports DCD */
506
 
                        f = m_getdcd(portfd);
507
 
                        bogus_dcd = 1;
508
 
 
509
 
                        /* jl 22.05.97, 22.09.97, 05.04.99 */
510
 
                        if (P_LOGCONN[0] == 'Y')
511
 
                          do_log("%s %s, %s",modbuf, d->name, d->number);
512
 
 
513
 
                        ptime=localtime(&now);
514
 
                        sprintf(d->lastdate,"%4.4d%2.2d%2.2d",
515
 
                                (ptime->tm_year)+1900,(ptime->tm_mon)+1,
516
 
                                ptime->tm_mday);
517
 
                        sprintf(d->lasttime,"%02d:%02d",
518
 
                                ptime->tm_hour,ptime->tm_min);
519
 
                        d->count ++;
520
 
 
521
 
#if _HAVE_MACROS
522
 
                        if (d->convfile[0]) {
523
 
                          loadconv(d->convfile);    /* jl 21.09.97 */
524
 
                          strcpy(P_CONVF, d->convfile);
525
 
                        }
526
 
#endif
527
 
 
528
 
                        wlocate(dialwin, 1, 7);
529
 
                        if (d->script[0] == 0) {
530
 
                                wputs(dialwin,
531
 
                                    _("Connected. Press any key to continue"));
532
 
#if VC_MUSIC
533
 
                                if (P_SOUND[0] == 'Y')
534
 
                                        music();
535
 
                                else {
536
 
                                        x = check_io(-1, 0, 0, NULL, NULL);
537
 
                                        if ((x & 2) == 2)
538
 
                                                (void) keyboard(KGETKEY, 0);
539
 
                                }
 
440
  while (++retries <= maxretries) {
 
441
 
 
442
    /* See if we need to try the next tagged entry. */
 
443
    if (retries > 1 && (d->flags & FL_TAG)) {
 
444
      do {
 
445
        d = d->next;
 
446
        if (d == (struct dialent *)NULL)
 
447
          d = dialents;
 
448
      } while (!(d->flags & FL_TAG));
 
449
      wlocate(dialwin, 0, 1);
 
450
      wprintf(dialwin, " %s : %s", _("Dialing"), d->name);
 
451
      wclreol(dialwin);
 
452
      wprintf(dialwin, "\n"); /* helps translators */
 
453
      wprintf(dialwin, _("      At : %s"), d->number);
 
454
      wclreol(dialwin);
 
455
      if (d->lastdate[0] && d->lasttime[0]) {
 
456
        wprintf(dialwin, "\n"); /* don't merge with next printf, helps translators */
 
457
        wprintf(dialwin, _(" Last on : %s at %s"),
 
458
                d->lastdate, d->lasttime);
 
459
        wclreol(dialwin);
 
460
      }
 
461
    }
 
462
 
 
463
    /* Calculate dial time */
 
464
    dialtime = atoi(P_MDIALTIME);
 
465
    if (dialtime == 0)
 
466
      dialtime = 45;
 
467
    time(&now);
 
468
    last = now;
 
469
 
 
470
    /* Show used time */
 
471
    wlocate(dialwin, 0, 4);
 
472
    wprintf(dialwin, _("    Time : %-3d"), dialtime);
 
473
    if (maxretries > 1)
 
474
      wprintf(dialwin, _("     Attempt #%d"), retries);
 
475
    wputs(dialwin, _("\n\n\n Escape to cancel, space to retry."));
 
476
 
 
477
    /* Start the dial */
 
478
    m_flush(portfd);
 
479
    switch (d->dialtype) {
 
480
      case 0:
 
481
        mputs(P_MDIALPRE, 0);
 
482
        mputs(d->number, 0);
 
483
        mputs(P_MDIALSUF, 0);
 
484
        break;
 
485
      case 1:
 
486
        mputs(P_MDIALPRE2, 0);
 
487
        mputs(d->number, 0);
 
488
        mputs(P_MDIALSUF2, 0);
 
489
        break;
 
490
      case 2:
 
491
        mputs(P_MDIALPRE3, 0);
 
492
        mputs(d->number, 0);
 
493
        mputs(P_MDIALSUF3, 0);
 
494
        break;
 
495
    }
 
496
 
 
497
    /* Wait 'till the modem says something */
 
498
    modbuf[0] = 0;
 
499
    modidx = 0;
 
500
    s = buf;
 
501
    buf[0] = 0;
 
502
    while (dialtime > 0) {
 
503
      if (*s == 0) {
 
504
        x = check_io(portfd_connected, 0, 1000, buf, NULL);
 
505
        s = buf;
 
506
      }
 
507
      if (x & 2) {
 
508
        f = keyboard(KGETKEY, 0);
 
509
        /* Cancel if escape was pressed. */
 
510
        if (f == K_ESC)
 
511
          mputs(P_MDIALCAN, 0);
 
512
 
 
513
        /* On space retry. */
 
514
        if (f == ' ') {
 
515
          mputs(P_MDIALCAN, 0);
 
516
          dialfailed(_("Cancelled"), 4);
 
517
          m_flush(portfd);
 
518
          break;
 
519
        }
 
520
        keyboard(KSTOP, 0);
 
521
        wclose(dialwin, 1);
 
522
        return retst;
 
523
      }
 
524
      if (x & 1) {
 
525
        /* Data available from the modem. Put in buffer. */
 
526
        if (*s == '\r' || *s == '\n') {
 
527
          /* We look for [\r\n]STRING[\r\n] */
 
528
          modbuf[modidx] = 0;
 
529
          modidx = 0;
 
530
        } else if (modidx < 127) {
 
531
          /* Normal character. Add. */
 
532
          modbuf[modidx++] = *s;
 
533
          modbuf[modidx] = 0;
 
534
        }
 
535
        /* Skip to next received char */
 
536
        if (*s)
 
537
          s++;
 
538
        /* Only look when we got a whole line. */
 
539
        if (modidx == 0 &&
 
540
            !strncmp(modbuf, P_MCONNECT, strlen(P_MCONNECT))) {
 
541
          timer_update(); /* the login scipt may take long.. */
 
542
          retst = 0;
 
543
          /* Try to do auto-bauding */
 
544
          if (sscanf(modbuf + strlen(P_MCONNECT), "%ld", &nb) == 1)
 
545
            retst = nb;
 
546
          linespd = retst;
 
547
 
 
548
          /* Try to figure out if this system supports DCD */
 
549
          f = m_getdcd(portfd);
 
550
          bogus_dcd = 1;
 
551
 
 
552
          /* jl 22.05.97, 22.09.97, 05.04.99 */
 
553
          if (P_LOGCONN[0] == 'Y')
 
554
            do_log("%s %s, %s",modbuf, d->name, d->number);
 
555
 
 
556
          ptime = localtime(&now);
 
557
          sprintf(d->lastdate,"%4.4d%2.2d%2.2d",
 
558
                  (ptime->tm_year)+1900,(ptime->tm_mon)+1,
 
559
                  ptime->tm_mday);
 
560
          sprintf(d->lasttime,"%02d:%02d",
 
561
                  ptime->tm_hour,ptime->tm_min);
 
562
          d->count++;
 
563
 
 
564
          if (d->convfile[0]) {
 
565
            loadconv(d->convfile);    /* jl 21.09.97 */
 
566
            strcpy(P_CONVF, d->convfile);
 
567
          }
 
568
 
 
569
          wlocate(dialwin, 1, 7);
 
570
          if (d->script[0] == 0) {
 
571
            wputs(dialwin,
 
572
                  _("Connected. Press any key to continue"));
 
573
#ifdef VC_MUSIC
 
574
            if (P_SOUND[0] == 'Y')
 
575
              music();
 
576
            else {
 
577
              x = check_io(-1, 0, 0, NULL, NULL);
 
578
              if ((x & 2) == 2)
 
579
                keyboard(KGETKEY, 0);
 
580
            }
540
581
#else
541
 
                                /* MARK updated 02/17/94 - If VC_MUSIC is not */
542
 
                                /* defined, then at least make some beeps! */
543
 
                                if (P_SOUND[0] == 'Y') 
544
 
                                        wputs(dialwin,"\007\007\007");
 
582
            /* MARK updated 02/17/94 - If VC_MUSIC is not */
 
583
            /* defined, then at least make some beeps! */
 
584
            if (P_SOUND[0] == 'Y') 
 
585
              wputs(dialwin,"\007\007\007");
545
586
#endif
546
 
                                x = check_io(-1, 0, 0, NULL, NULL);
547
 
                                if ((x & 2) == 2)
548
 
                                        (void) keyboard(KGETKEY, 0);
549
 
                        }
550
 
                        keyboard(KSTOP, 0);
551
 
                        wclose(dialwin, 1);
552
 
                        /* Print out the connect strings. */
553
 
                        wprintf(us, "\r\n%s\r\n", modbuf);
554
 
                        dialwin = NIL_WIN;
555
 
 
556
 
                        /* Un-tag this entry. */
557
 
                        d->flags &= ~FL_TAG;
558
 
 
559
 
                        /* store pointer to the entry that ANSWERED */
560
 
                        if (d2 != (struct dialent**)NULL)
561
 
                          *d2 = d;      /* jl 23.09.97 */
562
 
 
563
 
/* Here should placed code to untag phones with similar names */ 
564
 
                        if (P_MULTILINE[0] == 'Y') {
565
 
                        
566
 
                          struct dialent *d3;
567
 
                                
568
 
                          d3 = dialents;
569
 
                          while (d3 != (struct dialent*)NULL) {
570
 
                                if (!strcmp(d3->name, d->name))
571
 
                                        d3->flags &= ~FL_TAG;
572
 
 
573
 
                                d3 = d3->next;
574
 
                          }                             
575
 
                        }                               /*  er 27-Apr-99 */
576
 
 
577
 
                        return(retst);
578
 
                }
579
 
                for(f = 0; f < 3; f++) {
580
 
                        if (f == 0) t = P_MNOCON1;
581
 
                        if (f == 1) t = P_MNOCON2;
582
 
                        if (f == 2) t = P_MNOCON3;
583
 
                        if (f == 3) t = P_MNOCON4;
584
 
                        if ((*t) && (!strncmp(modbuf, t, strlen(t)))) {
585
 
                                if (retries < maxretries) {
586
 
                                        x = dialfailed(t, rdelay);
587
 
                                        if (x < 0) {
588
 
                                                keyboard(KSTOP, 0);
589
 
                                                wclose(dialwin, 1);
590
 
                                                return(retst);
591
 
                                        }
592
 
                                }
593
 
                                if (maxretries == 1) reason = t;
594
 
                                goto MainLoop;
595
 
                        }
596
 
                }
597
 
            }
598
 
 
599
 
            /* Do timer routines here. */
600
 
            time(&now);
601
 
            if (last != now) {
602
 
                dialtime -= (now - last);
603
 
                if (dialtime < 0) dialtime = 0;
604
 
                wlocate(dialwin, 11, 4);
605
 
                wprintf(dialwin, "%-3d  ", dialtime);
606
 
                if (dialtime <= 0) {
607
 
                        mputs(P_MDIALCAN, 0);
608
 
                        reason = _("Timeout");
609
 
                        retst = -1;
610
 
                        if (retries < maxretries) {
611
 
                                x = dialfailed(reason, rdelay);
612
 
                                if (x < 0) {
613
 
                                        keyboard(KSTOP, 0);
614
 
                                        wclose(dialwin, 1);
615
 
                                        return(retst);
616
 
                                }
617
 
                        }
618
 
                }
619
 
            }
620
 
            last = now;
621
 
        }
 
587
            x = check_io(-1, 0, 0, NULL, NULL);
 
588
            if ((x & 2) == 2)
 
589
              keyboard(KGETKEY, 0);
 
590
          }
 
591
          keyboard(KSTOP, 0);
 
592
          wclose(dialwin, 1);
 
593
          /* Print out the connect strings. */
 
594
          wprintf(us, "\r\n%s\r\n", modbuf);
 
595
          dialwin = NULL;
 
596
 
 
597
          /* Un-tag this entry. */
 
598
          d->flags &= ~FL_TAG;
 
599
 
 
600
          /* store pointer to the entry that ANSWERED */
 
601
          if (d2 != (struct dialent**)NULL)
 
602
            *d2 = d;    /* jl 23.09.97 */
 
603
 
 
604
          /* Here should placed code to untag phones with similar names */ 
 
605
          if (P_MULTILINE[0] == 'Y') {
 
606
            struct dialent *d3 = dialents;
 
607
 
 
608
            while (d3 != (struct dialent*)NULL) {
 
609
              if (!strcmp(d3->name, d->name))
 
610
                d3->flags &= ~FL_TAG;
 
611
              d3 = d3->next;
 
612
            }                           
 
613
          }                             /*  er 27-Apr-99 */
 
614
          return retst;
 
615
        }
 
616
 
 
617
        for (f = 0; f < 3; f++) {
 
618
          if (f == 0)
 
619
            t = P_MNOCON1;
 
620
          if (f == 1)
 
621
            t = P_MNOCON2;
 
622
          if (f == 2)
 
623
            t = P_MNOCON3;
 
624
          if (f == 3)
 
625
            t = P_MNOCON4;
 
626
          if ((*t) && (!strncmp(modbuf, t, strlen(t)))) {
 
627
            if (retries < maxretries) {
 
628
              x = dialfailed(t, rdelay);
 
629
              if (x < 0) {
 
630
                keyboard(KSTOP, 0);
 
631
                wclose(dialwin, 1);
 
632
                return retst;
 
633
              }
 
634
            }
 
635
            if (maxretries == 1)
 
636
              reason = t;
 
637
            goto MainLoop;
 
638
          }
 
639
        }
 
640
      }
 
641
 
 
642
      /* Do timer routines here. */
 
643
      time(&now);
 
644
      if (last != now) {
 
645
        dialtime -= (now - last);
 
646
        if (dialtime < 0)
 
647
          dialtime = 0;
 
648
        wlocate(dialwin, 11, 4);
 
649
        wprintf(dialwin, "%-3d  ", dialtime);
 
650
        if (dialtime <= 0) {
 
651
          mputs(P_MDIALCAN, 0);
 
652
          reason = _("Timeout");
 
653
          retst = -1;
 
654
          if (retries < maxretries) {
 
655
            x = dialfailed(reason, rdelay);
 
656
            if (x < 0) {
 
657
              keyboard(KSTOP, 0);
 
658
              wclose(dialwin, 1);
 
659
              return retst;
 
660
            }
 
661
          }
 
662
        }
 
663
      }
 
664
      last = now;
 
665
    }
622
666
  } /* End of main while cq MainLoop */ 
623
667
  dialfailed(reason, -1);
624
668
  keyboard(KSTOP, 0);
625
669
  wclose(dialwin, 1);
626
 
  return(retst);
 
670
  return retst;
627
671
}
628
672
 
629
673
/*
630
674
 * Create an empty entry.
631
675
 */
632
 
static struct dialent *mkstdent()
 
676
static struct dialent *mkstdent(void)
633
677
{
634
 
  struct dialent *d;
635
 
  
636
 
  d = (struct dialent *)malloc(sizeof (struct dialent));
637
 
  
638
 
  if (d == (struct dialent *)0) return(d);
 
678
  struct dialent *d = (struct dialent *)malloc(sizeof (struct dialent));
 
679
  
 
680
  if (d == (struct dialent *)0)
 
681
    return d;
639
682
 
640
683
  d->name[0] = 0;
641
684
  d->number[0] = 0;
655
698
  strcpy(d->stopb, "1");
656
699
  d->next = (struct dialent *)0;
657
700
 
658
 
  return(d);
 
701
  return d;
659
702
}
660
703
 
661
704
/* Read version 4 of the dialing directory. */
662
 
void v4_read(fp, d, dv)
663
 
struct dialent *d;
664
 
FILE *fp;
665
 
struct dver *dv;        /* jl 21.09.97 */
 
705
void v4_read(FILE *fp, struct dialent *d, struct dver *dv)
666
706
{
667
707
  (void) fread((char *)d, dv->size, (size_t)1, fp);
668
708
 
669
709
  if (dv->size < sizeof(struct dialent)) {
670
 
    if (dv->size < offsetof(struct dialent, count) + sizeof(struct dialent *)){
 
710
    if (dv->size < offsetof(struct dialent, count) + sizeof(struct dialent *)) {
671
711
      d->count = 0;
672
712
      d->lasttime[0] = 0;
673
713
      d->lastdate[0] = 0;
679
719
}
680
720
 
681
721
/* Read version 3 of the dialing directory. */
682
 
void v3_read(fp, d)
683
 
struct dialent *d;
684
 
FILE *fp;
 
722
void v3_read(FILE *fp, struct dialent *d)
685
723
{
686
724
  struct v3_dialent v3;   /* jl 22.06.97 */
687
725
 
688
726
  (void) fread((char *)&v3, sizeof(v3), (size_t)1, fp);
689
727
  memcpy(d, &v3, offsetof(struct v3_dialent, next));
690
 
  
691
 
  d->lastdate[0]=0;
692
 
  d->lasttime[0]=0;
693
 
  d->count=0;
694
 
  d->convfile[0]=0;
 
728
 
 
729
  d->lastdate[0] = 0;
 
730
  d->lasttime[0] = 0;
 
731
  d->count = 0;
 
732
  d->convfile[0] = 0;
695
733
  strcpy(d->stopb, "1");
696
734
}
697
735
 
698
736
/* Read version 2 of the dialing directory. */
699
 
void v2_read(fp, d)
700
 
struct dialent *d;
701
 
FILE *fp;
 
737
void v2_read(FILE *fp, struct dialent *d)
702
738
{
703
739
  struct v3_dialent v3;   /* jl 22.06.97 */
704
740
 
705
 
  (void) fread((char *)&v3, sizeof(v3), (size_t)1, fp);
 
741
  fread((char *)&v3, sizeof(v3), (size_t)1, fp);
706
742
  memcpy(d, &v3, offsetof(struct v3_dialent, next));
707
 
  if (d->flags & FL_ANSI) d->flags |= FL_WRAP;
708
 
  d->lastdate[0]=0;
709
 
  d->lasttime[0]=0;
710
 
  d->count=0;
711
 
  d->convfile[0]=0;
 
743
  if (d->flags & FL_ANSI)
 
744
    d->flags |= FL_WRAP;
 
745
  d->lastdate[0] = 0;
 
746
  d->lasttime[0] = 0;
 
747
  d->count = 0;
 
748
  d->convfile[0] = 0;
712
749
  strcpy(d->stopb, "1");
713
750
}
714
751
 
715
752
/* Read version 1 of the dialing directory. */
716
 
void v1_read(fp, d)
717
 
FILE *fp;
718
 
struct dialent *d;
 
753
void v1_read(FILE *fp, struct dialent *d)
719
754
{
720
755
  struct v1_dialent v1;
721
756
 
732
767
}
733
768
 
734
769
/* Read version 0 of the dialing directory. */
735
 
void v0_read(fp, d)
736
 
FILE *fp;
737
 
struct dialent *d;
 
770
void v0_read(FILE *fp, struct dialent *d)
738
771
{
739
772
  v1_read(fp, d);
740
773
  d->dialtype = 0;
744
777
/*
745
778
 * Read in the dialing directory from $HOME/.dialdir
746
779
 */
747
 
int readdialdir()
 
780
int readdialdir(void)
748
781
{
749
782
  long size;
750
783
  FILE *fp;
756
789
  struct dver dial_ver;
757
790
  WIN *w;
758
791
 
759
 
  if (didread) return(0);
 
792
  if (didread)
 
793
    return(0);
760
794
  didread = 1;
761
795
  nrents = 1;
762
796
  tagged = (char *)malloc(1);
771
805
 
772
806
  /* Try to open ~/.dialdir */
773
807
  if ((fp = sfopen(dfile, "r")) == (FILE *)NULL) {
774
 
        if (errno == EPERM) {
775
 
                werror(_("Cannot open ~/.dialdir: permission denied"));
776
 
                dialents = mkstdent();
777
 
                dendd = 1;
778
 
                return(0);
779
 
        }
780
 
        dialents = mkstdent();
781
 
        return(0);
 
808
    if (errno == EPERM) {
 
809
      werror(_("Cannot open ~/.dialdir: permission denied"));
 
810
      dialents = mkstdent();
 
811
      dendd = 1;
 
812
      return 0;
 
813
    }
 
814
    dialents = mkstdent();
 
815
    return 0;
782
816
  }
783
817
 
784
818
  /* Get size of the file */
785
819
  fseek(fp, 0L, SEEK_END);
786
820
  size = ftell(fp);
787
821
  if (size == 0) {
788
 
        dialents = mkstdent();
789
 
        fclose(fp);
790
 
        return(0);
 
822
    dialents = mkstdent();
 
823
    fclose(fp);
 
824
    return 0;
791
825
  }
792
826
 
793
827
  /* Get version of the dialing directory */
794
828
  fseek(fp, 0L, SEEK_SET);
795
829
  fread(&dial_ver, sizeof(dial_ver), 1, fp);
796
830
  if (dial_ver.magic != DIALMAGIC) {
797
 
        /* First version without version info. */
798
 
        dial_ver.version = 0;
799
 
        fseek(fp, 0L, SEEK_SET);
 
831
    /* First version without version info. */
 
832
    dial_ver.version = 0;
 
833
    fseek(fp, 0L, SEEK_SET);
800
834
  } else
801
 
        size -= sizeof(dial_ver);
 
835
    size -= sizeof(dial_ver);
802
836
 
803
837
  /* See if the size of the file is allright. */
804
 
  switch(dial_ver.version) {
805
 
        case 0:
806
 
        case 1:
807
 
                dial_ver.size = sizeof(struct v1_dialent);
808
 
                break;
809
 
        case 2:
810
 
        case 3:
811
 
                dial_ver.size = sizeof(struct v3_dialent);
812
 
                break;
813
 
        case 4:
814
 
          /* dial_ver.size = sizeof(struct dialent); */
815
 
          /* Removed the forced setting to add flexibility.
816
 
           * Now you don't need to change the version number
817
 
           * if you just add fields to the end of the dialent structure
818
 
           * before the *next pointer and don't change existing fields.
819
 
           * Just update the initialization in the functions
820
 
           * v4_read and mkstdent (and whatever you added the field for)
821
 
           * jl 21.09.97
822
 
           */
823
 
                if (dial_ver.size < 200 ||
824
 
                    dial_ver.size > sizeof(struct dialent)) {
825
 
                  werror(_("Phonelist garbled (unknown version?)"));
826
 
                  dendd = 1;
827
 
                  dialents = mkstdent();
828
 
                  return(-1);
829
 
                }
830
 
                break;
831
 
        default:
832
 
                werror(_("Unknown dialing directory version"));
833
 
                dendd = 1;
834
 
                dialents = mkstdent();
835
 
                return(-1);
 
838
  switch (dial_ver.version) {
 
839
    case 0:
 
840
    case 1:
 
841
      dial_ver.size = sizeof(struct v1_dialent);
 
842
      break;
 
843
    case 2:
 
844
    case 3:
 
845
      dial_ver.size = sizeof(struct v3_dialent);
 
846
      break;
 
847
    case 4:
 
848
      /* dial_ver.size = sizeof(struct dialent); */
 
849
      /* Removed the forced setting to add flexibility.
 
850
       * Now you don't need to change the version number
 
851
       * if you just add fields to the end of the dialent structure
 
852
       * before the *next pointer and don't change existing fields.
 
853
       * Just update the initialization in the functions
 
854
       * v4_read and mkstdent (and whatever you added the field for)
 
855
       * jl 21.09.97
 
856
       */
 
857
      if (dial_ver.size < 200 ||
 
858
          dial_ver.size > sizeof(struct dialent)) {
 
859
        werror(_("Phonelist garbled (unknown version?)"));
 
860
        dendd = 1;
 
861
        dialents = mkstdent();
 
862
        return -1;
 
863
      }
 
864
      break;
 
865
    default:
 
866
      werror(_("Unknown dialing directory version"));
 
867
      dendd = 1;
 
868
      dialents = mkstdent();
 
869
      return -1;
836
870
  }
837
871
 
838
872
  if (size % dial_ver.size != 0) {
839
 
        werror(_("Phonelist garbled (?)"));
840
 
        fclose(fp);
841
 
        dendd = 1;
842
 
        dialents = mkstdent();
843
 
        return(-1);
 
873
    werror(_("Phonelist garbled (?)"));
 
874
    fclose(fp);
 
875
    dendd = 1;
 
876
    dialents = mkstdent();
 
877
    return -1;
844
878
  }
845
879
 
846
880
  /* Read in the dialing entries */
847
881
  nrents = size / dial_ver.size;
848
882
  if (nrents == 0) {
849
 
        dialents = mkstdent();
850
 
        nrents = 1;
851
 
        fclose(fp);
852
 
        return(0);
 
883
    dialents = mkstdent();
 
884
    nrents = 1;
 
885
    fclose(fp);
 
886
    return 0;
853
887
  }
854
888
  for(f = 1; f <= nrents; f++) {
855
 
        if ((d = (struct dialent *)malloc(sizeof (struct dialent))) ==
856
 
                (struct dialent *)0) {
857
 
                        if(f == 1)
858
 
                                dialents = mkstdent();
859
 
                        else
860
 
                                prev->next = (struct dialent *)0;
861
 
 
862
 
                        werror(_("Out of memory while reading dialing directory"));
863
 
                        fclose(fp);
864
 
                        return(-1);
865
 
        }
866
 
        switch(dial_ver.version) {
867
 
                case 0:
868
 
                        v0_read(fp, d);
869
 
                        break;
870
 
                case 1:
871
 
                        v1_read(fp, d);
872
 
                        break;
873
 
                case 2:
874
 
                        v2_read(fp, d);
875
 
                        break;
876
 
                case 3:
877
 
                        v3_read(fp, d);
878
 
                        break;
879
 
                case 4:
880
 
                        v4_read(fp, d, &dial_ver);
881
 
                        break;
882
 
        }
883
 
        /* MINIX terminal type is obsolete */
884
 
        if (d->term == 2) d->term = 1;
885
 
 
886
 
        if (prev != (struct dialent *)0)
887
 
                prev->next = d;
888
 
        else
889
 
                dialents = d;
890
 
        prev = d;
 
889
    if ((d = (struct dialent *)malloc(sizeof (struct dialent))) ==
 
890
        (struct dialent *)0) {
 
891
      if (f == 1)
 
892
        dialents = mkstdent();
 
893
      else
 
894
        prev->next = (struct dialent *)0;
 
895
 
 
896
      werror(_("Out of memory while reading dialing directory"));
 
897
      fclose(fp);
 
898
      return -1;
 
899
    }
 
900
    switch (dial_ver.version) {
 
901
      case 0:
 
902
        v0_read(fp, d);
 
903
        break;
 
904
      case 1:
 
905
        v1_read(fp, d);
 
906
        break;
 
907
      case 2:
 
908
        v2_read(fp, d);
 
909
        break;
 
910
      case 3:
 
911
        v3_read(fp, d);
 
912
        break;
 
913
      case 4:
 
914
        v4_read(fp, d, &dial_ver);
 
915
        break;
 
916
    }
 
917
    /* MINIX terminal type is obsolete */
 
918
    if (d->term == 2)
 
919
      d->term = 1;
 
920
 
 
921
    if (prev != (struct dialent *)0)
 
922
      prev->next = d;
 
923
    else
 
924
      dialents = d;
 
925
    prev = d;
891
926
  }
892
927
  d->next = (struct dialent *)0;
893
928
  fclose(fp);
894
929
  if (dial_ver.size < sizeof(struct dialent)) {
895
930
    if (snprintf(copycmd,sizeof(copycmd),
896
 
             "cp %s %s.%hd",dfile,dfile,dial_ver.size) > 0) {
 
931
                 "cp %s %s.%hd",dfile,dfile,dial_ver.size) > 0) {
897
932
      if (P_LOGFNAME[0] != 0)
898
 
        do_log("%s", copycmd);
 
933
        do_log("%s", copycmd);
899
934
      if (system(copycmd) == 0) {
900
 
        snprintf(copycmd,sizeof(copycmd),
901
 
                 _("Old dialdir copied as %s.%hd"),dfile,dial_ver.size);
902
 
        w=mc_tell("%s", copycmd);
903
 
        if (w) {
904
 
          sleep(2);
905
 
          wclose(w,1);
906
 
        }
907
 
        writedialdir();
 
935
        snprintf(copycmd,sizeof(copycmd),
 
936
                 _("Old dialdir copied as %s.%hd"),dfile,dial_ver.size);
 
937
        w = mc_tell("%s", copycmd);
 
938
        if (w) {
 
939
          sleep(2);
 
940
          wclose(w,1);
 
941
        }
 
942
        writedialdir();
908
943
      }
909
944
    }
910
945
  }
911
 
  return(0);
 
946
  return 0;
912
947
}
913
948
 
914
949
/*
915
950
 * Write the new $HOME/.dialdir
916
951
 */
917
 
static void writedialdir()
 
952
static void writedialdir(void)
918
953
{
919
954
  struct dialent *d;
920
955
  char dfile[256];
924
959
  int omask;
925
960
 
926
961
  /* Make no sense if access denied */
927
 
  if (dendd) return;
 
962
  if (dendd)
 
963
    return;
928
964
 
929
965
  snprintf(dfile, sizeof(dfile), "%s/.dialdir", homedir);
930
966
 
931
967
  omask = umask(077);
932
968
  if ((fp = sfopen(dfile, "w")) == (FILE *)0) {
933
 
        (void)umask(omask);
934
 
        werror(_("Can't write to ~/.dialdir"));
935
 
        dendd = 1;
936
 
        return;
 
969
    umask(omask);
 
970
    werror(_("Cannot open ~/.dialdir for writing!"));
 
971
    dendd = 1;
 
972
    return;
937
973
  }
938
 
  (void)umask(omask);
 
974
  umask(omask);
939
975
 
940
976
  d = dialents;
941
977
  /* Set up version info. */
946
982
  dial_ver.res2 = 0;    /* initialize them to a known init value for */
947
983
  dial_ver.res3 = 0;    /* whoever needs them later / jl 22.09.97    */
948
984
  dial_ver.res4 = 0;
949
 
  fwrite(&dial_ver, sizeof(dial_ver), (size_t)1, fp);
 
985
  if (fwrite(&dial_ver, sizeof(dial_ver), (size_t)1, fp) != 1) {
 
986
    werror(_("Error writing to ~/.dialdir!"));
 
987
    fclose(fp);
 
988
    return;
 
989
  }
950
990
 
951
991
  /* Write dialing directory */
952
 
  while(d) {
953
 
        oldfl = d->flags;
954
 
        d->flags &= FL_SAVE;
955
 
        if (fwrite(d, sizeof(struct dialent), (size_t)1, fp) != 1) {
956
 
                werror(_("Error writing ~/.dialdir!"));
957
 
                fclose(fp);
958
 
                return;
959
 
        }
960
 
        d->flags = oldfl;
961
 
        d = d->next;
 
992
  while (d) {
 
993
    oldfl = d->flags;
 
994
    d->flags &= FL_SAVE;
 
995
    if (fwrite(d, sizeof(struct dialent), (size_t)1, fp) != 1) {
 
996
      werror(_("Error writing to ~/.dialdir!"));
 
997
      fclose(fp);
 
998
      return;
 
999
    }
 
1000
    d->flags = oldfl;
 
1001
    d = d->next;
962
1002
  }
963
1003
  fclose(fp);
964
1004
}
967
1007
/*
968
1008
 * Get entry "no" in list.
969
1009
 */
970
 
static struct dialent *getno(no)
971
 
int no;
 
1010
static struct dialent *getno(int no)
972
1011
{
973
1012
  struct dialent *d;
974
 
  
 
1013
 
975
1014
  d = dialents;
976
 
  
977
 
  if (no >= nrents) return((struct dialent *)NULL);
978
 
 
979
 
  while(no--) d = d->next;
980
 
  return(d);
 
1015
 
 
1016
  if (no < 0 || no >= nrents)
 
1017
    return (struct dialent *)NULL;
 
1018
 
 
1019
  while (no--)
 
1020
    d = d->next;
 
1021
 
 
1022
  return d;
981
1023
}
982
1024
 
983
1025
/* Note: Minix does not exist anymore. */
984
 
static char *te[] = { "VT102", "MINIX", "ANSI " };
 
1026
static const char *te[] = { "VT102", "MINIX", "ANSI " };
 
1027
 
 
1028
/*
 
1029
 * Display a "dedit" entry
 
1030
 * We need to make sure that the previous value
 
1031
 * gets fully overwritten in all languages (i.e. arbitrary strings)!
 
1032
 */
 
1033
static void dedit_toggle_entry(WIN *w, int x, int y, int toggle,
 
1034
                               char *toggle_true, char *toggle_false)
 
1035
{
 
1036
  int lt = mbslen(toggle_true);
 
1037
  int lf = mbslen(toggle_false);
 
1038
  int l = ((lt > lf) ? lt : lf) + 1;
 
1039
  char *buf, *s = toggle ? toggle_true : toggle_false;
 
1040
  int i;
 
1041
 
 
1042
  if (!(buf = alloca(l)))
 
1043
    return;
 
1044
 
 
1045
  strncpy(buf, s, l);
 
1046
  for (i = mbslen(s); i < l - 1; i++)
 
1047
    buf[i] = ' ';
 
1048
  buf[l - 1] = 0;
 
1049
 
 
1050
  wlocate(w, x, y);
 
1051
  wputs(w, buf);
 
1052
}
985
1053
 
986
1054
/*
987
1055
 * Edit an entry.
988
1056
 */
989
 
static void dedit(d)
990
 
struct dialent *d;
 
1057
static void dedit(struct dialent *d)
991
1058
{
992
1059
  WIN *w;
993
1060
  int c;
994
 
  char* name = _(" A -  Name                :"),
995
 
      * number = _(" B -  Number              :"),
996
 
      * dial_string = _(" C -  Dial string #       :"),
997
 
      * local_echo = _(" D -  Local echo          :"),
998
 
      * script = _(" E -  Script              :"),
999
 
      * username = _(" F -  Username            :"),
1000
 
      * password = _(" G -  Password            :"),
1001
 
      * terminal_emulation = _(" H -  Terminal Emulation  :"),
1002
 
      * backspace_key_sends = _(" I -  Backspace key sends :"),
1003
 
      * linewrap = _(" J -  Linewrap            :"),
1004
 
      * line_settings = _(" K -  Line Settings       :"),
1005
 
      * conversion_table = _(" L -  Conversion table    :"),
1006
 
      * question = _("Change which setting?");
 
1061
  char *name                = _(" A -  Name                :"),
 
1062
       *number              = _(" B -  Number              :"),
 
1063
       *dial_string         = _(" C -  Dial string #       :"),
 
1064
       *local_echo          = _(" D -  Local echo          :"),
 
1065
       *script              = _(" E -  Script              :"),
 
1066
       *username            = _(" F -  Username            :"),
 
1067
       *password            = _(" G -  Password            :"),
 
1068
       *terminal_emulation  = _(" H -  Terminal Emulation  :"),
 
1069
       *backspace_key_sends = _(" I -  Backspace key sends :"),
 
1070
       *linewrap            = _(" J -  Linewrap            :"),
 
1071
       *line_settings       = _(" K -  Line Settings       :"),
 
1072
       *conversion_table    = _(" L -  Conversion table    :"),
 
1073
       *question            = _("Change which setting?");
1007
1074
  
1008
1075
  w = wopen(5, 4, 75, 19, BDOUBLE, stdattr, mfcolor, mbcolor, 0, 0, 1);
1009
1076
  wprintf(w, "%s %s\n", name, d->name);
1015
1082
  wprintf(w, "%s %s\n", password, d->password);
1016
1083
  wprintf(w, "%s %s\n", terminal_emulation, te[d->term - 1]);
1017
1084
  wprintf(w, "%s %s\n", backspace_key_sends,
1018
 
        d->flags & FL_DEL ? _("Delete") : _("Backspace"));
 
1085
          d->flags & FL_DEL ? _("Delete") : _("Backspace"));
1019
1086
  wprintf(w, "%s %s\n", linewrap,
1020
 
        d->flags & FL_WRAP ? _("On") : _("Off"));
 
1087
          d->flags & FL_WRAP ? _("On") : _("Off"));
1021
1088
  wprintf(w, "%s %s %s%s%s\n", line_settings,
1022
 
        d->baud, d->bits, d->parity, d->stopb);
 
1089
          d->baud, d->bits, d->parity, d->stopb);
1023
1090
  wprintf(w, "%s %s\n", conversion_table, d->convfile);
1024
1091
  wprintf(w, _("      Last dialed         : %s %s\n"),d->lastdate,d->lasttime);
1025
1092
  wprintf(w, _("      Times on            : %d"),d->count);
1027
1094
  wputs(w, question);
1028
1095
  wredraw(w, 1);
1029
1096
 
1030
 
  while(1) {
1031
 
      wlocate(w, strlen (question) + 5, 15);
1032
 
      c = wxgetch();
1033
 
      if (c >= 'a') c -= 32;
1034
 
      switch(c) {
1035
 
        case '\033':
1036
 
        case '\r':
1037
 
        case '\n':
1038
 
                wclose(w, 1);
1039
 
                return;
1040
 
        case 'A':
1041
 
                wlocate(w, strlen (name) + 1, 0);
1042
 
                (void) wgets(w, d->name, 31, 32);
1043
 
                break;
1044
 
        case 'B':
1045
 
                wlocate(w, strlen (number) + 1, 1);
1046
 
                (void) wgets(w, d->number, 31, 32);
1047
 
                break;
1048
 
        case 'C':
1049
 
                d->dialtype = (d->dialtype + 1) % 3;
1050
 
                wlocate(w, strlen (dial_string) + 1, 2);
1051
 
                wprintf(w, "%d", d->dialtype + 1);
1052
 
                wflush();
1053
 
                break;
1054
 
        case 'D':
1055
 
                d->flags ^= FL_ECHO;
1056
 
                wlocate(w, strlen (local_echo) + 1, 3);
1057
 
                wprintf(w, "%s", _(yesno(d->flags & FL_ECHO)));
1058
 
                wflush();
1059
 
                break;
1060
 
        case 'E':
1061
 
                wlocate(w, strlen (script) + 1, 4);
1062
 
                (void) wgets(w, d->script, 31, 32);     
1063
 
                break;
1064
 
        case 'F':
1065
 
                wlocate(w, strlen (username) + 1, 5);
1066
 
                (void) wgets(w, d->username, 31, 32);
1067
 
                break;
1068
 
        case 'G':
1069
 
                wlocate(w, strlen (password) + 1, 6);
1070
 
                (void) wgets(w, d->password, 31, 32);
1071
 
                break;  
1072
 
        case 'H':
1073
 
                d->term = (d->term % 3) + 1;
1074
 
                /* MINIX == 2 is obsolete. */
1075
 
                if (d->term == 2) d->term = 3;
1076
 
                wlocate(w, strlen (terminal_emulation) + 1, 7);
1077
 
                wputs(w, te[d->term - 1]);      
 
1097
  while (1) {
 
1098
    wlocate(w, mbslen (question) + 5, 15);
 
1099
    c = wxgetch();
 
1100
    if (c >= 'a')
 
1101
      c -= 32;
 
1102
    switch(c) {
 
1103
      case '\033':
 
1104
      case '\r':
 
1105
      case '\n':
 
1106
        wclose(w, 1);
 
1107
        return;
 
1108
      case 'A':
 
1109
        wlocate(w, mbslen (name) + 1, 0);
 
1110
        wgets(w, d->name, 31, 32);
 
1111
        break;
 
1112
      case 'B':
 
1113
        wlocate(w, mbslen (number) + 1, 1);
 
1114
        wgets(w, d->number, 31, 32);
 
1115
        break;
 
1116
      case 'C':
 
1117
        d->dialtype = (d->dialtype + 1) % 3;
 
1118
        wlocate(w, mbslen (dial_string) + 1, 2);
 
1119
        wprintf(w, "%d", d->dialtype + 1);
 
1120
        wflush();
 
1121
        break;
 
1122
      case 'D':
 
1123
        d->flags ^= FL_ECHO;
 
1124
        wlocate(w, mbslen (local_echo) + 1, 3);
 
1125
        wprintf(w, "%s", _(yesno(d->flags & FL_ECHO)));
 
1126
        wflush();
 
1127
        break;
 
1128
      case 'E':
 
1129
        wlocate(w, mbslen (script) + 1, 4);
 
1130
        wgets(w, d->script, 31, 32);
 
1131
        break;
 
1132
      case 'F':
 
1133
        wlocate(w, mbslen (username) + 1, 5);
 
1134
        wgets(w, d->username, 31, 32);
 
1135
        break;
 
1136
      case 'G':
 
1137
        wlocate(w, mbslen (password) + 1, 6);
 
1138
        wgets(w, d->password, 31, 32);
 
1139
        break;
 
1140
      case 'H':
 
1141
        d->term = (d->term % 3) + 1;
 
1142
        /* MINIX == 2 is obsolete. */
 
1143
        if (d->term == 2)
 
1144
          d->term = 3;
 
1145
        wlocate(w, mbslen (terminal_emulation) + 1, 7);
 
1146
        wputs(w, te[d->term - 1]);
1078
1147
 
1079
 
                /* Also set backspace key. */
1080
 
                if (d->term == ANSI) {
1081
 
                        d->flags &= ~FL_DEL;
1082
 
                        d->flags |= FL_WRAP;
1083
 
                } else {
1084
 
                        d->flags &= ~FL_WRAP;
1085
 
                        d->flags |= FL_DEL;
1086
 
                }
1087
 
                wlocate(w, strlen (backspace_key_sends) + 1, 8);
1088
 
                wputs(w, d->flags & FL_DEL ? _("Delete   ") : _("Backspace"));
1089
 
                wlocate(w, strlen (linewrap) + 1, 9);
1090
 
                wputs(w, d->flags & FL_WRAP ? _("On ") : _("Off"));
1091
 
                break;
1092
 
        case 'I':
1093
 
                d->flags ^= FL_DEL;
1094
 
                wlocate(w, strlen (backspace_key_sends) + 1, 8);
1095
 
                wputs(w, d->flags & FL_DEL ? _("Delete   ") : _("Backspace"));
1096
 
                break;
1097
 
        case 'J':
1098
 
                d->flags ^= FL_WRAP;
1099
 
                wlocate(w, strlen (linewrap) + 1, 9);
1100
 
                wputs(w, d->flags & FL_WRAP ? _("On ") : _("Off"));
1101
 
                break;
1102
 
        case 'K':
1103
 
                get_bbp(d->baud, d->bits, d->parity, d->stopb, 1);
1104
 
                wlocate(w, strlen (line_settings) + 1, 10);
1105
 
                wprintf(w, "%s %s%s%s  ",
1106
 
                        d->baud, d->bits, d->parity, d->stopb);
1107
 
                break;
1108
 
        case 'L':       /* jl 21.09.97 */
1109
 
                wlocate(w, strlen (conversion_table) + 1, 11);
1110
 
                (void) wgets(w, d->convfile, 15, 16);
1111
 
                break;
1112
 
        default:
1113
 
                break;
1114
 
      }
 
1148
        /* Also set backspace key. */
 
1149
        if (d->term == ANSI) {
 
1150
          d->flags &= ~FL_DEL;
 
1151
          d->flags |= FL_WRAP;
 
1152
        } else {
 
1153
          d->flags |= FL_DEL;
 
1154
          d->flags &= ~FL_WRAP;
 
1155
        }
 
1156
        dedit_toggle_entry(w, mbslen(backspace_key_sends) + 1, 8,
 
1157
                           d->flags & FL_DEL, _("Delete"), _("Backspace"));
 
1158
        dedit_toggle_entry(w, mbslen(linewrap) + 1, 9,
 
1159
                           d->flags & FL_WRAP, _("On"), _("Off"));
 
1160
        break;
 
1161
      case 'I':
 
1162
        d->flags ^= FL_DEL;
 
1163
        dedit_toggle_entry(w, mbslen(backspace_key_sends) + 1, 8,
 
1164
                           d->flags & FL_DEL, _("Delete"), _("Backspace"));
 
1165
        break;
 
1166
      case 'J':
 
1167
        d->flags ^= FL_WRAP;
 
1168
        dedit_toggle_entry(w, mbslen(linewrap) + 1, 9,
 
1169
                           d->flags & FL_WRAP, _("On"), _("Off"));
 
1170
        break;
 
1171
      case 'K':
 
1172
        get_bbp(d->baud, d->bits, d->parity, d->stopb, 1);
 
1173
        wlocate(w, mbslen (line_settings) + 1, 10);
 
1174
        wprintf(w, "%s %s%s%s  ",
 
1175
                d->baud, d->bits, d->parity, d->stopb);
 
1176
        break;
 
1177
      case 'L': /* jl 21.09.97 */
 
1178
        wlocate(w, mbslen (conversion_table) + 1, 11);
 
1179
        wgets(w, d->convfile, 15, 16);
 
1180
        break;
 
1181
      default:
 
1182
        break;
 
1183
    }
1115
1184
  }
1116
1185
}
1117
1186
 
1118
1187
static WIN *dsub;
1119
 
static char *what =  
1120
 
        N_("  Dial    Find    Add     Edit   Remove   moVe   Manual ");
1121
 
/*          12345678901234567890123456789012345678901234567890123456
1122
 
                     1         2         3         4         5       */
 
1188
static const char *const what[] =
 
1189
  {
 
1190
    /* TRANSLATORS: Translation of each of these menu items should not be
 
1191
     * longer than 7 characters. The upper-case letter is a shortcut,
 
1192
     * so keep them unique and ASCII; 'h', 'j', 'k', 'l' are reserved */
 
1193
    N_("Dial"), N_("Find"), N_("Add"), N_("Edit"), N_("Remove"), N_("moVe"),
 
1194
    N_("Manual")
 
1195
  };
 
1196
/* Offsets of what[] entries from position_dialing_directory */
 
1197
#define DIALOPTS (sizeof(what) / sizeof(*what))
 
1198
#define DIAL_WIDTH 8 /* Width of one entry */
 
1199
static size_t what_lens[DIALOPTS]; /* Number of bytes for <= 7 characters */
 
1200
/* Number of ' ' padding entries at left and right, left is >= 1 */
 
1201
static int what_padding[DIALOPTS][2];
 
1202
 
1123
1203
static int dprev;
1124
 
#define DIALOPTS 7   /* Number of commands in vertical dial menu */
 
1204
 
 
1205
/* Draw an entry in the horizontal menu */
 
1206
static void horiz_draw(size_t k)
 
1207
{
 
1208
  static const char spaces[] = "        ";
 
1209
 
 
1210
  wprintf(dsub, "%.*s", what_padding[k][0], spaces);
 
1211
  wprintf(dsub, "%.*s", what_lens[k], _(what[k]));
 
1212
  wprintf(dsub, "%.*s", what_padding[k][1], spaces);
 
1213
}
1125
1214
 
1126
1215
/*
1127
1216
 * Highlight a choice in the horizontal menu.
1128
1217
 */
1129
 
static void dhili(position_dialing_directory, k)
1130
 
int position_dialing_directory, k;
 
1218
static void dhili(int position_dialing_directory, int k)
1131
1219
{
1132
 
  /* acme@conectiva.com.br 28/02/1998 
1133
 
     hack to make i18n strings work with _this_ hack ;> :
1134
 
     the i18n string must have a options with the same size (padded 
1135
 
     with spaces... I only hope the translations are smart enough to
1136
 
     figure this out... ;> */
1137
 
 
1138
 
  int option_size = strlen (_(what)) / DIALOPTS;
1139
 
 
1140
 
  if (k == dprev) return;
 
1220
  if (k == dprev)
 
1221
    return;
1141
1222
 
1142
1223
  if (dprev >= 0) {
1143
 
        wlocate(dsub, position_dialing_directory + option_size * dprev, 0);
1144
 
        if (!useattr) {
1145
 
                wputs(dsub, " ");
1146
 
        } else {
1147
 
 
1148
 
                wsetattr(dsub, XA_REVERSE | stdattr);
1149
 
                wprintf(dsub, "%*.*s", option_size, option_size, _(what) + option_size * dprev);
1150
 
        }
 
1224
    wlocate(dsub, position_dialing_directory + DIAL_WIDTH * dprev, 0);
 
1225
    if (!useattr) {
 
1226
      wputs(dsub, " ");
 
1227
    } else {
 
1228
      wsetattr(dsub, XA_REVERSE | stdattr);
 
1229
      horiz_draw(dprev);
 
1230
    }
1151
1231
  }
1152
1232
  dprev = k;
1153
 
  wlocate(dsub, position_dialing_directory + option_size * k, 0);
 
1233
  wlocate(dsub, position_dialing_directory + DIAL_WIDTH * k, 0);
1154
1234
  if (!useattr) {
1155
 
        wputs(dsub, ">");
 
1235
    wputs(dsub, ">");
1156
1236
  } else {
1157
 
        wsetattr(dsub, stdattr);
1158
 
        wprintf(dsub, "%*.*s", option_size, option_size, _(what) + option_size * k);
 
1237
    wsetattr(dsub, stdattr);
 
1238
    horiz_draw(k);
1159
1239
  }
1160
1240
}
1161
1241
 
1162
 
 
1163
 
static char *fmt = "\r %2d %c%-16.16s%-16.16s%8.8s %5.5s %4d %-15.15s\n";
 
1242
static const char *fmt = "\r %2d %c%-16.16s%-16.16s%8.8s %5.5s %4d %-15.15s\n";
1164
1243
 
1165
1244
/*
1166
1245
 * Print the dialing directory. Only draw from "cur" to bottom.
1167
1246
 */
1168
 
static void prdir(dialw, top, cur)
1169
 
WIN *dialw;
1170
 
int top, cur;
 
1247
static void prdir(WIN *dialw, int top, int cur)
1171
1248
{
1172
1249
  int f, start;
1173
1250
  struct dialent *d;
1175
1252
  start = cur - top;
1176
1253
  dirflush = 0;
1177
1254
  wlocate(dialw, 0, start + 1);
1178
 
  for(f = start; f < dialw->ys - 2; f++) {
1179
 
        d = getno(f + top);
1180
 
        if (d == (struct dialent *)0) break;
1181
 
        wprintf(dialw, fmt, f+1+top, (d->flags & FL_TAG) ? '>' : ' ',
1182
 
                d->name, d->number, d->lastdate, d->lasttime, 
1183
 
                d->count, d->script);
 
1255
  for (f = start; f < dialw->ys - 2; f++) {
 
1256
    d = getno(f + top);
 
1257
    if (d == (struct dialent *)0)
 
1258
      break;
 
1259
    wprintf(dialw, fmt, f+1+top, (d->flags & FL_TAG) ? '>' : ' ',
 
1260
            d->name, d->number, d->lastdate, d->lasttime, 
 
1261
            d->count, d->script);
1184
1262
  }
1185
1263
  dirflush = 1;
1186
1264
  wflush();
1197
1275
  struct dialent *dtmp;
1198
1276
 
1199
1277
  while (!quit) {
1200
 
 
1201
1278
    switch (c = wxgetch()) {
1202
 
        case K_DN:
1203
 
        case 'j':
1204
 
          if (!(d->next))
1205
 
            break;
1206
 
          if (cur == 0) {   /* special case: move d from start to 2nd */
1207
 
            dtmp = d->next;
1208
 
            d->next = dtmp->next;
1209
 
            dtmp->next = d;
1210
 
            dialents = dtmp;
1211
 
          } else {          /* swap d with the next one in the list */
1212
 
            dtmp = getno(cur - 1);
1213
 
            dtmp->next = d->next;
1214
 
            d->next = d->next->next;
1215
 
            dtmp->next->next = d;
1216
 
          }
1217
 
          cur++;
1218
 
          break;
1219
 
        case K_UP:
1220
 
        case 'k':
1221
 
          if (cur == 0)
1222
 
            break;
1223
 
          if (cur == 1) { /* special case: move d to start of list */
1224
 
            dtmp = dialents;
1225
 
            dtmp->next = d-> next;
1226
 
            d->next = dtmp;
1227
 
            dialents = d;
1228
 
          } else {        /* swap d with the previous one in the list */
1229
 
            dtmp = getno(cur - 2);
1230
 
            dtmp->next->next = d-> next;
1231
 
            d->next = dtmp->next;
1232
 
            dtmp->next = d;
1233
 
          }
1234
 
          cur--;
1235
 
          break;
1236
 
        case '\033':
1237
 
        case '\r':
1238
 
        case '\n':
1239
 
          quit = 1;
1240
 
          break;
1241
 
        default:
1242
 
          break;
 
1279
      case K_DN:
 
1280
      case 'j':
 
1281
        if (!(d->next))
 
1282
          break;
 
1283
        if (cur == 0) {   /* special case: move d from start to 2nd */
 
1284
          dtmp = d->next;
 
1285
          d->next = dtmp->next;
 
1286
          dtmp->next = d;
 
1287
          dialents = dtmp;
 
1288
        } else {            /* swap d with the next one in the list */
 
1289
          dtmp = getno(cur - 1);
 
1290
          dtmp->next = d->next;
 
1291
          d->next = d->next->next;
 
1292
          dtmp->next->next = d;
 
1293
        }
 
1294
        cur++;
 
1295
        break;
 
1296
      case K_UP:
 
1297
      case 'k':
 
1298
        if (cur == 0)
 
1299
          break;
 
1300
        if (cur == 1) { /* special case: move d to start of list */
 
1301
          dtmp = dialents;
 
1302
          dtmp->next = d-> next;
 
1303
          d->next = dtmp;
 
1304
          dialents = d;
 
1305
        } else {          /* swap d with the previous one in the list */
 
1306
          dtmp = getno(cur - 2);
 
1307
          dtmp->next->next = d-> next;
 
1308
          d->next = dtmp->next;
 
1309
          dtmp->next = d;
 
1310
        }
 
1311
        cur--;
 
1312
        break;
 
1313
      case '\033':
 
1314
      case '\r':
 
1315
      case '\n':
 
1316
        quit = 1;
 
1317
        break;
 
1318
      default:
 
1319
        break;
1243
1320
    } /* end switch */
1244
1321
 
1245
1322
    /* If the list order changed, redraw the directory window */
1247
1324
      /* First remove cursor bar from the old position */
1248
1325
      wcurbar(dialw, ocur + 1 - *top, XA_NORMAL | stdattr);
1249
1326
      if (cur < *top)
1250
 
        (*top)--;
 
1327
        (*top)--;
1251
1328
      else if (cur - *top > dialw->ys - 3)
1252
 
        (*top)++;
 
1329
        (*top)++;
1253
1330
      prdir(dialw, *top, *top);
1254
1331
      wcurbar(dialw, cur + 1 - *top, XA_REVERSE | stdattr);
1255
1332
      ocur = cur;
1256
1333
    } /* end redraw condition */
1257
 
 
1258
1334
  }   /* end loop   */
1259
1335
 
1260
1336
  return cur;
1261
1337
}
1262
1338
 
1263
1339
/* Little menu. */
1264
 
static char *d_yesno[] = { N_("   Yes  "), N_("   No   "), CNULL };
 
1340
static const char *d_yesno[] = { N_("   Yes  "), N_("   No   "), NULL };
1265
1341
 
1266
1342
/* Try to dial an entry. */
1267
 
static void dial_entry(d)
1268
 
struct dialent *d;
 
1343
static void dial_entry(struct dialent *d)
1269
1344
{
1270
1345
  long nb;
1271
1346
  struct dialent *d2;
1272
1347
 
1273
1348
  /* Change settings for this entry. */
1274
1349
  if (atoi(d->baud) != 0) {
1275
 
        strcpy(P_BAUDRATE, d->baud);
1276
 
        strcpy(P_PARITY, d->parity);
1277
 
        strcpy(P_BITS, d->bits);
1278
 
        strcpy(P_STOPB, d->stopb);
1279
 
        port_init();
1280
 
        mode_status();
 
1350
    strcpy(P_BAUDRATE, d->baud);
 
1351
    strcpy(P_PARITY, d->parity);
 
1352
    strcpy(P_BITS, d->bits);
 
1353
    strcpy(P_STOPB, d->stopb);
 
1354
    port_init();
 
1355
    mode_status();
1281
1356
  }
1282
1357
  newtype = d->term;
1283
1358
  vt_set(-1, d->flags & FL_WRAP, NULL, -1, -1, d->flags & FL_ECHO, -1, -1);
1284
 
#ifdef HAVE_SELECT
1285
1359
  local_echo = d->flags & FL_ECHO;
1286
 
#endif
1287
1360
  if (newtype != terminal)
1288
 
        init_emul(newtype, 1);
 
1361
    init_emul(newtype, 1);
1289
1362
 
1290
1363
  /* Set backspace key. */
1291
1364
  keyboard(KSETBS, d->flags & FL_DEL ? 127 : 8);
1292
1365
  strcpy(P_BACKSPACE, d->flags & FL_DEL ? "DEL" : "BS");
1293
1366
 
1294
1367
  /* Now that everything has been set, dial. */
1295
 
  if ((nb = dial(d, &d2)) < 0) return;
 
1368
  if ((nb = dial(d, &d2)) < 0)
 
1369
    return;
1296
1370
  
1297
1371
  if (d2 != (struct dialent *)NULL)
1298
1372
    d = d2;     /* jl 22.09.97 */
1299
1373
 
1300
1374
  /* Did we detect a baudrate , and can we set it? */
1301
1375
  if (P_MAUTOBAUD[0] == 'Y' && nb) {
1302
 
        sprintf(P_BAUDRATE, "%ld", nb);
1303
 
        port_init();
1304
 
        mode_status();
1305
 
  }
1306
 
  else if (P_SHOWSPD[0] == 'l')
 
1376
    sprintf(P_BAUDRATE, "%ld", nb);
 
1377
    port_init();
 
1378
    mode_status();
 
1379
  } else if (P_SHOWSPD[0] == 'l')
1307
1380
    mode_status();
1308
1381
 
1309
1382
  /* Make sure the last date is updated   / jl 22.06.97 */
1310
1383
  writedialdir();
1311
1384
 
1312
1385
  /* Run script if needed. */
1313
 
  if (d->script[0]) runscript(0, d->script, d->username, d->password);
 
1386
  if (d->script[0])
 
1387
    runscript(0, d->script, d->username, d->password);
1314
1388
 
1315
1389
  /* Remember _what_ we dialed.. */
1316
1390
  dial_name = d->name;
1317
1391
  dial_number = d->number;
1318
1392
  dial_user = d->username;
1319
1393
  dial_pass = d->password;
 
1394
 
1320
1395
  return;
1321
1396
}
1322
1397
 
1325
1400
 * is used for the "-d" command line flag.
1326
1401
 * Now you can tag multiple entries with the -d option / jl 3.5.1999
1327
1402
 */
1328
 
void dialone(entry)
1329
 
char *entry;
 
1403
void dialone(char *entry)
1330
1404
{
1331
1405
  int num;
1332
1406
  struct dialent *d;
1339
1413
    /* Find entry. */
1340
1414
    if ((num = atoi(s)) != 0) {
1341
1415
      if ((d = getno(num - 1))) {
1342
 
        d->flags |= FL_TAG;
1343
 
        if (d1 == (struct dialent *)NULL)
1344
 
          d1 = d;
 
1416
        d->flags |= FL_TAG;
 
1417
        if (d1 == (struct dialent *)NULL)
 
1418
          d1 = d;
1345
1419
      }
1346
1420
    } else {
1347
 
      for(d = dialents; d; d = d->next)
1348
 
        if (strstr(d->name, s)) {
1349
 
          d->flags |= FL_TAG;
1350
 
          if (d1 == (struct dialent *)NULL)
1351
 
            d1 = d;
1352
 
        }
 
1421
      for (d = dialents; d; d = d->next)
 
1422
        if (strstr(d->name, s)) {
 
1423
          d->flags |= FL_TAG;
 
1424
          if (d1 == (struct dialent *)NULL)
 
1425
            d1 = d;
 
1426
        }
1353
1427
    }
1354
1428
    s = strtok(NULL,",;");
1355
1429
  }
1356
1430
 
1357
1431
  /* Not found. */
1358
1432
  if (d1 == NULL) {
1359
 
        snprintf(buf, sizeof(buf), _("Entry \"%s\" not found. Enter dialdir?"), entry);
1360
 
        if (ask(buf, d_yesno) != 0) return;
1361
 
        dialdir();
1362
 
        return;
 
1433
    snprintf(buf, sizeof(buf), _("Entry \"%s\" not found. Enter dialdir?"), entry);
 
1434
    if (ask(buf, d_yesno) != 0)
 
1435
      return;
 
1436
    dialdir();
 
1437
    return;
1363
1438
  }
1364
1439
  /* Dial the number! */
1365
1440
  sleep(1);
1369
1444
/*
1370
1445
 * Draw the dialing directory.
1371
1446
 */
1372
 
void dialdir()
 
1447
void dialdir(void)
1373
1448
{
1374
1449
  WIN *w;
1375
1450
  struct dialent *d = NULL, *d1, *d2;
1385
1460
  char *s, dname[128];
1386
1461
  static char manual[128];
1387
1462
  int changed = 0;
1388
 
  static char *tag_exit  = N_("( Escape to exit, Space to tag )"),
1389
 
              *move_exit = N_(" Move entry up/down, Escape to exit");
 
1463
  static const char *tag_exit  = N_("( Escape to exit, Space to tag )"),
 
1464
                    *move_exit = N_(" Move entry up/down, Escape to exit");
1390
1465
  unsigned int tagmvlen = 0;
1391
 
  int position_dialing_directory = ((COLS / 2) + 32 - strlen (_(what))) / 2;
 
1466
  size_t i;
 
1467
  int position_dialing_directory = ((COLS / 2) + 32 - DIALOPTS * DIAL_WIDTH) / 2;
1392
1468
 
1393
1469
  dprev = -1;
1394
1470
  dname[0] = 0;
1395
1471
  tagmvlen = strlen(_(move_exit));
1396
1472
  if (strlen(_(tag_exit)) > tagmvlen)
1397
 
        tagmvlen = strlen(_(tag_exit));
 
1473
    tagmvlen = strlen(_(tag_exit));
1398
1474
 
1399
1475
  /* Allright, draw the dialing directory! */
1400
 
  
 
1476
 
1401
1477
  dirflush = 0;
1402
1478
  x1 = (COLS / 2) - 37;
1403
1479
  x2 = (COLS / 2) + 37;
1404
 
  dsub = wopen(x1 - 1, LINES - 3, x2 + 1, LINES - 3, BNONE, 
1405
 
                XA_REVERSE | stdattr, mfcolor, mbcolor, 0, 0, 1);
 
1480
  dsub = wopen(x1 - 1, LINES - 3, x2 + 1, LINES - 3, BNONE,
 
1481
               XA_REVERSE | stdattr, mfcolor, mbcolor, 0, 0, 1);
1406
1482
  w = wopen(x1, 2, x2, LINES - 6, BSINGLE, stdattr, mfcolor, mbcolor, 0, 0, 1);
1407
1483
  wcursor(w, CNONE);
1408
1484
  wtitle(w, TMID, _("Dialing Directory"));
1409
1485
  wputs(w,
1410
 
      _("     Name            Number            Last on      Times Script\n"));
 
1486
        _("     Name            Number            Last on      Times Script\n"));
 
1487
  for (i = 0; i < DIALOPTS; i++) {
 
1488
    const char *str, *c;
 
1489
    size_t j;
 
1490
 
 
1491
    str = _(what[i]);
 
1492
    c = str;
 
1493
    for (j = 0; j < DIAL_WIDTH - 1 && *c != 0; j++) {
 
1494
      wchar_t wc;
 
1495
      c += one_mbtowc(&wc, c, MB_LEN_MAX);
 
1496
    }
 
1497
    what_lens[i] = c - str;
 
1498
    j = DIAL_WIDTH - j; /* Characters left for padding */
 
1499
    what_padding[i][1] = j / 2; /* Rounding down */
 
1500
    what_padding[i][0] = j - what_padding[i][1]; /* >= 1 */
 
1501
  }
1411
1502
  wlocate(dsub, position_dialing_directory, 0);
1412
 
  wputs(dsub, _(what));
 
1503
  for (i = 0; i < DIALOPTS; i++)
 
1504
    horiz_draw(i);
1413
1505
 
1414
1506
  wsetregion(w, 1, w->ys - 1);
1415
1507
  w->doscroll = 0;
1416
1508
 
1417
 
  prdir(w, top, top);  
 
1509
  prdir(w, top, top);
1418
1510
  wlocate(w, position_dialing_directory, w->ys - 1);
1419
1511
  wprintf(w, "%*.*s", tagmvlen,tagmvlen, tag_exit);
1420
1512
  dhili(position_dialing_directory, subm);
1421
1513
  dirflush = 1;
1422
1514
  wredraw(dsub, 1);
1423
1515
 
1424
 
again:  
 
1516
again:
1425
1517
  wcurbar(w, cur + 1 - top, XA_REVERSE | stdattr);
1426
1518
  if (first) {
1427
 
        wredraw(w, 1);
1428
 
        first = 0;
 
1519
    wredraw(w, 1);
 
1520
    first = 0;
1429
1521
  }
1430
1522
  while(!quit) {
1431
 
        d = getno(cur);
1432
 
        switch(c = wxgetch()) {
1433
 
                case K_UP:
1434
 
                case 'k':
1435
 
                        cur -= (cur > 0);
1436
 
                        break;
1437
 
                case K_DN:
1438
 
                case 'j':
1439
 
                        cur += (cur < nrents - 1);
1440
 
                        break;
1441
 
                case K_LT:
1442
 
                case 'h':
1443
 
                        subm--;
1444
 
                        if (subm < 0) subm = DIALOPTS - 1;
1445
 
                        break;
1446
 
                case K_RT:
1447
 
                case 'l':
1448
 
                        subm = (subm + 1) % DIALOPTS;
1449
 
                        break;
1450
 
                case K_PGUP:
1451
 
                case '\002': /* Control-B */
1452
 
                        pgud = 1;
1453
 
                        quit = 1;
1454
 
                        break;  
1455
 
                case K_PGDN:
1456
 
                case '\006': /* Control-F */
1457
 
                        pgud = 2;
1458
 
                        quit = 1;
1459
 
                        break;  
1460
 
                case 'd':    /* Dial. */
1461
 
                        subm = 0;
1462
 
                        quit = 1;
1463
 
                        break;
1464
 
                case 'f':    /* Find. */
1465
 
                        subm = 1;
1466
 
                        quit = 1;
1467
 
                        break;
1468
 
                case 'a':    /* Add. */
1469
 
                        subm = 2;
1470
 
                        quit = 1;
1471
 
                        break;
1472
 
                case 'e':    /* Edit. */
1473
 
                        subm = 3;
1474
 
                        quit = 1;
1475
 
                        break;
1476
 
                case 'r':    /* Remove. */
1477
 
                        subm = 4;
1478
 
                        quit = 1;
1479
 
                        break;
1480
 
                case 'v':    /* moVe entry */
1481
 
                        subm = 5;
1482
 
                        quit = 2;
1483
 
                        break;
1484
 
                case 'm':    /* Manual. */
1485
 
                        subm = 6;
1486
 
                        quit = 1;
1487
 
                        break;
1488
 
                case ' ':    /* Tag. */
1489
 
                        wlocate(w, 4, cur + 1 - top);
1490
 
                        d->flags ^= FL_TAG;
1491
 
                        wsetattr(w, XA_REVERSE | stdattr);
1492
 
                        wprintf(w, "%c", d->flags & FL_TAG ? '>' : ' ');
1493
 
                        wsetattr(w, XA_NORMAL | stdattr);
1494
 
                        cur += (cur < nrents - 1);
1495
 
                        break;
1496
 
                case '\033':
1497
 
                case '\r':
1498
 
                case '\n':
1499
 
                        quit = (subm==5 ? 2 : 1);
1500
 
                        break;
1501
 
                default:
1502
 
                        break;
1503
 
        }
1504
 
        /* Decide if we have to delete the cursor bar */
1505
 
        if (cur != ocur || quit == 1)
1506
 
                wcurbar(w, ocur + 1 - top, XA_NORMAL | stdattr);
1507
 
                
1508
 
        if (cur < top) {
1509
 
                top--;
1510
 
                prdir(w, top, top);     
1511
 
        }
1512
 
        if (cur - top > w->ys - 3) {
1513
 
                top++;
1514
 
                prdir(w, top, top);
1515
 
        }
1516
 
        if (cur != ocur) wcurbar(w, cur + 1 - top, XA_REVERSE | stdattr);
1517
 
        ocur = cur;
1518
 
        dhili(position_dialing_directory, subm);
 
1523
    d = getno(cur);
 
1524
    switch (c = wxgetch()) {
 
1525
      case K_UP:
 
1526
      case 'k':
 
1527
        cur -= (cur > 0);
 
1528
        break;
 
1529
      case K_DN:
 
1530
      case 'j':
 
1531
        cur += (cur < nrents - 1);
 
1532
        break;
 
1533
      case K_LT:
 
1534
      case 'h':
 
1535
        subm--;
 
1536
        if (subm < 0)
 
1537
          subm = DIALOPTS - 1;
 
1538
        break;
 
1539
      case K_RT:
 
1540
      case 'l':
 
1541
        subm = (subm + 1) % DIALOPTS;
 
1542
        break;
 
1543
      case K_PGUP:
 
1544
      case '\002': /* Control-B */
 
1545
        pgud = 1;
 
1546
        quit = 1;
 
1547
        break;
 
1548
      case K_PGDN:
 
1549
      case '\006': /* Control-F */
 
1550
        pgud = 2;
 
1551
        quit = 1;
 
1552
        break;
 
1553
      case ' ':    /* Tag. */
 
1554
        wlocate(w, 4, cur + 1 - top);
 
1555
        d->flags ^= FL_TAG;
 
1556
        wsetattr(w, XA_REVERSE | stdattr);
 
1557
        wprintf(w, "%c", d->flags & FL_TAG ? '>' : ' ');
 
1558
        wsetattr(w, XA_NORMAL | stdattr);
 
1559
        cur += (cur < nrents - 1);
 
1560
        break;
 
1561
      case '\033':
 
1562
      case '\r':
 
1563
      case '\n':
 
1564
      selected:
 
1565
        quit = (subm == 5 ? 2 : 1);
 
1566
        break;
 
1567
      default:
 
1568
        for (i = 0; i < DIALOPTS; i++) {
 
1569
          if (strchr(_(what[i]), toupper(c)) != NULL) {
 
1570
            subm = i;
 
1571
            goto selected;
 
1572
          }
 
1573
        }
 
1574
        break;
 
1575
    }
 
1576
    /* Decide if we have to delete the cursor bar */
 
1577
    if (cur != ocur || quit == 1)
 
1578
      wcurbar(w, ocur + 1 - top, XA_NORMAL | stdattr);
 
1579
 
 
1580
    if (cur < top) {
 
1581
      top--;
 
1582
      prdir(w, top, top);
 
1583
    }
 
1584
    if (cur - top > w->ys - 3) {
 
1585
      top++;
 
1586
      prdir(w, top, top);
 
1587
    }
 
1588
    if (cur != ocur)
 
1589
      wcurbar(w, cur + 1 - top, XA_REVERSE | stdattr);
 
1590
    ocur = cur;
 
1591
    dhili(position_dialing_directory, subm);
1519
1592
  }
1520
1593
  quit = 0;
1521
1594
  /* ESC means quit */
1522
1595
  if (c == '\033') {
1523
 
        if (changed) writedialdir();
1524
 
        wclose(w, 1);
1525
 
        wclose(dsub, 1);
1526
 
        return;
 
1596
    if (changed)
 
1597
      writedialdir();
 
1598
    wclose(w, 1);
 
1599
    wclose(dsub, 1);
 
1600
    return;
1527
1601
  }
1528
1602
  /* Page up or down ? */
1529
1603
  if (pgud == 1) { /* Page up */
1530
 
        ocur = top;
1531
 
        top -= w->ys - 2;
1532
 
        if (top < 0) top = 0;
1533
 
        cur = top;
1534
 
        pgud = 0;
1535
 
        if (ocur != top) prdir(w, top, cur);
1536
 
        ocur = cur;
1537
 
        goto again;
 
1604
    ocur = top;
 
1605
    top -= w->ys - 2;
 
1606
    if (top < 0)
 
1607
      top = 0;
 
1608
    cur = top;
 
1609
    pgud = 0;
 
1610
    if (ocur != top)
 
1611
      prdir(w, top, cur);
 
1612
    ocur = cur;
 
1613
    goto again;
1538
1614
  }
1539
1615
  if (pgud == 2) { /* Page down */
1540
 
        ocur = top;
1541
 
        if (top < nrents - w->ys + 2) {
1542
 
                top += w->ys - 2;
1543
 
                if (top > nrents - w->ys + 2) {
1544
 
                        top = nrents - w->ys + 2;
1545
 
                }
1546
 
                cur = top;
1547
 
        } else
1548
 
                cur = nrents - 1;
1549
 
        pgud = 0;
1550
 
        if (ocur != top) prdir(w, top, cur);
1551
 
        ocur = cur;
1552
 
        goto again;
 
1616
    ocur = top;
 
1617
    if (top < nrents - w->ys + 2) {
 
1618
      top += w->ys - 2;
 
1619
      if (top > nrents - w->ys + 2)
 
1620
        top = nrents - w->ys + 2;
 
1621
      cur = top;
 
1622
    } else
 
1623
      cur = nrents - 1;
 
1624
    pgud = 0;
 
1625
    if (ocur != top)
 
1626
      prdir(w, top, cur);
 
1627
    ocur = cur;
 
1628
    goto again;
1553
1629
  }
1554
 
  
 
1630
 
1555
1631
  /* Dial an entry */
1556
1632
  if (subm == 0) {
1557
 
        wclose(w, 1);
1558
 
        wclose(dsub, 1);
1559
 
        if (changed) writedialdir();
 
1633
    wclose(w, 1);
 
1634
    wclose(dsub, 1);
 
1635
    if (changed)
 
1636
      writedialdir();
1560
1637
 
1561
 
        /* See if any entries were tagged. */
1562
 
        if (!(d->flags & FL_TAG)) {
1563
 
          /* First check the entries from the highlighted one to end.. */
1564
 
          for (d1 = d; d1; d1 = d1->next)
1565
 
            if (d1->flags & FL_TAG) {
1566
 
              d = d1;
1567
 
              break;
1568
 
            }
1569
 
          /* ..and if none of them was tagged, check from the begining. */
1570
 
          if (!d1)
1571
 
            for(d1 = dialents; d1 && d1!=d; d1 = d1->next)
1572
 
              if (d1->flags & FL_TAG) {
1573
 
                d = d1;
1574
 
                break;
1575
 
              }
1576
 
          /* If no tags were found, we'll dial the highlighted one */
1577
 
        }
1578
 
        dial_entry(d);
1579
 
        return;
 
1638
    /* See if any entries were tagged. */
 
1639
    if (!(d->flags & FL_TAG)) {
 
1640
      /* First check the entries from the highlighted one to end.. */
 
1641
      for (d1 = d; d1; d1 = d1->next)
 
1642
        if (d1->flags & FL_TAG) {
 
1643
          d = d1;
 
1644
          break;
 
1645
        }
 
1646
      /* ..and if none of them was tagged, check from the begining. */
 
1647
      if (!d1)
 
1648
        for (d1 = dialents; d1 && d1!=d; d1 = d1->next)
 
1649
          if (d1->flags & FL_TAG) {
 
1650
            d = d1;
 
1651
            break;
 
1652
          }
 
1653
      /* If no tags were found, we'll dial the highlighted one */
 
1654
    }
 
1655
    dial_entry(d);
 
1656
    return;
1580
1657
  }
1581
1658
  /* Find an entry */
1582
1659
  if (subm == 1) {
1583
 
        s = input(_("Find an entry"), dname);
1584
 
        if (s == NULL || s[0] == 0) goto again;
1585
 
        x1 = 0;
1586
 
        for(d = dialents; d; d = d->next, x1++)
1587
 
                if (strstr(d->name, s)) break;
1588
 
        if (d == NULL) {
1589
 
                wbell();
1590
 
                goto again;
1591
 
        }
1592
 
        /* Set current to found entry. */
1593
 
        ocur = top;
1594
 
        cur = x1;
1595
 
        /* Find out if it fits on screen. */
1596
 
        if (cur < top || cur >= top + w->ys - 2) {
1597
 
                /* No, try to put it in the middle. */
1598
 
                top = cur - (w->ys / 2) + 1;
1599
 
                if (top < 0) top = 0;
1600
 
                if (top > nrents - w->ys + 2) {
1601
 
                        top = nrents - w->ys + 2;
1602
 
                }
1603
 
        }
1604
 
        if (ocur != top) prdir(w, top, top);
1605
 
        ocur = cur;
 
1660
    s = input(_("Find an entry"), dname);
 
1661
    if (s == NULL || s[0] == 0)
 
1662
      goto again;
 
1663
    x1 = 0;
 
1664
    for (d = dialents; d; d = d->next, x1++)
 
1665
      if (strstr(d->name, s))
 
1666
        break;
 
1667
    if (d == NULL) {
 
1668
      wbell();
 
1669
      goto again;
 
1670
    }
 
1671
    /* Set current to found entry. */
 
1672
    ocur = top;
 
1673
    cur = x1;
 
1674
    /* Find out if it fits on screen. */
 
1675
    if (cur < top || cur >= top + w->ys - 2) {
 
1676
      /* No, try to put it in the middle. */
 
1677
      top = cur - (w->ys / 2) + 1;
 
1678
      if (top < 0)
 
1679
        top = 0;
 
1680
      if (top > nrents - w->ys + 2)
 
1681
        top = nrents - w->ys + 2;
 
1682
    }
 
1683
    if (ocur != top)
 
1684
      prdir(w, top, top);
 
1685
    ocur = cur;
1606
1686
  }
1607
1687
 
1608
1688
  /* Add / insert an entry */
1609
1689
  if (subm == 2) {
1610
 
        d1 = mkstdent();
1611
 
        if (d1 == (struct dialent *)0) {
1612
 
                wbell();
1613
 
                goto again;
1614
 
        }
1615
 
        changed++;
1616
 
        cur++;
1617
 
        ocur = cur;
1618
 
        d2 = d->next;
1619
 
        d->next = d1;
1620
 
        d1->next = d2;
1621
 
        
1622
 
        nrents++;
1623
 
        if (cur - top > w->ys - 3) {
1624
 
                top++;
1625
 
                prdir(w, top, top);
1626
 
        } else {
1627
 
                prdir(w, top, cur);
1628
 
        }
 
1690
    d1 = mkstdent();
 
1691
    if (d1 == (struct dialent *)0) {
 
1692
      wbell();
 
1693
      goto again;
 
1694
    }
 
1695
    changed++;
 
1696
    cur++;
 
1697
    ocur = cur;
 
1698
    d2 = d->next;
 
1699
    d->next = d1;
 
1700
    d1->next = d2;
 
1701
 
 
1702
    nrents++;
 
1703
    if (cur - top > w->ys - 3) {
 
1704
      top++;
 
1705
      prdir(w, top, top);
 
1706
    } else {
 
1707
      prdir(w, top, cur);
 
1708
    }
1629
1709
  }
1630
1710
 
1631
1711
  /* Edit an entry */
1632
1712
  if (subm == 3) {
1633
 
        dedit(d);
1634
 
        changed++;
1635
 
        wlocate(w, 0, cur + 1 - top);
1636
 
        wprintf(w, fmt, cur+1, (d->flags & FL_TAG) ? 16 : ' ', d->name,
1637
 
        d->number, d->lastdate, d->lasttime, d->count, d->script);
 
1713
    dedit(d);
 
1714
    changed++;
 
1715
    wlocate(w, 0, cur + 1 - top);
 
1716
    wprintf(w, fmt, cur+1, (d->flags & FL_TAG) ? 16 : ' ', d->name,
 
1717
            d->number, d->lastdate, d->lasttime, d->count, d->script);
1638
1718
  }
1639
 
  
 
1719
 
1640
1720
  /* Delete an entry from the list */
1641
1721
  if (subm == 4 && ask(_("Remove entry?"), d_yesno) == 0) {
1642
 
        changed++;
1643
 
        if (nrents == 1) {
1644
 
                free((char *)d);
1645
 
                d = dialents = mkstdent();
1646
 
                prdir(w, top, top);
1647
 
                goto again;
1648
 
        }
1649
 
        if (cur == 0)
1650
 
                dialents = d->next;
1651
 
        else
1652
 
                getno(cur - 1)->next = d->next;
1653
 
        free((char *)d);
1654
 
        nrents--;
1655
 
        if (cur - top == 0 && top == nrents) {
1656
 
                top--;
1657
 
                cur--;
1658
 
                prdir(w, top, top);
1659
 
        } else {
1660
 
                if (cur == nrents) cur--;
1661
 
                prdir(w, top, cur);
1662
 
        }
1663
 
        if (nrents - top <= w->ys - 3) {
1664
 
                wlocate(w, 0, nrents - top + 1);
1665
 
                wclreol(w);
1666
 
        }
1667
 
        ocur = cur;
 
1722
    changed++;
 
1723
    if (nrents == 1) {
 
1724
      free((char *)d);
 
1725
      d = dialents = mkstdent();
 
1726
      prdir(w, top, top);
 
1727
      goto again;
 
1728
    }
 
1729
    if (cur == 0)
 
1730
      dialents = d->next;
 
1731
    else
 
1732
      getno(cur - 1)->next = d->next;
 
1733
    free((char *)d);
 
1734
    nrents--;
 
1735
    if (cur - top == 0 && top == nrents) {
 
1736
      top--;
 
1737
      cur--;
 
1738
      prdir(w, top, top);
 
1739
    } else {
 
1740
      if (cur == nrents)
 
1741
        cur--;
 
1742
      prdir(w, top, cur);
 
1743
    }
 
1744
    if (nrents - top <= w->ys - 3) {
 
1745
      wlocate(w, 0, nrents - top + 1);
 
1746
      wclreol(w);
 
1747
    }
 
1748
    ocur = cur;
1668
1749
  }
1669
1750
 
1670
1751
  /* Move the entry up/down in directory. */
1671
1752
  if (subm == 5) {
1672
 
        wlocate(w, position_dialing_directory, w->ys - 1);
1673
 
        wprintf(w, "%*.*s", tagmvlen,tagmvlen, move_exit);
1674
 
        cur = move_entry (w, d, cur, &top);
1675
 
        if (cur != ocur)
1676
 
          changed++;
1677
 
        ocur = cur;
1678
 
        wlocate(w, position_dialing_directory, w->ys - 1);
1679
 
        wprintf(w, "%*.*s", tagmvlen,tagmvlen, tag_exit);
 
1753
    wlocate(w, position_dialing_directory, w->ys - 1);
 
1754
    wprintf(w, "%*.*s", tagmvlen,tagmvlen, move_exit);
 
1755
    cur = move_entry (w, d, cur, &top);
 
1756
    if (cur != ocur)
 
1757
      changed++;
 
1758
    ocur = cur;
 
1759
    wlocate(w, position_dialing_directory, w->ys - 1);
 
1760
    wprintf(w, "%*.*s", tagmvlen,tagmvlen, tag_exit);
1680
1761
  }
1681
1762
 
1682
1763
  /* Dial a number manually. */
1683
1764
  if (subm == 6) {
1684
 
        s = input(_("Enter number"), manual);
1685
 
        if (s && *s) {
1686
 
                if (changed) writedialdir();
1687
 
                wclose(w, 1);
1688
 
                wclose(dsub, 1);
1689
 
                
1690
 
                strncpy(d_man->number, manual, sizeof(d_man->number));
1691
 
                (void) dial(d_man, (struct dialent**)NULL);
1692
 
                if (P_SHOWSPD[0] == 'l')
1693
 
                  mode_status();
1694
 
                return;
1695
 
        }
 
1765
    s = input(_("Enter number"), manual);
 
1766
    if (s && *s) {
 
1767
      if (changed)
 
1768
        writedialdir();
 
1769
      wclose(w, 1);
 
1770
      wclose(dsub, 1);
 
1771
 
 
1772
      strncpy(d_man->number, manual, sizeof(d_man->number));
 
1773
      dial(d_man, (struct dialent**)NULL);
 
1774
      if (P_SHOWSPD[0] == 'l')
 
1775
        mode_status();
 
1776
      return;
 
1777
    }
1696
1778
  }
1697
1779
  goto again;
1698
1780
}