Advertisement
Mikhail-Podbolotov

Untitled

May 8th, 2024
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. #include "library.h"
  5. int main()
  6. {
  7.     ifstream input("input.txt");
  8.     ofstream nonRecursiveFile("non_recursive.txt");
  9.     ofstream recursiveFile("recursive.txt");
  10.     List functionsList;
  11.     bool inFunctionName = false;
  12.     string functionName;
  13.     bool isRecursive = false;
  14.     bool inFunction = false;
  15.     int ForWhileFlag = 0;
  16.     while (!input.eof()) {
  17.         string line;
  18.         getline(input, line);
  19.         if (!inFunction) {
  20.             for (char c : line) {
  21.                 if (inFunctionName && (c == ' ' or c == ':') && line.find("(") != string::npos) {
  22.                     functionName="";
  23.                 }
  24.                 if (c == '(') {
  25.                     inFunctionName = false;
  26.                 }
  27.                 if (c == ';' or c=='.' or c=='\'' and !inFunctionName) {
  28.                     functionName.clear();
  29.                     inFunctionName = false;
  30.                 }
  31.                 if (inFunctionName and c!='{' and c!=' ' and c!=':') {
  32.                     functionName += c;
  33.                 }
  34.                 if (!inFunctionName && (c == ' ' or c == ':') && line.find("(") != string::npos && functionName.empty()) {
  35.                     inFunctionName = true;
  36.                 }
  37.  
  38.                 if (!functionName.empty() and c == '{' or functionsList.InList(functionName)) {
  39.                     inFunction = true;
  40.                 }
  41.             }
  42.         }
  43.         else  {
  44.             // без костыля здесь не обойтись :)
  45.             string previosline;
  46.             //cout << line << "!!!" << functionName << " " << line.find(functionName) << endl;
  47.             while (line != "}") {
  48.                 if (line.find(functionName) != string::npos) isRecursive = true;
  49.                 getline(input, line);
  50.             }
  51.             if (!functionName.empty()) {
  52.                 functionsList.addFunction(functionName, isRecursive);
  53.             }
  54.             if (functionsList.InList(functionName)) {
  55.                 inFunctionName = false;
  56.                 functionName.clear();
  57.                 isRecursive = false;
  58.                 inFunction = false;
  59.             }
  60.  
  61.         }
  62.     }
  63.     functionsList.PrintR(recursiveFile);
  64.     functionsList.PrintNR(nonRecursiveFile);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement