Ejemplo n.º 1
0
Archivo: ut.c Proyecto: ralienpp/deco
char *timestr (long tim)
{
    struct tm *t = localtime (&tim);
    register char *p = pattern;

    STOREINT (p, t->tm_mday);
    if (*p == '0')
        *p = ' ';


    strncpy (p+3, "JanFebMarAprMayJunJulAugSepOctNovDec"+t->tm_mon*3, 3);
    STOREINT (p+9, t->tm_year);
    if (t->tm_year < 100) {
        p[7] = '1';
        p[8] = '9';
    } else {
        p[7] = '2';
        p[8] = '0';
    }
    STOREINT (p+12, t->tm_hour);
    STOREINT (p+15, t->tm_min);
    STOREINT (p+18, t->tm_sec);
    return (p);
}
Ejemplo n.º 2
0
/* We assume gn_phonebook_entry is ready for writing in, ie. no rubbish inside */
GNOKII_API int gn_ldif2phonebook(FILE *f, gn_phonebook_entry *entry)
{
	char buf[10240];
	int i;

	while (1) {
		if (!fgets(buf, 1024, f))
			return -1;
		if (BEGINS("dn:"))
			break;
	}

	while (1) {
		if (!fgets(buf, 1024, f)) {
			ERROR("LDIF began but not ended?");
			return -1;
		}
		STORE("cn: ", entry->name);
		STORE_BASE64("cn:: ", entry->name);

		STORESUB("homeurl: ", GN_PHONEBOOK_ENTRY_URL);
		STORESUB_BASE64("homeurl:: ", GN_PHONEBOOK_ENTRY_URL);
		STORESUB("mail: ", GN_PHONEBOOK_ENTRY_Email);
		STORESUB_BASE64("mail:: ", GN_PHONEBOOK_ENTRY_Email);
		STORESUB("homePostalAddress: ", GN_PHONEBOOK_ENTRY_Postal);
		STORESUB_BASE64("homePostalAddress:: ", GN_PHONEBOOK_ENTRY_Postal);
		STORESUB("Description: ", GN_PHONEBOOK_ENTRY_Note);
		STORESUB_BASE64("Description:: ", GN_PHONEBOOK_ENTRY_Note);

		STORENUM("homePhone: ", GN_PHONEBOOK_NUMBER_Home);
		STORENUM_BASE64("homePhone:: ", GN_PHONEBOOK_NUMBER_Home);
		STORENUM("mobile: ", GN_PHONEBOOK_NUMBER_Mobile);
		STORENUM_BASE64("mobile:: ", GN_PHONEBOOK_NUMBER_Mobile);
		STORENUM("cellphone: ", GN_PHONEBOOK_NUMBER_Mobile);
		STORENUM_BASE64("cellphone:: ", GN_PHONEBOOK_NUMBER_Mobile);
		STORENUM("fax: ", GN_PHONEBOOK_NUMBER_Fax);
		STORENUM_BASE64("fax:: ", GN_PHONEBOOK_NUMBER_Fax);
		STORENUM("workPhone: ", GN_PHONEBOOK_NUMBER_Work);
		STORENUM_BASE64("workPhone:: ", GN_PHONEBOOK_NUMBER_Work);
		STORENUM("telephoneNumber: ", GN_PHONEBOOK_NUMBER_General);
		STORENUM_BASE64("telephoneNumber:: ", GN_PHONEBOOK_NUMBER_General);
		
		STOREINT("businessCategory: ", entry->caller_group);

		if (BEGINS("\n"))
			break;
	}
	/* set entry->number from the first sub-entry that is a number */
	for (i = 0; i < entry->subentries_count && entry->number[0] == 0; i++) {
		if (entry->subentries[i].entry_type == GN_PHONEBOOK_ENTRY_Number) {
			switch (entry->subentries[i].number_type) {
			case GN_PHONEBOOK_NUMBER_None:
			case GN_PHONEBOOK_NUMBER_Common:
			case GN_PHONEBOOK_NUMBER_General:
			case GN_PHONEBOOK_NUMBER_Work: 
			case GN_PHONEBOOK_NUMBER_Home:
			case GN_PHONEBOOK_NUMBER_Mobile:
				dprintf("setting default number to %s\n", entry->subentries[i].data.number);
				snprintf(entry->number, sizeof(entry->number), "%s", entry->subentries[i].data.number);
				break;
			default:
				dprintf("unknown type\n");
				break;
			}
		}
	}
	return 0;
}