Exemplo n.º 1
0
void OpenURI(std::string uri) {
#if defined(WIN)
	ShellExecute(0, "OPEN", uri.c_str(), NULL, NULL, 0);
#elif defined(MACOSX)
	char *cmd = (char*)malloc(7+uri.length());
	strcpy(cmd, "open ");
	strappend(cmd, (char*)uri.c_str());
	system(cmd);
#elif defined(LIN)
	char *cmd = (char*)malloc(11+uri.length());
	strcpy(cmd, "xdg-open ");
	strappend(cmd, (char*)uri.c_str());
	system(cmd);
#else
	printf("Cannot open browser\n");
#endif
}
Exemplo n.º 2
0
static void
append_ignored (const char* ign)
{
  if (ignored_lines)
    ignored_lines = strappend (ignored_lines, ign);
  else
    ignored_lines = strdup (ign);
}
Exemplo n.º 3
0
int
cd_glob(
    char *	glob,
    int		verbose)
{
    char *regex;
    char *regex_path;
    char *s;
    char *uqglob;
    int   result;

    char *tpath_on_disk = NULL;

    if (disk_name == NULL) {
	g_printf(_("Must select disk before changing directory\n"));
	return 0;
    }

    uqglob = unquote_string(glob);
    regex = glob_to_regex(uqglob);
    dbprintf(_("cd_glob (%s) -> %s\n"), uqglob, regex);
    if ((s = validate_regexp(regex)) != NULL) {
        g_printf(_("\"%s\" is not a valid shell wildcard pattern: "), glob);
        puts(s);
	amfree(regex);
	amfree(uqglob);
        return 0;
    }
    /*
     * glob_to_regex() anchors the beginning of the pattern with ^,
     * but we will be tacking it onto the end of the current directory
     * in add_file, so strip that off.  Also, it anchors the end with
     * $, but we need to match a trailing /, add it if it is not there
     */
    regex_path = g_strdup(regex + 1);
    amfree(regex);
    if(regex_path[strlen(regex_path) - 2] != '/' ) {
	regex_path[strlen(regex_path) - 1] = '\0';
	strappend(regex_path, "/$");
    }

    /* convert path (assumed in cwd) to one on disk */
    if (g_str_equal(disk_path, "/"))
        tpath_on_disk = g_strconcat("/", regex_path, NULL);
    else {
        char *clean_disk_tpath = clean_regex(disk_tpath, 0);
        tpath_on_disk = g_strjoin(NULL, clean_disk_tpath, "/", regex_path, NULL);
        amfree(clean_disk_tpath);
    }

    result = cd_dir(tpath_on_disk, uqglob, verbose);

    amfree(regex_path);
    amfree(tpath_on_disk);
    amfree(uqglob);

    return result;
}
Exemplo n.º 4
0
static void test_one(
                const char *path,
                const char *interface,
                const char *member,
                const char *arg0,
                const char *match,
                bool good) {

        _cleanup_close_ int bus_ref = -1;
        _cleanup_free_ char *name = NULL, *bus_name = NULL, *address = NULL;
        _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
        sd_bus *a, *b;
        int r;

        assert_se(asprintf(&name, "deine-mutter-%u", (unsigned) getpid()) >= 0);

        bus_ref = bus_kernel_create_bus(name, false, &bus_name);
        if (bus_ref == -ENOENT)
                exit(EXIT_TEST_SKIP);

        assert_se(bus_ref >= 0);

        address = strappend("kernel:path=", bus_name);
        assert_se(address);

        r = sd_bus_new(&a);
        assert_se(r >= 0);

        r = sd_bus_new(&b);
        assert_se(r >= 0);

        r = sd_bus_set_address(a, address);
        assert_se(r >= 0);

        r = sd_bus_set_address(b, address);
        assert_se(r >= 0);

        r = sd_bus_start(a);
        assert_se(r >= 0);

        r = sd_bus_start(b);
        assert_se(r >= 0);

        log_debug("match");
        r = sd_bus_add_match(b, NULL, match, NULL, NULL);
        assert_se(r >= 0);

        log_debug("signal");
        r = sd_bus_emit_signal(a, path, interface, member, "s", arg0);
        assert_se(r >= 0);

        r = sd_bus_process(b, &m);
        assert_se(r >= 0 && (good == !!m));

        sd_bus_unref(a);
        sd_bus_unref(b);
}
Exemplo n.º 5
0
static char*
arg_resolve_env(const char *str)
{
    char *resolved_str = NULL;
    char env_name[100];
    const char *env_val;
    size_t alloced = 0;
    const char *i = str, *j;

    /* calculate required resolved_str size */
    do {
        j = strstr(i, "$(");
        if (j != NULL) {
            if (j != i) {
                strnappend(&resolved_str, &alloced, i, j - i);
                i = j;
            }
            j = strchr(i + 2, ')');
            if (j != NULL) {
                if (j - (i + 2) < 100) {
                    strncpy(env_name, i + 2, j - (i + 2));
                    env_name[j - (i + 2)] = '\0';
                    #if !defined(_WIN32_WCE)
                    env_val = getenv(env_name);
                    if (env_val)
                        strappend(&resolved_str, &alloced, env_val);
                    #else
                    env_val = 0;
                    #endif
                }
                i = j + 1;
            } else {
                /* unclosed, copy and skip */
                j = i + 2;
                strnappend(&resolved_str, &alloced, i, j - i);
                i = j;
            }
        } else {
            strappend(&resolved_str, &alloced, i);
        }
    } while(j != NULL);

    return resolved_str;
}
Exemplo n.º 6
0
        STRV_FOREACH(p, files) {
                _cleanup_free_ char *buf, *f;
                size_t sz;

                assert_se(f = strappend(copy_dir, *p));

                assert_se(access(f, F_OK) == 0);
                assert_se(read_full_file(f, &buf, &sz) == 0);
                assert_se(streq(buf, "file\n"));
        }
Exemplo n.º 7
0
int button_open(Button *b) {
        char name[256], *p;
        struct epoll_event ev;
        int r;

        assert(b);

        if (b->fd >= 0) {
                close_nointr_nofail(b->fd);
                b->fd = -1;
        }

        p = strappend("/dev/input/", b->name);
        if (!p)
                return log_oom();

        b->fd = open(p, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
        free(p);
        if (b->fd < 0) {
                log_warning("Failed to open %s: %m", b->name);
                return -errno;
        }

        if (ioctl(b->fd, EVIOCGNAME(sizeof(name)), name) < 0) {
                log_error("Failed to get input name: %m");
                r = -errno;
                goto fail;
        }

        zero(ev);
        ev.events = EPOLLIN;
        ev.data.u32 = FD_OTHER_BASE + b->fd;

        if (epoll_ctl(b->manager->epoll_fd, EPOLL_CTL_ADD, b->fd, &ev) < 0) {
                log_error("Failed to add to epoll: %m");
                r = -errno;
                goto fail;
        }

        r = hashmap_put(b->manager->button_fds, INT_TO_PTR(b->fd + 1), b);
        if (r < 0) {
                log_error("Failed to add to hash map: %s", strerror(-r));
                assert_se(epoll_ctl(b->manager->epoll_fd, EPOLL_CTL_DEL, b->fd, NULL) == 0);
                goto fail;
        }

        log_info("Watching system buttons on /dev/input/%s (%s)", b->name, name);

        return 0;

fail:
        close_nointr_nofail(b->fd);
        b->fd = -1;
        return r;
}
Exemplo n.º 8
0
/*
** Shared-memory operations.
*/
static int vfstraceShmLock(sqlite3_file *pFile, int ofst, int n, int flags){
  vfstrace_file *p = (vfstrace_file *)pFile;
  vfstrace_info *pInfo = p->pInfo;
  int rc;
  char zLck[100];
  int i = 0;
  memcpy(zLck, "|0", 3);
  if( flags & SQLITE_SHM_UNLOCK )    strappend(zLck, &i, "|UNLOCK");
  if( flags & SQLITE_SHM_LOCK )      strappend(zLck, &i, "|LOCK");
  if( flags & SQLITE_SHM_SHARED )    strappend(zLck, &i, "|SHARED");
  if( flags & SQLITE_SHM_EXCLUSIVE ) strappend(zLck, &i, "|EXCLUSIVE");
  if( flags & ~(0xf) ){
     sqlite3_snprintf(sizeof(zLck)-i, &zLck[i], "|0x%x", flags);
  }
  vfstrace_printf(pInfo, "%s.xShmLock(%s,ofst=%d,n=%d,%s)",
                  pInfo->zVfsName, p->zFName, ofst, n, &zLck[1]);
  rc = p->pReal->pMethods->xShmLock(p->pReal, ofst, n, flags);
  vfstrace_print_errcode(pInfo, " -> %s\n", rc);
  return rc;
}
Exemplo n.º 9
0
/*
** Sync an vfstrace-file.
*/
static int vfstraceSync(sqlite3_file *pFile, int flags){
  vfstrace_file *p = (vfstrace_file *)pFile;
  vfstrace_info *pInfo = p->pInfo;
  int rc;
  int i;
  char zBuf[100];
  memcpy(zBuf, "|0", 3);
  i = 0;
  if( flags & SQLITE_SYNC_FULL )        strappend(zBuf, &i, "|FULL");
  else if( flags & SQLITE_SYNC_NORMAL ) strappend(zBuf, &i, "|NORMAL");
  if( flags & SQLITE_SYNC_DATAONLY )    strappend(zBuf, &i, "|DATAONLY");
  if( flags & ~(SQLITE_SYNC_FULL|SQLITE_SYNC_DATAONLY) ){
    sqlite3_snprintf(sizeof(zBuf)-i, &zBuf[i], "|0x%x", flags);
  }
  vfstrace_printf(pInfo, "%s.xSync(%s,%s)", pInfo->zVfsName, p->zFName,
                  &zBuf[1]);
  rc = p->pReal->pMethods->xSync(p->pReal, flags);
  vfstrace_printf(pInfo, " -> %d\n", rc);
  return rc;
}
Exemplo n.º 10
0
static int add_matches(sd_journal *j, char **args) {
        char **i;
        int r;

        assert(j);

        STRV_FOREACH(i, args) {

                if (streq(*i, "+"))
                        r = sd_journal_add_disjunction(j);
                else if (path_is_absolute(*i)) {
                        char *p;
                        const char *path;
                        struct stat st;

                        p = canonicalize_file_name(*i);
                        path = p ? p : *i;

                        if (stat(path, &st) < 0)  {
                                free(p);
                                log_error("Couldn't stat file: %m");
                                return -errno;
                        }

                        if (S_ISREG(st.st_mode) && (0111 & st.st_mode)) {
                                char *t;

                                t = strappend("_EXE=", path);
                                if (!t) {
                                        free(p);
                                        log_error("Out of memory");
                                        return -ENOMEM;
                                }

                                r = sd_journal_add_match(j, t, 0);
                                free(t);
                        } else {
                                free(p);
                                log_error("File is not a regular file or is not executable: %s", *i);
                                return -EINVAL;
                        }

                        free(p);
                } else
                        r = sd_journal_add_match(j, *i, 0);

                if (r < 0) {
                        log_error("Failed to add match '%s': %s", *i, strerror(-r));
                        return r;
                }
        }

        return 0;
}
Exemplo n.º 11
0
char *unit_dbus_path_from_name(const char *name) {
        _cleanup_free_ char *e = NULL;

        assert(name);

        e = bus_label_escape(name);
        if (!e)
                return NULL;

        return strappend("/org/freedesktop/systemd1/unit/", e);
}
Exemplo n.º 12
0
/* ::cortex::ic::program::str() */
cx_string ic_program_str(ic_program _this) {
/* $begin(::cortex::ic::program::str) */
    cx_string result = NULL;

#ifdef CX_IC_TRACING
    result = strappend(result, "%%file %s\n", _this->filename);
    result = ic_scope_str(_this->scope, result);
#endif
    return result;
/* $end */
}
Exemplo n.º 13
0
char *image_bus_path(const char *name) {
        _cleanup_free_ char *e = NULL;

        assert(name);

        e = bus_label_escape(name);
        if (!e)
                return NULL;

        return strappend("/org/freedesktop/machine1/image/", e);
}
Exemplo n.º 14
0
Arquivo: parser.c Projeto: rju/slp
char* parse_hl_lines() {
	char* lines = NULL;
	if ((token = yylex()) == NORMAL_O_BRACE) {
		while (token != NORMAL_C_BRACE) {
			if ((token = yylex()) == NUMBER) {
				lines = strappend(lines,string);
				if ((token = yylex()) == COMMA) {
					lines = strappend(lines,",");
				}
			} else {
				fprintf(stderr,
					"[%d] Listing mode: Number expected, but %s \"%s\" found\n",
					yylineno, get_token_name(token), yytext);
				return NULL;
			}
		}
	}

	return lines;
}
Exemplo n.º 15
0
Arquivo: parser.c Projeto: rju/slp
/*
 * parse properties
 */
char* parse_properties() {
	char *result = NULL;
	while ((token = yylex()) != SQUARE_C_BRACE) {
		switch (token) {
		case PROPERTY:
			result = strappend(result,string); 
			break;
		case COMMA:
			result = strappend(result,",");
			break;
		case SQUARE_C_BRACE:
			break;
		default:
			fprintf(stderr, 
				"[%d] Figure mode, property sequence: Missing ]. Found '%s'\n", 
				yylineno,get_token_name(token));
			return NULL;
		}
	}
	return result;
}
Exemplo n.º 16
0
static char* get_default_res_path(void) {
	char *res;

#ifdef TAISEI_BUILDCONF_RELATIVE_DATA_PATH
	res = SDL_GetBasePath();
	strappend(&res, TAISEI_BUILDCONF_DATA_PATH);
#else
	res = strdup(TAISEI_BUILDCONF_DATA_PATH);
#endif

	return res;
}
Exemplo n.º 17
0
Arquivo: post.c Projeto: fbbs/fbbs
static void read_signature_legacy(const char *uname, int offset, char *buffer,
		size_t size)
{
	char *out = buffer;
	size_t remain = size;
	strappend(&out, &remain, "\n--\n");
	if (offset <= 0)
		return;

	char file[HOMELEN];
	sethomefile(file, uname, "signatures");
	FILE *fp = fopen(file, "r");
	if (!fp)
		return;

	char buf[256];
	for (int i = (offset - 1) * MAXSIGLINES; i > 0; --i) {
		if (!fgets(buf, sizeof(buf), fp)) {
			fclose(fp);
			return;
		}
	}

	int blank = 0;
	for (int i = 0; i < MAXSIGLINES; ++i) {
		if (!fgets(buf, sizeof(buf), fp))
			break;
		if (buf[0] == '\n' || streq(buf, "\r\n")) {
			++blank;
		} else {
			while (blank-- > 0)
				strappend(&out, &remain, "\n");
			blank = 0;
			//% ":·" "·[FROM:"
			if (!strstr(buf, ":\xa1\xa4"BBSNAME" "BBSHOST"\xa1\xa4[FROM:"))
				strappend(&out, &remain, buf);
		}
	}
	fclose(fp);
}
Exemplo n.º 18
0
Arquivo: brainfuck.c Projeto: svip/THC
void translate_brainfuck ( char *output, char *code ) {
  code = replace(code, "brainfuck-program=", "");
  // YES YES, THE SUBMIT VALUE REMAINS, BUT NONE OF ITS
  // CHARACTERS ARE BRAINFUCK CHARACTERS.  WHO CARES?!
  code = replace(code, "&brainfuck-submit=Oversæt!", "");
  
  strappend(output, "#include <stdio.h>\n#include <stdlib.h>\n\nint main (int argc, char** argv) {\nUNUSED(argc);\nUNUSED(argv);\nunsigned char* ptr;\n\n");
  
  for (int codep = 0; code[codep] != 0; codep++) {
    switch(code[codep]) {
    case '+':
      strappend(output, "(*ptr)++;\n");
      break;
    case '-':
      strappend(output, "(*ptr)--;\n");
      break;
    case '>':
      strappend(output, "ptr++;\n");
      break;
    case '<':
      strappend(output, "ptr--;\n");
      break;
    case '.':
      strappend(output, "putchar(*ptr);\n");
      break;
    case ',':
      strappend(output, "*ptr=getchar();\n");
      break;
    case '[':
      strappend(output, "while (*ptr) {\n");
      break;
    case ']':
      strappend(output, "}\n");
      break;
    }
  }
  
  strappend(output, "return 0;\n}\n");
}
Exemplo n.º 19
0
static void setup_test_dir(char *tmp_dir, const char *files, ...) {
        va_list ap;

        assert_se(mkdtemp(tmp_dir) != NULL);

        va_start(ap, files);
        while (files != NULL) {
                _cleanup_free_ char *path = strappend(tmp_dir, files);
                assert_se(touch_file(path, true, (usec_t) -1, (uid_t) -1, (gid_t) -1, 0) == 0);
                files = va_arg(ap, const char *);
        }
        va_end(ap);
}
Exemplo n.º 20
0
static corto_string ic_op_derefToString(corto_string string, ic_node s, ic_derefKind mode) {
    if (s->kind == IC_STORAGE) {
        corto_type t = ic_storage(s)->type;
        if (t->reference) {
            if (mode == IC_DEREF_VALUE) {
                string = strappend(string, " *");
            } else {
                string = strappend(string, " ");
            }
        } else {
            if (mode == IC_DEREF_ADDRESS) {
                string = strappend(string, " &");
            } else {
                string = strappend(string, " ");
            }
        }
    } else {
        string = strappend(string, " ");
    }

    return string;
}
Exemplo n.º 21
0
char *session_bus_path(Session *s) {
        char *t, *r;

        assert(s);

        t = bus_path_escape(s->id);
        if (!t)
                return NULL;

        r = strappend("/org/freedesktop/login1/session/", t);
        free(t);

        return r;
}
Exemplo n.º 22
0
Arquivo: parser.c Projeto: rju/slp
char* parse_highlighting() {
	char* highlighting = strduplicate("linebackgroundcolor={");
	while ((token = yylex()) != SQUARE_C_BRACE) {
		if (token == NUMBER) {
			int number = int_val;
			#define MAX_NUM_LENGTH 4
			char* lines = parse_hl_lines();
			if (lines != NULL) {
				char *frame = malloc(MAX_NUM_LENGTH+strlen(lines)+11+1);
				sprintf(frame,"\\btLstHL<%d>{%s}",number,lines);
				highlighting = strappend(highlighting,frame);
				// free(frame); /* should work */
				free(lines);
			}
		} else {
			fprintf(stderr,
				"[%d] Listing mode: Number expected, but %s \"%s\" found\n",
				yylineno, get_token_name(token), yytext);
			return NULL;
		}
	}
	return strappend(highlighting,"},");
}
Exemplo n.º 23
0
static int test_string_util_strappend_concat(void)
{
	const char *src = "world!";
	char *dest = strdup("hello, ");
	int ret;

	ret = strappend(&dest, src);
	if (!ret) {
		ret = strcmp(dest, "hello, world!") != 0;
		free(dest);
	}

	return ret;
}
Exemplo n.º 24
0
static int test_string_util_strappend_initial(void)
{
	const char *src = "source string";
	char *dest = NULL;
	int ret;

	ret = strappend(&dest, src);
	if (!ret) {
		ret = strcmp(dest, src) != 0;
		free(dest);
	}

	return ret;
}
Exemplo n.º 25
0
static int test_string_util_strappend_empty_src(void)
{
	const char *src = "";
	char *dest = strdup("dest string");
	int ret;

	ret = strappend(&dest, src);
	if (!ret) {
		ret = strcmp(dest, "dest string") != 0;
		free(dest);
	}

	return ret;
}
Exemplo n.º 26
0
void
CHAR_taperscan_output_callback(
    /*@keep@*/	void *data,
    char *msg)
{
    char **s = (char **)data;

    if(!msg) return;
    if(strlen(msg) == 0) return;

    if(*s)
        strappend(*s, msg);
    else
        *s = stralloc(msg);
}
Exemplo n.º 27
0
Arquivo: tui.c Projeto: fbbs/fbbs
static void notice_string(char *buf, size_t size)
{
	*buf = '\0';

	int replies, mentions;
	notice_count(&replies, &mentions);

	bool empty = !(replies || mentions);
	if (!empty) {
		char **dst = &buf;
		if (replies > 0) {
			char str[24];
			snprintf(str, sizeof(str), "%d篇回复", replies);
			strappend(dst, &size, str);
		}
		if (mentions > 0) {
			char str[24];
			snprintf(str, sizeof(str), "%d篇提及", mentions);
			strappend(dst, &size, str);
		}
		if (!_suppress_notice && screen_display_width(buf, true) <= 24)
			strappend(dst, &size, " 按^T查看");
	}
}
Exemplo n.º 28
0
int user_runtime_dir(char **runtime_dir) {
        const char *e;
        char *r;

        e = getenv("XDG_RUNTIME_DIR");
        if (e) {
                r = strappend(e, "/systemd/user");
                if (!r)
                        return -ENOMEM;

                *runtime_dir = r;
                return 1;
        }

        return 0;
}
Exemplo n.º 29
0
static void do_journal_append(char *file)
{
        struct iovec iovec[5];
        int r, f, j = 0;
        ssize_t n;
        _cleanup_free_ char *bootchart_file = NULL, *bootchart_message = NULL,
                *p = NULL;

        bootchart_file = strappend("BOOTCHART_FILE=", file);
        if (bootchart_file)
                IOVEC_SET_STRING(iovec[j++], bootchart_file);

        IOVEC_SET_STRING(iovec[j++], "MESSAGE_ID=9f26aa562cf440c2b16c773d0479b518");
        IOVEC_SET_STRING(iovec[j++], "PRIORITY=7");
        bootchart_message = strjoin("MESSAGE=Bootchart created: ", file, NULL);
        if (bootchart_message)
                IOVEC_SET_STRING(iovec[j++], bootchart_message);

        p = malloc(9 + BOOTCHART_MAX);
        if (!p) {
                r = log_oom();
                return;
        }

        memcpy(p, "BOOTCHART=", 10);

        f = open(file, O_RDONLY);
        if (f < 0) {
                log_error("Failed to read bootchart data: %m\n");
                return;
        }
        n = loop_read(f, p + 10, BOOTCHART_MAX, false);
        if (n < 0) {
                log_error("Failed to read bootchart data: %s\n", strerror(-n));
                close(f);
                return;
        }
        close(f);

        iovec[j].iov_base = p;
        iovec[j].iov_len = 10 + n;
        j++;

        r = sd_journal_sendv(iovec, j);
        if (r < 0)
                log_error("Failed to send bootchart: %s", strerror(-r));
}
Exemplo n.º 30
0
int main(int argc, char *argv[]) {
        _cleanup_free_ char *fn = NULL;
        char dn[] = "/var/tmp/test-journal-flush.XXXXXX";
        JournalFile *new_journal = NULL;
        sd_journal *j = NULL;
        unsigned n = 0;
        int r;

        assert_se(mkdtemp(dn));
        fn = strappend(dn, "/test.journal");

        r = journal_file_open(-1, fn, O_CREAT|O_RDWR, 0644, false, false, NULL, NULL, NULL, NULL, &new_journal);
        assert_se(r >= 0);

        r = sd_journal_open(&j, 0);
        assert_se(r >= 0);

        sd_journal_set_data_threshold(j, 0);

        SD_JOURNAL_FOREACH(j) {
                Object *o;
                JournalFile *f;

                f = j->current_file;
                assert_se(f && f->current_offset > 0);

                r = journal_file_move_to_object(f, OBJECT_ENTRY, f->current_offset, &o);
                assert_se(r >= 0);

                r = journal_file_copy_entry(f, new_journal, o, f->current_offset, NULL, NULL, NULL);
                assert_se(r >= 0);

                n++;
                if (n > 10000)
                        break;
        }

        sd_journal_close(j);

        (void) journal_file_close(new_journal);

        unlink(fn);
        assert_se(rmdir(dn) == 0);

        return 0;
}