Ejemplo n.º 1
0
void run_interactive_loop(geonames_by_token_func geonames_func,
                          int max_results,
                          process_geoname_id_func process_func) {
    char q[MAX_QUERY_LENGTH];

    debug("Ready to serve\n");

    for (;;) {
        int i;
        vector_t tokens;
        geoname_indices_t geonames;

        if (!fgets(q, sizeof q, stdin))
            break;

        strlower(strtrim(q));

        if (!*q) {
            puts("");
            continue;
        }

        tokens = strsplit(q, " \t");
        geonames = process_query(tokens, max_results, geonames_func);

        for (i = 0; i != vector_size(geonames); ++i)
            process_func(geoname_idx(geonames, i));

        puts("");

        vector_free(tokens);
        vector_free(geonames);
    }
}
Ejemplo n.º 2
0
static void
load_GoodBrd()			//´ÓÎļþÖлñÈ¡¶©ÔÄ°æÃ棬Ìî³äÊý¾Ý½á¹¹ GoodBrd
{
	char buf[STRLEN];
	FILE *fp;

	GoodBrd.num = 0;
	setuserfile(buf, ".goodbrd");
	if ((fp = fopen(buf, "r"))) {
		for (GoodBrd.num = 0; GoodBrd.num < GOOD_BRC_NUM;) {
			if (!fgets(buf, sizeof (buf), fp))
				break;
			strsncpy(GoodBrd.ID[GoodBrd.num], strtrim(buf),
				 sizeof (GoodBrd.ID[GoodBrd.num]));
			if (canberead(GoodBrd.ID[GoodBrd.num]))
				GoodBrd.num++;
		}
		fclose(fp);
	}
	if (GoodBrd.num == 0) {
		GoodBrd.num++;
		if (getbcache(DEFAULTBOARD))
			strcpy(GoodBrd.ID[0], DEFAULTBOARD);
		else
			strcpy(GoodBrd.ID[0], currboard);
	}
}
Ejemplo n.º 3
0
/*
 * Read from file <szGlobalExcludeFunctionFileName>
 * the names of global functions, which don't need to replace.
 * In this file are function's names on each string.
 * After '#' write comments
 */
int LuaObfuscator::readAddonGlobalExcludeFunctions(const char *szGlobalExcludeFunctionFileName, StringList &FunctionsExclude)
{
	const int N = 1024;
	int res = 0;
	char buf[N];

	if (!szGlobalExcludeFunctionFileName || !szGlobalExcludeFunctionFileName[0])
		return -1;

	FILE *file = fopen(szGlobalExcludeFunctionFileName, "rt");
	if (!file)
		return -1;

	FunctionsExclude.clear();

	std::string str;
	while (feof(file) && fgets(buf, N, file)) {
		char *pName = strtrim(buf);
		if (char *p = strchr(pName, '\n'))
			*p = 0;
		if (pName[0] && pName[0] != '#') {
			str.assign(pName);
			FunctionsExclude.push_back(str);
		}
	}

	fclose(file);

	return res;
}
Ejemplo n.º 4
0
int deleteEntry(char *cmd, int argc, char **argv, agenda ag) {
    char *valor;
    if (argc != 1 || (strcmp(argv[0], "nome") != 0 &&
                strcmp(argv[0], "sobrenome") != 0 &&
                strcmp(argv[0], "endereco") != 0 &&
                strcmp(argv[0], "telefone") != 0 &&
                strcmp(argv[0], "email") != 0)) {
        printf("A forma correta do comando e':\n apagar [nome|sobrenome|endereco|telefone|email]\n");
        return 1;
    }

    valor = (char *) malloc(STRING_SIZE * sizeof(char));
    if (valor == NULL) {
        printf("Impossivel alocar memoria para armazenar valor\n");
        exit(EXIT_FAILURE);
    }

    printf("%s: ", argv[0]);
    fgets(valor, STRING_SIZE, stdin);
    strtrim(valor);

    removeLista(ag, argv[0], valor);

    free(valor);
    return 0;
}
Ejemplo n.º 5
0
size_t LuaObfuscator::readAddonTocFile(char const *szTocFileName, StringList &luaFiles) {
	char buf[300];

	if (!szTocFileName || !szTocFileName[0])
		return 0;

	FILE *fileToc = fopen(szTocFileName, "rt");
	if (!fileToc) {
		print("Couldn't open the toc file %s\n", szTocFileName);
		return 0;
	}

	luaFiles.clear();
	//files.str("");
	while (!feof(fileToc) && fgets(buf, 300, fileToc)) {
		if (!buf[0])
			continue;
		char *pFile = strtrim(buf);
		char *pFileExt = strrchr(pFile, '.');
		bool bLuaFile = false;
		if (pFileExt) {
			strlwr(pFileExt);
			bLuaFile = !strcmp(pFileExt, ".lua");
		}
		if (pFile[0] && pFile[0] != '#' &&  bLuaFile) {
			luaFiles.push_back(pFile);
		}
	}
	fclose(fileToc);

	return luaFiles.size();
}
Ejemplo n.º 6
0
static int
dbfield_isnull( Dbptr db )
{
	char	*fnull;
	long	fsize;
	char	*stringval;
	int	isnull = 0;

	dbquery( db, dbFIELD_SIZE, &fsize );
	dbquery( db, dbNULL, &fnull );

	allot( char *, stringval, fsize + 2 );

	dbget( db, stringval );

	strtrim( stringval );

	if( ! strcmp( stringval, fnull ) ) {

		isnull = 1;

	} else {

		isnull = 0;
	}

	return isnull;
}
Ejemplo n.º 7
0
static int process_boolean(char *buffer, char *name, int namesize, int *val)
{
    char name1[BUFSIZ];
    char *ptr = NULL;
    char *tok = strtok_r(buffer, "=", &ptr);
    if (tok) {
        strncpy(name1, tok, BUFSIZ - 1);
        strtrim(name, name1, namesize - 1);
        if (name[0] == '#')
            return 0;
        tok = strtok_r(NULL, "\0", &ptr);
        if (tok) {
            while (isspace(*tok))
                tok++;
            *val = -1;
            if (isdigit(tok[0]))
                *val = atoi(tok);
            else if (!strncasecmp(tok, "true", sizeof("true") - 1))
                *val = 1;
            else if (!strncasecmp
                     (tok, "false", sizeof("false") - 1))
                *val = 0;
            if (*val != 0 && *val != 1) {
                ERR(NULL, "illegal value for boolean "
                    "%s=%s", name, tok);
                return -1;
            }

        }
    }
    return 1;
}
Ejemplo n.º 8
0
int
save_draw(ui_t *ui)
{
    char field_value[80];

    // Get panel information
    save_info_t *info = save_info(ui);

    // Get filter stats
    sip_stats_t stats = sip_calls_stats();

    mvwprintw(ui->win, 7, 3, "( ) all dialogs ");
    mvwprintw(ui->win, 8, 3, "( ) selected dialogs [%d]", call_group_count(info->group));
    mvwprintw(ui->win, 9, 3, "( ) filtered dialogs [%d]", stats.displayed);

    // Print 'current SIP message' field label if required
    if (info->msg != NULL)
        mvwprintw(ui->win, 10, 3, "( ) current SIP message");

    mvwprintw(ui->win, 7, 35, "( ) .pcap (SIP)");
    mvwprintw(ui->win, 8, 35, "( ) .pcap (SIP + RTP)");
    mvwprintw(ui->win, 9, 35, "( ) .txt");

    // Get filename field value.
    memset(field_value, 0, sizeof(field_value));
    strcpy(field_value, field_buffer(info->fields[FLD_SAVE_FILE], 0));
    strtrim(field_value);

    mvwprintw(ui->win, 4, 60, "     ");
    if (strstr(field_value, ".pcap")) {
        info->saveformat = (setting_enabled(SETTING_CAPTURE_RTP))? SAVE_PCAP_RTP : SAVE_PCAP;
    } else if (strstr(field_value, ".txt")) {
        info->saveformat = SAVE_TXT;
    } else {
        if (info->saveformat == SAVE_PCAP || info->saveformat == SAVE_PCAP_RTP)
            mvwprintw(ui->win, 4, 60, ".pcap");
        else
            mvwprintw(ui->win, 4, 60, ".txt ");
    }

    set_field_buffer(info->fields[FLD_SAVE_ALL], 0, (info->savemode == SAVE_ALL) ? "*" : " ");
    set_field_buffer(info->fields[FLD_SAVE_SELECTED], 0,
                     (info->savemode == SAVE_SELECTED) ? "*" : " ");
    set_field_buffer(info->fields[FLD_SAVE_DISPLAYED], 0,
                     (info->savemode == SAVE_DISPLAYED) ? "*" : " ");
    set_field_buffer(info->fields[FLD_SAVE_MESSAGE], 0,
                     (info->savemode == SAVE_MESSAGE) ? "*" : " ");
    set_field_buffer(info->fields[FLD_SAVE_PCAP], 0, (info->saveformat == SAVE_PCAP) ? "*" : " ");
    set_field_buffer(info->fields[FLD_SAVE_PCAP_RTP], 0, (info->saveformat == SAVE_PCAP_RTP) ? "*" : " ");
    set_field_buffer(info->fields[FLD_SAVE_TXT], 0, (info->saveformat == SAVE_TXT) ? "*" : " ");

    // Show disabled options with makers
    if (!setting_enabled(SETTING_CAPTURE_RTP))
        set_field_buffer(info->fields[FLD_SAVE_PCAP_RTP], 0, "-");

    set_current_field(info->form, current_field(info->form));
    form_driver(info->form, REQ_VALIDATION);

    return 0;
}
Ejemplo n.º 9
0
	/***************************************************************
	 * cli_error:
	 ***************************************************************/
int   cli_error(		/* Display only				*/
    int   sts			/* <r> status value			*/
   ,char  msg[]			/* <r> message to display		*/
   )
   {
    int   k;
    char  fmt[20];
    char  *p;
    struct descriptor  *dsc;

    if (msg && msg[0])
        fprintf(stderr,"\n*ERR* %s\n",msg);

    dsc = cli_addr_cmdline_dsc();
    if (p = dsc->dscA_pointer)
       {
        strtrim(p,0);
        fprintf(stderr,"cmdline = '%s'\n",p);
        k = cliNonblank_save - p;
        if (k>=0 && k<dsc->dscW_length)
           {
            sprintf(fmt,"%%%ds^^^^\n",k+11);
            fprintf(stderr,fmt,"");
           }
       }
    fprintf(stderr,"\n");
    return(sts);
   }
Ejemplo n.º 10
0
/*---------------------------------------------------------------------------*/
int main(int count, char *strings[])
{	const int on=1;
	int sd, port;
	struct sockaddr_in addr;
	char buffer[1024];

	/*---Get parameters---*/
	if ( count < 3  ||  count > 4)
	{
		printf("usage: %s [<listening-port>] <dest-addr> <dest-port>\n", strings[0]);
		return 0;
	}
	if ( count == 4 )
	{
		port = atoi(strings[1]);
		strings++;
	}
	else
		port = DEFAULT_PORT;

	/*---Create and configure socket---*/
	sd = socket(PF_INET, SOCK_DGRAM, 0);
	if ( sd < 0 )
		panic("socket failed");
	if ( setsockopt(sd, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) != 0 )
		panic("set broadcast failed");
	bzero(&addr, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(port);
	if ( inet_aton("128.1.1.1", &addr.sin_addr) == 0 )
		panic("inet_aton failed (%s)", strings[1]);
	if ( bind(sd, (struct sockaddr*)&addr, sizeof(addr)) != 0 )
		panic("bind failed");
	addr.sin_port = htons(atoi(strings[2]));
	if ( inet_aton(strings[1], &addr.sin_addr) == 0 )
		panic("inet_aton failed (%s)", strings[1]);

	/*---Create child---*/
	if ( fork() )
		Receiver(sd);
	else
		shutdown(sd, 0);	/* close the input channel */

	/*---Begin broadcast---*/
	do
	{
		fgets(buffer, sizeof(buffer), stdin);
		strtrim(buffer);
		if ( sendto(sd, buffer, strlen(buffer)+1, 0, (struct sockaddr*)&addr, sizeof(addr)) < 0 )
			perror("sendto");
	}
	while ( strcmp(buffer, "bye") != 0 );

	/*---Wait for child termination & cleanup---*/
	wait(0);
	close(sd);
	return 0;
}
Ejemplo n.º 11
0
int fswc_getopt_file(fswc_getopt_t *s)
{
	char line[1024];
	char *arg, *val;
	struct option *opt;
	
	while(fgets(line, 1024, s->f))
	{
		s->line++;
		strtrim(line, WHITESPACE);
		arg = argdup(line, WHITESPACE, 0, 0);
		
		if(!arg) continue;
		if(*arg == '#') continue;
		
		/* Find argument in the list. */
		opt = (struct option *) s->long_opts;
		while(opt->name)
		{
			if(!strcasecmp(opt->name, arg)) break;
			opt++;
		}
		
		if(!opt->name)
		{
			ERROR("Unknown argument: %s", arg);
			WARN("%s,%i: %s", s->filename, s->line, line);
			free(arg);
			return(-2);
		}
		
		if(opt->val == 'c')
		{
			ERROR("You can't use config from a configuration file.");
			WARN("%s,%i: %s", s->filename, s->line, line);
			free(arg);
			return(-2);
		}
		
		if(opt->has_arg)
		{
			val = argdup(line, WHITESPACE, 1, 0);
			optarg = val;
		}
		
		free(arg);
		
		return(opt->val);
	}
	
	/* Have we reached the end of the file? */
	if(feof(s->f)) return(-1);
	
	/* No.. there has been an error. */
	ERROR("fread: %s", strerror(errno));
	
	return(-2);
}
Ejemplo n.º 12
0
/*DirListing - read the directory and output an HTML table. Used partially from source above*/
void DirListing(FILE* FP, char* Path) {
	struct dirent *dirent;
	struct stat info;
	char Filename[MAXPATH];
	DIR* dir = opendir(Path);
	fprintf(FP, "<html><head><title>Directory Lister</title></body>"
		"<body><font size=+4>CS410 Web Server</font><br><hr width=\"100%%\"><br><center>"
		"<table border cols=4 width=\"100%%\" bgcolor=\"009999\">");
	fprintf(FP, "<caption><font size=+3>Directory of %s</font></caption>\n", Path);
	if ( dir == 0 )
	{
		fprintf(FP, "</table><font color=\"white\" size=+2>%s</font></body></html>", strerror(errno));
		return;
	}
	while ( (dirent = readdir(dir)) != 0 )
	{
		if ( strcmp(Path, "/") == 0 )
			sprintf(Filename, "/%s", dirent->d_name);
		else
			sprintf(Filename, "%s/%s", Path, dirent->d_name);
		fprintf(FP, "<tr>");
		if ( stat(Filename, &info) == 0 )
		{
			fprintf(FP, "<td>%s</td>", dirent->d_name);
			if ( S_ISDIR(info.st_mode) )
			{
				if ( strcmp(dirent->d_name, "..") == 0 )
					fprintf(FP, "<td><a href=\"http://%s%s\">(parent)</a></td>", Host, dir_up(Path));
				else
					fprintf(FP, "<td><a href=\"http://%s%s\">%s</a></td>", Host, Filename, dirent->d_name);
				fprintf(FP, "<td>Directory</td>");
			}
			else if ( S_ISREG(info.st_mode) )
			{
				fprintf(FP, "<td><a href=\"http://%s%s\">%s</a></td>", Host, Filename, dirent->d_name);
				fprintf(FP, "<td>%d</td>", info.st_size);
			}
			else if ( S_ISLNK(info.st_mode) )
				fprintf(FP, "<td>Link</td>");
			else if ( S_ISCHR(info.st_mode) )
				fprintf(FP, "<td>Character Device</td>");
			else if ( S_ISBLK(info.st_mode) )
				fprintf(FP, "<td>Block Device</td>");
			else if ( S_ISFIFO(info.st_mode) )
				fprintf(FP, "<td>FIFO</td>");
			else if ( S_ISSOCK(info.st_mode) )
				fprintf(FP, "<td>Socket</td>");
			else
				fprintf(FP, "<td>(unknown)</td>");
			fprintf(FP, "<td>%s</td>", strtrim(ctime(&info.st_ctime)));
		}
		else
			perror(Path);
		fprintf(FP, "</tr>\n");
	}
	fprintf(FP, "</table></center></body></html>");
}
Ejemplo n.º 13
0
void String::strip(const char *chars)
{
    size_t len = strtrim(chars, getText(), getLength());
    if(!len) {
        setLength(len);
        return;
    }
    setLength(strchop(chars, getText(), len));
}
Ejemplo n.º 14
0
char *t_Str::strip(const char *chars, char *str, size_t len)
{
    len = strtrim(chars, str, len);

    if(!len)
        return str;

    return ifind(chars, str, len);
}   
Ejemplo n.º 15
0
SEXP
read_mtp(SEXP fname)
{
    FILE *f;
    char buf[MTP_BUF_SIZE], blank[1], *pres;
    MTB  *mtb, thisRec;
    int i, j, res, nMTB = MTB_INITIAL_ENTRIES;

    PROTECT(fname = asChar(fname));
#ifdef WIN32 /* force text-mode read */
    if ((f = fopen(R_ExpandFileName(CHAR(fname)), "rt")) == NULL)
#else
    if ((f = fopen(R_ExpandFileName(CHAR(fname)), "r")) == NULL)
#endif
	error(_("unable to open file '%s': '%s'"), 
	      CHAR(fname), strerror(errno));
    if ((fgets(buf, MTP_BUF_SIZE, f) == NULL) ||
	strncmp(buf, "Minitab Portable Worksheet ", 27) != 0)
	error(_("file '%s' is not in Minitab Portable Worksheet format"),
	      CHAR(fname));
    pres = fgets(buf, MTP_BUF_SIZE, f);
    if(pres != buf) error(_("file read error"));
    UNPROTECT(1);

    mtb = Calloc(nMTB, MTB);
    for (i = 0; !feof(f); i++) {
	if (i >= nMTB) {
	    nMTB *= 2;
	    mtb = Realloc(mtb, nMTB, MTB);
	}
	thisRec = mtb[i] = Calloc(1, MTBDATC);
	if (sscanf(buf, "%%%7d%7d%7d%7d%c%8c", &(thisRec->type),
		   &(thisRec->cnum), &(thisRec->len),
		   &(thisRec->dtype), blank, thisRec->name) != 6)
	    error(_("first record for entry %d is corrupt"), i+1);
	thisRec->name[8] = '\0';
	strtrim(thisRec->name);	/* trim trailing white space on name */
	switch (thisRec->dtype) {
	case 0:		/* numeric data */
	    thisRec->dat.ndat = Calloc(thisRec->len, double);
	    for (j = 0; j < thisRec->len; j++) {
		res = fscanf(f, "%lg", thisRec->dat.ndat + j);
		if(res == EOF) error(_("file read error"));
	    }
	    break;
	default:
	    if (thisRec->type == 4) { /* we have a matrix so dtype is number of columns */
		thisRec->dat.ndat = Calloc(thisRec->len, double);
		for (j = 0; j < thisRec->len; j++) {
		    res = fscanf(f, "%lg", thisRec->dat.ndat + j);
		    if(res == EOF) error(_("file read error"));
		}
	    } else {
		error(_("non-numeric data types are not yet implemented"));
	    }
	}
Ejemplo n.º 16
0
Archivo: ini.c Proyecto: chengs/UEFI
INIFILEHANDLE ini_open(const char *iniFile, const char *mode)
{
	char lineBuf[1024];
	LPINIFILE file;
	LPINISECTION curSection = NULL;
	FILE *fp;
	fp = fopen(iniFile, mode);
	if(fp == NULL)
		return NULL;
	file = ini_createIniStruct(iniFile);
	strcpy(file->mode, mode);
	while(fgets(lineBuf, 1023, fp))
	{
		char *p = strtrim(lineBuf);
		int len = strlen(p);
		if(strlen(p) <= 0)
			continue;
		else if(p[0] == '#')
			continue;
		else if((p[0] == '[') && (p[len - 1] == ']'))
		{
			p[len - 1] = '\0';
			p = strtrim(&p[1]);
			curSection = ini_addSection(file, p);
		}
		else
		{
			char *p2 = strchr(lineBuf, '=');
			if(p2 == NULL)
			{
				ini_destryIniStruct(file);
				file = NULL;
				break;
			}
			*p2++ = '\0';
			p = strtrim(p);
			p2 = strtrim(p2);
			ini_addItem(curSection, p, p2);
		}
	}
	fclose(fp);
	return (INIFILEHANDLE)file;
}
Ejemplo n.º 17
0
Archivo: conf.c Proyecto: rctay/powaur
/* Disgusting 8 variable function */
static void parse_pmoption_repeat(int *flag, int *flag_com, char *line,
								  const char *key, void (*repeatfn) (char *),
								  void (*freefn) (void **), void **global_conf,
								  int comment)
{
	if ((comment && (*flag || *flag_com)) || (!comment && *flag)) {
		return;
	}

	if (!(line = strchr(line, '='))) {
		return;
	}

	if (*global_conf) {
		freefn(global_conf);
		*global_conf = NULL;
	}

	++line;
	line = strtrim(line);
	if (!strlen(line)) {
		return;
	}

	char *ptr;
	while (ptr = strchr(line, ' ')) {
		*ptr = 0;
		++ptr;

		repeatfn(line);
		line = ptr;
		line = strtrim(line);
	}

	repeatfn(line);

	if (comment) {
		*flag_com = 1;
	} else {
		*flag = 1;
	}
}
Ejemplo n.º 18
0
char * ps_strfilter_filename (char *filename)
{
	char * result = NULL;
	if (filename!=NULL)
	{
		result = strtrim (filename);
		for (unsigned int i=0;i<strlen (result);i++) 
			if (result[i]==' ' || result[i]=='\\' || result[i]=='/') result[i]='_';
	}
	return result;
}
Ejemplo n.º 19
0
Archivo: parser.c Proyecto: rju/slp
/* parser and renderer for seperator of two columns
 */
int parse_column_sep() {
	token = yylex();
	if (token == NUMBER) {
		token = yylex();
	} else {
		string = "0.5";
	}
	fprintf(ofile,"\\end{column}\n\\begin{column}{%s\\textwidth}\n",strtrim(string));
	structure_count = 0;
	return 0;
}
Ejemplo n.º 20
0
static bool
opt_parse_line(char *line, int n, char *fn)
{
	int i;
	const char *err = NULL;
	char *token;
	buffer b;

	assert(line && fn);

	b.ptr = line;

	if((err = get_token(&b, 0))) {
		fprintf(stderr, "%s\n", err);
		return FALSE;
	}

	if(b.data == NULL)
		return FALSE;

	strtrim(b.data);
	strtrim(b.ptr);

	token = b.data;
	b.data = b.ptr = b.ptr;

	for(i = 0; opt_parsers[i].token; i++)
		if(!strcmp(opt_parsers[i].token, token)) {
			if(!(err = opt_parsers[i].func(&b)))
				return FALSE;
			break;
		}

	fprintf(stderr, _("%s: parse error at line %d: "), fn, n);
	if(err)
		fprintf(stderr, "%s\n", err);
	else
		fprintf(stderr, _("unknown token %s\n"), token);

	return TRUE;
}
Ejemplo n.º 21
0
repository_t *rsync_get_repository(driver_t * self, char *supfile,
				   list_t * repositories_hierarchy)
{
	FILE *file;
	char *line, *path, *name, *extension;
	repository_t *repository;
	size_t n;
	int nread;

	assert(supfile);
	if (!(extension = rindex(supfile, '.')) || strcmp(extension, ".rsync"))
		return NULL;

	supfile = xstrdup_printf("/etc/ports/%s", supfile);

	file = fopen(supfile, "r");
	if (file == NULL)
		return NULL;

	line = NULL;
	repository = NULL;

	while ((nread = getline(&line, &n, file)) >= 0) {
		*(line + strlen(line) - 1) = 0;
		strtrim(line);
		if (line[0] == '#' || strlen(line) == 0 ||
		    (!strstr(line, "destination") && strchr(line, '=')))
			continue;
		path = strtrim(xstrdup(strchr(line, '=') + 1));
		if (!strncmp("/usr/ports/", path, 11))
			name = xstrdup(path + 11);
		else
			name = xstrdup(strrchr(path, '/') + 1);
		repository = repository_new(name, path, supfile, self,
					    repositories_hierarchy);
		break;
	}
	free(line);
	fclose(file);
	return repository;
}
Ejemplo n.º 22
0
/* Checks if we have .install file in PKGBUILD at cwd.
 * returns a newly allocated string for the .install file if we have
 * returns NULL if no
 */
char *have_dotinstall(void)
{
	FILE *fp;
	char buf[PATH_MAX];
	char *str, *dotinstall = NULL;
	size_t len;

	fp = fopen("PKGBUILD", "r");
	if (!fp) {
		error(PW_ERR_FOPEN, "PKGBUILD");
		return NULL;
	}

	while (str = fgets(buf, PATH_MAX, fp)) {
		str = strtrim(str);
		len = strlen(str);
		if (!len) {
			continue;
		}

		if (!strncmp(str, "install", 7)) {
			/* No error checking done here, if malformed, that's it */
			str = strchr(str, '=');
			if (!str) {
				break;
			}

			++str;
			str = strtrim(str);
			if (!strlen(str)) {
				break;
			} else {
				dotinstall = strdup(str);
				break;
			}
		}
	}

	fclose(fp);
	return dotinstall;
}
Ejemplo n.º 23
0
static int dbf_read_record(TABDCA *dca, struct dbf *dbf)
{     /* read next record from xBASE data file */
      int b, j, k, ret = 0;
      char buf[DBF_FDLEN_MAX+1];
      xassert(dbf->mode == 'R');
      if (setjmp(dbf->jump))
      {  ret = 1;
         goto done;
      }
      /* check record flag */
      b = read_byte(dbf);
      if (b == 0x1A)
      {  /* end of data */
         ret = -1;
         goto done;
      }
      if (b != 0x20)
      {  xprintf("%s:0x%X: invalid record flag\n", dbf->fname,
            dbf->offset);
         longjmp(dbf->jump, 0);
      }
      /* read dummy RECNO field */
      if (dbf->ref[0] > 0)
         mpl_tab_set_num(dca, dbf->ref[0], dbf->count+1);
      /* read fields */
      for (k = 1; k <= dbf->nf; k++)
      {  /* read k-th field */
         for (j = 0; j < dbf->len[k]; j++)
            buf[j] = (char)read_byte(dbf);
         buf[dbf->len[k]] = '\0';
         /* set field value */
         if (dbf->type[k] == 'C')
         {  /* character field */
            if (dbf->ref[k] > 0)
               mpl_tab_set_str(dca, dbf->ref[k], strtrim(buf));
         }
         else if (dbf->type[k] == 'N')
         {  /* numeric field */
            if (dbf->ref[k] > 0)
            {  double num;
               strspx(buf);
               xassert(str2num(buf, &num) == 0);
               mpl_tab_set_num(dca, dbf->ref[k], num);
            }
         }
         else
            xassert(dbf != dbf);
      }
      /* increase record count */
      dbf->count++;
done: return ret;
}
Ejemplo n.º 24
0
void main(void) {
  char *test1 = strdup("  \t  \nTest programu\tOK... ...\n\t\n    \n ");
  char *test2 = strdup("");
  char *test3 = strdup("   ");
  char *test4 = strdup("abcd");

  /* zde mozno nastavit ruzne testovaci retezce */
  char *test = test1;

  strtrim(test);

  printf("'%s'\n",test);
}
Ejemplo n.º 25
0
Pf *
orbstat2pf( Orbstat *orbstat, int orbversion ) 
{
	Pf	*pf;
	char	*s;
	struct in_addr in;

	if( orbstat == (Orbstat *) NULL ) {

		return (Pf *) NULL;
	} 

	pf = pfnew( PFARR );

	if( orbversion > 0 ) {
		pfput_int( pf, "orbversion", orbversion );
	}
	
	pfput_time( pf, "when", orbstat->when );
	pfput_time( pf, "started", orbstat->started );
	pfput_time( pf, "orb_start", orbstat->orb_start );

	pfput_boolean( pf, "connections", orbstat->connections );
	pfput_boolean( pf, "messages", orbstat->messages );

	pfput_int( pf, "maxdata", orbstat->maxdata );
	pfput_int( pf, "errors", orbstat->errors );
	pfput_int( pf, "rejected", orbstat->rejected );
	pfput_int( pf, "closes", orbstat->closes );
	pfput_int( pf, "opens", orbstat->opens );
	pfput_int( pf, "port", orbstat->port );

	memcpy( &in, &orbstat->address, sizeof( struct in_addr ) );
	pfput_string( pf, "address", inet_ntoa( in ) );

	pfput_int( pf, "pid", orbstat->pid );
	pfput_int( pf, "nsources", orbstat->nsources );
	pfput_int( pf, "nclients", orbstat->nclients );
	pfput_int( pf, "maxsrc", orbstat->maxsrc );
	pfput_int( pf, "maxpkts", orbstat->maxpkts );

	s = strdup( orbstat->version );
	strtrim( s );
	pfput_string( pf, "version", s );
	free( s );

	pfput_string( pf, "who", orbstat->who );
	pfput_string( pf, "host", orbstat->host );

	return pf;
}
Ejemplo n.º 26
0
static alpm_handle_t *alpm_init(void) {
  alpm_handle_t *alpm = NULL;
  enum _alpm_errno_t alpm_errno = 0;
  FILE *fp;
  char line[PATH_MAX];
  char *ptr, *section = NULL;

  alpm = alpm_initialize("/", "/var/lib/pacman", &alpm_errno);
  if (!alpm) {
    alpm_strerror(alpm_errno);
    return NULL;
  }

  db_local = alpm_get_localdb(alpm);

  fp = fopen("/etc/pacman.conf", "r");
  if (!fp) {
    perror("fopen: /etc/pacman.conf");
    return alpm;
  }

  while (fgets(line, PATH_MAX, fp)) {
    strtrim(line);

    if (strlen(line) == 0 || line[0] == '#') {
      continue;
    }
    if ((ptr = strchr(line, '#'))) {
      *ptr = '\0';
    }

    if (line[0] == '[' && line[strlen(line) - 1] == ']') {
      ptr = &line[1];
      if (section) {
        free(section);
      }

      section = strdup(ptr);
      section[strlen(section) - 1] = '\0';

      if (strcmp(section, "options") != 0) {
        alpm_register_syncdb(alpm, section, 0);
      }
    }
  }

  free(section);
  fclose(fp);
  return alpm;
}
Ejemplo n.º 27
0
int security_load_booleans(char *path) {
	FILE *boolf;
	char buffer[BUFSIZ];
	char name[BUFSIZ];
	char name1[BUFSIZ];
	int val;
	int errors=0;

	boolf = fopen(path ? path : selinux_booleans_path(),"r");
	if (boolf == NULL) 
		return -1;

        while (fgets(buffer, sizeof(buffer), boolf)) {
		char *tok=strtok(buffer,"=");
		if (tok) {
			strncpy(name1,tok, BUFSIZ-1);
			strtrim(name,name1,BUFSIZ-1);
			if ( name[0]=='#' ) continue;
			tok=strtok(NULL,"\0");
			if (tok) {
				while (isspace(*tok)) tok++;
				val = -1;
				if (isdigit(tok[0]))
					val=atoi(tok);
				else if (!strncmp(tok, "true", sizeof("true")-1))
					val = 1;
				else if (!strncmp(tok, "false", sizeof("false")-1))
					val = 0;
				if (val != 0 && val != 1) {
					fprintf(stderr,"illegal value for boolean %s=%s\n", name, tok);
					errors++;
					continue;
				}

				if (security_set_boolean(name, val) < 0) {
					fprintf(stderr,"error setting boolean %s to value %d \n", name, val);
					errors++;
				}
			}
		}
	}
	fclose(boolf);

	if (security_commit_booleans() < 0)
		return -1;

	if (errors)
		errno = EINVAL;
	return errors ? -1 : 0;
}
Ejemplo n.º 28
0
static void
add_endtag( void **vstack, char *tagname )
{
	char	*copy;

	copy = strdup( tagname );
	strtrim( copy );

	pushstr( vstack, "</" );
	pushstr( vstack, copy );
	pushstr( vstack, ">" );

	free( copy );
}
Ejemplo n.º 29
0
Archivo: burp.c Proyecto: cinelli/burp
static long cookie_expire_time(const char *cookie_file, const char *domain,
    const char *name) {
  FILE *fp;
  long expire;
  char cdomain[256], cname[256];

  fp = fopen(cookie_file, "r");
  if (!fp) {
    return 0L;
  }

  for (;;) {
    char cookie[COOKIE_SIZE];
    char *l = &cookie[0];
    size_t len;

    cdomain[0] = cname[0] = '\0';
    expire = 0L;

    if(!(fgets(l, COOKIE_SIZE, fp))) {
      break;
    }

    len = strtrim(l);
    if (len == 0) {
      continue;
    }

    if (strncmp(l, "#HttpOnly_", 10) == 0) {
      l += 10;
    }

    if (*l == '#' || *l == '\0') {
      continue;
    }

    if (sscanf(l, "%s\t%*s\t%*s\t%*s\t%ld\t%s\t%*s", cdomain, &expire, cname) != 3) {
      continue;
    }

    if (strcmp(domain, cdomain) == 0 && strcmp(name, cname) == 0) {
      debug("cookie found (expires %ld)\n", expire);
      break;
    }
  }

  fclose(fp);

  return expire;
}
Ejemplo n.º 30
0
/* 从配置文件读出key或value,数据返回到item_t指针 */
int get_item_from_line(char *line, item_t * item)
{
	char *p = NULL;
	char *p2 = NULL;
	int len = 0;

	p = strtrim(line);
	len = strlen(p);

	if (len <= 0) {
		return -1;
	} else if (p[0] == '#') {
		if (item->num > MAX_ITEM_COMMENT_NUM)
			return 1;

		if (item->comment == NULL) {
			item->comment =
				(char **)malloc(MAX_ITEM_COMMENT_NUM * sizeof(char *));
			if (item->comment == NULL) {
				printf("malloc error!\n");
				return -1;
			}
		}

		item->comment[item->num] = (char *)malloc(len + 1);
		strcpy(item->comment[item->num], p);
		item->num++;
		return 1;
	} else {
		p2 = strchr(p, '=');
		if (p2 == NULL) {
			p2 = strchr(p, ' ');
			if (p2 != NULL) {
				*p2++ = '\0';
			} else {
				return -1;
			}
		} else {
			*p2++ = '\0';
		}

		item->key = (char *)malloc(strlen(p) + 1);
		item->value = (char *)malloc(strlen(p2) + 1);
		strcpy(item->key, p);
		strcpy(item->value, p2);
	}

	return 0;
}