Exemple #1
0
int main(){
   int test;
   scanf("%d", &test);
   
   while(test-- > 0){
      /* 讀取方格 */
      int height, width;
      scanf("%d%d", &height, &width);
      
      char mx[50][51] = {0};
      int i;
      for(i = 0; i < height; ++i){
         scanf("%s", mx+i);
         strup(mx+i);
      }
      
      /* 讀取 query */
      int num;
      scanf("%d", &num);
      
      char find[100] = {0};
      for(i = 0; i < num; ++i){
         scanf("%s", find);
         strup(find);
         answer(mx, height, width, find);
      }
      
      if(test) puts("");
   }
   
   return 0;
}
void add_arg(char *name, char *value, list_t *arg_set) {
	define_t *new_arg;

	//label_t *label = search_labels(name);
	//if (label != NULL) {
	//	SetLastSPASMError(SPASM_ERR_LABEL_CONFLICT, name, label->input_file, label->line_num);
	//}

	if (!case_sensitive) {
		char *new_name = strup(name);
		free(name);
		name = new_name;
	}

	new_arg = (define_t *) malloc(sizeof(define_t));
	memset(new_arg, 0, sizeof(define_t));

	new_arg->name = name;
	new_arg->contents = value;
	new_arg->num_args = 0;
	new_arg->line_num = line_num;
	new_arg->input_file = strdup(curr_input_file);

	hash_insert((hash_t *) arg_set->data, new_arg);
}
define_t *search_local_defines (const char *name) {	
	define_t *result = NULL;
	char *search_name;

	//make name uppercase if needed for case-insensitivity
	if (!case_sensitive)
		search_name = strup (name);
	else
		search_name = (char *)name;

	//first search all the sets of arguments in order
	list_t *curr_arg_set = arg_list;
	while (curr_arg_set) {
		result = (define_t *)hash_lookup ((hash_t *)(curr_arg_set->data), search_name);
		if (result)
			break;
		curr_arg_set = curr_arg_set->next;
	}

	//first search all the sets of arguments in order
	while (curr_arg_set) {
		result = (define_t *)hash_lookup ((hash_t *)(curr_arg_set->data), search_name);
		if (result)
			break;
		curr_arg_set = curr_arg_set->next;
	}

	if (!case_sensitive)
		free (search_name);

	return result;
}
/*
   添加树

   每一步中,新单词与节点中存储的单词进行比较,随后,通过递归调用addtree 
   而转向左子树或右子树。该单词最终将与树中的某节点匹配(这种情况下计数
   值加 1) ,或遇到一个空指针(表明必须创建一个节点并加入到树中) 。若生成
   了新节点,则addtree 返回一个指向新节点的指针,该指针保存在父节点中
 */
struct tnode *addtree(struct tnode *p,char *w,int *nlines) {
	struct link *addlink(struct link *p,int *nlines);

	struct tnode *alloc(void);
	char *strup(char *w);
	int flag;
	/*
	   1.树还未建立,建树
	   2.比较新单词时,建树
	 */
	if(p == NULL ) {
		p = alloc();
		p->linkpoint = addlink(p->linkpoint,nlines);
		p->word = strup(w);
		p->left = p->right = NULL;
	}
	else if( (flag = strcmp(w,p->word)) == 0 ) {
		p->linkpoint= addlink(p->linkpoint,nlines);
	}
	//当小于当前节点时添加左子树
	else if(flag < 0 ) {
		p->left = addtree(p->left,w,nlines);
	}
	//当大于当前节点时添加右子树
	else {
		p->right = addtree(p->right,w,nlines);
	}

	return p;
}
Exemple #5
0
/*          , sonst 1                             */
int i8086ReadBoolConfig(const char *filename, const char *name, int defValue)
{
  char *str;
  int len, ret=defValue;

  str = (char*)calloc(i8086_CFG_MAX_VALUE_LEN, sizeof(char));
  
  if (i8086ReadStrConfig(str, filename, name)!=0)
  {
    len=strlen(str);
    strup(str);
    
    if (len==1)
    {
      if ((str[0]=='0') || (str[0]=='N'))
        ret=0;
      else
        ret=1; 
    }
    else
    {
      if (strcmp(str, "NO")==0)
        ret=0;
      else
        ret=1;
    }
  }
  
  free(str);
  
  return ret;
}
void remove_define (char *name) {
	if (!case_sensitive) {
		char *new_name = strup (name);
		name = new_name;
	}
			
	hash_remove (define_table, name);

	if (!case_sensitive)
		free(name);
}
label_t *search_labels (const char *name) {
	label_t *result;

	if (!case_sensitive) {
		char *new_name = strup (name);
		result = (label_t *)hash_lookup (label_table, new_name);
		free (new_name);
		return result;
	} else {
		return (label_t *)hash_lookup (label_table, name);
	}
}
label_t *add_label (char *name, int value) {
	label_t *new_label;
	define_t *conflict_define;

	if (mode & MODE_CODE_COUNTER) {
		free(name);
		return NULL;
	}

	if (!case_sensitive) {
		char *new_name = strup (name);
		free (name);
		name = new_name;
	}

	if ((conflict_define = search_defines(name))) {
		show_error ("conflicting definition of '%s'", name);
		//if (suppress_errors == false) {
			show_error_prefix (conflict_define->input_file, conflict_define->line_num);
			WORD attr = save_console_attributes();
			set_console_attributes (COLOR_RED);
			printf ("previous definition of '%s' was here\n", name);
			restore_console_attributes(attr);
		//}
		return NULL;
	}
	
	if ((new_label = search_labels (name))) {
		if (value != new_label->value) {
			new_label->value = value;
			show_warning ("redefinition of '%s'", name);
			show_warning_prefix (new_label->input_file, new_label->line_num);
			WORD attr = save_console_attributes();
			set_console_attributes (COLOR_YELLOW);
			printf ("previous definition of '%s' was here\n", name);
			restore_console_attributes(attr);
		}
	} else {
		new_label = (label_t *)malloc (sizeof (label_t));
		
		if (new_label != NULL) {
			new_label->name = name;
			new_label->line_num = line_num;
			new_label->input_file = strdup(curr_input_file);
			new_label->value = value;
			
			hash_insert (label_table, new_label);
		}
		
	}
	return new_label;
}
define_t *search_defines (const char *name) {	
	define_t *result = NULL;
	char *search_name;
	list_t *curr_arg_set = arg_list;
	unsigned int curr_hash;

	//make name uppercase if needed for case-insensitivity
	if (!case_sensitive)
		search_name = strup (name);
	else
		search_name = (char *)name;

	//first search all the sets of arguments in order
	while (curr_arg_set) {
		result = (define_t *)hash_lookup ((hash_t *)(curr_arg_set->data), search_name);
		if (result)
			break;
		curr_arg_set = curr_arg_set->next;
	}

	//if that doesn't work, look in the global define table
	if (!result)
		result = (define_t *)hash_lookup (define_table, search_name);
	
#define MHASH(Z) (murmur_hash(Z, strlen(Z)))

	curr_hash = murmur_hash (search_name, strlen (search_name));
	// Search all SPASM predefined values
	if (curr_hash == MHASH("__LINE")) {
		
		char line_buf[32];
		sprintf (line_buf, "%d", line_num);
		if (result)
			set_define (result, line_buf, -1, false);
		
	} else if (curr_hash == MHASH("__FILE")) {
		
		char fn_buf[MAX_PATH + 2];
		sprintf (fn_buf, "\"%s\"", curr_input_file);
		if (result)
			set_define (result, fn_buf, -1, false);
		
	}
	//printf("fail: %s %08x\n", search_name, murmur_hash(search_name, strlen(search_name)));
	
	if (!case_sensitive)
		free (search_name);

	//make sure any empty arguments get returned as undefined
	//if (result && result->contents == NULL) result = NULL;
	return result;
}
Exemple #10
0
void parseCommand (char * cmdstr)
{
    int8_t cmd=-1;
    int16_t num=0;
    
     // Serial.print("parseCommand:"); Serial.println(cmdstr);
    char * actpos = strtok(cmdstr," ");   // see a nice explaination of strtok here:  http://www.reddit.com/r/arduino/comments/2h9l1l/using_the_strtok_function/
    if (actpos) 
    {
        strup(actpos);

        // housekeeping commands
        if (!strcmp(actpos,"ID"))   cmd=CMD_PRINT_ID;
        if (!strcmp(actpos,"SAVE"))  { actpos=strtok(NULL," "); cmd=CMD_SAVE_SLOT; }
        if (!strcmp(actpos,"LOAD"))  { actpos=strtok(NULL," "); cmd=CMD_LOAD_SLOT; }
        if (!strcmp(actpos,"NEXT"))  cmd=CMD_NEXT_SLOT;
        if (!strcmp(actpos,"CLEAR")) cmd=CMD_DELETE_SLOTS;
        if (!strcmp(actpos,"LIST"))  cmd=CMD_LIST_SLOTS;
        if (!strcmp(actpos,"IDLE"))  cmd=CMD_IDLE;
        
        //  button feature commands
        if (!strcmp(actpos,"BM")) { actpos=strtok(NULL," "); if (get_uint(actpos, &num)) cmd=CMD_BUTTON_MODE; }
        if (!strcmp(actpos,"CL")) cmd=CMD_MOUSE_CLICK_LEFT;
        if (!strcmp(actpos,"CR")) cmd=CMD_MOUSE_CLICK_RIGHT; 
        if (!strcmp(actpos,"CM")) cmd=CMD_MOUSE_CLICK_MIDDLE; 
        if (!strcmp(actpos,"CD")) cmd=CMD_MOUSE_CLICK_DOUBLE; 
        if (!strcmp(actpos,"PL")) cmd=CMD_MOUSE_PRESS_LEFT; 
        if (!strcmp(actpos,"PR")) cmd=CMD_MOUSE_PRESS_RIGHT; 
        if (!strcmp(actpos,"PM")) cmd=CMD_MOUSE_PRESS_MIDDLE; 
        if (!strcmp(actpos,"RL")) cmd=CMD_MOUSE_RELEASE_LEFT; 
        if (!strcmp(actpos,"RR")) cmd=CMD_MOUSE_RELEASE_RIGHT; 
        if (!strcmp(actpos,"RM")) cmd=CMD_MOUSE_RELEASE_MIDDLE; 
        if (!strcmp(actpos,"WU")) cmd=CMD_MOUSE_WHEEL_UP; 
        if (!strcmp(actpos,"WD")) cmd=CMD_MOUSE_WHEEL_DOWN; 
        if (!strcmp(actpos,"WS")) { actpos=strtok(NULL," "); if (get_uint(actpos, &num)) cmd=CMD_MOUSE_WHEEL_STEP; }
        if (!strcmp(actpos,"MX")) { actpos=strtok(NULL," "); if (get_int(actpos, &num)) cmd=CMD_MOUSE_MOVEX; }
        if (!strcmp(actpos,"MY")) { actpos=strtok(NULL," "); if (get_int(actpos, &num)) cmd=CMD_MOUSE_MOVEY; }
        if (!strcmp(actpos,"KW")) { actpos+=3; cmd=CMD_KEY_WRITE; }
        if (!strcmp(actpos,"KP")) { actpos+=3; cmd=CMD_KEY_PRESS; }
        if (!strcmp(actpos,"KR")) { actpos+=3; cmd=CMD_KEY_RELEASE; }
        if (!strcmp(actpos,"RA")) cmd=CMD_RELEASE_ALL;
    }
    if (cmd>-1)
    {
        // Serial.print("cmd parser found:");Serial.print(cmd); Serial.print(", "); Serial.print(num); 
        // if (actpos) {Serial.print(", "); Serial.println(actpos);} else Serial.println();   
        performCommand(cmd,num,actpos,0);        
    }
    else   Serial.println("cmd parser: ?");              
}
Exemple #11
0
struct Person {
    char *name;
    int age;
    int height;
    int weight;
}

struct Person *Person_create(char *name, int age, int height, int weight) {
    struct Person *who = malloc(sizeof(struct Person));
    assert( who != NULL);

    who->name = strup(name);
    who->age = age;
    who->height = height;
    who->weight = weight;

    return who;
}
void add_arg(char *name, char *value, list_t *arg_set) {
	define_t *new_arg;

	if (!case_sensitive) {
		char *new_name = strup(name);
		free(name);
		name = new_name;
	}

	new_arg = (define_t *) malloc(sizeof(define_t));
	memset(new_arg, 0, sizeof(define_t));

	new_arg->name = name;
	new_arg->contents = value;
	new_arg->num_args = 0;
	new_arg->line_num = line_num;
	new_arg->input_file = strdup(curr_input_file);

	hash_insert((hash_t *) arg_set->data, new_arg);
}
Exemple #13
0
void parseCommand (char * cmdstr)
{
    int8_t cmd=-1;
    int16_t num=0;
    
    if (DebugOutput==DEBUG_FULLOUTPUT)  {
  		Serial.print("parseCommand:"); Serial.println(cmdstr); 
    }
    char * actpos = strtok(cmdstr," ");   // see a nice explaination of strtok here:  http://www.reddit.com/r/arduino/comments/2h9l1l/using_the_strtok_function/
    
    if (actpos) 
    {
        if (DebugOutput==DEBUG_FULLOUTPUT)  {
    			Serial.print("actpos:"); Serial.println(actpos);
        }
        int i;
        strup(actpos);
        
        for (i=0;(i<NUM_COMMANDS)&&(cmd==-1);i++)
        {
          if (!strcmp_FM(actpos,(uint_farptr_t_FM)atCommands[i].atCmd))  {
            // Serial.print ("partype="); Serial.println (pgm_read_byte_near(&(atCommands[i].partype)));
            switch (pgm_read_byte_near(&(atCommands[i].partype))) 
            {
               case PARTYPE_UINT: actpos=strtok(NULL," ");  if (get_uint(actpos, &num)) cmd=i ; break;
               case PARTYPE_INT:  actpos=strtok(NULL," ");  if (get_int(actpos, &num)) cmd=i ; break;
               case PARTYPE_STRING: actpos+=3; if (*actpos) cmd=i; break;
               default: cmd=i; actpos=0; break;
            }
          }
        }  
    }

    if (cmd>-1) { 
      // Serial.print("cmd:");Serial.print(cmd);Serial.print("numpar:");
      // Serial.print(num);Serial.print("stringpar:");Serial.println(actpos);
      performCommand(cmd,num,actpos,0);        
    } 
    else Serial.println("???");      // command not recognized!                
}
Exemple #14
0
static int read_atom_hin_file(char* t,char* listFields[])
{
	int taille = BSIZE;
	char dump[BSIZE];
	int i;

    	sscanf(t,"%s",dump);
	strup(dump);
	if(strcmp(dump,"ATOM")!=0)
	{
		if(strcmp(dump,"RES")==0)
		{
    			sscanf(t,"%s %s %s",dump,dump,listFields[1]);
			sprintf(listFields[0],"Unknown");
		}
		else
			return FALSE;
	}
	else
	{
		/* 0 -> Atom Type PDB Style*/
		/* 1 -> Atom Symbol*/
		/* 2 -> Atom Type Amber*/
		/* 3 -> Atom Charge*/
		/* 4 -> x*/
		/* 5 -> y*/
		/* 6 -> z*/
    		sscanf(t,"%s %s %s %s %s %s %s %s %s %s",dump,dump,listFields[0],listFields[1],listFields[2],dump,listFields[3],listFields[4],listFields[5],listFields[6]);
	}
	for(i=0;i<6;i++)
	{
		delete_last_spaces(listFields[i]);
		delete_first_spaces(listFields[i]);
	}
	return TRUE;

}
void smartfilter_report(void)
{

   FILE *fp_in = NULL, *fp_ou = NULL, *fp_user = NULL;

   char buf[MAXLEN];
   char url[MAXLEN];
   char csort[255];
   char smart_in[MAXLEN];
   char smart_ou[MAXLEN];
   char sites[MAXLEN];
   char report[MAXLEN];
   char ip[MAXLEN];
   char user[MAXLEN];
   char ouser[MAXLEN];
   char data[15];
   char hora[15];
   char smartcat[256];
   char smartheader[15];
   char ftime[128];
   char smartuser[MAXLEN];
   int  fuser=0;
   int cstatus;
   struct getwordstruct gwarea;
   const struct userinfostruct *uinfo;

   ouser[0]='\0';

   strcpy(smartheader,_("SmartFilter"));
   strup(smartheader);

   sprintf(smart_in,"%s/smartfilter.unsort",outdirname);
   sprintf(sites,"%s/sarg-sites",outdirname);
   sprintf(smart_ou,"%s/smartfilter.log",outdirname);
   sprintf(report,"%s/smartfilter.html",outdirname);

   if (snprintf(csort,sizeof(csort),"sort -n -k 1,1 -k 2,2 -k 3,3 -o \"%s\" \"%s\"",smart_ou,smart_in)>=sizeof(csort)) {
      debuga(_("cannot build the sort command to sort file %s\n"),smart_in);
      exit(EXIT_FAILURE);
   }
   cstatus=system(csort);
   if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
      debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
      debuga(_("sort command: %s\n"),csort);
      exit(EXIT_FAILURE);
   }
   if((fp_in=fopen(smart_ou,"r"))==NULL) {
      debuga(_("(smartfilter) Cannot open log file %s\n"),smart_ou);
      debuga(_("sort command: %s\n"),csort);
      exit(EXIT_FAILURE);
   }
   unlink(smart_in);

   if((fp_ou=fopen(report,"w"))==NULL) {
     debuga(_("(smartfilter) Cannot open log file %s\n"),report);
     exit(EXIT_FAILURE);
   }

   fprintf(fp_ou, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
   fputs("</head>\n",fp_ou);
   if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace);
   fprintf(fp_ou,"<body bgcolor=\"%s\" text=\"%s\" background=\"%s\">\n",BgColor,TxColor,BgImage);
   fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
   write_logo_image(fp_ou);

   fprintf(fp_ou,"<tr><th align=\"center\"><b><font color=\"%s\" size=\"+1\">%s</font></b></th></tr>\n",TiColor,Title);
   fprintf(fp_ou,"<tr><td align=\"center\" bgcolor=\"%s\"><font size=\"%s\">",HeaderBgColor,FontSize);
   fprintf(fp_ou,_("Period: %s"),period.html);
   fputs("</font></td></tr>\n",fp_ou);
   fprintf(fp_ou,"<tr><th bgcolor=\"%s\" align=\"center\"><font size=\"%s\">%s</font></th></tr>\n",HeaderBgColor,FontSize,_("SmartFilter"));
   fputs("</table></div>\n",fp_ou);

   fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_ou);
   fputs("<tr><td></td></tr>\n",fp_ou);
   fputs("<tr><td></td></tr>\n",fp_ou);
   fputs("<tr><td></td></tr>\n",fp_ou);
   fprintf(fp_ou,"<tr><th bgcolor=%s><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th><th bgcolor=\"%s\"><font size=\"%s\">%s</font></th></tr>\n",HeaderBgColor,FontSize,_("USERID"),HeaderBgColor,FontSize,_("IP/NAME"),HeaderBgColor,FontSize,_("DATE/TIME"),HeaderBgColor,FontSize,_("ACCESSED SITE"),HeaderBgColor,FontSize,smartheader);

   while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
      getword_start(&gwarea,buf);
      if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(data,sizeof(data),&gwarea,'\t')<0 ||
          getword(hora,sizeof(hora),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
          getword(url,sizeof(url),&gwarea,'\t')<0 || getword(smartcat,sizeof(smartcat),&gwarea,'\n')<0) {
         debuga(_("There is a broken record or garbage in file %s\n"),smart_ou);
         exit(EXIT_FAILURE);
      }

      uinfo=userinfo_find_from_id(user);
      if (!uinfo) {
         debuga(_("Unknown user ID %s in file %s\n"),user,smart_ou);
         exit(EXIT_FAILURE);
      }
      if(strcmp(ouser,user) != 0) {
         strcpy(ouser,user);
         sprintf(smartuser,"%s/denied_%s.html",outdirname,uinfo->filename);
         if(fuser) {
            fuser=0;
            fputs("</table>\n",fp_user);
            if(ShowSargInfo) {
               zdate(ftime, sizeof(ftime), DateFormat);
               fprintf(fp_user,"<br><br><div align=\"center\"><font size=\"-2\">%s <a href=\"%s\">%s-%s</a> %s %s</font></div>\n",_("Generated by"),URL,PGM,VERSION,_("on"),ftime);
            }
            fputs("</body>\n</html>\n",fp_user);
            fclose(fp_user);
         }
         if ((fp_user = fopen(smartuser, "a")) == 0) {
            debuga(_("(smartfilter) Cannot open file %s\n"),smartuser);
            exit(EXIT_FAILURE);
         }
         fuser=1;

         fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"",fp_ou);
         fputs(" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou);
         fputs("<html>\n",fp_user);
         fputs("<head>\n",fp_user);
         fprintf(fp_user,"  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
         fputs("</head>\n",fp_user);

         if(FontFace[0] != 0) {
            /*
            Before merging the sprintf and the fputs, the code looked like this:
            sprintf(html2,"<font face=%s>\n",FontFace);
            fputs(url,fp_user);
            The two lines don't use the same buffer so the string formated by sprintf is not the string
            written to fp_user. I (fmarchal) assumed it was a typo and replaced it by a fprintf but
            that font tag is not valid outside of the body. So, the generated html was likely
            containing garbage not rendered by the browser.
            */
            fprintf(fp_user,"<font face=%s>\n",FontFace);
         }
         fprintf(fp_user,"<body bgcolor=\"%s\" text=\"%s\" background=\"%s\">\n",BgColor,TxColor,BgImage);
         fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_user);
         if(LogoImage[0]!='\0') fprintf(fp_user,"<tr><th align=left><img src=\"%s\" border=\"0\" align=\"absmiddle\" width=\"%s\" height=\"%s\"><font color=\"%s\">%s</font>\n",LogoImage,Width,Height,LogoTextColor,LogoText);
         fprintf(fp_user,"<tr><th align=\"center\"><b><font color=\"%s\" size=\"+1\">%s</font></b></th></tr>\n",TiColor,Title);
         fputs("<tr><td align=center bgcolor=\"%s\"><font size=\"%s\">",fp_user);
         fprintf(fp_user,_("Period: %s"),period.html);
         fputs("</font></td></tr>\n",fp_user);
         fprintf(fp_user,"<tr><td align=\"center\" bgcolor=\"%s\"><font size=\"%s\">%s:</font><font size=\"%s\"> %s</font></td></tr>\n",HeaderBgColor,FontSize,_("User"),FontSize,uinfo->label);
         fputs("</table></div>\n",fp_user);
         fputs("<div align=\"center\"><table cellpadding=0 cellspacing=2>\n",fp_user);
         fputs("<tr><td></td></tr>\n",fp_user);
         fputs("<tr><td></td></tr>\n",fp_user);
         fputs("<tr><td></td></tr>\n",fp_user);
         fprintf(fp_user,"<tr><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th></tr>\n",HeaderBgColor,FontSize,_("USERID"),HeaderBgColor,FontSize,_("IP/NAME"),HeaderBgColor,FontSize,_("DATE/TIME"),HeaderBgColor,FontSize,_("ACCESSED SITE"),HeaderBgColor,FontSize,smartheader);
      }
      fprintf(fp_user,"<tr><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s-%s</font></td><td bgcolor=%s><font size=%s>%s</font></td><td bgcolor=%s><font size=%s>%s</font></td></th>\n",TxBgColor,FontSize,uinfo->label,TxBgColor,FontSize,ip,TxBgColor,FontSize,data,hora,TxBgColor,FontSize,url,TxBgColor,FontSize,smartcat);

      fprintf(fp_ou,"<tr><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s-%s</font></td><td bgcolor=%s><font size=%s>%s</font></td><td bgcolor=%s><font size=%s>%s</font></td></th>\n",TxBgColor,FontSize,uinfo->label,TxBgColor,FontSize,ip,TxBgColor,FontSize,data,hora,TxBgColor,FontSize,url,TxBgColor,FontSize,smartcat);
   }

   fputs("</table>\n",fp_ou);

   if(ShowSargInfo) {
      zdate(ftime, sizeof(ftime), DateFormat);
      fprintf(fp_ou,"<br><br><div align=\"center\"><font size=\"-2\">%s <a href=\"%s\">%s-%s</a> %s %s</font></div>\n",_("Generated by"),URL,PGM,VERSION,_("on"),ftime);
   }

   fputs("</body>\n</html>\n",fp_user);

   fclose(fp_ou);
   if(fp_user) {
      fputs("</table>\n",fp_user);
      if(ShowSargInfo) {
         zdate(ftime, sizeof(ftime), DateFormat);
         fprintf(fp_user,"<br><br><div align=\"center\"><font size=\"-2\">%s <a href=\"%s\">%s-%s</a> %s %s</font></div>\n",_("Generated by"),URL,PGM,VERSION,_("on"),ftime);
      }
      fputs("</body>\n</html>\n",fp_user);
      fclose(fp_user);
   }

   return;
}
define_t *add_define (char *name, bool *redefined, bool search_local) {
	define_t *define;
	label_t *conflict_label;

	if (strlen(name) == 0) {
		SetLastSPASMError(SPASM_ERR_NAME_EXPECTED);
		free(name);
		return NULL;
	}

	if (!case_sensitive) {
		char *new_name = strup (name);
		free (name);
		name = new_name;
	}
	
	if ((conflict_label = search_labels(name))) {
		show_error ("conflicting definition of '%s'", name);
		//if (suppress_errors == false) {
			show_error_prefix (conflict_label->input_file, conflict_label->line_num);
			WORD attr = save_console_attributes();
			set_console_attributes (COLOR_RED);
			printf ("previous definition of '%s' was here\n", name);
			restore_console_attributes(attr);
		//}
		return NULL;
	}
	
	// handle redefinitions
	if ((define = search_defines (name, search_local))) {
		int curr_arg;

		free (name);
		//define->line_num = line_num;
		//define->input_file = curr_input_file;
		/* Don't clear the contents of the #define, because
		   if it's being redefined references to itself may
		   need to be expanded, which will require the original
		   contents - all handled by set_define */

		for (curr_arg = 0; curr_arg < define->num_args; curr_arg++) {
			if (define->args[curr_arg] != NULL) {
				free(define->args[curr_arg]);
				define->args[curr_arg] = NULL;
			}
		}
		define->num_args = 0;

		if (redefined != NULL)
			*redefined = true;

		return define;
	} 
	
	if (redefined != NULL)
		*redefined = false;

	define = (define_t *) malloc (sizeof (define_t));
	if (define != NULL) {
		int curr_arg;

		define->name = name;
		define->line_num = line_num;
		define->input_file = strdup(curr_input_file);
		define->contents = NULL;
		define->num_args = 0;

		for (curr_arg = 0; curr_arg < MAX_ARGS; curr_arg++)
			define->args[curr_arg] = NULL;

		hash_insert (define_table, define);
	}
	return define;
}
Exemple #17
0
int main(int argc,char* argv[])
{
 FILE* fin;
 FILE* fout;
 char symb[10];
 char** pdb;
 char** mm;
 float* charge;
 char t[BSIZE];
 char dum1[100];
 char dum2[100];
 char dum3[100];
 char* filename = NULL;
 int Natoms = 0;
 float C[3];
 int i;
 char name[100];
 char *listFields[8];
 
 sprintf(name,"ToChange");

 if(argc<2) filename = strdup("p.hin");
 else filename = strdup(argv[1]);

 printf("FileName = %s\n",filename);

 fin = fopen(filename,"r");
 if(!fin)
 {
	printf("I can not open %s\n",filename);
	return 1;
 }
 Natoms = 0;
 while(fgets(t,BSIZE,fin))
 {
	 strup(t);
	 if(strstr(t,"ATOM"))Natoms++;
	 if(strstr(t,"RES") && strstr(name,"ToChange")) 
	 {
		 printf("t = %s\n",t);
		 if(3==sscanf(t,"%s %s %s",dum1,dum3,dum2))
			 sprintf(name,dum2);
	 }

 }
 fclose(fin);
 if(Natoms<=0)
	{
		printf("Error : Natoms <=0\n");
		return 1;
	}
 pdb = (char**)malloc(Natoms*sizeof(char*));
 mm = (char**)malloc(Natoms*sizeof(char*));
 charge = (float*)malloc(Natoms*sizeof(float));
 for(i=0;i<Natoms;i++)
 {
	 pdb[i] = (char*)malloc(100*sizeof(char));
	 mm[i] = (char*)malloc(100*sizeof(char));
 }
 printf("Natoms = %d\n",Natoms);
 fin = fopen(filename,"r");
 if(!fin)
 {
	printf("I can not open %s\n",filename);
	return 1;
 }
 printf("End sprintfName\n");
 fout = fopen("Fragment.cc","a");
 if(!fout)
 {
	printf("I can not open Fragment.cc\n");
	return 1;
 }
 fprintf(fout,"\telse if ( !strcmp(Name, \"%s\" ) )\n",name);
 fprintf(fout,"\t{\n");
 fprintf(fout,"\t\tF.NAtoms = %d;\n",Natoms);
 fprintf(fout,"\t\tF.Atoms  = g_malloc(F.NAtoms*sizeof(Atom));\n");
 printf("End fout\n");

 for(i=0;i<8;i++) listFields[i] = (char*)malloc(100*sizeof(char));
 i = -1;
 while(fgets(t,BSIZE,fin))
 {
	if(!strstr(t,"ATOM")) continue;
	if(!read_atom_hin_file(t,listFields))continue;
		/* 0 -> Atom Type PDB Style*/
		/* 1 -> Atom Symbol*/
		/* 2 -> Atom Type Amber*/
		/* 3 -> Atom Charge*/
		/* 4 -> x*/
		/* 5 -> y*/
		/* 6 -> z*/
	printf("t=%s\n",t);
	i++;
	sprintf(pdb[i],"%s",listFields[0]);
	sprintf(mm[i],"%s",listFields[2]);
	C[0] = atof(listFields[4]);
	C[1] = atof(listFields[5]);
	C[2] = atof(listFields[6]);
	charge[i] = atof(listFields[3]);
 	fprintf(fout,"\t\tSetAtom(&F.Atoms[ %d ] , \"%s\",%0.6ff,%0.6ff,%0.6ff,%0.6ff);\n",i,pdb[i],C[0],C[1],C[2],charge[i]);
 }
 /*
 fprintf(fout,"\t\tF.atomToDelete =%d;\n",1);
 fprintf(fout,"\t\tF.atomToBondTo =%d;\n",2);
 fprintf(fout,"\t\tF.angleAtom    =%d;\n",3);
 */
 fprintf(fout,"\t}\n");
 fprintf(fout,"\n\tfprintf(fout,\"%s\\n\")\n\n",name);
 fprintf(fout,"\tfprintf(fout,\"Begin %s Residue\\n\")\n",name);
 for(i=0;i<Natoms;i++)
 	fprintf(fout,"\tfprintf(fout,\"%s \t%s\t%0.6f\\n\")\n",pdb[i],mm[i],charge[i]);
 fprintf(fout,"\tfprintf(fout,\"End\\n\")\n");

 fclose(fin);
 fclose(fout);
 

 return 0;
	
}
define_t *search_defines (const char *name, bool search_local) {	
	define_t *result = NULL;
	char *search_name;
	list_t *curr_arg_set = arg_list;
	size_t curr_hash;

	//make name uppercase if needed for case-insensitivity
	if (!case_sensitive)
		search_name = strup (name);
	else
		search_name = (char *)name;

	//first search all the sets of arguments in order
	if (search_local)
	{
		while (curr_arg_set) {
			result = (define_t *)hash_lookup ((hash_t *)(curr_arg_set->data), search_name);
			if (result)
				break;
			curr_arg_set = curr_arg_set->next;
		}
	}

	//if that doesn't work, look in the global define table
	if (!result)
		result = (define_t *)hash_lookup (define_table, search_name);
	
#define MHASH(Z) (murmur_hash(Z, strlen(Z)))

	curr_hash = murmur_hash (search_name, strlen (search_name));
	// Search all SPASM predefined values
	if (!strcmp(search_name, "__LINE")) {
		
		char line_buf[32];
		sprintf (line_buf, "%d", line_num);
		if (result)
			set_define (result, line_buf, -1, false);
		
	} else if (!strcmp(search_name, "__FILE")) {
		
		char fn_buf[MAX_PATH * 2] = { 0 };
		char *buf_ptr = fn_buf;
		*buf_ptr++ = '"';
		char *fn_ptr = curr_input_file;
		if (fn_ptr != NULL) {
			while (*fn_ptr != '\0') {
				if (*fn_ptr == '\\') {
					*buf_ptr++ = '\\';
				}

				*buf_ptr++ = *fn_ptr++;
			}
		}
		*buf_ptr++ = '"';
		if (result) {
			set_define(result, fn_buf, -1, false);
		}
		
	}
	//printf("fail: %s %08x\n", search_name, murmur_hash(search_name, strlen(search_name)));
	
	if (!case_sensitive)
		free (search_name);

	//make sure any empty arguments get returned as undefined
	//if (result && result->contents == NULL) result = NULL;
	return result;
}