Example #1
0
bool
module_iconv (RECODE_OUTER outer)
{
  const char **cursor;

  for (cursor = iconv_name_list; *cursor; cursor++)
    {
      const char **aliases = cursor;
      const char *charset_name = *cursor;

      /* Scan aliases for some charset which would already be known.  If any,
	 use its official name as a charset.  Else, use the first alias.  */

      while (*cursor)
	{
          RECODE_ALIAS alias
            = find_alias (outer, *cursor, ALIAS_FIND_AS_CHARSET);

	  if (alias)
	    {
	      charset_name = alias->symbol->name;
	      break;
	    }
	  cursor++;
	}

      if (!declare_iconv (outer, charset_name, *aliases))
	return false;

      /* Declare all aliases, given they bring something we do not already
	 know.  Even then, we still declare too many useless aliases, as the
	 desambiguating tables are not recomputed as we go.  FIXME!  */

      for (cursor = aliases; *cursor; cursor++)
	{
	  RECODE_ALIAS alias
	    = find_alias (outer, *cursor, ALIAS_FIND_AS_CHARSET);

	  /* If there is a charset contradiction, call declare_alias
	     nevertheless, as the error processing will occur there.  */
	  if (!alias || alias->symbol->name != charset_name)
	    if (!declare_alias (outer, *cursor, charset_name))
	      return false;
	}
    }

  return true;
}
/********************************************************************
 * FUNCTION do_unset (local RPC)
 * 
 * unset def
 *
 * Handle the unset command; remove the specified alias
 *
 * INPUTS:
 *    server_cb == server control block to use
 *    rpc == RPC method for the unset command
 *    line == CLI input in progress
 *    len == offset into line buffer to start parsing
 *
 * RETURNS:
 *   status
 *********************************************************************/
extern status_t
    do_unset (server_cb_t *server_cb,
              obj_template_t *rpc,
              const xmlChar *line,
              uint32  len)
{
    val_value_t        *valset, *parm;
    status_t            res = NO_ERR;

    valset = get_valset(server_cb, rpc, &line[len], &res);

    if (res == NO_ERR && valset) {
        parm = val_find_child(valset, YANGCLI_MOD, NCX_EL_NAME);
        if (parm) {
            const xmlChar *varstr = VAL_STR(parm);
            alias_cb_t *alias = find_alias(varstr, xml_strlen(varstr));
            if (alias) {
                dlq_remove(alias);
                free_alias(alias);
                log_info("\nDeleted alias '%s'\n", varstr);
            } else {
                res = ERR_NCX_INVALID_VALUE;
                log_error("\nError: unknown alias '%s'\n", varstr);
            }
        }  /* else missing parameter already reported */
    } /* else no valset already reported */

    if (valset) {
        val_free_value(valset);
    }

    return res;

}  /* do_unset */
Example #3
0
 inline static void register_property(const std::type_info * type, const std::string & name, ValueType value)
 {
     std::string alias = find_alias(type);
     if (!alias.empty())
     {
         boost::unique_lock<boost::shared_mutex> lock(property_mutex);
         properties[alias][name] = value;
     }
 }
Example #4
0
File: run.c Project: ameenross/dex
static void run_command(const struct command *cmds, char **av)
{
	const struct command *cmd = find_command(cmds, av[0]);
	const char *pf;
	char **args;

	if (!cmd) {
		PTR_ARRAY(array);
		const char *alias_name = av[0];
		const char *alias_value = find_alias(alias_name);
		struct error *err = NULL;
		int i;

		if (alias_value == NULL) {
			error_msg("No such command or alias: %s", alias_name);
			return;
		}
		if (!parse_commands(&array, alias_value, &err)) {
			error_msg("Parsing alias %s: %s", alias_name, err->msg);
			error_free(err);
			ptr_array_free(&array);
			return;
		}

		/* remove NULL */
		array.count--;

		for (i = 1; av[i]; i++)
			ptr_array_add(&array, xstrdup(av[i]));
		ptr_array_add(&array, NULL);

		run_commands(cmds, &array);
		ptr_array_free(&array);
		return;
	}

	if (config_file && cmds == commands && !allowed_command(cmd->name)) {
		error_msg("Command %s not allowed in config file.", cmd->name);
		return;
	}

	// By default change can't be merged with previous on.
	// Any command can override this by calling begin_change() again.
	begin_change(CHANGE_MERGE_NONE);

	current_command = cmd;
	args = av + 1;
	pf = parse_args(args, cmd->flags, cmd->min_args, cmd->max_args);
	if (pf)
		cmd->cmd(pf, args);
	current_command = NULL;

	end_change();
}
Example #5
0
	//---------------------------------------------------------------------------------
	bool tx_memory_pool::add_alias_tx_pair(std::string & alias, crypto::hash id)
	{
		//check alias repeat or not
		if (alias.size())
		{
			CRITICAL_REGION_LOCAL(m_aliases_lock);
			crypto::hash h = find_alias(alias);
			if (h != null_hash)
			{
				LOG_ERROR("the same alias " << alias << " exists in pool, id: " << h << ", so tx: " << id << " can't be added to pool.");
				return false;
			}
			m_aliases_to_txid[alias] = id;
			LOG_PRINT_L2("Add alias: " << alias << " into pool with tx: " << id);
		}
		return true;
	}
Example #6
0
void build_stubs_output_lib(struct psp_lib *pLib)
{
	FILE *fp;
	char filename[256];

	snprintf(filename, 256, "%s.S", pLib->name);
	if(g_verbose)
	{
		fprintf(stderr, "Writing output file %s\n", filename);
	}
	fp = fopen(filename, "w");
	if(fp != NULL)
	{
		struct psp_export *pExp;

		fprintf(fp, "\t.set noreorder\n\n");
		fprintf(fp, "#include \"pspstub.s\"\n\n");
		fprintf(fp, "\tSTUB_START \"%s\",0x%08X,0x%08X\n", pLib->name, ((pLib->attr | 0x8) << 16) | pLib->ver,
						(pLib->funcCount << 16) | 5);

		pExp = pLib->pFuncHead;
		while(pExp != NULL)
		{
			const char *alias;

			alias = find_alias(pLib->pAliasHead, pExp->name);
			if(alias)
			{
				fprintf(fp, "\tSTUB_FUNC_WITH_ALIAS  0x%08X,%s,%s\n", pExp->nid, pExp->name,alias);
			}
			else
			{
				fprintf(fp, "\tSTUB_FUNC  0x%08X,%s\n", pExp->nid, pExp->name);
			}
			pExp = pExp->pNext;
		}

		fprintf(fp, "\tSTUB_END\n");

		fclose(fp);
	}
	else
	{
		fprintf(stderr, "Error, couldn't open file %s for writing\n", filename);
	}
}
/********************************************************************
 * FUNCTION show_alias_name
 * 
 * Output 1 alias by name
 *
 * INPUTS:
 *    name == name of alias to show (not z-terminated)
 *    namelen == length of name
 *********************************************************************/
static void
    show_alias_name (const xmlChar *name,
                     uint32 namelen)
{
    alias_cb_t *alias = find_alias(name, namelen);

    if (alias) {
        show_alias_ptr(alias);
        log_write("\n");
    } else {
        uint32 i;
        log_error("\nError: alias '");
        for (i = 0; i < namelen; i++) {
            log_error("%c", name[i]);
        }
        log_error("' not found\n");
    }

}  /* show_alias_name */
Example #8
0
File: alias.c Project: jalcim/42sh
int			my_alias(char **al, int opt)
{
	static char	**tb = NULL;

	if (tb && opt == 1)
		return (find_alias(tb, al));
	if (tb && opt == 2)
		return (stock_alias(tb));
	if (opt == 1 || opt == 2)
		return (-1);
	if (!tb)
		tb = (char **)malloc(sizeof(char *) * 1000);
	if (opt == 3)
		return (recup_alias(tb));
	if (opt == -1)
		return (p_alias(tb));
	if (opt == -2)
		return (d_alias(tb, al));
	return (end_alias(tb, al));
}
Example #9
0
File: alias.c Project: wfp5p/elm
static void get_aliases(int are_in_aliases)
{
/*
 *	Get all the system and user alias info
 *
 *	If we get this far, we must be needing to re-read from
 *	at least one data file.  Unfortunately that means we
 *	really need to read both since the aliases may be sorted
 *	and all mixed up...  :-(
 */

	int dups = 0;

	curr_alias = 0;
	num_duplicates = 0;
/*
 *	Read from user data file if it is open.
 */
	if (user_hash != NULL) {
	    dprint(6, (debugfile,
		      "About to read user data file = %s.\n",
	              user_hash->dbz_basefname));
	    fseek(user_hash->dbz_basef, 0L, 0);
	    while (get_one_alias(user_hash, curr_alias)) {
		dprint(8, (debugfile, "%d\t%s\t%s\n", curr_alias+1,
				       aliases[curr_alias]->alias,
				       aliases[curr_alias]->address));

		curr_alias++;
	    }
	}
	num_aliases = curr_alias;		/* Needed for find_alias() */

/*
 *	Read from system data file if it is open.
 */
	if (system_hash != NULL) {
	    dprint(6, (debugfile,
		      "About to read system data file = %s.\n",
	              system_hash->dbz_basefname));
	    fseek(system_hash->dbz_basef, 0L, 0);
	    while (get_one_alias(system_hash, curr_alias)) {
	    /*
	     *  If an identical user alias is found, we may
	     *  not want to display it, so we had better mark it.
	     */
		if (find_alias(aliases[curr_alias]->alias, USER) >= 0) {
		    setit(aliases[curr_alias]->type, DUPLICATE);
		    dups++;
		    setit(aliases[curr_alias]->status, URGENT);
				    /* Not really, I want the U for User */
		    dprint(6, (debugfile,
			       "System alias %s is same as user alias.\n",
			       aliases[curr_alias]->alias));
		}
		dprint(8, (debugfile, "%d\t%s\t%s\n", curr_alias+1,
				       aliases[curr_alias]->alias,
				       aliases[curr_alias]->address));

		curr_alias++;
	    }
	    num_duplicates = dups;
	}
	num_aliases = curr_alias - num_duplicates;

	if (OPMODE_IS_READMODE(opmode) && num_aliases > 0) {
	    curr_alias = 0;
	    sort_aliases((num_aliases+num_duplicates), FALSE, are_in_aliases);
	    curr_alias = 1;
	    if (are_in_aliases) {
	        (void) get_page(curr_alias);
	    }
	}

}
/********************************************************************
 * FUNCTION expand_alias
 * 
 * Check if the first token is an alias name
 * If so, construct a new command line with the alias contents
 *
 * INPUT:
 *   line == command line to check and possibly convert
 *   res == address of return status
 *
 * OUTPUTS:
 *   *res == return status (ERR_NCX_SKIPPED if nothing done)
 *
 * RETURNS:
 *   pointer to malloced command string if *res==NO_ERR
 *   NULL if *res==ERR_NCX_SKIPPED or some real error
 *********************************************************************/
xmlChar *
    expand_alias (xmlChar *line,
                  status_t *res)
{
    xmlChar  *start, *p = line, *newline;
    alias_cb_t *alias;
    uint32    namelen, newlen;
    boolean   done = FALSE;

    /* skip any leading whitespace; not expected from yangcli */
    while (*p && xml_isspace(*p)) {
        p++;
    }
    if (*p == 0) {
        *res = ERR_NCX_SKIPPED;
        return NULL;
    }

    /* look for end of name */
    start = p;
    if (!ncx_valid_fname_ch(*p++)) {
        *res = ERR_NCX_SKIPPED;
        return NULL;
    }
    while (*p && !done) {
        if (xml_isspace(*p)) {
            done = TRUE;
        } else if (!ncx_valid_name_ch(*p)) {
            *res = ERR_NCX_SKIPPED;
            return NULL;
        } else {
            p++;
        }
    }

    /* look for the alias */
    namelen = (uint32)(p - start);
    alias = find_alias(start, namelen);
    if (alias == NULL) {
        *res = ERR_NCX_SKIPPED;
        return NULL;
    }

    /* replace the alias name with its contents and make a new string */
    if (alias->value) {
        newlen = xml_strlen(p) + xml_strlen(alias->value);
    } else {
        newlen = xml_strlen(p);
    }
    newline = m__getMem(newlen + 1);
    if (newline == NULL) {
        *res = ERR_INTERNAL_MEM;
        return NULL;
    }
    start = newline;
    if (alias->value) {
        start += xml_strcpy(start, alias->value);
    }
    xml_strcpy(start, p);

    if (LOGDEBUG2) {
        log_debug2("\nExpanded alias '%s'; new line: '%s'",
                   alias->name, newline);
    }

    *res = NO_ERR;
    return newline;

}  /* expand_alias */
Example #11
0
void build_stubs_output_lib_new(struct psp_lib *pLib)
{
	FILE *fp;
	char filename[256];
	int i;

	snprintf(filename, 256, "%s.S", pLib->name);
	if(g_verbose)
	{
		fprintf(stderr, "Writing output file %s\n", filename);
	}
	fp = fopen(filename, "w");
	if(fp != NULL)
	{
		struct psp_export *pExp;

		fprintf(fp, "\t.set noreorder\n\n");
		fprintf(fp, "#include \"pspimport.s\"\n\n");

		fprintf(fp, "// Build files\n");
		fprintf(fp, "// %s_0000.o ", pLib->name);
		pExp = pLib->pFuncHead;
		i = 1;
		while(pExp != NULL)
		{
			fprintf(fp, "%s_%04d.o ", pLib->name, i++);
			pExp = pExp->pNext;
		}
		fprintf(fp, "\n\n");

		fprintf(fp, "#ifdef F_%s_0000\n", pLib->name);
		fprintf(fp, "\tIMPORT_START \"%s\",0x%08X\n", pLib->name, ((pLib->attr | 0x8) << 16) | pLib->ver);
		fprintf(fp, "#endif\n");

		pExp = pLib->pFuncHead;
		i = 1;
		while(pExp != NULL)
		{
			const char *alias;
			fprintf(fp, "#ifdef F_%s_%04d\n", pLib->name, i++);

			alias = find_alias(pLib->pAliasHead, pExp->name);
			if(alias)
			{
				fprintf(fp, "\tIMPORT_FUNC_WITH_ALIAS  \"%s\",0x%08X,%s,%s\n", pLib->name, pExp->nid, pExp->name, alias);
			}
			else
			{
				fprintf(fp, "\tIMPORT_FUNC  \"%s\",0x%08X,%s\n", pLib->name, pExp->nid, pExp->name);
			}

			fprintf(fp, "#endif\n");
			pExp = pExp->pNext;
		}

		fclose(fp);
	}
	else
	{
		fprintf(stderr, "Error, couldn't open file %s for writing\n", filename);
	}
}
/********************************************************************
 * FUNCTION handle_alias_parm
 * 
 * alias def
 * alias def=def-value
 *
 * Handle the alias command, based on the parameter
 *
 * INPUTS:
 *    varstr == alias command line
 *    setonly == TRUE if expecting set version only; ignore show alias
 *               FALSE if expecting show alias or set alias
 *    loginfo == TRUE if log-level=info should be used
 *               FALSE if log-level=debug2 should be used
 * RETURNS:
 *   status
 *********************************************************************/
static status_t
    handle_alias_parm (const xmlChar *varstr,
                       boolean setonly,
                       boolean loginfo)
{
    const xmlChar *valptr = NULL;    
    uint32    nlen = 0;
    status_t  res;

    res = parse_alias(varstr, &nlen, &valptr);
    if (res == NO_ERR) {
        if (valptr) {
            /* setting an alias */
            alias_cb_t *alias = find_alias(varstr, nlen);
            if (alias) {
                if (LOGDEBUG3) {
                    log_debug3("\nAbout to replace alias '%s'"
                               "\n  old value: '%s'"
                               "\n  new value: '%s'",
                               alias->name, 
                               alias->value ? alias->value : EMPTY_STRING,
                               valptr);
                }
                /* modify an existing alias */
                res = set_alias(alias, valptr);
                if (res == NO_ERR) {
                    if (loginfo) {
                        log_info("\nUpdated alias '%s'\n", alias->name);
                    } else {
                        log_debug2("\nUpdated alias '%s'", alias->name);
                    }
                } else {
                    log_error("\nError: invalid alias value '%s'\n",
                              valptr);
                }
            } else {
                /* create a new alias */
                alias = new_alias(varstr, nlen);
                if (alias == NULL) {
                    res = ERR_INTERNAL_MEM;
                } else {
                    res = set_alias(alias, valptr);
                    if (res == NO_ERR) {
                        res = add_alias(alias);
                        if (res == NO_ERR) {
                            if (loginfo) {
                                log_info("\nAdded alias '%s'\n", alias->name);
                            } else {
                                log_debug2("\nAdded alias '%s'", alias->name);
                            }
                        } else {
                            log_error("\nError: alias was not added '%s'\n",
                                      get_error_string(res));
                        }
                    } else {
                        log_error("\nError: invalid alias value '%s'\n",
                                  valptr);
                        free_alias(alias);
                    }
                }
            }
        } else if (!setonly) {
            /* just provided a name; show alias */
            show_alias_name(varstr, nlen);
        } else if (LOGDEBUG) {
            log_debug("\nSkipping alias '%s' because no value set", varstr);
        }
    } else if (res == ERR_NCX_INVALID_NAME) {
        log_error("\nError: invalid alias (%s)", get_error_string(res));
    } else {
        log_error("\nError: invalid alias '%s' (%s)", varstr,
                  get_error_string(res));
    }
    return res;

}  /* handle_alias_parm */
Example #13
0
int font_load_config(char *confname)
{
    FILE *f;
    FONTREC **flist=&fontlist;
    ATTRIBREC **alist=&attriblist;
    ENCODINGREC **elist=&encodinglist;
    RANGEREC **rlist=&rangelist;
    REMAPREC **rmlist=&remaplist;
    FONTREC *frec;
    char buffer[512];
    char *bpos;
    int linecount=0;
    if (!pmap) {
	pmap=make_pathinfo("MAPPATH",DEFAULTMAPPATH,".map,.ufont");
    }
    f=open_file(pmap, confname, "r");
    if (!f) {
	fprintf(stderr, "Unable to find font configuration '%s'\n", confname);
	return 0;
    }
    /* find the end of these lists */
    while (*flist) flist=&(*flist)->next;
    while (*alist) {
	if ((*alist)->value==-1) maxattrib++;
	alist=&(*alist)->next;
    }
    while (*elist) elist=&(*elist)->next;
    while (*rlist) rlist=&(*rlist)->next;
    while (*rmlist) rmlist=&(*rmlist)->next;
    frec=NULL;
    /* read in the file, line by line */
    /* a buffer of 511 character should suffice */
    while (fgets(buffer, 511, f)) {
	linecount++;
	bpos=buffer;
	skip_spaces(bpos);
	/* skip empty line or comments (starting with #) */
	if (!*bpos || *bpos=='#') continue;
	if (!strncmp(bpos,"ATTRIBUTE", 9)) {
	    /* define a new attribute:
	    ** ATTRIBUTE name value0 value1 value2 value3
	    ** value? is a string used as a reference
	    ** name is the name used to define the attribute
	    ** (so, a line of the form 'name value1' defines the attribute
	    **  name to be equal to value1 for the current font)
	    **
	    ** The font attribute detection algorithm uses these values
	    ** to find default attributes for fonts from their name.
	    */
	    char *c,*h;
	    char tc;
	    int i= -1;
	    c=bpos+9;
	    tc=*c;
	    h=get_string(&c,&tc);
	    while (h) {
		*alist=malloc(sizeof(ATTRIBREC));
		(*alist)->name=
		add_alias(h,
			  ((i<0)?ATTRIBGROUPALIAS:ATTRIBVALUEALIAS(maxattrib)),
			  *alist);
		(*alist)->value=i;
		(*alist)->num=maxattrib;
		h=get_string(&c,&tc);
		i++;
		(*alist)->next=NULL;
		alist=&(*alist)->next;
	    }
	    /* at least one (perhaps two?) value should be specified */
	    if (i>=0) {
		if (!i) {
                    /* no values given */
		    /* h still points to name of the attribute */
		    fprintf(stderr,
			    "%s:%i: No values given for attribute %s\n"
			    "%s:%i: Assuming attribute is not used\n",
			    confname, linecount, h,confname,linecount);
		    i=1;
		}
		attribinfo[maxattrib].max=i;
		if (maxattrib) i=i*attribinfo[maxattrib-1].multby;
		attribinfo[maxattrib].multby=i;
		attribinfo[maxattrib].divby=i/attribinfo[maxattrib].max;
		attribinfo[maxattrib].def=0;
		maxattrib++;
	    } else if (i<0) {
		fprintf(stderr, "%s:%i: No attribute name given\n",
			confname, linecount);
	    }
	} else if (!strncmp(bpos, "ATTRALIAS", 9)) {
	    /* Redefine the attributes for a certain group. These
	    ** attributes might be used in menus and you can adjust
	    ** the menus by changing the attribute names.  Useful
	    ** for localization, for example:
	    ** ATTRIBUTE Weight Medium Bold
	    ** ...
	    ** ATTRALIAS Weight Gewicht Normaal Vet
	    */
	    char *c,*h;
	    char tc;
	    int aliastype;
	    void *aliasdata;
	    ATTRIBREC *ar;
	    c=bpos+9;
	    tc=*c;
	    h=get_string(&c,&tc);
	    aliasdata=find_alias(h,ATTRIBGROUPALIAS);
	    if (!aliasdata) {
		fprintf(stderr, "%s:%i: Unknow attribute name %s\n",
			confname, linecount, h);
		continue;
	    }
	    ar=aliasdata;
	    aliastype=ar->num;
	    h=get_string(&c,&tc);
	    while (ar && (ar->num==aliastype) && h) {
		ar->name=add_alias(h,(ar->value>=0?
				      ATTRIBVALUEALIAS(aliastype):
				      ATTRIBGROUPALIAS),
				   ar);
		ar=ar->next;
		h=get_string(&c,&tc);
	    }
	    if (h) {
		fprintf(stderr, "%s:%i: Too many attributes given\n.",
			confname, linecount);
	    }
	    if (ar && (ar->num==aliastype)) {
		fprintf(stderr, "%s:%i: Not enough values given\n",
			confname, linecount);
	    }
	} else if (!strncmp(bpos, "ATTRREMAP", 9)) {
	    /* Add an entry for remapping an attribute within a group */
	    char *c, *h;
	    char tc;
	    int aliastype;
	    void *aliasdata;
	    ATTRIBREC *ar;
	    ATTRIBREC *oav, *nav;
	    c = bpos+9;
	    tc = *c;
	    h=get_string(&c,&tc);
	    aliasdata=find_alias(h, ATTRIBGROUPALIAS);
	    if (!aliasdata) {
	      fprintf(stderr, "%s:%i: Unknown attribute name %s\n",
		      confname, linecount, h);
	      continue;
	    }
	    ar = aliasdata;
	    aliastype = ar->num;
	    h=get_string(&c, &tc);
	    oav=NULL; nav=NULL;
	    if (h) {
	      oav = find_alias(h, ATTRIBVALUEALIAS(aliastype));
	    }
	    if (oav) {
	      h=get_string(&c, &tc);
	      if (h) {
		nav = find_alias(h, ATTRIBVALUEALIAS(aliastype));
		if (!nav) {
		  fprintf(stderr,
			  "%s:%i: Unknown attribute value %s for group %s\n",
			  confname, linecount, h, ar->name);
		}
	      }
	    } else {
	      fprintf(stderr,
		      "%s:%i: Unknown attribute value %s for group %s\n",
		      confname, linecount, h, ar->name);
	    }
	    if (ar && oav && nav) {
	      *rmlist = malloc(sizeof(REMAPREC));
	      (*rmlist)->attrgroup = aliastype;
	      (*rmlist)->oldval = oav->value;
	      (*rmlist)->newval = nav->value;
	      (*rmlist)->next =0;
	      rmlist = &((*rmlist)->next);
	    }
	} else if (!strncmp(bpos, "ALIAS",5)) {
	    /* Define an alias for some identifier. */
	    char *c,*h;
	    char tc;
	    int aliastype;
	    void *aliasdata;
	    c=bpos+5;
	    tc=*c;
	    h=get_string(&c,&tc);
	    aliasdata=find_aliasname(h,&aliastype);
	    if (!aliasdata) {
		fprintf(stderr, "%s:%i: identifier %s unknown\n",
			confname, linecount, h);
		continue;
	    }
	    h=get_string(&c,&tc);
	    while (h) {
		/* check if h is already defined for that type */
		if (!find_alias(h,aliastype)) {
		    add_alias(h,aliastype, aliasdata);
		}
		h=get_string(&c,&tc);
	    }
	} else if (!strncmp(bpos, "RANGE", 5)) {
	    /* define a range.
	    ** syntax: RANGE name n k-l s-t
	    ** n,k,l,s and t are integers in one of the following formats:
	    ** decimal 65, octal 0101, hexadecimal 0x41, character 'A',
	    ** Unicode U+0041.  Sorry, no i18n for numbers yet.
	    ** The integers indicate the positions in the encoding of
	    ** the font, not in the Unicode encoding.
	    */
	    char *c, *h;
	    char tc;
	    RANGEREC *rr;
	    int len, actnum;
	    c=bpos+5;
	    tc=*c;
	    h=get_string(&c,&tc);
	    if (!h) {
		fprintf(stderr, "%s:%i: No name specified\n",
			confname, linecount);
		continue;
	    }
	    (*rlist)=rr=malloc(sizeof(RANGEREC));
	    rr->name=add_alias(h,RANGEALIAS, rr);
	    rr->next=NULL;
	    rlist=&rr->next;
	    *c=tc;
	    /* upper limit to the length of the needed array is the length
	    ** of the string, since each number takes at least two positions
	    ** Add 2 for a termination pair.
	    */
	    skip_spaces(c);
	    len=strlen(c);
	    actnum=0;
	    rr->ranges=malloc(sizeof(int)*(len+2));
	    while (*c && actnum+1<len) {
		h=c;
		c=get_integer(c, rr->ranges+actnum);
		actnum++;
		if (*c=='-') {
		    c++;
		    c=get_integer(c,rr->ranges+actnum);
		} else {
		    rr->ranges[actnum]=rr->ranges[actnum-1];
		}
		actnum++;
		if (!isspace(*c)) {
		    find_spaces(c);
		    tc=*c;
		    *c=0;
		    fprintf(stderr, "%s:%i: strange range item %s\n",
			    confname, linecount, h);
		    *c=tc;
		}
		skip_spaces(c);
	    }
	    rr->ranges[actnum++]= -1;
	} else if (!strncmp(bpos, "ENCODING", 8)) {
	    /* Define an encoding for a font.
	    ** Multiple encoding can occur on the same line.
	    ** The encoding is only loaded when it is actually used.
	    */
	    char *c,*h;
	    char tc;
	    c=bpos+8;
	    tc=*c;
	    h=get_string(&c,&tc);
	    while (h) {
		*elist=malloc(sizeof(ENCODINGREC));
		(*elist)->encmap=0;
		(*elist)->mapfilename=add_alias(h, ENCODINGALIAS, *elist);
		(*elist)->next=0;
		elist=&(*elist)->next;
		h=get_string(&c,&tc);
	    }
	} else if (!strncmp(bpos, "FONTENC",7)) {
	    /* Define the encoding of the current font.
	    ** The name of the encoding has to be defined in an
	    ** "ENCODING" line, or as an alias for an encoding.
	    */
	    char *c, *h;
	    char tc;
	    ENCODINGREC *er;
	    if (!frec) {
		fprintf(stderr, "%s:%i: Not defining a font yet\n",
			confname,linecount);
		continue;
	    }
	    c=bpos+7;
	    tc=*c;
	    h=get_string(&c,&tc);
	    if (!h) {
		fprintf(stderr, "%s:%i: No encoding specified\n",
			confname, linecount);
		continue;
	    }
	    er=find_alias(h, ENCODINGALIAS);
	    if (!er) {
		fprintf(stderr, "%s:%i: Unknown encoding %s\n",
			confname, linecount, h);
	    } else {
		frec->encoding=er;
	    }
	} else if (!strncmp(bpos, "FONTRANGE",9)) {
	    /* Define the range of a font. Certain fonts might be too
	    ** large or contain too many bad characters.  The range
	    ** is used to select certain characters from a font.
	    ** It will be used when the virtual font is defined and
	    ** when the font is loaded.
	    */
	    char *c, *h;
	    char tc;
	    RANGEREC *rr;
	    if (!frec) {
		fprintf(stderr, "%s:%i: Not defining a font yet\n",
			confname,linecount);
		continue;
	    }
	    c=bpos+9;
	    tc=*c;
	    h=get_string(&c,&tc);
	    if (!h) {
		fprintf(stderr, "%s:%i: No range specified\n",
			confname, linecount);
		continue;
	    }
	    rr=find_alias(h, RANGEALIAS);
	    if (!rr) {
		fprintf(stderr, "%s:%i: Unknown range %s\n",
			confname, linecount, h);
	    } else {
		frec->range=rr;
	    }
	} else if (!strncmp(bpos, "FONT",4)) {
	    /* Start defining a new font with auto-detection of attributes
	    ** and encoding. The auto-detection should not load the font
	    ** itself, but rather use the name of the font to detect
	    ** attributes: matching alias names, using a database.
	    */
	    char *c,*h;
	    char tc;
	    FONTREC *reslist;

	    c=bpos+4;
	    tc=*c;
	    h=get_string(&c,&tc);
	    frec = malloc(sizeof(FONTREC));
	    frec->fontname=malloc(sizeof(char)*(c-h+1)); /* c-h==strlen(h) */
	    strcpy(frec->fontname, h);
	    frec->attribpos=0;
	    frec->encoding=NULL;
	    frec->range=NULL;
	    frec->fonttype=frec->loaded=frec->bt=frec->bm=frec->bmax=0;
	    frec->font=0;
	    frec->systemdata=NULL;
	    frec->next=NULL;
	    /* system specific attribute detection */
	    reslist = multi_detect_attributes(frec);
	    /* Could check if reslist empty. However, it would indicate
	    ** that the font is not available.  Just ignore it or complain.
	    ** If the font would be added anyhow, it could result in messages
	    ** when the font has to be loaded.
	    */
	    if (reslist) {
	      free(frec->fontname);
	      free(frec);
	      *flist = reslist;
	      frec = reslist;
	      while (*flist) flist = &((*flist)->next);
	    } else {
	      free(frec->fontname);
	      free(frec);
	    }
	} else {
	    /* The line starts the name of an attribute followed by
	    ** its value. Find the attribute and the value and change
	    ** the attribute of the current font.
	    */
	    char *c,*h;
	    char tc;
	    ATTRIBREC *ar;
	    ATTRIBREC *aval;
	    int agr;
	    c=bpos;
	    tc=*c;
	    /* get attribute name and look it up */
	    h=get_string(&c,&tc);
	    ar=find_alias(h,ATTRIBGROUPALIAS);
	    if (!ar) {
		fprintf(stderr,"%s:%i: Unknow attribute group %s\n",
			confname, linecount, h);
		continue;
	    }
	    agr=ar->num;
	    /* get attribute value and look it up */
	    h=get_string(&c,&tc);
	    if (!h) {
		fprintf(stderr,"%s:%i: No attribute value specified.\n",
			confname, linecount);
		aval=NULL;
	    } else {
		aval=find_alias(h,ATTRIBVALUEALIAS(agr));
	    }
	    if (!aval) {
		/* Invalid attribute value.
		** Print valid attribute values as feedback.
		*/
		char *vname;
		fprintf(stderr,"%s:%i: Invalid attribute %s\n",
			confname, linecount, h);
		fprintf(stderr,"%s:%i: use one of:", confname, linecount);
		vname=find_type(ATTRIBVALUEALIAS(agr));
		while (vname) {
		    fprintf(stderr, " %s", vname);
		    vname=find_type_next();
		}
		fprintf(stderr, "\n");
		continue;
	    } else if (frec) {
		/* change font attribute of current collection of fonts */
	        FONTREC *flist;
		flist = frec;
		while (flist) {
		  flist->attribpos=change_attribute(flist->attribpos,
						    aval->num,
						    aval->value);
		  flist=flist->next;
		}
	    } else {
		fprintf(stderr, "%s:%i: Not defining a font yet or previous font not found.\n",
			confname, linecount);
	    }
	}
    }
    close_file(f);
    return build_font_structure();
}
Example #14
0
/**************************************************************************************************
	ALIAS_RECURSE
	If the task has a matching ALIAS record, recurse into it.
	Returns the number of records added.
**************************************************************************************************/
int
alias_recurse(TASK *t, datasection_t section, char *fqdn, MYDNS_SOA *soa, char *label, MYDNS_RR *alias)
{
	uint32_t aliases[MAX_ALIAS_LEVEL];
	char name[DNS_MAXNAMELEN+1];
	register MYDNS_RR *rr;
	register int depth, n;

	if (LASTCHAR(alias->data) != '.')
		snprintf(name, sizeof(name), "%s.%s", alias->data, soa->origin);
	else
		strncpy(name, alias->data, sizeof(name)-1);

	for (depth = 0; depth < MAX_ALIAS_LEVEL; depth++)
	{
#if DEBUG_ENABLED && DEBUG_ALIAS
		Debug("%s: ALIAS -> `%s'", desctask(t), name);
#endif
		/* Are there any alias records? */
		if ((rr = find_alias(t, name)))
		{
			/* We need an A record that is not an alias to end the chain. */
			if (rr->alias == 0)
			{
				/* Override the id and name, because rrlist_add() checks for duplicates and we might have several records aliased to one */
				rr->id = alias->id;
				strcpy(rr->name, alias->name);
				rrlist_add(t, section, DNS_RRTYPE_RR, (void *)rr, fqdn);
				t->sort_level++;
				mydns_rr_free(rr);
				return (1);
			}

			/* Append origin if needed */
			int len = strlen(rr->data);
			if (len > 0 && rr->data[len - 1] != '.') {
				strcat(rr->data, ".");
				strncat(rr->data, soa->origin, sizeof(rr->name) - len - 1);
			}

			/* Check aliases list; if we are looping, stop. Otherwise add this to the list. */
			for (n = 0; n < depth; n++)
				if (aliases[n] == rr->id)
				{
					/* ALIAS loop: We aren't going to find an A record, so we're done. */
					Verbose("%s: %s: %s (depth %d)", desctask(t), _("ALIAS loop detected"), fqdn, depth);
					mydns_rr_free(rr);
					return (0);
				}
			aliases[depth] = rr->id;

			/* Continue search with new alias. */
			strncpy(name, rr->data, sizeof(name)-1);
			mydns_rr_free(rr);
		}
		else
		{
			Verbose("%s: %s: %s -> %s", desctask(t), _("ALIAS chain is broken"), fqdn, name);
			return (0);
		}
	}
	Verbose("%s: %s: %s -> %s (depth %d)", desctask(t), _("max ALIAS depth exceeded"), fqdn, alias->data, depth);
	return (0);
}
Example #15
0
static int
add_devs(di_node_t node, di_minor_t minor, void *arg)
{
	struct search_args	*args;
	int result = DI_WALK_CONTINUE;

	args = (struct search_args *)arg;

	if (dm_debug > 1) {
		/* This is all just debugging code */
		char	*devpath;
		char	dev_name[MAXPATHLEN];

		devpath = di_devfs_path(node);
		(void) snprintf(dev_name, sizeof (dev_name), "%s:%s", devpath,
		    di_minor_name(minor));
		di_devfs_path_free((void *) devpath);

		(void) fprintf(stderr,
		    "INFO: dev: %s, node: %s%d, minor: 0x%x, type: %s\n",
		    dev_name, di_node_name(node), di_instance(node),
		    di_minor_spectype(minor),
		    (di_minor_nodetype(minor) != NULL ?
		    di_minor_nodetype(minor) : "NULL"));
	}

	if (bus_type(node, minor, args->ph) != NULL) {
		if (add_bus(args, node, minor, NULL) == NULL) {
			args->dev_walk_status = ENOMEM;
			result = DI_WALK_TERMINATE;
		}

	} else if (is_ctrl(node, minor)) {
		if (add_controller(args, node, minor) == NULL) {
			args->dev_walk_status = ENOMEM;
			result = DI_WALK_TERMINATE;
		}

	} else if (di_minor_spectype(minor) == S_IFCHR &&
	    (is_drive(minor) || is_zvol(node, minor))) {
		char	*devidstr;
		char	kernel_name[MAXPATHLEN];
		disk_t	*diskp;

		(void) snprintf(kernel_name, sizeof (kernel_name), "%s%d",
		    di_node_name(node), di_instance(node));
		devidstr = get_str_prop(DEVICE_ID_PROP, node);

		args->node = node;
		args->minor = minor;
		/*
		 * Check if we already got this disk and
		 * this is another slice.
		 */
		if (!have_disk(args, devidstr, kernel_name, &diskp)) {
			args->dev_walk_status = 0;
			/*
			 * This is a newly found disk, create the
			 * disk structure.
			 */
			diskp = create_disk(devidstr, kernel_name, args);
			if (diskp == NULL) {
				args->dev_walk_status = ENOMEM;
			}

			if (diskp->drv_type != DM_DT_FLOPPY) {
				/* add the controller relationship */
				if (args->dev_walk_status == 0) {
					if (add_disk2controller(diskp,
					    args) != 0) {
						args->dev_walk_status = ENOMEM;
					}
				}
			}
		}
		if (is_zvol(node, minor)) {
			char zvdsk[MAXNAMELEN];
			char *str;
			alias_t *ap;

			if (di_prop_lookup_strings(di_minor_devt(minor),
			    node, "name", &str) == -1)
				return (DI_WALK_CONTINUE);
			(void) snprintf(zvdsk, MAXNAMELEN, "/dev/zvol/rdsk/%s",
			    str);
			if ((ap = find_alias(diskp, kernel_name)) == NULL) {
				if (new_alias(diskp, kernel_name,
				    zvdsk, args) != 0) {
					args->dev_walk_status = ENOMEM;
				}
			} else {
				/*
				 * It is possible that we have already added
				 * this devpath.
				 * Do not add it again. new_devpath will
				 * return a 0 if found, and not add the path.
				 */
				if (new_devpath(ap, zvdsk) != 0) {
					args->dev_walk_status = ENOMEM;
				}
			}
		}

		/* Add the devpaths for the drive. */
		if (args->dev_walk_status == 0) {
			char	*devpath;
			char	slice_path[MAXPATHLEN];
			char	*pattern;

			/*
			 * We will come through here once for each of
			 * the raw slice device names.
			 */
			devpath = di_devfs_path(node);
			(void) snprintf(slice_path,
			    sizeof (slice_path), "%s:%s",
			    devpath, di_minor_name(minor));
			di_devfs_path_free((void *) devpath);

			if (libdiskmgt_str_eq(di_minor_nodetype(minor),
			    DDI_NT_FD)) {
				pattern = DEVLINK_FLOPPY_REGEX;
			} else {
				pattern = DEVLINK_REGEX;
			}

			/* Walk the /dev tree to get the devlinks. */
			(void) di_devlink_walk(args->handle, pattern,
			    slice_path, DI_PRIMARY_LINK, arg, add_devpath);
		}

		if (args->dev_walk_status != 0) {
			result = DI_WALK_TERMINATE;
		}
	}

	return (result);
}
Example #16
0
static int
add_devpath(di_devlink_t devlink, void *arg)
{
	struct search_args *args;
	char		*devidstr;
	disk_t		*diskp;
	char		kernel_name[MAXPATHLEN];

	args =	(struct search_args *)arg;

	/*
	 * Get the diskp value from calling have_disk. Can either be found
	 * by kernel name or devid.
	 */

	diskp = NULL;
	devidstr = get_str_prop(DEVICE_ID_PROP, args->node);
	(void) snprintf(kernel_name, sizeof (kernel_name), "%s%d",
	    di_node_name(args->node), di_instance(args->node));

	(void) have_disk(args, devidstr, kernel_name, &diskp);

	/*
	 * The devlink_path is usually of the form /dev/rdsk/c0t0d0s0.
	 * For diskettes it is /dev/rdiskette*.
	 * On Intel we would also get each fdisk partition as well
	 * (e.g. /dev/rdsk/c0t0d0p0).
	 */
	if (diskp != NULL) {
		alias_t	*ap;
		char	*devlink_path;

		if (diskp->drv_type != DM_DT_FLOPPY) {
			/*
			 * Add other controllers for multipath disks.
			 * This will have no effect if the controller
			 * relationship is already set up.
			 */
			if (add_disk2controller(diskp, args) != 0) {
				args->dev_walk_status = ENOMEM;
			}
		}

		(void) snprintf(kernel_name, sizeof (kernel_name), "%s%d",
		    di_node_name(args->node), di_instance(args->node));
		devlink_path = (char *)di_devlink_path(devlink);

		if (dm_debug > 1) {
			(void) fprintf(stderr,
			    "INFO:     devpath %s\n", devlink_path);
		}

		if ((ap = find_alias(diskp, kernel_name)) == NULL) {
			if (new_alias(diskp, kernel_name, devlink_path,
			    args) != 0) {
				args->dev_walk_status = ENOMEM;
			}
		} else {
			/*
			 * It is possible that we have already added this
			 * devpath.  Do not add it again. new_devpath will
			 * return a 0 if found, and not add the path.
			 */
			if (new_devpath(ap, devlink_path) != 0) {
				args->dev_walk_status = ENOMEM;
			}
		}
	}

	return (DI_WALK_CONTINUE);
}
Example #17
0
	//---------------------------------------------------------------------------------
	bool tx_memory_pool::add_tx(const transaction &tx, const crypto::hash &id, tx_verification_context& tvc, bool kept_by_block, std::string alias)
	{
		size_t blob_size = get_object_blobsize(tx);
		//#9Protection from big transaction flood
		if (!kept_by_block && blob_size > currency::get_max_transaction_blob_size(m_blockchain.get_current_blockchain_height()))
		{
			LOG_PRINT_L0("transaction is too big (" << blob_size << ")bytes for current transaction flow, tx_id: " << id);
			tvc.m_verifivation_failed = true;
			return false;
		}

		if (!check_inputs_types_supported(tx))
		{
			tvc.m_verifivation_failed = true;
			return false;
		}

		uint64_t inputs_amount = 0;
		if (!get_inputs_money_amount(tx, inputs_amount))
		{
			tvc.m_verifivation_failed = true;
			return false;
		}

		uint64_t outputs_amount = get_outs_money_amount(tx);

		if (outputs_amount >= inputs_amount)
		{
			LOG_PRINT_L0("transaction use more money then it has: use " << outputs_amount << ", have " << inputs_amount);
			tvc.m_verifivation_failed = true;
			return false;
		}

		//check key images for transaction if it is not kept by blockhave_tx_keyimges_as_spent
		if (!kept_by_block)
		{
			if (have_tx_keyimges_as_spent(tx))
			{
				LOG_ERROR("Transaction with id= " << id << " used already spent key images");
				tvc.m_verifivation_failed = true;
				return false;
			}

			//transaction spam protection, soft rule
			if (inputs_amount - outputs_amount < TX_POOL_MINIMUM_FEE)
			{
				LOG_ERROR("Transaction with id= " << id << " has too small fee: " << inputs_amount - outputs_amount << ", expected fee: " << DEFAULT_FEE);
				tvc.m_verifivation_failed = true;
				return false;
			}
		}

		crypto::hash max_used_block_id = null_hash;
		uint64_t max_used_block_height = 0;
		bool ch_inp_res = m_blockchain.check_tx_inputs(tx, max_used_block_height, max_used_block_id);
		CRITICAL_REGION_LOCAL(m_transactions_lock);
		if (!ch_inp_res)
		{
			if (kept_by_block)
			{
				//if there is a same alias on the block, then delete the tx with the same alias in the pool
				crypto::hash hash;
				if (alias.size() && (hash = find_alias(alias)) != null_hash)
				{
					transaction tx = AUTO_VAL_INIT(tx);
					size_t size = 0;
					uint64_t  fee = 0;
					take_tx(hash, tx, size, fee);
					LOG_PRINT_L2("Found alias " << alias << " in block, delete pool tx with the same alias: " << id);
				}
				//anyway add this transaction to pool, because it related to block
				auto txd_p = m_transactions.insert(transactions_container::value_type(id, tx_details()));
				if (!txd_p.second)
				{
					return false;
				}

				//CHECK_AND_ASSERT_MES(txd_p.second, false, "transaction already exists at inserting in memory pool");
				txd_p.first->second.blob_size = blob_size;
				txd_p.first->second.tx = tx;
				txd_p.first->second.fee = inputs_amount - outputs_amount;
				txd_p.first->second.max_used_block_id = null_hash;
				txd_p.first->second.max_used_block_height = 0;
				txd_p.first->second.kept_by_block = kept_by_block;
				txd_p.first->second.receive_time = time(nullptr);
				tvc.m_verifivation_impossible = true;
				tvc.m_added_to_pool = true;
			}
			else
			{
				LOG_PRINT_L0("tx used wrong inputs, rejected");
				tvc.m_verifivation_failed = true;
				return false;
			}
		}
		else
		{
			//check alias repeat or not
			if (!add_alias_tx_pair(alias, id))
			{
				tvc.m_verifivation_failed = true;
				tvc.m_added_to_pool = false;
				return false;
			}

			//update transactions container
			auto txd_p = m_transactions.insert(transactions_container::value_type(id, tx_details()));
			if (!txd_p.second)
			{
				return false;
			}

			//CHECK_AND_ASSERT_MES(txd_p.second, false, "intrnal error: transaction already exists at inserting in memorypool");
			txd_p.first->second.blob_size = blob_size;
			txd_p.first->second.tx = tx;
			txd_p.first->second.kept_by_block = kept_by_block;
			txd_p.first->second.fee = inputs_amount - outputs_amount;
			txd_p.first->second.max_used_block_id = max_used_block_id;
			txd_p.first->second.max_used_block_height = max_used_block_height;
			txd_p.first->second.last_failed_height = 0;
			txd_p.first->second.last_failed_id = null_hash;
			txd_p.first->second.receive_time = time(nullptr);
			tvc.m_added_to_pool = true;

			if (txd_p.first->second.fee > 0)
				tvc.m_should_be_relayed = true;
		}

		tvc.m_verifivation_failed = true;
		//update image_keys container, here should everything goes ok.
		BOOST_FOREACH(const auto& in, tx.vin)
		{
			CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, txin, false);
			std::unordered_set<crypto::hash>& kei_image_set = m_spent_key_images[txin.k_image];
			CHECK_AND_ASSERT_MES(kept_by_block || kei_image_set.size() == 0, false, "internal error: keeped_by_block=" << kept_by_block
				<< ",  kei_image_set.size()=" << kei_image_set.size() << ENDL << "txin.k_image=" << txin.k_image << ENDL
				<< "tx_id=" << id);
			auto ins_res = kei_image_set.insert(id);
			CHECK_AND_ASSERT_MES(ins_res.second, false, "internal error: try to insert duplicate iterator in key_image set");
		}

		tvc.m_verifivation_failed = false;
		//succeed
		return true;
	}
Example #18
0
File: alias.c Project: wfp5p/elm
static int get_aliasname(char *aliasname, char *buffer, int *duplicate)
{

/*
 *	Have the user enter an aliasname, check to see if it
 *	is legal, then check for duplicates.  If a duplicate
 *	is found offer to replace existing alias.
 *
 *	Return values:
 *
 *	-1	Either the aliasname was zero length, had bad
 *		characters and was a duplicate which the user
 *		chose not to replace.
 *
 *	0	A new alias was entered successfully.
 *
 *	1	The entered alias was an existing USER alias
 *		that the user has chosen to replace.  In this
 *		case the alias to replace is passed back in
 *		in the variable 'duplicate'.
 */

	int loc;

	do {
	    if (enter_string(aliasname, SLEN,
				LINES-2, strlen(buffer), ESTR_REPLACE) < 0
			|| aliasname[0] == '\0')
	        return(-1);
	} while (check_alias(aliasname) == -1);

	clear_error();			/* Just in case */
/*
 *	Check to see if there is already a USER alias by this name.
 */
	if ((loc = find_alias(aliasname, USER)) >= 0) {
	    dprint(3, (debugfile,
	         "Attempt to add a duplicate alias [%s] in get_aliasname\n",
	         aliases[loc]->alias));
	    if (aliases[loc]->type & GROUP )
	        PutLine(LINES-2,0, catgets(elm_msg_cat,
	                AliasesSet, AliasesAlreadyGroup,
	                "Already a group with name %s."), aliases[loc]->alias);
	    else
	        PutLine(LINES-2,0, catgets(elm_msg_cat,
	                AliasesSet, AliasesAlreadyAlias,
	                "Already an alias for %s."), aliases[loc]->alias);
	    CleartoEOLN();
	 /*
	  * If they don't want to replace the alias by that name
	  * then just return.
	  */
	    if (!enter_yn(catgets(elm_msg_cat, AliasesSet,
			AliasesReplaceExisting,
			"Replace existing alias?"), FALSE, LINES-3, FALSE))
	        return(-1);
	    *duplicate = loc;
	    return(1);
	}
/*
 *	If they have elected to replace an existing alias then
 *	we assume that they would also elect to superceed a
 *	system alias by that name (since they have already
 *	done so).  So we don't even bother to check or ask.
 *
 *	Of course we do check if there was no USER alias match.
 */
	if ((loc = find_alias(aliasname, SYSTEM)) >= 0) {
	    dprint(3, (debugfile,
	      "Attempt to add a duplicate system alias [%s] in get_aliasname\n",
	      aliases[loc]->address));

	    if( ! superceed_system(loc))
	        return(-1);
	}
	return(0);

}
Example #19
0
int load_font_config(PathInfo pmap, char *confname)
{
    FILE *f;
    FONTREC **flist=&fontlist;
    ATTRIBREC **alist=&attriblist;
    ENCODINGREC **elist=&encodinglist;
    RANGEREC **rlist=&rangelist;
    FONTREC *frec;
    char buffer[512];
    char *bpos;
    int linecount=0;
    f=open_file(pmap, confname, "r");
    if (!f) {
	fprintf(stderr, "Unable to load font configuration\n");
	return 0;
    }
    while (*flist) flist=&(*flist)->next;
    while (*alist) {
	if ((*alist)->value==-1) lastattrib++;
	alist=&(*alist)->next;
    }
    while (*elist) elist=&(*elist)->next;
    while (*rlist) rlist=&(*rlist)->next;
    frec=NULL;
    while (fgets(buffer, 511, f)) {
	linecount++;
	bpos=buffer;
	skip_spaces(bpos);
	if (!*bpos || *bpos=='#') continue;
	if (!strncmp(bpos,"ATTRIBUTE", 9)) {
	    /* define a new attribute:
	    ** ATTRIBUTE name value0 value1 value2 value3
	    ** value? is a string used as a reference
	    ** defval is the default value
	    ** name is the name used to define the attribute
	    ** (so, a line of the form 'name value1' defines the attribute
	    **  name to be equal to value1 for the current font)
	    **
	    ** The font attribute detection algorithm uses these values
	    ** to find default attributes for fonts from their name.
	    */
	    char *c,*h;
	    char tc;
	    int i=-1;
	    c=bpos+9;
	    tc=*c;
	    h=get_string(&c,&tc);
	    while (h) {
		*alist=malloc(sizeof(ATTRIBREC));
		(*alist)->name=
		add_alias(h,
			  ((i<0)?ATTRIBGROUPALIAS:ATTRIBVALUEALIAS(lastattrib)),
			  *alist);
		(*alist)->value=i;
		(*alist)->num=lastattrib;
		h=get_string(&c,&tc);
		i++;
		(*alist)->next=NULL;
		alist=&(*alist)->next;
	    }
	    /* at least one (perhaps two?) value should be specified */
	    if (i>=0) {
		if (!i) {
                    /* no values given */
		    /* h still points to name of the attribute */
		    fprintf(stderr,
			    "%s:%i: No values given for attribute %s\n"
			    "%s:%i: Assuming attribute is not used\n",
			    confname, linecount, h,confname,linecount);
		    i=1;
		}
		attribinfo[lastattrib].max=i;
		if (lastattrib) i=i*attribinfo[lastattrib-1].multby;
		attribinfo[lastattrib].multby=i;
		attribinfo[lastattrib].divby=i/attribinfo[lastattrib].max;
		attribinfo[lastattrib].def=0;
		lastattrib++;
	    } else if (i<0) {
		fprintf(stderr, "%s:%i: No attribute name given\n",
			confname, linecount);
	    }
	} else if (!strncmp(bpos, "ATTRALIAS", 9)) {
	    /* Redefine the attributes for a certain group */
	    /* For example:
	    ** ATTRIBUTE Weight Medium Bold
	    ** ...
	    ** ATTRALIAS Weight Gewicht Normaal Vet
	    */
	    char *c,*h;
	    char tc;
	    int aliastype;
	    void *aliasdata;
	    ATTRIBREC *ar;
	    c=bpos+9;
	    tc=*c;
	    h=get_string(&c,&tc);
	    aliasdata=find_alias(h,ATTRIBGROUPALIAS);
	    if (!find_alias) {
		fprintf(stderr, "%s:%i: Unknow attribute name %s\n",
			confname, linecount, h);
		continue;
	    }
	    ar=aliasdata;
	    aliastype=ar->num;
	    h=get_string(&c,&tc);
	    while (ar && (ar->num==aliastype) && h) {
		ar->name=add_alias(h,(ar->value>=0?
				      ATTRIBVALUEALIAS(aliastype):
				      ATTRIBGROUPALIAS),
				   ar);
		ar=ar->next;
		h=get_string(&c,&tc);
	    }
	    if (h) {
		fprintf(stderr, "%s:%i: Too many attributes given\n.",
			confname, linecount);
	    }
	    if (ar && (ar->num==aliastype)) {
		fprintf(stderr, "%s:%i: Not enough values given\n",
			confname, linecount);
	    }
	} else if (!strncmp(bpos, "ALIAS",5)) {
	    /* Define an alias for some identifier. */
	    char *c,*h;
	    char tc;
	    int aliastype;
	    void *aliasdata;
	    c=bpos+5;
	    tc=*c;
	    h=get_string(&c,&tc);
	    aliasdata=find_aliasname(h,&aliastype);
	    if (!aliasdata) {
		fprintf(stderr, "%s:%i: identifier %s unknown\n",
			confname, linecount, h);
		continue;
	    }
	    h=get_string(&c,&tc);
	    while (h) {
		/* check if h is already defined for that type */
		if (!find_alias(h,aliastype)) {
		    add_alias(h,aliastype, aliasdata);
		}
		h=get_string(&c,&tc);
	    }
	} else if (!strncmp(bpos, "RANGE", 5)) {
	    /* define a range.
	    ** syntax: RANGE name n k-l s-t
	    ** n,k,l,s and t are integers in one of the following formats:
	    ** decimal 65, octal 0101, hexadecimal 0x41, character 'A',
	    ** Unicode U+0041.  Sorry, no internationalisation for numbers.
	    */
	    char *c, *h;
	    char tc;
	    RANGEREC *rr;
	    int len, actnum;
	    c=bpos+5;
	    tc=*c;
	    h=get_string(&c,&tc);
	    if (!h) {
		fprintf(stderr, "%s:%i: No name spacified\n",
			confname, linecount);
		continue;
	    }
	    (*rlist)=rr=malloc(sizeof(RANGEREC));
	    rr->name=add_alias(h,RANGEALIAS, rr);
	    rr->next=NULL;
	    rlist=&rr->next;
	    *c=tc;
	    /* upper limit to the length of the needed array is the length
	    ** of the string, since each number takes at least two positions
	    ** Add 2 for a termination pair.
	    */
	    skip_spaces(c);
	    len=strlen(c);
	    actnum=0;
	    rr->ranges=malloc(sizeof(int)*(len+2));
	    while (*c && actnum+1<len) {
		h=c;
		c=get_integer(c, rr->ranges+actnum);
		actnum++;
		if (*c=='-') {
		    c++;
		    c=get_integer(c,rr->ranges+actnum);
		} else {
		    rr->ranges[actnum]=rr->ranges[actnum-1];
		}
		actnum++;
		if (!isspace(*c)) {
		    find_spaces(c);
		    tc=*c;
		    *c=0;
		    fprintf(stderr, "%s:%i: strange range item %s\n",
			    confname, linecount, h);
		    *c=tc;
		}
		skip_spaces(c);
	    }
	    rr->ranges[actnum++]= -1;
	} else if (!strncmp(bpos, "ENCODING", 8)) {
	    /* define an encoding for a font. */
	    char *c,*h;
	    char tc;
	    c=bpos+8;
	    tc=*c;
	    h=get_string(&c,&tc);
	    while (h) {
		*elist=malloc(sizeof(ENCODINGREC));
		(*elist)->encmap=0;
		(*elist)->mapfilename=add_alias(h, ENCODINGALIAS, *elist);
		(*elist)->next=0;
		elist=&(*elist)->next;
		h=get_string(&c,&tc);
	    }
	} else if (!strncmp(bpos, "FONTENC",7)) {
	    char *c, *h;
	    char tc;
	    ENCODINGREC *er;
	    if (!frec) {
		fprintf(stderr, "%s:%i: Not defining a font yet\n",
			confname,linecount);
		continue;
	    }
	    c=bpos+7;
	    tc=*c;
	    h=get_string(&c,&tc);
	    if (!h) {
		fprintf(stderr, "%s:%i: No encoding specified\n",
			confname, linecount);
		continue;
	    }
	    er=find_alias(h, ENCODINGALIAS);
	    if (!er) {
		fprintf(stderr, "%s:%i: Unknown encoding %s\n",
			confname, linecount, h);
	    } else {
		frec->encoding=er;
	    }
	} else if (!strncmp(bpos, "FONTRANGE",9)) {
	    char *c, *h;
	    char tc;
	    RANGEREC *rr;
	    if (!frec) {
		fprintf(stderr, "%s:%i: Not defining a font yet\n",
			confname,linecount);
		continue;
	    }
	    c=bpos+9;
	    tc=*c;
	    h=get_string(&c,&tc);
	    if (!h) {
		fprintf(stderr, "%s:%i: No range specified\n",
			confname, linecount);
		continue;
	    }
	    rr=find_alias(h, RANGEALIAS);
	    if (!rr) {
		fprintf(stderr, "%s:%i: Unknown range %s\n",
			confname, linecount, h);
	    } else {
		frec->range=rr;
	    }
	} else if (!strncmp(bpos, "FONT",4)) {
	    /* Start defining a new font with auto-detection of attributes
	    ** and encoding.
	    */
	    char *c,*h;
	    char tc;

	    c=bpos+4;
	    tc=*c;
	    h=get_string(&c,&tc);
	    frec = (*flist) = malloc(sizeof(FONTREC));
	    frec->fontname=malloc(sizeof(char)*(c-h+1)); /* c-h==strlen(h) */
	    strcpy(frec->fontname, h);
	    frec->attribpos=0;
	    frec->encoding=NULL;
	    frec->range=NULL;
	    frec->fonttype=frec->bt=frec->bm=frec->bmax=0;
	    frec->font=0;
	    frec->fstruct=NULL;
	    frec->next=NULL;
	    flist=&frec->next;
	    /* detect attributes:  !!! X11 specific code
	    ** * divide the font name in parts between '-' signs
	    ** * for each part, check if it is an alias
	    ** If the encoding is not set at the end, combine the
	    ** last two parts and check if that is an alias.
	    ** Keep track which attributes are already set to make
	    ** sure no redefinitions are made.
	    */
	    {  int attrset[MAXATTRIB];
	       char *t;
	       void *aliasdata;
	       int aliastype;
	       int tosetleft;
	       int i;
	       /* add an '-' at the end to process the last item */
	       c[0]='-';c[1]='\0';
	       c=h;
	       for (i=0; i<lastattrib; i++) attrset[i]=0;
	       tosetleft=lastattrib+2; /* range and encoding */
	       t=strchr(h,'-');
	       while (t && tosetleft) {
		   /* skip field of the form "*" and "" */
		   if (*c!='*' && *c!='-') {
		       *t='\0';
		       aliasdata=find_aliasname(c,&aliastype);
		       while (aliasdata) {
			   switch (aliastype) {
			   case RANGEALIAS:
			       if (!frec->range) {
				   frec->range=aliasdata;
				   tosetleft--;
			       }
			       break;
			   case ENCODINGALIAS:
			       if (!frec->encoding) {
				   frec->encoding=aliasdata;
				   tosetleft--;
			       }
			       break;
			   case ATTRIBGROUPALIAS:
			       break;
			   default:
			       /* ATTRIBVALUEALIAS(n) */
			       for (i=0; i<lastattrib; i++) {
				   if (!attrset[i] &&
				       aliastype==ATTRIBVALUEALIAS(i)) {
				       ATTRIBREC *ar=aliasdata;
				       attrset[i]=1;
				       tosetleft--;
				       frec->attribpos =
                                       change_attribute(frec->attribpos,
							ar->num, ar->value);
				       continue;
				   }
			       }
			       break;
			   }
			   aliasdata=find_nextname(&aliastype);
		       }
		       *t='-';
		   }
		   t++;
		   c=t;
		   t=strchr(t,'-');
	       }
	    }
	    if (!frec->encoding) {
		/* try to find encoding in last two items
		** c is at a last position, after the added '-'
		** Remove it and search backward.
		*/
		c--;
		*c='\0';
		while (c>h && *c!='-') c--;   c--;
		while (c>h && *c!='-') c--;
		if (c!=h) {
		    c++;
		    frec->encoding=find_alias(c,ENCODINGALIAS);
		}
	    }
	} else {
	    /* The line starts the name of an attribute followed by
	    ** its value. Find the attribute and the value and change
	    ** the attribute of the current font.
	    */
	    char *c,*h;
	    char tc;
	    ATTRIBREC *ar;
	    ATTRIBREC *aval;
	    int agr;
	    c=bpos;
	    tc=*c;
	    /* get attribute name and look it up */
	    h=get_string(&c,&tc);
	    ar=find_alias(h,ATTRIBGROUPALIAS);
	    if (!ar) {
		fprintf(stderr,"%s:%i: unknow attribute group %s\n",
			confname, linecount, h);
		continue;
	    }
	    agr=ar->num;
	    /* get attribute value and look it up */
	    h=get_string(&c,&tc);
	    if (!h) {
		fprintf(stderr,"%s:%i: no attribute value specified.\n",
			confname, linecount);
		aval=NULL;
	    } else {
		aval=find_alias(h,ATTRIBVALUEALIAS(agr));
	    }
	    if (!aval) {
		char *vname;
		fprintf(stderr,"%s:%i: invalid attribute %s\n",
			confname, linecount, h);
		fprintf(stderr,"%s:%i: use one of:", confname, linecount);
		vname=find_type(ATTRIBVALUEALIAS(agr));
		while (vname) {
		    fprintf(stderr, " %s", vname);
		    vname=find_type_next();
		}
		fprintf(stderr, "\n");
		continue;
	    } else if (frec) {
		/* change font attribute of current font */
		frec->attribpos=change_attribute(frec->attribpos, aval->num,
						 aval->value);
	    } else {
		fprintf(stderr, "%s:%i: Not defining a font yet\n",
			confname, linecount);
	    }
	}
    }
    close_file(f);
    return 0;
}
Example #20
0
static void
grub_ofnet_findcards (void)
{
  auto int search_net_devices (struct grub_ieee1275_devalias *alias);

  int search_net_devices (struct grub_ieee1275_devalias *alias)
  {
    if (!grub_strcmp (alias->type, "network"))
      {
	struct grub_ofnetcard_data *ofdata;
	struct grub_net_card *card;
	grub_ieee1275_phandle_t devhandle;
	grub_net_link_level_address_t lla;
	char *shortname;

	ofdata = grub_malloc (sizeof (struct grub_ofnetcard_data));
	if (!ofdata)
	  {
	    grub_print_error ();
	    return 1;
	  }
	card = grub_zalloc (sizeof (struct grub_net_card));
	if (!card)
	  {
	    grub_free (ofdata);
	    grub_print_error ();
	    return 1;
	  }

	ofdata->path = grub_strdup (alias->path);

	grub_ieee1275_finddevice (ofdata->path, &devhandle);

	if (grub_ieee1275_get_integer_property
	    (devhandle, "max-frame-size", &(ofdata->mtu),
	     sizeof (ofdata->mtu), 0))
	  {
	    ofdata->mtu = 1500;
	  }

	if (grub_ieee1275_get_property (devhandle, "mac-address",
					&(lla.mac), 6, 0)
	    && grub_ieee1275_get_property (devhandle, "local-mac-address",
					   &(lla.mac), 6, 0))
	  {
	    grub_error (GRUB_ERR_IO, "Couldn't retrieve mac address.");
	    grub_print_error ();
	    return 0;
	  }

	lla.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
	card->default_address = lla;

	card->driver = NULL;
	card->data = ofdata;
	card->flags = 0;
	shortname = find_alias (alias->path);
	card->name = grub_xasprintf ("ofnet_%s", shortname ? : alias->path);
	card->idle_poll_delay_ms = 1;
	grub_free (shortname);

	card->driver = &ofdriver;
	grub_net_card_register (card);
	return 0;
      }
    return 0;
  }

  /* Look at all nodes for devices of the type network.  */
  grub_ieee1275_devices_iterate (search_net_devices);
}
Example #21
0
struct commandResult execute_command(struct player * me, char * cmd_buffer, char * cmd_param) {
    World *w = me->world;
    struct commandResult result;
    int ret = 0;
    int moved = 0;

    if(strlen(cmd_buffer) == 0) {
        printf("What?\n");
    }
    else if(has_exit(me->currentRoom, cmd_buffer)) {
        printf("You go: %s\n", cmd_buffer);
        char room_file[30];
        memset(&room_file, '\0', sizeof(char)*30);
        get_exit(&room_file, me->currentRoom, cmd_buffer);
        //free currentRoom..

        struct room * nextRoom = cached_read_room(w, room_file);
        if(nextRoom != NULL) {
            // Also free links, items etc
            //free(me->currentRoom);
            me->currentRoom=NULL;
            me->currentRoom = nextRoom;
            moved = 1;
        } else {
            printf("You didn't move.\n");
        }
    }
    else if(strcmp(cmd_buffer, "examine") == 0) {
      if((me->currentRoom)->items == NULL) {
        printf("You do not notice anything.\n");
      } else {
        printf("You notice:-\n");
        struct item * itemPtr = (me->currentRoom)->items;
          do {
            printf("%s\n", itemPtr->name);
            itemPtr = itemPtr->link;
          } while(itemPtr != NULL);
      }
    }
    else if(strcmp(cmd_buffer, "look") == 0) {
        if(cmd_param != NULL && strlen(cmd_param) > 0) {
    //      printf("%s\n", cmd_param);
            if(strcmp(cmd_param, "me") == 0) {
                time_t now;
                time(&now);
                int seconds = (int)difftime(now, me->connectionTime);

                printf(
"================================================================================\n"
"Player: %s\n"
"================================================================================\n"
"Current room: %s\n"
"Connected for: %d seconds\n",
                me->name, (me->currentRoom)->name, seconds);
            } else {
                printf("You do not notice anything special about: '%s'.\n", cmd_param);
            }
        }
        else {
            look_player(me);
        }
    }
    else if(strcmp(cmd_buffer, "mem") == 0) {
      printf("World: %s\n\n", w->name);
      LoadedRoom *head = w->rooms;
      printf("Loaded rooms:\n");
      do {
        printf("- %s\n", (head->current)->fileName);
        head = head->next;
      } while(head != NULL);
        // && head->next!=NULL);

    }
    else if(strcmp(cmd_buffer, "help") == 0) {
        showHelp();
    }
    else if(strcmp(cmd_buffer, "quit")==0) {
        ret = 1;
    }
    else {
        char expanded[30];
        if(find_alias(&expanded, cmd_buffer, me)) {
            printf("Using alias %s.\n", expanded);
            struct commandResult childResult = execute_command(me, &expanded, cmd_param);
            ret = childResult.exit;
            moved = childResult.moved;

        } else {
            printf("I do not understand: '%s'.. ?\n", cmd_buffer);
        }
    }
    result.exit = ret;
    result.moved = moved;
    return result;
}