char *mea_unescape(char *result, char *data) { int ch; int result_ptr = 0; int oval; int i; result[0]=0; while ((ch = *data++) != 0) { if (ch == '\\') { if ((ch = *data++) == 0) break; switch (ch) { case 'a': /* \a -> audible bell */ ch = '\a'; break; case 'b': /* \b -> backspace */ ch = '\b'; break; case 'f': /* \f -> formfeed */ ch = '\f'; break; case 'n': /* \n -> newline */ ch = '\n'; break; case 'r': /* \r -> carriagereturn */ ch = '\r'; break; case 't': /* \t -> horizontal tab */ ch = '\t'; break; case 'v': /* \v -> vertical tab */ ch = '\v'; break; case '0': /* \nnn -> ASCII value */ case '1': case '2': case '3': case '4': case '5': case '6': case '7': for (oval = ch - '0', i = 0; i < 2 && ((ch = *data) != 0) && ISOCTAL(ch); i++, data++) { oval = (oval << 3) | (ch - '0'); } ch = oval; break; default: /* \any -> any */ break; } } result[result_ptr++]=ch; } result[result_ptr]=0; return (result); }
VSTRING *unescape(VSTRING *result, const char *data) { int ch; int oval; int i; #define UCHAR(cp) ((unsigned char *) (cp)) #define ISOCTAL(ch) (ISDIGIT(ch) && (ch) != '8' && (ch) != '9') VSTRING_RESET(result); while ((ch = *UCHAR(data++)) != 0) { if (ch == '\\') { if ((ch = *UCHAR(data++)) == 0) break; switch (ch) { case 'a': /* \a -> audible bell */ ch = '\a'; break; case 'b': /* \b -> backspace */ ch = '\b'; break; case 'f': /* \f -> formfeed */ ch = '\f'; break; case 'n': /* \n -> newline */ ch = '\n'; break; case 'r': /* \r -> carriagereturn */ ch = '\r'; break; case 't': /* \t -> horizontal tab */ ch = '\t'; break; case 'v': /* \v -> vertical tab */ ch = '\v'; break; case '0': /* \nnn -> ASCII value */ case '1': case '2': case '3': case '4': case '5': case '6': case '7': for (oval = ch - '0', i = 0; i < 2 && (ch = *UCHAR(data)) != 0 && ISOCTAL(ch); i++, data++) { oval = (oval << 3) | (ch - '0'); } ch = oval; break; default: /* \any -> any */ break; } } VSTRING_ADDCH(result, ch); } VSTRING_TERMINATE(result); return (result); }
struct symbol *parser( ) { register struct symbol *psym; register char *pline; struct varent *pvar; struct strent *pstr; char *cp, *plc, *pn; long lnc; int i; long double tem; /* reference for old Whitesmiths compiler: */ /* *extern FILE *stdout; */ pline = interl; /* get current location in command string */ /* If at beginning of string, must ask for more input */ if( pline == line ) { if( maccnt > 0 ) { --maccnt; cp = maclin; plc = pline; while( (*plc++ = *cp++) != 0 ) ; goto mstart; } if( takptr < 0 ) { /* no take file active: prompt keyboard input */ printf("* "); } /* Various ways of typing in a command line. */ /* * Old Whitesmiths call to print "*" immediately * use RT11 .GTLIN to get command string * from command file or terminal */ /* * fflush(stdout); * gtlin(line); */ zgets( line, TRUE ); /* keyboard input for other systems: */ mstart: uposs = 1; /* unary operators possible at start of line */ } ignore: /* Skip over spaces */ while( *pline == ' ' ) ++pline; /* unary minus after operator */ if( uposs && (*pline == '-') ) { psym = &oprtbl[2]; /* UMINUS */ ++pline; goto pdon3; } /* COMP */ /* if( uposs && (*pline == '~') ) { psym = &oprtbl[3]; ++pline; goto pdon3; } */ if( uposs && (*pline == '+') ) /* ignore leading plus sign */ { ++pline; goto ignore; } /* end of null terminated input */ if( (*pline == '\n') || (*pline == '\0') || (*pline == '\r') ) { pline = line; goto endlin; } if( *pline == ';' ) { ++pline; endlin: psym = &oprtbl[1]; /* EOL */ goto pdon2; } /* parser() */ /* Test for numeric input */ if( (ISDIGIT(*pline)) || (*pline == '.') ) { lnc = 0; /* initialize numeric input to zero */ qnc = 0.0L; if( *pline == '0' ) { /* leading "0" may mean octal or hex radix */ ++pline; if( *pline == '.' ) goto decimal; /* 0.ddd */ /* leading "0x" means hexadecimal radix */ if( (*pline == 'x') || (*pline == 'X') ) { ++pline; while( ISXDIGIT(*pline) ) { i = *pline++ & 0xff; if( i >= 'a' ) i -= 047; if( i >= 'A' ) i -= 07; i -= 060; lnc = (lnc << 4) + i; qnc = lnc; } goto numdon; } else { while( ISOCTAL( *pline ) ) { i = ((*pline++) & 0xff) - 060; lnc = (lnc << 3) + i; qnc = lnc; } goto numdon; } } else { /* no leading "0" means decimal radix */ /******/ decimal: pn = number; while( (ISDIGIT(*pline)) || (*pline == '.') ) *pn++ = *pline++; /* get possible exponent field */ if( (*pline == 'e') || (*pline == 'E') ) *pn++ = *pline++; else goto numcvt; if( (*pline == '-') || (*pline == '+') ) *pn++ = *pline++; while( ISDIGIT(*pline) ) *pn++ = *pline++; numcvt: *pn++ = ' '; *pn++ = 0; #if NE == 6 asctoe64( number, &qnc ); #else asctoe113( number, &qnc ); #endif /* sscanf( number, "%le", &nc ); */ } /* output the number */ numdon: /* search the symbol table of constants */ pvar = &contbl[0]; for( i=0; i<NCONST; i++ ) { if( (pvar->attrib & BUSY) == 0 ) goto confnd; tem = *pvar->value; if( tem == qnc ) { psym = (struct symbol *)pvar; goto pdon2; } ++pvar; } printf( "no room for constant\n" ); psym = (struct symbol *)&contbl[0]; goto pdon2; confnd: pvar->spel= contbl[0].spel; pvar->attrib = CONST | BUSY; *pvar->value = qnc; psym = (struct symbol *)pvar; goto pdon2; } /* check for operators */ psym = &oprtbl[3]; for( i=0; i<NOPR; i++ ) { if( *pline == *(psym->spel) ) goto pdon1; ++psym; } /* if quoted, it is a string variable */ if( *pline == '"' ) { /* find an empty slot for the string */ pstr = strtbl; /* string table */ for( i=0; i<NSTRNG-1; i++ ) { if( (pstr->attrib & BUSY) == 0 ) goto fndstr; ++pstr; } printf( "No room for string\n" ); pstr->attrib |= ILLEG; psym = (struct symbol *)pstr; goto pdon0; fndstr: pstr->attrib |= BUSY; plc = pstr->string; ++pline; for( i=0; i<39; i++ ) { *plc++ = *pline; if( (*pline == '\n') || (*pline == '\0') || (*pline == '\r') ) { illstr: pstr = &strtbl[NSTRNG-1]; pstr->attrib |= ILLEG; printf( "Missing string terminator\n" ); psym = (struct symbol *)pstr; goto pdon0; } if( *pline++ == '"' ) goto finstr; } goto illstr; /* no terminator found */ finstr: --plc; *plc = '\0'; psym = (struct symbol *)pstr; goto pdon2; } /* If none of the above, search function and symbol tables: */ /* copy character string to array lc[] */ plc = &lc[0]; while( ISALPHA(*pline) ) { /* convert to lower case characters */ if( ISUPPER( *pline ) ) *pline += 040; *plc++ = *pline++; } *plc = 0; /* Null terminate the output string */ /* parser() */ psym = (struct symbol *)menstk[menptr]; /* function table */ plc = &lc[0]; cp = psym->spel; do { if( strcmp( plc, cp ) == 0 ) goto pdon3; /* following unary minus is possible */ ++psym; cp = psym->spel; } while( *cp != '\0' ); psym = (struct symbol *)&indtbl[0]; /* indirect symbol table */ plc = &lc[0]; cp = psym->spel; do { if( strcmp( plc, cp ) == 0 ) goto pdon2; ++psym; cp = psym->spel; } while( *cp != '\0' ); pdon0: pline = line; /* scrub line if illegal symbol */ goto pdon2; pdon1: ++pline; if( (psym->attrib & 0xf) == RPAREN ) pdon2: uposs = 0; else pdon3: uposs = 1; interl = pline; return( psym ); } /* end of parser */
void decode_header_format (union block *header, struct tar_stat_info *stat_info, enum archive_format *format_pointer, int do_user_group) { enum archive_format format; if (strcmp (header->header.magic, TMAGIC) == 0) { if (header->star_header.prefix[130] == 0 && ISOCTAL (header->star_header.atime[0]) && header->star_header.atime[11] == ' ' && ISOCTAL (header->star_header.ctime[0]) && header->star_header.ctime[11] == ' ') format = STAR_FORMAT; else if (stat_info->xhdr.size) format = POSIX_FORMAT; else format = USTAR_FORMAT; } else if (strcmp (header->header.magic, OLDGNU_MAGIC) == 0) format = OLDGNU_FORMAT; else format = V7_FORMAT; *format_pointer = format; #if 0 // 0 ************************************************* stat_info->stat.st_mode = MODE_FROM_HEADER (header->header.mode); stat_info->mtime.tv_sec = TIME_FROM_HEADER (header->header.mtime); stat_info->mtime.tv_nsec = 0; assign_string (&stat_info->uname, header->header.uname[0] ? header->header.uname : NULL); assign_string (&stat_info->gname, header->header.gname[0] ? header->header.gname : NULL); if (format == OLDGNU_FORMAT && incremental_option) { stat_info->atime.tv_sec = TIME_FROM_HEADER (header->oldgnu_header.atime); stat_info->ctime.tv_sec = TIME_FROM_HEADER (header->oldgnu_header.ctime); stat_info->atime.tv_nsec = stat_info->ctime.tv_nsec = 0; } else if (format == STAR_FORMAT) { stat_info->atime.tv_sec = TIME_FROM_HEADER (header->star_header.atime); stat_info->ctime.tv_sec = TIME_FROM_HEADER (header->star_header.ctime); stat_info->atime.tv_nsec = stat_info->ctime.tv_nsec = 0; } else stat_info->atime = stat_info->ctime = start_time; if (format == V7_FORMAT) { stat_info->stat.st_uid = UID_FROM_HEADER (header->header.uid); stat_info->stat.st_gid = GID_FROM_HEADER (header->header.gid); stat_info->stat.st_rdev = 0; } else { if (do_user_group) { /* FIXME: Decide if this should somewhat depend on -p. */ //**if (numeric_owner_option //** || !*header->header.uname //** || !uname_to_uid (header->header.uname, &stat_info->stat.st_uid)) stat_info->stat.st_uid = UID_FROM_HEADER (header->header.uid); //**if (numeric_owner_option //** || !*header->header.gname //** || !gname_to_gid (header->header.gname, &stat_info->stat.st_gid)) stat_info->stat.st_gid = GID_FROM_HEADER (header->header.gid); } switch (header->header.typeflag) { case BLKTYPE: case CHRTYPE: stat_info->stat.st_rdev = 0; //** makedev (MAJOR_FROM_HEADER (header->header.devmajor), //** MINOR_FROM_HEADER (header->header.devminor)); break; default: stat_info->stat.st_rdev = 0; } } stat_info->archive_file_size = stat_info->stat.st_size; #endif // 0 ************************************************** }
static inline char * translate_escape(char *p, int isArray) { char c, *q, *s; #ifdef TCL_ARRAYS_DEBUG_ESCAPE printf(" escape = '%s'\n", p); #endif /* Address of the first character after the escape sequence */ s = p + 2; switch (c = *(p + 1)) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': c = DIGIT(c); if (ISOCTAL(*s)) c = (c << 3) + DIGIT(*s++); if (ISOCTAL(*s)) c = (c << 3) + DIGIT(*s++); *p = c; break; case 'b': *p = '\b'; break; case 'f': *p = '\f'; break; case 'n': *p = '\n'; break; case 'r': *p = '\r'; break; case 't': *p = '\t'; break; case 'v': *p = '\v'; break; case '\\': case '{': case '}': case '"': /* * Backslahes, curly braces and double-quotes are left escaped * if they appear inside an array. They will be unescaped by * Tcl in Tcl_AppendElement. The buffer position is advanced * by 1 so that the this character is not processed again by * the caller. */ if (isArray) return p + 1; else *p = c; break; case '\0': /* * This means a backslash at the end of the string. It should * never happen but in that case replace the \ with a \0 but * don't shift the rest of the buffer so that the caller can * see the end of the string and terminate. */ *p = c; return p; break; default: /* * Default case, store the escaped character over the * backslash and shift the buffer over itself. */ *p = c; } /* Shift the rest of the buffer over itself after the current char */ q = p + 1; for (; *s;) *q++ = *s++; *q = '\0'; #ifdef TCL_ARRAYS_DEBUG_ESCAPE printf(" after = '%s'\n", p); #endif return p; }