Subversion Repositories SvarDOS

Rev

Rev 1602 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1602 Rev 1681
Line 1... Line 1...
1
/*
1
/*
2
 * PKG - SvarDOS package manager
2
 * PKG - SvarDOS package manager
3
 *
3
 *
4
 * PUBLISHED UNDER THE TERMS OF THE MIT LICENSE
4
 * PUBLISHED UNDER THE TERMS OF THE MIT LICENSE
5
 *
5
 *
6
 * COPYRIGHT (C) 2016-2023 MATEUSZ VISTE, ALL RIGHTS RESERVED.
6
 * COPYRIGHT (C) 2016-2024 MATEUSZ VISTE, ALL RIGHTS RESERVED.
7
 *
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a
8
 * Permission is hereby granted, free of charge, to any person obtaining a
9
 * copy of this software and associated documentation files (the "Software"),
9
 * copy of this software and associated documentation files (the "Software"),
10
 * to deal in the Software without restriction, including without limitation
10
 * to deal in the Software without restriction, including without limitation
11
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Line 28... Line 28...
28
#include <stdio.h>    /* printf() */
28
#include <stdio.h>    /* printf() */
29
#include <stdlib.h>   /* malloc() and friends */
29
#include <stdlib.h>   /* malloc() and friends */
30
#include <string.h>   /* strcasecmp() */
30
#include <string.h>   /* strcasecmp() */
31
 
31
 
32
#include "svarlang.lib/svarlang.h"
32
#include "svarlang.lib/svarlang.h"
-
 
33
#include "crc32.h"
33
#include "helpers.h"
34
#include "helpers.h"
34
#include "kprintf.h"
35
#include "kprintf.h"
35
#include "libunzip.h"
36
#include "libunzip.h"
36
#include "pkginst.h"
37
#include "pkginst.h"
37
#include "pkgrem.h"
38
#include "pkgrem.h"
Line 45... Line 46...
45
  ACTION_UPDATE,
46
  ACTION_UPDATE,
46
  ACTION_REMOVE,
47
  ACTION_REMOVE,
47
  ACTION_LISTFILES,
48
  ACTION_LISTFILES,
48
  ACTION_LISTLOCAL,
49
  ACTION_LISTLOCAL,
49
  ACTION_UNZIP,
50
  ACTION_UNZIP,
-
 
51
  ACTION_CRC32,
50
  ACTION_HELP
52
  ACTION_HELP
51
};
53
};
52
 
54
 
53
 
55
 
54
static int showhelp(void) {
56
static int showhelp(void) {
Line 60... Line 62...
60
  puts(svarlang_str(1, 21)); /* "       pkg update package.svp" */
62
  puts(svarlang_str(1, 21)); /* "       pkg update package.svp" */
61
  puts(svarlang_str(1, 22)); /* "       pkg remove package" */
63
  puts(svarlang_str(1, 22)); /* "       pkg remove package" */
62
  puts(svarlang_str(1, 23)); /* "       pkg listfiles package" */
64
  puts(svarlang_str(1, 23)); /* "       pkg listfiles package" */
63
  puts(svarlang_str(1, 24)); /* "       pkg listlocal [filter]" */
65
  puts(svarlang_str(1, 24)); /* "       pkg listlocal [filter]" */
64
  puts(svarlang_str(1, 27)); /* "       pkg unzip file.zip" */
66
  puts(svarlang_str(1, 27)); /* "       pkg unzip file.zip" */
-
 
67
  puts(svarlang_str(1, 28)); /* "       pkg crc32 file" */
65
  puts("");
68
  puts("");
66
  puts(svarlang_str(1, 25)); /* "PKG is published under the MIT license." */
69
  puts(svarlang_str(1, 25)); /* "PKG is published under the MIT license." */
67
  puts(svarlang_str(1, 26)); /* "It is configured through %DOSDIR%\CFG\PKG.CFG" */
70
  puts(svarlang_str(1, 26)); /* "It is configured through %DOSDIR%\CFG\PKG.CFG" */
68
  return(1);
71
  return(1);
69
}
72
}
Line 81... Line 84...
81
    return(ACTION_LISTFILES);
84
    return(ACTION_LISTFILES);
82
  } else if ((argc >= 2) && (argc <= 3) && (strcasecmp(argv[1], "listlocal") == 0)) {
85
  } else if ((argc >= 2) && (argc <= 3) && (strcasecmp(argv[1], "listlocal") == 0)) {
83
    return(ACTION_LISTLOCAL);
86
    return(ACTION_LISTLOCAL);
84
  } else if ((argc == 3) && (strcasecmp(argv[1], "unzip") == 0)) {
87
  } else if ((argc == 3) && (strcasecmp(argv[1], "unzip") == 0)) {
85
    return(ACTION_UNZIP);
88
    return(ACTION_UNZIP);
-
 
89
  } else if ((argc == 3) && (strcasecmp(argv[1], "crc32") == 0)) {
-
 
90
    return(ACTION_CRC32);
86
  } else {
91
  } else {
87
    return(ACTION_HELP);
92
    return(ACTION_HELP);
88
  }
93
  }
89
}
94
}
90
 
95
 
Line 128... Line 133...
128
  fclose(zipfilefd);
133
  fclose(zipfilefd);
129
  return(res);
134
  return(res);
130
}
135
}
131
 
136
 
132
 
137
 
-
 
138
/* pkg crc32 file */
-
 
139
static int crcfile(const char *fname) {
-
 
140
  FILE *fd;
-
 
141
  unsigned long crc;
-
 
142
  unsigned char buff[512];
-
 
143
  unsigned int len;
-
 
144
 
-
 
145
  fd = fopen(fname, "rb");
-
 
146
  if (fd == NULL) {
-
 
147
    puts(svarlang_str(10, 1)); /* failed to open file */
-
 
148
    return(1);
-
 
149
  }
-
 
150
 
-
 
151
  crc = crc32_init();
-
 
152
 
-
 
153
  for (;;) {
-
 
154
    len = fread(buff, 1, sizeof(buff), fd);
-
 
155
    if (len == 0) break;
-
 
156
    crc32_feed(&crc, buff, len);
-
 
157
  }
-
 
158
  fclose(fd);
-
 
159
 
-
 
160
  crc32_finish(&crc);
-
 
161
 
-
 
162
  printf("%08lX", crc);
-
 
163
  puts("");
-
 
164
 
-
 
165
  return(0);
-
 
166
}
-
 
167
 
-
 
168
 
133
int main(int argc, char **argv) {
169
int main(int argc, char **argv) {
134
  int res = 1;
170
  int res = 1;
135
  enum ACTIONTYPES action;
171
  enum ACTIONTYPES action;
136
  const char *dosdir;
172
  const char *dosdir;
137
  struct customdirs *dirlist;
173
  struct customdirs *dirlist;
Line 146... Line 182...
146
      break;
182
      break;
147
    case ACTION_UNZIP:
183
    case ACTION_UNZIP:
148
      res = unzip(argv[2]);
184
      res = unzip(argv[2]);
149
      goto GAMEOVER;
185
      goto GAMEOVER;
150
      break;
186
      break;
-
 
187
    case ACTION_CRC32:
-
 
188
      res = crcfile(argv[2]);
-
 
189
      goto GAMEOVER;
-
 
190
      break;
151
  }
191
  }
152
 
192
 
153
  /* read the DOSDIR environment variable */
193
  /* read the DOSDIR environment variable */
154
  dosdir = getenv("DOSDIR");
194
  dosdir = getenv("DOSDIR");
155
  if (dosdir == NULL) {
195
  if (dosdir == NULL) {