Exemplo n.º 1
0
Arquivo: error.c Projeto: kstephens/Rt
static
void	_print_line( int fd, const char* file, int line ) {
	int	filefd;

	writestring(fd, "in file ");
	writestring(fd, file);
	writestring(fd, " at line ");
	writeint(fd, line);
	writechar(fd, ':');

#ifndef O_TEXT
#define O_TEXT 0
#endif
	if ( (filefd = open(file, O_RDONLY | O_TEXT )) != -1 ) {
		char	c;

		for ( ; line > 1; line -- ) {
			while ( readchar(filefd) != '\n' )
				;
		}

		do {
			writechar(fd, c = readchar(filefd));
		} while ( c != '\n' );
	} else {
		writestring(2, "Couldn't open ");
		writestring(2, file);
		writechar(2, '\n');
	}
}
Exemplo n.º 2
0
static void itDisplayIns52(uint16_t *buf, int n, int plInstMode)
{
	char col=plInstMode?0x07:"\x08\x08\x0B\x0A"[plInstUsed[n]];
	writestring(buf, 0, col, (!plInstMode&&plInstUsed[n])?"    \xfe##: ":"     ##: ", 9);
	writenum(buf, 5, col, n+1, 16, 2, 0);
	writestring(buf, 9, col, plInstr[n].name, 43);
}
Exemplo n.º 3
0
static void gmdDisplayIns33(unsigned short *buf, int n, int plInstMode)
{
	char col=plInstMode?0x07:"\x08\x08\x0B\x0A"[(unsigned)plInstUsed[n]];
	writestring(buf, 0, col, (!plInstMode&&plInstUsed[n])?"\xfe##: ":" ##: ", 5);
	writenum(buf, 1, col, n+1, 16, 2, 0);
	writestring(buf, 5, col, plInstr[n].name, 28);
}
Exemplo n.º 4
0
/*-------------------------------------------------------------------
 TCP Server Task
 -------------------------------------------------------------------*/
void TcpServerTask(void * pd)
{
    int ListenPort = (int) pd;

    // Set up the listening TCP socket
    int fdListen = listen(INADDR_ANY, ListenPort, 5);

    if (fdListen > 0)
    {
        IPADDR	client_addr;
        WORD	port;

        while(1)
        {
            // The accept() function will block until a TCP client requests
            // a connection. Once a client connection is accepting, the
            // file descriptor fdnet is used to read/write to it.
            iprintf( "Wainting for connection on port %d...\n", ListenPort );
            int fdnet = accept(fdListen, &client_addr, &port, 0);

            iprintf("Connected to: ");
            ShowIP(client_addr);
            iprintf(":%d\n", port);

            writestring(fdnet, "Welcome to the NetBurner TCP Server\r\n");
            char s[20];
            IPtoString(EthernetIP, s);
            siprintf(RXBuffer, "You are connected to IP Address %s, port %d\r\n",
                     s, TCP_LISTEN_PORT);
            writestring(fdnet, RXBuffer);

            while (fdnet > 0)
            {
                /* Loop while connection is valid. The read() function will return
                   0 or a negative number if the client closes the connection, so we
                   test the return value in the loop. Note: you can also use
                   ReadWithTimout() in place of read to enable the connection to
                   terminate after a period of inactivity.
                */
                int n = 0;
                do
                {
                    n = read( fdnet, RXBuffer, RX_BUFSIZE );
                    RXBuffer[n] = '\0';
                    iprintf( "Read %d bytes: %s\n", n, RXBuffer );
                }
                while ( n > 0 );

                // Don't foreget to close !
                iprintf("Closing client connection: ");
                ShowIP(client_addr);
                iprintf(":%d\n", port);
                close(fdnet);
                fdnet = 0;
            }
        } // while(1)
    } // while listen
}
int block_writestart(FILETYPE f, char index[MAXBLOCKTITLE])
{
  if (strlen(index) >= MAXBLOCKTITLE)
    return RETURN_CODE_ERROR;
  if (!writestring(f, "{") ||
      !writestring(f, index) ||
      !writestring(f, " "))
    return RETURN_CODE_ERROR;
  return 0;
}
Exemplo n.º 6
0
/* write a page with nothing on it */
void writeemptypage(void)
{
   if (verbose)
      message(LOG, "[*] ");
   sprintf(buffer, "%%%%Page: * %d\n", ++outputpage);
   writestring(buffer);
   if (beginprocset)
      writestring("PStoPSxform concat\n");
   writestring("showpage\n");
}
Exemplo n.º 7
0
int msgsetup (void)
{
	int x;

	if (server) {
		x = readmsg (MSGSETUP);
		if (x != SCMOK)  return (x);
		if (protver >= 7) {
			x = readint (&xpatch);
			if (x != SCMOK)  return (x);
		} else
			xpatch = FALSE;
		if (xpatch) {
			x = readstring (&xuser);
			if (x != SCMOK)  return (x);
			return (readmend ());
		}
		x = readstring (&collname_g);
		if (x == SCMOK)  x = readint ((int *)&lasttime);
		if (x == SCMOK)  x = readstring (&basedir_g);
		if (x == SCMOK)  x = readint (&basedev);
		if (x == SCMOK)  x = readint (&baseino);
		if (x == SCMOK)  x = readint (&listonly);
		if (x == SCMOK)  x = readint (&newonly);
		if (x == SCMOK)
			if (protver < 6)
				release = (char *)NULL;
			else
				x = readstring (&release);
		if (x == SCMOK)  x = readmend ();
	} else {
		x = writemsg (MSGSETUP);
		if (x != SCMOK)  return (x);
		if (protver >= 7) {
			x = writeint (xpatch);
			if (x != SCMOK)  return (x);
		}
		if (xpatch) {
			x = writestring (xuser);
			if (x != SCMOK)  return (x);
			return (writemend ());
		}
		if (x == SCMOK)  x = writestring (collname_g);
		if (x == SCMOK)  x = writeint ((int)lasttime);
		if (x == SCMOK)  x = writestring (basedir_g);
		if (x == SCMOK)  x = writeint (basedev);
		if (x == SCMOK)  x = writeint (baseino);
		if (x == SCMOK)  x = writeint (listonly);
		if (x == SCMOK)  x = writeint (newonly);
		if (x == SCMOK && protver >= 6)  x = writestring (release);
		if (x == SCMOK)  x = writemend ();
	}
	return (x);
}
Exemplo n.º 8
0
int main(int argc, char* argv[])
{
	if(argc<3)
	{
		std::cout << "Usage: SQLGen [SQLite database filename] [cpp-file] ([Attached db name] [Attached db filename] ...)" << std::endl;
		return 1;
	}

	Server=new CServer;
	reinterpret_cast<CServer*>(Server)->setup();

	std::string sqlite_db_str=argv[1];
	std::string cppfile=argv[2];
	std::string headerfile=getuntil(".cpp", cppfile)+".h";

	if(!Server->openDatabase(sqlite_db_str, maindb))
	{
		std::cout << "Could not open sqlite db \"" << sqlite_db_str << "\"" << std::endl;
	}

	for(int i=3;i+1<argc;i+=2)
	{
		if(!Server->attachToDatabase(argv[i+1], argv[i], maindb))
		{
			std::cout << "Could not attach database \"" << argv[i+1] << "\"" << std::endl;
		}
	}

	std::string cppfile_data=getFile(cppfile);
	std::string headerfile_data=getFile(headerfile);

	writestring(cppfile_data, cppfile+".sqlgenbackup");
	writestring(headerfile_data, headerfile+".sqlgenbackup");

	try
	{
		sqlgen(Server->getDatabase(Server->getThreadID(), maindb), cppfile_data, headerfile_data);
	}
	catch (std::exception& e)
	{
		std::cout << "Error: " << e.what() << std::endl;
		return 1;
	}

	writestring(cppfile_data, cppfile);
	writestring(headerfile_data, headerfile);

	std::cout << "SQLGen: Ok." << std::endl;

	return 0;
}
Exemplo n.º 9
0
void make_title(char *part)
{
	uint16_t sbuf[CONSOLE_MAX_X];
	char *verstr="opencp v" VERSION;

	fillstr(sbuf, 0, 0x30, 0, CONSOLE_MAX_X);
	writestring(sbuf, 2, 0x30, verstr, strlen(verstr));
	if (plScrWidth<100)
		writestring(sbuf, plScrWidth-58, 0x30, part, strlen(part));
	else
		writestring(sbuf, (plScrWidth-strlen(part))/2, 0x30, part, strlen(part));
	writestring(sbuf, plScrWidth-28, 0x30, "(c) '94-'10 Stian Skjelstad", 27);
	displaystrattr(0, 0, sbuf, plScrWidth);
}
Exemplo n.º 10
0
void drawaxes(){

	glColor3f(0.0, 1.0, 0.0);
	glBegin(GL_LINES);
	glVertex2f(-50.0, 0.0);
	glVertex2f(50.0, 0.0);
	glVertex2f(0.0, -50.0);
	glVertex2f(0.0, 50.0);
	glEnd();
	glRasterPos3f(48, -2.0, 0.0);
	writestring((void *)font, "x");
	glRasterPos3f(1.0, 48.0, 0.0);
	writestring((void *)font, "y");
}
Exemplo n.º 11
0
/* write page comment */
void writepageheader(const char *label, int page)
{
   if (verbose)
      message(LOG, "[%d] ", page);
   sprintf(buffer, "%%%%Page: %s %d\n", label, ++outputpage);
   writestring(buffer);
}
Exemplo n.º 12
0
int msgxpatch (void)
{
	int x;
	int i;

	if (server) {
		x = readmsg (MSGXPATCH);
		if (x != SCMOK)  return (x);
		x = readint (&xargc);
		if (x != SCMOK)  return (x);
		xargc += 2;
		xargv = (char **)calloc (sizeof (char *),(unsigned)xargc+1);
		if (xargv == NULL)
			return (SCMERR);
		for (i = 2; i < xargc; i++) {
			x = readstring (&xargv[i]);
			if (x != SCMOK)  return (x);
		}
		x = readmend ();
	} else {
		x = writemsg (MSGXPATCH);
		if (x != SCMOK)  return (x);
		x = writeint (xargc);
		if (x != SCMOK)  return (x);
		for (i = 0; i < xargc; i++) {
			x = writestring (xargv[i]);
			if (x != SCMOK)  return (x);
		}
		x = writemend ();
	}
	return (x);
}
Exemplo n.º 13
0
int block_writeend(FILETYPE f)
{
  if (!writestring(f, "} "))
    return RETURN_CODE_ERROR;

  return 0;
}
Exemplo n.º 14
0
static int needone ( TREE *t, va_list ap )
{
	int x;
	x = writestring (t->Tname);
	if (x == SCMOK)  x = writeint ((t->Tflags&FUPDATE) != 0);
	return (x);
}
Exemplo n.º 15
0
int msgneed (void)
{
	int x;
	if (server) {
		char *name;
		int update;
		TREE *t;
		x = readmsg (MSGNEED);
		if (x == SCMOK)  x = readstring (&name);
		while (x == SCMOK) {
			if (name == NULL)  break;
			x = readint (&update);
			if (x != SCMOK)  break;
			t = Tinsert (&needT,name,TRUE);
			free (name);
			if (update)  t->Tflags |= FUPDATE;
			x = readstring (&name);
		}
		if (x == SCMOK)  x = readmend ();
	} else {
		x = writemsg (MSGNEED);
		if (x == SCMOK)  x = Tprocess (needT,needone);
		if (x == SCMOK)  x = writestring ((char *)NULL);
		if (x == SCMOK)  x = writemend ();
	}
	return (x);
}
Exemplo n.º 16
0
int block_write_data(FILETYPE f, int type, int dim, void *data)
{
  int error, i;
  char buffer[INT_SPACE + DOUBLE_SPACE];
  
  switch (type) {
  case TYPE_DOUBLE:
    if ((error = block_writestart(f, "_dval_")) != 0)
      return error;
    break;
  case TYPE_INT:
    if ((error = block_writestart(f, "_ival_")) != 0)
      return error;
    break;
  default: return RETURN_CODE_ERROR;
  }


  for (i = 0; i < dim; i++) {
    switch (type) {
    case TYPE_DOUBLE:
      sprintf(buffer, DOUBLE_FORMAT " ", ((double *)data)[i]);
      break;
    case TYPE_INT:
      sprintf(buffer, "%d ", ((int *)data)[i]);
      break;
    default: /* keep the compilers happy */;
    }
    if (!writestring(f, buffer))
      return RETURN_CODE_ERROR;
  }
  return block_writeend(f);
}
Exemplo n.º 17
0
int msglist (void)
{
	int x;
	if (server) {
		x = writemsg (MSGLIST);
		if (x == SCMOK)  x = Tprocess (listT,listone);
		if (x == SCMOK)  x = writestring ((char *)NULL);
		if (x == SCMOK)  x = writeint ((int)scantime);
		if (x == SCMOK)  x = writemend ();
	} else {
		char *name;
		int mode,flags,mtime;
		TREE *t;
		x = readmsg (MSGLIST);
		if (x == SCMOK)  x = readstring (&name);
		while (x == SCMOK) {
			if (name == NULL)  break;
			x = readint (&mode);
			if (x == SCMOK)  x = readint (&flags);
			if (x == SCMOK)  x = readint (&mtime);
			if (x != SCMOK)  break;
			t = Tinsert (&listT,name,TRUE);
			free (name);
			t->Tmode = mode;
			t->Tflags = flags;
			t->Tmtime = mtime;
			x = readstring (&name);
		}
		if (x == SCMOK)  x = readint ((int *)&scantime);
		if (x == SCMOK)  x = readmend ();
	}
	return (x);
}
Exemplo n.º 18
0
int
putc(int c, void *f)
{
    char ch = c;

    return writestring(f, &ch, 1) == 1? c: -1;
}
Exemplo n.º 19
0
int
fputs(char *str, void *f)
{
    int n = strlen(str);

    return writestring(f, str, n) == n? 0: -1;
}
Exemplo n.º 20
0
int msglogin (void)
{
	int x;
	if (server) {
		x = readmsg (MSGLOGIN);
		if (x == SCMOK)  x = readstring (&logcrypt);
		if (x == SCMOK)  x = readstring (&loguser);
		if (x == SCMOK)  x = readstring (&logpswd);
		if (x == SCMOK)  x = readmend ();
	} else {
		x = writemsg (MSGLOGIN);
		if (x == SCMOK)  x = writestring (logcrypt);
		if (x == SCMOK)  x = writestring (loguser);
		if (x == SCMOK)  x = writestring (logpswd);
		if (x == SCMOK)  x = writemend ();
	}
	return (x);
}
Exemplo n.º 21
0
int main(int argc, char* argv[])
{
  char* x = "Hello world\n";
  writestring(x);
  writeint(12345);
  writechar('\n');
  loop(1000);
  return 0;
}
Exemplo n.º 22
0
void writeheadermedia(int p, off_t *ignore, double width, double height)
{
    fseeko(infile, (off_t) 0, SEEK_SET);
   if (pagescmt) {
      if (!fcopy(pagescmt, ignore) || fgets(buffer, BUFSIZ, infile) == NULL)
	 message(FATAL, "I/O error in header\n");
      if (width > -1 && height > -1) {
         sprintf(buffer, "%%%%DocumentMedia: plain %d %d 0 () ()\n", (int) width, (int) height);
         writestring(buffer);
         sprintf(buffer, "%%%%BoundingBox: 0 0 %d %d\n", (int) width, (int) height);
         writestring(buffer);
      }
      sprintf(buffer, "%%%%Pages: %d 0\n", p);
      writestring(buffer);
   }
   if (!fcopy(headerpos, ignore))
      message(FATAL, "I/O error in header\n");
}
Exemplo n.º 23
0
/* write trailer */
void writetrailer(void)
{
   fseeko(infile, pageptr[pages], SEEK_SET);
   while (fgets(buffer, BUFSIZ, infile) != NULL) {
      writestring(buffer);
   }
   if (verbose)
      message(LOG, "Wrote %d pages, %ld bytes\n", outputpage, bytes);
}
Exemplo n.º 24
0
static int listone ( TREE *t, va_list ap )
{
	int x;

	x = writestring (t->Tname);
	if (x == SCMOK)  x = writeint ((int)t->Tmode);
	if (x == SCMOK)  x = writeint ((int)t->Tflags);
	if (x == SCMOK)  x = writeint (t->Tmtime);
	return (x);
}
Exemplo n.º 25
0
void
printk(char *fmt, ...)
{
	va_list args;
	int n;

	va_start(args, fmt);
	n = vsprintf(sprint_buf, fmt, args);
	va_end(args);
	writestring(stdout, sprint_buf, n);
}
Exemplo n.º 26
0
/* write from start of file to end of header comments */
void writeheader(int p)
{
   fseek(infile, 0L, SEEK_SET);
   if (pagescmt) {
      if (!fcopy(pagescmt) || fgets(buffer, BUFSIZ, infile) == NULL)
	 message(FATAL, "I/O error in header\n");
      sprintf(buffer, "%%%%Pages: %d 0\n", p);
      writestring(buffer);
   }
   if (!fcopy(headerpos))
      message(FATAL, "I/O error in header\n");
}
Exemplo n.º 27
0
static void drawlongvolbar(uint16_t *buf, int, unsigned char st)
{
	int l,r;
	l=ci.vol;
	r=ci.vol;
	logvolbar(l, r);
	l=(l+2)>>2;
	r=(r+2)>>2;
	if (plPause)
		l=r=0;
	if (st)
	{
		writestring(buf, 16-l, 0x08, "\376\376\376\376\376\376\376\376\376\376\376\376\376\376\376\376", l);
		writestring(buf, 17,   0x08, "\376\376\376\376\376\376\376\376\376\376\376\376\376\376\376\376", r);
	} else {
		uint16_t left[] =  {0x0ffe, 0x0ffe, 0x0bfe, 0x0bfe, 0x0bfe, 0x0bfe, 0x09fe, 0x09fe, 0x09fe, 0x09fe, 0x01fe, 0x01fe, 0x01fe, 0x01fe, 0x01fe, 0x01fe};
		uint16_t right[] = {0x01fe, 0x01fe, 0x01fe, 0x01fe, 0x01fe, 0x01fe, 0x09fe, 0x09fe, 0x09fe, 0x09fe, 0x0bfe, 0x0bfe, 0x0bfe, 0x0bfe, 0x0ffe, 0x0ffe};
		writestringattr(buf, 16-l, left+16-l, l);
		writestringattr(buf, 17,   right, r);
	}
}
Exemplo n.º 28
0
bool World::save(const char * file)
{      
	 POSITION pos ;
    	ofstream f(file,ios::binary | ios::out );
	assert(f);
	
	for( pos=oper_ar.get_top_position();
		pos; pos=oper_ar.get_next((pos))){
		_oper *p=oper_ar.get(pos);
		
		if(!p->want_save()) continue;
		
		writestring(f, p->getname());
		writestring(f, p->get_defn());
	#ifndef NDEBUG
		cout<<"saving "<<p->getname()<<"   "<<p->get_defn()<<endl;
	#endif
		//f<<p->getname()<<'\n'<<p->get_defn()<<endl;
	}
	
	writestring(f, ""); //blank line 
	//char a[30];
	for( pos=var_ar.get_top_position();
		pos; pos=var_ar.get_next((pos))){


		
		writestring(f, var_ar.get(pos).name);
		var_ar.get(pos).val.write_binary(f); 
	#ifndef NDEBUG
		cout<<"saving "<<var_ar.get(pos).name<<"   "
			<<endl;
	#endif	

	}
	writestring(f, "");
	f.close();
	return true;
	
}
Exemplo n.º 29
0
void ServerUpdate::operator()(void)
{
	IFileDownload *dl=download_fak->createFileDownload();

	if(!Server->getServerParameter("http_proxy").empty())
	{
		dl->setProxy(Server->getServerParameter("http_proxy"), (unsigned short)atoi(Server->getServerParameter("http_proxy_port").c_str()));
	}

	IFile *tmp=Server->openTemporaryFile();
	if(tmp==NULL) return;
	std::string tfn=tmp->getFilename();
	Server->destroy(tmp);
	Server->Log("Downloading version file...", LL_INFO);
	dl->download("http://update1.urbackup.org/version.txt", tfn);

	if(!waitForDownload(dl))
	{
		download_fak->destroyFileDownload(dl);
		return;
	}

	std::string version=getFile(tfn);
	std::string curr_version=getFile("urbackup/version.txt");
	if(curr_version.empty()) curr_version="0";
	
	Server->deleteFile(tfn);

	if(atoi(version.c_str())>atoi(curr_version.c_str()))
	{
		Server->Log("Downloading signature...", LL_INFO);
		dl->download("http://update1.urbackup.org/UrBackupUpdate.sig", "urbackup/UrBackupUpdate.sig");
		if(!waitForDownload(dl))
		{
			download_fak->destroyFileDownload(dl);
			return;
		}
		Server->Log("Downloading update...", LL_INFO);
		dl->download("http://update1.urbackup.org/UrBackupUpdate.exe", "urbackup/UrBackupUpdate.exe");
		if(!waitForDownload(dl))
		{
			download_fak->destroyFileDownload(dl);
			return;
		}

		writestring(version, "urbackup/version.txt");
	}

	download_fak->destroyFileDownload(dl);
}
Exemplo n.º 30
0
int main(void)
{
    oled_init();
    OLED_Display('G');
    switchline(0);
	//writestring("Hello,World!");
	writestring("The Advanced Encryption Standard is a specification for the encryption of electronic data established by the U.S. National Institute of Standards and Technology in 2001");
    while(1)
    {
	//writestring("Hello,World!");
		
        //TODO:: Please write your application code 
    }
	return 0;
}