- 
                Notifications
    You must be signed in to change notification settings 
- Fork 36
Fix extract_filename function #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
            anutosh491
  merged 1 commit into
  compiler-research:main
from
anutosh491:fix_extract_filename
  
      
      
   
  Jan 18, 2024 
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /************************************************************************************ | ||
| * Copyright (c) 2023, xeus-cpp contributors * | ||
| * * | ||
| * Distributed under the terms of the BSD 3-Clause License. * | ||
| * * | ||
| * The full license is in the file LICENSE, distributed with this software. * | ||
| ************************************************************************************/ | ||
|  | ||
| #ifndef XEUS_CPP_UTILS_HPP | ||
| #define XEUS_CPP_UTILS_HPP | ||
|  | ||
| #include "xinterpreter.hpp" | ||
|  | ||
| using interpreter_ptr = std::unique_ptr<xcpp::interpreter>; | ||
|  | ||
| namespace xcpp | ||
| { | ||
|  | ||
| #ifdef __GNUC__ | ||
| XEUS_CPP_API | ||
| void handler(int sig); | ||
| #endif | ||
|  | ||
| XEUS_CPP_API | ||
| void stop_handler(int sig); | ||
|  | ||
| XEUS_CPP_API | ||
| bool should_print_version(int argc, char* argv[]); | ||
|  | ||
| XEUS_CPP_API | ||
| std::string extract_filename(int &argc, char* argv[]); | ||
|  | ||
| XEUS_CPP_API | ||
| interpreter_ptr build_interpreter(int argc, char** argv); | ||
| } | ||
|  | ||
| #endif | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /************************************************************************************ | ||
| * Copyright (c) 2023, xeus-cpp contributors * | ||
| * * | ||
| * Distributed under the terms of the BSD 3-Clause License. * | ||
| * * | ||
| * The full license is in the file LICENSE, distributed with this software. * | ||
| ************************************************************************************/ | ||
|  | ||
| #include <cstddef> | ||
| #include <memory> | ||
| #include <string> | ||
| #include <utility> | ||
|  | ||
| #include <signal.h> | ||
|  | ||
| #ifdef __GNUC__ | ||
| #include <stdio.h> | ||
| #ifndef XEUS_CPP_EMSCRIPTEN_WASM_BUILD | ||
| #include <execinfo.h> | ||
| #endif | ||
| #include <stdlib.h> | ||
| #include <unistd.h> | ||
| #endif | ||
|  | ||
|  | ||
| #include "xeus-cpp/xutils.hpp" | ||
| #include "xeus-cpp/xinterpreter.hpp" | ||
|  | ||
| namespace xcpp | ||
| { | ||
|  | ||
| #if defined(__GNUC__) && !defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD) | ||
| void handler(int sig) | ||
| { | ||
| void* array[10]; | ||
|  | ||
| // get void*'s for all entries on the stack | ||
| std::size_t size = backtrace(array, 10); | ||
|  | ||
| // print out all the frames to stderr | ||
| fprintf(stderr, "Error: signal %d:\n", sig); | ||
| backtrace_symbols_fd(array, size, STDERR_FILENO); | ||
| exit(1); | ||
| } | ||
| #endif | ||
|  | ||
| void stop_handler(int /*sig*/) | ||
| { | ||
| exit(0); | ||
| } | ||
|  | ||
| bool should_print_version(int argc, char* argv[]) | ||
| { | ||
| for (int i = 0; i < argc; ++i) | ||
| { | ||
| if (std::string(argv[i]) == "--version") | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|  | ||
| std::string extract_filename(int &argc, char* argv[]) | ||
| { | ||
| std::string res = ""; | ||
| for (int i = 0; i < argc; ++i) | ||
| { | ||
| if ((std::string(argv[i]) == "-f") && (i + 1 < argc)) | ||
| { | ||
| res = argv[i + 1]; | ||
| for (int j = i; j < argc - 2; ++j) | ||
| { | ||
| argv[j] = argv[j + 2]; | ||
| } | ||
| argc -= 2; | ||
| break; | ||
| } | ||
| } | ||
| return res; | ||
| } | ||
|  | ||
| interpreter_ptr build_interpreter(int argc, char** argv) | ||
| { | ||
| int interpreter_argc = argc; // + 1; | ||
| const char** interpreter_argv = new const char*[interpreter_argc]; | ||
| interpreter_argv[0] = "xeus-cpp"; | ||
| // Copy all arguments in the new array excepting the process name. | ||
| for (int i = 1; i < argc; i++) | ||
| { | ||
| interpreter_argv[i] = argv[i]; | ||
| } | ||
|  | ||
| interpreter_ptr interp_ptr = std::make_unique<interpreter>(interpreter_argc, interpreter_argv); | ||
| delete[] interpreter_argv; | ||
| return interp_ptr; | ||
| } | ||
|  | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.