shithub: rewise

Download patch

ref: eefded827f06cef7aca1ff2fc4900facd856d272
parent: ef725ba3b6bb81ca2fe0aa3d37e920cdbb429c20
author: Jacob Moody <moody@posixcafe.org>
date: Sun May 7 16:13:01 EDT 2023

initial plan9 port

--- /dev/null
+++ b/src/mkfile
@@ -1,0 +1,29 @@
+</$objtype/mkfile
+
+CFLAGS=$CLFAGS -p -I ../../include -I/sys/include/npe -I libpng -I zlib -D__plan9__ -D__${objtype}__ $POSIX -DSTDC
+
+HFILES=\
+	print.h \
+	reader.h \
+	crc32.h \
+	inflate.h \
+	pefile.h \
+	wiseoverlay.h \
+	version.h \
+	errors.h
+
+OFILES=\
+	wisescript.$O \
+	wisescript.$O \
+	rewise.$O \
+	print.$O \
+	reader.$O \
+	crc32.$O \
+	inflate.$O \
+	pefile.$O \
+	wiseoverlay.$O \
+	getopt.$O \
+
+TARG=rewise
+
+</sys/src/cmd/mkone
--- a/src/rewise.c
+++ b/src/rewise.c
@@ -18,18 +18,16 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
-#include <getopt.h>
+#include "getopt.h"
 #include <time.h>
-#include <libgen.h> // dirname
+#include <libgen.h>
 #include <errno.h>
 #include <sys/stat.h> // mkdir
-#include <utime.h>
-#include <sys/statvfs.h>
 
 // PATH_MAX, NAME_MAX
 #ifdef __linux__
 #include <linux/limits.h>
-#elif defined(__CYGWIN__) || defined(_WIN32) || defined(_WIN64)
+#elif defined(__CYGWIN__) || defined(_WIN32) || defined(_WIN64) || defined(__plan9__)
 #include <limits.h>
 #endif
 
@@ -83,6 +81,7 @@
 
 
 unsigned long getFreeDiskSpace(char * path) {
+/*
   struct statvfs fsStats;
   if (statvfs((const char *)path, &fsStats) != 0) {
     printError("Failed to determine free disk space for '%s'. Errno: %s\n",
@@ -89,17 +88,19 @@
                strerror(errno));
     return 0;
   }
-  return fsStats.f_bsize * fsStats.f_bavail;
+  return fsStats.f_bsize * fsStats.f_bavail
+*/
+  return 0;
 }
 
 
 void convertMsDosTime(struct tm * destTime, uint16_t date, uint16_t time) {
   destTime->tm_year = (int)((date >> 9) + 80);
-  destTime->tm_mon  = (int)((date >> 5) & 0b0000000000001111);
-  destTime->tm_mday = (int)(date & 0b0000000000011111);
+  destTime->tm_mon  = (int)((date >> 5) & 0xf);
+  destTime->tm_mday = (int)(date & 0x1f);
   destTime->tm_hour = (int)(time >> 11);
-  destTime->tm_min  = (int)((time >> 5) & 0b0000000000111111);
-  destTime->tm_sec  = (int)(time & 0b0000000000011111) * 2;
+  destTime->tm_min  = (int)((time >> 5) & 0x3f);
+  destTime->tm_sec  = (int)(time & 0x1f) * 2;
 }
 
 static InflateObject * InflateObjPtr;
@@ -206,6 +207,7 @@
       // stat currentSubPath
       if (access(currentSubPath, F_OK) != 0) {
         // currentSubPath exists but is not a directory
+#ifndef __plan9__
         if (errno == ENOTDIR) {
           printError("Extract subpath '%s' exists but is not a directory!\n",
                      currentSubPath);
@@ -212,6 +214,7 @@
           free(outputFilePath);
           return false;
         }
+#endif
 
         // currentSubPath does not exist, try to create a new directory
         if (errno == ENOENT) {
@@ -236,6 +239,7 @@
 
   // last subdir
   if (access(currentSubPath, F_OK) != 0) {
+#ifndef __plan9__
     // currentSubPath exists but is not a directory
     if (errno == ENOTDIR) {
       printError("Extract path '%s' exists but is not a directory!\n",
@@ -243,6 +247,7 @@
       free(outputFilePath);
       return false;
     }
+#endif
 
     // currentSubPath does not exist, try to create a new directory
     if (errno == ENOENT) {
@@ -295,6 +300,7 @@
   time_t creationSeconds;
   convertMsDosTime(&fileCreation, data->date, data->time);
   creationSeconds = mktime(&fileCreation);
+#ifndef __plan9__
   const struct utimbuf times = {
     .actime  = creationSeconds,
     .modtime = creationSeconds
@@ -303,6 +309,7 @@
     printWarning("Failed to set access and modification datetime for file "
                  "'%s'\n", outputFilePath);
   }
+#endif
 
   printInfo("Extracted %s\n", data->destFile);
 }
@@ -343,11 +350,13 @@
 
   // Make sure the path exists
   if (access(dest, F_OK) != 0) {
+#ifndef __plan9__
     // dest exists but is not a directory
     if (errno == ENOTDIR) {
       printError("'%s' is not a directory.\n", dest);
       return false;
     }
+#endif
     // NOTE: realpath would have failed when the directory does not exist.
     // dest does not exist
     /*if (errno == ENOENT) {
@@ -391,7 +400,7 @@
   int option_index = 0;
   for (;;) {
     int opt = getopt_long(argc, argv, "x:r:t:lhdspznVv",
-                          long_options, &option_index);
+                          long_options, &option_index, 0);
 
     if (opt == -1) {
       break;
--- a/src/wisescript.c
+++ b/src/wisescript.c
@@ -20,10 +20,13 @@
 
 #ifdef __linux__
 #include <linux/limits.h>
-#elif defined(__CYGWIN__) || defined(_WIN32) || defined(_WIN64)
+#elif defined(__CYGWIN__) || defined(_WIN32) || defined(_WIN64) || defined(__plan9__)
 #include <limits.h>
 #endif
 
+#ifdef __plan9__
+#define NAME_MAX 512
+#endif
 
 #include "wisescript.h"
 #include "reader.h"
@@ -1003,11 +1006,11 @@
 void printDatetime(uint16_t date, uint16_t time) {
   printf("%04d-%02d-%02d %02d:%02d:%02d",
          (date >> 9) + 1980,
-         (date >> 5) & 0b0000000000001111,
-         date & 0b0000000000011111,
+         (date >> 5) & 0xf,
+         date & 0x1f,
          (time >> 11),
-         (time >> 5) & 0b0000000000111111,
-         (time & 0b0000000000011111) * 2);
+         (time >> 5) & 0x3f,
+         (time & 0x1f) * 2);
 }
 
 void printHex(unsigned char * value, uint32_t size) {