// Return an e-mail address for user PWD. static const char *email(struct passwd *pwd) { const char *s = 0; // Try Netscape and Lynx preferences // Netscape 4.0 if (!is_email(s)) s = email_from_preferences(pwd->pw_dir, ".netscape/preferences.js", "user_pref(\"mail.identity.useremail\","); // Netscape 3.0 if (!is_email(s)) s = email_from_preferences(pwd->pw_dir, ".netscape/preferences", "EMAIL_ADDRESS:"); // Netscape 2.0 and earlier if (!is_email(s)) s = email_from_preferences(pwd->pw_dir, ".netscape-preferences", "EMAIL_ADDRESS:"); // Lynx if (!is_email(s)) s = email_from_preferences(pwd->pw_dir, ".lynxrc", "personal_mail_address="); // Try .dot files used for e-mail and fingering if (!is_email(s)) s = email_from_signature(pwd->pw_dir, ".signature"); if (!is_email(s)) s = email_from_signature(pwd->pw_dir, ".Sig"); if (!is_email(s)) s = email_from_signature(pwd->pw_dir, ".project"); if (!is_email(s)) s = email_from_signature(pwd->pw_dir, ".plan"); // Try e-mail address from current host name if (!is_email(s)) s = email_from_pwd(pwd); // Tried it all, and failed :-( if (!is_email(s)) s = "unknown"; return s; }
int main(int argc,char** argv) { if(argc != 2){ printf("Use: ./lab11 <file.txt>\n"); } FILE* fp = fopen(argv[1],"r"); if(fp == NULL){ printf("Failed to open the selected file.\n"); return 0; } char buff[MAX_LINE+1]; while(fgets(buff,MAX_LINE,fp)){ if(buff[strlen(buff)-1] == '\n'){ buff[strlen(buff)-1] = '\0'; } char* token = strtok(buff," \n\r\t"); while(token != NULL){ if(is_phone_number(token)) { printf("\nPhone Number: %s",token); } else if(is_date(token)){ printf(" Date: %s",token); } else if(looks_like_name(token)){ char* nextName = strtok(NULL," \n\r\t"); if(looks_like_name(nextName)){ printf("Name:%s %s\n",nextName,token); } else token = nextName; } else if(is_email(token)){ printf("\nEmail: %s\n",token); } token = strtok(NULL," \n\r\t"); } } fclose(fp); return 0; }
bool DictInfo::save_ifo_file(void) const { if(ifo_file_name.empty()) { g_critical("Fail to save ifo file. ifo file name is not specified."); return false; } std::stringstream str; //str << UTF8_BOM; if(!is_infotype()) { g_critical("Fail to save ifo file. Dict info type is not specified."); return false; } const gchar *magic_data = NULL; if(infotype == DictInfoType_NormDict) magic_data = NORM_DICT_MAGIC_DATA; else if(infotype == DictInfoType_TreeDict) magic_data = TREE_DICT_MAGIC_DATA; else if(infotype == DictInfoType_ResDb) magic_data = RES_DB_MAGIC_DATA; else return false; str << magic_data << '\n'; if(!is_version()) { g_critical("Fail to save ifo file. version is not specified."); return false; } str << "version=" << version << '\n'; if(infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict) { if(!is_bookname()) { g_critical("Fail to save ifo file. bookname is not specified."); return false; } str << "bookname=" << bookname << '\n'; if(!is_wordcount()) { g_critical("Fail to save ifo file. wordcount is not specified."); return false; } str << "wordcount=" << wordcount << '\n'; } if(infotype == DictInfoType_NormDict) { if(is_synwordcount()) str << "synwordcount=" << synwordcount << '\n'; } if(infotype == DictInfoType_ResDb) { if(is_filecount()) str << "filecount=" << filecount << '\n'; } if(infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict || infotype == DictInfoType_ResDb) { if(!is_index_file_size()) { g_critical("Fail to save ifo file. index_file_size is not specified."); return false; } if(infotype == DictInfoType_NormDict) str << "idxfilesize=" << index_file_size << '\n'; if(infotype == DictInfoType_TreeDict) str << "tdxfilesize=" << index_file_size << '\n'; if(infotype == DictInfoType_ResDb) str << "ridxfilesize=" << index_file_size << '\n'; } if(infotype == DictInfoType_NormDict || infotype == DictInfoType_TreeDict) { if(is_author()) str << "author=" << author << '\n'; if(is_email()) str << "email=" << email << '\n'; if(is_website()) str << "website=" << website << '\n'; if(is_description()) { std::string temp; encode_description(description.c_str(), description.length(), temp); str << "description=" << temp << '\n'; } if(is_date()) str << "date=" << date << '\n'; if(is_sametypesequence()) str << "sametypesequence=" << sametypesequence << '\n'; } if(infotype == DictInfoType_NormDict) { if(is_dicttype()) str << "dicttype=" << dicttype << '\n'; } if(!g_file_set_contents(ifo_file_name.c_str(), str.str().c_str(), -1, NULL)) { g_critical("Fail to save ifo file." open_write_file_err, ifo_file_name.c_str()); return false; } return true; }