( uid_2716 | 2012. 05. 09., sze – 22:46 )


#include <stdio.h>
#include <stdlib.h>

int
main(void)
{
  int quote,
      prev,
      c;

  quote = 0;
  prev = -1;

  while (EOF != (c = fgetc(stdin))) {
    switch (c) {
      case '\'':
        quote = !quote;
        break;

      case ' ':
        if (' ' == prev && !quote) {
          continue;
        }
    }

    if (EOF == fputc(c, stdout)) {
      perror("fputc(stdout)");
      return EXIT_FAILURE;
    }

    prev = c;
  }

  if (ferror(stdin)) {
    perror("fgetc(stdout)");
    return EXIT_FAILURE;
  }

  if (EOF == fflush(stdout)) {
    perror("fflush(stdout)");
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

Nem foglalkozik különösebben újsor karakterrel; ha nincs lezárva az utolsó idézet a sor vége előtt, akkor az újsor karakter is az idézet része lesz (meg a következő sorok is, amíg el nem érünk egy idézőjelet). Ha ezt nem kívánjuk (vagyis az újsor zárja le a szökevény idézetet), akkor ennyi kell még bele:


--- squeeze.c	2012-05-09 22:39:26.000000000 +0200
+++ squeeze-nl.c	2012-05-09 22:42:32.000000000 +0200
@@ -17,6 +17,10 @@
         quote = !quote;
         break;
 
+      case '\n':
+        quote = 0;
+        break;
+
       case ' ':
         if (' ' == prev && !quote) {
           continue;