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 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
|
/*
* This file is part of the Seyon, Copyright (c) 1992-1993 by Muhammad M.
* Saggaf. All rights reserved.
*
* See the file COPYING (1-COPYING) or the manual page seyon(1) for a full
* statement of rights and permissions for this program.
*/
#include <math.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xaw/Toggle.h>
#include <X11/Xaw/Dialog.h>
#include "seyon.h"
#include "SeDecl.h"
#if HAVE_TERMIOS
#include <termios.h>
#endif
extern int param_pipe[2];
int DetNewlineTrMode(),
ToggleNewlineMode(),
SetIStrip(),
ToggleDelMode(),
ToggleMetaKeyTr(),
ToggleXOffMode(),
ToggleRtsctsMode(),
ToggleZmodemAutoDownload(),
ToggleIdleGuard(),
MenuSetGetBaud(),
MenuSetGetCSize(),
MenuSetGetParity(),
MenuSetGetStopBits(),
MenuSetGetParamSCut(),
MenuSetGetNewlineTrMode();
void UpdateToggleSettings(),
UpdateStates(),
SetGetRadioVal(),
SetDoGetRadioVal(),
SetGetValue(),
SetDoGetValue();
int SetBaud(),
SetPort();
int newlineTrMode;
struct _setToggle {
Widget widget;
char *name;
int state;
int (*call_back)();
};
struct _setRadio {
String name;
String button[10];
int activeIndex;
int (*call_back)();
};
struct _setValue {
char *name;
char value[SM_BUF];
int(*call_back)();
};
static struct _setToggle set_toggle[] =
{
{NULL, "stripHighBit", 0, SetIStrip},
{NULL, "del", 0, ToggleDelMode},
{NULL, "meta_tr", 0, ToggleMetaKeyTr},
{NULL, "xoff", 0, ToggleXOffMode},
{NULL, "rtscts", 0, ToggleRtsctsMode},
{NULL, "autozm", 0, ToggleZmodemAutoDownload},
{NULL, "idle", 0, ToggleIdleGuard},
{NULL, NULL, 0, NULL}
};
static struct _setRadio setRadio[] =
{
{"baud", {"300", "1200", "2400", "4800", "9600", "19200", "38400",
#if USE_NONSTD_BAUD
"57600", "115200",
#else
#ifdef B57600
"57600",
#endif
#ifdef B115200
"115200",
#endif
#endif
NULL}, 1, MenuSetGetBaud},
{"bits", {"5", "6", "7", "8", NULL}, 1, MenuSetGetCSize},
{"parity", {"none", "odd", "even", NULL}, 1, MenuSetGetParity},
{"stopBits", {"1", "2", NULL}, 1, MenuSetGetStopBits},
{"cut", {"8n1", "7e1", "other", NULL}, 1, MenuSetGetParamSCut},
{"nl_tr", {"nl", "cr", "cr_lf", NULL}, 1, MenuSetGetNewlineTrMode},
{NULL, {NULL}, 0, NULL}
};
static struct _setValue set_value[] =
{
{"port", "", SetPort},
{NULL, "", NULL}
};
struct _setRadio *curRadObjPtr;
struct _setValue *curValObjPtr;
void
TopSet(w)
Widget w;
{
Widget popup,
mBox,
uBox,
lBox;
struct _setToggle *tptr;
struct _setRadio *rPtr;
struct _setValue *vptr;
ErrorIfBusy()
tptr = set_toggle;
tptr->state = qres.stripHighBit; tptr++;
tptr->state = qres.backspaceTranslation; tptr++;
tptr->state = qres.metaKeyTranslation; tptr++;
tptr->state = qres.xonxoffFlowControl; tptr++;
tptr->state = qres.rtsctsFlowControl; tptr++;
tptr->state = qres.autoZmodem; tptr++;
tptr->state = qres.idleGuard; tptr++;
popup = SeAddPopup("set", w);
mBox = AddPaned("mBox", popup);
uBox = AddBox("uBox", mBox);
lBox = AddBox("lBox", mBox);
for (tptr = set_toggle; tptr->name != NULL; tptr++) {
tptr->widget = SeAddToggleWCD(tptr->name, uBox, UpdateToggleSettings,
(XtPointer)(tptr->call_back));
SeSetUnsetToggle(tptr->widget, tptr->state);
}
for (rPtr = setRadio; rPtr->name != NULL; rPtr++)
SeAddButtonWCD(rPtr->name, uBox, SetGetRadioVal, (XtPointer) rPtr);
for (vptr = set_value; vptr->name != NULL; vptr++)
SeAddButtonWCD(vptr->name, uBox, SetGetValue, (XtPointer) vptr);
SeAddButtonWCD("dismiss", lBox, DestroyShellCallBack, (XtPointer) mBox);
XtPopup(popup, XtGrabExclusive);
}
void
SetGetRadioVal(widget, client_data)
Widget widget;
XtPointer client_data;
{
struct _setRadio *rPtr = (struct _setRadio*)client_data;
rPtr->activeIndex = (*rPtr->call_back)(-1);
SePopupRadio(rPtr->name, widget, rPtr->button, rPtr->activeIndex,
SetDoGetRadioVal, (XtPointer)rPtr);
}
void
SetDoGetRadioVal(widget, client_data)
Widget widget;
XtPointer client_data;
{
int TerminalRefreshParameters();
struct _setRadio *rPtr = (struct _setRadio *)client_data;
Boolean state;
XtVaGetValues(widget, XtNradioData, &(rPtr->activeIndex), XtNstate,
&state, NULL);
/* The callback routine is called both when the widget is set or unset,
so we make sure we do nothing if the widget is unset */
if (state == False)
return;
(void)(*rPtr->call_back) (rPtr->activeIndex);
TerminalRefreshParameters();
SeyonMessage("Parameter Change Performed");
}
void
SetGetValue(widget, client_data)
Widget widget;
XtPointer client_data;
{
struct _setValue *vptr;
vptr = set_value;
strncpy(vptr->value, modem_port, SM_BUF);
vptr++;
curValObjPtr = (vptr = (struct _setValue *)client_data);
SePopupDialogGetStringE("set_value", widget, SetDoGetValue,
client_data, vptr->value, True);
}
void
SetDoGetValue(widget, client_data)
Widget widget;
XtPointer client_data;
{
int TerminalRefreshParameters();
Widget dialog = XtParent(widget);
struct _setValue *vptr = (struct _setValue *)client_data;
str_stripspc_copy(vptr->value, XawDialogGetValueString(dialog));
DestroyShell(dialog);
(void)(*vptr->call_back) (vptr->value);
RestartTerminal();
SeyonMessage("Parameter Change Performed");
}
void
setVal_action_ok(widget)
Widget widget;
{
SetDoGetValue(widget, (XtPointer) curValObjPtr);
}
void
UpdateToggleSettings(widget, clientData)
Widget widget;
XtPointer clientData;
{
int TerminalRefreshParameters();
/* We have to complicate things a bit to avoid the danger of the case
SeGetTog.. = True = -1. One should not assume True = 1*/
((void (*)())clientData)(SeGetToggleState(widget) ? 1 : 0);
TerminalRefreshParameters();
SeyonMessage("Parameter Change Performed");
}
int
SetIStrip(state)
int state;
{
qres.stripHighBit = (Boolean)state;
return MdmSetGetIStrip(state);
}
int
ToggleDelMode()
{
toggle_flag(&(qres.backspaceTranslation));
return 0;
}
int
ToggleMetaKeyTr()
{
toggle_flag(&(qres.metaKeyTranslation));
return 0;
}
int
ToggleXOffMode()
{
toggle_flag(&(qres.xonxoffFlowControl));
xc_setflow();
return 0;
}
int
ToggleRtsctsMode()
{
toggle_flag(&(qres.rtsctsFlowControl));
set_rtscts();
return 0;
}
int
ToggleZmodemAutoDownload()
{
toggle_flag(&(qres.autoZmodem));
return 0;
}
int
ToggleIdleGuard()
{
toggle_flag(&(qres.idleGuard));
IdleGuard();
return 0;
}
int
DetNewlineTrMode(keyword)
String keyword;
{
char kw[SM_BUF];
if ((keyword == NULL) || (*keyword == '\0')) {
SeError("missing newlineTranslation keyword");
return -1;
}
str_stripspc_copy(kw, keyword);
lc_word(kw);
if (strcmp(kw, "nl") == 0)
return 1;
else if (strcmp(kw, "cr") == 0)
return 2;
else if (strcmp(kw, "cr/lf") == 0)
return 3;
else {
SeErrorF("illigal newlineTranslation keyword: %s", keyword, "", "");
return -1;
}
}
void
SetNewlineTrMode(keyword)
String keyword;
{
if ((newlineTrMode = DetNewlineTrMode(keyword)) < 0)
newlineTrMode = 2;
}
int
MenuSetGetNewlineTrMode(trMode)
int trMode;
{
if (trMode != -1)
newlineTrMode = trMode;
return newlineTrMode;
}
void
SetScrNewlineTrMode()
{
getword();
if (word[0] == '\0') {
SeError("'set newlineTranslation' must specify translation mode");
eof_flag++;
return;
}
SetNewlineTrMode(word);
}
int
MenuSetGetBaud(baudIndex)
int baudIndex;
{
return MdmSetGetBaud(baudIndex);
}
int
MenuSetGetCSize(bitsIndex)
int bitsIndex;
{
return MdmSetGetCSize(bitsIndex == -1 ? bitsIndex :
bitsIndex + 4) - 4;
}
int
MenuSetGetParity(parityIndex)
int parityIndex;
{
return MdmSetGetParity(parityIndex == -1 ? parityIndex :
parityIndex - 1) + 1;
}
int
MenuSetGetStopBits(bitsIndex)
int bitsIndex;
{
return MdmSetGetStopBits(bitsIndex);
}
int
MenuSetGetParamSCut(paramIndex)
int paramIndex;
{
int bits,
parity,
stopBits;
if (paramIndex == -1) {
bits = MdmSetGetCSize(-1);
parity = MdmSetGetParity(-1);
stopBits = MdmSetGetStopBits(-1);
if (bits == 8 && parity == 0 && stopBits == 1)
return 1;
else if (bits == 7 && parity == 2 && stopBits == 1)
return 2;
else
return 3;
}
if (paramIndex == 1) {
MdmSetGetCSize(8);
MdmSetGetParity(0);
MdmSetGetStopBits(1);
}
else if (paramIndex == 2) {
MdmSetGetCSize(7);
MdmSetGetParity(2);
MdmSetGetStopBits(1);
}
return paramIndex;
}
int
SetBaud(baud)
String baud;
{
if (mbaud(baud) < 0) {
SeErrorF("unsupported baud rate %s", baud, "", "");
return False;
}
return True;
}
int
SetPort(port)
String port;
{
int retStatus,
reopRetStatus;
String oldPort = XtNewString(mport(NULL));
unlock_tty();
CloseModem();
if ((retStatus = OpenModem(port)) < 0) {
ShowOpenModemErrMsg(port, retStatus);
if ((reopRetStatus = OpenModem(oldPort)) < 0)
{ShowOpenModemErrMsg(oldPort, reopRetStatus);
SeError(FmtString("Could not re-open old modem device %s", oldPort, "",
""));}
}
XtFree(oldPort);
return retStatus;
}
void s_set_xoff(),
s_set_baud(),
set_port(),
s_set_cr(),
ScrSetIStrip(),
s_set_del(),
set_meta_tr(),
s_set_rtscts(),
s_set_autozm(),
SetScrIdleGuardMode(),
ScrSetCSize(),
ScrSetParity(),
ScrSetStopBits();
struct kw setlist[] =
{
{"stripHighBit", ScrSetIStrip},
{"bits", ScrSetCSize},
{"parity", ScrSetParity},
{"stopBits", ScrSetStopBits},
{"newlineTranslation", SetScrNewlineTrMode},
{"del", s_set_del},
{"meta_tr", set_meta_tr},
{"xoff", s_set_xoff},
{"rtscts", s_set_rtscts},
{"autozm", s_set_autozm},
{"idleGuard", SetScrIdleGuardMode},
{"baud", s_set_baud},
{"port", set_port},
{NULL, NULL}};
void
s_set()
{
struct kw *ptr;
GETTEST_ARG("set");
/* lc_word(word);*/
for (ptr = setlist; ptr->keyword != NULL; ptr++)
if (strcmp(ptr->keyword, word) == 0)
{(*ptr->rtn)(); return;}
SeErrorF("Invalid set keyword `%s'", word, "", "");
eof_flag++;
}
void
s_set_cr()
{
set_onoff(&(qres.newlineTranslation));
}
void
ScrSetIStrip()
{
Boolean tmpSetFlag;
set_onoff(&tmpSetFlag);
SetIStrip(tmpSetFlag ? 1 : 0);
}
void
s_set_del()
{
set_onoff(&(qres.backspaceTranslation));
}
void
set_meta_tr()
{
set_onoff(&(qres.metaKeyTranslation));
}
void
s_set_xoff()
{
set_onoff(&(qres.xonxoffFlowControl));
xc_setflow();
}
void
s_set_rtscts()
{
set_onoff(&(qres.rtsctsFlowControl));
set_rtscts();
}
void
s_set_autozm()
{
set_onoff(&(qres.autoZmodem));
}
void
SetScrIdleGuardMode()
{
set_onoff(&(qres.idleGuard));
IdleGuard();
}
void
set_onoff(flag)
Boolean *flag;
{
String keyWord = XtNewString(word);
getword();
lc_word(word);
if (strcmp(word, "on") == 0) *flag = True;
else if (strcmp(word, "off") == 0) *flag = False;
else {
SeErrorF("Argument `%s' to keyword `%s' is neither on nor off",
word, keyWord, "");
eof_flag++;
}
if (keyWord) XtFree(keyWord);
}
#define ScrGetArg(msg) \
{ \
getword(); \
if (word[0] == '\0') { \
SeError(msg); \
eof_flag++; \
return; \
} \
}
void
ScrSetCSize()
{
ScrGetArg("set bits: missing argument");
MdmSetGetCSize(atoi(word));
}
void
ScrSetParity()
{
ScrGetArg("set parity: missing argument");
MdmSetGetParity(atoi(word));
}
void
ScrSetStopBits()
{
ScrGetArg("set stopBits: missing argument");
MdmSetGetStopBits(atoi(word));
}
void
s_set_baud()
{
getword();
if (word[0] == '\0') {
SeError("'set baud' must specify baud rate");
eof_flag++;
return;
}
if (SetBaud(word) == False)
eof_flag++;
}
void
set_port()
{
SeNotice("/sp/ Sorry, \"set port\" is not supported in this release");
return;
getword();
if (word[0] == '\0') {
SeError("'set port' must specify modem device");
eof_flag++;
return;
}
if (SetPort(word) == False)
eof_flag++;
}
struct param {
Boolean autoZmodem;
Boolean idleGuard;
Boolean stripHighBit;
Boolean backspaceTranslation;
Boolean metaKeyTranslation;
Boolean xonxoffFlowControl;
Boolean rtsctsFlowControl;
int newlineTrMode;
};
int
PutParameters(destination)
int *destination;
{
struct param param;
int writeRetStatus;
param.idleGuard = qres.idleGuard;
param.stripHighBit = qres.stripHighBit;
param.backspaceTranslation = qres.backspaceTranslation;
param.metaKeyTranslation = qres.metaKeyTranslation;
param.xonxoffFlowControl = qres.xonxoffFlowControl;
param.rtsctsFlowControl = qres.rtsctsFlowControl;
param.autoZmodem = qres.autoZmodem;
param.newlineTrMode = newlineTrMode;
if ((writeRetStatus = write(destination[1], (char*)¶m, sizeof(param)))
== -1)
SePError("Could not write to pipe");
return writeRetStatus;
}
void
GetParameters(clientData, source)
XtPointer clientData;
int *source;
{
struct param param;
if (read(source[0], (char*)¶m, sizeof(param)) == -1)
SePError("Could not read from pipe");
qres.idleGuard = param.idleGuard;
qres.stripHighBit = param.stripHighBit;
qres.backspaceTranslation = param.backspaceTranslation;
qres.metaKeyTranslation = param.metaKeyTranslation;
qres.xonxoffFlowControl = param.xonxoffFlowControl;
qres.rtsctsFlowControl = param.rtsctsFlowControl;
qres.autoZmodem = param.autoZmodem;
newlineTrMode = param.newlineTrMode;
get_modem_attr();
}
|