コード例 #1
0
ファイル: bookshlf.c プロジェクト: CivilPol/sdcboot
void List ( void )
{
	int bookN = 0;

	puts ("List of available books:");
	while ( TRUE )
	{
		/* read line removing spaces */
		fgets (line, MaxLine, fin);
		NoSpaces ();

		/* if /BOOKSHELF or => break */
		if (!strcmp(line,"<!--/BOOKSHELF-->")) break;
		if (feof(fin)) CriticalError (SC_BooksCorrupted, "");

		bookN++;

		/* Line must start with <!--BOOK=bookname, and then print it */
		if ( !GetBookName() ) CriticalError (SC_BooksCorrupted, "");
		printf ("    %s\n",line);

		/* Strip until one gets to <!--/BOOK--> */
		do {
			fgets(line, MaxLine, fin);
			NoSpaces();
		} while ( strcmp(line,"<!--/BOOK-->") && !feof(fin) );

		if (feof(fin)) CriticalError (SC_BooksCorrupted, "");

	}
	printf ("Number of books found: %u\n", bookN);
}
コード例 #2
0
ファイル: extgraph.cpp プロジェクト: nejyeah/cplusplus
void SetPenColor(string color)
{
    if (TcpClient == NULL) Error("Graphics not initialized");
    stringstream cmd;
    cmd << "SETPENCOLOR " << NoSpaces(color);
    string resp = TcpClient->ExchangeMsg(cmd.str());
    if (resp != "OK") Error(cmd.str() + ": " + resp);
}
コード例 #3
0
ファイル: extgraph.cpp プロジェクト: nejyeah/cplusplus
void DefineColor(string name,
                 double red, double green, double blue)
{
    if (TcpClient == NULL) Error("Graphics not initialized");
    stringstream cmd;
    cmd << "DEFINECOLOR " << NoSpaces(name) << " "
	<< red << " " << green << " " << blue;
    string resp = TcpClient->ExchangeMsg(cmd.str());
    if (resp != "OK") Error(cmd.str() + ": " + resp);
}
コード例 #4
0
ファイル: bookshlf.c プロジェクト: CivilPol/sdcboot
void Del ( void )
{
	char tag[MaxLine]= "<!--BOOK=";
	char stout[255] = "";

	strcat (tag,BookName);
	strcat (tag,"-->");
	strupr (tag);

	fgets  (line, MaxLine, fin);
	strcpy (stout, line);
	NoSpaces();

	while (strcmp(line,tag))
	{
		if (!strcmp(line,"<!--/BOOKSHELF-->"))
			CriticalError (SC_BookNotFound, BookName);
		if (feof(fin)) CriticalError (SC_BooksCorrupted, "");

		fputs (stout, fout);
		do {
			fgets (line, MaxLine, fin);
			if (feof(fin)) CriticalError (SC_BooksCorrupted, "");
			fputs (line, fout);
			NoSpaces();
		} while (strcmp(line,"<!--/BOOK-->"));

		fgets  (line, MaxLine, fin);
		strcpy (stout, line);
		NoSpaces();

	}

	do {
		fgets (line, MaxLine, fin);
		NoSpaces();
		if (feof(fin)) CriticalError (SC_BooksCorrupted, "");
	} while (strcmp(line,"<!--/BOOK-->"));

}
コード例 #5
0
ファイル: bookshlf.c プロジェクト: CivilPol/sdcboot
void main ( BYTE argc, char *argv[] )
{
	int i=2 ;

  /*********** STARTUP AND PARAMETER PARSING **************/

	/* Opening strings */
	printf ("BOOKSHLF %s - FreeDOS Book Shelf manager\n", VerS);
	puts ("Copyright Aitor SANTAMARIA MERINO under the GNU GPL 2.0\n");

	/* Discard FastHelp */

	if ( (argc==1) ||
	     ( (argc==2) && (!strcmp(argv[1],"/?")) ) )
	     FastHelp ();

	/* Determine command (argv[1]) */

	if (!strcmp (strupr(argv[1]),"LIST") )
		curcommand = CM_List;
	else if (!strcmp (argv[1],"ADD"))
		curcommand = CM_Add;
	else if (!strcmp (argv[1],"DEL"))
		curcommand = CM_Del;
	else
		CriticalError (SC_UnknownCommand, "");

	/* Get the book name (ADD/DEL) */
	if ( (curcommand==CM_Add) || (curcommand==CM_Del) )
	{
		if (argc<3) CriticalError (SC_WrongNParams, "");
		strncpy (BookName, argv[i++], MaxLine);
	}

	/* More arguments? */
	if (argc > (i+1)) CriticalError (SC_WrongNParams, "");
	if (argc == (i+1))
		strncpy (finName, argv[i], 255);


  /*********** OPENING FILES **************/

	/*  Try to open the source HTML file */
	i=1;	/* Flag meaning: 2=no finName was specified, 1=was specified */
	if (!finName[0])
	{
		i++;
		strcpy (finName, "..\\HELP\\INDEX.HTM");
//		strcpy (finName, "INDEX.HTM");
// for easy testings
	}

	while (i--)
		if ((fin = fopen (finName,"rt"))!=NULL) i=0;
		else
		   if (i) {
			strcpy (foutName, getenv ("HELPPATH"));
			if (!foutName[0]) CriticalError (SC_CantOpenSource, finName);
			strcat (foutName, "\\INDEX.HTM");
			strcpy (finName, foutName);
		   }
		   else CriticalError (SC_CantOpenSource, finName);


	/* Add extension BI if not present */
	if ( curcommand==CM_Add )
	{
		for ( i = strlen(BookName)-1; (i>=0) && (BookName[i]!='\\') && (BookName[i]!='.'); i--);
		if (! ((i>=0) && (BookName[i]=='.')) )
			strcat (BookName, ".BI");

		/* Open book index */
		if ((fbook = fopen (BookName,"rt"))==NULL)
			CriticalError (SC_CantOpenBI, BookName);
	}

	/* Compose the target file name .$$$ and try to open it (ADD/DEL) */
	if ( (curcommand==CM_Add) || (curcommand==CM_Del) )
	{
		for ( i=strlen(finName)-1; (i>=0) && (finName[i]!='\\')
						   && (finName[i]!='.')         ; i--);
		if ( (i<0) || ( (i>=0) && (finName[i]=='\\') ) )
			i=strlen(finName);

		strncpy (foutName, finName, i);
		strcat  (foutName, ".$$$");

		if ((fout = fopen (foutName,"wt"))==NULL)
			CriticalError (SC_CantOpenTarget, foutName);
	}

  /*********** MAIN WORK **************/

	/* Find <!--BOOKSHELF-->*/
	do {
		fgets (line, MaxLine, fin);
		if ( (curcommand==CM_Add) || (curcommand==CM_Del) )
			fputs (line, fout);
		NoSpaces();
	} while ( strcmp(line,"<!--BOOKSHELF-->") &&
		    !feof (fin)	);
	if (feof(fin)) CriticalError (SC_NoBookhelpFile, finName);

	/* Main loop */
	switch ( curcommand )
	{
		case CM_List: List();
				  break;
		case CM_Add:  Add();
				  break;
		case CM_Del:  Del();
	}

  /*********** CLOSING TASKS **************/

	/* Close files */
	switch ( curcommand )
	{
	   case CM_Add:
		fclose (fbook);

	   case CM_Del:
		while (!feof(fin))
		{
			fgets (line, MaxLine, fin);
			if (feof(fin)) break;
			fputs (line, fout);
		}
		fclose (fout);

	   case CM_List:
		fclose (fin);
	}

	/* File renaming stuff */
	if ( (curcommand==CM_Add) || (curcommand==CM_Del) )
	{
		/* create the back name */
		strncpy (fbackName, finName, 255);
		if ( (strlen(fbackName)>4) &&
		     (fbackName[strlen(fbackName)-4]=='.') )
			fbackName[strlen(fbackName)-4]=0;
		strcat (fbackName,".BAK");

		/* File mangling */
		if (remove(fbackName)) CriticalError (SC_CantRemoveFin, finName);
		if (rename(finName,fbackName)) CriticalError (SC_CantRemoveFin, finName);
		if (rename(foutName,finName)) CriticalError (SC_CantRemoveFin, finName);

		if (curcommand==CM_Add) puts ("Book successfully added.");
		else		     	      puts ("Book successfully removed.");
	}

}
コード例 #6
0
ファイル: bookshlf.c プロジェクト: CivilPol/sdcboot
void Add ( void )
{
	char tag[MaxLine]= "<!--BOOK=";
	char stout[255] = "";
	BOOL Updates = FALSE;

	/* Set the book header */
	for (; (strlen(BookName)>0) && (BookName[strlen(BookName)-1]!='.');
		 BookName[strlen(BookName)-1]=0);
	BookName[strlen(BookName)-1]=0;

	/* Get the tag name */
	strcat (tag,BookName);
	strcat (tag,"-->");
	strupr (tag);

	/* Pass all earlier */
	while (TRUE) {
		fgets  (line, MaxLine, fin);

		if (feof(fin)) CriticalError (SC_BooksCorrupted, "");
		strcpy (stout, line);
		NoSpaces();

		if (!strcmp(line,"<!--/BOOKSHELF-->")) break;
		if (strcmp(line,tag)>=0) break;

		strcat (line,"\n");
		fputs (line, fout);
		do {
			fgets (line, MaxLine,fin);
			fputs (line, fout);
			NoSpaces();
		} while (strcmp(line,"<!--/BOOK-->"));

	}
	   /* In all exits of this loop through here, stout is pending to be put */

	/* if present, update, that is, ignore previous book */
	if (!strcmp(line,tag))  {
		Updates = TRUE;		/* flag to say that we don't have to */
						/* append the saved line */
		do {
			fgets (line, MaxLine,fin);
			NoSpaces();
		} while (strcmp(line,"<!--/BOOK-->"));
	}

	/* Insert the book */
	fprintf (fout, "%s\n", tag);

	/* Transfer contents */
	while (TRUE) {
		fgets (line, MaxLine, fbook);
		if feof(fbook) break;
		fputs (line, fout);
	}

	/* Set the book end */
	fputs ("<!--/BOOK-->\n", fout);

	if (!Updates) fputs (stout, fout);
}
コード例 #7
0
void HandleLinkLine(const char* str, const char* what)
{
/// Tokenize the input string and load/unload the libraries
/// from the list.
/// \param str  The string output from Geant4 liblist
/// \param what The option specifying whether we want to load ('l') or 
///             unload ('u') libraries

  // Fill the libs names in the vector
  std::vector<std::string> libs;
  std::stringstream sstream(str);
  unsigned int w = 0;
  while ( ! sstream.eof() ) {
    // Read one string
    std::string token;
    std::getline(sstream, token, ' ');

    // Check stream status 
    if ( sstream.bad() ) break;

    // Check that we got a meaningful tokenonent
    if ( token.empty() || std::isspace(token[0]) ) continue;
    
    if ( token[0] != '-' ) {
      Warning("LoadLibraryList", "Unknown element %s", token.c_str());
      continue;
    }
       
    std::string dir_or_file = token.substr(2,token.size()-2);
    if ( token[1] == 'L' ) { 
      std::stringstream path;
      path << gSystem->GetDynamicPath() << ":" 
	   << dir_or_file;
      gSystem->SetDynamicPath(path.str().c_str());
    }
    else if ( token[1] == 'l' ) {
      std::stringstream ln;
      ln << "lib" << NoSpaces(dir_or_file) << '.' << gSystem->GetSoExt();
      std::string lib(ln.str());
      libs.push_back(lib);
      if ( lib.length() > w ) w = lib.length();
    }
    else {
      Warning("LoadLibraryList", "Unknown option %s in", 
	      token.c_str(), str);
      continue;
     }
  }
  
  // Process the vector with libs names and load libraries
  size_t n = libs.size();
  TString sWhat(what);
  Bool_t load = sWhat.Contains("l");
  if (!load && !sWhat.Contains("u")) {
     std::cerr << "  Unknown load action " << what << std::endl;
     return;
  }

  for ( size_t i = 0; i < n; ++i ) {
    size_t idx = n - i - 1;
    
    // Uncomment to debug
    // size_t m = TMath::Log10(n)+1;
    // string say="   Loading ";
    // if ( TString(what).Contains("u") ) say = "   Unloading ";
    // std::cout << say         << std::setw(m) << (i+1) 
    //	      << "/"            << std::setw(m) << n 
    //        << ": "           << std::setw(w) << libs[idx] // << std::endl; 
    //        << std::flush;
   
    int result = 0; 
    if ( libs[idx].c_str() ) {
       if  (load) 
          result = gSystem->Load(libs[idx].c_str());
       else
          gSystem->Unload(libs[idx].c_str());
    } 
    // Uncomment to debug
    // if ( TString(what).Contains("l")  )
    //   std::cout << ( result < 0 ? " failed" : " ok" ) << "\r";
  }
  // std::cout << "\n   Done" << std::endl;
}