]> 4ch.mooo.com Git - bakadb.git/blob - bakadb.c
Initial commit
[bakadb.git] / bakadb.c
1 /*
2  * Copyright (C) 2015 sparky4
3  *
4  * This file is part of baka database.
5  *
6  * baka database 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  * baka database 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 //TODO
23 //price! and finish it
24 //additional paramiters
25 //make and model
26 //simple batch files
27 //color wwww
28 //
29 //for turbo goat!
30 //gui
31 //big font!
32 //customer dtabase
33
34 #include "bakadb.h"
35
36 byte *pc = NULL;
37 byte sheetstr[sizeof(byte)*((80*50)+1)];
38 byte *bakapee = NULL;
39 iword found_id=0;
40
41
42 iword baka_id;              //work order numer
43 byte baka_name[64];     //name of client
44 byte baka_phone[64];     //name of client
45 byte baka_address[64];     //name of client
46 byte baka_desc[4096];     //Description of the problem
47 time_t                          baka_date;
48 byte baka_price;                        //price
49 word baka_done;                 //is it done?
50
51 /*
52         "%[^\n]"
53 */
54
55 void bdwr(void)
56 {
57         byte str[BAKAPEE], buff[BAKAPEE], st[24];
58         byte *pc = NULL;
59         byte *p;
60
61         FILE *in = fopen ( "baka.db", "r+" );
62         FILE *out = NULL;
63         if(in == NULL)
64         {
65                 newdb:
66                 fclose(in);
67                 out = fopen ( "baka.db", "w+" );
68                 printf("\nNew database being made ^^;\n");
69                 printf("Work order number: ");
70                 scanf("%ud\n", &baka_id);   // input~
71                 if(baka_id==0) baka_id=1;
72         }
73         else
74         {
75                 fgets(buff, 1, in);
76                 if(buff==NULL)
77                 {
78                         unlink("baka.db");
79                         goto newdb;
80                 }
81                 while ( fgets ( buff, sizeof buff, in ) != NULL );
82                 fclose(in);
83                 pc = strtok(buff, SEPE);
84                 baka_id = atoi(pc);
85                 baka_id++;
86                 out = fopen ( "baka.db", "a+" );
87                 //printf("      baka_id=%u\n", baka_id);
88         }
89         sprintf(st, "%u", baka_id);
90         strcpy(str, st);
91         strcat(str,SEPE);
92
93         printf("Client's name: ");
94         scanf("%s", &(baka_name));     // input~
95
96         //TODO make uppercased names
97         found_id=0;
98         cmpstrfromdb(1);
99
100         strcat(str,baka_name);  strcat(str,SEPE);
101         if(found_id==0)
102         {
103                 printf("Client's Phone Number: ");
104                 scanf("%s", &(baka_phone));     // input~
105         }else getstrfromdb(2);
106         strcat(str,baka_phone);  strcat(str,SEPE);
107         if(found_id==0)
108         {
109                 printf("Client's Address: ");
110                 scanf("%s", &(baka_address));     // input~
111         }else getstrfromdb(3);
112         strcat(str,baka_address);  strcat(str,SEPE);
113
114         printf("Description of the Problem: ");
115         scanf("%s", &(baka_desc));     // input~
116         strcat(str,baka_desc); strcat(str,SEPE);
117         //time
118         memset(st, 0, sizeof st);       //reset str~
119         baka_date=time(NULL);
120         sprintf(st, "%s", ctime(&baka_date));
121         p = &st;
122         p++; /* 'N' is not in `p` */
123         p[strlen(p)-1] = 0; /* 'P' is not in `p` (and it isn't in `mystr` either) */
124         //printf("[%s]", st);
125         strcat(str, st);        strcat(str,SEPE);
126
127         //price var
128         strcat(str, "0"); strcat(str,SEPE);
129
130         //done var
131         strcat(str,"0");
132         strcat(str,SEPE);
133         strcat(str,"\n");
134         //bdmksheet(&bddb);
135         fwrite(str, strlen(str), 1, out);
136         fclose(out);
137         found_id=0;
138         free(pc);
139 }
140
141 void bddone(iword id)
142 {
143         byte buff[BAKAPEE], st[16], str[BAKAPEE];
144         byte *p;
145         siword eed;
146
147         FILE *in = fopen ( "baka.db", "r" );
148         FILE *out = NULL;
149         while ( fgets ( buff, sizeof buff, in ) != (NULL) )
150         {
151                 strcat(str, buff);
152                 pc = strtok(buff, SEPE);
153                 eed = atoi(pc);
154                 if(eed!=id)
155                 {
156                         continue;
157                 }
158                 else
159                 {
160                         sprintf(st, "%d", "1");
161                         p = &str;
162                         p++; /* 'N' is not in `p` */
163                         p[strlen(p)-4] = st[0]; /* 'P' is not in `p` (and it isn't in `mystr` either) */
164                         //printf("[%d]\n", eed);
165                 }
166         }
167         fclose(in);
168         out = fopen ( "baka.db", "w+" );
169         fwrite(str, strlen(str), 1, out);
170         fclose(out);
171         free(p);
172 }
173
174 void bdchange(iword id, byte i, sword t)
175 {
176         byte buff[BAKAPEE], str[BAKAPEE];
177         //siword st;
178         byte *p;
179         siword eed;
180
181         FILE *in = fopen ( "baka.db", "r" );
182         FILE *out = NULL;
183         dbvar(t);
184         found_id=id;
185         while ( fgets ( buff, sizeof buff, in ) != (NULL) )
186         {
187                 strcat(str, buff);
188                 pc = strtok(buff, SEPE);
189                 eed = atoi(pc);
190                 if(eed!=id)
191                 {
192                         continue;
193                 }
194                 else
195                 {
196                         getstrfromdb(-2);
197                         //sprintf(st, "%f", );
198                         p = &str;
199                         p++; /* 'N' is not in `p` */
200                         p[strlen(p)+(t*4)] = ((*bakapee)+(iword)(i)); /* 'P' is not in `p` (and it isn't in `mystr` either) */
201                         //printf("[%d]\n", eed);
202                 }
203         }
204         fclose(in);
205         out = fopen ( "baka.db", "w+" );
206         fwrite(str, strlen(str), 1, out);
207         fclose(out);
208         free(p);
209 }
210
211 void mksheetdrbd()
212 {
213         byte str[BAKAPEE*16], boo[BAKAPEE], st[24];
214         FILE *out = fopen ( "sheet.txt", "w+" );
215
216 //make sheet
217         strcpy(str, "Dr. Bulldog Computers                                      (318) 255-0333\n");
218         strcat(str, "208 N Trenton Street                                       Monday - Friday\n");
219         strcat(str, "Ruston, LA 71270                                   10:00 AM – 6:00 PM\n");
220         strcat(str, "Personal Information\n");
221         strcat(str,"Name: ");
222 //      getstrfromdb(1);
223 //      strcpy(baka_name, pc); strcat(str, baka_name); strcat(str, "            ");
224 //      strcat(str,"Date: ");
225 //      sprintf(st, "%s", baka_date);
226 //      strcat(str, st); strcat(str, "\n");
227 /*
228 Street Address: _____________________________ City: _______________ State: _____ Zip: _________
229 Phone:  Cell (        ) ______________ other: (        ) ________________ E-mail:______________________
230 Name of person referred you to us, if any: ___________________________________________
231 System Information
232 Brand: ______________Model: ____________Login Password:____________ Serial No:_____________
233 Accessories Included (Charger, External HDD, etc.): ___________________________________________
234 Problem Description (Please be specific)
235 __________________________________________________________________________________________________________________________________________________________________________
236 Data Backup
237 Before any repairs are made, please inform us of any data that you want saved. Programs cannot be backed up and must be reinstalled after a format operation. Anything NOT listed here is permanently deleted. Check all that apply:
238 I DO NOT NEED ANY BACKUPS  *All data will be deleted*
239 I DO NOT ALLOW A FORMAT *The software will not be altered in any way*
240 Personal Data (My Documents, My Pictures, My Music, My Videos, IE Favorites, Desktop)
241 E-Mail (Microsoft Outlook, Outlook Express, or Windows Mail)
242 Other (Be Specific) _______________________________________________________________
243 Legal
244 By signing this form I authorize Dr. Bulldog Computers to perform any necessary actions to repair problem as described above. I also understand that I left a malfunctioning unit that may have other problems in addition to the ones described. We quote for walk-in customers however in the case a device cannot be repaired, a $45 diagnostics fee will be charged and the device will be returned broken. Leaving your device with Dr. Bulldog for hardware repairs voids any warranty with any other company. All provided repair times are an estimate. In the event of data loss, Dr. Bulldog is not responsible for recovering the data in any way. I accept that all software on this device belongs to me and can provide any licensing necessary. The device also belongs to me, is NOT stolen, and has no liens attached.  I also agree that Dr.Bulldog Computer is not responsible for the machine(s) that I left past 30 days after the take-in date and special orders that I make cannot be refunded.
245 Customer Signature: ______________________________   Date: ___/___/___*/
246         fclose(out);
247 }
248
249 void dbvar(sword i)
250 {
251         switch(i)
252         {
253                 case 0:
254                         bakapee = NULL;
255                         bakapee = (byte *)baka_id;
256                 break;
257                 case 1:
258                         bakapee = NULL;
259                         bakapee = &baka_name;
260                 break;
261                 case 2:
262                         bakapee = NULL;
263                         bakapee = &baka_phone;
264                 break;
265                 case 3:
266                         bakapee = NULL;
267                         bakapee = &baka_address;
268                 break;
269                 case -2:
270                         bakapee = NULL;
271                         bakapee = &baka_price;
272                 break;
273                 default:
274                         bakapee = NULL;
275                 break;
276         }
277 }
278
279 void getstrfromdb(sword i)
280 {
281         byte buff[BAKAPEE];
282         word q;
283         FILE *in = fopen ( "baka.db", "r+" );
284         if(found_id>0) dbvar(i);
285         while ( fgets ( buff, sizeof buff, in ) != NULL )
286         {
287                 pc = strtok(buff, SEPE);
288                 if(found_id==atoi(pc))
289                 {
290                         break;
291                 }
292         }
293         if(i>=0)
294         {
295                 for(q=0;(q<i);q++)
296                 {
297                         pc = strtok(NULL, SEPE);
298                 }
299         }
300         else
301         {
302                 for(q=0;(q>i);q--)
303                 {
304                         pc = strtok(SEPE, NULL);
305                 }
306         }
307         if(found_id>0)
308                 strcpy(bakapee, pc);
309         fclose(in);
310 }
311
312 void cmpstrfromdb(word i)
313 {
314         byte buff[BAKAPEE];
315         byte pee[16];
316         word q;
317         FILE *in = fopen ( "baka.db", "r+" );
318         dbvar(i);
319         while ( fgets ( buff, sizeof buff, in ) != NULL )
320         {
321                 pc = strtok(buff, SEPE);
322                 found_id=atoi(pc);
323                 for(q=0;q<i;q++)
324                 {
325                         pc = strtok(NULL, SEPE);
326                 }
327                 if(strcmp(bakapee, pc)<1)
328                 {
329                         strcpy(pc, bakapee);
330                         break;
331                 }else found_id=0;
332         }
333         fclose(in);
334 }