Skip to content

Commit

Permalink
Merge pull request #8 from Rubear/master
Browse files Browse the repository at this point in the history
The segfault bridge is falling down, falling down, falling down.
  • Loading branch information
Cotix committed Jul 13, 2013
2 parents 220cec9 + 408579f commit cab5e00
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
29 changes: 21 additions & 8 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ void buildScreen(char **text, int selected, int size)
void showSubreddit(char *subreddit)
{
struct post threads[25];//Our array with reddit threads
redditGetSubreddit(subreddit,"hot",threads);
int *postCount;
postCount = malloc(sizeof(int));
redditGetSubreddit(subreddit,"hot",threads,postCount);
//Just some ncurses testing
int i;
char *text[25]; //Text buffer for each line
for(i = 0; i != 25; ++i)
int displayCount = 25;
if (*postCount < 25) {
displayCount=*postCount;
}
printw("%i\n", displayCount);
char *text[displayCount]; //Text buffer for each line
for(i = 0; i != displayCount; ++i)
{
if(threads[i].id == 0)
continue;
Expand All @@ -52,7 +59,7 @@ void showSubreddit(char *subreddit)
}

int selected = 0; //Lets select the first post!
buildScreen(text,selected,25); //And print it!
buildScreen(text,selected,displayCount); //And print it!
int c;
struct comments cList[500];
while(c = wgetch(stdscr))
Expand All @@ -73,11 +80,17 @@ void showSubreddit(char *subreddit)

case '\n':
refresh();
redditGetThread(threads[selected].id,cList);
int *commentCount;
commentCount = malloc(sizeof(int));
redditGetThread(threads[selected].id,cList,commentCount);
int cdisplayCount = 25;
if (*commentCount < 25) {
cdisplayCount=*postCount;
}
// Basically a copy of the code above
int u;
char *ctext[25]; //Text buffer for each line
for(u = 0; u != 25; ++u)
char *ctext[cdisplayCount]; //Text buffer for each line
for(u = 0; u != cdisplayCount; ++u)
{
//printw("starting");
if(cList[u].id == 0 || cList[u].text == NULL || cList[u].id == NULL || cList[u].author == NULL)
Expand All @@ -100,7 +113,7 @@ void showSubreddit(char *subreddit)
}
wgetch(stdscr);
}
buildScreen(text,selected,25); //Print the updates!!
buildScreen(text,selected,displayCount); //Print the updates!!
}

}
Expand Down
10 changes: 6 additions & 4 deletions reddit.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ char* prepend(char *pre, char *str)
return newString;
}

void redditGetSubreddit(char * sub, char * sorting, struct post * postList)
void redditGetSubreddit(char * sub, char * sorting, struct post * postList, int * postCount)
{
CURL *curl_handle;
struct MemoryStruct chunk;
Expand Down Expand Up @@ -74,8 +74,9 @@ void redditGetSubreddit(char * sub, char * sorting, struct post * postList)
r = jsmn_parse(&p, js, t, 25000);
int i =0;
char buffer[2048];

int atPost = 0;

for(i = 0; i < 25000; ++i)
{
if(t[i].start == -1) continue;
Expand Down Expand Up @@ -139,11 +140,11 @@ void redditGetSubreddit(char * sub, char * sorting, struct post * postList)
}

}
*postCount = atPost;
if(chunk.memory)
free(chunk.memory);

}
void redditGetThread(char * postid, struct comments * commentList)
void redditGetThread(char * postid, struct comments * commentList, int * commentCount)
{
CURL *curl_handle;
struct MemoryStruct chunk;
Expand Down Expand Up @@ -235,6 +236,7 @@ void redditGetThread(char * postid, struct comments * commentList)
free(tmp);
}
}
*commentCount = atPost;
if(chunk.memory)
free(chunk.memory);

Expand Down
4 changes: 2 additions & 2 deletions reddit.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ struct comments {
char * votes;
};

void redditGetThread(char * postid, struct comments * commentList);
void redditGetSubreddit(char * sub, char * sorting, struct post * postList);
void redditGetThread(char * postid, struct comments * commentList, int * commentCount);
void redditGetSubreddit(char * sub, char * sorting, struct post * postList, int * postCount);
char *ask_for_subreddit();
void showSubreddit(char *subreddit);
void cleanup();
Expand Down

0 comments on commit cab5e00

Please sign in to comment.