📄 sysdep_win32_c.c
字号:
/*
Copyright (c) 1999,2000, Compaq Computer Corporation
See the file "license.terms" for information on usage and redistribution
of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
/*
FORTRAN callable routines that do some system dependent things.
These routines were easier to write in C.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#if !defined(MIN)
#define MIN(x,y) (((x) <= (y)) ? (x) : (y))
#endif
#if defined(vms) || defined(__vms)
/* VMS does not need name change (all externals are upper case'd) */
#define FORTRAN_CALL
#elif defined(_WIN32)
/* Win32 name decoration */
#define FORTRAN_CALL __stdcall
#define get_term_display_size GET_TERM_DISPLAY_SIZE
#define cformat_axis_label CFORMAT_AXIS_LABEL
#define pm_tempnam PM_TEMPNAM
#define lnblnk LNBLNK
#else
/* Unix name decoration */
#define FORTRAN_CALL
#define get_term_display_size get_term_display_size_
#define cformat_axis_label cformat_axis_label_
#define pm_tempnam pm_tempnam_
#define lnblnk lnblnk_
#endif
/* FORTRAN callable routine to get terminal display size */
void FORTRAN_CALL get_term_display_size(int *rows, int *cols)
{
/* Return dummy values */
*rows = 24;
*cols = 80;
return;
}
/* Call out to C run time library to convert a float value to
a string, according to a "C" format */
#if defined(_WIN32)
void FORTRAN_CALL cformat_axis_label(float *ticvalue, char *format,
int format_len, char *label, int label_len)
#else
void FORTRAN_CALL cformat_axis_label(float *ticvalue, char *format,
char *label, int format_len, int label_len)
#endif
{
int FORTRAN_CALL lnblnk(char *, int);
int ilen, nchar;
char local_format[83], local_label[83];
#ifdef ultrix
char *ptr;
#endif
/* Convert format to NUL terminated string */
ilen = lnblnk(format,format_len);
if( ilen > 80 ) ilen=80;
/* Prepend %- format indicator. "-" makes string left justified */
local_format[0] = '%';
local_format[1] = '-';
memcpy(&local_format[2],format,ilen);
local_format[ilen+2] = '\0';
/* Scan format for some invalid characters for a float format */
/* This is not an all inclusive list, just trying to avoid the worst */
/* Include % and -, as we already put this in ourselves */
if ( strpbrk(&local_format[2],"%-*doxXucslipn") != NULL ) {
memset(label,'*',label_len);
return;
}
/* Is there a valid format character in the string? */
if ( strpbrk(local_format,"eEfgG") == NULL ) {
memset(label,'*',label_len);
return;
}
#ifdef ultrix
/* Default Ultrix behavior for sprintf is to return char * pointer! */
/* We could use the -YPOSIX flag, but any application that linked with
Postmini would have to know to use that flag also. */
ptr = sprintf(local_label,local_format,*ticvalue);
if( (int) ptr == EOF ) {
fprintf(stderr,"cformat_axis_label: error occurred while formatting string\n");
memset(label,'*',label_len);
return;
}
#else
nchar = sprintf(local_label,local_format,*ticvalue);
if( nchar == 0 || nchar > 80 ) {
fprintf(stderr,"cformat_axis_label: error occurred while formatting string\n");
memset(label,'*',label_len);
return;
}
#endif
/* Convert local_label to blank padded string */
memset(label,' ',label_len);
ilen = MIN(strlen(local_label),label_len);
memcpy(label,local_label,ilen);
}
#if defined(_WIN32)
void FORTRAN_CALL pm_tempnam(char *prefix, int ilen1, char *filename, int ilen2)
#else
void FORTRAN_CALL pm_tempnam(char *prefix, char *filename, int ilen1, int ilen2)
#endif
{
/* NOTE: we roll own own temporary name function to give us a little
more flexibility in naming the temp file, rather than
use tmpnam() */
char tmp_prefix[31], date[81], tmp_string[132], *ptr;
int length;
int FORTRAN_CALL lnblnk(char *, int);
static count = 0;
time_t timer;
/* Find length without trailing blanks */
length = lnblnk(prefix,ilen1);
/* Maximum of 30 characters in prefix */
length = MIN(length,30);
memcpy(tmp_prefix,prefix,(size_t) length);
/* Terminate string with NUL */
tmp_prefix[length] = '\0';
/* Make sure any prefix does not have a period in it */
for(ptr=tmp_prefix; *ptr != '\0'; ptr++) {
if( *ptr == '.' ) *ptr = '_';
}
/* Call time() and getpid() routines to generate temporary name */
time(&timer);
strncpy(date,ctime(&timer),80);
for(ptr=date; *ptr != '\0'; ptr++) {
if( *ptr == '\n' ) *ptr = '\0';
if( *ptr == ' ' ) *ptr = '_';
if( *ptr == ':' ) *ptr = '_';
}
/* Temporary filename is formed by concatenation of
prefix, date, process id, and a decimal count */
#if defined(_WIN32)
sprintf(tmp_string,"%s.%s_%u_%d",tmp_prefix,&date[4],getpid(),count);
#else
sprintf(tmp_string,"%s.%s_%d_%d",tmp_prefix,&date[4],getpid(),count);
#endif
count++;
/* Is output string large enough? */
length = strlen(tmp_string);
if( length > ilen2 ) {
/* Output string is too short, fill string with asterisks */
memset(filename,'*',(size_t) ilen2);
} else {
/* Set string to all blanks */
memset(filename,' ',(size_t) ilen2);
length = MIN(length,ilen2);
/* Copy result into output string */
memcpy(filename,tmp_string,(size_t) length);
}
}
/*
* strncasecmp.c --
*
* Source code for the "strncasecmp" library routine.
*
* Copyright (c) 1988-1993 The Regents of the University of California.
* Copyright (c) 1995-1996 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* SCCS: @(#) strncasecmp.c 1.7 96/10/24 15:23:36
*/
/*
* This array is designed for mapping upper and lower case letter
* together for a case independent comparison. The mappings are
* based upon ASCII character sequences.
*/
static unsigned char charmap[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xe1, 0xe2, 0xe3, 0xe4, 0xc5, 0xe6, 0xe7,
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
};
/*
* Here are the prototypes just in case they are not included
* in tclPort.h.
*/
int strncasecmp (const char *s1, const char *s2, size_t n);
int strcasecmp (const char *s1, const char *s2);
/*
*----------------------------------------------------------------------
*
* strcasecmp --
*
* Compares two strings, ignoring case differences.
*
* Results:
* Compares two null-terminated strings s1 and s2, returning -1, 0,
* or 1 if s1 is lexicographically less than, equal to, or greater
* than s2.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
strcasecmp(s1, s2)
const char *s1; /* First string. */
const char *s2; /* Second string. */
{
unsigned char u1, u2;
for ( ; ; s1++, s2++) {
u1 = (unsigned char) *s1;
u2 = (unsigned char) *s2;
if ((u1 == '\0') || (charmap[u1] != charmap[u2])) {
break;
}
}
return charmap[u1] - charmap[u2];
}
/*
*----------------------------------------------------------------------
*
* strncasecmp --
*
* Compares two strings, ignoring case differences.
*
* Results:
* Compares up to length chars of s1 and s2, returning -1, 0, or 1
* if s1 is lexicographically less than, equal to, or greater
* than s2 over those characters.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
strncasecmp(s1, s2, length)
const char *s1; /* First string. */
const char *s2; /* Second string. */
size_t length; /* Maximum number of characters to compare
* (stop earlier if the end of either string
* is reached). */
{
unsigned char u1, u2;
for (; length != 0; length--, s1++, s2++) {
u1 = (unsigned char) *s1;
u2 = (unsigned char) *s2;
if (charmap[u1] != charmap[u2]) {
return charmap[u1] - charmap[u2];
}
if (u1 == '\0') {
return 0;
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -