[sane-devel] Error while setting the mode option of HP ScanJet 6200C

Mohit Kumar Mohit Kumar <mohit.kumar@gmail.com>
Tue, 21 Jun 2005 10:47:02 +0530


Hi All,

I have the following code to display my SANE options:

void sane_display_options(SANE_Handle handle)
{
=09const SANE_Option_Descriptor* option;
=09int num_options;
=09int index =3D 0;
=09option =3D sane_get_option_descriptor(handle,index);
=09do =20
=09{
=09=09/* The option 0 value field would contain how many options are
available for the scanner chosen */
=09=09if(index !=3D 0)
=09=09{
=09=09=09printf("Option %d Name: %s",index, option->name);
=09=09=09switch(option->constraint_type)
=09=09=09{
=09=09=09=09case SANE_CONSTRAINT_NONE:
=09=09=09=09=09break;
=09=09=09=09case SANE_CONSTRAINT_RANGE:
=09=09=09=09=09printf("min:%d max:%d
quant:%d",option->constraint.range->min,option->constraint.range->max,optio=
n->constraint.range->quant);
=09=09=09=09=09break;
=09=09=09=09case SANE_CONSTRAINT_WORD_LIST:
=09=09=09=09=09{const int n =3D option->constraint.word_list[0];
=09=09=09=09=09for(int i =3D1; i<n+1; i ++)
=09=09=09=09=09=09printf(" %f",option->constraint.word_list[i]);
=09=09=09=09=09}
=09=09=09=09=09break;
=09=09=09=09case SANE_CONSTRAINT_STRING_LIST:
=09=09=09=09=09{
=09=09=09=09=09int i=3D0;
=09=09=09=09=09while(option->constraint.string_list[i])
=09=09=09=09=09{
=09=09=09=09=09=09printf(" %s",option->constraint.string_list[i++]);
=09=09=09=09=09}
=09=09=09=09=09}
=09=09=09=09=09break;
=09=09=09}
=09=09=09if(strcmp(option->name,"mode")=3D=3D0)
=09=09=09{
=09=09=09=09SANE_String mode =3D "Color";
=09=09=09=09SANE_Status status_loc =3D sane_control_option(handle, index,
SANE_ACTION_SET_VALUE,(SANE_String_Const*)mode,NULL);
=09=09=09=09if(status_loc =3D=3D SANE_STATUS_GOOD)
=09=09=09=09=09printf("Mode set correctly.");
=09=09=09}
=09=09=09if(strcmp(option->name,"mode")=3D=3D0)
=09=09=09{
=09=09=09=09SANE_String mode =3D "Grayscale";
=09=09=09=09SANE_Status status_loc =3D sane_control_option(handle, index,
SANE_ACTION_SET_VALUE,(SANE_String_Const*)mode,NULL);
=09=09=09=09if(status_loc =3D=3D SANE_STATUS_GOOD)
=09=09=09=09=09printf("Mode set correctly.");
=09=09=09}
=09=09=09if(strcmp(option->name,"depth")=3D=3D0)
=09=09=09{
=09=09=09=09SANE_String depth =3D "8";=20
=09=09=09=09SANE_Int info;
=09=09=09=09SANE_Status status_loc =3D sane_control_option(handle, index,
SANE_ACTION_SET_VALUE,(SANE_String_Const*)depth, &info);
=09=09=09=09printf("SANE CONTROL OPTION :%d",info);
=09=09=09=09if(status_loc =3D=3D SANE_STATUS_GOOD)
=09=09=09=09=09printf("Everything seems to be working ok.");
=09=09=09=09display_error_message(status_loc);
=09=09=09}=09
=09=09=09printf("\n");=09
=09=09}
=09=09option =3D sane_get_option_descriptor(handle, ++index);
=09}while(option!=3DNULL);
=09num_options =3D index;
}

However gdb throws an error in the second strcmp. I cannot understand
the reason why?

The following is the gdb output:

(gdb)
409                             if(strcmp(option->name,"mode")=3D=3D0)
(gdb)
411                                     SANE_String mode =3D "Color";
(gdb)
412                                     SANE_Status status_loc =3D
sane_control_option(handle, index,
SANE_ACTION_SET_VALUE,(SANE_String_Const*)mode,NULL);
(gdb)
413                                     if(status_loc =3D=3D SANE_STATUS_GO=
OD)
(gdb)
414                                             printf("Mode set correctly.=
");
(gdb)
416                             if(strcmp(option->name,"mode")=3D=3D0)
(gdb)
=20
Program received signal SIGSEGV, Segmentation fault.
0x42079408 in strcmp () from /lib/tls/libc.so.6
(gdb) p option->name
No symbol "option" in current context.
(gdb)


Can any one tell me what am i doing wrong here?

Thanks,
Mohit