int transcode(const char *path) { int ret; //if the file is a ts file ret = judge_file_suffix(path); //0, the file is not a ts file if (!ret) return 0; ret = if_file_exist(path); // -1 error; 0 not exist; 1 exist; if (ret == -1) return -1; else if (ret == 0) { TransTask task; ret = get_name_info(path, &task); //get the information from the file name. if (ret == -1) { servlog(ERROR, "can't get the info from file name:%s", path); return -1; } servlog(INFO, "task->file_name:%s", task.file_name); if(trans_file(&task, path)) servlog(INFO, "transcode the file success:%s", path); else { servlog(ERROR, "fail to transcode the file:%s", path); return -1; } } return 0; }
void EMFit::read_trans_file( const std::string file_name, std::vector<IMP::algebra::Transformation3D>& transforms) { std::ifstream trans_file(file_name.c_str()); if (!trans_file) { std::cerr << "Can't find Transformation file " << file_name << std::endl; exit(1); } IMP::algebra::Vector3D rotation_vec, translation; int trans_number; while (trans_file >> trans_number >> rotation_vec >> translation) { IMP::algebra::Rotation3D rotation = IMP::algebra::get_rotation_from_fixed_xyz( rotation_vec[0], rotation_vec[1], rotation_vec[2]); IMP::algebra::Transformation3D trans(rotation, translation); transforms.push_back(trans); } trans_file.close(); std::cout << transforms.size() << " transforms were read from " << file_name << std::endl; }
int main(){ int socket_fd; struct sockaddr_in dest; char buffer[B_SIZE]; socket_fd = socket(PF_INET, SOCK_STREAM, 0); bzero(&dest, sizeof(dest)); dest.sin_family = PF_INET; dest.sin_port = htons(8889); dest.sin_addr.s_addr = htonl(INADDR_ANY); bind(socket_fd, (struct sockaddr*)&dest, sizeof(dest)); listen(socket_fd, 20); FILE *fp; bzero(&buffer, B_SIZE); int client; struct sockaddr_in client_addr; socklen_t addlen; addlen = sizeof(client_addr); client = accept(socket_fd, (struct sockaddr*)&client_addr, &addlen); int check=0; char command='\0'; while(1){ bzero(&buffer, B_SIZE); /*always clear the buffer*/ recv(client, &command, sizeof(command), 0); switch(command){ case 'c': recv(client, &buffer, B_SIZE, 0); check = check_file(client, buffer); //only when file doesn't exist, server will create the file. if(check == -1){ fp = fopen(buffer, "w"); fclose(fp); break; } case 'e': edit_file(client); break; case 'r': /* Here is the remove function. */ recv(client, &buffer, B_SIZE, 0); check = check_file(client, buffer); if(check==1) remove(buffer); break; case 'l': list_file(client); break; case 'd': trans_file(client); break; case 'q': break; } if(command == 'q') break; } close(socket_fd); return 0; }
int trans_directory(const char* fn_dir, const char* fn_i, const char* backup_dir, const int rec_level, const char* fd_rec) { int i = 0, size, pad, result; unsigned char *si, *ei, *title, is_dir; unsigned char ID[80], name[50], date[9], title0[73 + 3] = { 0xa1,0xbb,' ' }; unsigned char file_path[300] = { "7\\A1234567" }, prop[12]; unsigned char *file = &(file_path[2]); FILE *fd_i; // directory fi char full_path[300] = { "" }, opt[300] = { "" }; fd_i = fopen(fn_i, "rb"); if (!fd_i) { printf("Loading directory file failed, %s\npath : \"%s\"\n", strerror(errno), fn_i); return -1; } fseek(fd_i, 0, SEEK_END); size = ftell(fd_i); // file size fseek(fd_i, 0, SEEK_SET); pad = (int)log10(size / 256) + 1; sprintf(opt, "mkdir \"%s\"", backup_dir); system(opt); while (++i) { fread(prop, sizeof(char), 12, fd_i); is_dir = (prop[6] == 0x01); if (fread(file, sizeof(char), 32, fd_i) <= 0) break; fread(ID, sizeof(char), 80, fd_i); si = strchr(ID, '.'); // [email protected] F if (si) *(si + 1) = '\0'; fread(name, sizeof(char), 50, fd_i); fseek(fd_i, 3, SEEK_CUR); // skip year fread(date, sizeof(char), 6, fd_i); fread(title0 + 3, sizeof(char), 73, fd_i); //++(square symbol) when ! Re if (!strncmp(title0 + 3, "Re: ", 4)) { // in order to edit "Re: " to "Re " title = title0 + 4; // e: ... title[0] = 'R'; title[1] = 'e'; } else { // not Re: adding square symbol if (is_dir) title0[1] = 0xbb; // ◆ else title0[1] = 0xba; title0[0] = 0xa1; title0[2] = ' '; title = title0; } if (file[0] == '@') file_path[0] = '@'; else file_path[0] = file[7]; sprintf(full_path, "%s%c\\%s", fn_dir, file_path[0], file); date[2] = '_'; // file name can't content '/' fix_file_name(title + 2); // replace other invalid char with space memset(file_path, '\0', sizeof(file_path)); // Here you can change the filename's formate of output file. if (strlen(date)) sprintf(file_path, "%s\\%0*d . %s . %s", backup_dir, pad, i, date, title); else sprintf(file_path, "%s\\%0*d . %s", backup_dir, pad, i, title); if (!is_dir) { sprintf(file_path, "%s.txt", file_path); result = trans_file(full_path, file_path); } else result = trans_directory(fn_dir, full_path, file_path, rec_level - 1, fd_rec); // only record at first time if (rec_level > 0) { fprintf(fd_rec, "%8s %6d %5s %-13s %-46s", full_path + strlen(full_path) - 10, i, date, ID, title); if (result) fprintf(fd_rec, "\t解析失敗!\n"); else fprintf(fd_rec, "\n"); } } fclose(fd_i); }