static void ls(const int& fd, const WorkingDirectory& wd) {
     DIR* dir = opendir(wd.getPath().c_str());
     if (!dir) {
         char buffer[maxn];
         cleanBuffer(buffer);
         sprintf(buffer, "%s: Cannot open the directory", wd.getPath().c_str());
         birdWrite(fd, buffer);
     }
     else {
         dirent *dirst;
         std::vector<std::string> fileList;
         while ((dirst = readdir(dir))) {
             std::string name(dirst->d_name);
             if (dirst->d_type == DT_DIR) {
                 name += "/";
             }
             fileList.push_back(name);
         }
         std::sort(fileList.begin(), fileList.end());
         char buffer[maxn];
         cleanBuffer(buffer);
         sprintf(buffer, "length = %d", static_cast<int>(fileList.size()));
         birdWrite(fd, buffer);
         for (unsigned i = 0; i < fileList.size(); ++i) {
             cleanBuffer(buffer);
             sprintf(buffer, "%s", fileList[i].c_str());
             birdWrite(fd, buffer);
         }
         closedir(dir);
     }
 }
예제 #2
0
파일: DataProvider.cpp 프로젝트: 4ortyk/Mix
void CDataProvider::setBufferFromEncodeFile()
{
	::std::ifstream inputFile(m_SrcFileName, ::std::ios::binary|::std::ios::in);
	if (!inputFile)
		return;

	inputFile.seekg (0, std::ios::end);
	std::streamoff end = inputFile.tellg();

	int oldBuffLen = m_BuffLen;
	m_BuffLen = ::std::min((unsigned) (end - m_FilePos),
		m_FrameLen * m_FramesPerSec * m_BuffTimeLen);

	if (m_BuffLen == 0) {
		cleanBuffer();
		inputFile.close();
		return;
	}

	if (m_BuffLen != oldBuffLen) {
		cleanBuffer();
		m_Buffer = new Uint8[m_BuffLen];
	}

	if (m_Buffer != NULL) {
		inputFile.seekg (m_FilePos, std::ios::beg);
		inputFile.read((char *)m_Buffer, m_BuffLen);
	}

	m_FilePos += m_BuffLen;
	inputFile.close();
}
예제 #3
0
int read(char *string, int lenght, int* number)
{
  char *end = NULL;
  if (fgets(string, lenght, stdin) != NULL)
    {
      end = strchr(string, '\n');
      if (end != NULL)
	{
	  *end = '\0';
        }
      else
        {
	  cleanBuffer();
        }
      if(string[0]>=48&&string[0]<=57)
	*number=atoi(string);
      else
	*number=-1;
      return 1;
    }
  else
    {
      cleanBuffer();
      return 0;
    }
}
예제 #4
0
int readFile(char *filename, char *buffer){
	int file = 0;
	int i=6;
	int sectors[26];
	int address=0;

	readSector(buffer,2);

	file = searchFileInDirectory(buffer,filename);
	if(file<0){
		cleanBuffer(buffer);
		return -1; //File was not found
	}

	file*=32; //set the rigth file offset
	for(i=0;i<26;i++){
		sectors[i]=buffer[file+i+6]; //pass each sector number to sectors array
	}

	cleanBuffer(buffer);

	for(i=0;i<26;i++){
		if(sectors[i]==0) //check if it is the last sector 
			break; 
		readSector(buffer+address,sectors[i]); //read the sector at sectors[i]
		address+=512; //create more space for the next sector to be read
	}

	return file;
}
 static std::string pwd(const int& fd) {
     char buffer[maxn];
     cleanBuffer(buffer);
     sprintf(buffer, "pwd");
     birdWrite(fd, buffer);
     cleanBuffer(buffer);
     birdRead(fd, buffer);
     return std::string(buffer);
 }
 static bool d(const int& fd, const std::string& argu, const WorkingDirectory& wd) {
     const std::string nargu = processArgument(argu);
     char buffer[maxn];
     cleanBuffer(buffer);
     sprintf(buffer, "d %s", argu.c_str());
     birdWrite(fd, buffer);
     cleanBuffer(buffer);
     birdRead(fd, buffer);
     if (std::string(buffer) == "UNEXPECTED_ERROR") {
         fprintf(stderr, "Unexpected Error\n");
         return false;
     }
     else if (std::string(buffer) == "PERMISSION_DENIED") {
         fprintf(stderr, "%s: Permission denied\n", nargu.c_str());
         return false;
     }
     else if (std::string(buffer) == "FILE_NOT_EXIST") {
         fprintf(stderr, "%s: No such file or directory\n", nargu.c_str());
         return false;
     }
     else if (std::string(buffer) == "IS_DIR") {
         fprintf(stderr, "%s is a directory\n", nargu.c_str());
         return false;
     }
     else if (std::string(buffer) == "NOT_REGULAR_FILE") {
         fprintf(stderr, "%s is not a regular file\n", nargu.c_str());
         return false;
     }
     std::string filename = getFileName(nargu);
     if (wd.getStartupPath().back() == '/') {
         filename = wd.getStartupPath() + "Download/" + filename;
     }
     else {
         filename = wd.getStartupPath() + "/Download/" + filename;
     }
     FILE* fp = fopen(filename.c_str(), "wb");
     if (!fp) {
         fprintf(stderr, "%s: File Open Error\n", filename.c_str());
         cleanBuffer(buffer);
         sprintf(buffer, "ERROR_OPEN_FILE");
         birdWrite(fd, buffer);
         return false;
     }
     cleanBuffer(buffer);
     sprintf(buffer, "OK");
     birdWrite(fd, buffer);
     printf("Download File \"%s\"\n", getFileName(nargu).c_str());
     unsigned long fileSize;
     birdRead(fd, buffer);
     sscanf(buffer, "%*s%*s%lu", &fileSize);
     printf("File size: %lu bytes\n", fileSize);
     birdReadFile(fd, fp, fileSize);
     printf("Download File \"%s\" Completed\n", getFileName(nargu).c_str());
     fclose(fp);
     return true;
 }
 static bool u(const int& fd, const std::string& argu) {
     const std::string nargu = processArgument(argu);
     int chk = isExist(nargu);
     if (chk == -2) {
         fprintf(stderr, "%s: Unexpected Error\n", nargu.c_str());
         return false;
     }
     else if (chk == -1) {
         fprintf(stderr, "%s: Permission denied\n", nargu.c_str());
         return false;
     }
     else if (chk == 0) {
         fprintf(stderr, "%s: No such file or directory\n", nargu.c_str());
         return false;
     }
     else if (chk == 2) {
         fprintf(stderr, "%s is a directory\n", nargu.c_str());
         return false;
     }
     else if (chk == 3) {
         fprintf(stderr, "%s is not a regular file\n", nargu.c_str());
         return false;
     }
     FILE* fp = fopen(nargu.c_str(), "rb");
     if (!fp) {
         fprintf(stderr, "%s: Unexpected Error\n", nargu.c_str());
         return false;
     }
     unsigned long fileSize;
     struct stat st;
     stat(nargu.c_str(), &st);
     fileSize = st.st_size;
     char buffer[maxn];
     cleanBuffer(buffer);
     sprintf(buffer, "u %s", argu.c_str());
     birdWrite(fd, buffer);
     cleanBuffer(buffer);
     birdRead(fd, buffer);
     if (std::string(buffer) == "ERROR_OPEN_FILE") {
         fprintf(stderr, "Cannot open file \"%s\" on Remote Server\n", getFileName(argu.c_str()).c_str());
         fclose(fp);
         return false;
     }
     printf("Upload File \"%s\"\n", getFileName(nargu).c_str());
     cleanBuffer(buffer);
     sprintf(buffer, "filesize = %lu", fileSize);
     birdWrite(fd, buffer);
     printf("File size: %lu bytes\n", fileSize);
     birdWriteFile(fd, fp, fileSize);
     printf("Upload File \"%s\" Completed\n", getFileName(nargu).c_str());
     fclose(fp);
     return true;
 }
 static void cd(const int& fd, const std::string& argu) {
     const std::string nargu = argu;
     char buffer[maxn];
     cleanBuffer(buffer);
     sprintf(buffer, "cd %s", nargu.c_str());
     birdWrite(fd, buffer);
     cleanBuffer(buffer);
     birdRead(fd, buffer);
     if (std::string(buffer) != "") {
         printf("%s\n", buffer);
     }
 }
예제 #9
0
bool GPRS::connect(int socket, Protocol ptl,const char * host, int port, int timeout)
{
    char buf[96];
    if (socket < 0 || socket > MAX_SOCK_NUM-1) {
        return false;
    }
    
    if(ptl == TCP) {
        sprintf(buf, "AT+CIPSTART=%d,\"TCP\",\"%s\",%d\r\n",socket, host, port);
    } 
#if 0
    else if(ptl == UDP) {
        sprintf(buf, "AT+CIPSTART=%d,\"UDP\",\"%s\",%d\r\n",socket, host, port);
    }
#endif    
    else {
        return false;
    }
    sendCmd(buf);
    cleanBuffer(buf,sizeof(buf));
    readBuffer(buf,sizeof(buf),2*DEFAULT_TIMEOUT);
    if(NULL != strstr(buf,"CONNECT")) { //ALREADY CONNECT or CONNECT OK
        return true;
    }
    return false;//ERROR
}
 static void cd(const int& fd, const std::string& argu, WorkingDirectory& wd) {
     const std::string nargu = processArgument(argu);
     std::string ret = wd.changeDir(nargu);
     char buffer[maxn];
     cleanBuffer(buffer);
     sprintf(buffer, "%s", ret.c_str());
     birdWrite(fd, buffer);
 }
예제 #11
0
KGridWidget::KGridWidget(QWidget *parent, bool draw) : m_drawGrid(draw)
{
	m_doubleBuffer = new QPixmap(parent->width(), parent->height());
	m_parent = parent;

	cleanBuffer();
	cacheImages();
}
예제 #12
0
/*!
\brief Data received from telnet interface

This function is called when data is sent by the router through the serial interface.
It calls CLInterface::cleanBuffer() function to clean up the buffer and emit proper signals.
*/
void TelnetInterface::telnetDataReceived()
{
	int r = s->readBlock(currPos, bufferFreeBytes() );
	currPos[r] = '\0';
	currPos += r;
	
	cleanBuffer();
}
예제 #13
0
/**
 * @brief In the main function the connection to mySQL is created, the serial port is being initialized.
 * The data will be readed from serial port until a key was pressed. \n Every message will be parsed into array,
 * which will be used for creating of a SQL-statement. The SQL-command is gonna be executed. \n Finally the serial port
 * and the SQL-connection is getting closed.
 */
int main(int argc, CHAR* argv[]) {
	BOOL rc;
	CHAR msgTextBuf[1024];
	DWORD bytesRead;        		  // NumberOfBytesRead
	DWORD start, end, result;
	int i, j;

	DWORD dwRead;
	BOOL fWaitingOnRead = FALSE;
	OVERLAPPED osReader = {0};

	char mce_table[] = "values_realtime";
	short *shortMsg;

	rc = MySQLConnect();			// connect to mySQL
	if (rc == FALSE) {
		printf("Error with MySQLConnect(). Program exits. \n");
		return -1;
	}

	rc = initSerial(COMPORT);          // If the function succeeds, the return value is nonzero.
	if (rc == FALSE) {
		printf("Error while initSerial(). Program exits. \n");
		return -1;
	}


	cleanBuffer(msgTextBuf);

	while (TRUE) {
		// reads data on port and store it on mySQL server. If succeeds rc is TRUE.
		rc = ReadFile(comPort, msgTextBuf, sizeof(msgTextBuf), &bytesRead, NULL);
		if (rc != FALSE && bytesRead != 0) {
			// parseMessage(msgTextBuf);
			shortMsg = parseMsgToShort(msgTextBuf, bytesRead);
			rc = updateMMData(mce_table, shortMsg);
			// rc = insertMMData(mce_table, shortMsg);
			if (rc == FALSE) {
				printf("Error while insertSQLData(). Program will continue. \n");
			} else {
				printf("MM-data successfull updated. \n");
			}
			// printf("%s \n", msgTextBuf);
		}
	}

	rc = CloseHandle(comPort);        	// If succeeds, rc is TRUE.
	if (rc == FALSE) {
		printf("Error while CloseHandle(). Program exits. \n");
		return -1;
	}

	mysql_close(g_pMySQL);
	mysql_library_end();

	printf("\n\nEnd of program..");
	return 0;
}
 static std::string ls(const int& fd) {
     char buffer[maxn];
     cleanBuffer(buffer);
     sprintf(buffer, "ls");
     birdWrite(fd, buffer);
     cleanBuffer(buffer);
     birdRead(fd, buffer);
     std::string ret = "";
     int msgLen;
     sscanf(buffer, "%*s%*s%d", &msgLen); // format: length = %d
     for (int i = 0; i < msgLen; ++i) {
         birdRead(fd, buffer);
         ret += std::string(buffer) + "\n";
     }
     if (ret.back() == '\n') {
         ret.pop_back();
     }
     return ret;
 }
예제 #15
0
int GPRS::recv(int socket, char* buf, int len)
{
    if (socket < 0 || socket > MAX_SOCK_NUM-1) {
        return -1;
    }
    cleanBuffer(buf,len);
    readBuffer(buf,len,DEFAULT_TIMEOUT/2);
    return len;
    //return strlen(buf);
}
 static void u(const int& fd, const std::string& argu, const WorkingDirectory& wd) {
     const std::string nargu = processArgument(argu);
     char buffer[maxn];
     std::string filename = getFileName(nargu);
     FILE* fp = fopen(filename.c_str(), "wb");
     if (!fp) {
         cleanBuffer(buffer);
         sprintf(buffer, "ERROR_OPEN_FILE");
         birdWrite(fd, buffer);
         return;
     }
     else {
         cleanBuffer(buffer);
         sprintf(buffer, "OK");
         birdWrite(fd, buffer);
     }
     unsigned long fileSize;
     birdRead(fd, buffer);
     sscanf(buffer, "%*s%*s%lu", &fileSize);
     birdReadFile(fd, fp, fileSize);
     fclose(fp);
 }
예제 #17
0
void stopChopperDrop(ChopperDrop* game)
{
	// unsubscribe devices
	unsubscribeKeyboard();
	unsubscribeTimer();
	unsubscribeMouse();

	deleteBitmap(game->mouseCursor);

	deleteCurrentState(game);

	disableMouse();
	cleanBuffer();
	deleteMouse();
	deleteTimer(game->timer);
	deleteDate(game->date);

	free(game);
}
예제 #18
0
bool GPRS::checkSIMStatus(void)
{
    char gprsBuffer[32];
    int count = 0;
    cleanBuffer(gprsBuffer,32);
    while(count < 3) {
        sendCmd("AT+CPIN?\r\n");
        readBuffer(gprsBuffer,32,DEFAULT_TIMEOUT);
        if((NULL != strstr(gprsBuffer,"+CPIN: READY"))) {
            break;
        }
        count++;
        delay(1000);
    }
    if(count == 3) {
        return false;
    }
    return true;
}
예제 #19
0
파일: menu.c 프로젝트: MFreeze/m2moca
void printMenu(int *choice) {
    char buffer[50];
    do {
        printf("\n*=====================================*\n"
               "|       Please choose an action       |\n"
               "*=====================================*\n"
               "\n"
               "1. [Diffie Hellman] Key computation \n"
               "2. [RSA] Key computation \n"
               "3. [RSA] Encryption \n"
               "4. [RSA] Decryption \n"
               "\n"
               "Your choice : ");
        fgets(buffer,sizeof(buffer),stdin);
        cleanBuffer(buffer);
        *choice = atoi(buffer);
        printf("%d\n", *choice);
    } while (*choice <= 0 || *choice > 4);
}
예제 #20
0
void initShell() {
	//clearScreen();
	printf("-- WELCOME THE SHELL --\n\n  >>");
	setTimeZone(-3);
	setConsoleSize();
	shellBuffer = sbuffer[0];
	cleanBuffer();

	while(1) {
		int c = getc();
		if (c != EOF) {
			if (c == '\n') {
				execute();
			} else if (c == '\b') {
				removeKey();
			} else {
				addToShellBuffer(c);
				putc(c);
			}
		}
	}
}
예제 #21
0
파일: DataProvider.cpp 프로젝트: 4ortyk/Mix
CDataProvider& CDataProvider::operator=(const CDataProvider& obj)
 {
	if (this == &obj)
		return *this;

	m_BuffPos = obj.m_BuffPos;
	m_BuffLen = obj.m_BuffLen;
	m_FilePos = obj.m_FilePos;
	m_SrcFileName = obj.m_SrcFileName;
	m_BuffTimeLen = obj.m_BuffTimeLen;

	cleanBuffer();

	if (obj.m_Buffer == NULL) {
		return *this;
	}

	m_Buffer = new Uint8[m_BuffLen];
	if (m_Buffer != NULL) {
		memcpy_s(m_Buffer, m_BuffLen, obj.m_Buffer, m_BuffLen);
	}

	return *this;
 }
예제 #22
0
파일: opengl_13.cpp 프로젝트: kindex/Steel
// нарисовать множество полигонов с указанным материалом / Multitexture
bool OpenGL_Engine::DrawFill_MaterialStd_OpenGL13(GraphShadow& e, const Faces& triangles, MaterialStd& material)
{
	if (GL_EXTENSION_MULTITEXTURE)
	{
		glPushAttrib(GL_ALL_ATTRIB_BITS);
		glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);

		pvector<uid> buffersToDelete;

		bool bump_map = material.normal_map.image != NULL && flags.bump && !e.lights.empty() && e.normals != NULL && GL_EXTENSION_DOT3 && GL_EXTENSION_TEXTURE_CUBE_MAP;
		bool diffuse_map = material.diffuse_map.image != NULL && flags.textures;
		bool emission_map = material.emission_map.image != NULL && flags.textures;
        bool blend_map = material.blend_map.image != NULL;
		int currentTextureArb = 0;

		if (bump_map)
		{
			const TexCoords *texCoords = e.getTexCoords(material.normal_map);

			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

			uid bufId = objectIdGenerator.genUid();
			buffersToDelete.push_back(bufId);

			drawBump(e, texCoords, e.position, e.lights[0]->position, bufId, currentTextureArb, material.normal_map.image);
			currentTextureArb +=2;
		}

		if (diffuse_map)
		{
			glActiveTextureARB(GL_TEXTURE0_ARB + currentTextureArb);
			glClientActiveTextureARB(GL_TEXTURE0_ARB + currentTextureArb);
			glDisable(GL_TEXTURE_COORD_ARRAY);

			GLint mode = GL_REPLACE;
			if(currentTextureArb > 0)
				mode = GL_MODULATE;

			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode);

			(this->*BindTexture)(*material.diffuse_map.image, true);

			const TexCoords *texCoords = NULL;

			if (material.diffuse_map.texCoordsUnit < e.texCoords.size())
			{
				texCoords = e.texCoords[material.diffuse_map.texCoordsUnit];
			}
			else if(!e.texCoords.empty())
			{
				texCoords = e.texCoords[0];
			}

			assert(texCoords->size() == e.vertexes->size(), "TexCoords.size != Vertex.size");
			if(BindTexCoords != NULL) (this->*BindTexCoords)(texCoords, &material.textureMatrix);
			currentTextureArb++;
		}

		if (emission_map)
		{
			glActiveTextureARB(GL_TEXTURE0_ARB + currentTextureArb);
			glClientActiveTextureARB(GL_TEXTURE0_ARB + currentTextureArb);
			glDisable(GL_TEXTURE_COORD_ARRAY);

			GLint mode = GL_REPLACE;
			if (currentTextureArb > 0)
			{
				mode = GL_ADD;
			}

			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode);

			(this->*BindTexture)(*material.emission_map.image, true);

			const TexCoords *texCoords = NULL;

			if (material.diffuse_map.texCoordsUnit < e.texCoords.size())
			{
				texCoords = e.texCoords[material.diffuse_map.texCoordsUnit];
			}
			else if (!e.texCoords.empty())
			{
				texCoords = e.texCoords[0];
			}

			assert(texCoords->size() == e.vertexes->size(), "TexCoords.size != Vertex.size");
			(this->*BindTexCoords)(texCoords, &material.textureMatrix);
			currentTextureArb++;
		}

		if (blend_map)
		{
			glActiveTextureARB(GL_TEXTURE0_ARB + currentTextureArb);
			glClientActiveTextureARB(GL_TEXTURE0_ARB + currentTextureArb);
			glDisable(GL_TEXTURE_COORD_ARRAY);

            GLint mode = GL_MODULATE;

			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode);

			(this->*BindTexture)(*material.blend_map.image, true);

			const TexCoords *texCoords = NULL;

			if (material.blend_map.texCoordsUnit < e.texCoords.size())
			{
				texCoords = e.texCoords[material.blend_map.texCoordsUnit];
			}
			else if (!e.texCoords.empty())
			{
				texCoords = e.texCoords[0];
			}

			assert(texCoords->size() == e.vertexes->size(), "TexCoords.size != Vertex.size");
			(this->*BindTexCoords)(texCoords, &material.textureMatrix);
			currentTextureArb++;
		}

        if (!diffuse_map)
		{
			glColor4fv(material.color.getfv());
		}

		(this->*DrawTriangles)(e, triangles, NULL);

		if (CleanupDrawTriangles != NULL) (this->*CleanupDrawTriangles)();

		for(uidVector::const_iterator it = buffersToDelete.begin(); it != buffersToDelete.end(); it++)
		{
			cleanBuffer(*it);
		}
		
		unbindTexCoords();

		glPopClientAttrib();
	   	glPopAttrib();

		return true;
	}
	return false;
}
예제 #23
0
void KGridWidget::finished()
{
	bitBlt(m_parent, 0, 0, m_doubleBuffer);
	cleanBuffer();
}
 static void undef(const int& fd, const std::string& command) {
     char buffer[maxn];
     cleanBuffer(buffer);
     sprintf(buffer, "%s: Command not found", command.c_str());
     birdWrite(fd, buffer);
 }
예제 #25
0
파일: main.c 프로젝트: AxelDelsol63/TPWeb
int main (int argc, char ** argv)
{
  int n, j, g, choice;
  double p;
  double** A;
  int i=1;
  while (i!=0)
  {
    clear();
    printf("Menu principal : Polynome caractéristique, valeurs propres et vecteurs propres\n\n");
    printf("Choisir le mode de saisie de la matrice :\n");
    printf("1- Utiliser le générateur de matrices\n");
    printf("0- Entrer manuellement les valeurs\n");
    printf("Votre choix : ");
    scanf("%d",&g);
    clear();
    if(g)
    {
      printf("MENU : GENERATION DE MATRICES\n\n");
      printf("Choisir un type de matrice à générer :\n");
      printf("1. Creuse à 70%%\n");
      printf("2. A bord\n");
      printf("3. Ding-Dong\n");
      printf("4. Franc\n");
      printf("5. Hilbert\n");
      printf("6. KMS\n");
      printf("7. Lehmer\n");
      printf("8. Lotkin\n");
      printf("9. Moler\n");
      printf("Votre choix : ");
      scanf("%d", &choice);
      printf("Dimension : ");
      scanf("%d", &n);
      switch (choice)
      {
	case 1:
	  A=creuse70(n);
	  break;
	case 2:
	  A=bord(n);
	  break;
	case 3:
	  A=dingDong(n);
	  break;
	case 4:
	  A=franc(n);
	  break;
	case 5:
	  A=hilbert(n);
	  break;
	case 6:
	  printf("Parametre p : ");
	  scanf("%lf", &p);
	  A=kms(n,p);
	  break;
	case 7:
	  A=lehmer(n);
	  break;
	case 8:
	  A=lotkin(n);
	  break;
	case 9:
	  A=moler(n);
	  break;
      }
//    Déplacement de afficher matrice pour l'afficher au-dessus du menu de choix, ainsi elle est systématiquement affichée
    }
    else
    {
      printf("Matrice A :\n");
      printf("Dimension : ");
      scanf("%d",&n);
      A=creerRemplirMatrice(n,n);
    }
      convertMattoLatex(A,n,n);
    i=1;
    while (i!=0 && i!=9)
    {
      clear();
      printf("Matrice :\n");
      afficherMatrice(A, n, n);
      printf("\nQue voulez-vous faire ?\n");
      printf("1- Méthode de Leverrier\n");
      printf("2- Méthode de Leverrier améliorée\n");
      printf("3- Méthode des Puissances Itérées\n");
      printf("9- Nouvelle matrice (Menu principal)\n");
      printf("0- Quitter\n");
      printf("Votre choix : ");
      scanf("%d", &i);
      cleanBuffer(); //vidage buffer
      clear();
      switch (i)
      {
	case 1:
	  printf("Polynome caracteristique par Leverrier... \n");
	  leverrier(A,n);
	  hitToContinue();
	  break;
	case 2:
	  printf("Polynome caracteristique par Leverrier améliorée ... \n");
	  leverrierA(A,n);
	  hitToContinue();
	  break;
	case 3:
	  printf("Méthode des puissances itérées ... \n");
	  printf("Précision souhaitée : ");
	  scanf("%lf", &p);
	  cleanBuffer();
	  puissancesIt(A,n,p);
	  hitToContinue();
	  break;
      }
    }
    
    //libération mémoire
    for (j=0; j<n; j++)
    {
      free(A[j]);
    }
    free(A);
  }
  return 0;
}
 static void q(const int& fd) {
     char buffer[maxn];
     cleanBuffer(buffer);
     sprintf(buffer, "q");
     birdWrite(fd, buffer);
 }
예제 #27
0
void execute() {
	char arr[100] = {0};
	int number = 0;


	int tz;
	sbuffer[shellIndex] = '\0';
	int num, pidToKill, msg = 0, psToFg = 1;
	putc('\n');
	if(shellBuffer[0] == '&') {
		psToFg = 0;
		shellBuffer++;
	}
	if (strcmp(shellBuffer, "func") == 0) {
		void** parg = (void**)malloc(sizeof(void*) * 2);
		parg[0] = (void*)"func";
		exec(&func, 1, parg, psToFg);

	} else if (strcmp(shellBuffer, "clear") == 0) {
//		void** parg = (void**)malloc(sizeof(void*));
//		parg[0] = (void*)"clear";
//		exec(&clearScreen, 1, parg, psToFg);
		clear();

	} else if(strcmp(shellBuffer, "time") == 0) {
		void** parg = (void**)malloc(sizeof(void*));
		parg[0] = (void*)"time";
		exec(&printTime, 1, parg, psToFg);

	} else if(strcmp(shellBuffer, "date") == 0) {
		void** parg = (void**)malloc(sizeof(void*));
		parg[0] = (void*)"date";	
		exec(&printDate, 1, parg, psToFg);

	} else if(sscanf("setTimeZone %d",shellBuffer,&tz)==1) {
		void** parg = (void**)malloc(sizeof(void*) * 2);
		parg[0] = (void*)"setTimeZone";
		parg[1] = (void*)tz;
		exec(&callSetTimeZone, 2, parg, psToFg);

	} else if(strcmp(shellBuffer, "fractal Zelda") == 0) {
		void** parg = (void**)malloc(sizeof(void*));
		parg[0] = (void*)"fractal";
		clear();
		int pid = exec(&drawFractal, 1, parg, psToFg);
		//sleep(1000);
		//clear();

	} else if(strcmp(shellBuffer, "multifractal") == 0) {
		clear();
		void** parg = (void**)malloc(sizeof(void*) * 1);
		parg[0] = (void*)"multifractal";
		exec(&multifractal, 1, parg, psToFg);
	
	} else if(sscanf("kill %d %d",shellBuffer,&pidToKill, &msg)==2){
		void** parg = (void**)malloc(sizeof(void*) * 3);
		parg[0] = (void*)"kill";
		parg[1] = (void*)pidToKill;
		parg[2] = (void*)msg;
		exec(&callKill, 3, parg, psToFg);

	} else if(strcmp(shellBuffer, "help") == 0) {
		void** parg = (void**)malloc(sizeof(void*));
		parg[0] = (void*)"help";
		exec(&printInstructions, 1, parg, psToFg);

	} else if(strcmp(shellBuffer, "star wars") == 0) {
		void** parg = (void**)malloc(sizeof(void*));
		parg[0] = (void*)"starwars";
		exec(&playStarWars, 1, parg, psToFg);

	} else if(strcmp(shellBuffer, "philo") == 0) {
		if(isRunningSync("philoManager")) {
			printf("Philo already running...\n");
		}else{
			void** parg = (void**)malloc(sizeof(void*));
			parg[0] = (void*)"philoManager";
			exec(&philosphers,1,parg, psToFg);
		}

	}else if(strcmp(shellBuffer, "prod") == 0) {
		if(isRunningSync("prodConsManager")) {
			printf("Producer-Consumer already running...\n");
		}else{
			void** parg = (void**)malloc(sizeof(void*));
			parg[0] = (void*)"prodConsManager";
			exec(&producerConsumer,1,parg, psToFg);
		}
	} else if(strcmp(shellBuffer, "gedit") == 0) {
		void** parg = (void**)malloc(sizeof(void*));
		parg[0] = (void*)"gedit";
		exec(&callRunGedit, 1, parg, psToFg);
	} else if(strcmp(shellBuffer, "paint") == 0) {
		void** parg = (void**)malloc(sizeof(void*));
		parg[0] = (void*)"paint";
		exec(&callPaintLoop, 1, parg, psToFg);

	} else if(sscanf("paintBg %d", shellBuffer, &num) == 1) {
		void** parg = (void**)malloc(sizeof(void*) * 2);
		parg[0] = (void*)"paintBg";
		parg[1] = (void*)num;
		exec(&paintBg, 2, parg, psToFg);

	} else if(sscanf("setupFont %d", shellBuffer, &num) == 1) {
		void** parg = (void**)malloc(sizeof(void*) * 2);
		parg[0] = (void*)"setupFont";
		parg[1] = (void*)num;
		exec(callChangeFont, 2, parg, psToFg);

	}else if(sscanf("echo %s",shellBuffer,arr)==1) {
//		void** parg = (void**)malloc(sizeof(void*) * 2);
//		parg[0] = (void*)"echo";
//		parg[1] = (void*)arr;
//		exec(&callEcho, 2, parg, psToFg);
		printf("%s\n",arr);
	} else if(strcmp(shellBuffer, "ps") == 0) {
		void** parg = (void**)malloc(sizeof(void*));
		parg[0] = (void*)"ps";
		exec(&ps, 1, parg, psToFg);

	} else if(strcmp(shellBuffer, "newps") == 0) {
		void** parg = (void**)malloc(sizeof(void*));
		parg[0] = (void*)"uslessPs";
		exec(&uslessPs, 1,parg, psToFg);

	} else if(strcmp(shellBuffer, "pepito") == 0) {
		void** parg = (void**)malloc(sizeof(void*));
		parg[0] = (void*)"PepitoJoseCreator";
		exec(&pepitoJose, 1,parg, psToFg);

	} else if(sscanf("pacman clear %d", shellBuffer, &num) == 1) {
        if(num<1 || num>20)
            printf("Number muste be between 1 and 20\n");
        else
            pacmanClear(num);
	}  else if(strcmp(shellBuffer, "ipcs") == 0) {
        printIPCs();
    } else if(sscanf("fg %i",shellBuffer, &num)==1) {
		void** parg = (void**)malloc(sizeof(void*) * 3);
		parg[0] = (void*)"giveForeground";
		parg[1] = (void*)num;
		parg[2] = (void*)3;
		exec(&callKill, 3, parg, psToFg);

	} else if(sscanf("isRunning %s",shellBuffer, arr)==1) {
		char * array = malloc(strlen(arr));	// <---- Necesita hacer malloc si no el parámetro se pierde a veces en exec
		strcpy(array, arr, 100);

		void** parg = (void**)malloc(sizeof(void*) * 2);
		parg[0] = (void*)"isRunning";
		parg[1] = (void*)array;
		exec(&isRunning, 2, parg, psToFg);
	} else if(strcmp(shellBuffer, "memory") == 0) {
        void** parg = (void**)malloc(sizeof(void*));
        parg[0] = (void*)"MemoryUsed";
        exec(&getMemoryUsed, 1, parg, psToFg);
        free(parg);
    }  else {
		printf("Command not found.\n");
	}

	if (psToFg == 0) {
		shellBuffer--;
	}
	sleep(200);
	printf("  >>");
	cleanBuffer();
}
 static void d(const int& fd, const std::string& argu) {
     const std::string nargu = processArgument(argu);
     char buffer[maxn];
     int chk = isExist(nargu);
     if (chk == -2) {
         cleanBuffer(buffer);
         sprintf(buffer, "UNEXPECTED_ERROR");
         birdWrite(fd, buffer);
         return;
     }
     else if (chk == -1) {
         cleanBuffer(buffer);
         sprintf(buffer, "PERMISSION_DENIED");
         birdWrite(fd, buffer);
         return;
     }
     else if (chk == 0) {
         cleanBuffer(buffer);
         sprintf(buffer, "FILE_NOT_EXIST");
         birdWrite(fd, buffer);
         return;
     }
     else if (chk == 2) {
         cleanBuffer(buffer);
         sprintf(buffer, "IS_DIR");
         birdWrite(fd, buffer);
         return;
     }
     else if (chk == 3) {
         cleanBuffer(buffer);
         sprintf(buffer, "NOT_REGULAR_FILE");
         birdWrite(fd, buffer);
         return;
     }
     FILE* fp = fopen(nargu.c_str(), "rb");
     if (!fp) {
         cleanBuffer(buffer);
         sprintf(buffer, "UNEXPECTED_ERROR");
         birdWrite(fd, buffer);
         return;
     }
     else {
         cleanBuffer(buffer);
         sprintf(buffer, "FILE_EXISTS");
         birdWrite(fd, buffer);
     }
     cleanBuffer(buffer);
     birdRead(fd, buffer);
     if (std::string(buffer) == "ERROR_OPEN_FILE") {
         fclose(fp);
         return;
     }
     unsigned long fileSize;
     struct stat st;
     stat(nargu.c_str(), &st);
     fileSize = st.st_size;
     cleanBuffer(buffer);
     sprintf(buffer, "filesize = %lu", fileSize);
     birdWrite(fd, buffer);
     birdWriteFile(fd, fp, fileSize);
     fclose(fp);
     return;
 }
 static std::string nextCommand(const int& fd) {
     char buffer[maxn];
     cleanBuffer(buffer);
     birdRead(fd, buffer);
     return std::string(buffer);
 }
 static void pwd(const int& fd, const WorkingDirectory& wd) {
     char buffer[maxn];
     cleanBuffer(buffer);
     sprintf(buffer, "%s", wd.getPath().c_str());
     birdWrite(fd, buffer);
 }