hschumann2/TempleOS-Source-Code
0838
1 2CHashDefineStr *DefineLoad(U8 *dname,U8 *st)3{//Create DEFINE hash entry with string.4 CHashDefineStr *tmph=CAlloc(sizeof(CHashDefineStr));5 tmph->type=HTT_DEFINE_STR;6 tmph->str=StrNew(dname);7 tmph->data=StrNew(st);8 tmph->cnt=-1;9 tmph->src_link=MStrPrint("AD:0x%X",Caller);10 HashAdd(tmph,Fs->hash_table);11 return tmph;12}13 14CHashDefineStr *DefineLstLoad(U8 *dname,U8 *lst)15{//Create DEFINE list. Not efficient, but handy.16 I64 cnt=0;17 U8 *ptr,**idx;18 CHashDefineStr *tmph=CAlloc(sizeof(CHashDefineStr));19 tmph->type=HTT_DEFINE_STR;20 tmph->str=StrNew(dname);21 tmph->src_link=MStrPrint("AD:0x%X",Caller);22 ptr=lst;23 while (*ptr) {24 if (*ptr!='@')25 cnt++;26 while (*ptr++);27 }28 tmph->data=MAlloc(ptr+1-lst);29 MemCpy(tmph->data,lst,ptr+1-lst);30 tmph->cnt=cnt;31 32 idx=tmph->sub_idx=MAlloc(cnt*sizeof(U8 *));33 ptr=lst;34 while (*ptr) {35 if (*ptr!='@')36 *idx++=ptr;37 while (*ptr++);38 }39 40 HashAdd(tmph,Fs->hash_table);41 return tmph;42}43 44U0 UndefinedDefine(U8 *dname)45{46 ST_ERR_ST "Undefined Define: '%s'.\n",dname;47 throw('UndefDef');48}49 50U8 *Define(U8 *dname)51{//Look for DEFINE named in hash table, return ptr string.52 CHashDefineStr *tmph;53 if (tmph=HashFind(dname,Fs->hash_table,HTT_DEFINE_STR))54 return tmph->data;55 else if (dname)56 UndefinedDefine(dname);57 else58 return NULL;59}60 61U8 *DefineSub(I64 sub,U8 *dname)62{//Return DEFINE list entry indexed by number.63 CHashDefineStr *tmph;64 if (tmph=HashFind(dname,Fs->hash_table,HTT_DEFINE_STR)) {65 if (0<=sub<tmph->cnt)66 return tmph->sub_idx[sub];67 else68 return NULL;69 } else if (dname)70 UndefinedDefine(dname);71 else72 return NULL;73}74 75I64 DefineCnt(U8 *dname)76{//Return cnt of entries in define list.77 CHashDefineStr *tmph;78 if (tmph=HashFind(dname,Fs->hash_table,HTT_DEFINE_STR))79 return tmph->cnt;80 else if (dname)81 UndefinedDefine(dname);82 else83 return -1;84}85 86I64 DefineMatch(U8 *needle,U8 *haystack_lst_dname,I64 flags=0)87{//Find match for string in define list.88 return LstMatch(needle,Define(haystack_lst_dname),flags);89}90 91U0 DefinePrint(U8 *dname,U8 *src,...)92{//Create DEFINE entry with Print()ed string.93 U8 *buf=StrPrintJoin(NULL,src,argc,argv);94 DefineLoad(dname,buf);95 Free(buf);96}97 98U0 SysDefinesLoad()99{100 DefineLstLoad("ST_OFF_ON","Off\0On\0");101 DefineLstLoad("ST_HTT_TYPES","ExportSysSym\0ImportSysSym\0DefineStr\0GlbVar\0"102 "Class\0IntType\0Funct\0Word\0DictWord\0KeyWord\0AsmKeyWord\0OpCode\0"103 "Reg\0File\0Module\0HelpFile\0Frame Ptr\0 \0 \0 \0 \0 \0 \0Private\0"104 "Public\0Export\0Import\0Imm\0Goto\0Res\0Unres\0Local\0");105 DefineLstLoad("ST_DAYS_OF_WEEK","Sunday\0Monday\0Tuesday\0Wednesday\0"106 "Thursday\0Friday\0Saturday\0");107 DefineLstLoad("ST_MONTHS","January\0February\0March\0April\0May\0"108 "June\0July\0August\0September\0October\0November\0December\0");109 DefineLstLoad("ST_FILE_ATTRS","R\0H\0S\0V\0D\0A\0 \0 \0X\0T\0Z\0C\0F\0");110 DefineLstLoad("ST_FILE_UTIL_FLAGS","r\0d\0i\0a\0c\0R\0p\0m\0x\0s\0"111 "D\0F\0T\0$\0S\0A\0J\0G\0Z\0O\0P\0f\0l\0lb\0la\0");112 DefineLstLoad("ST_BLKDEV_TYPES",113 "NULL\0RAM\0ATA\0FILE_READ\0FILE_WRITE\0ATAPI\0");114 DefineLstLoad("ST_DRV_TYPES",115 "NULL\0REDSEA\0FAT32\0ISO9660\0ISO13490\0ISO13346\0NTFS\0UNKNOWN\0");116 DefineLstLoad("ST_COLORS","BLACK\0BLUE\0GREEN\0CYAN\0"117 "RED\0PURPLE\0BROWN\0LTGRAY\0DKGRAY\0LTBLUE\0LTGREEN\0"118 "LTCYAN\0LTRED\0LTPURPLE\0YELLOW\0WHITE\0");119 DefineLstLoad("ST_INT_NAMES","Divide Error\0SingleStep\0NMI\0Breakpoint\0"120 "Overflow\0BOUND Range Exceeded\0Invalid Opcode\0No Math Coprocessor\0"121 "Double Fault\0Coprocessor Segment Fault\0Invalid TASK\0"122 "Segment Not Present\0Stk Segment Fault\0General Protection\0"123 "Page Fault\0 \0Math Fault\0Alignment Check\0Machine Check\0"124 "SIMD Exception\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0"125 " \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0MP Crash\0Wake\0Dbg\0");126}127 128U8 *Color2Str(U8 *buf,CColorROPU32 c)129{//CColorROPU32 with flags to DCLighting str.130 *buf=0;131 if (c.c0.rop&ROPBF_TWO_SIDED)132 CatPrint(buf,"TWO|");133 if (c.c0.rop&ROPBF_HALF_RANGE_COLOR)134 CatPrint(buf,"HALF|");135 if (0<=c.c0.color<16)136 CatPrint(buf,DefineSub(c.c0.color,"ST_COLORS"));137 else if (c.c0.color==TRANSPARENT)138 CatPrint(buf,"TRANSPARENT");139 else140 CatPrint(buf,"INVALID");141 if (c&ROPF_DITHER) {142 CatPrint(buf,"/");143 if (c.c1.rop&ROPBF_TWO_SIDED)144 CatPrint(buf,"TWO|");145 if (c.c1.rop&ROPBF_HALF_RANGE_COLOR)146 CatPrint(buf,"HALF|");147 if (0<=c.c1.color<16)148 CatPrint(buf,DefineSub(c.c1.color,"ST_COLORS"));149 else if (c.c1.color==TRANSPARENT)150 CatPrint(buf,"TRANSPARENT");151 else152 CatPrint(buf,"INVALID");153 }154 return buf;155}156 157U8 *str2color_lst="/,)}>";158 159CColorROPU16 Str2ColorU16(U8 *st)160{//DCLighting color str with flags to CColorROPU16.161 CColorROPU16 res=COLOR_INVALID;162 I64 i;163 U8 *ptr,*ptr2,*st2;164 if (!st) return COLOR_INVALID;165 while (TRUE) {166 if (!*st||StrOcc(str2color_lst,*st))167 return res;168 if (Bt(char_bmp_alpha,*st)) {169 ptr=st;170 while (Bt(char_bmp_alpha_numeric,*ptr))171 ptr++;172 st2=ptr2=MAlloc(ptr-st+1);173 while (st<ptr)174 *ptr2++=*st++;175 *ptr2++=0;176 if (!StrICmp(st2,"TWO"))177 res.rop|=ROPBF_TWO_SIDED;178 else if (!StrICmp(st2,"HALF"))179 res.rop|=ROPBF_HALF_RANGE_COLOR;180 else if ((i=DefineMatch(st2,"ST_COLORS",LMF_IGNORE_CASE))>=0)181 res.color=i;182 else if (!StrICmp(st2,"TRANSPARENT"))183 res.color=TRANSPARENT;184 else {185 Free(st2);186 return COLOR_INVALID;187 }188 Free(st2);189 } else if (*st=='+'||*st=='|'||Bt(char_bmp_white_space,*st))190 st++;191 else if ('0'<=*st<='9') {192 i=Str2I64(st,10,&ptr);193 if (0<=i<=0xFF) {194 res.color=i;195 st=ptr;196 } else197 return COLOR_INVALID;198 } else199 return COLOR_INVALID;200 }201}202 203CColorROPU32 Str2ColorU32(U8 *st)204{//DCLighting color str with flags to CColorROPU32.205 U8 *st2;206 CColorROPU32 res=0;207 if (!st) return COLOR_INVALID;208 st2=MAlloc(StrLen(st)+1);209 StrFirstRem(st,str2color_lst,st2);210 res.c0=Str2ColorU16(st2);211 if (*st) {212 res.c1=Str2ColorU16(st);213 res|=ROPF_DITHER;214 }215 if (res.c0.color==COLOR_INVALID||res.c1.color==COLOR_INVALID)216 return COLOR_INVALID;217 else218 return res;219}220 