コード例 #1
0
ファイル: filter.c プロジェクト: rubicks/rlwrap
void handle_out_of_band(int tag, char *message) {
    int split_em_up = FALSE;
    switch (tag) {
    case TAG_ERROR:
        if (expected_tag == TAG_COMPLETION) /* start new line when completing (looks better) */
            fprintf(stderr, "\n"); /* @@@ error reporting (still) uses bufered I/O */
        myerror(FATAL|NOERRNO, message);
    case TAG_OUTPUT_OUT_OF_BAND:
        my_putstr(message);
        break;
    case TAG_ADD_TO_COMPLETION_LIST:
    case TAG_REMOVE_FROM_COMPLETION_LIST:
        split_em_up = TRUE;
        break;
    case TAG_IGNORE:
        break;
    default:
        myerror(FATAL|USE_ERRNO, "out-of-band message with unknown tag %d: <%20s>", tag, message);
    }
    if (split_em_up) {
        char **words = split_with(message, " \n\t");
        char **plist, *word;
        for(plist = words; (word = *plist); plist++)
            if (tag == TAG_ADD_TO_COMPLETION_LIST)
                add_word_to_completions(word);
            else
                remove_word_from_completions(word);
        free_splitlist(words);
    }
    free(message);
}
コード例 #2
0
ファイル: rcfile.c プロジェクト: sunny256/suuid
char *get_rcfilename(const struct Options *opt)
{
	char *retval = NULL, *env;
	size_t size;

	assert(opt);

	if (opt && opt->rcfile) {
		retval = strdup(opt->rcfile);
		if (!retval)
			myerror("Cannot duplicate --rcfile argument");
		return retval;
	}
	env = getenv("HOME");
	if (!env) {
		fprintf(stderr, "%s: HOME environment variable not defined, "
		                "cannot determine name of rcfile\n", progname);
		return NULL;
	}
	size = strlen(env) + strlen(STD_RCFILE) + 32;
	retval = malloc(size);
	if (!retval) {
		myerror("Could not allocate %lu bytes for rcfile name", size);
		return NULL;
	}
	snprintf(retval, size, "%s/%s", env, STD_RCFILE); /* fixme: slash */

	return retval;
}
コード例 #3
0
ファイル: io.c プロジェクト: sunny256/suuid
char *read_from_fp(FILE *fp)
{
	char *retval = NULL;
	char *p = NULL;
	size_t bytes_read = 0, total_bytes_read = 0;
	size_t bufsize = BUFSIZ;

	assert(fp);

	do {
		char *new_mem = realloc(retval,
		                        bufsize + total_bytes_read + 1);
		if (!new_mem) {
			myerror("read_from_fp(): Cannot allocate memory for "
			        "stream buffer");
			free(retval);
			return NULL;
		}
		retval = new_mem;
		p = retval + total_bytes_read;
		bytes_read = fread(p, 1, bufsize, fp);
		total_bytes_read += bytes_read;
		p[bytes_read] = '\0';
		if (ferror(fp)) {
			myerror("read_from_fp(): Read error");
			free(retval);
			return NULL;
		}
	} while (!feof(fp));

	return retval;
}
コード例 #4
0
ファイル: DbUtil.cpp プロジェクト: 0x00xw/mysql-2
int
DbUtil::connect()
{
  if (!(m_mysql = mysql_init(NULL)))
  {
    myerror("DB connect-> mysql_init() failed");
    return DBU_FAILED;
  }

  /* Load connection parameters file and group */
  if (mysql_options(m_mysql, MYSQL_READ_DEFAULT_FILE, m_default_file.c_str()) ||
      mysql_options(m_mysql, MYSQL_READ_DEFAULT_GROUP, m_default_group.c_str()))
  {
    myerror("DB Connect -> mysql_options failed");
    return DBU_FAILED;
  }

  /*
    Connect, read settings from my.cnf
    NOTE! user and password can be stored there as well
   */

  if (mysql_real_connect(m_mysql, NULL, "root","", m_dbname.c_str(), 
                         0, NULL, 0) == NULL)
  {
    myerror("connection failed");
    mysql_close(m_mysql);
    return DBU_FAILED;
  }
  selectDb();
  m_connected = true;
  return DBU_OK;
}
コード例 #5
0
ファイル: mysql_client_fw.c プロジェクト: lanqiyi/CacheDB
static my_bool thread_query(const char *query)
{
 MYSQL *l_mysql;
 my_bool error;

 error= 0;
 if (!opt_silent)
 fprintf(stdout, "\n in thread_query(%s)", query);
 if (!(l_mysql= mysql_client_init(NULL)))
 {
   myerror("mysql_client_init() failed");
   return 1;
 }
 if (!(mysql_real_connect(l_mysql, opt_host, opt_user,
 opt_password, current_db, opt_port,
 opt_unix_socket, 0)))
 {
   myerror("connection failed");
   error= 1;
   goto end;
 }
 l_mysql->reconnect= 1;
 if (mysql_query(l_mysql, query))
 {
   fprintf(stderr, "Query failed (%s)\n", mysql_error(l_mysql));
   error= 1;
   goto end;
 }
 mysql_commit(l_mysql);
 end:
 mysql_close(l_mysql);
 return error;
}
コード例 #6
0
ファイル: mallocv.c プロジェクト: abumami/Shuffle
void *reallocv(char *filename, u_int32_t line, void *ptr, size_t size) {
	
	
	size_t delSize=0;

	if (ptr) {
		delSize=del(&list, ptr);
		if (!delSize) {
#if DEBUG >= 4
			myerror("No memory allocated for ptr %x freed (realloc) at %s:%u!", ptr, filename, line);
#endif
		}
		mem_used -= delSize;
	}

	void* newPtr = realloc(ptr, size);

	if (size && (newPtr == NULL)) {
		stderror();
		exit(1);		
	}

	if (newPtr)
		add(&list, newPtr, size, filename, line);
	
	mem_used += size;
	
#if DEBUG >= 3
	myerror("%d bytes reallocated in %s:%u, old ptr=%x, new ptr=%x (total memory %d)!", size-delSize, filename, line, ptr, newPtr, mem_used);
#endif

	return newPtr;
}
コード例 #7
0
ファイル: lua.c プロジェクト: maxhauser/tinyfugue
struct Value *handle_loadlua_command(String *args, int offset)
{
	// check if lua has been initialised
	if(lua_state == NULL)
	{ // it hasn't: initialise now
		lua_state = lua_open();
		luaL_openlibs(lua_state);

		// add our tf_eval() function for Lua scripts to call
		lua_register(lua_state, "tf_eval", tfeval_for_lua);
		// add tf_getvar() function
        lua_register(lua_state, "tf_getvar", getvar_for_lua);
	}

	// now read and execute the scripts that user asked for
	if(luaL_dofile(lua_state, args->data + offset) != 0)
	{
		myerror("Cannot load script: ");
		myerror(lua_tostring(lua_state, -1));
		lua_pop(lua_state, 1);
		return newint(1);
	}

	return newint(0);
}
コード例 #8
0
ファイル: Networkmodule.c プロジェクト: Sudoka/base
static PyObject *
ethernet_ntoa(PyObject *self, PyObject *args)
{
	char *nstr;
	char *astr;
	eth_addr_t eth_a;
	int rval;
	int nsize;
	struct intf_entry *entry = NULL;

	rval = PyArg_ParseTuple(args, "s#:eth_ntoa",
					&nstr, &nsize);

	if (!rval) return NULL;
	
	/* printf("Got addresses %s, %s\n", astr, bstr); */
	if (nsize != ETH_ADDR_LEN)
		myerror("Address is wrong length");

	memcpy(&eth_a, nstr, nsize);

	astr = eth_ntoa(&eth_a);
	if (!astr)
		myerror("Could not convert address");

	return Py_BuildValue("s", astr);
}
コード例 #9
0
ファイル: Networkmodule.c プロジェクト: Sudoka/base
static PyObject *
netcmp(PyObject *self, PyObject *args)
{
	char *astr;
	char *bstr;
	struct addr a;
	struct addr b;
	int rval;
	int cmp = 0;
	struct intf_entry *entry = NULL;

	rval = PyArg_ParseTuple(args, "ss:netcmp",
					&astr, &bstr);

	if (!rval) return NULL;
	
	/* printf("Got addresses %s, %s\n", astr, bstr); */

	rval = addr_pton(astr, &a);
	if (rval<0)
			myerror("Could not read first address");

	rval = addr_pton(bstr, &b);
	if (rval<0)
			myerror("Could not read second address");

	cmp = addr_cmp(&a, &b);

	return Py_BuildValue("i", cmp);
}
コード例 #10
0
ファイル: pars.c プロジェクト: queer1/rforensicbatwing
void read_parameters_data(parameters *p) {
    int i,integertmp=0;
    p->genetic_data=readcharintegermatrix(openinputfile(p->datafilename),
                                          &(p->samplesize),&(p->nloci));
    p->nSTR=p->nloci-p->ninf;
    if (p->samplesize<=1) {
      Rprintf("only one individual, unable to analyse this\n\n");
      error("error");
    }
    if (p->labelfilename!=NULL) {
      //    printf("reading from file %s\n",p->labelfilename);
      p->labels=readstrings(p->labelfilename,p->samplesize,20);
      for (i=1;i<=p->samplesize;i++) {
	Rprintf("%s ",p->labels[i]);
	Rprintf("\n");
      }
    } else {
      p->labels=NULL;
    }
    if (p->locationfilename!=NULL) {  /*  need to do this because of difficulties with fltk"*/
        if (strcmp(p->locationfilename,"")==0) {
            FREE(p->locationfilename);
            p->locationfilename=NULL;
        }
    }
    if (p->locationfilename==NULL) {
        p->location=NULL;
        p->npopulations=0;
        if (p->migmodel)
	  myerror("need locations for migration model");
    } else {
        p->location=readintegervector(openinputfile(p->locationfilename),&(integertmp));
        if (p->npopulations==0) {
            for (i=1;i<=integertmp;i++) {
                if (p->location[i]>p->npopulations)
                    p->npopulations=p->location[i];
            }
        }
        if (integertmp!=p->samplesize) {
	  Rprintf("locations %d not the same as # samples %d\n",integertmp,p->samplesize);
            error("error");
        }
    }
    if (p->migmodel)
        p->propprior.par[0]=(double)p->npopulations;

    if (p->npriors==p->locustypes[0]) {
        if (p->locustypes[0]==1&&p->locustypes[1]!=1) {
            if (p->locustypes[1]!=p->nSTR)
                myerror("incorrect locustype - need locustypes equal to number of STR loci");
        } else if (p->locustypes[0]!=1) {
            integertmp = 0;
            for (i=1;i<=p->locustypes[0];i++)
                integertmp+=p->locustypes[i];
            if (integertmp!=p->nSTR)
                myerror("incorrect locustype - sum does not equal number of STR loci");
        }
    } //else myerror("incorrect number of mutation rate priors");
}
コード例 #11
0
ファイル: klient.c プロジェクト: kgadek/kpfp
int main(int argc, char **argv) {
	int tmp;
	int i;
	int j;
	int msgCnt = 0;
	clMsg myMsg;

	srand((uint)time(0));
	if(argc != 2)
		myerror("Nieprawidłowa ilość argumentów! (Podaj jeden -- nazwę klienta)",1);

	myMsg.type = 72;
	strncpy(myMsg.myNameIs, argv[1], CLNAMELEN);
	myMsg.myNameIs[CLNAMELEN-1] = 0;
	myMsg.myCard = getpid();

	signal(SIGINT, makeMeQuit); /*och proszę, niech będą te dwa polecenia atomowe...*/
	tmp = atexit(myatexit);
	if(tmp != 0) {
		myatexit();
		myerror("Błąd atexit()!",2);
	}

	KS_h = mq_open(KSNAME,O_WRONLY);
	if(KS_h == (mqd_t)-1)
		myerror("Błąd mq_open (KS)!",1);
	KK_h = mq_open(KKNAME,O_RDONLY);
	if(KK_h == (mqd_t)-1) {
		tmp = mq_close(KS_h);
		if(tmp == -1)
			fprintf(stderr,"Błąd zamknięcia kolejki KS! errno=%d\n",errno);
		myerror("Błąd mq_open (KK)!",3);
	}

	signal(SIGUSR1, sigSigSigSigSigSig);
	for(;;) { /*klientujemy*/
		printf("Ile mesydżów wysłać? : ");
		scanf(" %d",&msgCnt);
		if(msgCnt < 0) {
			printf("\nBłąd -- podano ujemną liczbę!\n");
			continue;
		}

		for(i=0;i<msgCnt;++i) {
			j = rand()%CLMSGLEN;
			myMsg.iWantToSay[j+1] = 0;
			for(; j >= 0; --j)
				myMsg.iWantToSay[j] = getRandomChar();
			showClMsg(&myMsg,0);
			tmp = mq_send(KS_h, (char*)&myMsg, sizeof(clMsg), 0);
			if(tmp == -1)
				myerror("Błąd mq_send!",4);
			hr();
		}
	}

	return 0;
}
コード例 #12
0
ファイル: genuuid.c プロジェクト: sunny256/suuid
char *process_comment_option(const char *cmt)
{
	char *retval;

	assert(cmt);

	if (!strcmp(cmt, "-")) {
		/*
		 * Read comment from stdin.
		 */
		retval = read_from_fp(stdin);
		if (!retval) {
			myerror("Could not read data from stdin");
			return NULL;
		}
	} else if (!strcmp(cmt, "--")) {
		/*
		 * Open the user's favourite editor and edit the comment there 
		 * in a temporary file.
		 */
		char *e;

		e = get_editor();
		if (!e)
			return NULL;
		retval = read_from_editor(e);
		free(e);
		if (!retval)
			return NULL;
	} else {
		/*
		 * The comment was stored as a plain string in the -c/--comment 
		 * argument.
		 */
		retval = strdup(cmt);
		if (!retval) {
			myerror("%s: Cannot allocate memory for comment, "
			        "strdup() failed");
			return NULL;
		}
	}
	if (!valid_xml_chars(retval)) {
		fprintf(stderr, "%s: Comment contains illegal characters or "
		                "is not valid UTF-8\n", progname);
		free(retval);
		return NULL;
	}

	/* fixme: This is how it's done in the Perl version. I'm not sure if 
	 * it's an ok thing to do, even though it looks nice in the log files 
	 * and has worked great for years. Maybe this behaviour should be 
	 * changed when the C version passes all tests in suuid.t .
	 */
	trim_str_front(retval);
	trim_str_end(retval);

	return retval;
}
コード例 #13
0
ファイル: mallocv.c プロジェクト: abumami/Shuffle
void reportLeaks() {
	struct sList *tmp=&list;
	while(tmp->next != NULL) {
		myerror("%d bytes allocated for ptr %x at %s:%u were not freed!",
			tmp->next->size, tmp->next->ptr, tmp->next->file, tmp->next->line);
		tmp = tmp->next;
	}
	myerror("Total bytes not freed: %d", mem_used);
}
コード例 #14
0
ファイル: signals.c プロジェクト: junjiemars/rlwrap
static void
handle_sigTSTP(int signo)
{
    sigset_t all_signals;
    int error, saved_errno = errno;

    DEBUG_RANDOM_SLEEP;
    sigfillset(&all_signals);

    DPRINTF2(DEBUG_SIGNALS, "got %s, sending it to pgid %d", signal_name(signo), command_pid);
    zero_select_timeout();
    /* Hand the SIGTSTP down to command and its process group */
    if (command_pid && (error = kill(-command_pid, SIGTSTP))) {
        myerror(FATAL|USE_ERRNO, "Failed to deliver SIGTSTP");
    }

    if (within_line_edit)
        save_rl_state();


    mysignal(SIGTSTP, SIG_DFL);   /* reset disposition to default (i.e. suspend) */
    sigprocmask(SIG_UNBLOCK, &all_signals, NULL); /* respond to sleep- and wake-up signals  */
    kill(getpid(), SIGTSTP); /* suspend */
    /* keyboard gathers dust, kingdoms crumble,.... */

    /* .... */

    /* Beautiful princess types "fg", (or her father tries to kill us...) and we wake up HERE: */
    sigprocmask(SIG_BLOCK, &all_signals, NULL);
    mysignal(SIGTSTP, &handle_sigTSTP);
    DPRINTF0(DEBUG_SIGNALS, "woken up");

    /* On most systems, command's process group will have been woken up by the handler of
       the signal that woke us up. This doesn't seem to happen for SIGCONT on QNX, so here goes: */

#ifdef __QNX__
    if (command_pid && (error = kill(-command_pid, SIGCONT))) {
        myerror(FATAL|USE_ERRNO, "Failed to deliver SIGCONT");
    }
#endif

    if (within_line_edit) {
        restore_rl_state();
    } else {
        set_echo(FALSE);
        cr();
        if (skip_rlwrap())
            return;
        move_cursor_to_start_of_prompt(ERASE);
        cook_prompt_if_necessary();
        my_putstr(saved_rl_state.cooked_prompt);
    }
    adapt_tty_winsize(STDIN_FILENO, master_pty_fd);       /* just in case */
    errno = saved_errno;
    sigprocmask(SIG_UNBLOCK, &all_signals, NULL);
}
コード例 #15
0
ファイル: genuuid.c プロジェクト: sunny256/suuid
int fill_entry_struct(struct Entry *entry, const struct Rc *rc,
                      const struct Options *opt)
{
	unsigned int i;

	assert(entry);
	assert(rc);
	assert(opt);

	/*
	 * Get information about the environment; hostname, current directory, 
	 * login name and tty.
	 *
	 * Fixme: Add check so this and the session info thing are run only 
	 * once. Only has some effect if creating many UUIDs.
	 */

	entry->host = get_hostname(rc);
	if (!entry->host) {
		myerror("fill_entry_struct(): Cannot get hostname");
		return EXIT_FAILURE;
	}
	if (!valid_hostname(entry->host)) {
		myerror("fill_entry_struct(): Got invalid hostname: \"%s\"",
		        entry->host);
		return EXIT_FAILURE;
	}
	entry->cwd = getpath();
	entry->user = get_username();
	entry->tty = get_tty();

	/*
	 * Store tags and comment in entry.
	 */

	for (i = 0; i < MAX_TAGS && opt->tag[i]; i++)
		if (store_tag(entry, opt->tag[i]) == EXIT_FAILURE)
			return EXIT_FAILURE;

	if (opt->comment) {
		entry->txt = process_comment_option(opt->comment);
		if (!entry->txt)
			return EXIT_FAILURE;
	}

	/*
	 * Store session information from the environment variable.
	 */

	if (get_sess_info(entry) == EXIT_FAILURE) {
		free(entry->txt);
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
コード例 #16
0
ファイル: sessvar.c プロジェクト: sunny256/suuid
const char *add_to_sessvar(const char *desc, const char *uuid)
{
	size_t envlen; /* Length of the new string */
	char *sessvar; /* Copy of the original envvar */
	char *envbuf; /* Temporary buffer for the finished string */

	assert(valid_uuid(uuid, TRUE));

	if (!is_valid_desc_string(desc))
		desc = NULL;

	if (getenv(ENV_SESS)) {
		char *ap;

		ap = strdup(getenv(ENV_SESS));
		clean_up_sessvar(ap);
		sessvar = strdup(ap);
		free(ap);
	} else
		sessvar = strdup("");
	if (!sessvar) {
		myerror("add_to_sessvar(): Could not duplicate %s "
		        "environment variable", ENV_SESS);
		return NULL;
	}

	envlen = strlen(ENV_SESS) + 1 + strlen(sessvar) + 1 +
	         strlen(desc) + 1 + UUID_LENGTH + 1 + 1;
	envbuf = malloc(envlen);
	if (!envbuf) {
		myerror("Could not allocate %lu bytes for %s buffer",
		        envlen, ENV_SESS);
		free(sessvar);
		return NULL;
	}

	snprintf(envbuf, envlen,
	         "%s=%s,%s%s%s,",
	         ENV_SESS,
	         sessvar ? sessvar : "",
	         desc ? desc : "",
	         desc ? "/" : "",
	         uuid);

	if (putenv(envbuf)) {
		myerror("Could not set %s environment variable", ENV_SESS);
		free(sessvar);
		return NULL;
	}

	free(sessvar);

	return getenv(ENV_SESS);
}
コード例 #17
0
ファイル: slice.c プロジェクト: Ingwar/amuse
int skiptagheader(FILE *f, Slice *s)
/* Read the first 8 bytes from the tag file.  Check that the first int equals
the number of particles.  Return the second, which is the number of groups */
{
    int dummy[2];
    if (fread(&dummy, 4, 2, f)!=2) myerror("Error in reading tag file.");
    if (s->numpart!=0 && dummy[0]!=s->numpart) 
	myerror("First number in tag file doesn't match expected number of particles.");
    s->numgroups = dummy[1];
    return dummy[1];
}
コード例 #18
0
ファイル: sessvar.c プロジェクト: sunny256/suuid
int run_session(const struct Options *orig_opt,
                const int argc, char * const argv[])
{
	int retval = EXIT_SUCCESS;
	struct Options opt = *orig_opt;
	char *cmd = NULL;
	char *start_uuid = NULL;
	char *cmd_desc = NULL;
	struct uuid_result result;

	assert(orig_opt);
	assert(argv);

	cmd = concat_cmd_string(argc, argv);
	if (!cmd)
		return -1;
	cmd_desc = get_desc_from_command(cmd);
	msg(2, "cmd_desc = \"%s\"", cmd_desc);

	opt.count = 1;
	opt.whereto = "e";
	result = create_and_log_uuids(&opt);
	if (!result.success) {
		myerror("Error generating UUID, session not started");
		retval = -1;
		goto cleanup;
	}
	start_uuid = strdup(result.lastuuid);
	if (!start_uuid) {
		myerror("Could not duplicate start UUID");
		retval = -1;
		goto cleanup;
	}
	assert(valid_uuid(start_uuid, TRUE));
	msg(3, "old %s: \"%s\"", ENV_SESS, getenv(ENV_SESS));
	add_to_sessvar(cmd_desc, start_uuid);
	msg(3, "new %s: \"%s\"", ENV_SESS, getenv(ENV_SESS));

	msg(1, "Executing \"%s\"", cmd);
	retval = system(cmd); /* fixme: This value is shifted with 8 bits in 
	                       * main(). Check if it's ok.
	                       */
	msg(2, "run_session(): retval from system() = %d (0x%x)",
	       retval, retval);

cleanup:
	free(start_uuid);
	free(cmd_desc);
	free(cmd);

	return(retval);
}
コード例 #19
0
ファイル: rcfile.c プロジェクト: sunny256/suuid
int read_rcfile(const char *rcfile, struct Rc *rc)
{
	FILE *fp;
	char buf[BUFSIZ];

	assert(rc);

	rc->hostname = NULL;
	rc->macaddr = NULL;
	rc->uuidcmd = NULL;

	if (!rcfile)
		return EXIT_SUCCESS;

	fp = fopen(rcfile, "r");
	if (!fp)
		return EXIT_SUCCESS; /* It's perfectly fine if it's not 
		                      * readable, that probably means it 
		                      * doesn't exist.
		                      */

	do {
		if (!fgets(buf, BUFSIZ, fp) && errno) {
			myerror("%s: Could not read from rcfile", rcfile);
			fclose(fp);
			return EXIT_FAILURE;
		}
		trim_str_front(buf);
		trim_str_end(buf);
		if (parse_rc_line(buf, rc) == EXIT_FAILURE) {
			myerror("Could not allocate memory for line from "
			        "rc file \"%s\"", rcfile);
			fclose(fp);
			return EXIT_FAILURE;
		}
		*buf = '\0';
	} while (!feof(fp));

	fclose(fp);

	if (rc->macaddr && !strlen(rc->macaddr)) {
		/* Keyword with no value, that's ok */
		free(rc->macaddr);
		rc->macaddr = NULL;
	}
	if (rc->macaddr && !valid_macaddr(rc->macaddr))
		return EXIT_FAILURE;

	return EXIT_SUCCESS;
}
コード例 #20
0
ファイル: mallocv.c プロジェクト: abumami/Shuffle
void freev(char *filename, u_int32_t line, void *ptr) {
	
	size_t size=del(&list, ptr);
	if (size) {
		mem_used-=size;
		free(ptr);
#if DEBUG >= 3		
		myerror("%d bytes freed in %s:%u (total memory %d)!", size, filename, line, mem_used);
#endif
	} else {
#if DEBUG >= 4
		myerror("No memory allocated for ptr %x freed at %s:%u!", ptr, filename, line);
#endif
	}
}
コード例 #21
0
bool Connection::sendMsg(string msg) {
  int res = send(sock, msg.c_str(), msg.size(), 0);
  if (res < 0) 
    myerror("Unable to send");
  string answer = readLine();
  return answer == "ok";
}
コード例 #22
0
ファイル: bidl_parser.cpp プロジェクト: alemic/BGCC
ParseResult* BidlParser::parse_fp(FILE* fp) {
    if (!fp) {
        return NULL;
    }

    ParseResult* parse_result = new ParseResult;
    if (!parse_result) {
        return NULL;
    }

    parse_result->bt = new BidlNamespace;
    if (!parse_result->bt) {
        delete parse_result;
        parse_result = NULL;
        g_cur_bidl_namespace = NULL;
        return NULL;
    }

    g_parseresult = parse_result;
    yyin = fp;
    yylineno = 1;

    if (0 != yyparse()) {
        myerror("failed to parse bidl file %s", g_cur_bidl_file_name.c_str());
    }

    set_symtab_name(parse_result->bt, "");

    return parse_result;
}
コード例 #23
0
ファイル: bidl_parser.cpp プロジェクト: alemic/BGCC
void BidlParser::check_type_and_value(const BidlType* bt) {
    if (!bt) {
        return;
    }

    const BidlConst* c = dynamic_cast<const BidlConst*>(bt);
    if (!c) {
        return;
    }

    const BidlType* field_type = c->get_field_type();
    const BidlType* value = c->get_value();

    if (!field_type || !value) {
        return;
    }

    const BidlType* real_field_type = field_type->get_real_type();
    if (!real_field_type) {
        return;
    }

    if (!do_check_type_and_value(real_field_type, value)) {
        myerror("%s: %d: error: type and value mismatched: %s\n",
                bt->get_filename().c_str(),
                bt->get_line(),
                bt->get_name().c_str());
    }
}
コード例 #24
0
ファイル: sessvar.c プロジェクト: sunny256/suuid
char *concat_cmd_string(const int argc, char * const argv[])
{
	int t;
	size_t cmdsize = 0;
	char *cmd = NULL;

	assert(argv);

	for (t = optind; t < argc; t++) {
		msg(3, "Non-option arg: %s", argv[t]);
		cmdsize += strlen(argv[t]) + 1; /* Add one for space */
	}
	cmdsize += 1; /* Terminating '\0' */
	cmd = malloc(cmdsize);
	if (!cmd) {
		myerror("Could not allocate %lu bytes for command string",
		        cmdsize);
		return NULL;
	}
	memset(cmd, 0, cmdsize);

	for (t = optind; t < argc; t++) {
		strcat(cmd, argv[t]);
		strcat(cmd, " ");
	}
	if (strlen(cmd) && cmd[strlen(cmd) - 1] == ' ')
		cmd[strlen(cmd) - 1] = '\0'; /* Remove added space */
	if (!strlen(cmd)) {
		fprintf(stderr, "%s: Command is empty\n", progname);
		free(cmd);
		return NULL;
	}

	return cmd;
}
コード例 #25
0
static void GetDialogInfo (HWND hwnd, LPSTRUCTINFO lpinfo)
{
	char szBuf[100];

	GetDlgItemText (hwnd, IDC_ROWS, szBuf, sizeof (szBuf));
	lpinfo->dwRows = my_atodw(szBuf);

	GetDlgItemText (hwnd, IDC_ROWWIDTH, szBuf, sizeof (szBuf));
	lpinfo->nRowWidth = my_atoi(szBuf);

	GetDlgItemText (hwnd, IDC_UNIQUEKEYS, szBuf, sizeof (szBuf));
	lpinfo->dwUniqueKeys = my_atodw(szBuf);

	GetDlgItemText (hwnd, IDC_KEYWIDTH, szBuf, sizeof (szBuf));
	lpinfo->nKeyWidth = my_atoi(szBuf);

	GetDlgItemText (hwnd, IDC_DATA, szBuf, sizeof (szBuf));
	lpinfo->fillFactors.nData = my_atoi(szBuf);

	GetDlgItemText (hwnd, IDC_INDEX, szBuf, sizeof (szBuf));
	lpinfo->fillFactors.nIndex = my_atoi(szBuf);

	GetDlgItemText (hwnd, IDC_LEAF, szBuf, sizeof (szBuf));
	lpinfo->fillFactors.nLeaf = my_atoi(szBuf);



	if (lpinfo->nIngresVersion != OIVERS_12)   {
		HWND hwndCtl = GetDlgItem (hwnd, IDC_PAGESIZE);
		lpinfo->dwPageSize = ComboBox_GetItemData(hwndCtl, ComboBox_GetCurSel(hwndCtl));
	}
	else
		lpinfo->dwPageSize = 2048;

	if (lpinfo->nIngresVersion >= OIVERS_26)   {
		BOOL bIndex = Button_GetCheck (GetDlgItem (hwnd, IDC_TYPE_INDEX));
		int ipos = 0;
		long lpagesize = lpinfo->dwPageSize;
		while (lpagesize>2048) {
			ipos++;
			lpagesize/=2;
		}
		if (ipos>5) {
			myerror(ERR_INGRESPAGES);
			ipos=0;
		}
		if (bIndex)
			ipos+=6;
		lpinfo->iPageType = pagetypespertabletypes[ipos];
	}
	else if (lpinfo->nIngresVersion >= OIVERS_20)   {
		if (lpinfo->dwPageSize == 2048)
			lpinfo->iPageType = PAGE_TYPE_V1;
		else
			lpinfo->iPageType = PAGE_TYPE_V2;
	}
	else /* before 2.0 */
			lpinfo->iPageType = PAGE_TYPE_V1;

}
コード例 #26
0
ファイル: sessvar.c プロジェクト: sunny256/suuid
char *get_desc_from_command(const char *cmd)
{
	char *ap, *p, *p2;

	if (!cmd || !strlen(cmd))
		return NULL;
	ap = strdup(cmd);
	if (!ap) {
		myerror("get_desc_from_command(): Could not duplicate command "
		        "string");
		return NULL;
	}
	p = ap;
	while (strchr("./", *p))
		p++;
	p2 = p;
	while (*p2 && !isspace((int)*p2))
		p2++;
	if (p2 > p)
		*p2 = '\0';
	if (p > ap)
		memmove(ap, p, strlen(p) + 1);

	return ap;
}
コード例 #27
0
ファイル: main.c プロジェクト: albfan/rlwrap
/*
 * create pty pair and fork using my_pty_fork; parent returns immediately; child
 * executes the part of rlwrap's command line that remains after
 * read_options_and_command_name() has harvested rlwrap's own options
 */  
static void
fork_child(char *command_name, char **argv)
{
  char *arg = argv[optind], *p, **argp;
  int pid;

  command_line = mysavestring(arg);
  for (argp = argv + optind + 1; *argp; argp++) {
    command_line = append_and_free_old (command_line, " ");
    command_line = append_and_free_old (command_line, *argp);
  }

  pid = my_pty_fork(&master_pty_fd, &saved_terminal_settings, &winsize);
  if (pid > 0)			/* parent: */
    return;
  else {			/* child: */
    DPRINTF1(DEBUG_TERMIO, "preparing to execute %s", arg);
    close_open_files_without_writing_buffers();
    
    if (client_term_name)
      mysetenv("TERM", client_term_name);   
    if (execvp(argv[optind], &argv[optind]) < 0) {
      if (last_opt > 0 && last_option_didnt_have_optional_argument) { /* e.g. 'rlwrap -a Password: sqlpus' will try to exec 'Password:'******'; !(){}"; *p; p++) /* does arg need shell quoting? */ 
	  if (strchr(arg,*p)) { 
            arg = add3strings("'", arg,"'"); /* quote it  */
            break;
	  }	
	fprintf(stderr, "Did you mean '%s' to be an option argument?\nThen you should write -%c%s, without the space(s)\n",
                argv[optind], last_opt, arg); 
      }
      myerror("Cannot execute %s", argv[optind]);   	/* stillborn child, parent will live on and display child's last gasps */
    }
  }
}
コード例 #28
0
ファイル: util.c プロジェクト: loggerhead/tcp-reassembler
void *mymalloc(size_t size)
{
    void *ptr = malloc(size);
    if (!ptr)
        myerror("malloc failed");
    return ptr;
}
コード例 #29
0
ファイル: Cell.cpp プロジェクト: inonchiu/TreeCorr
Cell<D,C>::Cell(CellData<D,C>* ave, double sizesq,
                 std::vector<CellData<D,C>*>& vdata, 
                 double minsizesq, SplitMethod sm, size_t start, size_t end) :
    _sizesq(sizesq), _data(ave), _left(0), _right(0)
{
    Assert(sizesq >= 0.);
    //xdbg<<"Make cell starting with ave = "<<*ave<<std::endl;
    //xdbg<<"size = "<<_size<<std::endl;
    Assert(vdata.size()>0);
    Assert(end <= vdata.size());
    Assert(end > start);

    if (_sizesq > minsizesq) {
        _size = sqrt(_sizesq);
        size_t mid = SplitData(vdata,sm,start,end,_data->getPos());
        try {
            _left = new Cell<D,C>(vdata,minsizesq,sm,start,mid);
            _right = new Cell<D,C>(vdata,minsizesq,sm,mid,end);
        } catch (std::bad_alloc) {
            myerror("out of memory - cannot create new Cell");
        }
    } else {
        _size = _sizesq = 0.;
    }
}
コード例 #30
0
ファイル: util.c プロジェクト: loggerhead/tcp-reassembler
void *mycalloc(size_t count, size_t size)
{
    void *ptr = calloc(count, size);
    if (!ptr)
        myerror("calloc failed");
    return ptr;
}