aboutsummaryrefslogtreecommitdiff
path: root/src/searchbugs.c
blob: da15c994b779ced7b5b14b6143da3b8bd134e635 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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);
}