source: abuse/trunk/src/text_gui.cpp @ 90

Last change on this file since 90 was 90, checked in by Sam Hocevar, 11 years ago
  • Get rid of WATCOMC tests.
File size: 3.1 KB
Line 
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
12#include <ctype.h>
13
14#include <unistd.h>
15#include <stdio.h>
16#include <string.h>
17#include <stdlib.h>
18
19#include <sys/stat.h>
20#define make_dir(dir) mkdir(dir,S_IRWXU | S_IRWXG | S_IRWXO)
21
22#include "lisp.hpp"
23#include "lisp_gc.hpp"
24
25int change_dir(char *path)
26{
27    int ret = chdir(path); // weird
28    ret = chdir(path);
29    return ret == 0;
30}
31
32long K_avail(char *path);
33
34int nice_copy(char *title, char *source, char *dest) { return 0; }
35
36long K_avail(char *path)
37{
38#if 0 // ugh
39  char cmd[100];
40  sprintf(cmd,"du %s",path);
41  FILE *fp=popen(cmd,"rb");
42  if (!fp)
43  {
44    pclose(fp);
45    return 20000;
46  }
47  else
48  {
49    fgets(cmd,100,fp);
50    if (feof(fp))
51    {
52      pclose(fp);
53      return 20000;
54    }
55    fgets(cmd,100,fp);
56    char *s=cmd+strlen(cmd)-1;
57    while (*s==' ' || *s=='\t') s--;
58    while (*s!=' ' && *s!='\t') s--;  // skip last field
59
60    while (*s==' ' || *s=='\t') s--;
61    while (*s!=' ' && *s!='\t') s--;  // skip last field
62
63    while (*s==' ' || *s=='\t') s--;
64    while (*s!=' ' && *s!='\t') s--; s++;  // skip last field
65
66    long a;
67    sscanf(s,"%d",&a);
68   
69    pclose(fp);
70    return a;
71  }
72#endif
73        return 0;
74}
75
76void *show_yes_no(void *t, void *msg, void *y, void *n)
77{
78  p_ref r1(t),r2(msg),r3(y),r4(n);
79  t=eval(t); msg=eval(msg); y=eval(y); n=eval(n);
80  int c;
81  char const *yes = lstring_value(y);
82  char const *no = lstring_value(n);
83  do
84  {
85    printf("\n\n\n\n\n%s\n\n",lstring_value(t));
86    void *v=msg;
87    if (item_type(v)==L_CONS_CELL)
88      while (v) { printf("** %s\n",lstring_value(CAR(v))); v=CDR(v); }
89    else printf("** %s\n",lstring_value(v));
90    char msg[100];
91    fgets(msg,100,stdin);
92    c=msg[0];
93  } while (toupper(c)!=toupper(yes[0]) && toupper(c)!=toupper(no[0]));
94  if (toupper(c)==toupper(yes[0]))
95    return true_symbol;
96  else return NULL;
97}
98
99void *nice_menu(void *main_title, void *menu_title, void *list)
100{
101  p_ref r1(main_title),r2(menu_title),r3(list);
102  main_title=eval(main_title);  menu_title=eval(menu_title);  list=eval(list);
103  char msg[100];
104  int i=0,d;
105  do
106  {
107    printf("\n\n\n\n\n%s\n\n%s\n-----------------------------------\n",
108           lstring_value(main_title),lstring_value(menu_title));
109
110    void *v=list;
111    for (;v;v=CDR(v),i++)
112    {
113      printf("%d) %s\n",i+1,lstring_value(CAR(v)));
114    }
115    fprintf(stderr,"> ");
116    fgets(msg,100,stdin);
117    sscanf(msg,"%d",&d);
118  } while (d-1>=i && d<=0);
119  return new_lisp_number(d-1);
120}
121
122void *nice_input(char *t, char *p, char *d)
123{
124        unsigned int x;
125        for( x = 0; x < ( 40 - strlen( t ) / 2 ); x++ ) printf(" ");
126        printf("%s\n",t);
127        for( x = 0; x < 78; x++ ) printf("-"); printf("\n");
128        fprintf( stderr, "%s (ENTER=%s) > ", p, d );
129        char ln[100];
130        fgets( ln, 100, stdin ); ln[strlen(ln) - 1] = 0;
131        if( ln[0] == 0 )
132        {
133                strcpy(ln,d);                  // d might get collect in next new
134                return new_lisp_string(ln);
135        }
136        else
137                return new_lisp_string(ln);
138}
139
Note: See TracBrowser for help on using the repository browser.