コード例 #1
0
ファイル: sfs_err.C プロジェクト: gildafnai82/craq
const strbuf &
strbuf_cat (const strbuf &sb, sfsstat err)
{
  switch (err) {
  case SFS_REDIRECT:
    return strbuf_cat (sb, "hostname or public key has changed", false);
  default:
    return strbuf_cat (sb, nfsstat3 (err));
  }
}
コード例 #2
0
ファイル: board_rss.c プロジェクト: d-torrance/wmcoincoin
/* pinaise j'en ai marre de faire ce genre de fonctions */
char* rss_nettoie_la_soupe_de_tags(char *src) {
  strbuf sb; strbuf_init(&sb, "");
  char *p, *p2;
  while (src[0]) {
    int skip;
    skip = 0;
    if (*src == '\t') {
      p = src+1;
      if (*p == '<') {
        p++;
        while (*p && (isspace(*p) || *p == '/')) ++p;
        p2 = p;
        while (*p2 && !isspace(*p2) && *p2 != '/' && *p2 != '>') ++p2;
        if (*p2) {
          if ((strncasecmp(p, "br", 2)==0 && p2-p == 2) ||
              (strncasecmp(p, "p", 1)==0 && p2-p == 1) ||
              (strncasecmp(p, "div", 3)==0 && p2-p == 3) ||
              (strncasecmp(p, "table", 5)==0 && p2-p == 5) ||
              (strncasecmp(p, "tr", 2)==0 && p2-p == 2) ||
              (strncasecmp(p, "td", 2)==0 && p2-p == 2)) {
            skip = 1;
          } else if (strncasecmp(p, "img", 3)==0 && p2 - p == 3) {            
            char *ps, *pe;
            //printf("img tag here : %.50s\n", p);
            ps = str_case_str(p, "src=");
            pe = strstr(p, "\t>");
            if (ps && pe && ps < pe) {
              ps += 4;
              while (*ps && (isspace(*ps) || *ps == '"' || *ps == '\'')) ++ps;
              if (*ps) {                
                strbuf_cat(&sb, "\t<a href=\"./");
                while (*ps && *ps != '"' && *ps != '\'' && *ps != '\t' && !isspace(*ps)) 
                  strbuf_putc(&sb,*ps++);
                strbuf_cat(&sb, "\"\t><img>\t</a\t>");
                //printf("sbuff = %s\n", sb.str);
              }
            }
            ++p; skip = 1;
          }
        }
      }
      if (skip) {
        p = strchr(src+1,'\t'); 
        if (p) { src = p+1; if (*src) src++; strbuf_putc(&sb, ' '); }
        else { return sb.str; }
      }
    }
    if (!skip) strbuf_putc(&sb, *src++);
  }
  return sb.str;
  //*dest = 0;
}
コード例 #3
0
ファイル: poly.C プロジェクト: gildafnai82/craq
const strbuf & 
strbuf_cat (const strbuf &sb, const polynomial &P)
{
  const vec<bigint> coeffs = P.coefficients ();
  size_t len = coeffs.size ();
  if (!len)
    return sb;

  for (size_t i=0; i < len-1; i++) {
    strbuf_cat (sb, coeffs[i]);
    strbuf_cat (sb, ",");
  }
  return strbuf_cat (sb, coeffs[len-1]);
}
コード例 #4
0
ファイル: strbuf.c プロジェクト: FauxFaux/k2pdfopt
void strbuf_dsprintf(STRBUF *sbuf,STRBUF *sbuf2,char *fmt,...)

    {
    static char *funcname="strbuf_dsprintf";

    if (sbuf!=NULL || sbuf2!=NULL)
        {
        va_list args;
        char *buf;

        willus_mem_alloc_warn((void **)&buf,1024,funcname,10);
        va_start(args,fmt);
        vsprintf(buf,fmt,args);
        va_end(args);
        if (sbuf!=NULL && sbuf2==NULL)
            strbuf_cat(sbuf,buf);
        if (sbuf2!=NULL)
            strbuf_cat(sbuf2,buf);
        willus_mem_free((double **)&buf,funcname);
        }
    }
コード例 #5
0
ファイル: str.C プロジェクト: Sidnicious/sfslite
const strbuf &
operator<< (const strbuf &sb, const char *a)
{
  return strbuf_cat (sb, a);
}
コード例 #6
0
ファイル: sfsro_err.C プロジェクト: gildafnai82/craq
const strbuf &
strbuf_cat (const strbuf &sb, sfsrostat err)
{
    return strbuf_cat (sb, err);
}
コード例 #7
0
ファイル: k2parsecmd.c プロジェクト: hanshenu/libk2pdfopt
/*
** 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);
}
コード例 #8
0
ファイル: sfs_err.C プロジェクト: gildafnai82/craq
const strbuf &
strbuf_cat (const strbuf &sb, sfsauth_stat status)
{
  switch (status) {
  case SFSAUTH_OK:
    return strbuf_cat (sb, "Authorization OK");
  case SFSAUTH_LOGINMORE:
    return strbuf_cat (sb, "Authorization login not sufficient yet");
  case SFSAUTH_FAILED:
    return strbuf_cat (sb, "Authorization failed");
  case SFSAUTH_LOGINALLBAD:
    return strbuf_cat (sb, "Authorization invalid login; don't try again");
  case SFSAUTH_NOTSOCK:
    return strbuf_cat (sb, "Authorization failed--can't conect via network");
  case SFSAUTH_BADUSERNAME:
    return strbuf_cat (sb, "Authorization failed--username not in password"
		       " file");
  case SFSAUTH_WRONGUID:
    return strbuf_cat (sb, "Authorization failed--uid doesn't match"
		       " username");
  case SFSAUTH_DENYROOT:
    return strbuf_cat (sb, "Authorization failed--Can't register root"
		       " account");
  case SFSAUTH_BADSHELL:
    return strbuf_cat (sb, "Authorization failed--shell is not in"
		       " /etc/shells");
  case SFSAUTH_DENYFILE:
    return strbuf_cat (sb, "Authorization failed--user explicitly denied");
  case SFSAUTH_BADPASSWORD:
    return strbuf_cat (sb, "Authorization failed--incorrect password");
  case SFSAUTH_USEREXISTS:
    return strbuf_cat (sb, "Authorization failed--user exists in auth"
		       " database");
  case SFSAUTH_NOCHANGES:
    return strbuf_cat (sb, "Authorization failed--no changes");
  case SFSAUTH_BADSIGNATURE:
    return strbuf_cat (sb, "Authorization failed--bad signature");
  case SFSAUTH_PROTOERR:
    return strbuf_cat (sb, "Authorization failed--protocol error");
  case SFSAUTH_NOTTHERE:
    return strbuf_cat (sb, "Authorization failed--not there");
  case SFSAUTH_BADAUTHID:
    return strbuf_cat (sb, "Authorization failed--bad auth ID");
  case SFSAUTH_KEYEXISTS:
    return strbuf_cat (sb, "Authorization failed--key exists");
  case SFSAUTH_BADKEYNAME:
    return strbuf_cat (sb, "Authorization failed--bad key name");
  default:
    return strbuf_cat (sb, "Unknown response from authserv");
  }
}
コード例 #9
0
ファイル: nfs3_err.C プロジェクト: bougyman/sfs
const strbuf &
strbuf_cat (const strbuf &sb, nfsstat3 err)
{
  switch (err) {
  case NFS3_OK:
    return strbuf_cat (sb, "no error", false);
  case NFS3ERR_BADHANDLE:
    return strbuf_cat (sb, "illegal file handle", false);
  case NFS3ERR_NOT_SYNC:
    return strbuf_cat (sb, "setattr synchronization failure", false);
  case NFS3ERR_BAD_COOKIE:
    return strbuf_cat (sb, "stale directory cookie", false);
  case NFS3ERR_NOTSUPP:
    return strbuf_cat (sb, strerror (EOPNOTSUPP), false);
  case NFS3ERR_TOOSMALL:
    return strbuf_cat (sb, "buffer or request too small", false);
  case NFS3ERR_SERVERFAULT:
    return strbuf_cat (sb, "generic server error", false);
  case NFS3ERR_BADTYPE:
    return strbuf_cat (sb, "file type not supported", false);
  case NFS3ERR_FPRINTNOTFOUND:
    return strbuf_cat (sb, "finger print not found", false);
  case NFS3ERR_JUKEBOX:
    return strbuf_cat (sb, "try again later", false);
  default:
    return strbuf_cat (sb, strerror (err));
  }
}
コード例 #10
0
ファイル: net_http.c プロジェクト: htc550605125/http-proxy
static int net_transfer_body_HTTP_1_1(struct conn* dst,
                             struct conn* src,
                             struct net_data* data) {
    if (strcmp(data->buf.p, "HEAD") == 0)
        return 0;
    
    int ret = 0;
    char* keyval = net_data_get_ent(data, "Transfer-Encoding");
    if (keyval == NULL || strcmp(keyval, "chunked")) {
        // Not chunked encoding
        keyval = net_data_get_ent(data, "Content-Length");
        int len = 0;
        if (keyval)
            len += atoi(keyval);
        if (len > 0) {
            ret = conn_copy(dst, src, len);
            if (ret)
                return ret;
        }
        return 0;
    }
    
    // Transfer-Encoding: chunked
    // FIXME HTTP rfc tells that proxy should forward decoded body
    struct strbuf buf;
    strbuf_init(&buf);
    while (1) {
        strbuf_reset(&buf);
        ret = conn_gets(src, HTTP_CHUNK_HEADER_MAXLEN, &buf);
        if (ret <= 0) {
            ret = -1;
            break;
        }
        
        strbuf_cat(&buf, "\r\n");
        ret = conn_write(dst, buf.p, buf.len);
        if (ret) {
            break;
        }
        
        int len = -1;
        sscanf(buf.p, "%x", &len);
        if (len == 0) {
            // Last chunck
            ret = 0;
            break;
        }
        
        // Also copy the \r\n
        ret = conn_copy(dst, src, len+2);
        if (ret)
            break;
    }
    if (ret == 0) {
        // Chunked trailer part
        while (1) {
            strbuf_reset(&buf);
            ret = conn_gets(src, HTTP_HEADER_MAXLEN, &buf);
            if (ret < 0)
                return ret;
            strbuf_cat(&buf, "\r\n");
            if (conn_write(dst, buf.p, buf.len)) {
                ret = -1;
                break;
            }
            if (ret == 0)
                break;
        }
    }
    strbuf_done(&buf);
    return ret;
}