int main() { int comd; const char *origin = "http://jxuao.me/upload?user=group2&filename=data.zip"; strcpy(urls,origin); code = "510002"; int tag = 0; flag = 0; //创建文件夹 folder_create("/tmp/group2"); folder_create("/tmp/group2/data"); folder_create("/tmp/group2/data/hotspot"); folder_create("/tmp/group2/data/station"); folder_create("/tmp/group2/zip"); remove_dir("/tmp/group2/data/hotspot"); remove_dir("/tmp/group2/data/station"); remove_dir("/tmp/group2/zip"); printf("Please input a number:\n"); printf("1.run!\n"); printf("2.set upload interval!\n"); printf("3.set upload information!\n"); while(scanf("%d",&comd) == 1){ switch(comd){ case 1: if (!thread_create()) { printf("error\n"); } else { tag = 1; } break; case 2: scanf("%d",&interval); printf("upload interval:%d\n",interval); printf("Please input a number:\n"); printf("1.run!\n"); printf("2.set upload interval!\n"); printf("3.set upload information!\n"); break; case 3: seturls(); printf("Please input a number:\n"); printf("1.run!\n"); printf("2.set upload interval!\n"); printf("3.set upload information!\n"); break; default: printf("Input valid command!\n"); break; } // 运行后当所有线程结束,整个进程结束 while(tag) { if (pthread_kill(thd1,0)!=0 && pthread_kill(thd2,0)!=0 && pthread_kill(thd3,0)!=0) { return 0; } } } return 0; }
/** * Saves the database into its own folder. * Still working on this!!!! */ bool Database::save_table(std::string name) { folder_create(); if(db_error.code_number == Errors::error_path_not_found) { return false; } if(!containers.empty()) { std::ofstream file; serialization::ObjectStream temp_stream; for(int i = 0; i < containers.size(); ++i) { Container* container = &containers.at(i); file.open(directory_path + "/" + container->get_container_name() + ".txt" , std::fstream::in | std::fstream::out | std::fstream::trunc); if(file.is_open()) { container->serialize(temp_stream); temp_stream.write_to_file(file); file.close(); } } } update_last_error(); return true; }
static void nntp_connect (SOURCE *s) { FOLDER *f1 = folder_create (NULL); FOLDER *f2 = folder_create (NULL); FOLDER *f3 = folder_create (NULL); if (!f1 || !f2 || !f3) { printf ("nntp_connect: folder_create failed\n"); return NULL; } f1->container.object.name = strdup ("alt.swedish.chef"); f2->container.object.name = strdup ("rec.arts.poems"); f3->container.object.name = strdup ("sci.fractals"); EMAIL *e1 = email_create (NULL); EMAIL *e2 = email_create (NULL); EMAIL *e3 = email_create (NULL); EMAIL *e4 = email_create (NULL); EMAIL *e5 = email_create (NULL); EMAIL *e6 = email_create (NULL); EMAIL *e7 = email_create (NULL); if (!e1 || !e2 || !e3 || !e4 || !e5 || !e6 || !e7) { printf ("nntp_connect: email_create failed\n"); return NULL; } e1->item.object.name = strdup ("bork"); e2->item.object.name = strdup ("bork"); e3->item.object.name = strdup ("bork"); e4->item.object.name = strdup ("daffodils"); e5->item.object.name = strdup ("elegy"); e6->item.object.name = strdup ("mandelbrot"); e7->item.object.name = strdup ("siepinski"); add_child (f1, e1); add_child (f1, e2); add_child (f1, e3); add_child (f2, e4); add_child (f2, e5); add_child (f3, e6); add_child (f3, e7); release (e1); release (e2); release (e3); release (e4); release (e5); release (e6); release (e7); add_child (s, f1); add_child (s, f2); add_child (s, f3); release (f1); release (f2); release (f3); }