Example #1
0
/*
 *  convert address into a reverse lookup address
 */
static void
mkptrname(char *ip, char *rip, int rlen)
{
	char buf[128];
	char *p, *np;
	int len;

	if(strstr(ip, "in-addr.arpa") || strstr(ip, "IN-ADDR.ARPA")){
		nstrcpy(rip, ip, rlen);
		return;
	}

	nstrcpy(buf, ip, sizeof buf);
	for(p = buf; *p; p++)
		;
	*p = '.';
	np = rip;
	len = 0;
	while(p >= buf){
		len++;
		p--;
		if(*p == '.'){
			memmove(np, p+1, len);
			np += len;
			len = 0;
		}
	}
	memmove(np, p+1, len);
	np += len;
	strcpy(np, "in-addr.arpa");
}
Example #2
0
/*
 * Optionally translate an old format uucp name into a new one, e.g.
 * "mach1!mach2!user" becomes "*****@*****.**".  This optional because
 * some information is necessarily lost (e.g. the route it got here
 * via) and if we don't have the host in our routing tables, we lose.
 * XXX THIS IS NO LONGER VALID WITH THE NEW UUCP PROJECT PLANS TO
 * REGISTER UUCP HOSTS IN THE STANDARD INTERNET NAMESPACE, E.G.
 * ihnp4 BECOMES "ihnp4.att.com".
 */
char *
unuucp(char *name)
{
	register char *np, *hp, *cp;
	char result[100];
	char tname[300];

	if (UnUUCP==0 &&
	    ((cp = value("conv"))==NOSTR || strcmp(cp, "internet")))
		return name;
	if (debug) fprintf(stderr, "unuucp(%s)\n", name);
	nstrcpy(tname, sizeof (tname), name);
	np = strrchr(tname, '!');
	if (np == NOSTR)
		return name;
	*np++ = 0;
	hp = strrchr(tname, '!');
	if (hp == NOSTR)
		hp = tname;
	else
		*hp++ = 0;
	cp = strchr(np, '@');
	if (cp == NOSTR)
		cp = strchr(np, '%');
	if (cp)
		*cp = 0;
	if (debug) fprintf(stderr, "host %s, name %s\n", hp, np);
	snprintf(result, sizeof (result), "%s@%s.UUCP", np, hp);
	if (debug) fprintf(stderr, "unuucp returns %s\n", result);
	return savestr(result);
}
Example #3
0
int 
yyinit(char str[])
{
	static char lexbuf[BUFSIZ];

	netbuf[0] = 0;
	if (strlen(str) >= sizeof lexbuf - 1)
		return(-1);
	nexttok = 0;
	nstrcpy(lexbuf, sizeof (lexbuf), str);
	charp = lexbuf;
	return(0);
}
Example #4
0
//	////////////////////////////////////////////////////////////////////////////
char *TimeVal::FormatStringInterval(char *buffer, unsigned int max_length) const
{
	if (max_length < LengthInterval_TimeVal) {
		char tmp_buffer[LengthInterval_TimeVal + 1];
		return(nstrcpy(buffer, FormatStringInterval(tmp_buffer), max_length));
	}

	//	This gets dddddd hh:mm:ss
	TimeT tmp_time_t(tv_sec);
	tmp_time_t.ToStringInterval(buffer);

	return(AppendFractionalPortion(LengthInterval_TimeT, buffer));
}
Example #5
0
//	////////////////////////////////////////////////////////////////////////////
char *TimeVal::FormatString(const TimeTM &in_tm, char *buffer,
	unsigned int max_length) const
{
	if (max_length < Length_TimeVal) {
		char tmp_buffer[Length_TimeVal + 1];
		return(nstrcpy(buffer, FormatString(in_tm, tmp_buffer),
			max_length));
	}

	//	This gets YYYY-MM-DD hh:mm:ss
	in_tm.ToString(buffer);

	return(AppendFractionalPortion(Length_TimeT, buffer));
}
void register_name(struct subnet_record *subrec,
                   const char *name, int type, uint16 nb_flags,
                   register_name_success_function success_fn,
                   register_name_fail_function fail_fn,
                   struct userdata_struct *userdata)
{
	struct nmb_name nmbname;
	nstring nname;

        if (strlen(name)+1 > sizeof(nstring)) {
		memcpy(nname, name,sizeof(nstring)-1);
		nname[sizeof(nstring)-1] = '\0';
		DEBUG(0,("register_name: NetBIOS name %s is too long. Truncating to %s\n",
			name, nname));
	} else {
		nstrcpy(nname,name);
	}

	make_nmb_name(&nmbname, nname, type);

	/* Always set the NB_ACTIVE flag on the name we are
	   registering. Doesn't make sense without it.
	*/
	
	nb_flags |= NB_ACTIVE;
	
	if (subrec == unicast_subnet) {
		/* we now always do multi-homed registration if we are
		   registering to a WINS server. This copes much
		   better with complex WINS setups */
		multihomed_register_name(&nmbname, nb_flags,
					 success_fn, fail_fn);
		return;
	}
	
	if (queue_register_name(subrec,
				register_name_response,
				register_name_timeout_response,
				success_fn,
				fail_fn,
				userdata,
				&nmbname,
				nb_flags) == NULL) {
		DEBUG(0,("register_name: Failed to send packet trying to register name %s\n",
			 nmb_namestr(&nmbname)));
	}
}
Example #7
0
static void 
optim1(char netstr[], char name[])
{
	char path[STSIZ], rpath[STSIZ];
	register char *cp, *cp2;
	register int tp, nc;
	
	cp = netstr;
	prefer(cp);
	*name  = '\0';
	/*
	 * If the address ultimately points back to us,
	 * just return a null network path.
	 */
	if ((int)strlen(cp) > 1 && cp[strlen(cp) - 2] == LOCAL)
		return;
	while (*cp != 0) {
		*path = '\0';

		tp = ntype(cp[1]);
		nc = cp[1];
		while (*cp && tp == ntype(cp[1])) {
			stradd(path, sizeof (path), *cp++);
			cp++;
		}
		switch (netkind(tp)) {
		default:
			nstrcpy(rpath, sizeof (rpath), path);
			break;

		case IMPLICIT:
			optimimp(path, rpath);
			break;

		case EXPLICIT:
			optimex(path, rpath);
			break;
		}
		for (cp2 = rpath; *cp2 != 0; cp2++) {
			stradd(name, BUFSIZ, *cp2);
			stradd(name, BUFSIZ, nc);
		}
	}
	optiboth(name);
	prefer(name);
}
Example #8
0
/*
 * Deal with arpa net addresses.  The way this is done is strange.
 * name contains an "@" or "%".  Look up the machine after it in
 * the hash table.  If it isn't found, return name unmolested.
 * If ???, return name unmolested.
 * Otherwise, delete the "@" or "%" and the machine after it from
 * name, and return the new string.
 */
static char *
arpafix(char name[], char from[])
{
	register char *cp;
	register int arpamach;
	char newname[BUFSIZ];

	if (debug) {
		fprintf(stderr, "arpafix(%s, %s)\n", name, from);
	}
	cp = strrchr(name, '@');
	if (cp == NOSTR)
		cp = strrchr(name, '%');
	if (cp == NOSTR) {
		fprintf(stderr,
		    gettext("Something's amiss -- no @ or %% in arpafix\n"));
		return(name);
	}
	cp++;
	arpamach = netlook(cp, '@');
	if (debug)
		fprintf(stderr,
		    "cp '%s', arpamach %o, nettypes arpamach %o LOCAL %o\n",
		    cp, arpamach, nettype(arpamach), nettype(LOCAL));
	if (arpamach == 0) {
		if (debug)
			fprintf(stderr, "machine %s unknown, uses: %s\n",
			    cp, name);
		return(name);
	}
	if (((nettype(arpamach) & nettype(LOCAL)) & ~AN) == 0) {
		if (debug)
			fprintf(stderr, "machine %s known but remote, uses: %s\n",
			    cp, name);
		return(name);
	}
	nstrcpy(newname, sizeof (newname), name);
	cp = strrchr(newname, '@');
	if (cp == NOSTR)
		cp = strrchr(newname, '%');
	*cp = 0;
	if (debug) fprintf(stderr, "local address, return '%s'\n", newname);
	return(savestr(newname));
}
int CreateNewWiFiWindow(HWND hWnd, char* selssid)
{
	MSG msg;
	MAINWINCREATE CreateInfo;

	LoadWindowStr();
	memset(my_ssid, 0, sizeof(my_ssid));
	nstrcpy(my_ssid, selssid, strlen(selssid));

	hWnd = GetMainWindowHandle(hWnd);
	CreateInfo.dwStyle = WS_VISIBLE|WS_BORDER|WS_CAPTION;
	CreateInfo.dwExStyle = WS_EX_NONE;
	CreateInfo.spCaption = LoadStrByID(MID_WIFI_SETTING);
	CreateInfo.hMenu = 0;
	CreateInfo.hIcon = 0;
	CreateInfo.MainWindowProc = NewWiFiWinProc;
	CreateInfo.lx = 0;
	CreateInfo.ty = 0;
	CreateInfo.rx = g_rcScr.right;
	CreateInfo.by = g_rcScr.bottom;
	CreateInfo.iBkColor = 0x00FFA2BE;
	CreateInfo.dwAddData = 0;
	CreateInfo.hHosting = hWnd;

	if (LoadBitmap(HDC_SCREEN,&wifibkg,GetBmpPath("submenubg.jpg"))) {
		return 0;
	}
	WififHwnd = CreateMainWindow(&CreateInfo);
	if (WififHwnd == HWND_INVALID) {
		return -1;
	}
	ShowWindow(WififHwnd, SW_SHOWNORMAL);

	while (GetMessage(&msg,WififHwnd))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	MainWindowThreadCleanup(WififHwnd);
	return 0;
}
Example #10
0
//2006.08.03 ssr
//add '0' to pre str
char *Pad0Str(char *buf, int size,char *value)
{
	//printf("value: %s\n",value);
	int l=0;
	l = strlen(value);
	if (l == size)
	{
		nstrcpy(buf,value,size);
		return value;
	}
	if (gOptions.PinPreAdd0)
		memset(buf,'0',size);
	else
		memset(buf,' ',size);
	//printf("buf: %s\n",buf);
	memcpy(buf+(size-l),value,l);	
	//printf("buf2: %s\n",buf);

	return buf;
}
Example #11
0
/*
 * Determine the current folder directory name.
 */
int
getfold(char *name)
{
	char *folder;

	if ((folder = value("folder")) == NOSTR || *folder == '\0')
		return (-1);
	/*
	 * If name looks like a folder name, don't try
	 * to expand it, to prevent infinite recursion.
	 */
	if (*folder != '+' && (folder = expand(folder)) == NOSTR ||
	    *folder == '\0')
		return (-1);
	if (*folder == '/') {
		nstrcpy(name, BUFSIZ, folder);
	} else
		snprintf(name, BUFSIZ, "%s/%s", homedir, folder);
	return (0);
}
Example #12
0
int
exec(char *path, char *argv[])
{
    int i;
    char buf[400], *p;
    struct msg m;


    for (p = buf, i = 0; argv[i]; i++)
        p += nstrcpy(p, argv[i]) + 1;

    *p = 0;
    m.p1 = path;
    m.p2 = buf;
    m.i1 = p - buf + 1; // copy cnt
    m.type = MSG_EXEC;

    sys_msg(BOTH, &m, TASK_MM);

    return 0;
}
Example #13
0
static int 
optimex(char net[], char name[])
{
	register char *cp, *rp;
	register int m;

	nstrcpy(name, STSIZ, net);
	cp = name;
	if (strlen(cp) == 0)
		return(-1);
	if (cp[strlen(cp)-1] == LOCAL) {
		name[0] = 0;
		return(0);
	}
	for (cp = name; *cp; cp++) {
		m = *cp;
		rp = strrchr(cp+1, m);
		if (rp != NOSTR)
			strcpy(cp, rp);
	}
	return(0);
}
Example #14
0
//	////////////////////////////////////////////////////////////////////////////
char *TimeTM::ToString(char *buffer, unsigned int max_length) const
{
	if (max_length < Length_TimeTM) {
		char tmp_buffer[Length_TimeTM + 1];
		return(nstrcpy(buffer, ToString(tmp_buffer), max_length));
	}

	tm tm_data = *this;

	tm_data.tm_year  = (tm_data.tm_year + 1900) % 10000;
	tm_data.tm_mon   = (tm_data.tm_mon + 1) % 100;
	tm_data.tm_mday %= 100;
	tm_data.tm_hour %= 100;
	tm_data.tm_min  %= 100;
	tm_data.tm_sec  %= 100;

	buffer[0]        = ((char) ('0' + (tm_data.tm_year / 1000)));
	buffer[1]        = ((char) ('0' + ((tm_data.tm_year % 1000) / 100)));
	buffer[2]        = ((char) ('0' + ((tm_data.tm_year % 100) / 10)));
	buffer[3]        = ((char) ('0' + (tm_data.tm_year % 10)));
	buffer[4]        = '-';
	buffer[5]        = ((char) ('0' + (tm_data.tm_mon / 10)));
	buffer[6]        = ((char) ('0' + (tm_data.tm_mon % 10)));
	buffer[7]        = '-';
	buffer[8]        = ((char) ('0' + (tm_data.tm_mday / 10)));
	buffer[9]        = ((char) ('0' + (tm_data.tm_mday % 10)));
	buffer[10]       = ' ';
	buffer[11]       = ((char) ('0' + (tm_data.tm_hour / 10)));
	buffer[12]       = ((char) ('0' + (tm_data.tm_hour % 10)));
	buffer[13]       = ':';
	buffer[14]       = ((char) ('0' + (tm_data.tm_min / 10)));
	buffer[15]       = ((char) ('0' + (tm_data.tm_min % 10)));
	buffer[16]       = ':';
	buffer[17]       = ((char) ('0' + (tm_data.tm_sec / 10)));
	buffer[18]       = ((char) ('0' + (tm_data.tm_sec % 10)));
	buffer[19]       = '\0';

	return(buffer);
}
Example #15
0
File: target7.c Project: di/school
void bar(char *arg)
{
    char buf[200];

    nstrcpy(buf, sizeof buf, arg);
}
Example #16
0
static void
optim(char net[], char name[])
{
	char netcomp[BUFSIZ], netstr[STSIZ], xfstr[STSIZ];
	register char *cp, *cp2;
	register int c;

	if (debug) fprintf(stderr, "optim(%s, %s) called\n", net, name);
	*netstr = '\0';
	cp = net;
	for (;;) {
		/*
		 * Rip off next path component into netcomp
		 */
		cp2 = netcomp;
		while (*cp && !any(*cp, metanet))
			*cp2++ = *cp++;
		*cp2 = 0;
		/*
		 * If we hit null byte, then we just scanned
		 * the destination user name.  Go off and optimize
		 * if its so.
		 */
		if (*cp == 0)
			break;
		if ((c = netlook(netcomp, *cp)) == 0) {
			printf(gettext("No host named \"%s\"\n"), netcomp);
err:
			nstrcpy(name, BUFSIZ, net);
			return;
		}
		stradd(name, BUFSIZ, c);
		stradd(name, BUFSIZ, *cp++);
		/*
		 * If multiple network separators given,
		 * throw away the extras.
		 */
		while (any(*cp, metanet))
			cp++;
	}
	if (strlen(netcomp) == 0) {
		printf(gettext("net name syntax\n"));
		goto err;
	}
	if (debug) fprintf(stderr, "optim1(%s,%s) called\n", netstr, xfstr);
	optim1(netstr, xfstr);
	if (debug) fprintf(stderr, "optim1(%s,%s) returns\n", netstr, xfstr);

	/*
	 * Convert back to machine names.
	 */

	cp = xfstr;
	*name = '\0';
	while (*cp) {
		if ((cp2 = netname(*cp++)) == NOSTR) {
			printf(gettext("Made up bad net name\n"));
			printf(gettext("Machine code %c (0%o)\n"), cp[-1],
cp[-1]);
			printf(gettext("Sorry.\n"));
			goto err;
		}
		nstrcat(name, BUFSIZ, cp2);
		stradd(name, BUFSIZ, *cp++);
	}
	nstrcat(name, BUFSIZ, netcomp);
	if (debug) fprintf(stderr, "optim returns %s in name\n", name);
}
Example #17
0
/*
 * Terminate an editing session by attempting to write out the user's
 * file from the temporary.  Save any new stuff appended to the file.
 */
int
edstop(
    int noremove	/* don't allow the file to be removed, trunc instead */
)
{
	register int gotcha, c;
	register struct message *mp;
	FILE *obuf, *ibuf, *tbuf = 0, *readstat;
	struct stat statb;
	char tempname[STSIZ], *id;
	int tmpfd = -1;

	if (readonly)
		return (0);
	holdsigs();
	if (Tflag != NOSTR) {
		if ((readstat = fopen(Tflag, "w")) == NULL)
			Tflag = NOSTR;
	}
	for (mp = &message[0], gotcha = 0; mp < &message[msgCount]; mp++) {
		if (mp->m_flag & MNEW) {
			mp->m_flag &= ~MNEW;
			mp->m_flag |= MSTATUS;
		}
		if (mp->m_flag & (MODIFY|MDELETED|MSTATUS))
			gotcha++;
		if (Tflag != NOSTR && (mp->m_flag & (MREAD|MDELETED)) != 0) {
			if ((id = hfield("article-id", mp, addone)) != NOSTR)
				fprintf(readstat, "%s\n", id);
		}
	}
	if (Tflag != NOSTR)
		fclose(readstat);
	if (!gotcha || Tflag != NOSTR)
		goto done;
	if ((ibuf = fopen(editfile, "r+")) == NULL) {
		perror(editfile);
		relsesigs();
		longjmp(srbuf, 1);
	}
	lock(ibuf, "r+", 1);
	if (fstat(fileno(ibuf), &statb) >= 0 && statb.st_size > mailsize) {
		nstrcpy(tempname, STSIZ, "/tmp/mboxXXXXXX");
		if ((tmpfd = mkstemp(tempname)) == -1) {
			perror(tempname);
			fclose(ibuf);
			relsesigs();
			longjmp(srbuf, 1);
		}
		if ((obuf = fdopen(tmpfd, "w")) == NULL) {
			perror(tempname);
			fclose(ibuf);
			removefile(tempname);
			relsesigs();
			(void) close(tmpfd);
			longjmp(srbuf, 1);
		}
		fseek(ibuf, mailsize, 0);
		while ((c = getc(ibuf)) != EOF)
			putc(c, obuf);
		fclose(obuf);
		if ((tbuf = fopen(tempname, "r")) == NULL) {
			perror(tempname);
			fclose(ibuf);
			removefile(tempname);
			relsesigs();
			longjmp(srbuf, 1);
		}
		removefile(tempname);
	}
	if ((obuf = fopen(editfile, "r+")) == NULL) {
		if ((obuf = fopen(editfile, "w")) == NULL) {
			perror(editfile);
			fclose(ibuf);
			if (tbuf)
				fclose(tbuf);
			relsesigs();
			longjmp(srbuf, 1);
		}
	}
	printf("\"%s\" ", editfile);
	flush();
	c = 0;
	for (mp = &message[0]; mp < &message[msgCount]; mp++) {
		if ((mp->m_flag & MDELETED) != 0)
			continue;
		c++;
		if (msend(mp, obuf, 0, fputs) < 0) {
			perror(editfile);
			fclose(ibuf);
			fclose(obuf);
			if (tbuf)
				fclose(tbuf);
			relsesigs();
			longjmp(srbuf, 1);
		}
	}
	gotcha = (c == 0 && tbuf == NULL);
	if (tbuf != NULL) {
		while ((c = getc(tbuf)) != EOF)
			putc(c, obuf);
		fclose(tbuf);
	}
	fflush(obuf);
	if (fferror(obuf)) {
		perror(editfile);
		fclose(ibuf);
		fclose(obuf);
		relsesigs();
		longjmp(srbuf, 1);
	}
	if (gotcha && !noremove && (value("keep") == NOSTR)) {
		removefile(editfile);
		printf(gettext("removed.\n"));
	}
	else
		printf(gettext("updated.\n"));
	fclose(ibuf);
	trunc(obuf);
	fclose(obuf);
	flush();

done:
	relsesigs();
	return (1);
}
static struct work_record *create_workgroup(const char *name, int ttl)
{
	struct work_record *work;
	struct subnet_record *subrec;
	int t = -1;
  
	if((work = (struct work_record *)malloc(sizeof(*work))) == NULL) {
		DEBUG(0,("create_workgroup: malloc fail !\n"));
		return NULL;
	}
	memset((char *)work, '\0', sizeof(*work));
 
	if (strlen(name)+1 > sizeof(nstring)) {
		memcpy(work->work_group,name,sizeof(nstring)-1);
		work->work_group[sizeof(nstring)-1] = '\0';
		DEBUG(0,("create_workgroup: workgroup name %s is too long. Truncating to %s\n",
				name, work->work_group ));
	} else {
		nstrcpy(work->work_group,name);
	}
	work->serverlist = NULL;
  
	work->RunningElection = False;
	work->ElectionCount = 0;
	work->announce_interval = 0;
	work->needelection = False;
	work->needannounce = True;
	work->lastannounce_time = time(NULL);
	work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE;
	work->dom_state = DOMAIN_NONE;
	work->log_state = LOGON_NONE;
  
	work->death_time = (ttl != PERMANENT_TTL) ? time(NULL)+(ttl*3) : PERMANENT_TTL;

	/* Make sure all token representations of workgroups are unique. */
  
	for (subrec = FIRST_SUBNET; subrec && (t == -1); subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) {
		struct work_record *w;
		for (w = subrec->workgrouplist; w && t == -1; w = w->next) {
			if (strnequal(w->work_group, work->work_group, sizeof(nstring)-1))
				t = w->token;
		}
	}
  
	if (t == -1)
		work->token = ++workgroup_count;
	else
		work->token = t;
  
	/* No known local master browser as yet. */
	*work->local_master_browser_name = '\0';

	/* No known domain master browser as yet. */
	*work->dmb_name.name = '\0';
	zero_ip(&work->dmb_addr);

	/* WfWg  uses 01040b01 */
	/* Win95 uses 01041501 */
	/* NTAS  uses ???????? */
	work->ElectionCriterion  = (MAINTAIN_LIST)|(BROWSER_ELECTION_VERSION<<8); 
	work->ElectionCriterion |= (lp_os_level() << 24);
	if (lp_domain_master())
		work->ElectionCriterion |= 0x80;
  
	return work;
}
Example #19
0
char *
netmap(char name[], char from[])
{
	char nbuf[BUFSIZ], ret[BUFSIZ];
	register char *cp, *oname;

	if (debug) fprintf(stderr, "netmap(name '%s', from '%s')\n", name, from);
	if (strlen(from) == 0)
		return(name);	/* "from" is empty - can't do anything */

	if (strcmp(from, name) == 0)
		return(name);	/* "from" and "name" are the same, do nothing */

	/*
	 * If the name contains an "@" or a "%", remove it and the host
	 * following it if that host is "known".
	 */
	if (any('@', name) || any('%', name))
		return(arpafix(name, from));

	/*
	 * If the sender contains a "@" or a "%", make "name" into an
	 * address on that host, on the presumption that it should
	 * really have read "name@from" when we received the message
	 * rather than just "name".
	 */
	if (any('@', from) || any('%', from))
		return(unuucp(makeremote(name, from)));
	if (value("onehop") && (cp = strchr(name, '!')) && cp > name) {
		/*
		 * "onehop" is set, meaning all machines are one UUCP
		 * hop away (fat chance, in this day and age), and "name"
		 * is a UUCP path rather than just a name.  Leave it alone.
		 */
		nstrcpy(nbuf, sizeof (nbuf), name);
	} else {
		from = tackon(host, from);
		*strrchr(from, '!') = 0;
		name = tackon(lasthost(from), name);
		while (((cp = lasthost(from)) != 0) && ishost(cp, name)) {
			oname = name;
			name = strchr(name, '!') + 1;
			if (cp == from) {
				from[strlen(from)] = '!';
				if (value("mustbang") && !strchr(name, '!'))
					name = oname;
				return(unuucp(name));
			}
			*--cp = 0;
		}
		from[strlen(from)] = '!';
		from = strchr(from, '!') + 1;
		snprintf(nbuf, sizeof (nbuf), "%s!%s", from, name);
	}
	if (debug) fprintf(stderr, "before optim, nbuf '%s'\n", name);
#ifdef	OPTIM
	if ((cp = value("conv"))==NOSTR || strcmp(cp, "optimize") != 0)
		nstrcpy(ret, sizeof (ret), nbuf);
	else
		optim(nbuf, ret);
#else
	nstrcpy(ret, sizeof (ret), nbuf);
#endif	/* OPTIM */
	if (debug) fprintf(stderr, "after  optim, nbuf '%s', ret '%s'\n", nbuf, ret);
	cp = ret;
	if (debug) fprintf(stderr, "wind up with '%s'\n", name);
	if (!icequal(name, cp))
		return(unuucp((char *) savestr(cp)));
	return(unuucp(name));
}
Example #20
0
//	////////////////////////////////////////////////////////////////////////////
void ParseFromString(const char *in_date, time_t &out_secs,
	long &out_fractional, long fractional_places)
{
	if (in_date == NULL)
		ThrowInvalidArgument("Specified date string pointer is 'NULL'.");

	try {
		size_t date_length = strlen(in_date);
		char   date_buffer[Length_TimeSpec + 9 + 1];
		if (date_length < 8)
			ThrowInvalidArgument("Unknown date format.");
		if (date_length == 8) {
			char *end_ptr;
			strtoul(in_date, &end_ptr, 10);
			if (end_ptr != (in_date + 8))
				ThrowInvalidArgument("Invalid undelimited date string --- "
					"only numeric characters are valid.");
			strcat(nstrcat(strcat(nstrcat(strcat(nstrcpy(date_buffer, in_date, 4),
				"-"), in_date + 4, 2), "-"), in_date + 6, 2),
				" 00:00:00.000000000");
			ParseFromString_Basic(date_buffer, out_secs, out_fractional,
				fractional_places);
		}
		else {
			if ((!isdigit(in_date[0])) || (!isdigit(in_date[1])) ||
				(!isdigit(in_date[2])) || (!isdigit(in_date[3])) ||
				(!isdigit(in_date[5])) || (!isdigit(in_date[6])) ||
				(!isdigit(in_date[8])) || (!isdigit(in_date[9])))
				ThrowInvalidArgument("Invalid delimited date string --- "
					"expected format for date portion is 'yyyy-mm-dd'.");
			if (((in_date[4] != '-') && (in_date[4] != '/')) ||
				 ((in_date[7] != '-') && (in_date[7] != '/')))
				ThrowInvalidArgument("Invalid delimited date string --- "
					"expected format for date portion is 'yyyy-mm-dd'.");
			if (date_length == 10) {
				strcat(strcpy(date_buffer, in_date), " 00:00:00.000000000");
				ParseFromString_Basic(date_buffer, out_secs, out_fractional,
					fractional_places);
			}
			else if (date_length <= Length_TimeSpec) {
				if (((date_length < 20) && (date_length != 13) &&
					(date_length != 16) && (date_length != 19)))
					ThrowInvalidArgument("Unknown date format.");
				if (((in_date[10] != ' ') && (in_date[10] != '.')) ||
					(!isdigit(in_date[11])) || (!isdigit(in_date[12])))
					ThrowInvalidArgument("Invalid delimited date/time string.");
				if (date_length == 13)
					ParseFromString_Basic(strcat(strcpy(date_buffer, in_date),
						":00:00.000000000"), out_secs, out_fractional,
						fractional_places);
				else {
					if (((in_date[13] != ':') && (in_date[13] != '.')) ||
						(!isdigit(in_date[14])) || (!isdigit(in_date[15])))
						ThrowInvalidArgument("Invalid delimited date/time string.");
					if (date_length == 16)
						ParseFromString_Basic(strcat(strcpy(date_buffer, in_date),
							":00.000000000"), out_secs, out_fractional,
							fractional_places);
					else {
						if (((in_date[16] != ':') && (in_date[16] != '.')) ||
							(!isdigit(in_date[17])) || (!isdigit(in_date[18])))
							ThrowInvalidArgument("Invalid delimited date/time string.");
						else if (date_length == 19)
							ParseFromString_Basic(strcat(strcpy(date_buffer, in_date),
								".000000000"), out_secs, out_fractional,
								fractional_places);
						else if (in_date[19] != '.')
							ThrowInvalidArgument("Invalid delimited date/time string.");
						else
							ParseFromString_Basic(nstrcat(strcpy(date_buffer, in_date),
								"000000000", Length_TimeSpec - date_length), out_secs,
								out_fractional, fractional_places);
					}
				}
			}
			else
				ThrowInvalidArgument("Date/time string length exceeds maximum "
					"permissible (" + AnyToString(Length_TimeSpec) +
					" characters).");
		}
	}
	catch (const std::exception &except) {
		Rethrow(except, "Unable to parse date/time string '" +
			std::string(in_date) + "': " + std::string(except.what()));
	}
}