Beispiel #1
0
char* extract_command_str(int flags,const char *filename,int do_extract,const char* outputpath,char* type) {
  char* str;
  char* _uname_m=uname_m();
  char* _uname=uname();
  char* _homedir=configdir();
  char* exe=s_escape_string(cat(_homedir,"impls",SLASH,_uname_m,SLASH,_uname,SLASH,"7za",SLASH,"9.20",SLASH,"7za.exe",NULL));
  char *outputpath2=q(outputpath);
  char *filename2=q(filename);
  substitute_char('\\','/',outputpath2);
  outputpath2=s_escape_string(outputpath2);
  filename2=s_escape_string(filename2);
  ensure_directories_exist(outputpath2);
  if(strcmp(type,"gzip")==0 || strcmp(type,"bzip2")==0 || strcmp(type,"xz")==0) {
    str=cat("cmd /c \"",exe," ",do_extract?"x ":"l ",filename2," -so |",exe," x -ttar -si -y -o",outputpath2,"\"",NULL);
  }else if(strcmp(type,"7za")==0) {
    ensure_directories_exist(outputpath2);
    str=cat(exe," ",do_extract?"x":"t"," -y -o",outputpath2," ",filename2,NULL);
  }
  s(outputpath2),s(filename2),s(_homedir),s(_uname),s(_uname_m);
  return str;
}
TEST(ChangeAddressTransactionTest, PayrollTest) {
	int empid = 9;
	AddHourlyEmployee ahe(empid, "Test9", "Home9", 50.00);
	ahe.Execute();

	ChangeAddressTransaction cat(empid, "Home99");
	cat.Execute();

	Employee *e = ((DatabaseProxy *)getInstance())->GetEmployee(empid);
	EXPECT_TRUE(e != 0);
	EXPECT_TRUE(e->GetAddress() == "Home99");
}
Beispiel #3
0
/* test if close-on-exec works for open_pipe() */
static void test3(void) {

    int fd, pi[2];

    close(0);
    close(1);
    fd = open_pipe(pi);
    if (fd == -1) fail("unable to open pipe");
    if (pi[0] != 0) fail("unable to open pipe");
    if (pi[1] != 1) fail("unable to open pipe");
    cat();
}
Beispiel #4
0
constexpr
typename std::enable_if<N==N_2*2,recarr<T,N>>::type
fft_helper(recarr<T,N> v, recarr<T,N_2> rofu) {
  return cat(zipWith(sum<T>,fft_helper(condense(v), condense(rofu)),
                            zipWith(product<T>,fft_helper(condense(cshift1(v)),
                                                          condense(rofu)),
                                               rofu)),
             zipWith(sub<T>,fft_helper(condense(v), condense(rofu)),
                            zipWith(product<T>,fft_helper(condense(cshift1(v)),
                                                          condense(rofu)),
                                               rofu)));
}
Beispiel #5
0
static const char *
explode(const char *defs)
{
	static const char def[] = "defined("; /* ) */
	static char *buf;
	size_t len;
	const char *ptr, *bptr, *eptr = NULL, *name;
	size_t buflen = 0;

	if (strstr(defs, "#machine(" /* ) */))
		return defs;

	free(buf);
	buf = strdup("("); /* ) */
	for (ptr = defs; (bptr = strstr(ptr, def)) != NULL; ptr = eptr + 1) {
		if (ptr != bptr)
			buf = cat(buf, ptr, bptr - ptr);
		if ((eptr = strchr(ptr + sizeof(def) - 1, ')')) == NULL) {
			(void) fprintf(stderr, "%s: missing close paren `%s'\n",
			    pname, defs);
			return defs;
		}
		buf = cat(buf, bptr, eptr - bptr + 1);
		name = bptr + sizeof(def) - 1;
		len = eptr - name;
		if (len < 1) {
			(void) fprintf(stderr, "%s: empty define `%s'\n",
			    pname, defs);
			return defs;
		}
		if (*name != '_') {
			char *undername = malloc(len + 10);
			buf = cat(buf, " || defined(", 0);
			snprintf(undername, len + 10, "__%.*s__)", (int)len,
			    name);
			buf = cat(buf, undername, len + 5);
			buf = cat(buf, " || defined(", 0);
			snprintf(undername, len + 10, "__%.*s)", (int)len,
			    name);
			buf = cat(buf, undername, len + 3);
		}
	}
	if (!eptr) {
	    (void) fprintf(stderr, "%s: invalid input `%s'\n", pname, defs);
	    return defs;
        }
	buf = cat(buf, eptr + 1, 0);
	buf = cat(buf, ")", 0);
	return buf;
}
Beispiel #6
0
char *comando(char *cmd, char **argv, char* output,int rs[2], FD *ph,FD *hp){
    int argc=0;
    interprete(cmd, &argc, argv);
    strcpy(output, "");
    
    if (argc > 0) {
        if(!strcmp(argv[0], "ls")) {
            ls(argc, argv,output);
        }
        else if(!strcmp(argv[0], "cat")) {
            char *c = cat(argc, argv);
            if(c == NULL) {
                sprintf(output,"-fssh: %s/%s: No existe el archivo\n",
                        argv[1],argv[2]);
            }
            else {
                strcpy(output,c);
                return c;
            }
        }
        else if(!strcmp(argv[0], "cp")) {
            cp(argc, argv,output);
        }
        else if(!strcmp(argv[0], "mv")) {
            mv(argc, argv, output);
        }
        else if(!strcmp(argv[0], "find")) {
            find(argc,argv,output,rs,ph,hp);
        }
        else if(!strcmp(argv[0], "rm")) {
            rm(argc, argv,output);
        }
        else if(!strcmp(argv[0], "mkdir")) {
           output = mkdir_(argc, argv,output);
        }
        else if(!strcmp(argv[0], "rmdir")) {
            rmdir_(argc, argv,output);
        }
        else if(!strcmp(argv[0], "quit")) {
            exit(0);
        }
        else {
            sprintf(output,"-fssh: %s: No existe el comando\n",argv[0]);
        }
    }
    else {
        sprintf(output, "-fssh: %s: Es un directorio\n",argv[1]);
    }

    
    return output;
}
Beispiel #7
0
int main(int argc, char *argv[]) {
	FILE *fp;
	int needclose;
	int ttyfd;
	int line;

	if (isatty(STDIN_FILENO) == 0) {
		fp = stdin;
		needclose = 0;
	} else {
		if (argc <= 1) {
			printf("Usage: mymore [file]\n");
			return 0;
		}

		if ((fp = fopen(argv[1], "r")) == NULL) {
			perror("fopen");
			return 1;
		}
		needclose = 1;
	}

	// cat
	if (isatty(STDOUT_FILENO) == 0) {
		cat(fp);
	// more
	} else {
		if (termcap() == -1) {
			fprintf(stderr, "failed to load termcap.");
		}

		if ((tty = open("/dev/tty", O_RDONLY)) == -1) {
			perror("open");
			// return;
			tty = STDERR_FILENO;
		}

		raw_mode(1);
		more(fp);
		raw_mode(0);

		if (tty != STDERR_FILENO) {
			close(tty);
		}
	}

	if (needclose) {
		fclose(fp);
	}

	return 0;
}
QVector<ProjectPart::Ptr> ProjectInfoGenerator::createProjectParts(const RawProjectPart &rawProjectPart)
{
    QVector<ProjectPart::Ptr> result;
    ProjectFileCategorizer cat(rawProjectPart.displayName,
                               rawProjectPart.files,
                               rawProjectPart.fileClassifier);

    if (cat.hasParts()) {
        const ProjectPart::Ptr part = projectPartFromRawProjectPart(rawProjectPart,
                                                                    m_projectUpdateInfo.project);

        ProjectPart::LanguageVersion defaultVersion = ProjectPart::LatestCxxVersion;
        if (rawProjectPart.qtVersion == ProjectPart::Qt4_8_6AndOlder)
            defaultVersion = ProjectPart::CXX11;
        if (cat.hasCxxSources()) {
            result << createProjectPart(rawProjectPart,
                                        part,
                                        cat.cxxSources(),
                                        cat.partName("C++"),
                                        defaultVersion,
                                        ProjectPart::NoExtensions);
        }

        if (cat.hasObjcxxSources()) {
            result << createProjectPart(rawProjectPart,
                                        part,
                                        cat.objcxxSources(),
                                        cat.partName("Obj-C++"),
                                        defaultVersion,
                                        ProjectPart::ObjectiveCExtensions);
        }

        if (cat.hasCSources()) {
            result << createProjectPart(rawProjectPart,
                                        part,
                                        cat.cSources(),
                                        cat.partName("C"),
                                        ProjectPart::LatestCVersion,
                                        ProjectPart::NoExtensions);
        }

        if (cat.hasObjcSources()) {
            result << createProjectPart(rawProjectPart,
                                        part,
                                        cat.objcSources(),
                                        cat.partName("Obj-C"),
                                        ProjectPart::LatestCVersion,
                                        ProjectPart::ObjectiveCExtensions);
        }
    }
    return result;
}
Beispiel #9
0
int main(object me, string arg)
{
	string file;
	
	seteuid(geteuid(me));
    if (!arg) return notify_fail("你想要显示那个档案?\n");
	file = resolve_path(me->query("cwd"), arg);
	if( file_size(file)<0 ) return notify_fail("没有这个档案。\n");

	if(!SECURITY_D-> valid_read(file, this_object(), "read_file") )return notify_fail("对不起,你没有读这个档案的权力。\n");
	cat(file);
	return 1;
}
Beispiel #10
0
char *mv(int argc, char**argv,char *output){
    char **arg = (char **) malloc(sizeof(char*)*4);
    arg[0] = argv[0];
    arg[1] = argv[1];
    arg[2] = argv[3];
    char *contendio = cat(3, arg);
    rm(3, arg, output);
    if (!strcmp(output, "")){
        arg[1] = argv[2];
        touch(2, arg, contendio, output);
    }
    return "";
}
Beispiel #11
0
void save_num(
	CC const& src,
	FilepassString const& file_pass,
	std::string delimiter,
	WriteMode open_mode = WriteMode::overwrite)
{
	std::vector<std::string> tmp;

	for (auto const& line : src){
		tmp.push_back(cat(line, delimiter));
	}
	save_line(tmp, file_pass, open_mode);
}
Beispiel #12
0
int main(int argc, char **argv) {
    ls(NULL);
    ls("test.c");
    ls("../../");
    cat("test.c");
    dyn_array_t *strings = tokenizer("bob,sue,fred", ",");
    size_t end = dyn_array_size(strings);
    for (size_t i = 0; i < end; ++i) {
        printf("%s\n", *((char **) dyn_array_at(strings, i)));
    }
    dyn_array_destroy(strings);
    return 0;
}
Beispiel #13
0
void tst_QNoDebug::noDebugOutput() const
{
    QLoggingCategory cat("custom");
    // should do nothing
    qDebug() << "foo";
    qCDebug(cat) << "foo";

    // qWarning still works, though
    QTest::ignoreMessage(QtWarningMsg, "bar");
    QTest::ignoreMessage(QtWarningMsg, "custom-bar");
    qWarning() << "bar";
    qCWarning(cat) << "custom-bar";
}
Beispiel #14
0
constexpr
typename enable_if<sizeof...(Ts)==(2*sizeof...(Us)),tuple<Ts...>>::type
fft_helper(tuple<Ts...> v, tuple<Us...> rofu) {
  typedef typename pack_head<Ts...>::type T;   // T is usually cx<double>
  return cat(zipWith(sum<T>,fft_helper(condense(v), condense(rofu)),
                            zipWith(product<T>,fft_helper(condense(cshift1(v)),
                                                          condense(rofu)),
                                               rofu)),
             zipWith(sub<T>,fft_helper(condense(v), condense(rofu)),
                            zipWith(product<T>,fft_helper(condense(cshift1(v)),
                                                          condense(rofu)),
                                               rofu)));
}
Beispiel #15
0
static void create_dummy_instance (const char * file)
{
        xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0");
        xmlNodePtr instance = xmlNewNode (NULL, BAD_CAST "instance");
        xmlDocSetRootElement (doc, instance);
        {
                xmlNodePtr hypervisor = xmlNewChild (instance, NULL, BAD_CAST "hypervisor", NULL);
                _ATTRIBUTE(hypervisor, "type", "kvm");
                _ATTRIBUTE(hypervisor, "mode", "hvm");
        }
        _ELEMENT(instance, "name", "i-12345");
        _ELEMENT(instance, "kernel", "/var/run/instances/i-213456/kernel");
        _ELEMENT(instance, "ramdisk", "/var/run/instances/i-213456/initrd");
        _ELEMENT(instance, "consoleLogPath", "/var/run/instances/i-213456/console.log");
        _ELEMENT(instance, "cmdline", "ro console=ttyS0");
        _ELEMENT(instance, "cores", "1");
        _ELEMENT(instance, "memoryKB", "512000");
        {
                xmlNodePtr os = _NODE(instance, "os");
                _ATTRIBUTE(os, "platform", "linux");
                _ATTRIBUTE(os, "virtioRoot", "true");
                _ATTRIBUTE(os, "virtioDisk", "false");
                _ATTRIBUTE(os, "virtioNetwork", "false");
        }
        {
                xmlNodePtr features = _NODE(instance, "features");
                _NODE(features, "acpi");
        }
        {
                xmlNodePtr disks = _NODE(instance, "disks");
                {
                        xmlNodePtr disk1 = _ELEMENT(disks, "diskPath", "/var/run/instances/i-213456/root");
                        _ATTRIBUTE(disk1, "targetDeviceType", "disk");
                        _ATTRIBUTE(disk1, "targetDeviceName", "sda1");
                        _ATTRIBUTE(disk1, "targetDeviceBus", "virtio");
                        _ATTRIBUTE(disk1, "sourceType", "file");
                }
                {
                        xmlNodePtr disk1 = _ELEMENT(disks, "diskPath", "/var/run/instances/i-213456/swap");
                        _ATTRIBUTE(disk1, "targetDeviceType", "disk");
                        _ATTRIBUTE(disk1, "targetDeviceName", "sda3");
                        _ATTRIBUTE(disk1, "targetDeviceBus", "scsi");
                        _ATTRIBUTE(disk1, "sourceType", "file");
                }
        }

        xmlSaveFormatFileEnc (file, doc, "UTF-8", 1);
        logprintfl (EUCAINFO, "wrote XML to %s\n", file);
        cat (file);
        xmlFreeDoc(doc);
}
Beispiel #16
0
int main(int argc, char *argv[])
{
    int bright = -1;
    
    switch(argc)
    {
        case 2:
        {
            int max = cat(MAX_FILE);
            int current = cat(CTL_FILE);

            printf("brightness: max %d, current %d", max, current);
            const char *method = argv[1];

            if (strcmp(method, "up") == 0 && current < max)
            {
                bright = current + 1;
            }
            else if(strcmp(method, "down") == 0 && current > 0)
            {
                bright = current - 1;
            }
            break;
        }
        default:
        {
            show_help();
            return -1;
        }
    }
    if(bright > -1)
    {
        printf(", set %d", bright);
        set_brightness(bright);
    }
    printf("\n");
    return 0;
}
Beispiel #17
0
int main()
{
	char     *env_input;
	char     path[4096];

	/* CGI initial print */
	printf("Content-type: text/html\n\n");

	/* create trace/log */
	trace_init("list.log");

	/* get GET content from environment variable */ 
	env_input = getenv("QUERY_STRING");
	if (env_input == NULL) {
		trace(WEB, "No env variable: QUERY_STRING.\n", NULL);
		goto exit;
	}

	/* extract page number from GET content */
	sscanf(env_input, "p=%s", path);

	/* echo HTML */
	cat("head.cat");
	printf("file: %s <br/>", basename(path));
	printf("[dmath]%s[/dmath]", first_line(path));
	cat("neck.cat");

	echo_tex_li(path);
	
	cat("ass.cat");
	cat("tail.cat");

exit:
	/* delete trace/log */
	trace_unfree();
	trace_uninit();
	return 0;
}
Beispiel #18
0
void ViewRegistryReader::ReadCategory(const IConfigurationElement::Pointer& element)
{
  try
  {
    Category<IViewDescriptor::Pointer>::Pointer cat(new Category<IViewDescriptor::Pointer>(element));
    viewRegistry->Add(cat);
  }
  catch (const CoreException &e)
  {
    // log an error since its not safe to show a dialog here
    WorkbenchPlugin::Log(
        "Unable to create view category.", e);
  }
}
Beispiel #19
0
char *
gf(char *appl)
{
	static char	filename[SIZE];
	char		in_line[SIZE], *ptrs[3], *fmat[2], *tmp;

	TR("Gf: entry appl=(%s)\n", appl, EMPTY, EMPTY);
	cat (filename, NOGETTEXT("/usr/lib/M2/"), appl, EMPTY);
	fmat[0] = NOGETTEXT("DBBD");
	fmat[1] = EMPTY;
	TR("Gf: fmat[0]=(%s) fmat[1]=(%s)\n", fmat[0], fmat[1], EMPTY);
	if (sweep (VERIFY, filename, EMPTY, '\n', ':', SIZE, fmat, in_line, ptrs,
	  (int (*)(char *, int, char **)) NULL,
	  (int (*)(char **, char **, int)) NULL) != FOUND) {
		TR("Gf: not found\n", EMPTY, EMPTY, EMPTY);
		return (EMPTY);
		}
	tmp = strrchr (ptrs[1], (char) 01);
	*tmp = 0;						/* Find and clobber control A. */
	cat (filename, ptrs[1], NOGETTEXT("/.fred/.FRED"), EMPTY);
	TR("Gf: returns (%s)\n", filename, EMPTY, EMPTY);
	return (filename);
}
Beispiel #20
0
/*
 * Fix the header by glopping all of the expanded names from
 * the distribution list into the appropriate fields.
 */
void
fixhead(struct header *hp, struct name *tolist)
{
	struct name *np;

	hp->h_to = NULL;
	hp->h_cc = NULL;
	hp->h_bcc = NULL;
	for (np = tolist; np != NULL; np = np->n_flink) {
		/* Don't copy deleted addresses to the header */
		if (np->n_type & GDEL)
			continue;
		if ((np->n_type & GMASK) == GTO)
			hp->h_to =
			    cat(hp->h_to, nalloc(np->n_name, np->n_type));
		else if ((np->n_type & GMASK) == GCC)
			hp->h_cc =
			    cat(hp->h_cc, nalloc(np->n_name, np->n_type));
		else if ((np->n_type & GMASK) == GBCC)
			hp->h_bcc =
			    cat(hp->h_bcc, nalloc(np->n_name, np->n_type));
	}
}
Beispiel #21
0
void main()
{
char n[100],n2[100];

printf("Vavedete parvi niz za proverka i obrabotka:");gets(n);
printf("Vavedete vtori niz za proverka i obrabotka:");gets(n2);
printf("Broqt na simvolite v parvi niz e:%d\n",len(n));
printf("Broqt na simvolite v vtori niz e:%d\n",len(n2));
if(cmp(n,n2)==1)
printf("Nizovete sa ednakvi!!!\n");
else printf("Nizovete sa razlichni!!!\n");
cat(n,n2);
printf("Obedinenite nizove sa:%s\n",n);
}
Beispiel #22
0
task usercontrol()
{
	// User control code here, inside the loop
	slaveMotor(gb2,gb1);
	slaveMotor(gb3, gb2);
	slaveMotor(gb4, gb3);
	while (true)
	{
		/*motor[frontLeft] = vexRT[Ch1] + vexRT[Ch2];//x drive arcade
		motor[rearRight] =  vexRT[Ch1] - vexRT[Ch2];
		motor[rearLeft] = vexRT[Ch4] + vexRT[Ch3];
		motor[frontRight] =  vexRT[Ch4] - vexRT[Ch3];*/
		/*motor[frontLeft] =vexRT[Ch3];//tank drive arcade
		motor[rearLeft]=vexRT[Ch3];
		motor[frontRight]= -vexRT[Ch2];
		motor[rearRight]=-vexRT[Ch2];*/
		driveL3ft(Ch3);
		driveR1ght(Ch2);
		if (vexRT[Btn6U]==1)
		{
			cat(-127);//up
		}
		else if(vexRT[Btn6D] == 1)
		{
			cat(127);//down
		}
		//for catapult with high tension
		/*else if(vexRT[Btn5D]==1)
		{
		cat(10);//hold
		}*/
		else
		{
			cat(0);//no power
		}
	}
}
Beispiel #23
0
void FileMgr::initilize(int argc, char* argv[]){
	try{
		if (argc >= 2){
			int temp_int = 1, flag_d = 0, flag_f = 0;
			std::string temp, test_store;
			++argv;
			temp = *argv;
			if (temp.find('/') != 0 && (temp.find('*') == -1)){									 //to know if path is present at the starting
				path_ = temp;
				++argv;
				++temp_int;
			}
			for (int j = temp_int; j < argc; j++){												//looping through the extensions and filenames
				temp = *argv;
				if (temp.find('/') == -1 && temp.find('.') != -1){ addPattern(temp); }	        //saving the pattern
				else{
					if (temp == "/s" || temp == "/S"){ flag_fm = 1; }
					else if (temp == "/d" || temp == "/D"){ flag_d = 1; }						//identifing options
					else if ((temp == "/f" || temp == "/F") && j != argc - 1){
						++argv;
						test_store = (*argv);
						flag_f = 1;
						++j;
					}
					else{																	//ignoring invalid option
					}
				}
				++argv;
			}
			search();																			//building catalog
			Display dis(DataStore1);
			dis.display(0);
			if (flag_d == 1){ dis.display(1); }									 //to display duplicates flag_d is set when /d option is given
			if (flag_f == 1){
				Catalog cat(DataStore1);														//to check for /f optoin 
				cat.search_text(test_store, 0);
			}
		}
		else{
			path_ = ".";
			search();
			Display dis(DataStore1);
			dis.display(3);																	//if no command line argument was given
		}
 }
	catch (std::exception e) {
		std::cout << e.what();
	}
}
Beispiel #24
0
char* find_lcs(const char *a, int na, const char *b, int nb) {
	if (na > nb) {
		const char *c; int t;
		c = a, a = b, b = c;
		t = na, na = nb, nb = t;
	}

	if (na == 0)
		return alloc_str(1);

	if (na == 1) {
		for (int i = 0; i < nb; i++) {
			if (a[0] == b[i])
				return substr(a, 0, 1);
		}
		return alloc_str(1);
	}

	static int t1[MAXN];
	static int t2[MAXN];
	int len = lcs_len(a, na, b, nb, t1);
	if (len == 0)
		return alloc_str(1);
	int half_len = na / 2;
	char *la = substr(a, 0, half_len);
	char *ra = substr(a, half_len, na - half_len);
	char *tb = reverse(b, nb);
	char *ta = reverse(ra, na - half_len);
	lcs_len(la, half_len, b, nb, t1);
	lcs_len(ta, na - half_len, tb, nb, t2);
	
	int split = -1;
	for (int i = 0; i <= nb; i++) {
		if (t1[i] + t2[nb-i] == len) {
			split = i;
			break;
		}
	}
	
	char *lb = substr(b, 0, split);
	char *rb = substr(b, split, nb - split);
	char *sl = find_lcs(la, half_len, lb, split);
	char *sr = find_lcs(ra, na - half_len, rb, nb - split);
	char *ret = cat(sl, sr);
	free(la), free(ra), free(ta);
	free(lb), free(rb), free(tb);
	free(sl), free(sr);
	return ret;
}
Beispiel #25
0
int main(int argc, char *argv[])
{
    if (argc < 3) {
        write_(STDOUT_FILENO, "Usage:\n    filesender port file\n", 32);
        return 0;
    }

    struct sigaction sa;
    bzero(&sa, sizeof(sa));
    sa.sa_handler = SIG_IGN;
    sa.sa_flags = SA_RESTART;
    CATCH_IO(sigaction(SIGCHLD, &sa, NULL));
    
    CATCH_IO(access(argv[2], R_OK | F_OK));

    int sock;
    CATCH_IO(sock = make_server_socket(argv[1]));
    CATCH_IO(listen(sock, 1));

    struct sockaddr_in client;
    socklen_t len = sizeof(client);
    while(1) {
        int remote, pid;
        CATCH_IO(remote = accept(sock, (struct sockaddr*) &client, &len));
        CATCH_IO(pid = fork());

        if (pid == 0) {
            int file;

            CATCH_IO(file = open(argv[2], O_RDONLY));
            int s = cat(file, remote);
            int exit_status = 0;

            if (s == -1) {
                perror("Error while sending file");
                exit_status = 1;
            }

            close(remote);
            close(file);
            _exit(exit_status);
        }

        CATCH_IO(close(remote));
    }

    CATCH_IO(close(sock));
    return 0;
}
Beispiel #26
0
/**
 * Log the entry. Stop, when empty line is found
 */
int 
log_entry(Conf * conf){
    char * logentry;
    char * line;
    char * header;
    int byte_read;
    int bytes_sofar = 0;
    size_t log_size = sizeof(char) * STRINGSIZE;
    size_t line_size = sizeof(char) * STRINGSIZE;

    logentry = (char *) xmalloc(line_size);
    line = (char *) xmalloc(line_size);
    header = (char *) xmalloc(line_size);
    strcpy(logentry, "");

    header = mkheader(header);
    while(true){
        byte_read = getline(&line, &line_size, stdin);
        if(byte_read > 0){
            bytes_sofar += byte_read;
            if(byte_read < log_size){
                cat(&logentry, line);
            }
        }
        if(strcmp(line,"\n") == 0){
            if(strcmp(logentry, "\n") != 0){
                fprintf(conf->files.logfile, "%s", header);
                fprintf(conf->files.logfile, "%s", logentry);
                free(line);
                free(header);
                free(logentry);
                return 0;
            }
            else {
                printf("Nothing logged.\n");
                free(line);
                free(header);
                free(logentry);
                return 0;
            }
        }
    }

    // We should not be here
    free(line);
    free(header);
    free(logentry);
    return 1;
}
Beispiel #27
0
char *readInput(int *bg) {
	
	char* user = getenv("USER");
	char* prompt = cat(user," > ");
	char* stream = readline(prompt);
	int len = strlen(prompt);
	
	add_history(stream);
	
	*bg = prompt[len-1] == '&';
	if(*bg)
		prompt[len-1] = '\0';

	return stream;
}
Beispiel #28
0
static void get_def_paren(
    char *buf)
{
    char *b,
       *c;
    int lth,
        tlth;

    get_must(0, buf);
    if (def_constraintp)
        free(def_constraintp);
    for (def_constraintp = c = calloc(1, lth = 128); *buf != ')';
         get_must(0, buf))
    {
        tlth = strlen(buf) + 1;
        if (&c[tlth] > &def_constraintp[lth])
        {
            b = def_constraintp;
            def_constraintp = realloc(b, lth += 128);
            c = &def_constraintp[(c - b)];
        }
        c = cat(cat(c, buf), " ");
    }
}
Beispiel #29
0
int main(){
	char a[] = "aly ";
	char b[] = "milich";


	cat(a,b);
	printf("%s\n", a);

	char c[] = "atm";
	char d[] = "atm";

	comp(c,d);

	return 0;
}
Beispiel #30
0
//ファイルの終端からN行読み込む.(あんまり効率は良くない)
std::string XLFileUtil::tail(const std::string & inFileName,unsigned int lines)
{
	//すごく効率の悪いやり方
	auto filelines = XLStringUtil::split_vector("\n", cat(inFileName) );
	if ( filelines.size() < lines )
	{
		return XLStringUtil::join("\n",filelines);
	}
	std::string r ;
	for(unsigned int i = filelines.size() - lines ; i < filelines.size() ; i ++ )
	{
		r += filelines[i] + "\n";
	}
	return r;
}