Beispiel #1
0
static tokenType parseVhdlFile (tokenInfo * const token)
{
	do
	{
		readToken (token);
		parseKeywords (token, FALSE);
	} while (!isKeyword (token, KEYWORD_END) && !isType (token, TOKEN_EOF));
	return token->type;
}
Beispiel #2
0
char* Parser::regularExpression(char *expression) {
    trimBothParanthesis(expression);

    //If there is no operators return expression(end condition).
    operator_s op0 = findOperator(expression, 0);
    if (op0.pos == -1) {
        Alias_s a;
        //Is it a stack call?
        a = parseKeywords(expression);

        if (strlen(a.value) == 0) {
            memcpy(a.value, expression, a.len);
        }
        return a.value;
    }

    int len = strlen(expression);
    operator_s op1 = findOperator(expression, op0.pos + op0.len);
    if (op1.pos != -1) {

        //Negative number.
        if (op0.pos != -1 && op1.op[0] == '-' && op1.pos == op0.pos +1) {
            int len = strlen(expression);
        } else {
            //If there is a second operator set len = operator.
            len = op1.pos;
        }
    }

    memcpy(tmpLhs, expression, len);
    tmpLhs[len] = '\0';

    int rhsLen = strlen(expression) - len;
    memcpy(tmpRhs, expression + len, rhsLen);
    tmpRhs[rhsLen] = '\0';

    char *res = calculateResult(tmpLhs);

    len = strlen(res);
    memcpy(tmpStr, res, len);
    tmpStr[len] = '\0';

    strcat(tmpStr, tmpRhs);
    tmpStr[len + strlen(tmpRhs)] = '\0';

    //Negative number.
    if (isNegativeNumber(tmpStr)) {
        return tmpStr;
    }

    //recursion.
    regularExpression(tmpStr);

    return tmpStr;
}
Beispiel #3
0
static int proc_get_usblpid(struct usblp *usblp)
{
//JYWeng 20031212: set this as global   char *strtmp, *str_dev_id, *strunknown="unknown"; // Added by PaN
        char *strtmp, *str_dev_id; // Added by PaN: JYWeng 20031212: modified from the above
        int i, unk = 0; // Added by PaN
        int length, err;
        int retval = 0;

        prn_info= &prn_info_tmp; // Added by JYWeng 20031212:


        err = usblp_get_id(usblp, 0, usblp->device_id_string, USBLP_DEVICE_ID_SIZE - 1);

        if (err < 0) {
                dbg ("usblp%d: error = %d reading IEEE-1284 Device ID string",
                        usblp->minor, err);
                        usblp->device_id_string[0] = usblp->device_id_string[1] = '\0';
                retval = -EIO;
                goto done;
        }

        length = (usblp->device_id_string[0] << 8) + usblp->device_id_string[1]; /* big-endian */
        if (length < USBLP_DEVICE_ID_SIZE)
                usblp->device_id_string[length] = '\0';
        else
                usblp->device_id_string[USBLP_DEVICE_ID_SIZE - 1] = '\0';

        dbg ("usblp%d Device ID string [%d]='%s'",
                usblp->minor, length, &usblp->device_id_string[2]);

        str_dev_id = &usblp->device_id_string[2];
#if 1//JYWeng 20031212: modified from below
                                parseKeywords(str_dev_id, "MFG:", "MANUFACTURE:", prn_info->mfr, usblpid_info.mfr);
                                parseKeywords(str_dev_id, "MDL:", "MODEL:", prn_info->model, usblpid_info.model);
                                parseKeywords(str_dev_id, "CLS:", "CLASS:", prn_info->class_name, usblpid_info.class_name);
                                parseKeywords(str_dev_id, "DES:", "DESCRIPTION:", prn_info->description, usblpid_info.description);
#endif//JYWeng 20031212: end

done:
        return retval;

}
Beispiel #4
0
static int proc_get_usblpid(struct usblp *usblp)
{
	char *str_dev_id; // Added by PaN: JYWeng 20031212: modified from the above
	int length;

	length = usblp_cache_device_id_string(usblp);
	if (length < 0)
		return length;

	info ("usblp%d Device ID string [%d]='%s'",
		usblp->minor, length, &usblp->device_id_string[2]);

	str_dev_id = &usblp->device_id_string[2];	
//JYWeng 20031212: modified from below
	parseKeywords(str_dev_id, "MFG:", "MANUFACTURE:", usblp->usblpid_info->mfr);
	parseKeywords(str_dev_id, "MDL:", "MODEL:", usblp->usblpid_info->model);
	parseKeywords(str_dev_id, "CLS:", "CLASS:", usblp->usblpid_info->class_name);
	parseKeywords(str_dev_id, "DES:", "DESCRIPTION:", usblp->usblpid_info->description);
//JYWeng 20031212: end

	return 0;
}
Beispiel #5
0
static void parseSubProgram (tokenInfo * const token)
{
	tokenInfo *const name = newToken ();
	boolean endSubProgram = FALSE;
	const vhdlKind kind = isKeyword (token, KEYWORD_FUNCTION) ?
		VHDLTAG_FUNCTION : VHDLTAG_PROCEDURE;
	Assert (isKeyword (token, KEYWORD_FUNCTION) ||
		isKeyword (token, KEYWORD_PROCEDURE));
	readToken (name);	/* the name of the function or procedure */
	readToken (token);
	if (isType (token, TOKEN_OPEN_PAREN))
	{
		skipToMatched (token);
	}

	if (kind == VHDLTAG_FUNCTION)
	{
		if (isKeyword (token, KEYWORD_RETURN))
		{
			/* Read datatype */
			readToken (token);
			while (! isKeyword (token, KEYWORD_IS) &&
					! isType (token, TOKEN_SEMICOLON) &&
					! isType (token, TOKEN_EOF))
			{
				readToken (token);
			}
		}
	}

	if (isType (token, TOKEN_SEMICOLON))
	{
		makeVhdlTag (name, VHDLTAG_PROTOTYPE);
	}
	else if (isKeyword (token, KEYWORD_IS))
	{
		if (kind == VHDLTAG_FUNCTION)
		{
			makeVhdlTag (name, VHDLTAG_FUNCTION);
			do
			{
				readToken (token);
				if (isKeyword (token, KEYWORD_END))
				{
					readToken (token);
					endSubProgram = isKeywordOrIdent (token,
						KEYWORD_FUNCTION, name->string);
					fileSkipToCharacter (';');
				}
				else
				{
					if (isType (token, TOKEN_EOF))
					{
						endSubProgram = TRUE;
					}
					else
					{
						parseKeywords (token, TRUE);
					}
				}
			} while (!endSubProgram);
		}
		else
		{
			makeVhdlTag (name, VHDLTAG_PROCEDURE);
			do
			{
				readToken (token);
				if (isKeyword (token, KEYWORD_END))
				{
					readToken (token);
					endSubProgram = isKeywordOrIdent (token,
						KEYWORD_PROCEDURE, name->string);
					fileSkipToCharacter (';');
				}
				else
				{
					if (isType (token, TOKEN_EOF))
					{
						endSubProgram = TRUE;
					}
					else
					{
						parseKeywords (token, TRUE);
					}
				}
			} while (!endSubProgram);
		}
	}
	deleteToken (name);
}
Beispiel #6
0
static long usblp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	struct usblp *usblp = file->private_data;
        struct print_buffer user_buf_tmp, *user_buf; // Added by PaN
        char *strtmp, *str_dev_id; // Added by PaN: JYWeng 20031212: modified from the above
        int unk=0; // Added by PaN ---remove declaration of i for i is declared below: JY
	int length, err, i;
	unsigned char newChannel;
	int status;
	int twoints[2];
	int retval = 0;

	mutex_lock(&usblp->mut);
	if (!usblp->present) {
		retval = -ENODEV;
		goto done;
	}

	dbg("usblp_ioctl: cmd=0x%x (%c nr=%d len=%d dir=%d)", cmd, _IOC_TYPE(cmd),
		_IOC_NR(cmd), _IOC_SIZE(cmd), _IOC_DIR(cmd));

	if (_IOC_TYPE(cmd) == 'P')	/* new-style ioctl number */

		switch (_IOC_NR(cmd)) {

		case IOCNR_GET_DEVICE_ID: /* get the DEVICE_ID string */
			if (_IOC_DIR(cmd) != _IOC_READ) {
				retval = -EINVAL;
				goto done;
			}

			length = usblp_cache_device_id_string(usblp);
			if (length < 0) {
				retval = length;
				goto done;
			}
			if (length > _IOC_SIZE(cmd))
				length = _IOC_SIZE(cmd); /* truncate */

			if (copy_to_user((void __user *) arg,
					usblp->device_id_string,
					(unsigned long) length)) {
				retval = -EFAULT;
				goto done;
			}

			break;

		case IOCNR_GET_PROTOCOLS:
			if (_IOC_DIR(cmd) != _IOC_READ ||
			    _IOC_SIZE(cmd) < sizeof(twoints)) {
				retval = -EINVAL;
				goto done;
			}

			twoints[0] = usblp->current_protocol;
			twoints[1] = 0;
			for (i = USBLP_FIRST_PROTOCOL;
			     i <= USBLP_LAST_PROTOCOL; i++) {
				if (usblp->protocol[i].alt_setting >= 0)
					twoints[1] |= (1<<i);
			}

			if (copy_to_user((void __user *)arg,
					(unsigned char *)twoints,
					sizeof(twoints))) {
				retval = -EFAULT;
				goto done;
			}

			break;

		case IOCNR_SET_PROTOCOL:
			if (_IOC_DIR(cmd) != _IOC_WRITE) {
				retval = -EINVAL;
				goto done;
			}

#ifdef DEBUG
			if (arg == -10) {
				usblp_dump(usblp);
				break;
			}
#endif

			usblp_unlink_urbs(usblp);
			retval = usblp_set_protocol(usblp, arg);
			if (retval < 0) {
				usblp_set_protocol(usblp,
					usblp->current_protocol);
			}
			break;

		case IOCNR_HP_SET_CHANNEL:
			if (_IOC_DIR(cmd) != _IOC_WRITE ||
			    le16_to_cpu(usblp->dev->descriptor.idVendor) != 0x03F0 ||
			    usblp->quirks & USBLP_QUIRK_BIDIR) {
				retval = -EINVAL;
				goto done;
			}

			err = usblp_hp_channel_change_request(usblp,
				arg, &newChannel);
			if (err < 0) {
				dev_err(&usblp->dev->dev,
					"usblp%d: error = %d setting "
					"HP channel\n",
					usblp->minor, err);
				retval = -EIO;
				goto done;
			}

			dbg("usblp%d requested/got HP channel %ld/%d",
				usblp->minor, arg, newChannel);
			break;

		case IOCNR_GET_BUS_ADDRESS:
			if (_IOC_DIR(cmd) != _IOC_READ ||
			    _IOC_SIZE(cmd) < sizeof(twoints)) {
				retval = -EINVAL;
				goto done;
			}

			twoints[0] = usblp->dev->bus->busnum;
			twoints[1] = usblp->dev->devnum;
			if (copy_to_user((void __user *)arg,
					(unsigned char *)twoints,
					sizeof(twoints))) {
				retval = -EFAULT;
				goto done;
			}

			dbg("usblp%d is bus=%d, device=%d",
				usblp->minor, twoints[0], twoints[1]);
			break;

		case IOCNR_GET_VID_PID:
			if (_IOC_DIR(cmd) != _IOC_READ ||
			    _IOC_SIZE(cmd) < sizeof(twoints)) {
				retval = -EINVAL;
				goto done;
			}

			twoints[0] = le16_to_cpu(usblp->dev->descriptor.idVendor);
			twoints[1] = le16_to_cpu(usblp->dev->descriptor.idProduct);
			if (copy_to_user((void __user *)arg,
					(unsigned char *)twoints,
					sizeof(twoints))) {
				retval = -EFAULT;
				goto done;
			}

			dbg("usblp%d is VID=0x%4.4X, PID=0x%4.4X",
				usblp->minor, twoints[0], twoints[1]);
			break;

		case IOCNR_SOFT_RESET:
			if (_IOC_DIR(cmd) != _IOC_NONE) {
				retval = -EINVAL;
				goto done;
			}
			retval = usblp_reset(usblp);
			break;
		default:
			retval = -ENOTTY;
		}
	else	/* old-style ioctl value */
		switch (cmd) {
                        /*=================================================================================== PaN */
                        case LPGETID: /* get the DEVICE_ID string */
                                err = usblp_get_id(usblp, 0, usblp->device_id_string, USBLP_DEVICE_ID_SIZE - 1);
                                if (err < 0) {
                                        dbg ("usblp%d: error = %d reading IEEE-1284 Device ID string",
                                                usblp->minor, err);
                                        usblp->device_id_string[0] = usblp->device_id_string[1] = '\0';
                                        retval = -EIO;
                                        goto done;
                                }

                                length = (usblp->device_id_string[0] << 8) + usblp->device_id_string[1]; /* big-endian */
                                if (length < USBLP_DEVICE_ID_SIZE)
                                        usblp->device_id_string[length] = '\0';
                                else
                                        usblp->device_id_string[USBLP_DEVICE_ID_SIZE - 1] = '\0';

                                dbg ("usblp%d Device ID string [%d/max %d]='%s'",
                                        usblp->minor, length, cmd, &usblp->device_id_string[2]);

                                str_dev_id = &usblp->device_id_string[2];
#if 1//JYWeng 20031212: modified from below
                                parseKeywords(str_dev_id, "MFG:", "MANUFACTURE:", prn_info->mfr, usblpid_info.mfr);
                                parseKeywords(str_dev_id, "MDL:", "MODEL:", prn_info->model, usblpid_info.model);
                                parseKeywords(str_dev_id, "CLS:", "CLASS:", prn_info->class_name, usblpid_info.class_name);
                                parseKeywords(str_dev_id, "DES:", "DESCRIPTION:", prn_info->description, usblpid_info.description);
#endif//JYWeng 20031212: end

                                dbg ("Parsing USBLPID...");
                                if (copy_to_user((unsigned char *) arg,
                                                prn_info, (unsigned long) length)) {
                                        retval = -EFAULT;
                                        goto done;
                                }
                                break;

                        case LPREADDATA:
                                mutex_unlock (&usblp_mutex);
                                user_buf = (struct print_buffer *)arg;
                                retval = usblp_read(file, user_buf->buf, user_buf->len, NULL);
                                mutex_lock (&usblp_mutex);
                                break;


                        case LPWRITEDATA:
                                mutex_unlock (&usblp_mutex);
                                user_buf = (struct print_buffer *)arg;
                                retval = usblp_write(file, user_buf->buf, user_buf->len, NULL);
                                mutex_lock (&usblp_mutex);
                                break;

                        case LPRESET:
                                usblp_reset(usblp);
                                break;

			case LPGETSTATUS:
				/* OLD USB Code Removed by PaN for Printer Server
				if ((retval = usblp_read_status(usblp, usblp->statusbuf))) {
					if (printk_ratelimit())
						printk(KERN_ERR "usblp%d:"
					    	"failed reading printer status (%d)\n",
					    	usblp->minor, retval);
					retval = -EIO;
					goto done;
				}
				status = *usblp->statusbuf;
				*/
				status = 0;
				if (copy_to_user((void __user *)arg, &status, sizeof(int)))
				retval = -EFAULT;
			break;
/*=================================================================== PaN for Printer Server */

		case LPABORT:
			if (arg)
				usblp->flags |= LP_ABORT;
			else
				usblp->flags &= ~LP_ABORT;
			break;

		default:
			retval = -ENOTTY;
		}

done:
	mutex_unlock(&usblp->mut);
	return retval;
}
Beispiel #7
0
char* Parser::calculateResult(char *exp) {
    tmpStr[0] = '\0'; //reseting...

    operator_s op0 = findOperator(exp, 0);

    char lhs[INSTRUCTIONSIZE];
    char rhs[INSTRUCTIONSIZE];

    memcpy(lhs, exp, op0.pos);
    lhs[op0.pos] = '\0';

    int rhsLen = strlen(exp) - op0.pos;
    memcpy(rhs, exp + op0.pos + op0.len, rhsLen);
    rhs[rhsLen] = '\0';

    Alias_s aliasLhs = parseKeywords(lhs);
    Alias_s aliasRhs = parseKeywords(rhs);

    if (strCmp(aliasLhs.value, "")) {
        //alias need to be set to an default value, DO CRASH!!!
    } else if (strCmp(aliasRhs.value, "")) {
        //alias need to be set to an default value, DO CRASH!!!
    }

    //do calculation
    //Both are digits
    if (strCmp(aliasLhs.type, "int") && strCmp(aliasRhs.type, "int")) {
        if (strCmp(op0.op, "+")) {
            sprintf(tmpStr, "%d", atoi(aliasLhs.value) + atoi(aliasRhs.value));
        } else if (strCmp(op0.op, "-")) {
            sprintf(tmpStr, "%d", atoi(aliasLhs.value) - atoi(aliasRhs.value));
        } else if (strCmp(op0.op, "*")) {
            sprintf(tmpStr, "%d", atoi(aliasLhs.value) * atoi(aliasRhs.value));
        } else if (strCmp(op0.op, "/")) {
            sprintf(tmpStr, "%d", atoi(aliasLhs.value) / atoi(aliasRhs.value));
            int v = atoi(tmpStr);
            if (v < 0) {
                tmpStr[0] = '0';
                tmpStr[1] = '\0';
            }
        } else if (strCmp(op0.op, "==")) {
            if (strCmp(aliasLhs.value, aliasRhs.value)) {
                memcpy(tmpStr, "true", 4);
                tmpStr[4] = '\0';
            } else {
                memcpy(tmpStr, "false", 5);
                tmpStr[5] = '\0';
            }
        } else if (strCmp(op0.op, "!=")) {
            if (strCmp(aliasLhs.value, aliasRhs.value)) {
                memcpy(tmpStr, "false", 5);
                tmpStr[5] = '\0';
            } else {
                memcpy(tmpStr, "true", 4);
                tmpStr[4] = '\0';
            }
        } else if (strCmp(op0.op, "<")) {
            int l = atoi(aliasLhs.value);
            int r = atoi(aliasRhs.value);
            if (l < r) {
                memcpy(tmpStr, "true", 4);
                tmpStr[4] = '\0';
            } else {
                memcpy(tmpStr, "false", 5);
                tmpStr[5] = '\0';
            }
        } else if (strCmp(op0.op, ">")) {
            int l = atoi(aliasLhs.value);
            int r = atoi(aliasRhs.value);
            if (l < r) {
                memcpy(tmpStr, "true", 4);
                tmpStr[4] = '\0';
            } else {
                memcpy(tmpStr, "false", 5);
                tmpStr[5] = '\0';
            }
        } else if (strCmp(op0.op, "=")) {
            memcpy(&aliasLhs.value, &aliasRhs.value, aliasRhs.len);
            aliasLhs.value[aliasRhs.len] = '\0';
            aliasLhs.len = aliasRhs.len;
            int a = heap.getAddress(aliasLhs.name);
            heap.insertAliasAt(a, aliasLhs);
        } else {
            //Wrong syntax do CRASH!!!
        }
    }
    //Both are text strings.
    else if (strCmp(aliasLhs.type, "string") && strCmp(aliasRhs.type, "string")) {
        if (strCmp(op0.op, "+")) {
            return strcat(aliasLhs.value, aliasRhs.value);
        } else if (strCmp(op0.op, "-")) {
            //Wrong syntax do CRASH!!!
        } else if (strCmp(op0.op, "*")) {
            //Wrong syntax do CRASH!!!
        } else if (strCmp(op0.op, "/")) {
            //Wrong syntax do CRASH!!!
        } else if (strCmp(op0.op, "==")) {
            if (strCmp(aliasLhs.value, aliasRhs.value)) {
                memcpy(tmpStr, "true", 4);
                tmpStr[4] = '\0';
            } else {
                memcpy(tmpStr, "false", 5);
                tmpStr[5] = '\0';
            }
        } else if (strCmp(op0.op, "!=")) {
            if (strCmp(aliasLhs.value, aliasRhs.value)) {
                memcpy(tmpStr, "false", 5);
                tmpStr[5] = '\0';
            } else {
                memcpy(tmpStr, "true", 4);
                tmpStr[4] = '\0';
            }
        } else if (strCmp(op0.op, "<")) {
            if (aliasLhs.len < aliasRhs.len) {
                memcpy(tmpStr, "true", 4);
                tmpStr[4] = '\0';
            } else {
                memcpy(tmpStr, "false", 5);
                tmpStr[5] = '\0';
            }
        } else if (strCmp(op0.op, ">")) {
            if (aliasLhs.len > aliasRhs.len) {
                memcpy(tmpStr, "true", 4);
                tmpStr[4] = '\0';
            } else {
                memcpy(tmpStr, "false", 5);
                tmpStr[5] = '\0';
            }
        } else if (strCmp(op0.op, "=")) {
            memcpy(aliasLhs.value, aliasRhs.value, strlen(aliasLhs.value));
            aliasLhs.len == aliasRhs.len;
            int a = heap.getAddress(aliasLhs.name);
            heap.insertAliasAt(a, aliasLhs);
        } else {
            //Wrong syntax do CRASH!
        }
    } else {
        //Cannot compare digits and strings.
    }

    return tmpStr;
}