; list - name of the list.
; list@count - count of the list items.

macro __search_list flag, list, item {
forward
  flag equ FALSE
  rept list#@count i:1 \{ match iitem, item \\{ match =iitem, list\\#i \\\{ define flag TRUE \\\} \\} \}
}


macro ppAddUniqueList list, [listitem] {
forward
  local fFound
  __search_list fFound, list, listitem
  match =FALSE, fFound \{
    rept 1 x:list#\@count+1 \\{
      list\\#@count equ x
      list\\#x equ listitem
    \\}
  \}
}

macro ppInitList list {
  list#@count equ 0
}



macro __InitInitializeEngine {
  local i,f,ci,cf
  ci equ 0
  cf equ 0

  macro add_initialize procname \{
    \common
    rept 1 x:ci+1 \\{
      ci equ x
      i\\#x equ procname
    \\}
  \}

  macro add_finalize procname \{
    \common
    rept 1 x:cf+1 \\{
      cf equ x
      f\\#x equ procname
    \\}
  \}

  macro initialize procname \{
    \common
    rept 1 x:ci+1 \\{
      ci equ x
      i\\#x equ procname
      proc procname
    \\}
  \}

  macro finalize procname \{
    \common
    rept 1 x:cf+1 \\{
      cf equ x
      f\\#x equ procname
      proc procname
    \\}
  \}


  macro InitializeAll \{
    \common
    rept ci x \\{
      \\forward
      if defined i\\#x
        call i\\#x
      end if
    \\}
  \}

  macro FinalizeAll \{
    \common
    rept cf x \\{
      \\reverse
      if defined f\\#x
        call f\\#x
      end if
    \\}
  \}
}

__InitInitializeEngine

