//执行指定指令的函数 void console_runcmd(char *cmdline, CONSOLE *console, int *fat, unsigned int mem_total) { if(0 == strcmp(cmdline, "mem")) { cmd_mem(console, mem_total); } else if(0 == strcmp(cmdline, "clear")) { cmd_clear(console); } else if(0 == strcmp(cmdline, "ls")) { cmd_ls(console); } else if(0 == strncmp(cmdline, "type ", 5)) { cmd_type(console, fat, cmdline); } //不是命令但也不是空行 else if(0 != cmdline[0]) { //运行那个应用程序的任务已经在cmd_app中执行了,返回值只是告诉这里是否正常运行了而已 if(0 == cmd_app(console, fat, cmdline)) { //如果到这里了,说明这个命令对应的既不是命令,又不是应用程序,而且不是空行 console_putstring_toend(console, "Bad Command!\n\n"); } } return ; }
//执行指定指令的函数 void console_runcmd(char *cmdline, CONSOLE *console, int *fat, unsigned int mem_total) { if(0 == strcmp(cmdline, "mem")) { cmd_mem(console, mem_total); } else if(0 == strcmp(cmdline, "clear")) { cmd_clear(console); } else if(0 == strcmp(cmdline, "ls")) { cmd_ls(console); } else if(0 == strncmp(cmdline, "type ", 5)) { cmd_type(console, fat, cmdline); } else if(0 == strcmp(cmdline, "hlt")) { cmd_hlt(console, fat); } //不是命令但也不是空行 else if(0 != cmdline[0]) { displayStrings_atLayer(console->layer, 8, console->cursor_y, COL8_FFFFFF, COL8_000000, "Bad command!"); console_newline(console); console_newline(console); } return ; }
void cons_runcmd (char *cmdline, struct CONSOLE *cons, int *fat, unsigned int memtotal) { if (strcmp(cmdline, "mem") == 0) { cmd_mem (cons, memtotal); } else if (strcmp(cmdline, "cls") == 0) { cmd_cls (cons); } else if (strcmp (cmdline, "dir") == 0) { cmd_dir (cons); } else if (cmdline[0]=='t' && cmdline[1]=='y' && cmdline[2]=='p' && cmdline[3]=='e' && cmdline[4]==' ') { cmd_type (cons, fat, cmdline); } else if (cmdline[0] != 0) { if (cmd_app(cons, fat, cmdline) == 0) { // Not Command Line and Empty cons_putstr0 (cons, "bad command.\n\n"); } } }
void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, unsigned int memtotal) { if (strcmp(cmdline, "mem") == 0) { cmd_mem(cons, memtotal); } else if (strcmp(cmdline, "cls") == 0) { cmd_cls(cons); } else if (strcmp(cmdline, "dir") == 0) { cmd_dir(cons); } else if (strncmp(cmdline, "type", 5) == 0) { cmd_type(cons, fat, cmdline); } else if (cmdline[0] != 0) { if (cmd_app(cons, fat, cmdline) == 0) { cons_putstr0(cons, "Bad command.\n\n"); } } return; }
void cons_runcmd (char *cmdline, struct CONSOLE *cons, int *fat, unsigned int memtotal) { if (strcmp(cmdline, "mem") == 0) { cmd_mem (cons, memtotal); } else if (strcmp(cmdline, "cls") == 0) { cmd_cls (cons); } else if (strcmp (cmdline, "dir") == 0) { cmd_dir (cons); } else if (cmdline[0]=='t' && cmdline[1]=='y' && cmdline[2]=='p' && cmdline[3]=='e' && cmdline[4]==' ') { cmd_type (cons, fat, cmdline); } else if (strcmp (cmdline, "hlt") == 0) { cmd_hlt (cons, fat); } else if (cmdline[0] != 0) { // Not Command Line and Empty putfonts8_asc_sht (cons->sht, 8, cons->cur_y, COL8_FFFFFF, COL8_000000, "Bad command.", 12); cons_newline (cons); cons_newline (cons); } }
void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, unsigned int memtotal) { if (strcmp(cmdline, "mem") == 0) { cmd_mem(cons, memtotal); } else if (strcmp(cmdline, "cls") == 0) { cmd_cls(cons); } else if (strcmp(cmdline, "dir") == 0) { cmd_dir(cons); } else if (strncmp(cmdline, "type ", 5) == 0) { cmd_type(cons, fat, cmdline); } else if (strcmp(cmdline, "hlt") == 0) { cmd_hlt(cons, fat); } else if (cmdline[0] != 0) { /* コマンドではなく、さらに空行でもない */ putfonts8_asc_sht(cons->sht, 8, cons->cur_y, COL8_FFFFFF, COL8_000000, "Bad command.", 12); cons_newline(cons); cons_newline(cons); } return; }
void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, unsigned int memtotal) { if (strcmp(cmdline, "mem") == 0) { cmd_mem(cons, memtotal); } else if (strcmp(cmdline, "clear") == 0) { cmd_cls(cons); } else if (strcmp(cmdline, "ls") == 0) { cmd_dir(cons); } else if (strncmp(cmdline, "cat ", 4) == 0) { cmd_type(cons, fat, cmdline); //} else if (strcmp(cmdline, "hlt") == 0) { // cmd_hlt(cons, fat); } else if (cmdline[0] != 0) { if(cmd_app(cons,fat,cmdline) == 0) { bps(cons->sht, 8, cons->cur_y, COL8_000084,COL8_FFFFFF, "Bad command.", 12); cons_newline(cons); cons_newline(cons); } } return; }
int start(int ac, char *av[]) { if(ac < 3) { usage(); return 0; } char *cmd = av[1]; ac-=2; av+=2; if(strncmp(cmd,"type",5)==0) return cmd_type(ac, av); if(strncmp(cmd,"dir",4)==0) return cmd_dir(ac, av); if(strncmp(cmd,"stat",5)==0) return cmd_stat(ac, av); if(strncmp(cmd,"exec",5)==0) return cmd_exec(ac, av); usage(); return 0; }
int parse_cmd_str_to_cmd_struct (char* cmd_string , COMMAND* cmd_struct,unsigned address ){ get_cmd_name (cmd_string , cmd_struct->cmd_name ) ; cmd_type (cmd_struct->cmd_name , cmd_struct->cmd_type ); cmd_struct->b_is_labled = is_labled(cmd_string,cmd_struct->label); cmd_struct->inst_address = address; if (strcmp(cmd_struct->cmd_type,"R")==0){ update_R_type(cmd_string,cmd_struct ); } else if (strcmp(cmd_struct->cmd_type,"I")==0){ update_I_type(cmd_string,cmd_struct ); } else if (strcmp(cmd_struct->cmd_type,"J")==0){ update_J_type(cmd_string,cmd_struct); } //else the command is HALT and we don't have to update COMMAND struct. return 1 ; }
void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, unsigned int memtotal) { /* 执行命令 */ if (strcmp(cmdline, "mem") == 0) { /* mem命令 */ cmd_mem(cons, memtotal); } else if (strcmp(cmdline, "cls") == 0) { /* cls命令 */ cmd_cls(cons); } else if (strcmp(cmdline, "dir") == 0) { /* dir命令 */ cmd_dir(cons); } else if (strncmp(cmdline, "type ", 5) == 0) { /* type命令 */ cmd_type(cons, fat, cmdline); } else if (cmdline[0] != 0) { if (cmd_app(cons, fat, cmdline) == 0) { /* 不是命令,不是应用程序,也不是空行 */ cons_putstr0(cons, "Bad command.\n\n"); } } return; }
void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal) { if (strcmp(cmdline, "mem") == 0 && cons->sht != 0) { cmd_mem(cons, memtotal); } else if (strcmp(cmdline, "cls") == 0 && cons->sht != 0) { cmd_cls(cons); } else if (strcmp(cmdline, "dir") == 0 && cons->sht != 0) { cmd_dir(cons); } else if (strncmp(cmdline, "type ", 5) == 0 && cons->sht != 0) { cmd_type(cons, fat, cmdline); } else if (strcmp(cmdline, "exit") == 0) { cmd_exit(cons, fat); } else if (strncmp(cmdline, "start ", 6) == 0) { cmd_start(cons, cmdline, memtotal); } else if (strncmp(cmdline, "ncst ", 5) == 0) { cmd_ncst(cons, cmdline, memtotal); } else if (cmdline[0] != 0) { if (cmd_app(cons, fat, cmdline) == 0) { /* コマンドではなく、アプリでもなく、さらに空行でもない */ cons_putstr0(cons, "Bad command.\n\n"); } } return; }
// TODO: return bool void vogleditor_QApiCallTreeModel::setupModelData(vogl_trace_file_reader* pTrace_reader, vogleditor_apiCallTreeItem *parent) { const vogl_trace_stream_start_of_file_packet &sof_packet = pTrace_reader->get_sof_packet(); VOGL_NOTE_UNUSED(sof_packet); uint64_t total_swaps = 0; // TODO probably need to handle eof_packet //bool found_eof_packet = false; // make a PendingFrame node to hold the api calls // this will remain in the pending state until the first // api call is seen, then it will be made the CurFrame and // appended to the parent vogleditor_frameItem* pCurFrame = NULL; vogleditor_apiCallTreeItem* pCurParent = parent; // Make a PendingSnapshot that may or may not be populated when reading the trace. // This snapshot will be assigned to the next API call that occurs. vogleditor_gl_state_snapshot* pPendingSnapshot = NULL; m_trace_ctypes.init(pTrace_reader->get_sof_packet().m_pointer_sizes); for ( ; ; ) { vogl_trace_file_reader::trace_file_reader_status_t read_status = pTrace_reader->read_next_packet(); if ((read_status != vogl_trace_file_reader::c*K) && (read_status != vogl_trace_file_reader::cEOF)) { vogl_error_printf("Failed reading from trace file!\n"); break; } if (read_status == vogl_trace_file_reader::cEOF) { vogl_printf("At trace file EOF on swap %" PRIu64 "\n", total_swaps); break; } const vogl::vector<uint8> &packet_buf = pTrace_reader->get_packet_buf(); VOGL_NOTE_UNUSED(packet_buf); const vogl_trace_stream_packet_base &base_packet = pTrace_reader->get_base_packet(); VOGL_NOTE_UNUSED(base_packet); const vogl_trace_gl_entrypoint_packet *pGL_packet = NULL; if (pTrace_reader->get_packet_type() == cTSPTGLEntrypoint) { vogl_trace_packet* pTrace_packet = vogl_new(vogl_trace_packet, &m_trace_ctypes); if (!pTrace_packet->deserialize(pTrace_reader->get_packet_buf().get_ptr(), pTrace_reader->get_packet_buf().size(), false)) { console::error("%s: Failed parsing GL entrypoint packet\n", VOGL_FUNCTION_NAME); break; } pGL_packet = &pTrace_reader->get_packet<vogl_trace_gl_entrypoint_packet>(); gl_entrypoint_id_t entrypoint_id = static_cast<gl_entrypoint_id_t>(pGL_packet->m_entrypoint_id); if (entrypoint_id == VOGL_ENTRYPOINT_glInternalTraceCommandRAD) { // Check if this is a state snapshot. // This is entirely optional since the client is designed to dynamically get new snapshots // if they don't exist. GLuint cmd = pTrace_packet->get_param_value<GLuint>(0); GLuint size = pTrace_packet->get_param_value<GLuint>(1); VOGL_NOTE_UNUSED(size); if (cmd == cITCRKeyValueMap) { key_value_map &kvm = pTrace_packet->get_key_value_map(); dynamic_string cmd_type(kvm.get_string("command_type")); if (cmd_type == "state_snapshot") { dynamic_string id(kvm.get_string("binary_id")); if (id.is_empty()) { vogl_warning_printf("%s: Missing binary_id field in glInternalTraceCommandRAD key_valye_map command type: \"%s\"\n", VOGL_FUNCTION_NAME, cmd_type.get_ptr()); continue; } uint8_vec snapshot_data; { timed_scope ts("get_multi_blob_manager().get"); if (!pTrace_reader->get_multi_blob_manager().get(id, snapshot_data) || (snapshot_data.is_empty())) { vogl_warning_printf("%s: Failed reading snapshot blob data \"%s\"!\n", VOGL_FUNCTION_NAME, id.get_ptr()); continue; } } json_document doc; { timed_scope ts("doc.binary_deserialize"); if (!doc.binary_deserialize(snapshot_data) || (!doc.get_root())) { vogl_warning_printf("%s: Failed deserializing JSON snapshot blob data \"%s\"!\n", VOGL_FUNCTION_NAME, id.get_ptr()); continue; } } vogl_gl_state_snapshot* pGLSnapshot = vogl_new(vogl_gl_state_snapshot); pPendingSnapshot = vogl_new(vogleditor_gl_state_snapshot, pGLSnapshot); timed_scope ts("pPendingSnapshot->deserialize"); if (!pPendingSnapshot->get_snapshot()->deserialize(*doc.get_root(), pTrace_reader->get_multi_blob_manager(), &m_trace_ctypes)) { vogl_delete(pPendingSnapshot); pPendingSnapshot = NULL; vogl_warning_printf("%s: Failed deserializing snapshot blob data \"%s\"!\n", VOGL_FUNCTION_NAME, id.get_ptr()); } } } continue; } const gl_entrypoint_desc_t &entrypoint_desc = g_vogl_entrypoint_descs[entrypoint_id]; QString funcCall = entrypoint_desc.m_pName; // format parameters funcCall.append("( "); dynamic_string paramStr; for (uint param_index = 0; param_index < pTrace_packet->total_params(); param_index++) { if (param_index != 0) funcCall.append(", "); paramStr.clear(); pTrace_packet->pretty_print_param(paramStr, param_index, false); funcCall.append(paramStr.c_str()); } funcCall.append(" )"); if (pTrace_packet->has_return_value()) { funcCall.append(" = "); paramStr.clear(); pTrace_packet->pretty_print_return_value(paramStr, false); funcCall.append(paramStr.c_str()); } // if we don't have a current frame, make a new frame node // and append it to the parent if (pCurFrame == NULL) { pCurFrame = vogl_new(vogleditor_frameItem, total_swaps); vogleditor_apiCallTreeItem* pNewFrameNode = vogl_new(vogleditor_apiCallTreeItem, pCurFrame, pCurParent); pCurParent->appendChild(pNewFrameNode); m_itemList.append(pNewFrameNode); if (pPendingSnapshot != NULL) { pCurFrame->set_snapshot(pPendingSnapshot); pPendingSnapshot = NULL; } // update current parent pCurParent = pNewFrameNode; } // make item and node for the api call vogleditor_apiCallItem* pCallItem = vogl_new(vogleditor_apiCallItem, pCurFrame, pTrace_packet, *pGL_packet); pCurFrame->appendCall(pCallItem); if (pPendingSnapshot != NULL) { pCallItem->set_snapshot(pPendingSnapshot); pPendingSnapshot = NULL; } vogleditor_apiCallTreeItem* item = vogl_new(vogleditor_apiCallTreeItem, funcCall, pCallItem, pCurParent); pCurParent->appendChild(item); m_itemList.append(item); if (vogl_is_swap_buffers_entrypoint(entrypoint_id)) { total_swaps++; // reset the CurParent back to the original parent so that the next frame will be at the root level pCurParent = parent; // reset the CurFrame so that a new frame node will be created on the next api call pCurFrame = NULL; } else if (vogl_is_start_nested_entrypoint(entrypoint_id)) { // Nest logically paired blocks of gl calls including terminating // nest call pCurParent = item; } else if (vogl_is_end_nested_entrypoint(entrypoint_id)) { // move the parent back one level of the hierarchy, to its own parent // (but not past Frame parent [e.g., unpaired "end" operation]) if (pCurParent->parent() != parent) pCurParent = pCurParent->parent(); } } if (pTrace_reader->get_packet_type() == cTSPTEOF) { //found_eof_packet = true; vogl_printf("Found trace file EOF packet on swap %" PRIu64 "\n", total_swaps); break; } } }
int main (int argc, char *argv[]) { flux_t h; int ch; char *cmd; log_init ("flux-kvs"); while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) { switch (ch) { case 'h': /* --help */ usage (); break; default: usage (); break; } } if (optind == argc) usage (); cmd = argv[optind++]; if (!(h = flux_open (NULL, 0))) err_exit ("flux_open"); if (!strcmp (cmd, "get")) cmd_get (h, argc - optind, argv + optind); else if (!strcmp (cmd, "type")) cmd_type (h, argc - optind, argv + optind); else if (!strcmp (cmd, "put")) cmd_put (h, argc - optind, argv + optind); else if (!strcmp (cmd, "unlink")) cmd_unlink (h, argc - optind, argv + optind); else if (!strcmp (cmd, "link")) cmd_link (h, argc - optind, argv + optind); else if (!strcmp (cmd, "readlink")) cmd_readlink (h, argc - optind, argv + optind); else if (!strcmp (cmd, "mkdir")) cmd_mkdir (h, argc - optind, argv + optind); else if (!strcmp (cmd, "exists")) cmd_exists (h, argc - optind, argv + optind); else if (!strcmp (cmd, "version")) cmd_version (h, argc - optind, argv + optind); else if (!strcmp (cmd, "wait")) cmd_wait (h, argc - optind, argv + optind); else if (!strcmp (cmd, "watch")) cmd_watch (h, argc - optind, argv + optind); else if (!strcmp (cmd, "watch-dir")) cmd_watch_dir (h, argc - optind, argv + optind); else if (!strcmp (cmd, "dropcache")) cmd_dropcache (h, argc - optind, argv + optind); else if (!strcmp (cmd, "dropcache-all")) cmd_dropcache_all (h, argc - optind, argv + optind); else if (!strcmp (cmd, "copy-tokvs")) cmd_copy_tokvs (h, argc - optind, argv + optind); else if (!strcmp (cmd, "copy-fromkvs")) cmd_copy_fromkvs (h, argc - optind, argv + optind); else if (!strcmp (cmd, "dir")) cmd_dir (h, argc - optind, argv + optind); else if (!strcmp (cmd, "dirsize")) cmd_dirsize (h, argc - optind, argv + optind); else usage (); flux_close (h); log_fini (); return 0; }
static void kod_set_os (char *arg, int from_tty, struct cmd_list_element *command) { char *p; /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones the set command passed as a parameter. The clone operation will include (BUG?) any ``set'' command callback, if present. Commands like ``info set'' call all the ``show'' command callbacks. Unfortunately, for ``show'' commands cloned from ``set'', this includes callbacks belonging to ``set'' commands. Making this worse, this only occures if add_show_from_set() is called after add_cmd_sfunc() (BUG?). */ if (cmd_type (command) != set_cmd) return; /* If we had already had an open OS, close it. */ if (gdb_kod_close) (*gdb_kod_close) (); /* Also remove the old OS's command. */ if (old_operating_system) { delete_cmd (old_operating_system, &infolist); xfree (old_operating_system); } if (! operating_system || ! *operating_system) { /* If user set operating system to empty, we want to forget we had a module open. Setting these variables is just nice for debugging and clarity. */ gdb_kod_open = NULL; gdb_kod_request = NULL; gdb_kod_close = NULL; } else { char *kodlib; old_operating_system = xstrdup (operating_system); load_kod_library (operating_system); kodlib = (*gdb_kod_open) (gdb_kod_display, gdb_kod_query); /* Add kod related info commands to gdb. */ add_info (operating_system, info_kod_command, "Displays information about Kernel Objects."); p = strrchr (kodlib, '-'); if (p != NULL) p++; else p = "Unknown KOD library"; printf_filtered ("%s - %s\n", operating_system, p); xfree (kodlib); } }
/* Menu */ static int menu_run(void) { adv_bool done; int userkey; menu_base = 0; menu_rel = 0; menu_rel_max = MENU_DY; menu_max = crtc_container_max(&the_modes); menu_base_max = menu_max - menu_rel_max; if (menu_base_max < 0) menu_base_max = 0; done = 0; while (!done) { draw_text_index(BAR_X, BAR_Y1+1, BAR_DX); draw_text_bar(BAR_X, BAR_Y1, BAR_Y2, BAR_DX); draw_text_info(INFO_X, INFO_Y, INFO_DX, INFO_DY, menu_base + menu_rel); menu_draw(MENU_X, MENU_Y, MENU_DX, MENU_DY); video_wait_vsync(); target_idle(); os_poll(); userkey = inputb_get(); switch (userkey) { case INPUTB_UP: cmd_gotopos(menu_base + menu_rel - 1); break; case INPUTB_DOWN: cmd_gotopos(menu_base + menu_rel + 1); break; case INPUTB_HOME: { int i = menu_base + menu_rel - 1; if (i<0) i = 0; while (i>0 && !(crtc_container_pos(&the_modes, i)->user_flags & MODE_FLAGS_USER_BIT0)) --i; cmd_gotopos(i); break; } case INPUTB_END: { int i = menu_base + menu_rel + 1; if (i >= menu_max) i = menu_max - 1; while (i < menu_max - 1 && !(crtc_container_pos(&the_modes, i)->user_flags & MODE_FLAGS_USER_BIT0)) ++i; cmd_gotopos(i); break; } case INPUTB_PGDN: cmd_gotopos(menu_base + menu_rel + menu_rel_max); break; case INPUTB_PGUP: cmd_gotopos(menu_base + menu_rel - menu_rel_max); break; case INPUTB_F2: cmd_save(); break; case INPUTB_LEFT : case INPUTB_RIGHT : cmd_type(userkey); break; case INPUTB_ESC: done = cmd_exit(); break; case INPUTB_SPACE: cmd_select(); cmd_gotopos(menu_base + menu_rel + 1); break; case INPUTB_ENTER: if (cmd_onvideo_test() != 0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_F9: if (cmd_onvideo_calib() != 0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_F10: if (cmd_onvideo_animate() != 0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_TAB : cmd_rename(); break; case INPUTB_F5 : if (cmd_modeline_create(1) !=0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_F6 : if (cmd_modeline_create(0) !=0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_F7 : cmd_copy(); break; case INPUTB_F8 : if (cmd_mode_clock() !=0) { text_reset(); draw_text_error(); } else { text_reset(); } break; case INPUTB_DEL : cmd_del(); cmd_gotopos(menu_base + menu_rel); break; case INPUTB_F1: draw_text_help(); break; default: if (cmd_offvideo_test(userkey) != 0) { draw_text_error(); } break; } } return userkey; }
int main (int argc, char *argv[]) { setvbuf(stdout, NULL, _IONBF, 0); // need this to see i/o at all char *buf, *init_name, *output_name, *p; const char *cmdpnt; FILE *init_file; int i, len, rdonly, recover, siz; String *cmdstr; uLong sts; if (argc > 0) pn = argv[0]; fprintf (stderr, "Copyright (C) 2001,2002,2003,2004 Mike Rieker, Beverly, MA USA\n" "Version 2004-06-10, EDT comes with ABSOLUTELY NO WARRANTY\n" "EXPECT it to FAIL when someone's HeALTh or PROpeRTy is at RISk\n\n"); fflush (stderr); /* Parse command line */ init_name = NULL; input_name = NULL; journal_file = NULL; journal_name = NULL; output_name = NULL; rdonly = 0; recover = 0; recover_file = NULL; recover_name = NULL; for (i = 1; i < argc; i ++) { /* -init <file> : process the given initialization file */ if (strcasecmp (argv[i], "-init") == 0) { if (++ i >= argc) goto usage; if (argv[i][0] == '-') goto usage; if (init_name != NULL) goto usage; init_name = argv[i]; continue; } /* -journal <file> : write journal to specified file */ /* by default, it gets written to <output_file>.edtj */ if (strcasecmp (argv[i], "-journal") == 0) { if (++ i >= argc) goto usage; if (argv[i][0] == '-') goto usage; journal_name = argv[i]; continue; } /* -noinit : don't process default init file */ if (strcasecmp (argv[i], "-noinit") == 0) { if (init_name != NULL) goto usage; init_name = ""; continue; } /* -output <file> : write output to specified file */ /* by default, it gets written to <input_file> */ if (strcasecmp (argv[i], "-output") == 0) { if (++ i >= argc) goto usage; if (argv[i][0] == '-') goto usage; output_name = argv[i]; continue; } /* -readonly : don't write an output file */ if (strcasecmp (argv[i], "-readonly") == 0) { if (output_name == input_name) output_name = NULL; rdonly = 1; continue; } /* -recover [<file>] : process recovery from file */ /* by default, recovery is processed from <input_file>.edtj */ if (strcasecmp (argv[i], "-recover") == 0) { recover = 1; if (i + 1 == argc) continue; if (argv[i+1][0] == '-') continue; if ((input_name != NULL) || (i + 2 <= argc)) recover_name = argv[++i]; continue; } /* No more options */ if (argv[i][0] == '-') goto usage; /* first and only parameter <file> : input filename */ if (input_name == NULL) { input_name = argv[i]; if (!rdonly) output_name = input_name; continue; } goto usage; } /* Open recovery file */ if (recover && (input_name == NULL)) { fprintf (stderr, "no input file specified to recover\n"); return (-1); } if (recover && (recover_name == NULL)) recover_name = os_makejnlname (input_name); if (recover_name != NULL) { recover_file = fopen (recover_name, "r"); if (recover_file == NULL) { fprintf (stderr, "error opening recovery file %s: %s\n", recover_name, strerror (errno)); return (-1); } } /* Create journal file */ if ((output_name != NULL) && (journal_name == NULL)) journal_name = os_makejnlname (output_name); if (journal_name != NULL) { journal_file = os_crenewfile (journal_name); if (journal_file == NULL) { fprintf (stderr, "error creating journal file %s: %s\n", journal_name, strerror (errno)); return (-1); } } /* Initialize os dependent routines. No using stdin/stdout/stderr from now on. */ os_initialization (); /* If input file was given, read it into a buffer and mark that buffer for writing on exit */ if (input_name != NULL) { p = input_name; if (rdonly) { p = malloc (strlen (input_name) + 12); strcpy (p, "-readonly "); strcat (p, input_name); } cmd_open (p); if (p != input_name) free (p); cur_position.line = buffer_first_line (cur_position.buffer); cur_position.offset = 0; } /* Otherwise, allocate initial 'MAIN' buffer with no lines in it */ else { cur_position.buffer = buffer_create (4, "MAIN"); cur_position.line = NULL; cur_position.offset = 0; } /* Either way, that is the one used by the EXIT command */ main_buffer = cur_position.buffer; if (output_name != NULL) buffer_setfile (main_buffer, output_name); /* Process initialization file */ if (init_name == NULL) init_name = os_defaultinitname (); /* if no -noinit or -init, get default name */ if ((init_name != NULL) && (init_name[0] != 0)) { init_file = fopen (init_name, "r"); /* try to open init file */ if (init_file != NULL) { siz = 256; /* start with 256 byte buffer */ buf = malloc (siz); len = 0; /* don't have anything in it */ while (fgets (buf + len, siz - len, init_file) != NULL) { /* read onto end of what's there */ len += strlen (buf + len); /* get total length */ if (len == 0) break; /* stop if nothing there (eof?) */ if (buf[len-1] != '\n') { /* check for line terminator */ siz += 256; /* didn't get the whole thing, increase buffer */ buf = realloc (buf, siz); /* ... then loop to read more of the line */ } else { buf[--len] = 0; /* got terminator, remove it from buffer */ cmdpnt = skipspaces (buf); /* skip leading spaces */ if (*cmdpnt != 0) ln_command (cmdpnt); /* process command line */ len = 0; /* empty line buffer for next read */ } } fclose (init_file); free (buf); } else if (errno != ENOENT) { outerr (strlen (init_name) + strlen (strerror (errno)), "error opening init file %s: %s\n", init_name, strerror (errno)); exit (-1); } } /* Type out line at current position to begin with */ cmd_type ("."); /* Read and process commands until eof */ i = 0; while (1) { cmdstr = jnl_readprompt ("\r\n*"); if (cmdstr == NULL) { /* prompt then read command line */ if (++ i < 3) outerr (0, "use either EXIT or QUIT to terminate\n"); else { outerr (12, "%d EOF's in a row or fatal terminal error, exiting ...\n", i); cmd_exit (""); exit (-1); } continue; } i = 0; for (cmdpnt = string_getval (cmdstr); *cmdpnt != 0; cmdpnt ++) if (*cmdpnt > ' ') break; if (*cmdpnt == 0) cmd_type (".+1"); /* blank line means 'type .+1' */ else ln_command (cmdpnt); /* process command */ string_delete (cmdstr); /* free the command string off */ } /* Bad command line parameter */ usage: fprintf (stderr, "usage: %s [-init <init_file>] [-journal <journal_output>] [-noinit] [-output <output_file>] [-readonly] [-recover [<journal_input>]] [<input_file>]\n", pn); return (-1); }