+
+/* Scan filename and push the its tokens
+ onto the stack */
+int lexer_lexfilename
+(uint8_t* str)
+{
+ int ntok, i, cmp, len, set_len, height, width;
+ char map_key[] = "_m_";
+ static uint8_t set_name[MAX_SETNAME_LEN] = {0};
+ uint8_t *first, *map_begin;
+
+ printf("Starting lexerfilename on %s\n", str);
+
+
+ if(*str == 0)
+ printf("Lexfilename:: str is NULL so fail\n");
+ printf("setname is %s\n", set_name);
+
+ /* If last file was a mapfile, then its 5th to last token should
+ be a MOPEN. If this is the case, then we only pass MOPEN, height,
+ weight and name of the current file. */
+ if( (TK_STACKX - 5)->tok_t == MOPEN )
+ { printf("The last file was a mapfile\n");
+ if( (map_begin = strstr(map_key, str)) ) //if the current file is a mapfile
+ { printf("The current file is a variant of the last mapfile\n");
+ printf("Start lexing mapfile %s\n", str);
+ ntok += lexer_lexstring(map_begin, strlen(map_begin));
+ }
+ printf("Current file is not a variant of the last mapfile\n");
+ }
+ else //last file was not a mapfile
+ { printf("Last file was not a mapfile\n");
+
+ first = (uint8_t*) u8_strchr(str, '_'); //find the first '_' to find where str set_name ends
+
+ if(set_name[0] != 0) //if there is a set_name from last str
+ { printf("There is a set_name (%s) present\n", set_name);
+ set_len = first - str;
+
+ if(u8_strncmp(str, set_name, set_len) == 0) //check if it matches the current set_name
+ { str = str + set_len + 1; //if so, remove it from str
+ printf("str set_name matched last set_name, set str to %s\n", str);
+ }
+ else //update set_name to be str set_name
+ { u8_cpy(set_name, str, set_len);
+ set_name[set_len] = 0;
+
+ }
+ }
+ else //set set_name
+ { u8_cpy(set_name, str, first-str);
+ }
+ /* Call lexer_lexstring to tokenize the string */
+ printf("calling lexstring to tokenize str (%s) of len %d\n", str, u8_strlen(str));
+ ntok += lexer_lexstring(str, u8_strlen(str));
+ }
+
+ /*TODO: if regfile, store full path for later */
+
+ printf("Ending lexer_lex on %s, %d tokens were lexed\n", str, ntok);
+ return ntok;
+}
+
+/* int lexer_lexmapfile */
+/* #define INC_X() */
+/* (int height, int width) */
+/* { */
+/* int x, y; */
+
+/* /\* Give scanner_scanpixels a buffer and a len. Iterate through */
+/* buf with buf[n]. If n == 0, do nothing. if n has a value, push x, */
+/* push y, push (z = n << 24), push (ref_id = n >> 8) *\/ */
+/* //scanner_scanpixels() */
+
+/* for(i = 0; i < len; i++) */
+/* if(buf[i] == 0) */
+/* if(x == width) */
+/* x = 0; */
+/* else */
+
+
+
+
+/* } */
+/* fname_bytes = (uint8_t*)(DE_POP()->d_name); */
+ /* printf("d_name is %s\n", fname_bytes); */
+ /* for (fnp = filename, i = 0; i < NAME_MAX; i += unit_size, fnp++) */
+ /* { unit_size = u8_mblen(fname_bytes + i, min(4, NAME_MAX - i)); */
+ /* if (u8_mbtouc(fnp, fname_bytes + i, unit_size) == -1) //add ucs4 char to the filename */
+ /* FAIL("Lexer failed to convert ^%s to unicode\n", (fname_bytes + i)); */
+ /* if (*fnp == 0) //added a terminating char */
+ /* break; */
+ /* } */
+ /* if(u8_mbtouc(filename, DE_POP()->d_name, NAME_MAX) == -1) */
+ /* FAIL("Lexer failed to convert d_name into uint8_t\n"); */
+ /* ulc_fprintf(stdout, "filename is %11U\n c", filename); */