Subversion Repositories SvarDOS

Rev

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

Rev 530 Rev 538
Line 66... Line 66...
66
  }
66
  }
67
  return(0);
67
  return(0);
68
}
68
}
69
 
69
 
70
 
70
 
71
/* outputs a NULL-terminated string to stdout */
71
/* outputs a NULL-terminated string to handle (1=stdout 2=stderr) */
72
void output_internal(const char *s, unsigned char nl) {
72
void output_internal(const char *s, unsigned char nl, unsigned char handle) {
73
  const static unsigned char *crlf = "\r\n$";
73
  const static unsigned char *crlf = "\r\n";
74
  _asm {
74
  _asm {
75
    push ds
75
    push ds
76
    pop es         /* make sure es=ds (scasb uses es) */
76
    pop es         /* make sure es=ds (scasb uses es) */
77
    /* get length of s into CX */
77
    /* get length of s into CX */
78
    mov ax, 0x4000 /* ah=DOS "write to file" and AL=0 for NULL matching */
78
    mov ax, 0x4000 /* ah=DOS "write to file" and AL=0 for NULL matching */
Line 86... Line 86...
86
    dec cx         /* this is CX length */
86
    dec cx         /* this is CX length */
87
    jz WRITEDONE   /* do nothing for empty strings */
87
    jz WRITEDONE   /* do nothing for empty strings */
88
 
88
 
89
    /* output by writing to stdout */
89
    /* output by writing to stdout */
90
    /* mov ah, 0x40 */  /* DOS 2+ -- write to file via handle */
90
    /* mov ah, 0x40 */  /* DOS 2+ -- write to file via handle */
-
 
91
    xor bh, bh
91
    mov bx, 1      /* handle 1 is always stdout */
92
    mov bl, handle /* set handle (1=stdout 2=stderr) */
92
    /* mov cx, xxx */ /* write CX bytes */
93
    /* mov cx, xxx */ /* write CX bytes */
93
    /* mov dx, s   */ /* DS:DX is the source of bytes to "write" */
94
    /* mov dx, s   */ /* DS:DX is the source of bytes to "write" */
94
    int 0x21
95
    int 0x21
95
    WRITEDONE:
96
    WRITEDONE:
96
 
97
 
97
    /* print out a CR/LF trailer if nl set */
98
    /* print out a CR/LF trailer if nl set */
98
    or byte ptr [nl], 0
99
    test byte ptr [nl], 0xff
99
    jz FINITO
100
    jz FINITO
-
 
101
    /* bx still contains handle */
-
 
102
    mov ah, 0x40 /* "write to file" */
100
    mov ah, 0x09
103
    mov cx, 2
101
    mov dx, crlf
104
    mov dx, crlf
102
    int 0x21
105
    int 0x21
103
    FINITO:
106
    FINITO:
104
  }
107
  }
105
}
108
}
106
 
109
 
107
 
110
 
108
void nls_output_internal(unsigned short id, unsigned char nl) {
111
static const char *nlsblock_findstr(unsigned short id) {
109
  const char *ptr = langblock + 4; /* first 4 bytes are lang id and lang len */
112
  const char *ptr = langblock + 4; /* first 4 bytes are lang id and lang len */
110
  const char *NOTFOUND = "NLS_STRING_NOT_FOUND";
-
 
111
  /* find the string id in langblock memory */
113
  /* find the string id in langblock memory */
112
  for (;;) {
114
  for (;;) {
113
    if (((unsigned short *)ptr)[0] == id) {
115
    if (((unsigned short *)ptr)[0] == id) {
114
      ptr += 3;
116
      ptr += 3;
115
      break;
-
 
116
    }
-
 
117
    if (ptr[2] == 0) {
-
 
118
      ptr = NOTFOUND;
-
 
119
      break;
117
      return(ptr);
120
    }
118
    }
-
 
119
    if (ptr[2] == 0) return(NULL);
121
    ptr += ptr[2] + 3;
120
    ptr += ptr[2] + 3;
122
  }
121
  }
-
 
122
}
-
 
123
 
-
 
124
 
-
 
125
void nls_output_internal(unsigned short id, unsigned char nl) {
-
 
126
  const char *NOTFOUND = "NLS_STRING_NOT_FOUND";
-
 
127
  const char *ptr = nlsblock_findstr(id);
-
 
128
  if (ptr == NULL) ptr = NOTFOUND;
123
  output_internal(ptr, nl);
129
  output_internal(ptr, nl, hSTDOUT);
-
 
130
}
-
 
131
 
-
 
132
 
-
 
133
/* output DOS error e to stderr */
-
 
134
void nls_outputnl_doserr(unsigned short e) {
-
 
135
  static char errstr[16];
-
 
136
  const char *ptr = NULL;
-
 
137
  /* find string in nls block */
-
 
138
  if (e < 0xff) ptr = nlsblock_findstr(0xff00 | e);
-
 
139
  /* if not found, use a fallback */
-
 
140
  if (ptr == NULL) {
-
 
141
    sprintf(errstr, "DOS ERR %u", e);
-
 
142
    ptr = errstr;
-
 
143
  }
-
 
144
  /* display */
-
 
145
  output_internal(ptr, 1, hSTDERR);
124
}
146
}
125
 
147
 
126
 
148
 
127
/* find first matching files using a FindFirst DOS call
149
/* find first matching files using a FindFirst DOS call
128
 * returns 0 on success or a DOS err code on failure */
150
 * returns 0 on success or a DOS err code on failure */