int main(){ struct node *head=NULL,*temp; int i,j,n; char c='y'; do{ scanf("%d",&n); if(!head){ head=createnode(n); temp=head; } else{ while(temp->next){ temp=temp->next; } temp->next=createnode(n); } printf("Press y to continue: "); fflush(stdin); scanf("%c",&c); }while(c=='y'|| c=='Y'); printll(head); mergesort(&head); printf("Sorted "); printll(head); return 0; }
/** * Flushes the cache to disk * Returns 1 on success, 0 on failure */ int flush_disk_cache(struct group_list_t *group) { f_offset_t offset, seek_rval; int wrote_len; uint32_t i; if (group->fileinfo.cache_len == 0) return 1; offset = (f_offset_t) group->fileinfo.cache_start * group->blocksize; if ((seek_rval = lseek_func(group->fileinfo.fd, offset - group->fileinfo.curr_offset, SEEK_CUR)) == -1) { gsyserror(group, "lseek failed for file"); } if (seek_rval != offset) { glog2(group, "offset is %s", printll(seek_rval)); glog2(group, " should be %s", printll(offset)); if ((seek_rval = lseek_func(group->fileinfo.fd, offset, SEEK_SET)) == -1) { gsyserror(group, "lseek failed for file"); return 0; } } if ((wrote_len = write(group->fileinfo.fd, group->fileinfo.cache, group->fileinfo.cache_len)) == -1) { gsyserror(group, "Write failed for blocks %d - %d", group->fileinfo.cache_start, group->fileinfo.cache_end); return 0; } else { group->fileinfo.curr_offset = offset + wrote_len; if (wrote_len != group->fileinfo.cache_len) { glog0(group, "Write failed for blocks %d - %d, only wrote %d bytes", group->fileinfo.cache_start, group->fileinfo.cache_end); return 0; } else { glog4(group, "Wrote blocks %d - %d to disk from cache", group->fileinfo.cache_start, group->fileinfo.cache_end); for (i = group->fileinfo.cache_start; i <= group->fileinfo.cache_end; i++) { int status_idx = i - group->fileinfo.cache_start; if (group->fileinfo.cache_status[status_idx]) { group->fileinfo.naklist[i] = 0; } } group->fileinfo.cache_start = group->fileinfo.cache_end + 1; while ((group->fileinfo.cache_start < group->fileinfo.blocks) && (!group->fileinfo.naklist[group->fileinfo.cache_start])) { group->fileinfo.cache_start++; } group->fileinfo.cache_end = group->fileinfo.cache_start; group->fileinfo.cache_len = 0; memset(group->fileinfo.cache, 0, cache_len); memset(group->fileinfo.cache_status,0,cache_len / group->blocksize); return 1; } } }
/** * Writes file result data to status file */ void print_result_status(struct group_list_t *group) { struct tm *done_time; time_t t; if (!status_file) return; t = time(NULL); done_time = localtime(&t); fprintf(status_file, "RESULT;%04d/%02d/%02d-%02d:%02d:%02d;%08X;%08X;%s;%sKB", done_time->tm_year + 1900, done_time->tm_mon + 1, done_time->tm_mday, done_time->tm_hour, done_time->tm_min, done_time->tm_sec, ntohl(group->src_id), group->group_id, group->fileinfo.name, printll(group->fileinfo.size / 1024)); switch (group->fileinfo.comp_status) { case COMP_STAT_NORMAL: fprintf(status_file, ";copied\n"); break; case COMP_STAT_SKIPPED: fprintf(status_file, ";skipped\n"); break; case COMP_STAT_OVERWRITE: fprintf(status_file, ";overwritten\n"); break; case COMP_STAT_REJECTED: fprintf(status_file, ";rejected\n"); break; default: fprintf(status_file, ";unknown\n"); break; } fflush(status_file); }
/** * Seeks to a particular block in a file * Returns 1 on success, 0 on error */ int seek_block(int file, int block, f_offset_t *offset, f_offset_t curr_offset) { if ((*offset = lseek_func(file, ((f_offset_t)block * blocksize) - curr_offset, SEEK_CUR)) == -1) { syserror(0, 0, "lseek failed for file"); return 0; } if (*offset != (f_offset_t)block * blocksize) { log0(0, 0, "block %d: offset is %s", block, printll(*offset)); log0(0, 0, " should be %s", printll((f_offset_t)block * blocksize)); if ((*offset = lseek_func(file, ((f_offset_t)block * blocksize) - (*offset), SEEK_CUR)) == -1) { syserror(0, 0, "lseek failed for file"); return 0; } } return 1; }
int main() { struct node *head; int data; int t; int n; int i; /* Enter number of test cases */ scanf("%d", &t); while(t--) { /* Read number of nodes in the list */ scanf("%d", &n); for(i = 0; i < n; i++) { scanf("%d", &data); insertAtTail(&head, data); } printll(head); printf("\n"); } }
void Snippet(char* x0) { printf("%s\n","Phrase,Year,MatchCount,VolumeCount"); int32_t x5 = 0; int32_t x2 = open(x0,0); int32_t x3 = fsize(x2); char* x4 = mmap(0, x3, PROT_READ, MAP_FILE | MAP_SHARED, x2, 0); for (;;) { int32_t x6 = x5; bool x7 = x6 < x3; if (!x7) break; int32_t x9 = x5; for (;;) { int32_t x10 = x5; char x11 = x4[x10]; bool x12 = x11 != '\t'; if (!x12) break; x5 += 1; } int32_t x17 = x5; x5 += 1; int32_t x21 = x5; for (;;) { int32_t x22 = x5; char x23 = x4[x22]; bool x24 = x23 != '\t'; if (!x24) break; x5 += 1; } int32_t x29 = x5; x5 += 1; int32_t x33 = x5; for (;;) { int32_t x34 = x5; char x35 = x4[x34]; bool x36 = x35 != '\t'; if (!x36) break; x5 += 1; } int32_t x41 = x5; x5 += 1; int32_t x45 = x5; for (;;) { int32_t x46 = x5; char x47 = x4[x46]; bool x48 = x47 != '\n'; if (!x48) break; x5 += 1; } int32_t x53 = x5; x5 += 1; char* x20 = x4+x9; int32_t x57 = printll(x20); printf(","); char* x32 = x4+x21; int32_t x59 = printll(x32); printf(","); char* x44 = x4+x33; int32_t x61 = printll(x44); printf(","); char* x56 = x4+x45; int32_t x63 = printll(x56); printf("%s\n",""); } }
void Snippet(char* x0) { printf("%s\n","Phrase,Year,MatchCount,VolumeCount"); int32_t x5 = 0; int32_t x2 = open(x0,0); int32_t x3 = fsize(x2); char* x4 = mmap(0, x3, PROT_READ, MAP_FILE | MAP_SHARED, x2, 0); for (;;) { int32_t x6 = x5; bool x7 = x6 < x3; if (!x7) break; int32_t x9 = x5; for (;;) { int32_t x10 = x5; char x11 = x4[x10]; bool x12 = x11 != '\t'; if (!x12) break; x5 += 1; } int32_t x17 = x5; x5 += 1; int32_t x21 = x5; for (;;) { int32_t x22 = x5; char x23 = x4[x22]; bool x24 = x23 != '\t'; if (!x24) break; x5 += 1; } int32_t x29 = x5; x5 += 1; int32_t x33 = x5; for (;;) { int32_t x34 = x5; char x35 = x4[x34]; bool x36 = x35 != '\t'; if (!x36) break; x5 += 1; } int32_t x41 = x5; x5 += 1; int32_t x45 = x5; for (;;) { int32_t x46 = x5; char x47 = x4[x46]; bool x48 = x47 != '\n'; if (!x48) break; x5 += 1; } int32_t x53 = x5; x5 += 1; int32_t x18 = x17 - x9; bool x58 = x18 == 12; bool x73; if (x58) { int32_t x59 = 0; char* x20 = x4+x9; for (;;) { int32_t x60 = x59; bool x61 = x60 < x18; char x62 = x20[x60]; char x63 = "Auswanderung"[x60]; bool x64 = x62 == x63; bool x65 = x61 && x64; if (!x65) break; x59 += 1; } int32_t x70 = x59; bool x71 = x70 == x18; x73 = x71; } else { x73 = false; } if (x73) { char* x20 = x4+x9; int32_t x74 = printll(x20); printf(","); char* x32 = x4+x21; int32_t x76 = printll(x32); printf(","); char* x44 = x4+x33; int32_t x78 = printll(x44); printf(","); char* x56 = x4+x45; int32_t x80 = printll(x56); printf("%s\n",""); } else { } } }
void Snippet(char* x0) { printf("%s\n","Name,Value,Flag,Name"); char** x2 = (char**)malloc(256 * sizeof(char*)); int32_t* x3 = (int32_t*)malloc(256 * sizeof(int32_t)); int32_t x4 = 0; int32_t x5 = 0; int32_t* x6 = (int32_t*)malloc(256 * sizeof(int32_t)); for(int x8=0; x8 < 256; x8++) { x6[x8] = -1; } char** x12 = (char**)malloc(65536 * sizeof(char*)); int32_t* x13 = (int32_t*)malloc(65536 * sizeof(int32_t)); int32_t* x14 = (int32_t*)malloc(65536 * sizeof(int32_t)); char** x15 = (char**)malloc(65536 * sizeof(char*)); int32_t* x16 = (int32_t*)malloc(65536 * sizeof(int32_t)); int32_t x17 = 0; int32_t x18 = 0; int32_t* x19 = (int32_t*)malloc(65536 * sizeof(int32_t)); int32_t* x20 = (int32_t*)malloc(256 * sizeof(int32_t)); int32_t x24 = 0; int32_t x21 = open("src/data/t.csv",0); int32_t x22 = fsize(x21); char* x23 = mmap(0, x22, PROT_READ, MAP_FILE | MAP_SHARED, x21, 0); for (;;) { int32_t x25 = x24; char x26 = x23[x25]; bool x27 = x26 != ','; if (!x27) break; x24 += 1; } int32_t x32 = x24; x24 += 1; int32_t x35 = x24; int32_t x36 = 0; for (;;) { int32_t x37 = x24; char x38 = x23[x37]; bool x39 = x38 != ','; if (!x39) break; int32_t x41 = x36; int32_t x43 = x24; int32_t x42 = x41 * 10; char x44 = x23[x43]; char x45 = x44 - '0'; int32_t x46 = x42 + x45; x36 = x46; x24 += 1; } x24 += 1; int32_t x52 = x36; int32_t x53 = x24; for (;;) { int32_t x54 = x24; char x55 = x23[x54]; bool x56 = x55 != '\n'; if (!x56) break; x24 += 1; } int32_t x61 = x24; x24 += 1; for (;;) { int32_t x65 = x24; bool x66 = x65 < x22; if (!x66) break; int32_t x68 = x24; for (;;) { int32_t x69 = x24; char x70 = x23[x69]; bool x71 = x70 != ','; if (!x71) break; x24 += 1; } int32_t x76 = x24; x24 += 1; int32_t x80 = x24; int32_t x81 = 0; for (;;) { int32_t x82 = x24; char x83 = x23[x82]; bool x84 = x83 != ','; if (!x84) break; int32_t x86 = x81; int32_t x88 = x24; int32_t x87 = x86 * 10; char x89 = x23[x88]; char x90 = x89 - '0'; int32_t x91 = x87 + x90; x81 = x91; x24 += 1; } x24 += 1; int32_t x97 = x81; int32_t x98 = x24; for (;;) { int32_t x99 = x24; char x100 = x23[x99]; bool x101 = x100 != '\n'; if (!x101) break; x24 += 1; } int32_t x106 = x24; x24 += 1; int32_t x110 = x18; char* x79 = x23+x68; x12[x110] = x79; int32_t x77 = x76 - x68; x13[x110] = x77; x14[x110] = x97; char* x109 = x23+x98; x15[x110] = x109; int32_t x107 = x106 - x98; x16[x110] = x107; x18 += 1; int64_t x117 = hash(x79,x77); int32_t x118 = (int32_t)x117; int32_t x119 = x118 & 255; //#hash_lookup // generated code for hash lookup int32_t x120 = x119; for (;;) { int32_t x121 = x120; int32_t x122 = x6[x121]; bool x124 = x122 == -1; bool x146; if (x124) { x146 = false; } else { char* x125 = x2[x122]; int32_t x126 = x3[x122]; bool x128 = x126 == x77; bool x143; if (x128) { int32_t x129 = 0; for (;;) { int32_t x130 = x129; bool x131 = x130 < x126; bool x135; if (x131) { char x132 = x125[x130]; char x133 = x79[x130]; bool x134 = x132 == x133; x135 = x134; } else { x135 = false; } if (!x135) break; x129 += 1; } int32_t x140 = x129; bool x141 = x140 == x126; x143 = x141; } else { x143 = false; } bool x144 = !x143; x146 = x144; } if (!x146) break; int32_t x148 = x120; int32_t x149 = x148 + 1; int32_t x150 = x149 & 255; x120 = x150; } int32_t x154 = x120; int32_t x155 = x6[x154]; bool x156 = x155 == -1; int32_t x164; if (x156) { int32_t x157 = x5; x2[x157] = x79; x3[x157] = x77; x5 += 1; x6[x154] = x157; x20[x157] = 0; x164 = x157; } else { x164 = x155; } int32_t x166 = x164; //#hash_lookup int32_t x167 = x20[x166]; int32_t x168 = x166 * 256; int32_t x169 = x168 + x167; x19[x169] = x110; int32_t x171 = x167 + 1; x20[x166] = x171; } close(x21); int32_t x176 = 0; for (;;) { int32_t x177 = x176; char x178 = x23[x177]; bool x179 = x178 != ','; if (!x179) break; x176 += 1; } int32_t x184 = x176; x176 += 1; int32_t x186 = x176; int32_t x187 = 0; for (;;) { int32_t x188 = x176; char x189 = x23[x188]; bool x190 = x189 != ','; if (!x190) break; int32_t x192 = x187; int32_t x194 = x176; int32_t x193 = x192 * 10; char x195 = x23[x194]; char x196 = x195 - '0'; int32_t x197 = x193 + x196; x187 = x197; x176 += 1; } x176 += 1; int32_t x203 = x187; int32_t x204 = x176; for (;;) { int32_t x205 = x176; char x206 = x23[x205]; bool x207 = x206 != '\n'; if (!x207) break; x176 += 1; } int32_t x212 = x176; x176 += 1; for (;;) { int32_t x216 = x176; bool x217 = x216 < x22; if (!x217) break; int32_t x219 = x176; for (;;) { int32_t x220 = x176; char x221 = x23[x220]; bool x222 = x221 != ','; if (!x222) break; x176 += 1; } int32_t x227 = x176; x176 += 1; int32_t x231 = x176; int32_t x232 = 0; for (;;) { int32_t x233 = x176; char x234 = x23[x233]; bool x235 = x234 != ','; if (!x235) break; int32_t x237 = x232; int32_t x239 = x176; int32_t x238 = x237 * 10; char x240 = x23[x239]; char x241 = x240 - '0'; int32_t x242 = x238 + x241; x232 = x242; x176 += 1; } x176 += 1; int32_t x248 = x232; int32_t x249 = x176; for (;;) { int32_t x250 = x176; char x251 = x23[x250]; bool x252 = x251 != '\n'; if (!x252) break; x176 += 1; } int32_t x257 = x176; x176 += 1; int32_t x228 = x227 - x219; char* x230 = x23+x219; int64_t x261 = hash(x230,x228); int32_t x262 = (int32_t)x261; int32_t x263 = x262 & 255; //#hash_lookup // generated code for hash lookup int32_t x264 = x263; for (;;) { int32_t x265 = x264; int32_t x266 = x6[x265]; bool x268 = x266 == -1; bool x290; if (x268) { x290 = false; } else { char* x269 = x2[x266]; int32_t x270 = x3[x266]; bool x272 = x270 == x228; bool x287; if (x272) { int32_t x273 = 0; for (;;) { int32_t x274 = x273; bool x275 = x274 < x270; bool x279; if (x275) { char x276 = x269[x274]; char x277 = x230[x274]; bool x278 = x276 == x277; x279 = x278; } else { x279 = false; } if (!x279) break; x273 += 1; } int32_t x284 = x273; bool x285 = x284 == x270; x287 = x285; } else { x287 = false; } bool x288 = !x287; x290 = x288; } if (!x290) break; int32_t x292 = x264; int32_t x293 = x292 + 1; int32_t x294 = x293 & 255; x264 = x294; } int32_t x298 = x264; int32_t x299 = x6[x298]; int32_t x301 = x299; //#hash_lookup bool x303 = x301 == -1; if (x303) { } else { int32_t x304 = x20[x301]; int32_t x305 = x301 * 256; int32_t x306 = x305 + x304; for(int x308=x305; x308 < x306; x308++) { int32_t x309 = x19[x308]; char* x310 = x12[x309]; int32_t x311 = x13[x309]; int32_t x312 = x14[x309]; char* x313 = x15[x309]; int32_t x314 = x16[x309]; int32_t x315 = printll(x310); printf(","); printf("%d",x312); printf(","); int32_t x319 = printll(x313); printf(","); int32_t x321 = printll(x230); printf("%s\n",""); } } } close(x21); }
void Snippet(char* x0) { printf("%s\n","Name,Value"); char** x2 = (char**)malloc(256 * sizeof(char*)); int32_t* x3 = (int32_t*)malloc(256 * sizeof(int32_t)); int32_t x4 = 0; int32_t x5 = 0; int32_t* x6 = (int32_t*)malloc(256 * sizeof(int32_t)); for(int x8=0; x8 < 256; x8++) { x6[x8] = -1; } int32_t* x12 = (int32_t*)malloc(256 * sizeof(int32_t)); int32_t x13 = 0; int32_t x17 = 0; int32_t x14 = open("src/data/t.csv",0); int32_t x15 = fsize(x14); char* x16 = mmap(0, x15, PROT_READ, MAP_FILE | MAP_SHARED, x14, 0); for (;;) { int32_t x18 = x17; char x19 = x16[x18]; bool x20 = x19 != ','; if (!x20) break; x17 += 1; } int32_t x25 = x17; x17 += 1; int32_t x28 = x17; int32_t x29 = 0; for (;;) { int32_t x30 = x17; char x31 = x16[x30]; bool x32 = x31 != ','; if (!x32) break; int32_t x34 = x29; int32_t x36 = x17; int32_t x35 = x34 * 10; char x37 = x16[x36]; char x38 = x37 - '0'; int32_t x39 = x35 + x38; x29 = x39; x17 += 1; } x17 += 1; int32_t x45 = x29; int32_t x46 = x17; for (;;) { int32_t x47 = x17; char x48 = x16[x47]; bool x49 = x48 != '\n'; if (!x49) break; x17 += 1; } int32_t x54 = x17; x17 += 1; for (;;) { int32_t x58 = x17; bool x59 = x58 < x15; if (!x59) break; int32_t x61 = x17; for (;;) { int32_t x62 = x17; char x63 = x16[x62]; bool x64 = x63 != ','; if (!x64) break; x17 += 1; } int32_t x69 = x17; x17 += 1; int32_t x73 = x17; int32_t x74 = 0; for (;;) { int32_t x75 = x17; char x76 = x16[x75]; bool x77 = x76 != ','; if (!x77) break; int32_t x79 = x74; int32_t x81 = x17; int32_t x80 = x79 * 10; char x82 = x16[x81]; char x83 = x82 - '0'; int32_t x84 = x80 + x83; x74 = x84; x17 += 1; } x17 += 1; int32_t x90 = x74; int32_t x91 = x17; for (;;) { int32_t x92 = x17; char x93 = x16[x92]; bool x94 = x93 != '\n'; if (!x94) break; x17 += 1; } int32_t x99 = x17; x17 += 1; int32_t x70 = x69 - x61; char* x72 = x16+x61; int64_t x103 = hash(x72,x70); int32_t x104 = (int32_t)x103; int32_t x105 = x104 & 255; //#hash_lookup // generated code for hash lookup int32_t x106 = x105; for (;;) { int32_t x107 = x106; int32_t x108 = x6[x107]; bool x110 = x108 == -1; bool x132; if (x110) { x132 = false; } else { char* x111 = x2[x108]; int32_t x112 = x3[x108]; bool x114 = x112 == x70; bool x129; if (x114) { int32_t x115 = 0; for (;;) { int32_t x116 = x115; bool x117 = x116 < x112; bool x121; if (x117) { char x118 = x111[x116]; char x119 = x72[x116]; bool x120 = x118 == x119; x121 = x120; } else { x121 = false; } if (!x121) break; x115 += 1; } int32_t x126 = x115; bool x127 = x126 == x112; x129 = x127; } else { x129 = false; } bool x130 = !x129; x132 = x130; } if (!x132) break; int32_t x134 = x106; int32_t x135 = x134 + 1; int32_t x136 = x135 & 255; x106 = x136; } int32_t x140 = x106; int32_t x141 = x6[x140]; bool x142 = x141 == -1; int32_t x150; if (x142) { int32_t x143 = x5; x2[x143] = x72; x3[x143] = x70; x5 += 1; x6[x140] = x143; x12[x143] = 0; x150 = x143; } else { x150 = x141; } int32_t x152 = x150; //#hash_lookup int32_t x153 = x12[x152]; int32_t x154 = x153 + x90; x12[x152] = x154; } int32_t x159 = x5; for(int x161=0; x161 < x159; x161++) { char* x162 = x2[x161]; int32_t x163 = x3[x161]; int32_t x164 = x12[x161]; int32_t x165 = printll(x162); printf(","); printf("%d",x164); printf("%s\n",""); } }
/** * Process an incoming FILEINFO message. * Expected in the middle of a group with no current file. */ void handle_fileinfo(struct group_list_t *group, const unsigned char *message, unsigned meslen, struct timeval rxtime) { stat_struct statbuf; int found_dir; if (!read_fileinfo(group, message, meslen, rxtime)) { return; } glog2(group, "Name of file to receive: %s", group->fileinfo.name); switch (group->fileinfo.ftype) { case FTYPE_REG: glog2(group, "Bytes: %s, Blocks: %d, Sections: %d", printll(group->fileinfo.size), group->fileinfo.blocks, group->fileinfo.sections); glog3(group, "small section size: %d, " "big section size: %d, # big sections: %d", group->fileinfo.secsize_small, group->fileinfo.secsize_big, group->fileinfo.big_sections); break; case FTYPE_DIR: glog2(group, "Empty directory"); break; case FTYPE_LINK: glog2(group, "Symbolic link to %s", group->fileinfo.linkname); break; case FTYPE_DELETE: glog2(group, "Deleting file/directory"); break; case FTYPE_FREESPACE: glog2(group, "Get free space for path"); break; default: glog1(group, "Invalid file type: %d", group->fileinfo.ftype); send_abort(group, "Invalid file type"); return; } if (!setup_dest_file(group)) { // A rejected file is still a success because we responded with a // COMPLETE with status=rejected instead of with an ABORT return; } // Make sure the path to the destination file exists and // remove or back up any existing file if (!create_path_to_file(group, group->fileinfo.filepath)) { glog0(group, "Error creating path to data file"); early_complete(group, COMP_STAT_REJECTED, 0); return; } found_dir = 0; if (tempfile && !group->sync_preview) { clear_path(group->fileinfo.temppath, group); } if ((group->fileinfo.ftype != FTYPE_DELETE) || (group->fileinfo.ftype != FTYPE_FREESPACE)) { // Don't do path checks for metafile commands } else if (lstat_func(group->fileinfo.filepath, &statbuf) != -1) { glog3(group, "checking existing file"); if ((group->fileinfo.ftype != FTYPE_DIR) || !S_ISDIR(statbuf.st_mode)) { if ((group->fileinfo.ftype != FTYPE_REG) || !S_ISREG(statbuf.st_mode) || ((!group->restart) && (!group->sync_mode))) { // Don't clear/backup if we're receiving a regular file // and we're in either restart mode or sync mode glog3(group, "calling move_to_backup"); if (!tempfile) { move_to_backup(group); } } } else { glog3(group, "found dir"); found_dir = 1; } } else if (errno != ENOENT) { gsyserror(group, "Error checking file %s",group->fileinfo.filepath); } switch (group->fileinfo.ftype) { case FTYPE_REG: handle_fileinfo_regular(group); break; case FTYPE_DIR: handle_fileinfo_dir(group, found_dir); break; case FTYPE_LINK: handle_fileinfo_link(group); break; case FTYPE_DELETE: handle_fileinfo_delete(group); break; case FTYPE_FREESPACE: handle_fileinfo_freespace(group); break; default: glog0(group, "Error handling FILEINFO: shouldn't get here!"); } }
/** * Perform the Announce/Register phase for a particular group/file * Group & encryption: ->ANNOUNCE <-REGISTER ->KEYINFO <-INFO_ACK * Group & no encryption: ->ANNOUNCE <-REGISTER ->REG_CONF * Files within a group: ->FILEINFO <-INFO_ACK * If client_key == 1, REGISTER is followed by CLIENT_KEY * Returns 1 if at least one client responded, 0 if none responded */ int announce_phase(struct finfo_t *finfo) { time_t endtime; int attempt, resend, announce, regconf, keyinfo, fileinfo, open, anyerror; int len, rval, rcv_status, last_pass, gotall, gotone, allreg, regdone, i; unsigned char *packet, *decrypted; struct uftp_h *header; struct timeval timeout; struct sockaddr_in receiver; if (finfo->file_id) { log1(0, 0, "File ID: %04X Name: %s", finfo->file_id, finfo->filename); log1(0, 0, " sending as: %s", finfo->destfname); switch (finfo->ftype) { case FTYPE_REG: log(0, 0, "Bytes: %s Blocks: %d Sections: %d", printll(finfo->size), finfo->blocks, finfo->sections); break; case FTYPE_DIR: log(0, 0, "Empty directory"); break; case FTYPE_LINK: log(0, 0, "Symbolic link to %s", finfo->linkname); break; } } else { log(0, 0, "Initializing group"); if (sync_mode) { log0(0, 0, "- Connect -"); } } rval = 1; packet = calloc(mtu, 1); decrypted = calloc(mtu, 1); if ((packet == NULL) || (decrypted == NULL)) { syserror(0, 0, "calloc failed!"); exit(1); } header = (struct uftp_h *)packet; endtime = time(NULL) + announce_time; announce = (finfo->file_id == 0); regconf = (announce && (keytype == KEY_NONE)); keyinfo = (announce && (keytype != KEY_NONE)); fileinfo = (finfo->file_id != 0); open = (destcount == 0); for (i = 0; i < destcount; i++) { // At start of group, initialize all clients/proxies to DEST_MUTE. // At start of file, initialize proxies to DEST_ACTIVE (since they // don't respond directly to a FILEINFO) and clients to DEST_REGISTERED. if (announce) { destlist[i].status = DEST_MUTE; } else if (!client_error(i)) { if (destlist[i].clientcnt != -1) { destlist[i].status = DEST_ACTIVE; } else { destlist[i].status = DEST_REGISTERED; } } } timeout.tv_sec = announce_int / 1000; timeout.tv_usec = (announce_int % 1000) * 1000; resend = 1; attempt = 1; last_pass = 0; regdone = 0; while (time(NULL) < endtime) { // On the initial pass, or when the announce timeout trips, // send any necessary messages. if (resend) { if (keyinfo && !send_keyinfo(finfo, attempt)) { continue; } if (announce && !send_regconf(finfo, attempt, regconf)) { continue; } if (fileinfo && !send_fileinfo(finfo, attempt)) { continue; } if (announce && !send_announce(finfo, attempt, open)) { continue; } resend = 0; } // TODO: Currently, the interval between sends is really an inactivity // timer, not the actual time between sends. We might want to change // it to that, and perhaps add an extra "overage" timer in case we're // still processing responses when we're due to resend, that way we'll // always wait some minimum amount of time. if ((rcv_status = read_packet(sock, &receiver, packet, &len, mtu, &timeout)) == -1) { continue; } else if (rcv_status == 0) { attempt++; resend = 1; if (last_pass) break; continue; } if (!validate_packet(packet, len, finfo)) { continue; } if (!handle_announce_phase(packet, decrypted, &receiver, finfo, announce, open, regconf)) { continue; } if (!open) { for (i = 0, gotall = 1, allreg = 1; (i < destcount) && (gotall || allreg); i++) { if (announce) { gotall = gotall && ((destlist[i].status == DEST_ACTIVE) || (destlist[i].status == DEST_ABORT)); allreg = allreg && ((destlist[i].status == DEST_ACTIVE) || (destlist[i].status == DEST_REGISTERED) || (destlist[i].status == DEST_ABORT)); } else { gotall = gotall && ((destlist[i].status == DEST_ACTIVE) || (destlist[i].status == DEST_DONE) || (client_error(i))); } } if (gotall) { // Break out right away if this is a file registration. // For group registration, do one last wait, even if // encryption is enabled since we can still send a // REG_CONF for a client behind a proxy. // Change the wait interval to the client's register_int * 1.5 // to allow for late registers. // Be careful not to overrun the phase timeout! if (finfo->file_id != 0) break; timeout.tv_sec = (int)(register_int / 1000 * 1.5); timeout.tv_usec = (int)((register_int % 1000) * 1000 * 1.5); if (timeout.tv_sec > endtime) { #ifdef WINDOWS timeout.tv_sec = (long)endtime; #else timeout.tv_sec = endtime; #endif timeout.tv_usec = 0; } if (!last_pass) { log(0, 0, "Late registers:"); } last_pass = 1; send_regconf(finfo, attempt + 1, regconf); } else if (announce && allreg && !regdone) { // All have registered, so don't wait to send the next message resend = 1; regdone = 1; } } } for (i = 0, gotone = 0, anyerror = 0; i < destcount; i++) { gotone = gotone || (((destlist[i].status == DEST_ACTIVE) || (destlist[i].status == DEST_DONE)) && (destlist[i].clientcnt == -1)); if (destlist[i].status == DEST_REGISTERED) { log1(0, 0, "Couldn't get INFO_ACK from %s", destlist[i].name); destlist[i].status = DEST_LOST; anyerror = 1; } if ((destlist[i].status == DEST_MUTE) || (destlist[i].status == DEST_ABORT)) { anyerror = 1; } } if (anyerror && quit_on_error) { log0(0, 0, "Aboring all clients"); send_abort(finfo, "A client dropped out, aborting all", &receive_dest, NULL, (keytype != KEY_NONE), 0); for (i = 0; i < destcount; i++) { if (destlist[i].status == DEST_ACTIVE) { destlist[i].status = DEST_ABORT; } } rval = 0; } if (!gotone) { log0(0, 0, "Announce timed out"); rval = 0; } if (open) { send_regconf(finfo, attempt, regconf); } if ((finfo->file_id == 0) && sync_mode) { for (i = 0; i < destcount; i++) { if (destlist[i].status == DEST_ACTIVE) { log0(0, 0, "CONNECT;success;%s", destlist[i].name); } else { log0(0, 0, "CONNECT;failed;%s", destlist[i].name); } } log0(0, 0, "- Transfer -"); } free(packet); free(decrypted); return rval; }
/** * Print the final statistics for the given file while in sync mode */ void print_sync_status(const struct finfo_t *finfo, struct timeval start_time) { double elapsed_time, throughput; int i; if (finfo->file_id == 0) { log0(0, 0, "- Status -"); log0(0, 0, "HSTATS;target;copy;overwrite;" "skip;totalMB;time;speedKB/s"); for (i = 0; i < destcount; i++) { if (destlist[i].clientcnt >= 0) { continue; } if (destlist[i].total_time > 0) { throughput = destlist[i].total_size / destlist[i].total_time / 1024; } else { throughput = 0; } log0(0, 0, "STATS;%s;%d;%d;%d;%sMB;%.3f;%.2fKB/s", destlist[i].name, destlist[i].num_copy, destlist[i].num_overwrite, destlist[i].num_skip, printll(destlist[i].total_size / 1048576), destlist[i].total_time, throughput); } return; } for (i = 0; i < destcount; i++) { if (destlist[i].clientcnt >= 0) { continue; } clog0(0, 0, "RESULT;%s;%s;%sKB;", destlist[i].name, finfo->destfname, printll(finfo->size / 1024)); switch (destlist[i].status) { case DEST_MUTE: slog0("mute;"); break; case DEST_LOST: slog0("lost;"); break; case DEST_ABORT: slog0("aborted;"); break; case DEST_DONE: if (sync_preview) { throughput = rate / 8; elapsed_time = finfo->size / (throughput * 1024); } else { elapsed_time = (double)diff_usec(finfo->deststate[i].time, start_time) / 1000000; if (elapsed_time > 0) { throughput = finfo->size / elapsed_time / 1024; } else { throughput = 0; } } switch (destlist[i].comp_status) { case COMP_STAT_NORMAL: slog0("copy;%.2fKB/s", throughput); destlist[i].num_copy++; destlist[i].total_time += elapsed_time; destlist[i].total_size += finfo->size; break; case COMP_STAT_SKIPPED: slog0("skipped;"); destlist[i].num_skip++; break; case COMP_STAT_OVERWRITE: slog0("overwritten;%.2fKB/s", throughput); destlist[i].num_overwrite++; destlist[i].total_time += elapsed_time; destlist[i].total_size += finfo->size; break; case COMP_STAT_REJECTED: slog0("rejected;"); break; default: slog0("Unknown;"); break; } break; default: slog0("Unknown;"); break; } } }
void Snippet(char* x0) { printf("%s\n","Name,Value,Flag"); int32_t x5 = 0; int32_t x2 = open("src/data/t.csv",0); int32_t x3 = fsize(x2); char* x4 = mmap(0, x3, PROT_READ, MAP_FILE | MAP_SHARED, x2, 0); for (;;) { int32_t x6 = x5; char x7 = x4[x6]; bool x8 = x7 != ','; if (!x8) break; x5 += 1; } int32_t x13 = x5; x5 += 1; int32_t x16 = x5; int32_t x17 = 0; for (;;) { int32_t x18 = x5; char x19 = x4[x18]; bool x20 = x19 != ','; if (!x20) break; int32_t x22 = x17; int32_t x24 = x5; int32_t x23 = x22 * 10; char x25 = x4[x24]; char x26 = x25 - '0'; int32_t x27 = x23 + x26; x17 = x27; x5 += 1; } x5 += 1; int32_t x33 = x17; int32_t x34 = x5; for (;;) { int32_t x35 = x5; char x36 = x4[x35]; bool x37 = x36 != '\n'; if (!x37) break; x5 += 1; } int32_t x42 = x5; x5 += 1; for (;;) { int32_t x46 = x5; bool x47 = x46 < x3; if (!x47) break; int32_t x49 = x5; for (;;) { int32_t x50 = x5; char x51 = x4[x50]; bool x52 = x51 != ','; if (!x52) break; x5 += 1; } int32_t x57 = x5; x5 += 1; int32_t x61 = x5; int32_t x62 = 0; for (;;) { int32_t x63 = x5; char x64 = x4[x63]; bool x65 = x64 != ','; if (!x65) break; int32_t x67 = x62; int32_t x69 = x5; int32_t x68 = x67 * 10; char x70 = x4[x69]; char x71 = x70 - '0'; int32_t x72 = x68 + x71; x62 = x72; x5 += 1; } x5 += 1; int32_t x78 = x62; int32_t x79 = x5; for (;;) { int32_t x80 = x5; char x81 = x4[x80]; bool x82 = x81 != '\n'; if (!x82) break; x5 += 1; } int32_t x87 = x5; x5 += 1; char* x60 = x4+x49; int32_t x91 = printll(x60); printf(","); printf("%d",x78); printf(","); char* x90 = x4+x79; int32_t x95 = printll(x90); printf("%s\n",""); } }
void Snippet(char* x0) { printf("%s\n","Word,Value,Word,Year,MatchCount,VolumeCount"); int32_t x5 = 0; int32_t x2 = open("src/data/words.csv",0); int32_t x3 = fsize(x2); char* x4 = mmap(0, x3, PROT_READ, MAP_FILE | MAP_SHARED, x2, 0); for (;;) { int32_t x6 = x5; char x7 = x4[x6]; bool x8 = x7 != ','; if (!x8) break; x5 += 1; } int32_t x13 = x5; x5 += 1; int32_t x16 = x5; int32_t x17 = 0; for (;;) { int32_t x18 = x5; char x19 = x4[x18]; bool x20 = x19 != '\n'; if (!x20) break; int32_t x22 = x17; int32_t x24 = x5; int32_t x23 = x22 * 10; char x25 = x4[x24]; char x26 = x25 - '0'; int32_t x27 = x23 + x26; x17 = x27; x5 += 1; } x5 += 1; int32_t x33 = x17; int32_t x67 = open(x0,0); int32_t x68 = fsize(x67); char* x69 = mmap(0, x68, PROT_READ, MAP_FILE | MAP_SHARED, x67, 0); for (;;) { int32_t x34 = x5; bool x35 = x34 < x3; if (!x35) break; int32_t x37 = x5; for (;;) { int32_t x38 = x5; char x39 = x4[x38]; bool x40 = x39 != ','; if (!x40) break; x5 += 1; } int32_t x45 = x5; x5 += 1; int32_t x49 = x5; int32_t x50 = 0; for (;;) { int32_t x51 = x5; char x52 = x4[x51]; bool x53 = x52 != '\n'; if (!x53) break; int32_t x55 = x50; int32_t x57 = x5; int32_t x56 = x55 * 10; char x58 = x4[x57]; char x59 = x58 - '0'; int32_t x60 = x56 + x59; x50 = x60; x5 += 1; } x5 += 1; int32_t x66 = x50; int32_t x70 = 0; int32_t x46 = x45 - x37; char* x48 = x4+x37; for (;;) { int32_t x71 = x70; bool x72 = x71 < x68; if (!x72) break; int32_t x74 = x70; for (;;) { int32_t x75 = x70; char x76 = x69[x75]; bool x77 = x76 != '\t'; if (!x77) break; x70 += 1; } int32_t x82 = x70; x70 += 1; int32_t x86 = x70; for (;;) { int32_t x87 = x70; char x88 = x69[x87]; bool x89 = x88 != '\t'; if (!x89) break; x70 += 1; } int32_t x94 = x70; x70 += 1; int32_t x98 = x70; for (;;) { int32_t x99 = x70; char x100 = x69[x99]; bool x101 = x100 != '\t'; if (!x101) break; x70 += 1; } int32_t x106 = x70; x70 += 1; int32_t x110 = x70; for (;;) { int32_t x111 = x70; char x112 = x69[x111]; bool x113 = x112 != '\n'; if (!x113) break; x70 += 1; } int32_t x118 = x70; x70 += 1; int32_t x83 = x82 - x74; bool x123 = x46 == x83; bool x138; if (x123) { int32_t x124 = 0; char* x85 = x69+x74; for (;;) { int32_t x125 = x124; bool x126 = x125 < x46; bool x130; if (x126) { char x127 = x48[x125]; char x128 = x85[x125]; bool x129 = x127 == x128; x130 = x129; } else { x130 = false; } if (!x130) break; x124 += 1; } int32_t x135 = x124; bool x136 = x135 == x46; x138 = x136; } else { x138 = false; } if (x138) { int32_t x139 = printll(x48); printf(","); printf("%d",x66); printf(","); char* x85 = x69+x74; int32_t x143 = printll(x85); printf(","); char* x97 = x69+x86; int32_t x145 = printll(x97); printf(","); char* x109 = x69+x98; int32_t x147 = printll(x109); printf(","); char* x121 = x69+x110; int32_t x149 = printll(x121); printf("%s\n",""); } else { } } close(x67); } close(x2); }
void Snippet(char* x0) { printf("%s\n","Name,Value,Flag,Name1"); int32_t x5 = 0; int32_t x2 = open("src/data/t.csv",0); int32_t x3 = fsize(x2); char* x4 = mmap(0, x3, PROT_READ, MAP_FILE | MAP_SHARED, x2, 0); for (;;) { int32_t x6 = x5; char x7 = x4[x6]; bool x8 = x7 != ','; if (!x8) break; x5 += 1; } int32_t x13 = x5; x5 += 1; int32_t x16 = x5; int32_t x17 = 0; for (;;) { int32_t x18 = x5; char x19 = x4[x18]; bool x20 = x19 != ','; if (!x20) break; int32_t x22 = x17; int32_t x24 = x5; int32_t x23 = x22 * 10; char x25 = x4[x24]; char x26 = x25 - '0'; int32_t x27 = x23 + x26; x17 = x27; x5 += 1; } x5 += 1; int32_t x33 = x17; int32_t x34 = x5; for (;;) { int32_t x35 = x5; char x36 = x4[x35]; bool x37 = x36 != '\n'; if (!x37) break; x5 += 1; } int32_t x42 = x5; x5 += 1; for (;;) { int32_t x46 = x5; bool x47 = x46 < x3; if (!x47) break; int32_t x49 = x5; for (;;) { int32_t x50 = x5; char x51 = x4[x50]; bool x52 = x51 != ','; if (!x52) break; x5 += 1; } int32_t x57 = x5; x5 += 1; int32_t x61 = x5; int32_t x62 = 0; for (;;) { int32_t x63 = x5; char x64 = x4[x63]; bool x65 = x64 != ','; if (!x65) break; int32_t x67 = x62; int32_t x69 = x5; int32_t x68 = x67 * 10; char x70 = x4[x69]; char x71 = x70 - '0'; int32_t x72 = x68 + x71; x62 = x72; x5 += 1; } x5 += 1; int32_t x78 = x62; int32_t x79 = x5; for (;;) { int32_t x80 = x5; char x81 = x4[x80]; bool x82 = x81 != '\n'; if (!x82) break; x5 += 1; } int32_t x87 = x5; x5 += 1; int32_t x91 = 0; for (;;) { int32_t x92 = x91; char x93 = x4[x92]; bool x94 = x93 != ','; if (!x94) break; x91 += 1; } int32_t x99 = x91; x91 += 1; int32_t x101 = x91; int32_t x102 = 0; for (;;) { int32_t x103 = x91; char x104 = x4[x103]; bool x105 = x104 != ','; if (!x105) break; int32_t x107 = x102; int32_t x109 = x91; int32_t x108 = x107 * 10; char x110 = x4[x109]; char x111 = x110 - '0'; int32_t x112 = x108 + x111; x102 = x112; x91 += 1; } x91 += 1; int32_t x118 = x102; int32_t x119 = x91; for (;;) { int32_t x120 = x91; char x121 = x4[x120]; bool x122 = x121 != '\n'; if (!x122) break; x91 += 1; } int32_t x127 = x91; x91 += 1; char* x60 = x4+x49; char* x90 = x4+x79; for (;;) { int32_t x131 = x91; bool x132 = x131 < x3; if (!x132) break; int32_t x134 = x91; for (;;) { int32_t x135 = x91; char x136 = x4[x135]; bool x137 = x136 != ','; if (!x137) break; x91 += 1; } int32_t x142 = x91; x91 += 1; int32_t x146 = x91; int32_t x147 = 0; for (;;) { int32_t x148 = x91; char x149 = x4[x148]; bool x150 = x149 != ','; if (!x150) break; int32_t x152 = x147; int32_t x154 = x91; int32_t x153 = x152 * 10; char x155 = x4[x154]; char x156 = x155 - '0'; int32_t x157 = x153 + x156; x147 = x157; x91 += 1; } x91 += 1; int32_t x163 = x147; int32_t x164 = x91; for (;;) { int32_t x165 = x91; char x166 = x4[x165]; bool x167 = x166 != '\n'; if (!x167) break; x91 += 1; } int32_t x172 = x91; x91 += 1; int32_t x176 = printll(x60); printf(","); printf("%d",x78); printf(","); int32_t x180 = printll(x90); printf(","); char* x145 = x4+x134; int32_t x182 = printll(x145); printf("%s\n",""); } close(x2); } close(x2); }