示例#1
0
void Control_bar::_stop()
{
	if (_playing)
		_pause_resume();

	_rewind();
}
示例#2
0
void
c2_db_cronosII_message_set_mark (C2Db *db, gboolean mark)
{
	C2Mailbox *mailbox;
	FILE *fd;
	gint pos;

	mailbox = db->mailbox;
	_lock (mailbox);

	if (!goto_mid (mailbox, db->mid))
		return;

	fd = mailbox->protocol.cronosII.fd;

	/* Move to the 2nd \r */
	pos = ftell (fd);
	if (c2_fd_move_to (fd, '\r', 2, TRUE, TRUE) < 0)
	{
		fseek (fd, pos, SEEK_SET);
		_rewind (mailbox);
		_unlock (mailbox);
		return;
	}
	
	fputc (mark ? '1' : '0', fd);
	fseek (fd, pos, SEEK_SET);

	_unlock (mailbox);
}
示例#3
0
gboolean
c2_db_cronosII_message_add (C2Mailbox *mailbox, C2Db *db)
{
	gint mid = 0;
	FILE *fd;
	gchar *buf;
	C2MessageState state;

	/* Initialization */
	if (!cache_index (mailbox))
		return FALSE;

	_lock (mailbox);
	fd = mailbox->protocol.cronosII.fd;

	/* Get the MID */
	if (mailbox->db)
		mid = mailbox->db->prev->prev->mid+1;

	if (!mid)
		mid = 1;

	db->mid = mid;
	
	fseek (fd, 0, SEEK_END);

	switch (db->state)
	{
		case C2_MESSAGE_READED: state = ' '; break;
		default:
		case C2_MESSAGE_UNREADED: state = 'N'; break;
		case C2_MESSAGE_REPLIED: state = 'R'; break;
		case C2_MESSAGE_FORWARDED: state = 'F'; break;
	}

	fprintf (fd, "%c\r\r%d\r%s\r%s\r%d\r%s\r%d\n",
					state, db->mark, db->subject, db->from,
					db->date, db->account, db->mid);

	/* Now write to its own file */
	buf = g_strdup_printf ("%s" C2_HOME "%s.mbx/%d", g_get_home_dir (), mailbox->name, db->mid);
	if (!(fd = fopen (buf, "w")))
	{
		g_free (buf);
		c2_error_object_set (GTK_OBJECT (mailbox), -errno);
		return FALSE;
	}
	g_free (buf);

	fprintf (fd, "%s\n\n%s", db->message->header, db->message->body);
	fclose (fd);

	_rewind (mailbox);
	_unlock (mailbox);

	return TRUE;
}
示例#4
0
void ignoreWhiteSpace(int (*get_next_byte) (void *),
		      void *get_next_byte_argument)
{
  char c;

  while ((c = get_next_byte(get_next_byte_argument)) != EOF &&
	 (c == ' ' || c == '\n')) {
    ;
  }
  if (c != EOF) {
    _rewind(get_next_byte_argument, -1);
  }
}
示例#5
0
int
fillRedirectionOperands(char **input, char **output,
			int (*get_next_byte) (void *),
			void *get_next_byte_argument)
{
  int len = 0;
  TOKENTYPE type = 0;

  while (1) {
    len = 0;
    type = getTokenType(get_next_byte(get_next_byte_argument));
    switch (type) {
    case REDIRECTION1:
      type = readNextToken(input, &len, get_next_byte,
			   get_next_byte_argument);
      if (!(*input) || !strlen(*input)) {
	goto err;
      }
      break;
    case REDIRECTION2:
      type = readNextToken(output, &len, get_next_byte,
			   get_next_byte_argument);
      if (!(*output) || !strlen(*output)) {
	goto err;
      }
      break;
    default:
      _rewind(get_next_byte_argument, -1);
      goto out;
    }
    if (type == REDIRECTION2 || type == REDIRECTION1) {
      continue;
    } else {
      break;
    }
  }
 out:
  return type;
 err:
  printErr();
  return -1;
}
示例#6
0
int
checkRedirection(int (*get_next_byte) (void *),
		 void *get_next_byte_argument)
{
  char c;
  int flag = 0;

  while ((c = get_next_byte(get_next_byte_argument)) != EOF && c == ' ') {
    ;
  }
  switch (getTokenType(c)) {
  case REDIRECTION1:
  case REDIRECTION2:
    flag = 1;
    break;
  default:
    flag = 0;
    break;
  }
  _rewind(get_next_byte_argument, -1);

  return flag;
}
示例#7
0
void main(void) {
    uint8_t inputProgramType;
    char *inputProgram;
    uint16_t inputProgramSize;
    ti_var_t programSlot;
    uint8_t selectedProgram, amountOfPrograms, res = VALID, type;
    unsigned int programDataSize, offset, totalSize;
    uint8_t beginList, amountOfProgramsToDisplay;
    uint8_t relativeSelectedProgram;
    const char ICEheader[] = {tii, 0};
    ti_var_t tempProg;
    char buf[30], *temp_name = "", var_name[9];
    sk_key_t key = 0;
    void *search_pos;
    bool didCompile;

    // Install hooks
    ti_CloseAll();
    if ((tempProg = ti_Open("ICEHOOKS", "r"))) {
        ti_SetArchiveStatus(true, tempProg);
        SetHooks(ti_GetDataPtr(tempProg));
    }
    
    // Enable lowercase
    asm("ld iy, 0D00080h");
    asm("set 3, (iy+024h)");

    // check if a program was used as input
    ti_CloseAll();
    ice.usingInputProgram = false;
    inputProgram = os_RclAns(&inputProgramType);
    if (inputProgram && inputProgramType == TI_STRING_TYPE && inputProgram[2] == tProg && (inputProgramSize = *(uint16_t*)inputProgram) < 10) {
        memset(var_name, 0, sizeof var_name);
        memcpy(var_name, inputProgram + 3, inputProgramSize - 1);
        programSlot = ti_OpenVar(var_name, "r", TI_PRGM_TYPE);
        if (programSlot) {
            ice.usingInputProgram = true;
        }
    }

    // Yay, GUI! :)
displayMainScreen:
    gfx_Begin();

    gfx_SetColor(189);
    gfx_FillRectangle_NoClip(0, 0, 320, 10);
    gfx_SetColor(0);
    gfx_SetTextFGColor(0);
    gfx_HorizLine_NoClip(0, 10, 320);
    gfx_PrintStringXY(infoStr, 12, 1);

    // Get all the programs that start with the [i] token
    selectedProgram = 0;
    didCompile = false;
    ti_CloseAll();

    if (ice.usingInputProgram) {
        goto compile_program;
    }

    search_pos = NULL;
    while ((temp_name = ti_DetectAny(&search_pos, ICEheader, &type)) != NULL) {
        if (type == TI_PRGM_TYPE || type == TI_PPRGM_TYPE) {
            // Hidden programs
            if ((uint8_t)(*temp_name) < 64) {
                *temp_name += 64;
            }

            // Save the program name
            inputPrograms[selectedProgram] = malloc(9);
            strcpy(inputPrograms[selectedProgram++], temp_name);
        }
        
        if (selectedProgram >= NUMBEROFPROGRAM) {
            break;
        }
    }

    amountOfPrograms = selectedProgram;
    beginList = 0;
    amountOfProgramsToDisplay = (amountOfPrograms > PROGRAMPERSCREEN ? PROGRAMPERSCREEN : amountOfPrograms);

    // Check if there are ICE programs
    if (!amountOfPrograms) {
        gfx_PrintStringXY("No programs found!", 10, 13);
        goto stop;
    }

    // Display all the sorted programs
    qsort(inputPrograms, amountOfPrograms, sizeof(char *), myCompare);
    displayProgramList(beginList, amountOfProgramsToDisplay);
    
    // Display buttons
    gfx_PrintStringXY("Build", 4, 232);
    printButton(1);
    gfx_PrintStringXY("Debug", 66, 232);
    printButton(65);
    gfx_PrintStringXY("Quit", 285, 232);
    printButton(279);
    gfx_SetColor(0);

    // Select a program
    selectedProgram = 1;
    relativeSelectedProgram = 1;
    while ((key = os_GetCSC()) != sk_Enter && key != sk_2nd && key != sk_Yequ && key != sk_Window) {
        uint8_t selectionOffset = relativeSelectedProgram * 10 + 3;

        gfx_PrintStringXY(">", 1, selectionOffset);

        if (key) {
            gfx_SetColor(255);
            gfx_FillRectangle_NoClip(1, selectionOffset, 8, 8);

            // Stop and quit
            if (key == sk_Clear || key == sk_Graph) {
                goto err;
            }

            // Select the next program
            if (key == sk_Down) {
                if (selectedProgram != amountOfPrograms) {
                    selectedProgram++;
                    relativeSelectedProgram++;
                    if (relativeSelectedProgram > PROGRAMPERSCREEN) {
                        clearProgramList();
                        relativeSelectedProgram--;
                        beginList++;
                        displayProgramList(beginList, amountOfProgramsToDisplay);
                    }
                } else {
                    clearProgramList();
                    selectedProgram = 1;
                    relativeSelectedProgram = 1;
                    beginList = 0;
                    displayProgramList(beginList, amountOfProgramsToDisplay);
                }
            }

            // Select the previous program
            if (key == sk_Up) {
                if (selectedProgram != 1) {
                    selectedProgram--;
                    relativeSelectedProgram--;
                    if(relativeSelectedProgram == 0) {
                        clearProgramList();
                        relativeSelectedProgram++;
                        beginList--;
                        displayProgramList(beginList, amountOfProgramsToDisplay);
                    }
                } else {
                    clearProgramList();
                    selectedProgram = amountOfPrograms;
                    relativeSelectedProgram = (amountOfPrograms > PROGRAMPERSCREEN ? PROGRAMPERSCREEN : amountOfPrograms);
                    beginList = (selectedProgram >= PROGRAMPERSCREEN ? selectedProgram - PROGRAMPERSCREEN : 0);
                    displayProgramList(beginList, amountOfProgramsToDisplay);
                }
            }
        }
    }
    
    // Set some vars
    strcpy(var_name, inputPrograms[selectedProgram - 1]);
    for (selectedProgram = 0; selectedProgram < amountOfPrograms; selectedProgram++) {
        free(inputPrograms[selectedProgram]);
    }

compile_program:

    // Erase screen
    gfx_SetColor(255);
    gfx_FillRectangle_NoClip(0, 11, 320, 210);
    gfx_FillRectangle_NoClip(0, 220, 270, 20);

    didCompile = true;
    memset(&ice, 0, sizeof ice);
    memset(&expr, 0, sizeof expr);
    memset(&reg, 0, sizeof reg);
    memset(&prescan, 0, sizeof prescan);
    memset(&debug, 0, sizeof debug);
    
    // Output debug appvar
    if (key == sk_Window) {
        ice.debug = true;
    }

    gfx_SetTextXY(1, 12);
    displayMessageLineScroll("Prescanning...");
    displayLoadingBarFrame();

    ice.inPrgm = _open(var_name);
    _seek(0, SEEK_END, ice.inPrgm);

    ice.programLength   = _tell(ice.inPrgm);
    ice.programData     = (uint8_t*)0xD52C00;
    ice.programPtr      = ice.programData;
    ice.programDataData = ice.programData + 0xFFFF;
    ice.programDataPtr  = ice.programDataData;
    
    // Get the name/icon/description
    _rewind(ice.inPrgm);
    if ((res = getNameIconDescription()) != VALID) {
        displayError(res);
        goto stop;
    }
    
    // Open debug appvar to store things to
    sprintf(buf, "%.5sDBG", ice.outName);
    debug.dbgPrgm = ti_Open(buf, "w");
    
    if (ice.debug) {
        if (!debug.dbgPrgm) {
            displayError(E_NO_DBG_FILE);
            goto stop;
        }
        
        // Write version bytes to debug appvar
        ti_PutC(DEBUG_VERSION_MAJOR, debug.dbgPrgm);
        ti_PutC(DEBUG_VERSION_MINOR, debug.dbgPrgm);
        
        // Write amount of programs to debug appvar
        ti_PutC(0, debug.dbgPrgm);
    } else if (debug.dbgPrgm) {
        ti_Delete(buf);
    }

    // Prescan the program and output the header
    preScanProgram();
    if ((res = parsePrescan()) != VALID) {
        displayError(res);
        goto stop;
    }
	
	if (prescan.amountOfVariablesUsed > 84) {
		gfx_SetTextFGColor(224);
		sprintf(buf, "Too much variables used: %d", prescan.amountOfVariablesUsed);
		displayMessageLineScroll(buf);
		didCompile = false;
		goto stop;
	}

    // Allow hidden programs from Cesium
    if (*var_name < 64) {
        *var_name += 64;
    }
    sprintf(buf, "Compiling program %s...", var_name);
    displayMessageLineScroll(buf);

    // Create or empty the output program if parsing succeeded
    if ((res = parseProgram()) == VALID) {
        unsigned int previousSize = 0;

        // Get the sizes of both stacks
        ice.programSize = (uintptr_t)ice.programPtr - (uintptr_t)ice.programData;
        programDataSize = (uintptr_t)ice.programDataData - (uintptr_t)ice.programDataPtr;

        // Change the pointers to the data as well, but first calculate the offset
        offset = PRGM_START + ice.programSize - (uintptr_t)ice.programDataPtr;
        while (ice.dataOffsetElements--) {
            unsigned int *tempDataOffsetStackPtr = ice.dataOffsetStack[ice.dataOffsetElements];

            *tempDataOffsetStackPtr += offset;
        }
        totalSize = ice.programSize + programDataSize + 3;

        // Export the program
        ice.outPrgm = _open(ice.outName);
        if (ice.outPrgm) {
            // This program already exists
            if ((uint8_t)ti_GetC(ice.outPrgm) != 0xEF || (uint8_t)ti_GetC(ice.outPrgm) != 0x7B) {
                gfx_SetTextFGColor(224);
                displayMessageLineScroll("Output program already exists!");
                displayMessageLineScroll("Delete program to continue.");
                didCompile = false;
                goto stop;
            }
            
            previousSize = ti_GetSize(ice.outPrgm);
            ti_Close(ice.outPrgm);
        }
        ice.outPrgm = _new(ice.outName);
        if (!ice.outPrgm) {
            displayMessageLineScroll("Failed to open output file");
            goto stop;
        }

        // Write ASM header
        ti_PutC(tExtTok, ice.outPrgm);
        ti_PutC(tAsm84CeCmp, ice.outPrgm);

        // Write ICE header to be recognized by Cesium
        ti_PutC(0x7F, ice.outPrgm);

        // Write the header, main program, and data to output :D
        ti_Write(ice.programData, ice.programSize, 1, ice.outPrgm);
        if (programDataSize) ti_Write(ice.programDataPtr, programDataSize, 1, ice.outPrgm);
        _rewind(ice.outPrgm);
        
        // Write final CRC to debug program, as well as the ending line of the first program and the amount of total programs
        if (ice.debug) {
            uint16_t CRC;
            
            CRC = GetCRC(ti_GetDataPtr(ice.outPrgm), ti_GetSize(ice.outPrgm));
            WriteWordToDebugProg(CRC);
            ti_Seek(3 + offsetof(debug_prog_t, endingLine), SEEK_SET, debug.dbgPrgm);
            WriteWordToDebugProg(debug.currentLine);
            ti_Seek(2, SEEK_SET, debug.dbgPrgm);
            ti_PutC(debug.amountOfPrograms + 1, debug.dbgPrgm);         // +1 because the main program starts at 0
        }

        // Yep, we are really done!
        gfx_SetTextFGColor(4);
        displayMessageLineScroll("Successfully compiled!");
        if (ice.debug) {
            displayMessageLineScroll("Successfully exported debug appvar");
        }

        // Skip line
        displayMessageLineScroll(" ");

        // Display the size
        gfx_SetTextFGColor(0);
        sprintf(buf, "Output size: %u bytes", totalSize);
        displayMessageLineScroll(buf);
        if (previousSize) {
            sprintf(buf, "Previous size: %u bytes", previousSize);
            displayMessageLineScroll(buf);
        }
        sprintf(buf, "Output program: %s", ice.outName);
        displayMessageLineScroll(buf);
    } else if (res != W_VALID) {
        displayError(res);
    }

stop:
    gfx_SetTextFGColor(0);
    if (didCompile) {
        if (res == VALID) {
            gfx_PrintStringXY("Run", 9, 232);
            printButton(1);
        } else if (!ti_IsArchived(ice.inPrgm)) {
            gfx_PrintStringXY("Goto", 222, 232);
            printButton(217);
        }
        gfx_PrintStringXY("Back", 70, 232);
        printButton(65);
        gfx_PrintStringXY("Quit", 285, 232);
        printButton(279);
    }
    while (!(key = os_GetCSC()));
err:
    gfx_End();

    if (key != sk_Graph && didCompile) {
        if (key == sk_Yequ && res == VALID) {
            RunPrgm(ice.outName);
        }
        if (key == sk_Window) {
            // Erase screen
            gfx_SetColor(255);
            gfx_FillRectangle_NoClip(0, 11, 320, 229);

            goto displayMainScreen;
        }
        if (key == sk_Trace && res != VALID && !ti_IsArchived(ice.inPrgm)) {
            char buf[9];
            
            ti_GetName(buf, ice.inPrgm);
            GotoEditor(buf, ti_Tell(ice.inPrgm) - 1);
        }
    }
    ti_CloseAll();
}
示例#8
0
/**
 * c2_db_cronosII_load
 * @mailbox: Mailbox to load.
 *
 * Will load the Cronos II Mailbox.
 *
 * Return Value:
 * Number of loaded messages or -1 in case of error.
 **/
gint
c2_db_cronosII_load (C2Mailbox *mailbox)
{
	C2Db *current = NULL, *next;
	FILE *fd;
	gint position, mid;
	gchar c, *line, *buf;
	gboolean mark;
	time_t date;

	c2_return_val_if_fail_obj (mailbox, -1, C2EDATA, GTK_OBJECT (mailbox));	

	/* Initialization */
	if (!cache_index (mailbox))
		return -1;
	
	_lock (mailbox);
	fd = mailbox->protocol.cronosII.fd;
	_rewind (mailbox);
	
	/* Go through the lines */
	for (position = 0;;)
	{
		if (fread (&c, 1, sizeof (gchar), fd) < 1)
			break;

		/* A D has been reached */
		if (c == 'D')
		{
			/* Lets go to the next line.. */
			if (!c2_fd_move_to (fd, '\n', 1, TRUE, TRUE))
				break;

			/* .. and start again */
			continue;
		}

		/* Now that we know this is an interesting line,
		 * lets grab it.
		 */
		if (!(line = c2_fd_get_line (fd)))
		{
			c2_error_object_set (GTK_OBJECT (mailbox), c2_errno);
			break;
		}

		/* Create the new C2Db */
		buf = c2_str_get_word (5, line, '\r');
		date = atoi (buf);
		g_free (buf);

		buf = c2_str_get_word (7, line, '\r');
		mid = atoi (buf);
		g_free (buf);
		mailbox->protocol.cronosII.mid = mid;

		buf = c2_str_get_word (2, line, '\r');
		mark = atoi (buf);
		g_free (buf);

		next = c2_db_new (mailbox, mark, c2_str_get_word (3, line, '\r'),
							c2_str_get_word (4, line, '\r'),
							c2_str_get_word (6, line, '\r'),
							date, mid, ++position);

		switch (c)
		{
			default:
			case ' ': next->state = C2_MESSAGE_READED; break;
			case 'N': next->state = C2_MESSAGE_UNREADED; break;
			case 'R': next->state = C2_MESSAGE_REPLIED; break;
			case 'F': next->state = C2_MESSAGE_FORWARDED; break;
		}

		/* Append it to the list */
		if (current)
			current->next = next;

		if (!mailbox->db)
			mailbox->db = next;

		current = next;
	}
	
	_unlock (mailbox);
	_rewind (mailbox);

	return position;
}
示例#9
0
/**
 * This function will go to an specific MID
 * in an index file.
 **/
static gboolean
goto_mid (C2Mailbox *mailbox, gint req_mid)
{
	gboolean found = FALSE;
	gint line_length;
	
	if (!cache_index (mailbox))
		return FALSE;

	if (mailbox->protocol.cronosII.mid < req_mid)
	{
current_mid_less_than_req_mid:

		/* Go through the lines */
		for (;;)
		{
			gint fmid;

			if ((fmid = mid_in_line (mailbox, &line_length)) < 0)
			{
				found = FALSE;
				_rewind (mailbox);
				break;
			}
			
			if (fmid == req_mid)
			{
				found = TRUE;
				break;
			} else
				fseek (mailbox->protocol.cronosII.fd, line_length, SEEK_CUR);
		}
	} else if (mailbox->protocol.cronosII.mid > req_mid)
	{
		/* FIXME This is an ugly thing to do, lets change it */
		_rewind (mailbox);
		goto current_mid_less_than_req_mid;

		/* Go through the lines backwards */
		for (;;)
		{
			if (!c2_fd_move_to (mailbox->protocol.cronosII.fd, '\n', 1, FALSE, TRUE))
			{
move_error:
				c2_error_object_set (GTK_OBJECT (mailbox), c2_errno);
				found = FALSE;
				_rewind (mailbox);
				break;
			} else
			{
				if (!c2_fd_move_to (mailbox->protocol.cronosII.fd, '\r', 7, FALSE, FALSE))
					goto move_error;
				if (fseek (mailbox->protocol.cronosII.fd, -1, SEEK_CUR) < 0)
				{
					c2_error_set (-errno);
					goto move_error;
				}

				if (mid_in_line_reverse (mailbox, &line_length) == req_mid)
				{
					found = TRUE;
					break;
				} else
					fseek (mailbox->protocol.cronosII.fd, -(line_length+1), SEEK_CUR);
			}
		}
	} else
		found = TRUE;

	return found;
}
示例#10
0
/**
 * This function will do the same
 * thing as mid_in_line but will
 * go to the previous line instead
 * of to the next line.
 **/
static gint
mid_in_line_reverse (C2Mailbox *mailbox, gint *length)
{
	gchar c;
	gint line_length;
	gint sep;
	gint mid = -1;
	FILE *fd;

	fd = mailbox->protocol.cronosII.fd;
	
	/* Go through the line */
start:
	for (sep = 0, line_length = 0; fread (&c, 1, sizeof (gchar), fd);)
	{
		/* EOF reached */
		if (c == EOF)
		{
			_rewind (mailbox);
			return -1;
		}

		/* A D reached */
		if (c == 'D')
		{
			if (!c2_fd_move_to (mailbox->protocol.cronosII.fd, '\n', 2, FALSE, TRUE))
			{
				c2_error_object_set (GTK_OBJECT (mailbox), c2_errno);
				_rewind (mailbox);
				return -1;
			}
		}

		/* A \n reached */
		if (c == '\n')
			goto start;
			
		line_length++;
			
		/* A \r reached */
		if (c == '\r')
		{
			if (++sep == 7)
			{
				gchar buffer[11];
				gint bi = 0;

				for (bi = 0;; bi++)
				{
					line_length++;
					fread (&buffer[bi], 1, sizeof (gchar), fd);
				
					if (buffer[bi] == '\n' || buffer[bi] == EOF)
						break;
				}

				buffer[bi] = 0;
					
				mid = atoi (buffer);
				mailbox->protocol.cronosII.mid = mid;

				fseek (fd, -(line_length), SEEK_CUR);
				break;
			}
		}
	}

	if (length)
		*length = line_length;
	
	return mid;
}
示例#11
0
/**
 * This function will find the MID of the line
 * where the FD is currently set or the MID of
 * the next valid line.
 * The FD will be positionated at the start of
 * the line.
 **/
static gint
mid_in_line (C2Mailbox *mailbox, gint *length)
{
	gchar c;
	gint line_length;
	gint sep;
	gint mid = -1;
	FILE *fd;

	fd = mailbox->protocol.cronosII.fd;
	
	/* Go through the line */
start:
	for (sep = 0, line_length = 0; fread (&c, 1, sizeof (gchar), fd);)
	{
		/* EOF reached */
		if (c == EOF)
		{
			_rewind (mailbox);
			return -1;
		}

		/* A D reached */
		if (!sep && c == 'D')
		{
			for (; fread (&c, 1, sizeof (gchar), fd);)
			{
				if (c == '\n')
					goto start;
				else if (c == EOF)
				{
					_rewind (mailbox);
					return -1;
				}
			}
		}

		/* A \n reached */
		if (c == '\n')
			goto start;
			
		line_length++;
			
		/* A \r reached */
		if (c == '\r')
		{
			if (++sep == 7)
			{
				gchar buffer[11];
				gint bi = 0;

				for (bi = 0;; bi++)
				{
					line_length++;
					fread (&buffer[bi], 1, sizeof (gchar), fd);
				
					if (buffer[bi] == '\n' || buffer[bi] == EOF)
						break;
				}

				buffer[bi] = 0;
					
				mid = atoi (buffer);
				mailbox->protocol.cronosII.mid = mid;

				fseek (fd, -(line_length), SEEK_CUR);
				break;
			}
		}
	}

	if (length)
		*length = line_length;
	
	return mid;
}
示例#12
0
int
readNextToken(char **t, int *tlen, int (*get_next_byte) (void *),
              void *get_next_byte_argument)
{
  char c;
  char *token;
  int len = 0;
  int maxLen = BUF_SIZE;
  TOKENTYPE type = NOT_DEFINED;

  if (*tlen) {
    len = strlen(*t);
    token = *t;
    maxLen = *tlen;
  } else {
    token = malloc(BUF_SIZE);
    len = 0;
    maxLen = BUF_SIZE;
  }

  ignoreWhiteSpace(get_next_byte, get_next_byte_argument);

  while ((c = get_next_byte(get_next_byte_argument)) != EOF) {
    type = getTokenType(c);
    if (type == ALPHANUM) {
      if (c == '`') {
	backquote = !backquote;
      }
      token[len++] = c;
      if (len + 1 == maxLen) {
      	maxLen *= 2;
      	token = realloc(token, maxLen);
      }
    } else if (type == SPACE) {
      int val;
      while ((c = get_next_byte(get_next_byte_argument)) != EOF && c == ' ') {
	;
      }
      val = getTokenType(c);
      if (val == ALPHANUM || val == O_PAR || val == PIPE) {
	_rewind(get_next_byte_argument, -1);
      } else if (val == REDIRECTION1 || val == REDIRECTION2) {
	_rewind(get_next_byte_argument, -1);
	type = val;
      } else {
	type = val;
      }
      break;
    } else if (type == O_PAR) {
        *t = token;
        *tlen += 1;
        return type;
    } else if (type == REDIRECTION1 || type == REDIRECTION2) {
      _rewind(get_next_byte_argument, -1);
      break;
    } else {
      break;
    }
  }
  /* if (len == 0) { */
  /*   *t = NULL; */
  /*   free(token); */
  /* } else { */
    token[len] = '\0';
    *t = token;
    *tlen = maxLen;
    //  }
  return type;
}