Beispiel #1
0
/*
** Parses standard time format:  H[H]:M[M][:SS[.SSS]][AM|PM]
*/
int structtm_from_time(struct tm *date,char *time)

    {
    char buf[32];
    int am,pm,n,j;
    double secs;

    date->tm_hour=0;
    date->tm_min=0;
    date->tm_sec=0;
    strncpy(buf,time,31);
    buf[31]='\0';
    for (j=0;buf[j]!='\0';j++)
        if (buf[j]==':')
            buf[j]=' ';
    am=in_string(buf,"am");
    pm=in_string(buf,"pm");
    if (am>=0)
        buf[am]=buf[am+1]=' ';
    if (pm>=0)
        buf[pm]=buf[pm+1]=' ';
    n=sscanf(buf,"%d %d %lf",&date->tm_hour,&date->tm_min,&secs);
    date->tm_sec = (n>2) ? (int)secs : 0;
    if (am>=0 && date->tm_hour>0 && date->tm_hour<=12)
        date->tm_hour = (date->tm_hour==12) ? 0 : date->tm_hour;
    else if (pm>=0 && date->tm_hour>0 && date->tm_hour<=12)
        date->tm_hour = (date->tm_hour!=12) ? date->tm_hour+12 : date->tm_hour;
    return(0);
    }
Beispiel #2
0
/*
** Parses most date/time formats.  The key assumption is that the time
** part of the string is HH:MM[:SS.SS][am|pm] (i.e. has colons and no spaces,
** though it can have a space before the AM or PM.)
*/
int structtm_from_datetime(struct tm *date,char *datetime)

    {
    char buf[64];
    char time[64];
    int  i,p,i0,status;
    struct tm dt;

    date->tm_year=0;
    date->tm_mon=0;
    date->tm_mday=1;
    date->tm_hour=0;
    date->tm_min=0;
    date->tm_sec=0;

    /* Make temp copy of string */
    strncpy(buf,datetime,63);
    buf[63]='\0';

    /* Clean up string a bit */
    for (i=0;buf[i]!='\0';i++)
        if (buf[i]=='\t' || buf[i]==',')
            buf[i]=' ';
    clean_line(buf);

    /* First check for " am" or " pm" and remove preceding space if found. */
    while (1)
        {
        p=in_string(buf," am");
        if (p<0)
            p=in_string(buf," pm");
        if (p>=0)
            memmove(&buf[p],&buf[p+1],strlen(buf)-p);
        else
            break;
        }

    /* Now find string with colons (time string) */
    for (i=0;buf[i]!='\0' && buf[i]!=':';i++);
    /* If no colons found, assume it's a date only */
    if (buf[i]!=':')
        return(structtm_from_date(date,datetime));
    /* Put time into "time" */
    for (;i>=0 && buf[i]!=' ';i--);
    for (i++,i0=i;buf[i]!=' ' && buf[i]!='\0';i++)
        time[i-i0]=buf[i];
    time[i-i0]='\0';
    /* Remove time string from buf */
    memmove(&buf[i0-1],&buf[i],strlen(buf)-i+1);
    /* Parse time string */
    structtm_from_time(date,time);
    /* Parse date string */
    dt=(*date);
    status=structtm_from_date(date,buf);
    date->tm_hour = dt.tm_hour;
    date->tm_min = dt.tm_min;
    date->tm_sec = dt.tm_sec;
    return(status);
    }
DEVPROFILE *devprofile_get(char *name)

    {
    int i,i0,c;

    for (i0=i=c=0;devprof[i].width>0;i++)
        if (in_string(devprof[i].name,name)>=0 || in_string(devprof[i].alias,name)>=0)
            {
            c++;
            i0=i;
            }
    if (c==1)
        return(&devprof[i0]);
    return(NULL);
    }
Beispiel #4
0
/*
** Converts a string like "1,3,4,6,19-38,45-60" to an integer
** array sequence.
*/
int range_to_iarray(int *a,int maxsize,char *s)

    {
    char *p;
    static char nbuf[256];
    int n,i,i1,i2;

    for (n=0,p=strtok(s,", \t");p!=NULL && p[0]!='\0';p=strtok(NULL,", \t"))
        {
        i=in_string(p,"-");
        if (i<=0)
            {
            if (n<maxsize)
                a[n++]=atoi(p);  
            continue;
            }
        strcpy(nbuf,p);
        nbuf[i]='\0';
        i1=atoi(nbuf);
        i2=atoi(&nbuf[i+1]);
        for (i=i1;i<=i2;i++)
            {
            if (n<maxsize)
                a[n++]=i;
            }
        }
    return(n);
    }
Beispiel #5
0
/*
** Converts a string like "1,3,4,6,19-38,45-60" to a double precision
** array sequence.
*/
int range_to_darray(double *a,int maxsize,char *s)

    {
    char *p;
    static char nbuf[256];
    int n,i;
    double x,x1,x2;

    for (n=0,p=strtok(s,", \t");p!=NULL && p[0]!='\0';p=strtok(NULL,", \t"))
        {
        i=in_string(p,"-");
        if (i<=0)
            {
            if (n<maxsize)
                a[n++]=atof(p);
            continue;
            }
        strcpy(nbuf,p);
        nbuf[i]='\0';
        x1=atof(nbuf);
        x2=atof(&nbuf[i+1]);
        for (x=x1;x<=x2;x+=1.0)
            if (n<maxsize)
                a[n++]=x;
        }
    return(n);
    }
Beispiel #6
0
void strbuf_cat_with_quotes(STRBUF *sbuf,char *s)

    {
    if (s!=NULL && s[0]!='\0')
        {
        int q=0;
        strbuf_ensure(sbuf,(sbuf->s==NULL?0:strlen(sbuf->s))+strlen(s)+4);
        if (sbuf->s[0]!='\0')
            strcat(sbuf->s," ");
        q=(s[0]!='\"' && (in_string(s," ")>=0 || in_string(s,"\t")>=0));
        if (q)
            strcat(sbuf->s,"\"");
        strcat(sbuf->s,s);
        if (q)
            strcat(sbuf->s,"\"");
        }
    }
Beispiel #7
0
int main(void)
{
  int c;
  int state = NO_COMMENT;
  while ((c = getchar()) != EOF)
  {
    switch (state)
    {
    case NO_COMMENT:
      state = no_comment(c);
      break;
    case OPENING_SLASH:
      state = opening_slash(c);
      break;
    case C_COMMENT:
      state = c_comment(c);
      break;
    case CLOSING_STAR:
      state = closing_star(c);
      break;
    case LINE_COMMENT:
      state = line_comment(c);
      break;
    case IN_STRING:
      state = in_string(c);
      break;
    case IN_CHAR_LIT:
      state = in_char_lit(c);
      break;
    case STRING_ESCAPE:
      state = string_escape(c);
      break;
    case CHAR_LIT_ESCAPE:
      state = char_lit_escape(c);
      break;
    default:
      printf("error, unknown state: %d\n", state);
      return 1;
    }
  }
}
Beispiel #8
0
/*=============================================
 * value_to_list -- Convert string to word list
 *  str:     [IN]  input string to split up
 *  list:    [OUT] list of strings in name
 *  plen:    [OUT] #entries in list
 *  dlm:     [IN]  delimiter upon which to split str
 *===========================================*/
LIST
value_to_list (STRING str, INT *plen, STRING dlm)
{
	static STRING buf = NULL;
	static INT len0 = 0;
	STRING p, q, n;
	INT len, c, i, j;
	LIST list = create_list2(LISTDOFREE);

	if (!str || *str == 0)
		return list;
	if ((len = strlen(str)) > len0 - 2) {
		if (buf) stdfree(buf);
		buf = (STRING) stdalloc(len0 = len + 80);
	}
	strcpy(buf, str);
	buf[len + 1] = 0;
	p = buf;
	j = 1;
	while ((c = *p++)) {
		if (in_string(c, dlm)) {
			*(p - 1) = 0;
			j++;
		}
	}
	p = buf;
	for (i = 1;  i <= j;  i++) {
		n = p + strlen(p) + 1;
		while (chartype(c = *p++) == WHITE)
			;
		p--;
		q = p + strlen(p) - 1;
		while (q > p && chartype(*q) == WHITE)
			*q-- = 0;
		set_list_element(list, i, strsave(p), NULL);
		p = n;
	}
	*plen = j;
	return list;
}
Beispiel #9
0
void k2gui_cbox_set_pages_completed(int n,char *message)

    {
    char buf[MAXFILENAMELEN+80]; /* More room, v2.22 */
    int color;
    double progress;

    if (k2gui_cbox==NULL || !k2gui_cbox->converting)
        return;
    color=0xd0ffd0;
    if (k2gui_cbox->num_pages>0)
        progress=(double)n/k2gui_cbox->num_pages;
    else
        progress=0.;
    if (message==NULL)
        sprintf(buf,"%s: %d of %d pages completed.",k2gui_cbox->filename,n,k2gui_cbox->num_pages);
    else
        if (in_string(message,"cannot")>=0)
            {
            color=0xd0d0ff;
            progress=1.;
            }
    k2gui_cbox_update_progress_bar(1,progress,color,message==NULL?buf:message);
    }
Beispiel #10
0
void ocr_text_proc(char *s,int allow_spaces)

    {
    static char *word_swaps[] =
        {
        "neld","field",
        "_eld","field",
        "PaPeC","paper",
        "successrul","successful",
        "_or","for",
        "rrequency","frequency",
        "out_Ut","output",
        "_un","gun",
        "worh","work",
        "bene_t","benefit",
        "sign_cantly","significantly",
        "_oal","goal",
        ""
        };
    int i,j;

    if (!allow_spaces)
        {
        for (i=j=0;s[i]!='\0';i++)
            if (s[i]!=' ')
                {
                if (j!=i)
                    s[j]=s[i];
                j++;
                }
        s[j]='\0';
        }
    /* Specific word swaps */
    for (i=0;word_swaps[i][0]!='\0';i+=2)
        if (!strcmp(s,word_swaps[i]))
            {
            strcpy(s,word_swaps[i+1]);
            return;
            }

    /* Heuristic rules */

    /* Starting letter */
    if (s[0]=='T' && not_usually_after_T(s[1]))
        s[0]='I';
    else if (s[0]=='n' && not_usually_after_n(s[1]))
        {
        memmove(&s[2],&s[1],strlen(s)-1);
        s[0]='f';
        s[1]='i';
        }
    else if (s[0]=='l' && not_usually_after_l(s[1]))
        s[0]='i';
    else if (s[0]=='r' && not_usually_after_r(s[1]))
        s[0]='f';
    else if (s[0]=='h' && tolower(s[1])=='l')
        s[0]='k';
    /* I's and O's to 1's and 0's */
    if (strcmp(s,"OI") && strcmp(s,"O") && strcmp(s,"I"))
        {
        for (i=0;s[i]!='\0';i++)
            {
            if (s[i]!='I' && s[i]!='O' && (s[i]<'0' || s[i]>'9'))
                break;
            }
        if (s[i]=='\0')
            {
            for (i=0;s[i]!='\0';i++)
                {
                if (s[i]=='I')
                    s[i]='1';
                if (s[i]=='O')
                    s[i]='0';
                }
            }
        }
    /* Digits to letters */
    for (i=0;s[i]!='\0';i++)
        {
        if (s[i]>='0' && s[i]<='9' 
                      && (i==0 || (s[i-1]>='a' && s[i-1]<='z'))
                      && (s[i+1]=='\0' || (s[i+1]>='a' && s[i+1]<='z')))
            {
            if (s[i]=='1')
                s[i]='l';
            if (s[i]=='4')
                s[i]='u'; /* strange but true */
            }
        }
    /* Caps in the middle of lowercase letters */
    for (i=0;s[i]!='\0';i++)
        {
        if (i>0 && (s[i]>='A' && s[i]<='Z') 
                && (s[i-1]>='a' && s[i-1]<='z')
                && (s[i+1]>='a' && s[i+1]<='z'))
            {
            if (s[i]=='I')
                s[i]='l';
            else
                s[i]=tolower(s[i]);
            }
        }
    /* in_ to ing */
    while ((i=in_string(s,"in_"))>=0)
        s[i+2]='g';
    }
Beispiel #11
0
/*
** 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);
}
Beispiel #12
0
int in_value (FILE *stream, const char *format,...)
{
  static char *values=" .+-0123456789";
  
  char sub_format[16], modifier;
  char *string,*s;

  int len,flush,ExitCode;

  void *ref_ptr;
  
  va_list va;
  
  len=in_string (stream,&string,0);
  while (len && string[len-1]==' ')    string[--len]='\0';
  ExitCode=(len < 1 || string==NULL) ? IN_ERROR : 0;
  for (--len;!ExitCode && len>=0 ;len--)
    if (!strchr (values,string[len]))
        ExitCode=IN_ERROR;
  
  if (ExitCode)
  {
    if (string) free (string);
    return ExitCode;
  }
  
  va_start(va,format);

  len=flush=0; modifier=' '; s=string; 
  while (*format!='\0' && *s!='\0' && len+1<16)
  {
          
    sub_format[len++]=*format;
    
    if (strchr ("hlL",*format))
    {
      //
      // Modifier
      //
      modifier=*format;
      //
    }
    if (strchr("din",*format))
    {
      //
      //  Type  int *
      //
      if (modifier=='h')
        ref_ptr=(short int *)           va_arg(va,short int *);
      if (modifier=='l')
        ref_ptr=(long int *)            va_arg(va,long int *);
      else
        ref_ptr=(int *)va_arg(va,int *);
      
      flush=1;
    }
    if (strchr("oux",*format))
    {
      //
      //  Type  unsigned int *
      //
      if (modifier=='h')
        ref_ptr=(unsigned short *)      va_arg(va,unsigned short *);
      if (modifier=='l')
        ref_ptr=(long unsigned int *)   va_arg(va,long unsigned int *);
      else
        ref_ptr=(unsigned int *)        va_arg(va,unsigned int *);
      
      flush=1;
    }
Beispiel #13
0
void wsys_system_version(char *system,char *_os,char *_chip,char *_compiler)

    {
    char compiler_version[80],compname[100];
    int     ccode,oscode,chipcode;
    static char *compiler[] = {"Unknown C compiler","Watcom C","Gnu C",
                               "HPUX ANSI C","Sun C","Cray C","Turbo C",
                               "Microsoft Visual C++","Gnu C (DJGPP)",
                               "Gnu C (RSXNT/EMX)","Intel C/C++","HPUX C++",
                               "Digital Mars C/C++","LCC","Watcom C/C++",
                               "Borland C/C++","Gnu C (Mingw32)",
                               "Intel C++ for Linux","Gnu C (Mingw64)","Tiny CC"};
    static char *os[] = {"Unknown O/S","Unix","VMS","Unicos","SunOS","HPUX",
                         "MS-DOS","Win32","MS-DOS (32-bit)","OS/X",
                         "Linux","SuSE Linux","Win64"};
    static char *chip[] = {"Unknown architecture","CRAY2","CRAY","hppa 1.0",
                           "hppa 1.1","sparc","i386","hppa 2.0","PPC","x64"};

    ccode=0;
    oscode=0;
    chipcode=0;
    compiler_version[0]='\0';

    /* O/S's (more general) */
#if (defined(UNIX))
    oscode=1;
#elif (defined(__vax__) || defined(__vax) || defined(__vms))
    oscode=2;
#endif

    /* Specific O/S's */
#if (defined(WIN64))
    oscode=12;
#elif (defined(WIN32))
    if (wsys_win32_api())
        oscode=7;
    else
        oscode=8;
    chipcode=6;
#elif (defined(MSDOS32))
    oscode=8;
    chipcode=6;
#elif (defined(MSDOS))
    oscode=6;
    chipcode=6;
#elif (defined(__linux) && defined(__VERSION__))
    if (in_string(__VERSION__,"SuSE")>=0)
        oscode=11;
    else
        oscode=10;
#elif (defined(__linux))
    oscode=10;
#elif (defined(__sun) || defined(sun))
    oscode=4;
    ccode=4;
#elif (defined(hpux) || defined(__hpux))
    ccode=3;
    oscode=5;
    ccode=3;
#if (defined(__cplusplus))
    ccode=11;
#endif
#elif (defined(_CRAY))
    ccode=5;
    oscode=3;
    chipcode=2;
#elif (defined(_CRAY2))
    ccode=5;
    oscode=3;
    chipcode=1;
#elif (defined(__ppc__) || defined(__MACH__))
    oscode=9;
#endif

    /* Specific chips */
#if (defined(i386) || defined(__i386__) || defined(__i386) || defined(__386__) || defined(_M_IX86))
    chipcode=6;
#elif (defined(__x86_64) || defined(__amd64__))
    chipcode=9;
#elif (defined(__sparc) || defined(sparc))
    chipcode=5;
#elif (defined(_PA_RISC1_1))
    chipcode=4;
#elif (defined(_PA_RISC2_0))
    chipcode=7;
#elif (defined(__ppc__))
    chipcode=8;
#endif

    /* Specific compilers */
#if (defined(__DMC__))
    ccode=12;
    sprintf(compiler_version,"v%d.%d",((__DMC__ &0xf00)>>8),((__DMC__ &0xf0)>>4));
#elif (defined(__LCC__))
    ccode=13;
    strcpy(compiler_version,"3.7");
#elif (defined(__BORLANDC__))
    ccode=15;
    sprintf(compiler_version,"v%d.%d.%d",
             (__BORLANDC__ >> 8)&0xf,
             (__BORLANDC__ >> 4)&0xf,
             (__BORLANDC__ )&0xf);
#elif (defined(__WATCOMC__))
    ccode=14;
    sprintf(compiler_version,"%.2f",(double)__WATCOMC__/100.);
#elif (defined(DJGPP))
    ccode=8;
    gnu_compiler(compiler_version);
#elif (defined(__MINGW64__))
    ccode=18;
    gnu_compiler(compiler_version);
#elif (defined(__MINGW32__))
    ccode=16;
    gnu_compiler(compiler_version);
#elif (defined(EMX))
    ccode=9;
    gnu_compiler(compiler_version);
#elif (defined(__GNUC__))
    ccode=2;
    gnu_compiler(compiler_version);
#elif (defined(__TURBOC__))
    ccode=6;
#elif (defined(__ICL))
    ccode=10;
    sprintf(compiler_version,"v%4.2f",__ICL/100.);
#elif (defined(_MSC_VER))
    ccode=7;
    sprintf(compiler_version,"v%4.2f",_MSC_VER/100.-6.0);
#elif (defined(__386__))
    ccode=1;
#elif (defined(__TINYC__))
    ccode=19;
    compiler_version[0]='\0';
#elif (defined(__INTEL_COMPILER))
#if (defined(__linux__))
    ccode=17;
#else
    ccode=10;
#endif
    sprintf(compiler_version,"v%4.2f",__INTEL_COMPILER/100.);
#endif

    if (compiler_version[0]!='\0')
        sprintf(compname,"%s %s",compiler[ccode],compiler_version);
    else
        strcpy(compname,compiler[ccode]);
    if (system!=NULL)
        sprintf(system,"%s, %s, %s",os[oscode],chip[chipcode],compname);
    if (_os!=NULL)
        strcpy(_os,os[oscode]);
    if (_chip!=NULL)
        strcpy(_chip,chip[chipcode]);
    if (_compiler!=NULL)
        strcpy(_compiler,compname);
    }
int main()
{
    int input[MAX_INPUT_LENGTH];
    init_input_buffer(input);
    read_input(input);

    literal_state = NOT_IN_LITERAL;
    comment_state = NOT_IN_COMMENT;
    current_char = '\0';
    next_char = '\0';

    int line_number = 1;
    int char_number = 0;

    int num_parens = 0;
    int num_brackets = 0;
    int num_braces = 0;

    bool string_escaped = false;
    bool char_escaped = false;

    for (int i = 0; input[i] != '\0' && i < MAX_INPUT_LENGTH; ++i)
    {
        current_char = input[i];
        next_char = ((i == MAX_INPUT_LENGTH - 1) ? '\0' : input[i + 1]);

        ++char_number;

        if (current_char == '\n')
        {
            ++line_number;
            char_number = 0;
            continue;
        }

        if (in_code())
        {
            if (start_of_single_line_comment())
            {
                comment_state = IN_SINGLE_LINE_COMMENT;
            }
            else if (start_of_multi_line_comment())
            {
                comment_state = IN_MULTI_LINE_COMMENT;
            }
            else if (current_char == OPEN_PARENTHESIS)
            {
                ++num_parens;
            }
            else if (current_char == CLOSE_PARENTHESIS)
            {
                --num_parens;
                print_error_ln_if(line_number, char_number, "too many closing parentheses", num_parens < 0);
            }
            else if (current_char == OPEN_BRACE)
            {
                ++num_braces;
            }
            else if (current_char == CLOSE_BRACE)
            {
                --num_braces;
                print_error_ln_if(line_number, char_number, "too many closing braces", num_braces < 0);
            }
            else if (current_char == OPEN_BRACKET)
            {
                ++num_brackets;
            }
            else if (current_char == CLOSE_BRACKET)
            {
                --num_brackets;
                print_error_ln_if(line_number, char_number, "too many closing brackets", num_brackets < 0);
            }
            else if (current_char == '\"')
            {
                literal_state = IN_STRING;
            }
            else if (current_char == '\'')
            {
                literal_state = IN_CHARACTER;
            }
        }
        else if (in_single_line_comment())
        {
            if (current_char == '\n')
            {
                comment_state = NOT_IN_COMMENT;
            }
        }
        else if (in_multi_line_comment())
        {
            if (end_of_multi_line_comment())
            {
                comment_state = NOT_IN_COMMENT;
            }
        }
        else if (in_string())
        {
            if (current_char == '\\')
            {
                string_escaped = !string_escaped;
            }
            else if (current_char == '\"' && !string_escaped)
            {
                literal_state = NOT_IN_LITERAL;
            }
        }
        else if (in_character())
        {
            if (current_char == '\\')
            {
                char_escaped = !char_escaped;
            }
            else if (current_char == '\'' && !char_escaped)
            {
                literal_state = NOT_IN_LITERAL;
            }
        }
    }

    print_error_if("parentheses are not balanced", num_parens != 0);
    print_error_if("braces are not balanced", num_braces != 0);
    print_error_if("brackets are not balanced", num_brackets != 0);

    return 0;
}