GNU marks in auto generated source by lex or bison - gnu

I want to submit some code that generated by lex and bison. Since there are gnu marks in them, I'm serious if it will become a trouble later to a non open source, commercial project.
Thanks for any suggestion.

lex (you are probably referring to flex) is not a GNU project, and is not GPL-licensed (it uses the permissive BSD license instead). So there are no "gnu marks" in its output. You may be talking about text such as
#line 3 "lex.yy.c"
#define YY_INT_ALIGNED short int
/* A lexical scanner generated by flex */
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 5
#define YY_FLEX_SUBMINOR_VERSION 35
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
which are conventional C-preprocessor lines, unrelated to licensing.
Bison's output is explicitly addressed in its licensing, and is not a problem:
The distribution terms for Bison-generated parsers permit using the parsers in nonfree programs.

Related

What is value held in selector of task register? Index or byte-offsets?

I'm studying old linux kernel source(linux-0.11), some macros defined in sched.h:
#define FIRST_TSS_ENTRY 4
#define _TSS(n) ((((unsigned long) n)<<4)+(FIRST_TSS_ENTRY<<3))
#define ltr(n) __asm__("ltr %%ax"::"a" (_TSS(n)))
It loads byte-offsets into the selector part of task register, but as per Intel 80386 manual, the selector consists of index, TI and RPL parts. It makes me confused.

How to suppress warnings messages in Rcpp/RcppArmadillo functions

I am using RcppArmadillo within an R package. I want to suppress a warning message that occurs in a C++ function due to numerical precision when a symmetric matrix fails a test of symmetry within eig_sym(). I am confident this is a precision issue as I have saved some of the matrices hitting this warning and tested them in R using isSymmetric() and they pass this.
I have tried including #define ARMA_WARN_LEVEL 0 at the top of the header file where the function with this issue is defined, but this does not solve my issue and I am told 'ARMA_WARN_LEVEL' macro redefined (presumably it is defined in the config file of RcppArmadillo).
Ideally I would suppress only errors associated with this call of eig_sym, but failing this I am content to suppress all warnings. If anyone can advise on how to effect this I would be very grateful.
Thank you.
Looking at Armadillo's config.hpp -- the first header file included by Armadillo -- we see that it starts with
#if !defined(ARMA_WARN_LEVEL)
#define ARMA_WARN_LEVEL 2
#endif
//// The level of warning messages printed to ARMA_CERR_STREAM.
//// Must be an integer >= 0. The default value is 2.
//// 0 = no warnings
//// 1 = only critical warnings about arguments and/or data which are likely to lead to incorrect results
//// 2 = as per level 1, and warnings about poorly conditioned systems (low rcond) detected by solve(), spsolve(), etc
//// 3 = as per level 2, and warnings about failed decompositions, failed saving/loading, etc
so a simple
#define ARMA_WARN_LEVEL 0
#include <RcppArmadillo.h>
should take care of things. We cannot "show" this as we have no reproducible example to work with.
Also note that there is a good reason why warnings are usually on. They signal something you as author should be aware of.

what is the significance of these lines

I found in this code on codeforces . I am not that expert please guide me the use of these lines of code
The question just reads an input string of integers of maximum length 1000
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("test.in", "r", stdin);
#endif
The first line is basically done to speedup reading files since these features are not generally required in competitive coding (take this with a grain of salt):
Usage of ios_base::sync_with_stdio can be found in Using scanf() in C++ programs is faster than using cin?
Usage of cin.tie(0), cout.tie(0) can be found in Why do we need to tie std::cin and std::cout?
As for using ONLINE_JUDGE it has been explained in codeforces blog. Basically, when codeforces runs the code online it adds the ONLINE_JUDGE flag. In your case if you are running the code at home you can ignore ONLINE_JUDGE flag and it will read your test file test.in. The same code while running in Codeforces will have ONLINE_JUDGE set and will ignore the freopen("test.in", "r", stdin); line and run its own test cases.

New syscall not found (linux kernel 3.0.0) where should I start looking?

I created two new syscalls, but when I try to test them I get the following error:
matt#ubuntu:~/test$ gcc test.c
test.c: In function ‘newcall’:
test.c:6:17: error: ‘sys_get_slob_amnt_free’ undeclared (first use in this function)
test.c:6:17: note: each undeclared identifier is reported only once for each function it appears in
matt#ubuntu:~/test$
I also tried this with syscall(sys_get_slob_amnt_free) with the same result.
Here is the test code:
#include <unistd.h>
#include <stdio.h>
unsigned long newcall()
{
return syscall(__NR_get_slob_amnt_free);
}
int main()
{
printf("%d\n", newcall());
return 0;
}
In order to add these I put them in the syscall table
(/usr/src/linux-3.0/include/asm-generic/unistd.h)
#define __NR_sendmmsg 269
__SC_COMP(__NR_sendmmsg, sys_ sendmmsg, compat_sys_sendmmsg)
/** my changes here **/
#define __NR_get_slob_amnt_free 270
__SYSCALL(__NR__get_slob_amnt_free, sys_get_slob_amnt_free)
#define __NR_get_slob_amnt_claimed 271)
__SYSCALL(__NR_get_slob_amnt_claimed, sys_get_slob_amnt_claimed)
/** /my changes **/
#undef __NR_syscalls
#define __NR_syscalls 272
And here is the code for the calls themselves (../linux-3.0/mm/slob.c)
asmlinkage unsigned int sys_get_slob_amnt_claimed()
{
return memClaimed;
}
asmlinkage unsigned int sys_get_slob_amnt_free()
{
return memClaimed - memUsed;
}
I'm trying to figure out whether I'm botching the test code (maybe I need to include something more? or link something?) Or if I've overlooked something in adding the syscall in the first place. With the amount of time it takes to recompile the kernel, it would really help me out to know where to start looking.
Admittedly, this is related to a homework assignment. The assignment is about modifying slob.c, which I have a pretty good handle on. I'm just doing this to get a peek at whether the modifications I've made so far are going anywhere. I appreciate any guidance you can give. Thanks!
Edit: Solved (or at least solved enough for me).
Many thanks to bdonlan! Although syscall(270) didn't do it directly, it jogged my memory--there is another set of relevant numbers that I was neglecting entirely. The file /linux-3.0/arch/x86/kernel/syscall_table_32.c needed to be modified as well in order to properly add the syscall.
Once I added .long sys_get_slob_amnt_free and .long sys_get_slob_amnt_claimed to that file and rebuilt the kernel, I could hit my syscalls by using syscall(###) where ### is the numbering in syscall_table_32.c (not the numbering in unistd.h). I feel like they should match--but since this is just glorified debug information I think I'll leave that mystery for another time and just call it good.
There is another set of relevant numbers that I was needed to add. The file /linux-3.0/arch/x86/kernel/syscall_table_32.c needed to be modified as well in order to properly add the syscall.
Once I added .long sys_get_slob_amnt_free and .long sys_get_slob_amnt_claimed to that file and rebuilt the kernel, I could hit my syscalls by using syscall(###) where ### is the numbering in syscall_table_32.c (not the numbering in unistd.h)

detecting keyboard, mouse activity in linux

I need a way to detect mouse/keyboard activity on Linux. Something similar to what any IM program would do. If no activity is detected for, say 5 minutes, it will set your IM status to "I'm not here right now".
Any help towards this is appreciated.
Thanks.
Or simply use the command xprintidle which returns the idle time in milliseconds.
It has been packaged for debian based systems. (the source is not available any more on the original site dtek.chalmers.se/~henoch but you can get it at packages.ubuntu.com)
more info on freshmeat.net
Complete c solution : (cut & paste the whole code in a terminal)
cat>/tmp/idletime.c<<EOF
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/scrnsaver.h>
int GetIdleTime () {
time_t idle_time;
static XScreenSaverInfo *mit_info;
Display *display;
int screen;
mit_info = XScreenSaverAllocInfo();
if((display=XOpenDisplay(NULL)) == NULL) { return(-1); }
screen = DefaultScreen(display);
XScreenSaverQueryInfo(display, RootWindow(display,screen), mit_info);
idle_time = (mit_info->idle) / 1000;
XFree(mit_info);
XCloseDisplay(display);
return idle_time;
}
int main() {
printf("%d\n", GetIdleTime());
return 0;
}
EOF
gcc -Wall /tmp/idletime.c -o /tmp/idletime -L/usr/X11R6/lib/ -lX11 -lXext -lXss
DISPLAY=:0 /tmp/idletime
(the main part is coming from X11::IdleTime perl module)
My aproach is to use ad-hoc perl module :
# cpan -i X11::IdleTime; sleep 2; perl -MX11::IdleTime -e 'print GetIdleTime(), $/;'
Don't poll when there's better methods available.
You don't specify the environment, but since you mention the mouse, I'm going to assume modern X11.
xidle uses the MIT-SCREEN-SAVER extension to determine whether the user is idle or not -- you can use xidle directly, or read its source code to learn how to use the XScreenSaver(3) yourself.
Edit
man 3 XScreenSaver -- just use the idle-reporting/notification portions of it, since there is no more XIDLE extension since X11R6.
This is an example how to check that an user is idle for 5 minutes using xprintidle and shell script:
#!/bin/sh
idletime=$(xprintidle)
threshold=300000 # 5 min = 5 * 60 * 1000 ms
if [ "$idletime" -gt "$threshold" ]; then
echo "idle"
fi
xprintidle returns time in milliseconds.
This script does not do any polling or the like. It only executes some code if user is idle and does nothing otherwise.
Try executing who -u -H at the command line. It will tell you who's logged in and how long they've been idle. At least users logged in to a terminal; I don't think it works at all in X. Anyhow, with this information you can tell who's idle or not and take actions appropriately.
If you're in X you could create a script to run as a screen saver or something like that.
I wrote the wait-while-idle.rb which does the "detecting keyboard, mouse activity in linux" but the other way around — wait until the user's come back.
Yes, sure — it's polling, but I doubt anyone requires performance here.
Planning to catch pranksters sneaking up on my computer with it and a little scripting.

Resources