Exemplo n.º 1
0
int main(int argc, char *argv[]) {
    int option;
    char *infile = NULL;

    while((option = getopt(argc, argv, "f:h")) != -1) {
        switch(option) {
        case 'h':
            usage(argv[0]);
            exit(EXIT_SUCCESS);
            break;

        case 'f':
            infile = optarg;
            break;

        default:
            fprintf(stderr, "Unknown argument: '%c'\n", option);
            usage(argv[0]);
            exit(EXIT_FAILURE);
            break;
        }
    }

    if(infile) {
        // load the file and execute it.
        repl(0);
    } else {
        repl(0);
    }

    exit(EXIT_SUCCESS);
}
Exemplo n.º 2
0
Arquivo: main.c Projeto: mk12/eva
// Processes the command line arguments. Returns true on success.
static bool process_args(int argc, char **argv, struct Environment *env) {
	if (argc == 2 && is_opt(argv[1], 'h', "help")) {
		fputs(usage_message, stdout);
		return true;
	}

	bool tty = isatty(0);
	bool prelude = true;
	for (int i = 1; i < argc; i++) {
		if (is_opt(argv[i], 'n', "no-prelude")) {
			prelude = false;
			argv[i] = NULL;
			break;
		}
	}
	if (prelude) {
		execute(PRELUDE_FILENAME, prelude_source, env, false);
	}

	if (argc == 1 || (argc == 2 && !prelude)) {
		repl(env, tty);
		return true;
	}
	for (int i = 1; i < argc; i++) {
		if (argv[i] == NULL) {
			continue;
		}

		if (strcmp(argv[i], "-") == 0) {
			repl(env, tty);
		} else if (is_opt(argv[i], 'e', "expression")) {
			// Execute the next argument.
			if (i == argc - 1) {
				print_error(argv[i], err_opt_argument);
				return false;
			}
			if (!execute(argv_filename, argv[++i], env, true)) {
				return false;
			}
		} else {
			// Assume the argument is a filename.
			char *text = read_file(argv[i]);
			if (!text) {
				print_file_error(argv[i]);
				return false;
			}
			bool success = execute(argv[i], text, env, false);
			free(text);
			if (!success) {
				return false;
			}
		}
	}
	return true;
}
Exemplo n.º 3
0
bool ArrayInterface::
is_array_construct_op( CPPAstInterface& fa, const AstNodePtr& arrayExp, 
                       AstInterface::AstNodeList* alias,int *dimp, 
                               SymbolicFunctionDeclarationGroup *len, SymbolicFunctionDeclarationGroup* elem)
{
  ArrayDescriptor desc;
  if (ArrayAnnotation::get_inst()->is_array_construct_op( fa, arrayExp, alias, &desc) ) {
    HasValueMapReplace repl( fa, valueCollect.get_value_map(), true);
    desc.replace_val(repl);

    int dim = 0, dim1 = 0;
    if (elem != 0 && dimp == 0)
       dimp = &dim;
    if ( dimp != 0 && desc.get_dimension(*dimp)) {
      dim1 = *dimp;
    }

    if (len != 0)
      *len = desc.get_length();
    if (dimp != 0 || len != 0)
    {
      if (!is_array_exp( fa, arrayExp, dimp, len))
        assert(false);
      if (dimp != 0 && dim1 != 0 && *dimp > dim1)
        *dimp = dim1;
    }
    if (elem != 0)  {
      assert( dimp != 0);
      *elem = desc.get_elem();
      elem->replace_var("dimension", *dimp);
    }
    return true;
  } 
  return false;
}
Exemplo n.º 4
0
int main(int argc, const char **argv)
{
	unitTests();

	Settings settings;
	ArgumentList args = gatherArguments(argc, argv, settings);	

	// TODO: Probably don't want to share them between files
	Bindings bindings = bindStandardLibrary();
	Interpreter interpreter(bindings, settings);

	if (args.empty())
	{
		repl(interpreter, settings);
	}
	else
	{
		for (ArgumentList::const_iterator it = args.begin() ; it != args.end() ; ++it) 
		{
			execute(interpreter, *it, settings);
		}
	}
	// If you use CTRL-D, nice to output a newline...
	std::cout << '\n';
}
Exemplo n.º 5
0
template<class T> void TabsToSpaces(T& str, unsigned int n)
{
    T repl(n, ' ');
    typename T::size_type p;
    while ((p = str.find('\t')) != T::npos)
        str.replace(p, 1, repl);
}
int main()
{
   std::string text = "Quick brown fox";
   std::regex vowel_re("a|e|i|o|u");
 
   // write the results to an output iterator
   std::regex_replace(std::ostreambuf_iterator<char>(std::cout),
                      text.begin(), text.end(), vowel_re, std::string("*"));
 
   // construct a string holding the results
   std::cout << '\n' << std::regex_replace(text, vowel_re,
					   std::string("[$&]")) << '\n';
#if 0
  {
    std::string s ("there is a subsequence in the string\n");
    std::regex e ("[a-z]");   // matches words beginning by "sub"

    // using string/c-string (3) version:
    std::cout << std::regex_replace (s,e,std::string("$$"));
  }
  return 0;
#endif
  std::string line("hello world");
  //std::cin >> line;
  //std::regex expr ("\\<[a-z]");
  std::regex expr ("[^\\w]+");
  //std::string repl("\\u&");
  std::string repl("_");

  std::cout << std::regex_replace (line, expr, repl) << std::endl;
  std::cout << line << std::endl;

  return 0;
}
Exemplo n.º 7
0
int main(int argc, char ** argv) {
  if (argc < 3) {
    std::cout << "Not enough arguments. Args: <path to dir> <max page number>" << std::endl;
    return 0;
  }

  std::cout << "Welcome to ShredderDB." << std::endl;

  InfoPool::get_instance().get_db_info().root_path = argv[1];
  InfoPool::get_instance().get_db_info().max_page_cnt = std::stoi(argv[2]);
#ifdef MAIN_DBG
  Utils::info("[Common] Max page # is " + std::to_string(InfoPool::get_instance().get_db_info().max_page_cnt));
#endif
  if (InfoPool::get_instance().get_db_info().max_page_cnt == 0) {
    Utils::warning("[Common] Max buffer page size is 0.");
  }

  std::string &current_root_path = InfoPool::get_instance().get_db_info().root_path;
#ifdef MAIN_DBG
  Utils::info("[Common] DB root path is " + current_root_path);
#endif
  if (!Utils::check_existence(current_root_path, true)) {
#ifdef MAIN_DBG
    Utils::info("[Common] Creating missed DB directory " + current_root_path);
#endif
    mkdir(current_root_path.c_str(), 0777);
  }
  if (current_root_path[current_root_path.size() - 1] != '/') {
    current_root_path += '/';
  }

  repl();
}
Exemplo n.º 8
0
int main(int argc, char **argv) {
    int firstarg;
    char **argvcopy;
    struct redisCommand *rc;

    config.hostip = "127.0.0.1";
    config.hostport = 6379;
    config.repeat = 1;
    config.dbnum = 0;
    config.interactive = 0;
    config.auth = NULL;

    firstarg = parseOptions(argc,argv);
    argc -= firstarg;
    argv += firstarg;

    if (argc == 0 || config.interactive == 1) repl();

    argvcopy = convertToSds(argc, argv);

    /* Read the last argument from stdandard input if needed */
    if ((rc = lookupCommand(argv[0])) != NULL) {
      if (rc->arity > 0 && argc == rc->arity-1) {
        sds lastarg = readArgFromStdin();
        argvcopy[argc] = lastarg;
        argc++;
      }
    }

    return cliSendCommand(argc, argvcopy);
}
Exemplo n.º 9
0
static void ini_init (const char *filename)
{
	unsigned int len;
	char *dir;

	/* add the directory of the ini file */
	dir = g_path_get_dirname (filename);
	bp_library_path_add1 (curr_scene, dir);
	free (dir);

	len = strlen (filename);

	if (len > 4 && filename [--len] == 'i' 
	       && filename [--len] == 'n'
	       && filename [--len] == 'i'
	       && filename [len - 1] == '.') {
#define repl(file, a, b, c) { \
	file = strdup (filename);\
        file [len] = a; \
        file [len + 1] = b; \
        file [len + 2] = c; \
}
		repl (curr_scene->settings.input_filename,  'b', 'p', 'r');
#undef repl
	}
}
Exemplo n.º 10
0
void
finduser(register struct packet *pkt)
{
    register char *p;
    char	*user;
    char groupid[6];
    int none;
    int ok_user;
    extern char saveid[];

    none = 1;
#if 0
    user = logname();
#else
    user = saveid;
#endif
    sprintf(groupid,"%lu",(unsigned long)getgid());
    while ((p = getline(pkt)) != NULL && *p != CTLCHAR) {
        none = 0;
        ok_user = 1;
        repl(p,'\n','\0');	/* this is done for equal test below */
        if(*p == '!') {
            ++p;
            ok_user = 0;
        }
        if (!pkt->p_user)
            if (equal(user,p) || equal(groupid,p))
                pkt->p_user = ok_user;
        *(strend(p)) = '\n';	/* repl \0 end of line w/ \n again */
    }
    if (none)
        pkt->p_user = 1;
    if (p == NULL || p[1] != EUSERNAM)
        fmterr(pkt);
}
Exemplo n.º 11
0
/*
 * Here the fun begins
 */
int main(int argc, char **argv) {
	getOpts(argc, argv);
	init();
	getOpts(argc, argv);
	if (!Batch) {
		printf("ArrowLISP ");
		printf(ALISP_RELEASE);
		printf(" (C) 2006 Nils M Holm\n");
	}
	if (Image[0]) {
		if (alisp_load_image(Image)) {
			printf("* ");
			alisp_print_error();
			if (Batch) exit(1);
			alisp_fini();
			init();
			getOpts(argc, argv);
		}
	}
	else if (!Batch) {
		printf("Warning: no image loaded\n");
	}
	signal(SIGINT, catchIntr);
	repl();
	alisp_fini();
	return 0;
}
Exemplo n.º 12
0
int TextEditorWX::ReplaceAll(int flags, const char *ftext, const char *rtext, SelectInfo& info)
{
	if (!InitFind(flags, ftext, false))
		return -1;

	int count = 0;
	findStart = info.startPos;
	findEnd = info.endPos;
	if (findStart == findEnd)
		findEnd = edwnd->GetLastPosition();

	wxString repl(rtext);
	if (findFlags & TXTFIND_REGEXP)
	{
		matchText = edwnd->GetRange(findStart, findEnd);
		count = findRE.ReplaceAll(&matchText, wxString(rtext));
		if (count > 0)
			edwnd->Replace(findStart, findEnd, matchText);
	}
	else
	{
		long rlen = repl.Len() + 1;
		do
		{
			matchText = edwnd->GetRange(findStart, findEnd);
			if (!DoFind())
				break;
			count++;
			edwnd->Replace(matchStart, matchEnd, repl);
			findStart = matchStart + rlen;
		} while (findStart < findEnd);
	}
	return count;
}
Exemplo n.º 13
0
Variant f_substr_replace(CVarRef str, CVarRef replacement, CVarRef start,
                         CVarRef length /* = 0x7FFFFFFF */) {
  if (!str.is(KindOfArray)) {
    String repl;
    if (replacement.is(KindOfArray)) {
      repl = replacement[0].toString();
    } else {
      repl = replacement.toString();
    }
    if (start.is(KindOfArray)) {
      if (!length.is(KindOfArray)) {
        throw_invalid_argument("start and length should be of same type - "
                               "numerical or array");
        return str;
      }
      Array startArr = start.toArray();
      Array lengthArr = length.toArray();
      if (startArr.size() != lengthArr.size()) {
        throw_invalid_argument("start and length: (different item count)");
        return str;
      }
      throw_invalid_argument("start and length as arrays not implemented");
      return str;
    }
    return str.toString().replace(start.toInt32(), length.toInt32(), repl);
  }

  Array ret;
  Array strArr = str.toArray();
  Array startArr = start.toArray();
  Array lengthArr = length.toArray();
  ArrayIter startIter(startArr);
  ArrayIter lengthIter(lengthArr);

  if (replacement.is(KindOfArray)) {
    Array replArr = replacement.toArray();
    ArrayIter replIter(replArr);
    for (ArrayIter iter(strArr); iter;
         ++iter, ++startIter, ++lengthIter) {
      int nStart = startIter.second().toInt32();
      int nLength = lengthIter.second().toInt32();
      String repl("");
      if (replIter) {
        repl = replIter.second().toString();
        ++replIter;
      }
      ret.append(iter.second().toString().replace(nStart, nLength, repl));
    }
  } else {
    String repl = replacement.toString();
    for (ArrayIter iter(strArr); iter;
         ++iter, ++startIter, ++lengthIter) {
      int nStart = startIter.second().toInt32();
      int nLength = lengthIter.second().toInt32();
      ret.append(iter.second().toString().replace(nStart, nLength, repl));
    }
  }
  return ret;
}
Exemplo n.º 14
0
int main(int argc, char * argv[]){
	std::cout<<"LoLi PRPR!\nLoLi is a Free Software and you can do whatever you want with it under the licence GPLv3"<<std::endl;
	loli_init_tl();
	while(true){
		repl(top_env);
	}
	exit(0);
}
Exemplo n.º 15
0
int main(int argc, char *argv[]) 
{
  progname = strdup(basename(argv[0]));
  init();
  license();
  repl();
  exiting();
  exit(0);
}
Exemplo n.º 16
0
std::string escape(char c, const std::string& text) {
  // escape a character in the given string
  std::string repl(text);
  for (std::string::size_type next = repl.find(c);
       next != std::string::npos; next = repl.find(c, next)) {
    repl.insert(next, 1, '\\');
    next += 2;
  }
  return repl;
}
Exemplo n.º 17
0
Arquivo: luna.c Projeto: arschles/luna
int
main(int argc, const char **argv){
  int appended_ext = 0;
  const char *path, *orig;
  FILE *stream;

  // parse arguments
  argv = parse_args(&argc, argv);

  // REPL
  if (!stdio && 1 == argc) repl();

  // stdin
  if (stdio) {
    path = "stdin";
    stream = stdin;
  } else {
    orig = path = argv[1];
    read:
    stream = fopen(path, "r");
    if (!stream) {
      // try with .luna extension
      if (!appended_ext) {
        appended_ext = 1;
        char buf[256];
        snprintf(buf, 256, "%s.luna", path);
        path = buf;
        goto read;
      }
      fprintf(stderr, "error reading %s:\n\n  %s\n\n", orig, strerror(errno));
      exit(1);
    }    
  }

  // parse the input
  luna_lexer_t lex;
  luna_lexer_init(&lex, stream, path);
  luna_parser_t parser;
  luna_parser_init(&parser, &lex);
  luna_block_node_t *root;

  // oh noes!
  if (!(root = luna_parse(&parser))) {
    luna_report_error(&parser);
    exit(1);
  }

  // --ast
  if (ast) {
    luna_prettyprint((luna_node_t *) root);
    exit(0);
  }

  return 0;
}
Exemplo n.º 18
0
Arquivo: wisp.c Projeto: qyqx/wisp
int main (int argc, char **argv)
{
  progname = argv[0];
  wisp_init ();

  /* parse arguments */
  int c;
  while ((c = getopt (argc, argv, "+ihv")) != -1)
    switch (c)
      {
      case 'i':
	force_interaction = 1;
	break;
      case 'v':
	print_version ();
	break;
      case 'h':
	print_help = 1;
	break;
      case '?':
	print_usage (EXIT_FAILURE);
	break;
      }
  if (print_help)
    print_usage (EXIT_SUCCESS);

  if (argc - optind < 1)
    {
      /* Run interaction. */
      repl ();
    }
  else
    {
      /* Run script */
      char *file = argv[optind];
      FILE *fid = fopen (file, "r");
      if (fid == NULL)
	{
	  fprintf (stderr, "error: could not load %s: %s\n",
		   file, strerror (errno));
	  exit (EXIT_FAILURE);
	}
      /* expose argv to wisp program */
      object_t *args = NIL;
      while (argc > optind)
	{
	  args = c_cons (c_strs (xstrdup (argv[argc - 1])), args);
	  argc--;
	}
      SET (c_sym ("ARGS"), args);
      load_file (fid, file, 0);
      fclose (fid);
    }
  return EXIT_SUCCESS;
}
Exemplo n.º 19
0
int main(int argc, char **argv) {
    int firstarg;

    config.hostip = sdsnew("127.0.0.1");
    config.hostport = 6379;
    config.hostsocket = NULL;
    config.repeat = 1;
    config.interval = 0;
    config.dbnum = 0;
    config.interactive = 0;
    config.shutdown = 0;
    config.monitor_mode = 0;
    config.pubsub_mode = 0;
    config.latency_mode = 0;
    config.stdinarg = 0;
    config.auth = NULL;
    config.raw_output = !isatty(fileno(stdout)) && (getenv("FAKETTY") == NULL);
    config.mb_delim = sdsnew("\n");
    cliInitHelp();

#ifdef _WIN32
    _fmode = _O_BINARY;
    _setmode(_fileno(stdin), _O_BINARY);
    _setmode(_fileno(stdout), _O_BINARY);
    _setmode(_fileno(stderr), _O_BINARY);

    if (!w32initWinSock()) {
      printf("Winsock init error %d", WSAGetLastError());
      exit(1);
    };

    atexit((void(*)(void)) WSACleanup);
#endif
    firstarg = parseOptions(argc,argv);
    argc -= firstarg;
    argv += firstarg;

    /* Start in latency mode if appropriate */
    if (config.latency_mode) {
        cliConnect(0);
        latencyMode();
    }

    /* Start interactive mode when no command is provided */
    if (argc == 0) {
        /* Note that in repl mode we don't abort on connection error.
         * A new attempt will be performed for every command send. */
        cliConnect(0);
        repl();
    }

    /* Otherwise, we have some arguments to execute */
    if (cliConnect(0) != REDIS_OK) exit(1);
    return noninteractive(argc,convertToSds(argc,argv));
}
Exemplo n.º 20
0
Arquivo: main.c Projeto: npc3/DumbLisp
int main(int argc, char **argv) {
    char *file_to_eval = NULL;
    int replize = argc < 1;
    for(int i = 1; i < argc; i++) {
        if(!strcmp("-f", argv[i]))
            file_to_eval = argv[++i];
        else if(!strcmp("--verbose", argv[i]))
            VERBOSE = true;
        else if(!strcmp("-i", argv[i]))
            replize = true;
    }

    init_alloc_system();
    init_symboltable();
    register_builtin_functions();

    new_var(new_symbol("nil"), (LispObject*)nil);
    new_var(new_symbol("t"), (LispObject*)new_symbol("t"));

    nexception_points++;
    if(setjmp(exception_points[nexception_points - 1]) == 0) {
        eval_file("prelude.l");
        if(file_to_eval)
            eval_file(file_to_eval);
        else
            repl();
    } else {
        fprintf(stderr, "%s", error_string);
        printf("Stack trace:\n");
        for(int i = 0; i < call_stack->size; i++) {
            printf("  ");
            obj_print(vector_getitem(call_stack, i));
            printf("\n");
        }
        while(scopes->size > 1)
            pop_scope();
        while(call_stack->size > 1)
            vector_remove(call_stack, -1);
        if(replize)
            repl();
    }
}
Exemplo n.º 21
0
bool ppCtx::Check(int token, std::string &line)
{
    bool rv = false;
    if (token == PUSH)
        rv = push(line);
    else if (token == POP)
        rv = pop();
    else if (token == REPL)
        rv = repl(line);
    return rv;
}
Exemplo n.º 22
0
int main(int, char* [])
{
    Env env;

    appendFunctions(env);

    repl("lis.cpp> ", env);

    Atom::releaseAll();

    return 0;
}
Exemplo n.º 23
0
Arquivo: repl.c Projeto: bcho/homework
int
main()
{
    // 预先分配系统内存
    if ((os_mem = my_malloc(OS_MEM_SIZE)) == NULL)
        PANIC("初始化失败");
    printf("系统初始化成功\n");

    repl();

    return 0;
}
Exemplo n.º 24
0
void repl_driver(void)
{
    int k;
    k = setjmp(errjmp);
    if (k == 2) return;
    signal(SIGFPE,handle_sigfpe);
    signal(SIGINT,handle_sigint);
    close_open_files();
    errjmp_ok = 1;
    nointerrupt = 0;
    if (init_file && (k == 0)) vload(init_file);
    repl();
}
Exemplo n.º 25
0
int main(int argc, char *argv[]) {
	/* Name of the programme */
	char progname[] = "sesh";
	char progversion[] = "0.4.0";

	/* Arguments table */
	void *argtable[] = {
		help    = arg_litn("h", "help", 0, 1, "Display this help and exit"),
		version = arg_litn("v", "version", 0, 1, "Display version info and exit"),
		end     = arg_end(20),
	};

	/* Number of errors analysing arguments */
	int nerrors = arg_parse(argc, argv, argtable);

	/* If help needed we don't care about the errors */
	if (help->count > 0) {
		printf("Usage: %s", progname);
		arg_print_syntax(stdout, argtable, "\n");
		arg_print_glossary(stdout, argtable, "  %-25s %s\n");
		
		arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
		return 0;
	}

	/* If errors occured */
	if (nerrors > 0) {
		/* Displaying the error information */
		arg_print_errors(stdout, end, progname);
		printf("Try '%s --help' for more information.\n", progname);
		
		arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
		return 1;
	}

	if (version->count > 0) {
		printf("Version: %s %s\n", progname, progversion);

		arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
		return 0;
	}

	history_init();
	term_set_driver();
	repl();	
	term_reset_driver();

	arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
	return 0;
}
Exemplo n.º 26
0
bool ValueAnnotation::
is_value_restrict_op( AstInterface& fa, const AstNodePtr& exp, 
                    Collect2Object< AstNodePtr, HasValueDescriptor>* descp,
                     MapObject<SymbolicVal, SymbolicVal>* valMap,
                     Map2Object<AstInterface*, AstNodePtr, AstNodePtr>* astcodegen)
{
  RestrictValueOpDescriptor desc;
  if (!valueRestrict.known_operator( fa, exp, 0, &desc, true, astcodegen))
    return false;
  if (descp == 0)
     return true;
  ReplaceValue repl( fa, valMap);
  for (RestrictValueOpDescriptor::const_iterator p = desc.begin(); 
        p != desc.end(); ++p) {
      RestrictValueDescriptor cur = *p; 
      AstNodePtr curast;
      if (!cur.first.get_val().isAstWrap(curast))
         assert(false);
      HasValueDescriptor curval = cur.second;
      if (repl(curval)) {
         if (DebugValuePropogate()) {
             std::cerr << "found restrict value : " << AstInterface::AstToString(curast) << ":" << AstInterface::AstToString(exp);
             curval.Dump();
             std::cerr << std::endl;
          }
         (*descp)( curast, curval);
      }
      else {
        if (DebugValuePropogate()) {
             std::cerr << "discard restrict value : " << AstInterface::AstToString(curast) << ":" << AstInterface::AstToString(exp);
             curval.Dump();
             std::cerr << std::endl;
          }
      }
  }
  return true;
}
Exemplo n.º 27
0
// Restarts the vm.
void cmd_restart(char **_){
    FILE *in;
    void repl(void);
    void init_regs(void);
    pthread_cancel(input_thread);
    free_regs();
    init_regs();
    in = fopen(binary_fl,"r");
    if (!in){
        fprintf(stderr,"Error: Unable to open file '%s'\n",binary_fl);
        exit(-1);
    }
    load_file(&sysmem,0,in);
    repl();
}
Exemplo n.º 28
0
int main() {
        // Seed the random number generator with the current time.
        // Don't do this for anything serious like crypto.
        srand(time(0));
        // Generate the list of rooms.
        generate_rooms();
        // Serialize the list of rooms to a file and directory structure
        serialize_rooms(rooms_list);
        // Read them back
        struct room *read_rum = deserialize_rooms();
        // Enter the game loop
        repl();
        destroy_rooms(read_rum);
        return 0;
}
Exemplo n.º 29
0
int main(int argc, char *argv[]) {
  FILE *input = ((argc > 1) ? fopen(argv[1], "r") : stdin);

  if (!input) {
	fprintf(stderr, "[%s] failed to open file\n", __func__);
	exit(EXIT_FAILURE);
  }

  environment_t *env = init_environment();

  repl(input, &env, argc);

  fclose(input);

  return EXIT_SUCCESS;
}
Exemplo n.º 30
0
int main(int argc, char **argv) {
    int firstarg;

    config.hostip = "127.0.0.1";
    config.hostport = 6379;
    config.repeat = 1;
    config.dbnum = 0;
    config.interactive = 0;
    config.shutdown = 0;
    config.monitor_mode = 0;
    config.pubsub_mode = 0;
    config.raw_output = 0;
    config.stdinarg = 0;
    config.auth = NULL;
    config.historyfile = NULL;
    config.tty = isatty(fileno(stdout)) || (getenv("FAKETTY") != NULL);
    config.mb_sep = '\n';

    if (getenv("HOME") != NULL) {
        config.historyfile = malloc(256);
        snprintf(config.historyfile,256,"%s/.rediscli_history",getenv("HOME"));
        linenoiseHistoryLoad(config.historyfile);
    }

    firstarg = parseOptions(argc,argv);
    argc -= firstarg;
    argv += firstarg;

    if (config.auth != NULL) {
        char *authargv[2];
        int dbnum = config.dbnum;

        /* We need to save the real configured database number and set it to
         * zero here, otherwise cliSendCommand() will try to perform the
         * SELECT command before the authentication, and it will fail. */
        config.dbnum = 0;
        authargv[0] = "AUTH";
        authargv[1] = config.auth;
        cliSendCommand(2, convertToSds(2, authargv), 1);
        config.dbnum = dbnum; /* restore the right DB number */
    }

    /* Start interactive mode when no command is provided */
    if (argc == 0) repl();
    /* Otherwise, we have some arguments to execute */
    return noninteractive(argc,convertToSds(argc,argv));
}