コード例 #1
0
ファイル: pkgdep.c プロジェクト: razzlefratz/MotleyTools
static void function (FIND * find, flag_t flags)

{
	if (! match (find->filename, find->wildcard))
	{
		return;
	}
	if (efreopen (find->fullname, "rb", stdin))
	{
		SCAN scan;
		char package [FILENAME_MAX];
		char scratch [FILENAME_MAX];
		char buffer [TEXTLINE_MAX];
		size_t line;
		scaninput (& scan, buffer, sizeof (buffer));
		for (line = 0; ~ fgetline (buffer, sizeof (buffer), stdin); line++)
		{
			scanwhile (& scan, gcsASCIIAlpha ".");
			scanbreak (& scan, ":");
			if (havetoken (& scan, "Name:"))
			{
				scanuntil (& scan, gcsBreak);
				extract (& scan, package, sizeof (package));
			}
			else if (havetoken (& scan, "Requires:"))
			{
				while (tokensize (& scan))
				{
					if (isclass (& scan, "A"))
					{
						extract (& scan, scratch, sizeof (scratch));
						printf ("\"%s\",\"%s\"\n", package, scratch);
					}
					nexttoken (& scan);
				}
			}
			else if (havetoken (& scan, "Requires.private:"))
			{
				while (tokensize (& scan))
				{
					if (isclass (& scan, "A"))
					{
						extract (& scan, scratch, sizeof (scratch));
						printf ("\"%s\",\"%s\"\n", package, scratch);
					}
					nexttoken (& scan);
				}
			}
			scanstart (& scan);
		}
	}
	return;
}
コード例 #2
0
ファイル: ptlhwdef.cpp プロジェクト: zhongliang/cache_life
stringbuf& operator <<(stringbuf& sb, const TransOpBase& op) {
  static const char* size_names[4] = {"b", "w", "d", ""};
  // e.g. addfp, addfv, addfd, xxx
  static const char* fptype_names[4] = {".s", ".vs", ".d", ".d"};

  bool ld = isload(op.opcode);
  bool st = isstore(op.opcode);
  bool fp = (isclass(op.opcode, OPCLASS_FP_ALU));
  bool br = isbranch(op.opcode);

  stringbuf sbname;

  sbname << nameof(op.opcode);
  if (!(opinfo[op.opcode].flagops & opNOSIZE)) sbname << (fp ? fptype_names[op.size] : size_names[op.size]);

  if (isclass(op.opcode, OPCLASS_USECOND)) sbname << ".", cond_code_names[op.cond];

  if (ld|st) {
    if (op.opcode == OP_mf) {
      static const char* mf_names[4] = {"none", "st", "ld", "all"};
      sbname << '.', mf_names[op.extshift];
    }
    sbname << ((op.cond == LDST_ALIGN_LO) ? ".lo" : (op.cond == LDST_ALIGN_HI) ? ".hi" : "");
  } else if ((op.opcode == OP_mask) || (op.opcode == OP_maskb)) {
    sbname << ((op.cond == 0) ? "" : (op.cond == 1) ? ".z" : (op.cond == 2) ? ".x" : ".???");
  }

  if ((ld|st) && (op.cachelevel > 0)) sbname << ".L", (char)('1' + op.cachelevel);
  if ((ld|st) && (op.locked)) sbname << ((ld) ? ".acq" : ".rel");
  if (op.internal) sbname << ".p";
  if (op.eom) sbname << ".", (op.any_flags_in_insn ? "+" : "-");

  sb << padstring((char*)sbname, -12), " ", arch_reg_names[op.rd];
  if ((op.rd < ARCHREG_COUNT) & (!op.final_arch_in_insn)) sb << ".t";

  sb << " = ";
  if (ld|st) sb << "[";
  sb << arch_reg_names[op.ra];
  if (op.rb == REG_imm) {
    if (abs(op.rbimm) <= 32768) sb << ",", op.rbimm; else sb << ",", (void*)op.rbimm;
  } else {
    sb << ",", arch_reg_names[op.rb];
  }
  if (ld|st) sb << "]";
  if ((op.opcode == OP_mask) | (op.opcode == OP_maskb)) {
    MaskControlInfo mci(op.rcimm);
    int sh = (op.opcode == OP_maskb) ? 3 : 0;
    sb << ",[ms=", (mci.info.ms >> sh), " mc=", (mci.info.mc >> sh), " ds=", (mci.info.ds >> sh), "]";
  } else {
コード例 #3
0
ファイル: printer.c プロジェクト: alhazred/onarm
papi_status_t
papiPrinterRemove(papi_service_t handle, char *name)
{
	papi_status_t result;
	char *dest;

	if ((handle == NULL) || (name == NULL))
		return (PAPI_BAD_ARGUMENT);

	dest = printer_name_from_uri_id(name, -1);

	if (isprinter(dest) != 0) {
		result = lpsched_remove_printer(handle, dest);
	} else if (isclass(dest) != 0) {
		result = lpsched_remove_class(handle, dest);
	} else
		result = PAPI_NOT_FOUND;

	free(dest);

	return (result);
}
コード例 #4
0
ファイル: printer.c プロジェクト: alhazred/onarm
papi_status_t
papiPrinterAdd(papi_service_t handle, char *name,
		papi_attribute_t **attributes, papi_printer_t *result)
{
	papi_status_t status;
	printer_t *p = NULL;
	char *dest;

	if ((handle == NULL) || (name == NULL) || (attributes == NULL))
		return (PAPI_BAD_ARGUMENT);

	dest = printer_name_from_uri_id(name, -1);

	if (isprinter(dest) != 0) {
		status = lpsched_add_modify_printer(handle, dest,
							attributes, 0);

		if ((*result = p = calloc(1, sizeof (*p))) != NULL)
			lpsched_printer_configuration_to_attributes(handle, p,
									dest);
		else
			status = PAPI_TEMPORARY_ERROR;

	} else if (isclass(dest) != 0) {
		status = lpsched_add_modify_class(handle, dest, attributes);

		if ((*result = p = calloc(1, sizeof (*p))) != NULL)
			lpsched_class_configuration_to_attributes(handle, p,
									dest);
		else
			status = PAPI_TEMPORARY_ERROR;

	} else
		status = PAPI_NOT_FOUND;

	free(dest);

	return (status);
}
コード例 #5
0
ファイル: zparser.c プロジェクト: liweiwei05/shuke
/*!
 * parse all text RR fields, including owner name, ttl, class, type, rdata.
 * the parsed data will be stored in zone object.
 *
 * @param psr : the RRParser object.
 * @param ss : the text string of the RR.
 * @param name : the owner name. there are two situations:
 *              1. name is NULL then the ss should start with a owner name or a space.
 *                 this situation is mainly for RR stored in text file.
 *              2. name is not NULL, then ss should ignore owner name and only contain ttl, class(optional), type and rdata.
 *                 this situation is mainly for RR stored in databases(redis, mongodb, etc).
 * @param z : the zone object this RR belongs to.
 * @return OK_CODE if everything is ok otherwise return ERR_CODE.
 */
int RRParserFeed(RRParser *psr, char *ss, char *name, zone *z) {
    bool no_type = true;
    bool check_soa_top = true;
    char *tok;
    int err = OK_CODE;
    RRParserReset(psr);
    if (RRParserTokenize(psr, ss) < 0) {
        goto error;
    }
    if (name != NULL) {
        check_soa_top = false;
        strncpy(psr->name, name, MAX_DOMAIN_LEN);
        if (abs2lenRelative(psr->name, psr->dotOrigin) == ERR_CODE) {
            snprintf(psr->errstr, ERR_STR_LEN, "syntax error: invalid domain name(%s), dotOrigin(%s)", name, psr->dotOrigin);
            goto error;
        }
    } else {
        if (*ss != ' ') {
            strncpy(psr->name, psr->tokens[0], MAX_DOMAIN_LEN);
            if (abs2lenRelative(psr->name, psr->dotOrigin) == ERR_CODE) {
                // LOG_DEBUG("%s %s", psr->tokens[0], psr->dotOrigin);
                snprintf(psr->errstr, ERR_STR_LEN, "%s is not a valid domain name.", psr->tokens[0]);
                goto error;
            }
            psr->start_idx = 1;
        }
    }
    for (int i = 0; i < 3; ++i) {
        tok = RRParserNextToken(psr);
        if (tok == NULL) {
            snprintf(psr->errstr, ERR_STR_LEN, "no field for ttl, class and type");
            goto error;
        }
        if (isttl(tok)) {
            psr->ttl = (uint32_t)atoi(tok);
            if (psr->ttl > MAX_TTL) psr->ttl = MAX_TTL;
        } else if (isclass(tok)) {
            continue;
        } else {    // a type?
            int ret = strToDNSType(tok);
            if (ret == ERR_CODE) {
                snprintf(psr->errstr, ERR_STR_LEN, "%s is not a ttl, class or type", tok);
                goto error;
            }
            psr->type = (uint16_t)ret;
            no_type = false;
            break;
        }
    }
    if (no_type) {
        snprintf(psr->errstr, ERR_STR_LEN, "no type field");
        goto error;
    }
    if (RRParserDoParse(psr, z, check_soa_top) == ERR_CODE) goto error;
    goto ok;
error:
    psr->err = PARSER_ERR;
    err = ERR_CODE;
ok:
    return err;
}
コード例 #6
0
ファイル: printer.c プロジェクト: alhazred/onarm
papi_status_t
papiPrinterQuery(papi_service_t handle, char *name,
		char **requested_attrs,
		papi_attribute_t **job_attrs,
		papi_printer_t *printer)
{
	papi_status_t pst;
	service_t *svc = handle;
	printer_t *p = NULL;
	char *dest;
	short status = MOK;
	char *pname = NULL,
		*form = NULL,
		*request_id = NULL,
		*character_set = NULL,
		*reject_reason = NULL,
		*disable_reason = NULL;
	short printer_status = 0;
	long enable_date = 0, reject_date = 0;

	if ((handle == NULL) || (name == NULL) || (printer == NULL))
		return (PAPI_BAD_ARGUMENT);

	if ((*printer = p = calloc(1, sizeof (*p))) == NULL)
		return (PAPI_TEMPORARY_ERROR);

	dest = printer_name_from_uri_id(name, -1);

	if (strcmp(dest, "_default") == 0) {
		static char *_default;

		if (_default == NULL) {
			int fd;
			static char buf[128];

			if ((fd = open("/etc/lp/default", O_RDONLY)) >= 0) {
				read(fd, buf, sizeof (buf));
				close(fd);
				_default = strtok(buf, " \t\n");
			}
		}
		dest = _default;
	}

	if (isprinter(dest) != 0) {
		pst = lpsched_printer_configuration_to_attributes(svc, p, dest);
		if (pst != PAPI_OK)
			return (pst);

		/* get the spooler status data now */
		if (snd_msg(svc, S_INQUIRE_PRINTER_STATUS, dest) < 0)
			return (PAPI_SERVICE_UNAVAILABLE);

		if (rcv_msg(svc, R_INQUIRE_PRINTER_STATUS, &status, &pname,
				&form, &character_set, &disable_reason,
				&reject_reason, &printer_status, &request_id,
				&enable_date, &reject_date) < 0)
			return (PAPI_SERVICE_UNAVAILABLE);

		printer_status_to_attributes(p, pname, form, character_set,
				disable_reason, reject_reason, printer_status,
				request_id, enable_date, reject_date);
	} else if (isclass(dest) != 0) {
		pst = lpsched_class_configuration_to_attributes(svc, p, dest);
		if (pst != PAPI_OK)
			return (pst);

		/* get the spooler status data now */
		if (snd_msg(svc, S_INQUIRE_CLASS, dest) < 0)
			return (PAPI_SERVICE_UNAVAILABLE);

		if (rcv_msg(svc, R_INQUIRE_CLASS, &status, &pname,
				&printer_status, &reject_reason,
				&reject_date) < 0)
			return (PAPI_SERVICE_UNAVAILABLE);

		class_status_to_attributes(p, pname, printer_status,
				reject_reason, reject_date);
	} else if (strcmp(dest, "PrintService") == 0) {
		/* fill the printer object with service information */
		lpsched_service_information(&p->attributes);
	} else
		return (PAPI_NOT_FOUND);

	free(dest);

	return (PAPI_OK);
}