⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bprint

📁 c语言编译器
💻
📖 第 1 页 / 共 2 页
字号:
        assert(p);        for (q = p->funcs; q && name != q->name; q = q->link)                ;        if (!q) {                struct func **r;                NEW(q, PERM);                q->name = name;                q->count.x = x;                q->count.y = y;                q->count.count = 0;                q->callers = 0;                for (r = &p->funcs; *r && compare(&q->count, &(*r)->count) > 0; r = &(*r)->link)                        ;                q->link = *r;                *r = q;        }        q->count.count += count;        return q;}/* apoint - append execution point i to file's data */ static void apoint(int i, char *file, int x, int y, int count) {        struct file *p = findfile(file);        assert(p);        if (i >= p->size) {                int j;                if (p->size == 0) {                        p->size = i >= 200 ? 2*i : 200;                        p->counts = newarray(p->size, sizeof *p->counts, PERM);                } else {                        struct count *new;                        p->size = 2*i;                        new = newarray(p->size, sizeof *new, PERM);                        for (j = 0; j < p->count; j++)                                new[j] = p->counts[j];                        p->counts = new;                }                for (j = p->count; j < p->size; j++) {                        static struct count z;                        p->counts[j] = z;                }        }        p->counts[i].x = x;        p->counts[i].y = y;        p->counts[i].count += count;        if (i >= p->count)                p->count = i + 1;}/* findcount - return count associated with (file,x,y) or -1 */int findcount(char *file, int x, int y) {        static struct file *cursor;        if (cursor == 0 || cursor->name != file)                cursor = findfile(file);        if (cursor) {                int l, u;                struct count *c = cursor->counts;                for (l = 0, u = cursor->count - 1; l <= u; ) {                        int k = (l + u)/2;                        if (c[k].y > y || c[k].y == y && c[k].x > x)                                u = k - 1;                        else if (c[k].y < y || c[k].y == y && c[k].x < x)                                l = k + 1;                        else                                return c[k].count;                }        }        return -1;}/* findfunc - return count associated with function name in file or -1 */int findfunc(char *name, char *file) {        static struct file *cursor;        if (cursor == 0 || cursor->name != file)                cursor = findfile(file);        if (cursor) {                struct func *p;                for (p = cursor->funcs; p; p = p->link)                        if (p->name == name)                                return p->count.count;        }        return -1;}/* getd - read a nonnegative number */static int getd(void) {        int c, n = 0;        while ((c = getc(fp)) != EOF && (c == ' ' || c == '\n' || c == '\t'))                ;        if (c >= '0' && c <= '9') {                do                        n = 10*n + (c - '0');                while ((c = getc(fp)) >= '0' && c <= '9');                return n;        }        return -1;}/* getstr - read a string */static char *getstr(void) {        int c;        char buf[MAXTOKEN], *s = buf;        while ((c = getc(fp)) != EOF && c != ' ' && c != '\n' && c != '\t')                if (s - buf < (int)sizeof buf - 2)                        *s++ = c;        *s = 0;        return s == buf ? (char *)0 : string(buf);}/* gather - read prof.out data from fd */static int gather(void) {        int i, nfiles, nfuncs, npoints;        char *files[64];        if ((nfiles = getd()) < 0)                return 0;        assert(nfiles < NELEMS(files));        for (i = 0; i < nfiles; i++) {                if ((files[i] = getstr()) == 0)                        return -1;                if (!findfile(files[i])) {                        struct file *new;                        NEW(new, PERM);                        new->name = files[i];                        new->size = new->count = 0;                        new->counts = 0;                        new->funcs = 0;                        new->link = filelist;                        filelist = new;                }        }        if ((nfuncs = getd()) < 0)                return -1;        for (i = 0; i < nfuncs; i++) {                struct func *q;                char *name, *file;                int f, x, y, count;                if ((name = getstr()) == 0 || (f = getd()) <= 0                || (x = getd()) < 0 || (y = getd()) < 0 || (count = getd()) < 0)                        return -1;                q = afunction(name, files[f-1], x, y, count);                if ((name = getstr()) == 0 || (file = getstr()) == 0                || (x = getd()) < 0 || (y = getd()) < 0)                        return -1;                if (*name != '?')                        acaller(name, file, x, y, count, q);        }        if ((npoints = getd()) < 0)                return -1;        for (i = 0; i < npoints; i++) {                int f, x, y, count;                if ((f = getd()) < 0 || (x = getd()) < 0 || (y = getd()) < 0                || (count = getd()) < 0)                        return -1;                if (f)                        apoint(i, files[f-1], x, y, count);        }        return 1;}/* process - read prof.out data from file */int process(char *file) {        int more;        if ((fp = fopen(file, "r")) != NULL) {                struct file *p;                while ((more = gather()) > 0)                        ;                fclose(fp);                if (more < 0)                        return more;                for (p = filelist; p; p = p->link)                        qsort(p->counts, p->count, sizeof *p->counts,                                (int (*)(const void *, const void *))                                compare);                                return 1;        }        return 0;}int main(int argc, char *argv[]) {        int i;        struct file *p;        void (*f)(struct file *, int) = printfile;        progname = argv[0];        if ((i = process("prof.out")) <= 0) {                fprintf(stderr, "%s: can't %s `%s'\n", progname,                        i == 0 ? "open" : "interpret", "prof.out");                exit(1);        }        for (i = 1; i < argc && *argv[i] == '-'; i++)                if (strcmp(argv[i], "-c") == 0) {                        emitdata("prof.out");                         exit(0);                } else if (strcmp(argv[i], "-b") == 0)                        f = printfile;                else if (strcmp(argv[i], "-f") == 0) {                        fcount++;                        f = printfuncs;                } else if (strcmp(argv[i], "-n") == 0)                        number++;                else if (strncmp(argv[i], "-I", 2) == 0) {                        int j;                        for (j = 0; j < NDIRS && dirs[j]; j++)                                ;                        if (j < NDIRS)                                dirs[j] = &argv[i][2];                        else                                fprintf(stderr, "%s: too many -I options\n", progname);                } else {                        fprintf(stderr, "usage: %s [ -c | -b | -n | -f | -Idir... ] [ file... ]\n", progname);                        exit(1);                }        for (p = filelist; p; p = p->link)                qsort(p->counts, p->count, sizeof *p->counts,                        (int (*)(const void *, const void *))compare);        if (i < argc) {                int nf = i < argc - 1 ? 1 : 0;                for ( ; i < argc; i++, nf ? nf++ : 0)                        if (p = findfile(string(argv[i])))                                (*f)(p, nf);                        else                                fprintf(stderr, "%s: no data for `%s'\n", progname, argv[i]);        } else {                int nf = filelist && filelist->link ? 1 : 0;                for (p = filelist; p; p = p->link, nf ? nf++ : 0)                        (*f)(p, nf);        }        return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -