-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclipbrd.c
79 lines (67 loc) · 1.42 KB
/
clipbrd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
**
**
** Changes
** Author Date Desription
** P Slegg 29-May-2010 Moved from hwWind.c
**
*/
/*----------------------------------------------------------------------------*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <cflib.h>
#include "global.h"
#include "clipbrd.h"
FILE *
open_scrap (BOOL rdNwr)
{
char path[HW_PATH_MAX] = "";
const char * mode = (rdNwr ? "rb" : "wb");
FILE * file;
if (scrp_read (path) <= 0 || !path[0])
{
file = NULL;
}
else
{
char * scrp = strchr (path, '\0');
if (scrp[-1] != '\\') *(scrp++) = '\\';
if (path[0] >= 'a') path[0] -= ('a' - 'A');
strcpy (scrp, "scrap.txt");
if ((file = fopen (path, mode)) == NULL && rdNwr)
{
strcpy (scrp, "SCRAP.TXT");
file = fopen (path, mode);
}
}
return file;
}
/*============================================================================*/
char *
read_scrap(void)
{
FILE * file = open_scrap (TRUE);
if (file)
{
long filelength;
char * paste;
/* find the size of the file */
fseek (file, 0, SEEK_END);
filelength = ftell (file);
fseek (file, 0, SEEK_SET);
/* allocate enough memory to hold the file */
paste = malloc (filelength+1);
if (paste != NULL)
{
/* read the entire file */
long n = fread (paste, 1, filelength, file);
paste[n] = '\0';
}
fclose (file);
return paste;
}
else
return NULL;
}