int main( )
{
	Token *test_token = malloc(sizeof(Token));
	char *new_line;

	//valid
	get_source_line(new_line);
	//invalid
	get_source_line(test_token);


    return 0;
}
示例#2
0
static char* get_char(char source_buffer[MAX_TOKEN_STRING_LENGTH], char *token_ptr)
{
    if(source_buffer[0] == NULL)
    {
        if(!get_source_line(source_buffer))
        {
            return '.';
        }
        token_ptr = &source_buffer[0];
    }
    if((*(token_ptr)) == 10)
    {
        if(!get_source_line(source_buffer))
        {
            return '.';
        }
        token_ptr = source_buffer;
        if(*(token_ptr) == '\n')
        {
            token_ptr = get_char(source_buffer,token_ptr);
        }
    }
    if((*(token_ptr)) == 46)
    {
        *token_ptr = '.';
        return token_ptr;
    }
    if((*(token_ptr)) == 123)
    {
        token_ptr = skip_comment(token_ptr);
    }
    if(*token_ptr == 9) // Horizontal Tabs are a pain in my rump!!!
    {
        token_ptr++;
        if(*(token_ptr) == 9) //Recursively make them go away.
        {
            token_ptr = get_char(source_buffer,token_ptr);
        }
    }
    if((*(token_ptr)) == 32)
    {
        token_ptr = skip_blanks(token_ptr); //1.  Skip past all of the blanks
    }
    /*
     If at the end of the current line (how do you check for that?),
     we should call get source line.  If at the EOF (end of file) we should
     set the character ch to EOF and leave the function.
     */
     return token_ptr;
}
示例#3
0
int main (int argc, const char *argv[])
{
    FILE *source_file1;
    source_file1 = fopen("Test.c", "r");
    FILE *source_file2;
    source_file2 = fopen("Image.jpeg, "r");
    char source_name1[MAX_FILE_NAME_LENGTH] = "Test.c";
    char source_name2[MAX_FILE_NAME_LENGTH] = "Imagefile"
    char date1[DATE_STRING_LENGTH] = "Feb Tue 18 20:56:59 2014";
    char date2[DATE_STRING_LENGTH] = "Tue Feb 18 20:56:59 2014";
    char loop_check1 = TRUE;
    char loop_check2 = TRUE;
    char loop_check3 = TRUE;
    char loop_check4 = TRUE;
    char loop_check5 = TRUE;
    char loop_check6 = TRUE;
    char loop_check7 = TRUE;
    char loop_check8 = TRUE;
    

    //copy name of file from input argument into source_name    
    strcpy(source_name, argv[1]);
    
		loop_check1 = get_source_line(source_file1, source_name1, date1); //Valid as all parameters are valid
		loop_check2 = get_source_line(source_file1, source_name1, date2); //Invalid as date2 is in the wrong format
		loop_check3 = get_source_line(source_file1, source_name2, date1); //Invalid as source_name2 is wrong
		loop_check4 = get_source_line(source_file1, source_name2, date2); //Invalid as source_name2 and date2 is wrong
		loop_check5 = get_source_line(source_file2, source_name1, date1); //Invalid as source_file2 is the wrong type
		loop_check6 = get_source_line(source_file2, source_name2, date1); //Invalid as source file2 and source_name 2 is wrong
		loop_check7 = get_source_line(source_file2, source_name2, date1); //source_file2 and source_name2 are invalid
		loop_check8 = get_source_line(source_file2, source_name2, date2); //All parameters are invalid
		
		return 0;
}//end main function
示例#4
0
static PyObject *
warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
{
    static char *kwd_list[] = {"message", "category", "filename", "lineno",
                                "module", "registry", "module_globals",
                                "source", 0};
    PyObject *message;
    PyObject *category;
    PyObject *filename;
    int lineno;
    PyObject *module = NULL;
    PyObject *registry = NULL;
    PyObject *module_globals = NULL;
    PyObject *sourceobj = NULL;
    PyObject *source_line = NULL;
    PyObject *returned;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOUi|OOOO:warn_explicit",
                kwd_list, &message, &category, &filename, &lineno, &module,
                &registry, &module_globals, &sourceobj))
        return NULL;

    if (module_globals) {
        source_line = get_source_line(module_globals, lineno);
        if (source_line == NULL && PyErr_Occurred()) {
            return NULL;
        }
    }
    returned = warn_explicit(category, message, filename, lineno, module,
                             registry, source_line, sourceobj);
    Py_XDECREF(source_line);
    return returned;
}
示例#5
0
//2014.02.21.20
int main(int argc, const char *argv[]) {

	FILE *source_file;
	char source_name[MAX_FILE_NAME_LENGTH];
	char date[DATE_STRING_LENGTH];

	/* Missing Code Here */

	// check number of command-line arguments
	if (argc != 2) {
		puts("There should be two arguments");
		return 1;
	} // end if

	// get the file pointer
	source_file = init_lister(argv[1], source_name, date);

	// get line by line
	while (get_source_line(source_file, source_name, date)) {

	} // end while

	// fclose closes file
	fclose(source_file);
	//return zero for success
	return 0;
}
static void annotate_sym(struct hist_entry *he)
{
	struct map *map = he->map;
	struct dso *dso = map->dso;
	struct symbol *sym = he->sym;
	const char *filename = dso->long_name, *d_filename;
	u64 len;
	char command[PATH_MAX*2];
	FILE *file;

	if (!filename)
		return;

	if (verbose)
		fprintf(stderr, "%s: filename=%s, sym=%s, start=%Lx, end=%Lx\n",
			__func__, filename, sym->name,
			map->unmap_ip(map, sym->start),
			map->unmap_ip(map, sym->end));

	if (full_paths)
		d_filename = filename;
	else
		d_filename = basename(filename);

	len = sym->end - sym->start;

	if (print_line) {
		get_source_line(he, len, filename);
		print_summary(filename);
	}

	printf("\n\n------------------------------------------------\n");
	printf(" Percent |	Source code & Disassembly of %s\n", d_filename);
	printf("------------------------------------------------\n");

	if (verbose >= 2)
		printf("annotating [%p] %30s : [%p] %30s\n",
		       dso, dso->long_name, sym, sym->name);

	sprintf(command, "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS %s|grep -v %s",
		map->unmap_ip(map, sym->start), map->unmap_ip(map, sym->end),
		filename, filename);

	if (verbose >= 3)
		printf("doing: %s\n", command);

	file = popen(command, "r");
	if (!file)
		return;

	while (!feof(file)) {
		if (parse_line(file, he, len) < 0)
			break;
	}

	pclose(file);
	if (print_line)
		free_source_line(he, len);
}
示例#7
0
文件: const_op.cpp 项目: jingqi/silk
OpValue ConstOp::gen_icode(ICodeGenerator *gen)
{
    assert(NULL != gen);

    switch (_const_type)
    {
    case CT_NULL:
        return gen->null_operand(get_source_line());

    case CT_BOOLEAN:
        return gen->boolean_operand(_bool_value, get_source_line());

    case CT_INTEGER:
        return gen->integer_operand(_int_value, get_source_line());

    case CT_FLOAT:
        return gen->float_operand(_float_value, get_source_line());

    case CT_STRING:
        return gen->string_operand(_str_value, get_source_line());

    default:
        throw StaticException("Wrong type of value", get_source_line());
    }
}
示例#8
0
static char get_char(char token_string[]) {
	/*
	 If at the end of the current line (how do you check for that?),
	 we should call get source line.  If at the EOF (end of file) we should
	 set the character ch to EOF and leave the function.

	 Write some code to set the character ch to the next character in the buffer

	 checks the current state of the source_buffer and
	 gets a new line of code if it is at the end of a line.
	 If it sees a Pascal Comment it skips the comment (a pascal comment is anything between ‘{‘ and ‘}’).
	 */

	static char source_buffer[MAX_SOURCE_LINE_LENGTH];
	static size_t i = 0;
	size_t nextIndex = 0;

	char ch;

	if ((source_buffer[i] == '\0') || (source_buffer[i] == '\n')) {
		i = 0;

		BOOLEAN ret = get_source_line(source_buffer);

		if (ret == FALSE) {
			ch = EOF;
			return ch;
		}

		else {

			i = skip_blanks(source_buffer, i);


			i = skip_comment(source_buffer, i);

			ch = source_buffer[i];

		}

	} else {
		ch = source_buffer[i];

	}

	nextIndex = buildToken(source_buffer, token_string, i);

	i = nextIndex;

	return ch;

}
示例#9
0
文件: scanner.c 项目: CSE220Team/Lab3
char get_token()
{
   // char token_string[MAX_TOKEN_STRING_LENGTH]; //Store your token here as you build it.
    get_source_line(token_string);


    while(token_string[0] != '\0')
    {
    	//printf("I went through the while loop: %d times\n", debugCount); //debug line
    	transfer(skipArray,token_string);
        skip_blanks(skipArray);  //1.  Skip past all of the blanks
        transfer(token_string,skipArray);
        //printf("This is token_string after skip_blanks :2%s2\n", token_string); //debug
        //printf("ldksaf");
        if(token_string[0] == '\n')
        {
            return 'a';
        }
        if(token_string[0] == '.')
        {
            printf("\t>> .\t.\n");
            return '.';
        }
        if(isalpha(token_string[0]))
        {
        	get_word();
        }
        else if(isdigit(token_string[0]))
        {
            //token_string = get_number(token_string);
            get_number();
        }
        else if(token_string[0] == '\'')
        {
            //token_string = get_string(token_string);
            get_string();
        }
        else if(token_string[0] == '{'){
        	skip_comment(token_string);
        }
        else
        {
            if(token_string[0] == '.')
            {
                return '.';
            }
            get_special();
        }

    }
    return 'a'; //What should be returned here?
}
示例#10
0
文件: invoke_op.cpp 项目: jingqi/silk
OpValue InvokeOp::gen_icode(ICodeGenerator *gen)
{
    assert(NULL != gen);

    OpValue func = _func->gen_icode(gen);
    const size_t sz = _args.size();
    for (size_t i = 0; i < sz; ++i)
    {
        Op *p = _args.at(i);
        gen->push_param(p->gen_icode(gen), p->get_source_line());
    }
    return gen->invoke_op(func, sz, get_source_line());
}
示例#11
0
文件: scanner.c 项目: rgonza26/3rdLab
char get_char()
{
    char c;
    if(*ch == EOF) {
        return EOF;
    } else if(*ch == '\n' || *ch == '\0' || *ch == '\r') {
        get_source_line(line_buffer);
        ch = &line_buffer;
    }
    c = *ch;
    ch++;
    return c;
}
示例#12
0
int main (int argc, const char *argv[])
{
    FILE *source_file;
    char source_name[MAX_FILE_NAME_LENGTH];
    char date[DATE_STRING_LENGTH];
    
	source_file = init_lister(argv[1], source_name, date); //calls init_lister to initialize file
	
	while(get_source_line(source_file, source_name, date)) //runs until there are no more lines
	{
		
	}
	
    return 0;
}
示例#13
0
	int func_main (int argc, char *filename) {

        
        //Initialization of variables
        FILE *file = NULL;
        char source_file_name[MAX_FILE_NAME_LENGTH] = {'\0'};
        char date[DATE_STRING_LENGTH] = {'\0'};
        
        //Get date/time, Open File
        file = init_lister(filename, source_file_name, date);
        
        //Read/Print lines
        while (get_source_line(file, source_file_name, date));
        
        return 0;
        
    }
示例#14
0
文件: scanner.c 项目: rgonza26/3rdLab
void init_scanner(FILE *source_file, char source_name[], char date[])
{
    int asciiChar;
    src_file = source_file;
    strcpy(src_name, source_name);
    strcpy(todays_date, date);

    /*0,      1,     2,     3,       4,		   5		*/
    /*LETTER, DIGIT, QUOTE, SPECIAL, EOF_CODE, UNUSED	*/
    for(asciiChar = 0; asciiChar <= 255; asciiChar++) {
        char_table[asciiChar] = UNUSED;
    }
    for(asciiChar = 48; asciiChar<=57; asciiChar++) {
        char_table[asciiChar] = DIGIT;
    }
    for(asciiChar = 65; asciiChar <= 90; asciiChar++) {
        char_table[asciiChar] = LETTER;
    }
    for(asciiChar = 97; asciiChar <= 122; asciiChar++) {
        char_table[asciiChar] = LETTER;
    }
    /*	SPECIAL CHARACTERS:
    ^ * ( ) - + = [ ] : ; < > , . / := <= >= <> ..
    */
    for(asciiChar = 40; asciiChar <= 47; asciiChar++) {
        char_table[asciiChar] = SPECIAL;
    }
    for(asciiChar = 58; asciiChar <= 62; asciiChar++) {
        char_table[asciiChar] = SPECIAL;
    }
    for(asciiChar = 91; asciiChar <= 94; asciiChar++) {
        char_table[asciiChar] = SPECIAL;
    }
    char_table[95] = LETTER;	/* _underscore_	*/
    char_table[39] = QUOTE;
    char_table[32] = UNUSED;	/*	' space '	*/

    get_source_line(line_buffer);
}
示例#15
0
char get_char(char** ch)
{
    /*
     If at the end of the current line (how do you check for that?),
     we should call get source line.  If at the EOF (end of file) we should
     set the character ch to EOF and leave the function.
     */
    if(*(*ch) == '\n'){
    	if(get_source_line(src_name)){
			(*ch) = src_name;
		}
		else{
			*(*ch) = EOF;
		}
    }
    else if(*(*ch) != '\0'){
    	(*ch)++;
    }
    /*
     Write some code to set the character ch to the next character in the buffer
     */
     return *(*ch);
}
示例#16
0
/*
 * Extract a Python traceback from the given exception data.
 *
 * The exception error message is returned in xmsg, the traceback in
 * tbmsg (both as palloc'd strings) and the traceback depth in
 * tb_depth.
 *
 * We release refcounts on all the Python objects in the traceback stack,
 * but not on e or v.
 */
static void
PLy_traceback(PyObject *e, PyObject *v, PyObject *tb,
			  char **xmsg, char **tbmsg, int *tb_depth)
{
	PyObject   *e_type_o;
	PyObject   *e_module_o;
	char	   *e_type_s = NULL;
	char	   *e_module_s = NULL;
	PyObject   *vob = NULL;
	char	   *vstr;
	StringInfoData xstr;
	StringInfoData tbstr;

	/*
	 * if no exception, return nulls
	 */
	if (e == NULL)
	{
		*xmsg = NULL;
		*tbmsg = NULL;
		*tb_depth = 0;

		return;
	}

	/*
	 * Format the exception and its value and put it in xmsg.
	 */

	e_type_o = PyObject_GetAttrString(e, "__name__");
	e_module_o = PyObject_GetAttrString(e, "__module__");
	if (e_type_o)
		e_type_s = PyString_AsString(e_type_o);
	if (e_type_s)
		e_module_s = PyString_AsString(e_module_o);

	if (v && ((vob = PyObject_Str(v)) != NULL))
		vstr = PyString_AsString(vob);
	else
		vstr = "unknown";

	initStringInfo(&xstr);
	if (!e_type_s || !e_module_s)
	{
		if (PyString_Check(e))
			/* deprecated string exceptions */
			appendStringInfoString(&xstr, PyString_AsString(e));
		else
			/* shouldn't happen */
			appendStringInfoString(&xstr, "unrecognized exception");
	}
	/* mimics behavior of traceback.format_exception_only */
	else if (strcmp(e_module_s, "builtins") == 0
			 || strcmp(e_module_s, "__main__") == 0
			 || strcmp(e_module_s, "exceptions") == 0)
		appendStringInfo(&xstr, "%s", e_type_s);
	else
		appendStringInfo(&xstr, "%s.%s", e_module_s, e_type_s);
	appendStringInfo(&xstr, ": %s", vstr);

	*xmsg = xstr.data;

	/*
	 * Now format the traceback and put it in tbmsg.
	 */

	*tb_depth = 0;
	initStringInfo(&tbstr);
	/* Mimick Python traceback reporting as close as possible. */
	appendStringInfoString(&tbstr, "Traceback (most recent call last):");
	while (tb != NULL && tb != Py_None)
	{
		PyObject   *volatile tb_prev = NULL;
		PyObject   *volatile frame = NULL;
		PyObject   *volatile code = NULL;
		PyObject   *volatile name = NULL;
		PyObject   *volatile lineno = NULL;
		PyObject   *volatile filename = NULL;

		PG_TRY();
		{
			/*
			 * Ancient versions of Python (circa 2.3) contain a bug whereby
			 * the fetches below can fail if the error indicator is set.
			 */
			PyErr_Clear();

			lineno = PyObject_GetAttrString(tb, "tb_lineno");
			if (lineno == NULL)
				elog(ERROR, "could not get line number from Python traceback");

			frame = PyObject_GetAttrString(tb, "tb_frame");
			if (frame == NULL)
				elog(ERROR, "could not get frame from Python traceback");

			code = PyObject_GetAttrString(frame, "f_code");
			if (code == NULL)
				elog(ERROR, "could not get code object from Python frame");

			name = PyObject_GetAttrString(code, "co_name");
			if (name == NULL)
				elog(ERROR, "could not get function name from Python code object");

			filename = PyObject_GetAttrString(code, "co_filename");
			if (filename == NULL)
				elog(ERROR, "could not get file name from Python code object");
		}
		PG_CATCH();
		{
			Py_XDECREF(frame);
			Py_XDECREF(code);
			Py_XDECREF(name);
			Py_XDECREF(lineno);
			Py_XDECREF(filename);
			PG_RE_THROW();
		}
		PG_END_TRY();

		/* The first frame always points at <module>, skip it. */
		if (*tb_depth > 0)
		{
			PLyExecutionContext *exec_ctx = PLy_current_execution_context();
			char	   *proname;
			char	   *fname;
			char	   *line;
			char	   *plain_filename;
			long		plain_lineno;

			/*
			 * The second frame points at the internal function, but to mimick
			 * Python error reporting we want to say <module>.
			 */
			if (*tb_depth == 1)
				fname = "<module>";
			else
				fname = PyString_AsString(name);

			proname = PLy_procedure_name(exec_ctx->curr_proc);
			plain_filename = PyString_AsString(filename);
			plain_lineno = PyInt_AsLong(lineno);

			if (proname == NULL)
				appendStringInfo(
				&tbstr, "\n  PL/Python anonymous code block, line %ld, in %s",
								 plain_lineno - 1, fname);
			else
				appendStringInfo(
					&tbstr, "\n  PL/Python function \"%s\", line %ld, in %s",
								 proname, plain_lineno - 1, fname);

			/*
			 * function code object was compiled with "<string>" as the
			 * filename
			 */
			if (exec_ctx->curr_proc && plain_filename != NULL &&
				strcmp(plain_filename, "<string>") == 0)
			{
				/*
				 * If we know the current procedure, append the exact line
				 * from the source, again mimicking Python's traceback.py
				 * module behavior.  We could store the already line-split
				 * source to avoid splitting it every time, but producing a
				 * traceback is not the most important scenario to optimize
				 * for.  But we do not go as far as traceback.py in reading
				 * the source of imported modules.
				 */
				line = get_source_line(exec_ctx->curr_proc->src, plain_lineno);
				if (line)
				{
					appendStringInfo(&tbstr, "\n    %s", line);
					pfree(line);
				}
			}
		}

		Py_DECREF(frame);
		Py_DECREF(code);
		Py_DECREF(name);
		Py_DECREF(lineno);
		Py_DECREF(filename);

		/* Release the current frame and go to the next one. */
		tb_prev = tb;
		tb = PyObject_GetAttrString(tb, "tb_next");
		Assert(tb_prev != Py_None);
		Py_DECREF(tb_prev);
		if (tb == NULL)
			elog(ERROR, "could not traverse Python traceback");
		(*tb_depth)++;
	}

	/* Return the traceback. */
	*tbmsg = tbstr.data;

	Py_XDECREF(e_type_o);
	Py_XDECREF(e_module_o);
	Py_XDECREF(vob);
}