00001
00002
00003
00004 # include <stdio.h>
00005 # include "../parm.h"
00006 # include "strings.h"
00007 # include "tables.h"
00008
00009
00010 char * par_name(i)
00011 int i;
00012 {
00013 register char * result;
00014 if (i < 100) {
00015
00016 result = (char *) GC_malloc_atomic(6);
00017 result[0] = 'a';
00018 result[1] = 'r';
00019 result[2] = 'g';
00020 result[3] = i / 10 + '0';
00021 result[4] = i % 10 + '0';
00022 result[5] = '\0';
00023 } else {
00024 result = (char *) GC_malloc_atomic(12);
00025 sprintf(result, "arg%d", i);
00026 }
00027 return(result);
00028 }
00029
00030
00031 char * itos(i)
00032 int i;
00033 {
00034 register char * result;
00035 if (i > -10 && i < 10) {
00036
00037 result = (char *) GC_malloc_atomic(3);
00038 if (i >= 0) {
00039 result[0] = i + '0';
00040 result[1] = '\0';
00041 } else {
00042 result[0] = '-';
00043 result[1] = '0' - i;
00044 result[2] = '\0';
00045 }
00046 } else {
00047 char buf[30];
00048
00049 sprintf(buf, "%d", i);
00050 result = (char *) GC_malloc_atomic(strlen(buf) + 1);
00051 strcpy(result, buf);
00052 }
00053 return(result);
00054 }
00055
00056
00057
00058 char * rmcntrl(s)
00059 char * s;
00060 {
00061 long new_len = 1 ;
00062 register char * p;
00063 register char * q;
00064 register unsigned c;
00065 char * result;
00066 # define is_cntrl(c) ((c) < 32 || (c) > 127)
00067
00068
00069 for (p = s; *p != '\0'; p++) {
00070 if (is_cntrl(*p)) {
00071 new_len += 4;
00072 } else if (c == '"' || c == '\\') {
00073 new_len += 2;
00074 } else {
00075 new_len += 1;
00076 }
00077 }
00078 q = result = (char *) GC_malloc_atomic(new_len);
00079 for (p = s; *p != '\0'; p++) {
00080 c = (*p) & 0xff;
00081 if (is_cntrl(c)) {
00082 *q++ = '\\';
00083 if (c == '\n') {
00084 *q++ = 'n';
00085 } else if (c == '\t') {
00086 *q++ = 't';
00087 } else {
00088 *q++ = c/64 + '0'; c = c%64;
00089 *q++ = c/8 + '0';
00090 *q++ = c%8 + '0';
00091 }
00092 } else if (c == '"' || c == '\\') {
00093 *q++ = '\\';
00094 *q++ = c;
00095 } else {
00096 *q++ = c;
00097 }
00098 }
00099 *q = '\0';
00100 return(result);
00101 }
00102
00103
00104 char * tmp_decls(n)
00105 int n;
00106 {
00107 char * result = "";
00108 int i;
00109
00110 if (n < 0) return ("");
00111 for (i = 0; i <= n; i++) {
00112 result = concat(result, tmp_name(i));
00113 if (i != n) {
00114 result = concat(result, ",");
00115 }
00116 }
00117 result = concat("word ", concat(result, ";\n"));
00118 return(result);
00119 }
00120
00121
00122 char * par_names(n)
00123 int n;
00124 {
00125 char * result = "";
00126 int i;
00127
00128 for (i = 1; i <= n; i++) {
00129 result = concat(result, par_name(i));
00130 if (i != n) {
00131 result = concat(result, ",");
00132 }
00133 }
00134 return(result);
00135 }
00136
00137
00138
00139 char * arg_list(n)
00140 int n;
00141 {
00142 char * result = "";
00143 int i;
00144
00145 for (i = 1; i <= n; i++) {
00146 result = concat(result, get_expr(ARGLOC(i)));
00147 rem_vr(ARGLOC(i));
00148 if (i != n) {
00149 result = concat(result, ",");
00150 }
00151 }
00152 return(result);
00153 }