]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_head.c
Signed-off-by: sparky4 <sparky4@cock.li>
[16.git] / src / lib / 16_head.c
1 /* Project 16 Source Code~
2  * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669
3  *
4  * This file is part of Project 16.
5  *
6  * Project 16 is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Project 16 is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,
19  * Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22
23 #include "src/lib/16_head.h"
24
25 /* Function: Wait **********************************************************\r
26 *\r
27 *     Parameters:    wait - time in microseconds\r
28 *\r
29 *     Description:    pauses for a specified number of microseconds.\r
30 *\r
31 */\r
32 void wait(clock_t wait){\r
33         clock_t goal;\r
34 \r
35         if(!wait) return;\r
36 \r
37         goal = wait + clock();\r
38         while((goal > clock()) && !kbhit()) ;\r
39 } /* End of wait */
40
41 long int
42 filesize(FILE *fp)\r
43 {\r
44         long int save_pos, size_of_file;\r
45 \r
46         save_pos = ftell(fp);\r
47         fseek(fp, 0L, SEEK_END);\r
48         size_of_file = ftell(fp);\r
49         fseek(fp, save_pos, SEEK_SET);\r
50         return(size_of_file);\r
51 }
52
53 void printmeminfoline(byte *strc, const byte *pee, size_t h_total, size_t h_used, size_t h_free)
54 {
55         byte str[64];
56         strcat(strc,pee); strcat(strc,"            "); ultoa((dword)h_total,str,10); strcat(strc,str); strcat(strc,"    "); ultoa((dword)h_used,str,10); strcat(strc,str); strcat(strc,"        "); ultoa((dword)h_free,str,10); strcat(strc,str);
57         strcat(strc,"\n");
58 }
59
60 void print_normal_entry(char *text, dword total, dword used, dword free, byte *str)
61 {
62         printf("%-17s", text);
63         convert("%8sB ", total);
64         convert("%9sB ", used);
65         convert("%9sB\n", free);
66 }
67
68 /*
69  * As for printf(), but format may only contain a single format specifier,
70  * which must be "%s" and is replaced with the string form of num with commas
71  * separating groups of three digits.
72  *
73  * e.g. convert("%s bytes", 1234567) -> "1,234,567 bytes"
74  */
75 void convert(const char *format, dword num)
76 {
77     int c, i, j, n;
78     char des[4*sizeof(dword)+3];
79     union REGS regs;
80     struct SREGS sregs;
81     char mycountry[48]; /* probably 34 bytes are enough... */
82     char ksep = ',';    /* or . */
83
84     regs.x.ax = 0x3800;
85     sregs.ds = FP_SEG(&mycountry);
86     regs.x.dx = FP_OFF(&mycountry);
87     intdosx(&regs,&regs,&sregs);
88     if (regs.x.cflag == 0) {
89       ksep = mycountry[7];        /* 1000's separator  */
90       /* dsep = mycountry[9];     ** decimal separator */
91     }
92
93     n = sprintf(des, "%lu", num);
94     /* insert commas in the string */
95     c = 3;
96     for (i = n - 3; i > 0; i--) {
97         if (c%3==0) {
98             for (j = n; j >= i; j--)
99                 des[j+1] = des[j];
100             des[i]=ksep;        /* ',' */
101             n++;
102         }
103         c++;
104     }
105     printf(format, des);
106 }
107
108 ///////////////////////////////////////////////////////////////////////////\r
109 //\r
110 //      US_CheckParm() - checks to see if a string matches one of a set of\r
111 //              strings. The check is case insensitive. The routine returns the\r
112 //              index of the string that matched, or -1 if no matches were found\r
113 //\r
114 ///////////////////////////////////////////////////////////////////////////\r
115 int\r
116 US_CheckParm(char *parm,char **strings)\r
117 {\r
118         char    cp,cs,\r
119                         *p,*s;\r
120         int             i;\r
121 \r
122         while (!isalpha(*parm)) // Skip non-alphas\r
123                 parm++;\r
124 \r
125         for (i = 0;*strings && **strings;i++)\r
126         {\r
127                 for (s = *strings++,p = parm,cs = cp = 0;cs == cp;)\r
128                 {\r
129                         cs = *s++;\r
130                         if (!cs)\r
131                                 return(i);\r
132                         cp = *p++;\r
133 \r
134                         if (isupper(cs))\r
135                                 cs = tolower(cs);\r
136                         if (isupper(cp))\r
137                                 cp = tolower(cp);\r
138                 }\r
139         }\r
140         return(-1);\r
141 }
142
143 /*\r
144 ==========================\r
145 =\r
146 = Quit\r
147 =\r
148 ==========================\r
149 */\r
150 \r
151 /*void Quit(char *error, ...)\r
152 {\r
153         short exit_code=0;\r
154         unsigned        finscreen;\r
155 \r
156         va_list ap;\r
157 \r
158         va_start(ap,error);\r
159 \r
160 #ifndef CATALOG\r
161         if (!error)\r
162         {\r
163                 CA_SetAllPurge ();\r
164                 CA_CacheGrChunk (PIRACY);\r
165                 finscreen = (unsigned)grsegs[PIRACY];\r
166         }\r
167 #endif\r
168 \r
169         //ShutdownId ();\r
170 \r
171         if (error && *error)\r
172         {\r
173                 vprintf(error,ap);\r
174                 exit_code = 1;\r
175         }\r
176 #ifndef CATALOG\r
177         else\r
178         if (!NoWait)\r
179         {\r
180                 movedata (finscreen,0,0xb800,0,4000);\r
181                 bioskey (0);\r
182         }\r
183 #endif\r
184 \r
185         va_end(ap);\r
186 \r
187 #ifndef CATALOG\r
188         if (!error)\r
189         {\r
190                 _argc = 2;\r
191                 _argv[1] = "LAST.SHL";\r
192                 _argv[2] = "ENDSCN.SCN";\r
193                 _argv[3] = NULL;\r
194                 if (execv("LOADSCN.EXE", _argv) == -1)\r
195                 {\r
196                         clrscr();\r
197                         puts("Couldn't find executable LOADSCN.EXE.\n");\r
198                         exit(1);\r
199                 }\r
200         }\r
201 #endif\r
202 \r
203         exit(exit_code);\r
204 }*/