Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main(int argc, char *argv[]) {
- FILE* fp;
- int N = 50;
- fp = freopen("error", "a+b", stderr);
- char * program_name = argv[1];
- pid_t pid = fork();
- if (pid == -1) {
- return 1;
- }
- if (pid > 0) {
- int status;
- waitpid(pid, &status, 0);
- char s[N];
- int ans_err = 0;
- int ans_warn = 0;
- int err = 0;
- int warn = 0;
- while (fgets(s, N, fp) != NULL) {
- char* inf = strstr(s, ": error:");
- if (inf != NULL) {
- while (*inf != ':') {
- inf--;
- }
- inf--;
- int temp = 1;
- int cur = 0;
- while (*inf != ':') {
- cur += (*inf - '0') * temp;
- temp = temp * 10;
- inf--;
- }
- if (cur != err) {
- ans_err++;
- }
- }
- inf = strstr(s, ": warning:");
- if (inf != NULL) {
- while (*inf != ':') {
- inf--;
- }
- inf--;
- int temp = 1;
- int cur = 0;
- while(*inf != ':') {
- cur += (*inf - '0') * temp;
- temp = temp * 10;
- inf--;
- }
- if (cur != warn) {
- ans_warn++;
- }
- }
- }
- printf("%d %d", ans_err, ans_warn);
- return 0;
- }
- execlp("gcc", "gcc", program_name, NULL);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement