Example #1
0
		int MiniConsole::dump()
		{
			/*
			 * We dump on screen the textual console contents.
			 * We care about user set variables.
			 * */
			int co=getGlobalIntVariable(FIM_VID_CONSOLE_LINE_OFFSET);
			int lw=getGlobalIntVariable(FIM_VID_CONSOLE_LINE_WIDTH );
			int ls=getGlobalIntVariable(FIM_VID_CONSOLE_ROWS       );
			setGlobalVariable(FIM_VID_CONSOLE_BUFFER_TOTAL,bsize);
			setGlobalVariable(FIM_VID_CONSOLE_BUFFER_FREE,(int)bsize-(int)(bp-buffer));
			setGlobalVariable(FIM_VID_CONSOLE_BUFFER_USED,(int)(bp-buffer));
			// we eventually update internal variables now
			setRows(ls);
			if( lw > 0 && lw!=lwidth ) reformat(lw);
			if(co>=0)
			{
				scroll=scroll%(rows+1);
				if(scroll>0)
					return do_dump((cline-rows+1-co)>=0?(cline-(rows-scroll)+1-co):0,cline-co);
				else
					return do_dump((cline-rows+1-co)>=0?(cline-rows+1-co):0,cline-co);
			}
			else
				return do_dump(-co-1,cline);
			return -1;
		}
Example #2
0
		int MiniConsole::do_dump(int amount)const
		{
			/*
			 * We dump:
			 * 	the last amount of lines if	amount >  0
			 * 	all the lines if		amount == 0
			 * 	the first ones if		amount <  0
			 * */
			if(amount > 0)
			{
				// dumps the last amount of lines
				amount=amount>cline?cline:amount;
				do_dump(cline-amount+1,cline);
			}
			else
			if(amount ==0)
			{
				// dumps all of the lines
				do_dump(0,cline);
			}
			else
			if(amount < 0)
			{
				// dumps the first amount of lines
				if(-amount>=cline)amount+=cline;
				do_dump(0,-amount);
			}
			return 0;
		}
Example #3
0
void linux_unicast_router::check_initial_interfaces() {
    do_dump(RTM_GETLINK);

    for (std::vector<interface_desc>::const_iterator i = _interfaces.begin();
            i != _interfaces.end(); ++i) {
        _install_interface(*i);
    }

    _interfaces.clear();

    do_dump(RTM_GETROUTE);

    update_all();
}
Example #4
0
int
main (int argc, char **argv)
{
    if (argc < 2)
    {
	g_print (_("Insufficient number of command line arguments.\n"));
	usage (argc, argv);
	return 1;
    }
    setlocale (LC_ALL, "");
    g_type_init ();

    if (strcmp (argv[1], "dump") == 0)
    {
	return do_dump (argc, argv);
    }
    if (strcmp (argv[1], "add") == 0)
    {
	return do_add (argc, argv);
    }
    if (strcmp (argv[1], "list") == 0)
    {
	return do_list (argc, argv);
    }
    if (strcmp (argv[1], "remove") == 0)
    {
	return do_remove (argc, argv);
    }

    g_print (_("Unknown command '%s'\n"), argv[1]);
    usage (argc, argv);
    return 1;
}
Example #5
0
int main(int argc, char *argv[]) {
    int c;
    int dump_flags = 0;
    char *filename = DEFAULT_FILE;
    
    while ((c=getopt(argc, argv, "hvf:elo")) != EOF) {
	switch (c) {
	case 'h':
	case 'v': usage(argv[0]); exit(0);
	case 'f': filename = optarg; break;
	case 'e': dump_flags |= VMAD_DUMP_EXEC; break;
	case 'l': dump_flags |= VMAD_DUMP_LIBS; break;
	case 'o': dump_flags |= VMAD_DUMP_OTHER; break;
	default: exit(1);
	}
    }

    while (1) {
	int r;
	printf("Doing vmadump(\"%s\", 0x%x)=", filename, dump_flags); fflush(stdout);
	r = do_dump(filename, dump_flags);
	if (r > 0) {
	    printf("%d\n", r);
	    printf("Doing vmaundump(\"%s\")\n", filename);
	    fflush(stdout);
	    do_undump(filename);
	    /* not reached */
	}
	close(3); /* hack to deal with the lack of close_on_exec */
    }
}
Example #6
0
void decrypt_and_dump_self(char *selfFile, char *saveFile) {
    int fd = open(selfFile, O_RDONLY, 0);
    if (fd != -1) {
        void *addr = mmap(0, 0x4000, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
        if (addr != MAP_FAILED) {
            printfsocket("mmap %s : %p\n", selfFile, addr);

            uint16_t snum = *(uint16_t*)((uint8_t*)addr + 0x18);
            Elf64_Ehdr *ehdr = (Elf64_Ehdr *)((uint8_t*)addr + 0x20 + snum * 0x20);
            printfsocket("ehdr : %p\n", ehdr);

            // shdr fix
            ehdr->e_shoff = ehdr->e_shentsize = ehdr->e_shnum = ehdr->e_shstrndx = 0;

            Elf64_Phdr *phdrs = (Elf64_Phdr *)((uint8_t *)ehdr + 0x40);
            printfsocket("phdrs : %p\n", phdrs);

            int segBufNum = 0;
            SegmentBufInfo *segBufs = parse_phdr(phdrs, ehdr->e_phnum, &segBufNum);
            do_dump(saveFile, fd, segBufs, segBufNum, ehdr);
            printfsocket("dump completed\n");

            free(segBufs);
            munmap(addr, 0x4000);
        }
        else {
            printfsocket("mmap file %s err : %s\n", selfFile, strerror(errno));
        }
        close(fd);
    }
    else {
        printfsocket("open %s err : %s\n", selfFile, strerror(errno));
    }
}
Example #7
0
		int MiniConsole::do_dump()const
		{
			/*
			 * We dump on screen the textual console contents.
			 * */
			return do_dump((cline-rows+1)>=0?(cline-rows+1):0,cline);
		}
Example #8
0
/*
**  Name:	int dpeth_task(void)
**  Function:	Main entry for dp task
*/
PUBLIC int main(int argc, char **argv)
{
  message m;
  int ipc_status;
  int rc;

  /* SEF local startup. */
  env_setargs(argc, argv);
  sef_local_startup();

  while (TRUE) {
	if ((rc = netdriver_receive(ANY, &m, &ipc_status)) != OK){
		panic(RecvErrMsg, rc);
	}

	DEBUG(printf("eth: got message %d, ", m.m_type));

	if (is_ipc_notify(ipc_status)) {
		switch(_ENDPOINT_P(m.m_source)) {
			case CLOCK:
				/* to be defined */
				do_watchdog(&m);
				break;
			case HARDWARE:
				/* Interrupt from device */
				handle_hw_intr();
				break;
			case TTY_PROC_NR:
				/* Function key pressed */
				do_dump(&m);
				break;
			default:	
				/* Invalid message type */
				panic(TypeErrMsg, m.m_type);
				break;
		}
		/* message processed, get another one */
		continue;
	}

	switch (m.m_type) {
	    case DL_WRITEV_S:	/* Write message to device */
		do_vwrite_s(&m);
		break;
	    case DL_READV_S:	/* Read message from device */
		do_vread_s(&m);
		break;
	    case DL_CONF:	/* Initialize device */
		do_init(&m);
		break;
	    case DL_GETSTAT_S:	/* Get device statistics */
		do_getstat_s(&m);
		break;
	    default:		/* Invalid message type */
		panic(TypeErrMsg, m.m_type);
		break;
	}
  }
  return OK;			/* Never reached, but keeps compiler happy */
}
Example #9
0
int main(int argc, char **argv)
{
	prog_name = argv[0];
	decode_arguments(argc, argv);

	switch (operation) {

	/* calls to libdlm; pass a command to dlm-kernel */

	case OP_JOIN:
		do_join(lsname);
		break;

	case OP_LEAVE:
		do_leave(lsname);
		break;

	case OP_JOINLEAVE:
		do_join(lsname);
		do_leave(lsname);
		break;

	/* calls to libdlmcontrol; pass a command/query to dlm_controld */

	case OP_LIST:
		do_list(lsname);
		break;

	case OP_DUMP:
		do_dump();
		break;

	case OP_LOG_PLOCK:
		do_log_plock();
		break;

	case OP_PLOCKS:
		do_plocks(lsname);
		break;

	case OP_DEADLOCK_CHECK:
		do_deadlock_check(lsname);
		break;

	/* calls to read debugfs; query info from dlm-kernel */

	case OP_LOCKDUMP:
		do_lockdump(lsname);
		break;

	case OP_LOCKDEBUG:
		do_lockdebug(lsname);
		break;
	}
	return 0;
}
Example #10
0
static size_t dump(const parse_frame *f, int options, FILE *out)
{
  const cdp *c = (cdp *)f->off;
  int bytes = fprintf(out,
    "%s ver=%u ttl=%u chksum=0x%04x",
    Iface_CDP.shortname, c->version, c->ttl, c->chksum);
  bytes += do_dump(f, (char *)c + sizeof *c, f->len - sizeof *c, out);
  fputc('\n', out);
  bytes++;
  return (size_t)bytes;
}
Example #11
0
File: smb.c Project: epok76/lanmap2
size_t smb_dump(const parse_frame *f, int opt, FILE *out)
{
  const smb_hdr *h = (smb_hdr *)f->off;
  int bytes = fprintf(out,
    "%s cmd=0x%02x() err=%u errcode=%hu "
    "lckrd=%u rcvbufpst=%u casesens=%u canonpath=%u oplck=%u notify=%u reqresp=%u\n",
    Iface_SMB.shortname, h->cmd, h->err, ntohs((u16)((h->errcode[0] << 8) | h->errcode[1])),
    h->lckrd, h->rcvbufpst, h->casesens, h->canonpath, h->oplck, h->notify, h->reqresp);
  bytes += do_dump(f, (char *)h + sizeof *h, f->len - sizeof *h, opt, out, h);
  return (size_t)bytes;
}
Example #12
0
static int do_show(int argc, char **argv)
{
	int ifindex;

	if (argc == 0)
		return do_dump(0);

	ifindex = ll_name_to_index(*argv);
	if (ifindex == 0) {
		fprintf(stderr, "Device \"%s\" does not exist.\n", *argv);
		return -1;
	}

	argc--, argv++;
	if (argc == 0)
		return do_dump(ifindex);

	ipmacsec_usage();
	return -1;
}
int main(int argc, char *argv[]) {
    int fd, r,c ;
    int dump=-1;
    int dump_flags = 0;
    int fpop = 0;
    char *filename = DEFAULT_FILE;
    
    while ((c=getopt(argc, argv, "hvf:Fduelox")) != EOF) {
	switch (c) {
	case 'h':
	case 'v': usage(argv[0]); exit(0);
	case 'f': filename = optarg; break;
	case 'd': dump = 0; break;
	case 'u': dump = 1; break;
	case 'x': dump = 2; break;
	case 'e': dump_flags |= VMAD_DUMP_EXEC; break;
	case 'l': dump_flags |= VMAD_DUMP_LIBS; break;
	case 'o': dump_flags |= VMAD_DUMP_OTHER; break;
	case 'F': fpop = 1; break;
	default: exit(1);
	}
    }

    if (fpop) {
	double a, b;
	a = 5.3; 
	b = getpid();
	c = a * b;
    }

    switch (dump) {
    case 0:
	/* Set a sighandler to test sighandler save/restore */
	signal(SIGUSR1, (void (*)(int)) sighandler);
	do_dump(filename, dump_flags);
	break;

    case 1:
	printf("Undumping from: %s\n", filename);
	fd = open(filename, O_RDONLY);
	if (fd == -1) { perror("open"); exit(1); }
	r = vmaundump(fd);
	printf("VMAD_DO_UNDUMP failed: err=%d (%s)\n",
	       errno, strerror(errno));
	break;
    case 2:
	do_execdump(filename, dump_flags, argv);
	break;
    default:
	usage(argv[0]);
	exit(0);
  }
  exit(1);
}
Example #14
0
/*******************************************************************
 *          parse_options
 *
 * Parse options from the argv array
 */
static void parse_options (char *argv[])
{
  const struct my_option *opt;
  char *const *ptr;
  const char *arg = NULL;

  ptr = argv + 1;

  while (*ptr != NULL)
  {
    for (opt = option_table; opt->name; opt++)
    {
     if (globals.mode != NONE && opt->mode != NONE && globals.mode != opt->mode)
       continue;
     if (((opt->has_arg == 1) && !strncmp (*ptr, opt->name, strlen (opt->name))) ||
	 ((opt->has_arg == 2) && !strcmp (*ptr, opt->name)))
      {
        arg = *ptr + strlen (opt->name);
        if (*arg == '\0') arg = *++ptr;
        break;
      }
      if (!strcmp (*ptr, opt->name))
      {
        arg = NULL;
        break;
      }
    }

    if (!opt->name)
    {
        if ((*ptr)[0] == '-')
            fatal ("Unrecognized option");
        if (globals.input_name != NULL)
            fatal ("Only one file can be treated at once");
        globals.input_name = *ptr;
    }
    else if (opt->has_arg && arg != NULL)
	opt->func (arg);
    else
	opt->func ("");

    ptr++;
  }

  if (globals.mode == SPEC && globals.do_code && !globals.directory)
    fatal ("-I must be used if generating code");

  if (VERBOSE && QUIET)
    fatal ("Options -v and -q are mutually exclusive");

  if (globals.mode == NONE)
      do_dump("");
}
Example #15
0
int main(int argc, char* argv[]) {
   if(argc > 7 || argc < 4) {
      print_usage(argv[0]);
      return 1;
   }

   if(strcmp(argv[1], "dump") == 0) {
      if(argc != 5) {
         print_usage(argv[0]);
         return 1;
      }

      if(startup(0, 0))
         return 1;

      if(do_dump(argv[4], argv[2], argv[3]))
         return 1;

      return 0;
   } else if(strcmp(argv[1], "dis") == 0) {
      char*    mem_file = 0;
      uint32_t mem_offset;

      if(argc == 7) {
         if(strcmp(argv[4], "--file") == 0) {
            mem_file = argv[5];
            if(sscanf(argv[6], "0x%x", &mem_offset) != 1) {
               fprintf(stderr, "mem_base must be of the form 0x1234abcd\n");
               return 1;
            }
         } else {
            print_usage(argv[0]);
            return 1;
         }
      } else if(argc != 4) {
         print_usage(argv[0]);
         return 1;
      }

      if(startup(mem_file, mem_offset))
         return 1;

      if(do_dis(argv[2], argv[3]))
         return 1;

      return 0;
   } else {
      fprintf(stderr, "Invalid command %s\n", argv[1]);
      return 1;
   }

   return 0;
}
Example #16
0
File: xbee.cpp Project: jwatte/xbee
int main(int argc, char * const *argv) {

    int opt = 0;

    //  getopt treats argv interstingly
    while ((opt = getopt(argc, argv, "b:p:")) != -1) {
        switch (opt) {
        case 'b':
            baud = optarg;
            break;
        case 'p':
            port = optarg;
            break;
        default:
            usage();
            break;
        }
    }

    int baudi = atoi(baud);
    int bval = lookup_baud(baudi);
    if (bval <= 0) {
        fprintf(stderr, "Not a recognized baud rate: %s\n", baud);
        exit(EXIT_FAILURE);
    }

    if (optind >= argc) {
        usage();
    }
    command = argv[optind++];
    if (optind < argc) {
        filename = argv[optind++];
    }
    if (optind < argc) {
        usage();
    }

    openport(bval);

    if (!strcmp(command, "dump")) {
        do_dump();
    }
    else if (!strcmp(command, "load")) {
        do_load();
    }
    else {
        fprintf(stderr, "unknown command '%s'\n", command);
        usage();
    }

    return EXIT_SUCCESS;
}
Example #17
0
static int store_file_dump(void)
{
    int retval;

    debug("bb.store", 0, "Dumping %ld messages to store",
	  dict_key_count(sms_dict));
    mutex_lock(file_mutex);
    if (file != NULL) {
        fclose(file);
        file = NULL;
    }
    retval = do_dump();
    mutex_unlock(file_mutex);

    return retval;
}
gint main (gint argc, gchar **argv)
{
	if (argc < 2)
		do_usage (argv[0]);

	camel_init (NULL, 0);

	if (!strcmp(argv[1], "compress"))
		return do_compress (argc, argv);
	else if (!strcmp(argv[1], "dump"))
		return do_dump (argc, argv);
	else if (!strcmp(argv[1], "info"))
		return do_info (argc, argv);
	else if (!strcmp(argv[1], "check"))
		return do_check (argc, argv);
	else if (!strcmp(argv[1], "perf"))
		return do_perf (argc, argv);

	do_usage (argv[0]);
	return 1;
}
Example #19
0
int main(int argc, char *argv[])
{
	prog_name = basename(argv[0]);

	decode_arguments(argc, argv);

	switch (operation) {
	case OP_JOIN:
		do_join(argc, argv);
		break;
	case OP_LEAVE:
		do_leave();
		break;
	case OP_DUMP:
		do_dump();
		break;
	case OP_LIST:
		do_list();
		break;
	}

	return EXIT_FAILURE;
}
Example #20
0
int main(int argc, char **argv)
{
	decode_arguments(argc, argv);

	switch (operation) {

	case OP_LEAVE:
		do_leave(fsname);
		break;

	case OP_LIST:
		do_list(fsname);
		break;

	case OP_DUMP:
		do_dump();
		break;

	case OP_PLOCKS:
		do_plocks(fsname);
		break;
	}
	return 0;
}
Example #21
0
static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags,
                       ASN1_STRING *str)
{
    int outlen, len;
    int type;
    char quotes;
    unsigned char flags;
    quotes = 0;
    /* Keep a copy of escape flags */
    flags = (unsigned char)(lflags & ESC_FLAGS);

    type = str->type;

    outlen = 0;

    if (lflags & ASN1_STRFLGS_SHOW_TYPE) {
        const char *tagname;
        tagname = ASN1_tag2str(type);
        outlen += strlen(tagname);
        if (!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1))
            return -1;
        outlen++;
    }

    /* Decide what to do with type, either dump content or display it */

    /* Dump everything */
    if (lflags & ASN1_STRFLGS_DUMP_ALL)
        type = -1;
    /* Ignore the string type */
    else if (lflags & ASN1_STRFLGS_IGNORE_TYPE)
        type = 1;
    else {
        /* Else determine width based on type */
        if ((type > 0) && (type < 31))
            type = tag2nbyte[type];
        else
            type = -1;
        if ((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN))
            type = 1;
    }

    if (type == -1) {
        len = do_dump(lflags, io_ch, arg, str);
        if (len < 0)
            return -1;
        outlen += len;
        return outlen;
    }

    if (lflags & ASN1_STRFLGS_UTF8_CONVERT) {
        /*
         * Note: if string is UTF8 and we want to convert to UTF8 then we
         * just interpret it as 1 byte per character to avoid converting
         * twice.
         */
        if (!type)
            type = 1;
        else
            type |= BUF_TYPE_CONVUTF8;
    }

    len = do_buf(str->data, str->length, type, flags, &quotes, io_ch, NULL);
    if (len < 0)
        return -1;
    outlen += len;
    if (quotes)
        outlen += 2;
    if (!arg)
        return outlen;
    if (quotes && !io_ch(arg, "\"", 1))
        return -1;
    if (do_buf(str->data, str->length, type, flags, NULL, io_ch, arg) < 0)
        return -1;
    if (quotes && !io_ch(arg, "\"", 1))
        return -1;
    return outlen;
}
Example #22
0
 void dump(const std::string& folder) const
 {   return do_dump(folder);   }
Example #23
0
int gfsc_dump_plocks(char *name, char *buf)
{
	return do_dump(GFSC_CMD_DUMP_PLOCKS, name, buf);
}
int
main (int argc, char **argv)
{
	int exit = 0;
	char *buffer = g_new (char, 1024) ;
	GIOChannel *ioc;
	guint watch_id = 0;
	GOptionContext *ctx = NULL;
	GError *error = NULL;

	/* default to interactive on a terminal */
	interactive = isatty (0);

	ctx = g_option_context_new("test-vfs");
	g_option_context_add_main_entries(ctx, options, NULL);

	if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
		g_printerr("main: %s\n", error->message);

		g_error_free(error);
		g_option_context_free(ctx);
		return 1;
	}

	g_option_context_free(ctx);

	files = g_hash_table_new (g_str_hash, g_str_equal);

	if (noninteractive)
		interactive = FALSE;

	if (interactive)
		vfserr = stderr;
	else
		vfserr = stdout;

	if (!mate_vfs_init ()) {
		fprintf (vfserr, "Cannot initialize mate-vfs.\n");
		return 1;
	}
	mate_vfs_module_callback_push
		(MATE_VFS_MODULE_CALLBACK_AUTHENTICATION,
		 authentication_callback, NULL, NULL);

	if (argc == 1)
		cur_dir = g_get_current_dir ();
	else
		cur_dir = g_strdup(argv[1]);

	if (cur_dir && !G_IS_DIR_SEPARATOR (cur_dir [strlen (cur_dir) - 1]))
		cur_dir = g_strconcat (cur_dir, G_DIR_SEPARATOR_S, NULL);

	if (interactive == TRUE) {
		main_loop = g_main_loop_new (NULL, TRUE);
		ioc = g_io_channel_unix_new (0 /* stdin */);
		g_io_channel_set_encoding (ioc, NULL, NULL);
		g_io_channel_set_buffered (ioc, FALSE);
		watch_id = g_io_add_watch (ioc,
					   G_IO_IN | G_IO_HUP | G_IO_ERR,
					   callback, buffer);
		g_io_channel_unref (ioc);
	}

	while (!exit) {
		char *ptr;

		if (interactive) {
			fprintf (stdout,"\n%s > ", cur_dir);
			fflush (stdout);

			strcpy (buffer, "");
			g_main_loop_run (main_loop);
		} else {
			/* In non-interactive mode we just do this evil
			 * thingie */
			buffer[0] = '\0';
			fgets (buffer, 1023, stdin);
			if (!buffer [0]) {
				exit = 1;
				continue;
			}
		}

		if (!buffer || buffer [0] == '#')
			continue;

		arg_data = g_strsplit (g_strchomp (buffer), delim, -1);
		arg_cur  = 0;
		if ((!arg_data || !arg_data[0]) && interactive) continue;
		if (!interactive)
			printf ("Command : '%s'\n", arg_data [0]);
		ptr = arg_data[arg_cur++];
		if (!ptr)
			continue;

		if (g_ascii_strcasecmp (ptr, "ls") == 0)
			do_ls ();
		else if (g_ascii_strcasecmp (ptr, "cd") == 0)
			do_cd ();
		else if (g_ascii_strcasecmp (ptr, "dump") == 0)
			do_dump ();
		else if (g_ascii_strcasecmp (ptr, "type") == 0 ||
			 g_ascii_strcasecmp (ptr, "cat") == 0)
			do_cat ();
		else if (g_ascii_strcasecmp (ptr, "cp") == 0)
			do_cp ();
		else if (g_ascii_strcasecmp (ptr, "rm") == 0)
			do_rm ();
		else if (g_ascii_strcasecmp (ptr, "mkdir") == 0)
			do_mkdir ();
		else if (g_ascii_strcasecmp (ptr, "rmdir") == 0)
			do_rmdir ();
		else if (g_ascii_strcasecmp (ptr, "mv") == 0)
			do_mv ();
		else if (g_ascii_strcasecmp (ptr, "info") == 0 ||
			 g_ascii_strcasecmp (ptr, "stat") == 0)
			do_info ();
		else if (g_ascii_strcasecmp (ptr, "findtrash") == 0)
			do_findtrash ();
		else if (g_ascii_strcasecmp (ptr, "ssl") == 0)
			do_ssl ();
		else if (g_ascii_strcasecmp (ptr, "sync") == 0)
			fprintf (vfserr, "a shell is like a boat, it lists or syncs (RMS)\n");
		else if (g_ascii_strcasecmp (ptr,"help") == 0 ||
			 g_ascii_strcasecmp (ptr,"?")    == 0 ||
			 g_ascii_strcasecmp (ptr,"info") == 0 ||
			 g_ascii_strcasecmp (ptr,"man")  == 0)
			list_commands ();
		else if (g_ascii_strcasecmp (ptr,"exit") == 0 ||
			 g_ascii_strcasecmp (ptr,"quit") == 0 ||
			 g_ascii_strcasecmp (ptr,"q")    == 0 ||
			 g_ascii_strcasecmp (ptr,"bye") == 0)
			exit = 1;

		/* File ops */
		else if (g_ascii_strcasecmp (ptr, "open") == 0)
			do_open ();
		else if (g_ascii_strcasecmp (ptr, "create") == 0)
			do_create ();
		else if (g_ascii_strcasecmp (ptr, "close") == 0)
			do_close ();
		else if (g_ascii_strcasecmp (ptr, "handleinfo") == 0)
			do_handleinfo ();
		else if (g_ascii_strcasecmp (ptr, "read") == 0)
			do_read ();
		else if (g_ascii_strcasecmp (ptr, "seek") == 0)
			do_seek ();
		
		else
			fprintf (vfserr, "Unknown command '%s'", ptr);

		g_strfreev (arg_data);
		arg_data = NULL;
	}

	if (interactive) {
		g_source_remove (watch_id);
		g_main_loop_unref (main_loop);
		main_loop = NULL;
	}

	g_free (buffer);
	g_free (cur_dir);

	close_files ();

	return 0;
}
Example #25
0
void debug_parse(char *cmd_line)
{
	int params, result;
	unsigned int temp1,temp2,temp3,temp4;
	unsigned short tempword;
	unsigned char tempbyte;

	while (*cmd_line == ' ') cmd_line++;

	switch (toupper(*cmd_line++))
	{
	case '?':
		DebugPrint("\r\n Compile Date: %s, Time: %s",__DATE__,__TIME__);
		break;
	case 'A':  // assemble
		break;
	case 'B':
		break;
	case 'C':  // compare
		break;
	case 'D':  // dump
		params = sscanf(cmd_line,"%X %X",&temp2,&temp3);
		switch (params) {
		case 0:
			case EOF:
			dump_end = dump_beg + 127;
			do_dump();
			break;
		case 1:
			dump_beg = temp2;
			dump_end = dump_beg + 127;
			do_dump();
			break;
		case 2:
			if (temp3<temp2) temp3=temp2;
			dump_beg = temp2;
			dump_end = temp3;
			do_dump();
			break;
		}
		break;
	case 'E':  // read unsigned int
		if (sscanf(cmd_line,"%X",&temp1)==1)
			debug_port = (unsigned char*)(temp1&0xFFFFFFFC);
		temp2 = *(unsigned int*)debug_port;
		DebugPrint("\r\n %08X -> %08X",(int)debug_port,temp2);
//		debug_port += sizeof(int);
		break;
	case 'F':  // fill
		params = sscanf(cmd_line,"%X %X %X",&temp2,&temp3,&temp4);
		switch (params) {
		case 3:
			dump_end = temp3;
			for (old_dump_beg=temp2;old_dump_beg<=dump_end;old_dump_beg++)
			{
//				pokeb(dump_seg,old_dump_beg,temp4);
			}
			break;
		default:
			{
				DebugSend(" ?? \r\n");
			}
			break;
		}
		break;
	case 'G':  // go
		DebugInit();
		break;
	case 'H':  // hex
		break;
	case 'I':  // read byte
		break;
	case 'J':  // read word
		break;
	case 'K':
		break;
	case 'L':  // load
		break;
	case 'M':  // write unsigned int
		if (sscanf(cmd_line,"%X %X",&temp1,&temp2)==2)
		{
			debug_port = (unsigned char*)(temp1&0xFFFFFFFC);
			DebugPrint("\r\n %08X <- %08X",(int)debug_port,temp2);
			*(unsigned int*)debug_port = temp2;
			debug_port += sizeof(int);
		}
		else
		{
			DebugSend(" ?? \r\n");
		}
		break;
	case 'N':  // name
		break;
	case 'O':  // output byte
		if (sscanf(cmd_line,"%X %X",&temp1,&temp2)==2)
		{
			debug_port = (unsigned char*)temp1;
			tempbyte = temp2;
			DebugPrint("\r\n %08X <- %02X",(int)debug_port,tempbyte);
			*debug_port = tempbyte;
			debug_port += sizeof(tempbyte);
		}
		else
		{
			DebugSend(" ?? \r\n");
		}
		break;
	case 'P':  // proceed
		if (sscanf(cmd_line,"%d",&temp1)==1)
		{
			gain_Ap = temp1;
		}
		DebugPrint("\r\n gain_Ap = %5.1f",gain_Ap);
		break;
	case 'Q':  // quit
		if (sscanf(cmd_line,"%d",&temp1)==1)
		{
			gain_Ai = temp1;
		}
		DebugPrint("\r\n gain_Ai = %5.1f",gain_Ai);
		break;
	case 'R':  // register
		if (sscanf(cmd_line,"%d",&temp1)==1)
		{
			gain_Ad = temp1;
		}
		DebugPrint("\r\n gain_Ad = %5.1f",gain_Ad);
		break;
	case 'S':  // search
		if (sscanf(cmd_line,"%X",&temp2)==1)
		{
		}
		break;
	case 'T':  // Test
		if (sscanf(cmd_line,"%X",&temp1)==1)
		{
			switch (temp1){
			case 0:
				#ifdef	_MPU6050_H_			
				result = MPU6050_Setup();
				if (result==STATUS_OK)
				{
					DebugPrint("\r\n MPU6050 Init Success!");
				}
				else
				{
					DebugPrint("\r\n MPU6050 Init Fail. Error = %i", result);
				}
				#endif
				break;
			case 1:
				break;
			case 2:
				break;
			case 3:
				break;
			case 4:
				break;
			case 5:
				break;
			case 6:
				break;
			case 7:
				break;
			case 8:
				break;
			case 9:
				break;
			}
		}
		else
		{
			bTest = !bTest;
			if (bTest)
			{
				DebugPrint("\r\n Test ON!");
				ResetTimer(DEBUG_TIMER);
				StartTimer(DEBUG_TIMER,50);
			}
			else
			{
				DebugPrint("\r\n Test OFF!");
			}
		}
		break;
	case 'U':
		if (sscanf(cmd_line,"%d %d",&temp1,&temp2)==2)
		{
			DebugPrint("\r\n L298_set_speed(%d,%d)", temp1, temp2);
			L298_set_speed(temp1,temp2);
		}
		else
		if (sscanf(cmd_line,"%X",&temp1)==1)
		{
			switch (temp1){
			case 0:
				break;
			case 1:
				break;
			case 2:
				break;
			case 3:
				break;
			case 4:
				break;
			case 5:	//U5
				break;
			case 6:	//U6
				break;
			case 7:	//U7
				break;
			case 8:
				break;
			case 9:
				break;
			}
		}
		else
		{
		}
		break;
	case 'W':  // write word
		if (sscanf(cmd_line,"%X %X",&temp1,&temp2)==2)
		{
			debug_port = (unsigned char*)(temp1&0xFFFFFFFE);
			tempword = temp2;
			DebugPrint("\r\n %08X <- %04X",(int)debug_port,tempword);
			*(unsigned short*)debug_port = tempword;
			debug_port += sizeof(tempword);
		}
		else
		{
			DebugSend(" ?? \r\n");
		}
		break;
	case 'X':
		if (sscanf(cmd_line,"%X",&temp1)==1)
		{
			switch (temp1){
			case 0:
				break;
			case 1:
				break;
			case 2:
				break;
			case 3:
				break;
			case 4:
				break;
			case 5:
				break;
			case 6:
				break;
			case 7:
				break;
			case 8:
				break;
			case 9:
				break;
			}
		}
		else
		{
		}
		break;
	case 'Y':
		temp4 = sscanf(cmd_line,"%X %X",&temp1,&temp2);
		if (temp4>=1)
		{
			switch (temp1){
			case 0:
				break;
			case 1:
				break;
			case 2:
				break;
			case 3:
				break;
			case 4:
				break;
			case 5:
				break;
			case 6:
				break;
			case 7:
				break;
			case 8:
				break;
			case 9:
				break;
			}
		}
		else
		{
		}
		break;
	case 'Z':
		debug_main_Z(cmd_line);
		break;
	default:
		;
	}
}
Example #26
0
void do_quit(void)
{
    do_stop();
    do_dump();
    exit(0);
}
Example #27
0
void process_cli_data()
{
    int ret;
    ret = read(cli.in, buf, RXBUF);
    buf[ret]=0;
    if(buf[ret-1] == '\n')
        buf[ret-1] = 0;
    int done = 0;
    if ( !strncasecmp((char *)buf, "help", 4) )
    {
        print_help();
        done = 1;
    }
    if ( !strncasecmp((char *)buf, "fpscan", 6) )
    {
        do_fpscan();
        done = 1;
    }
    if ( !strncasecmp((char *)buf, "callscan", 8) )
    {
        do_callscan();
        done = 1;
    }
    if ( !strncasecmp((char *)buf, "autorec", 7) )
    {
        do_autorec();
        done = 1;
    }
    if ( !strncasecmp((char *)buf, "ppscan", 6) )
    {
        do_ppscan_str(&buf[6]);
        done = 1;
    }
    if ( !strncasecmp((char *)buf, "chan", 4) )
    {
        do_chan(&buf[4]);
        done = 1;
    }
    if ( !strncasecmp((char *)buf, "slot", 4) )
    {
        do_slot(&buf[4]);
        done = 1;
    }
    if ( !strncasecmp((char *)buf, "jam", 3) )
    {
        do_jam();
        done = 1;
    }
    if ( !strncasecmp((char *)buf, "ignore", 6) )
    {
        do_ignore_str(&buf[6]);
        done = 1;
    }
    if ( !strncasecmp((char *)buf, "dump", 4) )
    {
        do_dump();
        done = 1;
    }
    if ( !strncasecmp((char *)buf, "hop", 3) )
    {
        do_hop();
        done = 1;
    }
    if ( !strncasecmp((char *)buf, "audio", 5) )
    {
        do_audio();
        done = 1;
    }
    if ( !strncasecmp((char *)buf, "direction", 9) )
    {
        do_direction();
        done = 1;
    }
    if ( !strncasecmp((char *)buf, "wav", 3) )
    {
        do_wav();
        done = 1;
    }
    if ( !strncasecmp((char *)buf, "ima", 3) )
    {
        do_ima();
        done = 1;
    }
    if ( !strncasecmp((char *)buf, "verb", 4) )
    {
        do_verb();
        done = 1;
    }
    if ( !strncasecmp((char *)buf, "stop", 4) )
    {
        do_stop();
        done = 1;
    }
    if ( !strncasecmp((char *)buf, "quit", 4) )
        do_quit();

    if(!done)
        LOG("!!! no such command %s\n", buf);

}
Example #28
0
/*
 *	The function "mon()" is the dialog user interface, called
 *	from the simulation just after program start.
 */
void mon(void)
{
	register int eoj = 1;
	static char cmd[LENCMD];

	tcgetattr(0, &old_term);

	if (x_flag) {
		if (do_getfile(xfn) == 0)
			do_go();
	}
	while (eoj) {
		next:
		printf(">>> ");
		fflush(stdout);
		if (fgets(cmd, LENCMD, stdin) == NULL) {
			putchar('\n');
			goto next;
		}
		switch (*cmd) {
		case '\n':
			do_step();
			break;
		case 't':
			do_trace(cmd + 1);
			break;
		case 'g':
			do_go();
			break;
		case 'd':
			do_dump(cmd + 1);
			break;
		case 'l':
			do_list(cmd + 1);
			break;
		case 'm':
			do_modify(cmd +	1);
			break;
		case 'f':
			do_fill(cmd + 1);
			break;
		case 'v':
			do_move(cmd + 1);
			break;
		case 'x':
			do_reg(cmd + 1);
			break;
		case 'p':
			do_port(cmd + 1);
			break;
		case 'b':
			do_break(cmd + 1);
			break;
		case 'h':
			do_hist(cmd + 1);
			break;
		case 'z':
			do_count(cmd + 1);
			break;
		case 'c':
			do_clock();
			break;
		case 's':
			do_show();
			break;
		case '?':
			do_help();
			break;
		case 'r':
			do_getfile(cmd + 1);
			break;
		case '!':
			do_unix(cmd + 1);
			break;
		case 'q':
			eoj = 0;
			break;
		default:
			puts("what??");
			break;
		}
	}
}
Example #29
0
void
process_command(int descr, dbref player, char *command)
{
	char *arg1;
	char *arg2;
	char *full_command;
	char *p;					/* utility */
	char pbuf[BUFFER_LEN];
	char xbuf[BUFFER_LEN];
	char ybuf[BUFFER_LEN];
	struct timeval starttime;
	struct timeval endtime;
	double totaltime;

	if (command == 0)
		abort();

	/* robustify player */
	if (player < 0 || player >= db_top ||
		(Typeof(player) != TYPE_PLAYER && Typeof(player) != TYPE_THING)) {
		log_status("process_command: bad player %d", player);
		return;
	}

	if ((tp_log_commands || Wizard(OWNER(player)))) {
		if (!(FLAGS(player) & (INTERACTIVE | READMODE))) {
			if (!*command) {
				return; 
			}
			log_command("%s: %s", whowhere(player), command);
		} else {
			if (tp_log_interactive) {
				log_command("%s: %s%s", whowhere(player),
						(FLAGS(player) & (READMODE)) ? "[READ] " : "[INTERP] ", command);
			}
		}
	}

	if (FLAGS(player) & INTERACTIVE) {
		interactive(descr, player, command);
		return;
	}
	/* eat leading whitespace */
	while (*command && isspace(*command))
		command++;

	/* Disable null command once past READ line */
	if (!*command)
		return;

	/* check for single-character commands */
	if (!tp_enable_prefix) {
		if (*command == SAY_TOKEN) {
			snprintf(pbuf, sizeof(pbuf), "say %s", command + 1);
			command = &pbuf[0];
		} else if (*command == POSE_TOKEN) {
			snprintf(pbuf, sizeof(pbuf), "pose %s", command + 1);
			command = &pbuf[0];
		} else if (*command == EXIT_DELIMITER) {
			snprintf(pbuf, sizeof(pbuf), "delimiter %s", command + 1);
			command = &pbuf[0];
		}
	}

	/* profile how long command takes. */
	gettimeofday(&starttime, NULL);

	/* if player is a wizard, and uses overide token to start line... */
	/* ... then do NOT run actions, but run the command they specify. */
	if (!(TrueWizard(OWNER(player)) && (*command == OVERIDE_TOKEN))) {
		if (can_move(descr, player, command, 0)) {
			do_move(descr, player, command, 0);	/* command is exact match for exit */
			*match_args = 0;
			*match_cmdname = 0;
		} else {
			if (tp_enable_prefix) {
				if (*command == SAY_TOKEN) {
					snprintf(pbuf, sizeof(pbuf), "say %s", command + 1);
					command = &pbuf[0];
				} else if (*command == POSE_TOKEN) {
					snprintf(pbuf, sizeof(pbuf), "pose %s", command + 1);
					command = &pbuf[0];
				} else if (*command == EXIT_DELIMITER) {
					snprintf(pbuf, sizeof(pbuf), "delimiter %s", command + 1);
					command = &pbuf[0];
				} else {
					goto bad_pre_command;
				}
				if (can_move(descr, player, command, 0)) {
					do_move(descr, player, command, 0);	/* command is exact match for exit */
					*match_args = 0;
					*match_cmdname = 0;
				} else {
					goto bad_pre_command;
				}
			} else {
				goto bad_pre_command;
			}
		}
	} else {
	  bad_pre_command:
		if (TrueWizard(OWNER(player)) && (*command == OVERIDE_TOKEN))
			command++;
		full_command = strcpyn(xbuf, sizeof(xbuf), command);
		for (; *full_command && !isspace(*full_command); full_command++) ;
		if (*full_command)
			full_command++;

		/* find arg1 -- move over command word */
		command = strcpyn(ybuf, sizeof(ybuf), command);
		for (arg1 = command; *arg1 && !isspace(*arg1); arg1++) ;
		/* truncate command */
		if (*arg1)
			*arg1++ = '\0';

		/* remember command for programs */
		strcpyn(match_args, sizeof(match_args), full_command);
		strcpyn(match_cmdname, sizeof(match_cmdname), command);

		/* move over spaces */
		while (*arg1 && isspace(*arg1))
			arg1++;

		/* find end of arg1, start of arg2 */
		for (arg2 = arg1; *arg2 && *arg2 != ARG_DELIMITER; arg2++) ;

		/* truncate arg1 */
		for (p = arg2 - 1; p >= arg1 && isspace(*p); p--)
			*p = '\0';

		/* go past delimiter if present */
		if (*arg2)
			*arg2++ = '\0';
		while (*arg2 && isspace(*arg2))
			arg2++;

		switch (command[0]) {
		case '@':
			switch (command[1]) {
			case 'a':
			case 'A':
				/* @action, @armageddon, @attach */
				switch (command[2]) {
				case 'c':
				case 'C':
					Matched("@action");
					NOGUEST("@action", player);
					BUILDERONLY("@action", player);
					do_action(descr, player, arg1, arg2);
					break;
				case 'r':
				case 'R':
					if (strcmp(command, "@armageddon"))
						goto bad;
/*
					WIZARDONLY("@armageddon", player);
					PLAYERONLY("@armageddon", player);
*/
					do_armageddon(player, full_command);
					break;
				case 't':
				case 'T':
					Matched("@attach");
					NOGUEST("@attach", player);
					BUILDERONLY("@attach", player);
					do_attach(descr, player, arg1, arg2);
					break;
				default:
					goto bad;
				}
				break;
			case 'b':
			case 'B':
				/* @bless, @boot */
				switch (command[2]) {
				case 'l':
				case 'L':
					Matched("@bless");
					WIZARDONLY("@bless", player);
					PLAYERONLY("@bless", player);
					NOFORCE("@bless", force_level, player);
					do_bless(descr, player, arg1, arg2);
					break;
				case 'o':
				case 'O':
					Matched("@boot");
					WIZARDONLY("@boot", player);
					PLAYERONLY("@boot", player);
					do_boot(player, arg1);
					break;
				default:
					goto bad;
				}
				break;
			case 'c':
			case 'C':
				/* @chlock, @chown, @chown_lock, @clone,
				   @conlock, @contents, @create, @credits */
				switch (command[2]) {
				case 'h':
				case 'H':
					switch (command[3]) {
					case 'l':
					case 'L':
						Matched("@chlock");
						NOGUEST("@chlock", player);
						set_standard_lock(descr, player, arg1, MESGPROP_CHLOCK, "Chown Lock", arg2);
						break;
					case 'o':
					case 'O':
						if(strlen(command) < 7) {
							Matched("@chown");
							do_chown(descr, player, arg1, arg2);
						} else {
							Matched("@chown_lock");
							NOGUEST("@chown_lock", player);
							set_standard_lock(descr, player, arg1, MESGPROP_CHLOCK, "Chown Lock", arg2);
						}
						break;
					default:
						goto bad;
					}
					break;
				case 'l':
				case 'L':
					Matched("@clone");
					NOGUEST("@clone", player);
					BUILDERONLY("@clone", player);
					do_clone(descr, player, arg1);
					break;
				case 'o':
				case 'O':
					switch (command[4]) {
					case 'l':
					case 'L':
						Matched("@conlock");
						NOGUEST("@conlock", player);
						set_standard_lock(descr, player, arg1, MESGPROP_CONLOCK, "Container Lock", arg2);
						break;
					case 't':
					case 'T':
						Matched("@contents");
						do_contents(descr, player, arg1, arg2);
						break;
					default:
						goto bad;
					}
					break;
				case 'r':
				case 'R':
					if (string_compare(command, "@credits")) {
						Matched("@create");
						NOGUEST("@create", player);
						BUILDERONLY("@create", player);
						do_create(player, arg1, arg2);
					} else {
						do_credits(player);
					}
					break;
				default:
					goto bad;
				}
				break;
			case 'd':
			case 'D':
				/* @dbginfo, @describe, @dig, @doing,
				   @drop, @dump */
				switch (command[2]) {
#ifdef DISKBASE
				case 'b':
				case 'B':
					Matched("@dbginfo");
					WIZARDONLY("@dbginfo", player);
					diskbase_debug(player);
					break;
#endif
				case 'e':
				case 'E':
					Matched("@describe");
					NOGUEST("@describe", player);
					set_standard_property(descr, player, arg1, MESGPROP_DESC, "Object Description", arg2);
					break;
				case 'i':
				case 'I':
					Matched("@dig");
					NOGUEST("@dig", player);
					BUILDERONLY("@dig", player);
					do_dig(descr, player, arg1, arg2);
					break;
				case 'o':
				case 'O':
					Matched("@doing");
					if (!tp_who_doing)
						goto bad;
					NOGUEST("@doing", player);
					set_standard_property(descr, player, arg1, MESGPROP_DOING, "Doing", arg2);
					break;
				case 'r':
				case 'R':
					Matched("@drop");
					NOGUEST("@drop", player);
					set_standard_property(descr, player, arg1, MESGPROP_DROP, "Drop Message", arg2);
					break;
				case 'u':
				case 'U':
					Matched("@dump");
					WIZARDONLY("@dump", player);
					PLAYERONLY("@dump", player);
					do_dump(player, full_command);
					break;
				default:
					goto bad;
				}
				break;
			case 'e':
			case 'E':
				/* @edit, @entrances, @examine */
				switch (command[2]) {
				case 'd':
				case 'D':
					Matched("@edit");
					NOGUEST("@edit", player);
					PLAYERONLY("@edit", player);
					MUCKERONLY("@edit", player);
					do_edit(descr, player, arg1);
					break;
				case 'n':
				case 'N':
					Matched("@entrances");
					do_entrances(descr, player, arg1, arg2);
					break;
				case 'x':
				case 'X':
					Matched("@examine");
					GODONLY("@examine", player);
					sane_dump_object(player, arg1);
					break;
				default:
					goto bad;
				}
				break;
			case 'f':
			case 'F':
				/* @fail, @find, @flock, @force, @force_lock */
				switch (command[2]) {
				case 'a':
				case 'A':
					Matched("@fail");
					NOGUEST("@fail", player);
					set_standard_property(descr, player, arg1, MESGPROP_FAIL, "Fail Message", arg2);
					break;
				case 'i':
				case 'I':
					Matched("@find");
					do_find(player, arg1, arg2);
					break;
				case 'l':
				case 'L':
					Matched("@flock");
					NOGUEST("@flock", player);
					NOFORCE("@flock", force_level, player);
					set_standard_lock(descr, player, arg1, MESGPROP_FLOCK, "Force Lock", arg2);
					break;
				case 'o':
				case 'O':
					if(strlen(command) < 7) {
						Matched("@force");
						do_force(descr, player, arg1, arg2);
					} else {
						Matched("@force_lock");
						NOGUEST("@force_lock", player);
						NOFORCE("@force_lock", force_level, player);
						set_standard_lock(descr, player, arg1, MESGPROP_FLOCK, "Force Lock", arg2);
					}
					break;
				default:
					goto bad;
				}
				break;
			case 'h':
			case 'H':
				/* @hashes */
				Matched("@hashes");
				do_hashes(player, arg1);
				break;
			case 'i':
			case 'I':
				/* @idescribe */
				Matched("@idescribe");
				NOGUEST("@idescribe", player);
				set_standard_property(descr, player, arg1, MESGPROP_IDESC, "Inside Description", arg2);
				break;
			case 'k':
			case 'K':
				/* @kill */
				Matched("@kill");
				do_dequeue(descr, player, arg1);
				break;
			case 'l':
			case 'L':
				/* @link, @list, @lock */
				switch (command[2]) {
				case 'i':
				case 'I':
					switch (command[3]) {
					case 'n':
					case 'N':
						Matched("@link");
						NOGUEST("@link", player);
						do_link(descr, player, arg1, arg2);
						break;
					case 's':
					case 'S':
						Matched("@list");
						match_and_list(descr, player, arg1, arg2);
						break;
					default:
						goto bad;
					}
					break;
				case 'o':
				case 'O':
					Matched("@lock");
					NOGUEST("@lock", player);
					set_standard_lock(descr, player, arg1, MESGPROP_LOCK, "Lock", arg2);
					break;
				default:
					goto bad;
				}
				break;
			case 'm':
			case 'M':
				/* @mcpedit, @mcpprogram, @memory, @mpitops,
				   @muftops */
				switch (command[2]) {
#ifdef MCP_SUPPORT
				case 'c':
				case 'C':
					if (string_prefix("@mcpedit", command)) {
						Matched("@mcpedit");
						NOGUEST("@mcpedit", player);
						PLAYERONLY("@mcpedit", player);
						MUCKERONLY("@mcpedit", player);
						do_mcpedit(descr, player, arg1);
						break;
					} else {
						Matched("@mcpprogram");
						NOGUEST("@mcpprogram", player);
						PLAYERONLY("@mcpprogram", player);
						MUCKERONLY("@mcpprogram", player);
						do_mcpprogram(descr, player, arg1);
						break;
					}
#endif
#ifndef NO_MEMORY_COMMAND
				case 'e':
				case 'E':
					Matched("@memory");
					WIZARDONLY("@memory", player);
					do_memory(player);
					break;
#endif
				case 'p':
			    case 'P':
			        Matched("@mpitops");
				WIZARDONLY("@mpitops", player);
			        do_mpi_topprofs(player, arg1);
			        break;
			    case 'u':
			    case 'U':
			        Matched("@muftops");
				WIZARDONLY("@muftops", player);
			        do_muf_topprofs(player, arg1);
			        break;
				default:
					goto bad;
				}
				break;
			case 'n':
			case 'N':
				/* @name, @newpassword */
				switch (command[2]) {
				case 'a':
				case 'A':
					Matched("@name");
					NOGUEST("@name", player);
					do_name(descr, player, arg1, arg2);
					break;
				case 'e':
				case 'E':
					if (strcmp(command, "@newpassword"))
						goto bad;
					WIZARDONLY("@newpassword", player);
					PLAYERONLY("@newpassword", player);
					do_newpassword(player, arg1, arg2);
					break;
				default:
					goto bad;
				}
				break;
			case 'o':
			case 'O':
				/* @odrop, @oecho, @ofail, @open, @osuccess,
				   @owned */
				switch (command[2]) {
				case 'd':
				case 'D':
					Matched("@odrop");
					NOGUEST("@odrop", player);
					set_standard_property(descr, player, arg1, MESGPROP_ODROP, "ODrop Message", arg2);
					break;
				case 'e':
				case 'E':
					Matched("@oecho");
					NOGUEST("@oecho", player);
					set_standard_property(descr, player, arg1, MESGPROP_OECHO, "Outside-echo Prefix", arg2);
					break;
				case 'f':
				case 'F':
					Matched("@ofail");
					NOGUEST("@ofail", player);
					set_standard_property(descr, player, arg1, MESGPROP_OFAIL, "OFail Message", arg2);
					break;
				case 'p':
				case 'P':
					Matched("@open");
					NOGUEST("@open", player);
					BUILDERONLY("@open", player);
					do_open(descr, player, arg1, arg2);
					break;
				case 's':
				case 'S':
					Matched("@osuccess");
					NOGUEST("@osuccess", player);
					set_standard_property(descr, player, arg1, MESGPROP_OSUCC, "OSuccess Message", arg2);
					break;
				case 'w':
				case 'W':
					Matched("@owned");
					do_owned(player, arg1, arg2);
					break;
				default:
					goto bad;
				}
				break;
			case 'p':
			case 'P':
				/* @password, @pcreate, @pecho, @program, 
				   @propset, @ps */
				switch (command[2]) {
				case 'a':
				case 'A':
					Matched("@password");
					PLAYERONLY("@password", player);
					NOGUEST("@password", player);
					do_password(player, arg1, arg2);
					break;
				case 'c':
				case 'C':
					Matched("@pcreate");
					WIZARDONLY("@pcreate", player);
					PLAYERONLY("@pcreate", player);
					do_pcreate(player, arg1, arg2);
					break;
				case 'e':
				case 'E':
					Matched("@pecho");
					NOGUEST("@pecho", player);
					set_standard_property(descr, player, arg1, MESGPROP_PECHO, "Puppet-echo Prefix", arg2);
					break;
				case 'r':
				case 'R':
					if (string_prefix("@program", command)) {
						Matched("@program");
						NOGUEST("@program", player);
						PLAYERONLY("@program", player);
						MUCKERONLY("@program", player);
						do_prog(descr, player, arg1);
						break;
					} else {
						Matched("@propset");
						NOGUEST("@propset", player);
						do_propset(descr, player, arg1, arg2);
						break;
					}
				case 's':
				case 'S':
					Matched("@ps");
					list_events(player);
					break;
				default:
					goto bad;
				}
				break;
			case 'r':
			case 'R':
				/* @recycle, @reconfiguressl, @relink, @restart, @restrict */
				switch (command[3]) {
				case 'c':
				case 'C':
#ifdef USE_SSL
                                        if (!strcmp(command, "@reconfiguressl")) {
                                                WIZARDONLY("@reconfiguressl", player);
                                                PLAYERONLY("@reconfiguressl", player);
                                                do_reconfigure_ssl(player);
                                                break;
                                        }
#endif
                                        Matched("@recycle");
                                        NOGUEST("@recycle", player);
                                        do_recycle(descr, player, arg1);
                                        break;
				case 'l':
				case 'L':
					Matched("@relink");
					NOGUEST("@relink", player);
					do_relink(descr, player, arg1, arg2);
					break;
				case 's':
				case 'S':
					if (!strcmp(command, "@restart")) {
/*
						WIZARDONLY("@restart", player);
						PLAYERONLY("@restart", player);
*/
						do_restart(player);
					} else if (!strcmp(command, "@restrict")) {
						WIZARDONLY("@restrict", player);
						PLAYERONLY("@restrict", player);
						do_restrict(player, arg1);
					} else {
						goto bad;
					}
					break;
				default:
					goto bad;
				}
				break;
			case 's':
			case 'S':
				/* @sanity, @sanchange, @sanfix, @set,
				   @shutdown, @stats, @success, @sweep */
				switch (command[2]) {
				case 'a':
				case 'A':
					if (!strcmp(command, "@sanity")) {
						GODONLY("@sanity", player);
						sanity(player);
					} else if (!strcmp(command, "@sanchange")) {
						GODONLY("@sanchange", player);
						sanechange(player, full_command);
					} else if (!strcmp(command, "@sanfix")) {
						GODONLY("@sanfix", player);
						sanfix(player);
					} else {
						goto bad;
					}
					break;
				case 'e':
				case 'E':
					Matched("@set");
					NOGUEST("@set", player);
					do_set(descr, player, arg1, arg2);
					break;
				case 'h':
				case 'H':
					if (strcmp(command, "@shutdown"))
						goto bad;
/*
					WIZARDONLY("@shutdown", player);
					PLAYERONLY("@shutdown", player);
*/
					do_shutdown(player);
					break;
				case 't':
				case 'T':
					Matched("@stats");
					do_stats(player, arg1);
					break;
				case 'u':
				case 'U':
					Matched("@success");
					NOGUEST("@success", player);
					set_standard_property(descr, player, arg1, MESGPROP_SUCC, "Success Message", arg2);
					break;
				case 'w':
				case 'W':
					Matched("@sweep");
					do_sweep(descr, player, arg1);
					break;
				default:
					goto bad;
				}
				break;
			case 't':
			case 'T':
				/* @teleport, @toad, @trace, @tune */
				switch (command[2]) {
				case 'e':
				case 'E':
					Matched("@teleport");
					do_teleport(descr, player, arg1, arg2);
					break;
				case 'o':
				case 'O':
					if (!strcmp(command, "@toad")) {
						WIZARDONLY("@toad", player);
						PLAYERONLY("@toad", player);
						do_toad(descr, player, arg1, arg2);
					} else if (!strcmp(command, "@tops")) {
						WIZARDONLY("@tops", player);
						do_all_topprofs(player, arg1);
					} else {
						goto bad;
					}
					break;
				case 'r':
				case 'R':
					Matched("@trace");
					do_trace(descr, player, arg1, atoi(arg2));
					break;
				case 'u':
				case 'U':
					Matched("@tune");
					WIZARDONLY("@tune", player);
					PLAYERONLY("@tune", player);
					do_tune(player, arg1, arg2, !!strchr(full_command, ARG_DELIMITER));
					break;
				default:
					goto bad;
				}
				break;
			case 'u':
			case 'U':
				/* @unbless, @unlink, @unlock, @uncompile,
				   @usage */
				switch (command[2]) {
				case 'N':
				case 'n':
					if (string_prefix(command, "@unb")) {
						Matched("@unbless");
						WIZARDONLY("@unbless", player);
						PLAYERONLY("@unbless", player);
						NOFORCE("@unbless", force_level, player);
						do_unbless(descr, player, arg1, arg2);
					} else if (string_prefix(command, "@unli")) {
						Matched("@unlink");
						NOGUEST("@unlink", player);
						do_unlink(descr, player, arg1);
					} else if (string_prefix(command, "@unlo")) {
						Matched("@unlock");
						NOGUEST("@unlock", player);
						set_standard_lock(descr, player, arg1, MESGPROP_LOCK, "Lock", "");
					} else if (string_prefix(command, "@uncom")) {
						Matched("@uncompile");
						WIZARDONLY("@uncompile", player);
						PLAYERONLY("@uncompile", player);
						do_uncompile(player);
					} else {
						goto bad;
					}
					break;
#ifndef NO_USAGE_COMMAND
				case 'S':
				case 's':
					Matched("@usage");
					WIZARDONLY("@usage", player);
					do_usage(player);
					break;
#endif
				default:
					goto bad;
					break;
				}
				break;
			case 'v':
			case 'V':
				/* @version */
				Matched("@version");
				do_version(player);
				break;
			case 'w':
			case 'W':
				/* @wall */
				if (strcmp(command, "@wall"))
					goto bad;
				WIZARDONLY("@wall", player);
				PLAYERONLY("@wall", player);
				do_wall(player, full_command);
				break;
			default:
				goto bad;
			}
			break;
		case 'd':
		case 'D':
			/* disembark, drop */
			switch (command[1]) {
			case 'i':
			case 'I':
				Matched("disembark");
				do_leave(descr, player);
				break;
			case 'r':
			case 'R':
				Matched("drop");
				do_drop(descr, player, arg1, arg2);
				break;
			default:
				goto bad;
			}
			break;
		case 'e':
		case 'E':
			/* examine */
			Matched("examine");
			do_examine(descr, player, arg1, arg2);
			break;
		case 'g':
		case 'G':
			/* get, give, goto, gripe */
			switch (command[1]) {
			case 'e':
			case 'E':
				Matched("get");
				do_get(descr, player, arg1, arg2);
				break;
			case 'i':
			case 'I':
				Matched("give");
				do_give(descr, player, arg1, atoi(arg2));
				break;
			case 'o':
			case 'O':
				Matched("goto");
				do_move(descr, player, arg1, 0);
				break;
			case 'r':
			case 'R':
				if (string_compare(command, "gripe"))
					goto bad;
				do_gripe(player, full_command);
				break;
			default:
				goto bad;
			}
			break;
		case 'h':
		case 'H':
			/* help */
			Matched("help");
			do_help(player, arg1, arg2);
			break;
		case 'i':
		case 'I':
			/* inventory, info */
			if (string_compare(command, "info")) {
				Matched("inventory");
				do_inventory(player);
			} else {
				Matched("info");
				do_info(player, arg1, arg2);
			}
			break;
		case 'k':
		case 'K':
			/* kill */
			Matched("kill");
			do_kill(descr, player, arg1, atoi(arg2));
			break;
		case 'l':
		case 'L':
			/* leave, look */
			if (string_prefix("look", command)) {
				Matched("look");
				do_look_at(descr, player, arg1, arg2);
				break;
			} else {
				Matched("leave");
				do_leave(descr, player);
				break;
			}
		case 'm':
		case 'M':
			/* man, motd, move, mpi */
			if (string_prefix(command, "move")) {
				do_move(descr, player, arg1, 0);
				break;
			} else if (!string_compare(command, "motd")) {
				do_motd(player, full_command);
				break;
			} else if (!string_compare(command, "mpi")) {
				do_mpihelp(player, arg1, arg2);
				break;
			} else {
				if (string_compare(command, "man"))
					goto bad;
				do_man(player, (!*arg1 && !*arg2 && arg1 != arg2) ? "=" : arg1, arg2);
			}
			break;
		case 'n':
		case 'N':
			/* news */
			Matched("news");
			do_news(player, arg1, arg2);
			break;
		case 'p':
		case 'P':
			/* page, pose, put */
			switch (command[1]) {
			case 'a':
			case 'A':
				Matched("page");
				do_page(player, arg1, arg2);
				break;
			case 'o':
			case 'O':
				Matched("pose");
				do_pose(player, full_command);
				break;
			case 'u':
			case 'U':
				Matched("put");
				do_drop(descr, player, arg1, arg2);
				break;
			default:
				goto bad;
			}
			break;
		case 'r':
		case 'R':
			/* read, rob */
			switch (command[1]) {
			case 'e':
			case 'E':
				Matched("read");	/* undocumented alias for look */
				do_look_at(descr, player, arg1, arg2);
				break;
			case 'o':
			case 'O':
				Matched("rob");
				do_rob(descr, player, arg1);
				break;
			default:
				goto bad;
			}
			break;
		case 's':
		case 'S':
			/* say, score */
			switch (command[1]) {
			case 'a':
			case 'A':
				Matched("say");
				do_say(player, full_command);
				break;
			case 'c':
			case 'C':
				Matched("score");
				do_score(player);
				break;
			default:
				goto bad;
			}
			break;
		case 't':
		case 'T':
			/* take, throw */
			switch (command[1]) {
			case 'a':
			case 'A':
				Matched("take");
				do_get(descr, player, arg1, arg2);
				break;
			case 'h':
			case 'H':
				Matched("throw");
				do_drop(descr, player, arg1, arg2);
				break;
			default:
			goto bad;
			}
			break;
		case 'w':
		case 'W':
			/* whisper */
			Matched("whisper");
			do_whisper(descr, player, arg1, arg2);
			break;
		default:
		  bad:
			if (tp_m3_huh != 0)
			{
				char hbuf[BUFFER_LEN];
				snprintf(hbuf,BUFFER_LEN,"HUH? %s", command);
				if(can_move(descr, player, hbuf, 3)) {
					do_move(descr, player, hbuf, 3);
					*match_args = 0;
					*match_cmdname = 0;
					break;
				}
			}	
			notify(player, tp_huh_mesg);
			if (tp_log_failed_commands && !controls(player, LOCATION(player))) {
				log_status("HUH from %s(%d) in %s(%d)[%s]: %s %s",
						   NAME(player), player, NAME(LOCATION(player)),
						   LOCATION(player),
						   NAME(OWNER(LOCATION(player))), command, full_command);
			}
			break;
		}
	}

	/* calculate time command took. */
	gettimeofday(&endtime, NULL);
	if (starttime.tv_usec > endtime.tv_usec) {
		endtime.tv_usec += 1000000;
		endtime.tv_sec -= 1;
	}
	endtime.tv_usec -= starttime.tv_usec;
	endtime.tv_sec -= starttime.tv_sec;

	totaltime = endtime.tv_sec + (endtime.tv_usec * 1.0e-6);
	if (totaltime > (tp_cmd_log_threshold_msec / 1000.0)) {
		log2file(LOG_CMD_TIMES, "%6.3fs, %.16s: %s: %s",
					totaltime, ctime((time_t *)&starttime.tv_sec),
					whowhere(player), command);
	}
}
Example #30
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;
}