// -.1  Command-installing command.  Install manually as COM 2
MakeNotPendingDelete MakeSecondary Operations ToPrimary EditText MakePDel DoEdit CommandNumber "1"

// -.05 Do current substitution.  Install as COM 3
DoSubstitute

// 0. Provide type definitions for all procedure parameters and return values, and
//		for all "let" variables.  Manually.

// 1. Replace BCPL Comments by C Comments throughout

PushSelection MatchPattern MatchAnywhere SubstituteInEntireDoc SearchFor "//<comment>" InsertLineBreak ReplaceBy "/*<comment> */" InsertLineBreak PopSelection DoSubstitute PushSelection SearchFor "*/" InsertLineBreak "/*" ReplaceBy InsertLineBreak "  " MatchLiterally PopSelection DoSubstitute

// 2. Change "get" to "include" throughout

PushSelection MatchPattern MatchAnywhere SubstituteInEntireDoc SearchFor "get \'\"<whatever>.decl\'\"" InsertLineBreak ReplaceBy "#include \'<<whatever>.h\'>" InsertLineBreak PopSelection DoSubstitute

// 3. Manifests become defines throughout -- manual "Yes"
PushSelection MatchPattern MatchAnywhere SubstituteInEntireDoc SearchFor "manifest <name:&><stuff:~&>=<value>" InsertLineBreak ReplaceBy "#define <name> <value>" InsertLineBreak PopSelection


// 4. Fix "size" specifications

PushSelection MatchPattern MatchAnywhere SubstituteInEntireDoc SearchFor "\'#define <name:&> {size <whatever>/16}" InsertLineBreak ReplaceBy "(sizeof (<whatever>)/2)" InsertLineBreak PopSelection


// 5. Simple subst, bracket, semicolon transformations.

PushSelection MatchPattern MatchAnywhere SubstituteInEntireDoc SearchFor "structure <name>:<stuff>[" ReplaceBy "struct <name><stuff>{" PopSelection DoSubstitute PushSelection SearchFor "[" ReplaceBy "{" PopSelection DoSubstitute PushSelection SearchFor "]" ReplaceBy ";};" PopSelection DoSubstitute
PushSelection SearchFor " ;" ReplaceBy "; " PopSelection DoSubstitute PushSelection SearchFor ";;" ReplaceBy ";" PopSelection DoSubstitute

//5.5 Exchange types and ids in structure specifications

PushSelection SearchFor "<word:@&><sep:%$><otherword:@&><del:~@>" MatchLiterally MatchPattern SubstituteInSel ReplaceBy "<otherword><sep><word>;<del>" PopSelection

// 6. Clean up structure references (simple minded -- assume all right lumps.)

PushSelection MatchLiterally MatchAnywhere SubstituteInEntireDoc SearchFor ">>" ReplaceBy "++" PopSelection DoSubstitute PushSelection MatchPattern SearchFor "++<struct>." ReplaceBy "->" PopSelection DoSubstitute


// 7. More simple substitutions, statement level

PushSelection  MatchLiterally MatchWords SubstituteInEntireDoc SearchFor "resultis" ReplaceBy "return" PopSelection DoSubstitute

PushSelection MatchLiterally MatchAnywhere SubstituteInEntireDoc SearchFor "lv " ReplaceBy "&" PopSelection DoSubstitute

PushSelection MatchLiterally MatchAnywhere SubstituteInEntireDoc SearchFor "@" ReplaceBy "*" PopSelection DoSubstitute

// 8. Control structures
// First, eliminate all ifs that don't have matching thens.  Manually.
// Then run this.  You get to do the actual searching.

PushSelection MatchPattern MatchAnywhere SubstituteInEntireDoc SearchFor "if <pred><del:~&>then" ReplaceBy "if (<pred>)<del>" PopSelection

PushSelection MatchPattern MatchAnywhere SubstituteInEntireDoc SearchFor "test <pred><del:~&>ifso" ReplaceBy "if (<pred>)<del>" PopSelection

PushSelection MatchPattern MatchAnywhere SubstituteInEntireDoc SearchFor "<del:~@>ifnot" ReplaceBy "<del>;else" PopSelection

PushSelection MatchPattern MatchAnywhere SubstituteInEntireDoc SearchFor "while <something> do" ReplaceBy "while (<something>)" PopSelection

PushSelection MatchPattern MatchAnywhere SubstituteInEntireDoc SearchFor "switchon <something> into" ReplaceBy "switch (<something>)" PopSelection

PushSelection MatchPattern MatchAnywhere SubstituteInEntireDoc SearchFor "selecton <something> into" // You've got to deal with this one.

// Indexing -- doesn't do very well.

PushSelection MatchLiterally MatchAnywhere SubstituteInEntireDoc SearchFor "!(" ReplaceBy ":::(" PopSelection

PushSelection MatchPattern SearchFor MatchAnywhere SubstituteInEntireDoc SearchFor ":::(<something>)" ReplaceBy "[<something>]" PopSelection

// Conditionals

PushSelection  MatchLiterally MatchWords SubstituteInEntireDoc SearchFor "eq" ReplaceBy "==" PopSelection DoSubstitute PushSelection SearchFor "ne" ReplaceBy "!=" PopSelection DoSubstitute PushSelection SearchFor "le" ReplaceBy "<=" PopSelection DoSubstitute PushSelection SearchFor "ge" ReplaceBy ">=" PopSelection DoSubstitute PushSelection SearchFor "gr" ReplaceBy ">" PopSelection DoSubstitute PushSelection SearchFor "ls" ReplaceBy "<" PopSelection DoSubstitute

// External declarations; repair by adding return types.

PushSelection  MatchPattern MatchAnywhere SearchFor InsertLineBreak "{	<name:&>}" InsertLineBreak ReplaceBy "extern <name>();" PopSelection