004-check_tty.patch 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. --- a/comgt.c
  2. +++ b/comgt.c
  3. @@ -91,6 +91,7 @@ unsigned long hstart,hset;
  4. char NullString[]={ "" };
  5. BOOL lastcharnl=1; /* Indicate that last char printed from getonebyte
  6. was a nl, so no new one is needed */
  7. +BOOL tty=1;
  8. //"open com \"/dev/modem\"\nset com 38400n81\nset senddelay 0.05\nsend \"ATi^m\"\nget 2 \" ^m\" $s\nprint \"Response : \",$s,\"\\n\"\nget 2 \" ^m\" $s\nprint \"Response :\",$s,\"\\n\"\nget 2 \" ^m\" $s\nprint \"Response : \",$s,\"\\n\"\n\n";
  9. @@ -920,7 +921,7 @@ BOOL getonoroff(void) {
  10. void setcom(void) {
  11. stbuf.c_cflag &= ~(CBAUD | CSIZE | CSTOPB | CLOCAL | PARENB);
  12. stbuf.c_cflag |= (speed | bits | CREAD | clocal | parity | stopbits );
  13. - if (ioctl(comfd, TCSETS, &stbuf) < 0) {
  14. + if (tty && ioctl(comfd, TCSETS, &stbuf) < 0) {
  15. serror("Can't ioctl set device",1);
  16. }
  17. }
  18. @@ -1224,7 +1225,7 @@ void doclose(void) {
  19. if(strcmp(token,"hardcom")==0) {
  20. if(comfd== -1) serror("Com device not open",1);
  21. vmsg("Closing device");
  22. - if (ioctl(comfd, TCSETS, &svbuf) < 0) {
  23. + if (tty && ioctl(comfd, TCSETS, &svbuf) < 0) {
  24. sprintf(msg,"Can't ioctl set device %s.\n",device);
  25. serror(msg,1);
  26. }
  27. @@ -1266,12 +1267,17 @@ void opengt(void) {
  28. ext(1);
  29. }
  30. }
  31. - if (ioctl (comfd, TCGETS, &svbuf) < 0) {
  32. + if (isatty (comfd))
  33. + tty=1;
  34. + else
  35. + tty=0;
  36. + if (tty && ioctl (comfd, TCGETS, &svbuf) < 0) {
  37. sprintf(msg,"Can't control %s, please try again.\n",device);
  38. serror(msg,1);
  39. }
  40. setenv("COMGTDEVICE",device,1);
  41. - ioctl(comfd, TCGETS, &stbuf);
  42. + if (tty)
  43. + ioctl(comfd, TCGETS, &stbuf);
  44. speed=stbuf.c_cflag & CBAUD;
  45. if (high_speed == 0) strcpy(cspeed,"115200");
  46. else strcpy(cspeed,"57600");
  47. @@ -1302,12 +1308,16 @@ void opendevice(void) {
  48. }
  49. }
  50. else comfd=0;
  51. -
  52. - if (ioctl (comfd, TCGETS, &svbuf) < 0) {
  53. + if (isatty (comfd))
  54. + tty=1;
  55. + else
  56. + tty=0;
  57. + if (tty && ioctl (comfd, TCGETS, &svbuf) < 0) {
  58. sprintf(msg,"Can't ioctl get device %s.\n",device);
  59. serror(msg,1);
  60. }
  61. - ioctl(comfd, TCGETS, &stbuf);
  62. + if (tty)
  63. + ioctl(comfd, TCGETS, &stbuf);
  64. speed=stbuf.c_cflag & CBAUD;
  65. switch(speed) {
  66. case B0: strcpy(cspeed,"0");break;