All pastes #975131 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-04-07 09:37 UTC
rendered paste body
#!/bin/awk -f

# Tool to convert spr files
# Usage: update_spr.awk [input spr file] > [output spr file]

{
  gsub(/\r/,"");
}

/<plugin>/,/<\/plugin>/ {
  match($0, /crystalspace.mesh.loader.[a-zA-Z0-9\.]*/, array)
  PLUGIN = array[0];
}

/<meshfact name=\".*>/ {
  match($0, /<meshfact name=\".*>/, array)
  MESHFACT_NAME = array[0];
}

/\/planeshift\/.*\/.*\.dds/ {
  match($0, /\/planeshift\/.*\/.*\.dds/, array)
  MATERIAL_NAME = array[0];
}

/^[ \t]*<num/,/<\/num/ {
  gsub(/^[ \t]+|[ \t]+$/,"");
  if (NUM_SECTION == "")
    NUM_SECTION = "\t\t" ($0);
  else
    NUM_SECTION = (NUM_SECTION) "\n\t\t" ($0);
}

/^.*<v / {
  gsub(/^[ \t]+|[ \t]+$/,"");
  if (V_SECTION == "")
    V_SECTION = "\t\t\t" ($0);
  else
    V_SECTION = (V_SECTION) "\n\t\t\t" ($0);
}

/^.*<t / {
  gsub(/^[ \t]+|[ \t]+$/,"");
  if (T_SECTION == "")
    T_SECTION = "\t\t" ($0);
  else
    T_SECTION = (T_SECTION) "\n\t\t" ($0);
}

/<.*smooth>.*<\/.*smooth>/ {
  match($0, /<smooth>.*<\/smooth>/, array)
  SMOOTH = "\t\t" array[0];
}

/<noshadows\/>/ {
  match($0, /<noshadows>/, array)
  NOSHADOWS = "\t\t" array[0];
}

/<autonormals\/>/ {
  match($0, /<autonormals\/>/, array)
  AUTONORMALS = "\t\t" array[0];
}


END {
  print MESHFACT_NAME;
  if (PLUGIN != "") {
    print "\t<plugin>" (PLUGIN) "</plugin>";
  } else {
    print "\t<plugin>crystalspace.mesh.loader.factory.sprite.3d</plugin>";
  }
  print "\t<params>";
  print "\t\t<material>" (MATERIAL_NAME) "</material>";
  if (NUM_SECTION != "") {
    print NUM_SECTION;
  }
  print "\t\t<frame name=\"stand0\">";
  print V_SECTION;
  print "\t\t</frame>";
  print "";
  print "\t\t<action name=\"stand\"><f name=\"stand0\" delay=\"100\" /></action>";
  print "";
  print T_SECTION;
  if (SMOOTH != "") {
    print SMOOTH;
  }
  if (NOSHADOWS != "") {
    print NOSHADOWS;
  }
  if (AUTONORMALS != "") {
    print AUTONORMALS;
  }
  print "\t</params>";
  print "</meshfact>";

  if (MESHFACT_NAME == "")
    print "Error! no meshfact name.";
  if (MATERIAL_NAME == "")
    print "Error! no material name.";
}