arrayResizeImpl sname field@(StructField{ field_name = fname, field_array = farray, field_type = ftype })
 = case farray of
    Scalar -> undefined
    Fixed _ -> undefined
    Max _ -> do sayln' $ arrayResizeProto sname field ++ " {"
                sayln' $ "  if (nsize > " ++ arrayLenMax sname fname ++ ") return -1;"
                sayln' $ "  "
                sayln' $ "  if (0 == nsize) {"
                sayln' $ "    if (in->" ++ fname ++ ") {"
                sayln' $ "      free(in->" ++ fname ++ ");"
                sayln' $ "      in->" ++ fname ++ " = NULL;"
                sayln' $ "      in->" ++ arrayLen fname ++ " = 0;"
                sayln' $ "    }"
                sayln' $ "    return 0;"
                sayln' $ "  }"
                sayln' $ "  "
                sayln' $ "  " ++ fieldType ftype ++ "* temp = (" ++ fieldType ftype ++ "*)malloc(sizeof(*temp) * nsize);"
                sayln' $ "  if (!temp) return -1;"
                sayln' $ "  memset(temp, 0, sizeof(*temp) * nsize);"
                sayln' $ "  "
                sayln' $ "  " ++ intType IKUnsigned IS32 ++ " csize = in->" ++ arrayLen fname ++ ";"
                sayln' $ "  if (csize > nsize) csize = nsize;"
                sayln' $ "  memcpy(temp, in->" ++ fname ++ ", csize);"
                sayln' $ "  "
                sayln' $ "  free(in->" ++ fname ++ ");"
                sayln' $ "  in->" ++ fname ++ " = temp;";
                sayln' $ "  in->" ++ arrayLen fname ++ " = nsize;";
                sayln' $ "  return 0;"
                sayln' $ "}"
arrayResizeImpl sname field@(StructField{ field_name = fname, field_array = farray, field_type = ftype })
 = case farray of
    Scalar -> undefined
    Fixed _ -> undefined
    Max _ -> do sayln' $ arrayResizeProto sname field ++ " {"
                sayln' $ "  if (nsize > " ++ arrayLenMax sname fname ++ ") return -1;"
                sayln' $ "  "
                sayln' $ "  if (0 == nsize) {"
                sayln' $ "    if (in->" ++ fname ++ ") {"
                sayln' $ "      free(in->" ++ fname ++ ");"
                sayln' $ "      in->" ++ fname ++ " = NULL;"
                sayln' $ "      in->" ++ arrayLen fname ++ " = 0;"
                sayln' $ "    }"
                sayln' $ "    return 0;"
                sayln' $ "  }"
                sayln' $ "  "
                sayln' $ "  " ++ fieldType ftype ++ "* temp = (" ++ fieldType ftype ++ "*)malloc(sizeof(*temp) * nsize);"
                sayln' $ "  if (!temp) return -1;"
                sayln' $ "  memset(temp, 0, sizeof(*temp) * nsize);"
                sayln' $ "  "
                sayln' $ "  " ++ intType IKUnsigned IS32 ++ " csize = in->" ++ arrayLen fname ++ ";"
                sayln' $ "  if (csize > nsize) csize = nsize;"
                sayln' $ "  memcpy(temp, in->" ++ fname ++ ", csize);"
                sayln' $ "  "
                sayln' $ "  free(in->" ++ fname ++ ");"
                sayln' $ "  in->" ++ fname ++ " = temp;";
                sayln' $ "  in->" ++ arrayLen fname ++ " = nsize;";
                sayln' $ "  return 0;"
                sayln' $ "}"
arrayResizeImpl sname field@(StructField{ field_name = fname, field_array = farray, field_type = ftype })
 = case farray of
    Scalar -> undefined
    Fixed _ -> undefined
    Max _ -> do sayln' $ arrayResizeProto sname field ++ " {"
                sayln' $ "  if (nsize > " ++ arrayLenMax sname fname ++ ") return -1;"
                sayln' $ "  "
                sayln' $ "  if (0 == nsize) {"
                sayln' $ "    if (in->" ++ fname ++ ") {"
                sayln' $ "      free(in->" ++ fname ++ ");"
                sayln' $ "      in->" ++ fname ++ " = NULL;"
                sayln' $ "      in->" ++ arrayLen fname ++ " = 0;"
                sayln' $ "    }"
                sayln' $ "    return 0;"
                sayln' $ "  }"
                sayln' $ "  "
                sayln' $ "  " ++ fieldType ftype ++ "* temp = (" ++ fieldType ftype ++ "*)malloc(sizeof(*temp) * nsize);"
                sayln' $ "  if (!temp) return -1;"
                sayln' $ "  memset(temp, 0, sizeof(*temp) * nsize);"
                sayln' $ "  "
                sayln' $ "  " ++ intType IKUnsigned IS32 ++ " csize = in->" ++ arrayLen fname ++ ";"
                sayln' $ "  if (csize > nsize) csize = nsize;"
                sayln' $ "  memcpy(temp, in->" ++ fname ++ ", csize);"
                sayln' $ "  "
                sayln' $ "  free(in->" ++ fname ++ ");"
                sayln' $ "  in->" ++ fname ++ " = temp;";
                sayln' $ "  in->" ++ arrayLen fname ++ " = nsize;";
                sayln' $ "  return 0;"
                sayln' $ "}"