int check_next(char *cmd, char **arg, char **env) { int ret; ret = 0; if (my_strcmp("echo", arg[0]) == 0) { if (arg[1] == NULL) printf("Usage : echo [-neE] [VALUE] \n"); else my_echo(&arg[1], 0, 0); ++ret; } if (my_strcmp("cd", arg[0]) == 0) { change_directory(arg[1], env); ++ret; } if (my_strcmp("history", cmd) == 0) { my_history(); ++ret; } ret += check_again(cmd, arg, env); return (ret); }
int check_builtins(t_main *list, t_main **env) { if (strcmp(list->str, "cd") == 0) my_cd(list, *env); else if (strcmp(list->str, "env") == 0) show_env(*env); else if (strcmp(list->str, "setenv") == 0) my_setenv(list, env); else if (strcmp(list->str, "unsetenv") == 0) my_unsetenv(list, env); else if (strcmp(list->str, "exit") == 0) my_exit(list); else if (strcmp(list->str, "echo") == 0) my_echo(list); else if (strcmp(list->str, "..") == 0) my_cd(manage_double_dots(&list), *env); else return (0); return (1); }
int main(int argc, char **argv) { my_echo(argv); }
bool my_process_line( std::string Line) { std::vector<std::string> Vec; std::stringstream Stream; Vec = my_preprocess_line(Line); #define my_get_item(_stridx) (Indexer[_stridx] > 0 ? Vec[Indexer[_stridx] - 1] : "") #define my_print_indent(_indent)\ for (int _i = 0; _i < _indent * 4; _i++) Stream << ' '; #define my_print(_indent, _jidx, _cidx, _term)\ my_print_indent(_indent);\ Stream << "\"" << _jidx << "\" : " << _cidx << _term << "\n"; #define my_echo(_indent, _jidx, _cidx, _term)\ my_print(_indent, _jidx, my_get_item(_cidx), _term); #define my_echo_(_indent, _jidx, _cidx)\ my_echo(_indent, _jidx, _cidx, "") #define my_echo_d(_indent, _jidx, _term)\ my_echo(_indent, _jidx, "", _term) #define my_echo_str(_indent, _jidx, _cidx, _term)\ my_print(_indent, _jidx, "\"" << my_get_item(_cidx) << "\"", _term); // Things have been declared, now coming to the best part my_print_indent(0); Stream << "{\n"; my_echo_d(1, "Properties", "{"); my_echo_str(2, "Name", "Name", ","); my_echo_str(2, "Type", "Type", ","); my_echo_str(2, "Description", "Description", ","); my_echo_(2, "ShowInCreative", "ShowInCreative"); my_print_indent(1); Stream << "},\n"; my_echo_d(1, "Physics", "{"); my_echo(2, "PhysicsEnabled", "PhysicsEnabled", ","); my_echo(2, "CollisionEnabled", "CollisionEnabled", ","); my_echo(2, "LengthX", "pLengthX", ","); my_echo(2, "LengthY", "pLengthX", ","); my_echo(2, "Mass", "Mass", ","); my_echo(2, "FrictionFactorTop", "FrictionFactorTop", ","); my_echo(2, "FrictionFactorBottom", "FrictionFactorBottom", ","); my_echo(2, "FrictionFactorLeft", "FrictionFactorLeft", ","); my_echo(2, "FrictionFactorRight", "FrictionFactorRight", ","); my_echo(2, "ElasticFactorTop", "ElasticFactorTop", ","); my_echo(2, "ElasticFactorBottom", "ElasticFactorBottom", ","); my_echo(2, "ElasticFactorLeft", "ElasticFactorLeft", ","); my_echo(2, "ElasticFactorRight", "ElasticFactorRight", ","); my_echo_(2, "BlastResistance", "BlastResistance"); my_print_indent(1); Stream << "},\n"; my_echo_d(1, "Graphics", "{"); my_echo(2, "RenderEnabled", "RenderEnabled", ","); my_echo(2, "LengthX", "gLengthX", ","); my_echo(2, "LengthY", "gLengthY", ","); my_echo(2, "AnimationInterval", "AnimationInterval", ","); my_echo_str(2, "TextureOnHand", "TextureOnHand", ","); my_echo_d(2, "TextureList", "["); my_print_indent(3); Stream << "\"" << Vec[Indexer["Texture"] - 1] << "\"\n"; my_print_indent(2); Stream << "]\n"; my_print_indent(1); Stream << "}\n"; Stream << "}\n"; // Preparing to output... std::string Output = "", sTemp, openFile; std::ofstream Flow; while (getline(Stream, sTemp)) Output += sTemp + '\n'; openFile = my_get_item("ExportPath"); if (openFile == "") { openFile = my_get_item("Name"); for (char& c : openFile) { if (c == '.') c = '_'; if (c >= 'A' && c <= 'Z') c = c - 'A' + 'a'; } openFile += ".json"; } openFile = "./entities/" + openFile; Flow.open(openFile); Flow << Output; Flow.close(); return true; }