Works on Linux.
Perhaps LINES and/or COLS are something nonsensical causing newwin to fail? Did you try checking win for NULL?
[QUOTE=ZeekyHBomb;42934271]I'm not sure what you mean by automatic, but it kinda sounds like you want a blur filter, which can probably be done rather quickly in a shader.
[/QUOTE]
By automatic I meant any quick loop that would check adjacent vertices and build up the normals, I cant think of any way to do it
[img]http://i.imgur.com/iNzQbkc.png[/img]
Okay so I got this in visual c# Looks good but now Im stuck because I have no clue what to do.
[QUOTE=ZeekyHBomb;42939635]Works on Linux.
Perhaps LINES and/or COLS are something nonsensical causing newwin to fail? Did you try checking win for NULL?[/QUOTE]
[code]
int main(...) {
...
cbreak();
printw("Testing a custom window!\n");
printw("<LINES, COLS> = <%d, %d>\n",LINES,COLS);
refresh();
... }
WINDOW* nwin(int width, int height, int startx, int starty) {
WINDOW* win;
win = newwin(height,width,starty,startx);
box(win,0,0);
printw("win is %s null.\n",((!win) ? "" : "not"));
//wrefresh(win);
return win;
}[/code]
[code]Testing a custom window!
<LINES,COLS> = <25,80>
win is not null.[/code]
[editline]22nd November 2013[/editline]
I just ran the program through GDB, recompiling after uncommenting the wrefresh, breaking at nwin and stepping through it.
As soon as it executes the wrefresh, the program segfaults (sends SIGSEGV) in wnoutrefresh(). I am going to go and remember how to get GDB to dump the core, see if I can find a more thorough stacktrace.
[editline]22nd November 2013[/editline]
It is also worth noting that I downloaded and compiled the PDCurses myself. I downloaded the source files from [url=http://sourceforge.net/projects/pdcurses/files/pdcurses/3.4/pdcurs34.zip/download]this sourceforge location[/url].
Perhaps there is an issue with the source code somewhere?
[editline]22nd November 2013[/editline]
And it appears Windows doesn't create core dumps. Wonderful.
Any idea why "\\s+" isn't ignoring new line characters?
[cpp]public static void main(String[] args) throws Exception {
int count = 0;
URL gettysberg = new URL("http://cs.armstrong.edu/liang/data/Lincoln.txt");
BufferedReader in = new BufferedReader(
new InputStreamReader(gettysberg.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null){
//Want to split inputLine into words instead of a line
//Will split line into words, ignoring all white spaces and punctuation
String[] split = inputLine.split("\\s+");
//Now count number of items in array
count += split.length;
}
in.close();
System.out.println("The number of words is " + count + ".");
}
[/cpp]
Should come out to 277 but it comes out to 279 because the input file has three paragraphs (two spaces).
[QUOTE=Vilusia;42940678][img]http://i.imgur.com/iNzQbkc.png[/img]
Okay so I got this in visual c# Looks good but now Im stuck because I have no clue what to do.[/QUOTE]
Panels are most likely not the right control for your needs.
If this was WPF making complicated dynamic lists would be easy (with Grid or plain ListBoxes) but with WinForms it's really tedious afaik.
Maybe there is some table control you can use, but it's not going to be able to mix data formats very well.
I know this really isn't the right place, but I'm desperate. [url=http://facepunch.com/showthread.php?t=1326983]I made a thread[/url] to get help with a gmod module. (don't worry, it's not simple questions like 'how does the gmod api work') I'm getting a weird error with threads and cooperating with steamworks.
[QUOTE=Vilusia;42940678][img]http://i.imgur.com/iNzQbkc.png[/img]
Okay so I got this in visual c# Looks good but now Im stuck because I have no clue what to do.[/QUOTE]
To be honest, you won't get very far without any knowledge in programming.
I think a XML editor is a bit too difficult as a first project.
Read some tutorials about 'winforms', c# and experiment with those things for a bit before trying something harder.
[QUOTE=Zinayzen;42941639]Any idea why "\\s+" isn't ignoring new line characters?
[cpp]public static void main(String[] args) throws Exception {
int count = 0;
URL gettysberg = new URL("http://cs.armstrong.edu/liang/data/Lincoln.txt");
BufferedReader in = new BufferedReader(
new InputStreamReader(gettysberg.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null){
//Want to split inputLine into words instead of a line
//Will split line into words, ignoring all white spaces and punctuation
String[] split = inputLine.split("\\s+");
//Now count number of items in array
count += split.length;
}
in.close();
System.out.println("The number of words is " + count + ".");
}
[/cpp]
Should come out to 277 but it comes out to 279 because the input file has three paragraphs (two spaces).[/QUOTE]
[quote=http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String)]Trailing empty strings are [...] not included in the resulting array.[/quote]
It says nothing about empty spaces in the beginning.
Try only adding to count if !(split.length == 1 && split[0].length() == 0).
[QUOTE=Vilusia;42940678][IMG]http://i.imgur.com/iNzQbkc.png[/IMG]
Okay so I got this in visual c# Looks good but now Im stuck because I have no clue what to do.[/QUOTE]
I think your goal is not unreasonable for a first-time programming project, but making a GUI is another beast entirely. Using a scripting language like Python or Ruby, it's quite easy to create a script that can read/write XML files... if you don't mind interacting with it on the command line.
I would start by just making a script that reads in the XML file and summarizes its contents on the command line.
Then make a script that prompts the user for input on the command line a few times and creates an XML file based on their input.
From there it shouldn't be too hard to make a command line tool that modifies your XML file. For example, your input could be a series of tag/value pairs and the script searches for those tags and modifies their values accordingly. It all depends on the structure of the XML files and what exactly you want to do with them.
If you go with Ruby, you can use [URL="http://www.ruby-doc.org/stdlib-2.0.0/libdoc/rexml/rdoc/REXML.html"]rexml[/URL] or [URL="http://nokogiri.org/"]Nokogiri[/URL]. If you go with Python, use [URL="http://docs.python.org/3.3/library/xml.etree.elementtree.html"]ElementTree[/URL].
Can someone explain how a preempting scheduler is implemented when there is only one core?
With one core there is only one "hardware thread".
So when the kernel schedules a process, how can it be interrupted when it's time slice is up? There is no other thread that can preemt it is there?
Is this situation handled with hardware interrupts?
If so what interrupt is used? Maybe the "time interrupt"? But doesn't that fire too often to be of use for preempting threads?
Or maybe there is some sort of counter in the cpu that records the amount of instructions that have been executed so far that can be used?
It probably depends on the hardware available, but usually there is a programmable timer on the board, for which you can set the interval for it to send an interrupt to the CPU.
[editline]22nd November 2013[/editline]
[url=https://en.wikibooks.org/wiki/X86_Assembly/Programmable_Interval_Timer]Wikibooks, X86 Assembly - Programmable Interval Timer[/url]
I want to make a game with C# and XNA, but I don't want to build an engine. Does anyone have some suggestions for simple 2d engines for C#?
[QUOTE=BooTs;42949360]I want to make a game with C# and XNA, but I don't want to build an engine. Does anyone have some suggestions for simple 2d engines for C#?[/QUOTE]
Try Unity, I haven't used it but it seems to be both good and popular.
If you want to do anything with shaders for free you need to learn OpenGL or Direct3D though.
-There's nothing here, you see nothing (I figured it out as I posted it; was a dumb mistake on my part)-
Does anybody know a good physics engine that ISN'T Farseer physics and that works good with SFML.NET?
Farseer physics works but it's impossible to get correct sim unit to screen convertion.
Trying to use Garry's [URL="https://github.com/garrynewman/bootil"]Bootil library[/URL] with no avail.
[IMG]http://puu.sh/5qy0f.png[/IMG]
The files I am referencing are in the correct location.
[IMG]http://puu.sh/5qxYW.png[/IMG]
I've commented out line 44 only to have another line give the same error, so forth, and so forth. Can someone shed some light on this (Sorry if it's extremely obvious, tired and somewhat inexperienced)?
[QUOTE=rbreslow;42953540]-Bootil-[/QUOTE]
It looks like a problem on your end, without knowing anything about compiling C++ I'd say either your source root or working directory is wrong.
Can someone help me with Lua?
There is a map object that looks like map.tiles[x][y] = tileObj
the tileObj is an object that has a list of entites there are on that tile
for convenience I have a map.tilesList[x*y] = tileObj so I can loop through tiles easily.
There also is a list of entities, that looks like ents[z] = entObj
the entObj contains a reference to the tile it resides in.
So my question comes down to does Lua shits itself (makes an infinite loop)
Because I can make something like
map.tiles[i][j].entList[1].occupiedTile.entList[1].occupiedTile.entList[1].occupiedTile
-fixed on my own-
Guys, I need some help here in a very basic C program.
I'm currently making a simple program that manages calls from and to a file.
The problem here is: how do I make it so that when using main(int argc, char *argv[]) I can run the program like this: ./teltel NUMBER
where NUMBER is the phone number whose info I want to print on the screen whenever I call ./teltel NUMBER.
So far this is my code:
[CODE]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct registo_chamadas {
char origem[10];
char destino[10];
} registo_chamadas;
/*int writercalls(char* numero)
{
int i=0;
int i_virgula=0;
int i_ref=0;
char buffer[200];
char c;
FILE *dados_entrada;
registo_chamadas
}*/
int printmadecalls(char* numero)
{
int i=0;
int i_virgula=0;
int i_ref=0;
char buffer[200];
char c;
FILE *dados_entrada;
registo_chamadas chamada_actual;
if( (dados_entrada = fopen("db(pequeno).txt","r"))==NULL)
{
printf("File db.txt not found\n");
return -1;
}
while((fgets(buffer,200,dados_entrada))!=NULL)
{
i_virgula=0;
c=buffer[i_virgula];// no caso do primeiro caracter ser ;
while(c!=';')
{
c=buffer[i_virgula];
i_virgula++;
}
i_ref=i_virgula-10;
for(i=0;i<9;i++)
{
chamada_actual.origem[i]=buffer[i_ref+i];
}
chamada_actual.origem[9]='\0'; //numeros recebidos impressos para teste
c=buffer[i_virgula+1];
while(c!=';')
{
c=buffer[i_virgula];
i_virgula++;
}
i_ref=i_virgula-10;
for(i=0;i<9;i++)
{
chamada_actual.destino[i]=buffer[i_ref+i];
}
/*printf("%s\n",chamada_actual.destino);*/
chamada_actual.destino[9]='\0';
if(strcmp(numero,chamada_actual.origem)==0) // A zero value indicates that both strings are equal.
{
printf("%s\n",chamada_actual.destino);
}
}
fclose(dados_entrada);
}
void menu()
{
int op;
char numero[9];
do
{
printf("\t\tCall Analisys\n\n");
printf("0 - Exit the program\n");
printf("1 - Show calls performed by a number\n");
printf("2 - Write the calls received by a number in the file\n");
printf("3 - Total conversation time initiated by a number\n\n");
scanf(" %d", &op);
switch(op)
{
case 0 : printf("Bye\n"); exit(1); break;
case 1 : printf("What's the number you want to check? \n"); scanf(" %s", &numero); printmadecalls(numero); break;
default : printf("Invalid Choice\n"); break;
}
}
while(op!=0);
}
int main(int argc, char *argv[])
{
char numero[9];
argv[1] = numero;
if(argv[1]==numero)
printmadecalls(numero);
else
menu();
return 1;
}
[/CODE]
[B]main function:[/B]
[CODE]
int main(int argc, char *argv[])
{
char numero[9];
argv[1] = numero;
if(argv[1]==numero)
printmadecalls(numero);
else
menu();
return 1;
}
[/CODE]
What I wanna do is:
if you run the program with just [I]./teltel[/I] it shows me the menu. However if I run [I]./teltel 91XXXXXXX[/I] I want him to run the function printmadecalls(91XXXXXXX) (91XXXXXXXXX being the number in argv[1].
I know that argv[1] contains the string where my number is, right? So why is it that nothing happens when I run the program ./teltel 91XXXXXXXXX and when I run just ./teltel when I call printmadecalls(number) through the menu, it works? Am I not using pointers correctly?
Can anyone clarify how to properly specify linkage of external functions from C++? Everywhere I've read about the subject it indicates that "extern "C" { }" will, at the very least, suppress name_mangling (which in my experience it appears to), and use C-style linkage, which sounds to me like it will use the C-style calling conventions (i.e. without a 'this' parameter) but in my experience it appears to pass the 'this' parameter depending upon the conditions of the call.
For example, consider this:
main.cc:
[code]
#include "c_funcs.hh"
#include "foo.hh"
extern "C"
void start_kernel() {
Foo foo;
c_func(42);
foo.c_func_wrapper(42);
}
[/code]
c_funcs.hh:
[code]
#ifndef C_FUNCS_HH
#define C_FUNCS_HH
extern "C" {
void c_func(int);
}
#endif /* C_FUNCS_HH */
[/code]
foo.hh:
[code]
#ifndef FOO_HH
#define FOO_HH
#include "c_funcs.hh"
class Foo {
public:
void c_func_wrapper(int bar) { c_func(bar); }
};
#endif /* FOO_HH */
[/code]
The function c_func is defined in assembly, and it assumes the first parameter is in r0, as per the standard C-style calling convention. If it is invoked from start_kernel (which is also declared extern "C"), then this is in fact the case and the function executes properly. If, however, it is invoked from a class method like Foo::c_func_wrapper, it will just see the address of a Foo object in r0, and the function will behave strangely.
So, I guess I'm asking if anyone knows a compiler-independent way to specify linkage [i]and[/i] calling conventions in all cases, or if this is not possible, what the best work-around would be to wrap C and assembly functions for use in C++?
External linkage is the default.
You need to explicitly state, via static, that you want internal linkage.
Also, I don't believe there is a "standard C calling convention". The calling convention between C and C++ can also differ, but I thought that on most implementations they wouldn't. At least assuming you use the "same" compiler.
[QUOTE=aurum481;42957078]Can someone help me with Lua?
There is a map object that looks like map.tiles[x][y] = tileObj
the tileObj is an object that has a list of entites there are on that tile
for convenience I have a map.tilesList[x*y] = tileObj so I can loop through tiles easily.
There also is a list of entities, that looks like ents[z] = entObj
the entObj contains a reference to the tile it resides in.
So my question comes down to does Lua shits itself (makes an infinite loop)
Because I can make something like
map.tiles[i][j].entList[1].occupiedTile.entList[1].occupiedTile.entList[1].occupiedTile[/QUOTE]
[lua]a = {}
b = { a = a }
a.b = b[/lua]
Works fine. Is this your question? Because I didn't quite understand your problem.
[QUOTE=Behemoth_PT;42957320]Guys, I need some help here in a very basic C program.
I'm currently making a simple program that manages calls from and to a file.
The problem here is: how do I make it so that when using main(int argc, char *argv[]) I can run the program like this: ./teltel NUMBER
where NUMBER is the phone number whose info I want to print on the screen whenever I call ./teltel NUMBER.
So far this is my code:
[CODE]// code snip[/CODE]
[B]main function:[/B]
[CODE]
int main(int argc, char *argv[])
{
char numero[9];
argv[1] = numero;
if(argv[1]==numero)
printmadecalls(numero);
else
menu();
return 1;
}
[/CODE]
What I wanna do is:
if you run the program with just [I]./teltel[/I] it shows me the menu. However if I run [I]./teltel 91XXXXXXX[/I] I want him to run the function printmadecalls(91XXXXXXX) (91XXXXXXXXX being the number in argv[1].
I know that argv[1] contains the string where my number is, right? So why is it that nothing happens when I run the program ./teltel 91XXXXXXXXX and when I run just ./teltel when I call printmadecalls(number) through the menu, it works? Am I not using pointers correctly?[/QUOTE]
Try writing the code in English, too. Further more, I'd like to suggest you to use more whitespace.
I think you can just use memcpy instead of your for-loops for chamada_actual.origem and chamada_actual.destino.
You have to look out at the scanf call, which can easily overflow your buffer.
The logic in your main function is very weird. I think you want to printmadecalls if arg[b]c[/b] is 2 and otherwise print a menu.
argv[1] = numero; means, that you assign the pointer in argv[1] to the address of the numero array. You have that backwards.
Further more, you cannot copy c-strings just by using the assignment operator ("="), but you have to use str/memcpy (or a for-loop like you did in printmadecalls.
You might want to verify the inputs as well (meaning the argv[1] string, if it exists, and what you get via scanf).
Is there any way to split the cookies given to me by luasocket correctly? The website I am trying to access is using multiple set-cookie headers and luasocket just fucking concatenates them with a comma inbetween, the problem is I cant split them with a simple pattern because commas are legal in cookies and I can split a cookie in the wrong place. Has anyone got any tips on splitting this?
sample fucked up cookie (this is what luasocket shat out)
[code]
Session=216438734fa687; path=/, Test=543728a4587329; path=/, ID=deleted; expires=Fri, 23-Nov-2012 17:16:46 GMT; path=/, ID=5789475o578; expires=Wed, 22-Jan-2014 17:16:47 GMT; path=/
[/code]
also the "deleted" value is literally "deleted" I did not remove it from the string. I did change the session cookies though.
Some kind of regexes are probably able to do that, but I'm no wizard.
Basically I'd look for a comma, then see if the next token is a cookie-name and is followed by a equal-sign and if so, it's a cookie separator. Otherwise it's part of the cookie-value.
Might still fail for some weird cookie-value, not sure.
[QUOTE=ZeekyHBomb;42957742]External linkage is the default.
You need to explicitly state, via static, that you want internal linkage.
Also, I don't believe there is a "standard C calling convention". The calling convention between C and C++ can also differ, but I thought that on most implementations they wouldn't. At least assuming you use the "same" compiler.
[/QUOTE]
I think I need a crash course on how linkage works. When you specify "static" you are forced to define the implementation within the same translation unit, correct? I'm linking to a method which is not defined in the same translation unit (or even in the same language) so I have to specify it is "extern" so that the symbols can be matched up at link time. You mention "extern" is the default, but I include it because if I didn't specify "C" the name-mangling conventions would conflict and linking would fail.
Also, the C++ calling convention (in the case of g++) appears to be passing 'this' in the first register (r0 in armv6) with the second parameter in r1. For "standard" C calling I would expect r0 to contain the first parameter because there is no hidden 'this' parameter to pass. My problem is I don't know how to suppress the passing of 'this' when the function is defined to be extern "C". It appears 'this' is passed if the calling function is a method, regardless of the extern modifier. This is a problem in terms of kernel development, where I need to understand and control calling conventions between C++ and ASM. I know the assembly is inherently non-portable, but I would hope this portability is mostly in terms of architecture, not so much compiler (although I'm beginning to think I'm wrong on this point).
tl;dr I'm not sure how to consistently interface C++ code with ASM code while knowing for certain that a given calling convention will be used (since I have to write the ASM by hand, which requires only one convention be used).
The extern keyword is not to specify external linkage, but to specify functions from another language.
Well, when applied to functions anyway. It has different meanings in other contexts.
So with extern "C" you specify that the function is from the language C. If it is written in assembly, but abides by the rules of C functions, that's fine too of course.
The calling convention does not only depend on the compiler, but also the platform you're on.
[QUOTE=Rayjingstorm;42958130]I would hope this portability is mostly in terms of architecture, not so much compiler (although I'm beginning to think I'm wrong on this point).[/quote]
Well, you mentioned ARM. For ARM a calling convention is specified, so it won't depend on the compiler (well, as long as it abides by the ARM spec :P), but for x86 for example there are several ways this is done. I think you can instruct the compiler to use a certain convention though.
Looking at your code example though, I would expect this to behave as expected (e.g. on ARM there should be 42 in r0 for both calls). You could perhaps examine the assembly g++ generates.
[QUOTE=ZeekyHBomb;42958419]The extern keyword is not to specify external linkage, but to specify functions from another language.[/QUOTE]
extern always specifies external linkage. Function declarations are by default external, and variables internal. extern "C" specifies external C linkage.
[QUOTE=Rayjingstorm;42957396]If, however, it is invoked from a class method like Foo::c_func_wrapper, it will just see the address of a Foo object in r0, and the function will behave strangely.[/QUOTE]
It should not, the standard's clear about this.
Sorry for it being in another language, it's for an assignment.
However I solved it. Problem was: I wasn't saving the content of argv[1] in numero so nothing happened.
[QUOTE=ZeekyHBomb;42958419]The extern keyword is not to specify external linkage, but to specify functions from another language.
Well, when applied to functions anyway. It has different meanings in other contexts.
So with extern "C" you specify that the function is from the language C. If it is written in assembly, but abides by the rules of C functions, that's fine too of course.
The calling convention does not only depend on the compiler, but also the platform you're on.
Well, you mentioned ARM. For ARM a calling convention is specified, so it won't depend on the compiler (well, as long as it abides by the ARM spec :P), but for x86 for example there are several ways this is done. I think you can instruct the compiler to use a certain convention though.
Looking at your code example though, I would expect this to behave as expected (e.g. on ARM there should be 42 in r0 for both calls). You could perhaps examine the assembly g++ generates.[/QUOTE]
As I understand it, the ARMv6 ABI allocates r1-r4 as arguments, r1-r2 as return value, and everything else as preserved general-purpose. Also, the stack should grow descending, so for example `sub sp, #4` should "grow" the stack by 4 bytes (or one word).
I've been peeking at the ASM generated, but I'm not sure I understand it entirely; here are the relevant sections
[code]
00008040 <delay>:
8040: e2400001 sub r0, r0, #1
8044: e3500000 cmp r0, #0
8048: cafffffc bgt 8040 <delay>
804c: e1a0f00e mov pc, lr
…
0000808c <_ZN3LED4waitEj>:
808c: e92d4800 push {fp, lr}
8090: e28db004 add fp, sp, #4
8094: e24dd008 sub sp, sp, #8
8098: e50b0008 str r0, [fp, #-8]
809c: e50b100c str r1, [fp, #-12]
80a0: e51b000c ldr r0, [fp, #-12]
80a4: ebffffe5 bl 8040 <delay>
80a8: e24bd004 sub sp, fp, #4
80ac: e8bd8800 pop {fp, pc}
000080b0 <start_kernel>:
80b0: e92d4800 push {fp, lr}
80b4: e28db004 add fp, sp, #4
80b8: e24dd008 sub sp, sp, #8
80bc: e3a0083f mov r0, #4128768 ; 0x3f0000
80c0: ebffffde bl 8040 <delay>
80c4: e24b3008 sub r3, fp, #8
80c8: e1a00003 mov r0, r3
80cc: e3a0183f mov r1, #4128768 ; 0x3f0000
80d0: ebffffed bl 808c <_ZN3LED4waitEj>
80d4: eafffff8 b 80bc <start_kernel+0xc>
[/code]
Notice that in `start_kernel` the call directly to `delay` only uses r0, and just loads a literal into it, whereas the call to the `LED::wait` method has to use r0 to hold an address to the LED object on the stack, and so uses `r1` to hold the literal which goes to `LED::wait`.
As for the guts of `LED::wait` I'm still not sure, here it is with my comments:
[code]
0000808c <_ZN3LED4waitEj>:
@ Calling function expects frame pointer to be preserved, and we need to remember where to return to
808c: e92d4800 push {fp, lr}
@ Setup frame pointer
8090: e28db004 add fp, sp, #4
@ And stack pointer
8094: e24dd008 sub sp, sp, #8
@ Load r0 with third word indexed from fp (first argument to method?)
8098: e50b0008 str r0, [fp, #-8]
@ Load r1 with fourth word indexed from fp (second argument to method?)
809c: e50b100c str r1, [fp, #-12]
@ Load r0 with the value at the address in r1 (?)
80a0: e51b000c ldr r0, [fp, #-12]
@ Call the delay, which expects argument in r0
80a4: ebffffe5 bl 8040 <delay>
@ Restore the stack pointer (?)
80a8: e24bd004 sub sp, fp, #4
@ Restore calling functions frame pointer and jump to caller
80ac: e8bd8800 pop {fp, pc}
[/code]
As I said I'm still confused about what exactly is going on and any help would be greatly appreciated :V:
[editline]23rd November 2013[/editline]
Also, if it would help, I can throw this up on github if anyone is willing to review it (it's already tracked in git I just work off a local server, which is incidentally running on another RaspberryPi :v:)
Sorry, you need to Log In to post a reply to this thread.