view toys/sed.c @ 237:7cb15eae1664

Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS() macros in each C file, and making generated/globals.h from that. Rename "toy" to "this" along the way to avoid toy/toys confusion.
author Rob Landley <>
date Sun, 20 Jan 2008 17:25:44 -0600
parents 163498bf547b
line wrap: on
line source

/* vi: set sw=4 ts=4:
 * sed.c - Stream editor.
 * Copyright 2008 Rob Landley <>
 * See


config SED
	bool "sed"
	default n
	  usage: sed [-irn] {command | [-e command]...} [FILE...]

	  Stream EDitor, transforms text by appling commands to each line
	  of input.

#include "toys.h"
#include "lib/xregcomp.h"

	struct arg_list *commands;

#define TT this.sed

struct sed_command {
	// Doubly linked list of commands.
	struct sed_command *next, *prev;

	// Regexes for s/match/data/ and /match_begin/,/match_end/command
	regex_t *match, *match_begin, *match_end;

	// For numeric ranges ala 10,20command
	int first_line, last_line;

	// Which match to replace, 0 for all.
	int which;

	// s and w commands can write to a file.  Slight optimization: we use 0
	// instead of -1 to mean no file here, because even when there's no stdin
	// our input file would take fd 0.
	int outfd;

	// Data string for (saicytb)
	char *data;

	// Which command letter is this?
	char command;

void sed_main(void)
	struct arg_list *test;

	for (test = TT.commands; test; test = test->next)

	printf("Hello world\n");