示例#1
0
void Word::writeMsgEncoding     // WRITE WORD ENCODING IN A MESSAGE
    ( EncStats& stats           // - statistics
    , char *tgt )               // - output buffer
    const
{
    if( _code & ENC_BIT ) {
        if( _code & LARGE_BIT ) {
            stats.space_put_out += 2;
            tgt = concatStr( tgt, ", ENC_BIT | LARGE_BIT | " );
            tgt = concatHex( tgt,  (_code &  0xFF) - ENC_BIT - LARGE_BIT );
            tgt = concatStr( tgt, " , " );
            tgt = concatHex( tgt, ( _code & 0xFF00 ) >> 8 );
        } else {
示例#2
0
void docommand(int fd, char * line) {
	int argc;
	char * commandStr = NULL;
	int commandStrLen = 0;
	int commandCommandLen = 0;
	char ** argv;
	int i = 0;
	argv = parseLine(line, &argc);
	if (argv == NULL) {
		printf("Invalid argument(s)\n");
	} else {
		if (!strncmp(argv[0], "set", 3)
				|| !strncmp(argv[0], "add", 3) || !strncmp(argv[0], "replace", 6)) {
			if (argc < 3) {
				goto free;
			}
			commandStr = concatStr(commandStr, argv[0]);
			commandStr = concatStr(commandStr, " ");
			commandStr = concatStr(commandStr, argv[1]);
			commandStr = concatStr(commandStr, " ");

			if (argc >= 5) {
				commandStr = concatStr(commandStr, argv[4]);
			} else {
				commandStr = concatStr(commandStr, "0");
			}
			commandStr = concatStr(commandStr, " ");

			if (argc >= 4) {
				commandStr = concatStr(commandStr, argv[3]);
			} else {
				commandStr = concatStr(commandStr, "3600");
			}
			commandStr = concatStr(commandStr, " ");
			commandStr = concatStr(commandStr, intToString((int)strlen(argv[2])));
			commandStr = concatStr(commandStr, "\r\n");
			commandStr = concatStr(commandStr, argv[2]);
			commandStr = concatStr(commandStr, "\r\n");
		} else if (!strncmp(argv[0], "get", 3) || !strncmp(argv[0], "gets", 3)) {
			commandStr = concatStr(commandStr, argv[0]);
			commandStr = concatStr(commandStr, " ");
			for (i = 1; i < argc - 1; i ++) {
				commandStr = concatStr(commandStr, argv[i]);
				commandStr = concatStr(commandStr, " ");
			}
			commandStr = concatStr(commandStr, argv[argc - 1]);
			commandStr = concatStr(commandStr, "\r\n");
		} else if (!strncmp(argv[0], "delete", 6)) {
			commandStr = concatStr(commandStr, argv[0]);
			commandStr = concatStr(commandStr, " ");
			commandStr = concatStr(commandStr, argv[1]);
			commandStr = concatStr(commandStr, "\r\n");
		} else if (!strncmp(argv[0], "flush_all", 8) || !strncmp(argv[0], "version", 6)
				|| !strncmp(argv[0], "quit", 4) || !strncmp(argv[0], "stats", 5)
				|| !strncmp(argv[0], "stats settings", strlen("stats settings"))) {
			commandStr = concatStr(commandStr, argv[0]);
			commandStr = concatStr(commandStr, "\r\n");
			if (!strncmp(argv[0], "quit", 4)) {
				exit(0);
			}
		} else if (!strncmp(argv[0], "incr", 4) || !strncmp(argv[0], "decr", 4)) {
			commandStr = concatStr(commandStr, argv[0]);
			commandStr = concatStr(commandStr, " ");
			commandStr = concatStr(commandStr, argv[1]);
			commandStr = concatStr(commandStr, " ");
			if (argc == 3) {
				commandStr = concatStr(commandStr, argv[2]);
			} else {
				commandStr = concatStr(commandStr, "1");
			}
			commandStr = concatStr(commandStr, "\r\n");
		} else if (!strncmp(argv[0], "append", 6) || !strncmp(argv[0], "prepend", 6)) {
			commandStr = concatStr(commandStr, argv[0]);
			commandStr = concatStr(commandStr, " ");
			commandStr = concatStr(commandStr, argv[1]);
			commandStr = concatStr(commandStr, " ");
			commandStr = concatStr(commandStr, argv[2]);
			commandStr = concatStr(commandStr, "\r\n");
		} else if (!strncmp(argv[0], "touch", 5)) {
			commandStr = concatStr(commandStr, argv[0]);
			commandStr = concatStr(commandStr, " ");
			commandStr = concatStr(commandStr, argv[1]);
			commandStr = concatStr(commandStr, " ");
			if (argc == 3) {
				commandStr = concatStr(commandStr, argv[2]);
			} else {
				commandStr = concatStr(commandStr, "3600");
			}
		} else {
			printf("Invalid argument(s)\n");
			goto free;
		}
		readWrite(fd, commandStr);
	}
free:
	for(i = 0; i < argc; i ++ ) {
		free(argv[i]);
	}
	free(argv);
	if (commandStr) {
		free(commandStr);
	}
}
示例#3
0
void Word::writeMsgEncoding     // WRITE WORD ENCODING IN A MESSAGE
    ( EncStats& stats           // - statistics
    , char *tgt )               // - output buffer
    const
{
    if( _code & ENC_BIT ) {
        if( _code & LARGE_BIT ) {
            stats.space_put_out += 2;
            tgt = concatStr( tgt, ", ENC_BIT | LARGE_BIT | " );
            tgt = concatHex( tgt,  (_code &  0xFF) - ENC_BIT - LARGE_BIT );
            tgt = concatStr( tgt, " , " );
            tgt = concatHex( tgt, ( _code & 0xFF00 ) >> 8 );
        } else {
            stats.space_put_out += 1;
            tgt = concatStr( tgt, ", ENC_BIT | " );
            tgt = concatHex( tgt,  _code - ENC_BIT );
        }
    } else {
        stats.writeName( tgt, _word );
    }
}


static void Word::writeEncoded  // WRITE OUT WORD ENCODING
    ( EncStats& stats           // - statistics
    , FileCtlOutput& out )      // - output file
{
    WordIter iter;              // - iterator
    char buf[256];              // - buffer