File: manripper.cpp

package info (click to toggle)
yacas 1.3.6-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 7,176 kB
  • ctags: 3,520
  • sloc: cpp: 13,960; java: 12,602; sh: 11,401; makefile: 552; perl: 517; ansic: 381
file content (133 lines) | stat: -rw-r--r-- 4,331 bytes parent folder | download
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <stdlib.h>
#include <cctype>
#include <cstring>
#include <iostream>
#include <map>
#include <string>

typedef std::map<std::string, std::string> CmdEntries;


CmdEntries commands;
CmdEntries files;

int fileline = 0;

void GetBf(char* buf, int size, FILE*f)
{
    if (!fgets(buf, 2048, f)) {
        *buf = '\0';
        if (!feof(f)) {
            std::cerr << "Error reading, bailing out.\n";
            exit(-1);
        }
    }

    fileline++;
    const std::size_t n = std::strlen(buf);
    if (n && buf[n - 1] == '\n')
        buf[n] = '\0';
    char* ptr = buf;
    while (*ptr != '\0') {
        if (*ptr == ':') *ptr = ' ';
        ptr++;
    }
}

void ProcessFile(const char* fname)
{
    std::cerr << "\tFILE " << fname << "\n";
    FILE*f = fopen(fname, "r");
    if (!f) return;
    int prevline = fileline;
    fileline = 0;
    char buf[2048];
    while (!feof(f)) {
        GetBf(buf, 2048, f);
        const std::size_t n = std::strlen(buf);
        if (n && buf[n - 1] == '\n')
            buf[n - 1] = '\0';

        //*CMD Sin, Cos, Tan --- trigonometric functions
        if (!strncmp(buf, "*CMD", 4)) {
            char* description = buf;
            while (*description != '\0' && *description != '-') description++;
            if (*description == '\0') continue;
            while (*description == '-') description++;
            while (*description == ' ') description++;

            char* command = &buf[5];
            for (;;) {
                char* end = command;
                while (*end != ',' && *end != ' ') end++;
                char cmd[256];
                memset(cmd, 0, 255);
                memcpy(cmd, command, end - command);
                //        cmd[end-command] = '\0';

                commands[cmd] = description;
                files[cmd] = fname;

                if (*end == ' ') break;
                end++;
                if (*end == ' ') end++;
                command = end;
            }
        } else if (!strncmp(buf, "*CALL", 5)) {
            while (buf[0] != '\t')
                GetBf(buf, 2048, f);
            char cmd[256];
            while (buf[0] == '\t') {
                if (buf[strlen(buf) - 1] == '\n') buf[strlen(buf) - 1] = '\0';
                char* ptr = &buf[1];
                while (std::isalnum(*ptr) || *ptr == '\'') ptr++;
                memset(cmd, 0, 255);
                memcpy(cmd, &buf[1], ptr - (&buf[1]));

                if (cmd[0] && strncmp(&buf[1], "In>", 3) && strncmp(&buf[1], "Out>", 4) && isupper(buf[1])) {
                    CmdEntries::const_iterator iter = commands.find(cmd);
                    const char* desc = "";
                    if (iter != commands.end())
                        desc = iter->second.c_str();
                    else
                        std::cerr << "WARNING: function " << cmd << " does not have a short description (" << fname << ":" << fileline << ")\n";

                    std::cout << ":" << cmd << ":" << &buf[1] << ":" << desc << ":\n";
                    commands[cmd] = "";
                }
                GetBf(buf, 2048, f);
                while (buf[0] == '\0') GetBf(buf, 2048, f);
            }
            if (buf[0] == ' ')
                std::cerr << "WARNING: spaces might have been used instead of tabs (" << cmd << ", " << fname << ":" << fileline << ")\n";
        } else if (!strncmp(buf, "*INCLUDE", 8)) {
            const char* fn = &buf[8];
            while (*fn == ' ')
                ++fn;
            std::string fullname = fn;
            fullname += ".txt";
            ProcessFile(fullname.c_str());

        }
    }
    fclose(f);
    fileline = prevline;
}

int main(int argc, char** argv)
{
    for (int i = 1; i < argc; ++i) {
        std::cerr << "BOOK " << argv[i] << "\n";
        ProcessFile(argv[i]);
    }

    for (CmdEntries::const_iterator iter = commands.begin(); iter != commands.end(); ++iter) {
        if (iter->second.c_str()[0]) {
            CmdEntries::const_iterator fiter = files.find(iter->first.c_str());
            if (fiter != files.end())
                std::cerr << "WARNING: no call sequences for function " << iter->first << " (" << fiter->second << ")\n";
            else
                std::cerr << "WARNING: no call sequences for function " << iter->first << "\n";
        }
    }
}