[56] | 1 | /* |
---|
| 2 | * Abuse - dark 2D side-scrolling platform game |
---|
| 3 | * Copyright (c) 1995 Crack dot Com |
---|
| 4 | * |
---|
| 5 | * This software was released into the Public Domain. As with most public |
---|
| 6 | * domain software, no warranty is made or implied by Crack dot Com or |
---|
| 7 | * Jonathan Clark. |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #include "config.h" |
---|
| 11 | |
---|
[2] | 12 | #include <unistd.h> |
---|
| 13 | |
---|
| 14 | #include <stdio.h> |
---|
| 15 | #include <string.h> |
---|
| 16 | #include <stdlib.h> |
---|
| 17 | #ifdef __WATCOMC__ |
---|
[56] | 18 | # include <sys\types.h> |
---|
| 19 | # include <direct.h> |
---|
| 20 | # define make_dir(dir) mkdir(dir) |
---|
[2] | 21 | #else |
---|
[56] | 22 | # include <sys/stat.h> |
---|
| 23 | # define make_dir(dir) mkdir(dir,511) |
---|
[2] | 24 | #endif |
---|
| 25 | |
---|
[56] | 26 | #define NO_LIBS 1 |
---|
| 27 | #include "lisp.c" |
---|
| 28 | #include "trig.c" |
---|
| 29 | #include "lisp_gc.c" |
---|
| 30 | #include "lisp_opt.c" |
---|
[2] | 31 | |
---|
| 32 | enum { LINUX, WATCOM, AIX, SUN, SGI }; |
---|
| 33 | |
---|
| 34 | char *plat_names[] = {"Linux (SVGA & X11)", |
---|
| 35 | "Watcom for MS-DOS", |
---|
| 36 | "IBM AIX for RS6000's", |
---|
| 37 | "Sun OS", |
---|
| 38 | "Silicon Graphics"}; |
---|
| 39 | |
---|
| 40 | char *plat_name[] = {"LINUX","WATCOM","AIX","SUN","SGI"}; |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | int detect_platform() |
---|
| 44 | { |
---|
| 45 | #ifdef __linux__ |
---|
| 46 | return LINUX; |
---|
| 47 | #endif |
---|
| 48 | |
---|
| 49 | #ifdef __WATCOMC__ |
---|
| 50 | return WATCOM; |
---|
| 51 | #endif |
---|
| 52 | |
---|
| 53 | #ifdef _AIX |
---|
| 54 | return AIX; |
---|
| 55 | #endif |
---|
| 56 | |
---|
| 57 | #ifdef sun |
---|
| 58 | return SUN; |
---|
| 59 | #endif |
---|
| 60 | |
---|
| 61 | #ifdef SUN3 |
---|
| 62 | return SUN; |
---|
| 63 | #endif |
---|
| 64 | |
---|
| 65 | #ifdef SUN4 |
---|
| 66 | return SUN; |
---|
| 67 | #endif |
---|
| 68 | |
---|
| 69 | #ifdef __sgi |
---|
| 70 | return SGI; |
---|
| 71 | #endif |
---|
| 72 | |
---|
| 73 | printf("Cannot detect platform\n"); |
---|
| 74 | exit(1); |
---|
| 75 | |
---|
| 76 | return 0; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | void *l_obj_get(long number) { return NULL; } // exten lisp function switches on number |
---|
| 81 | void l_obj_set(long number, void *arg) { ; } // exten lisp function switches on number |
---|
| 82 | void l_obj_print(long number) { ; } // exten lisp function switches on number |
---|
| 83 | |
---|
| 84 | void clisp_init() |
---|
| 85 | { // external initalizer call by lisp_init() |
---|
| 86 | void *platform=make_find_symbol("platform"); |
---|
| 87 | set_symbol_value(platform,make_find_symbol(plat_name[detect_platform()])); |
---|
| 88 | add_lisp_function("get_depends",3,3, 0); |
---|
| 89 | add_lisp_function("split_filename",2,2, 1); |
---|
| 90 | add_lisp_function("convert_slashes",2,2, 2); |
---|
| 91 | add_lisp_function("make_dir",1,1, 3); |
---|
| 92 | add_lisp_function("extension",1,1, 4); |
---|
| 93 | add_lisp_function("system",1,1, 5); |
---|
| 94 | add_lisp_function("get_cwd",0,0, 6); |
---|
| 95 | |
---|
| 96 | add_lisp_function("mangle_oname",1,1, 7); |
---|
| 97 | |
---|
| 98 | add_c_bool_fun("chdir",1,1, 1); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | #ifdef __WATCOMC__ |
---|
| 103 | #include <dos.h> |
---|
| 104 | #endif |
---|
| 105 | |
---|
| 106 | int change_dir(char *path) |
---|
| 107 | { |
---|
| 108 | #ifdef __WATCOMC__ |
---|
| 109 | unsigned cur_drive; |
---|
| 110 | _dos_getdrive(&cur_drive); |
---|
| 111 | if (path[1]==':') |
---|
| 112 | { |
---|
| 113 | unsigned total; |
---|
| 114 | _dos_setdrive(toupper(path[0])-'A'+1,&total); |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | unsigned new_drive; |
---|
| 118 | _dos_getdrive(&new_drive); |
---|
| 119 | |
---|
| 120 | if (new_drive!=toupper(path[0])-'A'+1) |
---|
| 121 | { |
---|
| 122 | return 0; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | path+=2; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | int er=chdir(path); |
---|
| 129 | if (er) |
---|
| 130 | { |
---|
| 131 | unsigned total; |
---|
| 132 | _dos_setdrive(cur_drive,&total); |
---|
| 133 | } |
---|
| 134 | return !er; |
---|
| 135 | #else |
---|
| 136 | int ret=chdir(path); // weird |
---|
| 137 | ret=chdir(path); |
---|
| 138 | return ret==0; |
---|
| 139 | #endif |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | long c_caller(long number, void *arg) // exten c function switches on number |
---|
| 143 | { |
---|
| 144 | switch (number) |
---|
| 145 | { |
---|
| 146 | case 1 : |
---|
| 147 | { |
---|
| 148 | if (change_dir(lstring_value(eval(CAR(arg))))) |
---|
| 149 | return 1; |
---|
| 150 | else return 0; |
---|
| 151 | } break; |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | void get_depends(char *fn, char *slash, void *ilist, void *&ret) |
---|
| 156 | { |
---|
| 157 | p_ref r8(ret); |
---|
| 158 | p_ref r1(ilist); |
---|
| 159 | void *v=ret; |
---|
| 160 | p_ref r2(v); |
---|
| 161 | for (;v;v=CDR(v)) |
---|
| 162 | if (!strcmp(fn,lstring_value(CAR(v)))) return ; // check to see if file already in list |
---|
| 163 | |
---|
| 164 | char tmp_name[200]; |
---|
| 165 | strcpy(tmp_name,fn); |
---|
| 166 | FILE *fp=fopen(fn,"rb"); |
---|
| 167 | if (!fp) |
---|
| 168 | { |
---|
| 169 | for (v=ilist;!fp && v;v=CDR(v)) |
---|
| 170 | { |
---|
| 171 | sprintf(tmp_name,"%s%s%s",lstring_value(CAR(v)),slash,fn); |
---|
| 172 | for (void *v=ret;v;v=CDR(v)) |
---|
| 173 | if (!strcmp(tmp_name,lstring_value(CAR(v)))) return ; |
---|
| 174 | // check to see if file already in list |
---|
| 175 | fp=fopen(tmp_name,"rb"); |
---|
| 176 | } |
---|
| 177 | } |
---|
| 178 | if (fp) |
---|
| 179 | { |
---|
| 180 | push_onto_list(new_lisp_string(tmp_name),ret); |
---|
| 181 | |
---|
| 182 | char line[200]; |
---|
| 183 | while (!feof(fp)) |
---|
| 184 | { |
---|
| 185 | fgets(line,200,fp); |
---|
| 186 | if (!feof(fp)) |
---|
| 187 | { |
---|
| 188 | if (memcmp(line,"#include",8)==0) |
---|
| 189 | { |
---|
| 190 | char *ch,*ch2; |
---|
| 191 | for (ch=line+8;*ch==' ' || *ch=='\t';ch++); |
---|
| 192 | if (*ch=='"') |
---|
| 193 | { |
---|
| 194 | ch++; |
---|
| 195 | for (ch2=line;*ch!='"';ch++,ch2++) |
---|
| 196 | { *ch2=*ch; } |
---|
| 197 | *ch2=0; |
---|
| 198 | get_depends(line,slash,ilist,ret); |
---|
| 199 | } |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | fclose(fp); |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | void *l_caller(long number, void *arg) |
---|
| 208 | { |
---|
| 209 | p_ref r1(arg); |
---|
| 210 | void *ret=NULL; |
---|
| 211 | switch (number) |
---|
| 212 | { |
---|
| 213 | case 0 : |
---|
| 214 | { |
---|
| 215 | void *fn=eval(CAR(arg)); arg=CDR(arg); |
---|
| 216 | p_ref r1(fn); |
---|
| 217 | void *sl=eval(CAR(arg)); arg=CDR(arg); |
---|
| 218 | p_ref r2(sl); |
---|
| 219 | |
---|
| 220 | void *ilist=eval(CAR(arg)); |
---|
| 221 | p_ref r3(ilist); |
---|
| 222 | |
---|
| 223 | char filename[200]; |
---|
| 224 | strcpy(filename,lstring_value(fn)); |
---|
| 225 | |
---|
| 226 | char slash[10]; |
---|
| 227 | strcpy(slash,lstring_value(sl)); |
---|
| 228 | |
---|
| 229 | get_depends(filename,slash,ilist,ret); |
---|
| 230 | void *v=ret; |
---|
| 231 | if (v && CDR(v)) |
---|
| 232 | { |
---|
| 233 | for (;CDR(CDR(v));v=CDR(v)); CDR(v)=NULL; //chop of self |
---|
| 234 | } |
---|
| 235 | } break; |
---|
| 236 | case 1 : |
---|
| 237 | { |
---|
| 238 | void *fn=eval(CAR(arg)); arg=CDR(arg); |
---|
| 239 | p_ref r1(fn); |
---|
| 240 | char *current_dir=lstring_value(eval(CAR(arg))); |
---|
| 241 | char *filename=lstring_value(fn); |
---|
| 242 | |
---|
| 243 | char *last=NULL,*s=filename,*dp; |
---|
| 244 | char dir[200],name[200]; |
---|
| 245 | while (*s) { if (*s=='\\' || *s=='/') last=s+1; s++; } |
---|
| 246 | if (last) |
---|
| 247 | { |
---|
| 248 | for (dp=dir,s=filename;s!=last;dp++,s++) { *dp=*s; } |
---|
| 249 | *dp=0; |
---|
| 250 | strcpy(name,last); |
---|
| 251 | } else |
---|
| 252 | { |
---|
| 253 | strcpy(dir,current_dir); |
---|
| 254 | strcpy(name,filename); |
---|
| 255 | } |
---|
| 256 | void *cs=(void *)new_cons_cell(); |
---|
| 257 | p_ref r24(cs); |
---|
| 258 | ((cons_cell *)cs)->car=new_lisp_string(dir); |
---|
| 259 | ((cons_cell *)cs)->cdr=new_lisp_string(name); |
---|
| 260 | ret=cs; |
---|
| 261 | } break; |
---|
| 262 | case 2 : |
---|
| 263 | { |
---|
| 264 | void *fn=eval(CAR(arg)); arg=CDR(arg); |
---|
| 265 | p_ref r1(fn); |
---|
| 266 | char *slash=lstring_value(eval(CAR(arg))); |
---|
| 267 | char *filename=lstring_value(fn); |
---|
| 268 | |
---|
| 269 | char tmp[200],*s=filename,*tp; |
---|
| 270 | |
---|
| 271 | for (tp=tmp;*s;s++,tp++) |
---|
| 272 | { |
---|
| 273 | if (*s=='/' || *s=='\\') |
---|
| 274 | { |
---|
| 275 | *tp=*slash; |
---|
| 276 | // if (*slash=='\\') |
---|
| 277 | // { tp++; *tp='\\'; } |
---|
| 278 | } |
---|
| 279 | else *tp=*s; |
---|
| 280 | } |
---|
| 281 | *tp=0; |
---|
| 282 | ret=new_lisp_string(tmp); |
---|
| 283 | } break; |
---|
| 284 | case 3 : |
---|
| 285 | { |
---|
| 286 | char name_so_far[100]; |
---|
| 287 | char *dir=lstring_value(eval(CAR(arg))); |
---|
| 288 | char *d,ch; |
---|
| 289 | d=dir; |
---|
| 290 | while (*d) |
---|
| 291 | { |
---|
| 292 | if (*d=='\\' || *d=='/') |
---|
| 293 | { |
---|
| 294 | ch=*d; |
---|
| 295 | *d=0; |
---|
| 296 | make_dir(dir); |
---|
| 297 | *d=ch; |
---|
| 298 | |
---|
| 299 | } |
---|
| 300 | d++; |
---|
| 301 | } |
---|
| 302 | ret=NULL; |
---|
| 303 | } break; |
---|
| 304 | case 4 : |
---|
| 305 | { |
---|
| 306 | char *fn=lstring_value(eval(CAR(arg))); |
---|
| 307 | char *l=NULL,*s=fn; |
---|
| 308 | while (*s) { if (*s=='.') l=s; s++; } |
---|
| 309 | if (l) ret=new_lisp_string(l); |
---|
| 310 | else ret=new_lisp_string(""); |
---|
| 311 | } break; |
---|
| 312 | case 5 : |
---|
| 313 | { |
---|
| 314 | ret=new_lisp_number(system(lstring_value(eval(CAR(arg))))); |
---|
| 315 | } break; |
---|
| 316 | case 6 : |
---|
| 317 | { |
---|
| 318 | char cd[150]; |
---|
| 319 | getcwd(cd,100); |
---|
| 320 | return new_lisp_string(cd); |
---|
| 321 | } break; |
---|
| 322 | case 7 : |
---|
| 323 | { |
---|
| 324 | char *fn=lstring_value(eval(CAR(arg))); |
---|
| 325 | uchar c1=0,c2=0,c3=0,c4=0; |
---|
| 326 | while (*fn) |
---|
| 327 | { |
---|
| 328 | c1+=*fn; |
---|
| 329 | c2+=c1; |
---|
| 330 | c3+=c2; |
---|
| 331 | c4+=c3; |
---|
| 332 | fn++; |
---|
| 333 | } |
---|
| 334 | char st[15]; |
---|
| 335 | sprintf(st,"%02x%02x%02x%02x",c1,c2,c3,c4); |
---|
| 336 | return new_lisp_string(st); |
---|
| 337 | } break; |
---|
| 338 | } |
---|
| 339 | return ret; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | |
---|
| 343 | // exten lisp function switches on number |
---|
| 344 | |
---|
| 345 | |
---|
| 346 | main(int argc, char **argv) |
---|
| 347 | { |
---|
| 348 | lisp_init(5*1000*1024,5*1000*1024); |
---|
| 349 | char *use_file="maker.lsp"; |
---|
| 350 | for (int i=1;i<argc;i++) |
---|
| 351 | { |
---|
| 352 | if (!strcmp(argv[i],"-f")) |
---|
| 353 | { |
---|
| 354 | i++; |
---|
| 355 | use_file=argv[i]; |
---|
| 356 | } |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | char prog[100],*s; |
---|
| 360 | sprintf(prog,"(compile-file \"%s\")\n",use_file); |
---|
| 361 | s=prog; |
---|
| 362 | if (!eval(compile(s))) |
---|
| 363 | { |
---|
| 364 | printf("unable to open file %s",use_file); |
---|
| 365 | exit(0); |
---|
| 366 | } |
---|
| 367 | return 0; |
---|
| 368 | } |
---|
| 369 | |
---|
| 370 | |
---|
| 371 | |
---|
| 372 | |
---|
| 373 | |
---|