SET( PACKAGE "libzypp" )
SET( VERSION "${LIBZYPP_MAJOR}.${LIBZYPP_MINOR}.${LIBZYPP_PATCH}" )
-SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O3 -Wall -Woverloaded-virtual" )
-SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O3 -Wall" )
+SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -Wall -Woverloaded-virtual" )
+SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -Wall" )
ADD_DEFINITIONS( -D_FILE_OFFSET_BITS=64 )
ADD_DEFINITIONS( -DVERSION=\\\"${VERSION}\\\" )
SET( LIBZYPP_VERSION_INFO "${LIBZYPP_SO_FIRST}.${LIBZYPP_AGE}.${LIBZYPP_PATCH}" )
base/InputStream.cc
base/ReferenceCounted.cc
base/String.cc
+ base/Regex.cc
base/Unit.cc
base/ExternalDataSource.cc
base/Exception.cc
base/ReferenceCounted.h
base/SafeBool.h
base/String.h
+ base/Regex.h
base/Sysconfig.h
base/UniqueString.h
base/Unit.h
SET_TARGET_PROPERTIES( zypp PROPERTIES VERSION "${LIBZYPP_VERSION_INFO}" )
ADD_DEPENDENCIES(zypp schema_header)
# System libraries
-TARGET_LINK_LIBRARIES(zypp boost_filesystem boost_regex util )
+TARGET_LINK_LIBRARIES(zypp boost_filesystem util )
TARGET_LINK_LIBRARIES(zypp ${DBUS_LIBRARY} )
TARGET_LINK_LIBRARIES(zypp dbus-glib-1 )
TARGET_LINK_LIBRARIES(zypp ${GLIB_LIBRARY} )
#ifndef ZYPP_DEP_H
#define ZYPP_DEP_H
-#include <iosfwd>
+#include <iostream>
#include <string>
///////////////////////////////////////////////////////////////////
#include "zypp/base/Logger.h"
#include "base/String.h"
+#include "base/Regex.h"
#include "base/Exception.h"
#include "zypp/Edition.h"
Impl( const std::string & edition_r )
: _epoch( noepoch )
{
+ //[0-9]+:)?([^-]*)(-([^-]*))?" );
str::smatch what;
- if( str::regex_match( edition_r.begin(), edition_r.end(),
- what, _rxEdition ) )
+
+ std::cout << "edition: " << edition_r << std::endl;
+
+ std::cout << str::regex_match( edition_r, what, _rxEdition ) << std::endl;
+
+ std::cout << "size: " << what.size() << std::endl;
+
+ for (int i = 1; i < what.size(); ++i)
+ std::cout << i << ": " << what[i] << std::endl;
+
+
+ if( str::regex_match( edition_r, what, _rxEdition ) && what.size() >= 3)
{
- // what[2] contains the epoch
- // what[3] contains the version
- // what[5] contains the release
- if ( what[2].matched )
- _epoch = strtoul( what[2].str().c_str(), NULL, 10 );
- if ( what[3].matched )
- _version = what[3].str();
- if ( what[5].matched )
- _release = what[5].str();
+ if ( what[1].size() > 1 )
+ _epoch = strtoul( what[1].c_str(), NULL, 10 );
+ if ( what[2].size() )
+ _version = what[2];
+ if ( what[3].size() )
+ _release = what[3];
}
else
{
};
///////////////////////////////////////////////////////////////////
- const str::regex Edition::Impl::_rxEdition( "(([0-9]+):)?([^-]*)(-([^-]*))?" );
+ const str::regex Edition::Impl::_rxEdition( "([0-9]+:)?([^-]*)(-[^-]*)?" );
///////////////////////////////////////////////////////////////////
#define KVMap_h
#include <iosfwd>
+#include <vector>
#include <map>
#include "zypp/base/String.h"
#include "zypp/base/Logger.h"
#include "zypp/base/IOStream.h"
#include "zypp/base/String.h"
+#include "zypp/base/Regex.h"
#include "zypp/PathInfo.h"
#include "zypp/KeyRing.h"
#include "zypp/ExternalProgram.h"
{
//MIL << line << endl;
str::smatch what;
- if(str::regex_match(line, what, rxColons, str::match_extra))
+ if(str::regex_match(line, what, rxColons))
{
string id;
string fingerprint;
for(line2 = prog.receiveLine(); !line2.empty(); line2 = prog.receiveLine(), count++ )
{
str::smatch what2;
- if (str::regex_match(line2, what2, rxColonsFpr, str::match_extra))
+ if (str::regex_match(line2, what2, rxColonsFpr))
{
if ( (what2[1] == "fpr") && (what2[1] != "pub") && (what2[1] !="sub"))
{
{
//MIL << "[" << line << "]" << endl;
str::smatch what;
- if(str::regex_match(line, what, rxNoKey, str::match_extra))
+ if(str::regex_search(line, what, rxNoKey))
{
if ( what.size() > 1 )
id = what[1];
#include <fstream>
#include "zypp/base/LogTools.h"
+#include "zypp/base/Regex.h"
#include "zypp/base/UserRequestException.h"
#include "zypp/ZYppCallbacks.h"
#include "zypp/MediaSetAccess.h"
// code has to be adapted together with the MediaISO change.
// maybe some MediaISOURL interface should be used.
std::string isofile = url_r.getQueryParam("iso");
- boost::regex e("^(.*(cd|dvd))([0-9]+)(\\.iso)$", boost::regex::icase);
- boost::smatch what;
- if(boost::regex_match(isofile, what, e, boost::match_extra))
+ str::regex e("^(.*(cd|dvd))([0-9]+)(\\.iso)$", str::regex::icase);
+
+ str::smatch what;
+ if(str::regex_match(isofile, what, e))
{
Url url( url_r);
isofile = what[1] + str::numstring(medianr) + what[4];
else
{
std::string pathname = url_r.getPathName();
- boost::regex e("^(.*(cd|dvd))([0-9]+)(/?)$", boost::regex::icase);
- boost::smatch what;
- if(boost::regex_match(pathname, what, e, boost::match_extra))
+ str::regex e("^(.*(cd|dvd))([0-9]+)(/?)$", str::regex::icase);
+ str::smatch what;
+ if(str::regex_match(pathname, what, e))
{
Url url( url_r);
pathname = what[1] + str::numstring(medianr) + what[4];
#ifndef ZYPP_PATHNAME_H
#define ZYPP_PATHNAME_H
-#include <iosfwd>
+#include <iostream>
#include <string>
///////////////////////////////////////////////////////////////////
//#include "zypp/base/Logger.h"
#include "zypp/base/String.h"
+#include "zypp/base/Regex.h"
#include "zypp/PublicKey.h"
#include "zypp/ExternalProgram.h"
#include "zypp/TmpPath.h"
{
//MIL << "[" << line << "]" << std::endl;
str::smatch what;
- if(str::regex_match(line, what, rxColons, str::match_extra))
+ if(str::regex_match(line, what, rxColons))
{
if ( what[1] == "pub" )
{
#include <zypp/Url.h>
#include <zypp/base/Gettext.h>
#include <zypp/base/String.h>
+#include <zypp/base/Regex.h>
#include <stdexcept>
+#include <iostream>
//////////////////////////////////////////////////////////////////////
/*
* url = [scheme:] [//authority] /path [?query] [#fragment]
*/
- #define RX_SPLIT_URL "^(([^:/?#]+):)?" \
- "(//([^/?#]*))?" \
+ #define RX_SPLIT_URL "^([^:/?#]+:|)" \
+ "(//[^/?#]*|)" \
"([^?#]*)" \
- "([?]([^#]*))?" \
- "(#(.*))?"
+ "([?][^#]*|)" \
+ "(#.*|)"
////////////////////////////////////////////////////////////////////
catch( ... )
{}
- if(ret && out.size() == 10)
+ if(ret && out.size() == 5)
{
- url = g_urlSchemeRepository().getUrlByScheme(out[2].str());
+ std::string scheme = out[1];
+ if (scheme.size() > 1)
+ scheme = scheme.substr(0, scheme.size()-1);
+ std::string authority = out[2];
+ if (authority.size() >= 2)
+ authority = authority.substr(2);
+ std::string query = out[4];
+ if (query.size() > 1)
+ query = query.substr(1);
+ std::string fragment = out[5];
+ if (fragment.size() > 1)
+ fragment = fragment.substr(1);
+
+ std::cout << "scheme: " << scheme << " authority: " << authority
+ << " query " << query << " fragment " << fragment << std::endl;
+
+ std::cout << "out[3] " << out[3] << std::endl;
+
+ url = g_urlSchemeRepository().getUrlByScheme(scheme);
if( !url)
{
url.reset( new UrlBase());
}
- url->init(out[2].str(),
- out[4].str(),
- out[5].str(),
- out[7].str(),
- out[9].str());
+ url->init(scheme, authority, out[3],
+ query, fragment);
}
return url;
}
return matches;
}
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/base/Regex.cc
+ *
+*/
+#include <cstdio>
+#include <cstdarg>
+
+#include <iostream>
+
+#include "zypp/base/Regex.h"
+
+using namespace zypp::str;
+
+regex::regex(const std::string& str, int flags)
+{
+ m_valid = true;
+ if (regcomp(&m_preg, str.c_str(), REG_EXTENDED))
+ m_valid = false;
+}
+
+regex::~regex() throw()
+{
+ if (m_valid)
+ regfree(&m_preg);
+}
+
+bool zypp::str::regex_match(const std::string& s, smatch& matches, const regex& regex)
+{
+ bool r = regex.m_valid && !regexec(®ex.m_preg, s.c_str(), 12, &matches.pmatch[0], 0);
+ if (r)
+ matches.match_str = s;
+ return r;
+}
+
+bool zypp::str::regex_match(const std::string& s, const regex& regex)
+{
+ return !regexec(®ex.m_preg, s.c_str(), 0, NULL, 0);
+}
+
+bool zypp::str::regex_search(const std::string& s, smatch& matches, const regex& regex)
+{
+ bool r= regex.m_valid && !regexec(®ex.m_preg, s.c_str(), 12, &matches.pmatch[0], 0);
+ if (r)
+ matches.match_str = s;
+ return r;
+}
+
+smatch::smatch()
+{
+ memset(&pmatch, -1, sizeof(pmatch));
+}
+
+std::string smatch::operator[](unsigned i) const
+{
+ if (i < 12 && pmatch[i].rm_so != -1)
+ return match_str.substr(pmatch[i].rm_so, pmatch[i].rm_eo-pmatch[i].rm_so);
+ return std::string();
+}
+
+
+unsigned smatch::size() const
+{
+ unsigned matches = 0;
+ while (matches < 12 && pmatch[matches+1].rm_so != -1) {
+ // std::cout << "match[" << matches << "]: *" << (*this)[matches
+ // +1] << "*" << std::endl;
+ matches++;
+ }
+
+ return matches;
+}
} // namespace zypp
///////////////////////////////////////////////////////////////////
#endif // ZYPP_BASE_STRING_H
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/base/Regex.h
+ *
+*/
+#ifndef ZYPP_BASE_REGEX_H
+#define ZYPP_BASE_REGEX_H
+
+#include <iosfwd>
+#include <string>
+
+#include <regex.h>
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ /** String related utilities and \ref ZYPP_STR_REGEX.
+ \see \ref ZYPP_STR_REGEX
+ */
+ namespace str
+ { /////////////////////////////////////////////////////////////////
+
+ class regex {
+ public:
+
+ enum RegFlags {
+ optimize = 0,
+ match_extra = 0,
+ icase = REG_ICASE,
+ nosubs = REG_NOSUB,
+ match_extended = REG_EXTENDED
+ };
+
+ regex(const std::string& s,int flags = match_extended);
+ ~regex() throw();
+
+
+ public:
+ regex_t m_preg;
+ bool m_valid;
+ };
+
+
+ class smatch {
+ public:
+ smatch();
+
+ std::string operator[](unsigned i) const;
+
+ unsigned size() const;
+
+ std::string match_str;
+ regmatch_t pmatch[12];
+ };
+
+ bool regex_match(const std::string& s, str::smatch& matches, const regex& regex);
+ bool regex_match(const std::string& s, const regex& regex);
+ bool regex_search(const std::string& s, str::smatch& matches, const regex& regex);
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace str
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_BASE_STRING_H
return _getline(str, trim?TRIM:NO_TRIM);
}
- std::ostream & dumpRegexpResult( const boost::smatch &what, std::ostream & str )
- {
- for ( unsigned int k=0; k < what.size(); k++)
- {
- str << "[match "<< k << "] [" << what[k] << "]" << std::endl;
- }
-
- return str;
- }
/////////////////////////////////////////////////////////////////
} // namespace str
///////////////////////////////////////////////////////////////////
#include <iosfwd>
#include <string>
-#include <boost/regex.hpp>
#include "zypp/base/PtrTypes.h"
//@{
/** regex */
+#if 0
using boost::regex;
using boost::regex_match;
using boost::regex_search;
* helper to debug regular expressions matches
*/
std::ostream & dumpRegexpResult( const boost::smatch &what, std::ostream & str );
+#endif
///////////////////////////////////////////////////////////////////
/** \name String representation of number.
// build string
*result_r = std::string( beg, cur-beg );
// skip sepchars
- while ( sepchars_r.find( *cur ) != std::string::npos )
+ while ( cur != beg && sepchars_r.find( *cur ) != std::string::npos )
++cur;
}
return ret;
std::string getline( std::istream & str, const Trim trim_r );
+ inline bool startsWith(const std::string& s, const char* str) { return s.find(str) == 0; }
+ inline bool contains(const std::string& s, const char* str) { return s.find(str) != std::string::npos; }
+
///////////////////////////////////////////////////////////////////
/** \name String prefix handling.
inline std::string stripPrefix( const std::string & str_r, const std::string & prefix_r )
{ return( hasPrefix( str_r, prefix_r ) ? str_r.substr( prefix_r.size() ) : str_r ); }
//@}
-
/////////////////////////////////////////////////////////////////
} // namespace str
///////////////////////////////////////////////////////////////////
*
*/
#include <iostream>
+#include <vector>
#include "zypp/base/Logger.h"
#include "zypp/base/Exception.h"
}
//split: name:/absolute/path
- static const str::regex rx( "([^/]*):(/.*)" );
- str::smatch what;
- if( str::regex_match( name_r.begin(), name_r.end(), what, rx ) )
+ std::vector<std::string> what;
+ if (str::split( name_r, std::back_inserter(what), ":") >= 2)
{
- return new capability::SplitCap( refers_r, what[1].str(), what[2].str() );
+ return new capability::SplitCap( refers_r, what[0], what[1] );
}
//name: name
}
//split: hal(name) [op string]
- static const str::regex rx( "hal\\(([^)]*)\\)" );
- str::smatch what;
- if( str::regex_match( name_r.begin(), name_r.end(), what, rx ) )
+ std::vector<std::string> what;
+ if (str::split( name_r, std::back_inserter(what), ")"))
{
// Hal always refers to 'System' kind of Resolvable.
return new capability::HalCap( ResTraits<SystemResObject>::kind,
- what[1].str() );
+ what[0].substr(strlen("hal(")) );
}
// otherwise
ZYPP_THROW( Exception("Unsupported kind of Hal Capability '" + name_r + "'") );
}
//split: modalias(name) [op string]
- static const str::regex rx( "modalias\\(([^)]*)\\)" );
- str::smatch what;
- if( str::regex_match( name_r.begin(), name_r.end(), what, rx ) )
+ std::vector<std::string> what;
+ if (str::split( name_r, std::back_inserter(what), ")"))
{
// Modalias always refers to 'System' kind of Resolvable
return new capability::ModaliasCap( ResTraits<SystemResObject>::kind,
- what[1].str() );
+ what[0].substr(strlen("modalias(")));
}
// otherwise
ZYPP_THROW( Exception("Unsupported kind of Modalias Capability'" + name_r + "'") );
const std::string & name_r )
{
//split: filesystem(name) [op string]
- static const str::regex rx( "filesystem\\(([^)]*)\\)" );
- str::smatch what;
- if( str::regex_match( name_r.begin(), name_r.end(), what, rx ) )
+ std::vector<std::string> what;
+ if (str::split( name_r, std::back_inserter(what), ")"))
{
// Filesystem always refers to 'System' kind of Resolvable
return new capability::FilesystemCap( ResTraits<SystemResObject>::kind,
- what[1].str() );
+ what[0].substr(strlen("filesystem(")) );
}
// otherwise
ZYPP_THROW( Exception("Unsupported kind of Filesystem Capability'" + name_r + "'") );
}
// strval_r has at least two words which could make 'op edition'?
- // improve regex!
- static const str::regex rx( "(.*[^ \t])([ \t]+)([^ \t]+)([ \t]+)([^ \t]+)" );
- str::smatch what;
- if( str::regex_match( strval_r.begin(), strval_r.end(),what, rx ) )
+ std::vector<std::string> what;
+ if (str::split( strval_r, std::back_inserter(what)) >= 2)
{
Rel op;
Edition edition;
try
{
- op = Rel(what[3].str());
- edition = Edition(what[5].str());
+ op = Rel(what[1]);
+ edition = Edition(what[2]);
}
catch ( Exception & excpt )
{
// Valid 'op edition'
return buildVersioned( refers_r,
- what[1].str(), op, edition );
+ what[0], op, edition );
}
//else
// not a VersionedCap
list<string> filenames = header->tag_filenames();
pkg->deps[Dep::PROVIDES] = header->tag_provides ( filerequires );
- static str::smatch what;
- static const str::regex filenameRegex( "/(s?bin|lib(64)?|etc)/|^/usr/(games/|share/(dict/words|magic\\.mime)$)|^/opt/gnome/games/",
- str::regex::optimize|str::regex::nosubs );
-
for (list<string>::const_iterator filename = filenames.begin();
filename != filenames.end();
++filename)
{
- if ( str::regex_search( filename->begin(), filename->end(), what, filenameRegex ) )
+ if (str::contains(*filename, "/bin/")
+ || str::contains(*filename, "/sbin")
+ || str::contains(*filename, "/lib") || str::contains(*filename, "/lib64/")
+ || str::contains(*filename, "/etc/")
+ || str::startsWith(*filename, "/usr/games")
+ || str::startsWith(*filename, "/usr/share/dict/words")
+ || str::startsWith(*filename, "/opt/gnome/games/"))
{
try {
pkg->deps[Dep::PROVIDES].insert(capability::buildFile( ResTraits<Package>::kind, *filename ));
{ /////////////////////////////////////////////////////////////////
const Pathname applydeltarpm_prog( "/usr/bin/applydeltarpm" );
- const str::regex applydeltarpm_tick ( "([0-9]+) percent finished" );
/******************************************************************
**
const Progress & report_r = Progress() )
{
ExternalProgram prog( argv_r, ExternalProgram::Stderr_To_Stdout );
- str::smatch what;
for ( std::string line = prog.receiveLine(); ! line.empty(); line = prog.receiveLine() )
{
- if ( report_r && str::regex_search( line, what, applydeltarpm_tick ) )
- {
- report_r( str::strtonum<unsigned>( what[1] ) );
- }
+ if ( report_r )
+ report_r( str::strtonum<unsigned>( line ));
else
DBG << "Applydeltarpm : " << line;
- }
+ }
return( prog.close() == 0 );
}
#include "zypp/base/Logger.h"
#include "zypp/base/String.h"
+#include "zypp/base/Regex.h"
#include "zypp/Date.h"
#include "zypp/Pathname.h"
filename != filenames.end();
++filename)
{
- if ( str::regex_search( filename->begin(), filename->end(), what, filenameRegex ) )
+ if ( str::regex_match( *filename, what, filenameRegex ) )
{
try
{
#include <zypp/url/UrlBase.h>
#include <zypp/base/String.h>
#include <zypp/base/Gettext.h>
-
+#include <zypp/base/Regex.h>
+
#include <stdexcept>
#include <climits>
#include <errno.h>
#include <sys/socket.h>
#include <arpa/inet.h>
+#include <iostream>
// ---------------------------------------------------------------
/*
**
** host = hostname | IPv4 | "[" IPv6-IP "]" | "[v...]"
*/
-#define RX_SPLIT_AUTHORITY \
- "^(([^:@]*)([:]([^@]*))?@)?(\\[[^]]+\\]|[^:]+)?([:](.*))?"
-
#define RX_VALID_SCHEME "^[a-zA-Z][a-zA-Z0-9\\.+-]*$"
-#define RX_VALID_PORT "^[0-9]{1,5}$"
-
#define RX_VALID_HOSTNAME "^[[:alnum:]]+([\\.-][[:alnum:]]+)*$"
#define RX_VALID_HOSTIPV4 \
try
{
str::regex rex(regx);
+ std::cout << "testing *" << data << "* against *" << regx << "*" << std::endl;
valid = str::regex_match(data, rex);
}
catch( ... )
std::string url;
UrlBaseData tmp;
+ std::cout << "UrlBase:.asString()" << std::endl;
+
if( opts.has(ViewOptions::WITH_SCHEME))
{
tmp.scheme = getScheme();
}
}
+ std::cout << "tmp.host: *" << tmp.host << "*" << std::endl;
+
url += tmp.host;
if( opts.has(ViewOptions::WITH_PORT))
if( opts.has(ViewOptions::WITH_PATH_NAME))
{
tmp.pathname = getPathName(zypp::url::E_ENCODED);
+ std::cout << "pathname: *" << tmp.pathname << "*" << std::endl;
if( !tmp.pathname.empty())
{
if(url.find("/") != std::string::npos)
void
UrlBase::setAuthority(const std::string &authority)
{
- str::smatch out;
- bool ret = false;
+ std::string s = authority;
+ std::string::size_type p,q;
- try
- {
- str::regex rex(RX_SPLIT_AUTHORITY);
- ret = str::regex_match(authority, out, rex);
- }
- catch( ... )
- {}
+ std::string username, password, host, port;
- if( ret && out.size() == 8)
+ std::cout << "authority: " << authority << "*" << std::endl;
+
+ if ((p=s.find('@')) != std::string::npos)
{
- setUsername(out[2].str(), zypp::url::E_ENCODED);
- setPassword(out[4].str(), zypp::url::E_ENCODED);
- setHost(out[5].str());
- setPort(out[7].str());
+ q = s.find(':');
+ if (q != std::string::npos && q < p)
+ {
+ setUsername(s.substr(0, q), zypp::url::E_ENCODED);
+ setPassword(s.substr(q+1, p-q-1), zypp::url::E_ENCODED);
+ }
+ else
+ setUsername(s.substr(0, p), zypp::url::E_ENCODED);
+ s = s.substr(p+1);
}
- else
+ q = s.rfind(']');
+ if ((p = s.rfind(':')) != std::string::npos && p > q+1)
{
- ZYPP_THROW(UrlParsingException(
- _("Unable to parse Url authority")
- ));
+
+ setHost(s.substr(0, p));
+ setPort(s.substr(p+1));
}
+ else
+ setHost(s);
}
// ---------------------------------------------------------------
));
}
+ std::cout << "host: *" << host << "*" << std::endl;
+
if( isValidHost(host))
{
std::string temp;
bool
UrlBase::isValidPort(const std::string &port) const
{
- try
- {
- str::regex regx(RX_VALID_PORT);
- if( str::regex_match(port, regx))
- {
- long pnum = str::strtonum<long>(port);
- return ( pnum >= 1 && pnum <= USHRT_MAX);
- }
- }
- catch( ... )
- {}
+ char* endptr;
+ long pnum = strtol(port.c_str(), &endptr, 10);
+ return ( !port.empty() && !*endptr
+ && pnum >= 1 && pnum <= USHRT_MAX);
return false;
}