void TreeReader::ParseTree(const char * fname_in, const char * fname_out) { FILE* f1 = fopen(fname_in, "r"); int tempint = 0; fscanf(f1, "%d", &tempint); fscanf(f1, "%d\n", &tempint); fscanf(f1, "FUNCS %d\n", &number_of_func); namesfunc = (char**)calloc(number_of_func, sizeof(char*)); for (int i = 0; i < number_of_func; i++) { namesfunc[i] = (char*)calloc(MAX_STRLEN, sizeof(char)); fscanf(f1, "%s\n", namesfunc[i]); } fscanf(f1, "VARS %d\n", &number_of_vars); namesvar = (char**)calloc(number_of_vars, sizeof(char*)); for (int i = 0; i < number_of_vars; i++) { namesvar[i] = (char*)calloc(MAX_STRLEN, sizeof(char)); fscanf(f1, "%s\n", namesvar[i]); } FILE* f_out = fopen(fname_out, "w"); Unknown(f1, f_out); fclose(f1); fclose(f_out); }
void HardToFollow(int *p, int q, int *num) { *p = q + *num; *num = q; num = p; p = &q; Unknown(num, *p); }
int main() { int *p; int trouble[3]; trouble[0] = 1; p = &trouble[1]; *p = 2; trouble[2] = 3; printf("p is %d\n", *p); printf("trouble 0 is %d\n", trouble[0]); printf("trouble 2 is %d\n", trouble[2]); HardToFollow(p, trouble[0], &trouble[2]); printf("p is %d\n", *p); printf("trouble 0 is %d\n", trouble[0]); printf("trouble 2 is %d\n", trouble[2]); Unknown(&trouble[0], *p); printf("p is %d\n", *p); printf("trouble 0 is %d\n", trouble[0]); printf("trouble 2 is %d\n", trouble[2]); }
void CommandParser::start() { Vector< String > args; help( args); char buf[2000]; while (true) { printf("%s > ",FileSystem::path().data()); String line(Terminal::readLine(buf)); Vector< String > args = line.split(' '); if (args.isEmpty()) continue; String command = args[0]; if (command == String("time")) Ticks(args); else if (command == String("ram")) Ram(args); else if (command == String("cls")) ClearScreen(args); else if (command == String("ls")) ListOfFiles(args); else if (command == String("cd")) ChangeDirectory(args); else if (command == String("read")) ReadFile(args); else if (command == String("reboot")) reboot(args); else if (command == String("help")) help(args); else if (command == String("wait")) wait(args); else Unknown(args); } }
void AUD_AnimateableProperty::write(const float* data, int position, int count) { AUD_MutexLock lock(*this); int pos = getSize() / (sizeof(float) * m_count); if(!m_isAnimated) pos = 0; m_isAnimated = true; assureSize((count + position) * m_count * sizeof(float), true); float* buf = getBuffer(); memcpy(buf + position * m_count, data, count * m_count * sizeof(float)); // have to fill up space between? if(pos < position) { m_unknown.push_back(Unknown(pos, position - 1)); if(pos == 0) { memset(buf, 0, position * m_count * sizeof(float)); } else updateUnknownCache(pos, position - 1); } // otherwise it's not at the end, let's check if some unknown part got filled else { bool erased = false; for(std::list<Unknown>::iterator it = m_unknown.begin(); it != m_unknown.end(); erased ? it : it++) { erased = false; // unknown area before position if(it->end < position) continue; // we're after the new area, let's stop if(it->start >= position + count) break; // we have an intersection, now 4 cases: // the start is included if(position <= it->start) { // the end is included if(position + count > it->end) { // simply delete it = m_unknown.erase(it); erased = true; } // the end is excluded, a second part remains else { // update second part it->start = position + count; updateUnknownCache(it->start, it->end); break; } } // start is excluded, a first part remains else { // the end is included if(position + count > it->end) { // update first part it->end = position - 1; } // the end is excluded, a second part remains else { // add another item and update both parts m_unknown.insert(it, Unknown(it->start, position - 1)); it->start = position + count; updateUnknownCache(it->start, it->end); } } } } }
bool TreeReader::Unknown(FILE* f_in, FILE* f_out, int level, bool var_init, bool call) { char c = 0; int type = 0; double value = 0; int arg_amount = 0; fscanf(f_in, "%c", &c); bool is_operator = false; if (c == '[') { char *buf = (char *)calloc(MAX_STRLEN, sizeof(char)); fscanf(f_in, " %d %lf ", &type, &value); int value_int = int(value + 0.0001); bool flag_call = false; // Write standart if (type == NodeType::Root) { // Nothing to do } if (type == NodeType::Logic) { if (value_int == Logic1::If) { //print_align(f_out, level); fprintf(f_out, "if "); sprintf(buf, "end\n"); } if (value_int == Logic1::Condition) { //print_align(f_out, level); fprintf(f_out, "("); sprintf(buf, ")\n"); } if (value_int == Logic1::Condition_met) { // Nothing to do } if (value_int == Logic1::Else) { //print_align(f_out, level); fprintf(f_out, "else\n"); } if (value_int == Logic1::While) { //print_align(f_out, level); fprintf(f_out, "while "); sprintf(buf, "end\n"); } } if (type == NodeType::Main) { fprintf(f_out, "def main()\n"); sprintf(buf, "end\n"); } if (type == NodeType::Number) { fprintf(f_out, "%d", value_int); } if (type == NodeType::Operator) { if (value_int != 1 && value_int < 16) fprintf(f_out, "("); Unknown(f_in, f_out, level + 1); //fprintf(f_out, "+"); // fprintf(f_out, DefinedOperators[value_int]); // Unknown(f_in, f_out, level + 1); is_operator = true; if (value_int != 1 && value_int < 16) { fprintf(f_out, ")"); } else { fprintf(f_out, "\n"); } } if (type == NodeType::Service) { // Nothing to do } if (type == NodeType::Standart_function) { if (value_int == StandartFunction::Call) flag_call = true; else { fprintf(f_out, "%s(", DefinedFunctions2[value_int]); sprintf(buf, ")\n"); } arg_amount = 1; if (value_int == StandartFunction::MIN || value_int == StandartFunction::MAX) { arg_amount = 2; } } if (type == NodeType::User_function) { if (call) { fprintf(f_out, "%s\n", namesfunc[value_int]); //sprintf(buf, "\n"); } else { fprintf(f_out, "def %s()\n", namesfunc[value_int]); sprintf(buf, "end\n"); } } if (type == NodeType::Variable) { std::cerr << "123" << std::endl; if (var_init) { fprintf(f_out, "var "); } fprintf(f_out, "%s", namesvar[value_int]); if (var_init) { fprintf(f_out, " = "); } } if (type == NodeType::Var_init) { std::cerr << "var init" << std::endl; while (Unknown(f_in, f_out, level + 1, 1)) { fprintf(f_out, "\n"); } } printf("%d %d\n", type, value_int); while (Unknown(f_in, f_out, level + 1, false, flag_call)) { if (arg_amount >= 2) { fprintf(f_out, ","); arg_amount--; } } fprintf(f_out, "%s", buf); free(buf); return true; } else { fscanf(f_in, "ULL ] "); return false; } }