Beispiel #1
0
void process_msg(char *msg)
{
	int i = 0;
	int j = 0;
	int delay = 0;
	char tmp = '\0';
	char sy = '\0';
	char *symbol = NULL;
	for(i = 0; i < strlen(msg); i++)
	{
		tmp = msg[i];
		symbol = get_symbol(tmp);
		if (tmp == ' ')
		{
			delay = 6 * UNIT_DELAY;
		}
		else
		{
			printf("%c = ", tmp);
			fflush(stdout);
			for(j = 0; j < strlen(symbol); j++)
			{
				sy = symbol[j];
				printf("%c", sy);
				fflush(stdout);
				process_symbol(sy);
				usleep(short_delay);
			}
			delay = 2 * UNIT_DELAY;
		}
		usleep(delay);
		printf("\n");
	}
}
Beispiel #2
0
token getToken(fileStruct *files)
{
	token outToken;
    wipeout(&outToken);
	char c,array[2];

	c=fgetc(files->input);
	
    while(c==' '||c=='\t'||c=='\n')
    {
        array[0]=c;
        array[1]='\0';
        strcat(linebuff,array);
        if(c=='\n')
        {
            fprintf(files->lis_file,"%d %s",linenum,linebuff);
            linenum++;
            memset(linebuff,0,sizeof(linebuff));
        }
        c=fgetc(files->input);
    }

    if (c == -1) {
        outToken.actual[0] = ':'; 
        outToken.actual[1] = 'D';
        strcpy(outToken.type, "SCANEOF");
        outToken.number = SCANEOF;
    }
    else if(isalpha(c))
    {
        outToken=process_alpha(c, files);
    }
    else if(isdigit(c))
    {
        outToken=process_num(c,files);
    }
    else if(ispunct(c))
    {
        outToken=process_symbol(c,files);
    }	
    else {
        outToken.actual[0] = c;
        strcpy(outToken.type, "ERROR");
        outToken.number = ERROR;
    }

    fprintf(files->tmp1, "\nTOKEN %s\nTYPE %s\nNUMBER %d\n", outToken.actual, outToken.type, outToken.number);

    return outToken;
}
Beispiel #3
0
/*
 * read kernel symbol from /proc/kallsyms
 */
int kallsyms_parse(void *arg,
		   int(*process_symbol)(void *arg, const char *name,
		   char type, unsigned long start))
{
	int ret = 0;
	FILE *file;
	char *line = NULL;

	file = fopen(KALLSYMS_PATH, "r");
	if (file == NULL)
		handle_error("open " KALLSYMS_PATH " failed");

	while (!feof(file)) {
		char *symbol_name;
		char symbol_type;
		int line_len, len;
		unsigned long start;
		size_t n;

		line_len = getline(&line, &n, file);
		if (line_len < 0 || !line)
			break;

		line[--line_len] = '\0'; /* \n */

		len = hex2u64(line, &start);
		len++;
		if (len + 2 >= line_len)
			continue;

		symbol_type = line[len];
		len += 2;
		symbol_name = line + len;
		len = line_len - len;

		if (len >= KSYM_NAME_LEN) {
			ret = -1;
			break;
		}

		ret = process_symbol(arg, symbol_name, symbol_type, start);
		if (ret)
			break;
	}

	free(line);
	fclose(file);

	return ret;
}
Beispiel #4
0
/*
 * read kernel symbol from /proc/kallsyms
 */
int kallsyms_parse(void *arg,
		   int(*process_symbol)(void *arg, const char *name,
		   char type, unsigned long start))
{
	FILE *file;
	char *line = NULL;
	int ret = 0;
	int found = 0;

	file = fopen(KALLSYMS_PATH, "r");
	if (file == NULL)
		handle_error("open " KALLSYMS_PATH " failed");

	while (!feof(file)) {
		char *symbol_addr, *symbol_name;
		char symbol_type;
		unsigned long start;
		int line_len;
		size_t n;

		line_len = getline(&line, &n, file);
		if (line_len < 0 || !line)
			break;

		line[--line_len] = '\0'; /* \n */

		symbol_addr = strtok(line, " \t");
		start = strtoul(symbol_addr, NULL, 16);

		symbol_type = *strtok(NULL, " \t");
		symbol_name = strtok(NULL, " \t");

		ret = process_symbol(arg, symbol_name, symbol_type, start);
		if (!ret)
			found = 1;
	}

	free(line);
	fclose(file);

	return found;
}