/*
TurboC, a library for porting Borland Turbo C to GNU gcc.
The entire contents of this source file is
Copyright (c) Igor Bujna 1999-2001.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact Ron Burkey at info@sandroid.org.
Contact Igor Bujna <igor.bujna@maxi-tip.cz>
Filename: dos2unix.c
Purpose: Various TurboC library functions contributed by
Igor Bujna.
Mod history: 05/19/02 RSB Integrated Igor's contributions to the
existing TurboC library code.
12/16/02 RSB getdate changed to getdateTurbo, in order to
coexist with the getdate in newer system
libraries.
This file contains a lot of miscellaneous functions, appropriate to
a variety of headers (io.h, dos.h, bios.h), but I (RSB) felt it best and
least confusing to keep them together as Igor delivered them to me.
The associated header file, on the other hand, has been split up and joined
with io.h, dos.h, etc. Otherwise, minimal editing has been performed --
for example, to get the integer types to correspond to TurboC integer types.
The month and day names have been commented out not because they're Czech,
but because they don't seem to be used by the code. Similarly, the
sequence_STAR_34X function has been removed because I'm not entirely sure
what it's for. (I mean, I'm sure it translates the control codes for
some specific type of printer -- perhaps one of the Micronics line --
but I'm not sure how to document it or whether it's of any general use.)
*/
#ifdef __linux__
// The following apparent constants are macros containing casts that will
// fail if TurboC's automatic integer-type translation is used.
#include <sys/ioctl.h>
#include <linux/ppdev.h>
int pprstatus = PPRSTATUS;
int pprelease = PPRELEASE;
int ppclaim = PPCLAIM;
int ppwdata = PPWDATA;
int ppfcontrol = PPFCONTROL;
#endif // __linux__
#include "io.h"
#include "dos.h"
#include "bios.h"
#ifndef ESC_KEY
#define ESC_KEY 27
#define TAB_KEY 9
#define CTRL_X 24
#define RETURN 13
#define BACKSPACE 8
#endif
#ifndef N_C
#define N_C '\0' /* Definice NULL-teho znaku */
#endif
#ifndef TRUE
#define FALSE 0
#define TRUE !FALSE
#endif
/*
* Date and Time function
*/
struct date date_null = { 0, 0, 0 };
struct time time_null = { 0, 0, 0, 0 };
#if 0
char *month[] =
{ "---", "Led", "Uno", "Bre", "Dub", "Kve", "Cer", "Cec", "Srp", "Zar",
"Rij", "Lis", "Pr",
};
char *month_l[] =
{ "---", "Leden", "Unor", "Brezen", "Duben", "Kveten", "Cerven",
"Cervenec", "Srpen", "Zari", "Rijen", "Listopad", "Prosinec",
};
char *day[] = { "Ned", "Pon", "Ute", "Str", "Ctv", "Pat", "Sob", };
char *day_l[] =
{ "Nedele", "Pondeli", "Utery", "Streda", "Ctvrtek", "Patek", "Sobota", };
#endif // 0
time_t
dostounix (struct date *d, struct time *t)
{
struct tm utm, *ptm;
time_t the_time = time (0);
ptm = localtime (&the_time);
memset (&utm, N_C, sizeof (struct tm));
memcpy ((void *) &utm, (void *) ptm, sizeof (struct tm));
utm.tm_sec = t->ti_sec;
utm.tm_min = t->ti_min;
utm.tm_hour = t->ti_hour;
utm.tm_mday = d->da_day;
utm.tm_mon = d->da_mon - 1;
utm.tm_year = d->da_year - 1900;
return (mktime (&utm));
}
void
unixtodos (time_t the_time, struct date *d, struct time *t)
{
struct tm utm, *ptm;
memset (&utm, N_C, sizeof (struct tm));
ptm = localtime (&the_time);
memcpy ((void *) &utm, (void *) ptm, sizeof (struct tm));
t->ti_sec = utm.tm_sec;
t->ti_hund = 0;
t->ti_min = utm.tm_min;
t->ti_hour = utm.tm_hour;
d->da_day = utm.tm_mday;
d->da_mon = utm.tm_mon + 1;
d->da_year = utm.tm_year + 1900;
}
void
unixdos_time (time_t the_time, struct time *t)
{
struct date d;
memset (&d, N_C, sizeof (struct date));
unixtodos (the_time, &d, t);
}
void
unixdos_date (time_t the_time, struct date *d)
{
struct time t;
memset (&t, N_C, sizeof (struct time));
unixtodos (the_time, d, &t);
}
void
getdateTurbo (struct date *d)
{
unixdos_date (time (0), d);
}
void
gettime_d (struct time *t)
{
unixdos_time (time (0), t);
}
/*
* Print function (Biosprint ...)
* Value of return is status of printer
* cmd
*/
#ifdef __linux__
int
open_printer (int port)
{
int fd, mode = IEEE1284_MODE_COMPAT;
char pom[50];
switch (port)
{
case LPT1:
sprintf (pom, "/dev/parport0");
break;
case LPT2:
sprintf (pom, "/dev/parport1");
break;
case LPT3:
sprintf (pom, "/dev/parport2");
break;
case TO_FILE:
strcpy (pom, PRINT_FILE);
break;
}
fd = open (pom, O_RDWR);
if (fd != -1 && ioctl (fd, PPCLAIM))
{
close (fd);
fd = -1;
}
if (ioctl (fd, PPNEGOT, &mode))
{
close (fd);
fd = -1;
}
return (fd);
}
ssize_t
write_printer (int fd, const char *buf)
{
ssize_t wrote = 0;
int len = strlen (buf);
//write(fd, buf, sizeof(char) + strlen(buf));
while (wrote < len)
{
guchar status, data;
guchar mask = (PARPORT_STATUS_ERROR | PARPORT_STATUS_BUSY);
guchar val = (PARPORT_STATUS_ERROR | PARPORT_STATUS_BUSY);
struct ppdev_frob_struct frob;
struct timespec ts;
/* Wait for printer to be ready */
for (;;)
{
ioctl (fd, pprstatus, &status);
if ((status & mask) == val)
break;
ioctl (fd, pprelease);
/* Delay for a bit */
ts.tv_sec = 0;
ts.tv_nsec = 1;
// nanosleep (&ts, NULL);
ioctl (fd, ppclaim);
}
/* Set the data lines */
data = (guchar) buf[wrote];
ioctl (fd, ppwdata, &data);
/* Delay for a bit */
ts.tv_sec = 0;
ts.tv_nsec = 1000;
// nanosleep (&ts, NULL);
/* Pulse strobe */
// if(data == '\n')
frob.mask = PARPORT_CONTROL_STROBE;
frob.val = PARPORT_CONTROL_STROBE;
ioctl (fd, ppfcontrol, &frob);
// nanosleep (&ts, NULL);
/* End the pulse */
frob.val = 0;
ioctl (fd, ppfcontrol, &frob);
// nanosleep (&ts, NULL);
wrote++;
}
return wrote;
}
#endif
int
biosprint (int cmd, int byte, int port)
{
int ret = 144;
#ifdef __linux__
int fd;
char pom[10];
guchar status;
switch (cmd)
{
case 1:
break;
case 2:
fd = open_printer (port);
ioctl (fd, pprstatus, &status);
ret = (int) status;
close_printer (fd);
ret = 144;
break;
default:
fd = open_printer (port);
sprintf (pom, "%c%c", byte, N_C);
write_printer (fd, pom);
// write (fd, &byte, sizeof(int) );
close_printer (fd);
/* f = fopen (PRINT_FILE, "a+t");
fprintf (f, "%c", byte);
fclose (f);
*/ break;
}
#endif /* __linux__ */
#ifdef __CYGWIN__
FILE *f;
if (cmd != 0)
return (ret);
f = fopen (PRINT_FILE, "a+t");
fprintf (f, "%c", byte);
fclose (f);
#endif /* __CYGWIN__ */
return (ret);
}
void
flush_print (char *buf, int port)
{
guint i;
FILE *f;
if (port == TO_FILE)
{
f = fopen (PRINT_FILE, "a+t");
fprintf (f, "%s", buf);
fclose (f);
}
else
{
for (i = 0; i < strlen (buf); i++)
biosprint (0, buf[i], port);
}
}
void
print_file (const char *file, int port, int lowlevel_print)
{
/* int ch;*/
FILE *f;
char *text, pom[1024 + 1];
if (lowlevel_print == TRUE)
{
if ((f = fopen (file, "rt")) == NULL)
return;
if ((text = (char *) malloc (20 + 1)) == NULL)
return;
没有合适的资源?快使用搜索试试~ 我知道了~
377854144622605TurboC-dev.tar.gz
需积分: 9 0 下载量 29 浏览量
2022-10-22
19:04:58
上传
评论
收藏 102KB GZ 举报
温馨提示
共123个文件
c:101个
h:10个
bdf:3个
377854144622605TurboC-dev.tar.gz
资源详情
资源评论
资源推荐
收起资源包目录
377854144622605TurboC-dev.tar.gz (123个子文件)
VariableWidth-16.bdf 29KB
Console-16.bdf 28KB
Console-8.bdf 26KB
dos2unix.c 12KB
getchTurbo.c 10KB
textmode.c 10KB
initgraph.c 9KB
GraphicsTest.c 7KB
freeTurbo.c 6KB
outtextxy.c 5KB
getimage.c 5KB
ResizeTurboC.c 5KB
gettext.c 5KB
findfirst.c 5KB
setfillXXXX.c 4KB
textattr.c 4KB
puttext.c 4KB
drawpoly.c 3KB
graphdefaults.c 3KB
sector.c 3KB
getmodename.c 3KB
setlinestyle.c 3KB
setbkcolor.c 3KB
bar.c 3KB
setpalette.c 3KB
movetext.c 3KB
endian.c 3KB
detectgraph.c 3KB
endianFile.c 2KB
TurboX.c 2KB
line.c 2KB
window.c 2KB
kbhit.c 2KB
getpixel.c 2KB
putch.c 2KB
closegraph.c 2KB
clearXXXX.c 2KB
getftime.c 2KB
setcolor.c 2KB
cgets.c 2KB
ellipse.c 2KB
grapherrormsg.c 2KB
settextstyle.c 2KB
setXXXXpage.c 2KB
setviewport.c 2KB
textwidth.c 2KB
hex2h.c 2KB
random.c 2KB
pieslice.c 2KB
fillellipse.c 2KB
setwritemode.c 2KB
getpalette.c 2KB
setrgbpalette.c 2KB
rectangle.c 2KB
getmaxx.c 2KB
getmaxcolor.c 2KB
putpixel.c 2KB
arc.c 2KB
getarccoords.c 2KB
delay.c 2KB
ctype.c 2KB
TurboTrap.c 2KB
TurboCVariables.c 2KB
gotoxy.c 2KB
getviewsettings.c 1KB
getdateSystem.c 1KB
setgraphbufsize.c 1KB
TurboCChars.c 1KB
gettextsettings.c 1KB
cprintf.c 1KB
XXXaspectratio.c 1KB
strupr.c 1KB
strlwr.c 1KB
getdrivername.c 1KB
_setcursortype.c 1KB
gettime.c 1KB
getmoderange.c 1KB
getche.c 1KB
_graphXXXmem.c 1KB
cputs.c 1KB
graphresult.c 1KB
installuserdriver.c 1KB
circle.c 1KB
registerbgifont.c 1KB
registerbgidriver.c 1KB
textbackground.c 1KB
installuserfont.c 1KB
getgraphmode.c 1KB
getpass.c 1KB
getmaxmode.c 1KB
textcolor.c 1KB
ConioResizeCallback.c 1KB
delline.c 1KB
insline.c 1KB
clrscr.c 1KB
clreol.c 1KB
gettextinfo.c 1KB
wherex.c 1KB
wherey.c 1KB
highvideo.c 1KB
共 123 条
- 1
- 2
dmstrll
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0