Advertisement
froeling

local MicroSQL D Edition

Jul 5th, 2023
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.63 KB | None | 0 0
  1. import std.stdio;
  2. import std.file;
  3. import std.string;
  4.  
  5. void wrFile(byte command_code) {
  6.     string file_name;
  7.     string file_string;
  8.     string file_buffer;
  9.  
  10.     if (command_code == 1) {
  11.         write("File name > ");
  12.         file_name = readln().strip();
  13.  
  14.         if (file_name[$ - 3] != 't' && file_name[$ - 1] != 't') {
  15.             file_name = file_name ~ ".txt";
  16.         }
  17.  
  18.         write("File string > ");
  19.         file_string = readln().strip();
  20.  
  21.         File file1 = File(file_name, "w");
  22.             file1.write(file_string);
  23.         file1.close();
  24.     }
  25.  
  26.     if (command_code == 2) {
  27.         write("File name > ");
  28.         file_name = readln().strip();
  29.  
  30.         if (file_name[$ - 3] != 't' && file_name[$ - 1] != 't') {
  31.             file_name = file_name ~ ".txt";
  32.         }
  33.  
  34.         File file1 = File(file_name, "r");
  35.  
  36.             if (file1.isOpen() == true) {
  37.                 writeln("Debug > File opened");
  38.             }
  39.             write();
  40.  
  41.             file_buffer = file1.readln().strip();
  42.             writeln("File buffer > ", file_buffer);
  43.         file1.close();
  44.     }
  45. }
  46.  
  47. void main() {
  48.     string command;
  49.  
  50.     while (true) {
  51.         write("Command > ");
  52.         command = readln().strip();
  53.  
  54.         /*
  55.             Available commands:
  56.                 write - 1;
  57.                 read - 2;
  58.         */
  59.  
  60.         if (command[0] == 'w' && command[$ - 1] == 'e') {
  61.             wrFile(1);
  62.         }
  63.  
  64.         if (command[0] == 'r' && command[$ - 1] == 'd') {
  65.             wrFile(2);
  66.         }
  67.  
  68.         if (command[0] == 'e' && command[$ - 1] == 't') {
  69.             break;
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement