예제 #1
0
static int 
name(void)
{
	register int t;
	register char *cp;

	for (;;) {
		t = yylex();
		if (t != WORD)
			return(-1);
		cp = yylval;
		t = yylex();
		switch (t) {
		case 0:
			nstrcat(netbuf, sizeof (netbuf), cp);
			return(0);

		case '@':
		case '%':
			if (name())
				return(-1);
			stradd(netbuf, sizeof (netbuf), '@');
			nstrcat(netbuf, sizeof (netbuf), cp);
			return(0);	
		case WORD:
			return(-1);

		default:
			nstrcat(netbuf, sizeof (netbuf), cp);
			stradd(netbuf, sizeof (netbuf), t);
		}
	}
}
예제 #2
0
파일: wdwcreate.c 프로젝트: andreiw/polaris
int
glob_create()
{
    char *errstr;
    static char *argv[3];
    extern char *Filecabinet;
    char *path_to_full(), *bsd_path_to_title(), *cur_path();

    argv[0] = argv[1] = argv[2] = NULL;
    if (parse_n_in_fold(&argv[1], &argv[0]) == FAIL)
	return(TOK_CREATE);
    if (eqwaste(argv[0]))
	return(FAIL);
    if (isfolder(argv[0]) == FALSE) {
	mess_temp("You can only create new objects inside File folders");
	return(FAIL);
    }
    if (access(argv[0], 02) < 0) {
	mess_temp(nstrcat("You don't have permission to create objects in ",
	    bsd_path_to_title(argv[0], MESS_COLS-47), NULL));
	return(FAIL);
    }
    if (argv[1] == NULL) {
	enter_getname("create", "", argv);
	return(TOK_NOP);
    }
    if (namecheck(argv[0], argv[1], NULL, &errstr, TRUE) == FALSE) {
	mess_temp(errstr);
	argv[1] = NULL;
	enter_getname("create", "", argv);
	return(TOK_NOP);
    }
    Create_create(argv);
    return(TOK_NOP);
}
예제 #3
0
파일: Time.cpp 프로젝트: mlbrock/MlbDev
//	////////////////////////////////////////////////////////////////////////////
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()));
	}
}
예제 #4
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);
}