LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] [TOTD] find error corresponding to number

[ILUG] [TOTD] find error corresponding to number

Feargal Reilly feargal at helgrim.com
Fri May 7 12:38:28 IST 2004


On Fri, 07 May 2004 11:45:48 +0100
Stephen Shirley <diamond at skynet.ie> wrote:

> Bryan O'Donoghue wrote:
> > Stephen Shirley wrote:
> >> Also, as a nit pick, you should not be using the kernel headers, but 
> >> rather the headers of the kernel your glibc was compiled against, 
> >> which should be under /usr/include/{bits,asm,asm-generic,linux}
> >>
> > 
> > Why would that be now?
> > 
> > If the Kernel sets the signal state for a process, with a particular 
> > number and for argument's sake the signal number had changed from kernel 
> > version x, to kernel version y, you'd want to be aware of the current 
> > meaning of the signal number, ergo you'd want to check the meaning of 
> > the signal number in the *currently* running kernel, as opposed to the 
> > kernel, you libc may or may not have been compiled against?
> > 
> 
> http://linuxmafia.com/faq/Kernel/usr-src-linux-symlink.html
> 
> Short version: the kernel can take care of backwards compatibility
> 
> Steve

You're all feckers...

Following script should keep you happy, usage:

$ grepdef
Shows all definitions in <errno.h>

$ grepdef 5
#define EIO             5               /* Input/output error */

$ grepdef NET
#define ENETDOWN        50              /* Network is down */
#define ENETUNREACH     51              /* Network is unreachable */
#define ENETRESET       52              /* Network dropped connection on
reset *

$ grepdef 'Network is down'
#define ENETDOWN        50              /* Network is down */

$ grepdef . /usr/include/math.h
Shows all definitions in math.h

$ grepdef pi /usr/include/math.h
#define M_PI            3.14159265358979323846  /* pi */
#define M_PI_2          1.57079632679489661923  /* pi/2 */
#define M_PI_4   

Nice and useful. Except I wrote it in es.

#!/usr/local/bin/es
if {~ $#1 0} {
  a = ''                                 # match anything
} {~ $1 [0-9-]*} {
  a = [[:space:]]^$1\([[:space:]]\|\$\)  # :space: not matching
newline??
} {
  a = $1
}
if {~ $#2 0} {
  f = '<errno.h>'                        # default include
  p = 'errno.h'
} {
  if {~ $2 /*} {
    f = "$2"                             # must be a path, 
    p = $2                               # could skip the cpp, but lazy
  } {
    f = \<$2\>                           # include what they give us
    p = $2
  }
}
# use cpp to figure out the path, should be string wrapped in ""
cat <= {~~ `{echo \#include $f | cpp -d | grep $p | head -n1} "*"} |
grep -E \#define.*^$a
       0.78539816339744830962  /* pi/4 */
#define M_1_PI          0.31830988618379067154  /* 1/pi */
#define M_2_PI          0.63661977236758134308  /* 2/pi */
#define M_2_SQRTPI      1.12837916709551257390  /* 2/sqrt(pi) */


If first arg starts with a digit or -, searches for it wrapped in
whitespace.

Bloatware at 550 chars, but for those who are desperately short on bytes, you could put the
following 255 chars in your .esrc and avoid using up another valuable inode.
fn grepdef {
	if {~ $#1 0}{a=''}{~ $1 [0-9-]*}{a=[[:space:]]^$1\([[:space:]]\|\$\)}{a=$1}
	if {~ $#2 0}{f='<errno.h>';p='errno.h'}{if {~ $2/*}{f="$2";p=$2}{f=\<$2\>;p=$2}}
	cat<={~~ `{echo \#include $f|cpp -d|grep $p|head -n1} "*"}|grep -E \#define.*^$a
}

-fr.


--
Feargal Reillly,
http://www.helgrim.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://mail.linux.ie/pipermail/ilug/attachments/20040507/4c800225/attachment.pgp


More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell