void basic_feats(string targetname,bool is_bi,string mode,string gazfile,bool lowercase){ cerr << "\nbasic_feats(tagged=" << is_bi << "," << mode << ",low=" << lowercase << ")"; check_fname(targetname); ifstream in((targetname).c_str()); // #if USE_KF // ofstream out((targetname+"_basefeats_k").c_str()); // #else // ofstream out((targetname+"_basefeats").c_str()); // #endif gaz_server GZ; if (mode=="BIO"){ #if USE_MORPH_CACHE system("gunzip DATA/MORPH/MORPH_CACHE.gz"); GZ.init(gazfile,maxspan_gaz,"DATA/MORPH/MORPH_CACHE"); system("gzip DATA/MORPH/MORPH_CACHE"); #else GZ.init(gazfile,maxspan_gaz); #endif } char strbuf[10000]; while (in.peek() != -1){ string id = ""; in >> id; if (id != ""){ vector<string> W, P, L,LOW, WLEMMA; while (in.peek() == 9){ string w = "", pos = "", tag = ""; if (mode == "POS"){ in >> w; W.push_back(w); } else { in >> w >> pos; W.push_back(w); P.push_back(pos); } if (is_bi){ in >> tag; L.push_back(tag); } }
int handle_client(int csockfd, int timeout) { uint64_t fsize; ssize_t namelen; char buf[BUF_SZ]; char path[DIRLEN + FNAME_LENGTH + 1]; char *filename = path + DIRLEN; ssize_t nbytes; bool delete_file; /* reading filesize */ nbytes = read_tout(csockfd, &fsize, sizeof(fsize), timeout, 0, false); if (nbytes != sizeof(fsize)) { log("Filesize reading error\n"); return -1; } fsize = le64toh(fsize); if (fsize > ((uint64_t)1 << 62)) { log("Filesize is too big\n"); send_code(csockfd, CODE_BAD_FILELEN, timeout); return -1; } if (send_code(csockfd, CODE_ACK, timeout)) return -1; log("Filesize %llu accepted\n", fsize); /* reading filename */ //memset(path, 0, sizeof(path)); memcpy(path, DIRNAME, DIRLEN); nbytes = read_tout(csockfd, buf, sizeof(buf), timeout, MSG_PEEK, false); if (nbytes > 0) { namelen = fname_len(buf, nbytes); if (namelen <= 0 || namelen > FNAME_LENGTH) { log("Bad filename length\n"); send_code(csockfd, CODE_BAD_FILELEN, timeout); return -1; } /* There is no lseek() for socket, so .. */ read_tout(csockfd, filename, namelen + 1, 0, 0, true); } else { log("Filename reading error"); send_code(csockfd, CODE_ERR_UNKNOWN, timeout); return -1; } if (!check_fname(filename)) { log("Bad filename (check_fname)!\n"); send_code(csockfd, CODE_BAD_FILENAME, timeout); return -1; } if (access(path, F_OK) != -1) { send_code(csockfd, CODE_FILE_EXISTS, timeout); return -1; } int fd = open(path, O_CREAT | O_WRONLY, 0600); if (fd == -1) { perror("open()"); if (errno == ENAMETOOLONG) send_code(csockfd, CODE_BAD_FILELEN, timeout); else send_code(csockfd, CODE_ERR_UNKNOWN, timeout); return -1; } if (send_code(csockfd, CODE_ACK, timeout)) return -1; log("Filename `%s` accepted and file exchange started\n", filename); /* reading file */ nbytes = 0; delete_file = false; do { fsize -= (uint64_t) nbytes; nbytes = read_tout(csockfd, buf, sizeof(buf), timeout, 0, false); if (nbytes > 0) { if (write(fd, buf, min(nbytes, fsize)) == -1) { perror("write()"); send_code(csockfd, CODE_ERR_TRANSFER, timeout); delete_file = true; break; } } } while (nbytes > 0 && nbytes < fsize); if (nbytes < 0) { log("Error while transfer\n"); send_code(csockfd, CODE_ERR_TRANSFER, timeout); delete_file = true; } close(fd); if (delete_file) { log("Deleting file\n"); unlink(path); return -1; } if (send_code(csockfd, CODE_ACK, timeout)) log("Warning: send_code was unsuccessful, but file recieved ok"); log("File `%s` recieved ok!\n", path); return 0; }
/* Program main */ int main(int argc, char *argv[]) { cuuid_t cuuid; int c, rtn; unsigned int n = 1; char *fname = NULL; FILE *fp = NULL; int fout = 0, nout = 0, fmat = PRINT_FORMAT_HEX_BACKET, vbose = 0, gen = 1; int option_index; char tag[3] = {0x0, 0x0, 0x0}; static struct option long_options[] = { {"category", required_argument, 0, 0}, {"set-safe", no_argument, 0, 0}, {"set-master", no_argument, 0, 0}, {"set-public", no_argument, 0, 0}, {"set-sign", no_argument, 0, 0}, {"set-tag", no_argument, 0, 0}, {"set-strict", no_argument, 0, 0}, {"list-categories",no_argument, 0, 0}, {"rev", required_argument, 0, 0}, {"tag", required_argument, 0, 0}, {"rand-seed", required_argument, 0, 0}, {"memory-seed", required_argument, 0, 0}, {"output-hex", no_argument, 0, 'x'}, {"output-number", no_argument, 0, 'i'}, {"verbose", no_argument, 0, 'V'}, {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0 } }; /* Register interrupt handler */ signal(SIGINT, set_signint); while (1) { option_index = 0; c = getopt_long(argc, argv, "c:d:o:qxivVh", long_options, &option_index); if (c == -1) break; switch (c) { case 0: if (!strcmp("rand-seed", long_options[option_index].name)) { quid_set_rnd_seed(atoi(optarg)); } else if (!strcmp("memory-seed", long_options[option_index].name)) { quid_set_mem_seed(atoi(optarg)); } else if (!strcmp("rev", long_options[option_index].name)) { switch (atoi(optarg)) { case 4: cuuid.version = QUID_REV4; break; case 7: default: cuuid.version = QUID_REV7; break; } } else if (!strcmp("tag", long_options[option_index].name)) { if (strlen(optarg) != 3) { printf("tag must be 3 characters\n"); printf("see --help for more information\n"); return 1; } tag[0] = optarg[0]; tag[1] = optarg[1]; tag[2] = optarg[2]; } else if (!strcmp("list-categories", long_options[option_index].name)) { printf("%d) %s\n", CLS_CMON, category_name(CLS_CMON)); printf("%d) %s\n", CLS_INFO, category_name(CLS_INFO)); printf("%d) %s\n", CLS_WARN, category_name(CLS_WARN)); printf("%d) %s\n", CLS_ERROR, category_name(CLS_ERROR)); gen = 0; } else if (!strcmp("set-safe", long_options[option_index].name)) { flg |= IDF_IDSAFE; } else if (!strcmp("set-public", long_options[option_index].name)) { flg |= IDF_PUBLIC; } else if (!strcmp("set-master", long_options[option_index].name)) { flg |= IDF_MASTER; } else if (!strcmp("set-tag", long_options[option_index].name)) { flg |= IDF_TAGGED; } else if (!strcmp("set-strict", long_options[option_index].name)) { flg |= IDF_STRICT; } else if (!strcmp("set-sign", long_options[option_index].name)) { flg |= IDF_SIGNED; } else if (!strcmp("category", long_options[option_index].name)) { cat = (char)atoi(optarg); switch (cat) { case CLS_CMON: case CLS_INFO: case CLS_WARN: case CLS_ERROR: break; default: printf("unknown category %d\n", cat); printf("see --help for more information\n"); return 1; } } break; case 'c': n = atoi(optarg); break; case 'd': delay = atoi(optarg); break; case 'o': fname = optarg; fout = 1; break; case 'x': fmat = PRINT_FORMAT_HEX; break; case 'i': fmat = PRINT_FORMAT_DEC; break; case 'q': nout = 1; break; case 'V': vbose = 1; break; case 'v': print_version(); return 0; case 'h': case '?': default: usage(); return 0; } } /* Identifier as positional argument */ if (optind < argc) { cuuid_t uuid; while (optind < argc) { printf("%s\t", argv[optind]); if (quid_parse(argv[optind], &uuid)) { printf("VALID\n"); if (vbose) input_verbose(uuid); } else printf("INVALID\n"); optind++; } return 0; } /* Output new identifiers */ if (gen) { gettimeofday(&t1, NULL); /* File output */ if (fout) { rtn = check_fname(fname); if (!rtn) { fp = fopen(fname, "a"); } else if (rtn == 1) { printf("%s is a directory\n", fname); return 1; } else if (rtn == 2){ printf("%s already exists\n", fname); return 1; } } for (i=0; i<n; ++i) { assert(cat != 0); quid_create(&cuuid, flg, cat, tag); if (intflag) { break; } if (!fout){ if (!nout) { quid_print(cuuid, fmat); } } else { quid_print_file(fp, cuuid, fmat); } if (delay) { qusleep(delay * 1000); } ticks = clock(); } if (fp) { fclose(fp); } gettimeofday(&t2, NULL); } /* Show counters */ if (vbose && gen) { generate_verbose(); } return 0; }