47 static n_int command_line_execution;
48 static n_int command_line_external_exit = 0;
51 #define CHAR_SPACE (32)
55 #define IS_RETURN(val) (((val) == 10) || ((val) == 13))
56 #define IS_TAB(val) ((val) == CHAR_TAB)
57 #define IS_SPACE(val) ((val) == CHAR_SPACE)
58 #define IS_WHITE_HORIZON(val) (IS_TAB(val) || IS_SPACE(val))
59 #define IS_WHITE_SPACE(val) (IS_WHITE_HORIZON((val))||IS_RETURN((val)))
60 #define FILE_END_INCLUSION 0x0101
61 #define FILE_TYPE(num) ((num)&0x07)
62 #define FILE_CONTINUATION 0x80
66 command_line_execution = 1;
71 return command_line_execution;
78 if ((argc == 2) && (argv[1][0] ==
'c'))
93 memcpy(to, from, number);
106 tmp = (
void *) malloc(bytes);
132 void * memory_buffer = 0L;
135 memory_buffer = (
void *) malloc(*memory_allocated);
136 if (memory_buffer == 0L)
138 *memory_allocated = ((*memory_allocated) * 3) >> 2;
141 while((memory_buffer == 0L) && ((*memory_allocated)>memory_min));
142 return memory_buffer;
154 while (loop < length)
174 if (output->
data == 0L)
192 io_free((
void **)&((*file)->data));
220 FILE * in_file = fopen(file_name,
"rb");
223 fopen_s(&in_file,file_name,
"rb");
229 while (!feof(in_file))
232 if (fread(&local_char,1,1,in_file)>0)
257 FILE * out_file = 0L;
259 out_file = fopen(file_name,
"wb");
261 fopen_s(&out_file,file_name,
"wb");
265 return SHOW_ERROR(
"Error opening file to write");
267 if (local_file->
data == 0L)
269 return SHOW_ERROR(
"No data in file to be written");
272 written_length = fwrite(local_file->
data,1,local_file->
location, out_file);
274 if (fclose(out_file) != 0)
276 return SHOW_ERROR(
"File could not be closed");
279 if (written_length != local_file->
location)
281 return SHOW_ERROR(
"File did not complete write");
295 FILE * local_check_file = fopen(file_name,
"rb");
297 FILE * local_check_file = 0L;
299 fopen_s(&local_check_file,file_name,
"rb");
302 if (local_check_file == 0L)
305 if (fclose(local_check_file) != 0)
320 n_uint file_location = fil -> location;
321 if (file_location >= (fil -> size))
326 *local_byte = fil -> data[file_location];
327 fil->
location = (file_location + 1);
355 n_int string_point_location = 1;
356 n_int first_value = 0;
359 n_int local_row_value = 0;
364 while (loop < tab_file->location)
366 resultant_value = tab_file->
data[loop];
369 tab_file->
data[loop] = 0;
371 if ((local_row_value == 0) &&
IS_RETURN(resultant_value))
373 local_row_value = string_point_location;
380 string_point_location++;
388 if (size_value != 0L)
390 *size_value = string_point_location;
395 *row_value = local_row_value;
408 string_point_location = 0;
412 string_point[string_point_location++] = (
n_string)&(tab_file->
data[0]);
413 while (loop < tab_file->location)
415 resultant_value = tab_file->
data[loop];
416 if ((first_value) && (resultant_value != 0))
418 string_point[string_point_location++] = (
n_string)&(tab_file->
data[loop]);
421 if (resultant_value == 0)
441 n_int ten_power_place = 0;
444 n_byte value = io_read(fil);
448 *actual_value = temp;
450 return ten_power_place;
452 mod_ten = value -
'0';
453 if ((temp == 429496729) && (mod_ten > 5))
457 if (temp > 429496729)
461 temp = (temp * 10) + mod_ten;
477 n_int ten_power_place = 0;
478 n_int string_point = 0;
481 if (number_string == 0L)
return -1;
482 if (number_string[0] == 0)
return -1;
484 if (number_string[0] ==
'-')
492 n_byte value = number_string[string_point++];
500 translate = 0 - temp;
507 *actual_value = translate;
514 *decimal_divisor = divisor;
515 return ten_power_place;
532 mod_ten = value -
'0';
533 if (temp == 214748364)
550 if (temp > 214748364)
558 temp = (temp * 10) + mod_ten;
564 #define ASCII_WHITESPACE(num) ((((num)>8)&&((num)<14))||((num)==32))
572 n_uint loop = 0, out_loop = 0;
577 n_byte temp = local_data[loop++];
579 if((temp ==
'/') && (loop != end_loop))
581 n_byte check_twice[2]= {
'/', 0};
582 check_twice[1] = local_data[loop++];
583 if(check_twice[1] !=
'*')
585 local_data[out_loop++] =
'/';
588 local_data[out_loop++] = check_twice[1];
597 check_twice[0] = check_twice[1];
598 check_twice[1] = local_data[loop++];
600 while((loop != end_loop) && !((check_twice[0]==
'*')&&(check_twice[1]==
'/')));
605 local_data[out_loop++] = temp;
609 while (loop < end_loop)
611 local_data[loop++] = 0;
613 input->
size = out_loop;
628 if((fil->
location + 1) == local_size)
633 if (local_size <= (256*1024))
635 temp_size = local_size * 4;
639 if (local_size <= (512*1024*1024))
641 temp_size = local_size * 2;
645 temp_size = (local_size * 3) >> 1;
648 temp_data =
io_new(temp_size);
651 return(
SHOW_ERROR(
"Attempted file overwrite"));
655 fil->
data = temp_data;
656 fil->
size = temp_size;
682 n_int return_length = -1;
691 while ((value[return_length] != 0) && (return_length < max));
692 return return_length;
717 n_int check_length = 0;
720 if (check[loop] == value_find[check_length])
723 if (check_length == value_find_length)
738 #define FILE_MACRO_WRITE(ch) if(io_file_write(fil,(ch)) == -1) return -1
770 n_byte number_buffer[14] = {0};
778 positive_number = 0 - loc_val;
783 positive_number = loc_val;
788 n_uint roll_over = positive_number;
790 positive_number = positive_number * numer * 100;
792 if(positive_number < roll_over)
795 positive_number = positive_number / denom;
801 number_buffer[location --] = (
n_byte)((positive_number % 10) +
'0');
802 positive_number = positive_number / 10;
803 if(decimal && location == 10)
805 number_buffer[location --] =
'.';
806 if(positive_number == 0)
807 number_buffer[location --] =
'0';
810 while((positive_number>0) || (decimal && (location > 9)));
812 number_buffer[location] =
'-';
821 n_byte ekind_buffer[2] = {0};
824 ekind_buffer[0] = ekind;
832 n_byte found_text[7] = {0};
833 n_byte * commands_bytes = (
n_byte *) commands[0].characters;
837 found_text[0] = io_read(fil);
838 if (found_text[0] == 0)
842 found_text[1] = io_read(fil);
843 if (found_text[0] ==
'}' && found_text[1] ==
';')
847 found_text[2] = io_read(fil);
848 found_text[3] = io_read(fil);
849 found_text[4] = io_read(fil);
850 found_text[5] = io_read(fil);
854 commands_bytes = (
n_byte *) commands[lp].characters;
855 if (((commands_bytes[0] == found_text[0]) && (commands_bytes[1] == found_text[1])) &&
856 ((commands_bytes[2] == found_text[2]) && (commands_bytes[3] == found_text[3])) &&
857 ((commands_bytes[4] == found_text[4]) && (commands_bytes[5] == found_text[5])))
879 if (last_incl != data_incl)
899 if (running_entry > max_entry)
901 max_entry = running_entry;
903 last_incl = data_incl;
911 #define FILE_MACRO_CONCLUSION(ch) (((comman_req==1) && (ch) == ',') || \
912 ((comman_req==0) && (ch) == ';'))
935 buffer[0] = io_read(fil);
936 buffer[1] = io_read(fil);
937 buffer[2] = io_read(fil);
939 output_val = (buffer[0]-65);
940 output_val += (buffer[1]-65) * 41;
941 output_val += (buffer[2]-65) * 41 * 41;
943 data_read[loop++] = (output_val >> 0) & 255;
944 data_read[loop++] = (output_val >> 8) & 255;
946 num_char = io_read(fil);
962 if (response_code == 0)
964 return SHOW_ERROR(
"Expected number not found");
966 if (response_code < 0)
973 if (number > 0x000000ff)
975 data_read[0] = (
n_byte) number;
981 if (number > 0x0000ffff)
982 return SHOW_ERROR(
"Expected two byte too big");
983 data_read2[0] = (
n_byte2) number;
989 data_read4[0] = (
n_byte4) number;
1002 printf(
"--------------------FILE--------------------\n");
1003 printf(
"Location %ld\n", file->
location);
1004 printf(
"Size %ld\n", file->
size);
1005 printf(
"* * * * * * \n");
1007 while (loop < file->location)
1009 printf(
"%c", file->
data[loop++]);
1011 printf(
"--------------------------------------------n");
1028 n_int inclusion_number = 0xffff;
1029 n_int result_number = 0;
1033 if(result_number == -1)
1036 if (result_number > 0x00ff)
1039 return (result_number);
1050 n_byte *local_data = &data[com_location];
1052 if (inclusion_number == 0xffff)
1054 if (commands[result_number].characters[5] !=
'{')
1056 inclusion_number = com_inclusion;
1058 if (inclusion_number != com_inclusion)
1061 while (loop < com_number_of)
1063 n_byte local_kind = com_kind;
1064 if ((loop + 1) != com_number_of)
1080 local_data = &local_data[ 1 ];
1084 local_data = &local_data[ com_kind ];
1092 return (inclusion_number);
1095 #define IO_CHECK_ERROR(cnd) \
1097 n_int out_cnd = cnd; \
1098 if ( (out_cnd) != FILE_OKAY) \
1131 const n_byte *commands_bytes;
1132 n_byte writeout_commands[7]= {0};
1137 commands_bytes = commands[offset].
characters;
1138 if ((commands_bytes[0] == 0) && (commands_bytes[1] == 0) &&
1139 (commands_bytes[2] == 0) && (commands_bytes[3] == 0) &&
1140 (commands_bytes[4] == 0) && (commands_bytes[5] == 0))
1145 if (
FILE_INCL(commands[offset].incl_kind) == command_num)
1151 writeout_commands[0] = commands_bytes[0];
1152 writeout_commands[1] = commands_bytes[1];
1153 writeout_commands[2] = commands_bytes[2];
1154 writeout_commands[3] = commands_bytes[3];
1155 writeout_commands[4] = commands_bytes[4];
1156 writeout_commands[5] = commands_bytes[5];
1163 commands_bytes = commands[offset].
characters;
1165 if ((commands_bytes[0] == 0) && (commands_bytes[1] == 0) &&
1166 (commands_bytes[2] == 0) && (commands_bytes[3] == 0) &&
1167 (commands_bytes[4] == 0) && (commands_bytes[5] == 0))
1170 if (
FILE_INCL(commands[offset].incl_kind) != command_num)
1179 n_int right_ending = (
FILE_INCL(commands[offset+1].incl_kind) != command_num);
1181 right_ending |= ((commands[offset+1].
characters[0] == 0) && (commands[offset+1].characters[1] == 0) &&
1182 (commands[offset+1].
characters[2] == 0) && (commands[offset+1].characters[3] == 0) &&
1183 (commands[offset+1].
characters[4] == 0) && (commands[offset+1].characters[5] == 0));
1184 right_ending = 3 - (right_ending * 2);
1188 if (unpack_data != 0L)
1192 n_byte *local_unpack_data = unpack_data;
1193 writeout_commands[0] = commands_bytes[0];
1194 writeout_commands[1] = commands_bytes[1];
1195 writeout_commands[2] = commands_bytes[2];
1196 writeout_commands[3] = commands_bytes[3];
1197 writeout_commands[4] = commands_bytes[4];
1198 writeout_commands[5] = commands_bytes[5];
1200 while (loop < end_loop)
1205 output_val = local_unpack_data[data_loop++];
1206 output_val |= local_unpack_data[data_loop++] << 8;
1207 buffer[0] = (output_val % 41) + 65;
1209 buffer[1] = (output_val % 41) + 65;
1211 buffer[2] = (output_val % 41) + 65;
1213 if ((data_loop % 80 ) == 0)
1224 if (loop == end_loop)
1242 if (func != 0) (*func)((
n_string)block_code, byte_data);
1253 writeout_commands[0] = commands_bytes[0];
1254 writeout_commands[1] = commands_bytes[1];
1255 writeout_commands[2] = commands_bytes[2];
1256 writeout_commands[3] = commands_bytes[3];
1257 writeout_commands[4] = commands_bytes[4];
1258 writeout_commands[5] = commands_bytes[5];
1261 while (loop < end_loop)
1267 if((loop != 0) && ((loop % 3) == 0) && (loop != 126))
1270 if (func != 0L) (*func)(block_code, &byte_data[data_offset + loop]);
1280 num_write = byte_data[data_offset + loop];
1284 num_write = ((
n_byte2 *) &byte_data[data_offset + (loop * 2)])[0];
1288 num_write = ((
n_byte4 *) &byte_data[data_offset + (loop * 4)])[0];
1293 if (loop == end_loop)
1323 const n_byte * commands_bytes;
1327 n_byte writeout_commands[6]= {0};
1330 commands_bytes = commands[offset].
characters;
1331 if ((commands_bytes[0] == 0) && (commands_bytes[1] == 0) &&
1332 (commands_bytes[2] == 0) && (commands_bytes[3] == 0) &&
1333 (commands_bytes[4] == 0) && (commands_bytes[5] == 0))
1335 if (
FILE_INCL(commands[offset].incl_kind) == command_num)
1346 commands_bytes = commands[offset].
characters;
1347 if ((commands_bytes[0] == 0) && (commands_bytes[1] == 0) &&
1348 (commands_bytes[2] == 0) && (commands_bytes[3] == 0) &&
1349 (commands_bytes[4] == 0) && (commands_bytes[5] == 0))
1351 if (
FILE_INCL(commands[offset].incl_kind) != command_num)
1362 while (loop < end_loop)
1366 if (first_entry == 0)
1377 writeout_commands[0] = commands_bytes[0];
1378 writeout_commands[1] = commands_bytes[1];
1379 writeout_commands[2] = commands_bytes[2];
1380 writeout_commands[3] = commands_bytes[3];
1381 writeout_commands[4] = commands_bytes[4];
1382 writeout_commands[5] = commands_bytes[5];
1393 num_write = data[data_offset + loop];
1396 num_write = ((
n_byte2 *) & data[data_offset + (loop * 2)])[0];
1415 memset(buf_offscr, 0, nestop);
1421 n_byte print_file_format_exit = 0;
1422 n_byte print_file_place_show_all = 0;
1426 print_file_place_show_all = 2;
1430 n_byte leave_condition = 0;
1440 (place->
characters[4] == compare[4]) && (0 == compare[5]))
1442 leave_condition = 1;
1448 print_file_format_exit = 1;
1451 while((print_file_format_exit == 0) && (leave_condition == 0));
1453 if (print_file_format_exit == 1)
1460 print_file_place_show_all = 1;
1482 if (print_file_place_show_all == 0)
1486 if ((format[loop].characters[5]==
'{') && (print_file_place_show_all == 1))
1493 print_file_format_exit = 1;
1496 while(print_file_format_exit == 0);
1502 n_uint being_counter = 0;
1503 n_byte *local_characters;
1510 local_characters = (
n_byte*)format[loop].characters;
1511 if ((local_incl_kind & 0xF0) == section_to_audit)
1513 n_uint local_type = local_incl_kind & 0x0F;
1522 printout_characters[0] = local_characters[0];
1523 printout_characters[1] = local_characters[1];
1524 printout_characters[2] = local_characters[2];
1525 printout_characters[3] = local_characters[3];
1526 printout_characters[4] = local_characters[4];
1527 printout_characters[5] = local_characters[5];
1529 printf(
"%s \t %lu * %lu = %lu bytes \t reported/actual/diff offset %d / %d / %d\n", printout_characters,
1530 local_number, local_type, (local_number * local_type), (
int)local_location, (
int)being_counter, ((
int)local_location - (
int)being_counter));
1532 being_counter += (local_number * local_type);
1537 while((local_characters[0] != 0) && (local_characters[1] != 0) &&
1538 (local_characters[2] != 0) && (local_characters[3] != 0));
1548 n_int total = count - (command_length + addition_length + 1);
1556 while (loop2 < total)
1567 n_int military_time = (minutes % 60);
1568 n_int hours = (minutes/60);
1569 military_time += hours * 100;
1570 sprintf(value,
"%4ld:%ld", military_time, days);
1575 printf(
"%s %ld\n", text, (
n_int)(point - start));
1582 output_function(string_line);
1588 n_int response_len = 0;
1593 response_len =
io_length(response, 1024);
1596 if (response_len == 0)
1598 output_function(
"Commands:");
1603 if (local_commands[loop].
function != 0L)
1605 if ((local_commands[loop].help_information) && (local_commands[loop].help_information[0] != 0))
1607 if (response_len == 0)
1613 n_int command_len =
io_length(local_commands[loop].command, 1024);
1614 n_int count =
io_find(response, 0, response_len, local_commands[loop].command, command_len);
1615 if (count == command_len)
1625 while (local_commands[loop].
function != 0L);
1626 if ((response_len != 0) && (found == 0))
1628 (void)
SHOW_ERROR(
"Command not found, type help for more information");
1640 return fgets(
string, (
int)length, stdin);
1651 printf(
"%s\n", value);
1657 command_line_external_exit = 1;
1664 local_commands = commands;
1671 if ((commands[0].command == 0L) && (commands[0].
function == 0L))
1679 buffer[buffer_len-1] = 0;
1684 buffer[buffer_len-1] = 0;
1688 if (buffer_len != 0)
1700 return_value = (*function)(ptr,(
n_string)&buffer[count+1], output_function);
1701 if (command_line_external_exit)
1705 return return_value;
1707 else if (buffer[count] == 0)
1709 return_value = (*function)(ptr,0L, output_function);
1710 if (command_line_external_exit)
1714 return return_value;
1719 while ((commands[loop].command != 0L) && (commands[loop].
function != 0L));
1721 (void)
SHOW_ERROR(
"Command not found, type help for more information");
1738 character = insert [loop++];
1741 dest[*pos] = character;
1744 }
while (character);
1755 local_enum = apescript_errors[loop].enum_value;
1756 local_error = apescript_errors[loop].error_string;
1757 if (value == local_enum)
1771 while((local_enum !=
AE_NO_ERROR) && (local_error != 0L));
1776 #ifdef NOBLE_APE_ASSERT
1780 printf(
"Assert: %s, %s, %ld\n", message, file_loc, line);
1810 if (*entry == 0)
return;
1811 #ifndef COMMAND_LINE_DEBUG
1818 (void)
SHOW_ERROR(
"Could not set up special use file");
1834 if (*entry == 0)
return;
1835 #ifndef COMMAND_LINE_DEBUG
1845 if (entry == 0)
return;
1848 #ifndef COMMAND_LINE_DEBUG
1853 #ifndef COMMAND_LINE_DEBUG
1856 printf(
"%s",
string);