int main(int argc,char * argv[]) {

  char *printer;
  char ppd_line[500],tmp[500],*p_tmp,tmp_n[10],tmp_op[500];
  FILE *fp_ppd;
  char *p;
  char *commandline,*ppdfile, *printer_model;
  int i,ii;
  DEBUGPRINT("main:start\n");

//  fprintf (stderr, "ERROR: brcupsconfpt1 pid=%d\n", getpid());
//  sleep(100);

  if(argc < 1){
    return 0;
  }
  printer = argv[1];
  if(argc > 2){
    ppdfile= argv[2];
  }
  else{
    ppdfile="";
  }
	

//	fprintf(stderr, "ERROR: pid=%d\n", getpid());
//	sleep(1000);

  if(argc > 3){
    if(argv[3][0] >= '0' && argv[3][0] <= '9'){

      log_level = argv[3][0] -'0';
    }
    else{
      log_level = 0;
    }
  }
  else{
    log_level = 0;
  }

  if(argc > 4){
    commandline = argv[4];
  }
  else{
    commandline = "NULL COMMAND LINE";
  }

	printer_model = argv[5];

  fp_ppd = fopen(ppdfile , "r");
  if( fp_ppd == NULL) return 0;


  initialize_command_list();




  //************************************
  //  set default setting
  //************************************

#if	0
  DEBUGPRINT("main:set default setting\n");
  write_log_file(5,"DEFAULT SETTING\n");  
  for ( i = 0; default_setting[i] != NULL; i ++){
    p = strstr_ex(default_setting[i],"BROTHERPRINTER_XXX");
    if(p){
      p = strchr(p,'-');
      if(p){
	add_command_list_brcommand(p);
      }
    }
  }
#endif	// 0

  //************************************
  //  set PPD option 
  //************************************


  DEBUGPRINT("main:set PPD option (string)\n");
  write_log_file(5,"PPD SETTING\n");

  while(fgets(ppd_line,sizeof(ppd_line),fp_ppd)){
    if(NULL == delete_ppd_comment(ppd_line))continue;
    if(NULL == chk_ppd_default_setting_line(ppd_line))continue;

    //************************************
    //  set PPD option (string)
    //************************************

	for ( i = 0; ppdcommand_all_list[i]!= NULL; i ++)
	{
      //DEBUGPRINT2(    "main: set PPD option (string)    [%s]  [%s]\n",
      //	      ppd_line,ppdcommand_all_list[i]->label);
		p = strstr_ex(ppd_line,ppdcommand_all_list[i]->label);
		if(p)
		{
	//DEBUGPRINT2(    "main: set PPD option (string)    [%s]  [%s]\n",
	//       ppdcommand_all_list[i]->label,ppd_line);
	
		#if 1		// Added by SteadyBJ, Guo Jianxin , 20080121
			char * tmp;
			tmp = p + strlen( ppdcommand_all_list[i]->label);
        #endif
			for (ii = 0; ppdcommand_all_list[i]->ppdcommandlist[ii].value != NULL; ii++)
			{
	  //DEBUGPRINT3(    "main: set PPD option (string)    [%s]  [%s]  [%s]\n",
	  //       ppdcommand_all_list[i]->label,ppdcommand_all_list[i]->ppdcommandlist[ii].value ,  ppd_line);
	  		#if 0        // Modified by SteadyBJ, Guo Jianxin , 20080121
				p = strstr_ex(ppd_line,ppdcommand_all_list[i]->ppdcommandlist[ii].value);
			#else
				p = strstr_ex(tmp,ppdcommand_all_list[i]->ppdcommandlist[ii].value);
			#endif



				if(p)
				{
					add_command_list_brcommand(ppdcommand_all_list[i]->ppdcommandlist[ii].brcommand);
					break;
				}
			}
		}
	}



    //************************************
    //  set PPD option (numerical)
    //************************************
    for ( i = 0; PPDdefaultN[i].option!= NULL; i ++){
      strcpy(tmp,PPDdefaultN[i].option);
      p_tmp = tmp;
      if(tmp[0] == '^')p_tmp ++;
      p = strstr_ex(ppd_line,p_tmp);
      if(p){
	//DEBUGPRINT2(    "main: set PPD option (numerical)    [%s]  [%s]\n",
	//       ppd_line,p_tmp);

	sprintf(tmp,"%s  %s",PPDdefaultN[i].value,
	       p + strlen(PPDdefaultN[i].option));
        //DEBUGPRINT1("set commandline option(n)   **********    : [%s]\n",tmp);

	get_token(PPDdefaultN[i].value ,tmp_op);
	get_token(p + strlen(PPDdefaultN[i].option) ,tmp_n);

	add_command_list(tmp_op,tmp_n);

      }
    }

  }



  //************************************
  //  set brother command line option (string)
  //************************************
  DEBUGPRINT("main:set brother command line option (string)\n");
  write_log_file(5,"BROTHER COMMAND LINE SETTING(S)\n");  
  for ( i = 0; commandlinelist[i].value != NULL; i ++){
    //DEBUGPRINT2("main:set command line option (string)    Loop [%s] [%s]\n",
    //       commandline,commandlinelist[i].value );
    p = strstr_ex(commandline,commandlinelist[i].option);
    if(p){
      add_command_list_brcommand(commandlinelist[i].value);
    }
  }







  //************************************
  //  set cups standard command line option (duplex)
  //************************************
  DEBUGPRINT("main:set standard command line option (duplex)\n");
  write_log_file(5,"STANDARD COMMAND LINE SETTING(DUPLEX)\n");  
  for ( i = 0; standard_side_commandlinelist[i].value != NULL; i ++){
    //DEBUGPRINT2("main:set command line option (duplex)    Loop [%s] [%s]\n",
    //       commandline,standard_side_commandlinelist[i].option );
    p = strstr_ex(commandline,standard_side_commandlinelist[i].option);
    if(p){

      add_command_list_brcommand(standard_side_commandlinelist[i].value);
    }


  }


  //************************************
  //  set cups standard command line option (media )
  //************************************
  DEBUGPRINT("main:set standard command line option (media)\n");
  write_log_file(5,"STANDARD COMMAND LINE SETTING(MEDIA)\n");  
  {
    char output[5][30];
    int max;

    max = divide_media_token(commandline,output);
    //DEBUGPRINT2("main:set command line option (media)    Loop count %d   %s \n",
    //         max,commandline);
    for ( ii=0; ii < max; ii++){
//      for ( i = 0; standard_media_commandlinelist[i].value != NULL; i ++){
		for ( i = 0; standard_commandlinelist[i].value != NULL; i ++){
		
	//DEBUGPRINT2("main:set command line option (media)    Loop [%s] [%s]\n",
	//	    output[ii],standard_media_commandlinelist[i].option);
			p = strstr(standard_commandlinelist[i].option, output[ii]);
			if(p){
				add_command_list_brcommand(standard_commandlinelist[i].value);
			}
		}
    	}
  }
  
  //************************************

  //  set command line option (numerical)
  //************************************
  DEBUGPRINT("main:set command line option (numerical)\n");
  write_log_file(5,"COMMAND LINE SETTING(N)\n");  

  for(i = 0; commandlinelist2[i].option != NULL; i ++){
    p = strstr_ex(commandline,commandlinelist2[i].option);
    //DEBUGPRINT3("set commandline option(n) : [%s] [%s] [%s]\n"
    //	,commandline,commandlinelist2[i].option,p);
    if(p){
      //DEBUGPRINT3("set commandline option(n) 1  **********  : [%s] [%s] [%s]\n"
      //	  ,tmp_n,p + strlen(commandlinelist2[i].option),p);
      get_token(commandlinelist2[i].value   ,tmp_op);
      get_token(p + strlen(commandlinelist2[i].option) ,tmp_n);
      sprintf(tmp,"%s  %s",tmp_op,tmp_n );
      //DEBUGPRINT2("set commandline option(n) 2  **********    : [%s] [%s]\n"
      //	  ,tmp_op,tmp_n);

      add_command_list(tmp_op,tmp_n);

    }
  }

  //************************************
  //  call brprintconf
  //************************************

	exec_brprintconf(brprintconf,printer_model);

	return 0;
}
int main(int argc,char * argv[]) {

  char *printer;
  char ppd_line[500],tmp[500],*p_tmp,tmp_n[10],tmp_op[500];
  FILE *fp_ppd;
  char *p;
  char *commandline,*ppdfile;
  int i,ii;

#ifdef  _CUSTOM_TAPE_
      TapeItem tapeitem;
#endif
  DEBUGPRINT("main:start\n");

//  fprintf (stderr, "ERROR: brcupsconfpt1 pid=%d\n", getpid());
//  sleep(100);

#ifdef _CUSTOM_TAPE_
	memset(&g_tapelist, 0, sizeof(TapeList));
	g_tapelist.iSelIndex = -1;
#endif

  if(argc < 1){
    return 0;
  }
  printer = argv[1];
  if(argc > 2){
    ppdfile= argv[2];
  }
  else{
    ppdfile="";
  }

//	fprintf(stderr, "ERROR: pid=%d\n", getpid());
//	sleep(1000);

  if(argc > 3){
    if(argv[3][0] >= '0' && argv[3][0] <= '9'){

      log_level = argv[3][0] -'0';
    }
    else{
      log_level = 0;
    }
  }
  else{
    log_level = 0;
  }

  if(argc > 4){
    commandline = argv[4];
  }
  else{
    commandline = "NULL COMMAND LINE";
  }
  fp_ppd = fopen(ppdfile , "r");
  if( fp_ppd == NULL) return 0;


  initialize_command_list();




  //************************************
  //  set default setting
  //************************************
  DEBUGPRINT("main:set default setting\n");
  write_log_file(5,"DEFAULT SETTING\n");  
  for ( i = 0; default_setting[i] != NULL; i ++){
    p = strstr_ex(default_setting[i],"BROTHERPRINTER_XXX");
    if(p){
      p = strchr(p,'-');
      if(p){
	add_command_list_brcommand(p);
      }
    }
  }


  //************************************
  //  set PPD option 
  //************************************


      DEBUGPRINT("main:set PPD option (string)\n");
      write_log_file(5,"PPD SETTING\n");
#ifdef  _CUSTOM_TAPE_
 //     TapeItem tapeitem;
       while(fgets(ppd_line,sizeof(ppd_line),fp_ppd))
	{
		if(NULL == delete_ppd_comment(ppd_line))
			continue;
		if( 1 == GetLabel_name_id(ppd_line, tapeitem.tape_name, tapeitem.tape_id) )
		{
			add_tape(&g_tapelist, tapeitem.tape_name, tapeitem.tape_id);
		}
	}
	rewind(fp_ppd);
#endif

	while(fgets(ppd_line,sizeof(ppd_line),fp_ppd)){
		if(NULL == delete_ppd_comment(ppd_line))continue;
    		if(NULL == chk_ppd_default_setting_line(ppd_line))continue;

    //************************************
    //  set PPD option (string)
    //************************************

		for ( i = 0; ppdcommand_all_list[i]!= NULL; i ++)
		{
      //DEBUGPRINT2(    "main: set PPD option (string)    [%s]  [%s]\n",
      //	      ppd_line,ppdcommand_all_list[i]->label);
			p = strstr_ex(ppd_line,ppdcommand_all_list[i]->label);
			if(p)
			{
	//DEBUGPRINT2(    "main: set PPD option (string)    [%s]  [%s]\n",
	//       ppdcommand_all_list[i]->label,ppd_line);
				for (ii = 0; ppdcommand_all_list[i]->ppdcommandlist[ii].value != NULL; ii++)
				{
	  //DEBUGPRINT3(    "main: set PPD option (string)    [%s]  [%s]  [%s]\n",
	  //       ppdcommand_all_list[i]->label,ppdcommand_all_list[i]->ppdcommandlist[ii].value ,  ppd_line);
					p = strstr_ex(ppd_line,ppdcommand_all_list[i]->ppdcommandlist[ii].value);
					if(p)
					{
						add_command_list_brcommand(ppdcommand_all_list[i]->ppdcommandlist[ii].brcommand);
						break;
					}
				}
#ifdef _CUSTOM_TAPE_
				if( strcmp(ppdcommand_all_list[i]->label, "DefaultPageSize") == 0 )
				{
					for( ii = 0; ii < g_tapelist.count; ii++ )
					{
						p = strstr_ex(ppd_line, g_tapelist.tapelist[ii].tape_id);
						if(p)
						{
							char lp[512];
							sprintf(lp, "-media %s", g_tapelist.tapelist[ii].tape_name);
							add_command_list_brcommand(lp);
							break;


						}
					}
				}
#endif
			}
		}



    //************************************
    //  set PPD option (numerical)
    //************************************
		for ( i = 0; PPDdefaultN[i].option!= NULL; i ++){
      			strcpy(tmp,PPDdefaultN[i].option);
      			p_tmp = tmp;
     			if(tmp[0] == '^')p_tmp ++;
      			p = strstr_ex(ppd_line,p_tmp);
     			if(p){
	//DEBUGPRINT2(    "main: set PPD option (numerical)    [%s]  [%s]\n",
	//       ppd_line,p_tmp);

				sprintf(tmp,"%s  %s",PPDdefaultN[i].value,
	       		p + strlen(PPDdefaultN[i].option));
        //DEBUGPRINT1("set commandline option(n)   **********    : [%s]\n",tmp);

				get_token(PPDdefaultN[i].value ,tmp_op);
				get_token(p + strlen(PPDdefaultN[i].option) ,tmp_n);

				add_command_list(tmp_op,tmp_n);

      			}	
		}
	}



  //************************************
  //  set brother command line option (string)
  //************************************
  DEBUGPRINT("main:set brother command line option (string)\n");
  write_log_file(5,"BROTHER COMMAND LINE SETTING(S)\n");  
  for ( i = 0; commandlinelist[i].value != NULL; i ++){
    //DEBUGPRINT2("main:set command line option (string)    Loop [%s] [%s]\n",
    //       commandline,commandlinelist[i].value );
    p = strstr_ex(commandline,commandlinelist[i].option);
    if(p){
      add_command_list_brcommand(commandlinelist[i].value);
    }
  }



  //************************************
  //  set cups standard command line option (duplex)
  //************************************
  DEBUGPRINT("main:set standard command line option (duplex)\n");
  write_log_file(5,"STANDARD COMMAND LINE SETTING(DUPLEX)\n");  
  for ( i = 0; standard_side_commandlinelist[i].value != NULL; i ++){
    //DEBUGPRINT2("main:set command line option (duplex)    Loop [%s] [%s]\n",
    //       commandline,standard_side_commandlinelist[i].option );
    p = strstr_ex(commandline,standard_side_commandlinelist[i].option);
    if(p){

      add_command_list_brcommand(standard_side_commandlinelist[i].value);

    }


  }


  //************************************
  //  set cups standard command line option (media )
  //************************************
  DEBUGPRINT("main:set standard command line option (media)\n");
  write_log_file(5,"STANDARD COMMAND LINE SETTING(MEDIA)\n");  
  {
    char output[5][30];
    int max;

    max = divide_media_token(commandline,output);
    //DEBUGPRINT2("main:set command line option (media)    Loop count %d   %s \n",
    //         max,commandline);
    for ( ii=0; ii < max; ii++){
//      for ( i = 0; standard_media_commandlinelist[i].value != NULL; i ++){
		for ( i = 0; standard_commandlinelist[i].value != NULL; i ++){
		
	//DEBUGPRINT2("main:set command line option (media)    Loop [%s] [%s]\n",
	//	    output[ii],standard_media_commandlinelist[i].option);
			p = strstr(standard_commandlinelist[i].option, output[ii]);
			if(p){
				add_command_list_brcommand(standard_commandlinelist[i].value);
			}
		}
#ifdef _CUSTOM_TAPE_
         	for ( i = 0; i < g_tapelist.count; i++)
		{
                    // modified by Liu Bin 2006.2.20	
			char lp[512];

			p = strstr(output[ii], g_tapelist.tapelist[i].tape_name);
			
			if(p)		// when the user uses the tool to set media
			{
				sprintf(lp, "-media \"%s\"", g_tapelist.tapelist[i].tape_name);
				add_command_list_brcommand(lp);
			}
			else 	
			{
				p = strstr(output[ii], g_tapelist.tapelist[i].tape_id);
				if(p) // when the printing system uses the tool to set media
				{
					sprintf(lp, "-media \"%s\"", g_tapelist.tapelist[i].tape_name);
					add_command_list_brcommand(lp);
				}
			}
		}
#endif		
    	}
  }
  
  //************************************

  //  set command line option (numerical)
  //************************************
  DEBUGPRINT("main:set command line option (numerical)\n");
  write_log_file(5,"COMMAND LINE SETTING(N)\n");  

  for(i = 0; commandlinelist2[i].option != NULL; i ++){
    p = strstr_ex(commandline,commandlinelist2[i].option);
    //DEBUGPRINT3("set commandline option(n) : [%s] [%s] [%s]\n"
    //	,commandline,commandlinelist2[i].option,p);
    if(p){
      //DEBUGPRINT3("set commandline option(n) 1  **********  : [%s] [%s] [%s]\n"
      //	  ,tmp_n,p + strlen(commandlinelist2[i].option),p);
      get_token(commandlinelist2[i].value   ,tmp_op);
      get_token(p + strlen(commandlinelist2[i].option) ,tmp_n);
      sprintf(tmp,"%s  %s",tmp_op,tmp_n );
      //DEBUGPRINT2("set commandline option(n) 2  **********    : [%s] [%s]\n"
      //	  ,tmp_op,tmp_n);

      add_command_list(tmp_op,tmp_n);

    }
  }

  //************************************
  //  call brprintconf
  //************************************

  exec_brprintconf(brprintconf,printer);

	return 0;
}
int main(int argc,char * argv[]) {
  char *printer;
  char ppd_line[500],tmp[500],*p_tmp,tmp_n[10],tmp_op[500];
  FILE *fp_ppd;
  char *p;
  char *commandline,*ppdfile;
  int i,ii;

  DEBUGPRINT("main:start\n");
  
  if(argc < 1){
    return 0;
  }
  printer = argv[1];
  if(argc > 2){
    ppdfile= argv[2];
  }
  else{
    ppdfile="";
  }
  if(argc > 3){
    if(argv[3][0] >= '0' && argv[3][0] <= '9'){
      log_level = argv[3][0] -'0';
    }
    else{
      log_level = 0;
    }
  }
  else{
    log_level = 0;
  }
  if(argc > 4){
    commandline = argv[4];
  }
  else{
    commandline = "NULL COMMAND LINE";
  }
  fp_ppd = fopen(ppdfile , "r");
  if( fp_ppd == NULL) return 0;


  initialize_command_list();




  DEBUGPRINT("main:set default setting\n");
  write_log_file(5,"DEFAULT SETTING\n");  
  for ( i = 0; default_setting[i] != NULL; i ++){
    p = strstr_ex(default_setting[i],"BROTHERPRINTER_XXX");
    if(p){
      p = strchr(p,'-');
      if(p){
	add_command_list_brcommand(p);
      }
    }
  }


  DEBUGPRINT("main:set PPD option (string)\n");
  write_log_file(5,"PPD SETTING\n");  
  while(fgets(ppd_line,sizeof(ppd_line),fp_ppd)){
    if(NULL == delete_ppd_comment(ppd_line))continue;
    if(NULL == chk_ppd_default_setting_line(ppd_line))continue;


    for ( i = 0; ppdcommand_all_list[i]!= NULL; i ++){
      p = strstr_ex(ppd_line,ppdcommand_all_list[i]->label);
      if(p){
	for (ii = 0; ppdcommand_all_list[i]->ppdcommandlist[ii].value != NULL; ii++){
	  p = strstr_ex(ppd_line,ppdcommand_all_list[i]->ppdcommandlist[ii].value);
	  if(p){
	    add_command_list_brcommand(ppdcommand_all_list[i]->ppdcommandlist[ii].brcommand);
	    break;
	  }
	}
      }
    }



    for ( i = 0; PPDdefaultN[i].option!= NULL; i ++){
      strcpy(tmp,PPDdefaultN[i].option);
      p_tmp = tmp;
      if(tmp[0] == '^')p_tmp ++;
      p = strstr_ex(ppd_line,p_tmp);
      if(p){

	sprintf(tmp,"%s  %s",PPDdefaultN[i].value,
	       p + strlen(PPDdefaultN[i].option));

	get_token(PPDdefaultN[i].value ,tmp_op);
	get_token(p + strlen(PPDdefaultN[i].option) ,tmp_n);

	add_command_list(tmp_op,tmp_n);

      }
    }

  }



  DEBUGPRINT("main:set brother command line option (string)\n");
  write_log_file(5,"BROTHER COMMAND LINE SETTING(S)\n");  
  for ( i = 0; commandlinelist[i].value != NULL; i ++){
    p = strstr_ex(commandline,commandlinelist[i].option);
    if(p){
      add_command_list_brcommand(commandlinelist[i].value);
    }
  }



  DEBUGPRINT("main:set standard command line option (duplex)\n");
  write_log_file(5,"STANDARD COMMAND LINE SETTING(DUPLEX)\n");  
  for ( i = 0; standard_side_commandlinelist[i].value != NULL; i ++){
    p = strstr_ex(commandline,standard_side_commandlinelist[i].option);
    if(p){
      add_command_list_brcommand(standard_side_commandlinelist[i].value);
    }
  }


  DEBUGPRINT("main:set standard command line option (media)\n");
  write_log_file(5,"STANDARD COMMAND LINE SETTING(MEDIA)\n");  
  {
    char output[5][30];
    int max;

    max = divide_media_token(commandline,output);
    for ( ii=0; ii < max; ii++){
      for ( i = 0; standard_media_commandlinelist[i].value != NULL; i ++){
	p = strstr_ex(output[ii],standard_media_commandlinelist[i].option);
	if(p){
	  add_command_list_brcommand(standard_media_commandlinelist[i].value);
	}
      }
    }
  }
  
  DEBUGPRINT("main:set command line option (numerical)\n");
  write_log_file(5,"COMMAND LINE SETTING(N)\n");  

  for(i = 0; commandlinelist2[i].option != NULL; i ++){
    p = strstr_ex(commandline,commandlinelist2[i].option);
    if(p){
      get_token(commandlinelist2[i].value   ,tmp_op);
      get_token(p + strlen(commandlinelist2[i].option) ,tmp_n);
      sprintf(tmp,"%s  %s",tmp_op,tmp_n );

      add_command_list(tmp_op,tmp_n);

    }
  }


  exec_brprintconf(brprintconf,printer);



}
int main(int argc , char **argv ) 
{ 
  char *printer ;
  char ppd_line[500] ;
  char tmp[500] ;
  char *p_tmp ;
  char tmp_n[10] ;
  char tmp_op[500] ;
  FILE *fp_ppd ;
  char *p ;
  char *commandline ;
  char *ppdfile ;
  char *printer_model ;
  int i ;
  int ii ;
  char *tmp___0 ;
  char *tmp___1 ;
  size_t tmp___2 ;
  size_t tmp___3 ;
  char *tmp___4 ;
  char output[5][30] ;
  int max ;
  size_t tmp___5 ;

  {
#line 93
  if (argc < 1) {
#line 94
    return (0);
  }
#line 96
  printer = *(argv + 1);
#line 97
  if (argc > 2) {
#line 98
    ppdfile = *(argv + 2);
  } else {
#line 101
    ppdfile = (char *)"";
  }
#line 108
  if (argc > 3) {
#line 109
    if ((int )*(*(argv + 3) + 0) >= 48) {
#line 109
      if ((int )*(*(argv + 3) + 0) <= 57) {
#line 111
        log_level = (int )*(*(argv + 3) + 0) - 48;
      } else {
#line 114
        log_level = 0;
      }
    } else {
#line 114
      log_level = 0;
    }
  } else {
#line 118
    log_level = 0;
  }
#line 121
  if (argc > 4) {
#line 122
    commandline = *(argv + 4);
  } else {
#line 125
    commandline = (char *)"NULL COMMAND LINE";
  }
  {
#line 128
  printer_model = *(argv + 5);
#line 130
  fp_ppd = fopen((char const   */* __restrict  */)ppdfile, (char const   */* __restrict  */)"r");
  }
#line 131
  if ((unsigned long )fp_ppd == (unsigned long )((void *)0)) {
#line 131
    return (0);
  }
  {
#line 134
  initialize_command_list();
#line 163
  write_log_file(5, (char *)"PPD SETTING\n");
  }
  {
#line 165
  while (1) {
    while_continue: /* CIL Label */ ;
    {
#line 165
    tmp___4 = fgets((char */* __restrict  */)(ppd_line), (int )sizeof(ppd_line), (FILE */* __restrict  */)fp_ppd);
    }
#line 165
    if (! tmp___4) {
#line 165
      goto while_break;
    }
    {
#line 166
    tmp___0 = delete_ppd_comment(ppd_line);
    }
#line 166
    if ((unsigned long )((void *)0) == (unsigned long )tmp___0) {
#line 166
      goto while_continue;
    }
    {
#line 167
    tmp___1 = chk_ppd_default_setting_line(ppd_line);
    }
#line 167
    if ((unsigned long )((void *)0) == (unsigned long )tmp___1) {
#line 167
      goto while_continue;
    }
#line 173
    i = 0;
    {
#line 173
    while (1) {
      while_continue___0: /* CIL Label */ ;
#line 173
      if (! ((unsigned long )ppdcommand_all_list[i] != (unsigned long )((void *)0))) {
#line 173
        goto while_break___0;
      }
      {
#line 177
      p = strstr_ex(ppd_line, (ppdcommand_all_list[i])->label);
      }
#line 178
      if (p) {
#line 182
        ii = 0;
        {
#line 182
        while (1) {
          while_continue___1: /* CIL Label */ ;
#line 182
          if (! ((unsigned long )(ppdcommand_all_list[i])->ppdcommandlist[ii].value != (unsigned long )((void *)0))) {
#line 182
            goto while_break___1;
          }
          {
#line 186
          p = strstr_ex(ppd_line, (ppdcommand_all_list[i])->ppdcommandlist[ii].value);
          }
#line 190
          if (p) {
            {
#line 192
            add_command_list_brcommand((ppdcommand_all_list[i])->ppdcommandlist[ii].brcommand);
            }
#line 193
            goto while_break___1;
          }
#line 182
          ii ++;
        }
        while_break___1: /* CIL Label */ ;
        }
      }
#line 173
      i ++;
    }
    while_break___0: /* CIL Label */ ;
    }
#line 204
    i = 0;
    {
#line 204
    while (1) {
      while_continue___2: /* CIL Label */ ;
#line 204
      if (! ((unsigned long )PPDdefaultN[i].option != (unsigned long )((void *)0))) {
#line 204
        goto while_break___2;
      }
      {
#line 205
      strcpy((char */* __restrict  */)(tmp), (char const   */* __restrict  */)PPDdefaultN[i].option);
#line 206
      p_tmp = tmp;
      }
#line 207
      if ((int )tmp[0] == 94) {
#line 207
        p_tmp ++;
      }
      {
#line 208
      p = strstr_ex(ppd_line, p_tmp);
      }
#line 209
      if (p) {
        {
#line 213
        tmp___2 = strlen((char const   *)PPDdefaultN[i].option);
#line 213
        sprintf((char */* __restrict  */)(tmp), (char const   */* __restrict  */)"%s  %s",
                PPDdefaultN[i].value, p + tmp___2);
#line 217
        get_token(PPDdefaultN[i].value, tmp_op);
#line 218
        tmp___3 = strlen((char const   *)PPDdefaultN[i].option);
#line 218
        get_token(p + tmp___3, tmp_n);
#line 220
        add_command_list(tmp_op, tmp_n);
        }
      }
#line 204
      i ++;
    }
    while_break___2: /* CIL Label */ ;
    }
  }
  while_break: /* CIL Label */ ;
  }
  {
#line 233
  write_log_file(5, (char *)"BROTHER COMMAND LINE SETTING(S)\n");
#line 234
  i = 0;
  }
  {
#line 234
  while (1) {
    while_continue___3: /* CIL Label */ ;
#line 234
    if (! ((unsigned long )commandlinelist[i].value != (unsigned long )((void *)0))) {
#line 234
      goto while_break___3;
    }
    {
#line 237
    p = strstr_ex(commandline, commandlinelist[i].option);
    }
#line 238
    if (p) {
      {
#line 239
      add_command_list_brcommand(commandlinelist[i].value);
      }
    }
#line 234
    i ++;
  }
  while_break___3: /* CIL Label */ ;
  }
  {
#line 253
  write_log_file(5, (char *)"STANDARD COMMAND LINE SETTING(DUPLEX)\n");
#line 254
  i = 0;
  }
  {
#line 254
  while (1) {
    while_continue___4: /* CIL Label */ ;
#line 254
    if (! ((unsigned long )standard_side_commandlinelist[i].value != (unsigned long )((void *)0))) {
#line 254
      goto while_break___4;
    }
    {
#line 257
    p = strstr_ex(commandline, standard_side_commandlinelist[i].option);
    }
#line 258
    if (p) {
      {
#line 260
      add_command_list_brcommand(standard_side_commandlinelist[i].value);
      }
    }
#line 254
    i ++;
  }
  while_break___4: /* CIL Label */ ;
  }
  {
#line 271
  write_log_file(5, (char *)"STANDARD COMMAND LINE SETTING(MEDIA)\n");
#line 276
  max = divide_media_token(commandline, (char (*)[30])(output));
#line 279
  ii = 0;
  }
  {
#line 279
  while (1) {
    while_continue___5: /* CIL Label */ ;
#line 279
    if (! (ii < max)) {
#line 279
      goto while_break___5;
    }
#line 281
    i = 0;
    {
#line 281
    while (1) {
      while_continue___6: /* CIL Label */ ;
#line 281
      if (! ((unsigned long )standard_commandlinelist[i].value != (unsigned long )((void *)0))) {
#line 281
        goto while_break___6;
      }
      {
#line 285
      p = strstr((char const   *)standard_commandlinelist[i].option, (char const   *)(output[ii]));
      }
#line 286
      if (p) {
        {
#line 287
        add_command_list_brcommand(standard_commandlinelist[i].value);
        }
      }
#line 281
      i ++;
    }
    while_break___6: /* CIL Label */ ;
    }
#line 279
    ii ++;
  }
  while_break___5: /* CIL Label */ ;
  }
  {
#line 298
  write_log_file(5, (char *)"COMMAND LINE SETTING(N)\n");
#line 300
  i = 0;
  }
  {
#line 300
  while (1) {
    while_continue___7: /* CIL Label */ ;
#line 300
    if (! ((unsigned long )commandlinelist2[i].option != (unsigned long )((void *)0))) {
#line 300
      goto while_break___7;
    }
    {
#line 301
    p = strstr_ex(commandline, commandlinelist2[i].option);
    }
#line 304
    if (p) {
      {
#line 307
      get_token(commandlinelist2[i].value, tmp_op);
#line 308
      tmp___5 = strlen((char const   *)commandlinelist2[i].option);
#line 308
      get_token(p + tmp___5, tmp_n);
#line 309
      sprintf((char */* __restrict  */)(tmp), (char const   */* __restrict  */)"%s  %s",
              tmp_op, tmp_n);
#line 313
      add_command_list(tmp_op, tmp_n);
      }
    }
#line 300
    i ++;
  }
  while_break___7: /* CIL Label */ ;
  }
  {
#line 322
  exec_brprintconf(brprintconf, printer_model);
  }
#line 324
  return (0);
}
}
int main(int argc,char * argv[]) {

    TapeItem tapeitem;
    char *printer;
    char ppd_line[500],tmp[500],*p_tmp,tmp_n[10],tmp_op[500];
    FILE *fp_ppd;
    char *p;
    char *commandline,*ppdfile;
    int i,ii;

    memset(&g_tapelist, 0, sizeof(TapeList));
    g_tapelist.iSelIndex = -1;

    if(argc < 1){
        return 0;
    }

    printer = argv[1];
    if(argc > 2){
        ppdfile= argv[2];
    }
    else{
        ppdfile="";
    }

    if(argc > 3){
        if(argv[3][0] >= '0' && argv[3][0] <= '9'){
            log_level = argv[3][0] -'0';
        }
        else{
            log_level = 0;
        }
    }
    else{
        log_level = 0;
    }

    if(argc > 4){
        commandline = argv[4];
    }
    else{
        commandline = "NULL COMMAND LINE";
    }
    fp_ppd = fopen(ppdfile , "r");
    if( fp_ppd == NULL) return 0;


    initialize_command_list();




    //************************************
    //  set default setting
    //************************************
    DEBUGPRINT("main:set default setting\n");
    write_log_file(5,"DEFAULT SETTING\n");  
    for ( i = 0; default_setting[i] != NULL; i ++){
        p = strstr_ex(default_setting[i],"BROTHERPRINTER_XXX");
        if(p){
            p = strchr(p,'-');
            if(p){
                add_command_list_brcommand(p);
            }
        }
    }


    //************************************
    //  set PPD option 
    //************************************
    DEBUGPRINT("main:set PPD option (string)\n");
    write_log_file(5,"PPD SETTING\n");
    while(fgets(ppd_line,sizeof(ppd_line),fp_ppd))
    {
        if(NULL == delete_ppd_comment(ppd_line))
            continue;
        if( 1 == GetLabel_name_id(ppd_line, tapeitem.tape_name, tapeitem.tape_id) )
        {
            add_tape(&g_tapelist, tapeitem.tape_name, tapeitem.tape_id);
        }
    }
    rewind(fp_ppd);

    while(fgets(ppd_line,sizeof(ppd_line),fp_ppd)){
        if(NULL == delete_ppd_comment(ppd_line))continue;
        if(NULL == chk_ppd_default_setting_line(ppd_line))continue;

        //************************************
        //  set PPD option (string)
        //************************************

        for ( i = 0; ppdcommand_all_list[i]!= NULL; i ++)
        {
            p = strstr_ex(ppd_line,ppdcommand_all_list[i]->label);
            if(p)
            {
                for (ii = 0; ppdcommand_all_list[i]->ppdcommandlist[ii].value != NULL; ii++)
                {
                    p = strstr_ex(ppd_line,ppdcommand_all_list[i]->ppdcommandlist[ii].value);
                    if(p)
                    {
                        add_command_list_brcommand(ppdcommand_all_list[i]->ppdcommandlist[ii].brcommand);
                        break;
                    }
                }

                if( strcmp(ppdcommand_all_list[i]->label, "DefaultPageSize") == 0 )
                {
                    for( ii = 0; ii < g_tapelist.count; ii++ )
                    {
                        p = strstr_ex(ppd_line, g_tapelist.tapelist[ii].tape_id);
                        if(p)
                        {
                            char lp[512];
                            sprintf(lp, "-media %s", g_tapelist.tapelist[ii].tape_name);
                            add_command_list_brcommand(lp);
                            break;
                        }
                    }
                }
            }
        }

        //************************************
        //  set PPD option (numerical)
        //************************************
        for ( i = 0; PPDdefaultN[i].option!= NULL; i ++){
            strcpy(tmp,PPDdefaultN[i].option);
            p_tmp = tmp;

            if(tmp[0] == '^')p_tmp ++;
            p = strstr_ex(ppd_line,p_tmp);

            if(p){
                sprintf(tmp,"%s  %s",PPDdefaultN[i].value,
                        p + strlen(PPDdefaultN[i].option));

                get_token(PPDdefaultN[i].value ,tmp_op);
                get_token(p + strlen(PPDdefaultN[i].option) ,tmp_n);

                add_command_list(tmp_op,tmp_n);
            }
        }
    }

    //************************************
    //  set brother command line option (string)
    //************************************
    DEBUGPRINT("main:set brother command line option (string)\n");
    write_log_file(5,"BROTHER COMMAND LINE SETTING(S)\n");
    for ( i = 0; commandlinelist[i].value != NULL; i ++){
        p = strstr_ex(commandline,commandlinelist[i].option);
        if(p){
            add_command_list_brcommand(commandlinelist[i].value);
        }
    }

    //************************************
    //  set cups standard command line option (duplex)
    //************************************
    DEBUGPRINT("main:set standard command line option (duplex)\n");
    write_log_file(5,"STANDARD COMMAND LINE SETTING(DUPLEX)\n");
    for ( i = 0; standard_side_commandlinelist[i].value != NULL; i ++){
        p = strstr_ex(commandline,standard_side_commandlinelist[i].option);
        if(p){
            add_command_list_brcommand(standard_side_commandlinelist[i].value);
        }
    }
   
    //************************************
    //  set cups standard command line option (media )
    //************************************
    DEBUGPRINT("main:set standard command line option (media)\n");
    write_log_file(5,"STANDARD COMMAND LINE SETTING(MEDIA)\n");
    {
        char output[5][30];
        int max;

        max = divide_media_token(commandline,output);

        for ( ii=0; ii < max; ii++){
            for ( i = 0; standard_commandlinelist[i].value != NULL; i ++){
                p = strstr(standard_commandlinelist[i].option, output[ii]);
                if(p){
                    add_command_list_brcommand(standard_commandlinelist[i].value);
                }
            }

            for ( i = 0; i < g_tapelist.count; i++)
            {
                char lp[512];
                p = strstr(output[ii], g_tapelist.tapelist[i].tape_name);
            
                if(p)
                {
                    sprintf(lp, "-media \"%s\"", g_tapelist.tapelist[i].tape_name);
                    add_command_list_brcommand(lp);
                }
                else
                {
                    p = strstr(output[ii], g_tapelist.tapelist[i].tape_id);
                    if(p)
                    {
                        sprintf(lp, "-media \"%s\"", g_tapelist.tapelist[i].tape_name);
                        add_command_list_brcommand(lp);
                    }
                }
            }
        }
    }

    //************************************
    //  set command line option (numerical)
    //************************************
    DEBUGPRINT("main:set command line option (numerical)\n");
    write_log_file(5,"COMMAND LINE SETTING(N)\n");

    for(i = 0; commandlinelist2[i].option != NULL; i ++){
        p = strstr_ex(commandline,commandlinelist2[i].option);
    
        if(p){
            get_token(commandlinelist2[i].value   ,tmp_op);
            get_token(p + strlen(commandlinelist2[i].option) ,tmp_n);
            sprintf(tmp,"%s  %s",tmp_op,tmp_n );
            add_command_list(tmp_op,tmp_n);
        }
    }

    //************************************
    //  call brprintconf
    //************************************
    exec_brprintconf(brprintconf,printer,argv[5]);
    
    return 0;
}