Example #1
0
INTN EFIAPI ShellAppMain (IN UINTN Argc, IN CHAR16 **Argv) {
  CHAR8 c;
  int i;
  CHAR8 s[2];
  CHAR8 *source2 = source;
  EFI_FILE_HANDLE handle;
  UINTN size;
  for (i = 0; i < 4; i++) write_file(filenames[i], files[i]);
  ShellOpenFileByName(L"Quine.c", (void**)&handle,
    EFI_FILE_MODE_CREATE | EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0);
  while (c = *source2++, c) {
    if (36 == c) {
      print_escape(handle, files[i++-4]);
    } else if (126 == c) {
      print_escape(handle, source);
    } else {
      s[0] = c; s[1] = 0;
      size = AsciiStrSize(s) - 1;
      FileHandleWrite(handle, &size, s);
    }
  }
  FileHandleClose(handle);
  Print(
   L" _____ _____ ___    ___        _            \n"
   L"| ____|  ___|_ _|  / _ \\ _   _(_)_ __   ___ \n"
   L"|  _| | |_   | |  | | | | | | | | '_ \\ / _ \\\n"
   L"| |___|  _|  | |  | |_| | |_| | | | | |  __/\n"
   L"|_____|_|   |___|  \\__\\_\\\\__,_|_|_| |_|\\___|\n"
  );

  return 0;
}
Example #2
0
int main(int argc, char *argv[]) {
	int temp;
	char *ostring;
	int method;

	if ( *argv[1] == '1') {
		method = 0;
	} else if ( *argv[1] == '2') {
		method = 1;
	} else {
		printf("This argument is not supported");
		return 0;
	}

	printf("This has %d arguments  \n",argc);
	
	for (temp = 2; temp < argc; temp++) {

		ostring = (char *) malloc(strlen(argv[temp]) + 25);
		if (method) {
			print_escape(argv[temp],ostring);
		} else {
			escape_char(argv[temp],ostring);
		}

		printf("%s ",ostring);
		
		free(ostring);

	}
	printf("\n");
}
Example #3
0
void print_package (const char * target, void * pkg, printpkgfn f)
{
	if (config.quiet) return;
	if (!config.custom_out) { color_print_package (pkg, f); return; }
	char *s = pkg_to_str (target, pkg, f, config.format_out);
	if (config.escape)
		print_escape (s);
	else
		printf ("%s\n", s);
	free (s);
	fflush (NULL);
}
Example #4
0
/*
 * Print SysV echo(1) style escape string 
 *	Halts processing string and returns 1 if a \c escape is encountered.
 */
static int
print_escape_str(const char *str)
{
	int value;
	int c;

	while (*str) {
		if (*str == '\\') {
			str++;
			/* 
			 * %b string octal constants are not like those in C.
			 * They start with a \0, and are followed by 0, 1, 2, 
			 * or 3 octal digits. 
			 */
			if (*str == '0') {
				str++;
				for (c = 3, value = 0; c-- && isodigit(*str); str++) {
					value <<= 3;
					value += octtobin(*str);
				}
				putchar (value);
				str--;
			} else if (*str == 'c') {
				return 1;
			} else {
				str--;			
				str += print_escape(str);
			}
		} else {
			putchar (*str);
		}
		str++;
	}

	return 0;
}
Example #5
0
void ast_printer::visitStringLiteralNode( StringLiteralNode* node ) 
{
    print_escape(node->literal(), stream_);
}
Example #6
0
static int
print_encode(struct html *h, const char *p, int norecurse)
{
	size_t		 sz;
	int		 c, len, nospace;
	const char	*seq;
	enum mandoc_esc	 esc;
	static const char rejs[9] = { '\\', '<', '>', '&', '"',
		ASCII_NBRSP, ASCII_HYPH, ASCII_BREAK, '\0' };

	nospace = 0;

	while ('\0' != *p) {
		if (HTML_SKIPCHAR & h->flags && '\\' != *p) {
			h->flags &= ~HTML_SKIPCHAR;
			p++;
			continue;
		}

		sz = strcspn(p, rejs);

		fwrite(p, 1, sz, stdout);
		p += (int)sz;

		if ('\0' == *p)
			break;

		if (print_escape(*p++))
			continue;

		esc = mandoc_escape(&p, &seq, &len);
		if (ESCAPE_ERROR == esc)
			break;

		switch (esc) {
		case ESCAPE_FONT:
		case ESCAPE_FONTPREV:
		case ESCAPE_FONTBOLD:
		case ESCAPE_FONTITALIC:
		case ESCAPE_FONTBI:
		case ESCAPE_FONTROMAN:
			if (0 == norecurse)
				print_metaf(h, esc);
			continue;
		case ESCAPE_SKIPCHAR:
			h->flags |= HTML_SKIPCHAR;
			continue;
		default:
			break;
		}

		if (h->flags & HTML_SKIPCHAR) {
			h->flags &= ~HTML_SKIPCHAR;
			continue;
		}

		switch (esc) {
		case ESCAPE_UNICODE:
			/* Skip past "u" header. */
			c = mchars_num2uc(seq + 1, len - 1);
			break;
		case ESCAPE_NUMBERED:
			c = mchars_num2char(seq, len);
			if (c < 0)
				continue;
			break;
		case ESCAPE_SPECIAL:
			c = mchars_spec2cp(seq, len);
			if (c <= 0)
				continue;
			break;
		case ESCAPE_NOSPACE:
			if ('\0' == *p)
				nospace = 1;
			continue;
		case ESCAPE_OVERSTRIKE:
			if (len == 0)
				continue;
			c = seq[len - 1];
			break;
		default:
			continue;
		}
		if ((c < 0x20 && c != 0x09) ||
		    (c > 0x7E && c < 0xA0))
			c = 0xFFFD;
		if (c > 0x7E)
			printf("&#%d;", c);
		else if ( ! print_escape(c))
			putchar(c);
	}

	return nospace;
}
Example #7
0
main(int argc, char *argv[])
#endif
{
	char *fmt, *start;
	int fieldwidth, precision;
	char convch, nextch;
	char *format;

#if !defined(SHELL) && !defined(BUILTIN)
	setlocale (LC_ALL, "");
#endif

	/* Need to accept/ignore "--" option. */
	if (argc > 1 && strcmp(argv[1], "--") == 0) {
		argc--;
		argv++;
	}

	if (argc < 2) {
		usage();
		return (1);
	}

	format = *++argv;
	gargv = ++argv;

#define SKIP1	"#-+ 0"
#define SKIP2	"*0123456789"
	do {
		/*
		 * Basic algorithm is to scan the format string for conversion
		 * specifications -- once one is found, find out if the field
		 * width or precision is a '*'; if it is, gather up value. 
		 * Note, format strings are reused as necessary to use up the
		 * provided arguments, arguments of zero/null string are 
		 * provided to use up the format string.
		 */

		/* find next format specification */
		for (fmt = format; *fmt; fmt++) {
			switch (*fmt) {
			case '%':
				start = fmt++;

				if (*fmt == '%') {
					putchar ('%');
					break;
				} else if (*fmt == 'b') {
					char *p = getstr();
					if (print_escape_str(p)) {
						return (rval);
					}
					break;
				}

				/* skip to field width */
				for (; strchr(SKIP1, *fmt); ++fmt) ;
				fieldwidth = *fmt == '*' ? getint() : 0;

				/* skip to possible '.', get following precision */
				for (; strchr(SKIP2, *fmt); ++fmt) ;
				if (*fmt == '.')
					++fmt;
				precision = *fmt == '*' ? getint() : 0;

				for (; strchr(SKIP2, *fmt); ++fmt) ;
				if (!*fmt) {
					warnx ("missing format character");
					return(1);
				}

				convch = *fmt;
				nextch = *(fmt + 1);
				*(fmt + 1) = '\0';
				switch(convch) {
				case 'c': {
					char p = getchr();
					PF(start, p);
					break;
				}
				case 's': {
					char *p = getstr();
					PF(start, p);
					break;
				}
				case 'd':
				case 'i': {
					long p;
					char *f = mklong(start, convch);
					if (!f) {
						warnx("out of memory");
						return (1);
					}
					p = getlong();
					PF(f, p);
					break;
				}
				case 'o':
				case 'u':
				case 'x':
				case 'X': {
					unsigned long p;
					char *f = mklong(start, convch);
					if (!f) {
						warnx("out of memory");
						return (1);
					}
					p = getulong();
					PF(f, p);
					break;
				}
				case 'e':
				case 'E':
				case 'f':
				case 'g':
				case 'G': {
					double p = getdouble();
					PF(start, p);
					break;
				}
				default:
					warnx ("%s: invalid directive", start);
					return(1);
				}
				*(fmt + 1) = nextch;
				break;

			case '\\':
				fmt += print_escape(fmt);
				break;

			default:
				putchar (*fmt);
				break;
			}
		}
	} while (gargv > argv && *gargv);

	return (rval);
}
Example #8
0
int main(int argc, char **argv) {
  char *x, *me = argv[0];
  char *last_msg = "\\c";
  errmsg_iam(me);
  if (argc<2) {
  help:
    errmsg_iam(0);
    carp(Kill_Help);
    _exit(1);
  }
  argv++;
  x = argv[0];
  if (x[0]=='-' && x[1]=='h') goto help; /* -h... --help */

  opendevconsole();

  /* ignore next signals */
  set_sa(SIGQUIT); set_sa(SIGCHLD); set_sa(SIGHUP );
  set_sa(SIGTSTP); set_sa(SIGTTIN); set_sa(SIGTTOU);

  while (argv[0] && argv[0][0]=='-') {
    int sig=0, cfg_wall=0;
    char *y = argv[0] + 1;
    if ((unsigned int)(*y - '0') < 10) { 
      sig = x_atoi(y);
      goto again;
    }
    
    switch(*y) {
    case 'v': cfg_verbose++; if (y[1]=='v') cfg_verbose++; break;
    case 'q': set_sa(SIGINT); break;
    case 's': chk_opt(argv,x); deep_sleep(x); break;
    case 'W': ++cfg_wall;
    case 'M': chk_opt(argv,x);
      if (x[0] == '%' && x[1] == 0) x = last_msg;
      else last_msg = x;
      print_escape(x, cfg_wall); 
      break;
    case 'E':
      chk_opt(argv,x); *argv = x;
      execve(argv[0], argv, environ);
      carp("Unable to exec: ", argv[0]);
      _exit(1);
    default:
#ifdef NSVC_SIGNAL_CODED
      {
	unsigned char *S, *Sig = (unsigned char *)NSVC_SIGNAL_CODED;
	for (S=Sig; *S; S += 2)
	  if ((unsigned char)*y == *S) { sig = S[1]; goto again; }
      }
#else
#define kk(C,S) case C: sig=S; break
	kk('t',SIGTERM); kk('a',SIGALRM); kk('p',SIGSTOP); kk('c',SIGCONT);
	kk('h',SIGHUP);  kk('i',SIGINT);  kk('k',SIGKILL);
#endif
      goto help;
    }

  again:
    if (sig > 0) {
      sync();
      if (cfg_verbose) msg("Sending signal: ", y);
      if (kill(-1, sig)) carp("Unable to send signal: ", y);
    }
    argv++;
  }
  sync();
  return 0;
}
Example #9
0
/*
 * auparse_callback - callback routine to be executed once a complete event is composed
 */
void
auparse_callback(auparse_state_t * au, auparse_cb_event_t cb_event_type,
                 void *user_data)
{
    int *event_cnt = (int *) user_data;

    if (cb_event_type == AUPARSE_CB_EVENT_READY) {
        if (auparse_first_record(au) <= 0)
            return;             /* If no first record, then no event ! */

        if (!(flags & F_CHECK))
            printf("event=%d records=%d\n", *event_cnt,
                   auparse_get_num_records(au));
        do {
            const au_event_t *e = auparse_get_timestamp(au);
            if (e == NULL)
                return;         /* If no timestamp, then no event */

            /* If checking, we just emit the raw record again
             */
            if (flags & F_CHECK) {
                if (e->host != NULL)
                    printf("node=%s type=%s msg=audit(%u.%3.3u:%lu):",
                           e->host, auparse_get_type_name(au),
                           (unsigned) e->sec, e->milli, e->serial);
                else
                    printf("type=%s msg=audit(%u.%3.3u:%lu):",
                           auparse_get_type_name(au),
                           (unsigned) e->sec, e->milli, e->serial);
                auparse_first_field(au);        /* Move to first field */
                do {
                    const char *fname = auparse_get_field_name(au);

                    /* We ignore the node and type fields */
                    if (strcmp(fname, "type") == 0
                        || strcmp(fname, "node") == 0)
                        continue;
                    printf(" %s=%s", fname, auparse_get_field_str(au));
                } while (auparse_next_field(au) > 0);
                printf("\n");
                continue;
            }

            printf("fields=%d\t", auparse_get_num_fields(au));
            printf("type=%d (%s) ", auparse_get_type(au),
                   auparse_get_type_name(au));
            printf("event_tid=%u.%3.3u:%lu ",
                   (unsigned) e->sec, e->milli, e->serial);
            if (flags & F_VERBOSE) {
                char *fv, *ifv = NULL;
                auparse_first_field(au);        /* Move to first field */
                do {
                    fv = (char *) auparse_get_field_str(au);
                    ifv = (char *) auparse_interpret_field(au);
                    printf("%s=", auparse_get_field_name(au));
                    print_escape(stdout, fv, "=()");
                    printf(" (");
                    print_escape(stdout, ifv, "=()");
                    printf(") ");
                }
                while (auparse_next_field(au) > 0);
            }
            printf("\n");
        }
        while (auparse_next_record(au) > 0);
        (*event_cnt)++;
    }
}