/* File: showself1.c */

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

static char S_src[] = "%ooga%";

static void
S_PrintSub (char *from, char *to)
{
  char *p;

  for (p = from; p < to; ++p) printf ("%c", *p);
}

static void
S_PrintData (char str[])
{
  int i = 0;

  while (str[i] != '\0') {
    switch (str[i]) {
    case '"': printf ("\\\""); break;
    case '\\': printf ("\\\\"); break;
    case '\n': printf ("\\n\"\n  \""); break;
    default: putchar (str[i]);
    }
    ++i;
  }
}

static void
S_PrintRest (char str[])
{
  char *p;

  for (p = str; *p != '\0'; ++p) {
    putchar (*p);
  }
}

int
main ()
{
  char *src, *p;
  FILE *fp;
  int i;

  if (strcmp (S_src, "%ooga%") == 0) {
    /* Must load the source code from the file. */
    fp = fopen ("showself1.c", "r");
    src = (char *) malloc (10 * 1024);
    fread (src, 1, 10 * 1024, fp);
    fclose (fp);
  } else {
    src = S_src;
  }
  p = strstr (src, "%ooga%");
  i = strlen ("%ooga%");
  S_PrintSub (src, p);
  S_PrintData (src);
  S_PrintRest (p + i);
  return 0;
}
