int main() { int ncase = 0; while (true) { scanf("%d", &N); if (N == 0) break; printf("Case %d:\n", ++ncase); len = -1, from = -3, to = -2; while (N--) { scanf("%s", num); curr = atoi(num); if (curr == to + 1) { to = curr; strcpy(sto, num); } else handle_range(); } handle_range(); putchar('\n'); } return 0; }
SimpleReBuilder * simplifyRe(char ** complexRe, SimpleReBuilder * builder) { int len = strlen(*complexRe); simpleReBuilder(&builder, len); int i,j; for (i = 0, j = 0; i < len; i++, j++) { switch(DEREF(complexRe, i)) { case '\\': handle_escape(builder, complexRe, &len, &j, &i); break; case '.': builder->re[j] = ANY; //nak is ANY break; case '+': builder->re[j] = PLUS; //0x01 is + break; case '?': builder->re[j] = QUESTION; //0x02 is ? break; case '*': builder->re[j] = STAR; //0x03 is * break; case '|': builder->re[j] = ALTERNATE; //0x04 is | break; case '(': builder->re[j] = PAREN_OPEN; //0x05 is ( break; case ')': builder->re[j] = PAREN_CLOSE; //0x06 is ) break; case '[': handle_range(builder, *complexRe, len, &j, &i); break; default: builder->re[j] = DEREF(complexRe,i); break; } } builder->re[j] = '\0'; return builder; }
int static_file_handle(request_t *req, response_t *resp, handler_ctx_t *ctx) { mod_static_conf_t *conf; char path[2048]; int fd = -1, res, use_301; struct stat st; size_t len, pathlen, filesize, fileoffset; ctx_state_t val; conf = (mod_static_conf_t*) ctx->conf; len = strlen(conf->root); strncpy(path, conf->root, 2048); if (path[len - 1] == '/') { path[len - 1] = '\0'; } if (req->path[0] != '/') { return response_send_status(resp, STATUS_BAD_REQUEST); } strncat(path, req->path, 2048 - len); debug("Request path: %s, real file path: %s", req->path, path); res = try_open_file(path, &fd, &st); if (res < 0) { return static_file_handle_error(resp, fd); } else if (res > 0) { // Is a directory, try index files. pathlen = strlen(path); use_301 = 0; if (path[pathlen - 1] != '/') { path[pathlen] = '/'; path[pathlen + 1] = '\0'; pathlen++; use_301 = 1; } //for (i = 0; i < 10 && res != 0 && conf->index[i] != NULL; i++) { // path[pathlen] = '\0'; // strncat(path, conf->index[i], 2048 - pathlen); // res = try_open_file(path, &fd, &st); //} path[pathlen] = '\0'; strncat(path, conf->index, 2048 - pathlen); res = try_open_file(path, &fd, &st); path[pathlen] = '\0'; if (res != 0) { if (conf->enable_list_dir) { if (use_301) { // TODO Support HTTPS snprintf(path, 2048, "http://%s%s/", req->host, req->path); response_set_header(resp, "Location", path); resp->status = STATUS_MOVED; resp->content_length = 0; response_send_headers(resp, NULL); return HANDLER_DONE; } show_hidden_file = conf->show_hidden_file; return static_file_listdir(resp, req->path, path); } else { return static_file_handle_error(resp, fd); } } } fileoffset = 0; filesize = st.st_size; res = handle_range(req, resp, &fileoffset, &filesize); if (res < 0) { resp->status = STATUS_OK; } else if (res == 0) { resp->status = STATUS_PARTIAL_CONTENT; } else { return response_send_status(resp, STATUS_RANGE_NOT_SATISFIABLE); } resp->content_length = filesize; handle_content_type(resp, path); if (handle_cache(req, resp, &st, conf)) { return response_send_status(resp, STATUS_NOT_MODIFIED); } val.as_int = fd; context_push(ctx, val); val.as_long = fileoffset; context_push(ctx, val); val.as_long = filesize; context_push(ctx, val); debug("sending headers"); response_send_headers(resp, static_file_write_content); return HANDLER_UNFISHED; }