platform.h
author Ryan C. Gordon <icculus@icculus.org>
Wed, 18 May 2005 19:51:28 +0000
changeset 91 6db187bc77c7
parent 89 0befb9dfdee4
child 98 4912346d49c9
permissions -rw-r--r--
Let scripts run before and after each patch, and upon successful execution of all patches.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
#ifndef _INCL_PLATFORM_H_
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
#define _INCL_PLATFORM_H_
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
#ifdef __cplusplus
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
extern "C" {
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
#endif
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
36
9e60553d82bc Better fix for converting to Unix process exit codes.
Ryan C. Gordon <icculus@icculus.org>
parents: 27
diff changeset
     9
#define PATCHERROR    0
9e60553d82bc Better fix for converting to Unix process exit codes.
Ryan C. Gordon <icculus@icculus.org>
parents: 27
diff changeset
    10
#define PATCHSUCCESS  1
9e60553d82bc Better fix for converting to Unix process exit codes.
Ryan C. Gordon <icculus@icculus.org>
parents: 27
diff changeset
    11
0
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#if PLATFORM_WIN32
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
#  include <io.h>
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#  define PATH_SEP "\\"
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#  if (defined _MSC_VER)
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#    define inline __inline
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#    define snprintf _snprintf
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
#    define mkdir(x, y) _mkdir(x)
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
#    define chdir(x) _chdir(x)
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
#  endif
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
#  define MAX_PATH 1024
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
#elif PLATFORM_UNIX
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
#  include <unistd.h>
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
#  include <sys/stat.h>
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
#  include <sys/types.h>
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
#  include <sys/param.h>
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
#  include <fcntl.h>
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
#  define PATH_SEP "/"
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
#  define MAX_PATH MAXPATHLEN
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
#else
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
#  #error please define your platform.
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
#endif
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
typedef struct MOJOPATCH_FILELIST
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
{
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
    char *fname;
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
    struct MOJOPATCH_FILELIST *next;
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
} file_list;
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
91
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    40
typedef enum
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    41
{
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    42
    SPAWN_FILENOTFOUND,
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    43
    SPAWN_FAILED,
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    44
    SPAWN_RETURNGOOD,
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    45
    SPAWN_RETURNBAD
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    46
} SpawnResult;
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    47
0
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
/* Your mainline calls this. */
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
int mojopatch_main(int argc, char **argv);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
/* You call this for fatal error messages. */
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
void _fatal(const char *fmt, ...);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
/* Call this for logging (not debug info). */
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
void _log(const char *fmt, ...);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
/* Call this for logging (debug info). */
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
void _dlog(const char *fmt, ...);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
/* platform-specific stuff you implement. */
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
int file_exists(const char *fname);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
int file_is_directory(const char *fname);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
int file_is_symlink(const char *fname);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
file_list *make_filelist(const char *base);  /* must use malloc(). */
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
int get_file_size(const char *fname, long *fsize);
89
0befb9dfdee4 Removed getcwd() and use get_current_dir() instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
    66
char *get_current_dir(char *buf, size_t bufsize);
0
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
char *get_realpath(const char *path);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
int update_version(const char *ver);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
int calc_tmp_filenames(char **tmp1, char **tmp2);
81
50f6052737ce Did a lot of ripping things up.
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    70
int locate_product_by_identifier(const char *str, char *buf, size_t bufsize);
83
2ab590824674 Moved a bunch of the versioning stuff into mojopatch.c and cleaned up patch
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    71
int get_product_version(const char *ident, char *buf, size_t bufsize);
91
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    72
SpawnResult spawn_xdelta(const char *cmdline);
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    73
SpawnResult spawn_script(const char *scriptname, const char *dstdir);
0
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
#ifdef __cplusplus
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
}
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
#endif
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
#endif /* include-once blocker. */
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
/* end of platform.h ... */
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82