Ignore:
Timestamp:
01/04/07 02:09:04 (6 years ago)
Author:
sam
Message:
  • Implement -P / --protect.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/libzzuf.c

    r1553 r1554  
    2828#include <unistd.h> 
    2929#include <stdlib.h> 
     30#include <string.h> 
    3031#include <fcntl.h> 
    3132#include <regex.h> 
     
    4647int   _zz_signal   = 0; 
    4748 
     49/* Global tables */ 
     50int   _zz_protect[256]; 
     51 
    4852/* Local variables */ 
    4953static regex_t * re_include = NULL; 
     
    5155 
    5256/* Local prototypes */ 
     57static void _zz_protect_init(char const *); 
    5358static void _zz_fd_init(void); 
    5459static void _zz_fd_fini(void); 
     
    7580        _zz_ratio = 5.0f; 
    7681 
     82    tmp = getenv("ZZUF_PROTECT"); 
     83    if(tmp && *tmp) 
     84        _zz_protect_init(tmp); 
     85 
    7786    tmp = getenv("ZZUF_INCLUDE"); 
    7887    if(tmp && *tmp) 
     
    112121{ 
    113122    _zz_fd_fini(); 
     123} 
     124 
     125/* Byte list stuff */ 
     126static void _zz_protect_init(char const *list) 
     127{ 
     128    static char const hex[] = "0123456789abcdef0123456789ABCDEF"; 
     129    char const *tmp; 
     130    int a, b; 
     131 
     132    memset(_zz_protect, 0, 256 * sizeof(int)); 
     133 
     134    for(tmp = list, a = b = -1; *tmp; tmp++) 
     135    { 
     136        int new; 
     137 
     138        if(*tmp == '\\' && tmp[1] == '\0') 
     139            new = '\\'; 
     140        else if(*tmp == '\\') 
     141        { 
     142            tmp++; 
     143            if(*tmp == 'n') 
     144                new = '\n'; 
     145            else if(*tmp == 'r') 
     146                new = '\r'; 
     147            else if(*tmp == 't') 
     148                new = '\t'; 
     149            else if(*tmp == '0') 
     150                new = '\0'; 
     151            else if((*tmp == 'x' || *tmp == 'X') 
     152                     && tmp[1] && strchr(hex, tmp[1]) 
     153                     && tmp[2] && strchr(hex, tmp[2])) 
     154            { 
     155                new = ((strchr(hex, tmp[1]) - hex) & 0xf) << 4; 
     156                new |= (strchr(hex, tmp[2]) - hex) & 0xf; 
     157                tmp += 2; 
     158            } 
     159            else 
     160                new = (unsigned char)*tmp; /* XXX: OK for \\, but what else? */ 
     161        } 
     162        else 
     163            new = (unsigned char)*tmp; 
     164 
     165        if(a != -1 && b == '-' && a <= new) 
     166        { 
     167            while(a <= new) 
     168                _zz_protect[a++] = 1; 
     169            a = b = -1; 
     170        } 
     171        else 
     172        { 
     173            if(a != -1) 
     174                _zz_protect[a] = 1; 
     175            a = b; 
     176            b = new; 
     177        } 
     178    } 
     179 
     180    if(a != -1) 
     181        _zz_protect[a] = 1; 
     182    if(b != -1) 
     183        _zz_protect[b] = 1; 
    114184} 
    115185 
Note: See TracChangeset for help on using the changeset viewer.