Subversion Repositories SvarDOS

Rev

Rev 353 | Rev 355 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 353 Rev 354
Line 103... Line 103...
103
  argvlist[argc] = NULL;
103
  argvlist[argc] = NULL;
104
  return(argc);
104
  return(argc);
105
}
105
}
106
 
106
 
107
 
107
 
-
 
108
static void buildprompt(char *s, const char *fmt) {
-
 
109
  for (; *fmt != 0; fmt++) {
-
 
110
    if (*fmt != '$') {
-
 
111
      *s = *fmt;
-
 
112
      s++;
-
 
113
      continue;
-
 
114
    }
-
 
115
    /* escape code ($P, etc) */
-
 
116
    fmt++;
-
 
117
    switch (*fmt) {
-
 
118
      case 'Q':  /* $Q = = (equal sign) */
-
 
119
      case 'q':
-
 
120
        *s = '=';
-
 
121
        s++;
-
 
122
        break;
-
 
123
      case '$':  /* $$ = $ (dollar sign) */
-
 
124
        *s = '$';
-
 
125
        s++;
-
 
126
        break;
-
 
127
      case 'T':  /* $t = current time */
-
 
128
      case 't':
-
 
129
        s += sprintf(s, "00:00"); /* TODO */
-
 
130
        break;
-
 
131
      case 'D':  /* $D = current date */
-
 
132
      case 'd':
-
 
133
        s += sprintf(s, "1985-07-29"); /* TODO */
-
 
134
        break;
-
 
135
      case 'P':  /* $P = current drive and path */
-
 
136
      case 'p':
-
 
137
        _asm {
-
 
138
          mov ah, 0x19    /* DOS 1+ - GET CURRENT DRIVE */
-
 
139
          int 0x21
-
 
140
          mov bx, s
-
 
141
          mov [bx], al  /* AL = drive (00 = A:, 01 = B:, etc */
-
 
142
        }
-
 
143
        *s += 'A';
-
 
144
        s++;
-
 
145
        *s = ':';
-
 
146
        s++;
-
 
147
        *s = '\\';
-
 
148
        s++;
-
 
149
        _asm {
-
 
150
          mov ah, 0x47    /* DOS 2+ - CWD - GET CURRENT DIRECTORY */
-
 
151
          xor dl,dl       /* DL = drive number (00h = default, 01h = A:, etc) */
-
 
152
          mov si, s       /* DS:SI -> 64-byte buffer for ASCIZ pathname */
-
 
153
          int 0x21
-
 
154
        }
-
 
155
        while (*s != 0) s++; /* move ptr forward to end of pathname */
-
 
156
        break;
-
 
157
      case 'V':  /* $V = DOS version number */
-
 
158
      case 'v':
-
 
159
        s += sprintf(s, "VER"); /* TODO */
-
 
160
        break;
-
 
161
      case 'N':  /* $N = current drive */
-
 
162
      case 'n':
-
 
163
        _asm {
-
 
164
          mov ah, 0x19    /* DOS 1+ - GET CURRENT DRIVE */
-
 
165
          int 0x21
-
 
166
          mov bx, s
-
 
167
          mov [bx], al  /* AL = drive (00 = A:, 01 = B:, etc */
-
 
168
        }
-
 
169
        *s += 'A';
-
 
170
        s++;
-
 
171
        break;
-
 
172
      case 'G':  /* $G = > (greater-than sign) */
-
 
173
      case 'g':
-
 
174
        *s = '>';
-
 
175
        s++;
-
 
176
        break;
-
 
177
      case 'L':  /* $L = < (less-than sign) */
-
 
178
      case 'l':
-
 
179
        *s = '<';
-
 
180
        s++;
-
 
181
        break;
-
 
182
      case 'B':  /* $B = | (pipe) */
-
 
183
      case 'b':
-
 
184
        *s = '|';
-
 
185
        s++;
-
 
186
        break;
-
 
187
      case 'H':  /* $H = backspace (erases previous character) */
-
 
188
      case 'h':
-
 
189
        *s = '\b';
-
 
190
        s++;
-
 
191
        break;
-
 
192
      case 'E':  /* $E = Escape code (ASCII 27) */
-
 
193
      case 'e':
-
 
194
        *s = 27;
-
 
195
        s++;
-
 
196
        break;
-
 
197
      case '_':  /* $_ = CR+LF */
-
 
198
        *s = '\r';
-
 
199
        s++;
-
 
200
        *s = '\n';
-
 
201
        s++;
-
 
202
        break;
-
 
203
    }
-
 
204
  }
-
 
205
  *s = '$';
-
 
206
}
108
 
207
 
109
 
208
 
110
int main(int argc, char **argv) {
209
int main(int argc, char **argv) {
111
  struct config cfg;
210
  struct config cfg;
112
  unsigned short rmod_seg;
211
  unsigned short rmod_seg;
Line 140... Line 239...
140
  }
239
  }
141
 
240
 
142
  for (;;) {
241
  for (;;) {
143
    int i, argcount;
242
    int i, argcount;
144
    char far *cmdline = MK_FP(rmod_seg, RMOD_OFFSET_INPBUFF + 2);
243
    char far *cmdline = MK_FP(rmod_seg, RMOD_OFFSET_INPBUFF + 2);
145
    char path[256] = "C:\\>$";
244
    char buff[256];
146
    char const *argvlist[256];
245
    char const *argvlist[256];
147
    union REGS r;
-
 
148
 
246
 
-
 
247
    {
149
    /* print shell prompt */
248
      /* print shell prompt */
-
 
249
      char *promptptr = buff;
-
 
250
      buildprompt(promptptr, "$p$g"); /* TODO: prompt should be configurable via environment */
-
 
251
      _asm {
-
 
252
        push dx
150
    r.h.ah = 0x09;
253
        mov ah, 0x09
151
    r.x.dx = FP_OFF(path);
254
        mov dx, promptptr
152
    intdos(&r, &r);
255
        int 0x21
-
 
256
        pop dx
-
 
257
      }
-
 
258
    }
153
 
259
 
154
    /* wait for user input */
260
    /* wait for user input */
155
    _asm {
261
    _asm {
156
      push ds
262
      push ds
157
 
263
 
Line 185... Line 291...
185
 
291
 
186
    /* if nothing entered, loop again */
292
    /* if nothing entered, loop again */
187
    if (cmdline[-1] == 0) continue;
293
    if (cmdline[-1] == 0) continue;
188
 
294
 
189
    /* copy buffer to a near var (incl. trailing CR) */
295
    /* copy buffer to a near var (incl. trailing CR) */
190
    _fmemcpy(path, cmdline, cmdline[-1] + 1);
296
    _fmemcpy(buff, cmdline, cmdline[-1] + 1);
191
 
297
 
192
    argcount = explode_progparams(path, argvlist);
298
    argcount = explode_progparams(buff, argvlist);
193
 
299
 
194
    /* if nothing args found (eg. all-spaces), loop again */
300
    /* if nothing args found (eg. all-spaces), loop again */
195
    if (argcount == 0) continue;
301
    if (argcount == 0) continue;
196
 
302
 
197
    printf("got %u bytes of cmdline (%d args)\r\n", cmdline[-1], argcount);
303
    printf("got %u bytes of cmdline (%d args)\r\n", cmdline[-1], argcount);