Annotation of researchv10no/cmd/dist/lib/quote.c, revision 1.1.1.1

1.1       root        1: #include <ctype.h>
                      2: #include <stdio.h>
                      3: #include <time.h>
                      4: #include "lib.h"
                      5: 
                      6: void
                      7: quote(char *qs, char *us)
                      8: {
                      9:        unsigned char c;
                     10: 
                     11:        while (c = *us++)
                     12:                if (!isgraph(c) || c == '\\') {
                     13:                        *qs++ = '\\';
                     14:                        switch (c) {
                     15:                        case '\\':
                     16:                                *qs++ = '\\';
                     17:                                break;
                     18:                        case '\a':
                     19:                                *qs++ = 'a';
                     20:                                break;
                     21:                        case '\b':
                     22:                                *qs++ = 'b';
                     23:                                break;
                     24:                        case '\f':
                     25:                                *qs++ = 'f';
                     26:                                break;
                     27:                        case '\n':
                     28:                                *qs++ = 'n';
                     29:                                break;
                     30:                        case '\r':
                     31:                                *qs++ = 'r';
                     32:                                break;
                     33:                        case '\t':
                     34:                                *qs++ = 't';
                     35:                                break;
                     36:                        case '\v':
                     37:                                *qs++ = 'v';
                     38:                                break;
                     39:                        default:
                     40:                                *qs++ = c / 64 % 8 + '0';
                     41:                                *qs++ = c / 8 % 8 + '0';
                     42:                                *qs++ = c % 8 + '0';
                     43:                                break;
                     44:                        }
                     45:                } else
                     46:                        *qs++ = c;
                     47:        *qs = '\0';
                     48: }
                     49: 
                     50: void
                     51: unquote(char *us, char *qs)
                     52: {
                     53:        unsigned char c;
                     54:        int i;
                     55: 
                     56:        while (c = *qs++)
                     57:                if (c == '\\') {
                     58:                        c = *qs++;
                     59:                        switch (c) {
                     60:                        case '\\':
                     61:                                *us++ = '\\';
                     62:                                break;
                     63:                        case 'a':
                     64:                                *us++ = '\a';
                     65:                                break;
                     66:                        case 'b':
                     67:                                *us++ = '\b';
                     68:                                break;
                     69:                        case 'f':
                     70:                                *us++ = '\f';
                     71:                                break;
                     72:                        case 'n':
                     73:                                *us++ = '\n';
                     74:                                break;
                     75:                        case 'r':
                     76:                                *us++ = '\r';
                     77:                                break;
                     78:                        case 't':
                     79:                                *us++ = '\t';
                     80:                                break;
                     81:                        case 'v':
                     82:                                *us++ = '\v';
                     83:                                break;
                     84:                        default:
                     85:                                *us = 0;
                     86:                                for (i = 0; i < 3; ++i) {
                     87:                                        if (c < '0' || c > '7')
                     88:                                                break;
                     89:                                        *us = *us * 8 + c - '0';
                     90:                                        c = *qs++;
                     91:                                }
                     92:                                --qs;
                     93:                                ++us;
                     94:                                break;
                     95:                        }
                     96:                } else
                     97:                        *us++ = c;
                     98:        *us = '\0';
                     99: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.