static bool bvfs_parse_arg(UAContext *ua, DBId_t *pathid, char **path, char **jobid, char **username, int *limit, int *offset) { *pathid = 0; *limit = 2000; *offset = 0; *path = NULL; *jobid = NULL; *username = NULL; for (int i=1; i<ua->argc; i++) { if (bstrcasecmp(ua->argk[i], NT_("pathid"))) { if (is_a_number(ua->argv[i])) { *pathid = str_to_int64(ua->argv[i]); } } if (bstrcasecmp(ua->argk[i], NT_("path"))) { *path = ua->argv[i]; } if (bstrcasecmp(ua->argk[i], NT_("username"))) { *username = ua->argv[i]; } if (bstrcasecmp(ua->argk[i], NT_("jobid"))) { if (is_a_number_list(ua->argv[i])) { *jobid = ua->argv[i]; } } if (bstrcasecmp(ua->argk[i], NT_("limit"))) { if (is_a_number(ua->argv[i])) { *limit = str_to_int64(ua->argv[i]); } } if (bstrcasecmp(ua->argk[i], NT_("offset"))) { if (is_a_number(ua->argv[i])) { *offset = str_to_int64(ua->argv[i]); } } } if (!((*pathid || *path) && *jobid)) { return false; } if (!open_client_db(ua, true)) { return false; } return true; }
/* ** Caution: buf cannot be constant char *. It gets temporarily modified ** by this routine. */ int string_read_doubles(char *buf,double *a,int nmax) { int i,n; for (i=n=0;buf[i]!='\0';) { int j,c; for (;buf[i]=='\n' || buf[i]=='\r' || buf[i]==' ' || buf[i]=='\t' || buf[i]==',' || buf[i]==';';i++); if (buf[i]=='\0') break; j=i; for (;buf[i]!='\n' && buf[i]!='\r' && buf[i]!=' ' && buf[i]!='\t' && buf[i]!=',' && buf[i]!=';' && buf[i]!='\0';i++); c=buf[i]; if (buf[i]!='\0') buf[i]='\0'; if (!is_a_number(&buf[j])) { buf[i]=c; break; } a[n++]=string_atof(&buf[j]); buf[i]=c; if (n>=nmax) break; } return(n); }
/* * Return next JobId from comma separated list * * Returns: * 1 if next JobId returned * 0 if no more JobIds are in list * -1 there is an error */ int get_next_jobid_from_list(char **p, uint32_t *JobId) { const int maxlen = 30; char jobid[maxlen+1]; char *q = *p; jobid[0] = 0; for (int i=0; i<maxlen; i++) { if (*q == 0) { break; } else if (*q == ',') { q++; break; } jobid[i] = *q++; jobid[i+1] = 0; } if (jobid[0] == 0) { return 0; } else if (!is_a_number(jobid)) { return -1; /* error */ } *p = q; *JobId = str_to_int64(jobid); return 1; }
static bool bvfs_parse_arg_version(UAContext *ua, char **client, DBId_t *fnid, bool *versions, bool *copies) { *fnid = 0; *client = NULL; *versions = false; *copies = false; for (int i = 1; i < ua->argc; i++) { if (bstrcasecmp(ua->argk[i], NT_("fnid")) || bstrcasecmp(ua->argk[i], NT_("filenameid"))) { if (is_a_number(ua->argv[i])) { *fnid = str_to_int64(ua->argv[i]); } } if (bstrcasecmp(ua->argk[i], NT_("client"))) { *client = ua->argv[i]; } if (copies && bstrcasecmp(ua->argk[i], NT_("copies"))) { *copies = true; } if (versions && bstrcasecmp(ua->argk[i], NT_("versions"))) { *versions = true; } } return (*client && *fnid > 0); }
static int bvfs_result_handler(void *ctx, int fields, char **row) { UAContext *ua = (UAContext *)ctx; char *fileid=row[BVFS_FileId]; char *lstat=row[BVFS_LStat]; char *jobid=row[BVFS_JobId]; char empty[] = "A A A A A A A A A A A A A A"; char zero[] = "0"; /* We need to deal with non existant path */ if (!fileid || !is_a_number(fileid)) { lstat = empty; jobid = zero; fileid = zero; } Dmsg1(100, "type=%s\n", row[0]); if (bvfs_is_dir(row)) { char *path = bvfs_basename_dir(row[BVFS_Name]); ua->send->object_start(row[BVFS_Name]); ua->send->object_key_value("Type", row[BVFS_Type]); ua->send->object_key_value("PathId", str_to_uint64(row[BVFS_PathId]), "%lld\t"); ua->send->object_key_value("FilenameId", FileId_t(0), "%lld\t"); ua->send->object_key_value("FileId", str_to_uint64(fileid), "%lld\t"); ua->send->object_key_value("JobId", str_to_uint64(jobid), "%lld\t"); ua->send->object_key_value("lstat", lstat, "%s\t"); ua->send->object_key_value("Name", path, "%s\n"); ua->send->object_key_value("Fullpath", row[BVFS_Name]); bvfs_stat(ua, lstat); ua->send->object_end(row[BVFS_Name]); } else if (bvfs_is_version(row)) { ua->send->object_start(row[BVFS_Name]); ua->send->object_key_value("Type", row[BVFS_Type]); ua->send->object_key_value("PathId", str_to_uint64(row[BVFS_PathId]), "%lld\t"); ua->send->object_key_value("FilenameId", str_to_uint64(row[BVFS_FilenameId]), "%lld\t"); ua->send->object_key_value("FileId", str_to_uint64(fileid), "%lld\t"); ua->send->object_key_value("JobId", str_to_uint64(jobid), "%lld\t"); ua->send->object_key_value("lstat", lstat, "%s\t"); ua->send->object_key_value("MD5", row[BVFS_Md5], "%s\t"); ua->send->object_key_value("VolumeName", row[BVFS_VolName], "%s\t"); ua->send->object_key_value("VolumeInChanger", str_to_uint64(row[BVFS_VolInchanger]), "%lld\n"); ua->send->object_end(row[BVFS_Name]); } else if (bvfs_is_file(row)) { ua->send->object_start(row[BVFS_Name]); ua->send->object_key_value("Type", row[BVFS_Type]); ua->send->object_key_value("PathId", str_to_uint64(row[BVFS_PathId]), "%lld\t"); ua->send->object_key_value("FilenameId", str_to_uint64(row[BVFS_FilenameId]), "%lld\t"); ua->send->object_key_value("FileId", str_to_uint64(fileid), "%lld\t"); ua->send->object_key_value("JobId", str_to_uint64(jobid), "%lld\t"); ua->send->object_key_value("lstat", lstat, "%s\t"); ua->send->object_key_value("Name", row[BVFS_Name], "%s\n"); bvfs_stat(ua, lstat); ua->send->object_end(row[BVFS_Name]); } return 0; }
/* * Given a string "str", separate the numeric part into * str, and the modifier into mod. */ static bool get_modifier(char *str, char *num, int num_len, char *mod, int mod_len) { int i, len, num_begin, num_end, mod_begin, mod_end; strip_trailing_junk(str); len = strlen(str); for (i=0; i<len; i++) { if (!B_ISSPACE(str[i])) { break; } } num_begin = i; /* Walk through integer part */ for ( ; i<len; i++) { if (!B_ISDIGIT(str[i]) && str[i] != '.') { break; } } num_end = i; if (num_len > (num_end - num_begin + 1)) { num_len = num_end - num_begin + 1; } if (num_len == 0) { return false; } /* Eat any spaces in front of modifier */ for ( ; i<len; i++) { if (!B_ISSPACE(str[i])) { break; } } mod_begin = i; for ( ; i<len; i++) { if (!B_ISALPHA(str[i])) { break; } } mod_end = i; if (mod_len > (mod_end - mod_begin + 1)) { mod_len = mod_end - mod_begin + 1; } Dmsg5(900, "str=%s: num_beg=%d num_end=%d mod_beg=%d mod_end=%d\n", str, num_begin, num_end, mod_begin, mod_end); bstrncpy(num, &str[num_begin], num_len); bstrncpy(mod, &str[mod_begin], mod_len); if (!is_a_number(num)) { return false; } bstrncpy(str, &str[mod_end], len); Dmsg2(900, "num=%s mod=%s\n", num, mod); return true; }
//4970072278724 bool_t is_enum(const char *sipaddress, char **enum_domain){ char *p; p=strstr(sipaddress,"sip:"); if (p==NULL) return FALSE; /* enum should look like sip:4369959250*/ else p+=4; if (is_a_number(p)){ if (enum_domain!=NULL){ *enum_domain=create_enum_domain(p); } return TRUE; } return FALSE; }
static int uwsgi_hook_chown2(char *arg) { char *space = strchr(arg, ' '); if (!space) { uwsgi_log("invalid hook chown2 syntax, must be: <file> <uid> <gid>\n"); return -1; } *space = 0; char *space2 = strchr(space+1, ' '); if (!space2) { *space = ' '; uwsgi_log("invalid hook chown2 syntax, must be: <file> <uid> <gid>\n"); return -1; } *space2 = 0; if (!is_a_number(space+1)) { uwsgi_log("invalid hook chown2 syntax, uid must be a number\n"); *space = ' '; *space2 = ' '; return -1; } if (!is_a_number(space2+1)) { uwsgi_log("invalid hook chown2 syntax, gid must be a number\n"); *space = ' '; *space2 = ' '; return -1; } int ret = chown(arg, atoi(space+1), atoi(space2+1)); *space = ' '; *space2 = ' '; if (ret) { uwsgi_error("uwsgi_hook_chown2()/chown)"); } return ret; }
Awkfloat r_getfval(Cell *vp) /* get float val of a Cell */ { if ((vp->tval & (NUM | STR)) == 0) funnyvar(vp, "read value of"); if ((vp->tval & FLD) && donefld == 0) fldbld(); else if ((vp->tval & REC) && donerec == 0) recbld(); if (!isnum(vp)) { /* not a number */ vp->fval = atof(vp->sval); /* best guess */ if (is_a_number(vp->sval) && !(vp->tval&CON)) vp->tval |= NUM; /* make NUM only sparingly */ } dprintf( ("getfval %o: %s = %g, t=%o\n", vp, vp->nval, vp->fval, vp->tval) ); return(vp->fval); }
static uint64_t scan_pint64(LEX *lf, char *str) { uint64_t val = 0; if (!is_a_number(str)) { scan_err1(lf, _("expected a positive integer number, got: %s"), str); /* NOT REACHED */ } else { errno = 0; val = str_to_uint64(str); if (errno != 0) { scan_err1(lf, _("expected a positive integer number, got: %s"), str); /* NOT REACHED */ } } return val; }
static uint32_t scan_pint(LEX *lf, char *str) { int64_t val = 0; if (!is_a_number(str)) { scan_err1(lf, _("expected a positive integer number, got: %s"), str); /* NOT REACHED */ } else { errno = 0; val = str_to_int64(str); if (errno != 0 || val < 0) { scan_err1(lf, _("expected a positive integer number, got: %s"), str); /* NOT REACHED */ } } return (uint32_t)(val & 0xffffffff); }
void envinit(uchar **envp) /* set up ENVIRON variable */ { Cell *cp; uchar *p; cp = setsymtab("ENVIRON", "", 0.0, ARR, symtab); ENVtab = makesymtab(NSYMTAB); cp->sval = (uchar *) ENVtab; for ( ; *envp; envp++) { if ((p = (uchar *) strchr((char *) *envp, '=')) == NULL) continue; *p++ = 0; /* split into two strings at = */ if (is_a_number(p)) setsymtab(*envp, p, atof(p), STR|NUM, ENVtab); else setsymtab(*envp, p, 0.0, STR, ENVtab); p[-1] = '='; /* restore in case env is passed down to a shell */ } }
void arginit(int ac, uchar *av[]) /* set up ARGV and ARGC */ { Cell *cp; int i; uchar temp[5]; ARGC = &setsymtab("ARGC", "", (Awkfloat) ac, NUM, symtab)->fval; cp = setsymtab("ARGV", "", 0.0, ARR, symtab); ARGVtab = makesymtab(NSYMTAB); /* could be (int) ARGC as well */ cp->sval = (uchar *) ARGVtab; for (i = 0; i < ac; i++) { sprintf((char *)temp, "%d", i); if (is_a_number(*av)) setsymtab(temp, *av, atof(*av), STR|NUM, ARGVtab); else setsymtab(temp, *av, 0.0, STR, ARGVtab); av++; } }
static int bvfs_result_handler(void *ctx, int fields, char **row) { UAContext *ua = (UAContext *)ctx; struct stat statp; int32_t LinkFI; char *fileid=row[BVFS_FileId]; char *lstat=row[BVFS_LStat]; char *jobid=row[BVFS_JobId]; char empty[] = "A A A A A A A A A A A A A A"; char zero[] = "0"; /* We need to deal with non existant path */ if (!fileid || !is_a_number(fileid)) { lstat = empty; jobid = zero; fileid = zero; } memset(&statp, 0, sizeof(struct stat)); decode_stat(lstat, &statp, sizeof(statp), &LinkFI); Dmsg1(100, "type=%s\n", row[0]); if (bvfs_is_dir(row)) { char *path = bvfs_basename_dir(row[BVFS_Name]); ua->send_msg("%s\t0\t%s\t%s\t%s\t%s\n", row[BVFS_PathId], fileid, jobid, lstat, path); } else if (bvfs_is_version(row)) { ua->send_msg("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", row[BVFS_PathId], row[BVFS_FilenameId], fileid, jobid, lstat, row[BVFS_Md5], row[BVFS_VolName], row[BVFS_VolInchanger]); } else if (bvfs_is_file(row)) { ua->send_msg("%s\t%s\t%s\t%s\t%s\t%s\n", row[BVFS_PathId], row[BVFS_FilenameId], fileid, jobid, lstat, row[BVFS_Name]); } return 0; }
void spooler_manage_task(struct uwsgi_spooler *uspool, char *dir, char *task) { int i, ret; char spool_buf[0xffff]; struct uwsgi_header uh; char *body = NULL; size_t body_len = 0; int spool_fd; if (!dir) dir = uspool->dir; if (!strncmp("uwsgi_spoolfile_on_", task, 19) || (uwsgi.spooler_ordered && is_a_number(task))) { struct stat sf_lstat; if (lstat(task, &sf_lstat)) { return; } // a spool request for the future if (sf_lstat.st_mtime > uwsgi_now()) { return; } #ifdef __linux__ if (S_ISDIR(sf_lstat.st_mode) && uwsgi.spooler_ordered) { if (chdir(task)) { uwsgi_error("chdir()"); return; } char *prio_path = realpath(".", NULL); spooler_scandir(uspool, prio_path); free(prio_path); if (chdir(dir)) { uwsgi_error("chdir()"); } return; } #endif if (!S_ISREG(sf_lstat.st_mode)) { return; } if (!access(task, R_OK | W_OK)) { spool_fd = open(task, O_RDWR); if (spool_fd < 0) { if (errno != ENOENT) uwsgi_error_open(task); return; } // check if the file is locked by another process if (uwsgi_fcntl_is_locked(spool_fd)) { uwsgi_protected_close(spool_fd); return; } // unlink() can destroy the lock !!! if (access(task, R_OK | W_OK)) { uwsgi_protected_close(spool_fd); return; } ssize_t rlen = uwsgi_protected_read(spool_fd, &uh, 4); if (rlen != 4) { // it could be here for broken file or just opened one if (rlen < 0) uwsgi_error("read()"); uwsgi_protected_close(spool_fd); return; } #ifdef __BIG_ENDIAN__ uh.pktsize = uwsgi_swap16(uh.pktsize); #endif if (uwsgi_protected_read(spool_fd, spool_buf, uh.pktsize) != uh.pktsize) { uwsgi_error("read()"); destroy_spool(dir, task); uwsgi_protected_close(spool_fd); return; } // body available ? if (sf_lstat.st_size > (uh.pktsize+4)) { body_len = sf_lstat.st_size - (uh.pktsize+4); body = uwsgi_malloc(body_len); if ((size_t)uwsgi_protected_read(spool_fd, body, body_len) != body_len) { uwsgi_error("read()"); destroy_spool(dir, task); uwsgi_protected_close(spool_fd); free(body); return; } } // now the task is running and should not be waken up uspool->running = 1; if (!uwsgi.spooler_quiet) uwsgi_log("[spooler %s pid: %d] managing request %s ...\n", uspool->dir, (int) uwsgi.mypid, task); // chdir before running the task (if requested) if (uwsgi.spooler_chdir) { if (chdir(uwsgi.spooler_chdir)) { uwsgi_error("chdir()"); } } int callable_found = 0; for(i=0; i<256; i++) { if (uwsgi.p[i]->spooler) { time_t now = uwsgi_now(); if(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) { set_spooler_harakiri(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI]); } ret = uwsgi.p[i]->spooler(task, spool_buf, uh.pktsize, body, body_len); if(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) { set_spooler_harakiri(0); } if (ret == 0) continue; callable_found = 1; // increase task counter uspool->tasks++; if (ret == -2) { if (!uwsgi.spooler_quiet) uwsgi_log("[spooler %s pid: %d] done with task %s after %d seconds\n", uspool->dir, (int) uwsgi.mypid, task, uwsgi_now()-now); destroy_spool(dir, task); } // re-spool it break; } } if (body) free(body); // here we free and unlock the task uwsgi_protected_close(spool_fd); uspool->running = 0; if (chdir(dir)) { uwsgi_error("chdir()"); uwsgi_log("[spooler] something horrible happened to the spooler. Better to kill it.\n"); exit(1); } if (!callable_found) { uwsgi_log("unable to find the spooler function, have you loaded it into the spooler process ?\n"); } } } }
/* ** Return file count ** setvals==1 to set all values based on options ** ==2 to set only ansi, user interface, exit on complete ** ==0 to not set any values ** procfiles == 1 to process files ** == 0 to count files only */ int parse_cmd_args(K2PDFOPT_SETTINGS *k2settings,STRBUF *env,STRBUF *cmdline, STRBUF *usermenu,int setvals,int procfiles) { CMDLINEINPUT _cl,*cl; STRBUF *allopts,_allopts; int filecount,readnext; allopts=&_allopts; strbuf_init(allopts); strbuf_cpy(allopts,env->s); strbuf_cat(allopts,cmdline->s); strbuf_cat(allopts,usermenu->s); cl=&_cl; filecount=0; cmdlineinput_init(cl,0,NULL,allopts->s); readnext=1; while (1) { if (readnext && cmdlineinput_next(cl)==NULL) break; readnext=1; if (!stricmp(cl->cmdarg,"-?") || !stricmp(cl->cmdarg,"-?-")) { if (setvals==2) k2settings->show_usage = cl->cmdarg[2]=='-' ? 0 : 1; continue; } if (!stricmp(cl->cmdarg,"-a") || !stricmp(cl->cmdarg,"-a-")) { if (setvals>=1) ansi_set(cl->cmdarg[2]=='-' ? 0 : 1); continue; } if (!stricmp(cl->cmdarg,"-x") || !stricmp(cl->cmdarg,"-x-")) { if (setvals>=1) k2settings->exit_on_complete=(cl->cmdarg[2]=='-' ? 0 : 1); continue; } if (!strnicmp(cl->cmdarg,"-ui",3)) { if (setvals>=1) { if (cl->cmdarg[3]!='-') k2settings->query_user_explicit=1; k2settings->query_user=(cl->cmdarg[3]!='-') ? 1 : 0; } continue; } if (!stricmp(cl->cmdarg,"-evl")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->erase_vertical_lines=atoi(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-vls")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->vertical_line_spacing=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-vm")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { k2settings->vertical_multiplier=fabs(atof(cl->cmdarg)); if (k2settings->vertical_multiplier < 0.1) k2settings->vertical_multiplier = 0.1; } continue; } if (!stricmp(cl->cmdarg,"-vs")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->max_vertical_gap_inches=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-de")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->defect_size_pts=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-dev")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==2 && !strcmp(cl->cmdarg,"?")) { devprofiles_echo(stdout); k2sys_exit(k2settings,0); } if (setvals==1) { if (!k2pdfopt_settings_set_to_device(k2settings,devprofile_get(cl->cmdarg))) aprintf(TTEXT_WARN "\aDevice profile '%s' not known." TTEXT_NORMAL "\n",cl->cmdarg); } continue; } if (!stricmp(cl->cmdarg,"-pi") || !stricmp(cl->cmdarg,"-pi-")) { if (setvals==1) k2settings->preserve_indentation=(cl->cmdarg[3]=='-') ? 0 : 1; continue; } if (!strnicmp(cl->cmdarg,"-wrap",5)) { if (setvals==1) { k2settings->text_wrap=(cl->cmdarg[5]=='-') ? 0 : (cl->cmdarg[5]=='+' ? 2 : 1); if (k2settings->text_wrap) k2settings->use_crop_boxes=0; } continue; } #ifdef HAVE_MUPDF_LIB if (!stricmp(cl->cmdarg,"-gs") || !stricmp(cl->cmdarg,"-gs-") || !stricmp(cl->cmdarg,"-gs--")) { if (setvals==1) k2settings->user_usegs=(cl->cmdarg[3]=='-' ? (cl->cmdarg[4]=='-' ? -1 : 0) : 1); continue; } if (!stricmp(cl->cmdarg,"-n") || !stricmp(cl->cmdarg,"-n-")) { if (setvals==1) { k2settings->use_crop_boxes=(cl->cmdarg[2]=='-') ? 0 : 1; if (k2settings->use_crop_boxes) { k2settings->text_wrap=0; #ifdef HAVE_OCR_LIB k2settings->dst_ocr=0; #endif } } continue; } #endif if (!stricmp(cl->cmdarg,"-neg") || !stricmp(cl->cmdarg,"-neg-")) { if (setvals==1) k2settings->dst_negative=(cl->cmdarg[4]=='-') ? 0 : 1; continue; } if (!stricmp(cl->cmdarg,"-r") || !stricmp(cl->cmdarg,"-r-")) { if (setvals==1) k2settings->src_left_to_right=(cl->cmdarg[2]=='-') ? 1 : 0; continue; } if (!strnicmp(cl->cmdarg,"-hy",3)) { if (setvals==1) k2settings->hyphen_detect=(cl->cmdarg[3]=='-') ? 0 : 1; continue; } if (!strnicmp(cl->cmdarg,"-ls",3)) { if (setvals==1) k2settings->dst_landscape=(cl->cmdarg[3]=='-') ? 0 : 1; continue; } if (!stricmp(cl->cmdarg,"-mode")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { if (!stricmp(cl->cmdarg,"pdfr") || !stricmp(cl->cmdarg,"copy")) { /* -n- -wrap- -col 1 -vb -2 -w -1 -h -1 -dpi 150 -rt 0 -c -t- -f2p -2 */ /* -m 0 -om 0 -pl 0 -pr 0 -pt 0 -pb 0 -mc- */ k2settings->use_crop_boxes=0; k2settings->text_wrap=0; k2settings->max_columns=1; k2settings->vertical_break_threshold=-2; k2settings->dst_userwidth=-1.0; k2settings->dst_userwidth_units=UNITS_PIXELS; k2settings->dst_userheight=-1.0; k2settings->dst_userheight_units=UNITS_PIXELS; k2settings->dst_dpi=150; k2settings->src_rot=0.; k2settings->dst_color=1; k2settings->src_trim=0; k2settings->dst_fit_to_page=-2; k2settings->mar_left=k2settings->mar_top=k2settings->mar_right=k2settings->mar_bot=0.; k2settings->dst_mar=k2settings->dst_marleft=k2settings->dst_martop=k2settings->dst_marright=k2settings->dst_marbot=0.; k2settings->pad_left=k2settings->pad_top=k2settings->pad_bottom=k2settings->pad_right=0; k2settings->mark_corners=0; } else if (!stricmp(cl->cmdarg,"fw") || !stricmp(cl->cmdarg,"sopdf") || !stricmp(cl->cmdarg,"fitwidth")) { /* -wrap- -col 1 -vb -2 -t -ls */ k2settings->use_crop_boxes=1; k2settings->text_wrap=0; k2settings->max_columns=1; k2settings->vertical_break_threshold=-2; k2settings->src_trim=1; k2settings->dst_landscape=1; } else if (!stricmp(cl->cmdarg,"2col") || !stricmp(cl->cmdarg,"col2")) { k2settings->use_crop_boxes=1; k2settings->text_wrap=0; k2settings->max_columns=2; k2settings->vertical_break_threshold=-2; k2settings->src_trim=1; } else if (!stricmp(cl->cmdarg,"def") || !stricmp(cl->cmdarg,"default") || !stricmp(cl->cmdarg,"std") || !stricmp(cl->cmdarg,"standard")) { k2pdfopt_settings_set_to_device(k2settings,devprofile_get("k2")); k2settings->use_crop_boxes=1; k2settings->text_wrap=1; k2settings->max_columns=2; k2settings->vertical_break_threshold=1.75; k2settings->src_rot=SRCROT_AUTO; k2settings->src_trim=1; k2settings->dst_fit_to_page=0; k2settings->mar_left=k2settings->mar_top=k2settings->mar_right=k2settings->mar_bot=0.25; k2settings->dst_mar=k2settings->dst_marleft=k2settings->dst_martop=k2settings->dst_marright=k2settings->dst_marbot=0.02; } else aprintf(TTEXT_WARN "\a\n** Unknown mode: %s **\n\n" TTEXT_NORMAL, cl->cmdarg); } continue; } if (!stricmp(cl->cmdarg,"-o")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { strncpy(k2settings->dst_opname_format,cl->cmdarg,127); k2settings->dst_opname_format[127]='\0'; } continue; } if (!stricmp(cl->cmdarg,"-ow") || !stricmp(cl->cmdarg,"-ow-")) { int always_prompt; char *ptr; always_prompt = (cl->cmdarg[3]=='-'); if (((ptr=cmdlineinput_next(cl))==NULL) || !is_a_number(cl->cmdarg)) { readnext=0; if (setvals==1) k2settings->overwrite_minsize_mb= always_prompt ? 0 : -1; if (ptr==NULL) break; continue; } if (setvals==1) k2settings->overwrite_minsize_mb=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-grid")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { char buf[128]; double v[3]; int na,i; strncpy(buf,cl->cmdarg,127); buf[127]='\0'; k2settings->src_grid_order=0; for (i=0; buf[i]!='\0'; i++) { if (tolower(buf[i])=='x') buf[i]=' '; if (buf[i]=='+' && buf[i+1]=='\0') k2settings->src_grid_order=1; } na=string_read_doubles(buf,v,3); if (na>=2) { k2settings->src_grid_cols=(int)(v[0]+.5); k2settings->src_grid_rows=(int)(v[1]+.5); if (na>2) k2settings->src_grid_overlap_percentage=(int)(v[2]+.5); } else k2settings->src_grid_cols = k2settings->src_grid_rows = -1; if (k2settings->src_grid_cols>0 && k2settings->src_grid_rows>0) { k2settings->use_crop_boxes=1; k2settings->dst_fit_to_page=-2; k2settings->vertical_break_threshold=-2; k2settings->text_wrap=1; k2settings->max_columns=1; } } continue; } if (!stricmp(cl->cmdarg,"-f2p")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { k2settings->dst_fit_to_page=atoi(cl->cmdarg); if (k2settings->dst_fit_to_page == -2) k2settings->vertical_break_threshold=-2.; } continue; } if (!stricmp(cl->cmdarg,"-vb")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->vertical_break_threshold=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-sm") || !stricmp(cl->cmdarg,"-sm-")) { if (setvals==1) k2settings->show_marked_source=(cl->cmdarg[3]=='-' ? 0 : 1); continue; } if (!stricmp(cl->cmdarg,"-bp") || !stricmp(cl->cmdarg,"-bp-")) { if (cl->cmdarg[3]=='-') { if (setvals==1) k2settings->dst_break_pages=0; continue; } if (cmdlineinput_next(cl)==NULL) break; if (is_a_number(cl->cmdarg)) { if (setvals==1) k2settings->dst_break_pages= -1 - (int)(atof(cl->cmdarg)*1000.+.5); } else { if (setvals==1) k2settings->dst_break_pages=1; readnext=0; } continue; } if (!strnicmp(cl->cmdarg,"-fc",3)) { if (setvals==1) k2settings->fit_columns=(cl->cmdarg[3]=='-') ? 0 : 1; continue; } if (!stricmp(cl->cmdarg,"-d") || !stricmp(cl->cmdarg,"-d-")) { if (setvals==1) k2settings->dst_dither=(cl->cmdarg[2]=='-') ? 0 : 1; continue; } if (!stricmp(cl->cmdarg,"-c") || !stricmp(cl->cmdarg,"-c-")) { if (setvals==1) { k2settings->dst_color=(cl->cmdarg[2]=='-') ? 0 : 1; /* wrapbmp_set_color(k2settings->dst_color); */ } continue; } if (!strnicmp(cl->cmdarg,"-v",2)) { if (setvals==1) k2settings->verbose=(cl->cmdarg[2]=='-') ? 0 : 1; continue; } if (!strnicmp(cl->cmdarg,"-png",4)) { if (setvals==1) k2settings->jpeg_quality=(cl->cmdarg[4]=='-') ? 90 : -1; continue; } if (!strnicmp(cl->cmdarg,"-mc",3)) { if (setvals==1) k2settings->mark_corners=(cl->cmdarg[3]=='-') ? 0 : 1; continue; } if (!stricmp(cl->cmdarg,"-ocrlang") || !stricmp(cl->cmdarg,"-l")) { if (cmdlineinput_next(cl)==NULL) break; #ifdef HAVE_TESSERACT_LIB strncpy(k2settings->dst_ocr_lang,cl->cmdarg,15); k2settings->dst_ocr_lang[15]='\0'; #endif continue; } if (!stricmp(cl->cmdarg,"-ocrvis")) { if (cmdlineinput_next(cl)==NULL) break; #ifdef HAVE_OCR_LIB if (setvals==1) { k2settings->dst_ocr_visibility_flags=0; if (in_string(cl->cmdarg,"s")>=0) k2settings->dst_ocr_visibility_flags |= 1; if (in_string(cl->cmdarg,"t")>=0) k2settings->dst_ocr_visibility_flags |= 2; if (in_string(cl->cmdarg,"b")>=0) k2settings->dst_ocr_visibility_flags |= 4; } #endif continue; } if (!stricmp(cl->cmdarg,"-ocrhmax")) { if (cmdlineinput_next(cl)==NULL) break; #ifdef HAVE_OCR_LIB if (setvals==1) k2settings->ocr_max_height_inches=atof(cl->cmdarg); #endif continue; } if (!stricmp(cl->cmdarg,"-ocr") || !stricmp(cl->cmdarg,"-ocr-")) { #ifndef HAVE_OCR_LIB if (setvals==1) { static int warned=0; if (!warned) aprintf(TTEXT_WARN "\a\n** No OCR capability in this compile of k2pdfopt! **\n\n" TTEXT_NORMAL); warned=1; } #endif if (cl->cmdarg[4]=='-') { #ifdef HAVE_OCR_LIB if (setvals==1) k2settings->dst_ocr=0; #endif continue; } if (cmdlineinput_next(cl)==NULL || !stricmp(cl->cmdarg,"t")) { #ifdef HAVE_OCR_LIB if (setvals==1) { k2settings->dst_ocr='t'; k2settings->use_crop_boxes=0; } #endif continue; } if (!stricmp(cl->cmdarg,"g") || !stricmp(cl->cmdarg,"j")) { #ifdef HAVE_OCR_LIB if (setvals==1) { k2settings->dst_ocr='g'; k2settings->use_crop_boxes=0; } #endif continue; } #ifdef HAVE_OCR_LIB if (setvals==1) { #ifdef HAVE_TESSERACT_LIB k2settings->dst_ocr='t'; #else k2settings->dst_ocr='g'; #endif k2settings->use_crop_boxes=0; } #endif readnext=0; continue; } if (!stricmp(cl->cmdarg,"-t") || !stricmp(cl->cmdarg,"-t-")) { if (setvals==1) k2settings->src_trim=(cl->cmdarg[2]=='-') ? 0 : 1; continue; } if (!stricmp(cl->cmdarg,"-s") || !stricmp(cl->cmdarg,"-s-")) { if (setvals==1) k2settings->dst_sharpen=(cl->cmdarg[2]=='-') ? 0 : 1; continue; } if (!stricmp(cl->cmdarg,"-as")) { if (setvals==1) k2settings->src_autostraighten=4.; if (cmdlineinput_next(cl)==NULL) break; if (is_a_number(cl->cmdarg)) { if (setvals==1) k2settings->src_autostraighten=atof(cl->cmdarg); } else readnext=0; if (k2settings->src_autostraighten > 45.) k2settings->src_autostraighten = 45.; continue; } if (!stricmp(cl->cmdarg,"-rt")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { if (!stricmp(cl->cmdarg,"auto")) k2settings->src_rot=SRCROT_AUTO; else if (!stricmp(cl->cmdarg,"aep")) k2settings->src_rot=SRCROT_AUTOEP; else k2settings->src_rot=atoi(cl->cmdarg); } continue; } if (!stricmp(cl->cmdarg,"-crgh")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { k2settings->column_row_gap_height_in=atof(cl->cmdarg); if (k2settings->column_row_gap_height_in < 0.001) k2settings->column_row_gap_height_in = 0.001; } continue; } if (!stricmp(cl->cmdarg,"-cgr")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { k2settings->column_gap_range=atof(cl->cmdarg); if (k2settings->column_gap_range < 0.) k2settings->column_gap_range = 0.; if (k2settings->column_gap_range > 1.0) k2settings->column_gap_range = 1.0; } continue; } if (!stricmp(cl->cmdarg,"-comax")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { k2settings->column_offset_max=atof(cl->cmdarg); if (k2settings->column_offset_max > 1.0) k2settings->column_offset_max = 1.0; } continue; } if (!stricmp(cl->cmdarg,"-col")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { k2settings->max_columns=atoi(cl->cmdarg); if (k2settings->max_columns<1) k2settings->max_columns=1; if (k2settings->max_columns>2) k2settings->max_columns=4; } continue; } if (!strnicmp(cl->cmdarg,"-jpg",4) || !strnicmp(cl->cmdarg,"-jpeg",5)) { int ic; ic = (tolower(cl->cmdarg[3])=='g') ? 4 : 5; if (cl->cmdarg[ic]=='-') { if (setvals==1) k2settings->jpeg_quality=-1; } else { if (cmdlineinput_next(cl)==NULL) { if (setvals==1) k2settings->jpeg_quality=90; } else if (is_an_integer(cl->cmdarg)) { if (setvals==1) k2settings->jpeg_quality=atoi(cl->cmdarg); } else { readnext=0; if (setvals==1) k2settings->jpeg_quality=90; } } if (k2settings->jpeg_quality>100) k2settings->jpeg_quality=100; continue; } if (!stricmp(cl->cmdarg,"-col")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { k2settings->max_columns=atoi(cl->cmdarg); if (k2settings->max_columns<1) k2settings->max_columns=1; if (k2settings->max_columns>2) k2settings->max_columns=4; } continue; } if (!stricmp(cl->cmdarg,"-p")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { strncpy(k2settings->pagelist,cl->cmdarg,1023); k2settings->pagelist[1023]='\0'; } continue; } if (!stricmp(cl->cmdarg,"-bpc")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { k2settings->dst_bpc=atoi(cl->cmdarg); if (k2settings->dst_bpc>=6) k2settings->dst_bpc=8; else if (k2settings->dst_bpc>=3) k2settings->dst_bpc=4; else if (k2settings->dst_bpc<1) k2settings->dst_bpc=1; } continue; } if (!stricmp(cl->cmdarg,"-g")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { k2settings->dst_gamma=atof(cl->cmdarg); if (k2settings->dst_gamma<.01) k2settings->dst_gamma=.01; if (k2settings->dst_gamma>100.) k2settings->dst_gamma=100.; } continue; } if (!stricmp(cl->cmdarg,"-cg")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->min_column_gap_inches=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-cgmax")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->max_column_gap_inches=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-gtr")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { k2settings->gtr_in=atof(cl->cmdarg); if (k2settings->gtr_in<0.) k2settings->gtr_in=0.; } continue; } if (!stricmp(cl->cmdarg,"-gtc")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { k2settings->gtc_in=atof(cl->cmdarg); if (k2settings->gtc_in<0.) k2settings->gtc_in=0.; } continue; } if (!stricmp(cl->cmdarg,"-gtw")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { k2settings->gtw_in=atof(cl->cmdarg); if (k2settings->gtw_in<0.) k2settings->gtw_in=0.; } continue; } /* if (i<argc-1 && !stricmp(cl->cmdarg,"-cd")) { if (setvals==1) { cdthresh=atof(argv[++i]); if (cdthresh<0.) cdthresh=0.; else if (cdthresh>100.) cdthresh=100.; } else i++; continue; } */ if (!stricmp(cl->cmdarg,"-cmax")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->contrast_max=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-ch")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->min_column_height_inches=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-ds")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1 && atof(cl->cmdarg)>0.) k2settings->document_scale_factor=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-idpi")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1 && atof(cl->cmdarg)!=0.) k2settings->user_src_dpi=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-odpi") || !stricmp(cl->cmdarg,"-dpi")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->dst_dpi=atoi(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-jf")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->dst_figure_justify=atoi(cl->cmdarg); if (cmdlineinput_next(cl)==NULL) break; if (!is_a_number(cl->cmdarg)) { readnext=0; continue; } if (setvals==1) k2settings->dst_min_figure_height_in=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-j")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { k2settings->dst_justify=atoi(cl->cmdarg); if (in_string(cl->cmdarg,"+")>=0) k2settings->dst_fulljustify=1; else if (in_string(&cl->cmdarg[1],"-")>=0) k2settings->dst_fulljustify=0; else k2settings->dst_fulljustify=-1; } continue; } if (!stricmp(cl->cmdarg,"-dr")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->dst_display_resolution=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-h")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) set_value_with_units(cl->cmdarg,&k2settings->dst_userheight,&k2settings->dst_userheight_units); continue; } if (!stricmp(cl->cmdarg,"-ws")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->word_spacing=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-wt")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { k2settings->src_whitethresh=atoi(cl->cmdarg); if (k2settings->src_whitethresh>255) k2settings->src_whitethresh=255; } continue; } if (!stricmp(cl->cmdarg,"-w")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) set_value_with_units(cl->cmdarg,&k2settings->dst_userwidth,&k2settings->dst_userwidth_units); continue; } if (!stricmp(cl->cmdarg,"-omb")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->dst_marbot=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-omt")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->dst_martop=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-omr")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->dst_marright=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-oml")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->dst_marleft=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-om")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { double v[4]; int na; na=string_read_doubles(cl->cmdarg,v,4); if (na>=1) k2settings->dst_mar=k2settings->dst_marleft=k2settings->dst_martop=k2settings->dst_marright=k2settings->dst_marbot=v[0]; if (na>=2) k2settings->dst_martop=k2settings->dst_marright=k2settings->dst_marbot=v[1]; if (na>=3) k2settings->dst_marright=k2settings->dst_marbot=v[2]; if (na>=4) k2settings->dst_marbot=v[3]; } continue; } if (!stricmp(cl->cmdarg,"-mb")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->mar_bot=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-mt")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->mar_top=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-mr")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->mar_right=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-ml")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->mar_left=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-pb")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->pad_bottom=atoi(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-pt")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->pad_top=atoi(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-pr")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->pad_right=atoi(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-pl")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->pad_left=atoi(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-m")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) { double v[4]; int na; na=string_read_doubles(cl->cmdarg,v,4); if (na>=1) k2settings->mar_left=k2settings->mar_top=k2settings->mar_right=k2settings->mar_bot=v[0]; if (na>=2) k2settings->mar_top=k2settings->mar_right=k2settings->mar_bot=v[1]; if (na>=3) k2settings->mar_right=k2settings->mar_bot=v[2]; if (na>=4) k2settings->mar_bot=v[3]; } continue; } if (!strnicmp(cl->cmdarg,"-hq",3)) { if (setvals==1) continue; if (cl->cmdarg[3]=='-') { k2settings->dst_dpi=167; k2settings->user_src_dpi = -2.0; k2settings->dst_userwidth=DEFAULT_WIDTH; k2settings->dst_userwidth_units=UNITS_PIXELS; k2settings->dst_userheight=DEFAULT_HEIGHT; k2settings->dst_userheight_units=UNITS_PIXELS; } else { k2settings->dst_dpi=333; k2settings->user_src_dpi = -2.0; k2settings->dst_userwidth=DEFAULT_WIDTH*2; k2settings->dst_userheight=DEFAULT_HEIGHT*2; k2settings->dst_userwidth_units=UNITS_PIXELS; k2settings->dst_userheight_units=UNITS_PIXELS; } continue; } if (!stricmp(cl->cmdarg,"-debug")) { if (setvals==1) k2settings->debug=1; if (cmdlineinput_next(cl)==NULL) break; if (is_an_integer(cl->cmdarg)) { if (setvals==1) k2settings->debug=atoi(cl->cmdarg); } else readnext=0; continue; } /* ** UNDOCUMENTED COMMAND-LINE ARGS */ if (!stricmp(cl->cmdarg,"-whmax")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->no_wrap_height_limit_inches=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-arlim")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->no_wrap_ar_limit=atof(cl->cmdarg); continue; } if (!stricmp(cl->cmdarg,"-rwmin")) { if (cmdlineinput_next(cl)==NULL) break; if (setvals==1) k2settings->little_piece_threshold_inches=atof(cl->cmdarg); continue; } filecount++; /* if (filecount==1 && firstfile!=NULL) { strncpy(firstfile,cl->cmdarg,255); firstfile[255]='\0'; } */ if (procfiles) k2pdfopt_proc_wildarg(k2settings,cl->cmdarg); } strbuf_free(allopts); return(filecount); }
/* ========================================================================= */ struct options *ReadOptions(int argc, char *argv[]) { struct options *o; int index; int c; int postopts = 0; if ( NULL == (o = (struct options *)malloc(sizeof(struct options)))) { fprintf(stderr, "ERROR: Unable to allocate memory. Exiting.\n"); return(NULL); } set_opt_defaults(o); while ( -1 != ( c = getopt(argc, argv, ":+achHLmnstuv" ) ) ) { switch(c) { case '+': o->bDebug = 1; break; case 'a': o->bAbout = 1; break; case 'c': o->bCPUStats = 1; break; case 'h': o->bHelp = 1; break; case 'H': o->bHeader = 0; break; case 'L': o->bSkipLOC = 1; break; case 'm': o->bMonochrome = 1; break; case 'n': o->bNames = 0; break; case 's': o->bShortNames = 1; break; case 't': o->bTimestamp = 1; break; case 'u': o->bCollapse = 1; break; case ':': /* User forgot required argument */ o->bError = 1; fprintf (stderr, "ERROR: Missing the argument to the \"-%c\" option.\n", optopt); break; case '?': /* User entered some unknown/unsupported argument */ o->bError = 1; if (isprint (optopt)) fprintf (stderr, "ERROR: Unknown option \"-%c\".\n", optopt); else fprintf (stderr, "ERROR: Unknown option character `\\x%x'.\n", optopt); break; default: /* Really an unreachable place */ o->bError = 1; return(o); } } /* Read the non-flag options (the interval period) */ index = optind; while ( index < argc ) { if ( postopts ) { printf("Encountered this (extra) unhandled option: %s\n", argv[index]); return(NULL); } if ( is_a_number(argv[index]) ) { o->interval = atoi(argv[index]); postopts++; } else { printf("Option \"%s\" is not understood.\n", argv[index]); return(NULL); } index++; } /* Start validating user input */ if ( o->bError ) { fprintf(stderr, "ERROR: Problems parsing command line input.\n"); return(NULL); } if (( o->bAbout ) || ( o->bHelp )) { if (( o->bTimestamp ) || ( o->bCollapse ) || ( o->bMonochrome ) || ( 0 == o->bNames) || ( o->bSkipLOC ) || ( o->bShortNames ) || ( o->bCPUStats ) || ( o->bPivot ) || ( 0 == o->bHeader )) { fprintf(stderr, "NOTE: The -a and -h options are not compatible with other options.\n"); } /* No additional processing required if any of these are set */ return(o); } if ( o->bPivot ) { fprintf(stderr, "WARNING: The -p option is not implemented at this time.\n"); } if ( o->interval < 1 ) { fprintf(stderr, "ERROR: Invalid value for the sampling interval.\n"); return(NULL); } return(o); }
OpWithSeq *make_OpWithSeq_rec( const Op *op ) { if ( op->op_id == Op::current_op ) return reinterpret_cast<OpWithSeq *>( op->additional_info ); op->op_id = Op::current_op; // if ( op->type == Op::SYMBOL ) { OpWithSeq *res = new OpWithSeq( op->symbol_data()->cpp_name_str ); op->additional_info = reinterpret_cast<Op *>( res ); res->access_cost = op->symbol_data()->access_cost; res->nb_simd_terms = op->symbol_data()->nb_simd_terms; res->integer_type = op->integer_type; return res; } // if ( op->type == Op::NUMBER ) { OpWithSeq *res = OpWithSeq::new_number( op->number_data()->val ); op->additional_info = reinterpret_cast<Op *>( res ); res->integer_type = op->integer_type; return res; } // if ( op->type == STRING_add_NUM ) { SplittedVec<const Op *,32> sum; get_child_not_of_type_add( op, sum ); OpWithSeq *res = new OpWithSeq( op->type ); for(unsigned i=0;i<sum.size();++i) res->add_child( make_OpWithSeq_rec( sum[i] ) ); op->additional_info = reinterpret_cast<Op *>( res ); res->integer_type = op->integer_type; return res; } // if ( op->type == STRING_mul_NUM ) { SplittedVec<const Op *,32> mul; get_child_not_of_type_mul( op, mul ); bool want_neg = mul[0]->is_minus_one(); // std::vector<OpWithSeq *> ch; for(unsigned i=want_neg;i<mul.size();++i) { const Op *c = mul[i]; if ( c->type == STRING_pow_NUM and is_a_number( c->func_data()->children[1] ) and c->func_data()->children[1]->number_data()->val.is_integer() and c->func_data()->children[1]->number_data()->val.is_pos() ) { int a = int( c->func_data()->children[1]->number_data()->val ); for(int i=0;i<abs(a);++i) ch.push_back( make_OpWithSeq_rec( c->func_data()->children[0] ) ); } else ch.push_back( make_OpWithSeq_rec( mul[i] ) ); } // OpWithSeq *res = new_add_or_mul( STRING_mul_NUM, ch ); if ( want_neg ) res = new_neg( res ); op->additional_info = reinterpret_cast<Op *>( res ); res->integer_type = op->integer_type; return res; } // if ( op->type == STRING_pow_NUM and is_a_number( op->func_data()->children[1] ) and op->func_data()->children[1]->number_data()->val.is_integer() ) { OpWithSeq *res; int a = int( op->func_data()->children[1]->number_data()->val ); if ( a == -1 ) res = make_OpWithSeq_rec( op->func_data()->children[0] ); else { res = new OpWithSeq( STRING_mul_NUM ); for(int i=0;i<abs(a);++i) res->add_child( make_OpWithSeq_rec( op->func_data()->children[0] ) ); } // if ( a < 0 ) res = new_inv( res ); op->additional_info = reinterpret_cast<Op *>( res ); res->integer_type = op->integer_type; return res; } // // if ( op->type == STRING_select_symbolic_NUM ) { // OpWithSeq *res = new OpWithSeq( op->type ); // res->add_child( make_OpWithSeq_rec( op->func_data()->children[1] ) ); // op->additional_info = reinterpret_cast<Op *>( res ); // res->integer_type = op->integer_type; // return res; // } // OpWithSeq *res = new OpWithSeq( op->type ); for(unsigned i=0;i<Op::FuncData::max_nb_children and op->func_data()->children[i];++i) res->add_child( make_OpWithSeq_rec( op->func_data()->children[i] ) ); op->additional_info = reinterpret_cast<Op *>( res ); res->integer_type = op->integer_type; return res; }
arglex_token_ty arglex(void) { arglex_table_ty *tp; int j; arglex_table_ty *hit[20]; int nhit; char *arg; static char *pushback[3]; static int pushback_depth; trace(("arglex()\n{\n")); if (pushback_depth) { /* * the second half of a "-foo=bar" style argument. */ arg = pushback[--pushback_depth]; } else { if (argc <= 0) { arglex_token = arglex_token_eoln; arg = ""; goto done; } arg = argv[0]; argc--; argv++; /* * See if it looks like a GNU "-foo=bar" option. * Split it at the '=' to make it something the * rest of the code understands. */ if (arg[0] == '-' && arg[1] != '=') { char *eqp; eqp = strchr(arg, '='); if (eqp) { pushback[pushback_depth++] = eqp + 1; *eqp = 0; } } /* * Turn the GNU-style leading "--" * into "-" if necessary. */ if (arg[0] == '-' && arg[1] == '-' && arg[2] && !is_a_number(arg + 1)) ++arg; } /* * see if it is a number */ if (is_a_number(arg)) { arglex_token = arglex_token_number; goto done; } /* * scan the tables to see what it matches */ nhit = 0; partial = 0; for (tp = table; tp < ENDOF(table); tp++) { if (arglex_compare(tp->name, arg)) hit[nhit++] = tp; } if (utable) { for (tp = utable; tp->name; tp++) { if (arglex_compare(tp->name, arg)) hit[nhit++] = tp; } } /* * deal with unknown or ambiguous options */ switch (nhit) { case 0: /* * not found in the tables */ if (*arg == '-') arglex_token = arglex_token_option; else arglex_token = arglex_token_string; break; case 1: if (partial) pushback[pushback_depth++] = (char *)partial; arg = hit[0]->name; arglex_token = hit[0]->token; break; default: { string_ty *s1; string_ty *s2; sub_context_ty *scp; s1 = str_from_c(hit[0]->name); for (j = 1; j < nhit; ++j) { s2 = str_format("%s, %s", s1->str_text, hit[j]->name); str_free(s1); s1 = s2; } scp = sub_context_new(); sub_var_set_charstar(scp, "Name", arg); sub_var_set_string(scp, "Guess", s1); fatal_intl(scp, i18n("option \"$name\" ambiguous ($guess)")); /* NOTREACHED */ } } /* * here for all exits */ done: arglex_value.alv_string = arg; trace(("return %d; /* \"%s\" */\n", arglex_token, arg)); trace(("}\n")); return arglex_token; }
/* * * Get the next token from the input * */ int lex_get_token(LEX *lf, int expect) { int ch; int token = T_NONE; bool esc_next = false; /* Unicode files, especially on Win32, may begin with a "Byte Order Mark" to indicate which transmission format the file is in. The codepoint for this mark is U+FEFF and is represented as the octets EF-BB-BF in UTF-8 and as FF-FE in UTF-16le(little endian) and FE-FF in UTF-16(big endian). We use a distinct state for UTF-8 and UTF-16le, and use bom_bytes_seen to tell which byte we are expecting. */ int bom_bytes_seen = 0; Dmsg0(dbglvl, "enter lex_get_token\n"); while (token == T_NONE) { ch = lex_get_char(lf); switch (lf->state) { case lex_none: Dmsg2(dbglvl, "Lex state lex_none ch=%d,%x\n", ch, ch); if (B_ISSPACE(ch)) break; if (B_ISALPHA(ch)) { if (lf->options & LOPT_NO_IDENT || lf->options & LOPT_STRING) { lf->state = lex_string; } else { lf->state = lex_identifier; } begin_str(lf, ch); break; } if (B_ISDIGIT(ch)) { if (lf->options & LOPT_STRING) { lf->state = lex_string; } else { lf->state = lex_number; } begin_str(lf, ch); break; } Dmsg0(dbglvl, "Enter lex_none switch\n"); switch (ch) { case L_EOF: token = T_EOF; Dmsg0(dbglvl, "got L_EOF set token=T_EOF\n"); break; case '#': lf->state = lex_comment; break; case '{': token = T_BOB; begin_str(lf, ch); break; case '}': token = T_EOB; begin_str(lf, ch); break; case '"': lf->state = lex_quoted_string; begin_str(lf, 0); break; case '=': token = T_EQUALS; begin_str(lf, ch); break; case ',': token = T_COMMA; begin_str(lf, ch); break; case ';': if (expect != T_SKIP_EOL) { token = T_EOL; /* treat ; like EOL */ } break; case L_EOL: Dmsg0(dbglvl, "got L_EOL set token=T_EOL\n"); if (expect != T_SKIP_EOL) { token = T_EOL; } break; case '@': /* In NO_EXTERN mode, @ is part of a string */ if (lf->options & LOPT_NO_EXTERN) { lf->state = lex_string; begin_str(lf, ch); } else { lf->state = lex_include; begin_str(lf, 0); } break; case 0xEF: /* probably a UTF-8 BOM */ case 0xFF: /* probably a UTF-16le BOM */ case 0xFE: /* probably a UTF-16be BOM (error)*/ if (lf->line_no != 1 || lf->col_no != 1) { lf->state = lex_string; begin_str(lf, ch); } else { bom_bytes_seen = 1; if (ch == 0xEF) { lf->state = lex_utf8_bom; } else if (ch == 0xFF) { lf->state = lex_utf16_le_bom; } else { scan_err0(lf, _("This config file appears to be in an " "unsupported Unicode format (UTF-16be). Please resave as UTF-8\n")); return T_ERROR; } } break; default: lf->state = lex_string; begin_str(lf, ch); break; } break; case lex_comment: Dmsg1(dbglvl, "Lex state lex_comment ch=%x\n", ch); if (ch == L_EOL) { lf->state = lex_none; if (expect != T_SKIP_EOL) { token = T_EOL; } } else if (ch == L_EOF) { token = T_ERROR; } break; case lex_number: Dmsg2(dbglvl, "Lex state lex_number ch=%x %c\n", ch, ch); if (ch == L_EOF) { token = T_ERROR; break; } /* Might want to allow trailing specifications here */ if (B_ISDIGIT(ch)) { add_str(lf, ch); break; } /* A valid number can be terminated by the following */ if (B_ISSPACE(ch) || ch == L_EOL || ch == ',' || ch == ';') { token = T_NUMBER; lf->state = lex_none; } else { lf->state = lex_string; } lex_unget_char(lf); break; case lex_ip_addr: if (ch == L_EOF) { token = T_ERROR; break; } Dmsg1(dbglvl, "Lex state lex_ip_addr ch=%x\n", ch); break; case lex_string: Dmsg1(dbglvl, "Lex state lex_string ch=%x\n", ch); if (ch == L_EOF) { token = T_ERROR; break; } if (ch == '\n' || ch == L_EOL || ch == '=' || ch == '}' || ch == '{' || ch == '\r' || ch == ';' || ch == ',' || ch == '#' || (B_ISSPACE(ch)) ) { lex_unget_char(lf); token = T_UNQUOTED_STRING; lf->state = lex_none; break; } add_str(lf, ch); break; case lex_identifier: Dmsg2(dbglvl, "Lex state lex_identifier ch=%x %c\n", ch, ch); if (B_ISALPHA(ch)) { add_str(lf, ch); break; } else if (B_ISSPACE(ch)) { break; } else if (ch == '\n' || ch == L_EOL || ch == '=' || ch == '}' || ch == '{' || ch == '\r' || ch == ';' || ch == ',' || ch == '"' || ch == '#') { lex_unget_char(lf); token = T_IDENTIFIER; lf->state = lex_none; break; } else if (ch == L_EOF) { token = T_ERROR; lf->state = lex_none; begin_str(lf, ch); break; } /* Some non-alpha character => string */ lf->state = lex_string; add_str(lf, ch); break; case lex_quoted_string: Dmsg2(dbglvl, "Lex state lex_quoted_string ch=%x %c\n", ch, ch); if (ch == L_EOF) { token = T_ERROR; break; } if (ch == L_EOL) { esc_next = false; break; } if (esc_next) { add_str(lf, ch); esc_next = false; break; } if (ch == '\\') { esc_next = true; break; } if (ch == '"') { token = T_QUOTED_STRING; /* * Since we may be scanning a quoted list of names, * we get the next character (a comma indicates another * one), then we put it back for rescanning. */ lex_get_char(lf); lex_unget_char(lf); lf->state = lex_none; break; } add_str(lf, ch); break; case lex_include_quoted_string: if (ch == L_EOF) { token = T_ERROR; break; } if (esc_next) { add_str(lf, ch); esc_next = false; break; } if (ch == '\\') { esc_next = true; break; } if (ch == '"') { /* Keep the original LEX so we can print an error if the included file can't be opened. */ LEX* lfori = lf; /* Skip the double quote when restarting parsing */ lex_get_char(lf); lf->state = lex_none; lf = lex_open_file(lf, lf->str, lf->scan_error, lf->scan_warning); if (lf == NULL) { berrno be; scan_err2(lfori, _("Cannot open included config file %s: %s\n"), lfori->str, be.bstrerror()); return T_ERROR; } break; } add_str(lf, ch); break; case lex_include: /* scanning a filename */ if (ch == L_EOF) { token = T_ERROR; break; } if (ch == '"') { lf->state = lex_include_quoted_string; break; } if (B_ISSPACE(ch) || ch == '\n' || ch == L_EOL || ch == '}' || ch == '{' || ch == ';' || ch == ',' || ch == '"' || ch == '#') { /* Keep the original LEX so we can print an error if the included file can't be opened. */ LEX* lfori = lf; lf->state = lex_none; lf = lex_open_file(lf, lf->str, lf->scan_error, lf->scan_warning); if (lf == NULL) { berrno be; scan_err2(lfori, _("Cannot open included config file %s: %s\n"), lfori->str, be.bstrerror()); return T_ERROR; } break; } add_str(lf, ch); break; case lex_utf8_bom: /* we only end up in this state if we have read an 0xEF as the first byte of the file, indicating we are probably reading a UTF-8 file */ if (ch == 0xBB && bom_bytes_seen == 1) { bom_bytes_seen++; } else if (ch == 0xBF && bom_bytes_seen == 2) { token = T_UTF8_BOM; lf->state = lex_none; } else { token = T_ERROR; } break; case lex_utf16_le_bom: /* we only end up in this state if we have read an 0xFF as the first byte of the file -- indicating that we are probably dealing with an Intel based (little endian) UTF-16 file*/ if (ch == 0xFE) { token = T_UTF16_BOM; lf->state = lex_none; } else { token = T_ERROR; } break; } Dmsg4(dbglvl, "ch=%d state=%s token=%s %c\n", ch, lex_state_to_str(lf->state), lex_tok_to_str(token), ch); } Dmsg2(dbglvl, "lex returning: line %d token: %s\n", lf->line_no, lex_tok_to_str(token)); lf->token = token; /* * Here is where we check to see if the user has set certain * expectations (e.g. 32 bit integer). If so, we do type checking * and possible additional scanning (e.g. for range). */ switch (expect) { case T_PINT16: lf->u.pint16_val = (scan_pint(lf, lf->str) & 0xffff); lf->u2.pint16_val = lf->u.pint16_val; token = T_PINT16; break; case T_PINT32: lf->u.pint32_val = scan_pint(lf, lf->str); lf->u2.pint32_val = lf->u.pint32_val; token = T_PINT32; break; case T_PINT32_RANGE: if (token == T_NUMBER) { lf->u.pint32_val = scan_pint(lf, lf->str); lf->u2.pint32_val = lf->u.pint32_val; token = T_PINT32; } else { char *p = strchr(lf->str, '-'); if (!p) { scan_err2(lf, _("expected an integer or a range, got %s: %s"), lex_tok_to_str(token), lf->str); token = T_ERROR; break; } *p++ = 0; /* terminate first half of range */ lf->u.pint32_val = scan_pint(lf, lf->str); lf->u2.pint32_val = scan_pint(lf, p); token = T_PINT32_RANGE; } break; case T_INT16: if (token != T_NUMBER || !is_a_number(lf->str)) { scan_err2(lf, _("expected an integer number, got %s: %s"), lex_tok_to_str(token), lf->str); token = T_ERROR; break; } errno = 0; lf->u.int16_val = (int16_t)str_to_int64(lf->str); if (errno != 0) { scan_err2(lf, _("expected an integer number, got %s: %s"), lex_tok_to_str(token), lf->str); token = T_ERROR; } else { token = T_INT16; } break; case T_INT32: if (token != T_NUMBER || !is_a_number(lf->str)) { scan_err2(lf, _("expected an integer number, got %s: %s"), lex_tok_to_str(token), lf->str); token = T_ERROR; break; } errno = 0; lf->u.int32_val = (int32_t)str_to_int64(lf->str); if (errno != 0) { scan_err2(lf, _("expected an integer number, got %s: %s"), lex_tok_to_str(token), lf->str); token = T_ERROR; } else { token = T_INT32; } break; case T_INT64: Dmsg2(dbglvl, "int64=:%s: %f\n", lf->str, strtod(lf->str, NULL)); if (token != T_NUMBER || !is_a_number(lf->str)) { scan_err2(lf, _("expected an integer number, got %s: %s"), lex_tok_to_str(token), lf->str); token = T_ERROR; break; } errno = 0; lf->u.int64_val = str_to_int64(lf->str); if (errno != 0) { scan_err2(lf, _("expected an integer number, got %s: %s"), lex_tok_to_str(token), lf->str); token = T_ERROR; } else { token = T_INT64; } break; case T_PINT64_RANGE: if (token == T_NUMBER) { lf->u.pint64_val = scan_pint64(lf, lf->str); lf->u2.pint64_val = lf->u.pint64_val; token = T_PINT64; } else { char *p = strchr(lf->str, '-'); if (!p) { scan_err2(lf, _("expected an integer or a range, got %s: %s"), lex_tok_to_str(token), lf->str); token = T_ERROR; break; } *p++ = 0; /* terminate first half of range */ lf->u.pint64_val = scan_pint64(lf, lf->str); lf->u2.pint64_val = scan_pint64(lf, p); token = T_PINT64_RANGE; } break; case T_NAME: if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) { scan_err2(lf, _("expected a name, got %s: %s"), lex_tok_to_str(token), lf->str); token = T_ERROR; } else if (lf->str_len > MAX_RES_NAME_LENGTH) { scan_err3(lf, _("name %s length %d too long, max is %d\n"), lf->str, lf->str_len, MAX_RES_NAME_LENGTH); token = T_ERROR; } break; case T_STRING: if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) { scan_err2(lf, _("expected a string, got %s: %s"), lex_tok_to_str(token), lf->str); token = T_ERROR; } else { token = T_STRING; } break; default: break; /* no expectation given */ } lf->token = token; /* set possible new token */ return token; }
struct Tokens * tokenize(struct String file, struct Tokens *content){ assert(string_is_sane(&file)); int counter = 0; while (counter < file.length){ char c = file.body[counter]; if(c != ' ' && c != '\n'){ struct Token t = { .data = { .length = 0, .body = NULL } }; assert(string_is_sane(&t.data)); if(is_a_open_parens(c)){ t.type = 'o'; } else if(is_a_close_parens(c)){ t.type = 'c'; } else if(is_a_bracket(c)){ t.type = 'b'; } else if(is_a_end_bracket(c)){ t.type = 'e'; } else if(is_a_number(c)){ t.type = 'n'; while(is_a_number(c) || c == dot_const){ RESIZE(t.data.body, t.data.length+1); t.data.body[t.data.length] = file.body[counter]; t.data.length++; counter++; c = file.body[counter]; } RESIZE(t.data.body, t.data.length+1); t.data.body[t.data.length] = 0; assert(string_is_sane(&t.data)); counter--; } else if(is_a_quote(c)){ t.type = 's'; counter++; char s = file.body[counter]; while(!is_a_quote(s)){ RESIZE(t.data.body, t.data.length+1); t.data.body[t.data.length] = file.body[counter]; t.data.length++; counter++; s = file.body[counter]; } RESIZE(t.data.body, t.data.length+1); t.data.body[t.data.length] = 0; assert(string_is_sane(&t.data)); } else if(is_a_function(c)){ t.type = c; } else if(is_a_letter(c)){ t.type = 'k'; while(is_a_letter(c)){ RESIZE(t.data.body, t.data.length+1); t.data.body[t.data.length] = file.body[counter]; t.data.length++; counter++; c = file.body[counter]; } RESIZE(t.data.body, t.data.length+1); t.data.body[t.data.length] = 0; assert(string_is_sane(&t.data)); counter--; } content->tokens[content->length] = t; content->length++; } counter++; } return content; }
void spooler_manage_task(struct uwsgi_spooler *uspool, char *dir, char *task) { int i, ret; char spool_buf[0xffff]; struct uwsgi_header uh; char *body = NULL; size_t body_len = 0; int spool_fd; if (!dir) dir = uspool->dir; if (!strncmp("uwsgi_spoolfile_on_", task, 19) || (uwsgi.spooler_ordered && is_a_number(task))) { struct stat sf_lstat; if (lstat(task, &sf_lstat)) { return; } // a spool request for the future if (sf_lstat.st_mtime > uwsgi_now()) { return; } if (S_ISDIR(sf_lstat.st_mode) && uwsgi.spooler_ordered) { if (chdir(task)) { uwsgi_error("spooler_manage_task()/chdir()"); return; } #ifdef __UCLIBC__ char *prio_path = uwsgi_malloc(PATH_MAX); realpath(".", prio_path); #else char *prio_path = realpath(".", NULL); #endif spooler_scandir(uspool, prio_path); free(prio_path); if (chdir(dir)) { uwsgi_error("spooler_manage_task()/chdir()"); } return; } if (!S_ISREG(sf_lstat.st_mode)) { return; } if (!access(task, R_OK | W_OK)) { spool_fd = open(task, O_RDWR); if (spool_fd < 0) { if (errno != ENOENT) uwsgi_error_open(task); return; } if (uwsgi_spooler_read_header(task, spool_fd, &uh)) return; // access lstat second time after getting a lock // first-time lstat could be dirty (for example between writes in master) if (lstat(task, &sf_lstat)) { return; } if (uwsgi_spooler_read_content(spool_fd, spool_buf, &body, &body_len, &uh, &sf_lstat)) { destroy_spool(dir, task); return; } // now the task is running and should not be woken up uspool->running = 1; // this is used in cheap mode for making decision about who must die uspool->last_task_managed = uwsgi_now(); if (!uwsgi.spooler_quiet) uwsgi_log("[spooler %s pid: %d] managing request %s ...\n", uspool->dir, (int) uwsgi.mypid, task); // chdir before running the task (if requested) if (uwsgi.spooler_chdir) { if (chdir(uwsgi.spooler_chdir)) { uwsgi_error("spooler_manage_task()/chdir()"); } } int callable_found = 0; for (i = 0; i < 256; i++) { if (uwsgi.p[i]->spooler) { time_t now = uwsgi_now(); if (uwsgi.harakiri_options.spoolers > 0) { set_spooler_harakiri(uwsgi.harakiri_options.spoolers); } ret = uwsgi.p[i]->spooler(task, spool_buf, uh._pktsize, body, body_len); if (uwsgi.harakiri_options.spoolers > 0) { set_spooler_harakiri(0); } if (ret == 0) continue; callable_found = 1; // increase task counter uspool->tasks++; if (ret == -2) { if (!uwsgi.spooler_quiet) uwsgi_log("[spooler %s pid: %d] done with task %s after %lld seconds\n", uspool->dir, (int) uwsgi.mypid, task, (long long) uwsgi_now() - now); destroy_spool(dir, task); } // re-spool it break; } } if (body) free(body); // here we free and unlock the task uwsgi_protected_close(spool_fd); uspool->running = 0; // need to recycle ? if (uwsgi.spooler_max_tasks > 0 && uspool->tasks >= (uint64_t) uwsgi.spooler_max_tasks) { uwsgi_log("[spooler %s pid: %d] maximum number of tasks reached (%d) recycling ...\n", uspool->dir, (int) uwsgi.mypid, uwsgi.spooler_max_tasks); end_me(0); } if (chdir(dir)) { uwsgi_error("chdir()"); uwsgi_log("[spooler] something horrible happened to the spooler. Better to kill it.\n"); exit(1); } if (!callable_found) { uwsgi_log("unable to find the spooler function, have you loaded it into the spooler process ?\n"); } } } }