static int print_xml(t_object *root, int lvl) { t_lst *lst; int i; lst = root->inside->first; if (lst != NULL) { do { if ((print_markup(lst->data, lvl)) == 1) { i = -1; print_xml(lst->data, lvl + 1); while (++i < lvl) dputs(1, " "); dputs(3, "</", ((t_object*)lst->data)->type, ">\n"); } NEXT(lst); } while (lst != root->inside->first); return (1); } return (0); }
/*! \param \*argv[] ./verlet nsteps dt xml_file energy_file animation_file The input arguments are as follows: nsteps Number of timesteps to run for. dt Timestep to use. xml_file Initial configuration file (positions and velocities, etc.) energy_file Energetics and interactions file that contains function parameters. animation_file File to write the .xyz animation to. */ int main (int argc, char *argv[]) { int check; long int nsteps; double dt; System mysys; //Declare system if (argc != 6) { fprintf(stderr, "syntax: ./verlet nsteps dt xml_file energy_file animation_file\n"); return ILLEGAL_VALUE; } // Read nsteps and dt char* str_ptr; nsteps = strtol(argv[1], &str_ptr, 10); // Store number of steps dt = atof(argv[2]); if (str_ptr == argv[1]) { fprintf(stderr, "No value was found for the number of steps. \n"); return ILLEGAL_VALUE; } if (*str_ptr != '\0') { fprintf(stdout, "Number of steps taken as %ld ,", nsteps); fprintf(stdout, " Ignored characters : %s\n", str_ptr); } // Setup integrator Integrator *myint = new Verlet (dt); myint->set_dt(dt); check = start_mpi (argc, argv); if (check != 0) { goto finalize; } // Initialize coordinates check = initialize_from_files (argv[3], argv[4], &mysys); if (check != 0) { goto finalize; } // Run check = run (&mysys, myint, nsteps, argv[5]); if (check != 0) { goto finalize; } // Print final coordinates print_xml("outfile.xml", &mysys); // Finish safely end_mpi(); return SAFE_EXIT; // Finish if error was reported finalize: abort_mpi(); return BAD_EXIT; }
int render_entity_avatar(World *world, U32 id, char *buffer) { char *ptr = buffer; Dwarf *dwarf = 0; for (U32 i = 0; i < Count(world->dwarves); i++) { if (world->dwarves[i].id == id) { dwarf = &world->dwarves[i]; break; } } if (!dwarf) { sprintf(buffer, "Entity not found with ID #%u", id); return 404; } ptr += sprintf(ptr, "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"" " width=\"60\" height=\"60\" overflow=\"hidden\">\n"); Printer p; p.pos = ptr; p.end = ptr + 10000; Random_Series series = series_from_seed32(dwarf->seed); const char *parts[] = { "base", "beard", "eyes", }; for (size_t i = 0; i < Count(parts); i++) { char name[64]; sprintf(name, "face-%s%02d", parts[i], 1 + next(&series, 3)); XML_Node *node = svg_find_by_id(&world->assets->faces, c_string(name)); if (!print_xml(&p, node)) return 500; } ptr = p.pos; ptr += sprintf(ptr, "</svg>\n"); return 200; }
int main (int argc, char *argv[]) { set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); bindtextdomain ("bison-runtime", LOCALEDIR); textdomain (PACKAGE); { char const *cp = getenv ("LC_CTYPE"); if (cp && STREQ (cp, "C")) set_custom_quoting ("e_quoting_options, "'", "'"); else set_quoting_style ("e_quoting_options, locale_quoting_style); } atexit (close_stdout); uniqstrs_new (); muscle_init (); complain_init (); getargs (argc, argv); timevar_report = trace_flag & trace_time; init_timevar (); timevar_start (TV_TOTAL); if (trace_flag & trace_bitsets) bitset_stats_enable (); /* Read the input. Copy some parts of it to FGUARD, FACTION, FTABLE and FATTRS. In file reader.c. The other parts are recorded in the grammar; see gram.h. */ timevar_push (TV_READER); reader (); timevar_pop (TV_READER); if (complaint_status == status_complaint) goto finish; /* Find useless nonterminals and productions and reduce the grammar. */ timevar_push (TV_REDUCE); reduce_grammar (); timevar_pop (TV_REDUCE); /* Record other info about the grammar. In files derives and nullable. */ timevar_push (TV_SETS); derives_compute (); nullable_compute (); timevar_pop (TV_SETS); /* Compute LR(0) parser states. See state.h for more info. */ timevar_push (TV_LR0); generate_states (); timevar_pop (TV_LR0); /* Add lookahead sets to parser states. Except when LALR(1) is requested, split states to eliminate LR(1)-relative inadequacies. */ ielr (); /* Find and record any conflicts: places where one token of lookahead is not enough to disambiguate the parsing. In file conflicts. Also resolve s/r conflicts based on precedence declarations. */ timevar_push (TV_CONFLICTS); conflicts_solve (); if (!muscle_percent_define_flag_if ("lr.keep-unreachable-state")) { state_number *old_to_new = xnmalloc (nstates, sizeof *old_to_new); state_number nstates_old = nstates; state_remove_unreachable_states (old_to_new); lalr_update_state_numbers (old_to_new, nstates_old); conflicts_update_state_numbers (old_to_new, nstates_old); free (old_to_new); } conflicts_print (); timevar_pop (TV_CONFLICTS); /* Compute the parser tables. */ timevar_push (TV_ACTIONS); tables_generate (); timevar_pop (TV_ACTIONS); grammar_rules_useless_report (_("rule useless in parser due to conflicts")); print_precedence_warnings (); /* Output file names. */ compute_output_file_names (); /* Output the detailed report on the grammar. */ if (report_flag) { timevar_push (TV_REPORT); print_results (); timevar_pop (TV_REPORT); } /* Output the graph. */ if (graph_flag) { timevar_push (TV_GRAPH); print_graph (); timevar_pop (TV_GRAPH); } /* Output xml. */ if (xml_flag) { timevar_push (TV_XML); print_xml (); timevar_pop (TV_XML); } /* Stop if there were errors, to avoid trashing previous output files. */ if (complaint_status == status_complaint) goto finish; /* Lookahead tokens are no longer needed. */ timevar_push (TV_FREE); lalr_free (); timevar_pop (TV_FREE); /* Output the tables and the parser to ftable. In file output. */ timevar_push (TV_PARSER); output (); timevar_pop (TV_PARSER); timevar_push (TV_FREE); nullable_free (); derives_free (); tables_free (); states_free (); reduce_free (); conflicts_free (); grammar_free (); output_file_names_free (); /* The scanner memory cannot be released right after parsing, as it contains things such as user actions, prologue, epilogue etc. */ gram_scanner_free (); muscle_free (); uniqstrs_free (); code_scanner_free (); skel_scanner_free (); quotearg_free (); timevar_pop (TV_FREE); if (trace_flag & trace_bitsets) bitset_stats_dump (stderr); finish: /* Stop timing and print the times. */ timevar_stop (TV_TOTAL); timevar_print (stderr); cleanup_caret (); return complaint_status ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char **argv) { idevice_t device = NULL; lockdownd_client_t lockdown_client = NULL; diagnostics_relay_client_t diagnostics_client = NULL; lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; uint16_t port = 0; int result = -1; int i; const char *udid = NULL; int cmd = CMD_NONE; char* cmd_arg = NULL; plist_t node = NULL; plist_t keys = NULL; /* parse cmdline args */ for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { idevice_set_debug_level(1); continue; } else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--udid")) { i++; if (!argv[i] || (strlen(argv[i]) != 40)) { print_usage(argc, argv); result = 0; goto cleanup; } udid = argv[i]; continue; } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { print_usage(argc, argv); result = 0; goto cleanup; } else if (!strcmp(argv[i], "sleep")) { cmd = CMD_SLEEP; } else if (!strcmp(argv[i], "restart")) { cmd = CMD_RESTART; } else if (!strcmp(argv[i], "shutdown")) { cmd = CMD_SHUTDOWN; } else if (!strcmp(argv[i], "diagnostics")) { cmd = CMD_DIAGNOSTICS; /* read type */ i++; if (!argv[i] || ((strcmp(argv[i], "All") != 0) && (strcmp(argv[i], "WiFi") != 0) && (strcmp(argv[i], "GasGauge") != 0) && (strcmp(argv[i], "NAND") != 0))) { if (argv[i] == NULL) { cmd_arg = strdup("All"); continue; } if (!strncmp(argv[i], "-", 1)) { cmd_arg = strdup("All"); i--; continue; } printf("Unknown TYPE %s\n", argv[i]); print_usage(argc, argv); goto cleanup; } cmd_arg = strdup(argv[i]); continue; } else if (!strcmp(argv[i], "mobilegestalt")) { cmd = CMD_MOBILEGESTALT; /* read keys */ i++; if (!argv[i] || argv[i] == NULL || (!strncmp(argv[i], "-", 1))) { printf("Please supply the key to query.\n"); print_usage(argc, argv); goto cleanup; } keys = plist_new_array(); while(1) { if (argv[i] && (strlen(argv[i]) >= 2) && (strncmp(argv[i], "-", 1) != 0)) { plist_array_append_item(keys, plist_new_string(argv[i])); i++; } else { i--; break; } } continue; } else if (!strcmp(argv[i], "ioreg")) { cmd = CMD_IOREGISTRY; /* read plane */ i++; if (argv[i]) { cmd_arg = strdup(argv[i]); } continue; } else { print_usage(argc, argv); return 0; } } /* verify options */ if (cmd == CMD_NONE) { print_usage(argc, argv); goto cleanup; } if (IDEVICE_E_SUCCESS != idevice_new(&device, udid)) { if (udid) { printf("No device found with udid %s, is it plugged in?\n", udid); } else { printf("No device found, is it plugged in?\n"); } goto cleanup; } if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &lockdown_client, NULL)) { idevice_free(device); printf("Unable to connect to lockdownd.\n"); goto cleanup; } /* attempt to use newer diagnostics service available on iOS 5 and later */ ret = lockdownd_start_service(lockdown_client, "com.apple.mobile.diagnostics_relay", &port); if (ret != LOCKDOWN_E_SUCCESS) { /* attempt to use older diagnostics service */ ret = lockdownd_start_service(lockdown_client, "com.apple.iosdiagnostics.relay", &port); } lockdownd_client_free(lockdown_client); if ((ret == LOCKDOWN_E_SUCCESS) && (port > 0)) { if (diagnostics_relay_client_new(device, port, &diagnostics_client) != DIAGNOSTICS_RELAY_E_SUCCESS) { printf("Could not connect to diagnostics_relay!\n"); result = -1; } else { switch (cmd) { case CMD_SLEEP: if (diagnostics_relay_sleep(diagnostics_client) == DIAGNOSTICS_RELAY_E_SUCCESS) { printf("Putting device into deep sleep mode.\n"); result = EXIT_SUCCESS; } else { printf("Failed to put device into deep sleep mode.\n"); } break; case CMD_RESTART: if (diagnostics_relay_restart(diagnostics_client, 0) == DIAGNOSTICS_RELAY_E_SUCCESS) { printf("Restarting device.\n"); result = EXIT_SUCCESS; } else { printf("Failed to restart device.\n"); } break; case CMD_SHUTDOWN: if (diagnostics_relay_shutdown(diagnostics_client, 0) == DIAGNOSTICS_RELAY_E_SUCCESS) { printf("Shutting down device.\n"); result = EXIT_SUCCESS; } else { printf("Failed to shutdown device.\n"); } break; case CMD_MOBILEGESTALT: if (diagnostics_relay_query_mobilegestalt(diagnostics_client, keys, &node) == DIAGNOSTICS_RELAY_E_SUCCESS) { if (node) { print_xml(node); result = EXIT_SUCCESS; } } else { printf("Unable to query mobilegestalt keys.\n"); } break; case CMD_IOREGISTRY: if (diagnostics_relay_query_ioregistry_plane(diagnostics_client, cmd_arg == NULL ? "": cmd_arg, &node) == DIAGNOSTICS_RELAY_E_SUCCESS) { if (node) { print_xml(node); result = EXIT_SUCCESS; } } else { printf("Unable to retrieve IORegistry from device.\n"); } break; case CMD_DIAGNOSTICS: default: if (diagnostics_relay_request_diagnostics(diagnostics_client, cmd_arg, &node) == DIAGNOSTICS_RELAY_E_SUCCESS) { if (node) { print_xml(node); result = EXIT_SUCCESS; } } else { printf("Unable to retrieve diagnostics from device.\n"); } break; } diagnostics_relay_goodbye(diagnostics_client); diagnostics_relay_client_free(diagnostics_client); } } else { printf("Could not start diagnostics service!\n"); } idevice_free(device); cleanup: if (node) { plist_free(node); } if (keys) { plist_free(keys); } if (cmd_arg) { free(cmd_arg); } return result; }
int main(int argc, char **argv) { idevice_t device = NULL; lockdownd_client_t lckd = NULL; mobile_image_mounter_client_t mim = NULL; afc_client_t afc = NULL; lockdownd_service_descriptor_t service = NULL; int res = -1; char *image_path = NULL; char *image_sig_path = NULL; parse_opts(argc, argv); argc -= optind; argv += optind; if (!list_mode) { if (argc < 1) { printf("ERROR: No IMAGE_FILE has been given!\n"); return -1; } image_path = strdup(argv[0]); if (argc >= 2) { image_sig_path = strdup(argv[1]); } else { if (asprintf(&image_sig_path, "%s.signature", image_path) < 0) { printf("Out of memory?!\n"); return -1; } } } if (IDEVICE_E_SUCCESS != idevice_new(&device, udid)) { printf("No device found, is it plugged in?\n"); return -1; } if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &lckd, "ideviceimagemounter")) { printf("ERROR: could not connect to lockdown. Exiting.\n"); goto leave; } lockdownd_start_service(lckd, "com.apple.mobile.mobile_image_mounter", &service); if (!service || service->port == 0) { printf("ERROR: Could not start mobile_image_mounter service!\n"); goto leave; } if (mobile_image_mounter_new(device, service, &mim) != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { printf("ERROR: Could not connect to mobile_image_mounter!\n"); goto leave; } if (service) { lockdownd_service_descriptor_free(service); service = NULL; } if (!list_mode) { struct stat fst; if ((lockdownd_start_service(lckd, "com.apple.afc", &service) != LOCKDOWN_E_SUCCESS) || !service || !service->port) { fprintf(stderr, "Could not start com.apple.afc!\n"); goto leave; } if (afc_client_new(device, service, &afc) != AFC_E_SUCCESS) { fprintf(stderr, "Could not connect to AFC!\n"); goto leave; } if (service) { lockdownd_service_descriptor_free(service); service = NULL; } if (stat(image_path, &fst) != 0) { fprintf(stderr, "ERROR: stat: %s: %s\n", image_path, strerror(errno)); goto leave; } if (stat(image_sig_path, &fst) != 0) { fprintf(stderr, "ERROR: stat: %s: %s\n", image_sig_path, strerror(errno)); goto leave; } } lockdownd_client_free(lckd); lckd = NULL; mobile_image_mounter_error_t err; plist_t result = NULL; if (list_mode) { /* list mounts mode */ if (!imagetype) { imagetype = strdup("Developer"); } err = mobile_image_mounter_lookup_image(mim, imagetype, &result); free(imagetype); if (err == MOBILE_IMAGE_MOUNTER_E_SUCCESS) { res = 0; if (xml_mode) { print_xml(result); } else { plist_dict_to_string(result); } } else { printf("Error: lookup_image returned %d\n", err); } } else { char sig[8192]; size_t sig_length = 0; FILE *f = fopen(image_sig_path, "rb"); if (!f) { fprintf(stderr, "Error opening signature file '%s': %s\n", image_sig_path, strerror(errno)); goto leave; } sig_length = fread(sig, 1, sizeof(sig), f); fclose(f); if (sig_length == 0) { fprintf(stderr, "Could not read signature from file '%s'\n", image_sig_path); goto leave; } f = fopen(image_path, "rb"); if (!f) { fprintf(stderr, "Error opening image file '%s': %s\n", image_path, strerror(errno)); goto leave; } char *targetname = NULL; if (asprintf(&targetname, "%s/%s", PKG_PATH, "staging.dimage") < 0) { fprintf(stderr, "Out of memory!?\n"); goto leave; } char *mountname = NULL; if (asprintf(&mountname, "%s/%s", PATH_PREFIX, targetname) < 0) { fprintf(stderr, "Out of memory!?\n"); goto leave; } printf("Copying '%s' --> '%s'\n", image_path, targetname); char **strs = NULL; if (afc_get_file_info(afc, PKG_PATH, &strs) != AFC_E_SUCCESS) { if (afc_make_directory(afc, PKG_PATH) != AFC_E_SUCCESS) { fprintf(stderr, "WARNING: Could not create directory '%s' on device!\n", PKG_PATH); } } if (strs) { int i = 0; while (strs[i]) { free(strs[i]); i++; } free(strs); } uint64_t af = 0; if ((afc_file_open(afc, targetname, AFC_FOPEN_WRONLY, &af) != AFC_E_SUCCESS) || !af) { fclose(f); fprintf(stderr, "afc_file_open on '%s' failed!\n", targetname); goto leave; } char buf[8192]; size_t amount = 0; do { amount = fread(buf, 1, sizeof(buf), f); if (amount > 0) { uint32_t written, total = 0; while (total < amount) { written = 0; if (afc_file_write(afc, af, buf, amount, &written) != AFC_E_SUCCESS) { fprintf(stderr, "AFC Write error!\n"); break; } total += written; } if (total != amount) { fprintf(stderr, "Error: wrote only %d of %d\n", total, (unsigned int)amount); afc_file_close(afc, af); fclose(f); goto leave; } } } while (amount > 0); afc_file_close(afc, af); fclose(f); printf("done.\n"); printf("Mounting...\n"); if (!imagetype) { imagetype = strdup("Developer"); } err = mobile_image_mounter_mount_image(mim, mountname, sig, sig_length, imagetype, &result); free(imagetype); if (err == MOBILE_IMAGE_MOUNTER_E_SUCCESS) { if (result) { plist_t node = plist_dict_get_item(result, "Status"); if (node) { char *status = NULL; plist_get_string_val(node, &status); if (status) { if (!strcmp(status, "Complete")) { printf("Done.\n"); res = 0; } else { printf("unexpected status value:\n"); if (xml_mode) { print_xml(result); } else { plist_dict_to_string(result); } } free(status); } else { printf("unexpected result:\n"); if (xml_mode) { print_xml(result); } else { plist_dict_to_string(result); } } } node = plist_dict_get_item(result, "Error"); if (node) { char *error = NULL; plist_get_string_val(node, &error); if (error) { printf("Error: %s\n", error); free(error); } else { printf("unexpected result:\n"); if (xml_mode) { print_xml(result); } else { plist_dict_to_string(result); } } } else { if (xml_mode) { print_xml(result); } else { plist_dict_to_string(result); } } } } else { printf("Error: mount_image returned %d\n", err); } } if (result) { plist_free(result); } /* perform hangup command */ mobile_image_mounter_hangup(mim); /* free client */ mobile_image_mounter_free(mim); leave: if (afc) { afc_client_free(afc); } if (lckd) { lockdownd_client_free(lckd); } idevice_free(device); if (image_path) free(image_path); if (image_sig_path) free(image_sig_path); return res; }
int doprint_xml(t_object *root) { return (print_xml(root, 0)); }