Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit602ac52

Browse files
committed
From: Magnus Hagander <mha@edu.sollentuna.se>Ok. Here is a patch to make psql work on Win32 (as a console modeapplication, of course).It requires getopt.c to be in src/utils - works fine with the FreeBSDversion of it.Also, the file win32.mak should go into src/bin/psql.
1 parent50ad4a7 commit602ac52

File tree

4 files changed

+223
-3
lines changed

4 files changed

+223
-3
lines changed

‎src/bin/psql/psql.c

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.155 1998/08/22 04:49:05 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.156 1998/08/27 13:25:18 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -17,10 +17,16 @@
1717
#include<signal.h>
1818
#include<errno.h>
1919
#include<sys/types.h>
20+
#ifdefWIN32
21+
#defineWIN32_LEAN_AND_MEAN
22+
#include<windows.h>
23+
#include<io.h>
24+
#else
2025
#include<sys/param.h>/* for MAXPATHLEN */
21-
#include<sys/stat.h>
2226
#include<sys/ioctl.h>
2327
#include<unistd.h>
28+
#endif
29+
#include<sys/stat.h>
2430
#include<fcntl.h>
2531
#include<ctype.h>
2632
#include"postgres.h"
@@ -58,6 +64,23 @@
5864
#endif
5965
#endif
6066

67+
68+
#ifdefWIN32
69+
#definepopen(x,y) _popen(x,y)
70+
#definepclose(x) _pclose(x)
71+
#defineopen(x,y,z) _open(x,y,z)
72+
#definestrcasecmp(x,y) stricmp(x,y)
73+
#definepqsignal(x,y)
74+
#define MAXPATHLEN MAX_PATH
75+
#defineR_OK 0
76+
77+
/* getopt is not in the standard includes on Win32 */
78+
externchar*optarg;
79+
externintoptind,opterr,optopt;
80+
intgetopt (int,char*const [],constchar*);
81+
char*__progname="psql";
82+
#endif
83+
6184
/* This prompt string is assumed to have at least 3 characters by code in MainLoop().
6285
* A character two characters from the end is replaced each time by a mode character.
6386
*/
@@ -1468,7 +1491,11 @@ do_edit(const char *filename_arg, char *query, int *status_p)
14681491
}
14691492
else
14701493
{
1494+
#ifndefWIN32
14711495
sprintf(tmp,"/tmp/psql.%ld.%ld", (long)geteuid(), (long)getpid());
1496+
#else
1497+
GetTempFileName(".","psql",0,tmp);
1498+
#endif
14721499
fname=tmp;
14731500
unlink(tmp);
14741501
if (ql>0)
@@ -1503,7 +1530,7 @@ do_edit(const char *filename_arg, char *query, int *status_p)
15031530
else
15041531
{
15051532
editFile(fname);
1506-
if ((fd=open(fname,O_RDONLY))==-1)
1533+
if ((fd=open(fname,O_RDONLY,0))==-1)
15071534
{
15081535
perror(fname);
15091536
if (!filename_arg)
@@ -2648,6 +2675,16 @@ main(int argc, char **argv)
26482675

26492676
char*home=NULL;/* Used to store $HOME */
26502677

2678+
#ifdefWIN32
2679+
{
2680+
WSADATAwsaData;
2681+
if (WSAStartup(MAKEWORD(1,1),&wsaData)) {
2682+
fprintf(stderr,"Failed to start winsock: %i\n",WSAGetLastError());
2683+
exit(1);
2684+
}
2685+
}
2686+
#endif
2687+
26512688
MemSet(&settings,0,sizeofsettings);
26522689
settings.opt.align=1;
26532690
settings.opt.header=1;

‎src/bin/psql/win32.mak

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Makefile for Microsoft Visual C++ 5.0 (or compat)
2+
3+
!IF "$(OS)" == "Windows_NT"
4+
NULL=
5+
!ELSE
6+
NULL=nul
7+
!ENDIF
8+
9+
CPP=cl.exe
10+
11+
OUTDIR=.\Release
12+
INTDIR=.\Release
13+
# Begin Custom Macros
14+
OutDir=.\Release
15+
# End Custom Macros
16+
17+
ALL : "$(OUTDIR)\psql.exe"
18+
19+
CLEAN :
20+
-@erase"$(INTDIR)\psql.obj"
21+
-@erase"$(INTDIR)\stringutils.obj"
22+
-@erase"$(INTDIR)\getopt.obj"
23+
-@erase"$(INTDIR)\vc50.idb"
24+
-@erase"$(OUTDIR)\psql.exe"
25+
26+
"$(OUTDIR)" :
27+
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
28+
29+
CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D\
30+
"_MBCS" /Fp"$(INTDIR)\psql.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c \
31+
/I ..\..\include /I ..\..\interfaces\libpq
32+
CPP_OBJS=.\Release/
33+
CPP_SBRS=.
34+
35+
LINK32=link.exe
36+
LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\
37+
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib\
38+
odbccp32.libwsock32.lib/nologo/subsystem:console /incremental:no\
39+
/pdb:"$(OUTDIR)\psql.pdb" /machine:I386 /out:"$(OUTDIR)\psql.exe"
40+
LINK32_OBJS= \
41+
"$(INTDIR)\psql.obj" \
42+
"$(INTDIR)\stringutils.obj" \
43+
"$(INTDIR)\getopt.obj" \
44+
"..\..\interfaces\libpq\Release\libpqdll.lib"
45+
46+
"$(OUTDIR)\psql.exe" : "$(OUTDIR)"$(DEF_FILE)$(LINK32_OBJS)
47+
$(LINK32) @<<
48+
$(LINK32_FLAGS) $(LINK32_OBJS)
49+
<<
50+
51+
"$(OUTDIR)\getopt.obj" : "$(OUTDIR)" ..\..\utils\getopt.c
52+
$(CPP) @<<
53+
$(CPP_PROJ) ..\..\utils\getopt.c
54+
<<
55+
56+
.c{$(CPP_OBJS)}.obj::
57+
$(CPP) @<<
58+
$(CPP_PROJ) $<
59+
<<
60+
61+
.cpp{$(CPP_OBJS)}.obj::
62+
$(CPP) @<<
63+
$(CPP_PROJ) $<
64+
<<

‎src/utils/getopt.c

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright (c) 1987, 1993, 1994
3+
*The Regents of the University of California. All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* 3. All advertising materials mentioning features or use of this software
14+
* must display the following acknowledgement:
15+
*This product includes software developed by the University of
16+
*California, Berkeley and its contributors.
17+
* 4. Neither the name of the University nor the names of its contributors
18+
* may be used to endorse or promote products derived from this software
19+
* without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31+
* SUCH DAMAGE.
32+
*/
33+
34+
#if defined(LIBC_SCCS)&& !defined(lint)
35+
staticcharsccsid[]="@(#)getopt.c8.3 (Berkeley) 4/27/95";
36+
#endif/* LIBC_SCCS and not lint */
37+
38+
#include<stdio.h>
39+
#include<stdlib.h>
40+
#include<string.h>
41+
42+
intopterr=1,/* if error message should be printed */
43+
optind=1,/* index into parent argv vector */
44+
optopt,/* character checked for validity */
45+
optreset;/* reset getopt */
46+
char*optarg;/* argument associated with option */
47+
48+
#defineBADCH(int)'?'
49+
#defineBADARG(int)':'
50+
#defineEMSG""
51+
52+
/*
53+
* getopt --
54+
*Parse argc/argv argument vector.
55+
*/
56+
int
57+
getopt(nargc,nargv,ostr)
58+
intnargc;
59+
char*const*nargv;
60+
constchar*ostr;
61+
{
62+
externchar*__progname;
63+
staticchar*place=EMSG;/* option letter processing */
64+
char*oli;/* option letter list index */
65+
66+
if (optreset|| !*place) {/* update scanning pointer */
67+
optreset=0;
68+
if (optind >=nargc||*(place=nargv[optind])!='-') {
69+
place=EMSG;
70+
return (-1);
71+
}
72+
if (place[1]&&*++place=='-') {/* found "--" */
73+
++optind;
74+
place=EMSG;
75+
return (-1);
76+
}
77+
}/* option letter okay? */
78+
if ((optopt= (int)*place++)== (int)':'||
79+
!(oli=strchr(ostr,optopt))) {
80+
/*
81+
* if the user didn't specify '-' as an option,
82+
* assume it means -1.
83+
*/
84+
if (optopt== (int)'-')
85+
return (-1);
86+
if (!*place)
87+
++optind;
88+
if (opterr&&*ostr!=':')
89+
(void)fprintf(stderr,
90+
"%s: illegal option -- %c\n",__progname,optopt);
91+
return (BADCH);
92+
}
93+
if (*++oli!=':') {/* don't need argument */
94+
optarg=NULL;
95+
if (!*place)
96+
++optind;
97+
}
98+
else {/* need an argument */
99+
if (*place)/* no white space */
100+
optarg=place;
101+
elseif (nargc <=++optind) {/* no arg */
102+
place=EMSG;
103+
if (*ostr==':')
104+
return (BADARG);
105+
if (opterr)
106+
(void)fprintf(stderr,
107+
"%s: option requires an argument -- %c\n",
108+
__progname,optopt);
109+
return (BADCH);
110+
}
111+
else/* white space */
112+
optarg=nargv[optind];
113+
place=EMSG;
114+
++optind;
115+
}
116+
return (optopt);/* dump back option letter */
117+
}

‎src/win32.mak

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ NULL=nul
1313
ALL:
1414
cd interfaces\libpq
1515
nmake /f win32.mak
16+
cd ..\..\bin\psql
17+
nmake /f win32.mak
1618
cd ..\..
1719
echo All Win32 parts have been built!

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp