home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
TCH2AVI.LZH
/
STR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-05-10
|
4KB
|
234 lines
#pragma hdrstop
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#if 0
void _makepath(char *path, char *drive, char *dir, char *fname, char *ext)
{
for (; *drive; *path++ = *drive++);
for (; *dir; *path++ = *dir++);
for (; *fname; *path++ = *fname++);
for (; *ext; *path++ = *ext++);
*path = '\0';
/*
sprintf(path, "%s%s%s%s", drive, dir, fname, ext);
*/
}
void _splitpath(char *path, char *drive, char *dir, char *fname, char *ext)
{
char *p;
if (isalpha(path[0]) && path[1] == ':') {
drive[0] = path[0]; drive[1] = ':'; drive[2] = '\0';
path += 2;
} else {
drive[0] = '\0';
}
if ((p = strrchr(path, '\\')) != NULL || (p = strrchr(path, '/')) != NULL) {
strncpy(dir, path, p - path+1);
dir[p - path+1] = '\0';
path = p+1;
} else {
dir[0] = '\0';
}
if ((p = strchr(path, '.')) != NULL) {
strncpy(fname, path, p - path);
fname[p - path] = '\0';
strcpy(ext, p);
} else {
strcpy(fname, path);
ext[0] = '\0';
}
}
#endif
unsigned short getword(FILE *fp)
{
unsigned short d;
d = fgetc(fp) << 8;
d |= fgetc(fp);
return d;
}
int skipspace(FILE *fp)
{
int c, lc = 0;
long p;
p = ftell(fp);
while ((c = fgetc(fp)) != EOF) {
if (lc == '/' && c == '*') {
lc = fgetc(fp);
while ((c = fgetc(fp)) != EOF) {
if (lc == '*' && c == '/') {
break;
}
lc = c;
}
if (c == EOF) {
return EOF;
}
c = 0;
} else if (lc > 0x20) {
break;
} else if (lc != 0 && lc != ' ' && lc != '\t' && lc != '\r' && lc != '\n') {
break;
}
p = ftell(fp);
lc = c;
}
if (c == EOF) {
return EOF;
}
fseek(fp, p-1, SEEK_SET);
#if 0
ungetc(c, fp);
#endif
return c;
}
int gettoken(char *p, FILE *fp)
{
int c, lc;
long ft;
if (skipspace(fp) == EOF) {
return EOF;
}
*p++ = lc = c = fgetc(fp);
ft = ftell(fp);
if (c == 0x1a || strchr("(){}[]", c) != NULL) {
*p = '\0';
return c;
}
while ((c = *p++ = fgetc(fp)) != EOF) {
if (lc == '/' && c == '*') {
fseek(fp, -1, SEEK_CUR);
p[-2] = '\0';
break;
}
if (c <= 0x20) {
break;
}
if (strchr("(){}[]", c) != NULL) {
break;
}
lc = c;
ft = ftell(fp);
}
if (c == EOF) {
return EOF;
}
fseek(fp, ft, SEEK_SET);
#if 0
ungetc(c, fp);
#endif
*--p = '\0';
return c;
}
#if 0
int removepic(char *name)
{
int i;
i = strlen(name);
if (i > 4 && name[i-4] == '.'
&& toupper(name[i-3]) == 'P'
&& toupper(name[i-2]) == 'I'
&& toupper(name[i-1]) == 'C') {
name[i-4] = '\0';
i -= 4;
}
return i;
}
#else
int removepic(char *name)
{
int i;
i = strlen(name);
if (i > 4 && name[i-4] == '.'
&& toupper(name[i-3]) == 'B'
&& toupper(name[i-2]) == 'M'
&& toupper(name[i-1]) == 'P') {
name[i-4] = '\0';
i -= 4;
}
return i;
}
#endif
int removetch(char *name)
{
int i;
i = strlen(name);
if (i > 4 && name[i-4] == '.'
&& toupper(name[i-3]) == 'T'
&& toupper(name[i-2]) == 'C'
&& toupper(name[i-1]) == 'H') {
name[i-4] = '\0';
i -= 4;
}
return i;
}
void addtch(char *name)
{
int i;
i = strlen(name);
if (i > 4 && name[i-4] == '.'
&& toupper(name[i-3]) == 'T'
&& toupper(name[i-2]) == 'C'
&& toupper(name[i-1]) == 'H') {
} else {
name[i++] = '.';
name[i++] = 'T';
name[i++] = 'C';
name[i++] = 'H';
name[i++] = '\0';
}
}
int removenumber(char *name)
{
int i;
int frame = 0;
i = removepic(name);
if (i > 3 && isdigit(name[i-3]) && isdigit(name[i-2]) && isdigit(name[i-1])) {
frame = (name[i-3]-'0')*100 + (name[i-2]-'0')*10 + (name[i-1]-'0');
name[i-3] = '\0';
}
return frame;
}
#if 0
int ismovie(char *name)
{
int i;
i = strlen(name);
if (name[i-4] == '.'
&& toupper(name[i-3]) == 'P'
&& toupper(name[i-2]) == 'I'
&& toupper(name[i-1]) == 'C') {
i -= 4;
}
if (isdigit(name[i-3]) && isdigit(name[i-2]) && isdigit(name[i-1])) {
return (name[i-3]-'0')*100 + (name[i-2]-'0')*10 + (name[i-1]-'0');
}
return 0;
}
#else
int ismovie(char *name)
{
int i;
i = strlen(name);
if (name[i-4] == '.'
&& toupper(name[i-3]) == 'B'
&& toupper(name[i-2]) == 'M'
&& toupper(name[i-1]) == 'P') {
i -= 4;
}
if (isdigit(name[i-3]) && isdigit(name[i-2]) && isdigit(name[i-1])) {
return (name[i-3]-'0')*100 + (name[i-2]-'0')*10 + (name[i-1]-'0');
}
return 0;
}
#endif