示例#1
0
int parse_ip_port(char *line, t_ip_addr *ip, int *port) {
	char *s_ip, *s_port, sep = '?';

	if ((line == NULL) || (ip == NULL) || (port == NULL)) {
		return -1;
	}

#ifdef ENABLE_IPV6
	if (split_string(line, &s_ip, &s_port, ']') == 0) {
		if ((*s_ip != '[') || (*s_port != ':')) {
			return -1;
		}
		s_ip = remove_spaces(s_ip + 1);
		s_port = remove_spaces(s_port + 1);
	} else
#endif
	{
		s_port = line + strlen(line);
		do {
			if (s_port <= line) {
				return -1;
			}
			s_port--;
		} while ((*s_port != ':') && (*s_port != '.'));
		sep = *s_port;
		*s_port = '\0';
		s_ip = remove_spaces(line);
		s_port = remove_spaces(s_port + 1);
	}

	if (parse_ip(s_ip, ip) == -1) {
		return -1;
	} else if ((*port = str2int(s_port)) <= 0) {
		return -1;
	}

	if (sep != '?') {
		if ((ip->family == AF_INET) && (sep != ':')) {
			return -1;
		}
#ifdef ENABLE_IPV6
		if ((ip->family == AF_INET6) && (sep != '.')) {
			return -1;
		}
#endif
	}

	return 0;
}
示例#2
0
char *parse_attribute(xmlNode *attr_node) {
    xmlNode *it = 0;
    char *attr = 0;
    char *attr_value = 0;
    char *attr_name = 0;
    char *attr_operator = 0;
    int attr_value_len, attr_name_len, attr_operator_len;

    for (it = attr_node; it; it = it->next) {
        if (it->type == XML_ELEMENT_NODE) {
            if (strcmp((char *)it->name, ATTRIBUTE_NAME) == 0) {
                attr_name = (char *)it->last->content;
            } else if (strcmp((char *)it->name, ATTRIBUTE_VALUE) == 0) {
                attr_value = (char *)it->last->content;
            } else if (strcmp((char *)it->name, ATTRIBUTE_OPERATOR) == 0) {
                attr_operator = (char *)it->last->content;
            } else {
                printf("Invalid Node\n");
                exit(1);
            }
        }
    }

    if (!attr_value || !attr_operator || !attr_name) {
        printf("The attribute is not complete\n");
        exit(2);
    }
    
    /* Remove white spaces */
    remove_spaces(attr_value);
    remove_spaces(attr_name);
    remove_spaces(attr_operator);

    if (strcmp(attr_value, "*") != 0) {
        attr_value_len = strlen(attr_value);
        attr_operator_len = strlen(attr_operator);
        attr_name_len = strlen(attr_name);
        
        attr = malloc((attr_value_len + attr_operator_len + attr_name_len + 7) * sizeof(*attr));
        assert(attr);
        
        sprintf(attr, "( %s %s %s )", attr_name, attr_operator, attr_value);
        attr[attr_value_len + attr_operator_len + attr_name_len + 7] = '\0';

        return attr;
    } else {
        return attr_name;
    }
}
示例#3
0
文件: wire_test.cpp 项目: slon/raptor
void check(mock_writer_t* writer, const std::string& hex) {
	writer->flush_all();

	ASSERT_EQ(remove_spaces(hex), hexify(writer->data));

	writer->data.clear();
}
示例#4
0
void
on_protocol_edit_ok_clicked (GtkButton * button, gpointer user_data)
{
  gchar *proto_string;
  GtkTreePath *gpath = NULL;
  GtkTreeViewColumn *gcol = NULL;
  GtkTreeIter it;
  GtkComboBoxEntry *cbox;
  EATreePos ep;
  if (!get_color_store (&ep))
    return;

  /* gets the row (path) at cursor */
  gtk_tree_view_get_cursor (ep.gv, &gpath, &gcol);
  if (!gpath)
    return;			/* no row selected */

  if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (ep.gs), &it, gpath))
    return;			/* path not found */

  cbox = GTK_COMBO_BOX_ENTRY(glade_xml_get_widget (appdata.xml, "protocol_entry"));
  proto_string = gtk_combo_box_get_active_text(GTK_COMBO_BOX(cbox));
  proto_string = g_utf8_strup (proto_string, -1);
  proto_string = remove_spaces(proto_string);
  
  cbox_add_select(cbox, proto_string);
  gtk_list_store_set (ep.gs, &it, 2, proto_string, -1);

  g_free (proto_string);
  gtk_widget_hide (glade_xml_get_widget (appdata.xml, "protocol_edit_dialog"));

  colors_changed = TRUE;
  color_list_to_pref ();
}				/* on_protocol_edit_ok_clicked */
示例#5
0
/*!
 * \brief Parses a configuration string for the filter
 * Parses a configuration string for switch settings and
 * updates the configuration structure.
 * \param settings The configuration string in the following form:
\verbatim
 *              <id>=<filter>[:<filter>]...[,<id>=<filter>[:<filter>]...]...
\endverbatim
 * \return 1 on success, -1 otherwise
 */
int conf_parse_filter(char *settings)
{
	/* make a copy since we are modifying it */
	int len = strlen(settings);
	if (len==0) return 1;
	char *strc = (char *)pkg_malloc(len+1);
	if (strc == NULL) {
		PKG_MEM_ERROR;
		return -1;
	}
	memcpy(strc, settings, len+1);
	remove_spaces(strc);

	char *set_p = strc;
	char *token = NULL;
	while ((token = strsep(&set_p, ","))) {  /* iterate through list of settings */
		char *id_str = strsep(&token, "=");
		int id = conf_str2id(id_str);
		if (id<0) {
			LM_ERR("cannot parse id '%s'.\n", id_str);
			pkg_free(strc);
			return -1;
		}
		if (update_filter(id, token) < 0) {
			LM_ERR("cannot extract filters.\n");
			pkg_free(strc);
			return -1;
		}
	}

	pkg_free(strc);
	return 1;
}
示例#6
0
bool is_comment(string & str, bool* in_multiline_quote)
{
    string stemp = str;
    remove_spaces(stemp);
    if (stemp.length() == 0)
        return false;

    if (stemp[0] == '/')
    {
        if (stemp.length() < 2)
            return false;

        if (stemp[1] == '*')
        {
            *in_multiline_quote = true;
            return true;
        }
        else if (stemp[2] == '/')
        {
            return true;
        }
    }

    if (stemp[0] == '#')
        return true;

    return false;
}
示例#7
0
void show_disk(struct s_hardware *hardware, ZZJSON_CONFIG *conf, ZZJSON **it, int drive) {
	config=conf;
	item=it;
	int i = drive - 0x80;
	struct driveinfo *d = &hardware->disk_info[i];
	char mbr_name[50]={0};
	char disk_size[11]={0};

	get_mbr_string(hardware->mbr_ids[i], &mbr_name,sizeof(mbr_name));
	if ((int)d->edd_params.sectors > 0)
		sectors_to_size((int)d->edd_params.sectors, disk_size);

	char disk[5]={0};
	char edd_version[5]={0};
	snprintf(disk,sizeof(disk),"0x%X",d->disk);
	snprintf(edd_version,sizeof(edd_version),"%X",d->edd_version);
	zzjson_print(config, *item);
	zzjson_free(config, *item);

	CREATE_ARRAY
		add_as("disk->number",disk) 
		add_ai("disk->cylinders",d->legacy_max_cylinder +1) 
		add_ai("disk->heads",d->legacy_max_head +1)
		add_ai("disk->sectors_per_track",d->legacy_sectors_per_track)
		add_as("disk->edd_version",edd_version)
		add_as("disk->size",disk_size)
		add_ai("disk->bytes_per_sector",(int)d->edd_params.bytes_per_sector)
		add_ai("disk->sectors_per_track",(int)d->edd_params.sectors_per_track)
		add_as("disk->host_bus",remove_spaces((char *)d->edd_params.host_bus_type))
		add_as("disk->interface_type",remove_spaces((char *)d->edd_params.interface_type))
		add_as("disk->mbr_name",mbr_name)
		add_ai("disk->mbr_id",hardware->mbr_ids[i])
	END_OF_ARRAY;

	if (parse_partition_table(d, &show_partition_information)) {
	        if (errno_disk) { 
			APPEND_ARRAY
				add_as("disk->error", "IO Error")
			END_OF_APPEND;
		} else  {
			APPEND_ARRAY
				add_as("disk->error", "Unrecognized Partition Layout")
			END_OF_APPEND;
		}
	}
}
示例#8
0
XDeviceInfo*
find_device_info(Display    *display,
			const char       *name,
			bool       only_extended)
{
	XDeviceInfo *devices;
	XDeviceInfo *found = NULL;
	int     loop;
	int     num_devices;
	int     len = strlen(name);
	bool    is_id = true;
	XID     id = (XID)-1;

	for(loop = 0; loop < len; loop++)
    {
	   if (!isdigit(name[loop]))
       {
            is_id = false;
            break;
	   }
	}

	if (is_id)
    {
	   id = atoi(name);
	}

	devices = XListInputDevices(display, &num_devices);

	for(loop = 0; loop < num_devices; loop++)
    {
        osd_printf_verbose("Evaluating device with name: %s\n", devices[loop].name);
        
        // if only extended devices and our device isn't extended, skip
        if (only_extended && devices[loop].use < IsXExtensionDevice)
            continue;

        // Adjust name to remove spaces for accurate comparison
        std::string name_no_space = remove_spaces(devices[loop].name); 
        if ((!is_id && strcmp(name_no_space.c_str(), name) == 0)
            || (is_id && devices[loop].id == id))
        {
            if (found)
            {
                osd_printf_verbose(
                    "Warning: There are multiple devices named \"%s\".\n"
                    "To ensure the correct one is selected, please use "
                    "the device ID instead.\n\n", name);
            }
            else
            {
                found = &devices[loop];
            }
        }
	}

	return found;
}
示例#9
0
文件: strtoul.c 项目: BruceYi/okl4
uintmax_t
strtoumax(const char *nptr, char **endptr, int base)
{
    struct st_buf_ptr buf;
    buf.p = (char*)nptr;

    remove_spaces(&buf);

    return __strtoull(endptr, base, 0, get_from_buf, inc_buf, (void*)&buf);
}
示例#10
0
int main()
{
	//Variables
	char input[256];
	bool palin;
	
	//Process
	while(strcmp(input, "end"))
	{
		//get some input
		printf("Please enter a word to PalinCheck: ");
		scanf("%s", input);
		
		//can't assign with spaces so check 6-P2 copy for solution
		*input = "gay afasdfsd sfsd fs";
		//testing remove spaces
		printf("%s\n", input);
		remove_spaces(input, check_length(input));
		printf("%s \n", input);
		
		//process depending on odd or even characters
		int l;
		if(check_length(input) % 2 == 0) //even
		{
			l = check_length(input);
		}
		else //odd - needs fixing
		{
			l = check_length(input) - 1;
		}
			for(int i = 0;i<l/2;i++)
			{
				char a, b;
				a = input[i];
				b = input[l-(i+1)];
				if(a != b)
				{
					palin = false;
					break;
				}
				else{ palin = true; }
			}
			if(palin)
			{
				printf("Palindrome\n");
			}
			else if (!palin)
			{
				printf("Not palindrome\n");
			}
	}
}
static void parse_option_string(nv_stack_t *sp)
{
    unsigned int i;
    nv_parm_t *entry;
    char *option_string = NULL;
    char *ptr, *token;
    char *name, *value;
    NvU32 data;

    if (NVreg_RegistryDwords != NULL)
    {
        if ((option_string = remove_spaces(NVreg_RegistryDwords)) == NULL)
        {
            return;
        }

        ptr = option_string;

        while ((token = strsep(&ptr, ";")) != NULL)
        {
            if (!(name = strsep(&token, "=")) || !strlen(name))
            {
                continue;
            }

            if (!(value = strsep(&token, "=")) || !strlen(value))
            {
                continue;
            }

            if (strsep(&token, "=") != NULL)
            {
                continue;
            }

            data = (NvU32)simple_strtoul(value, NULL, 0);

            for (i = 0; (entry = &nv_parms[i])->name != NULL; i++)
            {
                if (strcmp(entry->name, name) == 0)
                    break;
            }

            if (!entry->name)
                rm_write_registry_dword(sp, NULL, "NVreg", name, data);
            else
                *entry->data = data;
        }

        os_free_mem(option_string);
    }
}
示例#12
0
void compute_filename(struct s_hardware *hardware, char *filename, int size) {

   snprintf(filename,size,"%s/",hardware->dump_path);

    if (hardware->is_pxe_valid) {
	    strncat(filename, hardware->pxe.mac_addr, sizeof(hardware->pxe.mac_addr));
	    strncat(filename, "+", 1);
    } 
    
    if (hardware->is_dmi_valid) {
	    strncat(filename, remove_spaces(hardware->dmi.system.product_name), sizeof(hardware->dmi.system.manufacturer));
	    strncat(filename, "+", 1);
	    strncat(filename, remove_spaces(hardware->dmi.system.manufacturer), sizeof(hardware->dmi.system.product_name));
    }

    /* We replace the ":" in the filename by some "-"
     * This will avoid Microsoft FS turning crazy */
    chrreplace(filename,':','-');

    /* Avoid space to make filename easier to manipulate */
    chrreplace(filename,' ','_');

}
示例#13
0
/*
 * Name:    combine_wrap_spill
 * Purpose: combine word wrap lines so we don't push each word onto a
 *          separate line.
 * Date:    November 27, 1991
 * Passed:  window:   pointer to current window
 *          wrap_col: col to combine next line
 *          lm:       left margin
 *          rm:       right margin
 *          side:     left or right margin to insert spaces
 *          new_line: boolean, should we insert a new line?
 */
void combine_wrap_spill( WINDOW *window, int wrap_col, int lm, int rm,
                         int side, int new_line )
{
line_list_ptr p;        /* line we wrapped */
line_list_ptr pp;       /* pointer to next line after wrapped line */
int  p_len;             /* length of line we just word wrapped */
int  non_blank;         /* first non-blank column on next line */
int  control_t;         /* number of times to call word_delete */
int  next_line_len;     /* length of next line counting from 1st word */
WINDOW w;               /* scratch window */

   dup_window_info( &w, window );
   g_status.command = WordWrap;
   w.rcol = wrap_col;
   if (new_line) {
      insert_newline( &w );
      if (mode.right_justify == TRUE)
         justify_right_margin( &w, w.ll->prev, mode.word_wrap == FIXED_WRAP ?
                find_left_margin( w.ll->prev, mode.word_wrap ) : lm, rm, side );
      p = window->ll->next;
   } else
      p = window->ll;
   if (p != NULL) {
      p_len = find_end( p->line, p->len );
      pp = p->next;
      if (pp != NULL) {
         non_blank = first_non_blank( pp->line, pp->len );
         next_line_len = find_end( pp->line, pp->len ) - non_blank;
         if (!is_line_blank( pp->line, pp->len ) && p_len + next_line_len <= rm) {
            control_t = 1;
            if (mode.inflate_tabs) {
               if (*pp->line == ' '  ||  *pp->line == '\t')
                  ++control_t;
            } else if (*pp->line == ' ')
               ++control_t;
            w.ll = p;
            w.rcol = p_len + 1;
            if (*(p->line+p_len-1) == '.')
               ++w.rcol;
            while (control_t--)
               word_delete( &w );
            remove_spaces( lm );
            un_copy_line( w.ll, &w, TRUE );
         }
         window->file_info->dirty = GLOBAL;
      }
   }
}
示例#14
0
int sta(double *accum, mem_array mem, char *cmdtrans, int prg_counter, int *next_loc) {
  int return_val = CONTINUE;

  mem[mem[prg_counter].addr - 1].entry_type = VAL;
  mem[mem[prg_counter].addr - 1].cmd_type = NOP;
  sprintf(mem[mem[prg_counter].addr - 1].cell_str, "%-7.1f", *accum);
  remove_spaces(MAX_FIELD, mem[mem[prg_counter].addr - 1].cell_str);
  sscanf(mem[mem[prg_counter].addr - 1].cell_str, "%lf", &mem[mem[prg_counter].addr - 1].val);

  //get value from string so string and double are exactly the same
  put_cell(mem[prg_counter].addr - 1, mem[mem[prg_counter].addr - 1]);
  *next_loc = prg_counter + 1;
  sprintf(cmdtrans,"Store the accumulator in location %d.", mem[prg_counter].addr);

  return return_val;
}
示例#15
0
/**
 * Removes useless furiganas at the beginning and at the end.
 */
std::vector<std::pair<std::string, std::string> > Furigana::tokenize(
    std::string kanjisString,
    std::string readingString
) {
    size_t start_len, end_len;

    remove_spaces(readingString);
    readingString = this->katakana_to_hiragana(readingString);

    auto tokens = split_furigana(
        kanjisString,
        readingString,
        WARIFURI_SEPARATOR
    );

    return tokens;
}
示例#16
0
int truth_table(char ipstr[], int fnvalues[], int *no_of_variables){
     int i, j, output, len;
	  
     remove_spaces(ipstr);
     
     if(check_for_valid_characters(ipstr)){
	  printf("ERROR! Use only valid characters - ~&|() a-z A-Z\n");
	  return 1;
     }

     set_precedence(precedence,  ipstr);
     get_variables(listvar, &numvar, precedence);

     if(conv_to_postfix(ipstr, opstr, precedence) == 1){
	  printf("\nError in input\n");
	  return 1;
     }

     len = strlen(ipstr);
     /* Truth-table Printing */
     printf("\n");
     for(i=0; i<numvar; i++){
	  printf("%c  ", listvar[i]);
     }
     printf("%s ", ipstr);
     
     for(i=0; i<(1<<numvar); i++){
	  /* For each permutation of bits */
	  printf("\n");
	  compute_val_var_from_perm(i, valvar, numvar);
	  for(j=0; j<numvar; j++)
	       printf("%d  ", valvar[j]);
	  output = eval_postfix(opstr, valvar, numvar, listvar);
	  if(output == 1){
	       printf("Error : eval - not enuff operands\n");
	       return 1;
	  }
	  fnvalues[i] = output - '0';
	  printf("%*c ", len/2 + 1, output);
     }

     *no_of_variables = numvar;
     printf("\n");
     return 0;
}
示例#17
0
文件: search.c 项目: vab/cks
int search_by_fingerprint(PGconn *conn, char *fingerprint,struct cks_config *config)
{
	int rslt = 0;


	remove_spaces(fingerprint);
	if(((strlen(fingerprint)) != 32) && ((strlen(fingerprint)) != 40))
	{
		return -1;
	}
	rslt = retrieve_key(conn,fingerprint,1,config);
	if(rslt != 0)
	{
		fprintf(stderr, "Function retrieve_key() return an error: %d\n",rslt);
	}


	return rslt;
}
示例#18
0
文件: strtoul.c 项目: BruceYi/okl4
unsigned long long
strtoull(const char *nptr, char **endptr, int base)
{
    struct st_buf_ptr buf;
    buf.p = (char*)nptr;
    uintmax_t ret;

    remove_spaces(&buf);

    ret = __strtoull(endptr, base, 0, get_from_buf, inc_buf, (void*)&buf);

    if (errno == ERANGE) {
        ret = ULLONG_MAX;
    } else if (ret > ULLONG_MAX) {
        ret = ULLONG_MAX;
        errno = ERANGE;
    }

    return (unsigned long long)ret;
}
示例#19
0
int inp(mem_array mem, char *cmdtrans, int prg_counter, int *next_loc) {
  int return_val = CONTINUE;
  double val = 0.0;

  // did user want to continue?
  if(get_input(&val) != EscKey) {
    mem[mem[prg_counter].addr - 1].val = val;
    mem[mem[prg_counter].addr - 1].entry_type = VAL;
    mem[mem[prg_counter].addr - 1].cmd_type = NOP;
    sprintf(mem[mem[prg_counter].addr - 1].cell_str, "%-7.1f", val);
    remove_spaces(MAX_FIELD, mem[mem[prg_counter].addr - 1].cell_str);
    put_cell(mem[prg_counter].addr-1, mem[mem[prg_counter].addr - 1]);
    *next_loc = prg_counter + 1;
  } else {
    return_val = STOP;
  }

  clear_monitor();
  sprintf(cmdtrans, "Input value from the keyboard and store at location %d.", mem[prg_counter].addr);
  return return_val;
}
示例#20
0
MenuItem *MenuItem_load(const char *filename)
{
	FILE *fp;
	char *buffer;
	unsigned int len;
	MenuItem *root = 0;
	
	fp = fopen(filename, "r");
	if (!fp) return 0;
	
	/* get file size */
	fseek(fp, 0, SEEK_END);
	len = ftell(fp);
	fseek(fp, 0, SEEK_SET);
		
	/* allocate buffer */
	buffer = malloc(len);
	
	/* copy file to memory */
	fread(buffer, 1, len, fp);
	
	/* process script */
	if (! error_check(buffer, len))
	{
		fprintf(stderr, "%s: syntax error\n", filename);
		return 0;
	}
	len = remove_comments(buffer, len);
	len = remove_spaces(buffer, len);
	root = new_MenuItem("Main menu");
	
	load(buffer, len, root);
	
	/* clean up */
	free(buffer);
	fclose(fp);
	
	return root;
}
int main(void)
{
    // test remove_spaces()

    char string[LIMIT];

    printf("Test remove_spaces()\n");

    printf("Enter a string: ");
    get(string, LIMIT);
    while (string[0] != '\0')
    {
        remove_spaces(string);
        printf("Your string, without spaces: %s\n", string);

        printf("Enter a string (empty line to quit): ");
        get(string, LIMIT);
    }
    puts("Bye");

    return 0;
}
示例#22
0
/*!
 * \brief Parses a configuration string for proxy settings
 * Parses a configuration string for proxy settings and
 * updates the configuration structure.
 * \param settings: The configuration string in the following form:
\verbatim
 *              <id>=<host>:<port>[,<id>=<host>:<port>]...
\endverbatim
 * \return: 1 on success, -1 otherwise
 */
int conf_parse_proxy(char *settings)
{
	/* make a copy since we are modifying it */
	int len = strlen(settings);
	if (len==0) return 1;
	char *strc = (char *)pkg_malloc(len+1);
	if (strc == NULL) {
		PKG_MEM_ERROR;
		return -1;
	}
	memcpy(strc, settings, len+1);
	remove_spaces(strc);

	char *set_p = strc;
	char *token = NULL;
	while ((token = strsep(&set_p, ","))) {  /* iterate through list of settings */
		char *id_str = strsep(&token, "=");
		int id = conf_str2id(id_str);
		if (id<0) {
			LM_ERR("cannot parse id '%s'.\n", id_str);
			pkg_free(strc);
			return -1;
		}
		char *host = strsep(&token, ":");

		/* got all data for one setting -> update configuration now */
		if (update_proxy(id, host, token) < 0) {
			LM_ERR("cannot update proxy.\n");
			pkg_free(strc);
			return -1;
		}
	}

	pkg_free(strc);
	return 1;
}
示例#23
0
bool ConfigFile::SetSource(const char* file, bool /*ignorecase*/)
{
    /* wipe any existing settings. */
    m_settings.clear();

    /* open the file */
    if (file != 0)
    {
        //the right mode in Windows is "rb" since '\n' is saved as 0x0D,0x0A but fopen(file,"r") reads these 2 chars
        //as only 1 char, so ftell(f) returns a higher value than the required by fread() to the file to buf.
#ifdef WIN32
        FILE* f = fopen(file, "rb");
#else
        FILE* f = fopen(file, "r");
#endif
        char* buf;
        int length;
        if (!f)
        {
            sLog.outError("Could not open %s.", file);
            return false;
        }

        /* get the length of the file */
        fseek(f, 0, SEEK_END);
        length = ftell(f);
        buf = new char[length + 1];
        fseek(f, 0, SEEK_SET);

        fread(buf, length, 1, f);
        buf[length] = '\0';
        string buffer = string(buf);
        delete[] buf;

        /* close the file, it is no longer needed */
        fclose(f);

        /* let's parse it. */
        string line;
        string::size_type end;
        string::size_type offset;
        bool in_multiline_comment = false;
        bool in_multiline_quote = false;
        bool in_block = false;
        string current_setting = "";
        string current_variable = "";
        string current_block = "";
        ConfigBlock current_block_map;
        ConfigSetting current_setting_struct;

        /* oh god this is awful */
        try
        {
            for (;;)
            {
                /* grab a line. */
                end = buffer.find(EOL);
                if (end == string::npos)
                {
                    if (buffer.size() == 0)
                        break;
                    line = buffer;
                    buffer.clear();
                    goto parse;
                }

                line = buffer.substr(0, end);
                buffer.erase(0, end + EOL_SIZE);
                goto parse;

            parse:
                if (!line.size())
                    continue;

                /* are we a comment? */
                if (!in_multiline_comment && is_comment(line, &in_multiline_comment))
                {
                    /* our line is a comment. */
                    if (!in_multiline_comment)
                    {
                        /* the entire line is a comment, skip it. */
                        continue;
                    }
                }

                /* handle our cases */
                if (in_multiline_comment)
                {
                    // we need to find a "*/".
                    offset = line.find("*/", 0);

                    /* skip this entire line, eh? */
                    if (offset == string::npos)
                        continue;

                    /* remove up to the end of the comment block. */
                    line.erase(0, offset + 2);
                    in_multiline_comment = false;
                }

                if (in_block)
                {
                    /* handle settings across multiple lines */
                    if (in_multiline_quote)
                    {
                        /* attempt to find the end of the quote block. */
                        offset = line.find("\"");

                        if (offset == string::npos)
                        {
                            /* append the whole line to the quote. */
                            current_setting += line;
                            current_setting += "\n";
                            continue;
                        }

                        /* only append part of the line to the setting. */
                        current_setting.append(line.c_str(), offset + 1);
                        line.erase(0, offset + 1);

                        /* append the setting to the config block. */
                        if (current_block == "" || current_variable == "")
                        {
                            sLog.outError("Quote without variable.");
                            return false;
                        }

                        /* apply the setting */
                        apply_setting(current_setting, current_setting_struct);

                        /* the setting is done, append it to the current block. */
                        current_block_map[ahash(current_variable)] = current_setting_struct;
#ifdef _CONFIG_DEBUG
                        sLog.outDebug("Block: '%s', Setting: '%s', Value: '%s'", current_block.c_str(), current_variable.c_str(), current_setting_struct.AsString.c_str());
#endif
                        /* no longer doing this setting, or in a quote. */
                        current_setting = "";
                        current_variable = "";
                        in_multiline_quote = false;
                    }

                    /* remove any leading spaces */
                    remove_spaces(line);

                    if (!line.size())
                        continue;

                    /* our target is a *setting*. look for an '=' sign, this is our seperator. */
                    offset = line.find("=");
                    if (offset != string::npos)
                    {
                        ASSERT(current_variable == "");
                        current_variable = line.substr(0, offset);

                        /* remove any spaces from the end of the setting */
                        remove_all_spaces(current_variable);

                        /* remove the directive *and* the = from the line */
                        line.erase(0, offset + 1);
                    }

                    /* look for the opening quote. this signifies the start of a setting. */
                    offset = line.find("\"");
                    if (offset != string::npos)
                    {
                        ASSERT(current_setting == "");
                        ASSERT(current_variable != "");

                        /* try and find the ending quote */
                        end = line.find("\"", offset + 1);
                        if (end != string::npos)
                        {
                            /* the closing quote is on the same line, oh goody. */
                            current_setting = line.substr(offset + 1, end - offset - 1);

                            /* erase up to the end */
                            line.erase(0, end + 1);

                            /* apply the setting */
                            apply_setting(current_setting, current_setting_struct);

                            /* the setting is done, append it to the current block. */
                            current_block_map[ahash(current_variable)] = current_setting_struct;

#ifdef _CONFIG_DEBUG
                            sLog.outDebug("Block: '%s', Setting: '%s', Value: '%s'", current_block.c_str(), current_variable.c_str(), current_setting_struct.AsString.c_str());
#endif
                            /* no longer doing this setting, or in a quote. */
                            current_setting = "";
                            current_variable = "";
                            in_multiline_quote = false;

                            /* attempt to grab more settings from the same line. */
                            goto parse;
                        }
                        else
                        {
                            /* the closing quote is not on the same line. means we'll try and find it on
                               the next. */
                            current_setting.append(line.c_str(), offset);

                            /* skip to the next line. (after setting our condition first, of course :P */
                            in_multiline_quote = true;
                            continue;
                        }
                    }

                    /* are we at the end of the block yet? */
                    offset = line.find(">");
                    if (offset != string::npos)
                    {
                        line.erase(0, offset + 1);

                        // freeeee!
                        in_block = false;

                        /* assign this block to the main "big" map. */
                        m_settings[ahash(current_block)] = current_block_map;

                        /* erase all data for this so it doesn't seep through */
                        current_block_map.clear();
                        current_setting = "";
                        current_variable = "";
                        current_block = "";
                    }
                }
                else
                {
                    /* we're not in a block. look for the start of one. */
                    offset = line.find("<");

                    if (offset != string::npos)
                    {
                        in_block = true;

                        /* whee, a block! let's cut the string and re-parse. */
                        line.erase(0, offset + 1);

                        /* find the name of the block first, though. */
                        offset = line.find(" ");
                        if (offset != string::npos)
                        {
                            current_block = line.substr(0, offset);
                            line.erase(0, offset + 1);
                        }
                        else
                        {
                            sLog.outError("Block without name.");
                            return false;
                        }

                        /* skip back */
                        goto parse;
                    }
                }
            }
        }
        catch (...)
        {
            sLog.outError("Exception in config parsing.");
            return false;
        }

        /* handle any errors */
        if (in_block)
        {
            sLog.outError("Unterminated block.");
            return false;
        }

        if (in_multiline_comment)
        {
            sLog.outError("Unterminated comment.");
            return false;
        }

        if (in_multiline_quote)
        {
            sLog.outError("Unterminated quote.");
            return false;
        }

        /* we're all good :) */
        return true;
    }

    return false;
}
示例#24
0
文件: http.c 项目: chogberg/hiawatha
/* Convert the requestbuffer to a session record.
 */
int parse_request(t_session *session, int total_bytes) {
	int retval = 200;
	char *request_end, *str_end, *conn;

	request_end = session->request + total_bytes;

	/* Request method
	 */
	session->method = str_end = session->request;
	while ((*str_end != ' ') && (str_end != request_end)) {
		str_end++;
	}
	if (str_end == request_end) {
		return 400;
	}
	*str_end = '\0';
	session->uri = ++str_end;

	/* URI
	 */
	while ((*str_end != ' ') && (str_end != request_end)) {
		str_end++;
	}
	if (str_end == request_end) {
		return 400;
	}
	*(str_end++) = '\0';
	session->uri_len = strlen(session->uri);
	if ((session->config->max_url_length > 0) && (session->uri_len > session->config->max_url_length)) {
		return 414;
	}

	if (strncmp(session->uri, "http://", 7) == 0) {
		return 400;
	} else if ((session->request_uri = strdup(session->uri)) == NULL) {
		return -1;
	}

	/* Protocol version
	 */
	if (min_strlen(str_end, 10) == false) {
		return 400;
	} else if (memcmp(str_end, "HTTP/", 5) != 0) {
		return 400;
	}

	session->http_version = str_end;
	str_end += 7;

	if ((*(str_end - 1) != '.') || (*(str_end + 1) != '\r') || (*(str_end + 2) != '\n')) {
		return 400;
	} else if (*(str_end - 2) != '1') {
		return 505;
	}
	*(str_end + 1) = '\0';

	/* Body and other request headerlines
	 */
	if (session->content_length > 0) {
		session->body = session->request + session->header_length;
	}
	session->http_headers = parse_http_headers(str_end + 3);
	session->hostname = strlower(get_http_header("Host:", session->http_headers));
	session->cookie = get_http_header("Cookie:", session->http_headers);

	if ((conn = get_http_header("Connection:", session->http_headers)) != NULL) {
		conn = strlower(remove_spaces(conn));
	}
	session->keep_alive = false;

	switch (*str_end) {
		case '0':
			if ((conn != NULL) && (session->kept_alive < session->binding->max_keepalive)) {
				if (strcasecmp(conn, "keep-alive") == 0) {
					session->keep_alive = true;
				}
			}
			break;
		case '1':
			if (session->hostname == NULL) {
				retval = 400;
			} else if (session->kept_alive < session->binding->max_keepalive) {
				session->keep_alive = true;
				if (conn != NULL) {
					if (strcmp(conn, "close") == 0) {
						session->keep_alive = false;
					}
				}
			}
			break;
		default:
			retval = 505;
			break;
	}
	if (session->keep_alive) {
		session->kept_alive++;
	}

	session->parsing_oke = true;

	return retval;
}
示例#25
0
文件: parser.c 项目: imliuyifan/sd
int get_fields(char *input_str, char *field1, char *field2, char *field3,
		char *field4, char *field5, char *field6, char *field7)
{
	int end, loc, loc2, last_field;
	int field_num;
    sd_long len;

	char *fields[NAME_SIZE];
	char *current, lastCh;

	/* initialize field number to be loaded */
	field_num = 0;

	/* initialize last field loaded to zero */
	last_field = 0;

	/* initialize array of string pointers */
	fields[0] = field1;
	fields[1] = field2;
	fields[2] = field3;
	fields[3] = field4;
	fields[4] = field5;
	fields[5] = field6;
	fields[6] = field7;

	/* initialize location of first character in input string to be read */
	end = 0;
	loc = 0;
	loc2 = 0;
	lastCh = ' ';

	/* obtain pointer to first field to be loaded */
	current = fields[field_num];

	/* get length of string to be parsed */
	len = strlen(input_str);

	while (loc < len)
	{
		/* check for end of string */
		if (input_str[loc] == '\0' || input_str[loc] == '\n')
		{
			end = 1;
		}

		/*  Load characters into field */

		/*  if tab encountered, mark end of string */
		else if (input_str[loc] == '\t' && lastCh != ' ')
		{
			end = 1;
			lastCh = ' ';
		}
		/* if blank space follows valid character, mark end of string*/
		else if (lastCh >= 33 && input_str[loc] == ' ')
		{
			end = 1;
			lastCh = ' ';
		}
		/* else load next character */
		else if (input_str[loc] >= 33)
		{
			current[loc2] = input_str[loc];
			lastCh = current[loc2++];
		}

		/* check for end of current field and begin next */
		if (end == 1)
		{
			end = 0;
			last_field++;
			current[loc2] = '\0';
			++field_num;
			if (field_num < 7)
			{
				loc2 = 0;
				current = fields[field_num];
			}
		}

		/* increment location index to input string */
		++loc;
	}

	/* eliminate additional spaces from fields */
	for (field_num = 0; field_num < last_field; field_num++)
	{
		remove_spaces(fields[field_num]);
	}

	return (last_field);
}
示例#26
0
文件: parser.c 项目: imliuyifan/sd
int title(char *input_str, char *field1, char *field2)
{
	/* Yifan 03/24/2012 endpt is not correctlly defined!*/
	int i, last_field=0, end, end1 = 0, end2 = 0, endpt = 0;
	end = 0;
	for (i = 0; i < 72; i++)
	{
		if (input_str[i] == '\0' || input_str[i] == '\n')
		{
			end = 1;
			end1 = 1;
			end2 = 1;
		}

		/*  Load first string into field 1  */

		if (!end1)
		{
			/*  if tab encountered, set end1 to 1 */
			if (input_str[i] == '\t' || input_str[i] == ' ')
			{
				field1[i] = '\0';
				end1 = 1;
				endpt = i + 1;
			}
			else if (i == 13)
			{
				/* field1[i] = '\n'; modified by zl */
				field1[i] = '\0';
				end1 = 1;
				endpt = i + 1;
			}
			else
			{
				field1[i] = input_str[i];
			}
			last_field = 1;
		}

		/*  Load second string in title into field 2  */
		if (end1)
			if (!end2)
			{
				/*  if tab encountered, replace with space */
				if (input_str[i] == '\t')
				{
					if (i >= endpt)
					{
						field2[i - endpt] = ' ';
					}
				}
				else
				{
					if (i >= endpt)
					{
						field2[i - endpt] = input_str[i];
					}
				}
				last_field = 2;
			}

		/*  end of string obtained, set conditions to exit loop.  */
		if (end == 1)
		{
			endpt = i - endpt;
			i = 72;
		}
	}

	/* Terminate field2 */
	if (last_field == 2)
	{
		field2[endpt] = '\0';
	}

	/* remove additional spaces from fields */
	if (last_field > 0)
	{
		remove_spaces(field1);
	}
	if (last_field > 1)
	{
		remove_spaces(field2);
	}

	return (last_field);
}
示例#27
0
void load_glslshaderbind () {

	int		i;
	int		num;
	char	string_name[128];
	char	string_type[128];
	char	string_value[512];
	
	varFloat*					vfloat;
	varVec2*					vec2;
	varVec3*					vec3;
	varVec4*					vec4;
	varSampler2D*				sampler2D;
	script_variable_matrix_4x4*	pVariableMatrix4x4;

	
	// script validation
	// 2 strings needed: Vertex and fragment shader path
	if (mySection->stringNum < 2){
		section_error("At least 2 strings are needed: vertex and fragment shader files");
		return;
	}
	
	local = malloc(sizeof(glslshaderbind_section));
	mySection->vars = (void *) local;
	
	// load program, 2 first strings are vertex and fragment program paths
	local->program = glslshad_load(mySection->strings[0], mySection->strings[1]);
	if (local->program == -1)
		return;
	glslshad_upload(local->program);
	glslshad_bind(local->program);	// We need to use the program (bind it) in order to retrieve it locations (some drivers need it)
	
	// Reset variables
	local->vfloat_num		= 0;
	local->vec2_num			= 0;
	local->vec3_num			= 0;
	local->vec4_num			= 0;
	local->sampler2D_num	= 0;
	local->matrix4x4_num	= 0;
	num = 0;
	
	// Read the variables
	for (i=2; i<mySection->stringNum; i++) {
		sscanf ( mySection->strings[i], "%s %s %s", string_type, string_name, string_value);	// Read one string and store values on temporary strings for frther evaluation
		dkernel_trace("glslshaderbind: string_type [%s], string_name [%s], string_value [%s]", string_type, string_name, string_value);
		remove_spaces(string_value);

		if (strcmp(string_type,"float")==0)	// FLOAT detected
		{
			num = max_shader_reached ( local->vfloat_num++ );
			vfloat = &(local->vfloat[num]);
			strcpy (vfloat->name, string_name);
			strcpy (vfloat->equation, string_value);
			vfloat->loc = glslshad_getUniformLocation (local->program, vfloat->name);
			vfloat->eva.equation = vfloat->equation;
			initExpression(&vfloat->eva);		// Inits the evaluator
		}
		else if (strcmp(string_type,"vec2")==0)	// VEC2 detected
		{
			num = max_shader_reached ( local->vec2_num++ );
			vec2 = &(local->vec2[num]);
			strcpy (vec2->name, string_name);
			strcpy (vec2->equation, string_value);
			vec2->loc = glslshad_getUniformLocation (local->program, vec2->name);
			vec2->eva.equation = vec2->equation;
			initExpression(&vec2->eva);		// Inits the evaluator
		}
		else if (strcmp(string_type,"vec3")==0)	// VEC3 detected
		{
			num = max_shader_reached ( local->vec3_num++ );
			vec3 = &(local->vec3[num]);
			strcpy (vec3->name, string_name);
			strcpy (vec3->equation, string_value);
			vec3->loc = glslshad_getUniformLocation (local->program, vec3->name);
			vec3->eva.equation = vec3->equation;
			initExpression(&vec3->eva);		// Inits the evaluator
		}
		else if (strcmp(string_type,"vec4")==0)	// VEC4 detected
		{
			num = max_shader_reached ( local->vec4_num++ );
			vec4 = &(local->vec4[num]);
			strcpy (vec4->name, string_name);
			strcpy (vec4->equation, string_value);
			vec4->loc = glslshad_getUniformLocation (local->program, vec4->name);
			vec4->eva.equation = vec4->equation;
			initExpression(&vec4->eva);		// Inits the evaluator
		}
		else if (strcmp(string_type,"sampler2D")==0)	// Texture (sampler2D) detected
		{
			num = max_shader_reached ( local->sampler2D_num++ );
			sampler2D = &(local->sampler2D[num]);
			strcpy (sampler2D->name, string_name);
			// If sampler2D is a fbo...
			if (0 == strncmp("fbo",string_value,3))	{
				int fbonum;
				sscanf(string_value, "fbo%d",&fbonum);
				if (fbonum<0 || fbonum>(FBO_BUFFERS - 1)) {
					section_error("sampler2D fbo not correct, it should be 'fboX', where X=>0 and X<=%d, you choose: %s", (FBO_BUFFERS - 1), string_value);
					return;
				}
				else {
					sampler2D->texture = demoSystem.fboRenderingBuffer[fbonum];
					sampler2D->texGLid = fbo_get_texbind_id(sampler2D->texture);
				}
			}
			// Is it s a normal texture...
			else {
				sampler2D->texture = tex_load (string_value, USE_CACHE);
				if (sampler2D->texture == -1)
					return;
				tex_properties(sampler2D->texture, NO_MIPMAP);
				tex_upload (sampler2D->texture, USE_CACHE);
				sampler2D->texGLid = tex_get_OpenGLid(sampler2D->texture);
			}
			sampler2D->loc = glslshad_getUniformLocation (local->program, sampler2D->name);
			glUniform1i(sampler2D->loc, (GLuint)num);
		}
		else if (strcmp(string_type,"mat4")==0)	{
			num = max_shader_reached( local->matrix4x4_num++ );
			pVariableMatrix4x4 = &local->matrix4x4[num];
			strcpy(pVariableMatrix4x4->m_name, string_name);
				
			// remove the ';'
			if (string_value[0] != '\0')
				string_value[strlen(string_value)-1] = '\0';
				
			pVariableMatrix4x4->m_SVEVariableID = get_sve_variable_id(string_value);
			pVariableMatrix4x4->m_ShaderUniformID = glslshad_getUniformLocation(local->program, pVariableMatrix4x4->m_name);
				
			// check whether the requested SVE Matrix4x4 variable exists
			/*
			if (get_sve_variable_type(pVariableMatrix4x4->m_SVEVariableID) != sve_variable_type_matrix_4x4f)
				{
				section_error("\"%s\" is not a valid SVE Engine Matrix4x4 variable", string_value);
				return;
				}
			*/
		}
	}
	
	// Unbind any shader used
	glslshad_reset_bind();
	glUseProgram(0);
	mySection->loaded=1;
}
示例#28
0
bool toolkit_setting(char *key, char *value, t_url_toolkit *toolkit) {
	t_toolkit_rule *new_rule, *rule;
	char *rest;
	int cflags;
	size_t len;
	char *do_operations[] = {
		"ban", "call", "denyaccess", "exit", "goto", "return", "omitrequestlog",
		"skip", "use", NULL};
	char *header_operations[] = {
		"ban", "call", "denyaccess", "exit", "goto", "return", "omitrequestlog",
		"skip", "use", NULL};
	char *match_operations[] = {
		"ban", "call", "denyaccess", "exit", "expire", "goto", "redirect",
		"return", "rewrite", "skip", "usefastcgi", NULL};
	char *method_operations[] = {
		"call", "denyaccess", "exit", "goto", "return", "skip", "use", NULL};
	char *requesturi_operations[] = {
		"call", "exit", "return", "skip", NULL};
	char *total_connections_operations[] = {
		"call", "goto", "omitrequestlog", "redirect", "skip", NULL};
#ifdef ENABLE_TLS
	char *usetls_operations[] = {
		"call", "exit", "goto", "return", "skip", NULL};
#endif

	if ((key == NULL) || (value == NULL) || (toolkit == NULL)) {
		return false;
	}

	if (strcmp(key, "toolkitid") == 0) {
		return (toolkit->toolkit_id = strdup(value)) != NULL;
	}

	if ((new_rule = (t_toolkit_rule*)malloc(sizeof(t_toolkit_rule))) == NULL) {
		return false;
	} else if (toolkit->toolkit_rule == NULL) {
		toolkit->toolkit_rule = new_rule;
	} else {
		rule = toolkit->toolkit_rule;
		while (rule->next != NULL) {
			rule = rule->next;
		}
		rule->next = new_rule;
	}

	new_rule->condition = tc_none;
	new_rule->operation = to_none;
	new_rule->flow = tf_continue;
	new_rule->match_loop = 1;
	new_rule->neg_match = false;
	new_rule->parameter = NULL;
	new_rule->header = NULL;
	new_rule->value = 0;
	new_rule->caco_private = true;
	new_rule->case_insensitive = false;
	new_rule->next = NULL;

	if (strcmp(key, "matchci") == 0) {
		new_rule->case_insensitive = true;
		key = "match";
	}

	if (strcmp(key, "do") == 0) {
		/* Do
		 */
		if (parse_parameters(new_rule, value, do_operations) == false) {
			return false;
		}
	} else if (strcmp(key, "header") == 0) {
		/* Header
		 */
		new_rule->condition = tc_header;

		if (split_string(value, &value, &rest, ' ') == -1) {
			return false;
		}

		if (strcmp(value, "*") == 0) {
			new_rule->header = NULL;
		} else {
			len = strlen(value);
			if ((new_rule->header = (char*)malloc(len + 2)) == NULL) {
				return false;
			}
			sprintf(new_rule->header, "%s:", value);
		}

		if ((*rest == '\'') || (*rest == '"')) {
			value = rest + 1;
			if ((rest = strchr(rest + 1, *rest)) == NULL) {
				return false;
			}
			*rest = '\0';
			rest = remove_spaces(rest + 1);
		} else if (split_string(rest, &value, &rest, ' ') == -1) {
			return false;
		}

		if (*value == '!') {
			new_rule->neg_match = true;
			value++;
		}
		if (regcomp(&(new_rule->pattern), value, REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0) {
			return false;
		}

		if (parse_parameters(new_rule, rest, header_operations) == false) {
			return false;
		}
	} else if (strcmp(key, "match") == 0) {
		/* Match
		 */
		cflags = REG_EXTENDED;
		if (new_rule->case_insensitive) {
			cflags |= REG_ICASE;
		}

		new_rule->condition = tc_match;
		if (split_string(value, &value, &rest, ' ') == -1) {
			return false;
		}
		if (*value == '!') {
			new_rule->neg_match = true;
			value++;
		}
		if (regcomp(&(new_rule->pattern), value, cflags) != 0) {
			return false;
		}

		if (parse_parameters(new_rule, rest, match_operations) == false) {
			return false;
		}
	} else if (strcasecmp(key, "method") == 0) {
		/* Method
		 */
		new_rule->condition = tc_method;
		new_rule->flow = tf_continue;
		
		if (split_string(value, &value, &rest, ' ') == -1) {
			return false;
		}

		if (*value == '!') {
			new_rule->neg_match = true;
			value++;
		}

		if ((new_rule->parameter = strdup(value)) == NULL) {
			return false;
		}

		if (parse_parameters(new_rule, rest, method_operations) == false) {
			return false;
		}
	} else if (strcmp(key, "requesturi") == 0) {
		/* RequestURI
		 */
		new_rule->condition = tc_request_uri;

		if (split_string(value, &value, &rest, ' ') == -1) {
			return false;
		}

		if (strcasecmp(value, "exists") == 0) {
			new_rule->value = IU_EXISTS;
		} else if (strcasecmp(value, "isfile") == 0) {
			new_rule->value = IU_ISFILE;
		} else if (strcasecmp(value, "isdir") == 0) {
			new_rule->value = IU_ISDIR;
		} else {
			return false;
		}

		if (parse_parameters(new_rule, rest, requesturi_operations) == false) {
			return false;
		}
	} else if (strcmp(key, "totalconnections") == 0) {
		/* TotalConnections
		 */
		new_rule->condition = tc_total_connections;

		if (split_string(value, &value, &rest, ' ') == -1) {
			return false;
		}

		if ((new_rule->value = str_to_int(value)) == -1) {
			return false;
		}

		if (parse_parameters(new_rule, rest, total_connections_operations) == false) {
			return false;
		}
#ifdef ENABLE_TLS
	} else if ((strcmp(key, "usetls") == 0) || (strcmp(key, "usessl") == 0)) {
		/* UseTLS
		 */
		new_rule->condition = tc_use_tls;

		if (parse_parameters(new_rule, value, usetls_operations) == false) {
			return false;
		}
#endif
	} else {
		/* Unknown condition
		 */
		return false;
	}

	return true;
}
示例#29
0
/* Other component label issues */
void parse_component(int fd1,int fd2)
{
    char localbuf[1000];
    char partname[256];
    char filename[512];
    char full_filename[1024];
    int size;
    int x,y;
    int xpos = 0,ypos = 0,xpossav,ypossav;
    int xgeda,ygeda;
    int angle,mirror;
    int i = 0;
    int sarlacc_xsize = 0, sarlacc_ysize = 0;
    int sarlacc_xoffset = 0, sarlacc_yoffset = 0;
    int attribcnt;

    int refx,refy,ref_vis;
    char refdes[32];
    int valx,valy,val_vis;
    char value[64];
    char attrib[64];
    char attribsav[64];

    char flags;
    char vis;

    int pointer;
    FILE *cfp;
    char buff[128];

    size = read_block(fd1,localbuf,29,sizeof(localbuf));

    x=CONV16(localbuf,0);
    y=CONV16(localbuf,2);

    refx = CONVX(x + CONV16(localbuf,4));
    refy = CONVY(y + CONV16(localbuf,6));

    valx = CONVX(x + CONV16(localbuf,8));
    valy = CONVY(y + CONV16(localbuf,10));

    xgeda = CONVX(x);
    ygeda = CONVY(y);

    if(localbuf[12] & 0x80) mirror=1;
    else mirror=0;

    angle=0;
    if (localbuf[12] & 0x20) angle=90;
    if (localbuf[12] & 0x40) angle+=180;
/* BAD decode and use device number, fix rotation offset */

    ref_vis=val_vis=1;

    flags = localbuf[13];
    if (flags & 2) ref_vis=0;
    if (flags & 4) val_vis=0;
/* BAD decode more flags */

    vis = localbuf[14];

    /* 14-27 */

    pointer = 28 + read_string(refdes,sizeof(refdes),localbuf+28) +1;
    pointer = pointer + 1 +read_string(value,sizeof(value),localbuf+pointer);

    read_string_file(fd2,partname,sizeof(partname));
    remove_spaces(partname);
 // fprintf(stderr,"Component %s: %s\n",refdes,partname);
    snprintf(filename,sizeof(filename),"%s-1.sym", partname);
    if (symbol_dir) {
	snprintf(full_filename,sizeof(full_filename),"%s/%s",
					       symbol_dir, filename);
    } else {
	snprintf(full_filename,sizeof(full_filename),"%s", filename);
    }

    cfp = fopen(full_filename, "r");
    if (cfp != NULL) {
	/* "sarlacc_dim=" set by sarlacc_sym */
	while (!feof(cfp)) {
	  fgets(buff, 128, cfp);
	  if (!strncmp(buff, "sarlacc_dim=", 12)) {
	    sscanf(buff+12, "%d,%d,%d,%d",
	    &sarlacc_xoffset,&sarlacc_yoffset,&sarlacc_xsize,&sarlacc_ysize);
	  }
	}
	fclose(cfp);

	fprintf(stderr,"ref: %s dim = %d %d %d %d angle = %d mirror = %d\n",
	      refdes,
	      sarlacc_xoffset, sarlacc_yoffset,
	      sarlacc_xsize, sarlacc_ysize, angle, mirror);

	switch (angle) {
	default: /* 0 */
	    if (mirror) {
		xgeda = xgeda + sarlacc_xsize + sarlacc_xoffset;
	    } else {
		xgeda = xgeda - sarlacc_xoffset;
	    }
	    ygeda = ygeda - (sarlacc_ysize + sarlacc_yoffset);
	    break;
	case 90:
	    xgeda = xgeda + sarlacc_ysize + sarlacc_yoffset;
	    if (mirror) {
		/* BAD untested */
		ygeda = ygeda + sarlacc_xoffset;
	    } else {
		ygeda = ygeda - (sarlacc_xsize + sarlacc_xoffset);
	    }
	    break;
	case 180:
	    if (mirror) {
		xgeda = xgeda - sarlacc_xoffset;
	    } else {
		xgeda = xgeda + sarlacc_xsize + sarlacc_xoffset;
	    }
	    ygeda = ygeda + sarlacc_yoffset;
	    break;
	case 270:
	    xgeda = xgeda - sarlacc_yoffset;
	    if (mirror) {
		/* BAD untested */
		ygeda = ygeda - (sarlacc_xsize + sarlacc_xoffset);
	    } else {
		ygeda = ygeda + sarlacc_xoffset;
	    }
	    break;
	}
    } else {
	fprintf(stderr,"Couldn't find symbol %s in file: %s\n"
		       "Position on sheet will be uncertain\n", partname, full_filename);
    }

    fprintf(stdout,"C %d %d 1 %d %d %s\n",
	xgeda,ygeda,angle,mirror,filename);
    fprintf(stdout,"{\n");

#if 0
    /* For sarlacc debugging purposes, it's useful to see
       if a component is mirrored and how much it's rotated */
       fprintf(stdout,"T %d %d %d %d %d 1 0 0\nmirror=%d\n",
				refx,refy,GRAPHIC_COLOR,TEXTSIZE,0,mirror);
       fprintf(stdout,"T %d %d %d %d %d 1 0 0\nrotation=%d\n",
				refx,refy,GRAPHIC_COLOR,TEXTSIZE,0,angle);
#endif
    if (refdes[0] != 0) {
      if (value[0] && refx==valx && refy==valy) {
	/* prevent text overlap */
	refy += scale;
      }
      fprintf(stdout,"T %d %d %d %d %d 1 0 0\nrefdes=%s\n",
	      refx,refy,ATTRIBUTE_COLOR,TEXTSIZE,ref_vis,refdes);
    }

    if (value[0] != 0) {
      fprintf(stdout,"T %d %d %d %d %d 1 0 0\nvalue=%s\n",
	      valx,valy,ATTRIBUTE_COLOR,TEXTSIZE,val_vis,value);
    }

    attribcnt = 0;
    if(flags & 0x40) {
	for(i=0;i<8;i++) {
	  /* This assumes that the last attribute is the footprint */
	    xpos = CONVX(x + CONV16(localbuf,pointer));
	    ypos = CONVY(y + CONV16(localbuf,pointer+2));
	    pointer += 4;
	    size = read_string(attrib,sizeof(attrib),localbuf+pointer);
	    pointer += size + 1;
	    if (size > 0) {
	      attribcnt++;
	      fprintf(stdout,"T %d %d %d %d %d 1 0 0\npattern=%s\n",
				xpos,ypos,ATTRIBUTE_COLOR,TEXTSIZE,
		      ( (flags & (1<<i))?1:0 ),attrib);
	      xpossav = xpos;
	      ypossav = ypos;
	      strcpy(attribsav, attrib);
	    }
	}
    }
    if (attribcnt > 0 && attrib[0]) {
      fprintf(stdout,"T %d %d %d %d %d 1 0 0\n"
		     "footprint=%s\n",
		     xpos,ypos,ATTRIBUTE_COLOR,TEXTSIZE,
	      ( (flags & (1<<i))?1:0 ),attrib);
    }
    fprintf(stdout,"}\n");
}
示例#30
0
文件: a2.c 项目: mikebochenek/college
int main(int argc, char *argv[]) 
{
   if (argc != 2 && argc != 3)
   {
      printf ("Error:  You must specify the regular expression as the first command line \nargument.  It must be placed inside quotation marks if special chracters \n(* or +) are used.\n");
      exit (0);
   }

   if (argc == 3)
   {
      if (strcmp (argv[2], "-nfa") == 0 || strcmp (argv[2], "-NFA") == 0)
      {
         print_flag = TRUE;
      }
   }

   regexp = argv[1];

   /* printf ("%s", regexp); */

   str = (char *) malloc (1000);

   add_node (0, 1, 0, 0, 1, 0, 0, 0);

   cur_sub_section.start_node = 1;
   cur_sub_section.end_node = 1;

   remove_spaces();

   advance();
   advance();
   program();

   add_node (node_num, 0, 0, 0, 0, 1, 0, 0);
   /* add_node (node_num, node_num, 0, 0, 0, 1, 0, 0); 
    * so that it keeps looping in on itself when it sees E */

   if (prev_tok == 0 && cur_tok == 0)
   {
      /* printf ("main() Everything OK\n"); */
   }
   else
   {
      printf ("FATAL ERROR\n");
      printf ("main() Some kind of error\n");
      printf ("cur_tok is %d and level is %d\n", cur_tok, level);
      exit (0);
   }

   /* printf ("counter: %d, str: %s\n", counter, str); */

   debug_print_nfa();

   mark_start_states(1);

   remove_E_transitions();

   build_dfa();

   print_final_dfa();

   free (str);
   free (nfa);

   /* printf ("\t\t\t\t\t\tProgram finished.\n"); */

   return 0;
}