static void create_compoundobject(int x, int y) { F_compound *c; if ((c = create_compound()) == NULL) return; if (compose_compound(c) == 0) { free((char *) c); compound_selected(); draw_mousefun_canvas(); put_msg("Empty compound, ignored"); return; } /* * Make the bounding box exactly match the dimensions of the compound. */ compound_bound(c, &c->nwcorner.x, &c->nwcorner.y, &c->secorner.x, &c->secorner.y); /* if zero width or height in the compound, adjust to next positioning grid point or a few pixels if positioning grid is "ANY" */ if (c->nwcorner.x == c->secorner.x) { if (cur_pointposn != P_ANY) { c->secorner.x += posn_rnd[cur_gridunit][cur_pointposn]; c->secorner.x = ceil_coords_x(c->secorner.x,c->secorner.y); } } if (c->nwcorner.y == c->secorner.y) { if (cur_pointposn != P_ANY) { c->secorner.y += posn_rnd[cur_gridunit][cur_pointposn]; c->secorner.y = ceil_coords_y(c->secorner.x,c->secorner.y); } } c->next = NULL; clean_up(); set_action(F_GLUE); toggle_markers_in_compound(c); list_add_compound(&objects.compounds, c); mask_toggle_compoundmarker(c); set_latestcompound(c); set_modifiedflag(); compound_selected(); draw_mousefun_canvas(); }
/** * The main entry function. * * Command line arguments have to be in order: * - command (cyboi) * - abstraction (compound|operation) * - location (inline|file|ftp|http) * - model (a compound model or primitive operation, for example: exit or model.submodel) * * Usage: * cyboi compound|operation inline|file|ftp|http model.submodel * * Example 1 (starts up and right away shuts down the system): * cyboi operation inline exit * * Example 2 (calls the startup routine of some application): * cyboi compound file /application/logic/startup.cybol * * The main function follows a system lifecycle to start up, * run and shut down the CYBOI system, in the following order: * 1 initialize global variables * 2 create statics (state/ logic knowledge container etc.) * 3 create startup signal and add to signal memory * 4 run dynamics (signal waiting loop) * 5 destroy startup signal * 6 destroy statics (state/ logic knowledge container etc.) * * @param p0 the argument count (argc) * @param p1 the argument vector (argv) * @return the return value */ int main(int p0, char** p1) { // Return 1 to indicate an error, by default. int r = 1; // // Global variables. // // Initialize global variables. // CAUTION! // They have to be initialized before the command line parameter check below! // Otherwise, the logger may not be able to log possible error messages. initialize_global_variables(); // // Testing. // // Call testing procedures. // Comment/ uncomment this as needed. // CAUTION! // This has to stand AFTER the initialization of the // global variables because these are used by the testing code. // test(); // return 0; if (p1 != NULL_POINTER) { if (p0 == STARTUP_PARAMETERS_COUNT) { // // Knowledge container. // // The knowledge container and its count and size. void* k = NULL_POINTER; int kc = 0; int ks = 0; // Create knowledge container. create_compound((void*) &k, (void*) &ks); // // Internals container. // // The internals container and its count and size. void* i = NULL_POINTER; int ic = 0; int is = 0; // Create internals container. //?? create_internals((void*) &i, (void*) &ic, (void*) &is); // // Signal container. // // The signal container and its count and size. void* s = NULL_POINTER; int sc = 0; int ss = 0; // Create signal container. create_signal_memory((void*) &s, (void*) &ss); // // Startup model. // // Initialize persistent part abstraction, location, model // and their counts and sizes. void* ppa = (void*) p1[ABSTRACTION_STARTUP_PARAMETER_INDEX]; int ppac = strlen(p1[ABSTRACTION_STARTUP_PARAMETER_INDEX]); int ppas = ppac; void* ppl = (void*) p1[LOCATION_STARTUP_PARAMETER_INDEX]; int pplc = strlen(p1[LOCATION_STARTUP_PARAMETER_INDEX]); int ppls = pplc; void* ppm = (void*) p1[MODEL_STARTUP_PARAMETER_INDEX]; int ppmc = strlen(p1[MODEL_STARTUP_PARAMETER_INDEX]); int ppms = ppmc; // Initialize transient part abstraction, model // and their counts and sizes. // CAUTION! A transient location is not stored, // since that is only needed temporarily // for model loading. void* tpa = NULL_POINTER; int tpac = 0; int tpas = 0; void* tpm = NULL_POINTER; int tpmc = 0; int tpms = 0; // Create transient part abstraction, model // and their counts and sizes. interpret_model((void*) &tpa, (void*) &tpac, (void*) &tpas, (void*) &ppa, (void*) &ppac, (void*) &STRING_ABSTRACTION, (void*) &STRING_ABSTRACTION_COUNT); interpret_located_model((void*) &tpm, (void*) &tpmc, (void*) &tpms, (void*) &ppa, (void*) &ppac, (void*) &ppl, (void*) &pplc, (void*) &ppm, (void*) &ppmc); // // Startup signal. // // Add startup signal to signal memory. set_signal((void*) &s, (void*) &sc, (void*) &ss, (void*) &tpm, (void*) &tpmc, (void*) &NORMAL_PRIORITY, (void*) &tpa, (void*) &tpac); // // Waiting loop. // // The system is now started up and complete so that a loop // can be entered, waiting for signals (events/ interrupts) // which are stored/ found in the signal memory. // The loop is left as soon as its shutdown flag is set. wait((void*) &s, (void*) &sc, (void*) &ss, (void*) &k, (void*) &kc, (void*) &ks, (void*) &i, (void*) &ic, (void*) &is); // // Destruction. // //?? Do not forget to destroy startup abstraction etc. HERE! // Destroy startup model. destroy_model((void*) &tpm, (void*) &tpmc, (void*) &tpms, (void*) &NULL_POINTER, (void*) &NULL_POINTER, (void*) &NULL_POINTER, (void*) &tpa, (void*) &tpac, (void*) &tpa, (void*) &tpac, (void*) &tpm, (void*) &tpmc, (void*) &NULL_POINTER, (void*) &NULL_POINTER, (void*) &NULL_POINTER, (void*) &NULL_POINTER, (void*) &NULL_POINTER, (void*) &NULL_POINTER); // Destroy signal container. destroy_signal_memory((void*) &s, (void*) &ss); // Destroy internals container. //?? destroy_internals((void*) &i, (void*) &ic, (void*) &is); // Destroy knowledge container. destroy_compound((void*) &k, (void*) &ks); log_message((void*) &INFO_LOG_LEVEL, (void*) &EXIT_CYBOI_NORMALLY_MESSAGE, (void*) &EXIT_CYBOI_NORMALLY_MESSAGE_COUNT); // Return 0 to indicate proper shutdown. r = 0; } else { log_message((void*) &ERROR_LOG_LEVEL, (void*) &COULD_NOT_EXECUTE_CYBOI_THE_COMMAND_LINE_ARGUMENT_NUMBER_IS_INCORRECT_MESSAGE, (void*) &COULD_NOT_EXECUTE_CYBOI_THE_COMMAND_LINE_ARGUMENT_NUMBER_IS_INCORRECT_MESSAGE_COUNT); log_message((void*) &INFO_LOG_LEVEL, (void*) &USAGE_MESSAGE, (void*) &USAGE_MESSAGE_COUNT); } } else { log_message((void*) &ERROR_LOG_LEVEL, (void*) &COULD_NOT_EXECUTE_CYBOI_THE_COMMAND_LINE_ARGUMENT_VECTOR_IS_NULL_MESSAGE, (void*) &COULD_NOT_EXECUTE_CYBOI_THE_COMMAND_LINE_ARGUMENT_VECTOR_IS_NULL_MESSAGE_COUNT); } return r; }