示例#1
0
int main(int argc, char* argv[])
{
 lua_State* L;
 int i;

  process_path = argv[0];
  strncpy(process_name, shfs_app_name(process_path), sizeof(process_name) - 1);

  run_flags |= RUNF_LOCAL;
  for (i = 1; i < argc; i++) {
    if (IS("-v") || IS("--version")) {
      print_process_version();
      return (EXIT_SUCCESS);
    }
    if (IS("-h") || IS("--help")) {
      print_process_usage();
      return (EXIT_SUCCESS);
    }
    if (IS("-V") || IS("--verbose")) {
      run_flags |= RUNF_VERBOSE;
      continue;
    }
    if (IS("-f") || IS("--fs")) {
      run_flags &= ~RUNF_LOCAL;
      if (i + 1 < argc && argv[i+1][0] != '-') {
        i++;
        strncpy(app_name, argv[i], sizeof(app_name) - 1);
      }
      continue;
    }

    if (argv[i][0] == '-') {
      printf("Warning: Invalid command-line option \"%s\".\n", argv[i]);
      continue;
    }

    /* source file specification. */
    run_flags |= RUNF_INPUT;
  }

  if (!(run_flags & RUNF_INPUT)) {
    printf("Error: no input file(s) specified.\n");
    exit(1);
  }

 L=luaL_newstate();
 if (L==NULL) fatal("cannot create state: not enough memory");
 lua_pushcfunction(L,&pmain);
 lua_pushinteger(L,argc);
 lua_pushlightuserdata(L,argv);
 if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1));
 lua_close(L);

 return EXIT_SUCCESS;
}
示例#2
0
int main(int argc, char **argv)
{
  shpeer_t *app_peer;
  time_t stime, etime;
  time_t now;
  char subcmd[256];
  char **args;
  char app_name[256];
  int i;

  signal(SIGHUP, SIG_IGN);
  signal(SIGPIPE, SIG_IGN);

  strncpy(process_path, argv[0], PATH_MAX);

  proc_mode = RUN_NONE;

  /* handle traditional arguments */
  for (i = 1; i < argc; i++) {
    if (0 == strcmp(argv[i], "--version") ||
        0 == strcmp(argv[i], "-v")) {
      print_process_version();
      return (0);
    }
    if (0 == strcmp(argv[i], "--help") ||
        0 == strcmp(argv[i], "-h")) {
      print_process_usage();
      return (0);
    }
  }


  memset(app_name, 0, sizeof(app_name));
  for (i = 1; i < argc; i++) {
    if (0 == strcmp(argv[i], "-f")) {
      proc_mode = RUN_TAIL;
      continue;
    }

    if (argv[i][0] == '-') {
      continue;
    }

    strncpy(app_name, argv[i], sizeof(app_name) - 1);
    if (proc_mode == RUN_NONE)
      proc_mode = RUN_LIST;
  }

  app_peer = shpeer_init(app_name, NULL);

  now = time(NULL);
  stime = etime = now;
  switch (proc_mode) {
    case RUN_NONE:
      print_process_usage();
      break;

    case RUN_LIST:
      sharelog_list(app_peer, stime, etime);
      break;

    case RUN_TAIL:
      sharelog_list(app_peer, now, now);
      sharelog_tail(app_peer);
      break;
  }

  shpeer_free(&app_peer);

	return (0);
}