callstub.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
  3. See the accompanying file LICENSE, version 2000-Apr-09 or later
  4. (the contents of which are also included in unzip.h) for terms of use.
  5. If, for some reason, these files are missing, the Info-ZIP license
  6. also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
  7. */
  8. #include <qdos.h>
  9. #include <limits.h>
  10. #include <string.h>
  11. struct
  12. {
  13. short flag1;
  14. short flag2;
  15. long offset; // The offset from &ds to unzipsfx exe
  16. long sfxlen; // size of unzipsfx program
  17. long sfxdsiz; // data size of unzipsfx program
  18. long sfxnam; // Name offset from start of sfxprog
  19. long ziplen; // size of zip file
  20. } ds = {0x4afb, 0x4afb, 0};
  21. typedef struct {short len; char chrs[1];} __QP_t;
  22. #define __QA(l) struct {short len; char chrs[(l)+1];}
  23. #define T1 \
  24. "\nThis is a self-extracting zip archive. In order to process the\n" \
  25. "archive you will be asked to give the name of a temporary directory\n" \
  26. "which must have at least as much free space as this SFX file.\n\n" \
  27. "You will also be asked for the name of the directory to which the\n" \
  28. "files are extracted. This directory _MUST_ exist. If you do not give\n" \
  29. "an output directory, the current default is used.\n\n\n" \
  30. "Device/directory for temporary files: "
  31. #define T2 "Device/directory to extract to : "
  32. #define T1LEN (sizeof(T1)-1)
  33. #define T2LEN (sizeof(T2)-1)
  34. static void xgetcwd (__QP_t *s)
  35. {
  36. extern char *_sys_var;
  37. static __QP_t **q;
  38. if (q = (__QP_t ** q) (_sys_var + 0xAC + 4))
  39. {
  40. memcpy (s->chrs, (*q)->chrs, (*q)->len);
  41. s->len = (*q)->len;
  42. *(s->chrs+s->len) = 0;
  43. }
  44. }
  45. int checkdir(__QP_t *dir)
  46. {
  47. qdirect_t s;
  48. int r,ch;
  49. if(dir->len > 1)
  50. {
  51. if(*(dir->chrs + dir->len-2) == '_')
  52. {
  53. *(dir->chrs + dir->len-1) = 0;
  54. dir->len--;
  55. }
  56. else
  57. {
  58. *(dir->chrs + dir->len-1) = '_';
  59. }
  60. }
  61. else
  62. {
  63. xgetcwd(dir);
  64. }
  65. r = ERR_NF;
  66. if((ch = io_open(dir->chrs, 4)) > 0)
  67. {
  68. if((r = fs_headr(ch, -1, &s, sizeof(s))) > 0)
  69. {
  70. r = (s.d_type == 0xff) ? 0 : ERR_NF;
  71. }
  72. io_close(ch);
  73. }
  74. return r;
  75. }
  76. int makesfx(__QP_t *tmp)
  77. {
  78. char *p = (char *)&ds;
  79. char *q;
  80. char txt[PATH_MAX];
  81. int fd,r = 0;
  82. qdirect_t qd;
  83. memcpy(txt, tmp->chrs, tmp->len);
  84. memcpy(txt+tmp->len, "SFX_EXE", 8);
  85. q = p + ds.offset;
  86. if((fd = io_open(txt, NEW_OVER)) > 0)
  87. {
  88. memcpy(txt+tmp->len+4, "DAT", 4);
  89. memcpy(q+ds.sfxnam, txt, tmp->len+8);
  90. fs_save(fd, q, ds.sfxlen);
  91. qd.d_length = ds.sfxlen;
  92. qd.d_datalen = ds.sfxdsiz;
  93. qd.d_type = 1;
  94. fs_heads(fd, -1, &qd, sizeof(qd));
  95. io_close(fd);
  96. if((fd = io_open(txt, NEW_OVER)) > 0)
  97. {
  98. q += ds.sfxlen;
  99. fs_save(fd, q, ds.ziplen);
  100. io_close(fd);
  101. }
  102. else r = fd;
  103. }
  104. else r = fd;
  105. return r;
  106. }
  107. #define T3 "\n\nTo extract the files, run the command \"LRUN "
  108. #define T4 "Press any key to exit "
  109. #define T3LEN (sizeof(T3)-1)
  110. #define T4LEN (sizeof(T4)-1)
  111. int unpackit ( __QP_t *tmpdir, __QP_t *outdir, char *basfil, int con)
  112. {
  113. int ch, r = 0;
  114. char c;
  115. memcpy(basfil, tmpdir->chrs,tmpdir->len);
  116. memcpy(basfil+tmpdir->len,"SFX_BAS", 8);
  117. if((ch = io_open(basfil, NEW_OVER)) > 0)
  118. {
  119. char *p,txt[80];
  120. int l;
  121. p = txt;
  122. *p++ = 'E';
  123. *p++ = 'W';
  124. *p++ = ' ';
  125. memcpy(p, tmpdir->chrs, tmpdir->len);
  126. p += tmpdir->len;
  127. memcpy(p, "SFX_EXE;'-d ", 12);
  128. p += 12;
  129. memcpy(p, outdir->chrs, outdir->len);
  130. p += outdir->len;
  131. *p++ = '\'';
  132. *p++ = '\n';
  133. io_sstrg(ch, -1, txt, (int)(p-txt));
  134. memcpy(txt, "delete ", 7);
  135. p = txt + 7;
  136. memcpy(p, tmpdir->chrs, tmpdir->len);
  137. p += tmpdir->len;
  138. memcpy(p, "SFX_EXE\n", 8);
  139. p += 4;
  140. l = (int)(p+4-txt);
  141. io_sstrg(ch, -1, txt, l);
  142. memcpy(p, "DAT\n", 4);
  143. io_sstrg(ch, -1, txt, l);
  144. memcpy(p, "BAS\n", 4);
  145. io_sstrg(ch, -1, txt, l);
  146. io_close(ch);
  147. makesfx((__QP_t *)tmpdir);
  148. }
  149. else r = ch;
  150. if(r == 0)
  151. {
  152. char t3[80];
  153. char *p;
  154. p = t3;
  155. memcpy(p, T3, T3LEN);
  156. p += T3LEN;
  157. memcpy (p, basfil, tmpdir->len+7);
  158. p += tmpdir->len+7;
  159. *p++ = '"';
  160. *p++ = '\n';
  161. io_sstrg(con, -1, t3, (int)(p-t3));
  162. }
  163. io_sstrg(con, -1, T4, T4LEN);
  164. io_fbyte(con, (5*60*50), &c);
  165. return r;
  166. }
  167. int main(void)
  168. {
  169. int con;
  170. int r,n;
  171. __QA(PATH_MAX) tmpdir;
  172. __QA(PATH_MAX) outdir;
  173. char basfil[PATH_MAX];
  174. con = io_open("con_480x160a16x38", 0);
  175. sd_bordr(con, -1, 7, 2);
  176. sd_clear(con, -1);
  177. sd_cure (con, -1);
  178. io_sstrg(con, -1, T1, T1LEN);
  179. if((tmpdir.len = io_fline(con, -1, tmpdir.chrs, PATH_MAX-1)) > 1)
  180. {
  181. if((r = checkdir((__QP_t *)&tmpdir)) == 0)
  182. {
  183. io_sstrg(con, -1, T2, T2LEN);
  184. if((outdir.len = io_fline(con, -1, outdir.chrs, PATH_MAX-1)) > 0)
  185. {
  186. if((r = checkdir((__QP_t *)&outdir)) == 0)
  187. {
  188. r = unpackit ((__QP_t *)&tmpdir, (__QP_t *)&outdir,
  189. basfil, con);
  190. }
  191. }
  192. }
  193. }
  194. sd_bordr(con, -1, 0, 0);
  195. sd_clear(con, -1);
  196. io_close(con);
  197. return r;
  198. }