summaryrefslogtreecommitdiff
path: root/ws2a/bugsdata.c
blob: d04560e9ab2acf200dc3971bf1e0595b84885e09 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>

int main(){
  printf("%s%c%c\n",
  "Content-Type:text/html;charset=iso-8859-1",13,10);
  FILE* lastfilenum;
  lastfilenum = fopen("../ws2a/bugs/lastbug","r");
  if(lastfilenum == NULL){
    printf("Error reteriveing bugs, contact the admin!");
    return 1;
  }
  long long last = 0;
  fscanf(lastfilenum,"%lld",&last);
  fclose(lastfilenum);
  long long end = last-20;

  while(last > end && last > 0){
    char filestring[64] = "../ws2a/bugs/";
    char filename[10];
    sprintf(filename,"%lld",last);
    strcat(filestring,filename);
    FILE* thisbug;
    thisbug = fopen(filestring,"r");
    if(thisbug == NULL){
      printf("Error opening bug:%s\n",filestring);
      printf("<br/>");
      last--;
      continue;
    }
    printf("<tr>");
    printbug(thisbug);
    fclose(thisbug);
    printf("</tr>");
    last--;
  }

  return 0;
}
/*Prints bugs, format:
  Submitter\n
  Date_submitted\n
  Short Description\n
  Status<Unassigned, Assigned, Closed>\n
*/
void printbug(FILE* f){
  printf("<td>");
  int part = 0;
  while(!feof(f)){
    char c = fgetc(f);
    if(c == '\n'){
      part++;
      printf("</td>");
      if(part != 2){
        printf("<td>");
      }
    }else if(c == "&"){
      printf("&amp;");
    }else if(c == "\""){
      printf("&quot;");
    }else if(c == "'"){
      printf("&#39;");
    }else if(c == "<"){
      printf("&lt;");
    }else if(c == ">"){
      printf("&gt;");
    }else if(c == "\\"){
      printf("&#x2F;");
    else{
      putchar(c);
    }
  }
}

/*
function htmlEscape(str) {
    return String(str)
        .replace(/&/g, '&amp;')
        .replace(/"/g, '&quot;')
        .replace(/'/g, '&#39;')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;')
        .replace(/\//g, '&#x2F;');
}
*/