LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-07-2004, 04:25 PM   #1
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Rep: Reputation: 51
setting terminal modes (structure question)


iv looked thru a few c tutorials but i don't seem to find what I'm looking for, more specifically the operators &= |= (i think they AND and OR the values with the previous one, but what really gets me is what does ~ mean.. ), heres 2 examples

int
set_istrip (int desc, int value)
{
struct termios settings;
int result;

result = tcgetattr (desc, &settings);
if (result < 0)
{
perror ("error in tcgetattr");
return 0;
}
settings.c_iflag &= ~ISTRIP;
if (value)
settings.c_iflag |= ISTRIP;
result = tcsetattr (desc, TCSANOW, &settings);
if (result < 0)
{
perror ("error in tcsetattr");
return 0;
}
return 1;
}

taken from a glib tutorial thing, and another one i found somewhere on the same site

termios-p->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
|INLCR|IGNCR|ICRNL|IXON);
termios-p->c_oflag &= ~OPOST;
termios-p->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
termios-p->c_cflag &= ~(CSIZE|PARENB);
termios-p->c_cflag |= CS8;

can anyone tell me what this means termios-p->c_oflag &= ~OPOST;

more like what it does to the termios-p->c_oflag flag, in the first example it looks like it might delete it, but the second one looks like it might set the flag,,, anyone know please?
 
Old 05-07-2004, 05:54 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Basically it removes the OPOST bit from the bitfield ("unset the OPOST flag"). The ~ operator returns all of the 1s and 0s reversed. Like if you had the following byte:

01011010

then ~byte would be:

10100101

So let's say you had OPOST defined as 0x4. If c_oflag looked like 01111100 then 'c_oflag &= ~OPOST;' would turn into 'c_oflag = 01111100 & ~00000100;' Since '01111100 & 00000100' is 01111000 it effectively removes the OPOST bit.

| is the bitwise OR, & is the bitwise AND.

I think it's easier to draw out on paper. I hope that all made sense

Last edited by itsme86; 05-07-2004 at 05:55 PM.
 
Old 05-07-2004, 06:50 PM   #3
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Original Poster
Rep: Reputation: 51
so basically the ~ is taking out that bit defined? (like XOR?)
 
Old 05-08-2004, 08:43 AM   #4
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
It's actually the combination of the ~ and the &= that is taking the bit out.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
directory structure question bmorency Linux - Newbie 1 10-27-2005 04:31 PM
Question, Apples Contribution to Open Source + MacOs file structure question Higgy3k Other *NIX 5 07-25-2005 04:23 AM
XF86 Modes/TVout Question kwiksand Linux - Software 2 04-13-2004 10:27 PM
c++ structure-array question deveraux83 Programming 2 01-01-2004 08:55 AM
structure question Lostman Linux - Newbie 1 11-04-2003 02:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration