code: def append_needs(need, flag=1):
      # This function modifies the contents of the global `outneeds` dict.
      if isinstance(need, list):
          for n in need:
              append_needs(n, flag)
      elif isinstance(need, str):
          if not need:
              return
          if need in includes0:
              n = "includes0"
          elif need in includes:
              n = "includes"
          elif need in typedefs:
              n = "typedefs"
          elif need in typedefs_generated:
              n = "typedefs_generated"
          elif need in cppmacros:
              n = "cppmacros"
          elif need in cfuncs:
              n = "cfuncs"
          elif need in callbacks:
              n = "callbacks"
          elif need in f90modhooks:
              n = "f90modhooks"
          elif need in commonhooks:
              n = "commonhooks"
          else:
              errmess("append_needs: unknown need %s\n" % (repr(need)))
              return
          if need in outneeds[n]:
              return
          if flag:
              tmp = {}
              if need in needs:
                  for nn in needs[need]:
                      t = append_needs(nn, 0)
                      if isinstance(t, dict):
                          for nnn in t.keys():
                              if nnn in tmp:
                                  tmp[nnn] = tmp[nnn] + t[nnn]
                              else:
                                  tmp[nnn] = t[nnn]
              for nn in tmp.keys():
                  for nnn in tmp[nn]:
                      if nnn not in outneeds[nn]:
                          outneeds[nn] = [nnn] + outneeds[nn]
              outneeds[n].append(need)
          else:
              tmp = {}
              if need in needs:
                  for nn in needs[need]:
                      t = append_needs(nn, flag)
                      if isinstance(t, dict):
                          for nnn in t.keys():
                              if nnn in tmp:
                                  tmp[nnn] = t[nnn] + tmp[nnn]
                              else:
                                  tmp[nnn] = t[nnn]
              if n not in tmp:
                  tmp[n] = []
              tmp[n].append(need)
              return tmp
      else:
          errmess(
              "append_needs: expected list or string but got :%s\n"
              % (repr(need))
          )
  
imports: import sys
  import copy
  from .None import __version__
label_desc: Use image node_id 2 for calling a global function with example usage: append_needs(need, flag) and returns: tmp