static int write_to_file(char *destination, output_buffer_t *buffer, char *message) { /* PRE: The given pointers are valid and legal. */ /* POST: Writes to the file at the given destination the sufficient binary to flash the Raspberry Pi's LED according to the sequence of morse characters in the buffer. */ assert (destination != NULL && buffer != NULL); FILE *file = fopen(destination, "w"); if (file == NULL) { perror("fopen"); printf("* Couldn't open output file. Stopping.\n"); return EXIT_FAILURE; } if (write_header(file, message) || write_template(file, "led_setup.s") || write_morse_calls(file, buffer) || write_template(file, "flash_loop.s")) { /* Couldn't write all code to the file */ printf("* Couldn't write assembly to output file. Stopping.\n"); return EXIT_FAILURE; } fclose(file); return EXIT_SUCCESS; }
static int module_init(void) { struct contacts *contacts = baresip_contacts(); char path[256] = "", file[256] = ""; int err; err = conf_path_get(path, sizeof(path)); if (err) return err; if (re_snprintf(file, sizeof(file), "%s/contacts", path) < 0) return ENOMEM; if (!conf_fileexist(file)) { (void)fs_mkdir(path, 0700); err = write_template(file); if (err) return err; } err = conf_parse(file, confline_handler, contacts); if (err) return err; err = cmd_register(baresip_commands(), cmdv, ARRAY_SIZE(cmdv)); if (err) return err; info("Populated %u contacts\n", list_count(contact_list(contacts))); return err; }
int main (int argc, char *argv[]) { if ((argc > 1) && (strcmp (argv[1],"-h") == 0)) write_header(); else if ((argc > 1) && (strcmp (argv[1],"-t") == 0)) write_template (); else write_opcodes(); return 0; }