Beispiel #1
0
int
getCharSize()
{
    int w = 0, h = 0;
    writestr("\x1b]99;w3m-getcharsize:%d:%d\x07", COLS, LINES);
    fscanf(stdin, "%d %d", &w, &h);
    if (!(w > 0 && h > 0))
	return FALSE;
    if (!set_pixel_per_char)
	pixel_per_char = (int)(1.0 * w / COLS + 0.5);
    if (!set_pixel_per_line)
	pixel_per_line = (int)(1.0 * h / LINES + 0.5);
    return TRUE;
}
Beispiel #2
0
static void teardown(int signo)
{
    signal(SIGCHLD, SIG_IGN);
    writestr(" ");
    readstr();
    if (sdofpid > 0) {
        kill(sdofpid, SIGINT);
        sleep(2);
        kill(sdofpid, SIGKILL);
    }
    unlink(pidlockfile);
    memset(memimg, 0xa5, 512);
    exit(0);
}
Beispiel #3
0
void TestFixture::assertEquals(const char *filename, unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg)
{
    if (expected != actual) {
        ++fails_counter;
        if (gcc_style_errors) {
            errmsg << filename << ':' << linenr << ": Assertion failed. "
                   << "Expected: "
                   << writestr(expected, true)
                   << ". Actual: "
                   << writestr(actual, true)
                   << '.'
                   << std::endl;
        } else {
            errmsg << "Assertion failed in " << filename << " at line " << linenr << std::endl
                   << "Expected:" << std::endl
                   << writestr(expected) << std::endl
                   << "Actual:" << std::endl
                   << writestr(actual) << std::endl << "_____" << std::endl;
        }
        if (!msg.empty()) {
            errmsg << msg << std::endl;
        }
    }
}
Beispiel #4
0
static int startup()
{
    int restart = 0, i;

    writestr(" ");
    for (;;) {
        while (sfd < 0) {
            printf("COMM RESTART\n");
            restart = 1;
            setupsdof();
            if (sfd < 0)
                sleep(5);       // time to connect
            writestr("\007");
        }

        i = readstr();
        if (i < 0)
            continue;
        if (i == 0)
            break;
    }
    printf("RECONNECTED\n");
    return restart;
}
Beispiel #5
0
static long ask_for_number(int n1,int n2)
{
  char s[50];
  int n;

  if (n1!=n2)
    sprintf(s,"Enter a number from %d to %d: ",n1,n2);
  else
    sprintf(s,"Enter a number: ");
  for(;;) {
    writestr(s);
    n=read_number();
    if (n1==n2 || ( n>=n1 && n<=n2)) return n;
    writeln("");
  }   
}
Beispiel #6
0
void SetDelParSelDisk()
{
#ifdef _DEBUG
	ShowMessage("SetDelParSelDisk");
#endif
	if(g_delparinfo.nselpar >= -1)
	{
		// 2004.08.03 huapage modify begin
		while(g_pDelParPartWin->m_pitemactive->btItem != (g_delparinfo.nselpar+1))
		// 2004.08.03 huapage modify end
		{
			winproc(g_pDelParPartWin, WM_KEY, DOWN);
		}
		g_pDelParPartWin->m_pitemactive->szitemtext[2] = 'X';
		writestr(PAGE_DELPAR, 5+g_pDelParPartWin->m_nactiverow , 25, "X");
	}
}
Beispiel #7
0
void paabout (SLOT *sl, char *msg)
{
  SLOT *sp;
  SLOT_LIST *slist;

  write_log_paabout (sl, msg);

  slist = channels[MAINLIST].members;
  while (slist) {
    sp = slist->slot;

    if (sp && (sp->acct.pa_notify || 
               (sl->acct.chan == sp->acct.chan))) {
      select_stop (sp);
      select_wrap (sp);
      begin_color (sp, sl->acct.msgcolor);
      if (slots_f) {
        writestr (sp, "-- #");
        writeint (sp, sl->nslot);
      } else {
        writestr (sp, "--");
      }
      writech (sp, ' ');
      writestr (sp, msg);
      writestr (sp, " channel ");
      if (sl->acct.chan == sp->acct.chan || 
          sl->flags.listed || sl->acct.chan == 1 ||
          sp->acct.level > 2)
        writetwodig (sp, sl->acct.chan);
      else
        writestr (sp, "**");
      writestr (sp, ": ");
      writestr (sp, sl->acct.id);
      writech (sp, '/');
      writestr (sp, sl->acct.handle);
      reset_attr (sp);
      writech (sp, '\n');
      clear_stop (sp);
      clear_wrap (sp);
    }
    slist = slist->next;
  }
}
Beispiel #8
0
void IOdebug(const char *str, ... )
{
	int base, i, *p;
	char *s;
	va_list a;

	va_start(a,str);

	while( *str ) 
	{
		if( *str == '%' )
		{
			base = 10;
			switch( *(++str) )
			{
			default:
				IOputc(*str); 
				break;

			case 0:				/* "...%" = no \n */
				goto nonl;
								
			case 'c':			/* char		*/
				i = va_arg(a,int);
				IOputc(i);
				break;

			case 'x': base = 16;		/* hex 		*/
			case 'd':			/* decimal	*/
				i = va_arg(a,int);
				writenum(i,base);
				break;
				
			case 's':			/* string	*/
				s = va_arg(a,char *);
				if( s == NULL ) s = "<NULL string>";
			putstr:
				writestr(s);
				break;

			}
			str++;
		}
		else IOputc(*str++);
Beispiel #9
0
void proc_id (char *id)
{
  SLOT *sp = NULL;
  char *offline_id = NULL;
  int err = 0;

  if (!id[0]) {
    setproc (sendpub, MAXMSG, 0);
    return;
  }
  if (slots_f && isdigit(id[0])) {
    sp = slotbynumber (id);
    if (!sp) {
      sprintf (msg_buf, "No such active slot: %s.\n", id);
      err = 1;
    }
  } else {
    sp = slotbyname (id);
    if (!sp) {
      if (cur_slot->flags.extid) {
        if (id[0] != '_' && db_pwd_exists (id) == DB_SUCCESS) {
          offline_id = id;
        } else {
          sprintf (msg_buf, "No such user: \"%s\".\n", id);
          err = 1;
        }
      } else {
        sprintf (msg_buf, "No such user online: \"%s\".\n", id);
        err = 1;
      }
    }
  }
  if (err) {
    writestr (cur_slot, msg_buf);
    setproc (sendpub, MAXMSG, 0);
  } else
    cur_slot->dispid (sp, offline_id);
}
Beispiel #10
0
char*
rexcall(int *fd, char *host, char *service)
{
	char *na;
	char dir[MaxStr];
	char err[ERRMAX];
	char msg[MaxStr];
	int n;

	na = netmkaddr(host, 0, service);
	procsetname("dialing %s", na);
	if((*fd = dial(na, 0, dir, 0)) < 0)
		return "can't dial";

	/* negotiate authentication mechanism */
	if(ealgs != nil)
		snprint(msg, sizeof(msg), "%s %s", am->name, ealgs);
	else
		snprint(msg, sizeof(msg), "%s", am->name);
	procsetname("writing %s", msg);
	writestr(*fd, msg, negstr, 0);
	procsetname("awaiting auth method");
	n = readstr(*fd, err, sizeof err);
	if(n < 0)
		return negstr;
	if(*err){
		werrstr(err);
		return negstr;
	}

	/* authenticate */
	procsetname("%s: auth via %s", origargs, am->name);
	*fd = (*am->cf)(*fd);
	if(*fd < 0)
		return "can't authenticate";
	return 0;
}
Beispiel #11
0
void operact (SLOT *from, SLOT *to, char * msg)
{
  SLOT *sp;
  SLOT_LIST *sl;
  
  sl = channels[MAINLIST].members;
  while(sl) {
    sp = sl->slot;
    if (sp && sp != from && sp->acct.level > 3) {
      select_stop (sp);
      select_wrap (sp);
      if (from)
        begin_color (sp, from->acct.msgcolor);
      writestr (sp, "** ");
      if (from) {
        writestr (sp, from->acct.id);
        writech (sp, '/');
        writestr (sp, from->acct.handle);
        writech (sp, ' ');
      }
      writestr (sp, msg);
      if (to != NULL) {
        writech (sp, ' ');
        writestr (sp, to->acct.id);
        writech (sp, '/');
        writestr (sp, to->acct.handle);
      }
      if (from)
        reset_attr (sp);
      writech (sp, '\n');
      clear_stop (sp);
      clear_wrap (sp);
    }
    sl = sl->next;
  }
}
Beispiel #12
0
int main( int argc, char **argv)
{

	setlocale( LC_ALL, "" );
	

	if( argc == 2 )
	{
		static char term_buffer[2048];
		char *termtype = getenv ("TERM");
		char *tbuff = malloc( sizeof(char)*9999);
		char *res;
		
		tgetent( term_buffer, termtype );
		res = tgetstr( argv[1], &tbuff );		
		if( res != 0 )
		{
			while( *res != 0 )
			{ 
				printf("%d ", *res );


				res++;
			}
			printf( "\n" );		
		}
		else
		{
			printf("Undefined sequence\n");
		}		
	}
	else
	{
		char scratch[1024];
		unsigned int c;

		struct termios modes,      /* so we can change the modes */
			savemodes;  /* so we can reset the modes when we're done */

		input_common_init(0);
		

		tcgetattr(0,&modes);        /* get the current terminal modes */
		savemodes = modes;          /* save a copy so we can reset them */
		
		modes.c_lflag &= ~ICANON;   /* turn off canonical mode */
		modes.c_lflag &= ~ECHO;   /* turn off echo mode */
		modes.c_cc[VMIN]=1;
		modes.c_cc[VTIME]=0;
		tcsetattr(0,TCSANOW,&modes);      /* set the new modes */
		while(1)
		{
			if( (c=input_common_readch(0)) == EOF )
				break;
			if( (c > 31) && (c != 127) )
				sprintf( scratch, "dec: %d hex: %x char: %c\n", c, c, c );
			else
				sprintf( scratch, "dec: %d hex: %x\n", c, c );
			writestr( scratch );			
		}
		/* reset the terminal to the saved mode */
		tcsetattr(0,TCSANOW,&savemodes);  

		input_common_destroy();
	}	

	return 0;
}
void aufgabe28() {
	char str[255];
	char *i,*j=str;
	int len;
	int knopp=0,ax=0,ay=0,az=0;
	
	int lastax=-1;
	int lastay=-1;
	int lastaz=-1;

    // Arbeitspalznummer +10
	setUid(17);
    // Selbe fequenz wie unsere Nachbarn mit denen wir komunizieren wollen
	switchFreq(8);
	while(1) {
		if(do_output==1) {
            // Daten des Packets holen und vorbereiten
			sprintPacket(str);
			len=strlen(str);
			writestr(str);
            
            // Code welcher die Funtionalitaet folgender Zeile hat
            // sscanf(j,"%d\t%d\t%d\r\n",NULL,NULL,ax,ay,az,knopp);
			j=str;
			while(*j!='\t') j++; j++;
			while(*j!='\t') j++;
			i=++j;
			while(*j!='\t') j++; *j='\0';
			ax=atoi(i);
			i=++j;
			while(*j!='\t') j++; *j='\0';
			ay=atoi(i);
			i=++j;
			while(*j!='\t') j++; *j='\0';
			az=atoi(i);
			i=++j;
			while(*j!='\r') j++; *j='\0';
			knopp=atoi(i);
			
            // Je nach dem welcher Knopf gedrueckt wurde LEDs einschalten
			if(knopp==2){
				LED_ON(GREEN);
			}
			if(knopp==1){
				LED_OFF(GREEN);
			}

            // Entscheiden ob einer der Beschleunigungswerte mehr als
            // 20 % vom alten abweicht - wenn ja rote LED einschalten
			if(lastax!=-1){
				
				if(	abs(lastay-ay) >= lastay*0.2 || 
					abs(lastax-ax) >= lastax*0.2 || 
					abs(lastaz-az) >= lastaz*0.2 ){
					LED_ON(RED);
				}else{
					LED_OFF(RED);
				}
					
			}
            // alte Werte fuer den naechten Druchlauf setzen
			lastax=ax;
			lastay=ay;
			lastaz=az;

            // gelbe LED als Statusanzeige toggeln
			LED_TOGGLE(YELLOW);
			do_output=0;
			
            // ACK an den sender schicken
			sprintf(str,"FACK:%d",len);
			sendPacket(18,17,str,strlen(str));
		}
	}
	
}
Beispiel #14
0
void prnobj(Obj a, Obj stream, int how){
	int typ = TYPEOFX(a);
	int (*printfnc)(Obj,Obj,int);
	char buf[8];
	char *foo;
	Obj radix;
	int base;
	
	switch( typ ){
	  case TPVF_IMMED:
		if( INUMP( a )){
			/* int */
			radix = getvalue( sym_oradix);
			if(DEFINEDP(radix)&& INUMP(radix))
				base = CINT(radix);
			else
				base = 10;
			if(how) base = 10;
			printnum(stream, CINT(a), base, 0,0);
		} else if( ICHARP( a )){
			/* char */
			foo = 0;
			if(how){
				writestr(stream, "#\\");
				foo = spec_repr( CCHAR(a), 0 );
			}
			if(foo)
				writestr(stream, foo);
			else
				writechar(stream, CCHAR(a));
		} else if( ICONSTP( a )){
			/* const sym */
			switch( a ){

			  case IC_NIL:
				writestr(stream, "()");
				break;

			  case IC_TRUE:
				writestr(stream, "#t");
				break;

			  case IC_FALSE:
				writestr(stream, "#f");
				break;

			  case IC_UNDEF:
				writestr(stream, "#<undefined>");
				break;

			  case IC_UNSPEC:
				writestr(stream, "#<unspecified>");
				break;

			  case IC_EOF:
				writestr(stream, "#<EOF>");
				break;

			  default:
				writestr(stream, "#<<send in bug report> IC_0x");
				printnum(stream, a, 16,0,0);
				writestr(stream, "?>");
				break;
			}
		} else if ( SYMBOLP( a )){
			writestr(stream, symbolname(a) );
		} else {
			writestr(stream, "#<<send in bug report> IMM_0x");
			printnum(stream, a, 16,0,0);
			writestr(stream, "?>");
		}
		break;
#if 0
	  case TPV_SYMBOL:
		writestr(stream, CCHARS(a));
		break;
#endif
	  case TPV_SYM_BOX:
		if(how)
			writestr(stream, symbolname( MAKSYM(CSYM_BOX(a)->id )));
		else{
			writestr(stream, "#<[");
			writestr(stream, symbolname( MAKSYM(CSYM_BOX(a)->id )));
			writestr(stream, "]>");
		}
		break;

	  default:
		printfnc = jlisp_vtbl[ typ ].print;

		if( !printfnc || ! printfnc(a, stream, how) ){
			writestr(stream, "#<_");
			printnum(stream, typ, 10,0,0);
			writestr(stream, "_0x");
			printnum(stream, a, 16, 0,0);
			writestr(stream, ">");
		}
		break;
	}
}
Beispiel #15
0
int prnmacr(Obj a, Obj stream, int how){

	if( how) return prn_func_macr(a, stream, "macro");
	else writestr(stream, "#<macro>");
	return 1;
}
Beispiel #16
0
void
cpumain(int argc, char **argv)
{
	char dat[MaxStr], buf[MaxStr], cmd[MaxStr], *err, *secstoreserver, *p, *s;
	int fd, ms, data;

	/* see if we should use a larger message size */
	fd = open("/dev/draw", OREAD);
	if(fd > 0){
		ms = iounit(fd);
		if(msgsize < ms+IOHDRSZ)
			msgsize = ms+IOHDRSZ;
		close(fd);
	}

	user = getenv("USER");
	secstoreserver = nil;
	authserver = getenv("auth");
	if(authserver == nil)
		authserver = "p9auth.cs.bell-labs.com";
	system = getenv("cpu");
	if(system == nil)
		system = "plan9.bell-labs.com";
	ARGBEGIN{
	case 'a':
		authserver = EARGF(usage());
		break;
	case 'c':
		system = EARGF(usage());
		break;
	case 'd':
		dbg++;
		break;
	case 'e':
		ealgs = EARGF(usage());
		if(*ealgs == 0 || strcmp(ealgs, "clear") == 0)
			ealgs = nil;
		break;
	case 'C':
		cflag++;
		cmd[0] = '!';
		cmd[1] = '\0';
		while((p = ARGF()) != nil) {
			strcat(cmd, " ");
			strcat(cmd, p);
		}
		break;
	case 'k':
		keyspec = EARGF(usage());
		break;
	case 'r':
		base = EARGF(usage());
		break;
	case 's':
		secstoreserver = EARGF(usage());
		break;
	case 'u':
		user = EARGF(usage());
		break;
	default:
		usage();
	}ARGEND;

	if(argc != 0)
		usage();

	if(user == nil)
		user = readcons("user", nil, 0);

	if(mountfactotum() < 0){
		if(secstoreserver == nil)
			secstoreserver = authserver;
	        if(havesecstore(secstoreserver, user)){
	                s = secstorefetch(secstoreserver, user, nil);
	                if(s){
	                        if(strlen(s) >= sizeof secstorebuf)
	                                sysfatal("secstore data too big");
	                        strcpy(secstorebuf, s);
	                }
	        }
	}

	if((err = rexcall(&data, system, srvname)))
		fatal(1, "%s: %s", err, system);

	/* Tell the remote side the command to execute and where our working directory is */
	if(cflag)
		writestr(data, cmd, "command", 0);
	if(getcwd(dat, sizeof(dat)) == 0)
		writestr(data, "NO", "dir", 0);
	else
		writestr(data, dat, "dir", 0);

	/* 
	 *  Wait for the other end to execute and start our file service
	 *  of /mnt/term
	 */
	if(readstr(data, buf, sizeof(buf)) < 0)
		fatal(1, "waiting for FS: %r");
	if(strncmp("FS", buf, 2) != 0) {
		print("remote cpu: %s", buf);
		exits(buf);
	}

	if(readstr(data, buf, sizeof buf) < 0)
		fatal(1, "waiting for remote export: %r");
	if(strcmp(buf, "/") != 0){
		print("remote cpu: %s" , buf);
		exits(buf);
	}
	write(data, "OK", 2);

	/* Begin serving the gnot namespace */
	exportfs(data, msgsize);
	fatal(1, "starting exportfs");
}
Beispiel #17
0
/* Invoked with stdin, stdout and stderr connected to the network connection */
void
remoteside(void)
{
	char user[MaxStr], home[MaxStr], buf[MaxStr], xdir[MaxStr], cmd[MaxStr];
	int i, n, fd, badchdir, gotcmd;

	rfork(RFENVG);
	putenv("service", "cpu");
	fd = 0;

	/* negotiate authentication mechanism */
	n = readstr(fd, cmd, sizeof(cmd));
	if(n < 0)
		fatal(1, "authenticating");
	if(setamalg(cmd) < 0){
		writestr(fd, "unsupported auth method", nil, 0);
		fatal(1, "bad auth method %s", cmd);
	} else
		writestr(fd, "", "", 1);

	fd = (*am->sf)(fd, user);
	if(fd < 0)
		fatal(1, "srvauth");

	/* Set environment values for the user */
	putenv("user", user);
	sprint(home, "/usr/%s", user);
	putenv("home", home);

	/* Now collect invoking cpu's current directory or possibly a command */
	gotcmd = 0;
	if(readstr(fd, xdir, sizeof(xdir)) < 0)
		fatal(1, "dir/cmd");
	if(xdir[0] == '!') {
		strcpy(cmd, &xdir[1]);
		gotcmd = 1;
		if(readstr(fd, xdir, sizeof(xdir)) < 0)
			fatal(1, "dir");
	}

	/* Establish the new process at the current working directory of the
	 * gnot */
	badchdir = 0;
	if(strcmp(xdir, "NO") == 0)
		chdir(home);
	else if(chdir(xdir) < 0) {
		badchdir = 1;
		chdir(home);
	}

	/* Start the gnot serving its namespace */
	writestr(fd, "FS", "FS", 0);
	writestr(fd, "/", "exportfs dir", 0);

	n = read(fd, buf, sizeof(buf));
	if(n != 2 || buf[0] != 'O' || buf[1] != 'K')
		exits("remote tree");

	/* make sure buffers are big by doing fversion explicitly; pick a huge number; other side will trim */
	strcpy(buf, VERSION9P);
	if(fversion(fd, 64*1024, buf, sizeof buf) < 0)
		exits("fversion failed");
	if(mount(fd, -1, "/mnt/term", MCREATE|MREPL, "") < 0)
		exits("mount failed");

	close(fd);

	/* the remote noteproc uses the mount so it must follow it */
	rmtnoteproc();

	for(i = 0; i < 3; i++)
		close(i);

	if(open("/mnt/term/dev/cons", OREAD) != 0)
		exits("open stdin");
	if(open("/mnt/term/dev/cons", OWRITE) != 1)
		exits("open stdout");
	dup(1, 2);

	if(badchdir)
		print("cpu: failed to chdir to '%s'\n", xdir);

	if(gotcmd)
		execl("/bin/rc", "rc", "-lc", cmd, nil);
	else
		execl("/bin/rc", "rc", "-li", nil);
	fatal(1, "exec shell");
}
Beispiel #18
0
Datei: wc.c Projekt: HNGNU/hutils
int
main(int argc, char **argv) {
	char **argp, *p, showtotal;
	int returnval, f;
	
	noflags=1;
	for(argp=argv+1;*argp&&**argp=='-';argp++)
		for(p=*argp+1;*p;p++)
			switch(*p) {
				case 'c':
					cflag=1;
					noflags=0;
					break;
				case 'l':
					lflag=1;
					noflags=0;
					break;
				case 'w':
					wflag=1;
					noflags=0;
					break;
				default:
					usage();
					return -1;
			}
	
	if(argp-argv==argc) {
		returnval=wc(0);
		putchar('\n');
		return returnval;
	}
	if(argc-(argp-argv)>1)
		showtotal=1;
	else
		showtotal=0;
	totalc=0;
	totall=0;
	totalw=0;
	for(returnval=0;*argp;argp++)
		if((f=open(*argp,O_RDONLY))==-1)
			if(errno==ENOENT) {
				writestr(2,"wc: ");
				writestr(2,*argp);
				writestr(2,": not found\n");
				returnval=1;
			} else {
				writestr(2,"wc: ");
				writestr(2,*argp);
				writestr(2,": can't open\n");
				returnval=1;
			}
		else {
			if(wc(f))
				returnval=1;
			writestr(1,*argp);
			writestr(1,"\n");
			close(f);
		}
	if(showtotal) {
		if(lflag||noflags)
			printf("%u ",totall);
		if(wflag||noflags)
			printf("%u ",totalw);
		if(cflag||noflags)
			printf("%u ",totalc);
		fflush(stdout); /* You can never trust that sneaky bastard */
		writestr(1,"total\n");
	}
	return returnval;
}
Beispiel #19
0
static void manualcheck(char skip)
  {
  static unsigned char encodedat[1510]="Put the copy protection here! ";
  unsigned char count=0;
  unsigned char lin,wor;
  unsigned int head,count2=0;
  unsigned char answer[14] = "",answeren[14]= "",temp[10] = "";
  register int i;
  char str[25];
  FILE *fp;
  
  count=(random(87)+91);
  if (skip)
    {
    gmmain();
    return;
    }
// Why chmodded?
/*  if (chmod("playgame.exe",S_IREAD|S_IWRITE))
    {
    if (errno == ENOENT) errorbox("Please run this application in the GM directory","                 (E)xit");
    else errorbox("Cannot Run PLAYGAME.EXE","     (E)xit");
    return;
    }
*/
  if ((fp = fopen ("playgame.exe","r+b")) == NULL)
    {
    errorbox("This application must be run from","the GM directory!     (E)xit");
    return;
    }
  fseek(fp,PLAYBYTE,SEEK_SET);
  count = fgetc(fp);
  count-=90;
  if ( (count<1) || (count>88) ) count=(random(87)+1);
  fseek(fp,PLAYBYTE,SEEK_SET);
  count2=(random(87)+91);
  if (fputc(count2,fp) == EOF)
    {
    errorbox("Cannot Find PLAYGAME.EXE","     (E)xit");
    fclose(fp);
    return;
    }
  fclose(fp);
  SetDate();
  count2=0;
  while ( (encodedat[count2] != count) && (count2<970) )
    {
    if (encodedat[count2] < 88)
      {                    /* eliminate possibility of head(int) bytes */
      count2+=5;
      }
    else count2++;  
    }
  if (count2>=970)
    {
    errorbox("Data Corrupted!","Reinstall from original disks.");
    return;
    }
  lin=encodedat[count2+1]-101;
  wor=encodedat[count2+2]-150;
  head=(*(unsigned int *) (&encodedat[count2+3]))/10;
  count2+=5; i=0;
  while(encodedat[count2+i]!=(count+1))
    {
    answer[i] = (encodedat[count2+i]-11-(count%57))/2;
    i++;
    }
  answer[i]=0;
  sprintf((char far *)temp,"%d",head);
  i=0;
  while (temp[i] != 0) i++;
  temp[2*i-1]=0;
  while (i != 0)
    {
    i--;
    temp[2*i]=temp[i];
    temp[2*i-1]='.';
    }
  count2 = openmenu(14,3,50,10,(char far *)encodedat);
  for (i=0;i<3;i++)
    {
    writestr(15,3,count2+15,"   Please enter the following informantion.");
    writestr(15,4,count2+14,"       OR send in your registration card");
    writestr(15,5,count2+14,"             to skip this hassle!");
    writestr(15,7,count2+15,"Count every line with text, not including");
    writestr(15,8,count2+15,"numbered headings. (\"Game-maker\" is one word).");
    sprintf(str,"Section: %s",temp);
    writestr(15,10,count2+14,str);
    sprintf(str,"Line: %d",lin);
    writestr(15,11,count2+14,str);
    sprintf(str,"Word: %d",wor);
    writestr(15,12,count2+14,str);
    qwindow(24,15,15,"Word Found: ",(char far *)answeren);
    if (stricmp((char far *)answeren,(char far *)answer) != 0)
      {
      if (i<2) 
        {
        errorbox("THAT IS INCORRECT","(R)etry");
        answeren[0]=0;
        }
      else
        {
        closemenu(14,3,50,10,(char far *)encodedat);
        errorbox("THAT IS INCORRECT","(E)xit");
        if ((fp = fopen ("playgame.exe","r+b")) == NULL)
          {
          errorbox("This application must be run from","the GM directory!     (E)xit");
          return;
          }
        fseek(fp,PLAYBYTE,SEEK_SET);
        count+=90;
        if (fputc(count,fp) == EOF)
          errorbox("Cannot Find PLAYGAME.EXE","     (E)xit");
        fclose(fp);
        SetDate();
        return;
        }
      }
    else i=3;
    }
  closemenu(14,3,50,10,(char far *)encodedat);
  gmmain();
  }
Beispiel #20
0
char showdelparwin()
{   
	int				nWidth;
	int				i;
	char			ch;
	char			szResult = 'c';
	char			szdrv[40],szStrCheck[65];
	char			*str[] = {"[V]iew Partition","Delete [M]ethod" ,"[D]elete ","[C]ancel"};
	static point	ptvpar, ptoption,ptdelpardel,ptdelparcancel;
	_itemnode 		*pitemHD;
	char			*szMethod[] = {"00 overwrite","FF overwrite",
						"random data","NSA method",
						"Old NSA method","DoD STD method",
						"NATO method","Gutmann method"};
	             

	_setvisualpage(PAGE_DELPAR);  
	_setactivepage(PAGE_DELPAR);  
    
	ptvpar.row = 23;
	ptvpar.col = 5;

    drawbox(1, 1, g_SysInfo.nmaxrows, g_SysInfo.nmaxcols);
    
	_settextposition(2, 4);          
	_outtext("Select the partition to be deleted");
	
	_settextposition(4, 5);          
	_outtext("PhysicalDisk:        Drive            Type   Size(MB)  Active    Pri/Log");
	
	_settextposition(12, 4);

	// 2004.08.03 huapage modify begin
	// _outtext("Selected partition");  
	_outtext("Partition information:");
	// 2004.08.03 huapage modify end
	//Add&Init Disk select window
	g_pDelParDiskWin = new cwindow(PAGE_DELPAR, 5, 4, 11, 20);

	for(i = 0; i < g_nDiskNum; i++)   // no A: B:
	{            
		sprintf(szdrv, DRIVEFORMAT, i + 1);
		g_pDelParDiskWin->additemNotSort(szdrv,i); 
	}
	g_pDelParDiskWin->enabledscroll();    
	if(!g_delparinfo.nseldisk)
		g_delparinfo.nseldisk = g_pDelParDiskWin->m_pitemactive->btItem+DISKBASE;    
	SetDelParDiskSel(g_delparinfo.nseldisk-DISKBASE);
    
    //Add&Init Partition select window
	g_pDelParPartWin = new cwindow(PAGE_DELPAR, 5, 22, 11, 78);
	writedriveletter(g_pDelParDiskWin, g_pDelParPartWin);
	
	//Add show selected partition information window
	g_pDelParSelWin = new cwindow(PAGE_DELPAR, 13, 4, 18, 78);
	
	//show delete method
	sprintf(szdrv,"Delete partition with %s",szMethod[g_nMethod]);
	_settextposition(19, 4);
	_outtext(szdrv);  
	
	// Add function box
	nWidth = strlen(str[0]);	                                 
	_settextposition(ptvpar.row, ptvpar.col);
	_outtext(str[0]);  
	drawbox(ptvpar.row - 1, ptvpar.col - 1, ptvpar.row + 1, ptvpar.col + nWidth);

	ptoption.row = ptvpar.row;
	ptoption.col = ptvpar.col + nWidth + 2;
	nWidth = strlen(str[1]);
	_settextposition(ptoption.row, ptoption.col);
	_outtext(str[1]);  
	drawbox(ptoption.row - 1, ptoption.col - 1, ptoption.row + 1, ptoption.col + nWidth);

	nWidth = strlen(str[3]);
	ptdelparcancel.row = ptvpar.row;
	ptdelparcancel.col = g_SysInfo.nmaxcols - 2 - nWidth;	           
	_settextposition(ptdelparcancel.row, ptdelparcancel.col);
	_outtext(str[3]);  
	drawbox(ptdelparcancel.row - 1, ptdelparcancel.col - 1, ptdelparcancel.row + 1, ptdelparcancel.col + nWidth);

	nWidth = strlen(str[2]);
	ptdelpardel.row = ptdelparcancel.row;
	ptdelpardel.col = ptdelparcancel.col - 2 -nWidth;	           
	_settextposition(ptdelpardel.row, ptdelpardel.col);
	_outtext(str[2]);  
	drawbox(ptdelpardel.row - 1, ptdelpardel.col - 1, ptdelpardel.row + 1, ptdelpardel.col + nWidth);
	
	SetDelParSelDisk();
	
	showtarparinfo();

	winproc(g_pDelParPartWin, WM_INACTIVE);
	switch(g_delparinfo.nselect)
	{
	case 0:
		winproc(g_pDelParDiskWin, WM_ACTIVE);
		break;
	case 1:
		winproc(g_pDelParPartWin, WM_ACTIVE);
		break;
	case 2:
		selectstr(str[0], ptvpar.row, ptvpar.col, SELCOLOR);
		break;
	case 3:
		selectstr(str[1], ptoption.row, ptoption.col, SELCOLOR);
		break;
	case 4:
		selectstr(str[2], ptdelpardel.row, ptdelpardel.col, SELCOLOR);
		break;
	case 5:
		selectstr(str[3], ptdelparcancel.row, ptdelparcancel.col, SELCOLOR);
		break;
	}
	while(1)
	{                                               
	  	ch = _getch();
		switch(ch)
		{
		case 'm':
		case 'M':
			_clearscreen(_GCLEARSCREEN); 
			DeleteDelParWin();
		    return 'm';
		case 'v':
		case 'V':
			// if(g_delparinfo.nselpar == -1)
			if( SEL_PAR_INIT_VALUE == g_delparinfo.nselpar )
			{
				ErrorMessageBox(NO_SELPAR);
				break;
			}
			_clearscreen(_GCLEARSCREEN); 
			DeleteDelParWin();
			return 'v';
		case 'd':
		case 'D':
			// 2004.08.03 huapage modify begin
			// if(g_delparinfo.nselpar == -1)
			if( SEL_PAR_INIT_VALUE == g_delparinfo.nselpar)
			// 2004.08.03 huapage modify end
			{
				ErrorMessageBox(NO_SELPAR);
				break;
			}
			_clearscreen(_GCLEARSCREEN); 
			DeleteDelParWin();
		    return 'd';
		case 'C':
		case 'c':
		case ESC :
			_clearscreen(_GCLEARSCREEN); 
			DeleteDelParWin();
			return 'c';
		case SPACE :

			if( 1 == g_delparinfo.nselect) // if the tab stop is in the proper window
			{
				pitemHD = g_pDelParPartWin->m_pitemhead;
				while(pitemHD!=NULL)
				{
				    if(pitemHD->szitemtext[SELPOINT] == SELFLAG)//no selected
					{
					    pitemHD->szitemtext[SELPOINT] = ' ';     	
					}
					pitemHD = pitemHD->pnext;
				}
				i=1;
				while(i<6)
				{  
					g_pDelParPartWin->gettext(szStrCheck,i);
					szStrCheck[0]=0x20;
					if(szStrCheck[2]=='X')		
					{
						writestr(PAGE_DELPAR, 5 + i, 23 + SELPOINT, " "); 
					}
					i++;
				}

				if( g_delparinfo.nselpar !=  ( g_pDelParPartWin->m_pitemactive->btItem -1) )
				{
					g_pDelParPartWin->m_pitemactive->szitemtext[SELPOINT] = SELFLAG; 
					writestr(PAGE_DELPAR, 5 + g_pDelParPartWin->m_nactiverow, 23 + SELPOINT, SELFLAG_STRING); 
				
					// 2004.08.02 huapage added begin
					// now we add select all, so nselpar should minus one
					g_delparinfo.nselpar = g_pDelParPartWin->m_pitemactive->btItem - 1;
					// 2004.08.02 huapage added end
				}
				else //already selected
				{
					// 2004.08.03 huapage comment begin
					// g_delparinfo.nselpar  =-1;  
					// 2004.08.03 huapage comment end
					
					g_delparinfo.nselpar = SEL_PAR_INIT_VALUE;

				}
				showtarparinfo();
			}
			else
			{
				// do nothing if the focus is not 
				// in the proper window and
				// user press space
			}

			break;
		case 0:
			switch(ch = _getch())
			{
			case SHIFT_TAB:
				switch(g_delparinfo.nselect)
				{
				case 0:
					g_delparinfo.nselect = 5;  
					selectstr(str[3], ptdelparcancel.row, ptdelparcancel.col, SELCOLOR);
					winproc(g_pDelParDiskWin, WM_INACTIVE);
					break;
				case 1:
					g_delparinfo.nselect = 0;
					winproc(g_pDelParDiskWin, WM_ACTIVE);
					winproc(g_pDelParPartWin, WM_INACTIVE);                                        
					break;
				case 2:
					g_delparinfo.nselect = 1;
					selectstr(str[0], ptvpar.row, ptvpar.col, TEXTCOLOR);
					winproc(g_pDelParPartWin, WM_ACTIVE);                                        
					//showtarparinfo();
					break;
				case 3:
					g_delparinfo.nselect = 2;
					selectstr(str[0], ptvpar.row, ptvpar.col, SELCOLOR); 
					selectstr(str[1], ptoption.row, ptoption.col, TEXTCOLOR);
					break;
				case 4:
					g_delparinfo.nselect = 3;
					selectstr(str[1], ptoption.row, ptoption.col, SELCOLOR);
					selectstr(str[2], ptdelpardel.row, ptdelpardel.col, TEXTCOLOR);
					break;
				case 5:
					g_delparinfo.nselect = 4;
					selectstr(str[2], ptdelpardel.row, ptdelpardel.col, SELCOLOR);
					selectstr(str[3], ptdelparcancel.row, ptdelparcancel.col, TEXTCOLOR);
					break;
				}
				break;
			case PAGEDOWN:
			case PAGEUP:
			case CTRL_END:
			case CTRL_HOME:  
			case UP:
			case DOWN:
				if(g_delparinfo.nselect == 0)
				{
					g_pDelParDiskWin->m_pitemactive->szitemtext[1] = ' ';
					writestr(PAGE_DELPAR, 5+g_pDelParDiskWin->m_nactiverow , 6, " ");
					winproc(g_pDelParDiskWin, WM_KEY, ch);
					g_pDelParDiskWin->m_pitemactive->szitemtext[1] = '*';
					writestr(PAGE_DELPAR, 5+g_pDelParDiskWin->m_nactiverow , 6, "*");
					g_delparinfo.nseldisk = g_pDelParDiskWin->m_pitemactive->btItem+DISKBASE;

					writedriveletter(g_pDelParDiskWin, g_pDelParPartWin);
					
					// 2004.08.03 huapage modify begin
					// g_delparinfo.nselpar = -1;
					g_delparinfo.nselpar = SEL_PAR_INIT_VALUE;
					// 2004.08.03 huapage modify end
					
					showtarparinfo();
				}
				if(g_delparinfo.nselect == 1)
				{
					winproc(g_pDelParPartWin, WM_KEY, ch);
					//showtarparinfo();
				}
				break;
			}
			break;
		case TAB:
			switch(g_delparinfo.nselect)
			{
			case 0:
				g_delparinfo.nselect = 1;  
				winproc(g_pDelParDiskWin, WM_INACTIVE);
				winproc(g_pDelParPartWin, WM_ACTIVE);                                        
				//showtarparinfo();
				break;
			case 1:
				g_delparinfo.nselect = 2;
				selectstr(str[0], ptvpar.row, ptvpar.col, SELCOLOR);
				winproc(g_pDelParPartWin, WM_INACTIVE);                                        
				break;
			case 2:
				g_delparinfo.nselect = 3;
				selectstr(str[0], ptvpar.row, ptvpar.col, TEXTCOLOR); 
				selectstr(str[1], ptoption.row, ptoption.col, SELCOLOR);
				break;
			case 3:
				g_delparinfo.nselect = 4;
				selectstr(str[1], ptoption.row, ptoption.col, TEXTCOLOR);
				selectstr(str[2], ptdelpardel.row, ptdelpardel.col, SELCOLOR);
				break;
			case 4:
				g_delparinfo.nselect = 5;
				selectstr(str[2], ptdelpardel.row, ptdelpardel.col, TEXTCOLOR);
				selectstr(str[3], ptdelparcancel.row, ptdelparcancel.col, SELCOLOR);
				break;
			case 5:
				g_delparinfo.nselect = 0;
				selectstr(str[3], ptdelparcancel.row, ptdelparcancel.col, TEXTCOLOR);
				winproc(g_pDelParDiskWin, WM_ACTIVE);
				break;
			}
			break;
		case CR:
			switch(g_delparinfo.nselect)
			{
			case 2:
				// if(g_delparinfo.nselpar == -1)
				if(SEL_PAR_INIT_VALUE == g_delparinfo.nselpar)
				{
					ErrorMessageBox(NO_SELPAR);
					break;
				}
				_clearscreen(_GCLEARSCREEN); 
				DeleteDelParWin();
				return 'v';
			case 3:
				_clearscreen(_GCLEARSCREEN); 
				DeleteDelParWin();
			    return 'm';
			case 4:
				// 2004.08.03 huapage modify begin
				// if(g_delparinfo.nselpar == -1)
				if(SEL_PAR_INIT_VALUE == g_delparinfo.nselpar)
				// 2004.08.03 huapage modify end
				{
					ErrorMessageBox(NO_SELPAR);
					break;
				}
				_clearscreen(_GCLEARSCREEN); 
				DeleteDelParWin();
				return 'd';
			case 5:
				_clearscreen(_GCLEARSCREEN); 
				DeleteDelParWin();
				return 'c';
			}
		default:break;
		}
	}
}
Beispiel #21
0
/*****************************************************************************
 *
 * NAME
 *
 * OVERVIEW
 *    process_char processes a single character of input.
 *
 ****************************************************************************/
static void process_char (unsigned char c)
{
  switch (cur_slot->tsmode)
    {
    case TS_NONE: 
      ts_none (c);
      break;

    case TS_IAC: 
      switch (c)
	{
	case IAC:
	  ts_none (c);
	  break;
	case WILL: 
	  cur_slot->tsmode = TS_WILL;
	  break;
	case WONT: 
	  cur_slot->tsmode = TS_WONT;
	  break;
	case DO: 
	  cur_slot->tsmode = TS_DO;
	  break;
	case DONT: 
	  cur_slot->tsmode = TS_DONT;
	  break;
	case EC: 
	  ts_none ('\b');
	  cur_slot->tsmode = TS_NONE;
	  break;
	case EL: 
	  ts_none (24);
	  cur_slot->tsmode = TS_NONE;
	  break;
	case AO: 
	  qflush (&cur_slot->outq);
	  qflush (&cur_slot->stopq);
	  break;
	case AYT: 
	  writestr (cur_slot, "\n[Yes]\n");
	default: 
	  cur_slot->tsmode = TS_NONE;
	  break;
	}
      break;

    case TS_WILL: 
      send_ts (DONT, (char)c);
      cur_slot->tsmode = TS_NONE;
      break;

    case TS_WONT: 
      cur_slot->tsmode = TS_NONE;
      break;

    case TS_DO: 
      if (c != TELOPT_SGA && c != TELOPT_ECHO)
	send_ts (WONT, (char)c);
      cur_slot->tsmode = TS_NONE;
      break;

    case TS_DONT: 
      cur_slot->tsmode = TS_NONE;
      break;
    }
}
//******************************************************
//    evalstatus - evaluates the status returned from
//     acceptscreen library function 
//*******************************************************    
void evalstatus(unsigned int status, const int bVerbose)
{
unsigned char type;
char dir;
int mode, cols, page, attr, len=0;
    static char *goodmsg=   "GOOD DATA  ";
    static char *lenmsg=    "LENGTH ERR ";
    static char *inputmsg=  "INPUT TYPE ERR";
    static char *barmsg=    "BAR KEY    ";
    static char *farmsg=    "FAR KEY    ";
    static char *darmsg=    "DAR KEY    ";
    static char *uarmsg=    "UAR KEY    ";
    static char *clrmsg=    "CLR KEY    ";
    static char *bskeymsg=  "BS KEY     ";
    static char *delmsg=    "DELETE KEY ";
    static char *ltormsg=   "L to R SCAN ";
    static char *rtolmsg=   "R to L SCAN ";
    static char *unknown=   "UNKNOWN RETVAL";

    attr = NORMAL_VID;
    getvidmode(&mode, &cols, &page);
    setcurpos(page, 4, 2);
    switch (status)
    {
  case GOOD_DATA :
       if (bVerbose) writestr (page, goodmsg, len, attr);
       break;
  case LENGTH_ERR :
       if (bVerbose) writestr (page, lenmsg, len, attr);
       break;
  case INPUT_TYPE_ERR :
       if (bVerbose) writestr (page, inputmsg, len, attr);
       break;
  case WND :
       dir = getlabeltype(&type);
       if ( dir == L_TO_R)
    if (bVerbose) writestr(page, ltormsg, len, attr);
       else
    if (bVerbose) writestr(page, rtolmsg, len, attr);
       switch (type)
       {
    case PLESSEY:
        if (bVerbose) writestr(page, "Plessey", len, attr);
        break;
    case ALPHA_PLESS:
        if (bVerbose) writestr(page, "Alpha Plessey", len, attr);
        break;
    case ISBN_PLESS:
        if (bVerbose) writestr(page, "Isbn Plessey", len, attr);
        break;
    case PURE_PLESS:
        if (bVerbose) writestr(page, "Pure Plessey", len, attr);
        break;
    case SAIN_PLESS:
        if (bVerbose) writestr(page, "Sainesbury Plessey", len, attr);
        break;
    case UPC:
        if (bVerbose) writestr(page, "UPC", len, attr);
        break;
    case EAN:
        if (bVerbose) writestr(page, "Ean", len, attr);
        break;
    case UPC_EAN:
        if (bVerbose) writestr(page, "Upc Ean", len, attr);
        break;
    case CODABAR:
        if (bVerbose) writestr(page, "Codabar", len, attr);
        break;
    case CODE_3_9:
        if (bVerbose) writestr(page, "Code 3 of 9", len, attr);
        break;
    case CODE_2_5:
        if (bVerbose) writestr(page, "Code 2 of 5", len, attr);
        break;
    case DISCR_2_5:
        if (bVerbose) writestr(page, "Discr 2 of 5", len, attr);
        break;
    case INTERL_2_5:
        if (bVerbose) writestr(page, "Interl 2 of 5", len, attr);
        break;
    case INDUST_2_5:
        if (bVerbose) writestr(page, "Indust 2 of 5", len, attr);
        break;
    case CODE_11:
        if (bVerbose) writestr(page, "Code 11", len, attr);
        break;
    case CODE_128:
        if (bVerbose) writestr(page, "Code 128", len, attr);
        break;
       }
       break;

      case BAR :
       if (bVerbose) writestr (page, barmsg, len, attr);
       break;
  case FAR :
       if (bVerbose) writestr (page, farmsg, len, attr);
       break;
  case DAR :
       if (bVerbose) writestr (page, darmsg, len, attr);
       break;
  case UAR :
       if (bVerbose) writestr (page, uarmsg, len, attr);
       break;
  case CLR :
       if (bVerbose) writestr (page, clrmsg, len, attr);
       break;
  case BSKEY :
           if (bVerbose) writestr (page, bskeymsg, len, attr);
       break;
  case DEL :
       if (bVerbose) writestr (page, delmsg, len, attr);
       break;
  default : if (bVerbose) write(page, unknown, len, attr);
       break;
    }
    sysdelay(SECOND);
}
Beispiel #23
0
void writemsg (SLOT *sp, char *msg, int typ)
{
  char *s;
  char *t;
  
  select_stop (sp);
  select_wrap (sp);
  begin_color (sp, cur_slot->acct.msgcolor);

  /* Emphasize personal messages */
  if (typ == 1)
    begin_attr (sp, 1);

  s = sp->acct.msgfmt;
  while (*s) {
    if (*s == '%') {
      switch (*++s) {
      case '\\': 
        writech (sp, '\\');
        break;

      case '_': 
        writech (sp, '_');
        break;

      case 'm': 
        while (*msg) {
          if (*msg == cur_slot->acct.nlchar && sp->acct.newlines)
            writestr (sp, "\n  ");
          else
            writech (sp, *msg);
          msg++;
        }
        break;
	    
      default: 
        if (shared_spec (sp, cur_slot, *s))
          break;
        writech (sp, '%');
        if (!*s)
          s--;
        else
          writech (sp, *s);
      }
    } else if (*s == '_') {
      t = (char *)index (++s, '_');
      if (typ == 2) {
        if (t != NULL)
          *t = '\0';
        writestr (sp, s);
        if (t != NULL)
          *t = '_';
      }
      if (t == NULL)
        break;
      else
        s = t;
    } else if (*s == '\\') {
      t = (char *)index (++s, '\\');
      if (typ == 1) {
        if (t != NULL)
          *t = '\0';
        writestr (sp, s);
        if (t != NULL)
          *t = '\\';
      }
      if (t == NULL)
        break;
      else
        s = t;
    } else
      writech (sp, *s);
    s++;
  }

  reset_attr (sp);
  writech (sp, '\n');
  clear_stop (sp);
  clear_wrap (sp);
}
Beispiel #24
0
int start_server(const char *url, const char *rtspport)
{
  int mediafd = -1, listenfd, tempfd, maxfd;
  int videofd;
  struct addrinfo *info;
  struct sockaddr_storage remoteaddr;
  socklen_t addrlen = sizeof remoteaddr;
  fd_set readfds, masterfds;
  int nready, i;
  int videosize, videoleft;
  int recvd, sent;
  char urlhost[URLSIZE], urlpath[URLSIZE], tempstr[URLSIZE];
  unsigned char msgbuf[BUFSIZE], sendbuf[BUFSIZE];
  char *temp;
  RTSPMsg rtspmsg;
  Client streamclient;


  /* The current state of the protocol */
  int mediastate = IDLE;
  int quit = 0;

  init_client(&streamclient);

  /* Open the a file where the video is to be stored */
  if ((videofd = open("videotemp.mp4", O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) {
    fatal_error("Error opening the temporary videofile");
  }

  /* Create the RTSP listening socket */
  resolve_host(NULL, rtspport, SOCK_STREAM, AI_PASSIVE, &info);
  listenfd = server_socket(info);
  maxfd = listenfd;


  FD_ZERO(&readfds);
  FD_ZERO(&masterfds);
  FD_SET(listenfd, &masterfds);


  while (!quit) {

    readfds = masterfds;

    if ((nready = Select(maxfd + 1, &readfds, NULL)) == -1) {
      write_log(logfd, "Select interrupted by a signal\n");
    } 

    for (i = 0; i <= maxfd; i++) {
      if (FD_ISSET(i, &readfds)) {

        nready--;

        /* New connection from a client */
        if (i == listenfd) {
          if ((tempfd = accept(i, (struct sockaddr *)&remoteaddr, &addrlen)) == -1) {
            if (errno != EWOULDBLOCK && errno != ECONNABORTED &&
                errno != EPROTO && errno != EINTR)
            {
              fatal_error("accept");
            }
          }

          /* If we are already serving a client, close the new connection. Otherwise, continue. */
          if (streamclient.state != NOCLIENT) close (tempfd);
          else {
            streamclient.rtspfd = tempfd;
            streamclient.state = CLICONNECTED;
            maxfd = max(2, streamclient.rtspfd, maxfd);
            FD_SET(streamclient.rtspfd, &masterfds);
          }
        }

        /* Data from the media source */
        else if (i == mediafd) {

          switch (mediastate) {

            case GETSENT:
              /* Read ONLY the HTTP message from the socket and store the video size */
              recvd = recv_all(i, msgbuf, BUFSIZE, MSG_PEEK);
              temp = strstr((char *)msgbuf, "\r\n\r\n");
              recvd = recv_all(i, msgbuf, (int)(temp + 4 - (char *)msgbuf), 0);
              temp = strstr((char *)msgbuf, "Content-Length:");
              sscanf(temp, "Content-Length: %d", &videosize);
              videoleft = videosize;
              mediastate = RECVTCP;
              break;

            case RECVTCP:
              if ((recvd = recv_all(i, msgbuf, BUFSIZE, 0)) == 0) {
                FD_CLR(i, &masterfds);
                close(i);
                printf("Socket closed\n");
              }
              writestr(videofd, msgbuf, recvd);
              videoleft -= recvd;
              if (videoleft <= 0) mediastate = STREAM;
              break;

              /* TODO: Start streaming, currently just exits the program */
            case STREAM:
              /*
                 close(videofd);
                 close(mediafd);
                 close(listenfd);
                 quit = 1;
                 */
              break;

            default: 
              break;
          }
        }

        /* Data from a client ( i == streamclient.rtspfd) */
        else {

          if ((recvd = recv_all(i, msgbuf, BUFSIZE, 0)) == 0) {
            FD_CLR(i, &masterfds);
            close(i);
            printf("Socket closed\n");
            streamclient.state = NOCLIENT;
          }
          else {
            printf("%s", msgbuf);
            parse_rtsp(&rtspmsg, msgbuf); 
          }

          switch (streamclient.state) {

            case CLICONNECTED:
              if (rtspmsg.type == OPTIONS) {
                sent = rtsp_options(&rtspmsg, sendbuf);
                send_all(i, sendbuf, sent);
              }
              else if (rtspmsg.type == DESCRIBE) {

                /* Start fetching the file from the server */
                parse_url(url, urlhost, urlpath);
                resolve_host(urlhost, "80", SOCK_STREAM, 0, &info);
                mediafd = client_socket(info, 0);
                FD_SET(mediafd, &masterfds);
                maxfd = max(2, maxfd, mediafd);

                /* Send the GET message */
                http_get(url, msgbuf);
                send_all(mediafd, msgbuf, strlen((char *)msgbuf));
                mediastate = GETSENT;

                /* TODO: parse SDP from the media file rather than hardcoding it */
                sent = rtsp_describe(&rtspmsg, sendbuf);
                send_all(i, sendbuf, sent);
                streamclient.state = SDPSENT;
              }
              break;

            case SDPSENT:
              if (rtspmsg.type == SETUP) {
                sent = rtsp_setup(&rtspmsg, sendbuf, 50508, 50509);
                send_all(i, sendbuf, sent);
                write_remote_ip(tempstr, streamclient.rtspfd);
                resolve_host(tempstr, rtspmsg.clirtpport, 0, SOCK_DGRAM, &info); 
                streamclient.videofds[0] = client_socket(info, 50508);
                resolve_host(tempstr, rtspmsg.clirtcpport, 0, SOCK_DGRAM, &info);
                streamclient.videofds[1] = client_socket(info, 50509);
                streamclient.state = SETUPSENT;
              }
              break;

            case SETUPSENT:
              if (rtspmsg.type == PLAY) {
              }
              
              break;

            default:
              break;
          }
        }
      }
      if (nready <= 0) break;   
    }

  }


  return 1;
}
Beispiel #25
0
Datei: wc.c Projekt: HNGNU/hutils
void
usage(void) {
	writestr(2,"usage: wc [-clw] [FILE ...]\n");
}
Beispiel #26
0
void dump_userinfo (SLOT *sp)
{
  ACCOUNT *acct;
  SLOT *sq;
  int i;

  acct = &sp->acct;

  dump_userinfoshort (acct, 1);

  writestr (cur_slot, "Account created from: ");
  writestr (cur_slot, acct->created_from);
  writestr (cur_slot, "\nMessage format: ");
  writestr (cur_slot, acct->msgfmt);
  writestr (cur_slot, "\nActive format: ");
  writestr (cur_slot, acct->activefmt);
  writestr (cur_slot, "\nNewline character: ");
  writech (cur_slot, acct->nlchar);
  writestr (cur_slot, "\nNewlines ");
  writestr (cur_slot, acct->newlines ? "on" : "off");
  writestr (cur_slot, "\nBeeping ");
  writestr (cur_slot, acct->beeping ? "on" : "off");
#ifndef NOBROADCAST
  writestr (cur_slot, "\nBroadcast messages ");
  writestr (cur_slot, acct->nostat ? "off" : "on");
#endif
  writestr (cur_slot, "\nPA messages ");
  writestr (cur_slot, acct->pa_notify ? "off" : "on");
  writestr (cur_slot, "\nANSI colors ");
  writestr (cur_slot, acct->usecolor ? "on" : "off");
  writestr (cur_slot, "\nEmail status: ");
  writestr (cur_slot, acct->email_verified ? "verified" : "new");

  writestr (cur_slot, "\nUser has squelched:");
  for (i = 1; i <= slots_used; i++) {
    sq = slotbase[i];
    if (sq && squelched (sp, sq)) {
      writestr (cur_slot, " ");
      writestr (cur_slot, sq->acct.id);
    }
  }
  writestr (cur_slot, "\nUser has reversed:");
  for (i = 1; i <= slots_used; i++) {
    sq = slotbase[i];
    if (sq && reversed (sp, sq)) {
      writestr (cur_slot, " ");
      writestr (cur_slot, sq->acct.id);
    }
  }
  writestr (cur_slot, "\nUser is being squelched by:");
  for (i = 1; i <= slots_used; i++) {
    sq = slotbase[i];
    if (sq && squelched (sq, sp)) {
      writestr (cur_slot, " ");
      writestr (cur_slot, sq->acct.id);
    }
  }
  writestr (cur_slot, "\nUser is being reversed by:");
  for (i = 1; i <= slots_used; i++) {
    sq = slotbase[i];
    if (sq && reversed (sq, sp)) {
      writestr (cur_slot, " ");
      writestr (cur_slot, sq->acct.id);
    }
  }
  writech (cur_slot, '\n');
}
Beispiel #27
0
static int completion_try_print( int cols,
				 wchar_t *prefix,
				 int is_quoted,
				 std::vector<comp_t *> &lst )
{
	/*
	  The calculated preferred width of each column
	*/
	int pref_width[PAGER_MAX_COLS];
	/*
	  The calculated minimum width of each column
	*/
	int min_width[PAGER_MAX_COLS];
	/*
	  If the list can be printed with this width, width will contain the width of each column
	*/
	int *width=pref_width;
	/*
	  Set to one if the list should be printed at this width
	*/
	int print=0;
	
	long i, j;
	
	int rows = (int)((lst.size()-1)/cols+1);
	
	int pref_tot_width=0;
	int min_tot_width = 0;
	int res=PAGER_RETRY;
	/*
	  Skip completions on tiny terminals
	*/
	
	if( termsize.ws_col < PAGER_MIN_WIDTH )
		return PAGER_DONE;
	
	memset( pref_width, 0, sizeof(pref_width) );
	memset( min_width, 0, sizeof(min_width) );
	
	/* Calculate how wide the list would be */
	for( j = 0; j < cols; j++ )
	{
		for( i = 0; i<rows; i++ )
		{
			int pref,min;
			comp_t *c;
			if( lst.size() <= j*rows + i )
				continue;

			c = lst.at(j*rows + i );
			pref = c->pref_width;
			min = c->min_width;
			
			if( j != cols-1 )
			{
				pref += 2;
				min += 2;
			}
			min_width[j] = maxi( min_width[j],
					     min );
			pref_width[j] = maxi( pref_width[j],
					      pref );
		}
		min_tot_width += min_width[j];
		pref_tot_width += pref_width[j];
	}
	/*
	  Force fit if one column
	*/
	if( cols == 1)
	{
		if( pref_tot_width > termsize.ws_col )
		{
			pref_width[0] = termsize.ws_col;
		}
		width = pref_width;
		print=1;
	}
	else if( pref_tot_width <= termsize.ws_col )
	{
		/* Terminal is wide enough. Print the list! */
		width = pref_width;
		print=1;
	}
	else
	{
		long next_rows = (lst.size()-1)/(cols-1)+1;
/*		fwprintf( stderr,
  L"cols %d, min_tot %d, term %d, rows=%d, nextrows %d, termrows %d, diff %d\n",
  cols,
  min_tot_width, termsize.ws_col,
  rows, next_rows, termsize.ws_row,
  pref_tot_width-termsize.ws_col );
*/
		if( min_tot_width < termsize.ws_col &&
		    ( ( (rows < termsize.ws_row) && (next_rows >= termsize.ws_row ) ) ||
		      ( pref_tot_width-termsize.ws_col< 4 && cols < 3 ) ) )
		{
			/*
			  Terminal almost wide enough, or squeezing makes the
			  whole list fit on-screen.

			  This part of the code is really important. People hate
			  having to scroll through the completion list. In cases
			  where there are a huge number of completions, it can't
			  be helped, but it is not uncommon for the completions to
			  _almost_ fit on one screen. In those cases, it is almost
			  always desirable to 'squeeze' the completions into a
			  single page. 

			  If we are using N columns and can get everything to
			  fit using squeezing, but everything would also fit
			  using N-1 columns, don't try.
			*/

			int tot_width = min_tot_width;
			width = min_width;

			while( tot_width < termsize.ws_col )
			{
				for( i=0; (i<cols) && ( tot_width < termsize.ws_col ); i++ )
				{
					if( width[i] < pref_width[i] )
					{
						width[i]++;
						tot_width++;
					}
				}
			}
			print=1;
		}
	}

	if( print )
	{
		res=PAGER_DONE;
		if( rows < termsize.ws_row )
		{
			/* List fits on screen. Print it and leave */
			if( is_ca_mode )
			{
				is_ca_mode = 0;
				writembs(exit_ca_mode);
			}
			
			completion_print( cols, width, 0, rows, prefix, is_quoted, lst);
			pager_flush();
		}
		else
		{
			int npos, pos = 0;
			int do_loop = 1;

			/*
			  Enter ca_mode, which means that the terminal
			  content will be restored to the current
			  state on exit.
			*/
			if( enter_ca_mode && exit_ca_mode )
			{
				is_ca_mode=1;
				writembs(enter_ca_mode);
			}
			

			completion_print( cols,
					  width,
					  0,
					  termsize.ws_row-1,
					  prefix,
					  is_quoted,
					  lst);
			/*
			  List does not fit on screen. Print one screenfull and
			  leave a scrollable interface
			*/
			while(do_loop)
			{
				set_color( rgb_color_t::black(), get_color(HIGHLIGHT_PAGER_PROGRESS) );
                wcstring msg = format_string(_(L" %d to %d of %d"), pos, pos+termsize.ws_row-1, rows );
				msg.append(L"   \r" );
								
				writestr(msg.c_str());
				set_color( rgb_color_t::normal(), rgb_color_t::normal() );
				pager_flush();
				int c = readch();

				switch( c )
				{
					case LINE_UP:
					{
						if( pos > 0 )
						{
							pos--;
							writembs(tparm( cursor_address, 0, 0));
							writembs(scroll_reverse);
							completion_print( cols,
									  width,
									  pos,
									  pos+1,
									  prefix,
									  is_quoted,
									  lst );
							writembs( tparm( cursor_address,
									 termsize.ws_row-1, 0) );
							writembs(clr_eol );

						}

						break;
					}

					case LINE_DOWN:
					{
						if( pos <= (rows - termsize.ws_row ) )
						{
							pos++;
							completion_print( cols,
									  width,
									  pos+termsize.ws_row-2,
									  pos+termsize.ws_row-1,
									  prefix,
									  is_quoted,
									  lst );
						}
						break;
					}

					case PAGE_DOWN:
					{

						npos = mini( (int)(rows - termsize.ws_row+1), (int)(pos + termsize.ws_row-1) );
						if( npos != pos )
						{
							pos = npos;
							completion_print( cols,
									  width,
									  pos,
									  pos+termsize.ws_row-1,
									  prefix,
									  is_quoted,
									  lst );
						}
						else
						{
							if( flash_screen )
								writembs( flash_screen );
						}

						break;
					}

					case PAGE_UP:
					{
						npos = maxi( 0,
							     pos - termsize.ws_row+1 );

						if( npos != pos )
						{
							pos = npos;
							completion_print( cols,
									  width,
									  pos,
									  pos+termsize.ws_row-1,
									  prefix,
									  is_quoted,
									  lst );
						}
						else
						{
							if( flash_screen )
								writembs( flash_screen );
						}
						break;
					}

					case R_NULL:
					{
						do_loop=0;
						res=PAGER_RESIZE;
						break;
						
					}
					
					default:
					{
						out_buff.push_back( c );
						do_loop = 0;
						break;
					}					
				}
			}
			writembs(clr_eol);
		}
	}
	return res;
}
Beispiel #28
0
void
main(int argc, char **argv)
{
	char dat[MaxStr], buf[MaxStr], cmd[MaxStr], *p, *err;
	int ac, fd, ms, data;
	char *av[10];

	quotefmtinstall();
	origargs = procgetname();
	/* see if we should use a larger message size */
	fd = open("/dev/draw", OREAD);
	if(fd > 0){
		ms = iounit(fd);
		if(msgsize < ms+IOHDRSZ)
			msgsize = ms+IOHDRSZ;
		close(fd);
	}

	user = getuser();
	if(user == nil)
		fatal(1, "can't read user name");
	ARGBEGIN{
	case 'a':
		p = EARGF(usage());
		if(setam(p) < 0)
			fatal(0, "unknown auth method %s", p);
		break;
	case 'e':
		ealgs = EARGF(usage());
		if(*ealgs == 0 || strcmp(ealgs, "clear") == 0)
			ealgs = nil;
		break;
	case 'd':
		dbg++;
		break;
	case 'f':
		/* ignored but accepted for compatibility */
		break;
	case 'R':				/* From listen */
		remoteside();
		break;
	case 'h':
		system = EARGF(usage());
		break;
	case 'c':
		cflag++;
		cmd[0] = '!';
		cmd[1] = '\0';
		while(p = ARGF()) {
			strcat(cmd, " ");
			strcat(cmd, p);
		}
		break;
	case 'k':
		keyspec = smprint("%s %s", keyspec, EARGF(usage()));
		break;
	case 'P':
		patternfile = EARGF(usage());
		break;
	case 'u':
		user = EARGF(usage());
		keyspec = smprint("%s user=%s", keyspec, user);
		break;
	default:
		usage();
	}ARGEND;


	if(argc != 0)
		usage();

	if(system == nil) {
		p = getenv("cpu");
		if(p == 0)
			fatal(0, "set $cpu");
		system = p;
	}

	if(err = rexcall(&data, system, srvname))
		fatal(1, "%s: %s", err, system);

	procsetname("%s", origargs);
	/* Tell the remote side the command to execute and where our working directory is */
	if(cflag)
		writestr(data, cmd, "command", 0);
	if(getwd(dat, sizeof(dat)) == 0)
		writestr(data, "NO", "dir", 0);
	else
		writestr(data, dat, "dir", 0);

	/* start up a process to pass along notes */
	lclnoteproc(data);

	/* 
	 *  Wait for the other end to execute and start our file service
	 *  of /mnt/term
	 */
	if(readstr(data, buf, sizeof(buf)) < 0)
		fatal(1, "waiting for FS: %r");
	if(strncmp("FS", buf, 2) != 0) {
		print("remote cpu: %s", buf);
		exits(buf);
	}

	/* Begin serving the gnot namespace */
	close(0);
	dup(data, 0);
	close(data);

	sprint(buf, "%d", msgsize);
	ac = 0;
	av[ac++] = exportfs;
	av[ac++] = "-m";
	av[ac++] = buf;
	if(dbg)
		av[ac++] = "-d";
	if(patternfile != nil){
		av[ac++] = "-P";
		av[ac++] = patternfile;
	}
	av[ac] = nil;
	exec(exportfs, av);
	fatal(1, "starting exportfs");
}
Beispiel #29
0
/// Convert a wide string to a multibyte string and append it to the buffer.
static void s_write_str(data_buffer_t *b, const wchar_t *s) {
    scoped_buffer_t scoped_buffer(b);  //!OCLINT(has side effects)
    writestr(s);
}
Beispiel #30
0
/**
   Convert a wide string to a multibyte string and append it to the
   buffer.
*/
static void s_write_str( data_buffer_t *b, const wchar_t *s )
{
    scoped_buffer_t scoped_buffer(b);
	writestr( s );
}