Example #1
0
int
operator == (const UAS_String &s1, const char *cp) {
    if (!cp) {
        return s1.length() == 0;
    }
    if (strlen (cp) != s1.length())
        return 0;
    return !memcmp (cp, (char *) s1, s1.length());
}
Example #2
0
UAS_String
UAS_String::operator + (const UAS_String &more) {
    int newLength = length() + more.length();
    char *ptr = new char[newLength + 1];
    (void) memcpy (ptr, fStringRep->fData, fStringRep->fDataSize);
    (void) memcpy (ptr + fStringRep->fDataSize,
                   more.fStringRep->fData,
                   more.fStringRep->fDataSize);
    ptr[newLength] = 0;
    //
    // The following two lines are weird but serve to
    // remove and extra malloc/copy.
    //
    UAS_String rval (ptr, newLength, UAS_NOT_OWNER);
    rval.fStringRep->fOwner = UAS_OWNER;
    return rval;
}
Example #3
0
File: EnvMgr.C Project: juddy/edcde
// parse_cmdline()
//
// Extracts info from command line and sets up internal flags.
// -1 returned on error. Innocuous problems ignored, like if no arg
// provided where we might have a default or environment variable
// specified. Caller should do "usage()" on error return, as this
// method flags rather than performs it. 
//
int
EnvMgr::parse_cmdline( int     argc_i,
                       char ** argv_i )
{
    for (int i = 1; i < argc_i; i++)
    {	
      if(strcmp(argv_i[i], "-help") == 0 ||
         strcmp(argv_i[i], "-h") == 0)
      {
	// Print a summary of the command's syntax.
        return -1;
      }
      else if (strcmp(argv_i[i], "-l") == 0 ||
               strcmp(argv_i[i], "-lib") == 0 )
      {
        // get infolibs from command line
        i++;
        if( ( i < argc_i ) && ( argv_i[i][0] != '-' ) )
        {
          // This arg gives an absolute file path to an information
          // library, or the short name of the library (which will be
          // used for substitution into the search path specified by
          // DTINFOLIBSEARCHPATH in order to locate the infolib).
          // If the -l option is not provided, the browser displays
          // the default information library by path obtained from
          // substituting DTINFOLIBDEFAULT into DTINFOLIBSEARCHPATH.
          // [DTINFOLIBDEFAULT should be a single library short name.]
          // The "-l" option may be specified more than once.

          UAS_String pathname;

          if( !strchr( argv_i[i], ':' ) )
          {
            char *tmp = infolibStringToPath(argv_i[i]);
            if( tmp )
            {
              pathname = UAS_String(tmp);
              if( tmp != argv_i[i] )  XtFree(tmp);	// clean-up case
            }
          }
          else   // defer validation if arg contains colon separators
            pathname = UAS_String(argv_i[i]);  

          if( pathname.length() != 0 )
            if( f_infolibsStr.length() != 0 )
            {
              // need to concatenate
              f_infolibsStr = f_infolibsStr + ":" + pathname ;
            }
            else
            {
              // init string
              f_infolibsStr = pathname ;
            }
          else
          {
            // invalid infolib--display error message, but not fatal
            message_mgr().error_dialog (
                  (char*)UAS_String(CATGETS(Set_AddLibraryAgent, 5,
                  "Infolib specification format error.")));
          }
        }
      //else ... ignore this one
      }
      else if (strcmp(argv_i[i], "-sect") == 0 ||
               strcmp(argv_i[i], "-section") == 0 )
      {
        // get a list of sections from the command line
        i++;
        if( ( i < argc_i ) && ( argv_i[i][0] != '-' ) )
        {
	  // This arg specifies the infolib section (or a comma-separated
          // list of sections) via their unique locator IDs to either
          // display or print. 
	  // Sections can be specified using the hyphen character to
          // represent a range of sections, although it is up the print
          // interface to resolve what such a range means. Note that a
          // section "range" is only predictable within the same version
          // of an infolib from which it was mapped.
          // If the -print option is specified, the sections are printed;
          // otherwise, they are displayed (if a range is specified without
          // "-print", only the first ID in the range will be processed).
          // If a specified location ID is not at the top of a section,
          // the section containing the location is printed.

          f_sectionsArg = UAS_String(argv_i[i]);
          // (we actually build the sections "list" later, based
          //  on document windows actually displayed)
        }
      //else ... ignore this one
      }
      else if (strcmp(argv_i[i], "-secondary") == 0)
      {
        // Run this dtinfo instance without tooltalk session participation.
	// Secondary instances do not respond to ToolTalk messages. 
        f_secondary = True;
      }
      else if (strcmp(argv_i[i], "-verbose") == 0 ||
               strcmp(argv_i[i], "-v") == 0)
      {
        // make verbose a boolean flag
        f_verbose = True;
      }
#ifdef UseSessionMgmt
      else if (strcmp(argv_i[i], "-session") == 0)
      {
        // Get special session save-state file name
        // This option will usually result only from programmatic insertion
        // for purpose of session restart.
        i++;
        if(argv_i[i][0] != '-')
        {
          session().file( argv_i[i] ) ;
        }
      //else, ignore any errors for this arg, which is usually transparent
#endif
      }
      else if (strcmp(argv_i[i], "-Debug") == 0 ||
               strcmp(argv_i[i], "-D") == 0)
      {
        // Undocumented flag:  turn on debugging
        g_debug = TRUE;
        f_debug = TRUE;
        cerr << "\nInternal debugging activated." << endl;
      }
      else
      {
        cerr << CATGETS(Set_EnvMgr, 2, "Invalid argument") << endl;
        return -1;
      }
   }

   // do any argument consistency/cross-validation here

    // make sure that if print option was specified that some sections 
    // to print were also specified.
    if ( (window_system().videoShell()->print_only) && (f_sectionsArg == (UAS_String)NULL)) {
	cerr << CATGETS(Set_EnvMgr, 3, "ERROR: The -sect option must be specified with the -print option.") << endl;
	cerr << endl;
	usage();
	exit(1);
    }
   return 0;
}
Example #4
0
int
operator == (const UAS_String &s1, const UAS_String &s2) {
    if (s1.length() != s2.length())
        return 0;
    return !memcmp ((char *) s1, (char *) s2, s1.length());
}