Skip to content

Commit

Permalink
Add append_to_file() w/ error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
xvxx committed Jan 8, 2020
1 parent a13ac1d commit 0e03607
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/ldpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1120,9 +1120,7 @@ void compile_line(vector<string> & tokens, unsigned int line_num, compiler_state
if(!in_procedure_section(state, line_num, current_file))
error("APPEND statement outside PROCEDURE section (\033[0m" + current_file + ":"+ to_string(line_num)+"\033[1;31m)");
//C++ Code
state.add_code("file_writing_stream.open(expandHomeDirectory(((chText)" + get_c_expression(state, tokens[4]) + ").str_rep()), ios_base::app);");
state.add_code("file_writing_stream <<" + get_c_expression(state, tokens[1]) + ";");
state.add_code("file_writing_stream.close();");
state.add_code("append_to_file(" + get_c_expression(state, tokens[4]) + ", " + get_c_expression(state, tokens[1]) + ");");
return;
}

Expand Down
18 changes: 18 additions & 0 deletions src/ldpl_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,24 @@ void load_file(chText filename, chText & destination)
file.close();
}
void append_to_file(chText filename, chText content){
file_writing_stream.open(expandHomeDirectory(filename.str_rep()), ios_base::app);
if(!file_writing_stream.is_open()){
VAR_ERRORTEXT = \"Could not append to \" + filename;
VAR_ERRORCODE = 1;
return;
}
file_writing_stream << content;
if(file_writing_stream.bad()){
VAR_ERRORTEXT = \"Could not append to \" + filename;
VAR_ERRORCODE = 2;
return;
}
VAR_ERRORTEXT = \"\";
VAR_ERRORCODE = 0;
file_writing_stream.close();
}
ldpl_number utf8GetIndexOf(chText haystack, chText needle){
int lenHaystack = haystack.size();
int lenNeedle = needle.size();
Expand Down

0 comments on commit 0e03607

Please sign in to comment.