ProgArgs.java 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // Body of ProgArgs interface.
  3. // This file implements the code of the ProgArgs.cp file.
  4. // kjg December 1999.
  5. //
  6. // The reason that this module is implemented as a Java class is
  7. // that the name CPmain has special meaning to the compiler, so
  8. // it must be imported secretly in the implementation.
  9. //
  10. package CP.ProgArgs;
  11. import CP.CPmain.CPmain;
  12. public class ProgArgs
  13. {
  14. public static int ArgNumber()
  15. {
  16. if (CP.CPmain.CPmain.args == null)
  17. return 0;
  18. else
  19. return CP.CPmain.CPmain.args.length;
  20. }
  21. public static void GetArg(int num, char[] str)
  22. {
  23. int i;
  24. if (CP.CPmain.CPmain.args == null) {
  25. str[0] = '\0';
  26. } else {
  27. for (i = 0;
  28. i < str.length && i < CP.CPmain.CPmain.args[num].length();
  29. i++) {
  30. str[i] = CP.CPmain.CPmain.args[num].charAt(i);
  31. }
  32. if (i == str.length)
  33. i--;
  34. str[i] = '\0';
  35. }
  36. }
  37. public static void GetEnvVar(char[] ss, char[] ds)
  38. {
  39. String path = CP.CPJ.CPJ.MkStr(ss);
  40. //
  41. // getenv was deprecated between jave 1.1 and SE 5 (!)
  42. //
  43. String valu = System.getProperty(path);
  44. if (valu == null) // Try getenv instead
  45. valu = System.getenv(path);
  46. int i;
  47. for (i = 0;
  48. i < valu.length() && i < ds.length;
  49. i++) {
  50. ds[i] = valu.charAt(i);
  51. }
  52. if (i == ds.length)
  53. i--;
  54. ds[i] = '\0';
  55. }
  56. } // end of public class ProgArgs