From c2a74cc20ebaa9898052ab758821ccfc7c3ee1f4 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Thu, 2 Jun 2016 16:54:20 -0400 Subject: Initial commit --- src/searchbugs.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/searchbugs.c (limited to 'src/searchbugs.c') diff --git a/src/searchbugs.c b/src/searchbugs.c new file mode 100644 index 0000000..da15c99 --- /dev/null +++ b/src/searchbugs.c @@ -0,0 +1,69 @@ +#include +#include +#include "shared.h" +#include "config.h" + +int main(){ + char* data = getenv("QUERY_STRING"); + //char data[] = "user=Apickx"; + char user[30]; + sscanf(data,"user=%29s",user); + char* duser = replaceHTML(user); + char lastbugfilepath[100]; + sprintf(lastbugfilepath,"%s/bugs/lastbug",REL_BINPATH); + FILE* lastbugfile; + lastbugfile = fopen(lastbugfilepath,"r"); + if(lastbugfile == NULL){ + printf("%s%c%c\n","Content-Type:text/html;charset=iso-8859-1",13,10); + printf("Unable to open recent file"); + exit(1); + } + unsigned long long lastbugnum; + fscanf(lastbugfile,"%llu",&lastbugnum); + fclose(lastbugfile); + unsigned long long thisbugnum = lastbugnum; + printf("%s%c%c\n","Content-Type:text/html;charset=iso-8859-1",13,10); + while(thisbugnum > 0){ + char thisbugpath[100]; + sprintf(thisbugpath,"%s/bugs/%llu",REL_BINPATH,thisbugnum); + FILE* thisbugfile; + thisbugfile = fopen(thisbugpath,"r"); + int bugfileline = 1; + while(bugfileline != 5){ + char c = fgetc(thisbugfile); + if(c == '\n'){ + bugfileline++; + } + } + char assignee[64]; + int type; + fscanf(thisbugfile,"%d:%s\n",&type,assignee); + if(type == 1){ + if(strcmp(assignee,duser) == 0){ + //If this is a file we need to print, back up and print it + fseek(thisbugfile,0,SEEK_SET); + printbug(thisbugfile); + } + } + fclose(thisbugfile); + thisbugnum--; + } +} + +void printbug(FILE* f){ + + int line = 0; + char tchar = ' '; + while((tchar = fgetc(f)) && tchar != EOF){ + if(tchar == '\n') + line++; + if(line > 4) + break; + putchar(tchar); + } + + unsigned int comments = 0; + while (EOF != (fscanf(f,"%*[^\n]"), fscanf(f,"%*c"))) + ++comments; + printf("\n%u\n",(comments-1)/4); +} -- cgit v1.2.3-70-g09d2