📄 misc.c
字号:
/* ---------------------------------------------------------------------------- * misc.c * this module contains misc functions * * Copyright 2003/2004 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * ----------------------------------------------------------------------------*/#ifdef HAVE_CONFIG_H# include <config.h>#endif#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/stat.h>#include <signal.h>#include <string.h>#include <termios.h>#include "isp-at89.h"extern struct ProgrammingData pd;/* Signal handler stuff */voidsignalhandler (int signum){ printf("\n"); setTerminal(&pd, 0); /* restore terminal settings */ exit(1); /* exit the program */}intinstallSighandler(){ struct sigaction sa = { {signalhandler}, {{0}}, SA_RESTART, 0 }; if (sigaction (SIGINT, &sa, NULL)) { printf (_("-- ERROR: cannot install SIGINT handler\n")); return ERROR; } if (sigaction (SIGTERM, &sa, NULL)) { printf (_("-- ERROR: cannot install SIGTERM handler\n")); return ERROR; } return OK;}/* Set the Terminal to Non Canonical mode with echo off * or reset the terminal. * USAGE: set_terminal(1) for raw mode */voidsetTerminal(struct ProgrammingData *pdata, int raw){ struct termios newcfg; if (raw){ /* save original settings and set raw mode*/ tcgetattr(fileno(stdin), &pdata->oldcfg); newcfg = pdata->oldcfg; newcfg.c_lflag &= ~ICANON; if (tcsetattr(fileno(stdin), TCSANOW, &newcfg) !=0) printf(_("-- WARNING: could not set terminal attributes on stdin\n")); else pdata->flags.rawterm = 1; } else if (pdata->flags.rawterm) tcsetattr(fileno(stdin), TCSANOW, &pdata->oldcfg); /* restore settings */}intgetFileStatus (char *file){ struct stat stat_buf; if (file[0] == 0) /* file is empty */ return FST_NOARG; if(stat(file, &stat_buf)) { return FST_NOEXIST; } else { if (S_ISCHR(stat_buf.st_mode)) return FST_CHARDEV; if (S_ISBLK(stat_buf.st_mode)) return FST_BLKDEV; if (S_ISREG(stat_buf.st_mode)) return FST_FILE; } return FST_UNKNOWN;}/* This function prints the current configuration to terminal. */voidprintFlags (struct ProgrammingData *pdata){ printf(_(" Additional options: ")); if (pdata->flags.erase == 1) { printf(_("preceding memory erase")); if (pdata->flags.verify == 1) { printf(","); printf(_(" verify")); } } else if (pdata->flags.verify == 1) printf(_(" verify")); else printf(_(" none")); printf(".\n");}/* This function decodes the given memory type and returns its name. * isp-at89.h defines which memory types are available. */const char *getMemoryName(int type){ static const char *MemNames[] = { N_("internal flash memory"), N_("external flash memory"), N_("EEPROM")}; return _(MemNames[type & 0x3]);}/* This function decodes the given memory type and returns its * size in bytes. isp-at89.h defines which memory types are available. */intgetMemorySize(int type){ switch (type) { case MEM_EXTERN: /* This value should be evaluated from the real existing * external memory later */ return AT89S8252_MEMSIZE_EXTERN; case MEM_EEPROM: return AT89S8252_MEMSIZE_EEPROM; case MEM_INTERN: default: return AT89S8252_MEMSIZE_INTERN; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -