Example #1
0
/*
	Function: import_ical (bask_core* tcore, struct bask_task** first, char* filename);
	Description: Imports tasks from a ical formated file.
	InitVersion: 0.0.1
*/
short import_ical (bask_core* tcore, struct bask_task** first, char* filename)
{
	unsigned int tid;
	short tactive, tpriority, tstate;
	char line[200], today[T_S_DUE], tadded[T_S_ADDED], tdue[T_S_DUE], tfinished[T_S_FINISHED], tproject[T_S_PROJECT], tdescription[T_S_DESCRIPTION];
	char tt_tmp[50];
	char saveptr[200];
	FILE* importfile;
	
	tid = tpriority = tstate = 0;
	tactive = TRUE;
	
	strcpy (tt_tmp, " ");
	strcpy (tadded, " ");
	strcpy (tdue, " ");
	strcpy (tfinished, " ");
	strcpy (tproject, " ");
	strcpy (tdescription, " "); 

	time_get_str (today, sizeof (today));

	importfile = fopen (filename, "r");

	if (importfile == NULL)
	{
		errors_filenotopened (filename);
		return -1;
	}
	
	while (fgets (line, sizeof (line), importfile) != NULL)
	{
		
		if (parser_get_str (line, "END:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0)
		{
			if (utils_streq (tt_tmp, "VTODO") == 0)
			{
				if (tid == 0)
				{
					tcore->baskbin_uid++;
					tid = tcore->baskbin_uid;
				}
				
				/* TODO: Put that into a function! */
				if (BITGET (tcore->t_options, T_O_AUTODUETODAY) == TRUE &&
				    utils_streq (tdue, "NONE") != 0 &&
				   ( time_get_day (today) == time_get_day (tdue) &&
				      time_get_month (today) == time_get_month (tdue) &&
				      time_get_year (today) == time_get_year (tdue)))
				{
					tpriority = 2;
				}
				
				task_insert (first, tcore->tc_amount, tid, tactive, tpriority, tstate, tadded, tdue, tfinished, tproject, tdescription);
				
				tcore->tc_amount++;
				tid = tpriority= 0;
				
				/* If there is no clue to tactive we enable it by default. */
				tactive = TRUE;
				tstate = FALSE;
			}
		}
		else
		{
			parser_get_int (line, "UID:", &tid, ICALSEP, saveptr);
			
			/* Try multiple ways to find the data. */
			if (parser_get_str (line, "CREATED:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0)
			{
				import_ical_getdatestr (tadded, tt_tmp);
			}
			else if (parser_get_str (line, "DTSTART:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0)
			{
				import_ical_getdatestr (tadded, tt_tmp);
			}
			else if (parser_get_str (line, "COMPLETED:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0)
			{
				if (import_ical_getdatestr (tfinished, tt_tmp) == -1)
				{
					strcpy (tfinished, "NONE");
					tstate = FALSE;
				}
				else
				{
					tstate = TRUE;
				}
			}
			else if (parser_get_str (line, "DTEND:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0)
			{
				if (import_ical_getdatestr (tfinished, tt_tmp) == -1)
				{
					strcpy (tfinished, "NONE");
					tstate = FALSE;
				}
				else
				{
					tstate = TRUE;
				}
			}
			else if (parser_get_str (line, "DUE:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0)
			{
				if (import_ical_getdatestr (tdue, tt_tmp) == -1)
				{
					strcpy (tdue, "NONE");
				}
			}
			
			parser_get_short (line, "PRIORITY:", &tpriority, ICALSEP, saveptr);
			parser_get_str (line, "DESCRIPTION:", tdescription, sizeof (tdescription), ICALSEP, saveptr);
			parser_get_str (line, "SUMMARY:", tproject, sizeof (tproject), ICALSEP, saveptr);
			
			if (parser_get_str (line, "STATUS:", tt_tmp, sizeof (tt_tmp), ICALSEP, saveptr) == 0)
			{
				if (utils_streq (tt_tmp, "IN-PROCESS") == 0)
				{
					tactive = TRUE;
				}
				else if (utils_streq (tt_tmp, "NEEDS-ACTION") == 0)
				{
					tactive = FALSE;
				}
			}
		}
	}
	
	fclose (importfile);
	
	return 0;
}
Example #2
0
/*
	Function: import_baskbin (bask_core* tcore, struct bask_task** first, char* filename);
	Description: Imports the tasks from a baskbin formated file.
	InitVersion: 0.0.1
*/
short import_baskbin (bask_core* tcore, struct bask_task** first, char* filename)
{
	unsigned int tid;
	int tstate, bb_state;
	short tactive, tpriority;
	char line[200], today[T_S_DUE], tadded[T_S_ADDED], tdue[T_S_DUE], tfinished[T_S_FINISHED], tproject[T_S_PROJECT], tdescription[T_S_DESCRIPTION];
	char saveptr[200];
	FILE* importfile;

	bb_state = tid = tactive = tpriority = tstate = 0;
	
	strcpy (tadded, "NONE");
	strcpy (tdue, "NONE");
	strcpy (tfinished, "NONE");
	strcpy (tproject, " ");
	strcpy (tdescription, " ");
	
	time_get_str (today, sizeof (today));

	importfile = fopen (filename, "r");

	if (importfile == NULL)
	{
		errors_filenotopened (filename);
		return -1;
	}
	
	while (fgets (line, sizeof (line), importfile) != NULL)
	{		
		if (utils_streq (line, "BASKBIN\n") == 0)
		{
			bb_state = TRUE;
		}
		else if (utils_streq (line, "BBEND\n") == 0)
		{
			bb_state = FALSE;
		}
			
		if (bb_state == TRUE)
		{
			parser_get_int (line, "bbuid=", &tcore->baskbin_uid, BASKSEP, saveptr);
		}
		else if (utils_streq (line, "END\n") == 0)
		{
			/* TODO: Put that into a function! */
			if (BITGET (tcore->t_options, T_O_AUTODUETODAY) == TRUE &&
			    utils_streq (tdue, "NONE") != 0 &&
			    ( time_get_day (today) == time_get_day (tdue) &&
			      time_get_month (today) == time_get_month (tdue) &&
			      time_get_year (today) == time_get_year (tdue)))
			{
				tpriority = 2;
			}
			
			task_insert (first, tcore->tc_amount, tid, tactive, tpriority, tstate, tadded, tdue, tfinished, tproject, tdescription);
			tcore->tc_amount++;
		}
		else
		{
			parser_get_int (line, "tid=", &tid, BASKSEP, saveptr);
			parser_get_short (line, "tactive=", &tactive, BASKSEP, saveptr);
			parser_get_short (line, "tpriority=", &tpriority, BASKSEP, saveptr);
			parser_get_str (line, "tadded=", tadded, sizeof (tadded), BASKSEP, saveptr);
			parser_get_str (line, "tdue=", tdue, sizeof (tdue), BASKSEP, saveptr);
			
			if (parser_get_str (line, "tfinished=", tfinished, sizeof (tfinished), BASKSEP, saveptr) == 0)
			{
				/* Use this instead of tstate because this tells us already the state. */
				if (strlen (tfinished) == F_BB_S_DATE-1)
				{
					tstate = TRUE;
				}
				else
				{
					tstate = FALSE;
				}
			}
			
			parser_get_str (line, "tproject=", tproject, sizeof (tproject), BASKSEP, saveptr);
			parser_get_str (line, "tdescription=", tdescription, sizeof (tdescription), BASKSEP, saveptr);
		}
	}
	
	fclose (importfile);
	
	return 0;
}
Example #3
0
/*
	Function: import_csv_parser (bask_core* tcore, struct bask_task** first, char* token, char* today, char* saveptr);
	Description: Parses a task data line from a csv formated file. 
	InitVersion: 0.0.1
*/
void import_csv_parser (bask_core* tcore, struct bask_task** first, char* token, char* today, char* saveptr)
{
	unsigned int tid;
	int tstate;
	short tactive, tpriority;
	char tadded[T_S_ADDED], tdue[T_S_DUE], tfinished[T_S_FINISHED], tproject[T_S_PROJECT], tdescription[T_S_DESCRIPTION];
	char tmp[200];
	
	tid = tactive = tpriority = tstate = 0;
	
	tid = atoi (token);
	
	token = strtok_r (NULL, ";", &saveptr);
	
	utils_atos (&tactive, token);
	
	token = strtok_r (NULL, ";", &saveptr);
	
	utils_atos (&tpriority, token);
	
	token = strtok_r (NULL, ";", &saveptr);
	
	/* Subtracting 2 byte for the " chars. */
	if (strlen (token)-2 < T_S_ADDED)
	{
		strcpy (tmp, token); 
		
		if (tmp[0] == '"')
		{
			strcpy (tadded, &tmp[1]);
		}
		else
		{
			strcpy (tadded, tmp);
		}
		
		if (tadded[strlen (tadded)-1] == '"')
		{
			tadded[strlen (tadded)-1] = '\0';
		}
	}
	else
	{
		strcpy (tadded, "NONE");
	}
	
	token = strtok_r (NULL, ";", &saveptr);
	
	/* Subtracting 2 byte for the " chars. */
	if (strlen (token)-2 < T_S_DUE)
	{
		strcpy (tmp, token); 
		
		if (tmp[0] == '"')
		{
			strcpy (tdue, &tmp[1]);
		}
		else
		{
			strcpy (tdue, tmp);
		}
		
		if (tdue[strlen (tdue)-1] == '"')
		{
			tdue[strlen (tdue)-1] = '\0';
		}
	}
	else
	{
		strcpy (tdue, "NONE");
	}
	
	token = strtok_r (NULL, ";", &saveptr);
	
	/* Subtracting 2 byte for the " chars. */
	if (strlen (token)-2 < T_S_FINISHED)
	{
		strcpy (tmp, token); 
		
		if (tmp[0] == '"')
		{
			strcpy (tfinished, &tmp[1]);
		}
		else
		{
			strcpy (tfinished, tmp);
		}
		
		if (tfinished[strlen (tfinished)-1] == '"')
		{
			tfinished[strlen (tfinished)-1] = '\0';
		}
		
		/* If the string isnt set to NONE its finished. */
		if (strlen (tfinished) > 4)
		{
			tstate = TRUE;
		}
	}
	else
	{
		strcpy (tfinished, "NONE");
	}
	
	token = strtok_r (NULL, ";", &saveptr);
	
	/* Subtracting 2 byte for the " chars. */
	if (strlen (token)-2 < T_S_PROJECT)
	{
		strcpy (tmp, token); 
		
		if (tmp[0] == '"')
		{
			strcpy (tproject, &tmp[1]);
		}
		else
		{
			strcpy (tproject, tmp);
		}
		
		if (tproject[strlen (tproject)-1] == '"')
		{
			tproject[strlen (tproject)-1] = '\0';
		}
	}
	else
	{
		strcpy (tproject, " ");
	}
	
	token = strtok_r (NULL, ";\n", &saveptr);
	
	/* Subtracting 2 byte for the " chars. */
	if (strlen (token)-2 < T_S_DESCRIPTION)
	{
		strcpy (tmp, token); 
		
		if (tmp[0] == '"')
		{
			strcpy (tdescription, &tmp[1]);
		}
		else
		{
			strcpy (tdescription, tmp);
		}
		
		if (tdescription[strlen (tdescription)-1] == '"')
		{
			tdescription[strlen (tdescription)-1] = '\0';
		}
	}
	else
	{
		strcpy (tdescription, " ");
	}
	
	/* TODO: Put that into a function! */
	if (BITGET (tcore->t_options, T_O_AUTODUETODAY) == TRUE &&
	    utils_streq (tdue, "NONE") != 0 &&
	    ( time_get_day (today) == time_get_day (tdue) &&
	      time_get_month (today) == time_get_month (tdue) &&
	      time_get_year (today) == time_get_year (tdue)))
	{
		tpriority = 2;
	}
	
	tcore->baskbin_uid++;
	task_insert (first, tcore->tc_amount, tid, tactive, tpriority, tstate, tadded, tdue, tfinished, tproject, tdescription);
	tcore->tc_amount++;
}
Example #4
0
int fpattern_isvalid(const char *pat)
{
    static const char specialchars[] = { FPAT_QUOTE, FPAT_SET_THRU, FPAT_SET_L,
                                         FPAT_SET_R, FPAT_MSET_L, FPAT_MSET_R,
                                         FPAT_ANY, FPAT_NOT, FPAT_CLOS, FPAT_CLOSP,
                                         '\0' };
    int     len, open;
    char    close, pch, pch2;
    unsigned char mask[256/sizeof(unsigned char)];

    /* Check args */
    if (pat == NULL)
        return (FPAT_INVALID);

    open = FALSE;   /* pattern is not open-ended */

    /* Verify that the pattern is valid */
    for (len = 0;  pat[len] != '\0';  len++)
    {
        switch (pat[len])
        {
        case FPAT_SET_L:
#if defined FPAT_MSET_ENABLED
        case FPAT_MSET_L:
#endif
            /* Char set */
            if (pat[len] == FPAT_SET_L)
            {
                open = FALSE;
                close = FPAT_SET_R;
            }
            else
            {
                open = TRUE;
                close = FPAT_MSET_R;
            }
            len++;
            if (pat[len] == FPAT_NOT)
                len++;          /* Set negation */

            memset(mask,0,sizeof mask);
            while (pat[len] != close)
            {
                pch = pat[len];
                if (pat[len] == FPAT_QUOTE) {
                    len++;      /* Quoted char */
                    pch = pat[len];
                    if (ishexdigit(pch)) {
                        len++;  /* Hex digits should come in pairs */
                        if (!ishexdigit(pat[len]))
                            return (FPAT_INVALID);
                        pch2 = pat[len];
                        pch = (hexdigit(pch) << 4) | hexdigit(pch2);
                    } else if (strchr(specialchars,pat[len])==NULL) {
                        return (FPAT_INVALID); /* escaped char should be special char */
                    } /* if */
                } /* if */
                if (pat[len] == '\0')
                    return (FPAT_INVALID); /* Missing closing bracket */
                if (BITGET(mask,pch))
                    return (FPAT_INVALID);
                BITSET(mask,pch);
                len++;

                if (pat[len] == FPAT_SET_THRU && (pat[len+1] != FPAT_SET_THRU || pch == FPAT_SET_THRU))
                {
                    /* Char range */
                    len++;
                    if (pat[len] == FPAT_QUOTE) {
                        len++;      /* Quoted char */
                        if (ishexdigit(pat[len])) {
                            len++;  /* Hex digits should come in pairs */
                            if (!ishexdigit(pat[len]))
                                return (FPAT_INVALID);
                        } else if (strchr(specialchars,pat[len])==NULL) {
                            return (FPAT_INVALID); /* escaped char should be special char */
                        } /* if */
                    } /* if */

                    if (pat[len] == '\0')
                        return (FPAT_INVALID); /* Missing closing bracket */
                    if (len<2 || (unsigned char)pat[len-2]>(unsigned char)pat[len]
                        || (pat[len-2]==pat[len] && pat[len]!=FPAT_SET_THRU))
                        return (FPAT_INVALID);  /* invalid range (decrementing) */
                    //??? also set bits of characters in range?
                    len++;
                }

                if (pat[len] == '\0')
                    return (FPAT_INVALID); /* Missing closing bracket */
            }
            break;

        case FPAT_QUOTE:
            /* Quoted char */
            len++;
            open = FALSE;
            if (ishexdigit(pat[len])) {
                len++;                    /* Hex digits should come in pairs */
                if (!ishexdigit(pat[len]))
                    return (FPAT_INVALID);
            } else if (strchr(specialchars,pat[len])==NULL) {
                return (FPAT_INVALID);    /* escaped char should be special char */
            } /* if */
            if (pat[len] == '\0')
                return (FPAT_INVALID);    /* Missing quoted char */
            break;

#if defined FPAT_NOT_ENABLED
        case FPAT_NOT:
            /* Negated pattern */
            len++;
            open = FALSE;
            if (pat[len] == '\0')
                return (FPAT_INVALID);     /* Missing subpattern */
            break;
#endif

        case FPAT_CLOS:
            open = TRUE;
            break;

        default:
            /* Valid character */
            open = FALSE;
            break;
        }
    }

    return (open ? FPAT_OPEN : FPAT_CLOSED);
}
 static inline DR7 ptr_dr7(ptr dr7)
 {
     DR7 result;
     memset(&result, 0, sizeof(DR7));
     if (BITGET(dr7, 0))
         BITSET(result.DR7_MODE[0], 0);
     if (BITGET(dr7, 1))
         BITSET(result.DR7_MODE[0], 1);
     if (BITGET(dr7, 2))
         BITSET(result.DR7_MODE[1], 0);
     if (BITGET(dr7, 3))
         BITSET(result.DR7_MODE[1], 1);
     if (BITGET(dr7, 4))
         BITSET(result.DR7_MODE[2], 0);
     if (BITGET(dr7, 5))
         BITSET(result.DR7_MODE[2], 1);
     if (BITGET(dr7, 6))
         BITSET(result.DR7_MODE[3], 0);
     if (BITGET(dr7, 7))
         BITSET(result.DR7_MODE[3], 1);
     if (BITGET(dr7, 16))
         BITSET(result.DR7_TYPE[0], 0);
     if (BITGET(dr7, 17))
         BITSET(result.DR7_TYPE[0], 1);
     if (BITGET(dr7, 18))
         BITSET(result.DR7_SIZE[0], 0);
     if (BITGET(dr7, 19))
         BITSET(result.DR7_SIZE[0], 1);
     if (BITGET(dr7, 20))
         BITSET(result.DR7_TYPE[1], 0);
     if (BITGET(dr7, 21))
         BITSET(result.DR7_TYPE[1], 1);
     if (BITGET(dr7, 22))
         BITSET(result.DR7_SIZE[1], 0);
     if (BITGET(dr7, 23))
         BITSET(result.DR7_SIZE[1], 1);
     if (BITGET(dr7, 24))
         BITSET(result.DR7_TYPE[2], 0);
     if (BITGET(dr7, 25))
         BITSET(result.DR7_TYPE[2], 1);
     if (BITGET(dr7, 26))
         BITSET(result.DR7_SIZE[2], 0);
     if (BITGET(dr7, 27))
         BITSET(result.DR7_SIZE[2], 1);
     if (BITGET(dr7, 28))
         BITSET(result.DR7_TYPE[3], 0);
     if (BITGET(dr7, 29))
         BITSET(result.DR7_TYPE[3], 1);
     if (BITGET(dr7, 30))
         BITSET(result.DR7_SIZE[3], 0);
     if (BITGET(dr7, 31))
         BITSET(result.DR7_SIZE[3], 1);
     return result;
 }
 static inline ptr dr7_ptr(const DR7 & dr7)
 {
     ptr result = 0;
     if (BITGET(dr7.DR7_MODE[0], 0))
         BITSET(result, 0);
     if (BITGET(dr7.DR7_MODE[0], 1))
         BITSET(result, 1);
     if (BITGET(dr7.DR7_MODE[1], 0))
         BITSET(result, 2);
     if (BITGET(dr7.DR7_MODE[1], 1))
         BITSET(result, 3);
     if (BITGET(dr7.DR7_MODE[2], 0))
         BITSET(result, 4);
     if (BITGET(dr7.DR7_MODE[2], 1))
         BITSET(result, 5);
     if (BITGET(dr7.DR7_MODE[3], 0))
         BITSET(result, 6);
     if (BITGET(dr7.DR7_MODE[3], 1))
         BITSET(result, 7);
     if (BITGET(dr7.DR7_TYPE[0], 0))
         BITSET(result, 16);
     if (BITGET(dr7.DR7_TYPE[0], 1))
         BITSET(result, 17);
     if (BITGET(dr7.DR7_SIZE[0], 0))
         BITSET(result, 18);
     if (BITGET(dr7.DR7_SIZE[0], 1))
         BITSET(result, 19);
     if (BITGET(dr7.DR7_TYPE[1], 0))
         BITSET(result, 20);
     if (BITGET(dr7.DR7_TYPE[1], 1))
         BITSET(result, 21);
     if (BITGET(dr7.DR7_SIZE[1], 0))
         BITSET(result, 22);
     if (BITGET(dr7.DR7_SIZE[1], 1))
         BITSET(result, 23);
     if (BITGET(dr7.DR7_TYPE[2], 0))
         BITSET(result, 24);
     if (BITGET(dr7.DR7_TYPE[2], 1))
         BITSET(result, 25);
     if (BITGET(dr7.DR7_SIZE[2], 0))
         BITSET(result, 26);
     if (BITGET(dr7.DR7_SIZE[2], 1))
         BITSET(result, 27);
     if (BITGET(dr7.DR7_TYPE[3], 0))
         BITSET(result, 28);
     if (BITGET(dr7.DR7_TYPE[3], 1))
         BITSET(result, 29);
     if (BITGET(dr7.DR7_SIZE[3], 0))
         BITSET(result, 30);
     if (BITGET(dr7.DR7_SIZE[3], 1))
         BITSET(result, 31);
     return result;
 }