diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2016-06-02 16:54:20 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2016-06-02 16:54:20 -0400 |
| commit | c2a74cc20ebaa9898052ab758821ccfc7c3ee1f4 (patch) | |
| tree | 9a9d90471dd6241da885950c5b52416bba28619f /src/searchbugs.c | |
| download | sober-c2a74cc20ebaa9898052ab758821ccfc7c3ee1f4.tar.gz sober-c2a74cc20ebaa9898052ab758821ccfc7c3ee1f4.tar.bz2 sober-c2a74cc20ebaa9898052ab758821ccfc7c3ee1f4.zip | |
Initial commit
Diffstat (limited to 'src/searchbugs.c')
| -rw-r--r-- | src/searchbugs.c | 69 |
1 files changed, 69 insertions, 0 deletions
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 <stdio.h> +#include <stdlib.h> +#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); +} |
