示例#1
0
文件: highlvl.c 项目: BENGMN/soen490
void 
install0(char *name, char *code, char *gpname, char *lib)
{
  FARPROC f;
  HMODULE handle;
#ifdef WINCE
  short wlib[256], wname[256];

  MultiByteToWideChar(CP_ACP, 0, lib, strlen(lib)+1, wlib, 256);
  MultiByteToWideChar(CP_ACP, 0, name, strlen(name)+1, wname, 256);
  lib = wlib;
  name = wname;
#endif

#ifdef DL_DFLT_NAME
  if (! *lib) lib = DL_DFLT_NAME;
#endif
  if (! *gpname) gpname=name;
  if (lib) lib = expand_tilde(lib);
  
  handle = LoadLibrary(lib);
  if (!handle)
  {
    if (lib) pari_err(talker,"couldn't open dynamic library '%s'",lib);
    pari_err(talker,"couldn't open dynamic symbol table of process");
  }
  f = GetProcAddress(handle,name);
  if (!f)
  {
    if (lib) pari_err(talker,"can't find symbol '%s' in library '%s'",name,lib);
    pari_err(talker,"can't find symbol '%s' in dynamic symbol table of process",name);
  }
  if (lib) free(lib);
  install((void*)f,gpname,code);
}
示例#2
0
文件: highlvl.c 项目: BENGMN/soen490
void 
install0(char *name, char *code, char *gpname, char *lib)
{
  void *f, *handle;

  if (! *lib) lib = DL_DFLT_NAME;
  if (! *gpname) gpname = name;
  if (lib) lib = expand_tilde(lib);

#ifndef RTLD_GLOBAL /* OSF1 has dlopen but not RTLD_GLOBAL*/
#  define RTLD_GLOBAL 0
#endif
  handle = dlopen(lib, RTLD_LAZY|RTLD_GLOBAL);

  if (!handle)
  {
    const char *s = dlerror(); if (s) fprintferr("%s\n\n",s);
    if (lib) pari_err(talker,"couldn't open dynamic library '%s'",lib);
    pari_err(talker,"couldn't open dynamic symbol table of process");
  }
  f = dlsym(handle, name);
  if (!f)
  {
    if (lib) pari_err(talker,"can't find symbol '%s' in library '%s'",name,lib);
    pari_err(talker,"can't find symbol '%s' in dynamic symbol table of process",name);
  }
  if (lib) free(lib);
  install(f, gpname, code);
}
示例#3
0
svector *load_text_file(const char *filename)
{
	svector *vec;
	char *t;

	if(filename[0] == '/')
		return do_load_text_file(filename);
	t = expand_tilde(filename);
	if(t != NULL)
	{
		vec = do_load_text_file(t);
		delete[] t;
		return vec;
	}
	
	vec = search_text_file(config->project_dir, filename);
	if(vec != NULL) return vec;
	vec = search_text_file(config->home_style_dir, filename);
	if(vec != NULL) return vec;
	vec = search_text_file(config->env_style_dir, filename);
	if(vec != NULL) return vec;
	vec = search_text_file(config->sys_style_dir, filename);
	if(vec != NULL) return vec;
	
	error("Cannot locate text file <%s>", filename);
	return NULL;
}
示例#4
0
/* extern int qsort(); */

static int
#ifndef ANSI_PROTOTYPES
name_cmp(s1, s2)
    char **s1;
    char **s2;
#else /* ANSI_PROTOTYPES */
name_cmp(char **s1, char **s2)
#endif /* ANSI_PROTOTYPES */
{
    return strcmp(*s1, *s2);
}


char *
#ifndef ANSI_PROTOTYPES
expand_tilde(pat)
    char *pat;
#else /* ANSI_PROTOTYPES */
expand_tilde(char *pat)
#endif /* ANSI_PROTOTYPES */
{
    static char buf[BUFSIZ];

    struct passwd *pw;
    char *tmp;
    char *bp;

    if (*pat != '~')
	return 0;

    pat++;
    if (*pat && *pat != '/')
    {
	bp = buf;
	for (tmp = pat; *tmp && *tmp != '/'; )
	    *bp++ = *tmp++;
	*bp = '\0';

	pw = getpwnam(buf);
	if (pw == 0)
	{
	    (void)sprintf(globerr_buf, "%s: Unknown user.", pat);
	    globerr = globerr_buf;
	    return 0;
	}
	pat = tmp ? tmp : "";
	tmp = pw->pw_dir;
    }
    else
    {
	if (*pat)
	    pat++;
	tmp = (char *)getenv("HOME");
     }

    for (bp = buf; *tmp; )
	*bp++ = *tmp++;
    *bp++ = '/';

    while (*pat)
	*bp++ = *pat++;
    *bp = '\0';

    return buf;
}

char **
#ifndef ANSI_PROTOTYPES
glob(pat)
    char *pat;
#else /* ANSI_PROTOTYPES */
glob(char *pat)
#endif /* ANSI_PROTOTYPES */
{
    char **names;
    int nnames;

    if (*pat == '~')
    {
	pat = expand_tilde(pat);
	if (pat == 0)
	    return 0;
    }

    nnames = glob_path(pat, &names);

    switch (nnames)
    {
      case -1:
	globerr = sys_errlist[errno];
	return 0;
      case 0:
	globerr = "No match.";
	return 0;
      default:
	qsort(names, nnames, sizeof(char *), name_cmp);
	return names;
    }
}
示例#5
0
文件: connect.c 项目: Schala/mhxd
static void
open_bookmark (GtkWidget *widget, gpointer data)
{
	struct connect_context *cc = (struct connect_context *)gtk_object_get_data(GTK_OBJECT(widget), "cc");
	char *file = (char *)data;
	FILE *fp;
	char line1[64];
	char line2[64];
	char line3[64];
	char path[MAXPATHLEN], buf[MAXPATHLEN];

	snprintf(buf, sizeof(buf), "~/.hx/bookmarks/%s", file);
	expand_tilde(path, buf);
	xfree(file);

	fp = fopen(path, "r");
	if (fp) {
		line1[0] = line2[0] = line3[0];
		fgets(line1, 64, fp);
		fgets(line2, 64, fp);
		fgets(line3, 64, fp);
		line1[strlen(line1)-1] = 0;
		if (strlen(line2))
			line2[strlen(line2)-1] = 0;
		if (strlen(line3))
			line3[strlen(line3)-1] = 0;
		connect_set_entries(cc, line1, line2, line3);
		fclose(fp);
	} else {
		g_message("No such file.  Bummer!");
	}
}
示例#6
0
文件: connect.c 项目: Schala/mhxd
static void
list_bookmarks (GtkWidget *menu, struct connect_context *cc)
{
	struct dirent *de;
	char *file;
	char path[MAXPATHLEN];
	GtkWidget *item;
	DIR *dir;

	expand_tilde(path, "~/.hx/bookmarks");
	dir = opendir(path);
	if (!dir)
		return;
	while ((de = readdir(dir))) {
		if (*de->d_name != '.') {
			file = xstrdup(de->d_name);
			item = gtk_menu_item_new_with_label(file);
			gtk_menu_append(GTK_MENU(menu), item);
			gtk_object_set_data(GTK_OBJECT(item), "cc", cc);
			gtk_signal_connect(GTK_OBJECT(item), "activate",
					   GTK_SIGNAL_FUNC(open_bookmark), file);
		}
	}
	closedir(dir);
}
示例#7
0
static int cmd_sym_load_add(int clear, char **arg)
{
	FILE *in;
	char * path;

	if (clear && prompt_abort(MODIFY_SYMS))
		return 0;

	path = expand_tilde(*arg);
	if (!path)
		return -1;

	in = fopen(path, "rb");
	free(path);
	if (!in) {
		printc_err("sym: %s: %s\n", *arg, last_error());
		return -1;
	}

	if (clear) {
		stab_clear();
		unmark_modified(MODIFY_SYMS);
	} else {
		mark_modified(MODIFY_SYMS);
	}

	if (binfile_syms(in) < 0) {
		fclose(in);
		return -1;
	}

	fclose(in);

	return 0;
}
示例#8
0
size_t unpack_dirname(char * to, const char *from)
{
  size_t length, h_length;
  char buff[FN_REFLEN+1+4],*suffix,*tilde_expansion;
  DBUG_ENTER("unpack_dirname");

  length= normalize_dirname(buff, from);

  if (buff[0] == FN_HOMELIB)
  {
    suffix=buff+1; tilde_expansion=expand_tilde(&suffix);
    if (tilde_expansion)
    {
      length-= (size_t) (suffix-buff)-1;
      if (length+(h_length= strlen(tilde_expansion)) <= FN_REFLEN)
      {
	if ((h_length > 0) && (tilde_expansion[h_length-1] == FN_LIBCHAR))
	  h_length--;
	if (buff+h_length < suffix)
	  bmove(buff+h_length,suffix,length);
	else
	  bmove_upp((uchar*) buff+h_length+length, (uchar*) suffix+length, length);
	bmove(buff,tilde_expansion,h_length);
      }
    }
  }
#ifdef USE_SYMDIR
  if (my_use_symdir)
    symdirget(buff);
#endif
  DBUG_RETURN(system_filename(to,buff));	/* Fix for open */
} /* unpack_dirname */
示例#9
0
文件: startup.c 项目: mlum/postgres
/*
 * Load .psqlrc file, if found.
 */
static void
process_psqlrc(char *argv0)
{
	char		home[MAXPGPATH];
	char		rc_file[MAXPGPATH];
	char		my_exec_path[MAXPGPATH];
	char		etc_path[MAXPGPATH];
	char       *envrc;

	find_my_exec(argv0, my_exec_path);
	get_etc_path(my_exec_path, etc_path);

	snprintf(rc_file, MAXPGPATH, "%s/%s", etc_path, SYSPSQLRC);
	process_psqlrc_file(rc_file);

	envrc = getenv("PSQLRC");
	
	if (envrc != NULL && strlen(envrc) > 0)
	{
		expand_tilde(&envrc);
		process_psqlrc_file(envrc);
	}
	else if (get_home_path(home))
	{
		snprintf(rc_file, MAXPGPATH, "%s/%s", home, PSQLRC);
		process_psqlrc_file(rc_file);
	}
}
示例#10
0
文件: fileswin.cpp 项目: nixz/covise
static void workingdir_apply_notify_proc(Widget, XtPointer, XtPointer)
{
    Arg args;
    XmString list_item;
    char *s;
    char buf[MAXPATHLEN];

    XtSetArg(args, XmNtextString, &list_item);
    XtGetValues(workingd_dialog, &args, 1);
    XmStringGetLtoR(list_item, charset, &s);
    strcpy(buf, s);
    XtFree(s);

    if (buf[0] == '~')
    {
        expand_tilde(buf);
    }
    if (chdir(buf) >= 0)
    {
        strcpy(workingdir, buf);
        set_title(workingdir);
        XmFileSelectionDoSearch(workingd_dialog, NULL);
    }
    else
    {
        errwin("Can't change to directory");
    }
    XtUnmanageChild(workingd_dialog);
}
示例#11
0
/*
 * Load .psqlrc file, if found.
 */
static void
process_psqlrc(char *argv0)
{
    char		home[MAXPGPATH];
    char		rc_file[MAXPGPATH];
    char		my_exec_path[MAXPGPATH];
    char		etc_path[MAXPGPATH];
    char	   *envrc = getenv("PSQLRC");

    if (find_my_exec(argv0, my_exec_path) < 0)
    {
        fprintf(stderr, _("%s: could not find own program executable\n"), argv0);
        exit(EXIT_FAILURE);
    }

    get_etc_path(my_exec_path, etc_path);

    snprintf(rc_file, MAXPGPATH, "%s/%s", etc_path, SYSPSQLRC);
    process_psqlrc_file(rc_file);

    if (envrc != NULL && strlen(envrc) > 0)
    {
        /* might need to free() this */
        char	   *envrc_alloc = pstrdup(envrc);

        expand_tilde(&envrc_alloc);
        process_psqlrc_file(envrc_alloc);
    }
    else if (get_home_path(home))
    {
        snprintf(rc_file, MAXPGPATH, "%s/%s", home, PSQLRC);
        process_psqlrc_file(rc_file);
    }
}
示例#12
0
文件: tfFileIO_.c 项目: KatsOide/SAD
static int ReadLink(integer4 *isp1,
		    integer8 *kx,
		    integer4 *irtc) {
  integer8 ia;
  integer4 nc;
  char *expanded, buf[MAXPATHLEN];

  if(isp != *isp1 + 1) {
    *irtc = itfmessage(9, "General::narg", "\"1\"");
    return -1;
  }
  if((ktfmask & ktastk( *isp1 + 1)) != ktfstring) {
    *irtc = itfmessage(9, "General::wrongtype", "\"String\"");
    return -1;
  }

  ia = (ktamask & ktastk(*isp1 + 1));
#if SAD_REQUIRE_STRING_TERMINATION
  jlist(ilist(1, ia) + 1, ia + 1) = '\0';
#endif

  expanded = expand_tilde(&jlist(1, ia + 1));
  if(expanded == NULL) {
    *kx = ktfoper + mtfnull;;
    *irtc = 0;
#ifdef SAD_THROW_EXCEPTION
    switch(errno) {
    case ENOMEM:
      *irtc = itfsyserr(9);
      break;

    default:
      *irtc = itfmessage(9, "System::error",
			 "\"No such home directory\"");
    }
#ifdef SAD_NOBREAK_EXCEPTION
    *irtc = 0;
#endif
#endif
    return 1;
  }

  nc = readlink(expanded, buf, sizeof(buf)); free(expanded);
  if(nc < 0) {
    *kx = ktfoper + mtfnull;;
    *irtc = 0;
#ifdef SAD_THROW_EXCEPTION
    *irtc = itfsyserr(9);
#ifdef SAD_NOBREAK_EXCEPTION
    *irtc = 0;
#endif
#endif
    return 1;
  }

  *kx = ktfstring + ktsalocbl(-1, buf, nc);
  *irtc = 0;
  return 0;
}
示例#13
0
static void readline_exit(void)
{
	char *path = expand_tilde(HISTORY_FILENAME);
	if (path) {
		write_history(path);
		free(path);
	}
}
示例#14
0
/* Performs custom pattern expansion.  Allocate new expanded string. */
static char *
pattern_expand_hook(const char pattern[])
{
	char *const no_tilde = expand_tilde(pattern);
	char *const expanded_pattern = expand_envvars(no_tilde, 0);
	free(no_tilde);

	return expanded_pattern;
}
示例#15
0
文件: shell.c 项目: Estella/wraith
char *move_bin(const char *ipath, const char *file, bool run)
{
  char *path = strdup(ipath);

  expand_tilde(&path);

  /* move the binary to the correct place */
  static char newbin[DIRMAX] = "";
  char real[DIRMAX] = "";

  simple_snprintf(newbin, sizeof newbin, "%s%s%s", path, path[strlen(path) - 1] == '/' ? "" : "/", file);

  ContextNote(STR("realpath()"));
  realpath(binname, real);            /* get the realpath of binname */
  ContextNote(STR("realpath(): Success"));
  /* running from wrong dir, or wrong bin name.. lets try to fix that :) */
  sdprintf(STR("binname: %s"), binname);
  sdprintf(STR("newbin: %s"), newbin);
  sdprintf(STR("real: %s"), real);
  if (strcmp(binname, newbin) && strcmp(newbin, real)) {              /* if wrong path and new path != current */
    bool ok = 1;

    sdprintf(STR("wrong dir, is: %s :: %s"), binname, newbin);

    unlink(newbin);
    if (copyfile(binname, newbin))
      ok = 0;

    if (ok && !can_stat(newbin)) {
       unlink(newbin);
       ok = 0;
    }

    if (ok && fixmod(newbin)) {
        unlink(newbin);
        ok = 0;
    }

    if (ok) {
      sdprintf(STR("Binary successfully moved to: %s"), newbin);
      unlink(binname);
      if (run) {
        simple_snprintf(newbin, sizeof newbin, "%s%s%s", 
                        path, path[strlen(path) - 1] == '/' ? "" : "/", shell_escape(file));
        system(newbin);
        sdprintf(STR("exiting to let new binary run..."));
        exit(0);
      }
    } else {
      if (run)
        werr(ERR_WRONGBINDIR);
      sdprintf(STR("Binary move failed to: %s"), newbin);
      return binname;
    }
  }
  return newbin;
}
示例#16
0
文件: menu.c 项目: acklinr/vifm
/* Writes all menu lines into file specified as argument. */
static int
write_cmd(const cmd_info_t *cmd_info)
{
	char *const no_tilde = expand_tilde(cmd_info->argv[0]);
	if(write_file_of_lines(no_tilde, menu->items, menu->len) != 0)
	{
		show_error_msg("Failed to open output file", strerror(errno));
	}
	free(no_tilde);
	return 0;
}
示例#17
0
Test(tilde_expansion, in_the_middle)
{
    char *result = expand_tilde(
        "xstarter, ~/xstarter, xstarter",
        mock_home
    );

    cr_assert_str_eq(
        result,
        "xstarter, /xstarter/xstarter, xstarter"
    );
}
示例#18
0
Test(tilde_expansion, multiple_expansions)
{
    char *result = expand_tilde(
        "~/xs1, $PATH, ~/xs2, ~/xs3, xs",
        mock_home
    );

    cr_assert_str_eq(
        result,
        "/xstarter/xs1, $PATH, /xstarter/xs2, /xstarter/xs3, xs"
    );
}
示例#19
0
static int readline_init(void)
{
	char *path = expand_tilde(HISTORY_FILENAME);
	if (path) {
		read_history(path);
		free(path);
	}

	rl_attempted_completion_function = mspdebug_completion;

	return 0;
}
示例#20
0
Test(tilde_expansion, two_expansions)
{
    char *result = expand_tilde(
        "~/xstarter, $PATH, ~/xstarter",
        mock_home
    );

    cr_assert_str_eq(
        result,
        "/xstarter/xstarter, $PATH, /xstarter/xstarter"
    );
}
示例#21
0
/*
 * Put any startup stuff related to input in here. It's good to maintain
 * abstraction this way.
 *
 * The only "flag" right now is 1 for use readline & history.
 */
void
initializeInput(int flags)
{
#ifdef USE_READLINE
	if (flags & 1)
	{
		const char *histfile;
		char		home[MAXPGPATH];

		useReadline = true;
		initialize_readline();

		useHistory = true;
		using_history();
		history_lines_added = 0;

		histfile = GetVariable(pset.vars, "HISTFILE");

		if (histfile == NULL)
		{
			char	   *envhist;

			envhist = getenv("PSQL_HISTORY");
			if (envhist != NULL && strlen(envhist) > 0)
				histfile = envhist;
		}

		if (histfile == NULL)
		{
			if (get_home_path(home))
			{
				psql_history = pg_malloc(strlen(home) + 1 +
										 strlen(PSQLHISTORY) + 1);
				snprintf(psql_history, MAXPGPATH, "%s/%s", home, PSQLHISTORY);
			}
		}
		else
		{
			psql_history = pg_strdup(histfile);
			expand_tilde(&psql_history);
		}

		if (psql_history)
		{
			read_history(psql_history);
			decode_history();
		}
	}
#endif

	atexit(finishInput);
}
示例#22
0
static gchar *tab_completion_get_text(TabCompData *td)
{
	gchar *text;

	text = g_strdup(gtk_entry_get_text(GTK_ENTRY(td->entry)));

	if (text[0] == '~')
		{
		gchar *t = text;
		text = expand_tilde(text);
		g_free(t);
		}

	return text;
}
示例#23
0
bool path_can_be_implicit_cd(const wcstring &path, wcstring *out_path, const wchar_t *wd,
                             const env_vars_snapshot_t &vars) {
    wcstring exp_path = path;
    expand_tilde(exp_path);

    bool result = false;
    if (string_prefixes_string(L"/", exp_path) || string_prefixes_string(L"./", exp_path) ||
        string_prefixes_string(L"../", exp_path) || string_suffixes_string(L"/", exp_path) ||
        exp_path == L"..") {
        // These paths can be implicit cd, so see if you cd to the path. Note that a single period
        // cannot (that's used for sourcing files anyways).
        result = path_get_cdpath(exp_path, out_path, wd, vars);
    }
    return result;
}
示例#24
0
unsigned char *get_next_path_filename( unsigned char **path_ptr, unsigned char separator )
{
  int eax;
  int ecx;
  unsigned char *path;
  unsigned char *filename;
  int filenamelen;
  path[0] = path_ptr[0];
{
  unsigned char *tmp;
  filenamelen = 0;
  if ( path[0] & 255 )
  {
    if ( path[0] != separator )
    {
      do
      {
        path[0] = path[1];
        if ( path[0] == 0 )
          filenamelen = path[0] - path[0];
        else
        {
          path_ptr[0] = path_ptr[0];
        }
      }
      while ( path[0] != separator );
      filenamelen = path[0] - path[0];
    }
    path_ptr[0] = &path[1];
    if ( filenamelen >= 1 )
    {
      if ( memacpy( &path[0], filenamelen ) )
      {
        mem_free( (void*)memacpy( &path[0], filenamelen ) );
        return expand_tilde( memacpy( &path[0], filenamelen ) );
      }
      filename[0] = 0;
    }
  }
  path_ptr[0] = &path[0];
  if ( filenamelen >= 1 )
  {
  }
  path_ptr[0] = &path[1];
}
}
示例#25
0
/*
 * Put any startup stuff related to input in here. It's good to maintain
 * abstraction this way.
 *
 * The only "flag" right now is 1 for use readline & history.
 */
void
initializeInput(int flags)
{
#ifdef USE_READLINE
	if (flags & 1)
	{
		const char *histfile;
		char		home[MAXPGPATH];

		useReadline = true;
		initialize_readline();

		useHistory = true;
		using_history();

		histfile = GetVariable(pset.vars, "HISTFILE");
		if (histfile == NULL)
		{
			if (get_home_path(home))
			{
				psql_history = pg_malloc(strlen(home) + 1 +
										 strlen(PSQLHISTORY) + 1);
				snprintf(psql_history, MAXPGPATH, "%s/%s", home, PSQLHISTORY);
			}
		}
		else
		{
			psql_history = pg_strdup(histfile);
			expand_tilde(&psql_history);
		}

		if (psql_history)
		{
			read_history(psql_history);
			decode_history();
		}
	}
#endif

#ifdef HAVE_ATEXIT
	atexit(finishInput);
#else
	on_exit(finishInput, NULL);
#endif
}
示例#26
0
文件: mf_pack.c 项目: OPSF/uClinux
uint unpack_dirname(my_string to, const char *from)
{
  uint length,h_length;
  char buff[FN_REFLEN+1+4],*suffix,*tilde_expansion;
  DBUG_ENTER("unpack_dirname");

  (void) intern_filename(buff,from);		/* Change to intern name */
  length= (uint) strlen(buff);			/* Fix that '/' is last */
  if (length &&
#ifdef FN_DEVCHAR
      buff[length-1] != FN_DEVCHAR &&
#endif
      buff[length-1] != FN_LIBCHAR && buff[length-1] != '/')
  {
    buff[length]=FN_LIBCHAR;
    buff[length+1]= '\0';
  }

  length=cleanup_dirname(buff,buff);
  if (buff[0] == FN_HOMELIB)
  {
    suffix=buff+1; tilde_expansion=expand_tilde(&suffix);
    if (tilde_expansion)
    {
      length-=(uint) (suffix-buff)-1;
      if (length+(h_length= (uint) strlen(tilde_expansion)) <= FN_REFLEN)
      {
	if (tilde_expansion[h_length-1] == FN_LIBCHAR)
	  h_length--;
	if (buff+h_length < suffix)
	  bmove(buff+h_length,suffix,length);
	else
	  bmove_upp(buff+h_length+length,suffix+length,length);
	bmove(buff,tilde_expansion,h_length);
      }
    }
  }
#ifdef USE_SYMDIR
  if (my_use_symdir)
    symdirget(buff);
#endif
  DBUG_RETURN(system_filename(to,buff));	/* Fix for open */
} /* unpack_dirname */
示例#27
0
文件: devcmd.c 项目: noccy80/mspdebug
static int hexout_start(struct hexout_data *hexout, const char *filename)
{
	char * path = NULL;

	path = expand_tilde(filename);
	if (!path)
		return -1;

	hexout->file = fopen(path, "w");
	free(path);

	if (!hexout->file) {
		pr_error("hexout: couldn't open output file");
		return -1;
	}

	hexout->addr = 0;
	hexout->len = 0;
	hexout->segoff = 0;

	return 0;
}
示例#28
0
文件: tfFileIO_.c 项目: KatsOide/SAD
/* SADScript function definition of FileIO stuff */
static int ExpandTilde(integer4 *isp1,
		       integer8 *kx,
		       integer4 *irtc) {
  integer8 ia;
  char *expanded;

  if(isp != *isp1 + 1) {
    *irtc = itfmessage(9, "General::narg", "\"1\"");
    return -1;
  }

  if((ktfmask & ktastk(*isp1 + 1)) != ktfstring) {
    *irtc = itfmessage(9, "General::wrongtype", "\"String\"");
    return -1;
  }

  ia = (ktamask & ktastk(*isp1 + 1));
#if SAD_REQUIRE_STRING_TERMINATION
  jlist(ilist(1, ia) + 1, ia + 1) = '\0';
#endif

  expanded = expand_tilde(&jlist(1, ia + 1));
  if(expanded == NULL) {
    switch(errno) {
    case ENOMEM:
      *irtc = itfsyserr(9);
      break;

    default:
      *irtc = itfmessage(9, "System::error",
			 "\"No such home directory\"");
    }
    return 1;
  }

  *kx = ktfstring + ktsalocb(-1, expanded); free(expanded);
  *irtc = 0;
  return 0;
}
示例#29
0
string
find_path_filename P2C(string, filename,  string *, dir_list)
{
  string found_name = NULL;
  
  /* Do this before testing for absolute-ness, as a leading ~ will be an
     absolute pathname.  */
  filename = expand_tilde (filename);
  
  /* If FILENAME is absolute or explicitly relative, or if DIR_LIST is
     null, only check if FILENAME is readable.  */
  if (absolute_p (filename) || dir_list == NULL)
    found_name = readable (filename);
  else
    { /* Test if FILENAME is in any of the directories in DIR_LIST.  */
      string save_filename = filename;
      
      while (*dir_list != NULL)
        {
          filename = concat (*dir_list, save_filename);
          found_name = readable (filename);
          if (found_name == NULL)
            {
              free (filename);
              dir_list++;
            }
          else
            {
              if (found_name != filename)
                free (filename);
              break;
            }
        }
    }
  
  return found_name;
}
示例#30
0
文件: copy.c 项目: colinet/sqlix
static struct copy_options *
parse_slash_copy(const char *args)
{
	struct copy_options *result;
	char* token;
	const char *whitespace = " \t\n\r";
	char nonstd_backslash = standard_strings() ? 0 : '\\';

	if (!args) {
		psql_error("\\copy: arguments required\n");
		return NULL;
	}

	result = pg_calloc(1, sizeof(struct copy_options));
	result->before_tofrom = pg_strdup("");		/* initialize for appending */
	token = strtokx(args, whitespace, ".,()", "\"", 0, false, false, pset.encoding);
	if (!token)
		goto error;

	/* The following can be removed when we drop 7.3 syntax support */
	if (pg_strcasecmp(token, "binary") == 0) {
		xstrcat(&result->before_tofrom, token);
		token = strtokx(NULL, whitespace, ".,()", "\"", 0, false, false, pset.encoding);
		if (!token)
			goto error;
	}

	/* Handle COPY (SELECT) case */
	if (token[0] == '(') {
		int parens = 1;

		while (parens > 0) {
			xstrcat(&result->before_tofrom, " ");
			xstrcat(&result->before_tofrom, token);
			token = strtokx(NULL, whitespace, "()", "\"'",
				nonstd_backslash, true, false, pset.encoding);
			if (!token)
				goto error;

			if (token[0] == '(')
				parens++;
			else if (token[0] == ')')
				parens--;
		}
	}

	xstrcat(&result->before_tofrom, " ");
	xstrcat(&result->before_tofrom, token);
	token = strtokx(NULL, whitespace, ".,()", "\"", 0, false, false, pset.encoding);
	if (!token)
		goto error;

	/*
	 * strtokx() will not have returned a multi-character token starting with
	 * '.', so we don't need strcmp() here.  Likewise for '(', etc, below.
	 */
	if (token[0] == '.') {
		/* handle schema . table */
		xstrcat(&result->before_tofrom, token);
		token = strtokx(NULL, whitespace, ".,()", "\"", 
				0, false, false, pset.encoding);
		if (!token)
			goto error;

		xstrcat(&result->before_tofrom, token);
		token = strtokx(NULL, whitespace, ".,()", "\"",
				0, false, false, pset.encoding);
		if (!token)
			goto error;
	}

	if (token[0] == '(') {
		/* handle parenthesized column list */
		for (;;) {
			xstrcat(&result->before_tofrom, " ");
			xstrcat(&result->before_tofrom, token);
			token = strtokx(NULL, whitespace, "()", "\"",
					0, false, false, pset.encoding);
			if (!token)
				goto error;

			if (token[0] == ')')
				break;
		}
		xstrcat(&result->before_tofrom, " ");
		xstrcat(&result->before_tofrom, token);
		token = strtokx(NULL, whitespace, ".,()", "\"",
				0, false, false, pset.encoding);
		if (!token)
			goto error;
	}

	if (pg_strcasecmp(token, "from") == 0)
		result->from = true;
	else if (pg_strcasecmp(token, "to") == 0)
		result->from = false;
	else
		goto error;

	token = strtokx(NULL, whitespace, NULL, "'", 0, false, true, pset.encoding);
	if (!token)
		goto error;

	if (pg_strcasecmp(token, "stdin") == 0
		|| pg_strcasecmp(token, "stdout") == 0) {
		result->psql_inout = false;
		result->file = NULL;
	} else if (pg_strcasecmp(token, "pstdin") == 0
		|| pg_strcasecmp(token, "pstdout") == 0) {
		result->psql_inout = true;
		result->file = NULL;
	} else {
		result->psql_inout = false;
		result->file = pg_strdup(token);
		expand_tilde(&result->file);
	}

	/* Collect the rest of the line (COPY options) */
	token = strtokx(NULL, "", NULL, NULL, 0, false, false, pset.encoding);
	if (token)
		result->after_tofrom = pg_strdup(token);

	return result;

error:
	if (token)
		psql_error("\\copy: parse error at \"%s\"\n", token);
	else
		psql_error("\\copy: parse error at end of line\n");

	free_copy_options(result);
	return NULL;
}