SHARE
TWEET

MiniBasic script driver C++ conversion

tangent Jul 19th, 2014 191 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --- script-original.c   2014-07-19 22:36:49.000000000 -0600
  2. +++ script.cpp  2014-07-19 22:47:53.000000000 -0600
  3. @@ -4,17 +4,19 @@
  4.    Leeds University
  5.  */
  6.  
  7. -#include <stdio.h>
  8. +#include "basic.c"
  9. +
  10. +#include <iostream>
  11.  #include <stdlib.h>
  12.  
  13. -#include "basic.h"
  14. +using namespace std;
  15.  
  16.  char *loadfile(char *path);
  17.  
  18.  /*
  19.    here is a simple script to play with
  20.  */
  21. -char *script =
  22. +const char *script =
  23.  "10 REM Test Script\n"
  24.  "20 REM Tests the Interpreter\n"
  25.  "30 REM By Malcolm Mclean\n"
  26. @@ -28,10 +30,10 @@
  27.  
  28.  void usage(void)
  29.  {
  30. -  printf("MiniBasic: a BASIC interpreter\n");
  31. -  printf("usage:\n");
  32. -  printf("Basic <script>\n");
  33. -  printf("See documentation for BASIC syntax.\n");
  34. +  cout << "MiniBasic: a BASIC interpreter\n";
  35. +  cout << "usage:\n";
  36. +  cout << "Basic <script>\n";
  37. +  cout << "See documentation for BASIC syntax.\n";
  38.    exit(EXIT_FAILURE);
  39.  }
  40.  
  41. @@ -77,7 +79,7 @@
  42.    fp = fopen(path, "r");
  43.    if(!fp)
  44.    {
  45. -    printf("Can't open %s\n", path);
  46. +    cout << "Can't open " << path << "\n";
  47.         return 0;
  48.    }
  49.  
  50. @@ -85,10 +87,10 @@
  51.    size = ftell(fp);
  52.    fseek(fp, 0, SEEK_SET);
  53.  
  54. -  answer = malloc(size + 100);
  55. +  answer = (char*)malloc(size + 100);
  56.    if(!answer)
  57.    {
  58. -    printf("Out of memory\n");
  59. +    cout << "Out of memory\n";
  60.      fclose(fp);
  61.         return 0;
  62.    }
  63. @@ -101,4 +103,4 @@
  64.    fclose(fp);
  65.  
  66.    return answer;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top