Exemple #1
0
/* Parse a single argument with matching templates. */
static int
parse_arg(struct fuse_args* args, int *argi, const char* arg,
		struct fuse_args *outargs, void *data,
		const struct fuse_opt *opts, fuse_opt_proc_t proc, bool is_opt)
{
	int sep_idx;
	const struct fuse_opt *opt = find_opt(opts, arg, &sep_idx);

	if (opt) {
		/* An argument can match to multiple templates. Process them
		 * all. */
		for (; opt != NULL && opt->templ != NULL;
			opt = find_opt(++opt, arg, &sep_idx)) {

			if (sep_idx > 0 && opt->templ[sep_idx] == ' ' &&
				arg[sep_idx] == '\0') {
				/* The template "-x %y" requests a separate
				 * parameter "%y". Try to find one. */
				char *new_arg;
				int rv;

				if (next_arg(args, argi) == -1)
					return -1;

				/* ...but processor callbacks expect a concatenated
				 * argument "-xfoo". */
				if ((new_arg = malloc(sep_idx +
									strlen(args->argv[*argi]) + 1)) == NULL)
					return -1;

				strncpy(new_arg, arg, sep_idx); /* -x */
				strcpy(new_arg + sep_idx, args->argv[*argi]); /* foo */
				rv = parse_matched_arg(new_arg, outargs, opt, sep_idx,
									data, proc, is_opt);
				free(new_arg);

				if (rv == -1)
					return -1;
			}
			else {
				int rv;
				rv = parse_matched_arg(arg, outargs, opt, sep_idx,
									data, proc, is_opt);
				if (rv == -1)
					return -1;
			}
		}
		return 0;
	}
	else {
		/* No templates matched to it so just invoke the callback. */
		return call_proc(proc, data, arg, FUSE_OPT_KEY_OPT, outargs, is_opt);
	}
}
void
test ()
{
  HSTMT hstmt;
  SQLRETURN rc;

  rc = SQLAllocHandle (SQL_HANDLE_STMT, (SQLHANDLE) hdbc,
      (SQLHANDLE *) & hstmt);
  if (rc != SQL_SUCCESS)
    {
      err_printf ("SQLAllocHandle() failed.\n");
      return;
    }

  rc = SQLPrepare (hstmt, "burstoff_rs_proc ()", SQL_NTS);
  if (rc != SQL_SUCCESS)
    {
      err_printf ("prepare failed.\n");
      error (SQL_HANDLE_STMT, (SQLHANDLE) hstmt);
      exit (1);
    }

  call_proc (10);
  printf ("test: SQLExecute\n");

  rc = SQLExecute (hstmt);
  if (rc != SQL_SUCCESS)
    {
      err_printf ("exec failed.\n");
      error (SQL_HANDLE_STMT, (SQLHANDLE) hstmt);
      exit (1);
    }
  printf ("test: SQLFetch\n");
  rc = SQLFetch (hstmt);
  if (rc != SQL_SUCCESS)
    {
      err_printf ("fetch failed.\n");
      error (SQL_HANDLE_STMT, (SQLHANDLE) hstmt);
      exit (1);
    }
  printf ("test: SQLCancel\n");
  rc = SQLCancel (hstmt);
  if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)
    {
      err_printf ("SQLCancel() failed.\n");
      exit (-1);
    }

  printf ("test: SQLFreeHandle\n");
  rc = SQLFreeHandle (SQL_HANDLE_STMT, (SQLHANDLE) hstmt);
}
Exemple #3
0
/* Parse a single argument with a matched template. */
static int
parse_matched_arg(const char* arg, struct fuse_args *outargs,
		const struct fuse_opt* opt, int sep_idx, void* data,
		fuse_opt_proc_t proc, bool is_opt)
{
	if (opt->offset == -1) {
		/* The option description does not want any variables to be
		 * updated.*/
		if (call_proc(proc, data, arg, opt->value, outargs, is_opt) == -1)
			return -1;
	}
	else {
		void *var = (char*)data + opt->offset;

		if (sep_idx > 0 && opt->templ[sep_idx + 1] == '%') {
			/* "foo=%y" or "-x %y" */
			const char* param =
				opt->templ[sep_idx] == '=' ? &arg[sep_idx + 1] : &arg[sep_idx];

			if (opt->templ[sep_idx + 2] == 's') {
				char* dup = strdup(param);
				if (dup == NULL)
					return -1;

				*(char **)var = dup;
			}
			else {
				/* The format string is not a literal. We all know
				 * this is a bad idea but it's exactly what fuse_opt
				 * wants to do... */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
				if (sscanf(param, &opt->templ[sep_idx + 1], var) == -1) {
#pragma GCC diagnostic pop
					(void)fprintf(stderr, "fuse: '%s' is not a "
								"valid parameter for option '%.*s'\n",
								param, sep_idx, opt->templ);
					return -1;
				}
			}
		}
		else {
			/* No parameter format is given. */
			*(int *)var = opt->value;
		}
	}
	return 0;
}
Exemple #4
0
static int process_gopt(struct fuse_opt_context *ctx, const char *arg, int iso)
{
    unsigned sep;
    const struct fuse_opt *opt = find_opt(ctx->opt, arg, &sep);
    if (opt) {
        for (; opt; opt = find_opt(opt + 1, arg, &sep)) {
            int res;
            if (sep && opt->templ[sep] == ' ' && !arg[sep])
                res = process_opt_sep_arg(ctx, opt, sep, arg, iso);
            else
                res = process_opt(ctx, opt, sep, arg, iso);
            if (res == -1)
                return -1;
        }
        return 0;
    } else
        return call_proc(ctx, arg, FUSE_OPT_KEY_OPT, iso);
}
Exemple #5
0
static int process_opt(struct fuse_opt_context *ctx,
		       const struct fuse_opt *opt, unsigned sep,
		       const char *arg, int iso)
{
	if (opt->offset == -1U) {
		if (call_proc(ctx, arg, opt->value, iso) == -1)
			return -1;
	} else {
		void *var = ctx->data + opt->offset;
		if (sep && opt->templ[sep + 1]) {
			const char *param = arg + sep;
			if (opt->templ[sep] == '=')
				param ++;
			if (process_opt_param(var, opt->templ + sep + 1,
					      param, arg) == -1)
				return -1;
		} else
			*(int *)var = opt->value;
	}
	return 0;
}
Exemple #6
0
static int process_one(struct fuse_opt_context *ctx, const char *arg)
{
    if (ctx->nonopt || arg[0] != '-')
        return call_proc(ctx, arg, FUSE_OPT_KEY_NONOPT, 0);
    else if (arg[1] == 'o') {
        if (arg[2])
            return process_option_group(ctx, arg + 2);
        else {
            if (next_arg(ctx, arg) == -1)
                return -1;

            return process_option_group(ctx, ctx->argv[ctx->argctr]);
        }
    } else if (arg[1] == '-' && !arg[2]) {
        if (add_arg(ctx, arg) == -1)
            return -1;
        ctx->nonopt = ctx->outargs.argc;
        return 0;
    } else
        return process_gopt(ctx, arg, 0);
}
Exemple #7
0
static int
parse_all(struct fuse_args *args, struct fuse_args *outargs, void *data,
		const struct fuse_opt *opts, fuse_opt_proc_t proc)
{
	bool nonopt = false; /* Have we seen the "--" marker? */
	int i;

	/* The first argument, the program name, is implicitly
	 * FUSE_OPT_KEY_KEEP. */
	if (args->argc > 0) {
		if (fuse_opt_add_arg(outargs, args->argv[0]) == -1)
			return -1;
	}

	/* the real loop to process the arguments */
	for (i = 1; i < args->argc; i++) {
		const char *arg = args->argv[i];

		/* argvn != -foo... */
		if (nonopt || arg[0] != '-') {
			if (call_proc(proc, data, arg, FUSE_OPT_KEY_NONOPT,
						outargs, false) == -1)
				return -1;
		}
		/* -o or -ofoo */
		else if (arg[1] == 'o') {
			/* -oblah,foo... */
			if (arg[2] != '\0') {
				/* skip -o */
				if (parse_opts(args, &i, arg + 2, outargs,
							data, opts, proc) == -1)
					return -1;
			}
			/* -o blah,foo... */
			else {
				if (next_arg(args, &i) == -1)
					return -1;
				if (parse_opts(args, &i, args->argv[i], outargs,
							data, opts, proc) == -1)
					return -1;
			}
		}
		/* -- */
		else if (arg[1] == '-' && arg[2] == '\0') {
			if (fuse_opt_add_arg(outargs, arg) == -1)
				return -1;
			nonopt = true;
		}
		/* -foo */
		else {
			if (parse_arg(args, &i, arg, outargs,
						data, opts, proc, false) == -1)
				return -1;
		}
	}

	/* The "--" marker at the last of outargs should be removed */
	if (nonopt && strcmp(outargs->argv[outargs->argc - 1], "--") == 0) {
		free(outargs->argv[outargs->argc - 1]);
		outargs->argv[--outargs->argc] = NULL;
	}

	return 0;
}
Exemple #8
0
/*
 * @brief
 * 本函数实现向数据库中存放Books的信息
 * @name Add
 * @arg
 * pObj QObject* :@class Books*, 需要添加到数据库的信息
 * @return bool
 * true 执行成功
 * false 执行失败
 * @author
 * QiumingLu Email:[email protected]
 * @test
 * no
 */
bool DaoBooks::Add(Books *pObj)
{
    Q_ASSERT(pObj != NULL);
    QStringList outFields("BOOK_ID");   //primary key
    return call_proc(pObj, "BOOKS_INSERT_PROC", outFields);
}
Exemple #9
0
int main(int argc, char** argv)
{
  int ret;
  
  setup_dir();
  
  /* init globals */
  gcc = sa_concat(gcc, "gcc"); /* replaced laterwards if c++ */
  gcc = sa_concat(gcc, "-I.");
  
  src_lines =
    sa_concat(src_lines,
	      "#define __LARGE_C__ " VERSION_INT_STR "\n"
	      "#ifdef __cplusplus\n"
	      "extern \"C\" {\n"
	      "#endif\n"
	      "#include <stdio.h>\n"
	      "#include <stdlib.h>\n"
	      "#ifdef __cplusplus\n"
	      "}\n"
	      "#include <iostream>\n"
	      "using namespace std;\n"
	      "#endif\n"
	      "\n"
	      "__LARGE_C_PREFIX__\n");
  
  argv++;
  { /* parse args, determine cache dir */
    char** new_argv = parse_args(argv, NULL, 0);
    for (; argv != new_argv; argv++) {
      add_spec(*argv, strlen(*argv) + 1);
    }
    if (! keep_files && (oneliner || *argv != NULL)) {
      struct stat st;
      if (oneliner) {
	build_store_dir();
      } else if (stat(*argv, &st) == 0) {
	add_spec(*argv, strlen(*argv) + 1);
	add_spec(&st.st_size, sizeof(st.st_size));
	add_spec(&st.st_mtime, sizeof(st.st_mtime));
	build_store_dir();
      }
    }
  }
  
  /* use cache if possible */
  if (store_dir != NULL && check_specs()) {
    char** child_argv = NULL;
#ifdef _WIN32
    _utime(store_dir, NULL); /* update mtime of the directory */
#else
    utimes(store_dir, NULL); /* update mtime of the directory */
#endif
    exec_file = str_concat(str_dup(store_dir), "/"A_OUT);
    child_argv = sa_concat(child_argv, exec_file);
#ifdef _WIN32
    {
      int status;
	  ret = spawn_w32(child_argv, &status);
      if (status == 0) exit(ret);
    }
#else
    execv(exec_file, child_argv);
#endif
    // if execv failed, we compile
    free(exec_file);
    remove_dir(store_dir);
  }
  
  /* prepare files */
  make_temp_dir();
  exec_file = str_concat(str_dup(temp_dir), "/"A_OUT);
  c_file = str_concat(str_dup(temp_dir), "/source.c");
  if ((src_fp = fopen(c_file, "wt")) == NULL) {
    cmd_error("failed to create temporary file: %s : %s\n", c_file,
	      strerror(errno));
  }
  while (src_lines != NULL && *src_lines != NULL) {
    fputs(*src_lines++, src_fp);
  }
  
  /* write source with adjustments */
  if (! oneliner) {
    FILE* fp;
    char* file;
    char* line;
    int line_no = 0;
    if (argv[0] == NULL) {
      fp = stdin;
      file = "stdin";
    } else if (strcmp(argv[0], "-") == 0) {
      fp = stdin;
      argv++;
      file = "stdin";
    } else {
      file = *argv++;
      if ((fp = fopen(file, "rt")) == NULL) {
	cmd_error("cannot open file: %s : %s\n", file, strerror(errno));
      }
      fprintf(src_fp, "# 1 \"%s\" 1\n", file);
    }
    while ((line = get_line(fp)) != NULL) {
      int comment_out = 0;
      line_no++;
      if (line_no == 1 && strncmp(line, "#!", 2) == 0) {
	comment_out = 1;
      } else if (line[0] == '#') {
	char* buf = str_dup(line + 1);
	char** tokens = split_tokens(buf);
	if (*tokens != NULL) {
	  if (strcmp(tokens[0], "option") == 0) {
	    parse_args(tokens + 1, file, line_no);
	    comment_out = 1;
	  }
	}
	free(buf);
	free(tokens);
      }
      if (comment_out == 1) {
	fprintf(src_fp, "// ");
      }
      fputs(line, src_fp);
    }
    fputs("\n", src_fp);
    if (fp != stdin) {
      fclose(fp);
    }
  }
  
  /* close source file */
  fputs("__LARGE_C_SUFFIX__\n", src_fp);
  fclose(src_fp);
  src_fp = NULL;
  
  /* compile */
  if (use_plusplus) {
    gcc[0] = "g++";
  }
  if (use_main) {
    gcc = sa_concat(gcc, "-D__LARGE_C_PREFIX__=");
    gcc = sa_concat(gcc, "-D__LARGE_C_SUFFIX__=");
  } else {
    gcc =
      sa_concat(gcc, "-D__LARGE_C_PREFIX__=int main(int argc, char** argv) {");
    gcc = sa_concat(gcc, "-D__LARGE_C_SUFFIX__=; return 0; }");
  }
  gcc = sa_concat(gcc, "-o");
  gcc = sa_concat(gcc, show_disassembly ? "-" : exec_file);
  gcc = sa_concat(gcc, c_file);
  gcc = sa_merge(gcc, lopts);
  if ((ret = call_proc(gcc, "could not execute compiler")) != 0) {
    cleanup();
    exit(ret);
  }
  
  if (show_disassembly) {
    cleanup();
    exit(0);
  }
  
  { /* execute */
    char** child_argv = NULL;
    if (use_debugger) {
      child_argv = sa_concat(child_argv, "gdb");
    }
    child_argv = sa_concat(child_argv, exec_file);
    child_argv = sa_merge(child_argv, argv);
    ret = call_proc(child_argv, "could not spawn child process");
  }
  
  /* move temp_dir to store_dir, if possible.
   * or, remove work_dir
   */
  if (store_dir == NULL) {
    cleanup();
  } else {
    save_specs();
    update_cache();
    if (rename(temp_dir, store_dir) != 0) {
      cleanup();
    }
  }
  
  return ret;
}