Exemplo n.º 1
0
void
lr0_print(lr0_machine_t mach)
{
    for (const struct lr0_state * s = mach->first_state; s; s = s->next) {
        printo(P_LR0_KERNELS, "\nState %u:\n", s->id); // FIXME
        if (print_opt(P_LR0_KERNELS)) {
            struct lr0_point points[s->nclosure];
            unsigned n = lr0_closure(mach, points, s);
            assert(n == s->nclosure);
            for (unsigned i = 0; i < n; ++i) {
                if (! print_opt(P_LR0_CLOSURES) && (i >= s->npoints))
                    break;
                print_point(&points[i], "  ");
            }
        }
        if (print_opt(P_LR0_GOTO) && s->gototab) {
            for (unsigned i = 0; i < s->gototab->ngo; ++i) {
                const struct lr0_state *go = s->gototab->go[i];
                print("    [%s] -> %u\n", go->access_sym->name, go->id);
            }
        }
        if (print_opt(P_LR_REDUCE) && s->reducetab) {
            for (unsigned i = 0; i < s->reducetab->nreduce; ++i) {
                const struct lr_reduce *rdc = &s->reducetab->reduce[i];
                print("    [%s] :< %s ~%u\n", rdc->sym->name, rdc->rule->sym->name, rdc->rule->id);
            }
        }
    }
}
Exemplo n.º 2
0
void printf(char * frmt,...){
    int i;
    char *p, *s, buf[1024];
    va_list argp;

    va_start(argp, frmt);

    for(p=frmt; *p!='\0';p++)
        if(*p=='%'){
            p++; //skip the first % sign
            switch(*p){
                case 'c': putc(va_arg(argp,char));      break;
                case 's': prints(va_arg(argp,char *));  break;
                case 'o': printo(va_arg(argp,u16));     break;
                case 'u': printu(va_arg(argp,u16));     break;
                case 'x': printx(va_arg(argp,u16));     break;
                case 'd': printd(va_arg(argp,int));     break;
                case 'l': printl(va_arg(argp,u32));     break;
                case '%': putc('%');
                    break;
            }
        }
        else{
            switch(*p){
                case '\n': putc(*p);putc('\r');                      break;
                case '\t': for(i=0;i<TAB_SPACE_COUNT;i++)putc(' '); break;
                default: putc(*p); break;
            }
        }
    va_end(argp);
}
Exemplo n.º 3
0
Arquivo: LAB1.c Projeto: Konsada/CS360
void myprintf(char *fmt, ...)
 {

  // char *cp = fmt;
  int *ip;
  char *cp;

  cp=fmt;

  /*while(cp != '\0') // iterate through fmt string until end of string
    {
      cp++;
    }
  cp++; // step over null character
  */
  asm("movl %ebp, FP"); // assign ip to the next parameter after fmt string

  //  ip = FP + 3; // moves the ip pointer over the fp, pc, and fmt
  ip = FP + 2;
  while(*cp != '\0')
    {
      if(*cp == '%')
	{
	  cp++;
	  ip++;
	  if(*cp == 'c')
	    {
	      putchar(*ip);
	    }
	  else if(*cp == 's')
	    {
	      prints((char *)(*ip));
	    }
	  else if(*cp == 'u')
	    {
	      printu(*ip);
	    }
	  else if(*cp == 'd')
	    {
	      printd(*ip);
	    }
	  else if (*cp == 'o')
	    {
	      printo(*ip);
	    }
	  else if(*cp == 'x')
	      printx(*ip);
	}
      else if(*cp == '\n')
	putchar('\n');
      putchar('\r');
      else
	{
	  putchar(*cp);
	}
      cp++;
    }
Exemplo n.º 4
0
int printf(char *fmt, ...)
{
	char *c = fmt;
	int *param = &fmt + 1;

	while(*c)
	{
		if(*c != '%')
		{
			putc(*c);
			if(*c == '\n')
				putc('\r');
		}
		else
		{
			c++;
			switch(*c)
			{
				case 'd':
				printd(*param++);
				//param++;
				break;

				case 's':
				prints(*param++);
				//param++;
				break;

				case 'c':
				putc(*param++);
				//param++;
				break;

				case 'o':
				printo(*param++);
				//param++;
				break;

				case 'x':
				printx(*param++);
				break;

				case 'u':
				printu(*param++);
				break;

				default:
				c--;
				putc(*c);
			}
		}

		c++;
	}
}
Exemplo n.º 5
0
int main()
{
    int a;
    a = ea | eb;

    printo("ea|eb=", a);
    if (a&ea) printo("a|ea=", a&ea);
    if (a&eb) printo("a|eb=", a&eb);
    if (a&ec) printo("a|ec=", a&ec);
    if (a&ed) printo("a|ed=", a&ed);

    a = eb | ed;
    printo("eb|ed=", a);
    if (a&ea) printo("a|ea=", a&ea);
    if (a&eb) printo("a|eb=", a&eb);
    if (a&ec) printo("a|ec=", a&ec);
    if (a&ed) printo("a|ed=", a&ed);

    return(1);
}
Exemplo n.º 6
0
int myprintf(char *fmt, ...) // SOME C compiler requires the 3 DOTsint a, int b, int c, int d
{
   
   	
   int *ip;
   char *cp;
  
   printf("&cp = %8x\n", &cp);
   cp = fmt;
   printf("adress of fmt=%8x\n", &fmt);
  
   
   ip =(&fmt)+1;
    
   /*printf("&cp = %8x\n", &cp);
   printf("*cp = %c\n", *cp);    
   printf("ip = %8x\n", ip); */
   printf("*ip = %d\n", *ip);
   

   for (cp ;*cp != '\0'; cp++){
	if (*cp != '%'){
		putchar(*cp);
		continue;
		}
	if(*cp == '\n'){
		putchar(*cp);
		putchar('\r');
		continue;
		}
	else{
		
		switch(*++cp){
			case 'c' : putchar(*ip);  break;
			case 's' : putchar(*ip);  break;
			case 'u' : printu(*ip);  break;
			case 'd' : printd(*ip);  break;
			case 'o' : printo(*ip);  break;
			case 'x' : printx(*ip);  break;
			}
	     }
	ip--;
   
    }
    printf("\n");
}
Exemplo n.º 7
0
int myprintf(char *fmt, ...)
{	
	//for most instructions that reference memory you must move it to/from a register, since we have an offset of 4 bytes we move into ecx
	//ecx is called the counter register. It is used as a loop counter and for shifts, in this case shift.
	
	//asm("movl 8(%ebp), %ecx"); 
	//asm("movl %ecx, cp"); 
	
	//^ can do it either way
	
	asm("movl %ebp, ip");
	ip += 2;
	cp = (char *) *ip;

	asm("movl %ebp, ip");
	
	ip += 3; // + 12 bytes to get to first parameter
		
	while(*cp != 0){
		
		if(*cp == '%' && *(cp+1) != 0){ //check that cp+1 isn't the end of the string. i.e if you have a string "you got 100%"	
			switch(*(cp + 1)){
				case 'c':
					putchar(*ip);
					cp += 2;
					ip++;
					break;
				case 's':
					prints((char *)*ip);
					cp += 2;
					ip++;
					break;
				case 'u':
					printu(*ip);
					cp += 2;
					ip++;
					break;
				case 'd':
					printd(*ip);
					cp += 2;
					ip++;
					break;
				case 'o':
					printo(*ip);
					cp += 2;
					ip++;
					break;
				case 'x':
					printx(*ip);
					cp += 2;
					ip++;
					break;
				default:
					putchar(*cp++); //incase it's some other letter like %m or %a
			}	
		}
		else if(*cp == '\n'){
			putchar('\n');
			putchar('\r');
			cp++;
		}
		else{
			putchar(*cp++);
		}
	}  
		

}
Exemplo n.º 8
0
void myprintf(char *fmt, ...)
{
    int i = 0;
    char *cp;
    int *bp;
    int *ip;
    int retPC;
    
    cp = fmt;
    bp = (int *)getbp();
    ip = bp;
    retPC = *(ip++);
    // To make ip point to first argument, we have to iterate it by 2
    ip += 2;


    
    i = 0;
    // We loop through the string.
    while(fmt[i] != '\0')
    {
        if(fmt[i] == '\n')  // Case where character is a newline
        {
            putc('\n');
            putc('\r');
        }
        else if(fmt[i] == '%')  // User wants to print either a char, string, int, etc.
        {
            char *cPtr = 0;
            switch(fmt[++i])
            {
                case 's':
                    cPtr = (char *)*ip;
                    prints(cPtr);
                    break;
                case 'u':
                    printu(*ip);    
                    break;
                case 'd':
                    printd(*ip);
                    break;
                case 'o':
                    printo(*ip);
                    break;
                case 'x':
                    printx(*ip);
                    break;
                case 'c':
                    putc(*ip);
                    break;
                default:
                    break;
            }
            ip++;
        }
        else
        {
            putc(fmt[i]);    // Case where just a regular character
        }
        i++;
    }
    
    return;
}
Exemplo n.º 9
0
// Formatted Printing
int myprintf(char *fmt, ...)
{
    //                12    8      4      0
    // ... d | c | b | a | fmt | retPC | ebp | locals ...

    int *ebp = (int*)get_ebp();
    char *cp = fmt;

    // each int ptr increment = 4 bytes 
    // 12 / 4 = 3
    int *ip = ebp + 3;

    while(*cp)
    {
        if (*cp != '%')
        {
            // for each \n, spit out an extra \r
            if (putchar(*cp) == '\n')
                putchar('\r'); 
        }
        else
        {
            cp++; // bypass %
            switch (*cp) // *cp = char after %
            {

                case 'c': // char
                    putchar(*ip);
                    ip++;
                    break;

                case 's': // string
                    prints((char*)(*ip));
                    ip++;	      
                    break;

                case 'd': // int
                    printd(*ip);
                    ip++;
                    break;

                case 'o': // OCTAL 
                    printo(*ip);
                    ip++;
                    break;

                case 'x': // HEX
                    printx(*ip);
                    ip++;
                    break;

                case 'u': // unsigned int
                    printu(*ip);
                    ip++;
                    break;

                case '%': // %% -> %
                    putchar('%');
                    break;

                default: // unknown specifier
                    putchar('%');
                    putchar(*cp);
                    break;

            }// switch(*cp)

        }// if(%)

        cp++;

    } // while(cp)

} // myprintf()
Exemplo n.º 10
0
static int conf_choice(struct menu *menu)
{
	struct symbol *sym, *def_sym;
	struct menu *cmenu, *def_menu;
	const char *help;
	int type, len;
	bool is_new;

	sym = menu->sym;
	type = sym_get_type(sym);
	is_new = !sym_has_value(sym);
	if (sym_is_changable(sym)) {
		conf_sym(menu);
		sym_calc_value(sym);
		switch (sym_get_tristate_value(sym)) {
		case no:
			return 1;
		case mod:
			return 0;
		case yes:
			break;
		}
	} else {
		sym->def = sym->curr;
		if (S_TRI(sym->curr) == mod) {
			printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
			return 0;
		}
	}

	while (1) {
		printf("%*s%s ", indent - 1, "", menu_get_prompt(menu));
		def_sym = sym_get_choice_value(sym);
		def_menu = NULL;
		for (cmenu = menu->list; cmenu; cmenu = cmenu->next) {
			if (!menu_is_visible(cmenu))
				continue;
			printo(menu_get_prompt(cmenu));
			if (cmenu->sym == def_sym)
				def_menu = cmenu;
		}
		printo(NULL);
		if (def_menu)
			printf("[%s] ", menu_get_prompt(def_menu));
		else {
			printf("\n");
			return 1;
		}
		switch (input_mode) {
		case ask_new:
		case ask_silent:
		case ask_all:
			if (is_new)
				sym->flags |= SYMBOL_NEW;
			conf_askvalue(sym, menu_get_prompt(def_menu));
			strip(line);
			break;
		default:
			line[0] = 0;
			printf("\n");
		}
		if (line[0] == '?' && !line[1]) {
			help = nohelp_text;
			if (menu->sym->help)
				help = menu->sym->help;
			printf("\n%s\n", help);
			continue;
		}
		if (line[0]) {
			len = strlen(line);
			line[len] = 0;

			def_menu = NULL;
			for (cmenu = menu->list; cmenu; cmenu = cmenu->next) {
				if (!cmenu->sym || !menu_is_visible(cmenu))
					continue;
				if (!strncasecmp(line, menu_get_prompt(cmenu), len)) {
					def_menu = cmenu;
					break;
				}
			}
		}
		if (def_menu) {
			sym_set_choice_value(sym, def_menu->sym);
			if (def_menu->list) {
				indent += 2;
				conf(def_menu->list);
				indent -= 2;
			}
			return 1;
		}
	}
}