root/shrinkcss.c
/*DEFINITIONS
This source file includes following definitions.1 /* Copyright (c) 2023 Amelia Campbell <ame@psianesia.org> 2 ** 3 ** Redistribution and use in source and binary forms, with or without 4 ** modification, are permitted provided that the following conditions 5 ** are met: 6 ** 1. Redistributions of source code must retain the above copyright 7 ** notice, this list of conditions and the following disclaimer. 8 ** 2. Redistributions in binary form must reproduce the above copyright 9 ** notice, this list of conditions and the following disclaimer in the 10 ** documentation and/or other materials provided with the distribution. 11 ** 12 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 13 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 16 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 17 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 18 ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 19 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 20 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 21 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 22 ** SUCH DAMAGE. 23 */ 24 25 26 #include <stdio.h> 27 #include <string.h> 28 29 int 30 main( int argc, char *argv[] ) 31 { 32 char line[2000]; 33 char *cp, *cp2; 34 int prop = 0, select = 1, comment = 0, putspc = 0, nstart; 35 36 (void) argc; 37 (void) argv; 38 39 while ( fgets( line, sizeof(line), stdin ) != NULL ) 40 { 41 cp = line; 42 nstart = 0; 43 while ( *cp != '\0' ) 44 { 45 if ( comment ) 46 { 47 cp2 = strstr( cp, "*/" ); 48 if ( cp2++ != NULL ) 49 cp = cp2, comment = 0; 50 goto retry; 51 } 52 53 switch ( *cp ) 54 { 55 case '\r': 56 case '\n': goto retry ; 57 case '\t': *cp = ' ' ; 58 case ' ' : if ( ( *(cp + 1) == '{' || *(cp + 1) == ';' ) 59 || ( ! nstart || putspc ) 60 || ( ! prop && ! select ) ) goto retry; 61 putspc = 1 ; goto put2 ; 62 case '}' : select = 1 ; goto put ; 63 case ':' : prop = 1 ; nstart = 0 ; goto put ; 64 case '{' : select = 0 ; goto put ; 65 case ';' : prop = 0 ; goto put ; 66 case '/' : if (*++cp == '*') { comment = 1; goto retry; } 67 else { cp-- ; } 68 default: 69 put: putspc = 0; 70 put2: *cp != ':' ? nstart = 1 :0; 71 ! comment ? fputc( *cp, stdout ) :0; break ; 72 } 73 retry: cp++; 74 } 75 } 76 77 return 0; 78 }
/*