int main( int argc, char *argv[] ) { char line[1024]; char cmd[1024]; char arg1[1024]; char arg2[1024]; int result, args; if(argc!=3) { printf("use: %s <diskfile> <nblocks>\n",argv[0]); return 1; } if(!disk_init(argv[1],atoi(argv[2]))) { printf("couldn't initialize %s: %s\n",argv[1],strerror(errno)); return 1; } printf("opened emulated disk image %s with %d blocks\n",argv[1],disk_size()); while(1) { printf(" prompt> "); fflush(stdout); if(!fgets(line,sizeof(line),stdin)) break; if(line[0]=='\n') continue; line[strlen(line)-1] = 0; args = sscanf(line,"%s %s %s",cmd,arg1,arg2); if(args==0) continue; if(!strcmp(cmd,"format")) { if(args==1) { if(!fs_format()) { printf("disk formatted.\n"); } else { printf("format failed!\n"); } } else { printf("use: format\n"); } } else if(!strcmp(cmd,"mount")) { if(args==1) { if(!fs_mount()) { printf("disk mounted.\n"); } else { printf("mount failed!\n"); } } else { printf("use: mount\n"); } } else if(!strcmp(cmd,"debug")) { if(args==1) { fs_debug(); } else { printf("use: debug\n"); } } else if(!strcmp(cmd,"getsize")) { if(args==2) { result = fs_getsize(arg1); if(result>=0) { printf("file %s has size %d\n",arg1,result); } else { printf("getsize failed!\n"); } } else { printf("use: getsize <filename>\n"); } } else if(!strcmp(cmd,"create")) { if(args==2) { result = fs_create(arg1); if(result==0) { printf("created file %s\n",arg1); } else { printf("create failed!\n"); } } else { printf("use: create <filename>\n"); } } else if(!strcmp(cmd,"delete")) { if(args==2) { if(!fs_delete(arg1)) { printf("file %s deleted.\n",arg1); } else { printf("delete failed!\n"); } } else { printf("use: delete <filename>\n"); } } else if(!strcmp(cmd,"cat")) { if(args==2) { if(!do_copyout(arg1,"/dev/stdout")) { printf("cat failed!\n"); } } else { printf("use: cat <name>\n"); } } else if(!strcmp(cmd,"copyin")) { if(args==3) { if(do_copyin(arg1,arg2)) { printf("copied file %s to %s\n",arg1,arg2); } else { printf("copy failed!\n"); } } else { printf("use: copyin <filename in host system> <filename in fs-miei-02>\n"); } } else if(!strcmp(cmd,"copyout")) { if(args==3) { if(do_copyout(arg1,arg2)) { printf("copied myfs_file %s to file %s\n", arg1,arg2); } else { printf("copy failed!\n"); } } else { printf("use: copyout <inumber> <filename>\n"); } } else if(!strcmp(cmd,"help")) { printf("Commands are:\n"); printf(" format\n"); printf(" mount\n"); printf(" debug\n"); printf(" create\n"); printf(" delete <filename>\n"); printf(" cat <filename>\n"); printf(" getsize <filename>\n"); printf(" copyin <file name in host system> <miei02-filename>\n"); printf(" copyout <miei02-filename> <file name in host system>\n"); printf(" dump <number_of_block_with_text_contents>\n"); printf(" help\n"); printf(" quit\n"); printf(" exit\n"); } else if(!strcmp(cmd,"quit")) { break; } else if(!strcmp(cmd,"exit")) { break; } else if (!strcmp(cmd, "dump")){ if(args==2) { int blNo = atoi(arg1); printf("Dumping disk block %d\n", blNo); char b[4096]; disk_read( blNo, b); printf("------------------------------\n"); printf("%s", b); printf("\n------------------------------\n"); } else { printf("use: dump <block_number>\n"); } } else { printf("unknown command: %s\n",cmd); printf("type 'help' for a list of commands.\n"); result = 1; } } printf("closing emulated disk.\n"); disk_close(); return 0; }
int main (int argc, char **argv) { MsOle *ole; int lp, exit = 0, interact = 0; char *buffer = g_new (char, 1024) ; if (argc<2) syntax_error(0); if (!g_strcasecmp (argv [1], "regression")) { do_regression_tests (); return 0; } printf ("Ole file '%s'\n", argv[1]); if (ms_ole_open_vfs (&ole, argv[1], TRUE, NULL) != MS_OLE_ERR_OK) { printf ("Creating new file '%s'\n", argv[1]); if (ms_ole_create_vfs (&ole, argv[1], TRUE, NULL) != MS_OLE_ERR_OK) syntax_error ("Can't open file or create new one"); } if (argc<=2) syntax_error ("Need command or -i"); if (argc>2 && argv[argc-1][0]=='-' && argv[argc-1][1]=='i') interact=1; else { char *str=g_strdup(argv[2]) ; for (lp=3;lp<argc;lp++) str = g_strconcat(str," ",argv[lp],NULL); /* FIXME Mega leak :-) */ buffer = str; /* and again */ } cur_dir = g_strdup ("/"); do { char *ptr; if (interact) { fprintf (stdout,"> "); fflush (stdout); fgets (buffer, 1023, stdin); } arg_data = g_strsplit (g_strchomp (buffer), delim, -1); arg_cur = 0; if (!arg_data && interact) continue; if (!interact) printf ("Command : '%s'\n", arg_data[0]); ptr = arg_data[arg_cur++]; if (!ptr) continue; if (g_strcasecmp (ptr, "ls") == 0) list_files (ole); else if (g_strcasecmp (ptr, "cd") == 0) enter_dir (ole); else if (g_strcasecmp (ptr, "dump") == 0) do_dump (ole); else if (g_strcasecmp (ptr, "biff") == 0) do_biff (ole); else if (g_strcasecmp (ptr, "biffraw") == 0) do_biff_raw (ole); else if (g_strcasecmp (ptr, "get") == 0) do_get (ole); else if (g_strcasecmp (ptr, "put") == 0) do_put (ole); else if (g_strcasecmp (ptr, "copyin") == 0) do_copyin (ole); else if (g_strcasecmp (ptr, "copyout") == 0) do_copyout (ole); else if (g_strcasecmp (ptr, "summary") == 0) do_summary (ole); else if (g_strcasecmp (ptr, "docsummary") == 0) do_docsummary (ole); else if (g_strcasecmp (ptr, "debug") == 0) ms_ole_debug (ole, 1); else if (g_strcasecmp (ptr, "tree") == 0) ms_ole_debug (ole, 2); else if (g_strcasecmp (ptr, "vba") == 0) dump_vba (ole); else if (g_strcasecmp (ptr, "help") == 0 || g_strcasecmp (ptr, "?") == 0 || g_strcasecmp (ptr, "info") == 0 || g_strcasecmp (ptr, "man") == 0) list_commands (); else if (g_strcasecmp (ptr, "exit") == 0 || g_strcasecmp (ptr, "quit") == 0 || g_strcasecmp (ptr, "q") == 0 || g_strcasecmp (ptr, "bye") == 0) exit = 1; } while (!exit && interact); ms_ole_destroy (&ole); return 0; }
int main( int argc, char *argv[] ) { char line[1024]; char cmd[1024]; char arg1[1024]; char arg2[1024]; int inumber, result, args; if(argc!=3) { printf("use: %s <diskfile> <nblocks>\n",argv[0]); return 1; } if(!disk_init(argv[1],atoi(argv[2]))) { printf("couldn't initialize %s: %s\n",argv[1],strerror(errno)); return 1; } printf("opened emulated disk image %s with %d blocks\n",argv[1],disk_size()); while(1) { printf(" prompt> "); fflush(stdout); if(!fgets(line,sizeof(line),stdin)) break; if(line[0]=='\n') continue; line[strlen(line)-1] = 0; args = sscanf(line,"%s %s %s",cmd,arg1,arg2); if(args==0) continue; if(!strcmp(cmd,"format")) { if(args==1) { if(fs_format()) { printf("disk formatted.\n"); } else { printf("format failed!\n"); } } else { printf("use: format\n"); } } else if(!strcmp(cmd,"mount")) { if(args==1) { if(fs_mount()) { printf("disk mounted.\n"); } else { printf("mount failed!\n"); } } else { printf("use: mount\n"); } } else if(!strcmp(cmd,"umount")) { if(args==1) { if(fs_umount()) { printf("disk umounted.\n"); } else { printf("umount failed!\n"); } } else { printf("use: mount\n"); } } else if(!strcmp(cmd,"debug")) { if(args==1) { fs_debug(); } else { printf("use: debug\n"); } } else if(!strcmp(cmd,"getsize")) { if(args==2) { inumber = atoi(arg1); result = fs_getsize(inumber); if(result>=0) { printf("inode %d has size %d\n",inumber,result); } else { printf("getsize failed!\n"); } } else { printf("use: getsize <inumber>\n"); } } else if(!strcmp(cmd,"create")) { if(args==1) { inumber = fs_create(); if(inumber>=0) { printf("created inode %d\n",inumber); } else { printf("create failed!\n"); } } else { printf("use: create\n"); } } else if(!strcmp(cmd,"delete")) { if(args==2) { inumber = atoi(arg1); if(fs_delete(inumber)) { printf("inode %d deleted.\n",inumber); } else { printf("delete failed!\n"); } } else { printf("use: delete <inumber>\n"); } } else if(!strcmp(cmd,"cat")) { if(args==2) { inumber = atoi(arg1); if(!do_copyout(inumber,"/dev/stdout")) { printf("cat failed!\n"); } } else { printf("use: cat <inumber>\n"); } } else if(!strcmp(cmd,"copyin")) { if(args==3) { inumber = atoi(arg2); if(do_copyin(arg1,inumber)) { printf("copied file %s to inode %d\n",arg1,inumber); } else { printf("copy failed!\n"); } } else { printf("use: copyin <filename> <inumber>\n"); } } else if(!strcmp(cmd,"copyout")) { if(args==3) { inumber = atoi(arg1); if(do_copyout(inumber,arg2)) { printf("copied inode %d to file %s\n",inumber,arg2); } else { printf("copy failed!\n"); } } else { printf("use: copyout <inumber> <filename>\n"); } } else if(!strcmp(cmd,"help")) { printf("Commands are:\n"); printf(" format\n"); printf(" mount\n"); printf(" umount\n"); printf(" debug\n"); printf(" create\n"); printf(" delete <inode>\n"); printf(" getsize <inode>\n"); printf(" cat <inode>\n"); printf(" copyin <file> <inode>\n"); printf(" copyout <inode> <file>\n"); printf(" help\n"); printf(" quit\n"); printf(" exit\n"); } else if(!strcmp(cmd,"quit")) { break; } else if(!strcmp(cmd,"exit")) { break; } else { printf("unknown command: %s\n",cmd); printf("type 'help' for a list of commands.\n"); result = 1; } } printf("closing emulated disk.\n"); disk_close(); return 0; }