예제 #1
0
파일: prf.c 프로젝트: TijmenW/FreeDOS
WORD CDECL sprintf(BYTE * buff, CONST BYTE * fmt, ...)
{
  WORD ret;

  charp = buff;
  ret = do_printf(fmt, (BYTE **) & fmt + 1);
  handle_char(NULL);
  return ret;
}
예제 #2
0
static bool clear_iir(void) {
    uint8_t iir;
    while (! ((iir = read_iir()) & IIR_PENDING)) {
        switch(iir & IIR_REASON) {
        case IIR_RDA:
        case IIR_TIME:
            while (read_lsr() & LSR_DATA_READY) {
                bool result = handle_char();
                if (result) {
                    return result;
                }
            }
        default:
            break;
        }
    }
    return false;
}
예제 #3
0
파일: tokenizer.cpp 프로젝트: k8e/school
std::vector<Token> Tokenizer::getTokens(std::ifstream & input) {
    // Reads input file, processing character by character.
    // Returns vector of tokens found.

    char c;

    // Read input file while processing characters
    while (input.get(c)) {
        // Analyze character
        handle_char(c);

        // Start processing next token
        if (buffer_ready) {
            init_state(c);
        }
    } // Finished processing intput file

    // Return vector of tokens
    return tokens;
}
예제 #4
0
static void clear_iir() {
    uint8_t iir;
    while (! ((iir = read_iir()) & IIR_PENDING)) {
        switch(iir & IIR_REASON) {
        case IIR_MSR:
            read_msr();
            break;
        case IIR_THR:
            break;
        case IIR_RDA:
        case IIR_TIME:
            while (read_lsr() & LSR_DATA_READY) {
                handle_char(read_rbr());
            }
            break;
        case IIR_LSR:
            read_lsr();
            break;
        }
    }
}
예제 #5
0
static cb_ret_t
query_callback (Dlg_head *h, dlg_msg_t msg, int parm)
{
    switch (msg) {
    case DLG_KEY:
	switch (parm) {
	case KEY_LEFT:
	case KEY_RIGHT:
	    h->ret_value = 0;
	    dlg_stop (h);
	    return 1;

	case KEY_BACKSPACE:
	    if (end == min_end) {
		h->ret_value = 0;
		dlg_stop (h);
		return 1;
	    } else {
		WLEntry *e, *e1;

		e1 = e = ((WListbox *) (h->current))->list;
		do {
		    if (!strncmp
			(input->buffer + start, e1->text,
			 end - start - 1)) {
			listbox_select_entry ((WListbox *) (h->current),
					      e1);
			handle_char (input, parm);
			end--;
			send_message (h->current, WIDGET_DRAW, 0);
			break;
		    }
		    e1 = e1->next;
		} while (e != e1);
	    }
	    return 1;

	default:
	    if (parm > 0xff || !is_printable (parm)) {
		if (is_in_input_map (input, parm) == 2) {
		    if (end == min_end)
			return 1;
		    h->ret_value = B_USER;	/* This means we want to refill the
						   list box and start again */
		    dlg_stop (h);
		    return 1;
		} else
		    return 0;
	    } else {
		WLEntry *e, *e1;
		int need_redraw = 0;
		int low = 4096;
		char *last_text = NULL;

		e1 = e = ((WListbox *) (h->current))->list;
		do {
		    if (!strncmp
			(input->buffer + start, e1->text, end - start)) {
			if (e1->text[end - start] == parm) {
			    if (need_redraw) {
				register int c1, c2, si;

				for (si = end - start + 1;
				     (c1 = last_text[si])
				     && (c2 = e1->text[si]); si++)
				    if (c1 != c2)
					break;
				if (low > si)
				    low = si;
				last_text = e1->text;
				need_redraw = 2;
			    } else {
				need_redraw = 1;
				listbox_select_entry ((WListbox *) (h->
								    current),
						      e1);
				last_text = e1->text;
			    }
			}
		    }
		    e1 = e1->next;
		} while (e != e1);
		if (need_redraw == 2) {
		    insert_text (input, last_text, low);
		    send_message (h->current, WIDGET_DRAW, 0);
		} else if (need_redraw == 1) {
		    h->ret_value = B_ENTER;
		    dlg_stop (h);
		}
	    }
	    return MSG_HANDLED;
	}
	break;

    default:
	return default_dlg_callback (h, msg, parm);
    }
}
예제 #6
0
파일: thongs.c 프로젝트: M-a-z/thongs
int main(int argc, char *argv[])
{	
    int c;
	int ch;
    int index;
    //pthread_t tid;
    sockstruct samant = {0};
    stringfilter *filters;
    char *dbglogname=NULL;
    char *udplogname=NULL;
    //FILE *udplogfile=NULL;
    char *cfgfile=NULL;
    FILE *cf=NULL;
    //FILE **arg2;
    char filterstring[1025]={0};
    unsigned filterindex=0;

    unsigned short ip4_parent_proto_list[IP4_PARENT_PROTO_AMNT]={0}; /* ethernet is only parent */
    unsigned short udp_parent_proto_list[UDP_PARENT_PROTO_AMNT]={0x800}; /* ipv4 is only parent */
    sdisplayhandler *displayhandler;
    user_commands uc;
    printptrhandler *bhandler;
    udp_handler *udphandler;
    tgt_commander *commander;
    shitemsgparser *msgfileparser=NULL;
    smsgloader *msgloader;
    char *ptr;
    //char *home=getenv("HOME");
    fileargs farg;
    memset(&farg,0,sizeof(farg));
    displayhandler=sdisplayhandler_init();
    if(!displayhandler)
    {
        EARLY_DBGPR("Failed to allocate displayhandler\n");
        return -1;
    }
    if(!(G_eth_parser=(protocolparser *)init_protocolparser_ethernet()))
    {
        EARLY_DBGPR("Failed to start ethernet protocol parser\n");
        return -1;
    }
    if(!(G_ip4_parser=(protocolparser *)init_protocolparser_ip4()))
    {
        EARLY_DBGPR("Failed to start IPv4 protocol parser\n");
        return -1;
    }
    
    if(!(G_arp_parser=(protocolparser *)init_protocolparser_arp()))
    {
        EARLY_DBGPR("Failed to start ARP protocol parser\n");
        return -1;
    }
    if(!(G_icmp_parser=(protocolparser *)init_protocolparser_icmp()))
    {
        EARLY_DBGPR("Failed to start ICMP protocol parser\n");
        return -1;
    }
    if(!(G_udp_parser=(protocolparser *)init_protocolparser_udp()))
    {
        EARLY_DBGPR("Failed to start UDP protocol parser\n");
        return -1;
    }
    if(!(G_udpcp_parser=(protocolparser *)init_protocolparser_udpcp()))
    {
        EARLY_DBGPR("Failed to start UDPCP protocol parser\n");
        return -1;
    }
    
    parser_add_0(G_eth_parser);

    parser_add_1(G_ip4_parser,ip4_parent_proto_list,IP4_PARENT_PROTO_AMNT);
    G_ip4_parser->activate(G_ip4_parser);
    parser_add_1(G_arp_parser,ip4_parent_proto_list,IP4_PARENT_PROTO_AMNT);
    G_arp_parser->activate(G_arp_parser);

    parser_add_2(G_udp_parser,udp_parent_proto_list,UDP_PARENT_PROTO_AMNT);
    G_udp_parser->activate(G_udp_parser);
    parser_add_2(G_icmp_parser,udp_parent_proto_list,UDP_PARENT_PROTO_AMNT);
    G_udp_parser->activate(G_icmp_parser);

    parser_add_udpcp2udp(G_udpcp_parser,G_udp_parser);
    G_udpcp_parser->activate(G_udpcp_parser);

    commander=init_tgt_commander();
    if(!commander)
    {
        EARLY_DBGPR("Failed to init tgt commander!\n");
    }
    
    memset(&uc,0,sizeof(uc));
    udphandler=init_udphandler();
    if(!udphandler)
    {
        EARLY_DBGPR("Failed to allocate udphandler\n");
        return -1;
    }


    G_exename=argv[0];
    while(-1 != (c = getopt_long(argc, argv, OPTSTRING,long_options,&index)))
    {
        switch(c)
        {
            case 'E':
                filter_before_file=1;
                break;
            case 'e':
            {
                uc.editor=optarg;
                break;
            }
            case 'c':
                if(optarg)
                    cfgfile=optarg;
                break;
            case 'd':
                if(optarg)
                    dbglogname=optarg;
                break;
            case 'i':
                if(optarg)
                {
                    udphandler->ifname=optarg;
                }
                break;
            case 'p':
                /* proto */
                if(optarg)
                {
                    identify_protocol(udphandler,optarg);
                }
                break;
            case 'v':
                EARLY_DBGPR("%s version %s\n",argv[0],VERSION);
                return 0;
                break;
            case '?':
            case 'h':
                EARLY_DBGPR("%s version %s\n",argv[0],VERSION);
                print_usage();
                return 0;
                break;
            case 'f':
            {
                if(optarg)
                {
                    farg.filebasename=udplogname=optarg;
                }
            }
            break;
            default:
                break;
        }
    }

    if(dbglogname)
        if(!(G_logfile=fopen(dbglogname,"w")))
        {
            EARLY_DBGPR("Failed to open logfile '%s' (%s)!\n",dbglogname,strerror(errno));
            return -1;
        }
    if(!cfgfile)
    {
            ptr=calloc(1,26);
            if(ptr)
                snprintf(ptr,25,"%s","/etc/thongs/default.conf");
            cfgfile=ptr;
    }
    if(cfgfile)
    {
        if(!(cf=fopen(cfgfile,"r")))
        {
            EARLY_DBGPR("Failed to open cfgfile '%s' (%s)!\n",cfgfile,strerror(errno));
        }
        else
            if(udphandler->read_portcfgfile(udphandler,cf))
                out(-1);
    }

    if(cf)
    {
        udplog_from_cfgfile(cf,&farg);
        ucs_from_cfgfile(cf,&uc);
        if(!uc.editor)
            uc.editor="gedit";
    }
    if(!farg.filebasename)
    {
        printf("thongs is file based version, -f <filename> or capturefile=<filename> at /etc/thongs/default.conf is REQUIRED!\n");
        return -1;
    }
    strncpy(G_CURRENT_UDP_FILE_NAME,farg.filebasename,1023);
    bhandler=init_printptrhandler(farg.filebasename,0,0);
    if(!bhandler)
    {
        EARLY_DBGPR("Failed to allocate stuff!\n");
        return -1;
    }

    udphandler->prepare_printbuffer(udphandler,bhandler);     

        G_USE_FILE=2;
    if(udphandler->start_sockets(udphandler))
    {
        return -1;
    }
    ptr=calloc(1, 26 /* /etc/thongs/msgtemplates+'\0' */ );
    if(ptr)
    {
        sprintf(ptr,"%s","/etc/thongs/msgtemplates");
        msgfileparser = init_shitemsgparser(ptr);
    }
    
    filters=filterinit(); 
    if(!filters)
    {
        DEBUGPR("Failed to init filters!\n");
        G_NOFILTERS=1;
    }

    signal(SIGSTOP,SIG_IGN);
    signal(SIGTERM,&out);
    signal(SIGINT,&out);
    
    
    DEBUGPR("Enabling ncurses mode...\n");
    displayhandler->ncursesmode_init(displayhandler);
    DEBUGPR("Initializing colours...\n");
    displayhandler->colors_init(displayhandler);
    DEBUGPR("Initializing windows...\n");
    if(displayhandler->windows_init(displayhandler))
    {
        DEBUGPR("Failed to create windows!\n");
        out(-1);
    }
    if(displayhandler->panels_init(displayhandler))
    {
        DEBUGPR("Failed to create panels to handle overlapping windows\n");
        out(-1);
    }
    msgloader=init_smsgloader(displayhandler->menuwin);
    if(!msgloader)
    {
        DEBUGPR("Failed to init msgloader!\n");
        out(-1);
    }
    if(msgfileparser)
        if(msgloader->msgloader_loaditems(msgloader,msgfileparser))
        {
            DEBUGPR("Something went wituiksi!\n");
            out(-1);
        }

    if(displayhandler->scomform_init(displayhandler))
    {
        DEBUGPR("Failed to create form for syscom msgs\n");
        out(-1);
    }

    if(pthread_create(&G_tid,NULL,&UDPreaderthread,  udphandler  ))
    {
        DEBUGPR("Failed to launch UDPlistener thread\n");
        out(0);
    }

    //DEBUGPR("Windows created - statuswin %p, filterwin %p, logwin %p,\n",statuswin,filter_win,logwin);
    filters->set_fstrwin(filters,displayhandler->fstrwin);
    filters->set_statsinfo(filters,displayhandler->statuswin,1);
    wprintw(displayhandler->statuswin,STATUSWIN_PRINT_FMT,samant.sockamnt,0,0,0,"LIVEDISPLAY");
    displayhandler->set_late_properties(displayhandler);
    if(cf && filters_from_cfgfile(filters,cf))
        out(-1);
    if(cf)
        fclose(cf);
//    msgloader->(msgloader,displayhandler->menuwin);
    msgloader->display_menu(msgloader);
    while(!uc.end)
    {
        if(!uc.scroll_mode)
            ch=getch();
        else
            ch=0;
        handle_char(ch,filters,displayhandler,filterstring,&filterindex,&uc,commander,msgloader,msgfileparser,bhandler);
        display_udpdata(filters,displayhandler,bhandler,&uc);
//        if(!uc.scroll_mode && uc.pause<2)
//        {
//            uc.pause*=2;
        if(!uc.scroll_mode)
        {
    		update_panels();
            doupdate();
        }
//        }
    }
    out(0);
	return 0;
}
예제 #7
0
파일: prf.c 프로젝트: TijmenW/FreeDOS
/*
ULONG FAR retcs(int i)
{
    char *p = (char*)&i;
    
    p -= 4;
    return *(ULONG *)p;
}
*/
COUNT do_printf(CONST BYTE * fmt, BYTE ** arg)
{
  int base;
  BYTE s[11], FAR * p;
  int c, flag, size, fill;
  int longarg;
  long currentArg;

/*  
  long cs = retcs(1);
  put_console("0123456789ABCDEF"[(cs >> 28) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >> 24) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >> 20) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >> 16) & 0x0f]);
  put_console(':');
  put_console("0123456789ABCDEF"[(cs >> 12) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >>  8) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >>  4) & 0x0f]);
  put_console("0123456789ABCDEF"[(cs >>  0) & 0x0f]);
*/
  while ((c = *fmt++) != '\0')
  {
    if (c != '%')
    {
      handle_char(c);
      continue;
    }

    longarg = FALSE;
    size = 0;
    flag = RIGHT;
    fill = ' ';

    if (*fmt == '-')
    {
      flag = LEFT;
      fmt++;
    }

    if (*fmt == '0')
    {
      fill = '0';
      fmt++;
    }

    while (*fmt >= '0' && *fmt <= '9')
    {
      size = size * 10 + (*fmt++ - '0');
    }

    if (*fmt == 'l')
    {
      longarg = TRUE;
      fmt++;
    }

    c = *fmt++;
    switch (c)
    {
      case '\0':
        return 0;

      case 'c':
        handle_char(*(COUNT *) arg++);
        continue;

      case 'p':
        {
          UWORD w[2];
          w[1] = *((UWORD *) arg);
          arg += sizeof(UWORD) / sizeof(BYTE *);
          w[0] = *((UWORD *) arg);
          arg += sizeof(UWORD) / sizeof(BYTE *);
          do_printf("%04x:%04x", (BYTE **) & w);
          continue;
        }

      case 's':
        p = *arg++;
        goto do_outputstring;

      case 'F':
        fmt++;
        /* we assume %Fs here */
      case 'S':
        p = *((BYTE FAR **) arg);
        arg += sizeof(BYTE FAR *) / sizeof(BYTE *);
        goto do_outputstring;

      case 'i':
      case 'd':
        base = -10;
        goto lprt;

      case 'o':
        base = 8;
        goto lprt;

      case 'u':
        base = 10;
        goto lprt;

      case 'X':
      case 'x':
        base = 16;

      lprt:
        if (longarg)
        {
          currentArg = *((LONG *) arg);
          arg += sizeof(LONG) / sizeof(BYTE *);
        }
        else
        {
          if (base < 0)
          {
            currentArg = *((int *)arg);
            arg += sizeof(int) / sizeof(BYTE *);
          }
          else
          {
            currentArg = *((unsigned int *)arg);
            arg += sizeof(unsigned int) / sizeof(BYTE *);
          }
        }

        ltob(currentArg, s, base);

        p = s;
      do_outputstring:

        size -= fstrlen(p);

        if (flag == RIGHT)
        {
          for (; size > 0; size--)
            handle_char(fill);
        }
        for (; *p != '\0'; p++)
          handle_char(*p);

        for (; size > 0; size--)
          handle_char(fill);

        continue;

      default:
        handle_char('?');

        handle_char(c);
        break;

    }
  }
  return 0;
}