Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
1.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: thsplit.c
  7. //
  8. // Contents: File splitter tool for the thunk tool
  9. //
  10. // History: 22-Feb-94 DrewB Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16. void __cdecl main(int argc, char **argv)
  17. {
  18. FILE *in, *out;
  19. char line[256];
  20. char ofile[32], nfile[32], *n, *l;
  21. if (argc != 2)
  22. {
  23. printf("Usage: %s multifile\n", argv[0]);
  24. exit(1);
  25. }
  26. in = fopen(argv[1], "r");
  27. if (in == NULL)
  28. {
  29. perror(argv[1]);
  30. exit(1);
  31. }
  32. out = NULL;
  33. for (;;)
  34. {
  35. if (fgets(line, 256, in) == NULL)
  36. break;
  37. if (strncmp(line, "|- ", 3) == 0)
  38. {
  39. n = nfile;
  40. l = line+3;
  41. while (*l != ' ')
  42. *n++ = *l++;
  43. *n = 0;
  44. if (out != NULL && strcmp(nfile, ofile) != 0)
  45. {
  46. printf("Section '%s' started while section '%s' was active\n",
  47. nfile, ofile);
  48. fclose(out);
  49. out = NULL;
  50. }
  51. if (out == NULL)
  52. {
  53. out = fopen(nfile, "a");
  54. if (out == NULL)
  55. {
  56. perror(nfile);
  57. exit(1);
  58. }
  59. strcpy(ofile, nfile);
  60. }
  61. else
  62. {
  63. fclose(out);
  64. out = NULL;
  65. }
  66. }
  67. else
  68. {
  69. if (out)
  70. {
  71. fprintf(out, "%s", line);
  72. }
  73. }
  74. }
  75. if (out != NULL)
  76. {
  77. printf("Unterminated section '%s'\n", ofile);
  78. fclose(out);
  79. }
  80. fclose(in);
  81. }