Example #1
0
static time_t
mktime_from_string (char *month,
		    char *mday,
		    char *year)
{
	static char  *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
				   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
	struct tm     tm = {0, };

	tm.tm_isdst = -1;

	if (month != NULL) {
		int i;
		for (i = 0; i < 12; i++)
			if (strcmp (months[i], month) == 0) {
				tm.tm_mon = i;
				break;
			}
	}
	tm.tm_mday = atoi (mday);
	if (strchr (year, ':') != NULL) {
		char **fields = g_strsplit (year, ":", 2);
        	if (n_fields (fields) == 2) {
	        	time_t      now;
        		struct tm  *now_tm;

	  		tm.tm_hour = atoi (fields[0]);
	  		tm.tm_min = atoi (fields[1]);

	  		now = time(NULL);
	  		now_tm = localtime (&now);
	  		tm.tm_year = now_tm->tm_year;
        	}
	} else
		tm.tm_year = atoi (year) - 1900;

	return mktime (&tm);
}
Example #2
0
document *
feature_matrix (char *file_name, int *maxid, int *maxlen)
{
	document *d;
	int  n, m;
	FILE *fp;
	char line[BUFSIZE];
	*maxid  = -1;
	*maxlen =  0;

	if ((fp = fopen(file_name, "r")) == NULL)
		return NULL;
	m = file_lines(fp);
	if ((d = (document *)calloc(m + 1, sizeof(document))) == NULL)
		return NULL;
	d[m].len = -1;
	
	n = 0;
	while (fgets(line, sizeof(line), fp))
	{
		int i, len;
		char *cp, *sp, *lp = line;

		if (isspaces(line))
			continue;
		
		len = n_fields(line);
		if (len > *maxlen)
			*maxlen = len;
		if (!(len > 0)) {
			fprintf(stderr, "feature_matrix: suspicious line:\n%s",
				line);
			exit(1);
		}

		d[n].id  = (int *)calloc(len, sizeof(int));
		d[n].cnt = (double *)calloc(len, sizeof(double));
		d[n].len = len;
		if ((d[n].id == NULL) || (d[n].cnt == NULL))
			return NULL;

		i = 0;
		while (*lp)
		{
			int id;
			double cnt;
			if ((cp = strchr(lp, ':')) == NULL)
				break;
			if ((sp = strpbrk(cp + 1, " \t\n")) == NULL)
				break;
			*cp = '\0';
			*sp = '\0';
			id  = atoi(lp) - 1;	/* zero origin */
			cnt = atof(cp + 1);
			if (id >= *maxid)
				*maxid = id + 1;
			d[n].id[i]  = id;
			d[n].cnt[i] = cnt;
			lp  = sp + 1;
			i++;
		}
		n++;
	}
	fclose(fp);
	return(d);
}
Example #3
0
static void
process_line (char     *line,
	      gpointer  data)
{
	FileData      *fdata;
	FrCommandAce  *ace_comm = FR_COMMAND_ACE (data);
	FrCommand     *comm = FR_COMMAND (data);
	char         **fields = NULL;
	const char    *field_name = NULL;

	g_return_if_fail (line != NULL);

	if (ace_comm->command_type == FR_ACE_COMMAND_UNKNOWN) {
		if (g_str_has_prefix (line, "UNACE")) {
			if (strstr (line, "public version") != NULL)
				ace_comm->command_type = FR_ACE_COMMAND_PUBLIC;
			else
				ace_comm->command_type = FR_ACE_COMMAND_NONFREE;
		}
		return;
	}

	if (! ace_comm->list_started) {
		if (ace_comm->command_type == FR_ACE_COMMAND_PUBLIC) {
			if (g_str_has_prefix (line, "Date"))
				ace_comm->list_started = TRUE;
		}
		else if (ace_comm->command_type == FR_ACE_COMMAND_NONFREE) {
			if (g_str_has_prefix (line, "  Date"))
				ace_comm->list_started = TRUE;
		}
		return;
	}

	fdata = file_data_new ();

	if (ace_comm->command_type == FR_ACE_COMMAND_PUBLIC)
		fields = g_strsplit (line, "|", 6);
	else if (ace_comm->command_type == FR_ACE_COMMAND_NONFREE)
		fields = split_line (line, 5);

	if ((fields == NULL) || (fields[0] == NULL) || (n_fields (fields) < 5))
		return;

	fdata->size = g_ascii_strtoull (fields[3], NULL, 10);
	fdata->modified = mktime_from_string (fields[0], fields[1]);

	if (ace_comm->command_type == FR_ACE_COMMAND_PUBLIC) {
		field_name = fields[5];
		field_name = field_name + 1;
	}
	else if (ace_comm->command_type == FR_ACE_COMMAND_NONFREE)
		field_name = get_last_field (line, 6);

        g_assert (field_name != NULL);
	if (field_name[0] != '/') {
		fdata->full_path = g_strconcat ("/", field_name, NULL);
		fdata->original_path = fdata->full_path + 1;
	}
	else {
		fdata->full_path = g_strdup (field_name);
		fdata->original_path = fdata->full_path;
	}

	g_strfreev (fields);

	fdata->name = g_strdup (file_name_from_path (fdata->full_path));
	fdata->path = remove_level_from_path (fdata->full_path);

	if (*fdata->name == 0)
		file_data_free (fdata);
	else
		fr_command_add_file (comm, fdata);
}